Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

TitledWindow.h

Go to the documentation of this file.
00001 #ifndef OglGui_TitledWindow_h
00002 #define OglGui_TitledWindow_h
00003 
00004 #ifndef OglGui_SizableWindow_h
00005 #include "OglGui/SizableWindow.h"
00006 #endif
00007 
00008 #ifndef OglGui_StaticText_h
00009 #include "OglGui/StaticText.h"
00010 #endif
00011 
00012 #ifndef OglGui_Button_h
00013 #include "OglGui/Button.h"
00014 #endif
00015 
00016 #ifndef OglGui_CloseWindowListener_h
00017 #include "OglGui/CloseWindowListener.h"
00018 #endif
00019 
00020 // RvB: There should be a possibility to react on close,
00021 // allowing to cancel it.
00022 // Maybe later indicate autoClosing of CloseListener: AutoClose=32 oid
00023 // For now as test automatically delete on close
00024 
00025 namespace OglGui
00026 {
00027 
00028 //class TitledWindow : public SizableWindow, public ButtonListener
00029 class TitledWindow : public SizableWindow
00030 {
00031 public:
00032 
00033     TitledWindow(Window *parent, int x, int y, int w, int h, strconst title,
00034                  int extInfo=0, bool is2D=true) :
00035         SizableWindow(parent, x, y, w, h, is2D)
00036     {
00037         Init(title, extInfo, is2D);
00038     }
00039 
00040     TitledWindow(Window *parent, int w, int h, strconst title,
00041                  int extInfo=0, bool is2D=true) :
00042         SizableWindow(parent, w, h, is2D)
00043     {
00044         Init(title, extInfo, is2D);
00045     }
00046 
00047     enum TWInfo {
00048         BtnClose = 1,
00049         BtnMax = 2,
00050         BtnMaxClose = 3,
00051         BtnMin = 4,
00052         BtnMinClose = 5,
00053         BtnMinMax = 6,
00054         BtnMinMaxClose = 7,
00055         BtnRounded = 8,
00056         TitleRounded = 16,
00057         NoContent = 32
00058     };
00059 
00060     void SetCloseWindowListener(CloseWindowListener* l, void* userData)
00061     {
00062         mCloseWindowListener = l;
00063         mCloseWindowUserData = userData;
00064     }
00065 
00066     void GetClientArea(int& x, int& y, int& w, int& h)
00067     {
00068         x = 4;
00069         y = 4;
00070         w = WndWidth() - 8;
00071         h = WndHeight() - mTitleHeight - 8;
00072     }
00073 
00074     virtual void SetBorderType(int type)
00075     {
00076         SizableWindow::SetBorderType(type);
00077         SetHighLightBorderType(type);
00078     }
00079 
00080     void SetButtonRoundness(int r0, int r1, int r2, int r3)
00081     {
00082         mCloseButton->SetRoundness(r0, r1, r2, r3);
00083         mMaximizeButton->SetRoundness(r0, r1, r2, r3);
00084         mMinimizeButton->SetRoundness(r0, r1, r2, r3);
00085     }
00086 
00087     void SetButtonBorderType(int type)
00088     {
00089         mCloseButton->SetUpBorderType(type);
00090         mMaximizeButton->SetUpBorderType(type);
00091         mMinimizeButton->SetUpBorderType(type);
00092     }
00093 
00094     void SetContentPane(Window *nwPane, bool delOldContent=true,
00095                         bool doLayoutAndConnect=true)
00096     {
00097         if (delOldContent && mContent){
00098             delete mContent;
00099             mContent = 0;
00100         }
00101         if ((mContent = nwPane) && doLayoutAndConnect){
00102             int clX, clY, clW, clH;
00103 
00104             GetClientArea(clX, clY, clW, clH);
00105             mContent->SetDimensions(clX, clY, clW, clH);
00106             mContent->ConnectTo(this, ALLSIDES);
00107             mContent->SetAllowReposition(false);
00108         }
00109     }
00110 
00111     virtual void MouseFunc(int msg, int but, int state, int x, int y)
00112     {
00113         SizableWindow::MouseFunc(msg, but, state, x, y);
00114 
00115         if (but == oglLeftButton && msg == oglMouseDblClick)
00116             if (y > mOglWnd->height - mTitleHeight - 8)
00117                 mMaximizeButton->DoButtonSelectionEvent();
00118     }
00119 
00120     // Get reference to components
00121     Window* ContentPane()
00122     {
00123         return mContent;
00124     } 
00125 
00126     Button* CloseButton()
00127     {
00128         return mCloseButton;
00129     }
00130 
00131     Button* MaximizeButton()
00132     {
00133         return mMaximizeButton;
00134     }
00135 
00136     Button* MinimizeButton()
00137     {
00138         return mMinimizeButton;
00139     }
00140 
00141     StaticText* TitleText()
00142     {
00143         return mTitleText;
00144     }
00145 
00146     virtual void OnCloseButton()
00147     {
00148         if (mCloseWindowListener)
00149             if (!mCloseWindowListener->OnCloseWindow(this,mCloseWindowUserData))
00150                 return;
00151         if (mMaxConnection)
00152             mMaximizeButton->DoButtonSelectionEvent();
00153         delete this;
00154     }
00155 
00156     virtual void OnMaximizeButton()
00157     {
00158         int pX, pY, pW, pH;
00159         this->GetParent()->GetDimensions(pX,pY,pW,pH);
00160         if (mMaxConnection != 0)
00161         {                
00162             delete mMaxConnection;
00163             mMaxConnection = 0;
00164 
00165             SetAllowMove(mOldAllowMove);
00166             SetDimensions(mOldX, mOldY, mOldW, mOldH);
00167             this->GetParent()->OnLayoutChange();
00168         }
00169         else 
00170         {
00171             mOldAllowMove = GetAllowMove();
00172             SetAllowMove(false);
00173             GetDimensions(mOldX, mOldY, mOldW, mOldH);
00174             SetDimensions(0, 0, pW, pH);
00175             mMaxConnection = ConnectTo(this->GetParent(), ALLSIDES | TPARENT);
00176         }
00177         mMaximizeButton->SetText(mMaxConnection ? "[]]" : "[]");
00178         HandleTargetVisibility(mOglWnd->parent, mOglWnd, true, !mMaxConnection);            
00179         this->GetParent()->RepositionViewports();
00180     }
00181 
00182     virtual void OnMinimizeButton()
00183     {
00184     }
00185 
00186     class TitleBarButtonListener : public ButtonListener
00187     {
00188     public:
00189         virtual void ButtonSelectionEvent(Button* btn, void* lData)
00190         {
00191             TitledWindow* tWnd = (TitledWindow*)lData;
00192             if (btn == tWnd->MaximizeButton())
00193                 tWnd->OnMaximizeButton();
00194             if (btn == tWnd->CloseButton())
00195                 tWnd->OnCloseButton();
00196         }
00197     };
00198     /*
00199     virtual void ButtonSelectionEvent(Button* btn, int lData)
00200     {
00201         if (btn == mMaximizeButton)
00202             OnMaximizeButton();
00203 
00204         // RvB: For test purposes, autoClosing.
00205         // Later CloseListener and/or (virtual bool OnClosing)
00206         if (btn == mCloseButton)
00207             OnCloseButton();
00208     }
00209     */
00210 
00211 
00212 private:
00213 
00214     void
00215     Init(strconst title, int extInfo, bool is2D)
00216     {
00217         mCloseWindowListener = 0;
00218         mTitleHeight = 24;
00219         mMaxConnection = 0;
00220         mContent = mTitleText = mMaximizeButton = mMinimizeButton = 0;
00221         mOldX = mOldY = mOldW = mOldH = 0;
00222         mMaximized = false;
00223 
00224         SetAllowChildScaling(false);
00225         SetBorderType(BEV_LINE);
00226         SetRoundness(10, 10, 0, 0);
00227         SetMinMaxSizes(120, RETAIN, mTitleHeight + 8, RETAIN);
00228 
00229         if (!(extInfo & NoContent))
00230             SetContentPane(new Window(this, 0, 0, 10, 10, is2D));
00231 
00232         CreateTitleBar(title, extInfo);
00233     }
00234 
00235     void
00236     CreateTitleBar(strconst title, int extInfo)
00237     {
00238         int     tH = mTitleHeight;
00239         int     w = WndWidth(), h = WndHeight();
00240         int     btnR = (extInfo & BtnRounded) ? 10 : 0;
00241         int     btnX = w - tH - 4, btnY = h - tH - 2;
00242         int     btnSz = tH - 4;
00243 
00244         mTitleBarButtonListener = new TitleBarButtonListener();
00245 
00246         mTitleText = new StaticText(this, 4, h-tH-4, w-8, tH, title, false);
00247         if (extInfo & TitleRounded)
00248         {
00249             mTitleText->SetRoundness(8, 8, 0, 0);
00250             if (!btnR)
00251                 btnX -= 3;
00252         }
00253 
00254         mTitleText->SetBorderFillShaded(2);
00255         mTitleText->SetAlignOffsets(6, 0);
00256         mTitleText->SetForeground(oglWHITE);
00257         mTitleText->SetBorderType(-1);
00258         mTitleText->SetBorderBackground(0x806060a0);
00259         //mTitleText->SetBorderBackground(0xff4040ff);
00260         mTitleText->SetNoMouseInput(true);
00261         mTitleText->ConnectTo(this, L2L | R2R | T2T | B2T | TPARENT);
00262 
00263         mCloseButton =
00264             TitleBarButton(btnX, btnY, btnSz, !(extInfo & BtnClose), btnR, "X");
00265         mCloseButton->SetStateFeedbackColor(0xffff8080);
00266         mCloseButton->SetUpBorderType(BEV_RAISED);
00267         mCloseButton->SetBorderBackground(0xffd04040);
00268         btnX -= btnSz + 2;
00269 
00270         mMaximizeButton =
00271             TitleBarButton(btnX, btnY, btnSz, !(extInfo & BtnMax), btnR, "[]");
00272         mMaximizeButton->SetAlignOffsets(0, 1);
00273         mMaximizeButton->SetVisible((extInfo & BtnMax)?true:false);
00274         btnX -= btnSz + 2;
00275 
00276         mMinimizeButton =
00277             TitleBarButton(btnX, btnY, btnSz, !(extInfo & BtnMin), btnR, "_");
00278         mMinimizeButton->SetAlignOffsets(0, 1);
00279         mMinimizeButton->SetVisible((extInfo & BtnMin)?true:false);
00280     }
00281 
00282     Button*
00283     TitleBarButton(int x, int y, int btnSz, bool disabled, int btnR, char *str)
00284     {
00285         Button*   btn = new Button(this, x, y, btnSz, btnSz, str);
00286 
00287         btn->ConnectTo(this, L2R | R2R | B2T | T2T | TPARENT);
00288         btn->SetRoundness(btnR, btnR, btnR, btnR );
00289         btn->SetUpBorderType(BEV_RAISED);
00290         //btn->SetButtonListener(this);
00291         btn->SetButtonListener(mTitleBarButtonListener, (void*) this);
00292 
00293         if (!disabled)
00294         {
00295             btn->SetForeground(oglWHITE);
00296             btn->SetShadowColor(oglDARKGREY);
00297         }
00298         else
00299             btn->SetState(0);
00300         return btn;
00301     }
00302 
00303     void
00304     HandleTargetVisibility(OGLWND *parent, OGLWND *targetWnd,
00305                            bool targetMode, bool otherMode)
00306     {
00307         OGLWND  *oglWnd;
00308         LIST    *obj;
00309 
00310         ForAllElements(obj, parent->wndList)
00311         {
00312             oglWnd = (OGLWND *) obj->info;
00313             SetTagsTo((TAGABLE *) oglWnd, visibleTag,
00314                       oglWnd==targetWnd ? targetMode : otherMode);
00315         }
00316     }
00317 
00318     TitleBarButtonListener* mTitleBarButtonListener;
00319 
00320     CloseWindowListener*    mCloseWindowListener;
00321     void*                   mCloseWindowUserData;
00322 
00323     Window*           mContent;
00324     StaticText*       mTitleText;
00325     Button*           mCloseButton;
00326     Button*           mMaximizeButton;
00327     Button*           mMinimizeButton;
00328     LayoutListener*   mMaxConnection;
00329     bool              mMaximized;
00330     bool              mOldAllowMove;
00331     int               mTitleHeight;
00332     int               mOldX, mOldY, mOldW, mOldH;
00333 
00334 };
00335 
00336 } // namespace OglGui
00337 
00338 #endif

Generated on Fri Mar 19 09:31:39 2010 for ImpalaSrc by  doxygen 1.5.1