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

DocScroller.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // DocScroller.h
00003 // Unlike ScrollWnd, that automatically scrolls a client window based
00004 // on its size and position, DocScroller does not reposition its client,
00005 // but scrolls the content of its client if it confirms to the
00006 // DocDimensions.h interface.
00007 //
00008 // Author: Richard van Balen
00009 #ifndef OglGui_DocScroller_h
00010 #define OglGui_DocScroller_h
00011 
00012 #ifndef OglGui_ScrollWnd_h
00013 #include "OglGui/ScrollWnd.h"
00014 #endif
00015 
00016 #ifndef OglGui_DocDimensions_h
00017 #include "OglGui/DocDimensions.h"
00018 #endif
00019 
00020 namespace OglGui
00021 {
00022 
00023 class DocScroller : public ScrollWnd
00024 {
00025 public:
00026     DocScroller(int x, int y, int w, int h,int sB=3+12) :
00027         ScrollWnd(x, y, w, h, true, (sB&1)?1:0, (sB&2)?1:0)
00028     {
00029         Init(sB);
00030     }
00031 
00032     DocScroller(Window* parent, int w, int h, int sB=3+12) :
00033         ScrollWnd(parent, w, h, true, (sB&1)?1:0, (sB&2)?1:0)
00034     {
00035         Init(sB);
00036     }
00037 
00038     DocScroller(Window* parent,int x,int y,int w,int h,int sB=3+12):
00039         ScrollWnd(parent, x, y, w, h, true, (sB&1)?1:0, (sB&2)?1:0)
00040     {
00041         Init(sB);
00042     }
00043 
00044     void SetDoc(DocDimensions* doc)
00045     {
00046         mDoc = doc;
00047     }
00048 
00049     void SetPageDeltas(int hor, int ver)
00050     {
00051         if (hor != RETAIN)
00052             mHorPageDelta = hor;
00053         if (ver != RETAIN)
00054             mVerPageDelta = ver;
00055     }
00056 
00057     void GetPageDeltas(int& hor, int& ver)
00058     {
00059         hor = mHorPageDelta;
00060         ver = mVerPageDelta;
00061     }
00062 
00063     virtual void SetContentPane(Window *nwPane, bool delOldContent=true,
00064                                 bool doLayout=true)
00065     {
00066         ScrollWnd::SetContentPane(nwPane,delOldContent,doLayout);
00067         if (doLayout)
00068             mContent->ConnectTo(mHolder);
00069     }
00070 
00071     virtual void OnScroll(ScrollBar *src, int position, void* userData)
00072     {
00073         if (mAdjusting) return;
00074         if (src == mHorizontalScrollBar)
00075             mDoc->DocX(-position);
00076         if (src == mVerticalScrollBar)
00077         {
00078             int nPos = -mDoc->DocH() + mHolder->H() + position;
00079             mDoc->DocY(nPos);
00080         }
00081     }
00082 /*
00083 virtual void DisplayFunc()
00084 {
00085     int     docX, docY, docW, docH;
00086     int     hX, hY, hW, hH;
00087     int     totalRange;
00088 
00089     mDoc->GetDocDimensions(docX, docY, docW, docH);
00090     mHolder->GetDimensions(hX, hY, hW, hH);
00091 
00092     if (mHorizontalScrollBar){
00093         int lineIncr = mHorizontalScrollBar->LineIncrement();
00094         totalRange = docW - ((mPartial&1) ? hW-2*lineIncr : 0);
00095         mHorizontalScrollBar->SetNewPos(-docX);
00096         mHorizontalScrollBar->SetRange(totalRange, hW - lineIncr);
00097     }
00098     if (mVerticalScrollBar){
00099         int nPos = docH - hH + docY;
00100         int lineIncr = mVerticalScrollBar->LineIncrement();
00101         totalRange = docH + ((mPartial&2) ? hH-2*lineIncr: 0);
00102         mVerticalScrollBar->SetNewPos(nPos);
00103         mVerticalScrollBar->SetRange(totalRange, hH - lineIncr);
00104     }
00105 
00106     mDoc->SetDocDimensions(docX, docY, docW, docH);
00107     Window::DisplayFunc();
00108 }
00109 */
00110 
00111     virtual void FollowContent()
00112     {
00113         int     docX, docY, docW, docH;
00114         int     hX, hY, hW, hH;
00115         int     totalRange;
00116 
00117         mDoc->GetDocDimensions(docX, docY, docW, docH);
00118         mHolder->GetDimensions(hX, hY, hW, hH);
00119 
00120         if (mHorizontalScrollBar){
00121             int lineIncr = mHorizontalScrollBar->LineIncrement();
00122             totalRange = docW - ((mPartial&1) ? hW-2*lineIncr : 0);
00123             mHorizontalScrollBar->SetRange(totalRange, hW - mHorPageDelta);
00124             mHorizontalScrollBar->SetNewPos(-docX);
00125         }
00126         if (mVerticalScrollBar){
00127             int nPos = docH - hH + docY;
00128             int lineIncr = mVerticalScrollBar->LineIncrement();
00129             totalRange = docH + ((mPartial&2) ? hH-2*lineIncr: 0);
00130             mVerticalScrollBar->SetRange(totalRange, hH - mVerPageDelta);
00131             mVerticalScrollBar->SetNewPos(nPos);
00132         }
00133     }
00134 
00135     virtual void FollowScrollBar()
00136     {
00137         if (!mDoc) return;
00138 
00139         int     cX, cY, cW, cH;
00140         int     hX, hY, hW, hH;
00141         mDoc->GetDocDimensions(cX, cY, cW, cH);
00142         mHolder->GetDimensions(hX, hY, hW, hH);
00143 
00144         if (mHorizontalScrollBar)
00145         {
00146             mHorizontalScrollBar->SetRange(cW, hW - mHorPageDelta);
00147             cX = -mHorizontalScrollBar->GetValue();
00148         }
00149         if (mVerticalScrollBar)
00150         {
00151             mVerticalScrollBar->SetRange(cH, hH - mVerPageDelta);
00152             cY = mVerticalScrollBar->GetValue() + hH - cH;
00153         }
00154         else
00155             cY = hH - cH;
00156         mDoc->DocX(cX);
00157         mDoc->DocY(cY);
00158     }
00159 
00160     // RvB: Could be moved to ScrollBar to also have partial page_up/down there
00161     // Its FollowContent would also have to be changed
00162     void SetPartialPageUpDown(bool horizontal, bool vertical)
00163     {
00164         mPartial = 0;
00165         if (horizontal)
00166             mPartial |= 1;
00167         if (vertical)
00168             mPartial |= 2;
00169     }
00170 
00171 protected:
00172     DocDimensions*  mDoc;       // The interface we work upon
00173     int             mPartial;   // On pagedown scroll somewhat less than page
00174     int             mVerPageDelta;
00175     int             mHorPageDelta;
00176 
00177 private:
00178     void Init(int sB)
00179     {
00180         mDoc = 0;
00181         mPartial = (sB & 12) >> 2;
00182         mVerPageDelta = 16;
00183         mHorPageDelta = 16;
00184     }
00185 
00186 };
00187 
00188 } // Namespace OglGui
00189 #endif
00190 

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