]>
git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/tabpgwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by: 19990908 : mj
6 // - rename to tabpgwin
7 // - restruction of Variable declaration
8 // - to prevent Warnings under MingW32
9 // Modified by: 19990909 : mj
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
.GetFirst();
164 delete ((twTabInfo
*)pTab
->GetData());
165 pTab
= pTab
->GetNext();
169 //---------------------------------------------------------------------------
170 void wxTabbedWindow::SizeTabs(int x
,int y
, int width
, int height
, bool WXUNUSED(repant
))
172 wxNode
* pTabNode
= mTabs
.GetFirst();
177 twTabInfo
& info
= *((twTabInfo
*)pTabNode
->GetData());
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
->GetNext();
199 //---------------------------------------------------------------------------
200 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
202 wxString imageFileName
,
203 wxBitmapType imageType
)
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, wxID_ANY
);
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, wxID_ANY
);
244 mTabs
.Append( (wxObject
*)pTab
);
249 //---------------------------------------------------------------------------
250 void wxTabbedWindow::RemoveTab( int tabNo
)
252 twTabInfo
* pTab
= ((twTabInfo
*)(mTabs
.Item( tabNo
)->GetData()));
253 pTab
->mpContent
->Destroy();
255 mTabs
.DeleteNode( mTabs
.Item( tabNo
) );
256 // if ( mActiveTab >= mTabs.GetCount() );
257 if ( mActiveTab
>= mTabs
.GetCount() )
258 mActiveTab
= mTabs
.GetCount() - 1;
259 SetActiveTab( mActiveTab
);
262 //---------------------------------------------------------------------------
263 int wxTabbedWindow::GetTabCount()
265 return mTabs
.GetCount();
268 //---------------------------------------------------------------------------
269 wxWindow
* wxTabbedWindow::GetTab( int tabNo
)
271 return ((twTabInfo
*)(mTabs
.Item( tabNo
)->GetData()))->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
.GetFirst();
371 // "hard-coded metafile" for decorations
373 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
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
->GetNext();
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
.GetFirst();
460 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
462 // hit test rectangle of the currnet tab title bar
463 if ( pos
.x
>= curX
&& pos
.x
< curX
+ tab
.mDims
.x
&&
464 pos
.y
>= curY
&& pos
.y
< curY
+ tab
.mDims
.y
472 pNode
= pNode
->GetNext();
477 } // wxTabbedWindow::HitTest()
479 //---------------------------------------------------------------------------
480 void wxTabbedWindow::HideInactiveTabs( bool andRepaint
)
485 wxNode
* pNode
= mTabs
.GetFirst();
490 if ( tabNo
!= mActiveTab
)
492 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
493 tab
.mpContent
->Show(false);
496 pNode
= pNode
->GetNext();
499 } // wxTabbedWindow::HideInactiveTabs()
501 //---------------------------------------------------------------------------
502 wxFont
wxTabbedWindow::GetLabelingFont()
506 font
.SetFaceName(_T("MS Sans Serif"));
508 font
.SetFamily( wxSWISS
);
513 font
.SetPointSize( 8 );
516 font
.RealizeResource();
520 } // wxTabbedWindow::GetLabelingFont()
522 //---------------------------------------------------------------------------
523 void wxTabbedWindow::RecalcLayout(bool andRepaint
)
525 HideInactiveTabs(andRepaint
);
527 // resetup position of the active tab
530 GetClientSize( &width
, &height
);
532 int curX
= mHorizGap
+ BORDER_SZ
;
533 int curY
= mVertGap
+ BORDER_SZ
;
535 int xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2-1;
536 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2-1 - mTitleHeight
;
538 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
540 // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT
542 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
544 wxNode
* pNode
= mTabs
.GetFirst();
546 curX
= mFirstTitleGap
; // the left-side gap
551 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
557 // set select default font of the window into it's device context
558 //dc.SetFont( GetLabelingFont() );
560 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
562 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
563 tab
.ImgWidth() + mTitleHorizGap
*2;
565 tab
.mDims
.y
= wxMax( h
, tab
.ImgHeight() ) + mTitleVertGap
*2;
566 mTitleHeight
= wxMax( mTitleHeight
, tab
.mDims
.y
);
570 pNode
= pNode
->GetNext();
573 curX
+= mHorizGap
; // the right-side gap
575 // make all title bars of equel height
577 pNode
= mTabs
.GetFirst();
581 ((twTabInfo
*)(pNode
->GetData()))->mDims
.y
= mTitleHeight
;;
582 pNode
= pNode
->GetNext();
585 // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return
586 if ( curX
< width
- mHorizGap
)
589 // pass #2 - try to layout assuming wxTITLE_IMG_ONLY
591 mLayoutType
= wxTITLE_IMG_ONLY
;
593 pNode
= mTabs
.GetFirst();
595 curX
= mFirstTitleGap
; // the left-side gap
597 int denomiator
= mTabs
.GetCount();
598 if ( denomiator
== 0 )
601 mBorderOnlyWidth
= (width
- mFirstTitleGap
- mHorizGap
) / denomiator
;
605 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
609 tab
.mDims
.x
= tab
.ImgWidth() + mTitleHorizGap
*2;
610 tab
.mDims
.y
= tab
.ImgHeight() + mTitleVertGap
*2;
614 tab
.mDims
.x
= mBorderOnlyWidth
;
615 tab
.mDims
.y
= mTitleHeight
;
620 pNode
= pNode
->GetNext();
623 curX
+= mHorizGap
; // the right-side gap
625 // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return
626 if ( curX
< width
- mHorizGap
)
629 // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY
631 mLayoutType
= wxTITLE_BORDER_ONLY
;
633 pNode
= mTabs
.GetFirst();
637 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
639 tab
.mDims
.x
= mBorderOnlyWidth
;
640 tab
.mDims
.y
= mTitleHeight
;
642 pNode
= pNode
->GetNext();
644 } // wxTabbedWindow::RecalcLayout()
646 //---------------------------------------------------------------------------
648 //---------------------------------------------------------------------------
649 void wxTabbedWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
652 DrawDecorations( dc
);
655 //---------------------------------------------------------------------------
656 void wxTabbedWindow::OnSize ( wxSizeEvent
& WXUNUSED(event
) )
658 SetBackgroundColour( wxColour( 192,192,192 ) );
662 //---------------------------------------------------------------------------
663 void wxTabbedWindow::OnBkErase( wxEraseEvent
& WXUNUSED(event
) )
668 //---------------------------------------------------------------------------
669 void wxTabbedWindow::OnLButtonDown( wxMouseEvent
& event
)
672 int x
= (int)event
.m_x
;
673 int y
= (int)event
.m_y
;
675 int tabNo
= HitTest( wxPoint(x
,y
) );
679 SetActiveTab( tabNo
);
683 //---------------------------------------------------------------------------
684 // Implementation for class wxPagedWindow
685 //---------------------------------------------------------------------------
686 IMPLEMENT_DYNAMIC_CLASS( wxPagedWindow
, wxTabbedWindow
)
688 //---------------------------------------------------------------------------
689 BEGIN_EVENT_TABLE( wxPagedWindow
, wxTabbedWindow
)
690 EVT_SIZE ( wxPagedWindow::OnSize
)
691 EVT_PAINT ( wxPagedWindow::OnPaint
)
692 EVT_LEFT_DOWN( wxPagedWindow::OnLButtonDown
)
693 EVT_LEFT_UP ( wxPagedWindow::OnLButtonUp
)
694 EVT_MOTION ( wxPagedWindow::OnMouseMove
)
695 EVT_SCROLL ( wxPagedWindow::OnScroll
)
698 //---------------------------------------------------------------------------
699 // border for paged-window is 2 shaded-lines
700 //---------------------------------------------------------------------------
704 //---------------------------------------------------------------------------
705 wxPagedWindow::wxPagedWindow()
707 : mScrollEventInProgress( false ),
709 mWhiteBrush( wxColour(255,255,255), wxSOLID
),
710 mGrayBrush ( wxColour(192,192,192), wxSOLID
),
712 mAdjustableTitleRowLen( 300 ),
713 mIsDragged ( false ),
715 mCursorChanged( false ),
716 mResizeCursor ( wxCURSOR_SIZEWE
),
717 mNormalCursor ( wxCURSOR_ARROW
)
721 mNoVertScroll
= true; // Horizontale Scroll abschalten
724 //---------------------------------------------------------------------------
725 wxPagedWindow::~wxPagedWindow()
727 // nothing (base class handles destruction)
730 //---------------------------------------------------------------------------
731 wxFont
wxPagedWindow::GetLabelingFont()
736 font
.SetFaceName(_T("Comic Sans MS"));
738 font
.SetFamily( wxSWISS
);
743 font
.SetPointSize( 8 );
748 //---------------------------------------------------------------------------
749 void wxPagedWindow::OnTabAdded( twTabInfo
* WXUNUSED(pInfo
) )
751 int units
= GetWholeTabRowLen() / 20;
753 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, false );
756 //---------------------------------------------------------------------------
757 wxScrollBar
& wxPagedWindow::GetVerticalScrollBar()
759 return *mpVertScroll
;
762 //---------------------------------------------------------------------------
763 wxScrollBar
& wxPagedWindow::GetHorizontalScrollBar()
765 return *mpHorizScroll
;
768 //---------------------------------------------------------------------------
769 int wxPagedWindow::GetWholeTabRowLen()
771 wxNode
* pNode
= mTabs
.GetFirst();
777 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
780 pNode
= pNode
->GetNext();
784 } // wxPagedWindow::GetWholeTabRowLen()
786 //---------------------------------------------------------------------------
787 void wxPagedWindow::DrawPaperBar( twTabInfo
& tab
, int x
, int y
,
788 wxBrush
& brush
, wxPen
& pen
, wxDC
& dc
)
792 // draw organizer-style paper outlet
794 poly
[0].x
= x
- mTabTrianGap
;
797 poly
[1].x
= x
+ mTabTrianGap
;
798 poly
[1].y
= y
+ tab
.mDims
.y
-1;
800 poly
[2].x
= x
+ tab
.mDims
.x
- mTabTrianGap
;
801 poly
[2].y
= y
+ tab
.mDims
.y
-1;
803 poly
[3].x
= x
+ tab
.mDims
.x
+ mTabTrianGap
;
807 dc
.SetBrush( brush
);
809 dc
.DrawPolygon( 4, poly
);
813 // set select default font of the window into it's device context
814 //dc.SetFont( GetLabelingFont() );
816 dc
.SetTextBackground( brush
.GetColour() );
818 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
823 tmpDc
.SelectObject( tab
.GetImg() );
825 dc
.Blit( x
+ mTitleHorizGap
,
826 y
+ ( tab
.mDims
.y
- tab
.ImgHeight() ) / 2,
835 int tx
= x
+ mTitleHorizGap
+
836 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
838 dc
.DrawText( tab
.GetText(), tx
, y
+ ( tab
.mDims
.y
- h
) / 2 );
840 } // wxPagedWindow::DrawPaperBar()
842 //---------------------------------------------------------------------------
843 void wxPagedWindow::DrawDecorations( wxDC
& dc
)
845 // FIXME:: the is big body have to be split!
848 GetClientSize( &width
, &height
);
850 int curX
= mHorizGap
;
853 int xSize
= width
- mHorizGap
*2;
854 int ySize
= height
- mVertGap
*2;
856 DrawShadedRect( curX
, curY
, xSize
, ySize
,
857 mDarkPen
, mWhitePen
, dc
);
859 DrawShadedRect( curX
+1, curY
+1, xSize
-2, ySize
-2,
860 mBlackPen
, mGrayPen
, dc
);
862 // draw inactive tab title bars frist (left-to-right)
864 wxNode
* pNode
= mTabs
.GetFirst();
868 curX = mTitleRowStart;
869 curY = height - mVertGap - BORDER_SZ - mTitleHeight;
875 // FOR NOW:: avoid creating bitmap with invalid dimensions
877 if ( mTitleRowLen
< 1 || mTitleHeight
< 1 )
881 wxBitmap
tmpBmp( mTitleRowLen
, mTitleHeight
);
883 tmpDc
.SelectObject( tmpBmp
);
884 tmpDc
.SetPen( mGrayPen
);
885 tmpDc
.SetBrush( mGrayBrush
);
886 tmpDc
.DrawRectangle( 0,0, mTitleRowLen
, mTitleHeight
);
888 tmpDc
.SetDeviceOrigin( mCurentRowOfs
, 0 );
892 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
894 if ( tabNo
!= mActiveTab
)
895 DrawPaperBar( tab
, curX
, curY
, mGrayBrush
, mBlackPen
, tmpDc
);
899 pNode
= pNode
->GetNext();
903 // finally, draw the active tab (white-filled)
905 pNode
= mTabs
.GetFirst();
912 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
914 if ( tabNo
== mActiveTab
)
916 DrawPaperBar( tab
, curX
, curY
, mWhiteBrush
, mBlackPen
, tmpDc
);
918 tmpDc
.SetPen( mWhitePen
);
920 tmpDc
.DrawLine( curX
- mTabTrianGap
+1, curY
,
921 curX
+ tab
.mDims
.x
+ mTabTrianGap
, curY
);
926 pNode
= pNode
->GetNext();
930 // back to initial device origin
932 tmpDc
.SetDeviceOrigin( 0, 0 );
934 // draw resize-hint-stick
936 curX
= mTitleRowLen
- 6;
938 DrawShadedRect( curX
+0, 0+0, 6, mTitleHeight
, mGrayPen
, mBlackPen
, tmpDc
);
939 DrawShadedRect( curX
+1, 0+1, 6-2, mTitleHeight
-2, mWhitePen
, mDarkPen
, tmpDc
);
940 DrawShadedRect( curX
+2, 0+2, 6-4, mTitleHeight
-4, mGrayPen
, mGrayPen
, tmpDc
);
944 dc
.Blit( mTitleRowStart
,
945 height
- mVertGap
- BORDER_SZ
- mTitleHeight
,
946 mTitleRowLen
, mTitleHeight
,
947 &tmpDc
, 0,0, wxCOPY
);
948 } // wxPagedWindow::DrawDecorations()
950 //---------------------------------------------------------------------------
951 int wxPagedWindow::HitTest( const wxPoint
& pos
)
953 return wxTabbedWindow::HitTest( pos
);
956 //---------------------------------------------------------------------------
957 void wxPagedWindow::RecalcLayout(bool andRepaint
)
959 mTitleRowLen
= mAdjustableTitleRowLen
;
961 if ( int(mpTabScroll
) == -1 ) return;
963 // scroll bars should be created after Create() for this window is called
967 new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
970 new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
971 if (!mNoVertScroll
) // Vertical Scroll (Original)
972 mpVertScroll
= new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_VERTICAL
);
976 int units
= GetWholeTabRowLen() / 20;
978 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, false );
981 // resetup position of the active tab
983 int thumbLen
= 16; // FOR NOW:: hardcoded
986 GetClientSize( &width
, &height
);
988 mTitleHeight
= thumbLen
;
990 int curX
= mHorizGap
+ BORDER_SZ
;
991 int curY
= mVertGap
+ BORDER_SZ
;
994 if (!mNoVertScroll
) // Vertical Scroll (Original)
995 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2 - thumbLen
;
997 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2;
999 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2 - mTitleHeight
;
1001 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
1003 // setup title bar LINES's horizontal scroll bar
1005 curY
= height
- mVertGap
- BORDER_SZ
- thumbLen
;
1007 mpTabScroll
->SetSize( curX
, curY
, thumbLen
*2, thumbLen
);
1009 // setup view's HORIZONTAL scroll bar
1012 mTitleRowStart
= curX
;
1013 mFirstTitleGap
= curX
+ mCurentRowOfs
+ mTabTrianGap
;
1015 mTitleRowLen
= wxMin( mAdjustableTitleRowLen
,
1016 width
- mHorizGap
- BORDER_SZ
- thumbLen
*4 - curX
);
1018 curX
+= mTitleRowLen
;
1020 if (!mNoVertScroll
) // Vertical Scroll (Original)
1021 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
- thumbLen
, thumbLen
);
1023 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
-4, thumbLen
);
1025 // setup view's VERTICAL scroll bar
1026 if (!mNoVertScroll
) // Vertical Scroll (Original)
1028 curX
= width
- mHorizGap
- BORDER_SZ
- thumbLen
;
1029 curY
= mVertGap
+ BORDER_SZ
;
1030 mpVertScroll
->SetSize( curX
, curY
, thumbLen
,height
- curY
- mVertGap
- BORDER_SZ
- thumbLen
);
1032 // layout tab title bars
1034 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
1036 wxNode
* pNode
= mTabs
.GetFirst();
1040 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
1042 wxWindowDC
dc(this);
1046 // set select default font of the window into it's device context
1047 //dc.SetFont( GetLabelingFont() );
1048 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
1050 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
1051 tab
.ImgWidth() + mTitleHorizGap
*2;
1053 tab
.mDims
.y
= mTitleHeight
;
1055 pNode
= pNode
->GetNext();
1058 // disable title-bar scroller if there's nowhere to scroll to
1060 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1063 //---------------------------------------------------------------------------
1065 //---------------------------------------------------------------------------
1066 void wxPagedWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1069 DrawDecorations( dc
);
1072 //---------------------------------------------------------------------------
1073 void wxPagedWindow::OnSize ( wxSizeEvent
& event
)
1075 wxTabbedWindow::OnSize(event
);
1078 //---------------------------------------------------------------------------
1079 void wxPagedWindow::OnLButtonDown( wxMouseEvent
& event
)
1081 if ( mCursorChanged
)
1084 mDagOrigin
= event
.m_x
;
1086 mOriginalTitleRowLen
= mAdjustableTitleRowLen
;
1092 wxTabbedWindow::OnLButtonDown( event
);
1094 } // wxPagedWindow::OnLButtonDown()
1096 //---------------------------------------------------------------------------
1097 void wxPagedWindow::OnLButtonUp( wxMouseEvent
& WXUNUSED(event
) )
1102 mCursorChanged
= false;
1103 SetCursor( mNormalCursor
);
1107 } // wxPagedWindow::OnLButtonUp()
1109 //---------------------------------------------------------------------------
1110 void wxPagedWindow::OnMouseMove( wxMouseEvent
& event
)
1113 GetClientSize( &width
, &height
);
1117 int y
= height
- mVertGap
- BORDER_SZ
- mTitleHeight
;
1118 int x
= mTitleRowStart
+ mTitleRowLen
- 6;
1120 if ( event
.m_x
>= x
&& event
.m_y
>= y
&&
1121 event
.m_x
< x
+ 6 &&
1122 event
.m_y
< y
+ mTitleHeight
1125 if ( !mCursorChanged
)
1127 SetCursor( mResizeCursor
);
1129 mCursorChanged
= true;
1133 if ( mCursorChanged
)
1135 SetCursor( mNormalCursor
);
1137 mCursorChanged
= false;
1144 mAdjustableTitleRowLen
= mOriginalTitleRowLen
+ ( event
.m_x
- mDagOrigin
);
1147 if ( mAdjustableTitleRowLen
< 6 ) mAdjustableTitleRowLen
= 6;
1149 wxWindowDC
dc(this);
1150 DrawDecorations( dc
);
1152 RecalcLayout(false);
1157 } // wxPagedWindow::OnMouseMove()
1159 //---------------------------------------------------------------------------
1160 void wxPagedWindow::OnScroll( wxScrollEvent
& event
)
1162 wxScrollBar
* pSender
= (wxScrollBar
*)event
.GetEventObject();
1163 // wxMessageBox("wxPagedWindow::OnScroll","-I->");
1164 if ( pSender
== mpTabScroll
)
1167 int maxUnits
= GetWholeTabRowLen() / 20;
1169 mCurentRowOfs
= -event
.GetPosition()*maxUnits
;
1171 mFirstTitleGap
= mTitleRowStart
+ mCurentRowOfs
+ mTabTrianGap
;
1173 // let' it automatically disable itself if it's time
1174 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1176 // repaint title bars
1177 wxWindowDC
dc(this);
1178 DrawDecorations( dc
);
1182 if ( !mScrollEventInProgress
)
1184 mScrollEventInProgress
= true;
1186 GetActiveTab()->GetEventHandler()->ProcessEvent( event
);
1190 // event bounced back to us, from here we
1191 // know that it has traveled the loop - thus it's processed!
1193 mScrollEventInProgress
= false;
1196 } // wxPagedWindow::OnScroll()
1197 //---------------------------------------------------------------------------