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"
36 // not defined: use old, square tab implementation (fills in tabs)
37 // defined: use new, rounded tab implementation (doesn't colour in tabs)
38 // #define wxUSE_NEW_METHOD
40 IMPLEMENT_DYNAMIC_CLASS(wxTabControl
, wxObject
)
42 IMPLEMENT_DYNAMIC_CLASS(wxTabLayer
, wxList
)
44 wxTabControl::wxTabControl(wxTabView
*v
)
57 wxTabControl::~wxTabControl(void)
61 void wxTabControl::OnDraw(wxDC
& dc
, bool lastInRow
)
63 // Old, but in some ways better (drawing opaque tabs)
64 #ifndef wxUSE_NEW_METHOD
68 // Top-left of tab view area
69 int viewX
= m_view
->GetViewRect().x
;
70 int viewY
= m_view
->GetViewRect().y
;
72 // Top-left of tab control
73 int tabX
= GetX() + viewX
;
74 int tabY
= GetY() + viewY
;
78 tabHeightInc
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
82 dc
.SetPen(*wxTRANSPARENT_PEN
);
84 // Draw grey background
85 if (m_view
->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
87 dc
.SetBrush(*m_view
->GetBackgroundBrush());
89 // Add 1 because the pen is transparent. Under Motif, may be different.
91 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + tabHeightInc
));
93 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc
));
97 // Draw highlight and shadow
98 dc
.SetPen(*m_view
->GetHighlightPen());
100 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
101 // a bit if the tab below happens to be selected. Check.
102 wxTabControl
*tabBeneath
= NULL
;
103 int subtractThis
= 0;
104 if (GetColPosition() > 0)
105 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition());
106 if (tabBeneath
&& tabBeneath
->IsSelected())
107 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
109 // Vertical highlight: if first tab, draw to bottom of view
110 if (tabX
== m_view
->GetViewRect().x
&& (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
111 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
));
112 else if (tabX
== m_view
->GetViewRect().x
)
113 // Not box drawing, just to top of view.
114 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
));
116 dc
.DrawLine(tabX
, tabY
, tabX
, (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
118 dc
.DrawLine(tabX
, tabY
, (tabX
+ GetWidth()), tabY
);
119 dc
.SetPen(*m_view
->GetShadowPen());
121 // Test if we're outside the right-hand edge of the view area
122 if (((tabX
+ GetWidth()) >= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
) && (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
124 int bottomY
= m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
+ GetY() + m_view
->GetTabHeight() + m_view
->GetTopMargin();
125 // Add a tab height since we wish to draw to the bottom of the view.
126 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
127 (tabX
+ GetWidth()), bottomY
);
129 // Calculate the far-right of the view, since we don't wish to
131 int rightOfView
= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
+ 1;
133 // Draw the horizontal bit to connect to the view rectangle
134 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
-1),
135 (tabX
+ GetWidth()), (bottomY
-1));
137 // Draw black line to emphasize shadow
138 dc
.SetPen(*wxBLACK_PEN
);
139 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1),
140 (tabX
+ GetWidth() + 1), bottomY
);
142 // Draw the horizontal bit to connect to the view rectangle
143 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
),
144 (tabX
+ GetWidth() + 1), (bottomY
));
150 // 25/5/97 UNLESS it's less than the max number of positions in this row
152 int topY
= m_view
->GetViewRect().y
- m_view
->GetTopMargin();
154 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Nth(0)->Data())->Number();
156 // Only down to the bottom of the tab, not to the top of the view
157 if ( GetRowPosition() < (maxPositions
- 1) )
158 topY
= tabY
+ GetHeight() + tabHeightInc
;
165 dc
.DrawLine((tabX
+ GetWidth()), tabY
, (tabX
+ GetWidth()), topY
);
166 // Draw black line to emphasize shadow
167 dc
.SetPen(*wxBLACK_PEN
);
168 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
173 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
174 // a bit if the tab below (and next col along) happens to be selected. Check.
175 wxTabControl
*tabBeneath
= NULL
;
176 int subtractThis
= 0;
177 if (GetColPosition() > 0)
178 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1);
179 if (tabBeneath
&& tabBeneath
->IsSelected())
180 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
186 // Draw only to next tab down.
187 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
188 (tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
190 // Draw black line to emphasize shadow
191 dc
.SetPen(*wxBLACK_PEN
);
192 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
193 (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
197 // Draw centered text
198 int textY
= tabY
+ m_view
->GetVerticalTabTextSpacing() + tabHeightInc
;
201 dc
.SetFont(* m_view
->GetSelectedTabFont());
203 dc
.SetFont(* GetFont());
205 wxColour
col(m_view
->GetTextColour());
206 dc
.SetTextForeground(col
);
207 dc
.SetBackgroundMode(wxTRANSPARENT
);
208 long textWidth
, textHeight
;
209 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
211 int textX
= (int)(tabX
+ (GetWidth() - textWidth
)/2.0);
212 if (textX
< (tabX
+ 2))
215 dc
.SetClippingRegion(tabX
, tabY
, GetWidth(), GetHeight());
216 dc
.DrawText(GetLabel(), textX
, textY
);
217 dc
.DestroyClippingRegion();
221 dc
.SetPen(*m_view
->GetHighlightPen());
223 // Draw white highlight from the tab's left side to the left hand edge of the view
224 dc
.DrawLine(m_view
->GetViewRect().x
, (tabY
+ GetHeight() + tabHeightInc
),
225 tabX
, (tabY
+ GetHeight() + tabHeightInc
));
227 // Draw white highlight from the tab's right side to the right hand edge of the view
228 dc
.DrawLine((tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
),
229 m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
, (tabY
+ GetHeight() + tabHeightInc
));
232 // New HEL version with rounder tabs
239 tabInc
= m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight();
241 int tabLeft
= GetX() + m_view
->GetViewRect().x
;
242 int tabTop
= GetY() + m_view
->GetViewRect().y
- tabInc
;
243 int tabRight
= tabLeft
+ m_view
->GetTabWidth();
244 int left
= m_view
->GetViewRect().x
;
245 int top
= tabTop
+ m_view
->GetTabHeight() + tabInc
;
246 int right
= left
+ m_view
->GetViewRect().width
;
247 int bottom
= top
+ m_view
->GetViewRect().height
;
251 // TAB is selected - draw TAB and the View's full outline
253 dc
.SetPen(*(m_view
->GetHighlightPen()));
256 pnts
[n
].x
= left
; pnts
[n
++].y
= bottom
;
257 pnts
[n
].x
= left
; pnts
[n
++].y
= top
;
258 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= top
;
259 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
260 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
261 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
262 dc
.DrawLines(n
, pnts
);
273 dc
.SetPen(*(m_view
->GetShadowPen()));
293 dc
.SetPen(*wxBLACK_PEN
);
335 // TAB is not selected - just draw TAB outline and RH edge
336 // if the TAB is the last in the row
338 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Nth(0)->Data())->Number();
339 wxTabControl
* tabBelow
= 0;
340 wxTabControl
* tabBelowRight
= 0;
341 if (GetColPosition() > 0)
343 tabBelow
= m_view
->FindTabControlForPosition(
344 GetColPosition() - 1,
348 if (!lastInRow
&& GetColPosition() > 0)
350 tabBelowRight
= m_view
->FindTabControlForPosition(
351 GetColPosition() - 1,
356 float raisedTop
= top
- m_view
->GetTabSelectionHeight() +
357 m_view
->GetTabHeight();
359 dc
.SetPen(*(m_view
->GetHighlightPen()));
365 if (tabBelow
&& tabBelow
->IsSelected())
367 pnts
[n
++].y
= (long)raisedTop
;
373 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
374 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
375 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
376 dc
.DrawLines(n
, pnts
);
378 dc
.SetPen(*(m_view
->GetShadowPen()));
379 if (GetRowPosition() >= maxPositions
- 1)
390 (tabRight
- m_view
->GetHorizontalTabOffset()),
396 if (tabBelowRight
&& tabBelowRight
->IsSelected())
416 dc
.SetPen(*wxBLACK_PEN
);
425 if (GetRowPosition() >= maxPositions
- 1)
427 // draw right hand edge to bottom of view
437 (tabRight
- m_view
->GetHorizontalTabOffset()),
443 // draw right hand edge of TAB
444 if (tabBelowRight
&& tabBelowRight
->IsSelected())
448 (long)(raisedTop
- 1),
465 // Draw centered text
466 dc
.SetPen(*wxBLACK_PEN
);
469 dc
.SetFont(*(m_view
->GetSelectedTabFont()));
473 dc
.SetFont(*(GetFont()));
476 wxColour
col(m_view
->GetTextColour());
477 dc
.SetTextForeground(col
);
478 dc
.SetBackgroundMode(wxTRANSPARENT
);
479 long textWidth
, textHeight
;
480 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
482 float textX
= (tabLeft
+ tabRight
- textWidth
) / 2;
483 float textY
= (tabInc
+ tabTop
+ m_view
->GetVerticalTabTextSpacing());
485 dc
.DrawText(GetLabel(), (long)textX
, (long)textY
);
489 bool wxTabControl::HitTest(int x
, int y
) const
491 // Top-left of tab control
492 int tabX1
= GetX() + m_view
->GetViewRect().x
;
493 int tabY1
= GetY() + m_view
->GetViewRect().y
;
496 int tabX2
= tabX1
+ GetWidth();
497 int tabY2
= tabY1
+ GetHeight();
499 if (x
>= tabX1
&& y
>= tabY1
&& x
<= tabX2
&& y
<= tabY2
)
505 IMPLEMENT_DYNAMIC_CLASS(wxTabView
, wxObject
)
507 wxTabView::wxTabView(long style
)
513 m_tabSelectionHeight
= m_tabHeight
+ 2;
515 m_tabHorizontalOffset
= 10;
516 m_tabHorizontalSpacing
= 2;
517 m_tabVerticalTextSpacing
= 3;
519 m_tabViewRect
.x
= 20;
520 m_tabViewRect
.y
= 20;
521 m_tabViewRect
.width
= 300;
522 m_tabViewRect
.x
= 300;
523 m_highlightColour
= *wxWHITE
;
524 m_shadowColour
= wxColour(128, 128, 128);
525 m_backgroundColour
= *wxLIGHT_GREY
;
526 m_textColour
= *wxBLACK
;
527 m_highlightPen
= wxWHITE_PEN
;
528 m_shadowPen
= wxGREY_PEN
;
529 m_backgroundPen
= wxLIGHT_GREY_PEN
;
530 m_backgroundBrush
= wxLIGHT_GREY_BRUSH
;
531 m_tabFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
532 m_tabSelectedFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
533 m_window
= (wxWindow
*) NULL
;
536 wxTabView::~wxTabView()
541 // Automatically positions tabs
542 // TODO: this should just add the tab to a list, and then
543 // a layout function (e.g. Realize) should be called when all tabs have been added.
544 // The view rect could easily change as the view window is resized.
545 wxTabControl
*wxTabView::AddTab(int id
, const wxString
& label
, wxTabControl
*existingTab
)
547 // First, find which layer we should be adding to.
548 wxNode
*node
= m_layers
.Last();
551 wxTabLayer
*newLayer
= new wxTabLayer
;
552 node
= m_layers
.Append(newLayer
);
554 // Check if adding another tab control would go off the
555 // right-hand edge of the layer.
556 wxTabLayer
*tabLayer
= (wxTabLayer
*)node
->Data();
557 wxNode
*lastTabNode
= tabLayer
->Last();
560 wxTabControl
*lastTab
= (wxTabControl
*)lastTabNode
->Data();
561 // Start another layer (row).
562 // Tricky choice: can't just check if will be overlapping the edge, because
563 // this happens anyway for 2nd and subsequent rows.
564 // Should check this for 1st row, and then subsequent rows should not exceed 1st
566 if (((tabLayer
== m_layers
.First()->Data()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
567 > GetViewRect().width
)) ||
568 ((tabLayer
!= m_layers
.First()->Data()) && (tabLayer
->Number() == ((wxTabLayer
*)m_layers
.First()->Data())->Number())))
570 tabLayer
= new wxTabLayer
;
571 m_layers
.Append(tabLayer
);
572 lastTabNode
= (wxNode
*) NULL
;
575 int layer
= m_layers
.Number() - 1;
577 wxTabControl
*tabControl
= existingTab
;
579 tabControl
= OnCreateTabControl();
580 tabControl
->SetRowPosition(tabLayer
->Number());
581 tabControl
->SetColPosition(layer
);
583 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
585 lastTab
= (wxTabControl
*)lastTabNode
->Data();
588 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
589 // Offset from view top-left
590 int horizontalOffset
= 0;
592 horizontalOffset
= layer
*GetHorizontalTabOffset();
594 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
596 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
597 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
598 tabControl
->SetId(id
);
599 tabControl
->SetLabel(label
);
600 tabControl
->SetFont(* GetTabFont());
602 tabLayer
->Append(tabControl
);
608 // Remove the tab without deleting the window
609 bool wxTabView::RemoveTab(int id
)
611 wxNode
*layerNode
= m_layers
.First();
614 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
615 wxNode
*tabNode
= layer
->First();
618 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
619 if (tab
->GetId() == id
)
621 if (id
== m_tabSelection
)
627 // The layout has changed
631 tabNode
= tabNode
->Next();
633 layerNode
= layerNode
->Next();
638 bool wxTabView::SetTabText(int id
, const wxString
& label
)
640 wxTabControl
* control
= FindTabControlForId(id
);
643 control
->SetLabel(label
);
647 wxString
wxTabView::GetTabText(int id
) const
649 wxTabControl
* control
= FindTabControlForId(id
);
651 return wxEmptyString
;
653 return control
->GetLabel();
656 // Returns the total height of the tabs component -- this may be several
657 // times the height of a tab, if there are several tab layers (rows).
658 int wxTabView::GetTotalTabHeight()
662 wxNode
*layerNode
= m_layers
.First();
665 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
666 wxNode
*tabNode
= layer
->First();
669 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
671 if (tab
->GetY() < minY
)
674 tabNode
= tabNode
->Next();
676 layerNode
= layerNode
->Next();
682 void wxTabView::ClearTabs(bool deleteTabs
)
684 wxNode
*layerNode
= m_layers
.First();
687 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
688 wxNode
*tabNode
= layer
->First();
691 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
694 wxNode
*next
= tabNode
->Next();
698 wxNode
*nextLayerNode
= layerNode
->Next();
701 layerNode
= nextLayerNode
;
708 // Layout tabs (optional, e.g. if resizing window)
709 void wxTabView::LayoutTabs(void)
711 // Make a list of the tab controls, deleting the wxTabLayers.
714 wxNode
*layerNode
= m_layers
.First();
717 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->Data();
718 wxNode
*tabNode
= layer
->First();
721 wxTabControl
*tab
= (wxTabControl
*)tabNode
->Data();
722 controls
.Append(tab
);
723 wxNode
*next
= tabNode
->Next();
727 wxNode
*nextLayerNode
= layerNode
->Next();
730 layerNode
= nextLayerNode
;
733 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
735 wxTabLayer
*currentLayer
= new wxTabLayer
;
736 m_layers
.Append(currentLayer
);
738 wxNode
*node
= controls
.First();
741 wxTabControl
*tabControl
= (wxTabControl
*)node
->Data();
744 // Start another layer (row).
745 // Tricky choice: can't just check if will be overlapping the edge, because
746 // this happens anyway for 2nd and subsequent rows.
747 // Should check this for 1st row, and then subsequent rows should not exceed 1st
749 if (((currentLayer
== m_layers
.First()->Data()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
750 > GetViewRect().width
)) ||
751 ((currentLayer
!= m_layers
.First()->Data()) && (currentLayer
->Number() == ((wxTabLayer
*)m_layers
.First()->Data())->Number())))
753 currentLayer
= new wxTabLayer
;
754 m_layers
.Append(currentLayer
);
755 lastTab
= (wxTabControl
*) NULL
;
759 int layer
= m_layers
.Number() - 1;
761 tabControl
->SetRowPosition(currentLayer
->Number());
762 tabControl
->SetColPosition(layer
);
765 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
766 // Offset from view top-left
767 int horizontalOffset
= 0;
769 horizontalOffset
= layer
*GetHorizontalTabOffset();
771 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
773 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
774 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
776 currentLayer
->Append(tabControl
);
777 lastTab
= tabControl
;
782 // Move the selected tab to the bottom
783 wxTabControl
*control
= FindTabControlForId(m_tabSelection
);
785 MoveSelectionTab(control
);
790 void wxTabView::Draw(wxDC
& dc
)
792 // Don't draw anything if there are no tabs.
793 if (GetNumberOfTabs() == 0)
796 // Draw top margin area (beneath tabs and above view area)
797 if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
799 dc
.SetPen(*wxTRANSPARENT_PEN
);
800 dc
.SetBrush(*GetBackgroundBrush());
802 // Add 1 because the pen is transparent. Under Motif, may be different.
805 (m_tabViewRect
.y
- m_topMargin
),
806 (m_tabViewRect
.width
+ 1),
811 // Draw layers in reverse order
812 wxNode
*node
= m_layers
.Last();
815 wxTabLayer
*layer
= (wxTabLayer
*)node
->Data();
816 wxNode
*node2
= layer
->First();
819 wxTabControl
*control
= (wxTabControl
*)node2
->Data();
820 control
->OnDraw(dc
, (node2
->Next() == NULL
));
821 node2
= node2
->Next();
824 node
= node
->Previous();
828 #ifndef wxUSE_NEW_METHOD
829 if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX
)
831 dc
.SetPen(* GetShadowPen());
835 (GetViewRect().x
+ 1),
836 (GetViewRect().y
+ GetViewRect().height
),
837 (GetViewRect().x
+ GetViewRect().width
+ 1),
838 (GetViewRect().y
+ GetViewRect().height
)
843 (GetViewRect().x
+ GetViewRect().width
),
844 (GetViewRect().y
- GetTopMargin() + 1),
845 (GetViewRect().x
+ GetViewRect().width
),
846 (GetViewRect().y
+ GetViewRect().height
)
849 dc
.SetPen(* wxBLACK_PEN
);
854 (GetViewRect().y
+ GetViewRect().height
+ 1),
855 #if defined(__WXMOTIF__)
856 (GetViewRect().x
+ GetViewRect().width
+ 1),
858 (GetViewRect().x
+ GetViewRect().width
+ 2),
861 (GetViewRect().y
+ GetViewRect().height
+ 1)
866 (GetViewRect().x
+ GetViewRect().width
+ 1),
867 (GetViewRect().y
- GetTopMargin()),
868 (GetViewRect().x
+ GetViewRect().width
+ 1),
869 (GetViewRect().y
+ GetViewRect().height
+ 1)
875 // Process mouse event, return FALSE if we didn't process it
876 bool wxTabView::OnEvent(wxMouseEvent
& event
)
878 if (!event
.LeftDown())
882 event
.GetPosition(&x
, &y
);
884 wxTabControl
*hitControl
= (wxTabControl
*) NULL
;
886 wxNode
*node
= m_layers
.First();
889 wxTabLayer
*layer
= (wxTabLayer
*)node
->Data();
890 wxNode
*node2
= layer
->First();
893 wxTabControl
*control
= (wxTabControl
*)node2
->Data();
894 if (control
->HitTest((int)x
, (int)y
))
896 hitControl
= control
;
897 node
= (wxNode
*) NULL
;
898 node2
= (wxNode
*) NULL
;
901 node2
= node2
->Next();
911 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
913 if (hitControl
== currentTab
)
916 ChangeTab(hitControl
);
921 bool wxTabView::ChangeTab(wxTabControl
*control
)
923 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
926 oldTab
= currentTab
->GetId();
928 if (control
== currentTab
)
931 if (m_layers
.Number() == 0)
934 if (!OnTabPreActivate(control
->GetId(), oldTab
))
937 // Move the tab to the bottom
938 MoveSelectionTab(control
);
941 currentTab
->SetSelected(FALSE
);
943 control
->SetSelected(TRUE
);
944 m_tabSelection
= control
->GetId();
946 OnTabActivate(control
->GetId(), oldTab
);
948 // Leave window refresh for the implementing window
953 // Move the selected tab to the bottom layer, if necessary,
954 // without calling app activation code
955 bool wxTabView::MoveSelectionTab(wxTabControl
*control
)
957 if (m_layers
.Number() == 0)
960 wxTabLayer
*firstLayer
= (wxTabLayer
*)m_layers
.First()->Data();
962 // Find what column this tab is at, so we can swap with the one at the bottom.
963 // If we're on the bottom layer, then no need to swap.
964 if (!firstLayer
->Member(control
))
968 wxNode
*thisNode
= FindTabNodeAndColumn(control
, &col
);
971 wxNode
*otherNode
= firstLayer
->Nth(col
);
975 // If this is already in the bottom layer, return now
976 if (otherNode
== thisNode
)
979 wxTabControl
*otherTab
= (wxTabControl
*)otherNode
->Data();
981 // We now have pointers to the tab to be changed to,
982 // and the tab on the first layer. Swap tab structures and
985 int thisX
= control
->GetX();
986 int thisY
= control
->GetY();
987 int thisColPos
= control
->GetColPosition();
988 int otherX
= otherTab
->GetX();
989 int otherY
= otherTab
->GetY();
990 int otherColPos
= otherTab
->GetColPosition();
992 control
->SetPosition(otherX
, otherY
);
993 control
->SetColPosition(otherColPos
);
994 otherTab
->SetPosition(thisX
, thisY
);
995 otherTab
->SetColPosition(thisColPos
);
997 // Swap the data for the nodes
998 thisNode
->SetData(otherTab
);
999 otherNode
->SetData(control
);
1004 // Called when a tab is activated
1005 void wxTabView::OnTabActivate(int /*activateId*/, int /*deactivateId*/)
1009 void wxTabView::SetHighlightColour(const wxColour
& col
)
1011 m_highlightColour
= col
;
1012 m_highlightPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1015 void wxTabView::SetShadowColour(const wxColour
& col
)
1017 m_shadowColour
= col
;
1018 m_shadowPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1021 void wxTabView::SetBackgroundColour(const wxColour
& col
)
1023 m_backgroundColour
= col
;
1024 m_backgroundPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1025 m_backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(col
, wxSOLID
);
1028 void wxTabView::SetTabSelection(int sel
, bool activateTool
)
1030 if ( sel
==m_tabSelection
)
1033 int oldSel
= m_tabSelection
;
1034 wxTabControl
*control
= FindTabControlForId(sel
);
1035 wxTabControl
*oldControl
= FindTabControlForId(m_tabSelection
);
1037 if (!OnTabPreActivate(sel
, oldSel
))
1041 control
->SetSelected((sel
!= -1)); // TODO ??
1044 wxFAIL_MSG(_("Could not find tab for id"));
1049 oldControl
->SetSelected(FALSE
);
1051 m_tabSelection
= sel
;
1054 MoveSelectionTab(control
);
1057 OnTabActivate(sel
, oldSel
);
1060 // Find tab control for id
1061 wxTabControl
*wxTabView::FindTabControlForId(int id
) const
1063 wxNode
*node1
= m_layers
.First();
1066 wxTabLayer
*layer
= (wxTabLayer
*)node1
->Data();
1067 wxNode
*node2
= layer
->First();
1070 wxTabControl
*control
= (wxTabControl
*)node2
->Data();
1071 if (control
->GetId() == id
)
1073 node2
= node2
->Next();
1075 node1
= node1
->Next();
1077 return (wxTabControl
*) NULL
;
1080 // Find tab control for layer, position (starting from zero)
1081 wxTabControl
*wxTabView::FindTabControlForPosition(int layer
, int position
) const
1083 wxNode
*node1
= m_layers
.Nth(layer
);
1085 return (wxTabControl
*) NULL
;
1086 wxTabLayer
*tabLayer
= (wxTabLayer
*)node1
->Data();
1087 wxNode
*node2
= tabLayer
->Nth(position
);
1089 return (wxTabControl
*) NULL
;
1090 return (wxTabControl
*)node2
->Data();
1093 // Find the node and the column at which this control is positioned.
1094 wxNode
*wxTabView::FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const
1096 wxNode
*node1
= m_layers
.First();
1099 wxTabLayer
*layer
= (wxTabLayer
*)node1
->Data();
1101 wxNode
*node2
= layer
->First();
1104 wxTabControl
*cnt
= (wxTabControl
*)node2
->Data();
1110 node2
= node2
->Next();
1113 node1
= node1
->Next();
1115 return (wxNode
*) NULL
;
1118 int wxTabView::CalculateTabWidth(int noTabs
, bool adjustView
)
1120 m_tabWidth
= (int)((m_tabViewRect
.width
- ((noTabs
- 1)*GetHorizontalTabSpacing()))/noTabs
);
1123 m_tabViewRect
.width
= noTabs
*m_tabWidth
+ ((noTabs
-1)*GetHorizontalTabSpacing());
1132 IMPLEMENT_CLASS(wxTabbedDialog
, wxDialog
)
1134 BEGIN_EVENT_TABLE(wxTabbedDialog
, wxDialog
)
1135 EVT_CLOSE(wxTabbedDialog::OnCloseWindow
)
1136 EVT_MOUSE_EVENTS(wxTabbedDialog::OnMouseEvent
)
1137 EVT_PAINT(wxTabbedDialog::OnPaint
)
1140 wxTabbedDialog::wxTabbedDialog(wxWindow
*parent
, wxWindowID id
,
1141 const wxString
& title
,
1142 const wxPoint
& pos
, const wxSize
& size
,
1143 long windowStyle
, const wxString
& name
):
1144 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
, name
)
1146 m_tabView
= (wxTabView
*) NULL
;
1149 wxTabbedDialog::~wxTabbedDialog(void)
1155 void wxTabbedDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
1160 void wxTabbedDialog::OnMouseEvent(wxMouseEvent
& event
)
1163 m_tabView
->OnEvent(event
);
1166 void wxTabbedDialog::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1170 m_tabView
->Draw(dc
);
1177 IMPLEMENT_CLASS(wxTabbedPanel
, wxPanel
)
1179 BEGIN_EVENT_TABLE(wxTabbedPanel
, wxPanel
)
1180 EVT_MOUSE_EVENTS(wxTabbedPanel::OnMouseEvent
)
1181 EVT_PAINT(wxTabbedPanel::OnPaint
)
1184 wxTabbedPanel::wxTabbedPanel(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
1185 const wxSize
& size
, long windowStyle
, const wxString
& name
):
1186 wxPanel(parent
, id
, pos
, size
, windowStyle
, name
)
1188 m_tabView
= (wxTabView
*) NULL
;
1191 wxTabbedPanel::~wxTabbedPanel(void)
1196 void wxTabbedPanel::OnMouseEvent(wxMouseEvent
& event
)
1199 m_tabView
->OnEvent(event
);
1202 void wxTabbedPanel::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1206 m_tabView
->Draw(dc
);
1213 IMPLEMENT_CLASS(wxPanelTabView
, wxTabView
)
1215 wxPanelTabView::wxPanelTabView(wxPanel
*pan
, long style
): wxTabView(style
), m_tabWindows(wxKEY_INTEGER
)
1218 m_currentWindow
= (wxWindow
*) NULL
;
1220 if (m_panel
->IsKindOf(CLASSINFO(wxTabbedDialog
)))
1221 ((wxTabbedDialog
*)m_panel
)->SetTabView(this);
1222 else if (m_panel
->IsKindOf(CLASSINFO(wxTabbedPanel
)))
1223 ((wxTabbedPanel
*)m_panel
)->SetTabView(this);
1228 wxPanelTabView::~wxPanelTabView(void)
1233 // Called when a tab is activated
1234 void wxPanelTabView::OnTabActivate(int activateId
, int deactivateId
)
1239 wxWindow
*oldWindow
= ((deactivateId
== -1) ? 0 : GetTabWindow(deactivateId
));
1240 wxWindow
*newWindow
= GetTabWindow(activateId
);
1243 oldWindow
->Show(FALSE
);
1245 newWindow
->Show(TRUE
);
1251 void wxPanelTabView::AddTabWindow(int id
, wxWindow
*window
)
1253 m_tabWindows
.Append((long)id
, window
);
1254 window
->Show(FALSE
);
1257 wxWindow
*wxPanelTabView::GetTabWindow(int id
) const
1259 wxNode
*node
= m_tabWindows
.Find((long)id
);
1261 return (wxWindow
*) NULL
;
1262 return (wxWindow
*)node
->Data();
1265 void wxPanelTabView::ClearWindows(bool deleteWindows
)
1268 m_tabWindows
.DeleteContents(TRUE
);
1269 m_tabWindows
.Clear();
1270 m_tabWindows
.DeleteContents(FALSE
);
1273 void wxPanelTabView::ShowWindowForTab(int id
)
1275 wxWindow
*newWindow
= GetTabWindow(id
);
1276 if (newWindow
== m_currentWindow
)
1278 if (m_currentWindow
)
1279 m_currentWindow
->Show(FALSE
);
1280 newWindow
->Show(TRUE
);
1281 newWindow
->Refresh();
1284 #endif // wxUSE_TAB_DIALOG