]>
Commit | Line | Data |
---|---|---|
cd05bf23 | 1 | /////////////////////////////////////////////////////////////////////////////// |
4444d148 | 2 | // Name: src/aui/auibook.cpp |
cd05bf23 BW |
3 | // Purpose: wxaui: wx advanced user interface - notebook |
4 | // Author: Benjamin I. Williams | |
5 | // Modified by: | |
6 | // Created: 2006-06-28 | |
7 | // Copyright: (C) Copyright 2006, Kirix Corporation, All Rights Reserved | |
8 | // Licence: wxWindows Library Licence, Version 3.1 | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ---------------------------------------------------------------------------- | |
12 | // headers | |
13 | // ---------------------------------------------------------------------------- | |
14 | ||
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #if wxUSE_AUI | |
22 | ||
189da67c | 23 | #include "wx/aui/auibook.h" |
cd05bf23 BW |
24 | |
25 | #ifndef WX_PRECOMP | |
4444d148 | 26 | #include "wx/settings.h" |
03265113 | 27 | #include "wx/image.h" |
c58ba15f | 28 | #include "wx/menu.h" |
cd05bf23 BW |
29 | #endif |
30 | ||
4444d148 WS |
31 | #include "wx/aui/tabmdi.h" |
32 | #include "wx/dcbuffer.h" | |
33 | ||
a0c2e4a0 JS |
34 | #include "wx/renderer.h" |
35 | ||
a51dc103 | 36 | #ifdef __WXMAC__ |
efdea9c3 | 37 | #include "wx/osx/private.h" |
a51dc103 JS |
38 | #endif |
39 | ||
cd05bf23 BW |
40 | #include "wx/arrimpl.cpp" |
41 | WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray) | |
42 | WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray) | |
43 | ||
3c778901 VZ |
44 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEvent); |
45 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEvent); | |
46 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEvent); | |
47 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEvent); | |
48 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, wxAuiNotebookEvent); | |
49 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, wxAuiNotebookEvent); | |
50 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEvent); | |
2bd82d72 | 51 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, wxAuiNotebookEvent); |
3c778901 VZ |
52 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, wxAuiNotebookEvent); |
53 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, wxAuiNotebookEvent); | |
54 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEvent); | |
55 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, wxAuiNotebookEvent); | |
56 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, wxAuiNotebookEvent); | |
57 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEvent); | |
58 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEvent); | |
59 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEvent); | |
cd05bf23 | 60 | |
0ce53f32 | 61 | IMPLEMENT_CLASS(wxAuiNotebook, wxControl) |
5d3aeb0f | 62 | IMPLEMENT_CLASS(wxAuiTabCtrl, wxControl) |
873ff54b | 63 | IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent, wxBookCtrlEvent) |
cd05bf23 | 64 | |
cd05bf23 BW |
65 | |
66 | ||
cd05bf23 BW |
67 | |
68 | ||
a500c7ed BW |
69 | // these functions live in dockart.cpp -- they'll eventually |
70 | // be moved to a new utility cpp file | |
cd05bf23 | 71 | |
a500c7ed BW |
72 | wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h, |
73 | const wxColour& color); | |
74 | ||
75 | wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size); | |
cd05bf23 | 76 | |
b0d17f7c BW |
77 | static void DrawButtons(wxDC& dc, |
78 | const wxRect& _rect, | |
79 | const wxBitmap& bmp, | |
80 | const wxColour& bkcolour, | |
81 | int button_state) | |
cd05bf23 BW |
82 | { |
83 | wxRect rect = _rect; | |
84 | ||
85 | if (button_state == wxAUI_BUTTON_STATE_PRESSED) | |
86 | { | |
87 | rect.x++; | |
88 | rect.y++; | |
89 | } | |
90 | ||
91 | if (button_state == wxAUI_BUTTON_STATE_HOVER || | |
92 | button_state == wxAUI_BUTTON_STATE_PRESSED) | |
93 | { | |
a310c91c VZ |
94 | dc.SetBrush(wxBrush(bkcolour.ChangeLightness(120))); |
95 | dc.SetPen(wxPen(bkcolour.ChangeLightness(75))); | |
cd05bf23 BW |
96 | |
97 | // draw the background behind the button | |
98 | dc.DrawRectangle(rect.x, rect.y, 15, 15); | |
99 | } | |
100 | ||
101 | // draw the button itself | |
102 | dc.DrawBitmap(bmp, rect.x, rect.y, true); | |
103 | } | |
104 | ||
b0d17f7c BW |
105 | static void IndentPressedBitmap(wxRect* rect, int button_state) |
106 | { | |
107 | if (button_state == wxAUI_BUTTON_STATE_PRESSED) | |
108 | { | |
109 | rect->x++; | |
110 | rect->y++; | |
111 | } | |
112 | } | |
113 | ||
b0d17f7c BW |
114 | |
115 | ||
116 | // -- GUI helper classes and functions -- | |
117 | ||
118 | class wxAuiCommandCapture : public wxEvtHandler | |
119 | { | |
120 | public: | |
7baac3cb | 121 | |
9a29fe70 VZ |
122 | wxAuiCommandCapture() { m_lastId = 0; } |
123 | int GetCommandId() const { return m_lastId; } | |
b0d17f7c BW |
124 | |
125 | bool ProcessEvent(wxEvent& evt) | |
126 | { | |
127 | if (evt.GetEventType() == wxEVT_COMMAND_MENU_SELECTED) | |
128 | { | |
9a29fe70 | 129 | m_lastId = evt.GetId(); |
b0d17f7c BW |
130 | return true; |
131 | } | |
7baac3cb | 132 | |
b0d17f7c BW |
133 | if (GetNextHandler()) |
134 | return GetNextHandler()->ProcessEvent(evt); | |
135 | ||
136 | return false; | |
137 | } | |
7baac3cb | 138 | |
b0d17f7c | 139 | private: |
9a29fe70 | 140 | int m_lastId; |
b0d17f7c BW |
141 | }; |
142 | ||
143 | ||
144 | // -- bitmaps -- | |
145 | ||
146 | #if defined( __WXMAC__ ) | |
a243da29 | 147 | static const unsigned char close_bits[]={ |
b0d17f7c BW |
148 | 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3, |
149 | 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3, | |
150 | 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF }; | |
7baac3cb | 151 | #elif defined( __WXGTK__) |
a243da29 | 152 | static const unsigned char close_bits[]={ |
7baac3cb VZ |
153 | 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfb, 0xef, 0xdb, 0xed, 0x8b, 0xe8, |
154 | 0x1b, 0xec, 0x3b, 0xee, 0x1b, 0xec, 0x8b, 0xe8, 0xdb, 0xed, 0xfb, 0xef, | |
155 | 0x07, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
b0d17f7c | 156 | #else |
a243da29 | 157 | static const unsigned char close_bits[]={ |
8896cb72 BW |
158 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0xcf, 0xf9, |
159 | 0x9f, 0xfc, 0x3f, 0xfe, 0x3f, 0xfe, 0x9f, 0xfc, 0xcf, 0xf9, 0xe7, 0xf3, | |
160 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
b0d17f7c BW |
161 | #endif |
162 | ||
a243da29 | 163 | static const unsigned char left_bits[] = { |
b0d17f7c BW |
164 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe, |
165 | 0x1f, 0xfe, 0x0f, 0xfe, 0x1f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0xff, 0xfe, | |
166 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
167 | ||
a243da29 | 168 | static const unsigned char right_bits[] = { |
b0d17f7c BW |
169 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0x9f, 0xff, 0x1f, 0xff, |
170 | 0x1f, 0xfe, 0x1f, 0xfc, 0x1f, 0xfe, 0x1f, 0xff, 0x9f, 0xff, 0xdf, 0xff, | |
171 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
172 | ||
a243da29 | 173 | static const unsigned char list_bits[] = { |
b0d17f7c BW |
174 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
175 | 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff, | |
176 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
177 | ||
178 | ||
179 | ||
180 | ||
181 | ||
182 | ||
183 | // -- wxAuiDefaultTabArt class implementation -- | |
184 | ||
185 | wxAuiDefaultTabArt::wxAuiDefaultTabArt() | |
186 | { | |
9a29fe70 VZ |
187 | m_normalFont = *wxNORMAL_FONT; |
188 | m_selectedFont = *wxNORMAL_FONT; | |
189 | m_selectedFont.SetWeight(wxBOLD); | |
190 | m_measuringFont = m_selectedFont; | |
7baac3cb | 191 | |
9a29fe70 VZ |
192 | m_fixedTabWidth = 100; |
193 | m_tabCtrlHeight = 0; | |
b0d17f7c | 194 | |
efdea9c3 | 195 | #if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON |
9a29fe70 | 196 | wxColor baseColour = wxColour( wxMacCreateCGColorFromHITheme(kThemeBrushToolbarBackground)); |
003cf4ef | 197 | #else |
9a29fe70 | 198 | wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
003cf4ef BW |
199 | #endif |
200 | ||
9a29fe70 | 201 | // the baseColour is too pale to use as our base colour, |
3f7fce73 | 202 | // so darken it a bit -- |
9a29fe70 VZ |
203 | if ((255-baseColour.Red()) + |
204 | (255-baseColour.Green()) + | |
205 | (255-baseColour.Blue()) < 60) | |
3f7fce73 | 206 | { |
9a29fe70 | 207 | baseColour = baseColour.ChangeLightness(92); |
3f7fce73 | 208 | } |
c58ba15f | 209 | |
9a29fe70 VZ |
210 | m_activeColour = baseColour; |
211 | m_baseColour = baseColour; | |
212 | wxColor borderColour = baseColour.ChangeLightness(75); | |
7baac3cb | 213 | |
9a29fe70 VZ |
214 | m_borderPen = wxPen(borderColour); |
215 | m_baseColourPen = wxPen(m_baseColour); | |
216 | m_baseColourBrush = wxBrush(m_baseColour); | |
7baac3cb | 217 | |
9a29fe70 VZ |
218 | m_activeCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK); |
219 | m_disabledCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 220 | |
9a29fe70 VZ |
221 | m_activeLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK); |
222 | m_disabledLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 223 | |
9a29fe70 VZ |
224 | m_activeRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK); |
225 | m_disabledRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 226 | |
9a29fe70 VZ |
227 | m_activeWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK); |
228 | m_disabledWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 229 | |
b0d17f7c BW |
230 | m_flags = 0; |
231 | } | |
232 | ||
233 | wxAuiDefaultTabArt::~wxAuiDefaultTabArt() | |
234 | { | |
235 | } | |
236 | ||
237 | wxAuiTabArt* wxAuiDefaultTabArt::Clone() | |
238 | { | |
9a7963a9 | 239 | return new wxAuiDefaultTabArt(*this); |
b0d17f7c BW |
240 | } |
241 | ||
242 | void wxAuiDefaultTabArt::SetFlags(unsigned int flags) | |
243 | { | |
244 | m_flags = flags; | |
245 | } | |
246 | ||
247 | void wxAuiDefaultTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, | |
248 | size_t tab_count) | |
249 | { | |
9a29fe70 | 250 | m_fixedTabWidth = 100; |
7baac3cb | 251 | |
69685ee0 | 252 | int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - 4; |
c58ba15f | 253 | |
97ac2d5e | 254 | if (m_flags & wxAUI_NB_CLOSE_BUTTON) |
9a29fe70 | 255 | tot_width -= m_activeCloseBmp.GetWidth(); |
97ac2d5e | 256 | if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) |
9a29fe70 | 257 | tot_width -= m_activeWindowListBmp.GetWidth(); |
97ac2d5e | 258 | |
b0d17f7c BW |
259 | if (tab_count > 0) |
260 | { | |
9a29fe70 | 261 | m_fixedTabWidth = tot_width/(int)tab_count; |
b0d17f7c | 262 | } |
7baac3cb VZ |
263 | |
264 | ||
9a29fe70 VZ |
265 | if (m_fixedTabWidth < 100) |
266 | m_fixedTabWidth = 100; | |
7baac3cb | 267 | |
9a29fe70 VZ |
268 | if (m_fixedTabWidth > tot_width/2) |
269 | m_fixedTabWidth = tot_width/2; | |
7baac3cb | 270 | |
9a29fe70 VZ |
271 | if (m_fixedTabWidth > 220) |
272 | m_fixedTabWidth = 220; | |
7baac3cb | 273 | |
9a29fe70 | 274 | m_tabCtrlHeight = tab_ctrl_size.y; |
b0d17f7c | 275 | } |
7baac3cb VZ |
276 | |
277 | ||
b0d17f7c BW |
278 | void wxAuiDefaultTabArt::DrawBackground(wxDC& dc, |
279 | wxWindow* WXUNUSED(wnd), | |
280 | const wxRect& rect) | |
281 | { | |
282 | // draw background | |
134198f1 | 283 | |
9a29fe70 VZ |
284 | wxColor top_color = m_baseColour.ChangeLightness(90); |
285 | wxColor bottom_color = m_baseColour.ChangeLightness(170); | |
134198f1 JS |
286 | wxRect r; |
287 | ||
288 | if (m_flags &wxAUI_NB_BOTTOM) | |
289 | r = wxRect(rect.x, rect.y, rect.width+2, rect.height); | |
290 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
291 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
292 | else //for wxAUI_NB_TOP | |
293 | r = wxRect(rect.x, rect.y, rect.width+2, rect.height-3); | |
294 | ||
6a93539e | 295 | dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH); |
7baac3cb | 296 | |
134198f1 JS |
297 | |
298 | // draw base lines | |
299 | ||
9a29fe70 | 300 | dc.SetPen(m_borderPen); |
134198f1 JS |
301 | int y = rect.GetHeight(); |
302 | int w = rect.GetWidth(); | |
303 | ||
304 | if (m_flags &wxAUI_NB_BOTTOM) | |
305 | { | |
306 | dc.SetBrush(wxBrush(bottom_color)); | |
307 | dc.DrawRectangle(-1, 0, w+2, 4); | |
308 | } | |
309 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
310 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
311 | else //for wxAUI_NB_TOP | |
312 | { | |
9a29fe70 | 313 | dc.SetBrush(m_baseColourBrush); |
134198f1 JS |
314 | dc.DrawRectangle(-1, y-4, w+2, 4); |
315 | } | |
b0d17f7c BW |
316 | } |
317 | ||
318 | ||
319 | // DrawTab() draws an individual tab. | |
320 | // | |
321 | // dc - output dc | |
322 | // in_rect - rectangle the tab should be confined to | |
323 | // caption - tab's caption | |
324 | // active - whether or not the tab is active | |
325 | // out_rect - actual output rectangle | |
326 | // x_extent - the advance x; where the next tab should start | |
327 | ||
328 | void wxAuiDefaultTabArt::DrawTab(wxDC& dc, | |
329 | wxWindow* wnd, | |
793d4365 | 330 | const wxAuiNotebookPage& page, |
b0d17f7c | 331 | const wxRect& in_rect, |
b0d17f7c BW |
332 | int close_button_state, |
333 | wxRect* out_tab_rect, | |
334 | wxRect* out_button_rect, | |
335 | int* x_extent) | |
336 | { | |
337 | wxCoord normal_textx, normal_texty; | |
338 | wxCoord selected_textx, selected_texty; | |
cedd7b22 | 339 | wxCoord texty; |
7baac3cb | 340 | |
b0d17f7c | 341 | // if the caption is empty, measure some temporary text |
793d4365 BW |
342 | wxString caption = page.caption; |
343 | if (caption.empty()) | |
b0d17f7c | 344 | caption = wxT("Xj"); |
7baac3cb | 345 | |
9a29fe70 | 346 | dc.SetFont(m_selectedFont); |
b0d17f7c | 347 | dc.GetTextExtent(caption, &selected_textx, &selected_texty); |
7baac3cb | 348 | |
9a29fe70 | 349 | dc.SetFont(m_normalFont); |
b0d17f7c | 350 | dc.GetTextExtent(caption, &normal_textx, &normal_texty); |
7baac3cb | 351 | |
b0d17f7c | 352 | // figure out the size of the tab |
2b9aac33 BW |
353 | wxSize tab_size = GetTabSize(dc, |
354 | wnd, | |
793d4365 BW |
355 | page.caption, |
356 | page.bitmap, | |
357 | page.active, | |
2b9aac33 BW |
358 | close_button_state, |
359 | x_extent); | |
360 | ||
9a29fe70 | 361 | wxCoord tab_height = m_tabCtrlHeight - 3; |
b0d17f7c BW |
362 | wxCoord tab_width = tab_size.x; |
363 | wxCoord tab_x = in_rect.x; | |
364 | wxCoord tab_y = in_rect.y + in_rect.height - tab_height; | |
365 | ||
366 | ||
793d4365 | 367 | caption = page.caption; |
b0d17f7c | 368 | |
b0d17f7c BW |
369 | |
370 | // select pen, brush and font for the tab to be drawn | |
371 | ||
793d4365 | 372 | if (page.active) |
b0d17f7c | 373 | { |
9a29fe70 | 374 | dc.SetFont(m_selectedFont); |
b0d17f7c BW |
375 | texty = selected_texty; |
376 | } | |
cedd7b22 | 377 | else |
b0d17f7c | 378 | { |
9a29fe70 | 379 | dc.SetFont(m_normalFont); |
b0d17f7c BW |
380 | texty = normal_texty; |
381 | } | |
382 | ||
7baac3cb | 383 | |
7c508bca | 384 | // create points that will make the tab outline |
7baac3cb | 385 | |
519337de BW |
386 | int clip_width = tab_width; |
387 | if (tab_x + clip_width > in_rect.x + in_rect.width) | |
388 | clip_width = (in_rect.x + in_rect.width) - tab_x; | |
7baac3cb | 389 | |
8096c425 | 390 | /* |
003cf4ef | 391 | wxPoint clip_points[6]; |
519337de BW |
392 | clip_points[0] = wxPoint(tab_x, tab_y+tab_height-3); |
393 | clip_points[1] = wxPoint(tab_x, tab_y+2); | |
394 | clip_points[2] = wxPoint(tab_x+2, tab_y); | |
395 | clip_points[3] = wxPoint(tab_x+clip_width-1, tab_y); | |
396 | clip_points[4] = wxPoint(tab_x+clip_width+1, tab_y+2); | |
397 | clip_points[5] = wxPoint(tab_x+clip_width+1, tab_y+tab_height-3); | |
003cf4ef | 398 | |
eab9751b | 399 | // FIXME: these ports don't provide wxRegion ctor from array of points |
0197bcdd | 400 | #if !defined(__WXDFB__) && !defined(__WXCOCOA__) |
003cf4ef | 401 | // set the clipping region for the tab -- |
7baac3cb | 402 | wxRegion clipping_region(WXSIZEOF(clip_points), clip_points); |
003cf4ef | 403 | dc.SetClippingRegion(clipping_region); |
0197bcdd | 404 | #endif // !wxDFB && !wxCocoa |
8096c425 BW |
405 | */ |
406 | // since the above code above doesn't play well with WXDFB or WXCOCOA, | |
407 | // we'll just use a rectangle for the clipping region for now -- | |
408 | dc.SetClippingRegion(tab_x, tab_y, clip_width+1, tab_height-3); | |
003cf4ef | 409 | |
c58ba15f | 410 | |
003cf4ef | 411 | wxPoint border_points[6]; |
134198f1 JS |
412 | if (m_flags &wxAUI_NB_BOTTOM) |
413 | { | |
414 | border_points[0] = wxPoint(tab_x, tab_y); | |
415 | border_points[1] = wxPoint(tab_x, tab_y+tab_height-6); | |
416 | border_points[2] = wxPoint(tab_x+2, tab_y+tab_height-4); | |
417 | border_points[3] = wxPoint(tab_x+tab_width-2, tab_y+tab_height-4); | |
418 | border_points[4] = wxPoint(tab_x+tab_width, tab_y+tab_height-6); | |
419 | border_points[5] = wxPoint(tab_x+tab_width, tab_y); | |
420 | } | |
421 | else //if (m_flags & wxAUI_NB_TOP) {} | |
422 | { | |
423 | border_points[0] = wxPoint(tab_x, tab_y+tab_height-4); | |
424 | border_points[1] = wxPoint(tab_x, tab_y+2); | |
425 | border_points[2] = wxPoint(tab_x+2, tab_y); | |
426 | border_points[3] = wxPoint(tab_x+tab_width-2, tab_y); | |
427 | border_points[4] = wxPoint(tab_x+tab_width, tab_y+2); | |
428 | border_points[5] = wxPoint(tab_x+tab_width, tab_y+tab_height-4); | |
429 | } | |
430 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} | |
431 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
7baac3cb | 432 | |
003cf4ef BW |
433 | int drawn_tab_yoff = border_points[1].y; |
434 | int drawn_tab_height = border_points[0].y - border_points[1].y; | |
435 | ||
2b9aac33 | 436 | |
793d4365 | 437 | if (page.active) |
003cf4ef | 438 | { |
7baac3cb VZ |
439 | // draw active tab |
440 | ||
1750e8e2 | 441 | // draw base background color |
003cf4ef | 442 | wxRect r(tab_x, tab_y, tab_width, tab_height); |
9a29fe70 VZ |
443 | dc.SetPen(wxPen(m_activeColour)); |
444 | dc.SetBrush(wxBrush(m_activeColour)); | |
8096c425 | 445 | dc.DrawRectangle(r.x+1, r.y+1, r.width-1, r.height-4); |
7baac3cb | 446 | |
003cf4ef | 447 | // this white helps fill out the gradient at the top of the tab |
1750e8e2 BW |
448 | dc.SetPen(*wxWHITE_PEN); |
449 | dc.SetBrush(*wxWHITE_BRUSH); | |
8096c425 | 450 | dc.DrawRectangle(r.x+2, r.y+1, r.width-3, r.height-4); |
7baac3cb | 451 | |
003cf4ef | 452 | // these two points help the rounded corners appear more antialiased |
9a29fe70 | 453 | dc.SetPen(wxPen(m_activeColour)); |
6a93539e BW |
454 | dc.DrawPoint(r.x+2, r.y+1); |
455 | dc.DrawPoint(r.x+r.width-2, r.y+1); | |
7baac3cb | 456 | |
1750e8e2 BW |
457 | // set rectangle down a bit for gradient drawing |
458 | r.SetHeight(r.GetHeight()/2); | |
003cf4ef | 459 | r.x += 2; |
4bd9bdf3 | 460 | r.width -= 3; |
1750e8e2 | 461 | r.y += r.height; |
6a93539e | 462 | r.y -= 2; |
7baac3cb | 463 | |
1750e8e2 | 464 | // draw gradient background |
6a93539e | 465 | wxColor top_color = *wxWHITE; |
9a29fe70 | 466 | wxColor bottom_color = m_activeColour; |
6a93539e | 467 | dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); |
b0d17f7c | 468 | } |
cedd7b22 | 469 | else |
1750e8e2 BW |
470 | { |
471 | // draw inactive tab | |
7baac3cb | 472 | |
1750e8e2 | 473 | wxRect r(tab_x, tab_y+1, tab_width, tab_height-3); |
7baac3cb | 474 | |
1750e8e2 BW |
475 | // start the gradent up a bit and leave the inside border inset |
476 | // by a pixel for a 3D look. Only the top half of the inactive | |
477 | // tab will have a slight gradient | |
6a93539e BW |
478 | r.x += 3; |
479 | r.y++; | |
480 | r.width -= 4; | |
1750e8e2 | 481 | r.height /= 2; |
6a93539e | 482 | r.height--; |
c58ba15f | 483 | |
6a93539e | 484 | // -- draw top gradient fill for glossy look |
9a29fe70 | 485 | wxColor top_color = m_baseColour; |
a310c91c | 486 | wxColor bottom_color = top_color.ChangeLightness(160); |
1750e8e2 | 487 | dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH); |
c58ba15f | 488 | |
6a93539e BW |
489 | r.y += r.height; |
490 | r.y--; | |
c58ba15f | 491 | |
6a93539e | 492 | // -- draw bottom fill for glossy look |
9a29fe70 VZ |
493 | top_color = m_baseColour; |
494 | bottom_color = m_baseColour; | |
6a93539e | 495 | dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH); |
1750e8e2 | 496 | } |
7baac3cb VZ |
497 | |
498 | // draw tab outline | |
9a29fe70 | 499 | dc.SetPen(m_borderPen); |
b0d17f7c | 500 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
7baac3cb VZ |
501 | dc.DrawPolygon(WXSIZEOF(border_points), border_points); |
502 | ||
7c508bca BW |
503 | // there are two horizontal grey lines at the bottom of the tab control, |
504 | // this gets rid of the top one of those lines in the tab control | |
793d4365 | 505 | if (page.active) |
b0d17f7c | 506 | { |
134198f1 | 507 | if (m_flags &wxAUI_NB_BOTTOM) |
9a29fe70 | 508 | dc.SetPen(wxPen(m_baseColour.ChangeLightness(170))); |
134198f1 JS |
509 | // TODO: else if (m_flags &wxAUI_NB_LEFT) {} |
510 | // TODO: else if (m_flags &wxAUI_NB_RIGHT) {} | |
511 | else //for wxAUI_NB_TOP | |
9a29fe70 | 512 | dc.SetPen(m_baseColourPen); |
6a93539e | 513 | dc.DrawLine(border_points[0].x+1, |
003cf4ef | 514 | border_points[0].y, |
6a93539e | 515 | border_points[5].x, |
003cf4ef | 516 | border_points[5].y); |
b0d17f7c | 517 | } |
7baac3cb | 518 | |
b0d17f7c | 519 | |
2b9aac33 | 520 | int text_offset = tab_x + 8; |
b0d17f7c | 521 | int close_button_width = 0; |
b0d17f7c BW |
522 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) |
523 | { | |
9a29fe70 | 524 | close_button_width = m_activeCloseBmp.GetWidth(); |
b0d17f7c | 525 | } |
7baac3cb | 526 | |
a0c2e4a0 | 527 | int bitmap_offset = 0; |
793d4365 | 528 | if (page.bitmap.IsOk()) |
2b9aac33 | 529 | { |
a0c2e4a0 | 530 | bitmap_offset = tab_x + 8; |
7baac3cb | 531 | |
2b9aac33 | 532 | // draw bitmap |
793d4365 | 533 | dc.DrawBitmap(page.bitmap, |
2b9aac33 | 534 | bitmap_offset, |
793d4365 | 535 | drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), |
2b9aac33 | 536 | true); |
7baac3cb | 537 | |
793d4365 | 538 | text_offset = bitmap_offset + page.bitmap.GetWidth(); |
2b9aac33 | 539 | text_offset += 3; // bitmap padding |
a0c2e4a0 | 540 | |
2b9aac33 | 541 | } |
cedd7b22 | 542 | else |
2b9aac33 BW |
543 | { |
544 | text_offset = tab_x + 8; | |
545 | } | |
7baac3cb | 546 | |
b0d17f7c | 547 | |
a500c7ed | 548 | wxString draw_text = wxAuiChopText(dc, |
b0d17f7c BW |
549 | caption, |
550 | tab_width - (text_offset-tab_x) - close_button_width); | |
7baac3cb | 551 | |
b0d17f7c BW |
552 | // draw tab text |
553 | dc.DrawText(draw_text, | |
554 | text_offset, | |
2b9aac33 | 555 | drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1); |
b0d17f7c | 556 | |
a0c2e4a0 JS |
557 | // draw focus rectangle |
558 | if (page.active && (wnd->FindFocus() == wnd)) | |
559 | { | |
560 | wxRect focusRectText(text_offset, (drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1), | |
561 | selected_textx, selected_texty); | |
562 | ||
563 | wxRect focusRect; | |
564 | wxRect focusRectBitmap; | |
b0d17f7c | 565 | |
a0c2e4a0 JS |
566 | if (page.bitmap.IsOk()) |
567 | focusRectBitmap = wxRect(bitmap_offset, drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2), | |
568 | page.bitmap.GetWidth(), page.bitmap.GetHeight()); | |
b0d17f7c | 569 | |
a0c2e4a0 JS |
570 | if (page.bitmap.IsOk() && draw_text.IsEmpty()) |
571 | focusRect = focusRectBitmap; | |
572 | else if (!page.bitmap.IsOk() && !draw_text.IsEmpty()) | |
573 | focusRect = focusRectText; | |
574 | else if (page.bitmap.IsOk() && !draw_text.IsEmpty()) | |
575 | focusRect = focusRectText.Union(focusRectBitmap); | |
576 | ||
577 | focusRect.Inflate(2, 2); | |
578 | ||
579 | wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); | |
580 | } | |
b0d17f7c BW |
581 | |
582 | // draw close button if necessary | |
583 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) | |
584 | { | |
9a29fe70 | 585 | wxBitmap bmp = m_disabledCloseBmp; |
b0d17f7c BW |
586 | |
587 | if (close_button_state == wxAUI_BUTTON_STATE_HOVER || | |
588 | close_button_state == wxAUI_BUTTON_STATE_PRESSED) | |
589 | { | |
9a29fe70 | 590 | bmp = m_activeCloseBmp; |
b0d17f7c | 591 | } |
7baac3cb | 592 | |
9a3551d3 JS |
593 | int offsetY = tab_y-1; |
594 | if (m_flags & wxAUI_NB_BOTTOM) | |
595 | offsetY = 1; | |
596 | ||
b0d17f7c | 597 | wxRect rect(tab_x + tab_width - close_button_width - 1, |
9a3551d3 | 598 | offsetY + (tab_height/2) - (bmp.GetHeight()/2), |
b0d17f7c BW |
599 | close_button_width, |
600 | tab_height); | |
9a3551d3 | 601 | |
b0d17f7c BW |
602 | IndentPressedBitmap(&rect, close_button_state); |
603 | dc.DrawBitmap(bmp, rect.x, rect.y, true); | |
7baac3cb | 604 | |
b0d17f7c BW |
605 | *out_button_rect = rect; |
606 | } | |
7baac3cb | 607 | |
b0d17f7c | 608 | *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); |
7baac3cb | 609 | |
b0d17f7c BW |
610 | dc.DestroyClippingRegion(); |
611 | } | |
612 | ||
613 | int wxAuiDefaultTabArt::GetIndentSize() | |
614 | { | |
615 | return 5; | |
616 | } | |
617 | ||
618 | wxSize wxAuiDefaultTabArt::GetTabSize(wxDC& dc, | |
619 | wxWindow* WXUNUSED(wnd), | |
620 | const wxString& caption, | |
2b9aac33 | 621 | const wxBitmap& bitmap, |
b0d17f7c BW |
622 | bool WXUNUSED(active), |
623 | int close_button_state, | |
624 | int* x_extent) | |
625 | { | |
626 | wxCoord measured_textx, measured_texty, tmp; | |
7baac3cb | 627 | |
9a29fe70 | 628 | dc.SetFont(m_measuringFont); |
b0d17f7c | 629 | dc.GetTextExtent(caption, &measured_textx, &measured_texty); |
7baac3cb | 630 | |
b0d17f7c | 631 | dc.GetTextExtent(wxT("ABCDEFXj"), &tmp, &measured_texty); |
7baac3cb | 632 | |
213e64e9 | 633 | // add padding around the text |
2b9aac33 BW |
634 | wxCoord tab_width = measured_textx; |
635 | wxCoord tab_height = measured_texty; | |
b0d17f7c | 636 | |
2b9aac33 | 637 | // if the close button is showing, add space for it |
b0d17f7c | 638 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) |
9a29fe70 | 639 | tab_width += m_activeCloseBmp.GetWidth() + 3; |
b0d17f7c | 640 | |
2b9aac33 BW |
641 | // if there's a bitmap, add space for it |
642 | if (bitmap.IsOk()) | |
643 | { | |
644 | tab_width += bitmap.GetWidth(); | |
645 | tab_width += 3; // right side bitmap padding | |
646 | tab_height = wxMax(tab_height, bitmap.GetHeight()); | |
647 | } | |
648 | ||
649 | // add padding | |
650 | tab_width += 16; | |
651 | tab_height += 10; | |
b0d17f7c BW |
652 | |
653 | if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) | |
654 | { | |
9a29fe70 | 655 | tab_width = m_fixedTabWidth; |
b0d17f7c | 656 | } |
7baac3cb | 657 | |
b0d17f7c | 658 | *x_extent = tab_width; |
7baac3cb | 659 | |
b0d17f7c BW |
660 | return wxSize(tab_width, tab_height); |
661 | } | |
662 | ||
663 | ||
664 | void wxAuiDefaultTabArt::DrawButton(wxDC& dc, | |
665 | wxWindow* WXUNUSED(wnd), | |
666 | const wxRect& in_rect, | |
667 | int bitmap_id, | |
668 | int button_state, | |
669 | int orientation, | |
b0d17f7c BW |
670 | wxRect* out_rect) |
671 | { | |
672 | wxBitmap bmp; | |
673 | wxRect rect; | |
7baac3cb | 674 | |
793d4365 | 675 | switch (bitmap_id) |
b0d17f7c | 676 | { |
793d4365 BW |
677 | case wxAUI_BUTTON_CLOSE: |
678 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 679 | bmp = m_disabledCloseBmp; |
cedd7b22 | 680 | else |
9a29fe70 | 681 | bmp = m_activeCloseBmp; |
793d4365 BW |
682 | break; |
683 | case wxAUI_BUTTON_LEFT: | |
684 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 685 | bmp = m_disabledLeftBmp; |
cedd7b22 | 686 | else |
9a29fe70 | 687 | bmp = m_activeLeftBmp; |
793d4365 BW |
688 | break; |
689 | case wxAUI_BUTTON_RIGHT: | |
690 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 691 | bmp = m_disabledRightBmp; |
cedd7b22 | 692 | else |
9a29fe70 | 693 | bmp = m_activeRightBmp; |
793d4365 BW |
694 | break; |
695 | case wxAUI_BUTTON_WINDOWLIST: | |
696 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 697 | bmp = m_disabledWindowListBmp; |
cedd7b22 | 698 | else |
9a29fe70 | 699 | bmp = m_activeWindowListBmp; |
793d4365 | 700 | break; |
b0d17f7c | 701 | } |
cd05bf23 | 702 | |
793d4365 | 703 | |
b0d17f7c BW |
704 | if (!bmp.IsOk()) |
705 | return; | |
7baac3cb | 706 | |
b0d17f7c | 707 | rect = in_rect; |
7baac3cb | 708 | |
b0d17f7c BW |
709 | if (orientation == wxLEFT) |
710 | { | |
711 | rect.SetX(in_rect.x); | |
712 | rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2)); | |
713 | rect.SetWidth(bmp.GetWidth()); | |
714 | rect.SetHeight(bmp.GetHeight()); | |
715 | } | |
cedd7b22 | 716 | else |
b0d17f7c BW |
717 | { |
718 | rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), | |
719 | ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2), | |
720 | bmp.GetWidth(), bmp.GetHeight()); | |
721 | } | |
7baac3cb | 722 | |
b0d17f7c BW |
723 | IndentPressedBitmap(&rect, button_state); |
724 | dc.DrawBitmap(bmp, rect.x, rect.y, true); | |
7baac3cb | 725 | |
b0d17f7c BW |
726 | *out_rect = rect; |
727 | } | |
cd05bf23 | 728 | |
793d4365 BW |
729 | int wxAuiDefaultTabArt::ShowDropDown(wxWindow* wnd, |
730 | const wxAuiNotebookPageArray& pages, | |
17dd0e05 | 731 | int /*active_idx*/) |
b0d17f7c | 732 | { |
c58ba15f | 733 | wxMenu menuPopup; |
3f69756e | 734 | |
793d4365 | 735 | size_t i, count = pages.GetCount(); |
b0d17f7c BW |
736 | for (i = 0; i < count; ++i) |
737 | { | |
793d4365 | 738 | const wxAuiNotebookPage& page = pages.Item(i); |
d51beb88 BW |
739 | wxString caption = page.caption; |
740 | ||
741 | // if there is no caption, make it a space. This will prevent | |
742 | // an assert in the menu code. | |
743 | if (caption.IsEmpty()) | |
744 | caption = wxT(" "); | |
745 | ||
17dd0e05 VZ |
746 | wxMenuItem* item = new wxMenuItem(NULL, 1000+i, caption); |
747 | if (page.bitmap.IsOk()) | |
748 | item->SetBitmap(page.bitmap); | |
749 | menuPopup.Append(item); | |
b0d17f7c | 750 | } |
7baac3cb | 751 | |
7f1e1468 | 752 | // find out where to put the popup menu of window items |
b0d17f7c BW |
753 | wxPoint pt = ::wxGetMousePosition(); |
754 | pt = wnd->ScreenToClient(pt); | |
7baac3cb | 755 | |
b0d17f7c BW |
756 | // find out the screen coordinate at the bottom of the tab ctrl |
757 | wxRect cli_rect = wnd->GetClientRect(); | |
758 | pt.y = cli_rect.y + cli_rect.height; | |
7baac3cb | 759 | |
b0d17f7c BW |
760 | wxAuiCommandCapture* cc = new wxAuiCommandCapture; |
761 | wnd->PushEventHandler(cc); | |
762 | wnd->PopupMenu(&menuPopup, pt); | |
763 | int command = cc->GetCommandId(); | |
764 | wnd->PopEventHandler(true); | |
7baac3cb | 765 | |
b0d17f7c BW |
766 | if (command >= 1000) |
767 | return command-1000; | |
7baac3cb | 768 | |
b0d17f7c BW |
769 | return -1; |
770 | } | |
3f69756e | 771 | |
2b9aac33 | 772 | int wxAuiDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd, |
793d4365 | 773 | const wxAuiNotebookPageArray& pages, |
9a29fe70 | 774 | const wxSize& requiredBmp_size) |
b0d17f7c BW |
775 | { |
776 | wxClientDC dc(wnd); | |
9a29fe70 | 777 | dc.SetFont(m_measuringFont); |
7baac3cb | 778 | |
9fbb7d80 BW |
779 | // sometimes a standard bitmap size needs to be enforced, especially |
780 | // if some tabs have bitmaps and others don't. This is important because | |
781 | // it prevents the tab control from resizing when tabs are added. | |
9a29fe70 VZ |
782 | wxBitmap measureBmp; |
783 | if (requiredBmp_size.IsFullySpecified()) | |
9fbb7d80 | 784 | { |
9a29fe70 VZ |
785 | measureBmp.Create(requiredBmp_size.x, |
786 | requiredBmp_size.y); | |
9fbb7d80 | 787 | } |
c58ba15f | 788 | |
9fbb7d80 | 789 | |
2b9aac33 BW |
790 | int max_y = 0; |
791 | size_t i, page_count = pages.GetCount(); | |
792 | for (i = 0; i < page_count; ++i) | |
793 | { | |
794 | wxAuiNotebookPage& page = pages.Item(i); | |
795 | ||
9fbb7d80 | 796 | wxBitmap bmp; |
9a29fe70 VZ |
797 | if (measureBmp.IsOk()) |
798 | bmp = measureBmp; | |
cedd7b22 | 799 | else |
9fbb7d80 BW |
800 | bmp = page.bitmap; |
801 | ||
2b9aac33 BW |
802 | // we don't use the caption text because we don't |
803 | // want tab heights to be different in the case | |
804 | // of a very short piece of text on one tab and a very | |
805 | // tall piece of text on another tab | |
806 | int x_ext = 0; | |
807 | wxSize s = GetTabSize(dc, | |
808 | wnd, | |
809 | wxT("ABCDEFGHIj"), | |
9fbb7d80 | 810 | bmp, |
2b9aac33 BW |
811 | true, |
812 | wxAUI_BUTTON_STATE_HIDDEN, | |
813 | &x_ext); | |
c58ba15f | 814 | |
2b9aac33 BW |
815 | max_y = wxMax(max_y, s.y); |
816 | } | |
7baac3cb | 817 | |
2b9aac33 | 818 | return max_y+2; |
b0d17f7c BW |
819 | } |
820 | ||
821 | void wxAuiDefaultTabArt::SetNormalFont(const wxFont& font) | |
822 | { | |
9a29fe70 | 823 | m_normalFont = font; |
b0d17f7c BW |
824 | } |
825 | ||
826 | void wxAuiDefaultTabArt::SetSelectedFont(const wxFont& font) | |
827 | { | |
9a29fe70 | 828 | m_selectedFont = font; |
b0d17f7c BW |
829 | } |
830 | ||
831 | void wxAuiDefaultTabArt::SetMeasuringFont(const wxFont& font) | |
832 | { | |
9a29fe70 | 833 | m_measuringFont = font; |
b0d17f7c BW |
834 | } |
835 | ||
ceb9b8db VZ |
836 | void wxAuiDefaultTabArt::SetColour(const wxColour& colour) |
837 | { | |
9a29fe70 VZ |
838 | m_baseColour = colour; |
839 | m_borderPen = wxPen(m_baseColour.ChangeLightness(75)); | |
840 | m_baseColourPen = wxPen(m_baseColour); | |
841 | m_baseColourBrush = wxBrush(m_baseColour); | |
ceb9b8db VZ |
842 | } |
843 | ||
844 | void wxAuiDefaultTabArt::SetActiveColour(const wxColour& colour) | |
845 | { | |
9a29fe70 | 846 | m_activeColour = colour; |
ceb9b8db | 847 | } |
b0d17f7c BW |
848 | |
849 | // -- wxAuiSimpleTabArt class implementation -- | |
850 | ||
851 | wxAuiSimpleTabArt::wxAuiSimpleTabArt() | |
cd05bf23 | 852 | { |
9a29fe70 VZ |
853 | m_normalFont = *wxNORMAL_FONT; |
854 | m_selectedFont = *wxNORMAL_FONT; | |
855 | m_selectedFont.SetWeight(wxBOLD); | |
856 | m_measuringFont = m_selectedFont; | |
4444d148 | 857 | |
b0d17f7c | 858 | m_flags = 0; |
9a29fe70 | 859 | m_fixedTabWidth = 100; |
b0d17f7c | 860 | |
9a29fe70 | 861 | wxColour baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
4444d148 | 862 | |
9a29fe70 VZ |
863 | wxColour backgroundColour = baseColour; |
864 | wxColour normaltabColour = baseColour; | |
865 | wxColour selectedtabColour = *wxWHITE; | |
4444d148 | 866 | |
9a29fe70 VZ |
867 | m_bkBrush = wxBrush(backgroundColour); |
868 | m_normalBkBrush = wxBrush(normaltabColour); | |
869 | m_normalBkPen = wxPen(normaltabColour); | |
870 | m_selectedBkBrush = wxBrush(selectedtabColour); | |
871 | m_selectedBkPen = wxPen(selectedtabColour); | |
7baac3cb | 872 | |
9a29fe70 VZ |
873 | m_activeCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK); |
874 | m_disabledCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 875 | |
9a29fe70 VZ |
876 | m_activeLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK); |
877 | m_disabledLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 878 | |
9a29fe70 VZ |
879 | m_activeRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK); |
880 | m_disabledRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 881 | |
9a29fe70 VZ |
882 | m_activeWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK); |
883 | m_disabledWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128)); | |
7baac3cb | 884 | |
cd05bf23 BW |
885 | } |
886 | ||
b0d17f7c | 887 | wxAuiSimpleTabArt::~wxAuiSimpleTabArt() |
488e50ee BW |
888 | { |
889 | } | |
890 | ||
b0d17f7c BW |
891 | wxAuiTabArt* wxAuiSimpleTabArt::Clone() |
892 | { | |
ceb9b8db | 893 | return new wxAuiSimpleTabArt(*this); |
b0d17f7c BW |
894 | } |
895 | ||
b0d17f7c BW |
896 | void wxAuiSimpleTabArt::SetFlags(unsigned int flags) |
897 | { | |
898 | m_flags = flags; | |
899 | } | |
900 | ||
901 | void wxAuiSimpleTabArt::SetSizingInfo(const wxSize& tab_ctrl_size, | |
902 | size_t tab_count) | |
903 | { | |
9a29fe70 | 904 | m_fixedTabWidth = 100; |
7baac3cb | 905 | |
69685ee0 | 906 | int tot_width = (int)tab_ctrl_size.x - GetIndentSize() - 4; |
97ac2d5e BW |
907 | |
908 | if (m_flags & wxAUI_NB_CLOSE_BUTTON) | |
9a29fe70 | 909 | tot_width -= m_activeCloseBmp.GetWidth(); |
97ac2d5e | 910 | if (m_flags & wxAUI_NB_WINDOWLIST_BUTTON) |
9a29fe70 | 911 | tot_width -= m_activeWindowListBmp.GetWidth(); |
97ac2d5e | 912 | |
b0d17f7c BW |
913 | if (tab_count > 0) |
914 | { | |
9a29fe70 | 915 | m_fixedTabWidth = tot_width/(int)tab_count; |
b0d17f7c | 916 | } |
7baac3cb VZ |
917 | |
918 | ||
9a29fe70 VZ |
919 | if (m_fixedTabWidth < 100) |
920 | m_fixedTabWidth = 100; | |
7baac3cb | 921 | |
9a29fe70 VZ |
922 | if (m_fixedTabWidth > tot_width/2) |
923 | m_fixedTabWidth = tot_width/2; | |
7baac3cb | 924 | |
9a29fe70 VZ |
925 | if (m_fixedTabWidth > 220) |
926 | m_fixedTabWidth = 220; | |
b0d17f7c BW |
927 | } |
928 | ||
ceb9b8db VZ |
929 | void wxAuiSimpleTabArt::SetColour(const wxColour& colour) |
930 | { | |
9a29fe70 VZ |
931 | m_bkBrush = wxBrush(colour); |
932 | m_normalBkBrush = wxBrush(colour); | |
933 | m_normalBkPen = wxPen(colour); | |
ceb9b8db VZ |
934 | } |
935 | ||
936 | void wxAuiSimpleTabArt::SetActiveColour(const wxColour& colour) | |
937 | { | |
9a29fe70 VZ |
938 | m_selectedBkBrush = wxBrush(colour); |
939 | m_selectedBkPen = wxPen(colour); | |
ceb9b8db VZ |
940 | } |
941 | ||
b0d17f7c BW |
942 | void wxAuiSimpleTabArt::DrawBackground(wxDC& dc, |
943 | wxWindow* WXUNUSED(wnd), | |
944 | const wxRect& rect) | |
3f69756e BW |
945 | { |
946 | // draw background | |
9a29fe70 | 947 | dc.SetBrush(m_bkBrush); |
a6b0e5bd BW |
948 | dc.SetPen(*wxTRANSPARENT_PEN); |
949 | dc.DrawRectangle(-1, -1, rect.GetWidth()+2, rect.GetHeight()+2); | |
3f69756e BW |
950 | |
951 | // draw base line | |
a6b0e5bd BW |
952 | dc.SetPen(*wxGREY_PEN); |
953 | dc.DrawLine(0, rect.GetHeight()-1, rect.GetWidth(), rect.GetHeight()-1); | |
3f69756e BW |
954 | } |
955 | ||
4953f8cf | 956 | |
3f69756e BW |
957 | // DrawTab() draws an individual tab. |
958 | // | |
959 | // dc - output dc | |
960 | // in_rect - rectangle the tab should be confined to | |
961 | // caption - tab's caption | |
962 | // active - whether or not the tab is active | |
963 | // out_rect - actual output rectangle | |
964 | // x_extent - the advance x; where the next tab should start | |
965 | ||
b0d17f7c BW |
966 | void wxAuiSimpleTabArt::DrawTab(wxDC& dc, |
967 | wxWindow* wnd, | |
793d4365 | 968 | const wxAuiNotebookPage& page, |
b0d17f7c | 969 | const wxRect& in_rect, |
b0d17f7c BW |
970 | int close_button_state, |
971 | wxRect* out_tab_rect, | |
972 | wxRect* out_button_rect, | |
973 | int* x_extent) | |
3f69756e BW |
974 | { |
975 | wxCoord normal_textx, normal_texty; | |
976 | wxCoord selected_textx, selected_texty; | |
3f69756e | 977 | wxCoord textx, texty; |
7baac3cb | 978 | |
3f69756e | 979 | // if the caption is empty, measure some temporary text |
793d4365 BW |
980 | wxString caption = page.caption; |
981 | if (caption.empty()) | |
3f69756e | 982 | caption = wxT("Xj"); |
7baac3cb | 983 | |
9a29fe70 | 984 | dc.SetFont(m_selectedFont); |
a6b0e5bd | 985 | dc.GetTextExtent(caption, &selected_textx, &selected_texty); |
7baac3cb | 986 | |
9a29fe70 | 987 | dc.SetFont(m_normalFont); |
a6b0e5bd | 988 | dc.GetTextExtent(caption, &normal_textx, &normal_texty); |
7baac3cb | 989 | |
a4c8fc23 | 990 | // figure out the size of the tab |
2b9aac33 BW |
991 | wxSize tab_size = GetTabSize(dc, |
992 | wnd, | |
793d4365 BW |
993 | page.caption, |
994 | page.bitmap, | |
995 | page.active, | |
2b9aac33 BW |
996 | close_button_state, |
997 | x_extent); | |
3f69756e | 998 | |
a4c8fc23 BW |
999 | wxCoord tab_height = tab_size.y; |
1000 | wxCoord tab_width = tab_size.x; | |
3f69756e BW |
1001 | wxCoord tab_x = in_rect.x; |
1002 | wxCoord tab_y = in_rect.y + in_rect.height - tab_height; | |
1003 | ||
793d4365 | 1004 | caption = page.caption; |
b965ffff | 1005 | |
3f69756e BW |
1006 | // select pen, brush and font for the tab to be drawn |
1007 | ||
793d4365 | 1008 | if (page.active) |
3f69756e | 1009 | { |
9a29fe70 VZ |
1010 | dc.SetPen(m_selectedBkPen); |
1011 | dc.SetBrush(m_selectedBkBrush); | |
1012 | dc.SetFont(m_selectedFont); | |
3f69756e BW |
1013 | textx = selected_textx; |
1014 | texty = selected_texty; | |
1015 | } | |
cedd7b22 | 1016 | else |
3f69756e | 1017 | { |
9a29fe70 VZ |
1018 | dc.SetPen(m_normalBkPen); |
1019 | dc.SetBrush(m_normalBkBrush); | |
1020 | dc.SetFont(m_normalFont); | |
3f69756e BW |
1021 | textx = normal_textx; |
1022 | texty = normal_texty; | |
1023 | } | |
1024 | ||
1025 | ||
1026 | // -- draw line -- | |
1027 | ||
1028 | wxPoint points[7]; | |
1029 | points[0].x = tab_x; | |
1030 | points[0].y = tab_y + tab_height - 1; | |
1031 | points[1].x = tab_x + tab_height - 3; | |
1032 | points[1].y = tab_y + 2; | |
1033 | points[2].x = tab_x + tab_height + 3; | |
1034 | points[2].y = tab_y; | |
1035 | points[3].x = tab_x + tab_width - 2; | |
1036 | points[3].y = tab_y; | |
1037 | points[4].x = tab_x + tab_width; | |
1038 | points[4].y = tab_y + 2; | |
1039 | points[5].x = tab_x + tab_width; | |
1040 | points[5].y = tab_y + tab_height - 1; | |
1041 | points[6] = points[0]; | |
1042 | ||
b0d17f7c | 1043 | dc.SetClippingRegion(in_rect); |
3f69756e | 1044 | |
7baac3cb | 1045 | dc.DrawPolygon(WXSIZEOF(points) - 1, points); |
3f69756e | 1046 | |
a6b0e5bd | 1047 | dc.SetPen(*wxGREY_PEN); |
3f69756e | 1048 | |
7baac3cb VZ |
1049 | //dc.DrawLines(active ? WXSIZEOF(points) - 1 : WXSIZEOF(points), points); |
1050 | dc.DrawLines(WXSIZEOF(points), points); | |
3f69756e | 1051 | |
3f69756e | 1052 | |
702b1c7e BW |
1053 | int text_offset; |
1054 | ||
1055 | int close_button_width = 0; | |
41b76acd | 1056 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) |
702b1c7e | 1057 | { |
9a29fe70 | 1058 | close_button_width = m_activeCloseBmp.GetWidth(); |
702b1c7e BW |
1059 | text_offset = tab_x + (tab_height/2) + ((tab_width-close_button_width)/2) - (textx/2); |
1060 | } | |
cedd7b22 | 1061 | else |
702b1c7e BW |
1062 | { |
1063 | text_offset = tab_x + (tab_height/3) + (tab_width/2) - (textx/2); | |
1064 | } | |
7baac3cb | 1065 | |
b0d17f7c BW |
1066 | // set minimum text offset |
1067 | if (text_offset < tab_x + tab_height) | |
1068 | text_offset = tab_x + tab_height; | |
1069 | ||
1070 | // chop text if necessary | |
a500c7ed | 1071 | wxString draw_text = wxAuiChopText(dc, |
b0d17f7c BW |
1072 | caption, |
1073 | tab_width - (text_offset-tab_x) - close_button_width); | |
702b1c7e BW |
1074 | |
1075 | // draw tab text | |
b0d17f7c | 1076 | dc.DrawText(draw_text, |
702b1c7e | 1077 | text_offset, |
a4c8fc23 | 1078 | (tab_y + tab_height)/2 - (texty/2) + 1); |
3f69756e | 1079 | |
702b1c7e | 1080 | |
a0c2e4a0 JS |
1081 | // draw focus rectangle |
1082 | if (page.active && (wnd->FindFocus() == wnd)) | |
1083 | { | |
1084 | wxRect focusRect(text_offset, ((tab_y + tab_height)/2 - (texty/2) + 1), | |
1085 | selected_textx, selected_texty); | |
1086 | ||
1087 | focusRect.Inflate(2, 2); | |
1088 | ||
1089 | wxRendererNative::Get().DrawFocusRect(wnd, dc, focusRect, 0); | |
1090 | } | |
1091 | ||
702b1c7e | 1092 | // draw close button if necessary |
41b76acd | 1093 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) |
702b1c7e BW |
1094 | { |
1095 | wxBitmap bmp; | |
793d4365 | 1096 | if (page.active) |
9a29fe70 | 1097 | bmp = m_activeCloseBmp; |
cedd7b22 | 1098 | else |
9a29fe70 | 1099 | bmp = m_disabledCloseBmp; |
7baac3cb | 1100 | |
0b3d6ff9 BW |
1101 | wxRect rect(tab_x + tab_width - close_button_width - 1, |
1102 | tab_y + (tab_height/2) - (bmp.GetHeight()/2) + 1, | |
1103 | close_button_width, | |
1104 | tab_height - 1); | |
b0d17f7c | 1105 | DrawButtons(dc, rect, bmp, *wxWHITE, close_button_state); |
7baac3cb | 1106 | |
41b76acd | 1107 | *out_button_rect = rect; |
702b1c7e BW |
1108 | } |
1109 | ||
1110 | ||
41b76acd | 1111 | *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height); |
7baac3cb | 1112 | |
b0d17f7c | 1113 | dc.DestroyClippingRegion(); |
3f69756e BW |
1114 | } |
1115 | ||
b0d17f7c BW |
1116 | int wxAuiSimpleTabArt::GetIndentSize() |
1117 | { | |
1118 | return 0; | |
1119 | } | |
3f69756e | 1120 | |
b0d17f7c BW |
1121 | wxSize wxAuiSimpleTabArt::GetTabSize(wxDC& dc, |
1122 | wxWindow* WXUNUSED(wnd), | |
1123 | const wxString& caption, | |
2b9aac33 | 1124 | const wxBitmap& WXUNUSED(bitmap), |
b0d17f7c BW |
1125 | bool WXUNUSED(active), |
1126 | int close_button_state, | |
1127 | int* x_extent) | |
4953f8cf BW |
1128 | { |
1129 | wxCoord measured_textx, measured_texty; | |
7baac3cb | 1130 | |
9a29fe70 | 1131 | dc.SetFont(m_measuringFont); |
a6b0e5bd | 1132 | dc.GetTextExtent(caption, &measured_textx, &measured_texty); |
7baac3cb | 1133 | |
4953f8cf BW |
1134 | wxCoord tab_height = measured_texty + 4; |
1135 | wxCoord tab_width = measured_textx + tab_height + 5; | |
1136 | ||
41b76acd | 1137 | if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN) |
9a29fe70 | 1138 | tab_width += m_activeCloseBmp.GetWidth(); |
7baac3cb | 1139 | |
b0d17f7c BW |
1140 | if (m_flags & wxAUI_NB_TAB_FIXED_WIDTH) |
1141 | { | |
9a29fe70 | 1142 | tab_width = m_fixedTabWidth; |
b0d17f7c | 1143 | } |
7baac3cb | 1144 | |
4953f8cf BW |
1145 | *x_extent = tab_width - (tab_height/2) - 1; |
1146 | ||
1147 | return wxSize(tab_width, tab_height); | |
1148 | } | |
1149 | ||
1150 | ||
b0d17f7c BW |
1151 | void wxAuiSimpleTabArt::DrawButton(wxDC& dc, |
1152 | wxWindow* WXUNUSED(wnd), | |
1153 | const wxRect& in_rect, | |
1154 | int bitmap_id, | |
1155 | int button_state, | |
1156 | int orientation, | |
b0d17f7c | 1157 | wxRect* out_rect) |
4953f8cf BW |
1158 | { |
1159 | wxBitmap bmp; | |
1160 | wxRect rect; | |
7baac3cb | 1161 | |
793d4365 | 1162 | switch (bitmap_id) |
4953f8cf | 1163 | { |
793d4365 BW |
1164 | case wxAUI_BUTTON_CLOSE: |
1165 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 1166 | bmp = m_disabledCloseBmp; |
cedd7b22 | 1167 | else |
9a29fe70 | 1168 | bmp = m_activeCloseBmp; |
793d4365 BW |
1169 | break; |
1170 | case wxAUI_BUTTON_LEFT: | |
1171 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 1172 | bmp = m_disabledLeftBmp; |
cedd7b22 | 1173 | else |
9a29fe70 | 1174 | bmp = m_activeLeftBmp; |
793d4365 BW |
1175 | break; |
1176 | case wxAUI_BUTTON_RIGHT: | |
1177 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 1178 | bmp = m_disabledRightBmp; |
cedd7b22 | 1179 | else |
9a29fe70 | 1180 | bmp = m_activeRightBmp; |
793d4365 BW |
1181 | break; |
1182 | case wxAUI_BUTTON_WINDOWLIST: | |
1183 | if (button_state & wxAUI_BUTTON_STATE_DISABLED) | |
9a29fe70 | 1184 | bmp = m_disabledWindowListBmp; |
cedd7b22 | 1185 | else |
9a29fe70 | 1186 | bmp = m_activeWindowListBmp; |
793d4365 | 1187 | break; |
4953f8cf BW |
1188 | } |
1189 | ||
1190 | if (!bmp.IsOk()) | |
1191 | return; | |
7baac3cb | 1192 | |
4953f8cf | 1193 | rect = in_rect; |
7baac3cb | 1194 | |
4953f8cf BW |
1195 | if (orientation == wxLEFT) |
1196 | { | |
25d7497c BW |
1197 | rect.SetX(in_rect.x); |
1198 | rect.SetY(((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2)); | |
4953f8cf BW |
1199 | rect.SetWidth(bmp.GetWidth()); |
1200 | rect.SetHeight(bmp.GetHeight()); | |
1201 | } | |
cedd7b22 | 1202 | else |
4953f8cf | 1203 | { |
25d7497c BW |
1204 | rect = wxRect(in_rect.x + in_rect.width - bmp.GetWidth(), |
1205 | ((in_rect.y + in_rect.height)/2) - (bmp.GetHeight()/2), | |
4953f8cf BW |
1206 | bmp.GetWidth(), bmp.GetHeight()); |
1207 | } | |
7baac3cb VZ |
1208 | |
1209 | ||
b0d17f7c | 1210 | DrawButtons(dc, rect, bmp, *wxWHITE, button_state); |
7baac3cb | 1211 | |
4953f8cf BW |
1212 | *out_rect = rect; |
1213 | } | |
1214 | ||
793d4365 BW |
1215 | int wxAuiSimpleTabArt::ShowDropDown(wxWindow* wnd, |
1216 | const wxAuiNotebookPageArray& pages, | |
1217 | int active_idx) | |
01372b8f | 1218 | { |
c58ba15f | 1219 | wxMenu menuPopup; |
01372b8f | 1220 | |
793d4365 | 1221 | size_t i, count = pages.GetCount(); |
01372b8f BW |
1222 | for (i = 0; i < count; ++i) |
1223 | { | |
793d4365 BW |
1224 | const wxAuiNotebookPage& page = pages.Item(i); |
1225 | menuPopup.AppendCheckItem(1000+i, page.caption); | |
01372b8f | 1226 | } |
7baac3cb | 1227 | |
01372b8f BW |
1228 | if (active_idx != -1) |
1229 | { | |
1230 | menuPopup.Check(1000+active_idx, true); | |
1231 | } | |
7baac3cb | 1232 | |
01372b8f BW |
1233 | // find out where to put the popup menu of window |
1234 | // items. Subtract 100 for now to center the menu | |
1235 | // a bit, until a better mechanism can be implemented | |
1236 | wxPoint pt = ::wxGetMousePosition(); | |
1237 | pt = wnd->ScreenToClient(pt); | |
1238 | if (pt.x < 100) | |
1239 | pt.x = 0; | |
cedd7b22 | 1240 | else |
01372b8f | 1241 | pt.x -= 100; |
7baac3cb | 1242 | |
01372b8f BW |
1243 | // find out the screen coordinate at the bottom of the tab ctrl |
1244 | wxRect cli_rect = wnd->GetClientRect(); | |
1245 | pt.y = cli_rect.y + cli_rect.height; | |
7baac3cb | 1246 | |
01372b8f BW |
1247 | wxAuiCommandCapture* cc = new wxAuiCommandCapture; |
1248 | wnd->PushEventHandler(cc); | |
1249 | wnd->PopupMenu(&menuPopup, pt); | |
1250 | int command = cc->GetCommandId(); | |
1251 | wnd->PopEventHandler(true); | |
7baac3cb | 1252 | |
01372b8f BW |
1253 | if (command >= 1000) |
1254 | return command-1000; | |
7baac3cb | 1255 | |
01372b8f BW |
1256 | return -1; |
1257 | } | |
1258 | ||
2b9aac33 | 1259 | int wxAuiSimpleTabArt::GetBestTabCtrlSize(wxWindow* wnd, |
793d4365 | 1260 | const wxAuiNotebookPageArray& WXUNUSED(pages), |
9a29fe70 | 1261 | const wxSize& WXUNUSED(requiredBmp_size)) |
a4c8fc23 BW |
1262 | { |
1263 | wxClientDC dc(wnd); | |
9a29fe70 | 1264 | dc.SetFont(m_measuringFont); |
a4c8fc23 | 1265 | int x_ext = 0; |
a6b0e5bd | 1266 | wxSize s = GetTabSize(dc, |
01372b8f BW |
1267 | wnd, |
1268 | wxT("ABCDEFGHIj"), | |
2b9aac33 | 1269 | wxNullBitmap, |
01372b8f BW |
1270 | true, |
1271 | wxAUI_BUTTON_STATE_HIDDEN, | |
1272 | &x_ext); | |
a4c8fc23 BW |
1273 | return s.y+3; |
1274 | } | |
4953f8cf | 1275 | |
b0d17f7c | 1276 | void wxAuiSimpleTabArt::SetNormalFont(const wxFont& font) |
3f69756e | 1277 | { |
9a29fe70 | 1278 | m_normalFont = font; |
3f69756e BW |
1279 | } |
1280 | ||
b0d17f7c | 1281 | void wxAuiSimpleTabArt::SetSelectedFont(const wxFont& font) |
3f69756e | 1282 | { |
9a29fe70 | 1283 | m_selectedFont = font; |
3f69756e BW |
1284 | } |
1285 | ||
b0d17f7c | 1286 | void wxAuiSimpleTabArt::SetMeasuringFont(const wxFont& font) |
3f69756e | 1287 | { |
9a29fe70 | 1288 | m_measuringFont = font; |
3f69756e BW |
1289 | } |
1290 | ||
1291 | ||
1292 | ||
1293 | ||
3f69756e BW |
1294 | // -- wxAuiTabContainer class implementation -- |
1295 | ||
1296 | ||
1297 | // wxAuiTabContainer is a class which contains information about each | |
1298 | // tab. It also can render an entire tab control to a specified DC. | |
1299 | // It's not a window class itself, because this code will be used by | |
1300 | // the wxFrameMananger, where it is disadvantageous to have separate | |
1301 | // windows for each tab control in the case of "docked tabs" | |
1302 | ||
1303 | // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window | |
1304 | // which can be used as a tab control in the normal sense. | |
1305 | ||
1306 | ||
1307 | wxAuiTabContainer::wxAuiTabContainer() | |
1308 | { | |
9a29fe70 | 1309 | m_tabOffset = 0; |
702b1c7e | 1310 | m_flags = 0; |
a3a5df9d | 1311 | m_art = new wxAuiDefaultTabArt; |
7baac3cb VZ |
1312 | |
1313 | AddButton(wxAUI_BUTTON_LEFT, wxLEFT); | |
01372b8f BW |
1314 | AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT); |
1315 | AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT); | |
4953f8cf | 1316 | AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT); |
3f69756e BW |
1317 | } |
1318 | ||
fe498448 BW |
1319 | wxAuiTabContainer::~wxAuiTabContainer() |
1320 | { | |
3f69756e BW |
1321 | delete m_art; |
1322 | } | |
1323 | ||
a3a5df9d | 1324 | void wxAuiTabContainer::SetArtProvider(wxAuiTabArt* art) |
3f69756e BW |
1325 | { |
1326 | delete m_art; | |
1327 | m_art = art; | |
7baac3cb | 1328 | |
b0d17f7c BW |
1329 | if (m_art) |
1330 | { | |
1331 | m_art->SetFlags(m_flags); | |
1332 | } | |
3f69756e BW |
1333 | } |
1334 | ||
e0dc13d4 | 1335 | wxAuiTabArt* wxAuiTabContainer::GetArtProvider() const |
3f69756e BW |
1336 | { |
1337 | return m_art; | |
fe498448 BW |
1338 | } |
1339 | ||
702b1c7e BW |
1340 | void wxAuiTabContainer::SetFlags(unsigned int flags) |
1341 | { | |
1342 | m_flags = flags; | |
7baac3cb | 1343 | |
41b76acd | 1344 | // check for new close button settings |
7baac3cb | 1345 | RemoveButton(wxAUI_BUTTON_LEFT); |
01372b8f BW |
1346 | RemoveButton(wxAUI_BUTTON_RIGHT); |
1347 | RemoveButton(wxAUI_BUTTON_WINDOWLIST); | |
41b76acd | 1348 | RemoveButton(wxAUI_BUTTON_CLOSE); |
7baac3cb VZ |
1349 | |
1350 | ||
01372b8f BW |
1351 | if (flags & wxAUI_NB_SCROLL_BUTTONS) |
1352 | { | |
7baac3cb | 1353 | AddButton(wxAUI_BUTTON_LEFT, wxLEFT); |
01372b8f BW |
1354 | AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT); |
1355 | } | |
1356 | ||
1357 | if (flags & wxAUI_NB_WINDOWLIST_BUTTON) | |
1358 | { | |
1359 | AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT); | |
1360 | } | |
7baac3cb | 1361 | |
41b76acd BW |
1362 | if (flags & wxAUI_NB_CLOSE_BUTTON) |
1363 | { | |
1364 | AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT); | |
1365 | } | |
7baac3cb | 1366 | |
b0d17f7c BW |
1367 | if (m_art) |
1368 | { | |
1369 | m_art->SetFlags(m_flags); | |
1370 | } | |
702b1c7e BW |
1371 | } |
1372 | ||
1373 | unsigned int wxAuiTabContainer::GetFlags() const | |
1374 | { | |
1375 | return m_flags; | |
1376 | } | |
1377 | ||
1378 | ||
cd05bf23 BW |
1379 | void wxAuiTabContainer::SetNormalFont(const wxFont& font) |
1380 | { | |
3f69756e | 1381 | m_art->SetNormalFont(font); |
cd05bf23 BW |
1382 | } |
1383 | ||
1384 | void wxAuiTabContainer::SetSelectedFont(const wxFont& font) | |
1385 | { | |
3f69756e | 1386 | m_art->SetSelectedFont(font); |
cd05bf23 BW |
1387 | } |
1388 | ||
1389 | void wxAuiTabContainer::SetMeasuringFont(const wxFont& font) | |
1390 | { | |
3f69756e | 1391 | m_art->SetMeasuringFont(font); |
cd05bf23 BW |
1392 | } |
1393 | ||
ceb9b8db VZ |
1394 | void wxAuiTabContainer::SetColour(const wxColour& colour) |
1395 | { | |
1396 | m_art->SetColour(colour); | |
1397 | } | |
1398 | ||
1399 | void wxAuiTabContainer::SetActiveColour(const wxColour& colour) | |
1400 | { | |
1401 | m_art->SetActiveColour(colour); | |
1402 | } | |
1403 | ||
cd05bf23 BW |
1404 | void wxAuiTabContainer::SetRect(const wxRect& rect) |
1405 | { | |
1406 | m_rect = rect; | |
7baac3cb | 1407 | |
b0d17f7c BW |
1408 | if (m_art) |
1409 | { | |
1410 | m_art->SetSizingInfo(rect.GetSize(), m_pages.GetCount()); | |
1411 | } | |
cd05bf23 BW |
1412 | } |
1413 | ||
1414 | bool wxAuiTabContainer::AddPage(wxWindow* page, | |
1415 | const wxAuiNotebookPage& info) | |
1416 | { | |
1417 | wxAuiNotebookPage page_info; | |
1418 | page_info = info; | |
1419 | page_info.window = page; | |
4444d148 | 1420 | |
cd05bf23 BW |
1421 | m_pages.Add(page_info); |
1422 | ||
b0d17f7c BW |
1423 | // let the art provider know how many pages we have |
1424 | if (m_art) | |
1425 | { | |
1426 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
1427 | } | |
7baac3cb | 1428 | |
cd05bf23 BW |
1429 | return true; |
1430 | } | |
1431 | ||
1432 | bool wxAuiTabContainer::InsertPage(wxWindow* page, | |
1433 | const wxAuiNotebookPage& info, | |
1434 | size_t idx) | |
1435 | { | |
1436 | wxAuiNotebookPage page_info; | |
1437 | page_info = info; | |
1438 | page_info.window = page; | |
4444d148 | 1439 | |
cd05bf23 BW |
1440 | if (idx >= m_pages.GetCount()) |
1441 | m_pages.Add(page_info); | |
cedd7b22 | 1442 | else |
cd05bf23 BW |
1443 | m_pages.Insert(page_info, idx); |
1444 | ||
b0d17f7c BW |
1445 | // let the art provider know how many pages we have |
1446 | if (m_art) | |
1447 | { | |
1448 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
1449 | } | |
7baac3cb | 1450 | |
cd05bf23 BW |
1451 | return true; |
1452 | } | |
1453 | ||
2fadbbfd BW |
1454 | bool wxAuiTabContainer::MovePage(wxWindow* page, |
1455 | size_t new_idx) | |
1456 | { | |
1457 | int idx = GetIdxFromWindow(page); | |
1458 | if (idx == -1) | |
1459 | return false; | |
7baac3cb | 1460 | |
2fadbbfd BW |
1461 | // get page entry, make a copy of it |
1462 | wxAuiNotebookPage p = GetPage(idx); | |
7baac3cb | 1463 | |
2fadbbfd BW |
1464 | // remove old page entry |
1465 | RemovePage(page); | |
7baac3cb | 1466 | |
2fadbbfd BW |
1467 | // insert page where it should be |
1468 | InsertPage(page, p, new_idx); | |
7baac3cb | 1469 | |
2fadbbfd BW |
1470 | return true; |
1471 | } | |
1472 | ||
cd05bf23 BW |
1473 | bool wxAuiTabContainer::RemovePage(wxWindow* wnd) |
1474 | { | |
1475 | size_t i, page_count = m_pages.GetCount(); | |
1476 | for (i = 0; i < page_count; ++i) | |
1477 | { | |
1478 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1479 | if (page.window == wnd) | |
1480 | { | |
1481 | m_pages.RemoveAt(i); | |
7baac3cb | 1482 | |
b0d17f7c BW |
1483 | // let the art provider know how many pages we have |
1484 | if (m_art) | |
1485 | { | |
1486 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
1487 | } | |
7baac3cb | 1488 | |
cd05bf23 BW |
1489 | return true; |
1490 | } | |
1491 | } | |
4444d148 | 1492 | |
cd05bf23 BW |
1493 | return false; |
1494 | } | |
1495 | ||
1496 | bool wxAuiTabContainer::SetActivePage(wxWindow* wnd) | |
1497 | { | |
1498 | bool found = false; | |
4444d148 | 1499 | |
cd05bf23 BW |
1500 | size_t i, page_count = m_pages.GetCount(); |
1501 | for (i = 0; i < page_count; ++i) | |
1502 | { | |
1503 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1504 | if (page.window == wnd) | |
1505 | { | |
1506 | page.active = true; | |
1507 | found = true; | |
1508 | } | |
cedd7b22 | 1509 | else |
cd05bf23 BW |
1510 | { |
1511 | page.active = false; | |
1512 | } | |
1513 | } | |
4444d148 | 1514 | |
cd05bf23 BW |
1515 | return found; |
1516 | } | |
1517 | ||
1518 | void wxAuiTabContainer::SetNoneActive() | |
1519 | { | |
1520 | size_t i, page_count = m_pages.GetCount(); | |
1521 | for (i = 0; i < page_count; ++i) | |
1522 | { | |
1523 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1524 | page.active = false; | |
1525 | } | |
1526 | } | |
1527 | ||
1528 | bool wxAuiTabContainer::SetActivePage(size_t page) | |
1529 | { | |
1530 | if (page >= m_pages.GetCount()) | |
1531 | return false; | |
4444d148 | 1532 | |
cd05bf23 BW |
1533 | return SetActivePage(m_pages.Item(page).window); |
1534 | } | |
4444d148 | 1535 | |
cd05bf23 BW |
1536 | int wxAuiTabContainer::GetActivePage() const |
1537 | { | |
1538 | size_t i, page_count = m_pages.GetCount(); | |
1539 | for (i = 0; i < page_count; ++i) | |
1540 | { | |
1541 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1542 | if (page.active) | |
1543 | return i; | |
1544 | } | |
4444d148 | 1545 | |
cd05bf23 BW |
1546 | return -1; |
1547 | } | |
1548 | ||
1549 | wxWindow* wxAuiTabContainer::GetWindowFromIdx(size_t idx) const | |
1550 | { | |
1551 | if (idx >= m_pages.GetCount()) | |
1552 | return NULL; | |
4444d148 | 1553 | |
cd05bf23 BW |
1554 | return m_pages[idx].window; |
1555 | } | |
1556 | ||
1557 | int wxAuiTabContainer::GetIdxFromWindow(wxWindow* wnd) const | |
1558 | { | |
849c353a VZ |
1559 | const size_t page_count = m_pages.GetCount(); |
1560 | for ( size_t i = 0; i < page_count; ++i ) | |
cd05bf23 BW |
1561 | { |
1562 | wxAuiNotebookPage& page = m_pages.Item(i); | |
1563 | if (page.window == wnd) | |
1564 | return i; | |
1565 | } | |
849c353a | 1566 | return wxNOT_FOUND; |
cd05bf23 BW |
1567 | } |
1568 | ||
1569 | wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx) | |
1570 | { | |
1571 | wxASSERT_MSG(idx < m_pages.GetCount(), wxT("Invalid Page index")); | |
1572 | ||
1573 | return m_pages[idx]; | |
1574 | } | |
1575 | ||
c3e016e4 JS |
1576 | const wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx) const |
1577 | { | |
1578 | wxASSERT_MSG(idx < m_pages.GetCount(), wxT("Invalid Page index")); | |
1579 | ||
1580 | return m_pages[idx]; | |
1581 | } | |
1582 | ||
cd05bf23 BW |
1583 | wxAuiNotebookPageArray& wxAuiTabContainer::GetPages() |
1584 | { | |
1585 | return m_pages; | |
1586 | } | |
1587 | ||
1588 | size_t wxAuiTabContainer::GetPageCount() const | |
1589 | { | |
1590 | return m_pages.GetCount(); | |
1591 | } | |
1592 | ||
4953f8cf BW |
1593 | void wxAuiTabContainer::AddButton(int id, |
1594 | int location, | |
9a29fe70 VZ |
1595 | const wxBitmap& normalBitmap, |
1596 | const wxBitmap& disabledBitmap) | |
cd05bf23 BW |
1597 | { |
1598 | wxAuiTabContainerButton button; | |
1599 | button.id = id; | |
9a29fe70 VZ |
1600 | button.bitmap = normalBitmap; |
1601 | button.disBitmap = disabledBitmap; | |
b6418695 | 1602 | button.location = location; |
9a29fe70 | 1603 | button.curState = wxAUI_BUTTON_STATE_NORMAL; |
4444d148 | 1604 | |
cd05bf23 BW |
1605 | m_buttons.Add(button); |
1606 | } | |
1607 | ||
41b76acd BW |
1608 | void wxAuiTabContainer::RemoveButton(int id) |
1609 | { | |
1610 | size_t i, button_count = m_buttons.GetCount(); | |
1611 | ||
1612 | for (i = 0; i < button_count; ++i) | |
1613 | { | |
1614 | if (m_buttons.Item(i).id == id) | |
1615 | { | |
1616 | m_buttons.RemoveAt(i); | |
1617 | return; | |
1618 | } | |
1619 | } | |
1620 | } | |
1621 | ||
1622 | ||
1623 | ||
4953f8cf BW |
1624 | size_t wxAuiTabContainer::GetTabOffset() const |
1625 | { | |
9a29fe70 | 1626 | return m_tabOffset; |
4953f8cf | 1627 | } |
cd05bf23 | 1628 | |
4953f8cf BW |
1629 | void wxAuiTabContainer::SetTabOffset(size_t offset) |
1630 | { | |
9a29fe70 | 1631 | m_tabOffset = offset; |
4953f8cf | 1632 | } |
cd05bf23 | 1633 | |
b0d17f7c BW |
1634 | |
1635 | ||
1636 | ||
cd05bf23 BW |
1637 | // Render() renders the tab catalog to the specified DC |
1638 | // It is a virtual function and can be overridden to | |
1639 | // provide custom drawing capabilities | |
01372b8f | 1640 | void wxAuiTabContainer::Render(wxDC* raw_dc, wxWindow* wnd) |
4444d148 | 1641 | { |
a9eeb510 BW |
1642 | if (!raw_dc || !raw_dc->IsOk()) |
1643 | return; | |
1644 | ||
cd05bf23 | 1645 | wxMemoryDC dc; |
ef329166 VZ |
1646 | |
1647 | // use the same layout direction as the window DC uses to ensure that the | |
1648 | // text is rendered correctly | |
1649 | dc.SetLayoutDirection(raw_dc->GetLayoutDirection()); | |
1650 | ||
cd05bf23 | 1651 | wxBitmap bmp; |
4953f8cf BW |
1652 | size_t i; |
1653 | size_t page_count = m_pages.GetCount(); | |
1654 | size_t button_count = m_buttons.GetCount(); | |
1655 | ||
1656 | // create off-screen bitmap | |
cd05bf23 BW |
1657 | bmp.Create(m_rect.GetWidth(), m_rect.GetHeight()); |
1658 | dc.SelectObject(bmp); | |
4444d148 | 1659 | |
a9eeb510 BW |
1660 | if (!dc.IsOk()) |
1661 | return; | |
4953f8cf BW |
1662 | |
1663 | // find out if size of tabs is larger than can be | |
1664 | // afforded on screen | |
1665 | int total_width = 0; | |
25d7497c | 1666 | int visible_width = 0; |
4953f8cf BW |
1667 | for (i = 0; i < page_count; ++i) |
1668 | { | |
1669 | wxAuiNotebookPage& page = m_pages.Item(i); | |
7baac3cb | 1670 | |
702b1c7e BW |
1671 | // determine if a close button is on this tab |
1672 | bool close_button = false; | |
1673 | if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 || | |
1674 | ((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active)) | |
1675 | { | |
1676 | close_button = true; | |
1677 | } | |
7baac3cb VZ |
1678 | |
1679 | ||
4953f8cf | 1680 | int x_extent = 0; |
a6b0e5bd | 1681 | wxSize size = m_art->GetTabSize(dc, |
01372b8f | 1682 | wnd, |
41b76acd | 1683 | page.caption, |
2b9aac33 | 1684 | page.bitmap, |
41b76acd BW |
1685 | page.active, |
1686 | close_button ? | |
1687 | wxAUI_BUTTON_STATE_NORMAL : | |
1688 | wxAUI_BUTTON_STATE_HIDDEN, | |
1689 | &x_extent); | |
7baac3cb | 1690 | |
4953f8cf BW |
1691 | if (i+1 < page_count) |
1692 | total_width += x_extent; | |
cedd7b22 | 1693 | else |
4953f8cf | 1694 | total_width += size.x; |
7baac3cb | 1695 | |
9a29fe70 | 1696 | if (i >= m_tabOffset) |
25d7497c BW |
1697 | { |
1698 | if (i+1 < page_count) | |
1699 | visible_width += x_extent; | |
cedd7b22 | 1700 | else |
25d7497c BW |
1701 | visible_width += size.x; |
1702 | } | |
4953f8cf | 1703 | } |
7baac3cb | 1704 | |
9a29fe70 | 1705 | if (total_width > m_rect.GetWidth() || m_tabOffset != 0) |
4953f8cf BW |
1706 | { |
1707 | // show left/right buttons | |
1708 | for (i = 0; i < button_count; ++i) | |
1709 | { | |
1710 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1711 | if (button.id == wxAUI_BUTTON_LEFT || | |
1712 | button.id == wxAUI_BUTTON_RIGHT) | |
1713 | { | |
9a29fe70 | 1714 | button.curState &= ~wxAUI_BUTTON_STATE_HIDDEN; |
4953f8cf BW |
1715 | } |
1716 | } | |
1717 | } | |
cedd7b22 | 1718 | else |
4953f8cf BW |
1719 | { |
1720 | // hide left/right buttons | |
1721 | for (i = 0; i < button_count; ++i) | |
1722 | { | |
1723 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1724 | if (button.id == wxAUI_BUTTON_LEFT || | |
1725 | button.id == wxAUI_BUTTON_RIGHT) | |
1726 | { | |
9a29fe70 | 1727 | button.curState |= wxAUI_BUTTON_STATE_HIDDEN; |
4953f8cf BW |
1728 | } |
1729 | } | |
1730 | } | |
1731 | ||
25d7497c BW |
1732 | // determine whether left button should be enabled |
1733 | for (i = 0; i < button_count; ++i) | |
1734 | { | |
1735 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1736 | if (button.id == wxAUI_BUTTON_LEFT) | |
1737 | { | |
9a29fe70 VZ |
1738 | if (m_tabOffset == 0) |
1739 | button.curState |= wxAUI_BUTTON_STATE_DISABLED; | |
cedd7b22 | 1740 | else |
9a29fe70 | 1741 | button.curState &= ~wxAUI_BUTTON_STATE_DISABLED; |
25d7497c BW |
1742 | } |
1743 | if (button.id == wxAUI_BUTTON_RIGHT) | |
1744 | { | |
1745 | if (visible_width < m_rect.GetWidth() - ((int)button_count*16)) | |
9a29fe70 | 1746 | button.curState |= wxAUI_BUTTON_STATE_DISABLED; |
cedd7b22 | 1747 | else |
9a29fe70 | 1748 | button.curState &= ~wxAUI_BUTTON_STATE_DISABLED; |
25d7497c BW |
1749 | } |
1750 | } | |
1751 | ||
4953f8cf BW |
1752 | |
1753 | ||
1754 | // draw background | |
a6b0e5bd | 1755 | m_art->DrawBackground(dc, wnd, m_rect); |
4444d148 | 1756 | |
4953f8cf BW |
1757 | // draw buttons |
1758 | int left_buttons_width = 0; | |
1759 | int right_buttons_width = 0; | |
7baac3cb | 1760 | |
cd05bf23 | 1761 | int offset = 0; |
b6418695 BW |
1762 | |
1763 | // draw the buttons on the right side | |
1764 | offset = m_rect.x + m_rect.width; | |
b6418695 BW |
1765 | for (i = 0; i < button_count; ++i) |
1766 | { | |
1767 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
7baac3cb | 1768 | |
b6418695 BW |
1769 | if (button.location != wxRIGHT) |
1770 | continue; | |
9a29fe70 | 1771 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
4953f8cf | 1772 | continue; |
7baac3cb | 1773 | |
4953f8cf BW |
1774 | wxRect button_rect = m_rect; |
1775 | button_rect.SetY(1); | |
1776 | button_rect.SetWidth(offset); | |
1777 | ||
a6b0e5bd | 1778 | m_art->DrawButton(dc, |
01372b8f | 1779 | wnd, |
4953f8cf BW |
1780 | button_rect, |
1781 | button.id, | |
9a29fe70 | 1782 | button.curState, |
4953f8cf | 1783 | wxRIGHT, |
4953f8cf BW |
1784 | &button.rect); |
1785 | ||
1786 | offset -= button.rect.GetWidth(); | |
1787 | right_buttons_width += button.rect.GetWidth(); | |
b6418695 BW |
1788 | } |
1789 | ||
1790 | ||
1791 | ||
1792 | offset = 0; | |
7baac3cb | 1793 | |
b6418695 BW |
1794 | // draw the buttons on the left side |
1795 | ||
1796 | for (i = 0; i < button_count; ++i) | |
1797 | { | |
1798 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
7baac3cb | 1799 | |
b6418695 BW |
1800 | if (button.location != wxLEFT) |
1801 | continue; | |
9a29fe70 | 1802 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
4953f8cf | 1803 | continue; |
7baac3cb | 1804 | |
4953f8cf BW |
1805 | wxRect button_rect(offset, 1, 1000, m_rect.height); |
1806 | ||
a6b0e5bd | 1807 | m_art->DrawButton(dc, |
01372b8f | 1808 | wnd, |
4953f8cf BW |
1809 | button_rect, |
1810 | button.id, | |
9a29fe70 | 1811 | button.curState, |
4953f8cf | 1812 | wxLEFT, |
4953f8cf | 1813 | &button.rect); |
7baac3cb | 1814 | |
4953f8cf BW |
1815 | offset += button.rect.GetWidth(); |
1816 | left_buttons_width += button.rect.GetWidth(); | |
b6418695 BW |
1817 | } |
1818 | ||
4953f8cf | 1819 | offset = left_buttons_width; |
7baac3cb | 1820 | |
b0d17f7c | 1821 | if (offset == 0) |
7baac3cb VZ |
1822 | offset += m_art->GetIndentSize(); |
1823 | ||
1824 | ||
41b76acd | 1825 | // prepare the tab-close-button array |
049333c2 | 1826 | // make sure tab button entries which aren't used are marked as hidden |
9a29fe70 VZ |
1827 | for (i = page_count; i < m_tabCloseButtons.GetCount(); ++i) |
1828 | m_tabCloseButtons.Item(i).curState = wxAUI_BUTTON_STATE_HIDDEN; | |
7baac3cb | 1829 | |
049333c2 | 1830 | // make sure there are enough tab button entries to accommodate all tabs |
9a29fe70 | 1831 | while (m_tabCloseButtons.GetCount() < page_count) |
41b76acd BW |
1832 | { |
1833 | wxAuiTabContainerButton tempbtn; | |
1834 | tempbtn.id = wxAUI_BUTTON_CLOSE; | |
1835 | tempbtn.location = wxCENTER; | |
9a29fe70 VZ |
1836 | tempbtn.curState = wxAUI_BUTTON_STATE_HIDDEN; |
1837 | m_tabCloseButtons.Add(tempbtn); | |
41b76acd | 1838 | } |
7baac3cb VZ |
1839 | |
1840 | ||
4abf84fb | 1841 | // buttons before the tab offset must be set to hidden |
9a29fe70 | 1842 | for (i = 0; i < m_tabOffset; ++i) |
41b76acd | 1843 | { |
9a29fe70 | 1844 | m_tabCloseButtons.Item(i).curState = wxAUI_BUTTON_STATE_HIDDEN; |
41b76acd | 1845 | } |
7baac3cb VZ |
1846 | |
1847 | ||
b6418695 | 1848 | // draw the tabs |
cd05bf23 BW |
1849 | |
1850 | size_t active = 999; | |
1851 | int active_offset = 0; | |
b0d17f7c | 1852 | wxRect active_rect; |
4444d148 | 1853 | |
cd05bf23 BW |
1854 | int x_extent = 0; |
1855 | wxRect rect = m_rect; | |
1856 | rect.y = 0; | |
cd05bf23 | 1857 | rect.height = m_rect.height; |
4444d148 | 1858 | |
9a29fe70 | 1859 | for (i = m_tabOffset; i < page_count; ++i) |
cd05bf23 BW |
1860 | { |
1861 | wxAuiNotebookPage& page = m_pages.Item(i); | |
9a29fe70 | 1862 | wxAuiTabContainerButton& tab_button = m_tabCloseButtons.Item(i); |
4444d148 | 1863 | |
702b1c7e | 1864 | // determine if a close button is on this tab |
702b1c7e BW |
1865 | if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 || |
1866 | ((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active)) | |
1867 | { | |
9a29fe70 | 1868 | if (tab_button.curState == wxAUI_BUTTON_STATE_HIDDEN) |
41b76acd BW |
1869 | { |
1870 | tab_button.id = wxAUI_BUTTON_CLOSE; | |
9a29fe70 | 1871 | tab_button.curState = wxAUI_BUTTON_STATE_NORMAL; |
41b76acd BW |
1872 | tab_button.location = wxCENTER; |
1873 | } | |
1874 | } | |
cedd7b22 | 1875 | else |
41b76acd | 1876 | { |
9a29fe70 | 1877 | tab_button.curState = wxAUI_BUTTON_STATE_HIDDEN; |
702b1c7e BW |
1878 | } |
1879 | ||
cd05bf23 | 1880 | rect.x = offset; |
b0d17f7c BW |
1881 | rect.width = m_rect.width - right_buttons_width - offset - 2; |
1882 | ||
47b6bebb BW |
1883 | if (rect.width <= 0) |
1884 | break; | |
1885 | ||
a6b0e5bd | 1886 | m_art->DrawTab(dc, |
01372b8f | 1887 | wnd, |
793d4365 | 1888 | page, |
01372b8f | 1889 | rect, |
9a29fe70 | 1890 | tab_button.curState, |
01372b8f BW |
1891 | &page.rect, |
1892 | &tab_button.rect, | |
1893 | &x_extent); | |
4444d148 | 1894 | |
cd05bf23 BW |
1895 | if (page.active) |
1896 | { | |
1897 | active = i; | |
1898 | active_offset = offset; | |
b0d17f7c | 1899 | active_rect = rect; |
cd05bf23 | 1900 | } |
7baac3cb | 1901 | |
cd05bf23 BW |
1902 | offset += x_extent; |
1903 | } | |
4444d148 | 1904 | |
4abf84fb BW |
1905 | |
1906 | // make sure to deactivate buttons which are off the screen to the right | |
9a29fe70 | 1907 | for (++i; i < m_tabCloseButtons.GetCount(); ++i) |
4abf84fb | 1908 | { |
9a29fe70 | 1909 | m_tabCloseButtons.Item(i).curState = wxAUI_BUTTON_STATE_HIDDEN; |
4abf84fb BW |
1910 | } |
1911 | ||
1912 | ||
cd05bf23 | 1913 | // draw the active tab again so it stands in the foreground |
9a29fe70 | 1914 | if (active >= m_tabOffset && active < m_pages.GetCount()) |
cd05bf23 BW |
1915 | { |
1916 | wxAuiNotebookPage& page = m_pages.Item(active); | |
1917 | ||
9a29fe70 | 1918 | wxAuiTabContainerButton& tab_button = m_tabCloseButtons.Item(active); |
41b76acd | 1919 | |
cd05bf23 | 1920 | rect.x = active_offset; |
a6b0e5bd | 1921 | m_art->DrawTab(dc, |
01372b8f | 1922 | wnd, |
793d4365 | 1923 | page, |
b0d17f7c | 1924 | active_rect, |
9a29fe70 | 1925 | tab_button.curState, |
01372b8f BW |
1926 | &page.rect, |
1927 | &tab_button.rect, | |
1928 | &x_extent); | |
cd05bf23 | 1929 | } |
4444d148 | 1930 | |
7baac3cb | 1931 | |
4953f8cf BW |
1932 | raw_dc->Blit(m_rect.x, m_rect.y, |
1933 | m_rect.GetWidth(), m_rect.GetHeight(), | |
1934 | &dc, 0, 0); | |
cd05bf23 BW |
1935 | } |
1936 | ||
a0c2e4a0 | 1937 | // Is the tab visible? |
0b3b8742 | 1938 | bool wxAuiTabContainer::IsTabVisible(int tabPage, int tabOffset, wxDC* dc, wxWindow* wnd) |
a0c2e4a0 JS |
1939 | { |
1940 | if (!dc || !dc->IsOk()) | |
1941 | return false; | |
1942 | ||
1943 | size_t i; | |
1944 | size_t page_count = m_pages.GetCount(); | |
1945 | size_t button_count = m_buttons.GetCount(); | |
1946 | ||
1947 | // Hasn't been rendered yet; assume it's visible | |
9a29fe70 | 1948 | if (m_tabCloseButtons.GetCount() < page_count) |
a0c2e4a0 JS |
1949 | return true; |
1950 | ||
1951 | // First check if both buttons are disabled - if so, there's no need to | |
1952 | // check further for visibility. | |
1953 | int arrowButtonVisibleCount = 0; | |
1954 | for (i = 0; i < button_count; ++i) | |
1955 | { | |
1956 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
1957 | if (button.id == wxAUI_BUTTON_LEFT || | |
1958 | button.id == wxAUI_BUTTON_RIGHT) | |
1959 | { | |
9a29fe70 | 1960 | if ((button.curState & wxAUI_BUTTON_STATE_HIDDEN) == 0) |
a0c2e4a0 JS |
1961 | arrowButtonVisibleCount ++; |
1962 | } | |
1963 | } | |
1964 | ||
1965 | // Tab must be visible | |
1966 | if (arrowButtonVisibleCount == 0) | |
1967 | return true; | |
1968 | ||
1969 | // If tab is less than the given offset, it must be invisible by definition | |
1970 | if (tabPage < tabOffset) | |
1971 | return false; | |
1972 | ||
1973 | // draw buttons | |
1974 | int left_buttons_width = 0; | |
1975 | int right_buttons_width = 0; | |
1976 | ||
1977 | int offset = 0; | |
1978 | ||
1979 | // calculate size of the buttons on the right side | |
1980 | offset = m_rect.x + m_rect.width; | |
1981 | for (i = 0; i < button_count; ++i) | |
1982 | { | |
1983 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
1984 | ||
1985 | if (button.location != wxRIGHT) | |
1986 | continue; | |
9a29fe70 | 1987 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
a0c2e4a0 JS |
1988 | continue; |
1989 | ||
1990 | offset -= button.rect.GetWidth(); | |
1991 | right_buttons_width += button.rect.GetWidth(); | |
1992 | } | |
1993 | ||
1994 | offset = 0; | |
1995 | ||
1996 | // calculate size of the buttons on the left side | |
1997 | for (i = 0; i < button_count; ++i) | |
1998 | { | |
1999 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
2000 | ||
2001 | if (button.location != wxLEFT) | |
2002 | continue; | |
9a29fe70 | 2003 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
a0c2e4a0 JS |
2004 | continue; |
2005 | ||
2006 | offset += button.rect.GetWidth(); | |
2007 | left_buttons_width += button.rect.GetWidth(); | |
2008 | } | |
2009 | ||
2010 | offset = left_buttons_width; | |
2011 | ||
2012 | if (offset == 0) | |
2013 | offset += m_art->GetIndentSize(); | |
2014 | ||
2015 | wxRect active_rect; | |
2016 | ||
2017 | wxRect rect = m_rect; | |
2018 | rect.y = 0; | |
2019 | rect.height = m_rect.height; | |
2020 | ||
2021 | // See if the given page is visible at the given tab offset (effectively scroll position) | |
2022 | for (i = tabOffset; i < page_count; ++i) | |
2023 | { | |
0b3b8742 PC |
2024 | wxAuiNotebookPage& page = m_pages.Item(i); |
2025 | wxAuiTabContainerButton& tab_button = m_tabCloseButtons.Item(i); | |
2026 | ||
a0c2e4a0 JS |
2027 | rect.x = offset; |
2028 | rect.width = m_rect.width - right_buttons_width - offset - 2; | |
2029 | ||
2030 | if (rect.width <= 0) | |
2031 | return false; // haven't found the tab, and we've run out of space, so return false | |
2032 | ||
2033 | int x_extent = 0; | |
0b3b8742 PC |
2034 | m_art->GetTabSize(*dc, |
2035 | wnd, | |
2036 | page.caption, | |
2037 | page.bitmap, | |
2038 | page.active, | |
2039 | tab_button.curState, | |
2040 | &x_extent); | |
2041 | ||
a0c2e4a0 JS |
2042 | offset += x_extent; |
2043 | ||
2044 | if (i == (size_t) tabPage) | |
2045 | { | |
2046 | // If not all of the tab is visible, and supposing there's space to display it all, | |
2047 | // we could do better so we return false. | |
2048 | if (((m_rect.width - right_buttons_width - offset - 2) <= 0) && ((m_rect.width - right_buttons_width - left_buttons_width) > x_extent)) | |
2049 | return false; | |
2050 | else | |
2051 | return true; | |
2052 | } | |
2053 | } | |
2054 | ||
2055 | // Shouldn't really get here, but if it does, assume the tab is visible to prevent | |
2056 | // further looping in calling code. | |
2057 | return true; | |
2058 | } | |
2059 | ||
2060 | // Make the tab visible if it wasn't already | |
2061 | void wxAuiTabContainer::MakeTabVisible(int tabPage, wxWindow* win) | |
2062 | { | |
2063 | wxClientDC dc(win); | |
2064 | if (!IsTabVisible(tabPage, GetTabOffset(), & dc, win)) | |
2065 | { | |
2066 | int i; | |
2067 | for (i = 0; i < (int) m_pages.GetCount(); i++) | |
2068 | { | |
2069 | if (IsTabVisible(tabPage, i, & dc, win)) | |
2070 | { | |
2071 | SetTabOffset(i); | |
2072 | win->Refresh(); | |
2073 | return; | |
2074 | } | |
2075 | } | |
2076 | } | |
2077 | } | |
cd05bf23 BW |
2078 | |
2079 | // TabHitTest() tests if a tab was hit, passing the window pointer | |
2080 | // back if that condition was fulfilled. The function returns | |
2081 | // true if a tab was hit, otherwise false | |
2082 | bool wxAuiTabContainer::TabHitTest(int x, int y, wxWindow** hit) const | |
2083 | { | |
22a35096 | 2084 | if (!m_rect.Contains(x,y)) |
cd05bf23 | 2085 | return false; |
7baac3cb | 2086 | |
41b76acd | 2087 | wxAuiTabContainerButton* btn = NULL; |
9a29fe70 | 2088 | if (ButtonHitTest(x, y, &btn) && !(btn->curState & wxAUI_BUTTON_STATE_DISABLED)) |
41b76acd BW |
2089 | { |
2090 | if (m_buttons.Index(*btn) != wxNOT_FOUND) | |
2091 | return false; | |
2092 | } | |
4444d148 | 2093 | |
cd05bf23 | 2094 | size_t i, page_count = m_pages.GetCount(); |
4444d148 | 2095 | |
9a29fe70 | 2096 | for (i = m_tabOffset; i < page_count; ++i) |
cd05bf23 BW |
2097 | { |
2098 | wxAuiNotebookPage& page = m_pages.Item(i); | |
22a35096 | 2099 | if (page.rect.Contains(x,y)) |
cd05bf23 | 2100 | { |
4953f8cf BW |
2101 | if (hit) |
2102 | *hit = page.window; | |
cd05bf23 BW |
2103 | return true; |
2104 | } | |
2105 | } | |
4444d148 | 2106 | |
cd05bf23 BW |
2107 | return false; |
2108 | } | |
2109 | ||
2110 | // ButtonHitTest() tests if a button was hit. The function returns | |
2111 | // true if a button was hit, otherwise false | |
2112 | bool wxAuiTabContainer::ButtonHitTest(int x, int y, | |
2113 | wxAuiTabContainerButton** hit) const | |
2114 | { | |
22a35096 | 2115 | if (!m_rect.Contains(x,y)) |
cd05bf23 | 2116 | return false; |
4444d148 | 2117 | |
41b76acd | 2118 | size_t i, button_count; |
7baac3cb VZ |
2119 | |
2120 | ||
41b76acd | 2121 | button_count = m_buttons.GetCount(); |
cd05bf23 BW |
2122 | for (i = 0; i < button_count; ++i) |
2123 | { | |
2124 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
9b405ab3 | 2125 | if (button.rect.Contains(x,y) && |
9a29fe70 | 2126 | !(button.curState & wxAUI_BUTTON_STATE_HIDDEN )) |
cd05bf23 | 2127 | { |
4953f8cf BW |
2128 | if (hit) |
2129 | *hit = &button; | |
cd05bf23 BW |
2130 | return true; |
2131 | } | |
2132 | } | |
7baac3cb | 2133 | |
9a29fe70 | 2134 | button_count = m_tabCloseButtons.GetCount(); |
41b76acd BW |
2135 | for (i = 0; i < button_count; ++i) |
2136 | { | |
9a29fe70 | 2137 | wxAuiTabContainerButton& button = m_tabCloseButtons.Item(i); |
9b405ab3 | 2138 | if (button.rect.Contains(x,y) && |
9a29fe70 | 2139 | !(button.curState & (wxAUI_BUTTON_STATE_HIDDEN | |
9b405ab3 | 2140 | wxAUI_BUTTON_STATE_DISABLED))) |
41b76acd BW |
2141 | { |
2142 | if (hit) | |
2143 | *hit = &button; | |
2144 | return true; | |
2145 | } | |
2146 | } | |
7baac3cb | 2147 | |
cd05bf23 BW |
2148 | return false; |
2149 | } | |
2150 | ||
2151 | ||
2152 | ||
2153 | // the utility function ShowWnd() is the same as show, | |
a3a5df9d | 2154 | // except it handles wxAuiMDIChildFrame windows as well, |
cd05bf23 BW |
2155 | // as the Show() method on this class is "unplugged" |
2156 | static void ShowWnd(wxWindow* wnd, bool show) | |
2157 | { | |
89272c55 | 2158 | #if wxUSE_MDI |
a3a5df9d | 2159 | if (wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) |
cd05bf23 | 2160 | { |
a3a5df9d | 2161 | wxAuiMDIChildFrame* cf = (wxAuiMDIChildFrame*)wnd; |
cd05bf23 BW |
2162 | cf->DoShow(show); |
2163 | } | |
cedd7b22 | 2164 | else |
89272c55 | 2165 | #endif |
cd05bf23 BW |
2166 | { |
2167 | wnd->Show(show); | |
2168 | } | |
2169 | } | |
2170 | ||
2171 | ||
2172 | // DoShowHide() this function shows the active window, then | |
2173 | // hides all of the other windows (in that order) | |
2174 | void wxAuiTabContainer::DoShowHide() | |
2175 | { | |
2176 | wxAuiNotebookPageArray& pages = GetPages(); | |
2177 | size_t i, page_count = pages.GetCount(); | |
2178 | ||
2179 | // show new active page first | |
2180 | for (i = 0; i < page_count; ++i) | |
2181 | { | |
2182 | wxAuiNotebookPage& page = pages.Item(i); | |
2183 | if (page.active) | |
2184 | { | |
2185 | ShowWnd(page.window, true); | |
2186 | break; | |
2187 | } | |
2188 | } | |
2189 | ||
2190 | // hide all other pages | |
2191 | for (i = 0; i < page_count; ++i) | |
2192 | { | |
2193 | wxAuiNotebookPage& page = pages.Item(i); | |
badcaaaf BW |
2194 | if (!page.active) |
2195 | ShowWnd(page.window, false); | |
cd05bf23 BW |
2196 | } |
2197 | } | |
2198 | ||
2199 | ||
2200 | ||
2201 | ||
2202 | ||
2203 | ||
2204 | // -- wxAuiTabCtrl class implementation -- | |
2205 | ||
2206 | ||
cd05bf23 BW |
2207 | |
2208 | BEGIN_EVENT_TABLE(wxAuiTabCtrl, wxControl) | |
2209 | EVT_PAINT(wxAuiTabCtrl::OnPaint) | |
2210 | EVT_ERASE_BACKGROUND(wxAuiTabCtrl::OnEraseBackground) | |
2211 | EVT_SIZE(wxAuiTabCtrl::OnSize) | |
2212 | EVT_LEFT_DOWN(wxAuiTabCtrl::OnLeftDown) | |
198be845 | 2213 | EVT_LEFT_DCLICK(wxAuiTabCtrl::OnLeftDClick) |
cd05bf23 | 2214 | EVT_LEFT_UP(wxAuiTabCtrl::OnLeftUp) |
69f5e420 BW |
2215 | EVT_MIDDLE_DOWN(wxAuiTabCtrl::OnMiddleDown) |
2216 | EVT_MIDDLE_UP(wxAuiTabCtrl::OnMiddleUp) | |
2217 | EVT_RIGHT_DOWN(wxAuiTabCtrl::OnRightDown) | |
2218 | EVT_RIGHT_UP(wxAuiTabCtrl::OnRightUp) | |
cd05bf23 BW |
2219 | EVT_MOTION(wxAuiTabCtrl::OnMotion) |
2220 | EVT_LEAVE_WINDOW(wxAuiTabCtrl::OnLeaveWindow) | |
c58ba15f | 2221 | EVT_AUINOTEBOOK_BUTTON(wxID_ANY, wxAuiTabCtrl::OnButton) |
a0c2e4a0 JS |
2222 | EVT_SET_FOCUS(wxAuiTabCtrl::OnSetFocus) |
2223 | EVT_KILL_FOCUS(wxAuiTabCtrl::OnKillFocus) | |
2224 | EVT_CHAR(wxAuiTabCtrl::OnChar) | |
45ca0e77 | 2225 | EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost) |
cd05bf23 BW |
2226 | END_EVENT_TABLE() |
2227 | ||
2228 | ||
2229 | wxAuiTabCtrl::wxAuiTabCtrl(wxWindow* parent, | |
2230 | wxWindowID id, | |
2231 | const wxPoint& pos, | |
2232 | const wxSize& size, | |
4444d148 | 2233 | long style) : wxControl(parent, id, pos, size, style) |
cd05bf23 | 2234 | { |
c7bfb76a | 2235 | SetName(wxT("wxAuiTabCtrl")); |
9a29fe70 VZ |
2236 | m_clickPt = wxDefaultPosition; |
2237 | m_isDragging = false; | |
2238 | m_hoverButton = NULL; | |
2239 | m_pressedButton = NULL; | |
cd05bf23 BW |
2240 | } |
2241 | ||
26da5e4f BW |
2242 | wxAuiTabCtrl::~wxAuiTabCtrl() |
2243 | { | |
2244 | } | |
cd05bf23 BW |
2245 | |
2246 | void wxAuiTabCtrl::OnPaint(wxPaintEvent&) | |
2247 | { | |
2248 | wxPaintDC dc(this); | |
4444d148 | 2249 | |
cd05bf23 | 2250 | dc.SetFont(GetFont()); |
4444d148 | 2251 | |
cd05bf23 | 2252 | if (GetPageCount() > 0) |
01372b8f | 2253 | Render(&dc, this); |
cd05bf23 BW |
2254 | } |
2255 | ||
2256 | void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) | |
2257 | { | |
2258 | } | |
2259 | ||
2260 | void wxAuiTabCtrl::OnSize(wxSizeEvent& evt) | |
2261 | { | |
2262 | wxSize s = evt.GetSize(); | |
2263 | wxRect r(0, 0, s.GetWidth(), s.GetHeight()); | |
2264 | SetRect(r); | |
2265 | } | |
2266 | ||
2267 | void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt) | |
2268 | { | |
2269 | CaptureMouse(); | |
9a29fe70 VZ |
2270 | m_clickPt = wxDefaultPosition; |
2271 | m_isDragging = false; | |
2272 | m_clickTab = NULL; | |
2273 | m_pressedButton = NULL; | |
4444d148 | 2274 | |
760d3542 | 2275 | |
cd05bf23 BW |
2276 | wxWindow* wnd; |
2277 | if (TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
9b405ab3 | 2278 | { |
049333c2 | 2279 | int new_selection = GetIdxFromWindow(wnd); |
7baac3cb | 2280 | |
68fd4f2c BW |
2281 | // wxAuiNotebooks always want to receive this event |
2282 | // even if the tab is already active, because they may | |
2283 | // have multiple tab controls | |
2284 | if (new_selection != GetActivePage() || | |
2285 | GetParent()->IsKindOf(CLASSINFO(wxAuiNotebook))) | |
049333c2 BW |
2286 | { |
2287 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
2288 | e.SetSelection(new_selection); | |
2289 | e.SetOldSelection(GetActivePage()); | |
2290 | e.SetEventObject(this); | |
2291 | GetEventHandler()->ProcessEvent(e); | |
2292 | } | |
4444d148 | 2293 | |
9a29fe70 VZ |
2294 | m_clickPt.x = evt.m_x; |
2295 | m_clickPt.y = evt.m_y; | |
2296 | m_clickTab = wnd; | |
cd05bf23 | 2297 | } |
7baac3cb | 2298 | |
9a29fe70 | 2299 | if (m_hoverButton) |
cd05bf23 | 2300 | { |
9a29fe70 VZ |
2301 | m_pressedButton = m_hoverButton; |
2302 | m_pressedButton->curState = wxAUI_BUTTON_STATE_PRESSED; | |
cd05bf23 BW |
2303 | Refresh(); |
2304 | Update(); | |
2305 | } | |
2306 | } | |
2307 | ||
45ca0e77 BW |
2308 | void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) |
2309 | { | |
9a29fe70 | 2310 | if (m_isDragging) |
2bd82d72 | 2311 | { |
9a29fe70 | 2312 | m_isDragging = false; |
2bd82d72 VZ |
2313 | |
2314 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, m_windowId); | |
9a29fe70 | 2315 | evt.SetSelection(GetIdxFromWindow(m_clickTab)); |
2bd82d72 VZ |
2316 | evt.SetOldSelection(evt.GetSelection()); |
2317 | evt.SetEventObject(this); | |
2318 | GetEventHandler()->ProcessEvent(evt); | |
2319 | } | |
45ca0e77 BW |
2320 | } |
2321 | ||
9b3f654a | 2322 | void wxAuiTabCtrl::OnLeftUp(wxMouseEvent& evt) |
cd05bf23 BW |
2323 | { |
2324 | if (GetCapture() == this) | |
2325 | ReleaseMouse(); | |
4444d148 | 2326 | |
9a29fe70 | 2327 | if (m_isDragging) |
cd05bf23 | 2328 | { |
9a29fe70 | 2329 | m_isDragging = false; |
cedd7b22 | 2330 | |
cd05bf23 | 2331 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, m_windowId); |
9a29fe70 | 2332 | evt.SetSelection(GetIdxFromWindow(m_clickTab)); |
08c068a4 | 2333 | evt.SetOldSelection(evt.GetSelection()); |
cd05bf23 BW |
2334 | evt.SetEventObject(this); |
2335 | GetEventHandler()->ProcessEvent(evt); | |
cedd7b22 | 2336 | |
cd05bf23 BW |
2337 | return; |
2338 | } | |
4444d148 | 2339 | |
9a29fe70 | 2340 | if (m_pressedButton) |
cd05bf23 | 2341 | { |
9b3f654a BW |
2342 | // make sure we're still clicking the button |
2343 | wxAuiTabContainerButton* button = NULL; | |
65052c6f | 2344 | if (!ButtonHitTest(evt.m_x, evt.m_y, &button) || |
9a29fe70 | 2345 | button->curState & wxAUI_BUTTON_STATE_DISABLED) |
9b3f654a | 2346 | return; |
7baac3cb | 2347 | |
9a29fe70 | 2348 | if (button != m_pressedButton) |
9b3f654a | 2349 | { |
9a29fe70 | 2350 | m_pressedButton = NULL; |
9b3f654a BW |
2351 | return; |
2352 | } | |
2353 | ||
cd05bf23 BW |
2354 | Refresh(); |
2355 | Update(); | |
4444d148 | 2356 | |
9a29fe70 | 2357 | if (!(m_pressedButton->curState & wxAUI_BUTTON_STATE_DISABLED)) |
25d7497c BW |
2358 | { |
2359 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, m_windowId); | |
9a29fe70 VZ |
2360 | evt.SetSelection(GetIdxFromWindow(m_clickTab)); |
2361 | evt.SetInt(m_pressedButton->id); | |
25d7497c BW |
2362 | evt.SetEventObject(this); |
2363 | GetEventHandler()->ProcessEvent(evt); | |
2364 | } | |
7baac3cb | 2365 | |
9a29fe70 | 2366 | m_pressedButton = NULL; |
cd05bf23 | 2367 | } |
4444d148 | 2368 | |
9a29fe70 VZ |
2369 | m_clickPt = wxDefaultPosition; |
2370 | m_isDragging = false; | |
2371 | m_clickTab = NULL; | |
cd05bf23 BW |
2372 | } |
2373 | ||
69f5e420 BW |
2374 | void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent& evt) |
2375 | { | |
2376 | wxWindow* wnd = NULL; | |
2377 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2378 | return; | |
2379 | ||
2380 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, m_windowId); | |
2381 | e.SetEventObject(this); | |
2382 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2383 | GetEventHandler()->ProcessEvent(e); | |
2384 | } | |
2385 | ||
2386 | void wxAuiTabCtrl::OnMiddleDown(wxMouseEvent& evt) | |
2387 | { | |
2388 | wxWindow* wnd = NULL; | |
2389 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2390 | return; | |
2391 | ||
2392 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, m_windowId); | |
2393 | e.SetEventObject(this); | |
2394 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2395 | GetEventHandler()->ProcessEvent(e); | |
2396 | } | |
2397 | ||
2398 | void wxAuiTabCtrl::OnRightUp(wxMouseEvent& evt) | |
2399 | { | |
2400 | wxWindow* wnd = NULL; | |
2401 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2402 | return; | |
2403 | ||
2404 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, m_windowId); | |
2405 | e.SetEventObject(this); | |
2406 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2407 | GetEventHandler()->ProcessEvent(e); | |
2408 | } | |
2409 | ||
2410 | void wxAuiTabCtrl::OnRightDown(wxMouseEvent& evt) | |
2411 | { | |
2412 | wxWindow* wnd = NULL; | |
2413 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
2414 | return; | |
2415 | ||
2416 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, m_windowId); | |
2417 | e.SetEventObject(this); | |
2418 | e.SetSelection(GetIdxFromWindow(wnd)); | |
2419 | GetEventHandler()->ProcessEvent(e); | |
2420 | } | |
2421 | ||
198be845 JS |
2422 | void wxAuiTabCtrl::OnLeftDClick(wxMouseEvent& evt) |
2423 | { | |
2424 | wxWindow* wnd; | |
2425 | wxAuiTabContainerButton* button; | |
2426 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd) && !ButtonHitTest(evt.m_x, evt.m_y, &button)) | |
2427 | { | |
2428 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, m_windowId); | |
2429 | e.SetEventObject(this); | |
2430 | GetEventHandler()->ProcessEvent(e); | |
2431 | } | |
2432 | } | |
2433 | ||
cd05bf23 BW |
2434 | void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) |
2435 | { | |
2436 | wxPoint pos = evt.GetPosition(); | |
2437 | ||
2438 | // check if the mouse is hovering above a button | |
2439 | wxAuiTabContainerButton* button; | |
9a29fe70 | 2440 | if (ButtonHitTest(pos.x, pos.y, &button) && !(button->curState & wxAUI_BUTTON_STATE_DISABLED)) |
cd05bf23 | 2441 | { |
9a29fe70 | 2442 | if (m_hoverButton && button != m_hoverButton) |
b6418695 | 2443 | { |
9a29fe70 VZ |
2444 | m_hoverButton->curState = wxAUI_BUTTON_STATE_NORMAL; |
2445 | m_hoverButton = NULL; | |
b6418695 BW |
2446 | Refresh(); |
2447 | Update(); | |
2448 | } | |
7baac3cb | 2449 | |
9a29fe70 | 2450 | if (button->curState != wxAUI_BUTTON_STATE_HOVER) |
cd05bf23 | 2451 | { |
9a29fe70 | 2452 | button->curState = wxAUI_BUTTON_STATE_HOVER; |
cd05bf23 BW |
2453 | Refresh(); |
2454 | Update(); | |
8c7fb508 | 2455 | |
9a29fe70 | 2456 | m_hoverButton = button; |
cd05bf23 BW |
2457 | return; |
2458 | } | |
2459 | } | |
cedd7b22 | 2460 | else |
cd05bf23 | 2461 | { |
9a29fe70 | 2462 | if (m_hoverButton) |
cd05bf23 | 2463 | { |
9a29fe70 VZ |
2464 | m_hoverButton->curState = wxAUI_BUTTON_STATE_NORMAL; |
2465 | m_hoverButton = NULL; | |
cd05bf23 BW |
2466 | Refresh(); |
2467 | Update(); | |
2468 | } | |
2469 | } | |
4444d148 WS |
2470 | |
2471 | ||
9a29fe70 | 2472 | if (!evt.LeftIsDown() || m_clickPt == wxDefaultPosition) |
cd05bf23 | 2473 | return; |
4444d148 | 2474 | |
9a29fe70 | 2475 | if (m_isDragging) |
cd05bf23 BW |
2476 | { |
2477 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, m_windowId); | |
9a29fe70 | 2478 | evt.SetSelection(GetIdxFromWindow(m_clickTab)); |
08c068a4 | 2479 | evt.SetOldSelection(evt.GetSelection()); |
cd05bf23 BW |
2480 | evt.SetEventObject(this); |
2481 | GetEventHandler()->ProcessEvent(evt); | |
2482 | return; | |
4444d148 WS |
2483 | } |
2484 | ||
2485 | ||
cd05bf23 BW |
2486 | int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X); |
2487 | int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y); | |
2488 | ||
9a29fe70 VZ |
2489 | if (abs(pos.x - m_clickPt.x) > drag_x_threshold || |
2490 | abs(pos.y - m_clickPt.y) > drag_y_threshold) | |
cd05bf23 BW |
2491 | { |
2492 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, m_windowId); | |
9a29fe70 | 2493 | evt.SetSelection(GetIdxFromWindow(m_clickTab)); |
08c068a4 | 2494 | evt.SetOldSelection(evt.GetSelection()); |
cd05bf23 BW |
2495 | evt.SetEventObject(this); |
2496 | GetEventHandler()->ProcessEvent(evt); | |
4444d148 | 2497 | |
9a29fe70 | 2498 | m_isDragging = true; |
cd05bf23 BW |
2499 | } |
2500 | } | |
2501 | ||
2502 | void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent& WXUNUSED(event)) | |
2503 | { | |
9a29fe70 | 2504 | if (m_hoverButton) |
cd05bf23 | 2505 | { |
9a29fe70 VZ |
2506 | m_hoverButton->curState = wxAUI_BUTTON_STATE_NORMAL; |
2507 | m_hoverButton = NULL; | |
cd05bf23 BW |
2508 | Refresh(); |
2509 | Update(); | |
2510 | } | |
2511 | } | |
2512 | ||
4953f8cf BW |
2513 | void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event) |
2514 | { | |
2515 | int button = event.GetInt(); | |
7baac3cb | 2516 | |
4953f8cf BW |
2517 | if (button == wxAUI_BUTTON_LEFT || button == wxAUI_BUTTON_RIGHT) |
2518 | { | |
2519 | if (button == wxAUI_BUTTON_LEFT) | |
2520 | { | |
2521 | if (GetTabOffset() > 0) | |
2522 | { | |
2523 | SetTabOffset(GetTabOffset()-1); | |
2524 | Refresh(); | |
2525 | Update(); | |
2526 | } | |
2527 | } | |
cedd7b22 | 2528 | else |
4953f8cf BW |
2529 | { |
2530 | SetTabOffset(GetTabOffset()+1); | |
2531 | Refresh(); | |
2532 | Update(); | |
2533 | } | |
01372b8f | 2534 | } |
cedd7b22 | 2535 | else if (button == wxAUI_BUTTON_WINDOWLIST) |
01372b8f | 2536 | { |
793d4365 | 2537 | int idx = GetArtProvider()->ShowDropDown(this, m_pages, GetActivePage()); |
7baac3cb | 2538 | |
01372b8f BW |
2539 | if (idx != -1) |
2540 | { | |
2541 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
2542 | e.SetSelection(idx); | |
2543 | e.SetOldSelection(GetActivePage()); | |
2544 | e.SetEventObject(this); | |
2545 | GetEventHandler()->ProcessEvent(e); | |
2546 | } | |
4953f8cf | 2547 | } |
cedd7b22 | 2548 | else |
4953f8cf BW |
2549 | { |
2550 | event.Skip(); | |
2551 | } | |
2552 | } | |
cd05bf23 | 2553 | |
a0c2e4a0 JS |
2554 | void wxAuiTabCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event)) |
2555 | { | |
2556 | Refresh(); | |
2557 | } | |
2558 | ||
2559 | void wxAuiTabCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event)) | |
2560 | { | |
2561 | Refresh(); | |
2562 | } | |
2563 | ||
2564 | void wxAuiTabCtrl::OnChar(wxKeyEvent& event) | |
2565 | { | |
2566 | if (GetActivePage() == -1) | |
2567 | { | |
2568 | event.Skip(); | |
2569 | return; | |
2570 | } | |
2571 | ||
2572 | // We can't leave tab processing to the system; on Windows, tabs and keys | |
2573 | // get eaten by the system and not processed properly if we specify both | |
2574 | // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL, | |
2575 | // we don't key arrow key events. | |
2576 | ||
2577 | int key = event.GetKeyCode(); | |
2578 | ||
2579 | if (key == WXK_NUMPAD_PAGEUP) | |
2580 | key = WXK_PAGEUP; | |
2581 | if (key == WXK_NUMPAD_PAGEDOWN) | |
2582 | key = WXK_PAGEDOWN; | |
2583 | if (key == WXK_NUMPAD_HOME) | |
2584 | key = WXK_HOME; | |
2585 | if (key == WXK_NUMPAD_END) | |
2586 | key = WXK_END; | |
2587 | if (key == WXK_NUMPAD_LEFT) | |
2588 | key = WXK_LEFT; | |
2589 | if (key == WXK_NUMPAD_RIGHT) | |
2590 | key = WXK_RIGHT; | |
2591 | ||
2592 | if (key == WXK_TAB || key == WXK_PAGEUP || key == WXK_PAGEDOWN) | |
2593 | { | |
2594 | bool bCtrlDown = event.ControlDown(); | |
2595 | bool bShiftDown = event.ShiftDown(); | |
2596 | ||
2597 | bool bForward = (key == WXK_TAB && !bShiftDown) || (key == WXK_PAGEDOWN); | |
2598 | bool bWindowChange = (key == WXK_PAGEUP) || (key == WXK_PAGEDOWN) || bCtrlDown; | |
2599 | bool bFromTab = (key == WXK_TAB); | |
2600 | ||
2601 | wxAuiNotebook* nb = wxDynamicCast(GetParent(), wxAuiNotebook); | |
2602 | if (!nb) | |
2603 | { | |
2604 | event.Skip(); | |
2605 | return; | |
2606 | } | |
2607 | ||
2608 | wxNavigationKeyEvent keyEvent; | |
2609 | keyEvent.SetDirection(bForward); | |
2610 | keyEvent.SetWindowChange(bWindowChange); | |
2611 | keyEvent.SetFromTab(bFromTab); | |
2612 | keyEvent.SetEventObject(nb); | |
2613 | ||
2614 | if (!nb->GetEventHandler()->ProcessEvent(keyEvent)) | |
2615 | { | |
2616 | // Not processed? Do an explicit tab into the page. | |
2617 | wxWindow* win = GetWindowFromIdx(GetActivePage()); | |
2618 | if (win) | |
2619 | win->SetFocus(); | |
2620 | } | |
2621 | return; | |
2622 | } | |
2623 | ||
2624 | if (m_pages.GetCount() < 2) | |
2625 | { | |
2626 | event.Skip(); | |
2627 | return; | |
2628 | } | |
2629 | ||
2630 | int newPage = -1; | |
2631 | ||
5c58a3a9 VZ |
2632 | int forwardKey, backwardKey; |
2633 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
2634 | { | |
2635 | forwardKey = WXK_LEFT; | |
2636 | backwardKey = WXK_RIGHT; | |
2637 | } | |
2638 | else | |
2639 | { | |
2640 | forwardKey = WXK_RIGHT; | |
2641 | backwardKey = WXK_LEFT; | |
2642 | } | |
2643 | ||
2644 | if (key == forwardKey) | |
a0c2e4a0 JS |
2645 | { |
2646 | if (m_pages.GetCount() > 1) | |
2647 | { | |
2648 | if (GetActivePage() == -1) | |
2649 | newPage = 0; | |
2650 | else if (GetActivePage() < (int) (m_pages.GetCount() - 1)) | |
2651 | newPage = GetActivePage() + 1; | |
2652 | } | |
2653 | } | |
5c58a3a9 | 2654 | else if (key == backwardKey) |
a0c2e4a0 JS |
2655 | { |
2656 | if (m_pages.GetCount() > 1) | |
2657 | { | |
2658 | if (GetActivePage() == -1) | |
2659 | newPage = (int) (m_pages.GetCount() - 1); | |
2660 | else if (GetActivePage() > 0) | |
2661 | newPage = GetActivePage() - 1; | |
2662 | } | |
2663 | } | |
2664 | else if (key == WXK_HOME) | |
2665 | { | |
2666 | newPage = 0; | |
2667 | } | |
2668 | else if (key == WXK_END) | |
2669 | { | |
2670 | newPage = (int) (m_pages.GetCount() - 1); | |
2671 | } | |
2672 | else | |
2673 | event.Skip(); | |
2674 | ||
2675 | if (newPage != -1) | |
2676 | { | |
2677 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
2678 | e.SetSelection(newPage); | |
2679 | e.SetOldSelection(newPage); | |
2680 | e.SetEventObject(this); | |
2681 | this->GetEventHandler()->ProcessEvent(e); | |
2682 | } | |
2683 | else | |
2684 | event.Skip(); | |
2685 | } | |
2686 | ||
cd05bf23 BW |
2687 | // wxTabFrame is an interesting case. It's important that all child pages |
2688 | // of the multi-notebook control are all actually children of that control | |
2689 | // (and not grandchildren). wxTabFrame facilitates this. There is one | |
2690 | // instance of wxTabFrame for each tab control inside the multi-notebook. | |
2691 | // It's important to know that wxTabFrame is not a real window, but it merely | |
2692 | // used to capture the dimensions/positioning of the internal tab control and | |
2693 | // it's managed page windows | |
2694 | ||
2695 | class wxTabFrame : public wxWindow | |
2696 | { | |
2697 | public: | |
2698 | ||
2699 | wxTabFrame() | |
2700 | { | |
2701 | m_tabs = NULL; | |
2702 | m_rect = wxRect(0,0,200,200); | |
9a29fe70 | 2703 | m_tabCtrlHeight = 20; |
da5e85d9 | 2704 | } |
4444d148 | 2705 | |
cedd7b22 PC |
2706 | ~wxTabFrame() |
2707 | { | |
2708 | wxDELETE(m_tabs); | |
2709 | } | |
bd4e0834 | 2710 | |
da5e85d9 BW |
2711 | void SetTabCtrlHeight(int h) |
2712 | { | |
9a29fe70 | 2713 | m_tabCtrlHeight = h; |
cd05bf23 | 2714 | } |
4444d148 | 2715 | |
cedd7b22 | 2716 | protected: |
cd05bf23 BW |
2717 | void DoSetSize(int x, int y, |
2718 | int width, int height, | |
2719 | int WXUNUSED(sizeFlags = wxSIZE_AUTO)) | |
2720 | { | |
2721 | m_rect = wxRect(x, y, width, height); | |
2722 | DoSizing(); | |
2723 | } | |
4444d148 | 2724 | |
cd05bf23 BW |
2725 | void DoGetClientSize(int* x, int* y) const |
2726 | { | |
2727 | *x = m_rect.width; | |
2728 | *y = m_rect.height; | |
2729 | } | |
4f450f41 | 2730 | |
cedd7b22 | 2731 | public: |
4f450f41 | 2732 | bool Show( bool WXUNUSED(show = true) ) { return false; } |
4444d148 | 2733 | |
cd05bf23 BW |
2734 | void DoSizing() |
2735 | { | |
2736 | if (!m_tabs) | |
2737 | return; | |
4444d148 | 2738 | |
64178c36 JS |
2739 | if (m_tabs->IsFrozen() || m_tabs->GetParent()->IsFrozen()) |
2740 | return; | |
2741 | ||
9a29fe70 | 2742 | m_tab_rect = wxRect(m_rect.x, m_rect.y, m_rect.width, m_tabCtrlHeight); |
134198f1 JS |
2743 | if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM) |
2744 | { | |
9a29fe70 VZ |
2745 | m_tab_rect = wxRect (m_rect.x, m_rect.y + m_rect.height - m_tabCtrlHeight, m_rect.width, m_tabCtrlHeight); |
2746 | m_tabs->SetSize (m_rect.x, m_rect.y + m_rect.height - m_tabCtrlHeight, m_rect.width, m_tabCtrlHeight); | |
2747 | m_tabs->SetRect (wxRect(0, 0, m_rect.width, m_tabCtrlHeight)); | |
134198f1 JS |
2748 | } |
2749 | else //TODO: if (GetFlags() & wxAUI_NB_TOP) | |
2750 | { | |
9a29fe70 VZ |
2751 | m_tab_rect = wxRect (m_rect.x, m_rect.y, m_rect.width, m_tabCtrlHeight); |
2752 | m_tabs->SetSize (m_rect.x, m_rect.y, m_rect.width, m_tabCtrlHeight); | |
2753 | m_tabs->SetRect (wxRect(0, 0, m_rect.width, m_tabCtrlHeight)); | |
134198f1 JS |
2754 | } |
2755 | // TODO: else if (GetFlags() & wxAUI_NB_LEFT){} | |
2756 | // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){} | |
2757 | ||
cd05bf23 | 2758 | m_tabs->Refresh(); |
9d59bf68 | 2759 | m_tabs->Update(); |
4444d148 | 2760 | |
cd05bf23 BW |
2761 | wxAuiNotebookPageArray& pages = m_tabs->GetPages(); |
2762 | size_t i, page_count = pages.GetCount(); | |
4444d148 | 2763 | |
cd05bf23 BW |
2764 | for (i = 0; i < page_count; ++i) |
2765 | { | |
9a29fe70 | 2766 | int height = m_rect.height - m_tabCtrlHeight; |
f96f6a88 VZ |
2767 | if ( height < 0 ) |
2768 | { | |
2769 | // avoid passing negative height to wxWindow::SetSize(), this | |
2770 | // results in assert failures/GTK+ warnings | |
2771 | height = 0; | |
2772 | } | |
2773 | ||
cd05bf23 | 2774 | wxAuiNotebookPage& page = pages.Item(i); |
134198f1 JS |
2775 | if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM) |
2776 | { | |
f96f6a88 | 2777 | page.window->SetSize(m_rect.x, m_rect.y, m_rect.width, height); |
134198f1 JS |
2778 | } |
2779 | else //TODO: if (GetFlags() & wxAUI_NB_TOP) | |
2780 | { | |
9a29fe70 | 2781 | page.window->SetSize(m_rect.x, m_rect.y + m_tabCtrlHeight, |
f96f6a88 | 2782 | m_rect.width, height); |
134198f1 JS |
2783 | } |
2784 | // TODO: else if (GetFlags() & wxAUI_NB_LEFT){} | |
2785 | // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){} | |
4444d148 | 2786 | |
89272c55 | 2787 | #if wxUSE_MDI |
a3a5df9d | 2788 | if (page.window->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) |
cd05bf23 | 2789 | { |
a3a5df9d | 2790 | wxAuiMDIChildFrame* wnd = (wxAuiMDIChildFrame*)page.window; |
cd05bf23 BW |
2791 | wnd->ApplyMDIChildFrameRect(); |
2792 | } | |
89272c55 | 2793 | #endif |
cd05bf23 BW |
2794 | } |
2795 | } | |
2796 | ||
cedd7b22 | 2797 | protected: |
134e83cb BW |
2798 | void DoGetSize(int* x, int* y) const |
2799 | { | |
2800 | if (x) | |
2801 | *x = m_rect.GetWidth(); | |
2802 | if (y) | |
2803 | *y = m_rect.GetHeight(); | |
2804 | } | |
4444d148 | 2805 | |
cedd7b22 | 2806 | public: |
134e83cb BW |
2807 | void Update() |
2808 | { | |
2809 | // does nothing | |
2810 | } | |
4444d148 | 2811 | |
cd05bf23 BW |
2812 | wxRect m_rect; |
2813 | wxRect m_tab_rect; | |
2814 | wxAuiTabCtrl* m_tabs; | |
9a29fe70 | 2815 | int m_tabCtrlHeight; |
cd05bf23 BW |
2816 | }; |
2817 | ||
2818 | ||
7ebc40e8 | 2819 | const int wxAuiBaseTabCtrlId = 5380; |
cd05bf23 BW |
2820 | |
2821 | ||
a3a5df9d | 2822 | // -- wxAuiNotebook class implementation -- |
cd05bf23 | 2823 | |
3c778901 VZ |
2824 | #define EVT_AUI_RANGE(id1, id2, event, func) \ |
2825 | wx__DECLARE_EVT2(event, id1, id2, wxAuiNotebookEventHandler(func)) | |
2826 | ||
a3a5df9d | 2827 | BEGIN_EVENT_TABLE(wxAuiNotebook, wxControl) |
9fbb7d80 | 2828 | EVT_SIZE(wxAuiNotebook::OnSize) |
5bf3f27f | 2829 | EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocusNotebook) |
3c778901 | 2830 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 2831 | wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, |
a3a5df9d | 2832 | wxAuiNotebook::OnTabClicked) |
3c778901 | 2833 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 2834 | wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, |
a3a5df9d | 2835 | wxAuiNotebook::OnTabBeginDrag) |
3c778901 | 2836 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 2837 | wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, |
a3a5df9d | 2838 | wxAuiNotebook::OnTabEndDrag) |
2bd82d72 VZ |
2839 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
2840 | wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, | |
2841 | wxAuiNotebook::OnTabCancelDrag) | |
3c778901 | 2842 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 2843 | wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, |
a3a5df9d | 2844 | wxAuiNotebook::OnTabDragMotion) |
3c778901 | 2845 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 2846 | wxEVT_COMMAND_AUINOTEBOOK_BUTTON, |
a3a5df9d | 2847 | wxAuiNotebook::OnTabButton) |
3c778901 | 2848 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
2849 | wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, |
2850 | wxAuiNotebook::OnTabMiddleDown) | |
3c778901 | 2851 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
2852 | wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, |
2853 | wxAuiNotebook::OnTabMiddleUp) | |
3c778901 | 2854 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
2855 | wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, |
2856 | wxAuiNotebook::OnTabRightDown) | |
3c778901 | 2857 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
2858 | wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, |
2859 | wxAuiNotebook::OnTabRightUp) | |
3c778901 | 2860 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
198be845 JS |
2861 | wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, |
2862 | wxAuiNotebook::OnTabBgDClick) | |
5bf3f27f | 2863 | EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook) |
cd05bf23 BW |
2864 | END_EVENT_TABLE() |
2865 | ||
90230407 | 2866 | void wxAuiNotebook::Init() |
cd05bf23 | 2867 | { |
9a29fe70 VZ |
2868 | m_curPage = -1; |
2869 | m_tabIdCounter = wxAuiBaseTabCtrlId; | |
2870 | m_dummyWnd = NULL; | |
2871 | m_tabCtrlHeight = 20; | |
2872 | m_requestedBmpSize = wxDefaultSize; | |
2873 | m_requestedTabCtrlHeight = -1; | |
cd05bf23 BW |
2874 | } |
2875 | ||
a3a5df9d | 2876 | bool wxAuiNotebook::Create(wxWindow* parent, |
cd05bf23 BW |
2877 | wxWindowID id, |
2878 | const wxPoint& pos, | |
2879 | const wxSize& size, | |
2880 | long style) | |
2881 | { | |
2882 | if (!wxControl::Create(parent, id, pos, size, style)) | |
2883 | return false; | |
4444d148 | 2884 | |
702b1c7e | 2885 | InitNotebook(style); |
4444d148 | 2886 | |
cd05bf23 BW |
2887 | return true; |
2888 | } | |
2889 | ||
2890 | // InitNotebook() contains common initialization | |
2891 | // code called by all constructors | |
a3a5df9d | 2892 | void wxAuiNotebook::InitNotebook(long style) |
cd05bf23 | 2893 | { |
c7bfb76a | 2894 | SetName(wxT("wxAuiNotebook")); |
9a29fe70 VZ |
2895 | m_curPage = -1; |
2896 | m_tabIdCounter = wxAuiBaseTabCtrlId; | |
2897 | m_dummyWnd = NULL; | |
702b1c7e | 2898 | m_flags = (unsigned int)style; |
9a29fe70 | 2899 | m_tabCtrlHeight = 20; |
c58ba15f | 2900 | |
9a29fe70 VZ |
2901 | m_normalFont = *wxNORMAL_FONT; |
2902 | m_selectedFont = *wxNORMAL_FONT; | |
2903 | m_selectedFont.SetWeight(wxBOLD); | |
4444d148 | 2904 | |
b0d17f7c | 2905 | SetArtProvider(new wxAuiDefaultTabArt); |
4444d148 | 2906 | |
9a29fe70 VZ |
2907 | m_dummyWnd = new wxWindow(this, wxID_ANY, wxPoint(0,0), wxSize(0,0)); |
2908 | m_dummyWnd->SetSize(200, 200); | |
2909 | m_dummyWnd->Show(false); | |
4444d148 | 2910 | |
cd05bf23 | 2911 | m_mgr.SetManagedWindow(this); |
a6b7a521 VZ |
2912 | m_mgr.SetFlags(wxAUI_MGR_DEFAULT); |
2913 | m_mgr.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint | |
4444d148 | 2914 | |
9a29fe70 | 2915 | m_mgr.AddPane(m_dummyWnd, |
9fbb7d80 | 2916 | wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false)); |
4444d148 | 2917 | |
cd05bf23 BW |
2918 | m_mgr.Update(); |
2919 | } | |
2920 | ||
a3a5df9d | 2921 | wxAuiNotebook::~wxAuiNotebook() |
cd05bf23 | 2922 | { |
18b40f30 | 2923 | // Indicate we're deleting pages |
c6212a0c | 2924 | SendDestroyEvent(); |
18b40f30 | 2925 | |
1c0955dd JS |
2926 | while ( GetPageCount() > 0 ) |
2927 | DeletePage(0); | |
2928 | ||
cd05bf23 BW |
2929 | m_mgr.UnInit(); |
2930 | } | |
2931 | ||
a3a5df9d | 2932 | void wxAuiNotebook::SetArtProvider(wxAuiTabArt* art) |
3f69756e BW |
2933 | { |
2934 | m_tabs.SetArtProvider(art); | |
7baac3cb | 2935 | |
4026f044 VZ |
2936 | // Update the height and do nothing else if it did something but otherwise |
2937 | // (i.e. if the new art provider uses the same height as the old one) we | |
2938 | // need to manually set the art provider for all tabs ourselves. | |
2939 | if ( !UpdateTabCtrlHeight() ) | |
2940 | { | |
2941 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
2942 | const size_t pane_count = all_panes.GetCount(); | |
2943 | for (size_t i = 0; i < pane_count; ++i) | |
2944 | { | |
2945 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
2946 | if (pane.name == wxT("dummy")) | |
2947 | continue; | |
2948 | wxTabFrame* tab_frame = (wxTabFrame*)pane.window; | |
2949 | wxAuiTabCtrl* tabctrl = tab_frame->m_tabs; | |
2950 | tabctrl->SetArtProvider(art->Clone()); | |
2951 | } | |
2952 | } | |
2b9aac33 BW |
2953 | } |
2954 | ||
ca0d4407 BW |
2955 | // SetTabCtrlHeight() is the highest-level override of the |
2956 | // tab height. A call to this function effectively enforces a | |
2957 | // specified tab ctrl height, overriding all other considerations, | |
2958 | // such as text or bitmap height. It overrides any call to | |
2959 | // SetUniformBitmapSize(). Specifying a height of -1 reverts | |
4c51a665 | 2960 | // any previous call and returns to the default behaviour |
ca0d4407 BW |
2961 | |
2962 | void wxAuiNotebook::SetTabCtrlHeight(int height) | |
2963 | { | |
9a29fe70 | 2964 | m_requestedTabCtrlHeight = height; |
c58ba15f | 2965 | |
ca0d4407 | 2966 | // if window is already initialized, recalculate the tab height |
9a29fe70 | 2967 | if (m_dummyWnd) |
ca0d4407 BW |
2968 | { |
2969 | UpdateTabCtrlHeight(); | |
2970 | } | |
2971 | } | |
2972 | ||
2973 | ||
2974 | // SetUniformBitmapSize() ensures that all tabs will have | |
2975 | // the same height, even if some tabs don't have bitmaps | |
2976 | // Passing wxDefaultSize to this function will instruct | |
2977 | // the control to use dynamic tab height-- so when a tab | |
2978 | // with a large bitmap is added, the tab ctrl's height will | |
2979 | // automatically increase to accommodate the bitmap | |
2980 | ||
9fbb7d80 BW |
2981 | void wxAuiNotebook::SetUniformBitmapSize(const wxSize& size) |
2982 | { | |
9a29fe70 | 2983 | m_requestedBmpSize = size; |
c58ba15f | 2984 | |
9fbb7d80 | 2985 | // if window is already initialized, recalculate the tab height |
9a29fe70 | 2986 | if (m_dummyWnd) |
dbbe02ea | 2987 | { |
ca0d4407 | 2988 | UpdateTabCtrlHeight(); |
dbbe02ea | 2989 | } |
9fbb7d80 BW |
2990 | } |
2991 | ||
ca0d4407 | 2992 | // UpdateTabCtrlHeight() does the actual tab resizing. It's meant |
4026f044 VZ |
2993 | // to be used internally |
2994 | bool wxAuiNotebook::UpdateTabCtrlHeight() | |
2b9aac33 | 2995 | { |
ca0d4407 BW |
2996 | // get the tab ctrl height we will use |
2997 | int height = CalculateTabCtrlHeight(); | |
c58ba15f | 2998 | |
2b9aac33 BW |
2999 | // if the tab control height needs to change, update |
3000 | // all of our tab controls with the new height | |
9a29fe70 | 3001 | if (m_tabCtrlHeight == height) |
4026f044 | 3002 | return false; |
7baac3cb | 3003 | |
4026f044 | 3004 | wxAuiTabArt* art = m_tabs.GetArtProvider(); |
7baac3cb | 3005 | |
9a29fe70 | 3006 | m_tabCtrlHeight = height; |
4026f044 VZ |
3007 | |
3008 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3009 | size_t i, pane_count = all_panes.GetCount(); | |
3010 | for (i = 0; i < pane_count; ++i) | |
3011 | { | |
3012 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3013 | if (pane.name == wxT("dummy")) | |
3014 | continue; | |
3015 | wxTabFrame* tab_frame = (wxTabFrame*)pane.window; | |
3016 | wxAuiTabCtrl* tabctrl = tab_frame->m_tabs; | |
9a29fe70 | 3017 | tab_frame->SetTabCtrlHeight(m_tabCtrlHeight); |
4026f044 VZ |
3018 | tabctrl->SetArtProvider(art->Clone()); |
3019 | tab_frame->DoSizing(); | |
b0d17f7c | 3020 | } |
4026f044 VZ |
3021 | |
3022 | return true; | |
3f69756e BW |
3023 | } |
3024 | ||
9fbb7d80 BW |
3025 | void wxAuiNotebook::UpdateHintWindowSize() |
3026 | { | |
3027 | wxSize size = CalculateNewSplitSize(); | |
c58ba15f | 3028 | |
9fbb7d80 BW |
3029 | // the placeholder hint window should be set to this size |
3030 | wxAuiPaneInfo& info = m_mgr.GetPane(wxT("dummy")); | |
3031 | if (info.IsOk()) | |
3032 | { | |
3033 | info.MinSize(size); | |
3034 | info.BestSize(size); | |
9a29fe70 | 3035 | m_dummyWnd->SetSize(size); |
9fbb7d80 BW |
3036 | } |
3037 | } | |
3038 | ||
3039 | ||
3040 | // calculates the size of the new split | |
3041 | wxSize wxAuiNotebook::CalculateNewSplitSize() | |
3042 | { | |
3043 | // count number of tab controls | |
3044 | int tab_ctrl_count = 0; | |
3045 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3046 | size_t i, pane_count = all_panes.GetCount(); | |
3047 | for (i = 0; i < pane_count; ++i) | |
3048 | { | |
3049 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3050 | if (pane.name == wxT("dummy")) | |
3051 | continue; | |
3052 | tab_ctrl_count++; | |
3053 | } | |
3054 | ||
3055 | wxSize new_split_size; | |
c58ba15f | 3056 | |
9fbb7d80 BW |
3057 | // if there is only one tab control, the first split |
3058 | // should happen around the middle | |
3059 | if (tab_ctrl_count < 2) | |
3060 | { | |
3061 | new_split_size = GetClientSize(); | |
3062 | new_split_size.x /= 2; | |
3063 | new_split_size.y /= 2; | |
3064 | } | |
cedd7b22 | 3065 | else |
9fbb7d80 BW |
3066 | { |
3067 | // this is in place of a more complicated calculation | |
3068 | // that needs to be implemented | |
3069 | new_split_size = wxSize(180,180); | |
3070 | } | |
c58ba15f | 3071 | |
9fbb7d80 BW |
3072 | return new_split_size; |
3073 | } | |
3074 | ||
2b9aac33 BW |
3075 | int wxAuiNotebook::CalculateTabCtrlHeight() |
3076 | { | |
ca0d4407 BW |
3077 | // if a fixed tab ctrl height is specified, |
3078 | // just return that instead of calculating a | |
3079 | // tab height | |
9a29fe70 VZ |
3080 | if (m_requestedTabCtrlHeight != -1) |
3081 | return m_requestedTabCtrlHeight; | |
c58ba15f | 3082 | |
2b9aac33 BW |
3083 | // find out new best tab height |
3084 | wxAuiTabArt* art = m_tabs.GetArtProvider(); | |
7baac3cb | 3085 | |
9fbb7d80 BW |
3086 | return art->GetBestTabCtrlSize(this, |
3087 | m_tabs.GetPages(), | |
9a29fe70 | 3088 | m_requestedBmpSize); |
2b9aac33 BW |
3089 | } |
3090 | ||
3091 | ||
e0dc13d4 | 3092 | wxAuiTabArt* wxAuiNotebook::GetArtProvider() const |
3f69756e BW |
3093 | { |
3094 | return m_tabs.GetArtProvider(); | |
3095 | } | |
3096 | ||
0ce53f32 BW |
3097 | void wxAuiNotebook::SetWindowStyleFlag(long style) |
3098 | { | |
3099 | wxControl::SetWindowStyleFlag(style); | |
7baac3cb | 3100 | |
0ce53f32 | 3101 | m_flags = (unsigned int)style; |
7baac3cb | 3102 | |
0ce53f32 BW |
3103 | // if the control is already initialized |
3104 | if (m_mgr.GetManagedWindow() == (wxWindow*)this) | |
3105 | { | |
3106 | // let all of the tab children know about the new style | |
7baac3cb | 3107 | |
0ce53f32 BW |
3108 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
3109 | size_t i, pane_count = all_panes.GetCount(); | |
3110 | for (i = 0; i < pane_count; ++i) | |
3111 | { | |
3112 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3113 | if (pane.name == wxT("dummy")) | |
3114 | continue; | |
97ac2d5e BW |
3115 | wxTabFrame* tabframe = (wxTabFrame*)pane.window; |
3116 | wxAuiTabCtrl* tabctrl = tabframe->m_tabs; | |
0ce53f32 | 3117 | tabctrl->SetFlags(m_flags); |
97ac2d5e | 3118 | tabframe->DoSizing(); |
0ce53f32 BW |
3119 | tabctrl->Refresh(); |
3120 | tabctrl->Update(); | |
3121 | } | |
3122 | } | |
3123 | } | |
3124 | ||
3125 | ||
a3a5df9d | 3126 | bool wxAuiNotebook::AddPage(wxWindow* page, |
cd05bf23 BW |
3127 | const wxString& caption, |
3128 | bool select, | |
3129 | const wxBitmap& bitmap) | |
3130 | { | |
3131 | return InsertPage(GetPageCount(), page, caption, select, bitmap); | |
3132 | } | |
4444d148 | 3133 | |
a3a5df9d | 3134 | bool wxAuiNotebook::InsertPage(size_t page_idx, |
cd05bf23 BW |
3135 | wxWindow* page, |
3136 | const wxString& caption, | |
3137 | bool select, | |
3138 | const wxBitmap& bitmap) | |
3139 | { | |
c36cdfc0 BW |
3140 | wxASSERT_MSG(page, wxT("page pointer must be non-NULL")); |
3141 | if (!page) | |
3142 | return false; | |
5c58a3a9 | 3143 | |
3d9b52a8 JS |
3144 | page->Reparent(this); |
3145 | ||
cd05bf23 BW |
3146 | wxAuiNotebookPage info; |
3147 | info.window = page; | |
3148 | info.caption = caption; | |
3149 | info.bitmap = bitmap; | |
3150 | info.active = false; | |
3151 | ||
3152 | // if there are currently no tabs, the first added | |
3153 | // tab must be active | |
3154 | if (m_tabs.GetPageCount() == 0) | |
3155 | info.active = true; | |
3156 | ||
3157 | m_tabs.InsertPage(page, info, page_idx); | |
3158 | ||
298773ec BW |
3159 | // if that was the first page added, even if |
3160 | // select is false, it must become the "current page" | |
3161 | // (though no select events will be fired) | |
3162 | if (!select && m_tabs.GetPageCount() == 1) | |
092d7f88 | 3163 | select = true; |
9a29fe70 | 3164 | //m_curPage = GetPageIndex(page); |
298773ec | 3165 | |
cd05bf23 BW |
3166 | wxAuiTabCtrl* active_tabctrl = GetActiveTabCtrl(); |
3167 | if (page_idx >= active_tabctrl->GetPageCount()) | |
3168 | active_tabctrl->AddPage(page, info); | |
cedd7b22 | 3169 | else |
cd05bf23 | 3170 | active_tabctrl->InsertPage(page, info, page_idx); |
4444d148 | 3171 | |
ca0d4407 | 3172 | UpdateTabCtrlHeight(); |
cd05bf23 BW |
3173 | DoSizing(); |
3174 | active_tabctrl->DoShowHide(); | |
4444d148 | 3175 | |
3d9b52a8 | 3176 | // adjust selected index |
9a29fe70 VZ |
3177 | if(m_curPage >= (int) page_idx) |
3178 | m_curPage++; | |
3d9b52a8 | 3179 | |
cd05bf23 BW |
3180 | if (select) |
3181 | { | |
849c353a | 3182 | SetSelectionToWindow(page); |
cd05bf23 | 3183 | } |
4444d148 | 3184 | |
cd05bf23 BW |
3185 | return true; |
3186 | } | |
3187 | ||
3188 | ||
3189 | // DeletePage() removes a tab from the multi-notebook, | |
3190 | // and destroys the window as well | |
a3a5df9d | 3191 | bool wxAuiNotebook::DeletePage(size_t page_idx) |
7baac3cb | 3192 | { |
fd749f4a BW |
3193 | if (page_idx >= m_tabs.GetPageCount()) |
3194 | return false; | |
cedd7b22 | 3195 | |
4444d148 | 3196 | wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); |
cedd7b22 | 3197 | |
fd749f4a BW |
3198 | // hide the window in advance, as this will |
3199 | // prevent flicker | |
3200 | ShowWnd(wnd, false); | |
5d3aeb0f BW |
3201 | |
3202 | if (!RemovePage(page_idx)) | |
3203 | return false; | |
3204 | ||
89272c55 | 3205 | #if wxUSE_MDI |
5d3aeb0f BW |
3206 | // actually destroy the window now |
3207 | if (wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) | |
3208 | { | |
3209 | // delete the child frame with pending delete, as is | |
3210 | // customary with frame windows | |
3211 | if (!wxPendingDelete.Member(wnd)) | |
3212 | wxPendingDelete.Append(wnd); | |
3213 | } | |
cedd7b22 | 3214 | else |
89272c55 | 3215 | #endif |
5d3aeb0f BW |
3216 | { |
3217 | wnd->Destroy(); | |
3218 | } | |
7baac3cb | 3219 | |
5d3aeb0f | 3220 | return true; |
cd05bf23 BW |
3221 | } |
3222 | ||
3223 | ||
3224 | ||
3225 | // RemovePage() removes a tab from the multi-notebook, | |
3226 | // but does not destroy the window | |
a3a5df9d | 3227 | bool wxAuiNotebook::RemovePage(size_t page_idx) |
cd05bf23 | 3228 | { |
9b362935 BW |
3229 | // save active window pointer |
3230 | wxWindow* active_wnd = NULL; | |
9a29fe70 VZ |
3231 | if (m_curPage >= 0) |
3232 | active_wnd = m_tabs.GetWindowFromIdx(m_curPage); | |
cedd7b22 | 3233 | |
9b362935 | 3234 | // save pointer of window being deleted |
cd05bf23 | 3235 | wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); |
5d3aeb0f | 3236 | wxWindow* new_active = NULL; |
4444d148 | 3237 | |
13aaa50f BW |
3238 | // make sure we found the page |
3239 | if (!wnd) | |
3240 | return false; | |
cedd7b22 | 3241 | |
5d3aeb0f | 3242 | // find out which onscreen tab ctrl owns this tab |
cd05bf23 BW |
3243 | wxAuiTabCtrl* ctrl; |
3244 | int ctrl_idx; | |
5d3aeb0f BW |
3245 | if (!FindTab(wnd, &ctrl, &ctrl_idx)) |
3246 | return false; | |
3247 | ||
9a29fe70 | 3248 | bool is_curpage = (m_curPage == (int)page_idx); |
13aaa50f | 3249 | bool is_active_in_split = ctrl->GetPage(ctrl_idx).active; |
5d3aeb0f | 3250 | |
4444d148 | 3251 | |
5d3aeb0f BW |
3252 | // remove the tab from main catalog |
3253 | if (!m_tabs.RemovePage(wnd)) | |
3254 | return false; | |
3255 | ||
3256 | // remove the tab from the onscreen tab ctrl | |
3257 | ctrl->RemovePage(wnd); | |
3258 | ||
13aaa50f BW |
3259 | if (is_active_in_split) |
3260 | { | |
3261 | int ctrl_new_page_count = (int)ctrl->GetPageCount(); | |
cedd7b22 | 3262 | |
13aaa50f BW |
3263 | if (ctrl_idx >= ctrl_new_page_count) |
3264 | ctrl_idx = ctrl_new_page_count-1; | |
cedd7b22 | 3265 | |
13aaa50f BW |
3266 | if (ctrl_idx >= 0 && ctrl_idx < (int)ctrl->GetPageCount()) |
3267 | { | |
3268 | // set new page as active in the tab split | |
3269 | ctrl->SetActivePage(ctrl_idx); | |
cedd7b22 | 3270 | |
13aaa50f BW |
3271 | // if the page deleted was the current page for the |
3272 | // entire tab control, then record the window | |
3273 | // pointer of the new active page for activation | |
3274 | if (is_curpage) | |
3275 | { | |
3276 | new_active = ctrl->GetWindowFromIdx(ctrl_idx); | |
3277 | } | |
3278 | } | |
3279 | } | |
cedd7b22 | 3280 | else |
9b362935 BW |
3281 | { |
3282 | // we are not deleting the active page, so keep it the same | |
3283 | new_active = active_wnd; | |
3284 | } | |
13aaa50f | 3285 | |
cedd7b22 | 3286 | |
13aaa50f BW |
3287 | if (!new_active) |
3288 | { | |
3289 | // we haven't yet found a new page to active, | |
3290 | // so select the next page from the main tab | |
3291 | // catalogue | |
cedd7b22 | 3292 | |
13aaa50f BW |
3293 | if (page_idx < m_tabs.GetPageCount()) |
3294 | { | |
3295 | new_active = m_tabs.GetPage(page_idx).window; | |
3296 | } | |
cedd7b22 | 3297 | |
13aaa50f BW |
3298 | if (!new_active && m_tabs.GetPageCount() > 0) |
3299 | { | |
3300 | new_active = m_tabs.GetPage(0).window; | |
3301 | } | |
3302 | } | |
5d3aeb0f | 3303 | |
cedd7b22 | 3304 | |
5d3aeb0f BW |
3305 | RemoveEmptyTabFrames(); |
3306 | ||
9a29fe70 | 3307 | m_curPage = wxNOT_FOUND; |
917f228a VZ |
3308 | |
3309 | // set new active pane unless we're being destroyed anyhow | |
18b40f30 | 3310 | if (new_active && !m_isBeingDeleted) |
849c353a | 3311 | SetSelectionToWindow(new_active); |
cedd7b22 | 3312 | |
5d3aeb0f | 3313 | return true; |
cd05bf23 BW |
3314 | } |
3315 | ||
e0dc13d4 BW |
3316 | // GetPageIndex() returns the index of the page, or -1 if the |
3317 | // page could not be located in the notebook | |
3318 | int wxAuiNotebook::GetPageIndex(wxWindow* page_wnd) const | |
3319 | { | |
3320 | return m_tabs.GetIdxFromWindow(page_wnd); | |
3321 | } | |
3322 | ||
3323 | ||
3324 | ||
cd05bf23 | 3325 | // SetPageText() changes the tab caption of the specified page |
a3a5df9d | 3326 | bool wxAuiNotebook::SetPageText(size_t page_idx, const wxString& text) |
4444d148 | 3327 | { |
cd05bf23 BW |
3328 | if (page_idx >= m_tabs.GetPageCount()) |
3329 | return false; | |
4444d148 | 3330 | |
cd05bf23 BW |
3331 | // update our own tab catalog |
3332 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3333 | page_info.caption = text; | |
4444d148 | 3334 | |
cd05bf23 BW |
3335 | // update what's on screen |
3336 | wxAuiTabCtrl* ctrl; | |
3337 | int ctrl_idx; | |
3338 | if (FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
3339 | { | |
3340 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
3341 | info.caption = text; | |
3342 | ctrl->Refresh(); | |
639a4f7b | 3343 | ctrl->Update(); |
cd05bf23 | 3344 | } |
4444d148 | 3345 | |
cd05bf23 BW |
3346 | return true; |
3347 | } | |
3348 | ||
c3e016e4 JS |
3349 | // returns the page caption |
3350 | wxString wxAuiNotebook::GetPageText(size_t page_idx) const | |
3351 | { | |
3352 | if (page_idx >= m_tabs.GetPageCount()) | |
3353 | return wxEmptyString; | |
3354 | ||
3355 | // update our own tab catalog | |
3356 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3357 | return page_info.caption; | |
3358 | } | |
e0dc13d4 BW |
3359 | |
3360 | bool wxAuiNotebook::SetPageBitmap(size_t page_idx, const wxBitmap& bitmap) | |
3361 | { | |
3362 | if (page_idx >= m_tabs.GetPageCount()) | |
3363 | return false; | |
7baac3cb | 3364 | |
e0dc13d4 BW |
3365 | // update our own tab catalog |
3366 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3367 | page_info.bitmap = bitmap; | |
7baac3cb | 3368 | |
e0dc13d4 | 3369 | // tab height might have changed |
ca0d4407 | 3370 | UpdateTabCtrlHeight(); |
7baac3cb | 3371 | |
e0dc13d4 BW |
3372 | // update what's on screen |
3373 | wxAuiTabCtrl* ctrl; | |
3374 | int ctrl_idx; | |
3375 | if (FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
3376 | { | |
3377 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
3378 | info.bitmap = bitmap; | |
3379 | ctrl->Refresh(); | |
3380 | ctrl->Update(); | |
3381 | } | |
7baac3cb | 3382 | |
e0dc13d4 BW |
3383 | return true; |
3384 | } | |
3385 | ||
c3e016e4 JS |
3386 | // returns the page bitmap |
3387 | wxBitmap wxAuiNotebook::GetPageBitmap(size_t page_idx) const | |
3388 | { | |
3389 | if (page_idx >= m_tabs.GetPageCount()) | |
3390 | return wxBitmap(); | |
3391 | ||
3392 | // update our own tab catalog | |
3393 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
3394 | return page_info.bitmap; | |
3395 | } | |
e0dc13d4 | 3396 | |
cd05bf23 | 3397 | // GetSelection() returns the index of the currently active page |
a3a5df9d | 3398 | int wxAuiNotebook::GetSelection() const |
cd05bf23 | 3399 | { |
9a29fe70 | 3400 | return m_curPage; |
cd05bf23 BW |
3401 | } |
3402 | ||
3403 | // SetSelection() sets the currently active page | |
873ff54b | 3404 | int wxAuiNotebook::SetSelection(size_t new_page) |
cd05bf23 | 3405 | { |
873ff54b | 3406 | return DoModifySelection(new_page, true); |
cd05bf23 BW |
3407 | } |
3408 | ||
849c353a VZ |
3409 | void wxAuiNotebook::SetSelectionToWindow(wxWindow *win) |
3410 | { | |
3411 | const int idx = m_tabs.GetIdxFromWindow(win); | |
9a83f860 | 3412 | wxCHECK_RET( idx != wxNOT_FOUND, wxT("invalid notebook page") ); |
849c353a | 3413 | |
ea34484c BW |
3414 | |
3415 | // since a tab was clicked, let the parent know that we received | |
3416 | // the focus, even if we will assign that focus immediately | |
3417 | // to the child tab in the SetSelection call below | |
3418 | // (the child focus event will also let wxAuiManager, if any, | |
3419 | // know that the notebook control has been activated) | |
03647350 | 3420 | |
ea34484c BW |
3421 | wxWindow* parent = GetParent(); |
3422 | if (parent) | |
3423 | { | |
3424 | wxChildFocusEvent eventFocus(this); | |
3425 | parent->GetEventHandler()->ProcessEvent(eventFocus); | |
3426 | } | |
3427 | ||
3428 | ||
849c353a VZ |
3429 | SetSelection(idx); |
3430 | } | |
3431 | ||
cd05bf23 BW |
3432 | // GetPageCount() returns the total number of |
3433 | // pages managed by the multi-notebook | |
a3a5df9d | 3434 | size_t wxAuiNotebook::GetPageCount() const |
cd05bf23 BW |
3435 | { |
3436 | return m_tabs.GetPageCount(); | |
3437 | } | |
3438 | ||
3439 | // GetPage() returns the wxWindow pointer of the | |
3440 | // specified page | |
a3a5df9d | 3441 | wxWindow* wxAuiNotebook::GetPage(size_t page_idx) const |
cd05bf23 BW |
3442 | { |
3443 | wxASSERT(page_idx < m_tabs.GetPageCount()); | |
4444d148 | 3444 | |
cd05bf23 BW |
3445 | return m_tabs.GetWindowFromIdx(page_idx); |
3446 | } | |
3447 | ||
3448 | // DoSizing() performs all sizing operations in each tab control | |
a3a5df9d | 3449 | void wxAuiNotebook::DoSizing() |
cd05bf23 | 3450 | { |
a3a5df9d | 3451 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
3452 | size_t i, pane_count = all_panes.GetCount(); |
3453 | for (i = 0; i < pane_count; ++i) | |
3454 | { | |
3455 | if (all_panes.Item(i).name == wxT("dummy")) | |
3456 | continue; | |
3457 | ||
3458 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
3459 | tabframe->DoSizing(); | |
3460 | } | |
3461 | } | |
3462 | ||
3463 | // GetActiveTabCtrl() returns the active tab control. It is | |
3464 | // called to determine which control gets new windows being added | |
a3a5df9d | 3465 | wxAuiTabCtrl* wxAuiNotebook::GetActiveTabCtrl() |
cd05bf23 | 3466 | { |
9a29fe70 | 3467 | if (m_curPage >= 0 && m_curPage < (int)m_tabs.GetPageCount()) |
cd05bf23 BW |
3468 | { |
3469 | wxAuiTabCtrl* ctrl; | |
3470 | int idx; | |
4444d148 | 3471 | |
cd05bf23 | 3472 | // find the tab ctrl with the current page |
9a29fe70 | 3473 | if (FindTab(m_tabs.GetPage(m_curPage).window, |
cd05bf23 | 3474 | &ctrl, &idx)) |
4444d148 | 3475 | { |
cd05bf23 BW |
3476 | return ctrl; |
3477 | } | |
3478 | } | |
4444d148 | 3479 | |
cd05bf23 | 3480 | // no current page, just find the first tab ctrl |
a3a5df9d | 3481 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
3482 | size_t i, pane_count = all_panes.GetCount(); |
3483 | for (i = 0; i < pane_count; ++i) | |
3484 | { | |
3485 | if (all_panes.Item(i).name == wxT("dummy")) | |
3486 | continue; | |
4444d148 | 3487 | |
cd05bf23 BW |
3488 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
3489 | return tabframe->m_tabs; | |
3490 | } | |
4444d148 | 3491 | |
cd05bf23 BW |
3492 | // If there is no tabframe at all, create one |
3493 | wxTabFrame* tabframe = new wxTabFrame; | |
9a29fe70 | 3494 | tabframe->SetTabCtrlHeight(m_tabCtrlHeight); |
cd05bf23 | 3495 | tabframe->m_tabs = new wxAuiTabCtrl(this, |
9a29fe70 | 3496 | m_tabIdCounter++, |
cd05bf23 BW |
3497 | wxDefaultPosition, |
3498 | wxDefaultSize, | |
a0c2e4a0 | 3499 | wxNO_BORDER|wxWANTS_CHARS); |
702b1c7e | 3500 | tabframe->m_tabs->SetFlags(m_flags); |
b0d17f7c | 3501 | tabframe->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); |
cd05bf23 | 3502 | m_mgr.AddPane(tabframe, |
a3a5df9d | 3503 | wxAuiPaneInfo().Center().CaptionVisible(false)); |
4444d148 | 3504 | |
cd05bf23 | 3505 | m_mgr.Update(); |
4444d148 | 3506 | |
cd05bf23 BW |
3507 | return tabframe->m_tabs; |
3508 | } | |
3509 | ||
3510 | // FindTab() finds the tab control that currently contains the window as well | |
3511 | // as the index of the window in the tab control. It returns true if the | |
3512 | // window was found, otherwise false. | |
a3a5df9d | 3513 | bool wxAuiNotebook::FindTab(wxWindow* page, wxAuiTabCtrl** ctrl, int* idx) |
cd05bf23 | 3514 | { |
a3a5df9d | 3515 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
3516 | size_t i, pane_count = all_panes.GetCount(); |
3517 | for (i = 0; i < pane_count; ++i) | |
3518 | { | |
3519 | if (all_panes.Item(i).name == wxT("dummy")) | |
3520 | continue; | |
4444d148 | 3521 | |
cd05bf23 | 3522 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
4444d148 | 3523 | |
cd05bf23 BW |
3524 | int page_idx = tabframe->m_tabs->GetIdxFromWindow(page); |
3525 | if (page_idx != -1) | |
3526 | { | |
3527 | *ctrl = tabframe->m_tabs; | |
3528 | *idx = page_idx; | |
3529 | return true; | |
3530 | } | |
3531 | } | |
4444d148 | 3532 | |
cd05bf23 BW |
3533 | return false; |
3534 | } | |
3535 | ||
d606b6e9 BW |
3536 | void wxAuiNotebook::Split(size_t page, int direction) |
3537 | { | |
3538 | wxSize cli_size = GetClientSize(); | |
54a8a78e | 3539 | |
d606b6e9 BW |
3540 | // get the page's window pointer |
3541 | wxWindow* wnd = GetPage(page); | |
3542 | if (!wnd) | |
3543 | return; | |
54a8a78e | 3544 | |
d606b6e9 BW |
3545 | // notebooks with 1 or less pages can't be split |
3546 | if (GetPageCount() < 2) | |
3547 | return; | |
54a8a78e | 3548 | |
d606b6e9 BW |
3549 | // find out which tab control the page currently belongs to |
3550 | wxAuiTabCtrl *src_tabs, *dest_tabs; | |
3551 | int src_idx = -1; | |
3552 | src_tabs = NULL; | |
3553 | if (!FindTab(wnd, &src_tabs, &src_idx)) | |
3554 | return; | |
3555 | if (!src_tabs || src_idx == -1) | |
3556 | return; | |
54a8a78e | 3557 | |
d606b6e9 BW |
3558 | // choose a split size |
3559 | wxSize split_size; | |
3560 | if (GetPageCount() > 2) | |
3561 | { | |
3562 | split_size = CalculateNewSplitSize(); | |
3563 | } | |
cedd7b22 | 3564 | else |
d606b6e9 BW |
3565 | { |
3566 | // because there are two panes, always split them | |
3567 | // equally | |
3568 | split_size = GetClientSize(); | |
3569 | split_size.x /= 2; | |
3570 | split_size.y /= 2; | |
3571 | } | |
54a8a78e VZ |
3572 | |
3573 | ||
d606b6e9 BW |
3574 | // create a new tab frame |
3575 | wxTabFrame* new_tabs = new wxTabFrame; | |
3576 | new_tabs->m_rect = wxRect(wxPoint(0,0), split_size); | |
9a29fe70 | 3577 | new_tabs->SetTabCtrlHeight(m_tabCtrlHeight); |
d606b6e9 | 3578 | new_tabs->m_tabs = new wxAuiTabCtrl(this, |
9a29fe70 | 3579 | m_tabIdCounter++, |
d606b6e9 BW |
3580 | wxDefaultPosition, |
3581 | wxDefaultSize, | |
a0c2e4a0 | 3582 | wxNO_BORDER|wxWANTS_CHARS); |
d606b6e9 BW |
3583 | new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); |
3584 | new_tabs->m_tabs->SetFlags(m_flags); | |
3585 | dest_tabs = new_tabs->m_tabs; | |
3586 | ||
3587 | // create a pane info structure with the information | |
3588 | // about where the pane should be added | |
9a29fe70 | 3589 | wxAuiPaneInfo paneInfo = wxAuiPaneInfo().Bottom().CaptionVisible(false); |
d606b6e9 | 3590 | wxPoint mouse_pt; |
54a8a78e | 3591 | |
d606b6e9 BW |
3592 | if (direction == wxLEFT) |
3593 | { | |
9a29fe70 | 3594 | paneInfo.Left(); |
d606b6e9 BW |
3595 | mouse_pt = wxPoint(0, cli_size.y/2); |
3596 | } | |
cedd7b22 | 3597 | else if (direction == wxRIGHT) |
d606b6e9 | 3598 | { |
9a29fe70 | 3599 | paneInfo.Right(); |
d606b6e9 BW |
3600 | mouse_pt = wxPoint(cli_size.x, cli_size.y/2); |
3601 | } | |
cedd7b22 | 3602 | else if (direction == wxTOP) |
d606b6e9 | 3603 | { |
9a29fe70 | 3604 | paneInfo.Top(); |
d606b6e9 BW |
3605 | mouse_pt = wxPoint(cli_size.x/2, 0); |
3606 | } | |
cedd7b22 | 3607 | else if (direction == wxBOTTOM) |
d606b6e9 | 3608 | { |
9a29fe70 | 3609 | paneInfo.Bottom(); |
d606b6e9 BW |
3610 | mouse_pt = wxPoint(cli_size.x/2, cli_size.y); |
3611 | } | |
54a8a78e | 3612 | |
9a29fe70 | 3613 | m_mgr.AddPane(new_tabs, paneInfo, mouse_pt); |
d606b6e9 | 3614 | m_mgr.Update(); |
54a8a78e | 3615 | |
d606b6e9 BW |
3616 | // remove the page from the source tabs |
3617 | wxAuiNotebookPage page_info = src_tabs->GetPage(src_idx); | |
3618 | page_info.active = false; | |
3619 | src_tabs->RemovePage(page_info.window); | |
3620 | if (src_tabs->GetPageCount() > 0) | |
3621 | { | |
3622 | src_tabs->SetActivePage((size_t)0); | |
3623 | src_tabs->DoShowHide(); | |
3624 | src_tabs->Refresh(); | |
3625 | } | |
3626 | ||
3627 | ||
3628 | // add the page to the destination tabs | |
3629 | dest_tabs->InsertPage(page_info.window, page_info, 0); | |
3630 | ||
3631 | if (src_tabs->GetPageCount() == 0) | |
3632 | { | |
3633 | RemoveEmptyTabFrames(); | |
3634 | } | |
3635 | ||
3636 | DoSizing(); | |
3637 | dest_tabs->DoShowHide(); | |
3638 | dest_tabs->Refresh(); | |
3639 | ||
3640 | // force the set selection function reset the selection | |
9a29fe70 | 3641 | m_curPage = -1; |
54a8a78e | 3642 | |
d606b6e9 | 3643 | // set the active page to the one we just split off |
849c353a | 3644 | SetSelectionToPage(page_info); |
54a8a78e | 3645 | |
d606b6e9 BW |
3646 | UpdateHintWindowSize(); |
3647 | } | |
3648 | ||
3649 | ||
9fbb7d80 | 3650 | void wxAuiNotebook::OnSize(wxSizeEvent& evt) |
cd05bf23 | 3651 | { |
9fbb7d80 | 3652 | UpdateHintWindowSize(); |
c58ba15f | 3653 | |
9fbb7d80 | 3654 | evt.Skip(); |
cd05bf23 BW |
3655 | } |
3656 | ||
3c778901 | 3657 | void wxAuiNotebook::OnTabClicked(wxAuiNotebookEvent& evt) |
cd05bf23 | 3658 | { |
cd05bf23 BW |
3659 | wxAuiTabCtrl* ctrl = (wxAuiTabCtrl*)evt.GetEventObject(); |
3660 | wxASSERT(ctrl != NULL); | |
4444d148 | 3661 | |
cd05bf23 BW |
3662 | wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection()); |
3663 | wxASSERT(wnd != NULL); | |
4444d148 | 3664 | |
849c353a | 3665 | SetSelectionToWindow(wnd); |
cd05bf23 BW |
3666 | } |
3667 | ||
3c778901 | 3668 | void wxAuiNotebook::OnTabBgDClick(wxAuiNotebookEvent& WXUNUSED(evt)) |
198be845 JS |
3669 | { |
3670 | // notify owner that the tabbar background has been double-clicked | |
3671 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, m_windowId); | |
3672 | e.SetEventObject(this); | |
3673 | GetEventHandler()->ProcessEvent(e); | |
3674 | } | |
3675 | ||
3c778901 | 3676 | void wxAuiNotebook::OnTabBeginDrag(wxAuiNotebookEvent&) |
cd05bf23 | 3677 | { |
9a29fe70 | 3678 | m_lastDragX = 0; |
cd05bf23 BW |
3679 | } |
3680 | ||
3c778901 | 3681 | void wxAuiNotebook::OnTabDragMotion(wxAuiNotebookEvent& evt) |
cd05bf23 BW |
3682 | { |
3683 | wxPoint screen_pt = ::wxGetMousePosition(); | |
3684 | wxPoint client_pt = ScreenToClient(screen_pt); | |
3685 | wxPoint zero(0,0); | |
4444d148 | 3686 | |
cd05bf23 | 3687 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
08c068a4 | 3688 | wxAuiTabCtrl* dest_tabs = GetTabCtrlFromPoint(client_pt); |
7baac3cb | 3689 | |
08c068a4 | 3690 | if (dest_tabs == src_tabs) |
cd05bf23 | 3691 | { |
3941df70 BW |
3692 | if (src_tabs) |
3693 | { | |
3694 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
3695 | } | |
7baac3cb | 3696 | |
08c068a4 | 3697 | // always hide the hint for inner-tabctrl drag |
cd05bf23 | 3698 | m_mgr.HideHint(); |
7baac3cb | 3699 | |
695c0088 BW |
3700 | // if tab moving is not allowed, leave |
3701 | if (!(m_flags & wxAUI_NB_TAB_MOVE)) | |
3702 | { | |
3703 | return; | |
3704 | } | |
7baac3cb | 3705 | |
08c068a4 BW |
3706 | wxPoint pt = dest_tabs->ScreenToClient(screen_pt); |
3707 | wxWindow* dest_location_tab; | |
7baac3cb | 3708 | |
08c068a4 BW |
3709 | // this is an inner-tab drag/reposition |
3710 | if (dest_tabs->TabHitTest(pt.x, pt.y, &dest_location_tab)) | |
3711 | { | |
3712 | int src_idx = evt.GetSelection(); | |
3713 | int dest_idx = dest_tabs->GetIdxFromWindow(dest_location_tab); | |
7baac3cb | 3714 | |
08c068a4 BW |
3715 | // prevent jumpy drag |
3716 | if ((src_idx == dest_idx) || dest_idx == -1 || | |
9a29fe70 VZ |
3717 | (src_idx > dest_idx && m_lastDragX <= pt.x) || |
3718 | (src_idx < dest_idx && m_lastDragX >= pt.x)) | |
08c068a4 | 3719 | { |
9a29fe70 | 3720 | m_lastDragX = pt.x; |
08c068a4 BW |
3721 | return; |
3722 | } | |
3723 | ||
3724 | ||
3725 | wxWindow* src_tab = dest_tabs->GetWindowFromIdx(src_idx); | |
3726 | dest_tabs->MovePage(src_tab, dest_idx); | |
3727 | dest_tabs->SetActivePage((size_t)dest_idx); | |
3728 | dest_tabs->DoShowHide(); | |
3729 | dest_tabs->Refresh(); | |
9a29fe70 | 3730 | m_lastDragX = pt.x; |
08c068a4 BW |
3731 | |
3732 | } | |
7baac3cb | 3733 | |
cd05bf23 BW |
3734 | return; |
3735 | } | |
4444d148 | 3736 | |
695c0088 | 3737 | |
5d3aeb0f BW |
3738 | // if external drag is allowed, check if the tab is being dragged |
3739 | // over a different wxAuiNotebook control | |
3740 | if (m_flags & wxAUI_NB_TAB_EXTERNAL_MOVE) | |
3741 | { | |
3742 | wxWindow* tab_ctrl = ::wxFindWindowAtPoint(screen_pt); | |
7baac3cb | 3743 | |
87e5fe69 BW |
3744 | // if we aren't over any window, stop here |
3745 | if (!tab_ctrl) | |
3746 | return; | |
7baac3cb | 3747 | |
13d0b605 | 3748 | // make sure we are not over the hint window |
87e5fe69 | 3749 | if (!tab_ctrl->IsKindOf(CLASSINFO(wxFrame))) |
5d3aeb0f | 3750 | { |
13d0b605 | 3751 | while (tab_ctrl) |
5d3aeb0f | 3752 | { |
13d0b605 BW |
3753 | if (tab_ctrl->IsKindOf(CLASSINFO(wxAuiTabCtrl))) |
3754 | break; | |
3755 | tab_ctrl = tab_ctrl->GetParent(); | |
5d3aeb0f | 3756 | } |
7baac3cb | 3757 | |
13d0b605 BW |
3758 | if (tab_ctrl) |
3759 | { | |
3760 | wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent(); | |
7baac3cb | 3761 | |
13d0b605 BW |
3762 | if (nb != this) |
3763 | { | |
87e5fe69 | 3764 | wxRect hint_rect = tab_ctrl->GetClientRect(); |
13d0b605 BW |
3765 | tab_ctrl->ClientToScreen(&hint_rect.x, &hint_rect.y); |
3766 | m_mgr.ShowHint(hint_rect); | |
3767 | return; | |
3768 | } | |
87e5fe69 BW |
3769 | } |
3770 | } | |
cedd7b22 | 3771 | else |
87e5fe69 BW |
3772 | { |
3773 | if (!dest_tabs) | |
3774 | { | |
3775 | // we are either over a hint window, or not over a tab | |
3776 | // window, and there is no where to drag to, so exit | |
3777 | return; | |
13d0b605 | 3778 | } |
5d3aeb0f BW |
3779 | } |
3780 | } | |
3781 | ||
3782 | ||
69685ee0 BW |
3783 | // if there are less than two panes, split can't happen, so leave |
3784 | if (m_tabs.GetPageCount() < 2) | |
3785 | return; | |
7baac3cb | 3786 | |
695c0088 BW |
3787 | // if tab moving is not allowed, leave |
3788 | if (!(m_flags & wxAUI_NB_TAB_SPLIT)) | |
695c0088 | 3789 | return; |
695c0088 | 3790 | |
3941df70 BW |
3791 | |
3792 | if (src_tabs) | |
3793 | { | |
3794 | src_tabs->SetCursor(wxCursor(wxCURSOR_SIZING)); | |
3795 | } | |
7baac3cb VZ |
3796 | |
3797 | ||
08c068a4 | 3798 | if (dest_tabs) |
cd05bf23 | 3799 | { |
08c068a4 | 3800 | wxRect hint_rect = dest_tabs->GetRect(); |
cd05bf23 BW |
3801 | ClientToScreen(&hint_rect.x, &hint_rect.y); |
3802 | m_mgr.ShowHint(hint_rect); | |
3803 | } | |
cedd7b22 | 3804 | else |
cd05bf23 | 3805 | { |
9a29fe70 | 3806 | m_mgr.DrawHintRect(m_dummyWnd, client_pt, zero); |
cd05bf23 BW |
3807 | } |
3808 | } | |
3809 | ||
3810 | ||
3811 | ||
3c778901 | 3812 | void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent& evt) |
cd05bf23 | 3813 | { |
cd05bf23 | 3814 | m_mgr.HideHint(); |
4444d148 | 3815 | |
7baac3cb | 3816 | |
3941df70 | 3817 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
9a83f860 | 3818 | wxCHECK_RET( src_tabs, wxT("no source object?") ); |
54a8a78e VZ |
3819 | |
3820 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
7baac3cb | 3821 | |
cd05bf23 BW |
3822 | // get the mouse position, which will be used to determine the drop point |
3823 | wxPoint mouse_screen_pt = ::wxGetMousePosition(); | |
3824 | wxPoint mouse_client_pt = ScreenToClient(mouse_screen_pt); | |
3825 | ||
3826 | ||
4444d148 | 3827 | |
5d3aeb0f BW |
3828 | // check for an external move |
3829 | if (m_flags & wxAUI_NB_TAB_EXTERNAL_MOVE) | |
cd05bf23 | 3830 | { |
5d3aeb0f | 3831 | wxWindow* tab_ctrl = ::wxFindWindowAtPoint(mouse_screen_pt); |
7baac3cb | 3832 | |
5d3aeb0f | 3833 | while (tab_ctrl) |
c69532f7 | 3834 | { |
5d3aeb0f BW |
3835 | if (tab_ctrl->IsKindOf(CLASSINFO(wxAuiTabCtrl))) |
3836 | break; | |
3837 | tab_ctrl = tab_ctrl->GetParent(); | |
c69532f7 | 3838 | } |
7baac3cb | 3839 | |
5d3aeb0f BW |
3840 | if (tab_ctrl) |
3841 | { | |
3842 | wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent(); | |
7baac3cb | 3843 | |
5d3aeb0f BW |
3844 | if (nb != this) |
3845 | { | |
3846 | // find out from the destination control | |
3847 | // if it's ok to drop this tab here | |
3848 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, m_windowId); | |
3849 | e.SetSelection(evt.GetSelection()); | |
3850 | e.SetOldSelection(evt.GetSelection()); | |
3851 | e.SetEventObject(this); | |
3852 | e.SetDragSource(this); | |
3853 | e.Veto(); // dropping must be explicitly approved by control owner | |
7baac3cb | 3854 | |
5d3aeb0f | 3855 | nb->GetEventHandler()->ProcessEvent(e); |
7baac3cb | 3856 | |
5d3aeb0f BW |
3857 | if (!e.IsAllowed()) |
3858 | { | |
3859 | // no answer or negative answer | |
3860 | m_mgr.HideHint(); | |
3861 | return; | |
3862 | } | |
7baac3cb | 3863 | |
5d3aeb0f BW |
3864 | // drop was allowed |
3865 | int src_idx = evt.GetSelection(); | |
3866 | wxWindow* src_page = src_tabs->GetWindowFromIdx(src_idx); | |
7baac3cb | 3867 | |
884a369a JS |
3868 | // Check that it's not an impossible parent relationship |
3869 | wxWindow* p = nb; | |
3870 | while (p && !p->IsTopLevel()) | |
3871 | { | |
3872 | if (p == src_page) | |
3873 | { | |
3874 | return; | |
3875 | } | |
3876 | p = p->GetParent(); | |
3877 | } | |
3878 | ||
5d3aeb0f BW |
3879 | // get main index of the page |
3880 | int main_idx = m_tabs.GetIdxFromWindow(src_page); | |
9a83f860 | 3881 | wxCHECK_RET( main_idx != wxNOT_FOUND, wxT("no source page?") ); |
849c353a | 3882 | |
7baac3cb | 3883 | |
5d3aeb0f | 3884 | // make a copy of the page info |
849c353a | 3885 | wxAuiNotebookPage page_info = m_tabs.GetPage(main_idx); |
7baac3cb | 3886 | |
5d3aeb0f BW |
3887 | // remove the page from the source notebook |
3888 | RemovePage(main_idx); | |
7baac3cb | 3889 | |
5d3aeb0f BW |
3890 | // reparent the page |
3891 | src_page->Reparent(nb); | |
7baac3cb VZ |
3892 | |
3893 | ||
5d3aeb0f BW |
3894 | // found out the insert idx |
3895 | wxAuiTabCtrl* dest_tabs = (wxAuiTabCtrl*)tab_ctrl; | |
3896 | wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); | |
3897 | ||
3898 | wxWindow* target = NULL; | |
3899 | int insert_idx = -1; | |
3900 | dest_tabs->TabHitTest(pt.x, pt.y, &target); | |
3901 | if (target) | |
3902 | { | |
3903 | insert_idx = dest_tabs->GetIdxFromWindow(target); | |
3904 | } | |
702b1c7e | 3905 | |
7baac3cb | 3906 | |
5d3aeb0f BW |
3907 | // add the page to the new notebook |
3908 | if (insert_idx == -1) | |
3909 | insert_idx = dest_tabs->GetPageCount(); | |
3910 | dest_tabs->InsertPage(page_info.window, page_info, insert_idx); | |
3911 | nb->m_tabs.AddPage(page_info.window, page_info); | |
3912 | ||
3913 | nb->DoSizing(); | |
3914 | dest_tabs->DoShowHide(); | |
3915 | dest_tabs->Refresh(); | |
7baac3cb | 3916 | |
5d3aeb0f | 3917 | // set the selection in the destination tab control |
849c353a | 3918 | nb->SetSelectionToPage(page_info); |
5d3aeb0f | 3919 | |
d92f353c JS |
3920 | // notify owner that the tab has been dragged |
3921 | wxAuiNotebookEvent e2(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, m_windowId); | |
3922 | e2.SetSelection(evt.GetSelection()); | |
3923 | e2.SetOldSelection(evt.GetSelection()); | |
3924 | e2.SetEventObject(this); | |
3925 | GetEventHandler()->ProcessEvent(e2); | |
3926 | ||
5d3aeb0f BW |
3927 | return; |
3928 | } | |
3929 | } | |
cd05bf23 | 3930 | } |
4444d148 WS |
3931 | |
3932 | ||
3933 | ||
5d3aeb0f BW |
3934 | |
3935 | // only perform a tab split if it's allowed | |
54a8a78e VZ |
3936 | wxAuiTabCtrl* dest_tabs = NULL; |
3937 | ||
69685ee0 | 3938 | if ((m_flags & wxAUI_NB_TAB_SPLIT) && m_tabs.GetPageCount() >= 2) |
cd05bf23 | 3939 | { |
5d3aeb0f BW |
3940 | // If the pointer is in an existing tab frame, do a tab insert |
3941 | wxWindow* hit_wnd = ::wxFindWindowAtPoint(mouse_screen_pt); | |
3942 | wxTabFrame* tab_frame = (wxTabFrame*)GetTabFrameFromTabCtrl(hit_wnd); | |
3943 | int insert_idx = -1; | |
3944 | if (tab_frame) | |
3945 | { | |
3946 | dest_tabs = tab_frame->m_tabs; | |
cd05bf23 | 3947 | |
5d3aeb0f BW |
3948 | if (dest_tabs == src_tabs) |
3949 | return; | |
7baac3cb VZ |
3950 | |
3951 | ||
5d3aeb0f BW |
3952 | wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); |
3953 | wxWindow* target = NULL; | |
3954 | dest_tabs->TabHitTest(pt.x, pt.y, &target); | |
3955 | if (target) | |
3956 | { | |
3957 | insert_idx = dest_tabs->GetIdxFromWindow(target); | |
3958 | } | |
3959 | } | |
54a8a78e | 3960 | else |
5d3aeb0f | 3961 | { |
ce15b45f | 3962 | wxPoint zero(0,0); |
9a29fe70 | 3963 | wxRect rect = m_mgr.CalculateHintRect(m_dummyWnd, |
ce15b45f BW |
3964 | mouse_client_pt, |
3965 | zero); | |
3966 | if (rect.IsEmpty()) | |
3967 | { | |
3968 | // there is no suitable drop location here, exit out | |
3969 | return; | |
3970 | } | |
7baac3cb | 3971 | |
5d3aeb0f BW |
3972 | // If there is no tabframe at all, create one |
3973 | wxTabFrame* new_tabs = new wxTabFrame; | |
9fbb7d80 | 3974 | new_tabs->m_rect = wxRect(wxPoint(0,0), CalculateNewSplitSize()); |
9a29fe70 | 3975 | new_tabs->SetTabCtrlHeight(m_tabCtrlHeight); |
5d3aeb0f | 3976 | new_tabs->m_tabs = new wxAuiTabCtrl(this, |
9a29fe70 | 3977 | m_tabIdCounter++, |
5d3aeb0f BW |
3978 | wxDefaultPosition, |
3979 | wxDefaultSize, | |
a0c2e4a0 | 3980 | wxNO_BORDER|wxWANTS_CHARS); |
b0d17f7c | 3981 | new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); |
5d3aeb0f BW |
3982 | new_tabs->m_tabs->SetFlags(m_flags); |
3983 | ||
3984 | m_mgr.AddPane(new_tabs, | |
3985 | wxAuiPaneInfo().Bottom().CaptionVisible(false), | |
3986 | mouse_client_pt); | |
3987 | m_mgr.Update(); | |
3988 | dest_tabs = new_tabs->m_tabs; | |
3989 | } | |
4444d148 WS |
3990 | |
3991 | ||
4444d148 | 3992 | |
5d3aeb0f BW |
3993 | // remove the page from the source tabs |
3994 | wxAuiNotebookPage page_info = src_tabs->GetPage(evt.GetSelection()); | |
3995 | page_info.active = false; | |
3996 | src_tabs->RemovePage(page_info.window); | |
3997 | if (src_tabs->GetPageCount() > 0) | |
3998 | { | |
3999 | src_tabs->SetActivePage((size_t)0); | |
4000 | src_tabs->DoShowHide(); | |
4001 | src_tabs->Refresh(); | |
4002 | } | |
4444d148 | 4003 | |
cd05bf23 | 4004 | |
5d3aeb0f BW |
4005 | |
4006 | // add the page to the destination tabs | |
4007 | if (insert_idx == -1) | |
4008 | insert_idx = dest_tabs->GetPageCount(); | |
4009 | dest_tabs->InsertPage(page_info.window, page_info, insert_idx); | |
4010 | ||
4011 | if (src_tabs->GetPageCount() == 0) | |
4012 | { | |
4013 | RemoveEmptyTabFrames(); | |
4014 | } | |
4015 | ||
4016 | DoSizing(); | |
4017 | dest_tabs->DoShowHide(); | |
4018 | dest_tabs->Refresh(); | |
4019 | ||
68fd4f2c | 4020 | // force the set selection function reset the selection |
9a29fe70 | 4021 | m_curPage = -1; |
c58ba15f | 4022 | |
68fd4f2c | 4023 | // set the active page to the one we just split off |
849c353a | 4024 | SetSelectionToPage(page_info); |
c58ba15f | 4025 | |
9fbb7d80 | 4026 | UpdateHintWindowSize(); |
5d3aeb0f | 4027 | } |
d92f353c JS |
4028 | |
4029 | // notify owner that the tab has been dragged | |
4030 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, m_windowId); | |
4031 | e.SetSelection(evt.GetSelection()); | |
4032 | e.SetOldSelection(evt.GetSelection()); | |
4033 | e.SetEventObject(this); | |
4034 | GetEventHandler()->ProcessEvent(e); | |
cd05bf23 BW |
4035 | } |
4036 | ||
3941df70 BW |
4037 | |
4038 | ||
2bd82d72 VZ |
4039 | void wxAuiNotebook::OnTabCancelDrag(wxAuiNotebookEvent& command_evt) |
4040 | { | |
4041 | wxAuiNotebookEvent& evt = (wxAuiNotebookEvent&)command_evt; | |
4042 | ||
4043 | m_mgr.HideHint(); | |
4044 | ||
4045 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
2e92ad1b | 4046 | wxCHECK_RET( src_tabs, wxT("no source object?") ); |
2bd82d72 VZ |
4047 | |
4048 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
4049 | } | |
4050 | ||
a3a5df9d | 4051 | wxAuiTabCtrl* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint& pt) |
cd05bf23 BW |
4052 | { |
4053 | // if we've just removed the last tab from the source | |
4054 | // tab set, the remove the tab control completely | |
a3a5df9d | 4055 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
4056 | size_t i, pane_count = all_panes.GetCount(); |
4057 | for (i = 0; i < pane_count; ++i) | |
4058 | { | |
4059 | if (all_panes.Item(i).name == wxT("dummy")) | |
4060 | continue; | |
4444d148 | 4061 | |
cd05bf23 | 4062 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
22a35096 | 4063 | if (tabframe->m_tab_rect.Contains(pt)) |
cd05bf23 BW |
4064 | return tabframe->m_tabs; |
4065 | } | |
4444d148 | 4066 | |
cd05bf23 BW |
4067 | return NULL; |
4068 | } | |
4069 | ||
a3a5df9d | 4070 | wxWindow* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow* tab_ctrl) |
cd05bf23 BW |
4071 | { |
4072 | // if we've just removed the last tab from the source | |
4073 | // tab set, the remove the tab control completely | |
a3a5df9d | 4074 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
4075 | size_t i, pane_count = all_panes.GetCount(); |
4076 | for (i = 0; i < pane_count; ++i) | |
4077 | { | |
4078 | if (all_panes.Item(i).name == wxT("dummy")) | |
4079 | continue; | |
4444d148 | 4080 | |
cd05bf23 BW |
4081 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
4082 | if (tabframe->m_tabs == tab_ctrl) | |
4083 | { | |
4084 | return tabframe; | |
4085 | } | |
4086 | } | |
4444d148 | 4087 | |
cd05bf23 BW |
4088 | return NULL; |
4089 | } | |
4090 | ||
a3a5df9d | 4091 | void wxAuiNotebook::RemoveEmptyTabFrames() |
cd05bf23 | 4092 | { |
cd05bf23 BW |
4093 | // if we've just removed the last tab from the source |
4094 | // tab set, the remove the tab control completely | |
a3a5df9d | 4095 | wxAuiPaneInfoArray all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
4096 | size_t i, pane_count = all_panes.GetCount(); |
4097 | for (i = 0; i < pane_count; ++i) | |
4098 | { | |
4099 | if (all_panes.Item(i).name == wxT("dummy")) | |
4100 | continue; | |
4101 | ||
4102 | wxTabFrame* tab_frame = (wxTabFrame*)all_panes.Item(i).window; | |
4103 | if (tab_frame->m_tabs->GetPageCount() == 0) | |
4104 | { | |
4105 | m_mgr.DetachPane(tab_frame); | |
4444d148 | 4106 | |
cd05bf23 BW |
4107 | // use pending delete because sometimes during |
4108 | // window closing, refreshs are pending | |
4109 | if (!wxPendingDelete.Member(tab_frame->m_tabs)) | |
4444d148 | 4110 | wxPendingDelete.Append(tab_frame->m_tabs); |
cedd7b22 | 4111 | |
13aaa50f | 4112 | tab_frame->m_tabs = NULL; |
4444d148 | 4113 | |
cd05bf23 | 4114 | delete tab_frame; |
cd05bf23 BW |
4115 | } |
4116 | } | |
4444d148 WS |
4117 | |
4118 | ||
cd05bf23 BW |
4119 | // check to see if there is still a center pane; |
4120 | // if there isn't, make a frame the center pane | |
a3a5df9d | 4121 | wxAuiPaneInfoArray panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
4122 | pane_count = panes.GetCount(); |
4123 | wxWindow* first_good = NULL; | |
4124 | bool center_found = false; | |
4125 | for (i = 0; i < pane_count; ++i) | |
4126 | { | |
4127 | if (panes.Item(i).name == wxT("dummy")) | |
4128 | continue; | |
4129 | if (panes.Item(i).dock_direction == wxAUI_DOCK_CENTRE) | |
4130 | center_found = true; | |
4131 | if (!first_good) | |
4132 | first_good = panes.Item(i).window; | |
4133 | } | |
4134 | ||
4135 | if (!center_found && first_good) | |
4136 | { | |
4137 | m_mgr.GetPane(first_good).Centre(); | |
cd05bf23 BW |
4138 | } |
4139 | ||
18b40f30 JS |
4140 | if (!m_isBeingDeleted) |
4141 | m_mgr.Update(); | |
cd05bf23 BW |
4142 | } |
4143 | ||
5bf3f27f | 4144 | void wxAuiNotebook::OnChildFocusNotebook(wxChildFocusEvent& evt) |
cd05bf23 | 4145 | { |
d4f4657a VZ |
4146 | evt.Skip(); |
4147 | ||
d16619f8 BW |
4148 | // if we're dragging a tab, don't change the current selection. |
4149 | // This code prevents a bug that used to happen when the hint window | |
4150 | // was hidden. In the bug, the focus would return to the notebook | |
4151 | // child, which would then enter this handler and call | |
4152 | // SetSelection, which is not desired turn tab dragging. | |
cedd7b22 | 4153 | |
d16619f8 BW |
4154 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
4155 | size_t i, pane_count = all_panes.GetCount(); | |
4156 | for (i = 0; i < pane_count; ++i) | |
4157 | { | |
4158 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
4159 | if (pane.name == wxT("dummy")) | |
4160 | continue; | |
4161 | wxTabFrame* tabframe = (wxTabFrame*)pane.window; | |
4162 | if (tabframe->m_tabs->IsDragging()) | |
4163 | return; | |
4164 | } | |
4165 | ||
4166 | ||
4167 | // change the tab selection to the child | |
4168 | // which was focused | |
cd05bf23 | 4169 | int idx = m_tabs.GetIdxFromWindow(evt.GetWindow()); |
9a29fe70 | 4170 | if (idx != -1 && idx != m_curPage) |
cd05bf23 | 4171 | { |
4444d148 | 4172 | SetSelection(idx); |
cd05bf23 BW |
4173 | } |
4174 | } | |
4175 | ||
5bf3f27f | 4176 | void wxAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent& event) |
a0c2e4a0 JS |
4177 | { |
4178 | if ( event.IsWindowChange() ) { | |
4179 | // change pages | |
4180 | // FIXME: the problem with this is that if we have a split notebook, | |
4181 | // we selection may go all over the place. | |
4182 | AdvanceSelection(event.GetDirection()); | |
4183 | } | |
4184 | else { | |
4185 | // we get this event in 3 cases | |
4186 | // | |
4187 | // a) one of our pages might have generated it because the user TABbed | |
4188 | // out from it in which case we should propagate the event upwards and | |
4189 | // our parent will take care of setting the focus to prev/next sibling | |
4190 | // | |
4191 | // or | |
4192 | // | |
4193 | // b) the parent panel wants to give the focus to us so that we | |
4194 | // forward it to our selected page. We can't deal with this in | |
4195 | // OnSetFocus() because we don't know which direction the focus came | |
4196 | // from in this case and so can't choose between setting the focus to | |
4197 | // first or last panel child | |
4198 | // | |
4199 | // or | |
4200 | // | |
4201 | // c) we ourselves (see MSWTranslateMessage) generated the event | |
4202 | // | |
4203 | wxWindow * const parent = GetParent(); | |
4204 | ||
4205 | // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE | |
4206 | const bool isFromParent = event.GetEventObject() == (wxObject*) parent; | |
4207 | const bool isFromSelf = event.GetEventObject() == (wxObject*) this; | |
4208 | ||
4209 | if ( isFromParent || isFromSelf ) | |
4210 | { | |
4211 | // no, it doesn't come from child, case (b) or (c): forward to a | |
4212 | // page but only if direction is backwards (TAB) or from ourselves, | |
4213 | if ( GetSelection() != wxNOT_FOUND && | |
4214 | (!event.GetDirection() || isFromSelf) ) | |
4215 | { | |
4216 | // so that the page knows that the event comes from it's parent | |
4217 | // and is being propagated downwards | |
4218 | event.SetEventObject(this); | |
4219 | ||
4220 | wxWindow *page = GetPage(GetSelection()); | |
4221 | if ( !page->GetEventHandler()->ProcessEvent(event) ) | |
4222 | { | |
4223 | page->SetFocus(); | |
4224 | } | |
4225 | //else: page manages focus inside it itself | |
4226 | } | |
4227 | else // otherwise set the focus to the notebook itself | |
4228 | { | |
4229 | SetFocus(); | |
4230 | } | |
4231 | } | |
4232 | else | |
4233 | { | |
4234 | // it comes from our child, case (a), pass to the parent, but only | |
4235 | // if the direction is forwards. Otherwise set the focus to the | |
4236 | // notebook itself. The notebook is always the 'first' control of a | |
4237 | // page. | |
4238 | if ( !event.GetDirection() ) | |
4239 | { | |
4240 | SetFocus(); | |
4241 | } | |
4242 | else if ( parent ) | |
4243 | { | |
4244 | event.SetCurrentFocus(this); | |
4245 | parent->GetEventHandler()->ProcessEvent(event); | |
4246 | } | |
4247 | } | |
4248 | } | |
4249 | } | |
cd05bf23 | 4250 | |
3c778901 | 4251 | void wxAuiNotebook::OnTabButton(wxAuiNotebookEvent& evt) |
cd05bf23 | 4252 | { |
cd05bf23 | 4253 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
4444d148 | 4254 | |
cd05bf23 | 4255 | int button_id = evt.GetInt(); |
4444d148 | 4256 | |
4953f8cf | 4257 | if (button_id == wxAUI_BUTTON_CLOSE) |
cd05bf23 | 4258 | { |
9b362935 | 4259 | int selection = evt.GetSelection(); |
4444d148 | 4260 | |
94473fa8 BW |
4261 | if (selection == -1) |
4262 | { | |
4263 | // if the close button is to the right, use the active | |
4264 | // page selection to determine which page to close | |
b27fdc38 | 4265 | selection = tabs->GetActivePage(); |
94473fa8 | 4266 | } |
884a369a | 4267 | |
cd05bf23 BW |
4268 | if (selection != -1) |
4269 | { | |
4270 | wxWindow* close_wnd = tabs->GetWindowFromIdx(selection); | |
4444d148 | 4271 | |
3fd8c988 BW |
4272 | // ask owner if it's ok to close the tab |
4273 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, m_windowId); | |
4274 | e.SetSelection(m_tabs.GetIdxFromWindow(close_wnd)); | |
d92f353c JS |
4275 | const int idx = m_tabs.GetIdxFromWindow(close_wnd); |
4276 | e.SetSelection(idx); | |
3fd8c988 BW |
4277 | e.SetOldSelection(evt.GetSelection()); |
4278 | e.SetEventObject(this); | |
7ebc40e8 | 4279 | GetEventHandler()->ProcessEvent(e); |
3fd8c988 BW |
4280 | if (!e.IsAllowed()) |
4281 | return; | |
4282 | ||
4283 | ||
89272c55 | 4284 | #if wxUSE_MDI |
a3a5df9d | 4285 | if (close_wnd->IsKindOf(CLASSINFO(wxAuiMDIChildFrame))) |
cd05bf23 BW |
4286 | { |
4287 | close_wnd->Close(); | |
4288 | } | |
760fdb67 | 4289 | else |
89272c55 | 4290 | #endif |
cd05bf23 BW |
4291 | { |
4292 | int main_idx = m_tabs.GetIdxFromWindow(close_wnd); | |
9a83f860 | 4293 | wxCHECK_RET( main_idx != wxNOT_FOUND, wxT("no page to delete?") ); |
760fdb67 | 4294 | |
cd05bf23 BW |
4295 | DeletePage(main_idx); |
4296 | } | |
d92f353c JS |
4297 | |
4298 | // notify owner that the tab has been closed | |
4299 | wxAuiNotebookEvent e2(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, m_windowId); | |
4300 | e2.SetSelection(idx); | |
4301 | e2.SetEventObject(this); | |
4302 | GetEventHandler()->ProcessEvent(e2); | |
cd05bf23 BW |
4303 | } |
4304 | } | |
4305 | } | |
4306 | ||
69f5e420 | 4307 | |
3c778901 | 4308 | void wxAuiNotebook::OnTabMiddleDown(wxAuiNotebookEvent& evt) |
69f5e420 BW |
4309 | { |
4310 | // patch event through to owner | |
4311 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4312 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4313 | ||
4314 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, m_windowId); | |
4315 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4316 | e.SetEventObject(this); | |
4317 | GetEventHandler()->ProcessEvent(e); | |
4318 | } | |
4319 | ||
3c778901 | 4320 | void wxAuiNotebook::OnTabMiddleUp(wxAuiNotebookEvent& evt) |
69f5e420 BW |
4321 | { |
4322 | // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle | |
4323 | // click should act like a tab close action. However, first | |
4324 | // give the owner an opportunity to handle the middle up event | |
4325 | // for custom action | |
cedd7b22 | 4326 | |
69f5e420 BW |
4327 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
4328 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4329 | ||
4330 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, m_windowId); | |
4331 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4332 | e.SetEventObject(this); | |
4333 | if (GetEventHandler()->ProcessEvent(e)) | |
4334 | return; | |
4335 | if (!e.IsAllowed()) | |
4336 | return; | |
cedd7b22 | 4337 | |
69f5e420 BW |
4338 | // check if we are supposed to close on middle-up |
4339 | if ((m_flags & wxAUI_NB_MIDDLE_CLICK_CLOSE) == 0) | |
4340 | return; | |
cedd7b22 | 4341 | |
69f5e420 BW |
4342 | // simulate the user pressing the close button on the tab |
4343 | evt.SetInt(wxAUI_BUTTON_CLOSE); | |
4344 | OnTabButton(evt); | |
4345 | } | |
4346 | ||
3c778901 | 4347 | void wxAuiNotebook::OnTabRightDown(wxAuiNotebookEvent& evt) |
69f5e420 BW |
4348 | { |
4349 | // patch event through to owner | |
4350 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4351 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4352 | ||
4353 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, m_windowId); | |
4354 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4355 | e.SetEventObject(this); | |
4356 | GetEventHandler()->ProcessEvent(e); | |
4357 | } | |
4358 | ||
3c778901 | 4359 | void wxAuiNotebook::OnTabRightUp(wxAuiNotebookEvent& evt) |
69f5e420 BW |
4360 | { |
4361 | // patch event through to owner | |
4362 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
4363 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
4364 | ||
4365 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, m_windowId); | |
4366 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
4367 | e.SetEventObject(this); | |
4368 | GetEventHandler()->ProcessEvent(e); | |
4369 | } | |
4370 | ||
fc17828a JS |
4371 | // Sets the normal font |
4372 | void wxAuiNotebook::SetNormalFont(const wxFont& font) | |
4373 | { | |
9a29fe70 | 4374 | m_normalFont = font; |
fc17828a JS |
4375 | GetArtProvider()->SetNormalFont(font); |
4376 | } | |
4377 | ||
4378 | // Sets the selected tab font | |
4379 | void wxAuiNotebook::SetSelectedFont(const wxFont& font) | |
4380 | { | |
9a29fe70 | 4381 | m_selectedFont = font; |
fc17828a JS |
4382 | GetArtProvider()->SetSelectedFont(font); |
4383 | } | |
4384 | ||
4385 | // Sets the measuring font | |
4386 | void wxAuiNotebook::SetMeasuringFont(const wxFont& font) | |
4387 | { | |
4388 | GetArtProvider()->SetMeasuringFont(font); | |
4389 | } | |
4390 | ||
4391 | // Sets the tab font | |
4392 | bool wxAuiNotebook::SetFont(const wxFont& font) | |
4393 | { | |
4394 | wxControl::SetFont(font); | |
cd05bf23 | 4395 | |
fc17828a JS |
4396 | wxFont normalFont(font); |
4397 | wxFont selectedFont(normalFont); | |
4398 | selectedFont.SetWeight(wxBOLD); | |
4399 | ||
4400 | SetNormalFont(normalFont); | |
4401 | SetSelectedFont(selectedFont); | |
4402 | SetMeasuringFont(selectedFont); | |
4403 | ||
4404 | return true; | |
4405 | } | |
4406 | ||
4407 | // Gets the tab control height | |
4408 | int wxAuiNotebook::GetTabCtrlHeight() const | |
4409 | { | |
9a29fe70 | 4410 | return m_tabCtrlHeight; |
fc17828a JS |
4411 | } |
4412 | ||
4413 | // Gets the height of the notebook for a given page height | |
4414 | int wxAuiNotebook::GetHeightForPageHeight(int pageHeight) | |
4415 | { | |
4416 | UpdateTabCtrlHeight(); | |
4417 | ||
4418 | int tabCtrlHeight = GetTabCtrlHeight(); | |
4419 | int decorHeight = 2; | |
4420 | return tabCtrlHeight + pageHeight + decorHeight; | |
4421 | } | |
cd05bf23 | 4422 | |
a0c2e4a0 JS |
4423 | // Advances the selection, generation page selection events |
4424 | void wxAuiNotebook::AdvanceSelection(bool forward) | |
4425 | { | |
4426 | if (GetPageCount() <= 1) | |
4427 | return; | |
4428 | ||
4429 | int currentSelection = GetSelection(); | |
4430 | ||
4431 | if (forward) | |
4432 | { | |
4433 | if (currentSelection == (int) (GetPageCount() - 1)) | |
4434 | return; | |
4435 | else if (currentSelection == -1) | |
4436 | currentSelection = 0; | |
4437 | else | |
4438 | currentSelection ++; | |
4439 | } | |
4440 | else | |
4441 | { | |
4442 | if (currentSelection <= 0) | |
4443 | return; | |
4444 | else | |
4445 | currentSelection --; | |
4446 | } | |
4447 | ||
4448 | SetSelection(currentSelection); | |
4449 | } | |
4450 | ||
4451 | // Shows the window menu | |
4452 | bool wxAuiNotebook::ShowWindowMenu() | |
4453 | { | |
4454 | wxAuiTabCtrl* tabCtrl = GetActiveTabCtrl(); | |
4455 | ||
4456 | int idx = tabCtrl->GetArtProvider()->ShowDropDown(tabCtrl, tabCtrl->GetPages(), tabCtrl->GetActivePage()); | |
4457 | ||
4458 | if (idx != -1) | |
4459 | { | |
4460 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, tabCtrl->GetId()); | |
4461 | e.SetSelection(idx); | |
4462 | e.SetOldSelection(tabCtrl->GetActivePage()); | |
4463 | e.SetEventObject(tabCtrl); | |
4464 | GetEventHandler()->ProcessEvent(e); | |
4465 | ||
4466 | return true; | |
4467 | } | |
4468 | else | |
4469 | return false; | |
4470 | } | |
cd05bf23 | 4471 | |
64178c36 JS |
4472 | void wxAuiNotebook::Thaw() |
4473 | { | |
4474 | DoSizing(); | |
4475 | ||
4476 | wxControl::Thaw(); | |
4477 | } | |
4478 | ||
873ff54b SL |
4479 | void wxAuiNotebook::SetPageSize (const wxSize& WXUNUSED(size)) |
4480 | { | |
4481 | wxFAIL_MSG("Not implemented for wxAuiNotebook"); | |
4482 | } | |
4483 | ||
4484 | int wxAuiNotebook::HitTest (const wxPoint& WXUNUSED(pt), long* WXUNUSED(flags)) const | |
4485 | { | |
4486 | wxFAIL_MSG("Not implemented for wxAuiNotebook"); | |
4487 | return wxNOT_FOUND; | |
4488 | } | |
4489 | ||
4490 | int wxAuiNotebook::GetPageImage(size_t WXUNUSED(n)) const | |
4491 | { | |
4492 | wxFAIL_MSG("Not implemented for wxAuiNotebook"); | |
4493 | return -1; | |
4494 | } | |
4495 | ||
4496 | bool wxAuiNotebook::SetPageImage(size_t n, int imageId) | |
4497 | { | |
4498 | return SetPageBitmap(n, GetImageList()->GetBitmap(imageId)); | |
4499 | } | |
4500 | ||
4501 | wxWindow* wxAuiNotebook::GetCurrentPage () const | |
4502 | { | |
b98eb28a VZ |
4503 | const int sel = GetSelection(); |
4504 | ||
4505 | return sel == wxNOT_FOUND ? NULL : GetPage(sel); | |
873ff54b SL |
4506 | } |
4507 | ||
4508 | int wxAuiNotebook::ChangeSelection(size_t n) | |
4509 | { | |
4510 | return DoModifySelection(n, false); | |
4511 | } | |
4512 | ||
4513 | bool wxAuiNotebook::AddPage(wxWindow *page, const wxString &text, bool select, | |
4514 | int imageId) | |
4515 | { | |
4516 | if(HasImageList()) | |
4517 | { | |
4518 | return AddPage(page, text, select, GetImageList()->GetBitmap(imageId)); | |
4519 | } | |
4520 | else | |
4521 | { | |
4522 | return AddPage(page, text, select, wxNullBitmap); | |
4523 | } | |
4524 | } | |
4525 | ||
4526 | bool wxAuiNotebook::DeleteAllPages() | |
4527 | { | |
4528 | size_t count = GetPageCount(); | |
4529 | for(size_t i = 0; i < count; i++) | |
4530 | { | |
4531 | DeletePage(0); | |
4532 | } | |
4533 | return true; | |
4534 | } | |
4535 | ||
4536 | bool wxAuiNotebook::InsertPage(size_t index, wxWindow *page, | |
4537 | const wxString &text, bool select, | |
4538 | int imageId) | |
4539 | { | |
4540 | if(HasImageList()) | |
4541 | { | |
4542 | return InsertPage(index, page, text, select, | |
4543 | GetImageList()->GetBitmap(imageId)); | |
4544 | } | |
4545 | else | |
4546 | { | |
4547 | return InsertPage(index, page, text, select, wxNullBitmap); | |
4548 | } | |
4549 | } | |
4550 | ||
4551 | int wxAuiNotebook::DoModifySelection(size_t n, bool events) | |
4552 | { | |
9a29fe70 | 4553 | wxWindow* wnd = m_tabs.GetWindowFromIdx(n); |
873ff54b | 4554 | if (!wnd) |
9a29fe70 | 4555 | return m_curPage; |
873ff54b SL |
4556 | |
4557 | // don't change the page unless necessary; | |
4558 | // however, clicking again on a tab should give it the focus. | |
9a29fe70 | 4559 | if ((int)n == m_curPage) |
873ff54b SL |
4560 | { |
4561 | wxAuiTabCtrl* ctrl; | |
4562 | int ctrl_idx; | |
4563 | if (FindTab(wnd, &ctrl, &ctrl_idx)) | |
4564 | { | |
4565 | if (FindFocus() != ctrl) | |
4566 | ctrl->SetFocus(); | |
4567 | } | |
9a29fe70 | 4568 | return m_curPage; |
873ff54b SL |
4569 | } |
4570 | ||
4571 | bool vetoed = false; | |
4572 | ||
4573 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
4574 | ||
4575 | if(events) | |
4576 | { | |
4577 | evt.SetSelection(n); | |
9a29fe70 | 4578 | evt.SetOldSelection(m_curPage); |
873ff54b SL |
4579 | evt.SetEventObject(this); |
4580 | GetEventHandler()->ProcessEvent(evt); | |
4581 | vetoed = !evt.IsAllowed(); | |
4582 | } | |
4583 | ||
4584 | if (!vetoed) | |
4585 | { | |
9a29fe70 VZ |
4586 | int old_curpage = m_curPage; |
4587 | m_curPage = n; | |
873ff54b SL |
4588 | |
4589 | // program allows the page change | |
4590 | if(events) | |
4591 | { | |
4592 | evt.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED); | |
4593 | (void)GetEventHandler()->ProcessEvent(evt); | |
4594 | } | |
4595 | ||
4596 | ||
4597 | wxAuiTabCtrl* ctrl; | |
4598 | int ctrl_idx; | |
4599 | if (FindTab(wnd, &ctrl, &ctrl_idx)) | |
4600 | { | |
4601 | m_tabs.SetActivePage(wnd); | |
4602 | ||
4603 | ctrl->SetActivePage(ctrl_idx); | |
4604 | DoSizing(); | |
4605 | ctrl->DoShowHide(); | |
4606 | ||
4607 | ctrl->MakeTabVisible(ctrl_idx, ctrl); | |
4608 | ||
4609 | // set fonts | |
4610 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
4611 | size_t i, pane_count = all_panes.GetCount(); | |
4612 | for (i = 0; i < pane_count; ++i) | |
4613 | { | |
4614 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
4615 | if (pane.name == wxT("dummy")) | |
4616 | continue; | |
4617 | wxAuiTabCtrl* tabctrl = ((wxTabFrame*)pane.window)->m_tabs; | |
4618 | if (tabctrl != ctrl) | |
9a29fe70 | 4619 | tabctrl->SetSelectedFont(m_normalFont); |
873ff54b | 4620 | else |
9a29fe70 | 4621 | tabctrl->SetSelectedFont(m_selectedFont); |
873ff54b SL |
4622 | tabctrl->Refresh(); |
4623 | } | |
4624 | ||
4625 | // Set the focus to the page if we're not currently focused on the tab. | |
4626 | // This is Firefox-like behaviour. | |
4627 | if (wnd->IsShownOnScreen() && FindFocus() != ctrl) | |
4628 | wnd->SetFocus(); | |
4629 | ||
4630 | return old_curpage; | |
4631 | } | |
4632 | } | |
4633 | ||
9a29fe70 | 4634 | return m_curPage; |
873ff54b SL |
4635 | } |
4636 | ||
4637 | ||
cd05bf23 | 4638 | #endif // wxUSE_AUI |