1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/tabg.cpp
3 // Purpose: Generic tabbed dialogs
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/settings.h"
24 #include "wx/dcclient.h"
33 #include "wx/listimpl.cpp"
35 WX_DEFINE_LIST(wxTabLayerList
)
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 if(m_view
->GetBackgroundBrush())
89 dc
.SetBrush(*m_view
->GetBackgroundBrush());
91 // Add 1 because the pen is transparent. Under Motif, may be different.
93 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + tabHeightInc
));
95 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc
));
99 // Draw highlight and shadow
100 dc
.SetPen(*m_view
->GetHighlightPen());
102 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
103 // a bit if the tab below happens to be selected. Check.
104 wxTabControl
*tabBeneath
= NULL
;
105 int subtractThis
= 0;
106 if (GetColPosition() > 0)
107 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition());
108 if (tabBeneath
&& tabBeneath
->IsSelected())
109 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
111 // Vertical highlight: if first tab, draw to bottom of view
112 if (tabX
== m_view
->GetViewRect().x
&& (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
113 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
));
114 else if (tabX
== m_view
->GetViewRect().x
)
115 // Not box drawing, just to top of view.
116 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
));
118 dc
.DrawLine(tabX
, tabY
, tabX
, (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
120 dc
.DrawLine(tabX
, tabY
, (tabX
+ GetWidth()), tabY
);
121 dc
.SetPen(*m_view
->GetShadowPen());
123 // Test if we're outside the right-hand edge of the view area
124 if (((tabX
+ GetWidth()) >= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
) && (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
126 int bottomY
= m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
+ GetY() + m_view
->GetTabHeight() + m_view
->GetTopMargin();
127 // Add a tab height since we wish to draw to the bottom of the view.
128 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
129 (tabX
+ GetWidth()), bottomY
);
131 // Calculate the far-right of the view, since we don't wish to
133 int rightOfView
= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
+ 1;
135 // Draw the horizontal bit to connect to the view rectangle
136 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
-1),
137 (tabX
+ GetWidth()), (bottomY
-1));
139 // Draw black line to emphasize shadow
140 dc
.SetPen(*wxBLACK_PEN
);
141 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1),
142 (tabX
+ GetWidth() + 1), bottomY
);
144 // Draw the horizontal bit to connect to the view rectangle
145 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
),
146 (tabX
+ GetWidth() + 1), (bottomY
));
152 // 25/5/97 UNLESS it's less than the max number of positions in this row
154 int topY
= m_view
->GetViewRect().y
- m_view
->GetTopMargin();
156 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Item(0)->GetData())->GetCount();
158 // Only down to the bottom of the tab, not to the top of the view
159 if ( GetRowPosition() < (maxPositions
- 1) )
160 topY
= tabY
+ GetHeight() + tabHeightInc
;
167 dc
.DrawLine((tabX
+ GetWidth()), tabY
, (tabX
+ GetWidth()), topY
);
168 // Draw black line to emphasize shadow
169 dc
.SetPen(*wxBLACK_PEN
);
170 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
175 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
176 // a bit if the tab below (and next col along) happens to be selected. Check.
177 wxTabControl
*tabBeneath
= NULL
;
178 int subtractThis
= 0;
179 if (GetColPosition() > 0)
180 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1);
181 if (tabBeneath
&& tabBeneath
->IsSelected())
182 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
188 // Draw only to next tab down.
189 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
190 (tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
192 // Draw black line to emphasize shadow
193 dc
.SetPen(*wxBLACK_PEN
);
194 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
195 (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
199 // Draw centered text
200 int textY
= tabY
+ m_view
->GetVerticalTabTextSpacing() + tabHeightInc
;
203 dc
.SetFont(* m_view
->GetSelectedTabFont());
205 dc
.SetFont(* GetFont());
207 wxColour
col(m_view
->GetTextColour());
208 dc
.SetTextForeground(col
);
209 dc
.SetBackgroundMode(wxTRANSPARENT
);
210 wxCoord textWidth
, textHeight
;
211 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
213 int textX
= (int)(tabX
+ (GetWidth() - textWidth
)/2.0);
214 if (textX
< (tabX
+ 2))
217 dc
.SetClippingRegion(tabX
, tabY
, GetWidth(), GetHeight());
218 dc
.DrawText(GetLabel(), textX
, textY
);
219 dc
.DestroyClippingRegion();
223 dc
.SetPen(*m_view
->GetHighlightPen());
225 // Draw white highlight from the tab's left side to the left hand edge of the view
226 dc
.DrawLine(m_view
->GetViewRect().x
, (tabY
+ GetHeight() + tabHeightInc
),
227 tabX
, (tabY
+ GetHeight() + tabHeightInc
));
229 // Draw white highlight from the tab's right side to the right hand edge of the view
230 dc
.DrawLine((tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
),
231 m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
, (tabY
+ GetHeight() + tabHeightInc
));
234 // New HEL version with rounder tabs
241 tabInc
= m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight();
243 int tabLeft
= GetX() + m_view
->GetViewRect().x
;
244 int tabTop
= GetY() + m_view
->GetViewRect().y
- tabInc
;
245 int tabRight
= tabLeft
+ m_view
->GetTabWidth();
246 int left
= m_view
->GetViewRect().x
;
247 int top
= tabTop
+ m_view
->GetTabHeight() + tabInc
;
248 int right
= left
+ m_view
->GetViewRect().width
;
249 int bottom
= top
+ m_view
->GetViewRect().height
;
253 // TAB is selected - draw TAB and the View's full outline
255 dc
.SetPen(*(m_view
->GetHighlightPen()));
258 pnts
[n
].x
= left
; pnts
[n
++].y
= bottom
;
259 pnts
[n
].x
= left
; pnts
[n
++].y
= top
;
260 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= top
;
261 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
262 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
263 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
264 dc
.DrawLines(n
, pnts
);
275 dc
.SetPen(*(m_view
->GetShadowPen()));
295 dc
.SetPen(*wxBLACK_PEN
);
337 // TAB is not selected - just draw TAB outline and RH edge
338 // if the TAB is the last in the row
340 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Item(0)->GetData())->GetCount();
341 wxTabControl
* tabBelow
= 0;
342 wxTabControl
* tabBelowRight
= 0;
343 if (GetColPosition() > 0)
345 tabBelow
= m_view
->FindTabControlForPosition(
346 GetColPosition() - 1,
350 if (!lastInRow
&& GetColPosition() > 0)
352 tabBelowRight
= m_view
->FindTabControlForPosition(
353 GetColPosition() - 1,
358 float raisedTop
= top
- m_view
->GetTabSelectionHeight() +
359 m_view
->GetTabHeight();
361 dc
.SetPen(*(m_view
->GetHighlightPen()));
367 if (tabBelow
&& tabBelow
->IsSelected())
369 pnts
[n
++].y
= (long)raisedTop
;
375 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
376 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
377 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
378 dc
.DrawLines(n
, pnts
);
380 dc
.SetPen(*(m_view
->GetShadowPen()));
381 if (GetRowPosition() >= maxPositions
- 1)
392 (tabRight
- m_view
->GetHorizontalTabOffset()),
398 if (tabBelowRight
&& tabBelowRight
->IsSelected())
418 dc
.SetPen(*wxBLACK_PEN
);
427 if (GetRowPosition() >= maxPositions
- 1)
429 // draw right hand edge to bottom of view
439 (tabRight
- m_view
->GetHorizontalTabOffset()),
445 // draw right hand edge of TAB
446 if (tabBelowRight
&& tabBelowRight
->IsSelected())
450 (long)(raisedTop
- 1),
467 // Draw centered text
468 dc
.SetPen(*wxBLACK_PEN
);
471 dc
.SetFont(*(m_view
->GetSelectedTabFont()));
475 dc
.SetFont(*(GetFont()));
478 wxColour
col(m_view
->GetTextColour());
479 dc
.SetTextForeground(col
);
480 dc
.SetBackgroundMode(wxTRANSPARENT
);
481 long textWidth
, textHeight
;
482 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
484 float textX
= (tabLeft
+ tabRight
- textWidth
) / 2;
485 float textY
= (tabInc
+ tabTop
+ m_view
->GetVerticalTabTextSpacing());
487 dc
.DrawText(GetLabel(), (long)textX
, (long)textY
);
491 bool wxTabControl::HitTest(int x
, int y
) const
493 // Top-left of tab control
494 int tabX1
= GetX() + m_view
->GetViewRect().x
;
495 int tabY1
= GetY() + m_view
->GetViewRect().y
;
498 int tabX2
= tabX1
+ GetWidth();
499 int tabY2
= tabY1
+ GetHeight();
501 if (x
>= tabX1
&& y
>= tabY1
&& x
<= tabX2
&& y
<= tabY2
)
507 IMPLEMENT_DYNAMIC_CLASS(wxTabView
, wxObject
)
509 wxTabView::wxTabView(long style
)
515 m_tabSelectionHeight
= m_tabHeight
+ 2;
517 m_tabHorizontalOffset
= 10;
518 m_tabHorizontalSpacing
= 2;
519 m_tabVerticalTextSpacing
= 3;
521 m_tabViewRect
.x
= 20;
522 m_tabViewRect
.y
= 20;
523 m_tabViewRect
.width
= 300;
524 m_tabViewRect
.x
= 300;
525 m_highlightColour
= *wxWHITE
;
526 m_shadowColour
= wxColour(128, 128, 128);
527 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
528 m_textColour
= *wxBLACK
;
529 m_highlightPen
= wxWHITE_PEN
;
530 m_shadowPen
= wxGREY_PEN
;
531 // SetBackgroundColour(m_backgroundColour);
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 wxTabLayerList::compatibility_iterator 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 wxList::compatibility_iterator 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
= wxList::compatibility_iterator();
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 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
615 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
616 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
619 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
620 if (tab
->GetId() == id
)
622 if (id
== m_tabSelection
)
625 layer
->Erase(tabNode
);
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 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
666 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
667 wxList::compatibility_iterator 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 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
688 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
689 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
692 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
695 wxList::compatibility_iterator next
= tabNode
->GetNext();
696 layer
->Erase(tabNode
);
699 wxTabLayerList::compatibility_iterator nextLayerNode
= layerNode
->GetNext();
701 m_layers
.Erase(layerNode
);
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 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
718 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
719 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
722 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
723 controls
.Append(tab
);
724 wxList::compatibility_iterator next
= tabNode
->GetNext();
725 layer
->Erase(tabNode
);
728 wxTabLayerList::compatibility_iterator nextLayerNode
= layerNode
->GetNext();
730 m_layers
.Erase(layerNode
);
731 layerNode
= nextLayerNode
;
734 wxTabControl
*lastTab
= (wxTabControl
*) NULL
;
736 wxTabLayer
*currentLayer
= new wxTabLayer
;
737 m_layers
.Append(currentLayer
);
739 wxList::compatibility_iterator 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 if(GetBackgroundBrush())
802 dc
.SetBrush(*GetBackgroundBrush());
804 // Add 1 because the pen is transparent. Under Motif, may be different.
807 (m_tabViewRect
.y
- m_topMargin
),
808 (m_tabViewRect
.width
+ 1),
813 // Draw layers in reverse order
814 wxTabLayerList::compatibility_iterator node
= m_layers
.GetLast();
817 wxTabLayer
*layer
= (wxTabLayer
*)node
->GetData();
818 wxList::compatibility_iterator node2
= layer
->GetFirst();
821 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
822 control
->OnDraw(dc
, (!node2
->GetNext()));
823 node2
= node2
->GetNext();
826 node
= node
->GetPrevious();
830 #ifndef wxUSE_NEW_METHOD
831 if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX
)
833 dc
.SetPen(* GetShadowPen());
837 (GetViewRect().x
+ 1),
838 (GetViewRect().y
+ GetViewRect().height
),
839 (GetViewRect().x
+ GetViewRect().width
+ 1),
840 (GetViewRect().y
+ GetViewRect().height
)
845 (GetViewRect().x
+ GetViewRect().width
),
846 (GetViewRect().y
- GetTopMargin() + 1),
847 (GetViewRect().x
+ GetViewRect().width
),
848 (GetViewRect().y
+ GetViewRect().height
)
851 dc
.SetPen(* wxBLACK_PEN
);
856 (GetViewRect().y
+ GetViewRect().height
+ 1),
857 #if defined(__WXMOTIF__)
858 (GetViewRect().x
+ GetViewRect().width
+ 1),
860 (GetViewRect().x
+ GetViewRect().width
+ 2),
863 (GetViewRect().y
+ GetViewRect().height
+ 1)
868 (GetViewRect().x
+ GetViewRect().width
+ 1),
869 (GetViewRect().y
- GetTopMargin()),
870 (GetViewRect().x
+ GetViewRect().width
+ 1),
871 (GetViewRect().y
+ GetViewRect().height
+ 1)
877 // Process mouse event, return false if we didn't process it
878 bool wxTabView::OnEvent(wxMouseEvent
& event
)
880 if (!event
.LeftDown())
884 event
.GetPosition(&x
, &y
);
886 wxTabControl
*hitControl
= (wxTabControl
*) NULL
;
888 wxTabLayerList::compatibility_iterator node
= m_layers
.GetFirst();
891 wxTabLayer
*layer
= (wxTabLayer
*)node
->GetData();
892 wxList::compatibility_iterator node2
= layer
->GetFirst();
895 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
896 if (control
->HitTest((int)x
, (int)y
))
898 hitControl
= control
;
899 node
= wxTabLayerList::compatibility_iterator();
900 node2
= wxList::compatibility_iterator();
903 node2
= node2
->GetNext();
907 node
= node
->GetNext();
913 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
915 if (hitControl
== currentTab
)
918 ChangeTab(hitControl
);
923 bool wxTabView::ChangeTab(wxTabControl
*control
)
925 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
928 oldTab
= currentTab
->GetId();
930 if (control
== currentTab
)
933 if (m_layers
.GetCount() == 0)
936 if (!OnTabPreActivate(control
->GetId(), oldTab
))
939 // Move the tab to the bottom
940 MoveSelectionTab(control
);
943 currentTab
->SetSelected(false);
945 control
->SetSelected(true);
946 m_tabSelection
= control
->GetId();
948 OnTabActivate(control
->GetId(), oldTab
);
950 // Leave window refresh for the implementing window
955 // Move the selected tab to the bottom layer, if necessary,
956 // without calling app activation code
957 bool wxTabView::MoveSelectionTab(wxTabControl
*control
)
959 if (m_layers
.GetCount() == 0)
962 wxTabLayer
*firstLayer
= (wxTabLayer
*)m_layers
.GetFirst()->GetData();
964 // Find what column this tab is at, so we can swap with the one at the bottom.
965 // If we're on the bottom layer, then no need to swap.
966 if (!firstLayer
->Member(control
))
970 wxList::compatibility_iterator thisNode
= FindTabNodeAndColumn(control
, &col
);
973 wxList::compatibility_iterator otherNode
= firstLayer
->Item(col
);
977 // If this is already in the bottom layer, return now
978 if (otherNode
== thisNode
)
981 wxTabControl
*otherTab
= (wxTabControl
*)otherNode
->GetData();
983 // We now have pointers to the tab to be changed to,
984 // and the tab on the first layer. Swap tab structures and
987 int thisX
= control
->GetX();
988 int thisY
= control
->GetY();
989 int thisColPos
= control
->GetColPosition();
990 int otherX
= otherTab
->GetX();
991 int otherY
= otherTab
->GetY();
992 int otherColPos
= otherTab
->GetColPosition();
994 control
->SetPosition(otherX
, otherY
);
995 control
->SetColPosition(otherColPos
);
996 otherTab
->SetPosition(thisX
, thisY
);
997 otherTab
->SetColPosition(thisColPos
);
999 // Swap the data for the nodes
1000 thisNode
->SetData(otherTab
);
1001 otherNode
->SetData(control
);
1006 // Called when a tab is activated
1007 void wxTabView::OnTabActivate(int /*activateId*/, int /*deactivateId*/)
1011 void wxTabView::SetHighlightColour(const wxColour
& col
)
1013 m_highlightColour
= col
;
1014 m_highlightPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1017 void wxTabView::SetShadowColour(const wxColour
& col
)
1019 m_shadowColour
= col
;
1020 m_shadowPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1023 void wxTabView::SetBackgroundColour(const wxColour
& col
)
1025 m_backgroundColour
= col
;
1026 m_backgroundPen
= wxThePenList
->FindOrCreatePen(col
, 1, wxSOLID
);
1027 m_backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(col
, wxSOLID
);
1030 // this may be called with sel = zero (which doesn't match any page)
1031 // when wxMotif deletes a page
1032 // so return the first tab...
1034 void wxTabView::SetTabSelection(int sel
, bool activateTool
)
1036 if ( sel
==m_tabSelection
)
1039 int oldSel
= m_tabSelection
;
1040 wxTabControl
*control
= FindTabControlForId(sel
);
1041 if (sel
== 0) sel
=control
->GetId();
1042 wxTabControl
*oldControl
= FindTabControlForId(m_tabSelection
);
1044 if (!OnTabPreActivate(sel
, oldSel
))
1048 control
->SetSelected((sel
!= -1)); // TODO ??
1051 wxFAIL_MSG(_("Could not find tab for id"));
1056 oldControl
->SetSelected(false);
1058 m_tabSelection
= sel
;
1061 MoveSelectionTab(control
);
1064 OnTabActivate(sel
, oldSel
);
1067 // Find tab control for id
1068 // this may be called with zero (which doesn't match any page)
1069 // so return the first control...
1070 wxTabControl
*wxTabView::FindTabControlForId(int id
) const
1072 wxTabLayerList::compatibility_iterator node1
= m_layers
.GetFirst();
1075 wxTabLayer
*layer
= (wxTabLayer
*)node1
->GetData();
1076 wxList::compatibility_iterator node2
= layer
->GetFirst();
1079 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
1080 if (control
->GetId() == id
|| id
== 0)
1082 node2
= node2
->GetNext();
1084 node1
= node1
->GetNext();
1086 return (wxTabControl
*) NULL
;
1089 // Find tab control for layer, position (starting from zero)
1090 wxTabControl
*wxTabView::FindTabControlForPosition(int layer
, int position
) const
1092 wxTabLayerList::compatibility_iterator node1
= m_layers
.Item(layer
);
1094 return (wxTabControl
*) NULL
;
1095 wxTabLayer
*tabLayer
= (wxTabLayer
*)node1
->GetData();
1096 wxList::compatibility_iterator node2
= tabLayer
->Item(position
);
1098 return (wxTabControl
*) NULL
;
1099 return (wxTabControl
*)node2
->GetData();
1102 // Find the node and the column at which this control is positioned.
1103 wxList::compatibility_iterator
wxTabView::FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const
1105 wxTabLayerList::compatibility_iterator node1
= m_layers
.GetFirst();
1108 wxTabLayer
*layer
= (wxTabLayer
*)node1
->GetData();
1110 wxList::compatibility_iterator node2
= layer
->GetFirst();
1113 wxTabControl
*cnt
= (wxTabControl
*)node2
->GetData();
1119 node2
= node2
->GetNext();
1122 node1
= node1
->GetNext();
1124 return wxList::compatibility_iterator();
1127 int wxTabView::CalculateTabWidth(int noTabs
, bool adjustView
)
1129 m_tabWidth
= (int)((m_tabViewRect
.width
- ((noTabs
- 1)*GetHorizontalTabSpacing()))/noTabs
);
1132 m_tabViewRect
.width
= noTabs
*m_tabWidth
+ ((noTabs
-1)*GetHorizontalTabSpacing());
1141 IMPLEMENT_CLASS(wxTabbedDialog
, wxDialog
)
1143 BEGIN_EVENT_TABLE(wxTabbedDialog
, wxDialog
)
1144 EVT_CLOSE(wxTabbedDialog::OnCloseWindow
)
1145 EVT_MOUSE_EVENTS(wxTabbedDialog::OnMouseEvent
)
1146 EVT_PAINT(wxTabbedDialog::OnPaint
)
1149 wxTabbedDialog::wxTabbedDialog(wxWindow
*parent
, wxWindowID id
,
1150 const wxString
& title
,
1151 const wxPoint
& pos
, const wxSize
& size
,
1152 long windowStyle
, const wxString
& name
):
1153 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
, name
)
1155 m_tabView
= (wxTabView
*) NULL
;
1158 wxTabbedDialog::~wxTabbedDialog(void)
1164 void wxTabbedDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
1169 void wxTabbedDialog::OnMouseEvent(wxMouseEvent
& event
)
1172 m_tabView
->OnEvent(event
);
1175 void wxTabbedDialog::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1179 m_tabView
->Draw(dc
);
1186 IMPLEMENT_CLASS(wxTabbedPanel
, wxPanel
)
1188 BEGIN_EVENT_TABLE(wxTabbedPanel
, wxPanel
)
1189 EVT_MOUSE_EVENTS(wxTabbedPanel::OnMouseEvent
)
1190 EVT_PAINT(wxTabbedPanel::OnPaint
)
1193 wxTabbedPanel::wxTabbedPanel(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
1194 const wxSize
& size
, long windowStyle
, const wxString
& name
):
1195 wxPanel(parent
, id
, pos
, size
, windowStyle
, name
)
1197 m_tabView
= (wxTabView
*) NULL
;
1200 wxTabbedPanel::~wxTabbedPanel(void)
1205 void wxTabbedPanel::OnMouseEvent(wxMouseEvent
& event
)
1208 m_tabView
->OnEvent(event
);
1211 void wxTabbedPanel::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1215 m_tabView
->Draw(dc
);
1222 IMPLEMENT_CLASS(wxPanelTabView
, wxTabView
)
1224 wxPanelTabView::wxPanelTabView(wxPanel
*pan
, long style
)
1228 m_currentWindow
= (wxWindow
*) NULL
;
1230 if (m_panel
->IsKindOf(CLASSINFO(wxTabbedDialog
)))
1231 ((wxTabbedDialog
*)m_panel
)->SetTabView(this);
1232 else if (m_panel
->IsKindOf(CLASSINFO(wxTabbedPanel
)))
1233 ((wxTabbedPanel
*)m_panel
)->SetTabView(this);
1238 wxPanelTabView::~wxPanelTabView(void)
1243 // Called when a tab is activated
1244 void wxPanelTabView::OnTabActivate(int activateId
, int deactivateId
)
1249 wxWindow
*oldWindow
= ((deactivateId
== -1) ? 0 : GetTabWindow(deactivateId
));
1250 wxWindow
*newWindow
= GetTabWindow(activateId
);
1253 oldWindow
->Show(false);
1255 newWindow
->Show(true);
1261 void wxPanelTabView::AddTabWindow(int id
, wxWindow
*window
)
1263 wxASSERT(m_tabWindows
.find(id
) == m_tabWindows
.end());
1264 m_tabWindows
[id
] = window
;
1265 window
->Show(false);
1268 wxWindow
*wxPanelTabView::GetTabWindow(int id
) const
1270 wxIntToWindowHashMap::const_iterator it
= m_tabWindows
.find(id
);
1271 return it
== m_tabWindows
.end() ? NULL
: it
->second
;
1274 void wxPanelTabView::ClearWindows(bool deleteWindows
)
1277 WX_CLEAR_HASH_MAP(wxIntToWindowHashMap
, m_tabWindows
);
1278 m_tabWindows
.clear();
1281 void wxPanelTabView::ShowWindowForTab(int id
)
1283 wxWindow
*newWindow
= GetTabWindow(id
);
1284 if (newWindow
== m_currentWindow
)
1286 if (m_currentWindow
)
1287 m_currentWindow
->Show(false);
1288 newWindow
->Show(true);
1289 newWindow
->Refresh();
1292 #endif // wxUSE_TAB_DIALOG