Planeshift

pawswidget.h

Go to the documentation of this file.
00001 /*
00002  * pawswidget.h - Author: Andrew Craig
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  *
00019  * pawswidget.h: interface for the pawsWidget class.
00020  ---------------------------------------------------------------------------*/
00021 
00022 #ifndef PAWS_WIDGET_HEADER
00023 #define PAWS_WIDGET_HEADER
00024 
00025 #include <ivideo/graph2d.h>
00026 
00027 #include <csutil/array.h>
00028 #include <csutil/csstring.h>
00029 
00030 #include <csgeom/csrectrg.h>
00031 #include <csgeom/vector2.h>
00032 
00033 #include <iutil/document.h>
00034 
00035 //#include "net/cmdbase.h"
00036 #include "pawsmanager.h"
00037 #include "util/scriptvar.h"
00038 
00043 #define ATTACH_LEFT     2
00044 #define ATTACH_RIGHT    4
00045 #define ATTACH_BOTTOM   8
00046 #define ATTACH_TOP      16
00047 #define PROPORTIONAL_LEFT   32
00048 #define PROPORTIONAL_RIGHT  64
00049 #define PROPORTIONAL_TOP    128
00050 #define PROPORTIONAL_BOTTOM 256
00051 
00052 #define SCROLL_UP     -1000
00053 #define SCROLL_DOWN   -2000
00054 #define SCROLL_THUMB  -3000
00055 #define SCROLL_AUTO   -4000
00056 #define SCROLL_SET    -5000
00057 
00058 #define DEFAULT_MIN_HEIGHT  5
00059 #define DEFAULT_MIN_WIDTH   5
00060 
00061 
00062 #define RESIZE_LEFT    2
00063 #define RESIZE_RIGHT   4
00064 #define RESIZE_TOP     8
00065 #define RESIZE_BOTTOM 16
00066 
00067 enum
00068 {
00069     ALIGN_LEFT,
00070     ALIGN_CENTER,
00071     ALIGN_RIGHT
00072 };
00073 
00074 #define BORDER_INNER_BEVEL 0x1
00075 #define BORDER_OUTER_BEVEL 0x2
00076 #define BORDER_REVERSED    0x4
00077 #define BORDER_BUMP        (BORDER_OUTER_BEVEL)
00078 #define BORDER_RAISED      (BORDER_INNER_BEVEL|BORDER_OUTER_BEVEL)
00079 #define BORDER_SUNKEN      (BORDER_REVERSED|BORDER_OUTER_BEVEL)
00080 #define BORDER_ETCHED      (BORDER_REVERSED|BORDER_RAISED)
00081 
00082 
00083 #define DEFAULT_FONT_SIZE   12
00084 
00085 #define DEFAULT_FONT_STYLE     0
00086 #define FONT_STYLE_DROPSHADOW  1
00087 #define FONT_STYLE_BOLD        2
00088 
00089 
00090 enum PAWS_WIDGET_SCRIPT_EVENTS
00091 {
00092     PW_SCRIPT_EVENT_SHOW = 0,
00093     PW_SCRIPT_EVENT_HIDE,
00094     PW_SCRIPT_EVENT_MOUSEDOWN,
00095     PW_SCRIPT_EVENT_MOUSEUP,
00096     PW_SCRIPT_EVENT_VALUECHANGED,
00097 
00098     PW_SCRIPT_EVENT_COUNT
00099 };
00100 
00101 struct iPawsImage;
00102 class PawsManager;
00103 class pawsBorder;
00104 class pawsScrollBar;
00105 class pawsListBox;
00106 class pawsButton;
00107 class pawsMenu;
00108 class pawsMenuAction;
00109 class WidgetConfigWindow;
00110 class pawsScript;
00111 class pawsTitle;
00112 
00116 class pawsWidget : public iPAWSSubscriber, public iScriptableVar
00117 {
00118 public:
00120     class iWidgetData {};
00121 
00122 protected:
00124     csString factory;
00125 
00127     int id;
00128 
00130     pawsWidget* parent;
00131 
00133     csRef<iGraphics2D> graphics2D;
00134 
00136     csRect defaultFrame;
00137 
00139     csRect screenFrame;
00140 
00142     csRect clipRect;
00143 
00145     pawsTitle* titleBar;
00146 
00148     csString filename;
00149 
00151     pawsButton* close_widget;
00152 
00160     csArray<pawsWidget*> children;
00161 
00163     csArray<pawsWidget*> taborder;
00164 
00166     pawsWidget* onEnter;
00167 
00169     bool visible;
00170 
00175     bool saveWidgetPositions;
00176 
00181     bool configurable;
00182 
00184     bool movable;
00185 
00187     bool isResizable;
00188 
00190     bool showResize;
00191 
00196     bool resizeToScreen;
00197 
00199     bool keepaspect;
00200 
00202     bool alwaysOnTop;
00203 
00205     int min_width;
00206 
00208     int min_height;
00209 
00211     int max_width;
00212 
00214     int max_height;
00215 
00217     csString name;
00218 
00220     csString closeName;
00221 
00223     csString subscribedVar;
00224 
00230     int bgColour;
00231 
00233     csRef<iPawsImage> bgImage;
00234 
00236     pawsBorder* border;
00237 
00239     bool borderTitleShadow;
00240 
00242     int attachFlags;
00243 
00245     bool hasFocus;
00246 
00248     bool hasMouseFocus;
00249 
00251     float fadeVal;
00252 
00254     int alpha;
00255 
00257     int alphaMin;
00258 
00260     bool fade;
00261 
00263     float fadeSpeed;
00264 
00271     csString contextMenuFile;
00272 
00278     pawsMenu* contextMenu;
00279 
00281     int borderColours[5];
00282 
00284     bool hasBorderColours;
00285 
00287     csRef<iFont> myFont;
00288 
00290     int defaultFontColour;
00291 
00293     int defaultFontShadowColour;
00294 
00296     float defaultFontSize;
00297 
00299     float fontSize;
00300 
00302     bool scaleFont;
00303 
00305     csString fontName;
00306 
00308     int fontStyle;
00309 
00314     csString xmlbinding;
00315 
00317     csString toolTip;
00318 
00320     csString defaultToolTip;
00321 
00323     csRef<iPawsImage> maskImage;
00324 
00330     bool ignore;
00331 
00333     int margin;
00334 
00336     iWidgetData* extraData;
00337 
00339     bool needsRender;
00340 
00345     bool parentDraw;
00346 
00354     bool overwrite_subscription;
00355 
00356     csString subscription_format;
00357 
00358     pawsScript* scriptEvents[PW_SCRIPT_EVENT_COUNT];
00359 
00360     csHash<csString,csString> defaultWidgetStyles;
00361 
00362     bool ReadDefaultWidgetStyles(iDocumentNode* node);
00363 
00365     bool showOnMouseOver;
00366 
00368     csString showOnMouseOver_image;
00369 
00370 public:
00371 
00372     pawsWidget();
00373     pawsWidget(const pawsWidget &origin);
00374 
00375 
00376     virtual ~pawsWidget();
00377 
00390     virtual pawsWidget* WidgetAt(int x, int y);
00391 
00392     virtual void Ignore(bool ig)
00393     {
00394         ignore = ig;
00395     }
00396 
00402     virtual void PerformAction(const char* action);
00403 
00409     virtual csRect GetScreenFrame();
00410 
00416     virtual csRect GetDefaultFrame()
00417     {
00418         return defaultFrame;
00419     }
00420 
00426     bool IsVisible()
00427     {
00428         return visible && (!parent || parent->IsVisible());
00429     }
00430 
00436     void SetVisibility(bool visible)
00437     {
00438         if(visible) Show();
00439         else Hide();
00440     }
00441 
00448     virtual void Show();
00449 
00457     virtual void ShowBehind();
00458 
00465     virtual void Hide();
00466 
00470     virtual void Close()
00471     {
00472         Hide();
00473     }
00474 
00483     virtual bool CheckButtonPressed(int button, int modifiers, pawsWidget* pressedWidget);
00484 
00493     virtual bool CheckButtonReleased(int button, int modifiers, pawsWidget* pressedWidget);
00494 
00499     virtual bool CheckKeyHandled(int /*keyCode*/)
00500     {
00501         return false;
00502     }
00503 
00511     void AddChild(pawsWidget* widget);
00512 
00520     void AddChild(size_t Index, pawsWidget* widget);
00521 
00526     virtual void DeleteChild(pawsWidget* widget);
00527 
00531     void DeleteYourself()
00532     {
00533         parent->DeleteChild(this);
00534     }
00535 
00542     void RemoveChild(pawsWidget* widget);
00543 
00549     pawsWidget* GetChild(size_t i)
00550     {
00551         return children.Get(i);
00552     }
00553 
00559     size_t GetChildrenCount()
00560     {
00561         return children.GetSize();
00562     }
00563 
00570     bool IsIndirectChild(pawsWidget* widget);
00571 
00577     bool IsChildOf(pawsWidget* someParent);
00578 
00584     bool Includes(pawsWidget* widget);
00585 
00591     void SetParent(pawsWidget* widget);
00592 
00602     pawsWidget* FindWidget(const char* name, bool complain = true);
00603 
00613     pawsWidget* FindWidget(int id, bool complain = true);
00614 
00623     pawsWidget* FindWidgetXMLBinding(const char* xmlbinding);
00624 
00630     virtual const csString &GetXMLBinding()
00631     {
00632         return xmlbinding;
00633     }
00634 
00640     virtual void SetXMLBinding(csString &xmlbinding)
00641     {
00642         this->xmlbinding = xmlbinding;
00643     }
00644 
00650     pawsWidget* GetParent()
00651     {
00652         return parent;
00653     }
00654 
00661     virtual bool Load(iDocumentNode* node);
00662 
00668     virtual bool LoadAttributes(iDocumentNode* node);
00669 
00675     virtual bool LoadEventScripts(iDocumentNode* node);
00676 
00682     virtual bool LoadChildren(iDocumentNode* node);
00683 
00692     bool LoadFromFile(const csString &fileName);
00693 
00697     virtual bool Setup(iDocumentNode* /*node*/)
00698     {
00699         return true;
00700     }
00701 
00709     virtual bool PostSetup()
00710     {
00711         return true;
00712     }
00713 
00722     virtual bool SelfPopulateXML(const char* xmlstr);
00723 
00736     virtual bool SelfPopulate(iDocumentNode* node);
00737 
00743     bool DrawWindow();
00744 
00748     void DrawForeground();
00749 
00756     virtual void Draw();
00757 
00758     virtual void Draw3D(iGraphics3D*) {}
00759 
00765     virtual void DrawBackground();
00766 
00770     virtual void DrawChildren();
00771 
00777     virtual void DrawMask();
00778 
00782     virtual bool ParentDraw() const
00783     {
00784         return parentDraw || !PawsManager::GetSingleton().UsingR2T();
00785     }
00786 
00794     bool IsResizable()
00795     {
00796         return isResizable;
00797     }
00798 
00804     void SetResizeShow(bool v)
00805     {
00806         showResize = v;
00807     }
00808 
00814     void SetModalState(bool isModal);
00815 
00823     virtual bool OnGainFocus(bool /*notifyParent*/ = true)
00824     {
00825         hasFocus = true;
00826         if(hasFocus) return true;
00827         if(parent) parent->OnGainFocus();
00828         return true;
00829     }
00830 
00834     virtual void OnLostFocus()
00835     {
00836         if(!hasFocus) return;
00837         hasFocus = false;
00838         if(parent) parent->OnLostFocus();
00839     }
00840 
00844     virtual void OnResize();
00845 
00849     virtual void StopResize();
00850 
00859     virtual int GetBorderColour(int which);
00860 
00869     virtual void SetRelativeFrame(int x, int y, int width, int height);
00870 
00874     virtual void ResetToDefaultFrame()
00875     {
00876         screenFrame = defaultFrame;
00877     }
00878 
00886     virtual void SetRelativeFramePos(int x, int y);
00887 
00895     virtual void SetRelativeFrameSize(int width, int height);
00896 
00903     virtual void SetAttachFlags(int flags)
00904     {
00905         attachFlags = flags;
00906     }
00907 
00919     virtual bool OnMouseDown(int button, int modifiers, int x, int y);
00920 
00927     virtual bool OnMouseUp(int button, int modifiers, int x, int y);
00928 
00935     virtual bool OnDoubleClick(int button, int modifiers, int x, int y);
00936 
00937 
00944     virtual bool OnMouseEnter();
00945 
00951     virtual bool OnMouseExit();
00952 
00960     virtual bool OnChildMouseEnter(pawsWidget* child);
00961 
00969     virtual bool OnChildMouseExit(pawsWidget* child);
00970 
00981     virtual bool OnKeyDown(utf32_char keyCode, utf32_char keyChar, int modifiers);
00982 
00990     virtual bool OnJoypadDown(int key, int modifiers);
00991 
00998     virtual bool OnClipboard(const csString &content);
00999 
01005     virtual bool HasFocus()
01006     {
01007         return hasFocus;
01008     }
01009 
01015     virtual bool GetFocusOverridesControls() const
01016     {
01017         return false;
01018     }
01019 
01029     virtual void BringToTop(pawsWidget* widget);
01030 
01036     virtual void SendToBottom(pawsWidget* widget);
01037 
01041     const char* GetName()
01042     {
01043         return name;
01044     }
01045 
01049     void SetName(const char* newName)
01050     {
01051         name.Replace(newName);
01052         closeName = name;
01053         closeName.Append("_close");
01054     }
01055 
01059     const char* GetCloseName()
01060     {
01061         return closeName;
01062     }
01063 
01071     virtual void MoveDelta(int dx, int dy);
01072 
01079     virtual void MoveTo(int x, int y);
01080 
01087     virtual void CenterTo(int x, int y);
01088 
01092     virtual void CenterToMouse();
01093 
01100     virtual void Resize(int flags);
01101 
01110     virtual void Resize(int dx, int dy, int flags);
01111 
01120     virtual void SetSize(int newWidth, int newHeight);
01121 
01125     virtual void SetForceSize(int newWidth, int newHeight);
01126 
01132     virtual void UseBorder(const char* style = 0);
01133 
01137     virtual pawsBorder* GetBorder()
01138     {
01139         return border;
01140     }
01141 
01148     virtual int GetBorderStyle()
01149     {
01150         return BORDER_BUMP;
01151     }
01152 
01159     virtual void SetBackground(const char* imageName);
01160 
01166     csString GetBackground();
01167 
01175     virtual void SetBackgroundAlpha(int alphaValue);
01176 
01180     virtual void Resize();
01181 
01190     virtual bool OnButtonPressed(int button, int keyModifier, pawsWidget* widget)
01191     {
01192         if(parent)
01193             return parent->OnButtonPressed(button, keyModifier, widget);
01194 
01195         return true;
01196     }
01197 
01205     virtual bool OnButtonReleased(int button, int keyModifier, pawsWidget* widget)
01206     {
01207         if(parent)
01208             return parent->OnButtonReleased(button, keyModifier, widget);
01209         return false;
01210     }
01211 
01219     virtual bool OnScroll(int scrollDirection, pawsScrollBar* widget)
01220     {
01221         if(parent) return parent->OnScroll(scrollDirection, widget);
01222         return false;
01223     }
01224 
01231     virtual bool OnSelected(pawsWidget* widget);
01232 
01240     virtual bool OnMenuAction(pawsWidget* widget, const pawsMenuAction &action);
01241 
01248     virtual bool OnChange(pawsWidget* widget);
01249 
01255     void SetID(int newID)
01256     {
01257         id = newID;
01258     }
01259 
01265     int  GetID()
01266     {
01267         return id;
01268     }
01269 
01275     bool IsAlwaysOnTop()
01276     {
01277         return alwaysOnTop;
01278     }
01279 
01286     void SetAlwaysOnTop(bool value)
01287     {
01288         alwaysOnTop = value;
01289         if(parent)
01290             parent->BringToTop(this);
01291     }
01292 
01298     void SetMovable(bool value)
01299     {
01300         movable = value;
01301     }
01302 
01308     void SetToolTip(const char* text)
01309     {
01310         toolTip.Replace(text);
01311     }
01312 
01318     csString &GetToolTip()
01319     {
01320         return toolTip;
01321     }
01322 
01329     void FormatToolTip(const char* fmt, ...);
01330 
01334     void SetDefaultToolTip()
01335     {
01336         toolTip.Replace(defaultToolTip);
01337     }
01338 
01345     virtual void OnListAction(pawsListBox* selected, int status)
01346     {
01347         if(parent) parent->OnListAction(selected,status);
01348     }
01349 
01356     virtual void SavePosition();
01357 
01364     virtual csRect LoadPositions();
01365 
01371     void SetFactory(const char* myfactory)
01372     {
01373         factory = myfactory;
01374     }
01375 
01381     const char* GetType()
01382     {
01383         return factory;
01384     }
01385 
01390     int GetActualWidth(int myValue=-1)
01391     {
01392         if(myValue == -1)
01393             return screenFrame.Width();
01394 
01395         if(!resizeToScreen)
01396             return myValue;
01397 
01398         int desktop = graphics2D->GetWidth();
01399         if(myValue > 800)
01400             return desktop;
01401 
01402         float value = (float)myValue;
01403 
01404         float ret = (value * desktop) / 800.0f + 0.5f;
01405         return ((int)ret);
01406     }
01407 
01412     int GetActualHeight(int myValue=-1)
01413     {
01414         if(myValue == -1)
01415             return screenFrame.Height();
01416 
01417         if(!resizeToScreen)
01418             return myValue;
01419 
01420         int desktop = graphics2D->GetHeight();
01421         if(myValue > 600)
01422             return desktop;
01423 
01424         float value = (float)myValue;
01425 
01426         float ret = (value * desktop) / 600.0f + 0.5f;
01427         return ((int)ret);
01428     }
01429 
01430     int GetLogicalWidth(int myValue)
01431     {
01432         if(!resizeToScreen)
01433             return myValue;
01434 
01435         int desktop = graphics2D->GetWidth();
01436         myValue *= 800;
01437         myValue /= desktop;
01438         return myValue;
01439     }
01440 
01441     int GetLogicalHeight(int myValue)
01442     {
01443         if(!resizeToScreen)
01444             return myValue;
01445 
01446         int desktop = graphics2D->GetHeight();
01447         myValue *= 600;
01448         myValue /= desktop;
01449         return myValue;
01450     }
01451 
01459     virtual void MouseOver(bool value);
01460 
01466     void SetFade(bool value);
01467 
01473     void SetFontScaling(bool value);
01474 
01485     void DrawWidgetText(const char* text, int x, int y, int style=-1);
01486 
01497     csRect GetWidgetTextRect(const char* text, int x, int y, int style=-1);
01498 
01502     void SetMinSize(int width, int height)
01503     {
01504         min_width = width;
01505         min_height = height;
01506     }
01507 
01508     void GetMinSize(int &width, int &height)
01509     {
01510         width = min_width;
01511         height = min_height;
01512     }
01513 
01519     void SetMaxSize(int width, int height)
01520     {
01521         max_width = width;
01522         max_height = height;
01523     }
01524 
01525 
01529     void SetContextMenu(const csString &fileName)
01530     {
01531         contextMenuFile = fileName;
01532     }
01533 
01538     void MakeFullyVisible();
01539 
01544     void RecalcScreenPositions();
01545 
01553     void ClipToParent(bool allowForBackgroundBorder);
01554 
01560     csRect ClipRect()
01561     {
01562         return clipRect;
01563     }
01564 
01574     void SetColour(int newColour = -2);
01575 
01579     void SetFont(const char* fontName, int Size=0);
01580 
01586     void ChangeFontSize(float newSize);
01587 
01594     float GetFontSize();
01595 
01602     iFont* GetFont(bool scaled = true);
01603 
01611     virtual int GetFontColour();
01612 
01619     int    GetFontShadowColour();
01620 
01627     int    GetFontStyle();
01628 
01632     void   SetFontStyle(int style);
01633 
01641     virtual bool Contains(int x, int y);
01642 
01647     virtual void CreateWidgetConfigWindow();
01648 
01653     virtual void DestroyWidgetConfigWindow();
01654 
01658     int GetMinAlpha()
01659     {
01660         return alphaMin;
01661     };
01662 
01666     int GetMaxAlpha()
01667     {
01668         return alpha;
01669     };
01670 
01674     int GetFadeVal()
01675     {
01676         return (int)fadeVal;
01677     };
01678 
01682     void SetMinAlpha(int value)
01683     {
01684         alphaMin=value;
01685     };
01686 
01690     void SetMaxAlpha(int value)
01691     {
01692         alpha=value;
01693     };
01694 
01698     bool isFadeEnabled()
01699     {
01700         return fade;
01701     };
01702 
01706     float GetFadeSpeed()
01707     {
01708         return fadeSpeed;
01709     };
01710 
01714     void SetFadeSpeed(float speed)
01715     {
01716         fadeSpeed=speed;
01717     };
01718 
01722     bool isScalingFont()
01723     {
01724         return scaleFont;
01725     }
01726 
01730     void SetTitle(const char* title);
01731 
01735     virtual void SaveSettings();
01736 
01740     virtual void LoadSettings();
01741 
01749     virtual void DrawToolTip(int x, int y);
01750 
01756     virtual void Dump(csString tab = "");
01757 
01762     csString GetPathInWidgetTree();
01763 
01769     void SetMaskingImage(const char* image);
01770 
01774     void ClearMaskingImage();
01775 
01783     void SetBackgroundColor(int r,int g, int b);
01784 
01785     void ClearBackgroundColor()
01786     {
01787         bgColour = -1;
01788     }
01789 
01793     void SetFilename(const char* name);
01794 
01798     const char* GetFilename();
01799 
01803     void ReloadWidget();
01804 
01811     void SetExtraData(iWidgetData* data)
01812     {
01813         delete extraData;
01814         extraData = data;
01815     }
01816 
01822     iWidgetData* GetExtraData()
01823     {
01824         return extraData;
01825     }
01826 
01832     bool IsConfigurable()
01833     {
01834         return configurable;
01835     }
01836 
01837     virtual void OnUpdateData(const char* /*dataname*/, PAWSData & /*data*/) {}
01838     virtual void NewSubscription(const char* dataname)
01839     {
01840         subscribedVar = dataname;
01841     }
01842 
01854     bool SetTitle(const char* text, const char* image, const char* align, const char* close_button, const bool shadowTitle = true);
01855 
01856     void RemoveTitle();
01857 
01858     const char* FindDefaultWidgetStyle(const char* factoryName);
01859 
01864     void SetNeedsRender(bool needs)
01865     {
01866         if(parent)
01867             parent->SetNeedsRender(needs);
01868         else
01869             needsRender = needs;
01870     }
01871 
01875     bool NeedsRender() const
01876     {
01877         return needsRender;
01878     }
01879 
01880 protected:
01884     int ResizeFlags(int mouseX, int mouseY);
01885 
01889     bool CreateContextMenu();
01890 
01895     int CalcChildPosition(pawsWidget* child);
01896 
01900     void LoadBorderColours(iDocumentNode* node);
01901 
01905     void SetCloseButtonPos();
01906 
01910     int GetAttachFlag(const char* flag);
01911 
01912 public:
01916     void RunScriptEvent(PAWS_WIDGET_SCRIPT_EVENTS event);
01917 
01918     const char* ToString()
01919     {
01920         return name.GetDataSafe();
01921     }
01922     virtual double GetProperty(MathEnvironment* env, const char* ptr);
01923     virtual double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
01924     virtual void SetProperty(const char* ptr, double value);
01925 
01926     csArray<csString> publishList;
01927 };
01928 
01929 //----------------------------------------------------------------------------
01930 
01931 
01932 
01933 class pawsWidgetFactory
01934 {
01935 public:
01936     virtual ~pawsWidgetFactory() {};
01937 
01938     virtual pawsWidget* Create();
01939 
01940     virtual pawsWidget* Create(const pawsWidget* origin);
01941 
01942     virtual const char* GetName()
01943     {
01944         return factoryName;
01945     }
01946 
01947 protected:
01948     virtual void Register(const char* name);
01949 
01950 
01951     csString factoryName;
01952 };
01953 
01954 //---------------------------------------------------------------------------
01955 
01956 
01957 class pawsBaseWidgetFactory : public pawsWidgetFactory
01958 {
01959 public:
01960     pawsBaseWidgetFactory()
01961     {
01962         Register("pawsWidget");
01963     }
01964 
01965     pawsWidget* Create()
01966     {
01967         return new pawsWidget();
01968     }
01969 };
01970 
01971 
01972 #define CREATE_PAWS_FACTORY( factoryName ) \
01973 class factoryName##Factory : public pawsWidgetFactory \
01974 { \
01975 public: \
01976     factoryName##Factory( ) \
01977     { \
01978         Register( #factoryName ); \
01979     } \
01980  \
01981     pawsWidget* Create() \
01982     { \
01983         return new factoryName( ); \
01984     } \
01985     pawsWidget* Create(const pawsWidget* origin)\
01986     {\
01987         const factoryName * widget = dynamic_cast<const factoryName *>(origin);\
01988         if(widget)\
01989         {\
01990             return new factoryName(*widget);\
01991         }\
01992         return NULL;\
01993     }\
01994 }
01995 
01996 
01997 
01998 
02001 #endif
02002 
02003