1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/tabg.cpp
3 // Purpose: Generic tabbed dialogs; used by wxMotif's wxNotebook
4 // Author: Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
19 #include "wx/settings.h"
21 #include "wx/dcclient.h"
29 #include "wx/generic/tabg.h"
30 #include "wx/listimpl.cpp"
32 WX_DEFINE_LIST(wxTabLayerList
)
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 if(m_view
->GetBackgroundBrush())
86 dc
.SetBrush(*m_view
->GetBackgroundBrush());
88 // Add 1 because the pen is transparent. Under Motif, may be different.
90 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + tabHeightInc
));
92 dc
.DrawRectangle(tabX
, tabY
, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc
));
96 // Draw highlight and shadow
97 dc
.SetPen(*m_view
->GetHighlightPen());
99 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
100 // a bit if the tab below happens to be selected. Check.
101 wxTabControl
*tabBeneath
= NULL
;
102 int subtractThis
= 0;
103 if (GetColPosition() > 0)
104 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition());
105 if (tabBeneath
&& tabBeneath
->IsSelected())
106 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
108 // Vertical highlight: if first tab, draw to bottom of view
109 if (tabX
== m_view
->GetViewRect().x
&& (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
110 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
));
111 else if (tabX
== m_view
->GetViewRect().x
)
112 // Not box drawing, just to top of view.
113 dc
.DrawLine(tabX
, tabY
, tabX
, (m_view
->GetViewRect().y
));
115 dc
.DrawLine(tabX
, tabY
, tabX
, (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
117 dc
.DrawLine(tabX
, tabY
, (tabX
+ GetWidth()), tabY
);
118 dc
.SetPen(*m_view
->GetShadowPen());
120 // Test if we're outside the right-hand edge of the view area
121 if (((tabX
+ GetWidth()) >= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
) && (m_view
->GetTabStyle() & wxTAB_STYLE_DRAW_BOX
))
123 int bottomY
= m_view
->GetViewRect().y
+ m_view
->GetViewRect().height
+ GetY() + m_view
->GetTabHeight() + m_view
->GetTopMargin();
124 // Add a tab height since we wish to draw to the bottom of the view.
125 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
126 (tabX
+ GetWidth()), bottomY
);
128 // Calculate the far-right of the view, since we don't wish to
130 int rightOfView
= m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
+ 1;
132 // Draw the horizontal bit to connect to the view rectangle
133 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
-1),
134 (tabX
+ GetWidth()), (bottomY
-1));
136 // Draw black line to emphasize shadow
137 dc
.SetPen(*wxBLACK_PEN
);
138 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1),
139 (tabX
+ GetWidth() + 1), bottomY
);
141 // Draw the horizontal bit to connect to the view rectangle
142 dc
.DrawLine((wxMax((tabX
+ GetWidth() - m_view
->GetHorizontalTabOffset()), rightOfView
)), (bottomY
),
143 (tabX
+ GetWidth() + 1), (bottomY
));
149 // 25/5/97 UNLESS it's less than the max number of positions in this row
151 int topY
= m_view
->GetViewRect().y
- m_view
->GetTopMargin();
153 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Item(0)->GetData())->GetCount();
155 // Only down to the bottom of the tab, not to the top of the view
156 if ( GetRowPosition() < (maxPositions
- 1) )
157 topY
= tabY
+ GetHeight() + tabHeightInc
;
164 dc
.DrawLine((tabX
+ GetWidth()), tabY
, (tabX
+ GetWidth()), topY
);
165 // Draw black line to emphasize shadow
166 dc
.SetPen(*wxBLACK_PEN
);
167 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
172 // Calculate the top of the tab beneath. It's the height of the tab, MINUS
173 // a bit if the tab below (and next col along) happens to be selected. Check.
174 wxTabControl
*tabBeneath
= NULL
;
175 int subtractThis
= 0;
176 if (GetColPosition() > 0)
177 tabBeneath
= m_view
->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1);
178 if (tabBeneath
&& tabBeneath
->IsSelected())
179 subtractThis
= (m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight());
185 // Draw only to next tab down.
186 dc
.DrawLine((tabX
+ GetWidth()), tabY
,
187 (tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
189 // Draw black line to emphasize shadow
190 dc
.SetPen(*wxBLACK_PEN
);
191 dc
.DrawLine((tabX
+ GetWidth() + 1), (tabY
+1), (tabX
+ GetWidth() + 1),
192 (tabY
+ GetHeight() + tabHeightInc
- subtractThis
));
196 // Draw centered text
197 int textY
= tabY
+ m_view
->GetVerticalTabTextSpacing() + tabHeightInc
;
200 dc
.SetFont(* m_view
->GetSelectedTabFont());
202 dc
.SetFont(* GetFont());
204 wxColour
col(m_view
->GetTextColour());
205 dc
.SetTextForeground(col
);
206 dc
.SetBackgroundMode(wxTRANSPARENT
);
207 wxCoord textWidth
, textHeight
;
208 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
210 int textX
= (int)(tabX
+ (GetWidth() - textWidth
)/2.0);
211 if (textX
< (tabX
+ 2))
214 dc
.SetClippingRegion(tabX
, tabY
, GetWidth(), GetHeight());
215 dc
.DrawText(GetLabel(), textX
, textY
);
216 dc
.DestroyClippingRegion();
220 dc
.SetPen(*m_view
->GetHighlightPen());
222 // Draw white highlight from the tab's left side to the left hand edge of the view
223 dc
.DrawLine(m_view
->GetViewRect().x
, (tabY
+ GetHeight() + tabHeightInc
),
224 tabX
, (tabY
+ GetHeight() + tabHeightInc
));
226 // Draw white highlight from the tab's right side to the right hand edge of the view
227 dc
.DrawLine((tabX
+ GetWidth()), (tabY
+ GetHeight() + tabHeightInc
),
228 m_view
->GetViewRect().x
+ m_view
->GetViewRect().width
, (tabY
+ GetHeight() + tabHeightInc
));
231 // New HEL version with rounder tabs
238 tabInc
= m_view
->GetTabSelectionHeight() - m_view
->GetTabHeight();
240 int tabLeft
= GetX() + m_view
->GetViewRect().x
;
241 int tabTop
= GetY() + m_view
->GetViewRect().y
- tabInc
;
242 int tabRight
= tabLeft
+ m_view
->GetTabWidth();
243 int left
= m_view
->GetViewRect().x
;
244 int top
= tabTop
+ m_view
->GetTabHeight() + tabInc
;
245 int right
= left
+ m_view
->GetViewRect().width
;
246 int bottom
= top
+ m_view
->GetViewRect().height
;
250 // TAB is selected - draw TAB and the View's full outline
252 dc
.SetPen(*(m_view
->GetHighlightPen()));
255 pnts
[n
].x
= left
; pnts
[n
++].y
= bottom
;
256 pnts
[n
].x
= left
; pnts
[n
++].y
= top
;
257 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= top
;
258 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
259 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
260 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
261 dc
.DrawLines(n
, pnts
);
272 dc
.SetPen(*(m_view
->GetShadowPen()));
292 dc
.SetPen(*wxBLACK_PEN
);
334 // TAB is not selected - just draw TAB outline and RH edge
335 // if the TAB is the last in the row
337 int maxPositions
= ((wxTabLayer
*)m_view
->GetLayers().Item(0)->GetData())->GetCount();
338 wxTabControl
* tabBelow
= 0;
339 wxTabControl
* tabBelowRight
= 0;
340 if (GetColPosition() > 0)
342 tabBelow
= m_view
->FindTabControlForPosition(
343 GetColPosition() - 1,
347 if (!lastInRow
&& GetColPosition() > 0)
349 tabBelowRight
= m_view
->FindTabControlForPosition(
350 GetColPosition() - 1,
355 float raisedTop
= top
- m_view
->GetTabSelectionHeight() +
356 m_view
->GetTabHeight();
358 dc
.SetPen(*(m_view
->GetHighlightPen()));
364 if (tabBelow
&& tabBelow
->IsSelected())
366 pnts
[n
++].y
= (long)raisedTop
;
372 pnts
[n
].x
= tabLeft
; pnts
[n
++].y
= tabTop
+ 2;
373 pnts
[n
].x
= tabLeft
+ 2; pnts
[n
++].y
= tabTop
;
374 pnts
[n
].x
= tabRight
- 1; pnts
[n
++].y
= tabTop
;
375 dc
.DrawLines(n
, pnts
);
377 dc
.SetPen(*(m_view
->GetShadowPen()));
378 if (GetRowPosition() >= maxPositions
- 1)
389 (tabRight
- m_view
->GetHorizontalTabOffset()),
395 if (tabBelowRight
&& tabBelowRight
->IsSelected())
415 dc
.SetPen(*wxBLACK_PEN
);
424 if (GetRowPosition() >= maxPositions
- 1)
426 // draw right hand edge to bottom of view
436 (tabRight
- m_view
->GetHorizontalTabOffset()),
442 // draw right hand edge of TAB
443 if (tabBelowRight
&& tabBelowRight
->IsSelected())
447 (long)(raisedTop
- 1),
464 // Draw centered text
465 dc
.SetPen(*wxBLACK_PEN
);
468 dc
.SetFont(*(m_view
->GetSelectedTabFont()));
472 dc
.SetFont(*(GetFont()));
475 wxColour
col(m_view
->GetTextColour());
476 dc
.SetTextForeground(col
);
477 dc
.SetBackgroundMode(wxTRANSPARENT
);
478 long textWidth
, textHeight
;
479 dc
.GetTextExtent(GetLabel(), &textWidth
, &textHeight
);
481 float textX
= (tabLeft
+ tabRight
- textWidth
) / 2;
482 float textY
= (tabInc
+ tabTop
+ m_view
->GetVerticalTabTextSpacing());
484 dc
.DrawText(GetLabel(), (long)textX
, (long)textY
);
488 bool wxTabControl::HitTest(int x
, int y
) const
490 // Top-left of tab control
491 int tabX1
= GetX() + m_view
->GetViewRect().x
;
492 int tabY1
= GetY() + m_view
->GetViewRect().y
;
495 int tabX2
= tabX1
+ GetWidth();
496 int tabY2
= tabY1
+ GetHeight();
498 if (x
>= tabX1
&& y
>= tabY1
&& x
<= tabX2
&& y
<= tabY2
)
504 IMPLEMENT_DYNAMIC_CLASS(wxTabView
, wxObject
)
506 wxTabView::wxTabView(long style
)
512 m_tabSelectionHeight
= m_tabHeight
+ 2;
514 m_tabHorizontalOffset
= 10;
515 m_tabHorizontalSpacing
= 2;
516 m_tabVerticalTextSpacing
= 3;
518 m_tabViewRect
.x
= 20;
519 m_tabViewRect
.y
= 20;
520 m_tabViewRect
.width
= 300;
521 m_tabViewRect
.x
= 300;
522 m_highlightColour
= *wxWHITE
;
523 m_shadowColour
= wxColour(128, 128, 128);
524 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
525 m_textColour
= *wxBLACK
;
526 m_highlightPen
= wxWHITE_PEN
;
527 m_shadowPen
= wxGREY_PEN
;
528 // SetBackgroundColour(m_backgroundColour);
529 m_tabFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
530 m_tabSelectedFont
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
534 wxTabView::~wxTabView()
539 // Automatically positions tabs
540 // TODO: this should just add the tab to a list, and then
541 // a layout function (e.g. Realize) should be called when all tabs have been added.
542 // The view rect could easily change as the view window is resized.
543 wxTabControl
*wxTabView::AddTab(int id
, const wxString
& label
, wxTabControl
*existingTab
)
545 // First, find which layer we should be adding to.
546 wxTabLayerList::compatibility_iterator node
= m_layers
.GetLast();
549 wxTabLayer
*newLayer
= new wxTabLayer
;
550 node
= m_layers
.Append(newLayer
);
552 // Check if adding another tab control would go off the
553 // right-hand edge of the layer.
554 wxTabLayer
*tabLayer
= (wxTabLayer
*)node
->GetData();
555 wxList::compatibility_iterator lastTabNode
= tabLayer
->GetLast();
558 wxTabControl
*lastTab
= (wxTabControl
*)lastTabNode
->GetData();
559 // Start another layer (row).
560 // Tricky choice: can't just check if will be overlapping the edge, because
561 // this happens anyway for 2nd and subsequent rows.
562 // Should check this for 1st row, and then subsequent rows should not exceed 1st
564 if (((tabLayer
== m_layers
.GetFirst()->GetData()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
565 > GetViewRect().width
)) ||
566 ((tabLayer
!= m_layers
.GetFirst()->GetData()) && (tabLayer
->GetCount() == ((wxTabLayer
*)m_layers
.GetFirst()->GetData())->GetCount())))
568 tabLayer
= new wxTabLayer
;
569 m_layers
.Append(tabLayer
);
570 lastTabNode
= wxList::compatibility_iterator();
573 int layer
= m_layers
.GetCount() - 1;
575 wxTabControl
*tabControl
= existingTab
;
577 tabControl
= OnCreateTabControl();
578 tabControl
->SetRowPosition(tabLayer
->GetCount());
579 tabControl
->SetColPosition(layer
);
581 wxTabControl
*lastTab
= NULL
;
583 lastTab
= (wxTabControl
*)lastTabNode
->GetData();
586 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
587 // Offset from view top-left
588 int horizontalOffset
= 0;
590 horizontalOffset
= layer
*GetHorizontalTabOffset();
592 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
594 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
595 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
596 tabControl
->SetId(id
);
597 tabControl
->SetLabel(label
);
598 tabControl
->SetFont(* GetTabFont());
600 tabLayer
->Append(tabControl
);
606 // Remove the tab without deleting the window
607 bool wxTabView::RemoveTab(int id
)
609 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
612 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
613 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
616 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
617 if (tab
->GetId() == id
)
619 if (id
== m_tabSelection
)
622 layer
->Erase(tabNode
);
625 // The layout has changed
629 tabNode
= tabNode
->GetNext();
631 layerNode
= layerNode
->GetNext();
636 bool wxTabView::SetTabText(int id
, const wxString
& label
)
638 wxTabControl
* control
= FindTabControlForId(id
);
641 control
->SetLabel(label
);
645 wxString
wxTabView::GetTabText(int id
) const
647 wxTabControl
* control
= FindTabControlForId(id
);
649 return wxEmptyString
;
651 return control
->GetLabel();
654 // Returns the total height of the tabs component -- this may be several
655 // times the height of a tab, if there are several tab layers (rows).
656 int wxTabView::GetTotalTabHeight()
660 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
663 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
664 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
667 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
669 if (tab
->GetY() < minY
)
672 tabNode
= tabNode
->GetNext();
674 layerNode
= layerNode
->GetNext();
680 void wxTabView::ClearTabs(bool deleteTabs
)
682 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
685 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
686 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
689 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
692 wxList::compatibility_iterator next
= tabNode
->GetNext();
693 layer
->Erase(tabNode
);
696 wxTabLayerList::compatibility_iterator nextLayerNode
= layerNode
->GetNext();
698 m_layers
.Erase(layerNode
);
699 layerNode
= nextLayerNode
;
706 // Layout tabs (optional, e.g. if resizing window)
707 void wxTabView::LayoutTabs(void)
709 // Make a list of the tab controls, deleting the wxTabLayers.
712 wxTabLayerList::compatibility_iterator layerNode
= m_layers
.GetFirst();
715 wxTabLayer
*layer
= (wxTabLayer
*)layerNode
->GetData();
716 wxList::compatibility_iterator tabNode
= layer
->GetFirst();
719 wxTabControl
*tab
= (wxTabControl
*)tabNode
->GetData();
720 controls
.Append(tab
);
721 wxList::compatibility_iterator next
= tabNode
->GetNext();
722 layer
->Erase(tabNode
);
725 wxTabLayerList::compatibility_iterator nextLayerNode
= layerNode
->GetNext();
727 m_layers
.Erase(layerNode
);
728 layerNode
= nextLayerNode
;
731 wxTabControl
*lastTab
= NULL
;
733 wxTabLayer
*currentLayer
= new wxTabLayer
;
734 m_layers
.Append(currentLayer
);
736 wxList::compatibility_iterator node
= controls
.GetFirst();
739 wxTabControl
*tabControl
= (wxTabControl
*)node
->GetData();
742 // Start another layer (row).
743 // Tricky choice: can't just check if will be overlapping the edge, because
744 // this happens anyway for 2nd and subsequent rows.
745 // Should check this for 1st row, and then subsequent rows should not exceed 1st
747 if (((currentLayer
== m_layers
.GetFirst()->GetData()) && ((lastTab
->GetX() + 2*lastTab
->GetWidth() + GetHorizontalTabSpacing())
748 > GetViewRect().width
)) ||
749 ((currentLayer
!= m_layers
.GetFirst()->GetData()) && (currentLayer
->GetCount() == ((wxTabLayer
*)m_layers
.GetFirst()->GetData())->GetCount())))
751 currentLayer
= new wxTabLayer
;
752 m_layers
.Append(currentLayer
);
757 int layer
= m_layers
.GetCount() - 1;
759 tabControl
->SetRowPosition(currentLayer
->GetCount());
760 tabControl
->SetColPosition(layer
);
763 int verticalOffset
= (- GetTopMargin()) - ((layer
+1)*GetTabHeight());
764 // Offset from view top-left
765 int horizontalOffset
= 0;
767 horizontalOffset
= layer
*GetHorizontalTabOffset();
769 horizontalOffset
= lastTab
->GetX() + GetTabWidth() + GetHorizontalTabSpacing();
771 tabControl
->SetPosition(horizontalOffset
, verticalOffset
);
772 tabControl
->SetSize(GetTabWidth(), GetTabHeight());
774 currentLayer
->Append(tabControl
);
775 lastTab
= tabControl
;
777 node
= node
->GetNext();
780 // Move the selected tab to the bottom
781 wxTabControl
*control
= FindTabControlForId(m_tabSelection
);
783 MoveSelectionTab(control
);
788 void wxTabView::Draw(wxDC
& dc
)
790 // Don't draw anything if there are no tabs.
791 if (GetNumberOfTabs() == 0)
794 // Draw top margin area (beneath tabs and above view area)
795 if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR
)
797 dc
.SetPen(*wxTRANSPARENT_PEN
);
798 if(GetBackgroundBrush())
799 dc
.SetBrush(*GetBackgroundBrush());
801 // Add 1 because the pen is transparent. Under Motif, may be different.
804 (m_tabViewRect
.y
- m_topMargin
),
805 (m_tabViewRect
.width
+ 1),
810 // Draw layers in reverse order
811 wxTabLayerList::compatibility_iterator node
= m_layers
.GetLast();
814 wxTabLayer
*layer
= (wxTabLayer
*)node
->GetData();
815 wxList::compatibility_iterator node2
= layer
->GetFirst();
818 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
819 control
->OnDraw(dc
, (!node2
->GetNext()));
820 node2
= node2
->GetNext();
823 node
= node
->GetPrevious();
827 #ifndef wxUSE_NEW_METHOD
828 if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX
)
830 dc
.SetPen(* GetShadowPen());
834 (GetViewRect().x
+ 1),
835 (GetViewRect().y
+ GetViewRect().height
),
836 (GetViewRect().x
+ GetViewRect().width
+ 1),
837 (GetViewRect().y
+ GetViewRect().height
)
842 (GetViewRect().x
+ GetViewRect().width
),
843 (GetViewRect().y
- GetTopMargin() + 1),
844 (GetViewRect().x
+ GetViewRect().width
),
845 (GetViewRect().y
+ GetViewRect().height
)
848 dc
.SetPen(* wxBLACK_PEN
);
853 (GetViewRect().y
+ GetViewRect().height
+ 1),
854 #if defined(__WXMOTIF__)
855 (GetViewRect().x
+ GetViewRect().width
+ 1),
857 (GetViewRect().x
+ GetViewRect().width
+ 2),
860 (GetViewRect().y
+ GetViewRect().height
+ 1)
865 (GetViewRect().x
+ GetViewRect().width
+ 1),
866 (GetViewRect().y
- GetTopMargin()),
867 (GetViewRect().x
+ GetViewRect().width
+ 1),
868 (GetViewRect().y
+ GetViewRect().height
+ 1)
874 // Process mouse event, return false if we didn't process it
875 bool wxTabView::OnEvent(wxMouseEvent
& event
)
877 if (!event
.LeftDown())
881 event
.GetPosition(&x
, &y
);
883 wxTabControl
*hitControl
= NULL
;
885 wxTabLayerList::compatibility_iterator node
= m_layers
.GetFirst();
888 wxTabLayer
*layer
= (wxTabLayer
*)node
->GetData();
889 wxList::compatibility_iterator node2
= layer
->GetFirst();
892 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
893 if (control
->HitTest((int)x
, (int)y
))
895 hitControl
= control
;
896 node
= wxTabLayerList::compatibility_iterator();
897 node2
= wxList::compatibility_iterator();
900 node2
= node2
->GetNext();
904 node
= node
->GetNext();
910 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
912 if (hitControl
== currentTab
)
915 ChangeTab(hitControl
);
920 bool wxTabView::ChangeTab(wxTabControl
*control
)
922 wxTabControl
*currentTab
= FindTabControlForId(m_tabSelection
);
925 oldTab
= currentTab
->GetId();
927 if (control
== currentTab
)
930 if (m_layers
.GetCount() == 0)
933 if (!OnTabPreActivate(control
->GetId(), oldTab
))
936 // Move the tab to the bottom
937 MoveSelectionTab(control
);
940 currentTab
->SetSelected(false);
942 control
->SetSelected(true);
943 m_tabSelection
= control
->GetId();
945 OnTabActivate(control
->GetId(), oldTab
);
947 // Leave window refresh for the implementing window
952 // Move the selected tab to the bottom layer, if necessary,
953 // without calling app activation code
954 bool wxTabView::MoveSelectionTab(wxTabControl
*control
)
956 if (m_layers
.GetCount() == 0)
959 wxTabLayer
*firstLayer
= (wxTabLayer
*)m_layers
.GetFirst()->GetData();
961 // Find what column this tab is at, so we can swap with the one at the bottom.
962 // If we're on the bottom layer, then no need to swap.
963 if (!firstLayer
->Member(control
))
967 wxList::compatibility_iterator thisNode
= FindTabNodeAndColumn(control
, &col
);
970 wxList::compatibility_iterator otherNode
= firstLayer
->Item(col
);
974 // If this is already in the bottom layer, return now
975 if (otherNode
== thisNode
)
978 wxTabControl
*otherTab
= (wxTabControl
*)otherNode
->GetData();
980 // We now have pointers to the tab to be changed to,
981 // and the tab on the first layer. Swap tab structures and
984 int thisX
= control
->GetX();
985 int thisY
= control
->GetY();
986 int thisColPos
= control
->GetColPosition();
987 int otherX
= otherTab
->GetX();
988 int otherY
= otherTab
->GetY();
989 int otherColPos
= otherTab
->GetColPosition();
991 control
->SetPosition(otherX
, otherY
);
992 control
->SetColPosition(otherColPos
);
993 otherTab
->SetPosition(thisX
, thisY
);
994 otherTab
->SetColPosition(thisColPos
);
996 // Swap the data for the nodes
997 thisNode
->SetData(otherTab
);
998 otherNode
->SetData(control
);
1003 // Called when a tab is activated
1004 void wxTabView::OnTabActivate(int /*activateId*/, int /*deactivateId*/)
1008 void wxTabView::SetHighlightColour(const wxColour
& col
)
1010 m_highlightColour
= col
;
1011 m_highlightPen
= wxThePenList
->FindOrCreatePen(col
);
1014 void wxTabView::SetShadowColour(const wxColour
& col
)
1016 m_shadowColour
= col
;
1017 m_shadowPen
= wxThePenList
->FindOrCreatePen(col
);
1020 void wxTabView::SetBackgroundColour(const wxColour
& col
)
1022 m_backgroundColour
= col
;
1023 m_backgroundPen
= wxThePenList
->FindOrCreatePen(col
);
1024 m_backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(col
);
1027 // this may be called with sel = zero (which doesn't match any page)
1028 // when wxMotif deletes a page
1029 // so return the first tab...
1031 void wxTabView::SetTabSelection(int sel
, bool activateTool
)
1033 if ( sel
==m_tabSelection
)
1036 int oldSel
= m_tabSelection
;
1037 wxTabControl
*control
= FindTabControlForId(sel
);
1038 if (sel
== 0) sel
=control
->GetId();
1039 wxTabControl
*oldControl
= FindTabControlForId(m_tabSelection
);
1041 if (!OnTabPreActivate(sel
, oldSel
))
1045 control
->SetSelected((sel
!= -1)); // TODO ??
1048 wxFAIL_MSG(_("Could not find tab for id"));
1053 oldControl
->SetSelected(false);
1055 m_tabSelection
= sel
;
1058 MoveSelectionTab(control
);
1061 OnTabActivate(sel
, oldSel
);
1064 // Find tab control for id
1065 // this may be called with zero (which doesn't match any page)
1066 // so return the first control...
1067 wxTabControl
*wxTabView::FindTabControlForId(int id
) const
1069 wxTabLayerList::compatibility_iterator node1
= m_layers
.GetFirst();
1072 wxTabLayer
*layer
= (wxTabLayer
*)node1
->GetData();
1073 wxList::compatibility_iterator node2
= layer
->GetFirst();
1076 wxTabControl
*control
= (wxTabControl
*)node2
->GetData();
1077 if (control
->GetId() == id
|| id
== 0)
1079 node2
= node2
->GetNext();
1081 node1
= node1
->GetNext();
1086 // Find tab control for layer, position (starting from zero)
1087 wxTabControl
*wxTabView::FindTabControlForPosition(int layer
, int position
) const
1089 wxTabLayerList::compatibility_iterator node1
= m_layers
.Item(layer
);
1092 wxTabLayer
*tabLayer
= (wxTabLayer
*)node1
->GetData();
1093 wxList::compatibility_iterator node2
= tabLayer
->Item(position
);
1096 return (wxTabControl
*)node2
->GetData();
1099 // Find the node and the column at which this control is positioned.
1100 wxList::compatibility_iterator
wxTabView::FindTabNodeAndColumn(wxTabControl
*control
, int *col
) const
1102 wxTabLayerList::compatibility_iterator node1
= m_layers
.GetFirst();
1105 wxTabLayer
*layer
= (wxTabLayer
*)node1
->GetData();
1107 wxList::compatibility_iterator node2
= layer
->GetFirst();
1110 wxTabControl
*cnt
= (wxTabControl
*)node2
->GetData();
1116 node2
= node2
->GetNext();
1119 node1
= node1
->GetNext();
1121 return wxList::compatibility_iterator();
1124 int wxTabView::CalculateTabWidth(int noTabs
, bool adjustView
)
1126 m_tabWidth
= (int)((m_tabViewRect
.width
- ((noTabs
- 1)*GetHorizontalTabSpacing()))/noTabs
);
1129 m_tabViewRect
.width
= noTabs
*m_tabWidth
+ ((noTabs
-1)*GetHorizontalTabSpacing());
1138 IMPLEMENT_CLASS(wxTabbedDialog
, wxDialog
)
1140 BEGIN_EVENT_TABLE(wxTabbedDialog
, wxDialog
)
1141 EVT_CLOSE(wxTabbedDialog::OnCloseWindow
)
1142 EVT_MOUSE_EVENTS(wxTabbedDialog::OnMouseEvent
)
1143 EVT_PAINT(wxTabbedDialog::OnPaint
)
1146 wxTabbedDialog::wxTabbedDialog(wxWindow
*parent
, wxWindowID id
,
1147 const wxString
& title
,
1148 const wxPoint
& pos
, const wxSize
& size
,
1149 long windowStyle
, const wxString
& name
):
1150 wxDialog(parent
, id
, title
, pos
, size
, windowStyle
, name
)
1155 wxTabbedDialog::~wxTabbedDialog(void)
1161 void wxTabbedDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
) )
1166 void wxTabbedDialog::OnMouseEvent(wxMouseEvent
& event
)
1169 m_tabView
->OnEvent(event
);
1172 void wxTabbedDialog::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1176 m_tabView
->Draw(dc
);
1183 IMPLEMENT_CLASS(wxTabbedPanel
, wxPanel
)
1185 BEGIN_EVENT_TABLE(wxTabbedPanel
, wxPanel
)
1186 EVT_MOUSE_EVENTS(wxTabbedPanel::OnMouseEvent
)
1187 EVT_PAINT(wxTabbedPanel::OnPaint
)
1190 wxTabbedPanel::wxTabbedPanel(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
1191 const wxSize
& size
, long windowStyle
, const wxString
& name
):
1192 wxPanel(parent
, id
, pos
, size
, windowStyle
, name
)
1197 wxTabbedPanel::~wxTabbedPanel(void)
1202 void wxTabbedPanel::OnMouseEvent(wxMouseEvent
& event
)
1205 m_tabView
->OnEvent(event
);
1208 void wxTabbedPanel::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1212 m_tabView
->Draw(dc
);
1219 IMPLEMENT_CLASS(wxPanelTabView
, wxTabView
)
1221 wxPanelTabView::wxPanelTabView(wxPanel
*pan
, long style
)
1225 m_currentWindow
= NULL
;
1227 if (m_panel
->IsKindOf(wxCLASSINFO(wxTabbedDialog
)))
1228 ((wxTabbedDialog
*)m_panel
)->SetTabView(this);
1229 else if (m_panel
->IsKindOf(wxCLASSINFO(wxTabbedPanel
)))
1230 ((wxTabbedPanel
*)m_panel
)->SetTabView(this);
1235 wxPanelTabView::~wxPanelTabView(void)
1240 // Called when a tab is activated
1241 void wxPanelTabView::OnTabActivate(int activateId
, int deactivateId
)
1246 wxWindow
*oldWindow
= ((deactivateId
== -1) ? 0 : GetTabWindow(deactivateId
));
1247 wxWindow
*newWindow
= GetTabWindow(activateId
);
1250 oldWindow
->Show(false);
1252 newWindow
->Show(true);
1258 void wxPanelTabView::AddTabWindow(int id
, wxWindow
*window
)
1260 wxASSERT(m_tabWindows
.find(id
) == m_tabWindows
.end());
1261 m_tabWindows
[id
] = window
;
1262 window
->Show(false);
1265 wxWindow
*wxPanelTabView::GetTabWindow(int id
) const
1267 wxIntToWindowHashMap::const_iterator it
= m_tabWindows
.find(id
);
1268 return it
== m_tabWindows
.end() ? NULL
: it
->second
;
1271 void wxPanelTabView::ClearWindows(bool deleteWindows
)
1274 WX_CLEAR_HASH_MAP(wxIntToWindowHashMap
, m_tabWindows
);
1275 m_tabWindows
.clear();
1278 void wxPanelTabView::ShowWindowForTab(int id
)
1280 wxWindow
*newWindow
= GetTabWindow(id
);
1281 if (newWindow
== m_currentWindow
)
1283 if (m_currentWindow
)
1284 m_currentWindow
->Show(false);
1285 newWindow
->Show(true);
1286 newWindow
->Refresh();