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"
39 #include "wx/string.h"
40 #include "wx/utils.h" // import wxMin/wxMax macros and wxFileExist(..)
44 //---------------------------------------------------------------------------
45 // Implementation for class twTabInfo
46 //---------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS( twTabInfo
, wxObject
)
49 //---------------------------------------------------------------------------
50 twTabInfo::twTabInfo()
54 //---------------------------------------------------------------------------
55 int twTabInfo::ImgWidth()
57 if ( mBitMap
.Ok() ) return mBitMap
.GetWidth();
61 //---------------------------------------------------------------------------
62 int twTabInfo::ImgHeight()
65 return mBitMap
.GetHeight();
70 //---------------------------------------------------------------------------
71 int twTabInfo::ImageToTxtGap( int prefGap
)
79 //---------------------------------------------------------------------------
80 bool twTabInfo::HasImg()
85 //---------------------------------------------------------------------------
86 // bool twTabInfo::HasText();
87 unsigned int twTabInfo::HasText()
89 return mText
.Length();
92 //---------------------------------------------------------------------------
93 wxBitmap
& twTabInfo::GetImg()
98 //---------------------------------------------------------------------------
99 wxString
& twTabInfo::GetText()
104 //---------------------------------------------------------------------------
105 wxWindow
& twTabInfo::GetContent()
110 //---------------------------------------------------------------------------
111 // Implementation for class wxTabbedWindow
112 //---------------------------------------------------------------------------
113 IMPLEMENT_DYNAMIC_CLASS( wxTabbedWindow
, wxPanel
)
115 //---------------------------------------------------------------------------
116 BEGIN_EVENT_TABLE( wxTabbedWindow
, wxPanel
)
117 EVT_SIZE ( wxTabbedWindow::OnSize
)
118 EVT_PAINT( wxTabbedWindow::OnPaint
)
119 EVT_LEFT_DOWN( wxTabbedWindow::OnLButtonDown
)
120 // TDB:: filciker reduction
121 // EVT_ERASE_BACKGROUND( wxTabbedWindow::OnBkErase )
124 //---------------------------------------------------------------------------
125 wxTabbedWindow::wxTabbedWindow()
127 : mpTabScroll ( NULL
),
128 mpHorizScroll( NULL
),
129 mpVertScroll ( NULL
),
137 mFirstTitleGap( 11 ),
139 mBorderOnlyWidth( 8 ),
141 mWhitePen( wxColour(255,255,255), 1, wxSOLID
),
142 mGrayPen ( wxColour(192,192,192), 1, wxSOLID
),
143 mDarkPen ( wxColour(128,128,128), 1, wxSOLID
),
144 mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID
),
149 mLayoutType( wxTITLE_IMG_AND_TEXT
)
152 //---------------------------------------------------------------------------
153 wxTabbedWindow::~wxTabbedWindow()
155 wxObjectList::compatibility_iterator pTab
= mTabs
.GetFirst();
159 delete ((twTabInfo
*)pTab
->GetData());
160 pTab
= pTab
->GetNext();
164 //---------------------------------------------------------------------------
165 void wxTabbedWindow::SizeTabs(int x
,int y
, int width
, int height
, bool WXUNUSED(repant
))
167 wxObjectList::compatibility_iterator pTabNode
= mTabs
.GetFirst();
172 twTabInfo
& info
= *((twTabInfo
*)pTabNode
->GetData());
174 if ( n
== mActiveTab
)
177 //info.mpContent->GetEventHandler()->ProcessEvent( evt );
179 info
.mpContent
->SetSize( x
, y
, width
, height
, 0 );
180 info
.mpContent
->Show(true);
181 info
.mpContent
->Refresh();
186 info
.mpContent
->Show(false);
189 pTabNode
= pTabNode
->GetNext();
194 //---------------------------------------------------------------------------
195 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
197 wxString imageFileName
,
198 wxBitmapType imageType
)
200 twTabInfo
* pTab
= new twTabInfo();
202 pTab
->mpContent
= pContent
;
203 pTab
->mText
= tabText
;
205 if ( wxFileExists( imageFileName
) &&
207 pTab
->mBitMap
.LoadFile( imageFileName
, imageType
) )
209 pTab
->mImageFile
= imageFileName
;
210 pTab
->mImageType
= imageType
;
214 if ( pContent
->GetParent() == NULL
)
215 pContent
->Create( this, wxID_ANY
);
217 mTabs
.Append( (wxObject
*)pTab
);
224 //---------------------------------------------------------------------------
225 void wxTabbedWindow::AddTab( wxWindow
* pContent
,
226 wxString tabText
, wxBitmap
* pImage
)
228 twTabInfo
* pTab
= new twTabInfo();
230 pTab
->mpContent
= pContent
;
231 pTab
->mText
= tabText
;
234 pTab
->mBitMap
= *pImage
;
236 if ( pContent
->GetParent() == NULL
)
237 pContent
->Create( this, wxID_ANY
);
239 mTabs
.Append( (wxObject
*)pTab
);
244 //---------------------------------------------------------------------------
245 void wxTabbedWindow::RemoveTab( int tabNo
)
247 twTabInfo
* pTab
= ((twTabInfo
*)(mTabs
.Item( tabNo
)->GetData()));
248 pTab
->mpContent
->Destroy();
250 mTabs
.Erase( mTabs
.Item( tabNo
) );
251 // if ( mActiveTab >= mTabs.GetCount() );
252 if ( mActiveTab
>= mTabs
.GetCount() )
253 mActiveTab
= mTabs
.GetCount() - 1;
254 SetActiveTab( mActiveTab
);
257 //---------------------------------------------------------------------------
258 int wxTabbedWindow::GetTabCount()
260 return mTabs
.GetCount();
263 //---------------------------------------------------------------------------
264 wxWindow
* wxTabbedWindow::GetTab( int tabNo
)
266 return ((twTabInfo
*)(mTabs
.Item( tabNo
)->GetData()))->mpContent
;
269 //---------------------------------------------------------------------------
270 wxWindow
* wxTabbedWindow::GetActiveTab()
272 // FIMXE:: this is lame
273 return GetTab( mActiveTab
);
276 //---------------------------------------------------------------------------
277 void wxTabbedWindow::SetActiveTab( int tabNo
)
284 //---------------------------------------------------------------------------
285 // width of the decorations border (4 shade-lines), should not be changed
286 //---------------------------------------------------------------------------
289 //---------------------------------------------------------------------------
290 void wxTabbedWindow::DrawShadedRect( int x
, int y
, int width
, int height
,
291 wxPen
& upperPen
, wxPen
& lowerPen
, wxDC
& dc
294 // darw the lightened upper-left sides of the rectangle
296 dc
.SetPen( upperPen
);
297 dc
.DrawLine( x
,y
, x
, y
+ height
- 1 ); // vert
298 dc
.DrawLine( x
,y
, x
+ width
- 1, y
); // horiz
300 // draw the unenlightened lower-right sides of the rectangle
302 dc
.SetPen( lowerPen
);
303 dc
.DrawLine( x
+ width
- 1, y
, x
+ width
- 1, y
+ height
- 1 ); // vert
304 dc
.DrawLine( x
, y
+ height
- 1, x
+ width
, y
+ height
- 1 ); // horiz
307 //---------------------------------------------------------------------------
308 void wxTabbedWindow::DrawDecorations( wxDC
& dc
)
310 // Protability NOTE::: DrawLine(..) draws a line from the first position,
311 // but not including the point specified by last position.
312 // This way Windows draws lines, not sure how Motif and Gtk
316 GetClientSize( &width
, &height
);
318 // check if there's at least a bit of space to draw things
320 if ( width
< mHorizGap
*2 + BORDER_SZ
*2+1 ||
321 height
< mVertGap
*2 + BORDER_SZ
*2+1 + mTitleHeight
325 // step #1 - draw border around the tab content area
327 // setup position for kind of "pencil"
328 int curX
= mHorizGap
;
331 int xSize
= width
- mHorizGap
*2;
332 int ySize
= height
- mVertGap
*2 - mTitleHeight
;
334 // layer 1 (upper white)
335 DrawShadedRect( curX
+0, curY
+0, xSize
-0, ySize
-0,
336 mWhitePen
, mBlackPen
, dc
);
338 // layer 2 (upper gray)
339 DrawShadedRect( curX
+1, curY
+1, xSize
-2-1, ySize
-2-1,
340 mGrayPen
, mGrayPen
, dc
);
342 // layer 3 (upper darkGray)
343 DrawShadedRect( curX
+2, curY
+2, xSize
-3-2, ySize
-3-2,
344 mDarkPen
, mWhitePen
, dc
);
346 // layer 4 (upper black)
347 DrawShadedRect( curX
+3, curY
+3, xSize
-4-3, ySize
-4-3,
348 mBlackPen
, mGrayPen
, dc
);
350 // add non-siemtric layer from the lower-right side (confroming to MFC-look)
352 dc
.SetPen( mDarkPen
);
353 dc
.DrawLine( curX
+1, curY
+ ySize
- 2, curX
+ xSize
- 1, curY
+ ySize
- 2 ); // horiz
354 dc
.DrawLine( curX
+ xSize
- 2, curY
+ 1, curX
+ xSize
- 2, curY
+ ySize
- 2 ); // vert
356 // step #2 - draw tab title bars
358 curX
= mFirstTitleGap
;
359 curY
= height
- mVertGap
- mTitleHeight
;
362 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
366 // "hard-coded metafile" for decorations
368 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
371 ySize
= mTitleHeight
;
373 if ( tabNo
== mActiveTab
)
375 dc
.SetPen( mGrayPen
);
376 dc
.DrawLine( curX
+1, curY
-2, curX
+xSize
-2, curY
-2 );
377 dc
.DrawLine( curX
+1, curY
-1, curX
+xSize
-2, curY
-1 );
380 dc
.SetPen( mWhitePen
);
382 if ( tabNo
== mActiveTab
)
383 dc
.DrawLine( curX
, curY
-2, curX
, curY
+ySize
-2 );
385 dc
.DrawLine( curX
, curY
, curX
, curY
+ySize
-2 );
387 dc
.SetPen( mDarkPen
);
388 dc
.DrawLine( curX
+1, curY
+ySize
-3, curX
+1, curY
+ySize
-1 ); // to pix down
389 dc
.DrawLine( curX
+2, curY
+ySize
-2, curX
+xSize
-2, curY
+ySize
-2 );
390 dc
.DrawLine( curX
+xSize
-3, curY
+ySize
-3, curX
+xSize
-2, curY
+ySize
-3 );
391 if ( tabNo
== mActiveTab
)
392 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-3, curX
+xSize
-2, curY
-3 );
394 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-3, curX
+xSize
-2, curY
-1 );
396 dc
.SetPen( mBlackPen
);
397 dc
.DrawLine( curX
+xSize
-1, curY
, curX
+xSize
-1, curY
+ySize
-2 );
398 dc
.DrawLine( curX
+xSize
-2, curY
+ySize
-2, curX
+xSize
-3, curY
+ySize
-2 );
399 dc
.DrawLine( curX
+xSize
-3, curY
+ySize
-1, curX
+1, curY
+ySize
-1 );
401 pNode
= pNode
->GetNext();
404 // darw image and (or without) text centered within the
405 // title bar rectangle
407 if ( mLayoutType
!= wxTITLE_BORDER_ONLY
&& tab
.HasImg() )
410 tmpDc
.SelectObject( tab
.GetImg() );
412 dc
.Blit( curX
+ mTitleHorizGap
,
413 curY
+ ( ySize
- tab
.ImgHeight() ) / 2,
420 if ( mLayoutType
== wxTITLE_IMG_AND_TEXT
&& tab
.HasText() )
424 // set select default font of the window into it's device context
425 //dc.SetFont( GetLabelingFont() );
427 dc
.SetTextBackground( GetBackgroundColour() );
429 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
431 x
= curX
+ mTitleHorizGap
+
432 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
434 dc
.DrawText( tab
.GetText(), x
, curY
+ ( ySize
- h
) / 2 );
438 } // end of `while (pNode)'
439 } // wxTabbedWindow::DrawDecorations()
441 //---------------------------------------------------------------------------
442 int wxTabbedWindow::HitTest( const wxPoint
& pos
)
445 GetClientSize( &width
, &height
);
447 int curX
= mFirstTitleGap
;
448 int curY
= height
- mVertGap
- mTitleHeight
;
451 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
455 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
457 // hit test rectangle of the currnet tab title bar
458 if ( pos
.x
>= curX
&& pos
.x
< curX
+ tab
.mDims
.x
&&
459 pos
.y
>= curY
&& pos
.y
< curY
+ tab
.mDims
.y
467 pNode
= pNode
->GetNext();
472 } // wxTabbedWindow::HitTest()
474 //---------------------------------------------------------------------------
475 void wxTabbedWindow::HideInactiveTabs( bool andRepaint
)
480 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
485 if ( tabNo
!= mActiveTab
)
487 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
488 tab
.mpContent
->Show(false);
491 pNode
= pNode
->GetNext();
494 } // wxTabbedWindow::HideInactiveTabs()
496 //---------------------------------------------------------------------------
497 wxFont
wxTabbedWindow::GetLabelingFont()
501 font
.SetFaceName(_T("MS Sans Serif"));
503 font
.SetFamily( wxSWISS
);
508 font
.SetPointSize( 8 );
511 font
.RealizeResource();
515 } // wxTabbedWindow::GetLabelingFont()
517 //---------------------------------------------------------------------------
518 void wxTabbedWindow::RecalcLayout(bool andRepaint
)
520 HideInactiveTabs(andRepaint
);
522 // resetup position of the active tab
525 GetClientSize( &width
, &height
);
527 int curX
= mHorizGap
+ BORDER_SZ
;
528 int curY
= mVertGap
+ BORDER_SZ
;
530 int xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2-1;
531 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2-1 - mTitleHeight
;
533 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
535 // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT
537 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
539 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
541 curX
= mFirstTitleGap
; // the left-side gap
546 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
552 // set select default font of the window into it's device context
553 //dc.SetFont( GetLabelingFont() );
555 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
557 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
558 tab
.ImgWidth() + mTitleHorizGap
*2;
560 tab
.mDims
.y
= wxMax( h
, tab
.ImgHeight() ) + mTitleVertGap
*2;
561 mTitleHeight
= wxMax( mTitleHeight
, tab
.mDims
.y
);
565 pNode
= pNode
->GetNext();
568 curX
+= mHorizGap
; // the right-side gap
570 // make all title bars of equel height
572 pNode
= mTabs
.GetFirst();
576 ((twTabInfo
*)(pNode
->GetData()))->mDims
.y
= mTitleHeight
;;
577 pNode
= pNode
->GetNext();
580 // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return
581 if ( curX
< width
- mHorizGap
)
584 // pass #2 - try to layout assuming wxTITLE_IMG_ONLY
586 mLayoutType
= wxTITLE_IMG_ONLY
;
588 pNode
= mTabs
.GetFirst();
590 curX
= mFirstTitleGap
; // the left-side gap
592 int denomiator
= mTabs
.GetCount();
593 if ( denomiator
== 0 )
596 mBorderOnlyWidth
= (width
- mFirstTitleGap
- mHorizGap
) / denomiator
;
600 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
604 tab
.mDims
.x
= tab
.ImgWidth() + mTitleHorizGap
*2;
605 tab
.mDims
.y
= tab
.ImgHeight() + mTitleVertGap
*2;
609 tab
.mDims
.x
= mBorderOnlyWidth
;
610 tab
.mDims
.y
= mTitleHeight
;
615 pNode
= pNode
->GetNext();
618 curX
+= mHorizGap
; // the right-side gap
620 // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return
621 if ( curX
< width
- mHorizGap
)
624 // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY
626 mLayoutType
= wxTITLE_BORDER_ONLY
;
628 pNode
= mTabs
.GetFirst();
632 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
634 tab
.mDims
.x
= mBorderOnlyWidth
;
635 tab
.mDims
.y
= mTitleHeight
;
637 pNode
= pNode
->GetNext();
639 } // wxTabbedWindow::RecalcLayout()
641 //---------------------------------------------------------------------------
643 //---------------------------------------------------------------------------
644 void wxTabbedWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
647 DrawDecorations( dc
);
650 //---------------------------------------------------------------------------
651 void wxTabbedWindow::OnSize ( wxSizeEvent
& WXUNUSED(event
) )
653 SetBackgroundColour( wxColour( 192,192,192 ) );
657 //---------------------------------------------------------------------------
658 void wxTabbedWindow::OnBkErase( wxEraseEvent
& WXUNUSED(event
) )
663 //---------------------------------------------------------------------------
664 void wxTabbedWindow::OnLButtonDown( wxMouseEvent
& event
)
667 int x
= (int)event
.m_x
;
668 int y
= (int)event
.m_y
;
670 int tabNo
= HitTest( wxPoint(x
,y
) );
674 SetActiveTab( tabNo
);
678 //---------------------------------------------------------------------------
679 // Implementation for class wxPagedWindow
680 //---------------------------------------------------------------------------
681 IMPLEMENT_DYNAMIC_CLASS( wxPagedWindow
, wxTabbedWindow
)
683 //---------------------------------------------------------------------------
684 BEGIN_EVENT_TABLE( wxPagedWindow
, wxTabbedWindow
)
685 EVT_SIZE ( wxPagedWindow::OnSize
)
686 EVT_PAINT ( wxPagedWindow::OnPaint
)
687 EVT_LEFT_DOWN( wxPagedWindow::OnLButtonDown
)
688 EVT_LEFT_UP ( wxPagedWindow::OnLButtonUp
)
689 EVT_MOTION ( wxPagedWindow::OnMouseMove
)
690 EVT_SCROLL ( wxPagedWindow::OnScroll
)
693 //---------------------------------------------------------------------------
694 // border for paged-window is 2 shaded-lines
695 //---------------------------------------------------------------------------
699 //---------------------------------------------------------------------------
700 wxPagedWindow::wxPagedWindow()
702 : mScrollEventInProgress( false ),
704 mWhiteBrush( wxColour(255,255,255), wxSOLID
),
705 mGrayBrush ( wxColour(192,192,192), wxSOLID
),
707 mAdjustableTitleRowLen( 300 ),
708 mIsDragged ( false ),
710 mCursorChanged( false ),
711 mResizeCursor ( wxCURSOR_SIZEWE
),
712 mNormalCursor ( wxCURSOR_ARROW
)
716 mNoVertScroll
= true; // Horizontale Scroll abschalten
719 //---------------------------------------------------------------------------
720 wxFont
wxPagedWindow::GetLabelingFont()
725 font
.SetFaceName(_T("Comic Sans MS"));
727 font
.SetFamily( wxSWISS
);
732 font
.SetPointSize( 8 );
737 //---------------------------------------------------------------------------
738 void wxPagedWindow::OnTabAdded( twTabInfo
* WXUNUSED(pInfo
) )
740 int units
= GetWholeTabRowLen() / 20;
742 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, false );
745 //---------------------------------------------------------------------------
746 wxScrollBar
& wxPagedWindow::GetVerticalScrollBar()
748 return *mpVertScroll
;
751 //---------------------------------------------------------------------------
752 wxScrollBar
& wxPagedWindow::GetHorizontalScrollBar()
754 return *mpHorizScroll
;
757 //---------------------------------------------------------------------------
758 int wxPagedWindow::GetWholeTabRowLen()
760 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
766 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
769 pNode
= pNode
->GetNext();
773 } // wxPagedWindow::GetWholeTabRowLen()
775 //---------------------------------------------------------------------------
776 void wxPagedWindow::DrawPaperBar( twTabInfo
& tab
, int x
, int y
,
777 wxBrush
& brush
, wxPen
& pen
, wxDC
& dc
)
781 // draw organizer-style paper outlet
783 poly
[0].x
= x
- mTabTrianGap
;
786 poly
[1].x
= x
+ mTabTrianGap
;
787 poly
[1].y
= y
+ tab
.mDims
.y
-1;
789 poly
[2].x
= x
+ tab
.mDims
.x
- mTabTrianGap
;
790 poly
[2].y
= y
+ tab
.mDims
.y
-1;
792 poly
[3].x
= x
+ tab
.mDims
.x
+ mTabTrianGap
;
796 dc
.SetBrush( brush
);
798 dc
.DrawPolygon( 4, poly
);
802 // set select default font of the window into it's device context
803 //dc.SetFont( GetLabelingFont() );
805 dc
.SetTextBackground( brush
.GetColour() );
807 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
812 tmpDc
.SelectObject( tab
.GetImg() );
814 dc
.Blit( x
+ mTitleHorizGap
,
815 y
+ ( tab
.mDims
.y
- tab
.ImgHeight() ) / 2,
824 int tx
= x
+ mTitleHorizGap
+
825 tab
.ImgWidth() + tab
.ImageToTxtGap(mImageTextGap
);
827 dc
.DrawText( tab
.GetText(), tx
, y
+ ( tab
.mDims
.y
- h
) / 2 );
829 } // wxPagedWindow::DrawPaperBar()
831 //---------------------------------------------------------------------------
832 void wxPagedWindow::DrawDecorations( wxDC
& dc
)
834 // FIXME:: the is big body have to be split!
837 GetClientSize( &width
, &height
);
839 int curX
= mHorizGap
;
842 int xSize
= width
- mHorizGap
*2;
843 int ySize
= height
- mVertGap
*2;
845 DrawShadedRect( curX
, curY
, xSize
, ySize
,
846 mDarkPen
, mWhitePen
, dc
);
848 DrawShadedRect( curX
+1, curY
+1, xSize
-2, ySize
-2,
849 mBlackPen
, mGrayPen
, dc
);
851 // draw inactive tab title bars frist (left-to-right)
853 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
857 curX = mTitleRowStart;
858 curY = height - mVertGap - BORDER_SZ - mTitleHeight;
864 // FOR NOW:: avoid creating bitmap with invalid dimensions
866 if ( mTitleRowLen
< 1 || mTitleHeight
< 1 )
870 wxBitmap
tmpBmp( mTitleRowLen
, mTitleHeight
);
872 tmpDc
.SelectObject( tmpBmp
);
873 tmpDc
.SetPen( mGrayPen
);
874 tmpDc
.SetBrush( mGrayBrush
);
875 tmpDc
.DrawRectangle( 0,0, mTitleRowLen
, mTitleHeight
);
877 tmpDc
.SetDeviceOrigin( mCurentRowOfs
, 0 );
881 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
883 if ( tabNo
!= mActiveTab
)
884 DrawPaperBar( tab
, curX
, curY
, mGrayBrush
, mBlackPen
, tmpDc
);
888 pNode
= pNode
->GetNext();
892 // finally, draw the active tab (white-filled)
894 pNode
= mTabs
.GetFirst();
901 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
903 if ( tabNo
== mActiveTab
)
905 DrawPaperBar( tab
, curX
, curY
, mWhiteBrush
, mBlackPen
, tmpDc
);
907 tmpDc
.SetPen( mWhitePen
);
909 tmpDc
.DrawLine( curX
- mTabTrianGap
+1, curY
,
910 curX
+ tab
.mDims
.x
+ mTabTrianGap
, curY
);
915 pNode
= pNode
->GetNext();
919 // back to initial device origin
921 tmpDc
.SetDeviceOrigin( 0, 0 );
923 // draw resize-hint-stick
925 curX
= mTitleRowLen
- 6;
927 DrawShadedRect( curX
+0, 0+0, 6, mTitleHeight
, mGrayPen
, mBlackPen
, tmpDc
);
928 DrawShadedRect( curX
+1, 0+1, 6-2, mTitleHeight
-2, mWhitePen
, mDarkPen
, tmpDc
);
929 DrawShadedRect( curX
+2, 0+2, 6-4, mTitleHeight
-4, mGrayPen
, mGrayPen
, tmpDc
);
933 dc
.Blit( mTitleRowStart
,
934 height
- mVertGap
- BORDER_SZ
- mTitleHeight
,
935 mTitleRowLen
, mTitleHeight
,
936 &tmpDc
, 0,0, wxCOPY
);
937 } // wxPagedWindow::DrawDecorations()
939 //---------------------------------------------------------------------------
940 int wxPagedWindow::HitTest( const wxPoint
& pos
)
942 return wxTabbedWindow::HitTest( pos
);
945 //---------------------------------------------------------------------------
946 void wxPagedWindow::RecalcLayout(bool andRepaint
)
948 mTitleRowLen
= mAdjustableTitleRowLen
;
950 if ( int(mpTabScroll
) == -1 ) return;
952 // scroll bars should be created after Create() for this window is called
956 new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
959 new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_HORIZONTAL
);
960 if (!mNoVertScroll
) // Vertical Scroll (Original)
961 mpVertScroll
= new wxScrollBar( this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSB_VERTICAL
);
965 int units
= GetWholeTabRowLen() / 20;
967 mpTabScroll
->SetScrollbar( 0, 1, units
, 1, false );
970 // resetup position of the active tab
972 int thumbLen
= 16; // FOR NOW:: hardcoded
975 GetClientSize( &width
, &height
);
977 mTitleHeight
= thumbLen
;
979 int curX
= mHorizGap
+ BORDER_SZ
;
980 int curY
= mVertGap
+ BORDER_SZ
;
983 if (!mNoVertScroll
) // Vertical Scroll (Original)
984 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2 - thumbLen
;
986 xSize
= width
- mHorizGap
*2 - BORDER_SZ
*2;
988 int ySize
= height
- mVertGap
*2 - BORDER_SZ
*2 - mTitleHeight
;
990 SizeTabs( curX
, curY
, xSize
, ySize
, andRepaint
);
992 // setup title bar LINES's horizontal scroll bar
994 curY
= height
- mVertGap
- BORDER_SZ
- thumbLen
;
996 mpTabScroll
->SetSize( curX
, curY
, thumbLen
*2, thumbLen
);
998 // setup view's HORIZONTAL scroll bar
1001 mTitleRowStart
= curX
;
1002 mFirstTitleGap
= curX
+ mCurentRowOfs
+ mTabTrianGap
;
1004 mTitleRowLen
= wxMin( mAdjustableTitleRowLen
,
1005 width
- mHorizGap
- BORDER_SZ
- thumbLen
*4 - curX
);
1007 curX
+= mTitleRowLen
;
1009 if (!mNoVertScroll
) // Vertical Scroll (Original)
1010 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
- thumbLen
, thumbLen
);
1012 mpHorizScroll
->SetSize( curX
, curY
,width
- curX
- mHorizGap
- BORDER_SZ
-4, thumbLen
);
1014 // setup view's VERTICAL scroll bar
1015 if (!mNoVertScroll
) // Vertical Scroll (Original)
1017 curX
= width
- mHorizGap
- BORDER_SZ
- thumbLen
;
1018 curY
= mVertGap
+ BORDER_SZ
;
1019 mpVertScroll
->SetSize( curX
, curY
, thumbLen
,height
- curY
- mVertGap
- BORDER_SZ
- thumbLen
);
1021 // layout tab title bars
1023 mLayoutType
= wxTITLE_IMG_AND_TEXT
;
1025 wxObjectList::compatibility_iterator pNode
= mTabs
.GetFirst();
1029 twTabInfo
& tab
= *((twTabInfo
*)(pNode
->GetData()));
1031 wxWindowDC
dc(this);
1035 // set select default font of the window into it's device context
1036 //dc.SetFont( GetLabelingFont() );
1037 dc
.GetTextExtent(tab
.mText
, &w
, &h
);
1039 tab
.mDims
.x
= w
+ tab
.ImageToTxtGap(mImageTextGap
) +
1040 tab
.ImgWidth() + mTitleHorizGap
*2;
1042 tab
.mDims
.y
= mTitleHeight
;
1044 pNode
= pNode
->GetNext();
1047 // disable title-bar scroller if there's nowhere to scroll to
1049 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1052 //---------------------------------------------------------------------------
1054 //---------------------------------------------------------------------------
1055 void wxPagedWindow::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1058 DrawDecorations( dc
);
1061 //---------------------------------------------------------------------------
1062 void wxPagedWindow::OnSize ( wxSizeEvent
& event
)
1064 wxTabbedWindow::OnSize(event
);
1067 //---------------------------------------------------------------------------
1068 void wxPagedWindow::OnLButtonDown( wxMouseEvent
& event
)
1070 if ( mCursorChanged
)
1073 mDagOrigin
= event
.m_x
;
1075 mOriginalTitleRowLen
= mAdjustableTitleRowLen
;
1081 wxTabbedWindow::OnLButtonDown( event
);
1083 } // wxPagedWindow::OnLButtonDown()
1085 //---------------------------------------------------------------------------
1086 void wxPagedWindow::OnLButtonUp( wxMouseEvent
& WXUNUSED(event
) )
1091 mCursorChanged
= false;
1092 SetCursor( mNormalCursor
);
1096 } // wxPagedWindow::OnLButtonUp()
1098 //---------------------------------------------------------------------------
1099 void wxPagedWindow::OnMouseMove( wxMouseEvent
& event
)
1102 GetClientSize( &width
, &height
);
1106 int y
= height
- mVertGap
- BORDER_SZ
- mTitleHeight
;
1107 int x
= mTitleRowStart
+ mTitleRowLen
- 6;
1109 if ( event
.m_x
>= x
&& event
.m_y
>= y
&&
1110 event
.m_x
< x
+ 6 &&
1111 event
.m_y
< y
+ mTitleHeight
1114 if ( !mCursorChanged
)
1116 SetCursor( mResizeCursor
);
1118 mCursorChanged
= true;
1122 if ( mCursorChanged
)
1124 SetCursor( mNormalCursor
);
1126 mCursorChanged
= false;
1133 mAdjustableTitleRowLen
= mOriginalTitleRowLen
+ ( event
.m_x
- mDagOrigin
);
1136 if ( mAdjustableTitleRowLen
< 6 ) mAdjustableTitleRowLen
= 6;
1138 wxWindowDC
dc(this);
1139 DrawDecorations( dc
);
1141 RecalcLayout(false);
1146 } // wxPagedWindow::OnMouseMove()
1148 //---------------------------------------------------------------------------
1149 void wxPagedWindow::OnScroll( wxScrollEvent
& event
)
1151 wxScrollBar
* pSender
= (wxScrollBar
*)event
.GetEventObject();
1152 // wxMessageBox("wxPagedWindow::OnScroll","-I->");
1153 if ( pSender
== mpTabScroll
)
1156 int maxUnits
= GetWholeTabRowLen() / 20;
1158 mCurentRowOfs
= -event
.GetPosition()*maxUnits
;
1160 mFirstTitleGap
= mTitleRowStart
+ mCurentRowOfs
+ mTabTrianGap
;
1162 // let' it automatically disable itself if it's time
1163 mpTabScroll
->Enable( mTitleRowLen
< GetWholeTabRowLen() || mCurentRowOfs
< 0 );
1165 // repaint title bars
1166 wxWindowDC
dc(this);
1167 DrawDecorations( dc
);
1171 if ( !mScrollEventInProgress
)
1173 mScrollEventInProgress
= true;
1175 GetActiveTab()->GetEventHandler()->ProcessEvent( event
);
1179 // event bounced back to us, from here we
1180 // know that it has traveled the loop - thus it's processed!
1182 mScrollEventInProgress
= false;
1185 } // wxPagedWindow::OnScroll()
1186 //---------------------------------------------------------------------------