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

ScrollWnd.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 #ifndef OglGui_ScrollWnd_h
00003 #define OglGui_ScrollWnd_h
00004 
00005 #ifndef OglGui_WindowScrollBar_h
00006 #include "OglGui/WindowScrollBar.h"
00007 #endif
00008 
00009 namespace OglGui
00010 {
00011 
00012 // RvB: Nog naar kijken vanwege onduidelijke default waardes
00013 class ScrollWnd : public Window, ScrollBarListener
00014 {
00015 public:
00016 
00017     // NOTE: For vert and hor: 0: no scrollbar, 1:normal side, -1:other side
00018     ScrollWnd(int x, int y, int w, int h, bool is2D=true,
00019               int hor=1, int vert=1, int sbW=16) :
00020         Window(x, y, w, h)
00021     {
00022         Init(hor, vert, is2D, sbW);
00023     }
00024 
00025     ScrollWnd(Window *parent, int w, int h, bool is2D=true,
00026               int hor=1, int vert=1, int sbW=16) :
00027         Window(parent, w, h)
00028     {
00029         Init(hor, vert, is2D, sbW);
00030     }
00031 
00032     ScrollWnd(Window *parent, int x, int y, int w, int h, bool is2D=true,
00033                  int hor=1, int vert=1, int sbW=16) :
00034         Window(parent, x, y, w, h)
00035     {
00036         Init(hor, vert, is2D, sbW);
00037     }
00038 
00039     // RvB: NOTE; We could support reparenting of existing
00040     // OGLWND's. Simply remove the link to it from it's parent wndList
00041     // and adding a new link to it in the new parent window and setting
00042     // the parent members
00043     // Still need to think about it. Can not be made generally safe
00044     // as the old parent object might have other references to it.
00045 
00046     // ReplaceContentPane support for items that want to create their own
00047     // content window rather than using an existing one.
00048 
00049     // RvB: Maybe change it to the way TitledWnd handles creating a content
00050     // And renaming it into SetContentPane(Window* content, delOldContent=true)
00051     bool ReplaceContentPane(Window *contentPane)
00052     {
00053         if (!contentPane)
00054             return false;
00055 
00056         if (mContent)
00057             delete mContent;
00058         mContent = contentPane;
00059         return true;
00060     }
00061     virtual void SetContentPane(Window *nwPane, bool delOldContent=true,
00062                                 bool doLayout=true)
00063     {
00064         if (delOldContent && mContent){
00065             delete mContent;
00066             mContent = 0;
00067         }
00068         if ((mContent = nwPane) && doLayout){
00069             int clW, clH;
00070 
00071             mContent->SetBorderType(BEV_NONE);
00072             mHolder->GetDimensions(clW, clH);
00073             mContent->SetDimensions(0, 0, clW, clH);
00074             mContent->SetAllowReposition(false);
00075         }
00076     }
00077 
00078 
00079     void DisplayFollowMode(int mode)    { mDisplayFollowMode = mode; }
00080     void ReshapeFollowMode(int mode)    { mReshapeFollowMode = mode; }
00081 
00082     Window*     ContentPane()           { return mContent; }
00083     Window*     ContentHolder()         { return mHolder; }
00084     ScrollBar*  HorizontalScrollBar()   { return mHorizontalScrollBar; }
00085     ScrollBar*  VerticalScrollBar()     { return mVerticalScrollBar; }
00086 
00087     virtual void OnScroll(ScrollBar *src, int position, void* userData)
00088     {
00089         if (mAdjusting) return;
00090 
00091         int     cX, cY, cW, cH;
00092         mContent->GetDimensions(cX, cY, cW, cH);
00093         if (src == mHorizontalScrollBar)
00094             cX = -position;
00095         if (src == mVerticalScrollBar)
00096             cY = position + mHolder->H() - cH;
00097         mContent->SetDimensions(cX, cY, cW, cH);
00098     }
00099 
00100     virtual void ReshapeFunc(int w, int h)
00101     {
00102         Window::ReshapeFunc(w,h);
00103         if (mReshapeFollowMode==1)
00104             FollowContent();
00105         else if (mReshapeFollowMode==2)
00106             FollowScrollBar();
00107     }
00108 
00109     virtual void DisplayFunc()
00110     {
00111         mAdjusting = true;
00112         if (mDisplayFollowMode==1 && mInitialized)
00113             FollowContent();
00114         else if (mDisplayFollowMode!=0)
00115             FollowScrollBar();
00116         mAdjusting = false;
00117         mInitialized = true;
00118         Window::DisplayFunc();
00119     }
00120 
00121 
00122     virtual void FollowContent()
00123     {
00124         int     cX, cY, cW, cH;
00125         int     hX, hY, hW, hH;
00126 
00127         mContent->GetDimensions(cX, cY, cW, cH);
00128         mHolder->GetDimensions(hX, hY, hW, hH);
00129 
00130         if (mHorizontalScrollBar)
00131         {
00132             mHorizontalScrollBar->SetRange(cW, hW);
00133             mHorizontalScrollBar->SetNewPos(-cX);
00134         }
00135         if (mVerticalScrollBar)
00136         {
00137             int nPos = cH - hH + cY;
00138             mVerticalScrollBar->SetRange(cH, hH);
00139             mVerticalScrollBar->SetNewPos(nPos);
00140         }
00141     }
00142 
00143     virtual void FollowScrollBar()
00144     {
00145         int     cX, cY, cW, cH;
00146         int     hX, hY, hW, hH;
00147 
00148         mContent->GetDimensions(cX, cY, cW, cH);
00149         mHolder->GetDimensions(hX, hY, hW, hH);
00150 
00151         if (mHorizontalScrollBar)
00152         {
00153             mHorizontalScrollBar->SetRange(cW, hW);
00154             cX = -mHorizontalScrollBar->GetValue();
00155         }
00156         if (mVerticalScrollBar)
00157         {
00158             mVerticalScrollBar->SetRange(cH, hH);
00159             cY = mVerticalScrollBar->GetValue() + hH - cH;
00160         }
00161         else
00162             cY = hH - cH;
00163         mContent->SetDimensions(cX, cY, cW, cH);
00164     }
00165 
00166 protected:
00167 
00168     WindowScrollBar *mHorizontalScrollBar, *mVerticalScrollBar;
00169     Window          *mHolder;
00170     Window          *mContent;
00171     bool            mInitialized;
00172     bool            mAdjusting;
00173     int             mDisplayFollowMode;
00174     int             mReshapeFollowMode;
00175 
00176     void
00177     Init(int hor, int vert, bool is2D, int sbW)
00178     {
00179         int     holdW = mOglWnd->width - 2 - ((vert!=0) ? sbW : 0);
00180         int     holdH = mOglWnd->height - 2 - ((hor!=0) ? sbW : 0);
00181 
00182         mInitialized = false;
00183         mAdjusting = false;
00184         mDisplayFollowMode = 1;
00185         mReshapeFollowMode = 2;
00186         mHorizontalScrollBar = 0;
00187         mVerticalScrollBar = 0;
00188 
00189         SetBorderType(BEV_ETCHED);
00190 
00191         if (hor != 0){
00192             mHorizontalScrollBar =
00193                 new WindowScrollBar(this, true, hor==1, sbW,
00194                                     (vert==0)?0:(vert==1)?sbW:-sbW);
00195             mHorizontalScrollBar->SetScrollBarListener(this, (void*)1);
00196             mHorizontalScrollBar->SetLineIncrement(16);
00197         }
00198         if (vert != 0){
00199             mVerticalScrollBar =
00200                 new WindowScrollBar(this, false, vert==1, sbW,
00201                                     (hor==0)?0:(hor==1)?sbW:-sbW);
00202             mVerticalScrollBar->SetScrollBarListener(this, (void*)1);
00203             mVerticalScrollBar->SetLineIncrement(16);
00204         }
00205 
00206         mHolder = new Window(this, 2 + ((vert==-1)?sbW:0), ((hor==1)?sbW:0),
00207                              holdW, holdH);
00208         mHolder->SetAllowScaling(false);
00209         mHolder->ConnectTo(this, ALLSIDES|TPARENT);
00210         mContent = new Window(mHolder, 0, 0, holdW, holdH, is2D);
00211     }
00212 };
00213 
00214 } // namespace OglGui
00215 
00216 #endif

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