]>
git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/tabpgwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by: 19990908 : mj10777@gmx.net
6 // - rename to tabpgwin
7 // - restruction of Variable declaration
8 // - to prevent Warnings under MingW32
9 // Modified by: 19990909 : mj10777@gmx.net
10 // - mNoVertScroll TRUE = no / FALSE = Original Code
11 // the Original Code Paints a Vertical Scroll in wxPagedWindow
12 // which is not needed in this Version. Use TRUE for this.
15 // Copyright: (c) Aleksandras Gluchovas
16 // Licence: wxWindows license
17 /////////////////////////////////////////////////////////////////////////////
20 #pragma implementation
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
38 #include "wx/string.h"
39 #include "wx/utils.h" // import wxMin/wxMax macros and wxFileExist(..)
43 //---------------------------------------------------------------------------
44 // Implementation for class twTabInfo
45 //---------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS( twTabInfo
, wxObject
)
48 //---------------------------------------------------------------------------
49 twTabInfo::twTabInfo()
53 //---------------------------------------------------------------------------
54 twTabInfo::~twTabInfo()
59 //---------------------------------------------------------------------------
60 int twTabInfo::ImgWidth()
62 if ( mBitMap
.Ok() ) return mBitMap
.GetWidth();
66 //---------------------------------------------------------------------------
67 int twTabInfo::ImgHeight()
70 return mBitMap
.GetHeight();
75 //---------------------------------------------------------------------------
76 int twTabInfo::ImageToTxtGap( int prefGap
)
84 //---------------------------------------------------------------------------
85 bool twTabInfo::HasImg()
90 //---------------------------------------------------------------------------
91 // bool twTabInfo::HasText();
92 unsigned int twTabInfo::HasText()
94 return mText
.Length();
97 //---------------------------------------------------------------------------
98 wxBitmap
& twTabInfo::GetImg()
103 //---------------------------------------------------------------------------
104 wxString
& twTabInfo::GetText()
109 //---------------------------------------------------------------------------
110 wxWindow
& twTabInfo::GetContent()
115 //---------------------------------------------------------------------------
116 // Implementation for class wxTabbedWindow
117 //---------------------------------------------------------------------------
118 IMPLEMENT_DYNAMIC_CLASS( wxTabbedWindow
, wxPanel
)
120 //---------------------------------------------------------------------------
121 BEGIN_EVENT_TABLE( wxTabbedWindow
, wxPanel
)
122 EVT_SIZE ( wxTabbedWindow::OnSize
)
123 EVT_PAINT( wxTabbedWindow::OnPaint
)
124 EVT_LEFT_DOWN( wxTabbedWindow::OnLButtonDown
)
125 // TDB:: filciker reduction
126 // EVT_ERASE_BACKGROUND( wxTabbedWindow::OnBkErase )
129 //---------------------------------------------------------------------------
130 wxTabbedWindow::wxTabbedWindow()
132 : mpTabScroll ( NULL
),
133 mpHorizScroll( NULL
),
134 mpVertScroll ( NULL
),
142 mFirstTitleGap( 11 ),
144 mBorderOnlyWidth( 8 ),
146 mWhitePen( wxColour(255,255,255), 1, wxSOLID
),
147 mGrayPen ( wxColour(192,192,192), 1, wxSOLID
),
148 mDarkPen ( wxColour(128,128,128), 1, wxSOLID
),
149 mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID
),
154 mLayoutType( wxTITLE_IMG_AND_TEXT
)
157 //---------------------------------------------------------------------------
158 wxTabbedWindow::~wxTabbedWindow()
160 wxNode
* pTab
= mTabs
.First();
164 delete ((twTabInfo
*)pTab
->Data());
169 //---------------------------------------------------------------------------
170 void wxTabbedWindow::SizeTabs(int x
,int y
, int width
, int height
, bool repant
)
172 wxNode
* pTabNode
= mTabs
.First();
177 twTabInfo
& info
= *((twTabInfo
*)pTabNode
->Data());
179 if ( n
== mActiveTab
)
182 //info.mpContent->GetEventHandler()->ProcessEvent( evt );
184 info
.mpContent
->SetSize( x
, y
, width
, height
, 0 );
185 info
.mpContent
->Show(TRUE
);
186 info
.mpContent
->Refresh();
191 info
.mpContent
->Show(FALSE
);
194 pTabNode
= pTabNode
->Next();
199 //---------------------------------------------------------------------------
200 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
202 wxString imageFileName
,
205 twTabInfo
* pTab
= new twTabInfo();
207 pTab
->mpContent
= pContent
;
208 pTab
->mText
= tabText
;
210 if ( wxFileExists( imageFileName
) &&
212 pTab
->mBitMap
.LoadFile( imageFileName
, imageType
) )
214 pTab
->mImageFile
= imageFileName
;
215 pTab
->mImageType
= imageType
;
219 if ( pContent
->GetParent() == NULL
)
220 pContent
->Create( this, -1 );
222 mTabs
.Append( (wxObject
*)pTab
);
229 //---------------------------------------------------------------------------
230 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
231 wxString tabText
, wxBitmap
* pImage
)
233 twTabInfo
* pTab
= new twTabInfo();
235 pTab
->mpContent
= pContent
;
236 pTab
->mText
= tabText
;
239 pTab
->mBitMap
= *pImage
;
241 if ( pContent
->GetParent() == NULL
)
242 pContent
->Create( this, -1 );
244 mTabs
.Append( (wxObject
*)pTab
);
249 //---------------------------------------------------------------------------
250 void wxTabbedWindow::RemoveTab( int tabNo
)
252 twTabInfo
* pTab
= ((twTabInfo
*)(mTabs
.Nth( tabNo
)->Data()));
253 pTab
->mpContent
->Destroy();
255 mTabs
.DeleteNode( mTabs
.Nth( tabNo
) );
256 // if ( mActiveTab >= mTabs.Number() );
257 if ( mActiveTab
>= mTabs
.Number() )
258 mActiveTab
= mTabs
.Number() - 1;
259 SetActiveTab( mActiveTab
);
262 //---------------------------------------------------------------------------
263 int wxTabbedWindow::GetTabCount()
265 return mTabs
.Number();
268 //---------------------------------------------------------------------------
269 wxWindow
* wxTabbedWindow::GetTab( int tabNo
)
271 return ((twTabInfo
*)(mTabs
.Nth( tabNo
)->Data()))->mpContent
;
274 //---------------------------------------------------------------------------
275 wxWindow
* wxTabbedWindow::GetActiveTab()
277 // FIMXE:: this is lame
278 return GetTab( mActiveTab
);
281 //---------------------------------------------------------------------------
282 void wxTabbedWindow::SetActiveTab( int tabNo
)
289 //---------------------------------------------------------------------------
290 // width of the decorations border (4 shade-lines), should not be changed
291 //---------------------------------------------------------------------------
294 //---------------------------------------------------------------------------
295 void wxTabbedWindow::DrawShadedRect( int x
, int y
, int width
, int height
,
296 wxPen
& upperPen
, wxPen
& lowerPen
, wxDC
& dc
299 // darw the lightened upper-left sides of the rectangle
301 dc
.SetPen( upperPen
);
302 dc
.DrawLine( x
,y
, x
, y
+ height
- 1 ); // vert
303 dc
.DrawLine( x
,y
, x
+ width
- 1, y
); // horiz
305 // draw the unenlightened lower-right sides of the rectangle
307 dc
.SetPen( lowerPen
);
308 dc
.DrawLine( x
+ width
- 1, y
, x
+ width
- 1, y
+ height
- 1 ); // vert
309 dc
.DrawLine( x
, y
+ height
- 1, x
+ width
, y
+ height
- 1 ); // horiz
312 //---------------------------------------------------------------------------
313 void wxTabbedWindow::DrawDecorations( wxDC
& dc
)
315 // Protability NOTE::: DrawLine(..) draws a line from the first position,
316 // but not including the point specified by last position.
317 // This way Windows draws lines, not sure how Motif and Gtk
321 GetClientSize( &width
, &height
);
323 // check if there's at least a bit of space to draw things
325 if ( width
< mHorizGap
*2 + BORDER_SZ
*2+1 ||
326 height
< mVertGap
*2 + BORDER_SZ
*2+1 + mTitleHeight
330 // step #1 - draw border around the tab content area
332 // setup position for kind of "pencil"
333 int curX
= mHorizGap
;
336 int xSize
= width
- mHorizGap
*2;
337 int ySize
= height
- mVertGap
*2 - mTitleHeight
;
339 // layer 1 (upper white)
340 DrawShadedRect( curX
+0, curY
+0, xSize
-0, ySize
-0,
341 mWhitePen
, mBlackPen
, dc
);
343 // layer 2 (upper gray)
344 DrawShadedRect( curX
+1, curY
+1, xSize
-2-1, ySize
-2-1,
345 mGrayPen
, mGrayPen
, dc
);
347 // layer 3 (upper darkGray)
348 DrawShadedRect( curX
+2, curY
+2, xSize
-3-2, ySize
-3-2,
349 mDarkPen
, mWhitePen
, dc
);
351 // layer 4 (upper black)
352 DrawShadedRect( curX
+3, curY
+3, xSize
-4-3, ySize
-4-3,
353 mBlackPen
, mGrayPen
, dc
);
355 // add non-siemtric layer from the lower-right side (confroming to MFC-look)
357 dc
.SetPen( mDarkPen
);
358 dc
.DrawLine( curX
+1, curY
+ ySize
- 2, curX
+ xSize
- 1, curY
+ ySize
- 2 ); // horiz
359 dc
.DrawLine( curX
+ xSize
- 2, curY
+ 1, curX
+ xSize
- 2, curY
+ ySize
- 2 ); // vert
361 // step #2 - draw tab title bars
363 curX
= mFirstTitleGap
;
364 curY
= height
- mVertGap
- mTitleHeight
;
367 wxNode
* pNode
= mTabs
.First();
371 // "hard-coded metafile" for decorations
373 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
376 ySize
= mTitleHeight
;
378 if ( tabNo
== mActiveTab
)
380 dc
.SetPen( mGrayPen
);
381 dc
.DrawLine( curX
+1, curY
-2, curX
+xSize
-2, curY
-2 );
382 dc
.DrawLine( curX
+1, curY
-1, curX
+xSize
-2, curY
-1 );
385 dc
.SetPen( mWhitePen
);
387 if ( tabNo
== mActiveTab
)
388 dc
.DrawLine( curX
, curY
-2, curX
, curY
+ySize
-2 );
390 dc
.DrawLine( curX
, curY
, curX
, curY
+ySize
-2 );
392 dc
.SetPen( mDarkPen
);
393 dc
.DrawLine( curX
+1, curY
+ySize
-3, curX
+1, curY
+ySize
-1 ); // to pix down
394 dc
.DrawLine( curX
+2, curY
+ySize
-2, curX
+xSize
-2, curY
+ySize
-2 );
395 dc
.DrawLine( curX
+xSize
-3, curY
+ySize
-3, curX
+xSize
-2, curY
+ySize
-3 );
396 if ( tabNo
== mActiveTab
)
397 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-3, curX
+xSize
-2, curY
-3 );
399 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-3, curX
+xSize
-2, curY
-1 );
401 dc
.SetPen( mBlackPen
);
402 dc
.DrawLine( curX
+xSize
-1, curY
, curX
+xSize
-1, curY
+ySize
-2 );
403 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-2, curX
+xSize
-3, curY
+ySize
-2 );
404 dc
.DrawLine( curX
+xSize
-3, curY
+ySize
-1, curX
+1, curY
+ySize
-1 );
406 pNode
= pNode
->Next();
409 // darw image and (or without) text centered within the
410 // title bar rectangle
412 if ( mLayoutType
!= wxTITLE_BORDER_ONLY
&& tab
.HasImg() )
415 tmpDc
.SelectObject( tab
.GetImg() );
417 dc
.Blit( curX
+ mTitleHorizGap
,
418 curY
+ ( ySize
- tab
.ImgHeight() ) / 2,
425 if ( mLayoutType
== wxTITLE_IMG_AND_TEXT
&& tab
.HasText() )
429 // set select default font of the window into it's device context
430 //dc.SetFont( GetLabelingFont() );
432 dc
.SetTextBackground( GetBackgroundColour() );
434 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
436 x
= curX
+ mTitleHorizGap
+
437 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
439 dc
.DrawText( tab
.GetText(), x
, curY
+ ( ySize
- h
) / 2 );
443 } // end of `while (pNode)'
444 } // wxTabbedWindow::DrawDecorations()
446 //---------------------------------------------------------------------------
447 int wxTabbedWindow::HitTest( const wxPoint
& pos
)
450 GetClientSize( &width
, &height
);
452 int curX
= mFirstTitleGap
;
453 int curY
= height
- mVertGap
- mTitleHeight
;
456 wxNode
* pNode
= mTabs
.First();
460 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
465 // hit test rectangle of the currnet tab title bar
466 if ( pos
.x
>= curX
&& pos
.x
< curX
+ tab
.mDims
.x
&&
467 pos
.y
>= curY
&& pos
.y
< curY
+ tab
.mDims
.y
475 pNode
= pNode
->Next();
480 } // wxTabbedWindow::HitTest()
482 //---------------------------------------------------------------------------
483 void wxTabbedWindow::HideInactiveTabs( bool andRepaint
)
488 wxNode
* pNode
= mTabs
.First();
493 if ( tabNo
!= mActiveTab
)
495 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
496 tab
.mpContent
->Show(FALSE
);
499 pNode
= pNode
->Next();
502 } // wxTabbedWindow::HideInactiveTabs()
504 //---------------------------------------------------------------------------
505 wxFont
wxTabbedWindow::GetLabelingFont()
509 font
.SetFaceName("MS Sans Serif");
511 font
.SetFamily( wxSWISS
);
516 font
.SetPointSize( 8 );
519 font
.RealizeResource();
523 } // wxTabbedWindow::GetLabelingFont()
525 //---------------------------------------------------------------------------
526 void wxTabbedWindow::RecalcLayout(bool andRepaint
)
528 HideInactiveTabs(andRepaint
);
530 // resetup position of the active tab
533 GetClientSize( &width
, &height
);
535 int curX
= mHorizGap
+ BORDER_SZ
;
536 int curY
= mVertGap
+ BORDER_SZ
;
538 int xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2-1;
539 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2-1 - mTitleHeight
;
541 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
543 // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT
545 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
547 wxNode
* pNode
= mTabs
.First();
549 curX
= mFirstTitleGap
; // the left-side gap
554 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
560 // set select default font of the window into it's device context
561 //dc.SetFont( GetLabelingFont() );
563 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
565 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
566 tab
.ImgWidth() + mTitleHorizGap
*2;
568 tab
.mDims
.y
= wxMax( h
, tab
.ImgHeight() ) + mTitleVertGap
*2;
569 mTitleHeight
= wxMax( mTitleHeight
, tab
.mDims
.y
);
573 pNode
= pNode
->Next();
576 curX
+= mHorizGap
; // the right-side gap
578 // make all title bars of equel height
580 pNode
= mTabs
.First();
584 ((twTabInfo
*)(pNode
->Data()))->mDims
.y
= mTitleHeight
;;
585 pNode
= pNode
->Next();
588 // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return
589 if ( curX
< width
- mHorizGap
)
592 // pass #2 - try to layout assuming wxTITLE_IMG_ONLY
594 mLayoutType
= wxTITLE_IMG_ONLY
;
596 pNode
= mTabs
.First();
598 curX
= mFirstTitleGap
; // the left-side gap
600 int denomiator
= mTabs
.Number();
601 if ( denomiator
== 0 )
604 mBorderOnlyWidth
= (width
- mFirstTitleGap
- mHorizGap
) / denomiator
;
608 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
612 tab
.mDims
.x
= tab
.ImgWidth() + mTitleHorizGap
*2;
613 tab
.mDims
.y
= tab
.ImgHeight() + mTitleVertGap
*2;
617 tab
.mDims
.x
= mBorderOnlyWidth
;
618 tab
.mDims
.y
= mTitleHeight
;
623 pNode
= pNode
->Next();
626 curX
+= mHorizGap
; // the right-side gap
628 // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return
629 if ( curX
< width
- mHorizGap
)
632 // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY
634 mLayoutType
= wxTITLE_BORDER_ONLY
;
636 pNode
= mTabs
.First();
640 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
642 tab
.mDims
.x
= mBorderOnlyWidth
;
643 tab
.mDims
.y
= mTitleHeight
;
645 pNode
= pNode
->Next();
647 } // wxTabbedWindow::RecalcLayout()
649 //---------------------------------------------------------------------------
651 //---------------------------------------------------------------------------
652 void wxTabbedWindow::OnPaint( wxPaintEvent
& event
)
655 DrawDecorations( dc
);
658 //---------------------------------------------------------------------------
659 void wxTabbedWindow::OnSize ( wxSizeEvent
& event
)
661 SetBackgroundColour( wxColour( 192,192,192 ) );
665 //---------------------------------------------------------------------------
666 void wxTabbedWindow::OnBkErase( wxEraseEvent
& event
)
671 //---------------------------------------------------------------------------
672 void wxTabbedWindow::OnLButtonDown( wxMouseEvent
& event
)
675 int x
= (int)event
.m_x
;
676 int y
= (int)event
.m_y
;
678 int tabNo
= HitTest( wxPoint(x
,y
) );
682 SetActiveTab( tabNo
);
686 //---------------------------------------------------------------------------
687 // Implementation for class wxPagedWindow
688 //---------------------------------------------------------------------------
689 IMPLEMENT_DYNAMIC_CLASS( wxPagedWindow
, wxTabbedWindow
)
691 //---------------------------------------------------------------------------
692 BEGIN_EVENT_TABLE( wxPagedWindow
, wxTabbedWindow
)
693 EVT_SIZE ( wxPagedWindow::OnSize
)
694 EVT_PAINT ( wxPagedWindow::OnPaint
)
695 EVT_LEFT_DOWN( wxPagedWindow::OnLButtonDown
)
696 EVT_LEFT_UP ( wxPagedWindow::OnLButtonUp
)
697 EVT_MOTION ( wxPagedWindow::OnMouseMove
)
698 EVT_SCROLL ( wxPagedWindow::OnScroll
)
701 //---------------------------------------------------------------------------
702 // border for paged-window is 2 shaded-lines
703 //---------------------------------------------------------------------------
707 //---------------------------------------------------------------------------
708 wxPagedWindow::wxPagedWindow()
710 : mScrollEventInProgress( FALSE
),
712 mWhiteBrush( wxColour(255,255,255), wxSOLID
),
713 mGrayBrush ( wxColour(192,192,192), wxSOLID
),
715 mAdjustableTitleRowLen( 300 ),
716 mIsDragged ( FALSE
),
718 mCursorChanged( FALSE
),
719 mResizeCursor ( wxCURSOR_SIZEWE
),
720 mNormalCursor ( wxCURSOR_ARROW
)
724 mNoVertScroll
= TRUE
; // Horizontale Scroll abschalten
727 //---------------------------------------------------------------------------
728 wxPagedWindow::~wxPagedWindow()
730 // nothing (base class handles destruction)
733 //---------------------------------------------------------------------------
734 wxFont
wxPagedWindow::GetLabelingFont()
739 font
.SetFaceName("Comic Sans MS");
741 font
.SetFamily( wxSWISS
);
746 font
.SetPointSize( 8 );
751 //---------------------------------------------------------------------------
752 void wxPagedWindow::OnTabAdded( twTabInfo
* pInfo
)
754 int units
= GetWholeTabRowLen() / 20;
756 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, FALSE
);
759 //---------------------------------------------------------------------------
760 wxScrollBar
& wxPagedWindow::GetVerticalScrollBar()
762 return *mpVertScroll
;
765 //---------------------------------------------------------------------------
766 wxScrollBar
& wxPagedWindow::GetHorizontalScrollBar()
768 return *mpHorizScroll
;
771 //---------------------------------------------------------------------------
772 int wxPagedWindow::GetWholeTabRowLen()
774 wxNode
* pNode
= mTabs
.First();
780 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
783 pNode
= pNode
->Next();
787 } // wxPagedWindow::GetWholeTabRowLen()
789 //---------------------------------------------------------------------------
790 void wxPagedWindow::DrawPaperBar( twTabInfo
& tab
, int x
, int y
,
791 wxBrush
& brush
, wxPen
& pen
, wxDC
& dc
)
795 // draw organizer-style paper outlet
797 poly
[0].x
= x
- mTabTrianGap
;
800 poly
[1].x
= x
+ mTabTrianGap
;
801 poly
[1].y
= y
+ tab
.mDims
.y
-1;
803 poly
[2].x
= x
+ tab
.mDims
.x
- mTabTrianGap
;
804 poly
[2].y
= y
+ tab
.mDims
.y
-1;
806 poly
[3].x
= x
+ tab
.mDims
.x
+ mTabTrianGap
;
810 dc
.SetBrush( brush
);
812 dc
.DrawPolygon( 4, poly
);
816 // set select default font of the window into it's device context
817 //dc.SetFont( GetLabelingFont() );
819 dc
.SetTextBackground( brush
.GetColour() );
821 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
826 tmpDc
.SelectObject( tab
.GetImg() );
828 dc
.Blit( x
+ mTitleHorizGap
,
829 y
+ ( tab
.mDims
.y
- tab
.ImgHeight() ) / 2,
838 int tx
= x
+ mTitleHorizGap
+
839 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
841 dc
.DrawText( tab
.GetText(), tx
, y
+ ( tab
.mDims
.y
- h
) / 2 );
843 } // wxPagedWindow::DrawPaperBar()
845 //---------------------------------------------------------------------------
846 void wxPagedWindow::DrawDecorations( wxDC
& dc
)
848 // FIXME:: the is big body have to be split!
851 GetClientSize( &width
, &height
);
853 int curX
= mHorizGap
;
856 int xSize
= width
- mHorizGap
*2;
857 int ySize
= height
- mVertGap
*2;
859 DrawShadedRect( curX
, curY
, xSize
, ySize
,
860 mDarkPen
, mWhitePen
, dc
);
862 DrawShadedRect( curX
+1, curY
+1, xSize
-2, ySize
-2,
863 mBlackPen
, mGrayPen
, dc
);
865 // draw inactive tab title bars frist (left-to-right)
867 wxNode
* pNode
= mTabs
.First();
871 curX = mTitleRowStart;
872 curY = height - mVertGap - BORDER_SZ - mTitleHeight;
878 // FOR NOW:: avoid creating bitmap with invalid dimensions
880 if ( mTitleRowLen
< 1 || mTitleHeight
< 1 )
884 wxBitmap
tmpBmp( mTitleRowLen
, mTitleHeight
);
886 tmpDc
.SelectObject( tmpBmp
);
887 tmpDc
.SetPen( mGrayPen
);
888 tmpDc
.SetBrush( mGrayBrush
);
889 tmpDc
.DrawRectangle( 0,0, mTitleRowLen
, mTitleHeight
);
891 tmpDc
.SetDeviceOrigin( mCurentRowOfs
, 0 );
895 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
897 if ( tabNo
!= mActiveTab
)
898 DrawPaperBar( tab
, curX
, curY
, mGrayBrush
, mBlackPen
, tmpDc
);
902 pNode
= pNode
->Next();
906 // finally, draw the active tab (white-filled)
908 pNode
= mTabs
.First();
915 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
917 if ( tabNo
== mActiveTab
)
919 DrawPaperBar( tab
, curX
, curY
, mWhiteBrush
, mBlackPen
, tmpDc
);
921 tmpDc
.SetPen( mWhitePen
);
923 tmpDc
.DrawLine( curX
- mTabTrianGap
+1, curY
,
924 curX
+ tab
.mDims
.x
+ mTabTrianGap
, curY
);
929 pNode
= pNode
->Next();
933 // back to initial device origin
935 tmpDc
.SetDeviceOrigin( 0, 0 );
937 // draw resize-hint-stick
939 curX
= mTitleRowLen
- 6;
941 DrawShadedRect( curX
+0, 0+0, 6, mTitleHeight
, mGrayPen
, mBlackPen
, tmpDc
);
942 DrawShadedRect( curX
+1, 0+1, 6-2, mTitleHeight
-2, mWhitePen
, mDarkPen
, tmpDc
);
943 DrawShadedRect( curX
+2, 0+2, 6-4, mTitleHeight
-4, mGrayPen
, mGrayPen
, tmpDc
);
947 dc
.Blit( mTitleRowStart
,
948 height
- mVertGap
- BORDER_SZ
- mTitleHeight
,
949 mTitleRowLen
, mTitleHeight
,
950 &tmpDc
, 0,0, wxCOPY
);
951 } // wxPagedWindow::DrawDecorations()
953 //---------------------------------------------------------------------------
954 int wxPagedWindow::HitTest( const wxPoint
& pos
)
956 return wxTabbedWindow::HitTest( pos
);
959 //---------------------------------------------------------------------------
960 void wxPagedWindow::RecalcLayout(bool andRepaint
)
962 mTitleRowLen
= mAdjustableTitleRowLen
;
964 if ( int(mpTabScroll
) == -1 ) return;
966 // scroll bars should be created after Create() for this window is called
970 new wxScrollBar( this, -1, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
973 new wxScrollBar( this, -1, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
974 if (!mNoVertScroll
) // Vertical Scroll (Original)
975 mpVertScroll
= new wxScrollBar( this, -1, wxDefaultPosition
, wxDefaultSize
, wxSB_VERTICAL
);
979 int units
= GetWholeTabRowLen() / 20;
981 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, FALSE
);
984 // resetup position of the active tab
986 int thumbLen
= 16; // FOR NOW:: hardcoded
989 GetClientSize( &width
, &height
);
991 mTitleHeight
= thumbLen
;
993 int curX
= mHorizGap
+ BORDER_SZ
;
994 int curY
= mVertGap
+ BORDER_SZ
;
997 if (!mNoVertScroll
) // Vertical Scroll (Original)
998 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2 - thumbLen
;
1000 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2;
1002 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2 - mTitleHeight
;
1004 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
1006 // setup title bar LINES's horizontal scroll bar
1008 curY
= height
- mVertGap
- BORDER_SZ
- thumbLen
;
1010 mpTabScroll
->SetSize( curX
, curY
, thumbLen
*2, thumbLen
);
1012 // setup view's HORIZONTAL scroll bar
1015 mTitleRowStart
= curX
;
1016 mFirstTitleGap
= curX
+ mCurentRowOfs
+ mTabTrianGap
;
1018 mTitleRowLen
= wxMin( mAdjustableTitleRowLen
,
1019 width
- mHorizGap
- BORDER_SZ
- thumbLen
*4 - curX
);
1021 curX
+= mTitleRowLen
;
1023 if (!mNoVertScroll
) // Vertical Scroll (Original)
1024 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
- thumbLen
, thumbLen
);
1026 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
-4, thumbLen
);
1028 // setup view's VERTICAL scroll bar
1029 if (!mNoVertScroll
) // Vertical Scroll (Original)
1031 curX
= width
- mHorizGap
- BORDER_SZ
- thumbLen
;
1032 curY
= mVertGap
+ BORDER_SZ
;
1033 mpVertScroll
->SetSize( curX
, curY
, thumbLen
,height
- curY
- mVertGap
- BORDER_SZ
- thumbLen
);
1035 // layout tab title bars
1037 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
1039 wxNode
* pNode
= mTabs
.First();
1043 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->Data()));
1045 wxWindowDC
dc(this);
1049 // set select default font of the window into it's device context
1050 //dc.SetFont( GetLabelingFont() );
1051 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
1053 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
1054 tab
.ImgWidth() + mTitleHorizGap
*2;
1056 tab
.mDims
.y
= mTitleHeight
;
1058 pNode
= pNode
->Next();
1061 // disable title-bar scroller if there's nowhere to scroll to
1063 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1066 //---------------------------------------------------------------------------
1068 //---------------------------------------------------------------------------
1069 void wxPagedWindow::OnPaint( wxPaintEvent
& event
)
1072 DrawDecorations( dc
);
1075 //---------------------------------------------------------------------------
1076 void wxPagedWindow::OnSize ( wxSizeEvent
& event
)
1078 wxTabbedWindow::OnSize(event
);
1081 //---------------------------------------------------------------------------
1082 void wxPagedWindow::OnLButtonDown( wxMouseEvent
& event
)
1084 if ( mCursorChanged
)
1087 mDagOrigin
= event
.m_x
;
1089 mOriginalTitleRowLen
= mAdjustableTitleRowLen
;
1095 wxTabbedWindow::OnLButtonDown( event
);
1097 } // wxPagedWindow::OnLButtonDown()
1099 //---------------------------------------------------------------------------
1100 void wxPagedWindow::OnLButtonUp( wxMouseEvent
& event
)
1105 mCursorChanged
= FALSE
;
1106 SetCursor( mNormalCursor
);
1110 } // wxPagedWindow::OnLButtonUp()
1112 //---------------------------------------------------------------------------
1113 void wxPagedWindow::OnMouseMove( wxMouseEvent
& event
)
1116 GetClientSize( &width
, &height
);
1120 int y
= height
- mVertGap
- BORDER_SZ
- mTitleHeight
;
1121 int x
= mTitleRowStart
+ mTitleRowLen
- 6;
1123 if ( event
.m_x
>= x
&& event
.m_y
>= y
&&
1124 event
.m_x
< x
+ 6 &&
1125 event
.m_y
< y
+ mTitleHeight
1128 if ( !mCursorChanged
)
1130 SetCursor( mResizeCursor
);
1132 mCursorChanged
= TRUE
;
1136 if ( mCursorChanged
)
1138 SetCursor( mNormalCursor
);
1140 mCursorChanged
= FALSE
;
1147 mAdjustableTitleRowLen
= mOriginalTitleRowLen
+ ( event
.m_x
- mDagOrigin
);
1150 if ( mAdjustableTitleRowLen
< 6 ) mAdjustableTitleRowLen
= 6;
1152 wxWindowDC
dc(this);
1153 DrawDecorations( dc
);
1155 RecalcLayout(FALSE
);
1160 } // wxPagedWindow::OnMouseMove()
1162 //---------------------------------------------------------------------------
1163 void wxPagedWindow::OnScroll( wxScrollEvent
& event
)
1165 wxScrollBar
* pSender
= (wxScrollBar
*)event
.GetEventObject();
1166 // wxMessageBox("wxPagedWindow::OnScroll","-I->");
1167 if ( pSender
== mpTabScroll
)
1170 int maxUnits
= GetWholeTabRowLen() / 20;
1172 mCurentRowOfs
= -event
.GetPosition()*maxUnits
;
1174 mFirstTitleGap
= mTitleRowStart
+ mCurentRowOfs
+ mTabTrianGap
;
1176 // let' it automatically disable itself if it's time
1177 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1179 // repaint title bars
1180 wxWindowDC
dc(this);
1181 DrawDecorations( dc
);
1185 if ( !mScrollEventInProgress
)
1187 mScrollEventInProgress
= TRUE
;
1189 GetActiveTab()->GetEventHandler()->ProcessEvent( event
);
1193 // event bounced back to us, from here we
1194 // know that it has traveled the loop - thus it's processed!
1196 mScrollEventInProgress
= FALSE
;
1199 } // wxPagedWindow::OnScroll()
1200 //---------------------------------------------------------------------------