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 /////////////////////////////////////////////////////////////////////////////
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
34 #include "wx/string.h"
35 #include "wx/utils.h" // import wxMin/wxMax macros and wxFileExist(..)
39 //---------------------------------------------------------------------------
40 // Implementation for class twTabInfo
41 //---------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS( twTabInfo
, wxObject
)
44 //---------------------------------------------------------------------------
45 twTabInfo::twTabInfo()
49 //---------------------------------------------------------------------------
50 int twTabInfo::ImgWidth()
52 if ( mBitMap
.Ok() ) return mBitMap
.GetWidth();
56 //---------------------------------------------------------------------------
57 int twTabInfo::ImgHeight()
60 return mBitMap
.GetHeight();
65 //---------------------------------------------------------------------------
66 int twTabInfo::ImageToTxtGap( int prefGap
)
74 //---------------------------------------------------------------------------
75 bool twTabInfo::HasImg()
80 //---------------------------------------------------------------------------
81 // bool twTabInfo::HasText();
82 unsigned int twTabInfo::HasText()
84 return mText
.Length();
87 //---------------------------------------------------------------------------
88 wxBitmap
& twTabInfo::GetImg()
93 //---------------------------------------------------------------------------
94 wxString
& twTabInfo::GetText()
99 //---------------------------------------------------------------------------
100 wxWindow
& twTabInfo::GetContent()
105 //---------------------------------------------------------------------------
106 // Implementation for class wxTabbedWindow
107 //---------------------------------------------------------------------------
108 IMPLEMENT_DYNAMIC_CLASS( wxTabbedWindow
, wxPanel
)
110 //---------------------------------------------------------------------------
111 BEGIN_EVENT_TABLE( wxTabbedWindow
, wxPanel
)
112 EVT_SIZE ( wxTabbedWindow::OnSize
)
113 EVT_PAINT( wxTabbedWindow::OnPaint
)
114 EVT_LEFT_DOWN( wxTabbedWindow::OnLButtonDown
)
115 // TDB:: filciker reduction
116 // EVT_ERASE_BACKGROUND( wxTabbedWindow::OnBkErase )
119 //---------------------------------------------------------------------------
120 wxTabbedWindow::wxTabbedWindow()
122 : mpTabScroll ( NULL
),
123 mpHorizScroll( NULL
),
124 mpVertScroll ( NULL
),
132 mFirstTitleGap( 11 ),
134 mBorderOnlyWidth( 8 ),
136 mWhitePen( wxColour(255,255,255), 1, wxSOLID
),
137 mGrayPen ( wxColour(192,192,192), 1, wxSOLID
),
138 mDarkPen ( wxColour(128,128,128), 1, wxSOLID
),
139 mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID
),
144 mLayoutType( wxTITLE_IMG_AND_TEXT
)
147 //---------------------------------------------------------------------------
148 wxTabbedWindow::~wxTabbedWindow()
150 wxObjectList::compatibility_iterator pTab
= mTabs
.GetFirst();
154 delete ((twTabInfo
*)pTab
->GetData());
155 pTab
= pTab
->GetNext();
159 //---------------------------------------------------------------------------
160 void wxTabbedWindow::SizeTabs(int x
,int y
, int width
, int height
, bool WXUNUSED(repant
))
162 wxObjectList::compatibility_iterator pTabNode
= mTabs
.GetFirst();
167 twTabInfo
& info
= *((twTabInfo
*)pTabNode
->GetData());
169 if ( n
== mActiveTab
)
172 //info.mpContent->GetEventHandler()->ProcessEvent( evt );
174 info
.mpContent
->SetSize( x
, y
, width
, height
, 0 );
175 info
.mpContent
->Show(true);
176 info
.mpContent
->Refresh();
181 info
.mpContent
->Show(false);
184 pTabNode
= pTabNode
->GetNext();
189 //---------------------------------------------------------------------------
190 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
192 wxString imageFileName
,
193 wxBitmapType imageType
)
195 twTabInfo
* pTab
= new twTabInfo();
197 pTab
->mpContent
= pContent
;
198 pTab
->mText
= tabText
;
200 if ( wxFileExists( imageFileName
) &&
202 pTab
->mBitMap
.LoadFile( imageFileName
, imageType
) )
204 pTab
->mImageFile
= imageFileName
;
205 pTab
->mImageType
= imageType
;
209 if ( pContent
->GetParent() == NULL
)
210 pContent
->Create( this, wxID_ANY
);
212 mTabs
.Append( (wxObject
*)pTab
);
219 //---------------------------------------------------------------------------
220 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
221 wxString tabText
, wxBitmap
* pImage
)
223 twTabInfo
* pTab
= new twTabInfo();
225 pTab
->mpContent
= pContent
;
226 pTab
->mText
= tabText
;
229 pTab
->mBitMap
= *pImage
;
231 if ( pContent
->GetParent() == NULL
)
232 pContent
->Create( this, wxID_ANY
);
234 mTabs
.Append( (wxObject
*)pTab
);
239 //---------------------------------------------------------------------------
240 void wxTabbedWindow::RemoveTab( int tabNo
)
242 twTabInfo
* pTab
= ((twTabInfo
*)(mTabs
.Item( tabNo
)->GetData()));
243 pTab
->mpContent
->Destroy();
245 mTabs
.Erase( mTabs
.Item( tabNo
) );
246 // if ( mActiveTab >= mTabs.GetCount() );
247 if ( mActiveTab
>= mTabs
.GetCount() )
248 mActiveTab
= mTabs
.GetCount() - 1;
249 SetActiveTab( mActiveTab
);
252 //---------------------------------------------------------------------------
253 int wxTabbedWindow::GetTabCount()
255 return mTabs
.GetCount();
258 //---------------------------------------------------------------------------
259 wxWindow
* wxTabbedWindow::GetTab( int tabNo
)
261 return ((twTabInfo
*)(mTabs
.Item( tabNo
)->GetData()))->mpContent
;
264 //---------------------------------------------------------------------------
265 wxWindow
* wxTabbedWindow::GetActiveTab()
267 // FIMXE:: this is lame
268 return GetTab( mActiveTab
);
271 //---------------------------------------------------------------------------
272 void wxTabbedWindow::SetActiveTab( int tabNo
)
279 //---------------------------------------------------------------------------
280 // width of the decorations border (4 shade-lines), should not be changed
281 //---------------------------------------------------------------------------
284 //---------------------------------------------------------------------------
285 void wxTabbedWindow::DrawShadedRect( int x
, int y
, int width
, int height
,
286 wxPen
& upperPen
, wxPen
& lowerPen
, wxDC
& dc
289 // darw the lightened upper-left sides of the rectangle
291 dc
.SetPen( upperPen
);
292 dc
.DrawLine( x
,y
, x
, y
+ height
- 1 ); // vert
293 dc
.DrawLine( x
,y
, x
+ width
- 1, y
); // horiz
295 // draw the unenlightened lower-right sides of the rectangle
297 dc
.SetPen( lowerPen
);
298 dc
.DrawLine( x
+ width
- 1, y
, x
+ width
- 1, y
+ height
- 1 ); // vert
299 dc
.DrawLine( x
, y
+ height
- 1, x
+ width
, y
+ height
- 1 ); // horiz
302 //---------------------------------------------------------------------------
303 void wxTabbedWindow::DrawDecorations( wxDC
& dc
)
305 // Protability NOTE::: DrawLine(..) draws a line from the first position,
306 // but not including the point specified by last position.
307 // This way Windows draws lines, not sure how Motif and Gtk
311 GetClientSize( &width
, &height
);
313 // check if there's at least a bit of space to draw things
315 if ( width
< mHorizGap
*2 + BORDER_SZ
*2+1 ||
316 height
< mVertGap
*2 + BORDER_SZ
*2+1 + mTitleHeight
320 // step #1 - draw border around the tab content area
322 // setup position for kind of "pencil"
323 int curX
= mHorizGap
;
326 int xSize
= width
- mHorizGap
*2;
327 int ySize
= height
- mVertGap
*2 - mTitleHeight
;
329 // layer 1 (upper white)
330 DrawShadedRect( curX
+0, curY
+0, xSize
-0, ySize
-0,
331 mWhitePen
, mBlackPen
, dc
);
333 // layer 2 (upper gray)
334 DrawShadedRect( curX
+1, curY
+1, xSize
-2-1, ySize
-2-1,
335 mGrayPen
, mGrayPen
, dc
);
337 // layer 3 (upper darkGray)
338 DrawShadedRect( curX
+2, curY
+2, xSize
-3-2, ySize
-3-2,
339 mDarkPen
, mWhitePen
, dc
);
341 // layer 4 (upper black)
342 DrawShadedRect( curX
+3, curY
+3, xSize
-4-3, ySize
-4-3,
343 mBlackPen
, mGrayPen
, dc
);
345 // add non-siemtric layer from the lower-right side (confroming to MFC-look)
347 dc
.SetPen( mDarkPen
);
348 dc
.DrawLine( curX
+1, curY
+ ySize
- 2, curX
+ xSize
- 1, curY
+ ySize
- 2 ); // horiz
349 dc
.DrawLine( curX
+ xSize
- 2, curY
+ 1, curX
+ xSize
- 2, curY
+ ySize
- 2 ); // vert
351 // step #2 - draw tab title bars
353 curX
= mFirstTitleGap
;
354 curY
= height
- mVertGap
- mTitleHeight
;
357 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
361 // "hard-coded metafile" for decorations
363 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
366 ySize
= mTitleHeight
;
368 if ( tabNo
== mActiveTab
)
370 dc
.SetPen( mGrayPen
);
371 dc
.DrawLine( curX
+1, curY
-2, curX
+xSize
-2, curY
-2 );
372 dc
.DrawLine( curX
+1, curY
-1, curX
+xSize
-2, curY
-1 );
375 dc
.SetPen( mWhitePen
);
377 if ( tabNo
== mActiveTab
)
378 dc
.DrawLine( curX
, curY
-2, curX
, curY
+ySize
-2 );
380 dc
.DrawLine( curX
, curY
, curX
, curY
+ySize
-2 );
382 dc
.SetPen( mDarkPen
);
383 dc
.DrawLine( curX
+1, curY
+ySize
-3, curX
+1, curY
+ySize
-1 ); // to pix down
384 dc
.DrawLine( curX
+2, curY
+ySize
-2, curX
+xSize
-2, curY
+ySize
-2 );
385 dc
.DrawLine( curX
+xSize
-3, curY
+ySize
-3, curX
+xSize
-2, curY
+ySize
-3 );
386 if ( tabNo
== mActiveTab
)
387 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-3, curX
+xSize
-2, curY
-3 );
389 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-3, curX
+xSize
-2, curY
-1 );
391 dc
.SetPen( mBlackPen
);
392 dc
.DrawLine( curX
+xSize
-1, curY
, curX
+xSize
-1, curY
+ySize
-2 );
393 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-2, curX
+xSize
-3, curY
+ySize
-2 );
394 dc
.DrawLine( curX
+xSize
-3, curY
+ySize
-1, curX
+1, curY
+ySize
-1 );
396 pNode
= pNode
->GetNext();
399 // darw image and (or without) text centered within the
400 // title bar rectangle
402 if ( mLayoutType
!= wxTITLE_BORDER_ONLY
&& tab
.HasImg() )
405 tmpDc
.SelectObject( tab
.GetImg() );
407 dc
.Blit( curX
+ mTitleHorizGap
,
408 curY
+ ( ySize
- tab
.ImgHeight() ) / 2,
415 if ( mLayoutType
== wxTITLE_IMG_AND_TEXT
&& tab
.HasText() )
419 // set select default font of the window into it's device context
420 //dc.SetFont( GetLabelingFont() );
422 dc
.SetTextBackground( GetBackgroundColour() );
424 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
426 x
= curX
+ mTitleHorizGap
+
427 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
429 dc
.DrawText( tab
.GetText(), x
, curY
+ ( ySize
- h
) / 2 );
433 } // end of `while (pNode)'
434 } // wxTabbedWindow::DrawDecorations()
436 //---------------------------------------------------------------------------
437 int wxTabbedWindow::HitTest( const wxPoint
& pos
)
440 GetClientSize( &width
, &height
);
442 int curX
= mFirstTitleGap
;
443 int curY
= height
- mVertGap
- mTitleHeight
;
446 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
450 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
452 // hit test rectangle of the currnet tab title bar
453 if ( pos
.x
>= curX
&& pos
.x
< curX
+ tab
.mDims
.x
&&
454 pos
.y
>= curY
&& pos
.y
< curY
+ tab
.mDims
.y
462 pNode
= pNode
->GetNext();
467 } // wxTabbedWindow::HitTest()
469 //---------------------------------------------------------------------------
470 void wxTabbedWindow::HideInactiveTabs( bool andRepaint
)
475 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
480 if ( tabNo
!= mActiveTab
)
482 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
483 tab
.mpContent
->Show(false);
486 pNode
= pNode
->GetNext();
489 } // wxTabbedWindow::HideInactiveTabs()
491 //---------------------------------------------------------------------------
492 wxFont
wxTabbedWindow::GetLabelingFont()
496 font
.SetFaceName(_T("MS Sans Serif"));
498 font
.SetFamily( wxSWISS
);
503 font
.SetPointSize( 8 );
506 font
.RealizeResource();
510 } // wxTabbedWindow::GetLabelingFont()
512 //---------------------------------------------------------------------------
513 void wxTabbedWindow::RecalcLayout(bool andRepaint
)
515 HideInactiveTabs(andRepaint
);
517 // resetup position of the active tab
520 GetClientSize( &width
, &height
);
522 int curX
= mHorizGap
+ BORDER_SZ
;
523 int curY
= mVertGap
+ BORDER_SZ
;
525 int xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2-1;
526 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2-1 - mTitleHeight
;
528 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
530 // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT
532 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
534 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
536 curX
= mFirstTitleGap
; // the left-side gap
541 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
547 // set select default font of the window into it's device context
548 //dc.SetFont( GetLabelingFont() );
550 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
552 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
553 tab
.ImgWidth() + mTitleHorizGap
*2;
555 tab
.mDims
.y
= wxMax( h
, tab
.ImgHeight() ) + mTitleVertGap
*2;
556 mTitleHeight
= wxMax( mTitleHeight
, tab
.mDims
.y
);
560 pNode
= pNode
->GetNext();
563 curX
+= mHorizGap
; // the right-side gap
565 // make all title bars of equel height
567 pNode
= mTabs
.GetFirst();
571 ((twTabInfo
*)(pNode
->GetData()))->mDims
.y
= mTitleHeight
;;
572 pNode
= pNode
->GetNext();
575 // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return
576 if ( curX
< width
- mHorizGap
)
579 // pass #2 - try to layout assuming wxTITLE_IMG_ONLY
581 mLayoutType
= wxTITLE_IMG_ONLY
;
583 pNode
= mTabs
.GetFirst();
585 curX
= mFirstTitleGap
; // the left-side gap
587 int denomiator
= mTabs
.GetCount();
588 if ( denomiator
== 0 )
591 mBorderOnlyWidth
= (width
- mFirstTitleGap
- mHorizGap
) / denomiator
;
595 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
599 tab
.mDims
.x
= tab
.ImgWidth() + mTitleHorizGap
*2;
600 tab
.mDims
.y
= tab
.ImgHeight() + mTitleVertGap
*2;
604 tab
.mDims
.x
= mBorderOnlyWidth
;
605 tab
.mDims
.y
= mTitleHeight
;
610 pNode
= pNode
->GetNext();
613 curX
+= mHorizGap
; // the right-side gap
615 // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return
616 if ( curX
< width
- mHorizGap
)
619 // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY
621 mLayoutType
= wxTITLE_BORDER_ONLY
;
623 pNode
= mTabs
.GetFirst();
627 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
629 tab
.mDims
.x
= mBorderOnlyWidth
;
630 tab
.mDims
.y
= mTitleHeight
;
632 pNode
= pNode
->GetNext();
634 } // wxTabbedWindow::RecalcLayout()
636 //---------------------------------------------------------------------------
638 //---------------------------------------------------------------------------
639 void wxTabbedWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
642 DrawDecorations( dc
);
645 //---------------------------------------------------------------------------
646 void wxTabbedWindow::OnSize ( wxSizeEvent
& WXUNUSED(event
) )
648 SetBackgroundColour( wxColour( 192,192,192 ) );
652 //---------------------------------------------------------------------------
653 void wxTabbedWindow::OnBkErase( wxEraseEvent
& WXUNUSED(event
) )
658 //---------------------------------------------------------------------------
659 void wxTabbedWindow::OnLButtonDown( wxMouseEvent
& event
)
662 int x
= (int)event
.m_x
;
663 int y
= (int)event
.m_y
;
665 int tabNo
= HitTest( wxPoint(x
,y
) );
669 SetActiveTab( tabNo
);
673 //---------------------------------------------------------------------------
674 // Implementation for class wxPagedWindow
675 //---------------------------------------------------------------------------
676 IMPLEMENT_DYNAMIC_CLASS( wxPagedWindow
, wxTabbedWindow
)
678 //---------------------------------------------------------------------------
679 BEGIN_EVENT_TABLE( wxPagedWindow
, wxTabbedWindow
)
680 EVT_SIZE ( wxPagedWindow::OnSize
)
681 EVT_PAINT ( wxPagedWindow::OnPaint
)
682 EVT_LEFT_DOWN( wxPagedWindow::OnLButtonDown
)
683 EVT_LEFT_UP ( wxPagedWindow::OnLButtonUp
)
684 EVT_MOTION ( wxPagedWindow::OnMouseMove
)
685 EVT_SCROLL ( wxPagedWindow::OnScroll
)
688 //---------------------------------------------------------------------------
689 // border for paged-window is 2 shaded-lines
690 //---------------------------------------------------------------------------
694 //---------------------------------------------------------------------------
695 wxPagedWindow::wxPagedWindow()
697 : mScrollEventInProgress( false ),
699 mWhiteBrush( wxColour(255,255,255), wxSOLID
),
700 mGrayBrush ( wxColour(192,192,192), wxSOLID
),
702 mAdjustableTitleRowLen( 300 ),
703 mIsDragged ( false ),
705 mCursorChanged( false ),
706 mResizeCursor ( wxCURSOR_SIZEWE
),
707 mNormalCursor ( wxCURSOR_ARROW
)
711 mNoVertScroll
= true; // Horizontale Scroll abschalten
714 //---------------------------------------------------------------------------
715 wxFont
wxPagedWindow::GetLabelingFont()
720 font
.SetFaceName(_T("Comic Sans MS"));
722 font
.SetFamily( wxSWISS
);
727 font
.SetPointSize( 8 );
732 //---------------------------------------------------------------------------
733 void wxPagedWindow::OnTabAdded( twTabInfo
* WXUNUSED(pInfo
) )
735 int units
= GetWholeTabRowLen() / 20;
737 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, false );
740 //---------------------------------------------------------------------------
741 wxScrollBar
& wxPagedWindow::GetVerticalScrollBar()
743 return *mpVertScroll
;
746 //---------------------------------------------------------------------------
747 wxScrollBar
& wxPagedWindow::GetHorizontalScrollBar()
749 return *mpHorizScroll
;
752 //---------------------------------------------------------------------------
753 int wxPagedWindow::GetWholeTabRowLen()
755 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
761 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
764 pNode
= pNode
->GetNext();
768 } // wxPagedWindow::GetWholeTabRowLen()
770 //---------------------------------------------------------------------------
771 void wxPagedWindow::DrawPaperBar( twTabInfo
& tab
, int x
, int y
,
772 wxBrush
& brush
, wxPen
& pen
, wxDC
& dc
)
776 // draw organizer-style paper outlet
778 poly
[0].x
= x
- mTabTrianGap
;
781 poly
[1].x
= x
+ mTabTrianGap
;
782 poly
[1].y
= y
+ tab
.mDims
.y
-1;
784 poly
[2].x
= x
+ tab
.mDims
.x
- mTabTrianGap
;
785 poly
[2].y
= y
+ tab
.mDims
.y
-1;
787 poly
[3].x
= x
+ tab
.mDims
.x
+ mTabTrianGap
;
791 dc
.SetBrush( brush
);
793 dc
.DrawPolygon( 4, poly
);
797 // set select default font of the window into it's device context
798 //dc.SetFont( GetLabelingFont() );
800 dc
.SetTextBackground( brush
.GetColour() );
802 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
807 tmpDc
.SelectObject( tab
.GetImg() );
809 dc
.Blit( x
+ mTitleHorizGap
,
810 y
+ ( tab
.mDims
.y
- tab
.ImgHeight() ) / 2,
819 int tx
= x
+ mTitleHorizGap
+
820 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
822 dc
.DrawText( tab
.GetText(), tx
, y
+ ( tab
.mDims
.y
- h
) / 2 );
824 } // wxPagedWindow::DrawPaperBar()
826 //---------------------------------------------------------------------------
827 void wxPagedWindow::DrawDecorations( wxDC
& dc
)
829 // FIXME:: the is big body have to be split!
832 GetClientSize( &width
, &height
);
834 int curX
= mHorizGap
;
837 int xSize
= width
- mHorizGap
*2;
838 int ySize
= height
- mVertGap
*2;
840 DrawShadedRect( curX
, curY
, xSize
, ySize
,
841 mDarkPen
, mWhitePen
, dc
);
843 DrawShadedRect( curX
+1, curY
+1, xSize
-2, ySize
-2,
844 mBlackPen
, mGrayPen
, dc
);
846 // draw inactive tab title bars frist (left-to-right)
848 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
852 curX = mTitleRowStart;
853 curY = height - mVertGap - BORDER_SZ - mTitleHeight;
859 // FOR NOW:: avoid creating bitmap with invalid dimensions
861 if ( mTitleRowLen
< 1 || mTitleHeight
< 1 )
865 wxBitmap
tmpBmp( mTitleRowLen
, mTitleHeight
);
867 tmpDc
.SelectObject( tmpBmp
);
868 tmpDc
.SetPen( mGrayPen
);
869 tmpDc
.SetBrush( mGrayBrush
);
870 tmpDc
.DrawRectangle( 0,0, mTitleRowLen
, mTitleHeight
);
872 tmpDc
.SetDeviceOrigin( mCurentRowOfs
, 0 );
876 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
878 if ( tabNo
!= mActiveTab
)
879 DrawPaperBar( tab
, curX
, curY
, mGrayBrush
, mBlackPen
, tmpDc
);
883 pNode
= pNode
->GetNext();
887 // finally, draw the active tab (white-filled)
889 pNode
= mTabs
.GetFirst();
896 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
898 if ( tabNo
== mActiveTab
)
900 DrawPaperBar( tab
, curX
, curY
, mWhiteBrush
, mBlackPen
, tmpDc
);
902 tmpDc
.SetPen( mWhitePen
);
904 tmpDc
.DrawLine( curX
- mTabTrianGap
+1, curY
,
905 curX
+ tab
.mDims
.x
+ mTabTrianGap
, curY
);
910 pNode
= pNode
->GetNext();
914 // back to initial device origin
916 tmpDc
.SetDeviceOrigin( 0, 0 );
918 // draw resize-hint-stick
920 curX
= mTitleRowLen
- 6;
922 DrawShadedRect( curX
+0, 0+0, 6, mTitleHeight
, mGrayPen
, mBlackPen
, tmpDc
);
923 DrawShadedRect( curX
+1, 0+1, 6-2, mTitleHeight
-2, mWhitePen
, mDarkPen
, tmpDc
);
924 DrawShadedRect( curX
+2, 0+2, 6-4, mTitleHeight
-4, mGrayPen
, mGrayPen
, tmpDc
);
928 dc
.Blit( mTitleRowStart
,
929 height
- mVertGap
- BORDER_SZ
- mTitleHeight
,
930 mTitleRowLen
, mTitleHeight
,
931 &tmpDc
, 0,0, wxCOPY
);
932 } // wxPagedWindow::DrawDecorations()
934 //---------------------------------------------------------------------------
935 int wxPagedWindow::HitTest( const wxPoint
& pos
)
937 return wxTabbedWindow::HitTest( pos
);
940 //---------------------------------------------------------------------------
941 void wxPagedWindow::RecalcLayout(bool andRepaint
)
943 mTitleRowLen
= mAdjustableTitleRowLen
;
945 if ( int(mpTabScroll
) == -1 ) return;
947 // scroll bars should be created after Create() for this window is called
951 new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
954 new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
955 if (!mNoVertScroll
) // Vertical Scroll (Original)
956 mpVertScroll
= new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_VERTICAL
);
960 int units
= GetWholeTabRowLen() / 20;
962 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, false );
965 // resetup position of the active tab
967 int thumbLen
= 16; // FOR NOW:: hardcoded
970 GetClientSize( &width
, &height
);
972 mTitleHeight
= thumbLen
;
974 int curX
= mHorizGap
+ BORDER_SZ
;
975 int curY
= mVertGap
+ BORDER_SZ
;
978 if (!mNoVertScroll
) // Vertical Scroll (Original)
979 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2 - thumbLen
;
981 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2;
983 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2 - mTitleHeight
;
985 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
987 // setup title bar LINES's horizontal scroll bar
989 curY
= height
- mVertGap
- BORDER_SZ
- thumbLen
;
991 mpTabScroll
->SetSize( curX
, curY
, thumbLen
*2, thumbLen
);
993 // setup view's HORIZONTAL scroll bar
996 mTitleRowStart
= curX
;
997 mFirstTitleGap
= curX
+ mCurentRowOfs
+ mTabTrianGap
;
999 mTitleRowLen
= wxMin( mAdjustableTitleRowLen
,
1000 width
- mHorizGap
- BORDER_SZ
- thumbLen
*4 - curX
);
1002 curX
+= mTitleRowLen
;
1004 if (!mNoVertScroll
) // Vertical Scroll (Original)
1005 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
- thumbLen
, thumbLen
);
1007 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
-4, thumbLen
);
1009 // setup view's VERTICAL scroll bar
1010 if (!mNoVertScroll
) // Vertical Scroll (Original)
1012 curX
= width
- mHorizGap
- BORDER_SZ
- thumbLen
;
1013 curY
= mVertGap
+ BORDER_SZ
;
1014 mpVertScroll
->SetSize( curX
, curY
, thumbLen
,height
- curY
- mVertGap
- BORDER_SZ
- thumbLen
);
1016 // layout tab title bars
1018 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
1020 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
1024 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
1026 wxWindowDC
dc(this);
1030 // set select default font of the window into it's device context
1031 //dc.SetFont( GetLabelingFont() );
1032 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
1034 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
1035 tab
.ImgWidth() + mTitleHorizGap
*2;
1037 tab
.mDims
.y
= mTitleHeight
;
1039 pNode
= pNode
->GetNext();
1042 // disable title-bar scroller if there's nowhere to scroll to
1044 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1047 //---------------------------------------------------------------------------
1049 //---------------------------------------------------------------------------
1050 void wxPagedWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1053 DrawDecorations( dc
);
1056 //---------------------------------------------------------------------------
1057 void wxPagedWindow::OnSize ( wxSizeEvent
& event
)
1059 wxTabbedWindow::OnSize(event
);
1062 //---------------------------------------------------------------------------
1063 void wxPagedWindow::OnLButtonDown( wxMouseEvent
& event
)
1065 if ( mCursorChanged
)
1068 mDagOrigin
= event
.m_x
;
1070 mOriginalTitleRowLen
= mAdjustableTitleRowLen
;
1076 wxTabbedWindow::OnLButtonDown( event
);
1078 } // wxPagedWindow::OnLButtonDown()
1080 //---------------------------------------------------------------------------
1081 void wxPagedWindow::OnLButtonUp( wxMouseEvent
& WXUNUSED(event
) )
1086 mCursorChanged
= false;
1087 SetCursor( mNormalCursor
);
1091 } // wxPagedWindow::OnLButtonUp()
1093 //---------------------------------------------------------------------------
1094 void wxPagedWindow::OnMouseMove( wxMouseEvent
& event
)
1097 GetClientSize( &width
, &height
);
1101 int y
= height
- mVertGap
- BORDER_SZ
- mTitleHeight
;
1102 int x
= mTitleRowStart
+ mTitleRowLen
- 6;
1104 if ( event
.m_x
>= x
&& event
.m_y
>= y
&&
1105 event
.m_x
< x
+ 6 &&
1106 event
.m_y
< y
+ mTitleHeight
1109 if ( !mCursorChanged
)
1111 SetCursor( mResizeCursor
);
1113 mCursorChanged
= true;
1117 if ( mCursorChanged
)
1119 SetCursor( mNormalCursor
);
1121 mCursorChanged
= false;
1128 mAdjustableTitleRowLen
= mOriginalTitleRowLen
+ ( event
.m_x
- mDagOrigin
);
1131 if ( mAdjustableTitleRowLen
< 6 ) mAdjustableTitleRowLen
= 6;
1133 wxWindowDC
dc(this);
1134 DrawDecorations( dc
);
1136 RecalcLayout(false);
1141 } // wxPagedWindow::OnMouseMove()
1143 //---------------------------------------------------------------------------
1144 void wxPagedWindow::OnScroll( wxScrollEvent
& event
)
1146 wxScrollBar
* pSender
= (wxScrollBar
*)event
.GetEventObject();
1147 // wxMessageBox("wxPagedWindow::OnScroll","-I->");
1148 if ( pSender
== mpTabScroll
)
1151 int maxUnits
= GetWholeTabRowLen() / 20;
1153 mCurentRowOfs
= -event
.GetPosition()*maxUnits
;
1155 mFirstTitleGap
= mTitleRowStart
+ mCurentRowOfs
+ mTabTrianGap
;
1157 // let' it automatically disable itself if it's time
1158 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1160 // repaint title bars
1161 wxWindowDC
dc(this);
1162 DrawDecorations( dc
);
1166 if ( !mScrollEventInProgress
)
1168 mScrollEventInProgress
= true;
1170 GetActiveTab()->GetEventHandler()->ProcessEvent( event
);
1174 // event bounced back to us, from here we
1175 // know that it has traveled the loop - thus it's processed!
1177 mScrollEventInProgress
= false;
1180 } // wxPagedWindow::OnScroll()
1181 //---------------------------------------------------------------------------