]> git.saurik.com Git - wxWidgets.git/blob - demos/dbbrowse/tabpgwin.cpp
Correction of a commented out line of code so that if ever uncommented, it will work...
[wxWidgets.git] / demos / dbbrowse / tabpgwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tabpgwin.cpp
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.
13 // Created: 07/09/98
14 // RCS-ID: $Id$
15 // Copyright: (c) Aleksandras Gluchovas
16 // Licence: wxWindows license
17 /////////////////////////////////////////////////////////////////////////////
18
19 #ifdef __GNUG__
20 #pragma implementation
21 //#pragma interface
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/wx.h"
33 #endif
34
35 #include <math.h>
36 #include <stdlib.h>
37
38 #include "wx/string.h"
39 #include "wx/utils.h" // import wxMin/wxMax macros and wxFileExist(..)
40
41 #include "tabpgwin.h"
42
43 //---------------------------------------------------------------------------
44 // Implementation for class twTabInfo
45 //---------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS( twTabInfo, wxObject )
47
48 //---------------------------------------------------------------------------
49 twTabInfo::twTabInfo()
50 : mpContent( 0 )
51 {}
52
53 //---------------------------------------------------------------------------
54 int twTabInfo::ImgWidth()
55 {
56 if ( mBitMap.Ok() ) return mBitMap.GetWidth();
57 else return 0;
58 }
59
60 //---------------------------------------------------------------------------
61 int twTabInfo::ImgHeight()
62 {
63 if ( mBitMap.Ok() )
64 return mBitMap.GetHeight();
65 else
66 return 0;
67 }
68
69 //---------------------------------------------------------------------------
70 int twTabInfo::ImageToTxtGap( int prefGap )
71 {
72 if ( mBitMap.Ok() )
73 return prefGap;
74 else
75 return 0;
76 }
77
78 //---------------------------------------------------------------------------
79 bool twTabInfo::HasImg()
80 {
81 return mBitMap.Ok();
82 }
83
84 //---------------------------------------------------------------------------
85 // bool twTabInfo::HasText();
86 unsigned int twTabInfo::HasText()
87 {
88 return mText.Length();
89 }
90
91 //---------------------------------------------------------------------------
92 wxBitmap& twTabInfo::GetImg()
93 {
94 return mBitMap;
95 }
96
97 //---------------------------------------------------------------------------
98 wxString& twTabInfo::GetText()
99 {
100 return mText;
101 }
102
103 //---------------------------------------------------------------------------
104 wxWindow& twTabInfo::GetContent()
105 {
106 return *mpContent;
107 }
108
109 //---------------------------------------------------------------------------
110 // Implementation for class wxTabbedWindow
111 //---------------------------------------------------------------------------
112 IMPLEMENT_DYNAMIC_CLASS( wxTabbedWindow, wxPanel )
113
114 //---------------------------------------------------------------------------
115 BEGIN_EVENT_TABLE( wxTabbedWindow, wxPanel )
116 EVT_SIZE ( wxTabbedWindow::OnSize )
117 EVT_PAINT( wxTabbedWindow::OnPaint )
118 EVT_LEFT_DOWN( wxTabbedWindow::OnLButtonDown )
119 // TDB:: filciker reduction
120 // EVT_ERASE_BACKGROUND( wxTabbedWindow::OnBkErase )
121 END_EVENT_TABLE()
122
123 //---------------------------------------------------------------------------
124 wxTabbedWindow::wxTabbedWindow()
125
126 : mpTabScroll ( NULL ),
127 mpHorizScroll( NULL ),
128 mpVertScroll ( NULL ),
129
130 mVertGap ( 0 ),
131 mHorizGap( 0 ),
132
133 mTitleVertGap ( 3 ),
134 mTitleHorizGap( 4 ),
135 mImageTextGap ( 2 ),
136 mFirstTitleGap( 11 ),
137
138 mBorderOnlyWidth( 8 ),
139
140 mWhitePen( wxColour(255,255,255), 1, wxSOLID ),
141 mGrayPen ( wxColour(192,192,192), 1, wxSOLID ),
142 mDarkPen ( wxColour(128,128,128), 1, wxSOLID ),
143 mBlackPen( wxColour( 0, 0, 0), 1, wxSOLID ),
144
145 // state variables
146 mActiveTab ( 0 ),
147 mTitleHeight( 0 ),
148 mLayoutType( wxTITLE_IMG_AND_TEXT )
149 {}
150
151 //---------------------------------------------------------------------------
152 wxTabbedWindow::~wxTabbedWindow()
153 {
154 wxObjectList::compatibility_iterator pTab = mTabs.GetFirst();
155
156 while( pTab )
157 {
158 delete ((twTabInfo*)pTab->GetData());
159 pTab = pTab->GetNext();
160 }
161 }
162
163 //---------------------------------------------------------------------------
164 void wxTabbedWindow::SizeTabs(int x,int y, int width, int height, bool WXUNUSED(repant))
165 {
166 wxObjectList::compatibility_iterator pTabNode = mTabs.GetFirst();
167 size_t n = 0;
168
169 while( pTabNode )
170 {
171 twTabInfo& info = *((twTabInfo*)pTabNode->GetData());
172
173 if ( n == mActiveTab )
174 {
175 //wxSizeEvent evt;
176 //info.mpContent->GetEventHandler()->ProcessEvent( evt );
177
178 info.mpContent->SetSize( x, y, width, height, 0 );
179 info.mpContent->Show(true);
180 info.mpContent->Refresh();
181
182 }
183 else
184 {
185 info.mpContent->Show(false);
186 }
187
188 pTabNode = pTabNode->GetNext();
189 ++n;
190 }
191 }
192
193 //---------------------------------------------------------------------------
194 void wxTabbedWindow::AddTab( wxWindow* pContent,
195 wxString tabText,
196 wxString imageFileName,
197 wxBitmapType imageType )
198 {
199 twTabInfo* pTab = new twTabInfo();
200
201 pTab->mpContent = pContent;
202 pTab->mText = tabText;
203
204 if ( wxFileExists( imageFileName ) &&
205
206 pTab->mBitMap.LoadFile( imageFileName, imageType ) )
207 {
208 pTab->mImageFile = imageFileName;
209 pTab->mImageType = imageType;
210 }
211
212
213 if ( pContent->GetParent() == NULL )
214 pContent->Create( this, wxID_ANY );
215
216 mTabs.Append( (wxObject*)pTab );
217
218 RecalcLayout(true);
219
220 OnTabAdded( pTab );
221 }
222
223 //---------------------------------------------------------------------------
224 void wxTabbedWindow::AddTab( wxWindow* pContent,
225 wxString tabText, wxBitmap* pImage )
226 {
227 twTabInfo* pTab = new twTabInfo();
228
229 pTab->mpContent = pContent;
230 pTab->mText = tabText;
231
232 if ( pImage )
233 pTab->mBitMap = *pImage;
234
235 if ( pContent->GetParent() == NULL )
236 pContent->Create( this, wxID_ANY );
237
238 mTabs.Append( (wxObject*)pTab );
239 RecalcLayout(true);
240 OnTabAdded( pTab );
241 }
242
243 //---------------------------------------------------------------------------
244 void wxTabbedWindow::RemoveTab( int tabNo )
245 {
246 twTabInfo* pTab = ((twTabInfo*)(mTabs.Item( tabNo )->GetData()));
247 pTab->mpContent->Destroy();
248 delete pTab;
249 mTabs.Erase( mTabs.Item( tabNo ) );
250 // if ( mActiveTab >= mTabs.GetCount() );
251 if ( mActiveTab >= mTabs.GetCount() )
252 mActiveTab = mTabs.GetCount() - 1;
253 SetActiveTab( mActiveTab );
254 }
255
256 //---------------------------------------------------------------------------
257 int wxTabbedWindow::GetTabCount()
258 {
259 return mTabs.GetCount();
260 }
261
262 //---------------------------------------------------------------------------
263 wxWindow* wxTabbedWindow::GetTab( int tabNo )
264 {
265 return ((twTabInfo*)(mTabs.Item( tabNo )->GetData()))->mpContent;
266 }
267
268 //---------------------------------------------------------------------------
269 wxWindow* wxTabbedWindow::GetActiveTab()
270 {
271 // FIMXE:: this is lame
272 return GetTab( mActiveTab );
273 }
274
275 //---------------------------------------------------------------------------
276 void wxTabbedWindow::SetActiveTab( int tabNo )
277 {
278 mActiveTab = tabNo;
279 RecalcLayout(true);
280 Refresh();
281 }
282
283 //---------------------------------------------------------------------------
284 // width of the decorations border (4 shade-lines), should not be changed
285 //---------------------------------------------------------------------------
286 #define BORDER_SZ 4
287
288 //---------------------------------------------------------------------------
289 void wxTabbedWindow::DrawShadedRect( int x, int y, int width, int height,
290 wxPen& upperPen, wxPen& lowerPen, wxDC& dc
291 )
292 {
293 // darw the lightened upper-left sides of the rectangle
294
295 dc.SetPen( upperPen );
296 dc.DrawLine( x,y, x, y + height - 1 ); // vert
297 dc.DrawLine( x,y, x + width - 1, y ); // horiz
298
299 // draw the unenlightened lower-right sides of the rectangle
300
301 dc.SetPen( lowerPen );
302 dc.DrawLine( x + width - 1, y, x + width - 1, y + height - 1 ); // vert
303 dc.DrawLine( x, y + height - 1, x + width, y + height - 1 ); // horiz
304 }
305
306 //---------------------------------------------------------------------------
307 void wxTabbedWindow::DrawDecorations( wxDC& dc )
308 {
309 // Protability NOTE::: DrawLine(..) draws a line from the first position,
310 // but not including the point specified by last position.
311 // This way Windows draws lines, not sure how Motif and Gtk
312 // prots behave...
313
314 int width, height;
315 GetClientSize( &width, &height );
316
317 // check if there's at least a bit of space to draw things
318
319 if ( width < mHorizGap*2 + BORDER_SZ*2+1 ||
320 height < mVertGap*2 + BORDER_SZ*2+1 + mTitleHeight
321 )
322 return;
323
324 // step #1 - draw border around the tab content area
325
326 // setup position for kind of "pencil"
327 int curX = mHorizGap;
328 int curY = mVertGap;
329
330 int xSize = width - mHorizGap*2;
331 int ySize = height - mVertGap *2 - mTitleHeight;
332
333 // layer 1 (upper white)
334 DrawShadedRect( curX+0, curY+0, xSize-0, ySize-0,
335 mWhitePen, mBlackPen, dc );
336
337 // layer 2 (upper gray)
338 DrawShadedRect( curX+1, curY+1, xSize-2-1, ySize-2-1,
339 mGrayPen, mGrayPen, dc );
340
341 // layer 3 (upper darkGray)
342 DrawShadedRect( curX+2, curY+2, xSize-3-2, ySize-3-2,
343 mDarkPen, mWhitePen, dc );
344
345 // layer 4 (upper black)
346 DrawShadedRect( curX+3, curY+3, xSize-4-3, ySize-4-3,
347 mBlackPen, mGrayPen, dc );
348
349 // add non-siemtric layer from the lower-right side (confroming to MFC-look)
350
351 dc.SetPen( mDarkPen );
352 dc.DrawLine( curX+1, curY + ySize - 2, curX + xSize - 1, curY + ySize - 2 ); // horiz
353 dc.DrawLine( curX + xSize - 2, curY + 1, curX + xSize - 2, curY + ySize - 2 ); // vert
354
355 // step #2 - draw tab title bars
356
357 curX = mFirstTitleGap;
358 curY = height - mVertGap - mTitleHeight;
359
360 size_t tabNo = 0;
361 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
362
363 while( pNode )
364 {
365 // "hard-coded metafile" for decorations
366
367 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
368
369 xSize = tab.mDims.x;
370 ySize = mTitleHeight;
371
372 if ( tabNo == mActiveTab )
373 {
374 dc.SetPen( mGrayPen );
375 dc.DrawLine( curX+1, curY-2, curX+xSize-2, curY-2 );
376 dc.DrawLine( curX+1, curY-1, curX+xSize-2, curY-1 );
377 }
378
379 dc.SetPen( mWhitePen );
380
381 if ( tabNo == mActiveTab )
382 dc.DrawLine( curX, curY-2, curX, curY+ySize-2 );
383 else
384 dc.DrawLine( curX, curY, curX, curY+ySize-2 );
385
386 dc.SetPen( mDarkPen );
387 dc.DrawLine( curX+1, curY+ySize-3, curX+1, curY+ySize-1 ); // to pix down
388 dc.DrawLine( curX+2, curY+ySize-2, curX+xSize-2, curY+ySize-2 );
389 dc.DrawLine( curX+xSize-3, curY+ySize-3, curX+xSize-2, curY+ySize-3 );
390 if ( tabNo == mActiveTab )
391 dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-3 );
392 else
393 dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-1 );
394
395 dc.SetPen( mBlackPen );
396 dc.DrawLine( curX+xSize-1, curY, curX+xSize-1, curY+ySize-2 );
397 dc.DrawLine( curX+xSize-2, curY+ySize-2, curX+xSize-3, curY+ySize-2 );
398 dc.DrawLine( curX+xSize-3, curY+ySize-1, curX+1, curY+ySize-1 );
399
400 pNode = pNode->GetNext();
401 ++tabNo;
402
403 // darw image and (or without) text centered within the
404 // title bar rectangle
405
406 if ( mLayoutType != wxTITLE_BORDER_ONLY && tab.HasImg() )
407 {
408 wxMemoryDC tmpDc;
409 tmpDc.SelectObject( tab.GetImg() );
410
411 dc.Blit( curX + mTitleHorizGap,
412 curY + ( ySize - tab.ImgHeight() ) / 2,
413 tab.ImgWidth(),
414 tab.ImgHeight(),
415 &tmpDc, 0, 0, wxCOPY
416 );
417 }
418
419 if ( mLayoutType == wxTITLE_IMG_AND_TEXT && tab.HasText() )
420 {
421 long x,w,h;
422
423 // set select default font of the window into it's device context
424 //dc.SetFont( GetLabelingFont() );
425
426 dc.SetTextBackground( GetBackgroundColour() );
427
428 dc.GetTextExtent(tab.mText, &w, &h );
429
430 x = curX + mTitleHorizGap +
431 tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap);
432
433 dc.DrawText( tab.GetText(), x, curY + ( ySize - h ) / 2 );
434 }
435 curX += xSize;
436
437 } // end of `while (pNode)'
438 } // wxTabbedWindow::DrawDecorations()
439
440 //---------------------------------------------------------------------------
441 int wxTabbedWindow::HitTest( const wxPoint& pos )
442 {
443 int width, height;
444 GetClientSize( &width, &height );
445
446 int curX = mFirstTitleGap;
447 int curY = height - mVertGap - mTitleHeight;
448
449 int tabNo = 0;
450 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
451
452 while( pNode )
453 {
454 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
455
456 // hit test rectangle of the currnet tab title bar
457 if ( pos.x >= curX && pos.x < curX + tab.mDims.x &&
458 pos.y >= curY && pos.y < curY + tab.mDims.y
459 )
460 {
461 return tabNo;
462 }
463
464 curX += tab.mDims.x;
465
466 pNode = pNode->GetNext();
467 ++tabNo;
468 }
469
470 return -1;
471 } // wxTabbedWindow::HitTest()
472
473 //---------------------------------------------------------------------------
474 void wxTabbedWindow::HideInactiveTabs( bool andRepaint )
475 {
476 if ( !andRepaint )
477 return;
478
479 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
480 size_t tabNo = 0;
481
482 while( pNode )
483 {
484 if ( tabNo != mActiveTab )
485 {
486 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
487 tab.mpContent->Show(false);
488 }
489
490 pNode = pNode->GetNext();
491 ++tabNo;
492 }
493 } // wxTabbedWindow::HideInactiveTabs()
494
495 //---------------------------------------------------------------------------
496 wxFont wxTabbedWindow::GetLabelingFont()
497 {
498 wxFont font;
499 #ifdef __WINDOWS__
500 font.SetFaceName(_T("MS Sans Serif"));
501 #else
502 font.SetFamily( wxSWISS );
503 #endif
504
505 font.SetStyle(40);
506 font.SetWeight(40);
507 font.SetPointSize( 8 );
508
509 #ifdef __WINDOWS__
510 font.RealizeResource();
511 #endif
512
513 return font;
514 } // wxTabbedWindow::GetLabelingFont()
515
516 //---------------------------------------------------------------------------
517 void wxTabbedWindow::RecalcLayout(bool andRepaint)
518 {
519 HideInactiveTabs(andRepaint);
520
521 // resetup position of the active tab
522
523 int width, height;
524 GetClientSize( &width, &height );
525
526 int curX = mHorizGap + BORDER_SZ;
527 int curY = mVertGap + BORDER_SZ;
528
529 int xSize = width - mHorizGap*2 - BORDER_SZ*2-1;
530 int ySize = height - mVertGap*2 - BORDER_SZ*2-1 - mTitleHeight;
531
532 SizeTabs( curX, curY, xSize, ySize, andRepaint );
533
534 // pass #1 - try to layout assuming it's wxTITLE_IMG_AND_TEXT
535
536 mLayoutType = wxTITLE_IMG_AND_TEXT;
537
538 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
539
540 curX = mFirstTitleGap; // the left-side gap
541 mTitleHeight = 0;
542
543 while( pNode )
544 {
545 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
546
547 wxWindowDC dc(this);
548
549 long w,h;
550
551 // set select default font of the window into it's device context
552 //dc.SetFont( GetLabelingFont() );
553
554 dc.GetTextExtent(tab.mText, &w, &h );
555
556 tab.mDims.x = w + tab.ImageToTxtGap(mImageTextGap) +
557 tab.ImgWidth() + mTitleHorizGap*2;
558
559 tab.mDims.y = wxMax( h, tab.ImgHeight() ) + mTitleVertGap*2;
560 mTitleHeight = wxMax( mTitleHeight, tab.mDims.y );
561
562 curX += tab.mDims.x;
563
564 pNode = pNode->GetNext();
565 }
566
567 curX += mHorizGap; // the right-side gap
568
569 // make all title bars of equel height
570
571 pNode = mTabs.GetFirst();
572
573 while( pNode )
574 {
575 ((twTabInfo*)(pNode->GetData()))->mDims.y = mTitleHeight;;
576 pNode = pNode->GetNext();
577 }
578
579 // if curX has'nt ran out of bounds, leave TITLE_IMG layout and return
580 if ( curX < width - mHorizGap )
581 return;
582
583 // pass #2 - try to layout assuming wxTITLE_IMG_ONLY
584
585 mLayoutType = wxTITLE_IMG_ONLY;
586
587 pNode = mTabs.GetFirst();
588
589 curX = mFirstTitleGap; // the left-side gap
590
591 int denomiator = mTabs.GetCount();
592 if ( denomiator == 0 )
593 ++denomiator;
594
595 mBorderOnlyWidth = (width - mFirstTitleGap - mHorizGap) / denomiator;
596
597 while( pNode )
598 {
599 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
600
601 if ( tab.HasImg() )
602 {
603 tab.mDims.x = tab.ImgWidth() + mTitleHorizGap*2;
604 tab.mDims.y = tab.ImgHeight() + mTitleVertGap*2;
605 }
606 else
607 {
608 tab.mDims.x = mBorderOnlyWidth;
609 tab.mDims.y = mTitleHeight;
610 }
611
612 curX += tab.mDims.x;
613
614 pNode = pNode->GetNext();
615 }
616
617 curX += mHorizGap; // the right-side gap
618
619 // if curX has'nt ran out of bounds, leave IMG_ONLY layout and return
620 if ( curX < width - mHorizGap )
621 return;
622
623 // pass #3 - set the narrowest layout wxTITLE_BORDER_ONLY
624
625 mLayoutType = wxTITLE_BORDER_ONLY;
626
627 pNode = mTabs.GetFirst();
628
629 while( pNode )
630 {
631 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
632
633 tab.mDims.x = mBorderOnlyWidth;
634 tab.mDims.y = mTitleHeight;
635
636 pNode = pNode->GetNext();
637 }
638 } // wxTabbedWindow::RecalcLayout()
639
640 //---------------------------------------------------------------------------
641 // wx event handlers
642 //---------------------------------------------------------------------------
643 void wxTabbedWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
644 {
645 wxPaintDC dc(this);
646 DrawDecorations( dc );
647 }
648
649 //---------------------------------------------------------------------------
650 void wxTabbedWindow::OnSize ( wxSizeEvent& WXUNUSED(event) )
651 {
652 SetBackgroundColour( wxColour( 192,192,192 ) );
653 RecalcLayout(true);
654 }
655
656 //---------------------------------------------------------------------------
657 void wxTabbedWindow::OnBkErase( wxEraseEvent& WXUNUSED(event) )
658 {
659 // do nothing
660 }
661
662 //---------------------------------------------------------------------------
663 void wxTabbedWindow::OnLButtonDown( wxMouseEvent& event )
664 {
665 // floats, why?
666 int x = (int)event.m_x;
667 int y = (int)event.m_y;
668
669 int tabNo = HitTest( wxPoint(x,y) );
670
671 if ( tabNo != -1 )
672 {
673 SetActiveTab( tabNo );
674 }
675 }
676
677 //---------------------------------------------------------------------------
678 // Implementation for class wxPagedWindow
679 //---------------------------------------------------------------------------
680 IMPLEMENT_DYNAMIC_CLASS( wxPagedWindow, wxTabbedWindow )
681
682 //---------------------------------------------------------------------------
683 BEGIN_EVENT_TABLE( wxPagedWindow, wxTabbedWindow )
684 EVT_SIZE ( wxPagedWindow::OnSize )
685 EVT_PAINT ( wxPagedWindow::OnPaint )
686 EVT_LEFT_DOWN( wxPagedWindow::OnLButtonDown )
687 EVT_LEFT_UP ( wxPagedWindow::OnLButtonUp )
688 EVT_MOTION ( wxPagedWindow::OnMouseMove )
689 EVT_SCROLL ( wxPagedWindow::OnScroll )
690 END_EVENT_TABLE()
691
692 //---------------------------------------------------------------------------
693 // border for paged-window is 2 shaded-lines
694 //---------------------------------------------------------------------------
695 #undef BORDER_SZ
696 #define BORDER_SZ 2
697
698 //---------------------------------------------------------------------------
699 wxPagedWindow::wxPagedWindow()
700
701 : mScrollEventInProgress( false ),
702 mTabTrianGap(4),
703 mWhiteBrush( wxColour(255,255,255), wxSOLID ),
704 mGrayBrush ( wxColour(192,192,192), wxSOLID ),
705 mCurentRowOfs( 0 ),
706 mAdjustableTitleRowLen( 300 ),
707 mIsDragged ( false ),
708 mDagOrigin ( 0 ),
709 mCursorChanged( false ),
710 mResizeCursor ( wxCURSOR_SIZEWE ),
711 mNormalCursor ( wxCURSOR_ARROW )
712 {
713 mTitleVertGap = 2;
714 mTitleHorizGap = 10;
715 mNoVertScroll = true; // Horizontale Scroll abschalten
716 }
717
718 //---------------------------------------------------------------------------
719 wxFont wxPagedWindow::GetLabelingFont()
720 {
721 wxFont font;
722
723 #ifdef __WINDOWS__
724 font.SetFaceName(_T("Comic Sans MS"));
725 #else
726 font.SetFamily( wxSWISS );
727 #endif
728
729 font.SetStyle(40);
730 font.SetWeight(40);
731 font.SetPointSize( 8 );
732
733 return font;
734 }
735
736 //---------------------------------------------------------------------------
737 void wxPagedWindow::OnTabAdded( twTabInfo* WXUNUSED(pInfo) )
738 {
739 int units = GetWholeTabRowLen() / 20;
740
741 mpTabScroll->SetScrollbar( 0, 1, units, 1, false );
742 }
743
744 //---------------------------------------------------------------------------
745 wxScrollBar& wxPagedWindow::GetVerticalScrollBar()
746 {
747 return *mpVertScroll;
748 }
749
750 //---------------------------------------------------------------------------
751 wxScrollBar& wxPagedWindow::GetHorizontalScrollBar()
752 {
753 return *mpHorizScroll;
754 }
755
756 //---------------------------------------------------------------------------
757 int wxPagedWindow::GetWholeTabRowLen()
758 {
759 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
760
761 int len = 0;
762
763 while( pNode )
764 {
765 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
766
767 len += tab.mDims.x;
768 pNode = pNode->GetNext();
769 }
770
771 return len;
772 } // wxPagedWindow::GetWholeTabRowLen()
773
774 //---------------------------------------------------------------------------
775 void wxPagedWindow::DrawPaperBar( twTabInfo& tab, int x, int y,
776 wxBrush& brush, wxPen& pen, wxDC& dc )
777 {
778 wxPoint poly[4];
779
780 // draw organizer-style paper outlet
781
782 poly[0].x = x - mTabTrianGap;
783 poly[0].y = y;
784
785 poly[1].x = x + mTabTrianGap;
786 poly[1].y = y + tab.mDims.y-1;
787
788 poly[2].x = x + tab.mDims.x - mTabTrianGap;
789 poly[2].y = y + tab.mDims.y-1;
790
791 poly[3].x = x + tab.mDims.x + mTabTrianGap;
792 poly[3].y = y;
793
794 dc.SetPen( pen );
795 dc.SetBrush( brush );
796
797 dc.DrawPolygon( 4, poly );
798
799 long w,h;
800
801 // set select default font of the window into it's device context
802 //dc.SetFont( GetLabelingFont() );
803
804 dc.SetTextBackground( brush.GetColour() );
805
806 dc.GetTextExtent(tab.mText, &w, &h );
807
808 if ( tab.HasImg() )
809 {
810 wxMemoryDC tmpDc;
811 tmpDc.SelectObject( tab.GetImg() );
812
813 dc.Blit( x + mTitleHorizGap,
814 y + ( tab.mDims.y - tab.ImgHeight() ) / 2,
815 tab.ImgWidth(),
816 tab.ImgHeight(),
817 &tmpDc, 0, 0, wxCOPY
818 );
819 }
820
821 if ( tab.HasText() )
822 {
823 int tx = x + mTitleHorizGap +
824 tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap);
825
826 dc.DrawText( tab.GetText(), tx, y + ( tab.mDims.y - h ) / 2 );
827 }
828 } // wxPagedWindow::DrawPaperBar()
829
830 //---------------------------------------------------------------------------
831 void wxPagedWindow::DrawDecorations( wxDC& dc )
832 {
833 // FIXME:: the is big body have to be split!
834
835 int width, height;
836 GetClientSize( &width, &height );
837
838 int curX = mHorizGap;
839 int curY = mVertGap;
840
841 int xSize = width - mHorizGap*2;
842 int ySize = height - mVertGap*2;
843
844 DrawShadedRect( curX, curY, xSize, ySize,
845 mDarkPen, mWhitePen, dc );
846
847 DrawShadedRect( curX+1, curY+1, xSize-2, ySize-2,
848 mBlackPen, mGrayPen, dc );
849
850 // draw inactive tab title bars frist (left-to-right)
851
852 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
853 size_t tabNo = 0;
854
855 /* OLD STUFF::
856 curX = mTitleRowStart;
857 curY = height - mVertGap - BORDER_SZ - mTitleHeight;
858 */
859
860 curX = mTabTrianGap;
861 curY = 0;
862
863 // FOR NOW:: avoid creating bitmap with invalid dimensions
864
865 if ( mTitleRowLen < 1 || mTitleHeight < 1 )
866 return;
867
868 wxMemoryDC tmpDc;
869 wxBitmap tmpBmp( mTitleRowLen, mTitleHeight );
870
871 tmpDc.SelectObject( tmpBmp );
872 tmpDc.SetPen( mGrayPen );
873 tmpDc.SetBrush( mGrayBrush );
874 tmpDc.DrawRectangle( 0,0, mTitleRowLen, mTitleHeight );
875
876 tmpDc.SetDeviceOrigin( mCurentRowOfs, 0 );
877
878 while( pNode )
879 {
880 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
881
882 if ( tabNo != mActiveTab )
883 DrawPaperBar( tab, curX, curY, mGrayBrush, mBlackPen, tmpDc );
884
885 curX += tab.mDims.x;
886
887 pNode = pNode->GetNext();
888 ++tabNo;
889 }
890
891 // finally, draw the active tab (white-filled)
892
893 pNode = mTabs.GetFirst();
894 tabNo = 0;
895
896 curX = mTabTrianGap;
897
898 while( pNode )
899 {
900 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
901
902 if ( tabNo == mActiveTab )
903 {
904 DrawPaperBar( tab, curX, curY, mWhiteBrush, mBlackPen, tmpDc );
905
906 tmpDc.SetPen( mWhitePen );
907
908 tmpDc.DrawLine( curX - mTabTrianGap+1, curY,
909 curX + tab.mDims.x + mTabTrianGap, curY );
910 break;
911 }
912 curX += tab.mDims.x;
913
914 pNode = pNode->GetNext();
915 ++tabNo;
916 }
917
918 // back to initial device origin
919
920 tmpDc.SetDeviceOrigin( 0, 0 );
921
922 // draw resize-hint-stick
923
924 curX = mTitleRowLen - 6;
925
926 DrawShadedRect( curX+0, 0+0, 6, mTitleHeight, mGrayPen, mBlackPen, tmpDc );
927 DrawShadedRect( curX+1, 0+1, 6-2, mTitleHeight-2, mWhitePen, mDarkPen, tmpDc );
928 DrawShadedRect( curX+2, 0+2, 6-4, mTitleHeight-4, mGrayPen, mGrayPen, tmpDc );
929
930
931
932 dc.Blit( mTitleRowStart,
933 height - mVertGap - BORDER_SZ - mTitleHeight,
934 mTitleRowLen, mTitleHeight,
935 &tmpDc, 0,0, wxCOPY );
936 } // wxPagedWindow::DrawDecorations()
937
938 //---------------------------------------------------------------------------
939 int wxPagedWindow::HitTest( const wxPoint& pos )
940 {
941 return wxTabbedWindow::HitTest( pos );
942 }
943
944 //---------------------------------------------------------------------------
945 void wxPagedWindow::RecalcLayout(bool andRepaint)
946 {
947 mTitleRowLen = mAdjustableTitleRowLen;
948
949 if ( int(mpTabScroll) == -1 ) return;
950
951 // scroll bars should be created after Create() for this window is called
952 if ( !mpTabScroll )
953 {
954 mpTabScroll =
955 new wxScrollBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL );
956
957 mpHorizScroll =
958 new wxScrollBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL );
959 if (!mNoVertScroll) // Vertical Scroll (Original)
960 mpVertScroll = new wxScrollBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL );
961 }
962
963 {
964 int units = GetWholeTabRowLen() / 20;
965
966 mpTabScroll->SetScrollbar( 0, 1, units, 1, false );
967 }
968
969 // resetup position of the active tab
970
971 int thumbLen = 16; // FOR NOW:: hardcoded
972
973 int width, height;
974 GetClientSize( &width, &height );
975
976 mTitleHeight = thumbLen;
977
978 int curX = mHorizGap + BORDER_SZ;
979 int curY = mVertGap + BORDER_SZ;
980
981 int xSize;
982 if (!mNoVertScroll) // Vertical Scroll (Original)
983 xSize = width - mHorizGap*2 - BORDER_SZ*2 - thumbLen;
984 else
985 xSize = width - mHorizGap*2 - BORDER_SZ*2;
986
987 int ySize = height - mVertGap*2 - BORDER_SZ*2 - mTitleHeight;
988
989 SizeTabs( curX, curY, xSize, ySize, andRepaint );
990
991 // setup title bar LINES's horizontal scroll bar
992
993 curY = height - mVertGap - BORDER_SZ - thumbLen;
994
995 mpTabScroll->SetSize( curX, curY, thumbLen*2, thumbLen );
996
997 // setup view's HORIZONTAL scroll bar
998 curX += thumbLen*2;
999
1000 mTitleRowStart = curX;
1001 mFirstTitleGap = curX + mCurentRowOfs + mTabTrianGap;
1002
1003 mTitleRowLen = wxMin( mAdjustableTitleRowLen,
1004 width - mHorizGap - BORDER_SZ - thumbLen*4 - curX );
1005
1006 curX += mTitleRowLen;
1007
1008 if (!mNoVertScroll) // Vertical Scroll (Original)
1009 mpHorizScroll->SetSize( curX, curY,width - curX - mHorizGap - BORDER_SZ - thumbLen, thumbLen );
1010 else
1011 mpHorizScroll->SetSize( curX, curY,width - curX - mHorizGap - BORDER_SZ-4, thumbLen );
1012
1013 // setup view's VERTICAL scroll bar
1014 if (!mNoVertScroll) // Vertical Scroll (Original)
1015 {
1016 curX = width - mHorizGap - BORDER_SZ - thumbLen;
1017 curY = mVertGap + BORDER_SZ;
1018 mpVertScroll->SetSize( curX, curY, thumbLen,height - curY - mVertGap - BORDER_SZ - thumbLen);
1019 }
1020 // layout tab title bars
1021
1022 mLayoutType = wxTITLE_IMG_AND_TEXT;
1023
1024 wxObjectList::compatibility_iterator pNode = mTabs.GetFirst();
1025
1026 while( pNode )
1027 {
1028 twTabInfo& tab = *((twTabInfo*)(pNode->GetData()));
1029
1030 wxWindowDC dc(this);
1031
1032 long w,h;
1033
1034 // set select default font of the window into it's device context
1035 //dc.SetFont( GetLabelingFont() );
1036 dc.GetTextExtent(tab.mText, &w, &h );
1037
1038 tab.mDims.x = w + tab.ImageToTxtGap(mImageTextGap) +
1039 tab.ImgWidth() + mTitleHorizGap*2;
1040
1041 tab.mDims.y = mTitleHeight;
1042
1043 pNode = pNode->GetNext();
1044 }
1045
1046 // disable title-bar scroller if there's nowhere to scroll to
1047
1048 mpTabScroll->Enable( mTitleRowLen < GetWholeTabRowLen() || mCurentRowOfs < 0 );
1049 }
1050
1051 //---------------------------------------------------------------------------
1052 // event handlers
1053 //---------------------------------------------------------------------------
1054 void wxPagedWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
1055 {
1056 wxPaintDC dc(this);
1057 DrawDecorations( dc );
1058 }
1059
1060 //---------------------------------------------------------------------------
1061 void wxPagedWindow::OnSize ( wxSizeEvent& event )
1062 {
1063 wxTabbedWindow::OnSize(event);
1064 }
1065
1066 //---------------------------------------------------------------------------
1067 void wxPagedWindow::OnLButtonDown( wxMouseEvent& event )
1068 {
1069 if ( mCursorChanged )
1070 {
1071 mIsDragged = true;
1072 mDagOrigin = event.m_x;
1073
1074 mOriginalTitleRowLen = mAdjustableTitleRowLen;
1075
1076 CaptureMouse();
1077 }
1078 else
1079 {
1080 wxTabbedWindow::OnLButtonDown( event );
1081 }
1082 } // wxPagedWindow::OnLButtonDown()
1083
1084 //---------------------------------------------------------------------------
1085 void wxPagedWindow::OnLButtonUp( wxMouseEvent& WXUNUSED(event) )
1086 {
1087 if ( mIsDragged )
1088 {
1089 mIsDragged = false;
1090 mCursorChanged = false;
1091 SetCursor( mNormalCursor );
1092
1093 ReleaseMouse();
1094 }
1095 } // wxPagedWindow::OnLButtonUp()
1096
1097 //---------------------------------------------------------------------------
1098 void wxPagedWindow::OnMouseMove( wxMouseEvent& event )
1099 {
1100 int width, height;
1101 GetClientSize( &width, &height );
1102
1103 if ( !mIsDragged )
1104 {
1105 int y = height - mVertGap - BORDER_SZ - mTitleHeight;
1106 int x = mTitleRowStart + mTitleRowLen - 6;
1107
1108 if ( event.m_x >= x && event.m_y >= y &&
1109 event.m_x < x + 6 &&
1110 event.m_y < y + mTitleHeight
1111 )
1112 {
1113 if ( !mCursorChanged )
1114 {
1115 SetCursor( mResizeCursor );
1116
1117 mCursorChanged = true;
1118 }
1119 }
1120 else
1121 if ( mCursorChanged )
1122 {
1123 SetCursor( mNormalCursor );
1124
1125 mCursorChanged = false;
1126 }
1127 }
1128 else
1129 {
1130 if ( mIsDragged )
1131 {
1132 mAdjustableTitleRowLen = mOriginalTitleRowLen + ( event.m_x - mDagOrigin );
1133
1134 // FOR NOW:: fixed
1135 if ( mAdjustableTitleRowLen < 6 ) mAdjustableTitleRowLen = 6;
1136
1137 wxWindowDC dc(this);
1138 DrawDecorations( dc );
1139
1140 RecalcLayout(false);
1141
1142 //Refresh();
1143 }
1144 }
1145 } // wxPagedWindow::OnMouseMove()
1146
1147 //---------------------------------------------------------------------------
1148 void wxPagedWindow::OnScroll( wxScrollEvent& event )
1149 {
1150 wxScrollBar* pSender = (wxScrollBar*)event.GetEventObject();
1151 // wxMessageBox("wxPagedWindow::OnScroll","-I->");
1152 if ( pSender == mpTabScroll )
1153 {
1154
1155 int maxUnits = GetWholeTabRowLen() / 20;
1156
1157 mCurentRowOfs = -event.GetPosition()*maxUnits;
1158
1159 mFirstTitleGap = mTitleRowStart + mCurentRowOfs + mTabTrianGap;
1160
1161 // let' it automatically disable itself if it's time
1162 mpTabScroll->Enable( mTitleRowLen < GetWholeTabRowLen() || mCurentRowOfs < 0 );
1163
1164 // repaint title bars
1165 wxWindowDC dc(this);
1166 DrawDecorations( dc );
1167 }
1168 else
1169 {
1170 if ( !mScrollEventInProgress )
1171 {
1172 mScrollEventInProgress = true;
1173
1174 GetActiveTab()->GetEventHandler()->ProcessEvent( event );
1175 }
1176 else
1177 {
1178 // event bounced back to us, from here we
1179 // know that it has traveled the loop - thus it's processed!
1180
1181 mScrollEventInProgress = false;
1182 }
1183 }
1184 } // wxPagedWindow::OnScroll()
1185 //---------------------------------------------------------------------------
1186