1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic tabbed dialogs
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "tabg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
34 // not defined: use old, square tab implementation (fills in tabs)
35 // defined: use new, rounded tab implementation (doesn't colour in tabs)
36 // #define wxUSE_NEW_METHOD
38 IMPLEMENT_DYNAMIC_CLASS(wxTabControl
, wxObject
)
40 IMPLEMENT_DYNAMIC_CLASS(wxTabLayer
, wxList
)
42 wxTabControl::wxTabControl(wxTabView
*v
)
55 wxTabControl::~wxTabControl(void)
59 void wxTabControl::OnDraw(wxDC
& dc
, bool lastInRow
)
61 // Old, but in some ways better (drawing opaque tabs)
62 #ifndef wxUSE_NEW_METHOD
66 // Top-left of tab view area
67 int viewX
= m_view
->GetViewRect().x
;
68 int viewY
= m_view
->GetViewRect().y
;
70 // Top-left of tab control
71 int tabX
= GetX() + viewX
;
72 int tabY
= GetY() + viewY
;
76 tabHeightInc
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
80 dc
.SetPen(*wxTRANSPARENT_PEN
);
82 // Draw grey background
83 if (m_view
->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
85 dc
.SetBrush(*m_view
->GetBackgroundBrush());
87 // Add 1 because the pen is transparent. Under Motif, may be different.
89 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + tabHeightInc
));
91 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc
));
95 // Draw highlight and shadow
96 dc
.SetPen(*m_view
->GetHighlightPen());
98 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
99 // a bit if the tab below happens to be selected. Check.
100 wxTabControl
*tabBeneath
= NULL
;
101 int subtractThis
= 0;
102 if (GetColPosition() > 0)
103 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition());
104 if (tabBeneath
&& tabBeneath
->IsSelected())
105 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
107 // Vertical highlight: if first tab, draw to bottom of view
108 if (tabX
== m_view
->GetViewRect().x
&& (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
109 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
));
110 else if (tabX
== m_view
->GetViewRect().x
)
111 // Not box drawing, just to top of view.
112 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
));
114 dc
.DrawLine(tabX
, tabY
, tabX
, (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
116 dc
.DrawLine(tabX
, tabY
, (tabX
+ GetWidth()), tabY
);
117 dc
.SetPen(*m_view
->GetShadowPen());
119 // Test if we're outside the right-hand edge of the view area
120 if (((tabX
+ GetWidth()) >= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
) && (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
122 int bottomY
= m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
+ GetY() + m_view
->GetTabHeight() + m_view
->GetTopMargin();
123 // Add a tab height since we wish to draw to the bottom of the view.
124 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
125 (tabX
+ GetWidth()), bottomY
);
127 // Calculate the far-right of the view, since we don't wish to
129 int rightOfView
= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
+ 1;
131 // Draw the horizontal bit to connect to the view rectangle
132 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
-1),
133 (tabX
+ GetWidth()), (bottomY
-1));
135 // Draw black line to emphasize shadow
136 dc
.SetPen(*wxBLACK_PEN
);
137 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1),
138 (tabX
+ GetWidth() + 1), bottomY
);
140 // Draw the horizontal bit to connect to the view rectangle
141 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
),
142 (tabX
+ GetWidth() + 1), (bottomY
));
148 // 25/5/97 UNLESS it's less than the max number of positions in this row
150 int topY
= m_view
->GetViewRect().y
- m_view
->GetTopMargin();
152 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Nth(0)->Data())->Number();
154 // Only down to the bottom of the tab, not to the top of the view
155 if ( GetRowPosition() < (maxPositions
- 1) )
156 topY
= tabY
+ GetHeight() + tabHeightInc
;
163 dc
.DrawLine((tabX
+ GetWidth()), tabY
, (tabX
+ GetWidth()), topY
);
164 // Draw black line to emphasize shadow
165 dc
.SetPen(*wxBLACK_PEN
);
166 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
171 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
172 // a bit if the tab below (and next col along) happens to be selected. Check.
173 wxTabControl
*tabBeneath
= NULL
;
174 int subtractThis
= 0;
175 if (GetColPosition() > 0)
176 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1);
177 if (tabBeneath
&& tabBeneath
->IsSelected())
178 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
184 // Draw only to next tab down.
185 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
186 (tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
188 // Draw black line to emphasize shadow
189 dc
.SetPen(*wxBLACK_PEN
);
190 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
191 (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
195 // Draw centered text
196 int textY
= tabY
+ m_view
->GetVerticalTabTextSpacing() + tabHeightInc
;
199 dc
.SetFont(* m_view
->GetSelectedTabFont());
201 dc
.SetFont(* GetFont());
203 wxColour
col(m_view
->GetTextColour());
204 dc
.SetTextForeground(col
);
205 dc
.SetBackgroundMode(wxTRANSPARENT
);
206 long textWidth
, textHeight
;
207 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
209 int textX
= (int)(tabX
+ (GetWidth() - textWidth
)/2.0);
210 dc
.DrawText(GetLabel(), textX
, textY
);
214 dc
.SetPen(*m_view
->GetHighlightPen());
216 // Draw white highlight from the tab's left side to the left hand edge of the view
217 dc
.DrawLine(m_view
->GetViewRect().x
, (tabY
+ GetHeight() + tabHeightInc
),
218 tabX
, (tabY
+ GetHeight() + tabHeightInc
));
220 // Draw white highlight from the tab's right side to the right hand edge of the view
221 dc
.DrawLine((tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
),
222 m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
, (tabY
+ GetHeight() + tabHeightInc
));
225 // New HEL version with rounder tabs
232 tabInc
= m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight();
234 int tabLeft
= GetX() + m_view
->GetViewRect().x
;
235 int tabTop
= GetY() + m_view
->GetViewRect().y
- tabInc
;
236 int tabRight
= tabLeft
+ m_view
->GetTabWidth();
237 int left
= m_view
->GetViewRect().x
;
238 int top
= tabTop
+ m_view
->GetTabHeight() + tabInc
;
239 int right
= left
+ m_view
->GetViewRect().width
;
240 int bottom
= top
+ m_view
->GetViewRect().height
;
244 // TAB is selected - draw TAB and the View's full outline
246 dc
.SetPen(*(m_view
->GetHighlightPen()));
249 pnts
[n
].x
= left
; pnts
[n
++].y
= bottom
;
250 pnts
[n
].x
= left
; pnts
[n
++].y
= top
;
251 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= top
;
252 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
253 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
254 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
255 dc
.DrawLines(n
, pnts
);
266 dc
.SetPen(*(m_view
->GetShadowPen()));
286 dc
.SetPen(*wxBLACK_PEN
);
328 // TAB is not selected - just draw TAB outline and RH edge
329 // if the TAB is the last in the row
331 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Nth(0)->Data())->Number();
332 wxTabControl
* tabBelow
= 0;
333 wxTabControl
* tabBelowRight
= 0;
334 if (GetColPosition() > 0)
336 tabBelow
= m_view
->FindTabControlForPosition(
337 GetColPosition() - 1,
341 if (!lastInRow
&& GetColPosition() > 0)
343 tabBelowRight
= m_view
->FindTabControlForPosition(
344 GetColPosition() - 1,
349 float raisedTop
= top
- m_view
->GetTabSelectionHeight() +
350 m_view
->GetTabHeight();
352 dc
.SetPen(*(m_view
->GetHighlightPen()));
358 if (tabBelow
&& tabBelow
->IsSelected())
360 pnts
[n
++].y
= (long)raisedTop
;
366 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
367 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
368 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
369 dc
.DrawLines(n
, pnts
);
371 dc
.SetPen(*(m_view
->GetShadowPen()));
372 if (GetRowPosition() >= maxPositions
- 1)
383 (tabRight
- m_view
->GetHorizontalTabOffset()),
389 if (tabBelowRight
&& tabBelowRight
->IsSelected())
409 dc
.SetPen(*wxBLACK_PEN
);
418 if (GetRowPosition() >= maxPositions
- 1)
420 // draw right hand edge to bottom of view
430 (tabRight
- m_view
->GetHorizontalTabOffset()),
436 // draw right hand edge of TAB
437 if (tabBelowRight
&& tabBelowRight
->IsSelected())
441 (long)(raisedTop
- 1),
458 // Draw centered text
459 dc
.SetPen(*wxBLACK_PEN
);
462 dc
.SetFont(*(m_view
->GetSelectedTabFont()));
466 dc
.SetFont(*(GetFont()));
469 wxColour
col(m_view
->GetTextColour());
470 dc
.SetTextForeground(col
);
471 dc
.SetBackgroundMode(wxTRANSPARENT
);
472 long textWidth
, textHeight
;
473 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
475 float textX
= (tabLeft
+ tabRight
- textWidth
) / 2;
476 float textY
= (tabInc
+ tabTop
+ m_view
->GetVerticalTabTextSpacing());
478 dc
.DrawText(GetLabel(), (long)textX
, (long)textY
);
482 bool wxTabControl::HitTest(int x
, int y
) const
484 // Top-left of tab control
485 int tabX1
= GetX() + m_view
->GetViewRect().x
;
486 int tabY1
= GetY() + m_view
->GetViewRect().y
;
489 int tabX2
= tabX1
+ GetWidth();
490 int tabY2
= tabY1
+ GetHeight();
492 if (x
>= tabX1
&& y
>= tabY1
&& x
<= tabX2
&& y
<= tabY2
)
498 IMPLEMENT_DYNAMIC_CLASS(wxTabView
, wxObject
)
500 wxTabView::wxTabView(long style
)
506 m_tabSelectionHeight
= m_tabHeight
+ 2;
508 m_tabHorizontalOffset
= 10;
509 m_tabHorizontalSpacing
= 2;
510 m_tabVerticalTextSpacing
= 3;
512 m_tabViewRect
.x
= 20;
513 m_tabViewRect
.y
= 20;
514 m_tabViewRect
.width
= 300;
515 m_tabViewRect
.x
= 300;
516 m_highlightColour
= *wxWHITE
;
517 m_shadowColour
= wxColour(128, 128, 128);
518 m_backgroundColour
= *wxLIGHT_GREY
;
519 m_textColour
= *wxBLACK
;
520 m_highlightPen
= wxWHITE_PEN
;
521 m_shadowPen
= wxGREY_PEN
;
522 m_backgroundPen
= wxLIGHT_GREY_PEN
;
523 m_backgroundBrush
= wxLIGHT_GREY_BRUSH
;
524 m_tabFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
525 m_tabSelectedFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
526 m_window
= (wxWindow
*) NULL
;
529 wxTabView::~wxTabView()
534 // Automatically positions tabs
535 // TODO: this should just add the tab to a list, and then
536 // a layout function (e.g. Realize) should be called when all tabs have been added.
537 // The view rect could easily change as the view window is resized.
538 wxTabControl
*wxTabView::AddTab(int id
, const wxString
& label
, wxTabControl
*existingTab
)
540 // First, find which layer we should be adding to.
541 wxNode
*node
= m_layers
.Last();
544 wxTabLayer
*newLayer
= new wxTabLayer
;
545 node
= m_layers
.Append(newLayer
);
547 // Check if adding another tab control would go off the
548 // right-hand edge of the layer.
549 wxTabLayer
*tabLayer
= (wxTabLayer
*)node
->Data();
550 wxNode
*lastTabNode
= tabLayer
->Last();
553 wxTabControl
*lastTab
= (wxTabControl
*)lastTabNode
->Data();
554 // Start another layer (row).
555 // Tricky choice: can't just check if will be overlapping the edge, because
556 // this happens anyway for 2nd and subsequent rows.
557 // Should check this for 1st row, and then subsequent rows should not exceed 1st
559 if (((tabLayer
== m_layers
.First()->Data()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
560 > GetViewRect().width
)) ||
561 ((tabLayer
!= m_layers
.First()->Data()) && (tabLayer
->Number() == ((wxTabLayer
*)m_layers
.First()->Data())->Number())))
563 tabLayer
= new wxTabLayer
;
564 m_layers
.Append(tabLayer
);
565 lastTabNode
= (wxNode
*) NULL
;
568 int layer
= m_layers
.Number() - 1;
570 wxTabControl
*tabControl
= existingTab
;
572 tabControl
= OnCreateTabControl();
573 tabControl
->SetRowPosition(tabLayer
->Number());
574 tabControl
->SetColPosition(layer
);
576 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
578 lastTab
= (wxTabControl
*)lastTabNode
->Data();
581 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
582 // Offset from view top-left
583 int horizontalOffset
= 0;
585 horizontalOffset
= layer
*GetHorizontalTabOffset();
587 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
589 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
590 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
591 tabControl
->SetId(id
);
592 tabControl
->SetLabel(label
);
593 tabControl
->SetFont(* GetTabFont());
595 tabLayer
->Append(tabControl
);
601 // Returns the total height of the tabs component -- this may be several
602 // times the height of a tab, if there are several tab layers (rows).
603 int wxTabView::GetTotalTabHeight()
607 wxNode
*layerNode
= m_layers
.First();
610 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
611 wxNode
*tabNode
= layer
->First();
614 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
616 if (tab
->GetY() < minY
)
619 tabNode
= tabNode
->Next();
621 layerNode
= layerNode
->Next();
627 void wxTabView::ClearTabs(bool deleteTabs
)
629 wxNode
*layerNode
= m_layers
.First();
632 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
633 wxNode
*tabNode
= layer
->First();
636 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
639 wxNode
*next
= tabNode
->Next();
643 wxNode
*nextLayerNode
= layerNode
->Next();
646 layerNode
= nextLayerNode
;
651 // Layout tabs (optional, e.g. if resizing window)
652 void wxTabView::Layout(void)
654 // Make a list of the tab controls, deleting the wxTabLayers.
657 wxNode
*layerNode
= m_layers
.First();
660 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
661 wxNode
*tabNode
= layer
->First();
664 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
665 controls
.Append(tab
);
666 wxNode
*next
= tabNode
->Next();
670 wxNode
*nextLayerNode
= layerNode
->Next();
673 layerNode
= nextLayerNode
;
676 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
678 wxTabLayer
*currentLayer
= new wxTabLayer
;
679 m_layers
.Append(currentLayer
);
681 wxNode
*node
= controls
.First();
684 wxTabControl
*tabControl
= (wxTabControl
*)node
->Data();
687 // Start another layer (row).
688 // Tricky choice: can't just check if will be overlapping the edge, because
689 // this happens anyway for 2nd and subsequent rows.
690 // Should check this for 1st row, and then subsequent rows should not exceed 1st
692 if (((currentLayer
== m_layers
.First()->Data()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
693 > GetViewRect().width
)) ||
694 ((currentLayer
!= m_layers
.First()->Data()) && (currentLayer
->Number() == ((wxTabLayer
*)m_layers
.First()->Data())->Number())))
696 currentLayer
= new wxTabLayer
;
697 m_layers
.Append(currentLayer
);
698 lastTab
= (wxTabControl
*) NULL
;
702 int layer
= m_layers
.Number() - 1;
704 tabControl
->SetRowPosition(currentLayer
->Number());
705 tabControl
->SetColPosition(layer
);
708 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
709 // Offset from view top-left
710 int horizontalOffset
= 0;
712 horizontalOffset
= layer
*GetHorizontalTabOffset();
714 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
716 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
717 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
719 currentLayer
->Append(tabControl
);
720 lastTab
= tabControl
;
725 // Move the selected tab to the bottom
726 wxTabControl
*control
= FindTabControlForId(m_tabSelection
);
728 MoveSelectionTab(control
);
733 void wxTabView::Draw(wxDC
& dc
)
735 // Draw top margin area (beneath tabs and above view area)
736 if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
738 dc
.SetPen(*wxTRANSPARENT_PEN
);
739 dc
.SetBrush(*GetBackgroundBrush());
741 // Add 1 because the pen is transparent. Under Motif, may be different.
744 (m_tabViewRect
.y
- m_topMargin
),
745 (m_tabViewRect
.width
+ 1),
750 // Draw layers in reverse order
751 wxNode
*node
= m_layers
.Last();
754 wxTabLayer
*layer
= (wxTabLayer
*)node
->Data();
755 wxNode
*node2
= layer
->First();
758 wxTabControl
*control
= (wxTabControl
*)node2
->Data();
759 control
->OnDraw(dc
, (node2
->Next() == NULL
));
760 node2
= node2
->Next();
763 node
= node
->Previous();
767 #ifndef wxUSE_NEW_METHOD
768 if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX
)
770 dc
.SetPen(GetShadowPen());
774 (GetViewRect().x
+ 1),
775 (GetViewRect().y
+ GetViewRect().height
),
776 (GetViewRect().x
+ GetViewRect().width
+ 1),
777 (GetViewRect().y
+ GetViewRect().height
)
782 (GetViewRect().x
+ GetViewRect().width
),
783 (GetViewRect().y
- GetTopMargin() + 1),
784 (GetViewRect().x
+ GetViewRect().width
),
785 (GetViewRect().y
+ GetViewRect().height
)
788 dc
.SetPen(wxBLACK_PEN
);
793 (GetViewRect().y
+ GetViewRect().height
+ 1),
794 #if defined(__WXMOTIF__)
795 (GetViewRect().x
+ GetViewRect().width
+ 1),
797 (GetViewRect().x
+ GetViewRect().width
+ 2),
800 (GetViewRect().y
+ GetViewRect().height
+ 1)
805 (GetViewRect().x
+ GetViewRect().width
+ 1),
806 (GetViewRect().y
- GetTopMargin()),
807 (GetViewRect().x
+ GetViewRect().width
+ 1),
808 (GetViewRect().y
+ GetViewRect().height
+ 1)
814 // Process mouse event, return FALSE if we didn't process it
815 bool wxTabView::OnEvent(wxMouseEvent
& event
)
817 if (!event
.LeftDown())
821 event
.Position(&x
, &y
);
823 wxTabControl
*hitControl
= (wxTabControl
*) NULL
;
825 wxNode
*node
= m_layers
.First();
828 wxTabLayer
*layer
= (wxTabLayer
*)node
->Data();
829 wxNode
*node2
= layer
->First();
832 wxTabControl
*control
= (wxTabControl
*)node2
->Data();
833 if (control
->HitTest((int)x
, (int)y
))
835 hitControl
= control
;
836 node
= (wxNode
*) NULL
;
837 node2
= (wxNode
*) NULL
;
840 node2
= node2
->Next();
850 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
852 if (hitControl
== currentTab
)
855 ChangeTab(hitControl
);
860 bool wxTabView::ChangeTab(wxTabControl
*control
)
862 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
865 oldTab
= currentTab
->GetId();
867 if (control
== currentTab
)
870 if (m_layers
.Number() == 0)
873 if (!OnTabPreActivate(control
->GetId(), oldTab
))
876 // Move the tab to the bottom
877 MoveSelectionTab(control
);
880 currentTab
->SetSelected(FALSE
);
882 control
->SetSelected(TRUE
);
883 m_tabSelection
= control
->GetId();
885 OnTabActivate(control
->GetId(), oldTab
);
887 // Leave window refresh for the implementing window
892 // Move the selected tab to the bottom layer, if necessary,
893 // without calling app activation code
894 bool wxTabView::MoveSelectionTab(wxTabControl
*control
)
896 if (m_layers
.Number() == 0)
899 wxTabLayer
*firstLayer
= (wxTabLayer
*)m_layers
.First()->Data();
901 // Find what column this tab is at, so we can swap with the one at the bottom.
902 // If we're on the bottom layer, then no need to swap.
903 if (!firstLayer
->Member(control
))
907 wxNode
*thisNode
= FindTabNodeAndColumn(control
, &col
);
910 wxNode
*otherNode
= firstLayer
->Nth(col
);
914 // If this is already in the bottom layer, return now
915 if (otherNode
== thisNode
)
918 wxTabControl
*otherTab
= (wxTabControl
*)otherNode
->Data();
920 // We now have pointers to the tab to be changed to,
921 // and the tab on the first layer. Swap tab structures and
924 int thisX
= control
->GetX();
925 int thisY
= control
->GetY();
926 int thisColPos
= control
->GetColPosition();
927 int otherX
= otherTab
->GetX();
928 int otherY
= otherTab
->GetY();
929 int otherColPos
= otherTab
->GetColPosition();
931 control
->SetPosition(otherX
, otherY
);
932 control
->SetColPosition(otherColPos
);
933 otherTab
->SetPosition(thisX
, thisY
);
934 otherTab
->SetColPosition(thisColPos
);
936 // Swap the data for the nodes
937 thisNode
->SetData(otherTab
);
938 otherNode
->SetData(control
);
943 // Called when a tab is activated
944 void wxTabView::OnTabActivate(int /*activateId*/, int /*deactivateId*/)
948 void wxTabView::SetHighlightColour(const wxColour
& col
)
950 m_highlightColour
= col
;
951 m_highlightPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
954 void wxTabView::SetShadowColour(const wxColour
& col
)
956 m_shadowColour
= col
;
957 m_shadowPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
960 void wxTabView::SetBackgroundColour(const wxColour
& col
)
962 m_backgroundColour
= col
;
963 m_backgroundPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
964 m_backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(col
, wxSOLID
);
967 void wxTabView::SetTabSelection(int sel
, bool activateTool
)
969 int oldSel
= m_tabSelection
;
970 wxTabControl
*control
= FindTabControlForId(sel
);
972 if (!OnTabPreActivate(sel
, oldSel
))
976 control
->SetSelected((sel
!= 0)); // TODO ??
979 wxMessageBox(_("Could not find tab for id"), _("Error"), wxOK
);
983 m_tabSelection
= sel
;
984 MoveSelectionTab(control
);
987 OnTabActivate(sel
, oldSel
);
990 // Find tab control for id
991 wxTabControl
*wxTabView::FindTabControlForId(int id
) const
993 wxNode
*node1
= m_layers
.First();
996 wxTabLayer
*layer
= (wxTabLayer
*)node1
->Data();
997 wxNode
*node2
= layer
->First();
1000 wxTabControl
*control
= (wxTabControl
*)node2
->Data();
1001 if (control
->GetId() == id
)
1003 node2
= node2
->Next();
1005 node1
= node1
->Next();
1007 return (wxTabControl
*) NULL
;
1010 // Find tab control for layer, position (starting from zero)
1011 wxTabControl
*wxTabView::FindTabControlForPosition(int layer
, int position
) const
1013 wxNode
*node1
= m_layers
.Nth(layer
);
1015 return (wxTabControl
*) NULL
;
1016 wxTabLayer
*tabLayer
= (wxTabLayer
*)node1
->Data();
1017 wxNode
*node2
= tabLayer
->Nth(position
);
1019 return (wxTabControl
*) NULL
;
1020 return (wxTabControl
*)node2
->Data();
1023 // Find the node and the column at which this control is positioned.
1024 wxNode
*wxTabView::FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const
1026 wxNode
*node1
= m_layers
.First();
1029 wxTabLayer
*layer
= (wxTabLayer
*)node1
->Data();
1031 wxNode
*node2
= layer
->First();
1034 wxTabControl
*cnt
= (wxTabControl
*)node2
->Data();
1040 node2
= node2
->Next();
1043 node1
= node1
->Next();
1045 return (wxNode
*) NULL
;
1048 int wxTabView::CalculateTabWidth(int noTabs
, bool adjustView
)
1050 m_tabWidth
= (int)((m_tabViewRect
.width
- ((noTabs
- 1)*GetHorizontalTabSpacing()))/noTabs
);
1053 m_tabViewRect
.width
= noTabs
*m_tabWidth
+ ((noTabs
-1)*GetHorizontalTabSpacing());
1062 IMPLEMENT_CLASS(wxTabbedDialog
, wxDialog
)
1064 BEGIN_EVENT_TABLE(wxTabbedDialog
, wxDialog
)
1065 EVT_CLOSE(wxTabbedDialog::OnCloseWindow
)
1066 EVT_MOUSE_EVENTS(wxTabbedDialog::OnMouseEvent
)
1067 EVT_PAINT(wxTabbedDialog::OnPaint
)
1070 wxTabbedDialog::wxTabbedDialog(wxWindow
*parent
, wxWindowID id
,
1071 const wxString
& title
,
1072 const wxPoint
& pos
, const wxSize
& size
,
1073 long windowStyle
, const wxString
& name
):
1074 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
, name
)
1076 m_tabView
= (wxTabView
*) NULL
;
1079 wxTabbedDialog::~wxTabbedDialog(void)
1085 void wxTabbedDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
1090 void wxTabbedDialog::OnMouseEvent(wxMouseEvent
& event
)
1093 m_tabView
->OnEvent(event
);
1096 void wxTabbedDialog::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1100 m_tabView
->Draw(dc
);
1107 IMPLEMENT_CLASS(wxTabbedPanel
, wxPanel
)
1109 BEGIN_EVENT_TABLE(wxTabbedPanel
, wxPanel
)
1110 EVT_MOUSE_EVENTS(wxTabbedPanel::OnMouseEvent
)
1111 EVT_PAINT(wxTabbedPanel::OnPaint
)
1114 wxTabbedPanel::wxTabbedPanel(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
1115 const wxSize
& size
, long windowStyle
, const wxString
& name
):
1116 wxPanel(parent
, id
, pos
, size
, windowStyle
, name
)
1118 m_tabView
= (wxTabView
*) NULL
;
1121 wxTabbedPanel::~wxTabbedPanel(void)
1126 void wxTabbedPanel::OnMouseEvent(wxMouseEvent
& event
)
1129 m_tabView
->OnEvent(event
);
1132 void wxTabbedPanel::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1136 m_tabView
->Draw(dc
);
1143 IMPLEMENT_CLASS(wxPanelTabView
, wxTabView
)
1145 wxPanelTabView::wxPanelTabView(wxPanel
*pan
, long style
): wxTabView(style
), m_tabWindows(wxKEY_INTEGER
)
1148 m_currentWindow
= (wxWindow
*) NULL
;
1150 if (m_panel
->IsKindOf(CLASSINFO(wxTabbedDialog
)))
1151 ((wxTabbedDialog
*)m_panel
)->SetTabView(this);
1152 else if (m_panel
->IsKindOf(CLASSINFO(wxTabbedPanel
)))
1153 ((wxTabbedPanel
*)m_panel
)->SetTabView(this);
1158 wxPanelTabView::~wxPanelTabView(void)
1163 // Called when a tab is activated
1164 void wxPanelTabView::OnTabActivate(int activateId
, int deactivateId
)
1169 wxWindow
*oldWindow
= ((deactivateId
== -1) ? 0 : GetTabWindow(deactivateId
));
1170 wxWindow
*newWindow
= GetTabWindow(activateId
);
1173 oldWindow
->Show(FALSE
);
1175 newWindow
->Show(TRUE
);
1181 void wxPanelTabView::AddTabWindow(int id
, wxWindow
*window
)
1183 m_tabWindows
.Append((long)id
, window
);
1184 window
->Show(FALSE
);
1187 wxWindow
*wxPanelTabView::GetTabWindow(int id
) const
1189 wxNode
*node
= m_tabWindows
.Find((long)id
);
1191 return (wxWindow
*) NULL
;
1192 return (wxWindow
*)node
->Data();
1195 void wxPanelTabView::ClearWindows(bool deleteWindows
)
1198 m_tabWindows
.DeleteContents(TRUE
);
1199 m_tabWindows
.Clear();
1200 m_tabWindows
.DeleteContents(FALSE
);
1203 void wxPanelTabView::ShowWindowForTab(int id
)
1205 wxWindow
*newWindow
= GetTabWindow(id
);
1206 if (newWindow
== m_currentWindow
)
1208 if (m_currentWindow
)
1209 m_currentWindow
->Show(FALSE
);
1210 newWindow
->Show(TRUE
);
1211 newWindow
->Refresh();