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"
26 #include "wx/settings.h"
37 // not defined: use old, square tab implementation (fills in tabs)
38 // defined: use new, rounded tab implementation (doesn't colour in tabs)
39 // #define wxUSE_NEW_METHOD
41 IMPLEMENT_DYNAMIC_CLASS(wxTabControl
, wxObject
)
43 IMPLEMENT_DYNAMIC_CLASS(wxTabLayer
, wxList
)
45 wxTabControl::wxTabControl(wxTabView
*v
)
58 wxTabControl::~wxTabControl(void)
62 void wxTabControl::OnDraw(wxDC
& dc
, bool lastInRow
)
64 // Old, but in some ways better (drawing opaque tabs)
65 #ifndef wxUSE_NEW_METHOD
69 // Top-left of tab view area
70 int viewX
= m_view
->GetViewRect().x
;
71 int viewY
= m_view
->GetViewRect().y
;
73 // Top-left of tab control
74 int tabX
= GetX() + viewX
;
75 int tabY
= GetY() + viewY
;
79 tabHeightInc
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
83 dc
.SetPen(*wxTRANSPARENT_PEN
);
85 // Draw grey background
86 if (m_view
->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
88 dc
.SetBrush(*m_view
->GetBackgroundBrush());
90 // Add 1 because the pen is transparent. Under Motif, may be different.
92 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + tabHeightInc
));
94 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc
));
98 // Draw highlight and shadow
99 dc
.SetPen(*m_view
->GetHighlightPen());
101 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
102 // a bit if the tab below happens to be selected. Check.
103 wxTabControl
*tabBeneath
= NULL
;
104 int subtractThis
= 0;
105 if (GetColPosition() > 0)
106 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition());
107 if (tabBeneath
&& tabBeneath
->IsSelected())
108 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
110 // Vertical highlight: if first tab, draw to bottom of view
111 if (tabX
== m_view
->GetViewRect().x
&& (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
112 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
));
113 else if (tabX
== m_view
->GetViewRect().x
)
114 // Not box drawing, just to top of view.
115 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
));
117 dc
.DrawLine(tabX
, tabY
, tabX
, (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
119 dc
.DrawLine(tabX
, tabY
, (tabX
+ GetWidth()), tabY
);
120 dc
.SetPen(*m_view
->GetShadowPen());
122 // Test if we're outside the right-hand edge of the view area
123 if (((tabX
+ GetWidth()) >= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
) && (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
125 int bottomY
= m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
+ GetY() + m_view
->GetTabHeight() + m_view
->GetTopMargin();
126 // Add a tab height since we wish to draw to the bottom of the view.
127 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
128 (tabX
+ GetWidth()), bottomY
);
130 // Calculate the far-right of the view, since we don't wish to
132 int rightOfView
= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
+ 1;
134 // Draw the horizontal bit to connect to the view rectangle
135 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
-1),
136 (tabX
+ GetWidth()), (bottomY
-1));
138 // Draw black line to emphasize shadow
139 dc
.SetPen(*wxBLACK_PEN
);
140 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1),
141 (tabX
+ GetWidth() + 1), bottomY
);
143 // Draw the horizontal bit to connect to the view rectangle
144 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
),
145 (tabX
+ GetWidth() + 1), (bottomY
));
151 // 25/5/97 UNLESS it's less than the max number of positions in this row
153 int topY
= m_view
->GetViewRect().y
- m_view
->GetTopMargin();
155 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Item(0)->GetData())->GetCount();
157 // Only down to the bottom of the tab, not to the top of the view
158 if ( GetRowPosition() < (maxPositions
- 1) )
159 topY
= tabY
+ GetHeight() + tabHeightInc
;
166 dc
.DrawLine((tabX
+ GetWidth()), tabY
, (tabX
+ GetWidth()), topY
);
167 // Draw black line to emphasize shadow
168 dc
.SetPen(*wxBLACK_PEN
);
169 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
174 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
175 // a bit if the tab below (and next col along) happens to be selected. Check.
176 wxTabControl
*tabBeneath
= NULL
;
177 int subtractThis
= 0;
178 if (GetColPosition() > 0)
179 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1);
180 if (tabBeneath
&& tabBeneath
->IsSelected())
181 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
187 // Draw only to next tab down.
188 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
189 (tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
191 // Draw black line to emphasize shadow
192 dc
.SetPen(*wxBLACK_PEN
);
193 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
194 (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
198 // Draw centered text
199 int textY
= tabY
+ m_view
->GetVerticalTabTextSpacing() + tabHeightInc
;
202 dc
.SetFont(* m_view
->GetSelectedTabFont());
204 dc
.SetFont(* GetFont());
206 wxColour
col(m_view
->GetTextColour());
207 dc
.SetTextForeground(col
);
208 dc
.SetBackgroundMode(wxTRANSPARENT
);
209 long textWidth
, textHeight
;
210 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
212 int textX
= (int)(tabX
+ (GetWidth() - textWidth
)/2.0);
213 if (textX
< (tabX
+ 2))
216 dc
.SetClippingRegion(tabX
, tabY
, GetWidth(), GetHeight());
217 dc
.DrawText(GetLabel(), textX
, textY
);
218 dc
.DestroyClippingRegion();
222 dc
.SetPen(*m_view
->GetHighlightPen());
224 // Draw white highlight from the tab's left side to the left hand edge of the view
225 dc
.DrawLine(m_view
->GetViewRect().x
, (tabY
+ GetHeight() + tabHeightInc
),
226 tabX
, (tabY
+ GetHeight() + tabHeightInc
));
228 // Draw white highlight from the tab's right side to the right hand edge of the view
229 dc
.DrawLine((tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
),
230 m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
, (tabY
+ GetHeight() + tabHeightInc
));
233 // New HEL version with rounder tabs
240 tabInc
= m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight();
242 int tabLeft
= GetX() + m_view
->GetViewRect().x
;
243 int tabTop
= GetY() + m_view
->GetViewRect().y
- tabInc
;
244 int tabRight
= tabLeft
+ m_view
->GetTabWidth();
245 int left
= m_view
->GetViewRect().x
;
246 int top
= tabTop
+ m_view
->GetTabHeight() + tabInc
;
247 int right
= left
+ m_view
->GetViewRect().width
;
248 int bottom
= top
+ m_view
->GetViewRect().height
;
252 // TAB is selected - draw TAB and the View's full outline
254 dc
.SetPen(*(m_view
->GetHighlightPen()));
257 pnts
[n
].x
= left
; pnts
[n
++].y
= bottom
;
258 pnts
[n
].x
= left
; pnts
[n
++].y
= top
;
259 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= top
;
260 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
261 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
262 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
263 dc
.DrawLines(n
, pnts
);
274 dc
.SetPen(*(m_view
->GetShadowPen()));
294 dc
.SetPen(*wxBLACK_PEN
);
336 // TAB is not selected - just draw TAB outline and RH edge
337 // if the TAB is the last in the row
339 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Item(0)->GetData())->GetCount();
340 wxTabControl
* tabBelow
= 0;
341 wxTabControl
* tabBelowRight
= 0;
342 if (GetColPosition() > 0)
344 tabBelow
= m_view
->FindTabControlForPosition(
345 GetColPosition() - 1,
349 if (!lastInRow
&& GetColPosition() > 0)
351 tabBelowRight
= m_view
->FindTabControlForPosition(
352 GetColPosition() - 1,
357 float raisedTop
= top
- m_view
->GetTabSelectionHeight() +
358 m_view
->GetTabHeight();
360 dc
.SetPen(*(m_view
->GetHighlightPen()));
366 if (tabBelow
&& tabBelow
->IsSelected())
368 pnts
[n
++].y
= (long)raisedTop
;
374 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
375 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
376 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
377 dc
.DrawLines(n
, pnts
);
379 dc
.SetPen(*(m_view
->GetShadowPen()));
380 if (GetRowPosition() >= maxPositions
- 1)
391 (tabRight
- m_view
->GetHorizontalTabOffset()),
397 if (tabBelowRight
&& tabBelowRight
->IsSelected())
417 dc
.SetPen(*wxBLACK_PEN
);
426 if (GetRowPosition() >= maxPositions
- 1)
428 // draw right hand edge to bottom of view
438 (tabRight
- m_view
->GetHorizontalTabOffset()),
444 // draw right hand edge of TAB
445 if (tabBelowRight
&& tabBelowRight
->IsSelected())
449 (long)(raisedTop
- 1),
466 // Draw centered text
467 dc
.SetPen(*wxBLACK_PEN
);
470 dc
.SetFont(*(m_view
->GetSelectedTabFont()));
474 dc
.SetFont(*(GetFont()));
477 wxColour
col(m_view
->GetTextColour());
478 dc
.SetTextForeground(col
);
479 dc
.SetBackgroundMode(wxTRANSPARENT
);
480 long textWidth
, textHeight
;
481 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
483 float textX
= (tabLeft
+ tabRight
- textWidth
) / 2;
484 float textY
= (tabInc
+ tabTop
+ m_view
->GetVerticalTabTextSpacing());
486 dc
.DrawText(GetLabel(), (long)textX
, (long)textY
);
490 bool wxTabControl::HitTest(int x
, int y
) const
492 // Top-left of tab control
493 int tabX1
= GetX() + m_view
->GetViewRect().x
;
494 int tabY1
= GetY() + m_view
->GetViewRect().y
;
497 int tabX2
= tabX1
+ GetWidth();
498 int tabY2
= tabY1
+ GetHeight();
500 if (x
>= tabX1
&& y
>= tabY1
&& x
<= tabX2
&& y
<= tabY2
)
506 IMPLEMENT_DYNAMIC_CLASS(wxTabView
, wxObject
)
508 wxTabView::wxTabView(long style
)
514 m_tabSelectionHeight
= m_tabHeight
+ 2;
516 m_tabHorizontalOffset
= 10;
517 m_tabHorizontalSpacing
= 2;
518 m_tabVerticalTextSpacing
= 3;
520 m_tabViewRect
.x
= 20;
521 m_tabViewRect
.y
= 20;
522 m_tabViewRect
.width
= 300;
523 m_tabViewRect
.x
= 300;
524 m_highlightColour
= *wxWHITE
;
525 m_shadowColour
= wxColour(128, 128, 128);
526 m_backgroundColour
= *wxLIGHT_GREY
;
527 m_textColour
= *wxBLACK
;
528 m_highlightPen
= wxWHITE_PEN
;
529 m_shadowPen
= wxGREY_PEN
;
530 m_backgroundPen
= wxLIGHT_GREY_PEN
;
531 m_backgroundBrush
= wxLIGHT_GREY_BRUSH
;
532 m_tabFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
533 m_tabSelectedFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
534 m_window
= (wxWindow
*) NULL
;
537 wxTabView::~wxTabView()
542 // Automatically positions tabs
543 // TODO: this should just add the tab to a list, and then
544 // a layout function (e.g. Realize) should be called when all tabs have been added.
545 // The view rect could easily change as the view window is resized.
546 wxTabControl
*wxTabView::AddTab(int id
, const wxString
& label
, wxTabControl
*existingTab
)
548 // First, find which layer we should be adding to.
549 wxNode
*node
= m_layers
.GetLast();
552 wxTabLayer
*newLayer
= new wxTabLayer
;
553 node
= m_layers
.Append(newLayer
);
555 // Check if adding another tab control would go off the
556 // right-hand edge of the layer.
557 wxTabLayer
*tabLayer
= (wxTabLayer
*)node
->GetData();
558 wxNode
*lastTabNode
= tabLayer
->GetLast();
561 wxTabControl
*lastTab
= (wxTabControl
*)lastTabNode
->GetData();
562 // Start another layer (row).
563 // Tricky choice: can't just check if will be overlapping the edge, because
564 // this happens anyway for 2nd and subsequent rows.
565 // Should check this for 1st row, and then subsequent rows should not exceed 1st
567 if (((tabLayer
== m_layers
.GetFirst()->GetData()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
568 > GetViewRect().width
)) ||
569 ((tabLayer
!= m_layers
.GetFirst()->GetData()) && (tabLayer
->GetCount() == ((wxTabLayer
*)m_layers
.GetFirst()->GetData())->GetCount())))
571 tabLayer
= new wxTabLayer
;
572 m_layers
.Append(tabLayer
);
573 lastTabNode
= (wxNode
*) NULL
;
576 int layer
= m_layers
.GetCount() - 1;
578 wxTabControl
*tabControl
= existingTab
;
580 tabControl
= OnCreateTabControl();
581 tabControl
->SetRowPosition(tabLayer
->GetCount());
582 tabControl
->SetColPosition(layer
);
584 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
586 lastTab
= (wxTabControl
*)lastTabNode
->GetData();
589 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
590 // Offset from view top-left
591 int horizontalOffset
= 0;
593 horizontalOffset
= layer
*GetHorizontalTabOffset();
595 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
597 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
598 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
599 tabControl
->SetId(id
);
600 tabControl
->SetLabel(label
);
601 tabControl
->SetFont(* GetTabFont());
603 tabLayer
->Append(tabControl
);
609 // Remove the tab without deleting the window
610 bool wxTabView::RemoveTab(int id
)
612 wxNode
*layerNode
= m_layers
.GetFirst();
615 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
616 wxNode
*tabNode
= layer
->GetFirst();
619 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
620 if (tab
->GetId() == id
)
622 if (id
== m_tabSelection
)
628 // The layout has changed
632 tabNode
= tabNode
->GetNext();
634 layerNode
= layerNode
->GetNext();
639 bool wxTabView::SetTabText(int id
, const wxString
& label
)
641 wxTabControl
* control
= FindTabControlForId(id
);
644 control
->SetLabel(label
);
648 wxString
wxTabView::GetTabText(int id
) const
650 wxTabControl
* control
= FindTabControlForId(id
);
652 return wxEmptyString
;
654 return control
->GetLabel();
657 // Returns the total height of the tabs component -- this may be several
658 // times the height of a tab, if there are several tab layers (rows).
659 int wxTabView::GetTotalTabHeight()
663 wxNode
*layerNode
= m_layers
.GetFirst();
666 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
667 wxNode
*tabNode
= layer
->GetFirst();
670 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
672 if (tab
->GetY() < minY
)
675 tabNode
= tabNode
->GetNext();
677 layerNode
= layerNode
->GetNext();
683 void wxTabView::ClearTabs(bool deleteTabs
)
685 wxNode
*layerNode
= m_layers
.GetFirst();
688 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
689 wxNode
*tabNode
= layer
->GetFirst();
692 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
695 wxNode
*next
= tabNode
->GetNext();
699 wxNode
*nextLayerNode
= layerNode
->GetNext();
702 layerNode
= nextLayerNode
;
709 // Layout tabs (optional, e.g. if resizing window)
710 void wxTabView::LayoutTabs(void)
712 // Make a list of the tab controls, deleting the wxTabLayers.
715 wxNode
*layerNode
= m_layers
.GetFirst();
718 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
719 wxNode
*tabNode
= layer
->GetFirst();
722 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
723 controls
.Append(tab
);
724 wxNode
*next
= tabNode
->GetNext();
728 wxNode
*nextLayerNode
= layerNode
->GetNext();
731 layerNode
= nextLayerNode
;
734 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
736 wxTabLayer
*currentLayer
= new wxTabLayer
;
737 m_layers
.Append(currentLayer
);
739 wxNode
*node
= controls
.GetFirst();
742 wxTabControl
*tabControl
= (wxTabControl
*)node
->GetData();
745 // Start another layer (row).
746 // Tricky choice: can't just check if will be overlapping the edge, because
747 // this happens anyway for 2nd and subsequent rows.
748 // Should check this for 1st row, and then subsequent rows should not exceed 1st
750 if (((currentLayer
== m_layers
.GetFirst()->GetData()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
751 > GetViewRect().width
)) ||
752 ((currentLayer
!= m_layers
.GetFirst()->GetData()) && (currentLayer
->GetCount() == ((wxTabLayer
*)m_layers
.GetFirst()->GetData())->GetCount())))
754 currentLayer
= new wxTabLayer
;
755 m_layers
.Append(currentLayer
);
756 lastTab
= (wxTabControl
*) NULL
;
760 int layer
= m_layers
.GetCount() - 1;
762 tabControl
->SetRowPosition(currentLayer
->GetCount());
763 tabControl
->SetColPosition(layer
);
766 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
767 // Offset from view top-left
768 int horizontalOffset
= 0;
770 horizontalOffset
= layer
*GetHorizontalTabOffset();
772 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
774 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
775 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
777 currentLayer
->Append(tabControl
);
778 lastTab
= tabControl
;
780 node
= node
->GetNext();
783 // Move the selected tab to the bottom
784 wxTabControl
*control
= FindTabControlForId(m_tabSelection
);
786 MoveSelectionTab(control
);
791 void wxTabView::Draw(wxDC
& dc
)
793 // Don't draw anything if there are no tabs.
794 if (GetNumberOfTabs() == 0)
797 // Draw top margin area (beneath tabs and above view area)
798 if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
800 dc
.SetPen(*wxTRANSPARENT_PEN
);
801 dc
.SetBrush(*GetBackgroundBrush());
803 // Add 1 because the pen is transparent. Under Motif, may be different.
806 (m_tabViewRect
.y
- m_topMargin
),
807 (m_tabViewRect
.width
+ 1),
812 // Draw layers in reverse order
813 wxNode
*node
= m_layers
.GetLast();
816 wxTabLayer
*layer
= (wxTabLayer
*)node
->GetData();
817 wxNode
*node2
= layer
->GetFirst();
820 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
821 control
->OnDraw(dc
, (node2
->GetNext() == NULL
));
822 node2
= node2
->GetNext();
825 node
= node
->GetPrevious();
829 #ifndef wxUSE_NEW_METHOD
830 if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX
)
832 dc
.SetPen(* GetShadowPen());
836 (GetViewRect().x
+ 1),
837 (GetViewRect().y
+ GetViewRect().height
),
838 (GetViewRect().x
+ GetViewRect().width
+ 1),
839 (GetViewRect().y
+ GetViewRect().height
)
844 (GetViewRect().x
+ GetViewRect().width
),
845 (GetViewRect().y
- GetTopMargin() + 1),
846 (GetViewRect().x
+ GetViewRect().width
),
847 (GetViewRect().y
+ GetViewRect().height
)
850 dc
.SetPen(* wxBLACK_PEN
);
855 (GetViewRect().y
+ GetViewRect().height
+ 1),
856 #if defined(__WXMOTIF__)
857 (GetViewRect().x
+ GetViewRect().width
+ 1),
859 (GetViewRect().x
+ GetViewRect().width
+ 2),
862 (GetViewRect().y
+ GetViewRect().height
+ 1)
867 (GetViewRect().x
+ GetViewRect().width
+ 1),
868 (GetViewRect().y
- GetTopMargin()),
869 (GetViewRect().x
+ GetViewRect().width
+ 1),
870 (GetViewRect().y
+ GetViewRect().height
+ 1)
876 // Process mouse event, return FALSE if we didn't process it
877 bool wxTabView::OnEvent(wxMouseEvent
& event
)
879 if (!event
.LeftDown())
883 event
.GetPosition(&x
, &y
);
885 wxTabControl
*hitControl
= (wxTabControl
*) NULL
;
887 wxNode
*node
= m_layers
.GetFirst();
890 wxTabLayer
*layer
= (wxTabLayer
*)node
->GetData();
891 wxNode
*node2
= layer
->GetFirst();
894 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
895 if (control
->HitTest((int)x
, (int)y
))
897 hitControl
= control
;
898 node
= (wxNode
*) NULL
;
899 node2
= (wxNode
*) NULL
;
902 node2
= node2
->GetNext();
906 node
= node
->GetNext();
912 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
914 if (hitControl
== currentTab
)
917 ChangeTab(hitControl
);
922 bool wxTabView::ChangeTab(wxTabControl
*control
)
924 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
927 oldTab
= currentTab
->GetId();
929 if (control
== currentTab
)
932 if (m_layers
.GetCount() == 0)
935 if (!OnTabPreActivate(control
->GetId(), oldTab
))
938 // Move the tab to the bottom
939 MoveSelectionTab(control
);
942 currentTab
->SetSelected(FALSE
);
944 control
->SetSelected(TRUE
);
945 m_tabSelection
= control
->GetId();
947 OnTabActivate(control
->GetId(), oldTab
);
949 // Leave window refresh for the implementing window
954 // Move the selected tab to the bottom layer, if necessary,
955 // without calling app activation code
956 bool wxTabView::MoveSelectionTab(wxTabControl
*control
)
958 if (m_layers
.GetCount() == 0)
961 wxTabLayer
*firstLayer
= (wxTabLayer
*)m_layers
.GetFirst()->GetData();
963 // Find what column this tab is at, so we can swap with the one at the bottom.
964 // If we're on the bottom layer, then no need to swap.
965 if (!firstLayer
->Member(control
))
969 wxNode
*thisNode
= FindTabNodeAndColumn(control
, &col
);
972 wxNode
*otherNode
= firstLayer
->Item(col
);
976 // If this is already in the bottom layer, return now
977 if (otherNode
== thisNode
)
980 wxTabControl
*otherTab
= (wxTabControl
*)otherNode
->GetData();
982 // We now have pointers to the tab to be changed to,
983 // and the tab on the first layer. Swap tab structures and
986 int thisX
= control
->GetX();
987 int thisY
= control
->GetY();
988 int thisColPos
= control
->GetColPosition();
989 int otherX
= otherTab
->GetX();
990 int otherY
= otherTab
->GetY();
991 int otherColPos
= otherTab
->GetColPosition();
993 control
->SetPosition(otherX
, otherY
);
994 control
->SetColPosition(otherColPos
);
995 otherTab
->SetPosition(thisX
, thisY
);
996 otherTab
->SetColPosition(thisColPos
);
998 // Swap the data for the nodes
999 thisNode
->SetData(otherTab
);
1000 otherNode
->SetData(control
);
1005 // Called when a tab is activated
1006 void wxTabView::OnTabActivate(int /*activateId*/, int /*deactivateId*/)
1010 void wxTabView::SetHighlightColour(const wxColour
& col
)
1012 m_highlightColour
= col
;
1013 m_highlightPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1016 void wxTabView::SetShadowColour(const wxColour
& col
)
1018 m_shadowColour
= col
;
1019 m_shadowPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1022 void wxTabView::SetBackgroundColour(const wxColour
& col
)
1024 m_backgroundColour
= col
;
1025 m_backgroundPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1026 m_backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(col
, wxSOLID
);
1029 void wxTabView::SetTabSelection(int sel
, bool activateTool
)
1031 if ( sel
==m_tabSelection
)
1034 int oldSel
= m_tabSelection
;
1035 wxTabControl
*control
= FindTabControlForId(sel
);
1036 wxTabControl
*oldControl
= FindTabControlForId(m_tabSelection
);
1038 if (!OnTabPreActivate(sel
, oldSel
))
1042 control
->SetSelected((sel
!= -1)); // TODO ??
1045 wxFAIL_MSG(_("Could not find tab for id"));
1050 oldControl
->SetSelected(FALSE
);
1052 m_tabSelection
= sel
;
1055 MoveSelectionTab(control
);
1058 OnTabActivate(sel
, oldSel
);
1061 // Find tab control for id
1062 wxTabControl
*wxTabView::FindTabControlForId(int id
) const
1064 wxNode
*node1
= m_layers
.GetFirst();
1067 wxTabLayer
*layer
= (wxTabLayer
*)node1
->GetData();
1068 wxNode
*node2
= layer
->GetFirst();
1071 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
1072 if (control
->GetId() == id
)
1074 node2
= node2
->GetNext();
1076 node1
= node1
->GetNext();
1078 return (wxTabControl
*) NULL
;
1081 // Find tab control for layer, position (starting from zero)
1082 wxTabControl
*wxTabView::FindTabControlForPosition(int layer
, int position
) const
1084 wxNode
*node1
= m_layers
.Item(layer
);
1086 return (wxTabControl
*) NULL
;
1087 wxTabLayer
*tabLayer
= (wxTabLayer
*)node1
->GetData();
1088 wxNode
*node2
= tabLayer
->Item(position
);
1090 return (wxTabControl
*) NULL
;
1091 return (wxTabControl
*)node2
->GetData();
1094 // Find the node and the column at which this control is positioned.
1095 wxNode
*wxTabView::FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const
1097 wxNode
*node1
= m_layers
.GetFirst();
1100 wxTabLayer
*layer
= (wxTabLayer
*)node1
->GetData();
1102 wxNode
*node2
= layer
->GetFirst();
1105 wxTabControl
*cnt
= (wxTabControl
*)node2
->GetData();
1111 node2
= node2
->GetNext();
1114 node1
= node1
->GetNext();
1116 return (wxNode
*) NULL
;
1119 int wxTabView::CalculateTabWidth(int noTabs
, bool adjustView
)
1121 m_tabWidth
= (int)((m_tabViewRect
.width
- ((noTabs
- 1)*GetHorizontalTabSpacing()))/noTabs
);
1124 m_tabViewRect
.width
= noTabs
*m_tabWidth
+ ((noTabs
-1)*GetHorizontalTabSpacing());
1133 IMPLEMENT_CLASS(wxTabbedDialog
, wxDialog
)
1135 BEGIN_EVENT_TABLE(wxTabbedDialog
, wxDialog
)
1136 EVT_CLOSE(wxTabbedDialog::OnCloseWindow
)
1137 EVT_MOUSE_EVENTS(wxTabbedDialog::OnMouseEvent
)
1138 EVT_PAINT(wxTabbedDialog::OnPaint
)
1141 wxTabbedDialog::wxTabbedDialog(wxWindow
*parent
, wxWindowID id
,
1142 const wxString
& title
,
1143 const wxPoint
& pos
, const wxSize
& size
,
1144 long windowStyle
, const wxString
& name
):
1145 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
, name
)
1147 m_tabView
= (wxTabView
*) NULL
;
1150 wxTabbedDialog::~wxTabbedDialog(void)
1156 void wxTabbedDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
1161 void wxTabbedDialog::OnMouseEvent(wxMouseEvent
& event
)
1164 m_tabView
->OnEvent(event
);
1167 void wxTabbedDialog::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1171 m_tabView
->Draw(dc
);
1178 IMPLEMENT_CLASS(wxTabbedPanel
, wxPanel
)
1180 BEGIN_EVENT_TABLE(wxTabbedPanel
, wxPanel
)
1181 EVT_MOUSE_EVENTS(wxTabbedPanel::OnMouseEvent
)
1182 EVT_PAINT(wxTabbedPanel::OnPaint
)
1185 wxTabbedPanel::wxTabbedPanel(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
1186 const wxSize
& size
, long windowStyle
, const wxString
& name
):
1187 wxPanel(parent
, id
, pos
, size
, windowStyle
, name
)
1189 m_tabView
= (wxTabView
*) NULL
;
1192 wxTabbedPanel::~wxTabbedPanel(void)
1197 void wxTabbedPanel::OnMouseEvent(wxMouseEvent
& event
)
1200 m_tabView
->OnEvent(event
);
1203 void wxTabbedPanel::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1207 m_tabView
->Draw(dc
);
1214 IMPLEMENT_CLASS(wxPanelTabView
, wxTabView
)
1216 wxPanelTabView::wxPanelTabView(wxPanel
*pan
, long style
): wxTabView(style
), m_tabWindows(wxKEY_INTEGER
)
1219 m_currentWindow
= (wxWindow
*) NULL
;
1221 if (m_panel
->IsKindOf(CLASSINFO(wxTabbedDialog
)))
1222 ((wxTabbedDialog
*)m_panel
)->SetTabView(this);
1223 else if (m_panel
->IsKindOf(CLASSINFO(wxTabbedPanel
)))
1224 ((wxTabbedPanel
*)m_panel
)->SetTabView(this);
1229 wxPanelTabView::~wxPanelTabView(void)
1234 // Called when a tab is activated
1235 void wxPanelTabView::OnTabActivate(int activateId
, int deactivateId
)
1240 wxWindow
*oldWindow
= ((deactivateId
== -1) ? 0 : GetTabWindow(deactivateId
));
1241 wxWindow
*newWindow
= GetTabWindow(activateId
);
1244 oldWindow
->Show(FALSE
);
1246 newWindow
->Show(TRUE
);
1252 void wxPanelTabView::AddTabWindow(int id
, wxWindow
*window
)
1254 m_tabWindows
.Append((long)id
, window
);
1255 window
->Show(FALSE
);
1258 wxWindow
*wxPanelTabView::GetTabWindow(int id
) const
1260 wxNode
*node
= m_tabWindows
.Find((long)id
);
1262 return (wxWindow
*) NULL
;
1263 return (wxWindow
*)node
->GetData();
1266 void wxPanelTabView::ClearWindows(bool deleteWindows
)
1269 m_tabWindows
.DeleteContents(TRUE
);
1270 m_tabWindows
.Clear();
1271 m_tabWindows
.DeleteContents(FALSE
);
1274 void wxPanelTabView::ShowWindowForTab(int id
)
1276 wxWindow
*newWindow
= GetTabWindow(id
);
1277 if (newWindow
== m_currentWindow
)
1279 if (m_currentWindow
)
1280 m_currentWindow
->Show(FALSE
);
1281 newWindow
->Show(TRUE
);
1282 newWindow
->Refresh();
1285 #endif // wxUSE_TAB_DIALOG