]>
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 | |
4758baf5 | 5 | // Modified by: Jens Lody |
cd05bf23 BW |
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" |
25d7cf54 PC |
27 | #include "wx/dcclient.h" |
28 | #include "wx/dcmemory.h" | |
cd05bf23 BW |
29 | #endif |
30 | ||
4444d148 | 31 | #include "wx/aui/tabmdi.h" |
a0c2e4a0 | 32 | |
a51dc103 | 33 | #ifdef __WXMAC__ |
efdea9c3 | 34 | #include "wx/osx/private.h" |
a51dc103 JS |
35 | #endif |
36 | ||
cd05bf23 BW |
37 | #include "wx/arrimpl.cpp" |
38 | WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray) | |
39 | WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray) | |
40 | ||
3c778901 VZ |
41 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEvent); |
42 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEvent); | |
43 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEvent); | |
44 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEvent); | |
45 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, wxAuiNotebookEvent); | |
46 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, wxAuiNotebookEvent); | |
47 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEvent); | |
2bd82d72 | 48 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, wxAuiNotebookEvent); |
3c778901 VZ |
49 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, wxAuiNotebookEvent); |
50 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, wxAuiNotebookEvent); | |
51 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEvent); | |
52 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, wxAuiNotebookEvent); | |
53 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, wxAuiNotebookEvent); | |
54 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, wxAuiNotebookEvent); | |
55 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, wxAuiNotebookEvent); | |
56 | wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, wxAuiNotebookEvent); | |
cd05bf23 | 57 | |
0ce53f32 | 58 | IMPLEMENT_CLASS(wxAuiNotebook, wxControl) |
5d3aeb0f | 59 | IMPLEMENT_CLASS(wxAuiTabCtrl, wxControl) |
873ff54b | 60 | IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent, wxBookCtrlEvent) |
cd05bf23 | 61 | |
cd05bf23 | 62 | |
3f69756e BW |
63 | // -- wxAuiTabContainer class implementation -- |
64 | ||
65 | ||
66 | // wxAuiTabContainer is a class which contains information about each | |
67 | // tab. It also can render an entire tab control to a specified DC. | |
68 | // It's not a window class itself, because this code will be used by | |
69 | // the wxFrameMananger, where it is disadvantageous to have separate | |
70 | // windows for each tab control in the case of "docked tabs" | |
71 | ||
72 | // A derived class, wxAuiTabCtrl, is an actual wxWindow-derived window | |
73 | // which can be used as a tab control in the normal sense. | |
74 | ||
75 | ||
76 | wxAuiTabContainer::wxAuiTabContainer() | |
77 | { | |
9a29fe70 | 78 | m_tabOffset = 0; |
702b1c7e | 79 | m_flags = 0; |
a3a5df9d | 80 | m_art = new wxAuiDefaultTabArt; |
7baac3cb VZ |
81 | |
82 | AddButton(wxAUI_BUTTON_LEFT, wxLEFT); | |
01372b8f BW |
83 | AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT); |
84 | AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT); | |
4953f8cf | 85 | AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT); |
3f69756e BW |
86 | } |
87 | ||
fe498448 BW |
88 | wxAuiTabContainer::~wxAuiTabContainer() |
89 | { | |
3f69756e BW |
90 | delete m_art; |
91 | } | |
92 | ||
a3a5df9d | 93 | void wxAuiTabContainer::SetArtProvider(wxAuiTabArt* art) |
3f69756e BW |
94 | { |
95 | delete m_art; | |
96 | m_art = art; | |
7baac3cb | 97 | |
b0d17f7c BW |
98 | if (m_art) |
99 | { | |
100 | m_art->SetFlags(m_flags); | |
101 | } | |
3f69756e BW |
102 | } |
103 | ||
e0dc13d4 | 104 | wxAuiTabArt* wxAuiTabContainer::GetArtProvider() const |
3f69756e BW |
105 | { |
106 | return m_art; | |
fe498448 BW |
107 | } |
108 | ||
702b1c7e BW |
109 | void wxAuiTabContainer::SetFlags(unsigned int flags) |
110 | { | |
111 | m_flags = flags; | |
7baac3cb | 112 | |
41b76acd | 113 | // check for new close button settings |
7baac3cb | 114 | RemoveButton(wxAUI_BUTTON_LEFT); |
01372b8f BW |
115 | RemoveButton(wxAUI_BUTTON_RIGHT); |
116 | RemoveButton(wxAUI_BUTTON_WINDOWLIST); | |
41b76acd | 117 | RemoveButton(wxAUI_BUTTON_CLOSE); |
7baac3cb VZ |
118 | |
119 | ||
01372b8f BW |
120 | if (flags & wxAUI_NB_SCROLL_BUTTONS) |
121 | { | |
7baac3cb | 122 | AddButton(wxAUI_BUTTON_LEFT, wxLEFT); |
01372b8f BW |
123 | AddButton(wxAUI_BUTTON_RIGHT, wxRIGHT); |
124 | } | |
125 | ||
126 | if (flags & wxAUI_NB_WINDOWLIST_BUTTON) | |
127 | { | |
128 | AddButton(wxAUI_BUTTON_WINDOWLIST, wxRIGHT); | |
129 | } | |
7baac3cb | 130 | |
41b76acd BW |
131 | if (flags & wxAUI_NB_CLOSE_BUTTON) |
132 | { | |
133 | AddButton(wxAUI_BUTTON_CLOSE, wxRIGHT); | |
134 | } | |
7baac3cb | 135 | |
b0d17f7c BW |
136 | if (m_art) |
137 | { | |
138 | m_art->SetFlags(m_flags); | |
139 | } | |
702b1c7e BW |
140 | } |
141 | ||
142 | unsigned int wxAuiTabContainer::GetFlags() const | |
143 | { | |
144 | return m_flags; | |
145 | } | |
146 | ||
147 | ||
cd05bf23 BW |
148 | void wxAuiTabContainer::SetNormalFont(const wxFont& font) |
149 | { | |
3f69756e | 150 | m_art->SetNormalFont(font); |
cd05bf23 BW |
151 | } |
152 | ||
153 | void wxAuiTabContainer::SetSelectedFont(const wxFont& font) | |
154 | { | |
3f69756e | 155 | m_art->SetSelectedFont(font); |
cd05bf23 BW |
156 | } |
157 | ||
158 | void wxAuiTabContainer::SetMeasuringFont(const wxFont& font) | |
159 | { | |
3f69756e | 160 | m_art->SetMeasuringFont(font); |
cd05bf23 BW |
161 | } |
162 | ||
ceb9b8db VZ |
163 | void wxAuiTabContainer::SetColour(const wxColour& colour) |
164 | { | |
165 | m_art->SetColour(colour); | |
166 | } | |
167 | ||
168 | void wxAuiTabContainer::SetActiveColour(const wxColour& colour) | |
169 | { | |
170 | m_art->SetActiveColour(colour); | |
171 | } | |
172 | ||
cd05bf23 BW |
173 | void wxAuiTabContainer::SetRect(const wxRect& rect) |
174 | { | |
175 | m_rect = rect; | |
7baac3cb | 176 | |
b0d17f7c BW |
177 | if (m_art) |
178 | { | |
179 | m_art->SetSizingInfo(rect.GetSize(), m_pages.GetCount()); | |
180 | } | |
cd05bf23 BW |
181 | } |
182 | ||
183 | bool wxAuiTabContainer::AddPage(wxWindow* page, | |
184 | const wxAuiNotebookPage& info) | |
185 | { | |
186 | wxAuiNotebookPage page_info; | |
187 | page_info = info; | |
188 | page_info.window = page; | |
4444d148 | 189 | |
cd05bf23 BW |
190 | m_pages.Add(page_info); |
191 | ||
b0d17f7c BW |
192 | // let the art provider know how many pages we have |
193 | if (m_art) | |
194 | { | |
195 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
196 | } | |
7baac3cb | 197 | |
cd05bf23 BW |
198 | return true; |
199 | } | |
200 | ||
201 | bool wxAuiTabContainer::InsertPage(wxWindow* page, | |
202 | const wxAuiNotebookPage& info, | |
203 | size_t idx) | |
204 | { | |
205 | wxAuiNotebookPage page_info; | |
206 | page_info = info; | |
207 | page_info.window = page; | |
4444d148 | 208 | |
cd05bf23 BW |
209 | if (idx >= m_pages.GetCount()) |
210 | m_pages.Add(page_info); | |
cedd7b22 | 211 | else |
cd05bf23 BW |
212 | m_pages.Insert(page_info, idx); |
213 | ||
b0d17f7c BW |
214 | // let the art provider know how many pages we have |
215 | if (m_art) | |
216 | { | |
217 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
218 | } | |
7baac3cb | 219 | |
cd05bf23 BW |
220 | return true; |
221 | } | |
222 | ||
2fadbbfd BW |
223 | bool wxAuiTabContainer::MovePage(wxWindow* page, |
224 | size_t new_idx) | |
225 | { | |
226 | int idx = GetIdxFromWindow(page); | |
227 | if (idx == -1) | |
228 | return false; | |
7baac3cb | 229 | |
2fadbbfd BW |
230 | // get page entry, make a copy of it |
231 | wxAuiNotebookPage p = GetPage(idx); | |
7baac3cb | 232 | |
2fadbbfd BW |
233 | // remove old page entry |
234 | RemovePage(page); | |
7baac3cb | 235 | |
2fadbbfd BW |
236 | // insert page where it should be |
237 | InsertPage(page, p, new_idx); | |
7baac3cb | 238 | |
2fadbbfd BW |
239 | return true; |
240 | } | |
241 | ||
cd05bf23 BW |
242 | bool wxAuiTabContainer::RemovePage(wxWindow* wnd) |
243 | { | |
244 | size_t i, page_count = m_pages.GetCount(); | |
245 | for (i = 0; i < page_count; ++i) | |
246 | { | |
247 | wxAuiNotebookPage& page = m_pages.Item(i); | |
248 | if (page.window == wnd) | |
249 | { | |
250 | m_pages.RemoveAt(i); | |
7baac3cb | 251 | |
b0d17f7c BW |
252 | // let the art provider know how many pages we have |
253 | if (m_art) | |
254 | { | |
255 | m_art->SetSizingInfo(m_rect.GetSize(), m_pages.GetCount()); | |
256 | } | |
7baac3cb | 257 | |
cd05bf23 BW |
258 | return true; |
259 | } | |
260 | } | |
4444d148 | 261 | |
cd05bf23 BW |
262 | return false; |
263 | } | |
264 | ||
265 | bool wxAuiTabContainer::SetActivePage(wxWindow* wnd) | |
266 | { | |
267 | bool found = false; | |
4444d148 | 268 | |
cd05bf23 BW |
269 | size_t i, page_count = m_pages.GetCount(); |
270 | for (i = 0; i < page_count; ++i) | |
271 | { | |
272 | wxAuiNotebookPage& page = m_pages.Item(i); | |
273 | if (page.window == wnd) | |
274 | { | |
275 | page.active = true; | |
276 | found = true; | |
277 | } | |
cedd7b22 | 278 | else |
cd05bf23 BW |
279 | { |
280 | page.active = false; | |
281 | } | |
282 | } | |
4444d148 | 283 | |
cd05bf23 BW |
284 | return found; |
285 | } | |
286 | ||
287 | void wxAuiTabContainer::SetNoneActive() | |
288 | { | |
289 | size_t i, page_count = m_pages.GetCount(); | |
290 | for (i = 0; i < page_count; ++i) | |
291 | { | |
292 | wxAuiNotebookPage& page = m_pages.Item(i); | |
293 | page.active = false; | |
294 | } | |
295 | } | |
296 | ||
297 | bool wxAuiTabContainer::SetActivePage(size_t page) | |
298 | { | |
299 | if (page >= m_pages.GetCount()) | |
300 | return false; | |
4444d148 | 301 | |
cd05bf23 BW |
302 | return SetActivePage(m_pages.Item(page).window); |
303 | } | |
4444d148 | 304 | |
cd05bf23 BW |
305 | int wxAuiTabContainer::GetActivePage() const |
306 | { | |
307 | size_t i, page_count = m_pages.GetCount(); | |
308 | for (i = 0; i < page_count; ++i) | |
309 | { | |
310 | wxAuiNotebookPage& page = m_pages.Item(i); | |
311 | if (page.active) | |
312 | return i; | |
313 | } | |
4444d148 | 314 | |
cd05bf23 BW |
315 | return -1; |
316 | } | |
317 | ||
318 | wxWindow* wxAuiTabContainer::GetWindowFromIdx(size_t idx) const | |
319 | { | |
320 | if (idx >= m_pages.GetCount()) | |
321 | return NULL; | |
4444d148 | 322 | |
cd05bf23 BW |
323 | return m_pages[idx].window; |
324 | } | |
325 | ||
326 | int wxAuiTabContainer::GetIdxFromWindow(wxWindow* wnd) const | |
327 | { | |
849c353a VZ |
328 | const size_t page_count = m_pages.GetCount(); |
329 | for ( size_t i = 0; i < page_count; ++i ) | |
cd05bf23 BW |
330 | { |
331 | wxAuiNotebookPage& page = m_pages.Item(i); | |
332 | if (page.window == wnd) | |
333 | return i; | |
334 | } | |
849c353a | 335 | return wxNOT_FOUND; |
cd05bf23 BW |
336 | } |
337 | ||
338 | wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx) | |
339 | { | |
340 | wxASSERT_MSG(idx < m_pages.GetCount(), wxT("Invalid Page index")); | |
341 | ||
342 | return m_pages[idx]; | |
343 | } | |
344 | ||
c3e016e4 JS |
345 | const wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx) const |
346 | { | |
347 | wxASSERT_MSG(idx < m_pages.GetCount(), wxT("Invalid Page index")); | |
348 | ||
349 | return m_pages[idx]; | |
350 | } | |
351 | ||
cd05bf23 BW |
352 | wxAuiNotebookPageArray& wxAuiTabContainer::GetPages() |
353 | { | |
354 | return m_pages; | |
355 | } | |
356 | ||
357 | size_t wxAuiTabContainer::GetPageCount() const | |
358 | { | |
359 | return m_pages.GetCount(); | |
360 | } | |
361 | ||
4953f8cf BW |
362 | void wxAuiTabContainer::AddButton(int id, |
363 | int location, | |
9a29fe70 VZ |
364 | const wxBitmap& normalBitmap, |
365 | const wxBitmap& disabledBitmap) | |
cd05bf23 BW |
366 | { |
367 | wxAuiTabContainerButton button; | |
368 | button.id = id; | |
9a29fe70 VZ |
369 | button.bitmap = normalBitmap; |
370 | button.disBitmap = disabledBitmap; | |
b6418695 | 371 | button.location = location; |
9a29fe70 | 372 | button.curState = wxAUI_BUTTON_STATE_NORMAL; |
4444d148 | 373 | |
cd05bf23 BW |
374 | m_buttons.Add(button); |
375 | } | |
376 | ||
41b76acd BW |
377 | void wxAuiTabContainer::RemoveButton(int id) |
378 | { | |
379 | size_t i, button_count = m_buttons.GetCount(); | |
380 | ||
381 | for (i = 0; i < button_count; ++i) | |
382 | { | |
383 | if (m_buttons.Item(i).id == id) | |
384 | { | |
385 | m_buttons.RemoveAt(i); | |
386 | return; | |
387 | } | |
388 | } | |
389 | } | |
390 | ||
391 | ||
392 | ||
4953f8cf BW |
393 | size_t wxAuiTabContainer::GetTabOffset() const |
394 | { | |
9a29fe70 | 395 | return m_tabOffset; |
4953f8cf | 396 | } |
cd05bf23 | 397 | |
4953f8cf BW |
398 | void wxAuiTabContainer::SetTabOffset(size_t offset) |
399 | { | |
9a29fe70 | 400 | m_tabOffset = offset; |
4953f8cf | 401 | } |
cd05bf23 | 402 | |
b0d17f7c BW |
403 | |
404 | ||
405 | ||
cd05bf23 BW |
406 | // Render() renders the tab catalog to the specified DC |
407 | // It is a virtual function and can be overridden to | |
408 | // provide custom drawing capabilities | |
01372b8f | 409 | void wxAuiTabContainer::Render(wxDC* raw_dc, wxWindow* wnd) |
4444d148 | 410 | { |
a9eeb510 BW |
411 | if (!raw_dc || !raw_dc->IsOk()) |
412 | return; | |
413 | ||
cd05bf23 | 414 | wxMemoryDC dc; |
ef329166 VZ |
415 | |
416 | // use the same layout direction as the window DC uses to ensure that the | |
417 | // text is rendered correctly | |
418 | dc.SetLayoutDirection(raw_dc->GetLayoutDirection()); | |
419 | ||
cd05bf23 | 420 | wxBitmap bmp; |
4953f8cf BW |
421 | size_t i; |
422 | size_t page_count = m_pages.GetCount(); | |
423 | size_t button_count = m_buttons.GetCount(); | |
424 | ||
425 | // create off-screen bitmap | |
cd05bf23 BW |
426 | bmp.Create(m_rect.GetWidth(), m_rect.GetHeight()); |
427 | dc.SelectObject(bmp); | |
4444d148 | 428 | |
a9eeb510 BW |
429 | if (!dc.IsOk()) |
430 | return; | |
4953f8cf BW |
431 | |
432 | // find out if size of tabs is larger than can be | |
433 | // afforded on screen | |
434 | int total_width = 0; | |
25d7497c | 435 | int visible_width = 0; |
4953f8cf BW |
436 | for (i = 0; i < page_count; ++i) |
437 | { | |
438 | wxAuiNotebookPage& page = m_pages.Item(i); | |
7baac3cb | 439 | |
702b1c7e BW |
440 | // determine if a close button is on this tab |
441 | bool close_button = false; | |
442 | if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 || | |
443 | ((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active)) | |
444 | { | |
445 | close_button = true; | |
446 | } | |
7baac3cb VZ |
447 | |
448 | ||
4953f8cf | 449 | int x_extent = 0; |
a6b0e5bd | 450 | wxSize size = m_art->GetTabSize(dc, |
01372b8f | 451 | wnd, |
41b76acd | 452 | page.caption, |
2b9aac33 | 453 | page.bitmap, |
41b76acd BW |
454 | page.active, |
455 | close_button ? | |
456 | wxAUI_BUTTON_STATE_NORMAL : | |
457 | wxAUI_BUTTON_STATE_HIDDEN, | |
458 | &x_extent); | |
7baac3cb | 459 | |
4953f8cf BW |
460 | if (i+1 < page_count) |
461 | total_width += x_extent; | |
cedd7b22 | 462 | else |
4953f8cf | 463 | total_width += size.x; |
7baac3cb | 464 | |
9a29fe70 | 465 | if (i >= m_tabOffset) |
25d7497c BW |
466 | { |
467 | if (i+1 < page_count) | |
468 | visible_width += x_extent; | |
cedd7b22 | 469 | else |
25d7497c BW |
470 | visible_width += size.x; |
471 | } | |
4953f8cf | 472 | } |
7baac3cb | 473 | |
9a29fe70 | 474 | if (total_width > m_rect.GetWidth() || m_tabOffset != 0) |
4953f8cf BW |
475 | { |
476 | // show left/right buttons | |
477 | for (i = 0; i < button_count; ++i) | |
478 | { | |
479 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
480 | if (button.id == wxAUI_BUTTON_LEFT || | |
481 | button.id == wxAUI_BUTTON_RIGHT) | |
482 | { | |
9a29fe70 | 483 | button.curState &= ~wxAUI_BUTTON_STATE_HIDDEN; |
4953f8cf BW |
484 | } |
485 | } | |
486 | } | |
cedd7b22 | 487 | else |
4953f8cf BW |
488 | { |
489 | // hide left/right buttons | |
490 | for (i = 0; i < button_count; ++i) | |
491 | { | |
492 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
493 | if (button.id == wxAUI_BUTTON_LEFT || | |
494 | button.id == wxAUI_BUTTON_RIGHT) | |
495 | { | |
9a29fe70 | 496 | button.curState |= wxAUI_BUTTON_STATE_HIDDEN; |
4953f8cf BW |
497 | } |
498 | } | |
499 | } | |
500 | ||
25d7497c BW |
501 | // determine whether left button should be enabled |
502 | for (i = 0; i < button_count; ++i) | |
503 | { | |
504 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
505 | if (button.id == wxAUI_BUTTON_LEFT) | |
506 | { | |
9a29fe70 VZ |
507 | if (m_tabOffset == 0) |
508 | button.curState |= wxAUI_BUTTON_STATE_DISABLED; | |
cedd7b22 | 509 | else |
9a29fe70 | 510 | button.curState &= ~wxAUI_BUTTON_STATE_DISABLED; |
25d7497c BW |
511 | } |
512 | if (button.id == wxAUI_BUTTON_RIGHT) | |
513 | { | |
514 | if (visible_width < m_rect.GetWidth() - ((int)button_count*16)) | |
9a29fe70 | 515 | button.curState |= wxAUI_BUTTON_STATE_DISABLED; |
cedd7b22 | 516 | else |
9a29fe70 | 517 | button.curState &= ~wxAUI_BUTTON_STATE_DISABLED; |
25d7497c BW |
518 | } |
519 | } | |
520 | ||
4953f8cf BW |
521 | |
522 | ||
523 | // draw background | |
a6b0e5bd | 524 | m_art->DrawBackground(dc, wnd, m_rect); |
4444d148 | 525 | |
4953f8cf BW |
526 | // draw buttons |
527 | int left_buttons_width = 0; | |
528 | int right_buttons_width = 0; | |
7baac3cb | 529 | |
b6418695 | 530 | // draw the buttons on the right side |
b576c83a | 531 | int offset = m_rect.x + m_rect.width; |
b6418695 BW |
532 | for (i = 0; i < button_count; ++i) |
533 | { | |
534 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
7baac3cb | 535 | |
b6418695 BW |
536 | if (button.location != wxRIGHT) |
537 | continue; | |
9a29fe70 | 538 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
4953f8cf | 539 | continue; |
7baac3cb | 540 | |
4953f8cf BW |
541 | wxRect button_rect = m_rect; |
542 | button_rect.SetY(1); | |
543 | button_rect.SetWidth(offset); | |
544 | ||
a6b0e5bd | 545 | m_art->DrawButton(dc, |
01372b8f | 546 | wnd, |
4953f8cf BW |
547 | button_rect, |
548 | button.id, | |
9a29fe70 | 549 | button.curState, |
4953f8cf | 550 | wxRIGHT, |
4953f8cf BW |
551 | &button.rect); |
552 | ||
553 | offset -= button.rect.GetWidth(); | |
554 | right_buttons_width += button.rect.GetWidth(); | |
b6418695 BW |
555 | } |
556 | ||
557 | ||
558 | ||
559 | offset = 0; | |
7baac3cb | 560 | |
b6418695 BW |
561 | // draw the buttons on the left side |
562 | ||
563 | for (i = 0; i < button_count; ++i) | |
564 | { | |
565 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
7baac3cb | 566 | |
b6418695 BW |
567 | if (button.location != wxLEFT) |
568 | continue; | |
9a29fe70 | 569 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
4953f8cf | 570 | continue; |
7baac3cb | 571 | |
4953f8cf BW |
572 | wxRect button_rect(offset, 1, 1000, m_rect.height); |
573 | ||
a6b0e5bd | 574 | m_art->DrawButton(dc, |
01372b8f | 575 | wnd, |
4953f8cf BW |
576 | button_rect, |
577 | button.id, | |
9a29fe70 | 578 | button.curState, |
4953f8cf | 579 | wxLEFT, |
4953f8cf | 580 | &button.rect); |
7baac3cb | 581 | |
4953f8cf BW |
582 | offset += button.rect.GetWidth(); |
583 | left_buttons_width += button.rect.GetWidth(); | |
b6418695 BW |
584 | } |
585 | ||
4953f8cf | 586 | offset = left_buttons_width; |
7baac3cb | 587 | |
b0d17f7c | 588 | if (offset == 0) |
7baac3cb VZ |
589 | offset += m_art->GetIndentSize(); |
590 | ||
591 | ||
41b76acd | 592 | // prepare the tab-close-button array |
049333c2 | 593 | // make sure tab button entries which aren't used are marked as hidden |
9a29fe70 VZ |
594 | for (i = page_count; i < m_tabCloseButtons.GetCount(); ++i) |
595 | m_tabCloseButtons.Item(i).curState = wxAUI_BUTTON_STATE_HIDDEN; | |
7baac3cb | 596 | |
049333c2 | 597 | // make sure there are enough tab button entries to accommodate all tabs |
9a29fe70 | 598 | while (m_tabCloseButtons.GetCount() < page_count) |
41b76acd BW |
599 | { |
600 | wxAuiTabContainerButton tempbtn; | |
601 | tempbtn.id = wxAUI_BUTTON_CLOSE; | |
602 | tempbtn.location = wxCENTER; | |
9a29fe70 VZ |
603 | tempbtn.curState = wxAUI_BUTTON_STATE_HIDDEN; |
604 | m_tabCloseButtons.Add(tempbtn); | |
41b76acd | 605 | } |
7baac3cb VZ |
606 | |
607 | ||
4abf84fb | 608 | // buttons before the tab offset must be set to hidden |
9a29fe70 | 609 | for (i = 0; i < m_tabOffset; ++i) |
41b76acd | 610 | { |
9a29fe70 | 611 | m_tabCloseButtons.Item(i).curState = wxAUI_BUTTON_STATE_HIDDEN; |
41b76acd | 612 | } |
7baac3cb VZ |
613 | |
614 | ||
b6418695 | 615 | // draw the tabs |
cd05bf23 BW |
616 | |
617 | size_t active = 999; | |
618 | int active_offset = 0; | |
b0d17f7c | 619 | wxRect active_rect; |
4444d148 | 620 | |
cd05bf23 BW |
621 | int x_extent = 0; |
622 | wxRect rect = m_rect; | |
623 | rect.y = 0; | |
cd05bf23 | 624 | rect.height = m_rect.height; |
4444d148 | 625 | |
9a29fe70 | 626 | for (i = m_tabOffset; i < page_count; ++i) |
cd05bf23 BW |
627 | { |
628 | wxAuiNotebookPage& page = m_pages.Item(i); | |
9a29fe70 | 629 | wxAuiTabContainerButton& tab_button = m_tabCloseButtons.Item(i); |
4444d148 | 630 | |
702b1c7e | 631 | // determine if a close button is on this tab |
702b1c7e BW |
632 | if ((m_flags & wxAUI_NB_CLOSE_ON_ALL_TABS) != 0 || |
633 | ((m_flags & wxAUI_NB_CLOSE_ON_ACTIVE_TAB) != 0 && page.active)) | |
634 | { | |
9a29fe70 | 635 | if (tab_button.curState == wxAUI_BUTTON_STATE_HIDDEN) |
41b76acd BW |
636 | { |
637 | tab_button.id = wxAUI_BUTTON_CLOSE; | |
9a29fe70 | 638 | tab_button.curState = wxAUI_BUTTON_STATE_NORMAL; |
41b76acd BW |
639 | tab_button.location = wxCENTER; |
640 | } | |
641 | } | |
cedd7b22 | 642 | else |
41b76acd | 643 | { |
9a29fe70 | 644 | tab_button.curState = wxAUI_BUTTON_STATE_HIDDEN; |
702b1c7e BW |
645 | } |
646 | ||
cd05bf23 | 647 | rect.x = offset; |
b0d17f7c BW |
648 | rect.width = m_rect.width - right_buttons_width - offset - 2; |
649 | ||
47b6bebb BW |
650 | if (rect.width <= 0) |
651 | break; | |
652 | ||
a6b0e5bd | 653 | m_art->DrawTab(dc, |
01372b8f | 654 | wnd, |
793d4365 | 655 | page, |
01372b8f | 656 | rect, |
9a29fe70 | 657 | tab_button.curState, |
01372b8f BW |
658 | &page.rect, |
659 | &tab_button.rect, | |
660 | &x_extent); | |
4444d148 | 661 | |
cd05bf23 BW |
662 | if (page.active) |
663 | { | |
664 | active = i; | |
665 | active_offset = offset; | |
b0d17f7c | 666 | active_rect = rect; |
cd05bf23 | 667 | } |
7baac3cb | 668 | |
cd05bf23 BW |
669 | offset += x_extent; |
670 | } | |
4444d148 | 671 | |
4abf84fb BW |
672 | |
673 | // make sure to deactivate buttons which are off the screen to the right | |
9a29fe70 | 674 | for (++i; i < m_tabCloseButtons.GetCount(); ++i) |
4abf84fb | 675 | { |
9a29fe70 | 676 | m_tabCloseButtons.Item(i).curState = wxAUI_BUTTON_STATE_HIDDEN; |
4abf84fb BW |
677 | } |
678 | ||
679 | ||
cd05bf23 | 680 | // draw the active tab again so it stands in the foreground |
9a29fe70 | 681 | if (active >= m_tabOffset && active < m_pages.GetCount()) |
cd05bf23 BW |
682 | { |
683 | wxAuiNotebookPage& page = m_pages.Item(active); | |
684 | ||
9a29fe70 | 685 | wxAuiTabContainerButton& tab_button = m_tabCloseButtons.Item(active); |
41b76acd | 686 | |
cd05bf23 | 687 | rect.x = active_offset; |
a6b0e5bd | 688 | m_art->DrawTab(dc, |
01372b8f | 689 | wnd, |
793d4365 | 690 | page, |
b0d17f7c | 691 | active_rect, |
9a29fe70 | 692 | tab_button.curState, |
01372b8f BW |
693 | &page.rect, |
694 | &tab_button.rect, | |
695 | &x_extent); | |
cd05bf23 | 696 | } |
4444d148 | 697 | |
7baac3cb | 698 | |
4953f8cf BW |
699 | raw_dc->Blit(m_rect.x, m_rect.y, |
700 | m_rect.GetWidth(), m_rect.GetHeight(), | |
701 | &dc, 0, 0); | |
cd05bf23 BW |
702 | } |
703 | ||
a0c2e4a0 | 704 | // Is the tab visible? |
0b3b8742 | 705 | bool wxAuiTabContainer::IsTabVisible(int tabPage, int tabOffset, wxDC* dc, wxWindow* wnd) |
a0c2e4a0 JS |
706 | { |
707 | if (!dc || !dc->IsOk()) | |
708 | return false; | |
709 | ||
710 | size_t i; | |
711 | size_t page_count = m_pages.GetCount(); | |
712 | size_t button_count = m_buttons.GetCount(); | |
713 | ||
714 | // Hasn't been rendered yet; assume it's visible | |
9a29fe70 | 715 | if (m_tabCloseButtons.GetCount() < page_count) |
a0c2e4a0 JS |
716 | return true; |
717 | ||
718 | // First check if both buttons are disabled - if so, there's no need to | |
719 | // check further for visibility. | |
720 | int arrowButtonVisibleCount = 0; | |
721 | for (i = 0; i < button_count; ++i) | |
722 | { | |
723 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
724 | if (button.id == wxAUI_BUTTON_LEFT || | |
725 | button.id == wxAUI_BUTTON_RIGHT) | |
726 | { | |
9a29fe70 | 727 | if ((button.curState & wxAUI_BUTTON_STATE_HIDDEN) == 0) |
a0c2e4a0 JS |
728 | arrowButtonVisibleCount ++; |
729 | } | |
730 | } | |
731 | ||
732 | // Tab must be visible | |
733 | if (arrowButtonVisibleCount == 0) | |
734 | return true; | |
735 | ||
736 | // If tab is less than the given offset, it must be invisible by definition | |
737 | if (tabPage < tabOffset) | |
738 | return false; | |
739 | ||
740 | // draw buttons | |
741 | int left_buttons_width = 0; | |
742 | int right_buttons_width = 0; | |
743 | ||
a0c2e4a0 | 744 | // calculate size of the buttons on the right side |
b576c83a | 745 | int offset = m_rect.x + m_rect.width; |
a0c2e4a0 JS |
746 | for (i = 0; i < button_count; ++i) |
747 | { | |
748 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
749 | ||
750 | if (button.location != wxRIGHT) | |
751 | continue; | |
9a29fe70 | 752 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
a0c2e4a0 JS |
753 | continue; |
754 | ||
755 | offset -= button.rect.GetWidth(); | |
756 | right_buttons_width += button.rect.GetWidth(); | |
757 | } | |
758 | ||
759 | offset = 0; | |
760 | ||
761 | // calculate size of the buttons on the left side | |
762 | for (i = 0; i < button_count; ++i) | |
763 | { | |
764 | wxAuiTabContainerButton& button = m_buttons.Item(button_count - i - 1); | |
765 | ||
766 | if (button.location != wxLEFT) | |
767 | continue; | |
9a29fe70 | 768 | if (button.curState & wxAUI_BUTTON_STATE_HIDDEN) |
a0c2e4a0 JS |
769 | continue; |
770 | ||
771 | offset += button.rect.GetWidth(); | |
772 | left_buttons_width += button.rect.GetWidth(); | |
773 | } | |
774 | ||
775 | offset = left_buttons_width; | |
776 | ||
777 | if (offset == 0) | |
778 | offset += m_art->GetIndentSize(); | |
779 | ||
780 | wxRect active_rect; | |
781 | ||
782 | wxRect rect = m_rect; | |
783 | rect.y = 0; | |
784 | rect.height = m_rect.height; | |
785 | ||
786 | // See if the given page is visible at the given tab offset (effectively scroll position) | |
787 | for (i = tabOffset; i < page_count; ++i) | |
788 | { | |
0b3b8742 PC |
789 | wxAuiNotebookPage& page = m_pages.Item(i); |
790 | wxAuiTabContainerButton& tab_button = m_tabCloseButtons.Item(i); | |
791 | ||
a0c2e4a0 JS |
792 | rect.x = offset; |
793 | rect.width = m_rect.width - right_buttons_width - offset - 2; | |
794 | ||
795 | if (rect.width <= 0) | |
796 | return false; // haven't found the tab, and we've run out of space, so return false | |
797 | ||
798 | int x_extent = 0; | |
0b3b8742 PC |
799 | m_art->GetTabSize(*dc, |
800 | wnd, | |
801 | page.caption, | |
802 | page.bitmap, | |
803 | page.active, | |
804 | tab_button.curState, | |
805 | &x_extent); | |
806 | ||
a0c2e4a0 JS |
807 | offset += x_extent; |
808 | ||
809 | if (i == (size_t) tabPage) | |
810 | { | |
811 | // If not all of the tab is visible, and supposing there's space to display it all, | |
812 | // we could do better so we return false. | |
813 | if (((m_rect.width - right_buttons_width - offset - 2) <= 0) && ((m_rect.width - right_buttons_width - left_buttons_width) > x_extent)) | |
814 | return false; | |
815 | else | |
816 | return true; | |
817 | } | |
818 | } | |
819 | ||
820 | // Shouldn't really get here, but if it does, assume the tab is visible to prevent | |
821 | // further looping in calling code. | |
822 | return true; | |
823 | } | |
824 | ||
825 | // Make the tab visible if it wasn't already | |
826 | void wxAuiTabContainer::MakeTabVisible(int tabPage, wxWindow* win) | |
827 | { | |
828 | wxClientDC dc(win); | |
829 | if (!IsTabVisible(tabPage, GetTabOffset(), & dc, win)) | |
830 | { | |
831 | int i; | |
832 | for (i = 0; i < (int) m_pages.GetCount(); i++) | |
833 | { | |
834 | if (IsTabVisible(tabPage, i, & dc, win)) | |
835 | { | |
836 | SetTabOffset(i); | |
837 | win->Refresh(); | |
838 | return; | |
839 | } | |
840 | } | |
841 | } | |
842 | } | |
cd05bf23 BW |
843 | |
844 | // TabHitTest() tests if a tab was hit, passing the window pointer | |
845 | // back if that condition was fulfilled. The function returns | |
846 | // true if a tab was hit, otherwise false | |
847 | bool wxAuiTabContainer::TabHitTest(int x, int y, wxWindow** hit) const | |
848 | { | |
22a35096 | 849 | if (!m_rect.Contains(x,y)) |
cd05bf23 | 850 | return false; |
7baac3cb | 851 | |
41b76acd | 852 | wxAuiTabContainerButton* btn = NULL; |
9a29fe70 | 853 | if (ButtonHitTest(x, y, &btn) && !(btn->curState & wxAUI_BUTTON_STATE_DISABLED)) |
41b76acd BW |
854 | { |
855 | if (m_buttons.Index(*btn) != wxNOT_FOUND) | |
856 | return false; | |
857 | } | |
4444d148 | 858 | |
cd05bf23 | 859 | size_t i, page_count = m_pages.GetCount(); |
4444d148 | 860 | |
9a29fe70 | 861 | for (i = m_tabOffset; i < page_count; ++i) |
cd05bf23 BW |
862 | { |
863 | wxAuiNotebookPage& page = m_pages.Item(i); | |
22a35096 | 864 | if (page.rect.Contains(x,y)) |
cd05bf23 | 865 | { |
4953f8cf BW |
866 | if (hit) |
867 | *hit = page.window; | |
cd05bf23 BW |
868 | return true; |
869 | } | |
870 | } | |
4444d148 | 871 | |
cd05bf23 BW |
872 | return false; |
873 | } | |
874 | ||
875 | // ButtonHitTest() tests if a button was hit. The function returns | |
876 | // true if a button was hit, otherwise false | |
877 | bool wxAuiTabContainer::ButtonHitTest(int x, int y, | |
878 | wxAuiTabContainerButton** hit) const | |
879 | { | |
22a35096 | 880 | if (!m_rect.Contains(x,y)) |
cd05bf23 | 881 | return false; |
4444d148 | 882 | |
41b76acd | 883 | size_t i, button_count; |
7baac3cb VZ |
884 | |
885 | ||
41b76acd | 886 | button_count = m_buttons.GetCount(); |
cd05bf23 BW |
887 | for (i = 0; i < button_count; ++i) |
888 | { | |
889 | wxAuiTabContainerButton& button = m_buttons.Item(i); | |
9b405ab3 | 890 | if (button.rect.Contains(x,y) && |
9a29fe70 | 891 | !(button.curState & wxAUI_BUTTON_STATE_HIDDEN )) |
cd05bf23 | 892 | { |
4953f8cf BW |
893 | if (hit) |
894 | *hit = &button; | |
cd05bf23 BW |
895 | return true; |
896 | } | |
897 | } | |
7baac3cb | 898 | |
9a29fe70 | 899 | button_count = m_tabCloseButtons.GetCount(); |
41b76acd BW |
900 | for (i = 0; i < button_count; ++i) |
901 | { | |
9a29fe70 | 902 | wxAuiTabContainerButton& button = m_tabCloseButtons.Item(i); |
9b405ab3 | 903 | if (button.rect.Contains(x,y) && |
9a29fe70 | 904 | !(button.curState & (wxAUI_BUTTON_STATE_HIDDEN | |
9b405ab3 | 905 | wxAUI_BUTTON_STATE_DISABLED))) |
41b76acd BW |
906 | { |
907 | if (hit) | |
908 | *hit = &button; | |
909 | return true; | |
910 | } | |
911 | } | |
7baac3cb | 912 | |
cd05bf23 BW |
913 | return false; |
914 | } | |
915 | ||
916 | ||
917 | ||
918 | // the utility function ShowWnd() is the same as show, | |
a3a5df9d | 919 | // except it handles wxAuiMDIChildFrame windows as well, |
cd05bf23 BW |
920 | // as the Show() method on this class is "unplugged" |
921 | static void ShowWnd(wxWindow* wnd, bool show) | |
922 | { | |
89272c55 | 923 | #if wxUSE_MDI |
345c78ca | 924 | if (wxDynamicCast(wnd, wxAuiMDIChildFrame)) |
cd05bf23 | 925 | { |
a3a5df9d | 926 | wxAuiMDIChildFrame* cf = (wxAuiMDIChildFrame*)wnd; |
cd05bf23 BW |
927 | cf->DoShow(show); |
928 | } | |
cedd7b22 | 929 | else |
89272c55 | 930 | #endif |
cd05bf23 BW |
931 | { |
932 | wnd->Show(show); | |
933 | } | |
934 | } | |
935 | ||
936 | ||
937 | // DoShowHide() this function shows the active window, then | |
938 | // hides all of the other windows (in that order) | |
939 | void wxAuiTabContainer::DoShowHide() | |
940 | { | |
941 | wxAuiNotebookPageArray& pages = GetPages(); | |
942 | size_t i, page_count = pages.GetCount(); | |
943 | ||
944 | // show new active page first | |
945 | for (i = 0; i < page_count; ++i) | |
946 | { | |
947 | wxAuiNotebookPage& page = pages.Item(i); | |
948 | if (page.active) | |
949 | { | |
950 | ShowWnd(page.window, true); | |
951 | break; | |
952 | } | |
953 | } | |
954 | ||
955 | // hide all other pages | |
956 | for (i = 0; i < page_count; ++i) | |
957 | { | |
958 | wxAuiNotebookPage& page = pages.Item(i); | |
badcaaaf BW |
959 | if (!page.active) |
960 | ShowWnd(page.window, false); | |
cd05bf23 BW |
961 | } |
962 | } | |
963 | ||
964 | ||
965 | ||
966 | ||
967 | ||
968 | ||
969 | // -- wxAuiTabCtrl class implementation -- | |
970 | ||
971 | ||
cd05bf23 BW |
972 | |
973 | BEGIN_EVENT_TABLE(wxAuiTabCtrl, wxControl) | |
974 | EVT_PAINT(wxAuiTabCtrl::OnPaint) | |
975 | EVT_ERASE_BACKGROUND(wxAuiTabCtrl::OnEraseBackground) | |
976 | EVT_SIZE(wxAuiTabCtrl::OnSize) | |
977 | EVT_LEFT_DOWN(wxAuiTabCtrl::OnLeftDown) | |
198be845 | 978 | EVT_LEFT_DCLICK(wxAuiTabCtrl::OnLeftDClick) |
cd05bf23 | 979 | EVT_LEFT_UP(wxAuiTabCtrl::OnLeftUp) |
69f5e420 BW |
980 | EVT_MIDDLE_DOWN(wxAuiTabCtrl::OnMiddleDown) |
981 | EVT_MIDDLE_UP(wxAuiTabCtrl::OnMiddleUp) | |
982 | EVT_RIGHT_DOWN(wxAuiTabCtrl::OnRightDown) | |
983 | EVT_RIGHT_UP(wxAuiTabCtrl::OnRightUp) | |
cd05bf23 BW |
984 | EVT_MOTION(wxAuiTabCtrl::OnMotion) |
985 | EVT_LEAVE_WINDOW(wxAuiTabCtrl::OnLeaveWindow) | |
c58ba15f | 986 | EVT_AUINOTEBOOK_BUTTON(wxID_ANY, wxAuiTabCtrl::OnButton) |
a0c2e4a0 JS |
987 | EVT_SET_FOCUS(wxAuiTabCtrl::OnSetFocus) |
988 | EVT_KILL_FOCUS(wxAuiTabCtrl::OnKillFocus) | |
989 | EVT_CHAR(wxAuiTabCtrl::OnChar) | |
45ca0e77 | 990 | EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost) |
cd05bf23 BW |
991 | END_EVENT_TABLE() |
992 | ||
993 | ||
994 | wxAuiTabCtrl::wxAuiTabCtrl(wxWindow* parent, | |
995 | wxWindowID id, | |
996 | const wxPoint& pos, | |
997 | const wxSize& size, | |
4444d148 | 998 | long style) : wxControl(parent, id, pos, size, style) |
cd05bf23 | 999 | { |
c7bfb76a | 1000 | SetName(wxT("wxAuiTabCtrl")); |
9a29fe70 VZ |
1001 | m_clickPt = wxDefaultPosition; |
1002 | m_isDragging = false; | |
1003 | m_hoverButton = NULL; | |
1004 | m_pressedButton = NULL; | |
cd05bf23 BW |
1005 | } |
1006 | ||
26da5e4f BW |
1007 | wxAuiTabCtrl::~wxAuiTabCtrl() |
1008 | { | |
1009 | } | |
cd05bf23 BW |
1010 | |
1011 | void wxAuiTabCtrl::OnPaint(wxPaintEvent&) | |
1012 | { | |
1013 | wxPaintDC dc(this); | |
4444d148 | 1014 | |
cd05bf23 | 1015 | dc.SetFont(GetFont()); |
4444d148 | 1016 | |
cd05bf23 | 1017 | if (GetPageCount() > 0) |
01372b8f | 1018 | Render(&dc, this); |
cd05bf23 BW |
1019 | } |
1020 | ||
1021 | void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) | |
1022 | { | |
1023 | } | |
1024 | ||
1025 | void wxAuiTabCtrl::OnSize(wxSizeEvent& evt) | |
1026 | { | |
1027 | wxSize s = evt.GetSize(); | |
1028 | wxRect r(0, 0, s.GetWidth(), s.GetHeight()); | |
1029 | SetRect(r); | |
1030 | } | |
1031 | ||
1032 | void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt) | |
1033 | { | |
1034 | CaptureMouse(); | |
9a29fe70 VZ |
1035 | m_clickPt = wxDefaultPosition; |
1036 | m_isDragging = false; | |
1037 | m_clickTab = NULL; | |
1038 | m_pressedButton = NULL; | |
4444d148 | 1039 | |
760d3542 | 1040 | |
cd05bf23 BW |
1041 | wxWindow* wnd; |
1042 | if (TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
9b405ab3 | 1043 | { |
049333c2 | 1044 | int new_selection = GetIdxFromWindow(wnd); |
7baac3cb | 1045 | |
68fd4f2c BW |
1046 | // wxAuiNotebooks always want to receive this event |
1047 | // even if the tab is already active, because they may | |
1048 | // have multiple tab controls | |
20ebd9ff | 1049 | if ((new_selection != GetActivePage() || |
345c78ca | 1050 | wxDynamicCast(GetParent(), wxAuiNotebook)) && !m_hoverButton) |
049333c2 BW |
1051 | { |
1052 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
1053 | e.SetSelection(new_selection); | |
1054 | e.SetOldSelection(GetActivePage()); | |
1055 | e.SetEventObject(this); | |
1056 | GetEventHandler()->ProcessEvent(e); | |
1057 | } | |
4444d148 | 1058 | |
9a29fe70 VZ |
1059 | m_clickPt.x = evt.m_x; |
1060 | m_clickPt.y = evt.m_y; | |
1061 | m_clickTab = wnd; | |
cd05bf23 | 1062 | } |
7baac3cb | 1063 | |
9a29fe70 | 1064 | if (m_hoverButton) |
cd05bf23 | 1065 | { |
9a29fe70 VZ |
1066 | m_pressedButton = m_hoverButton; |
1067 | m_pressedButton->curState = wxAUI_BUTTON_STATE_PRESSED; | |
cd05bf23 BW |
1068 | Refresh(); |
1069 | Update(); | |
1070 | } | |
1071 | } | |
1072 | ||
45ca0e77 BW |
1073 | void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) |
1074 | { | |
9a29fe70 | 1075 | if (m_isDragging) |
2bd82d72 | 1076 | { |
9a29fe70 | 1077 | m_isDragging = false; |
2bd82d72 VZ |
1078 | |
1079 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, m_windowId); | |
9a29fe70 | 1080 | evt.SetSelection(GetIdxFromWindow(m_clickTab)); |
2bd82d72 VZ |
1081 | evt.SetOldSelection(evt.GetSelection()); |
1082 | evt.SetEventObject(this); | |
1083 | GetEventHandler()->ProcessEvent(evt); | |
1084 | } | |
45ca0e77 BW |
1085 | } |
1086 | ||
9b3f654a | 1087 | void wxAuiTabCtrl::OnLeftUp(wxMouseEvent& evt) |
cd05bf23 BW |
1088 | { |
1089 | if (GetCapture() == this) | |
1090 | ReleaseMouse(); | |
4444d148 | 1091 | |
9a29fe70 | 1092 | if (m_isDragging) |
cd05bf23 | 1093 | { |
9a29fe70 | 1094 | m_isDragging = false; |
cedd7b22 | 1095 | |
7d1214cd PC |
1096 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, m_windowId); |
1097 | e.SetSelection(GetIdxFromWindow(m_clickTab)); | |
1098 | e.SetOldSelection(e.GetSelection()); | |
1099 | e.SetEventObject(this); | |
1100 | GetEventHandler()->ProcessEvent(e); | |
cedd7b22 | 1101 | |
cd05bf23 BW |
1102 | return; |
1103 | } | |
4444d148 | 1104 | |
9a29fe70 | 1105 | if (m_pressedButton) |
cd05bf23 | 1106 | { |
9b3f654a BW |
1107 | // make sure we're still clicking the button |
1108 | wxAuiTabContainerButton* button = NULL; | |
65052c6f | 1109 | if (!ButtonHitTest(evt.m_x, evt.m_y, &button) || |
9a29fe70 | 1110 | button->curState & wxAUI_BUTTON_STATE_DISABLED) |
9b3f654a | 1111 | return; |
7baac3cb | 1112 | |
9a29fe70 | 1113 | if (button != m_pressedButton) |
9b3f654a | 1114 | { |
9a29fe70 | 1115 | m_pressedButton = NULL; |
9b3f654a BW |
1116 | return; |
1117 | } | |
1118 | ||
cd05bf23 BW |
1119 | Refresh(); |
1120 | Update(); | |
4444d148 | 1121 | |
9a29fe70 | 1122 | if (!(m_pressedButton->curState & wxAUI_BUTTON_STATE_DISABLED)) |
25d7497c | 1123 | { |
7d1214cd PC |
1124 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, m_windowId); |
1125 | e.SetSelection(GetIdxFromWindow(m_clickTab)); | |
1126 | e.SetInt(m_pressedButton->id); | |
1127 | e.SetEventObject(this); | |
1128 | GetEventHandler()->ProcessEvent(e); | |
25d7497c | 1129 | } |
7baac3cb | 1130 | |
9a29fe70 | 1131 | m_pressedButton = NULL; |
cd05bf23 | 1132 | } |
4444d148 | 1133 | |
9a29fe70 VZ |
1134 | m_clickPt = wxDefaultPosition; |
1135 | m_isDragging = false; | |
1136 | m_clickTab = NULL; | |
cd05bf23 BW |
1137 | } |
1138 | ||
69f5e420 BW |
1139 | void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent& evt) |
1140 | { | |
1141 | wxWindow* wnd = NULL; | |
1142 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
1143 | return; | |
1144 | ||
1145 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, m_windowId); | |
1146 | e.SetEventObject(this); | |
1147 | e.SetSelection(GetIdxFromWindow(wnd)); | |
1148 | GetEventHandler()->ProcessEvent(e); | |
1149 | } | |
1150 | ||
1151 | void wxAuiTabCtrl::OnMiddleDown(wxMouseEvent& evt) | |
1152 | { | |
1153 | wxWindow* wnd = NULL; | |
1154 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
1155 | return; | |
1156 | ||
1157 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, m_windowId); | |
1158 | e.SetEventObject(this); | |
1159 | e.SetSelection(GetIdxFromWindow(wnd)); | |
1160 | GetEventHandler()->ProcessEvent(e); | |
1161 | } | |
1162 | ||
1163 | void wxAuiTabCtrl::OnRightUp(wxMouseEvent& evt) | |
1164 | { | |
1165 | wxWindow* wnd = NULL; | |
1166 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
1167 | return; | |
1168 | ||
1169 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, m_windowId); | |
1170 | e.SetEventObject(this); | |
1171 | e.SetSelection(GetIdxFromWindow(wnd)); | |
1172 | GetEventHandler()->ProcessEvent(e); | |
1173 | } | |
1174 | ||
1175 | void wxAuiTabCtrl::OnRightDown(wxMouseEvent& evt) | |
1176 | { | |
1177 | wxWindow* wnd = NULL; | |
1178 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
1179 | return; | |
1180 | ||
1181 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, m_windowId); | |
1182 | e.SetEventObject(this); | |
1183 | e.SetSelection(GetIdxFromWindow(wnd)); | |
1184 | GetEventHandler()->ProcessEvent(e); | |
1185 | } | |
1186 | ||
198be845 JS |
1187 | void wxAuiTabCtrl::OnLeftDClick(wxMouseEvent& evt) |
1188 | { | |
1189 | wxWindow* wnd; | |
1190 | wxAuiTabContainerButton* button; | |
1191 | if (!TabHitTest(evt.m_x, evt.m_y, &wnd) && !ButtonHitTest(evt.m_x, evt.m_y, &button)) | |
1192 | { | |
1193 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, m_windowId); | |
1194 | e.SetEventObject(this); | |
1195 | GetEventHandler()->ProcessEvent(e); | |
1196 | } | |
1197 | } | |
1198 | ||
cd05bf23 BW |
1199 | void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) |
1200 | { | |
1201 | wxPoint pos = evt.GetPosition(); | |
1202 | ||
1203 | // check if the mouse is hovering above a button | |
1204 | wxAuiTabContainerButton* button; | |
9a29fe70 | 1205 | if (ButtonHitTest(pos.x, pos.y, &button) && !(button->curState & wxAUI_BUTTON_STATE_DISABLED)) |
cd05bf23 | 1206 | { |
9a29fe70 | 1207 | if (m_hoverButton && button != m_hoverButton) |
b6418695 | 1208 | { |
9a29fe70 VZ |
1209 | m_hoverButton->curState = wxAUI_BUTTON_STATE_NORMAL; |
1210 | m_hoverButton = NULL; | |
b6418695 BW |
1211 | Refresh(); |
1212 | Update(); | |
1213 | } | |
7baac3cb | 1214 | |
9a29fe70 | 1215 | if (button->curState != wxAUI_BUTTON_STATE_HOVER) |
cd05bf23 | 1216 | { |
9a29fe70 | 1217 | button->curState = wxAUI_BUTTON_STATE_HOVER; |
cd05bf23 BW |
1218 | Refresh(); |
1219 | Update(); | |
8c7fb508 | 1220 | |
9a29fe70 | 1221 | m_hoverButton = button; |
cd05bf23 BW |
1222 | return; |
1223 | } | |
1224 | } | |
cedd7b22 | 1225 | else |
cd05bf23 | 1226 | { |
9a29fe70 | 1227 | if (m_hoverButton) |
cd05bf23 | 1228 | { |
9a29fe70 VZ |
1229 | m_hoverButton->curState = wxAUI_BUTTON_STATE_NORMAL; |
1230 | m_hoverButton = NULL; | |
cd05bf23 BW |
1231 | Refresh(); |
1232 | Update(); | |
1233 | } | |
1234 | } | |
4444d148 | 1235 | |
11527fc9 | 1236 | wxWindow* wnd = NULL; |
d4df01f1 JJ |
1237 | |
1238 | #if wxUSE_TOOLTIPS | |
1239 | if (evt.Moving() && TabHitTest(evt.m_x, evt.m_y, &wnd)) | |
11527fc9 VZ |
1240 | { |
1241 | wxString tooltip(m_pages[GetIdxFromWindow(wnd)].tooltip); | |
1242 | ||
1243 | // If the text changes, set it else, keep old, to avoid | |
1244 | // 'moving tooltip' effect | |
1245 | if (GetToolTipText() != tooltip) | |
1246 | SetToolTip(tooltip); | |
1247 | } | |
1248 | else | |
1249 | UnsetToolTip(); | |
d4df01f1 JJ |
1250 | #endif |
1251 | ||
9a29fe70 | 1252 | if (!evt.LeftIsDown() || m_clickPt == wxDefaultPosition) |
cd05bf23 | 1253 | return; |
4444d148 | 1254 | |
9a29fe70 | 1255 | if (m_isDragging) |
cd05bf23 | 1256 | { |
7d1214cd PC |
1257 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, m_windowId); |
1258 | e.SetSelection(GetIdxFromWindow(m_clickTab)); | |
1259 | e.SetOldSelection(e.GetSelection()); | |
1260 | e.SetEventObject(this); | |
1261 | GetEventHandler()->ProcessEvent(e); | |
cd05bf23 | 1262 | return; |
4444d148 WS |
1263 | } |
1264 | ||
1265 | ||
cd05bf23 BW |
1266 | int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X); |
1267 | int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y); | |
1268 | ||
9a29fe70 VZ |
1269 | if (abs(pos.x - m_clickPt.x) > drag_x_threshold || |
1270 | abs(pos.y - m_clickPt.y) > drag_y_threshold) | |
cd05bf23 | 1271 | { |
7d1214cd PC |
1272 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, m_windowId); |
1273 | e.SetSelection(GetIdxFromWindow(m_clickTab)); | |
1274 | e.SetOldSelection(e.GetSelection()); | |
1275 | e.SetEventObject(this); | |
1276 | GetEventHandler()->ProcessEvent(e); | |
4444d148 | 1277 | |
9a29fe70 | 1278 | m_isDragging = true; |
cd05bf23 BW |
1279 | } |
1280 | } | |
1281 | ||
1282 | void wxAuiTabCtrl::OnLeaveWindow(wxMouseEvent& WXUNUSED(event)) | |
1283 | { | |
9a29fe70 | 1284 | if (m_hoverButton) |
cd05bf23 | 1285 | { |
9a29fe70 VZ |
1286 | m_hoverButton->curState = wxAUI_BUTTON_STATE_NORMAL; |
1287 | m_hoverButton = NULL; | |
cd05bf23 BW |
1288 | Refresh(); |
1289 | Update(); | |
1290 | } | |
1291 | } | |
1292 | ||
4953f8cf BW |
1293 | void wxAuiTabCtrl::OnButton(wxAuiNotebookEvent& event) |
1294 | { | |
1295 | int button = event.GetInt(); | |
7baac3cb | 1296 | |
4953f8cf BW |
1297 | if (button == wxAUI_BUTTON_LEFT || button == wxAUI_BUTTON_RIGHT) |
1298 | { | |
1299 | if (button == wxAUI_BUTTON_LEFT) | |
1300 | { | |
1301 | if (GetTabOffset() > 0) | |
1302 | { | |
1303 | SetTabOffset(GetTabOffset()-1); | |
1304 | Refresh(); | |
1305 | Update(); | |
1306 | } | |
1307 | } | |
cedd7b22 | 1308 | else |
4953f8cf BW |
1309 | { |
1310 | SetTabOffset(GetTabOffset()+1); | |
1311 | Refresh(); | |
1312 | Update(); | |
1313 | } | |
01372b8f | 1314 | } |
cedd7b22 | 1315 | else if (button == wxAUI_BUTTON_WINDOWLIST) |
01372b8f | 1316 | { |
793d4365 | 1317 | int idx = GetArtProvider()->ShowDropDown(this, m_pages, GetActivePage()); |
7baac3cb | 1318 | |
01372b8f BW |
1319 | if (idx != -1) |
1320 | { | |
1321 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
1322 | e.SetSelection(idx); | |
1323 | e.SetOldSelection(GetActivePage()); | |
1324 | e.SetEventObject(this); | |
1325 | GetEventHandler()->ProcessEvent(e); | |
1326 | } | |
4953f8cf | 1327 | } |
cedd7b22 | 1328 | else |
4953f8cf BW |
1329 | { |
1330 | event.Skip(); | |
1331 | } | |
1332 | } | |
cd05bf23 | 1333 | |
a0c2e4a0 JS |
1334 | void wxAuiTabCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event)) |
1335 | { | |
1336 | Refresh(); | |
1337 | } | |
1338 | ||
1339 | void wxAuiTabCtrl::OnKillFocus(wxFocusEvent& WXUNUSED(event)) | |
1340 | { | |
1341 | Refresh(); | |
1342 | } | |
1343 | ||
1344 | void wxAuiTabCtrl::OnChar(wxKeyEvent& event) | |
1345 | { | |
1346 | if (GetActivePage() == -1) | |
1347 | { | |
1348 | event.Skip(); | |
1349 | return; | |
1350 | } | |
1351 | ||
1352 | // We can't leave tab processing to the system; on Windows, tabs and keys | |
1353 | // get eaten by the system and not processed properly if we specify both | |
1354 | // wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL, | |
1355 | // we don't key arrow key events. | |
1356 | ||
1357 | int key = event.GetKeyCode(); | |
1358 | ||
1359 | if (key == WXK_NUMPAD_PAGEUP) | |
1360 | key = WXK_PAGEUP; | |
1361 | if (key == WXK_NUMPAD_PAGEDOWN) | |
1362 | key = WXK_PAGEDOWN; | |
1363 | if (key == WXK_NUMPAD_HOME) | |
1364 | key = WXK_HOME; | |
1365 | if (key == WXK_NUMPAD_END) | |
1366 | key = WXK_END; | |
1367 | if (key == WXK_NUMPAD_LEFT) | |
1368 | key = WXK_LEFT; | |
1369 | if (key == WXK_NUMPAD_RIGHT) | |
1370 | key = WXK_RIGHT; | |
1371 | ||
1372 | if (key == WXK_TAB || key == WXK_PAGEUP || key == WXK_PAGEDOWN) | |
1373 | { | |
1374 | bool bCtrlDown = event.ControlDown(); | |
1375 | bool bShiftDown = event.ShiftDown(); | |
1376 | ||
1377 | bool bForward = (key == WXK_TAB && !bShiftDown) || (key == WXK_PAGEDOWN); | |
1378 | bool bWindowChange = (key == WXK_PAGEUP) || (key == WXK_PAGEDOWN) || bCtrlDown; | |
1379 | bool bFromTab = (key == WXK_TAB); | |
1380 | ||
1381 | wxAuiNotebook* nb = wxDynamicCast(GetParent(), wxAuiNotebook); | |
1382 | if (!nb) | |
1383 | { | |
1384 | event.Skip(); | |
1385 | return; | |
1386 | } | |
1387 | ||
1388 | wxNavigationKeyEvent keyEvent; | |
1389 | keyEvent.SetDirection(bForward); | |
1390 | keyEvent.SetWindowChange(bWindowChange); | |
1391 | keyEvent.SetFromTab(bFromTab); | |
1392 | keyEvent.SetEventObject(nb); | |
1393 | ||
1394 | if (!nb->GetEventHandler()->ProcessEvent(keyEvent)) | |
1395 | { | |
1396 | // Not processed? Do an explicit tab into the page. | |
1397 | wxWindow* win = GetWindowFromIdx(GetActivePage()); | |
1398 | if (win) | |
1399 | win->SetFocus(); | |
1400 | } | |
1401 | return; | |
1402 | } | |
1403 | ||
1404 | if (m_pages.GetCount() < 2) | |
1405 | { | |
1406 | event.Skip(); | |
1407 | return; | |
1408 | } | |
1409 | ||
1410 | int newPage = -1; | |
1411 | ||
5c58a3a9 VZ |
1412 | int forwardKey, backwardKey; |
1413 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
1414 | { | |
1415 | forwardKey = WXK_LEFT; | |
1416 | backwardKey = WXK_RIGHT; | |
1417 | } | |
1418 | else | |
1419 | { | |
1420 | forwardKey = WXK_RIGHT; | |
1421 | backwardKey = WXK_LEFT; | |
1422 | } | |
1423 | ||
1424 | if (key == forwardKey) | |
a0c2e4a0 JS |
1425 | { |
1426 | if (m_pages.GetCount() > 1) | |
1427 | { | |
1428 | if (GetActivePage() == -1) | |
1429 | newPage = 0; | |
1430 | else if (GetActivePage() < (int) (m_pages.GetCount() - 1)) | |
1431 | newPage = GetActivePage() + 1; | |
1432 | } | |
1433 | } | |
5c58a3a9 | 1434 | else if (key == backwardKey) |
a0c2e4a0 JS |
1435 | { |
1436 | if (m_pages.GetCount() > 1) | |
1437 | { | |
1438 | if (GetActivePage() == -1) | |
1439 | newPage = (int) (m_pages.GetCount() - 1); | |
1440 | else if (GetActivePage() > 0) | |
1441 | newPage = GetActivePage() - 1; | |
1442 | } | |
1443 | } | |
1444 | else if (key == WXK_HOME) | |
1445 | { | |
1446 | newPage = 0; | |
1447 | } | |
1448 | else if (key == WXK_END) | |
1449 | { | |
1450 | newPage = (int) (m_pages.GetCount() - 1); | |
1451 | } | |
1452 | else | |
1453 | event.Skip(); | |
1454 | ||
1455 | if (newPage != -1) | |
1456 | { | |
1457 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
1458 | e.SetSelection(newPage); | |
1459 | e.SetOldSelection(newPage); | |
1460 | e.SetEventObject(this); | |
1461 | this->GetEventHandler()->ProcessEvent(e); | |
1462 | } | |
1463 | else | |
1464 | event.Skip(); | |
1465 | } | |
1466 | ||
cd05bf23 BW |
1467 | // wxTabFrame is an interesting case. It's important that all child pages |
1468 | // of the multi-notebook control are all actually children of that control | |
1469 | // (and not grandchildren). wxTabFrame facilitates this. There is one | |
1470 | // instance of wxTabFrame for each tab control inside the multi-notebook. | |
1471 | // It's important to know that wxTabFrame is not a real window, but it merely | |
1472 | // used to capture the dimensions/positioning of the internal tab control and | |
1473 | // it's managed page windows | |
1474 | ||
1475 | class wxTabFrame : public wxWindow | |
1476 | { | |
1477 | public: | |
1478 | ||
1479 | wxTabFrame() | |
1480 | { | |
1481 | m_tabs = NULL; | |
1482 | m_rect = wxRect(0,0,200,200); | |
9a29fe70 | 1483 | m_tabCtrlHeight = 20; |
da5e85d9 | 1484 | } |
4444d148 | 1485 | |
cedd7b22 PC |
1486 | ~wxTabFrame() |
1487 | { | |
1488 | wxDELETE(m_tabs); | |
1489 | } | |
bd4e0834 | 1490 | |
da5e85d9 BW |
1491 | void SetTabCtrlHeight(int h) |
1492 | { | |
9a29fe70 | 1493 | m_tabCtrlHeight = h; |
cd05bf23 | 1494 | } |
4444d148 | 1495 | |
cedd7b22 | 1496 | protected: |
cd05bf23 BW |
1497 | void DoSetSize(int x, int y, |
1498 | int width, int height, | |
1499 | int WXUNUSED(sizeFlags = wxSIZE_AUTO)) | |
1500 | { | |
1501 | m_rect = wxRect(x, y, width, height); | |
1502 | DoSizing(); | |
1503 | } | |
4444d148 | 1504 | |
cd05bf23 BW |
1505 | void DoGetClientSize(int* x, int* y) const |
1506 | { | |
1507 | *x = m_rect.width; | |
1508 | *y = m_rect.height; | |
1509 | } | |
4f450f41 | 1510 | |
cedd7b22 | 1511 | public: |
4f450f41 | 1512 | bool Show( bool WXUNUSED(show = true) ) { return false; } |
4444d148 | 1513 | |
cd05bf23 BW |
1514 | void DoSizing() |
1515 | { | |
1516 | if (!m_tabs) | |
1517 | return; | |
4444d148 | 1518 | |
64178c36 JS |
1519 | if (m_tabs->IsFrozen() || m_tabs->GetParent()->IsFrozen()) |
1520 | return; | |
1521 | ||
9a29fe70 | 1522 | m_tab_rect = wxRect(m_rect.x, m_rect.y, m_rect.width, m_tabCtrlHeight); |
134198f1 JS |
1523 | if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM) |
1524 | { | |
9a29fe70 VZ |
1525 | m_tab_rect = wxRect (m_rect.x, m_rect.y + m_rect.height - m_tabCtrlHeight, m_rect.width, m_tabCtrlHeight); |
1526 | m_tabs->SetSize (m_rect.x, m_rect.y + m_rect.height - m_tabCtrlHeight, m_rect.width, m_tabCtrlHeight); | |
1527 | m_tabs->SetRect (wxRect(0, 0, m_rect.width, m_tabCtrlHeight)); | |
134198f1 JS |
1528 | } |
1529 | else //TODO: if (GetFlags() & wxAUI_NB_TOP) | |
1530 | { | |
9a29fe70 VZ |
1531 | m_tab_rect = wxRect (m_rect.x, m_rect.y, m_rect.width, m_tabCtrlHeight); |
1532 | m_tabs->SetSize (m_rect.x, m_rect.y, m_rect.width, m_tabCtrlHeight); | |
1533 | m_tabs->SetRect (wxRect(0, 0, m_rect.width, m_tabCtrlHeight)); | |
134198f1 JS |
1534 | } |
1535 | // TODO: else if (GetFlags() & wxAUI_NB_LEFT){} | |
1536 | // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){} | |
1537 | ||
cd05bf23 | 1538 | m_tabs->Refresh(); |
9d59bf68 | 1539 | m_tabs->Update(); |
4444d148 | 1540 | |
cd05bf23 BW |
1541 | wxAuiNotebookPageArray& pages = m_tabs->GetPages(); |
1542 | size_t i, page_count = pages.GetCount(); | |
4444d148 | 1543 | |
cd05bf23 BW |
1544 | for (i = 0; i < page_count; ++i) |
1545 | { | |
9fa99f04 | 1546 | wxAuiNotebookPage& page = pages.Item(i); |
1e30d94e | 1547 | int border_space = m_tabs->GetArtProvider()->GetAdditionalBorderSpace(page.window); |
9fa99f04 | 1548 | |
1e30d94e | 1549 | int height = m_rect.height - m_tabCtrlHeight - border_space; |
f96f6a88 VZ |
1550 | if ( height < 0 ) |
1551 | { | |
1552 | // avoid passing negative height to wxWindow::SetSize(), this | |
1553 | // results in assert failures/GTK+ warnings | |
1554 | height = 0; | |
1555 | } | |
1556 | ||
134198f1 JS |
1557 | if (m_tabs->GetFlags() & wxAUI_NB_BOTTOM) |
1558 | { | |
1e30d94e VZ |
1559 | page.window->SetSize(m_rect.x + border_space, |
1560 | m_rect.y + border_space, | |
1561 | m_rect.width - 2 * border_space, | |
9fa99f04 | 1562 | height); |
134198f1 JS |
1563 | } |
1564 | else //TODO: if (GetFlags() & wxAUI_NB_TOP) | |
1565 | { | |
1e30d94e | 1566 | page.window->SetSize(m_rect.x + border_space, |
9fa99f04 | 1567 | m_rect.y + m_tabCtrlHeight, |
1e30d94e | 1568 | m_rect.width - 2 * border_space, |
9fa99f04 | 1569 | height); |
134198f1 JS |
1570 | } |
1571 | // TODO: else if (GetFlags() & wxAUI_NB_LEFT){} | |
1572 | // TODO: else if (GetFlags() & wxAUI_NB_RIGHT){} | |
4444d148 | 1573 | |
89272c55 | 1574 | #if wxUSE_MDI |
345c78ca | 1575 | if (wxDynamicCast(page.window, wxAuiMDIChildFrame)) |
cd05bf23 | 1576 | { |
a3a5df9d | 1577 | wxAuiMDIChildFrame* wnd = (wxAuiMDIChildFrame*)page.window; |
cd05bf23 BW |
1578 | wnd->ApplyMDIChildFrameRect(); |
1579 | } | |
89272c55 | 1580 | #endif |
cd05bf23 BW |
1581 | } |
1582 | } | |
1583 | ||
cedd7b22 | 1584 | protected: |
134e83cb BW |
1585 | void DoGetSize(int* x, int* y) const |
1586 | { | |
1587 | if (x) | |
1588 | *x = m_rect.GetWidth(); | |
1589 | if (y) | |
1590 | *y = m_rect.GetHeight(); | |
1591 | } | |
4444d148 | 1592 | |
cedd7b22 | 1593 | public: |
134e83cb BW |
1594 | void Update() |
1595 | { | |
1596 | // does nothing | |
1597 | } | |
4444d148 | 1598 | |
cd05bf23 BW |
1599 | wxRect m_rect; |
1600 | wxRect m_tab_rect; | |
1601 | wxAuiTabCtrl* m_tabs; | |
9a29fe70 | 1602 | int m_tabCtrlHeight; |
cd05bf23 BW |
1603 | }; |
1604 | ||
1605 | ||
7ebc40e8 | 1606 | const int wxAuiBaseTabCtrlId = 5380; |
cd05bf23 BW |
1607 | |
1608 | ||
a3a5df9d | 1609 | // -- wxAuiNotebook class implementation -- |
cd05bf23 | 1610 | |
3c778901 VZ |
1611 | #define EVT_AUI_RANGE(id1, id2, event, func) \ |
1612 | wx__DECLARE_EVT2(event, id1, id2, wxAuiNotebookEventHandler(func)) | |
1613 | ||
a3a5df9d | 1614 | BEGIN_EVENT_TABLE(wxAuiNotebook, wxControl) |
9fbb7d80 | 1615 | EVT_SIZE(wxAuiNotebook::OnSize) |
5bf3f27f | 1616 | EVT_CHILD_FOCUS(wxAuiNotebook::OnChildFocusNotebook) |
3c778901 | 1617 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 1618 | wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, |
a3a5df9d | 1619 | wxAuiNotebook::OnTabClicked) |
3c778901 | 1620 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 1621 | wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, |
a3a5df9d | 1622 | wxAuiNotebook::OnTabBeginDrag) |
3c778901 | 1623 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 1624 | wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, |
a3a5df9d | 1625 | wxAuiNotebook::OnTabEndDrag) |
2bd82d72 VZ |
1626 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
1627 | wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, | |
1628 | wxAuiNotebook::OnTabCancelDrag) | |
3c778901 | 1629 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 1630 | wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, |
a3a5df9d | 1631 | wxAuiNotebook::OnTabDragMotion) |
3c778901 | 1632 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
cd05bf23 | 1633 | wxEVT_COMMAND_AUINOTEBOOK_BUTTON, |
a3a5df9d | 1634 | wxAuiNotebook::OnTabButton) |
3c778901 | 1635 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
1636 | wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, |
1637 | wxAuiNotebook::OnTabMiddleDown) | |
3c778901 | 1638 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
1639 | wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, |
1640 | wxAuiNotebook::OnTabMiddleUp) | |
3c778901 | 1641 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
1642 | wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, |
1643 | wxAuiNotebook::OnTabRightDown) | |
3c778901 | 1644 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
69f5e420 BW |
1645 | wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, |
1646 | wxAuiNotebook::OnTabRightUp) | |
3c778901 | 1647 | EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, |
198be845 JS |
1648 | wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, |
1649 | wxAuiNotebook::OnTabBgDClick) | |
5bf3f27f | 1650 | EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook) |
cd05bf23 BW |
1651 | END_EVENT_TABLE() |
1652 | ||
90230407 | 1653 | void wxAuiNotebook::Init() |
cd05bf23 | 1654 | { |
9a29fe70 VZ |
1655 | m_curPage = -1; |
1656 | m_tabIdCounter = wxAuiBaseTabCtrlId; | |
1657 | m_dummyWnd = NULL; | |
1658 | m_tabCtrlHeight = 20; | |
1659 | m_requestedBmpSize = wxDefaultSize; | |
1660 | m_requestedTabCtrlHeight = -1; | |
cd05bf23 BW |
1661 | } |
1662 | ||
a3a5df9d | 1663 | bool wxAuiNotebook::Create(wxWindow* parent, |
cd05bf23 BW |
1664 | wxWindowID id, |
1665 | const wxPoint& pos, | |
1666 | const wxSize& size, | |
1667 | long style) | |
1668 | { | |
1669 | if (!wxControl::Create(parent, id, pos, size, style)) | |
1670 | return false; | |
4444d148 | 1671 | |
702b1c7e | 1672 | InitNotebook(style); |
4444d148 | 1673 | |
cd05bf23 BW |
1674 | return true; |
1675 | } | |
1676 | ||
1677 | // InitNotebook() contains common initialization | |
1678 | // code called by all constructors | |
a3a5df9d | 1679 | void wxAuiNotebook::InitNotebook(long style) |
cd05bf23 | 1680 | { |
c7bfb76a | 1681 | SetName(wxT("wxAuiNotebook")); |
9a29fe70 VZ |
1682 | m_curPage = -1; |
1683 | m_tabIdCounter = wxAuiBaseTabCtrlId; | |
1684 | m_dummyWnd = NULL; | |
702b1c7e | 1685 | m_flags = (unsigned int)style; |
9a29fe70 | 1686 | m_tabCtrlHeight = 20; |
c58ba15f | 1687 | |
9a29fe70 VZ |
1688 | m_normalFont = *wxNORMAL_FONT; |
1689 | m_selectedFont = *wxNORMAL_FONT; | |
1690 | m_selectedFont.SetWeight(wxBOLD); | |
4444d148 | 1691 | |
b0d17f7c | 1692 | SetArtProvider(new wxAuiDefaultTabArt); |
4444d148 | 1693 | |
9a29fe70 VZ |
1694 | m_dummyWnd = new wxWindow(this, wxID_ANY, wxPoint(0,0), wxSize(0,0)); |
1695 | m_dummyWnd->SetSize(200, 200); | |
1696 | m_dummyWnd->Show(false); | |
4444d148 | 1697 | |
cd05bf23 | 1698 | m_mgr.SetManagedWindow(this); |
a6b7a521 VZ |
1699 | m_mgr.SetFlags(wxAUI_MGR_DEFAULT); |
1700 | m_mgr.SetDockSizeConstraint(1.0, 1.0); // no dock size constraint | |
4444d148 | 1701 | |
9a29fe70 | 1702 | m_mgr.AddPane(m_dummyWnd, |
9fbb7d80 | 1703 | wxAuiPaneInfo().Name(wxT("dummy")).Bottom().CaptionVisible(false).Show(false)); |
4444d148 | 1704 | |
cd05bf23 BW |
1705 | m_mgr.Update(); |
1706 | } | |
1707 | ||
a3a5df9d | 1708 | wxAuiNotebook::~wxAuiNotebook() |
cd05bf23 | 1709 | { |
18b40f30 | 1710 | // Indicate we're deleting pages |
c6212a0c | 1711 | SendDestroyEvent(); |
18b40f30 | 1712 | |
1c0955dd JS |
1713 | while ( GetPageCount() > 0 ) |
1714 | DeletePage(0); | |
1715 | ||
cd05bf23 BW |
1716 | m_mgr.UnInit(); |
1717 | } | |
1718 | ||
a3a5df9d | 1719 | void wxAuiNotebook::SetArtProvider(wxAuiTabArt* art) |
3f69756e BW |
1720 | { |
1721 | m_tabs.SetArtProvider(art); | |
7baac3cb | 1722 | |
4026f044 VZ |
1723 | // Update the height and do nothing else if it did something but otherwise |
1724 | // (i.e. if the new art provider uses the same height as the old one) we | |
1725 | // need to manually set the art provider for all tabs ourselves. | |
1726 | if ( !UpdateTabCtrlHeight() ) | |
1727 | { | |
1728 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
1729 | const size_t pane_count = all_panes.GetCount(); | |
1730 | for (size_t i = 0; i < pane_count; ++i) | |
1731 | { | |
1732 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
1733 | if (pane.name == wxT("dummy")) | |
1734 | continue; | |
1735 | wxTabFrame* tab_frame = (wxTabFrame*)pane.window; | |
1736 | wxAuiTabCtrl* tabctrl = tab_frame->m_tabs; | |
1737 | tabctrl->SetArtProvider(art->Clone()); | |
1738 | } | |
1739 | } | |
2b9aac33 BW |
1740 | } |
1741 | ||
ca0d4407 BW |
1742 | // SetTabCtrlHeight() is the highest-level override of the |
1743 | // tab height. A call to this function effectively enforces a | |
1744 | // specified tab ctrl height, overriding all other considerations, | |
1745 | // such as text or bitmap height. It overrides any call to | |
1746 | // SetUniformBitmapSize(). Specifying a height of -1 reverts | |
4c51a665 | 1747 | // any previous call and returns to the default behaviour |
ca0d4407 BW |
1748 | |
1749 | void wxAuiNotebook::SetTabCtrlHeight(int height) | |
1750 | { | |
9a29fe70 | 1751 | m_requestedTabCtrlHeight = height; |
c58ba15f | 1752 | |
ca0d4407 | 1753 | // if window is already initialized, recalculate the tab height |
9a29fe70 | 1754 | if (m_dummyWnd) |
ca0d4407 BW |
1755 | { |
1756 | UpdateTabCtrlHeight(); | |
1757 | } | |
1758 | } | |
1759 | ||
1760 | ||
1761 | // SetUniformBitmapSize() ensures that all tabs will have | |
1762 | // the same height, even if some tabs don't have bitmaps | |
1763 | // Passing wxDefaultSize to this function will instruct | |
1764 | // the control to use dynamic tab height-- so when a tab | |
1765 | // with a large bitmap is added, the tab ctrl's height will | |
1766 | // automatically increase to accommodate the bitmap | |
1767 | ||
9fbb7d80 BW |
1768 | void wxAuiNotebook::SetUniformBitmapSize(const wxSize& size) |
1769 | { | |
9a29fe70 | 1770 | m_requestedBmpSize = size; |
c58ba15f | 1771 | |
9fbb7d80 | 1772 | // if window is already initialized, recalculate the tab height |
9a29fe70 | 1773 | if (m_dummyWnd) |
dbbe02ea | 1774 | { |
ca0d4407 | 1775 | UpdateTabCtrlHeight(); |
dbbe02ea | 1776 | } |
9fbb7d80 BW |
1777 | } |
1778 | ||
ca0d4407 | 1779 | // UpdateTabCtrlHeight() does the actual tab resizing. It's meant |
4026f044 VZ |
1780 | // to be used internally |
1781 | bool wxAuiNotebook::UpdateTabCtrlHeight() | |
2b9aac33 | 1782 | { |
ca0d4407 BW |
1783 | // get the tab ctrl height we will use |
1784 | int height = CalculateTabCtrlHeight(); | |
c58ba15f | 1785 | |
2b9aac33 BW |
1786 | // if the tab control height needs to change, update |
1787 | // all of our tab controls with the new height | |
9a29fe70 | 1788 | if (m_tabCtrlHeight == height) |
4026f044 | 1789 | return false; |
7baac3cb | 1790 | |
4026f044 | 1791 | wxAuiTabArt* art = m_tabs.GetArtProvider(); |
7baac3cb | 1792 | |
9a29fe70 | 1793 | m_tabCtrlHeight = height; |
4026f044 VZ |
1794 | |
1795 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
1796 | size_t i, pane_count = all_panes.GetCount(); | |
1797 | for (i = 0; i < pane_count; ++i) | |
1798 | { | |
1799 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
1800 | if (pane.name == wxT("dummy")) | |
1801 | continue; | |
1802 | wxTabFrame* tab_frame = (wxTabFrame*)pane.window; | |
1803 | wxAuiTabCtrl* tabctrl = tab_frame->m_tabs; | |
9a29fe70 | 1804 | tab_frame->SetTabCtrlHeight(m_tabCtrlHeight); |
4026f044 VZ |
1805 | tabctrl->SetArtProvider(art->Clone()); |
1806 | tab_frame->DoSizing(); | |
b0d17f7c | 1807 | } |
4026f044 VZ |
1808 | |
1809 | return true; | |
3f69756e BW |
1810 | } |
1811 | ||
9fbb7d80 BW |
1812 | void wxAuiNotebook::UpdateHintWindowSize() |
1813 | { | |
1814 | wxSize size = CalculateNewSplitSize(); | |
c58ba15f | 1815 | |
9fbb7d80 BW |
1816 | // the placeholder hint window should be set to this size |
1817 | wxAuiPaneInfo& info = m_mgr.GetPane(wxT("dummy")); | |
1818 | if (info.IsOk()) | |
1819 | { | |
1820 | info.MinSize(size); | |
1821 | info.BestSize(size); | |
9a29fe70 | 1822 | m_dummyWnd->SetSize(size); |
9fbb7d80 BW |
1823 | } |
1824 | } | |
1825 | ||
1826 | ||
1827 | // calculates the size of the new split | |
1828 | wxSize wxAuiNotebook::CalculateNewSplitSize() | |
1829 | { | |
1830 | // count number of tab controls | |
1831 | int tab_ctrl_count = 0; | |
1832 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
1833 | size_t i, pane_count = all_panes.GetCount(); | |
1834 | for (i = 0; i < pane_count; ++i) | |
1835 | { | |
1836 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
1837 | if (pane.name == wxT("dummy")) | |
1838 | continue; | |
1839 | tab_ctrl_count++; | |
1840 | } | |
1841 | ||
1842 | wxSize new_split_size; | |
c58ba15f | 1843 | |
9fbb7d80 BW |
1844 | // if there is only one tab control, the first split |
1845 | // should happen around the middle | |
1846 | if (tab_ctrl_count < 2) | |
1847 | { | |
1848 | new_split_size = GetClientSize(); | |
1849 | new_split_size.x /= 2; | |
1850 | new_split_size.y /= 2; | |
1851 | } | |
cedd7b22 | 1852 | else |
9fbb7d80 BW |
1853 | { |
1854 | // this is in place of a more complicated calculation | |
1855 | // that needs to be implemented | |
1856 | new_split_size = wxSize(180,180); | |
1857 | } | |
c58ba15f | 1858 | |
9fbb7d80 BW |
1859 | return new_split_size; |
1860 | } | |
1861 | ||
2b9aac33 BW |
1862 | int wxAuiNotebook::CalculateTabCtrlHeight() |
1863 | { | |
ca0d4407 BW |
1864 | // if a fixed tab ctrl height is specified, |
1865 | // just return that instead of calculating a | |
1866 | // tab height | |
9a29fe70 VZ |
1867 | if (m_requestedTabCtrlHeight != -1) |
1868 | return m_requestedTabCtrlHeight; | |
c58ba15f | 1869 | |
2b9aac33 BW |
1870 | // find out new best tab height |
1871 | wxAuiTabArt* art = m_tabs.GetArtProvider(); | |
7baac3cb | 1872 | |
9fbb7d80 BW |
1873 | return art->GetBestTabCtrlSize(this, |
1874 | m_tabs.GetPages(), | |
9a29fe70 | 1875 | m_requestedBmpSize); |
2b9aac33 BW |
1876 | } |
1877 | ||
1878 | ||
e0dc13d4 | 1879 | wxAuiTabArt* wxAuiNotebook::GetArtProvider() const |
3f69756e BW |
1880 | { |
1881 | return m_tabs.GetArtProvider(); | |
1882 | } | |
1883 | ||
0ce53f32 BW |
1884 | void wxAuiNotebook::SetWindowStyleFlag(long style) |
1885 | { | |
1886 | wxControl::SetWindowStyleFlag(style); | |
7baac3cb | 1887 | |
0ce53f32 | 1888 | m_flags = (unsigned int)style; |
7baac3cb | 1889 | |
0ce53f32 BW |
1890 | // if the control is already initialized |
1891 | if (m_mgr.GetManagedWindow() == (wxWindow*)this) | |
1892 | { | |
1893 | // let all of the tab children know about the new style | |
7baac3cb | 1894 | |
0ce53f32 BW |
1895 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
1896 | size_t i, pane_count = all_panes.GetCount(); | |
1897 | for (i = 0; i < pane_count; ++i) | |
1898 | { | |
1899 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
1900 | if (pane.name == wxT("dummy")) | |
1901 | continue; | |
97ac2d5e BW |
1902 | wxTabFrame* tabframe = (wxTabFrame*)pane.window; |
1903 | wxAuiTabCtrl* tabctrl = tabframe->m_tabs; | |
0ce53f32 | 1904 | tabctrl->SetFlags(m_flags); |
97ac2d5e | 1905 | tabframe->DoSizing(); |
0ce53f32 BW |
1906 | tabctrl->Refresh(); |
1907 | tabctrl->Update(); | |
1908 | } | |
1909 | } | |
1910 | } | |
1911 | ||
1912 | ||
a3a5df9d | 1913 | bool wxAuiNotebook::AddPage(wxWindow* page, |
cd05bf23 BW |
1914 | const wxString& caption, |
1915 | bool select, | |
1916 | const wxBitmap& bitmap) | |
1917 | { | |
1918 | return InsertPage(GetPageCount(), page, caption, select, bitmap); | |
1919 | } | |
4444d148 | 1920 | |
a3a5df9d | 1921 | bool wxAuiNotebook::InsertPage(size_t page_idx, |
cd05bf23 BW |
1922 | wxWindow* page, |
1923 | const wxString& caption, | |
1924 | bool select, | |
1925 | const wxBitmap& bitmap) | |
1926 | { | |
c36cdfc0 BW |
1927 | wxASSERT_MSG(page, wxT("page pointer must be non-NULL")); |
1928 | if (!page) | |
1929 | return false; | |
5c58a3a9 | 1930 | |
3d9b52a8 JS |
1931 | page->Reparent(this); |
1932 | ||
cd05bf23 BW |
1933 | wxAuiNotebookPage info; |
1934 | info.window = page; | |
1935 | info.caption = caption; | |
1936 | info.bitmap = bitmap; | |
1937 | info.active = false; | |
1938 | ||
1939 | // if there are currently no tabs, the first added | |
1940 | // tab must be active | |
1941 | if (m_tabs.GetPageCount() == 0) | |
1942 | info.active = true; | |
1943 | ||
1944 | m_tabs.InsertPage(page, info, page_idx); | |
1945 | ||
298773ec BW |
1946 | // if that was the first page added, even if |
1947 | // select is false, it must become the "current page" | |
1948 | // (though no select events will be fired) | |
1949 | if (!select && m_tabs.GetPageCount() == 1) | |
092d7f88 | 1950 | select = true; |
9a29fe70 | 1951 | //m_curPage = GetPageIndex(page); |
298773ec | 1952 | |
cd05bf23 BW |
1953 | wxAuiTabCtrl* active_tabctrl = GetActiveTabCtrl(); |
1954 | if (page_idx >= active_tabctrl->GetPageCount()) | |
1955 | active_tabctrl->AddPage(page, info); | |
cedd7b22 | 1956 | else |
cd05bf23 | 1957 | active_tabctrl->InsertPage(page, info, page_idx); |
4444d148 | 1958 | |
ca0d4407 | 1959 | UpdateTabCtrlHeight(); |
cd05bf23 BW |
1960 | DoSizing(); |
1961 | active_tabctrl->DoShowHide(); | |
4444d148 | 1962 | |
3d9b52a8 | 1963 | // adjust selected index |
9a29fe70 VZ |
1964 | if(m_curPage >= (int) page_idx) |
1965 | m_curPage++; | |
3d9b52a8 | 1966 | |
cd05bf23 BW |
1967 | if (select) |
1968 | { | |
849c353a | 1969 | SetSelectionToWindow(page); |
cd05bf23 | 1970 | } |
4444d148 | 1971 | |
cd05bf23 BW |
1972 | return true; |
1973 | } | |
1974 | ||
1975 | ||
1976 | // DeletePage() removes a tab from the multi-notebook, | |
1977 | // and destroys the window as well | |
a3a5df9d | 1978 | bool wxAuiNotebook::DeletePage(size_t page_idx) |
7baac3cb | 1979 | { |
fd749f4a BW |
1980 | if (page_idx >= m_tabs.GetPageCount()) |
1981 | return false; | |
cedd7b22 | 1982 | |
4444d148 | 1983 | wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); |
cedd7b22 | 1984 | |
fd749f4a BW |
1985 | // hide the window in advance, as this will |
1986 | // prevent flicker | |
1987 | ShowWnd(wnd, false); | |
5d3aeb0f BW |
1988 | |
1989 | if (!RemovePage(page_idx)) | |
1990 | return false; | |
1991 | ||
89272c55 | 1992 | #if wxUSE_MDI |
5d3aeb0f | 1993 | // actually destroy the window now |
345c78ca | 1994 | if (wxDynamicCast(wnd, wxAuiMDIChildFrame)) |
5d3aeb0f BW |
1995 | { |
1996 | // delete the child frame with pending delete, as is | |
1997 | // customary with frame windows | |
1998 | if (!wxPendingDelete.Member(wnd)) | |
1999 | wxPendingDelete.Append(wnd); | |
2000 | } | |
cedd7b22 | 2001 | else |
89272c55 | 2002 | #endif |
5d3aeb0f BW |
2003 | { |
2004 | wnd->Destroy(); | |
2005 | } | |
7baac3cb | 2006 | |
5d3aeb0f | 2007 | return true; |
cd05bf23 BW |
2008 | } |
2009 | ||
2010 | ||
2011 | ||
2012 | // RemovePage() removes a tab from the multi-notebook, | |
2013 | // but does not destroy the window | |
a3a5df9d | 2014 | bool wxAuiNotebook::RemovePage(size_t page_idx) |
cd05bf23 | 2015 | { |
9b362935 BW |
2016 | // save active window pointer |
2017 | wxWindow* active_wnd = NULL; | |
9a29fe70 VZ |
2018 | if (m_curPage >= 0) |
2019 | active_wnd = m_tabs.GetWindowFromIdx(m_curPage); | |
cedd7b22 | 2020 | |
9b362935 | 2021 | // save pointer of window being deleted |
cd05bf23 | 2022 | wxWindow* wnd = m_tabs.GetWindowFromIdx(page_idx); |
5d3aeb0f | 2023 | wxWindow* new_active = NULL; |
4444d148 | 2024 | |
13aaa50f BW |
2025 | // make sure we found the page |
2026 | if (!wnd) | |
2027 | return false; | |
cedd7b22 | 2028 | |
5d3aeb0f | 2029 | // find out which onscreen tab ctrl owns this tab |
cd05bf23 BW |
2030 | wxAuiTabCtrl* ctrl; |
2031 | int ctrl_idx; | |
5d3aeb0f BW |
2032 | if (!FindTab(wnd, &ctrl, &ctrl_idx)) |
2033 | return false; | |
2034 | ||
9a29fe70 | 2035 | bool is_curpage = (m_curPage == (int)page_idx); |
13aaa50f | 2036 | bool is_active_in_split = ctrl->GetPage(ctrl_idx).active; |
5d3aeb0f | 2037 | |
4444d148 | 2038 | |
5d3aeb0f BW |
2039 | // remove the tab from main catalog |
2040 | if (!m_tabs.RemovePage(wnd)) | |
2041 | return false; | |
2042 | ||
2043 | // remove the tab from the onscreen tab ctrl | |
2044 | ctrl->RemovePage(wnd); | |
2045 | ||
13aaa50f BW |
2046 | if (is_active_in_split) |
2047 | { | |
2048 | int ctrl_new_page_count = (int)ctrl->GetPageCount(); | |
cedd7b22 | 2049 | |
13aaa50f BW |
2050 | if (ctrl_idx >= ctrl_new_page_count) |
2051 | ctrl_idx = ctrl_new_page_count-1; | |
cedd7b22 | 2052 | |
13aaa50f BW |
2053 | if (ctrl_idx >= 0 && ctrl_idx < (int)ctrl->GetPageCount()) |
2054 | { | |
2055 | // set new page as active in the tab split | |
2056 | ctrl->SetActivePage(ctrl_idx); | |
cedd7b22 | 2057 | |
13aaa50f BW |
2058 | // if the page deleted was the current page for the |
2059 | // entire tab control, then record the window | |
2060 | // pointer of the new active page for activation | |
2061 | if (is_curpage) | |
2062 | { | |
2063 | new_active = ctrl->GetWindowFromIdx(ctrl_idx); | |
2064 | } | |
2065 | } | |
2066 | } | |
cedd7b22 | 2067 | else |
9b362935 BW |
2068 | { |
2069 | // we are not deleting the active page, so keep it the same | |
2070 | new_active = active_wnd; | |
2071 | } | |
13aaa50f | 2072 | |
cedd7b22 | 2073 | |
13aaa50f BW |
2074 | if (!new_active) |
2075 | { | |
2076 | // we haven't yet found a new page to active, | |
2077 | // so select the next page from the main tab | |
2078 | // catalogue | |
cedd7b22 | 2079 | |
13aaa50f BW |
2080 | if (page_idx < m_tabs.GetPageCount()) |
2081 | { | |
2082 | new_active = m_tabs.GetPage(page_idx).window; | |
2083 | } | |
cedd7b22 | 2084 | |
13aaa50f BW |
2085 | if (!new_active && m_tabs.GetPageCount() > 0) |
2086 | { | |
2087 | new_active = m_tabs.GetPage(0).window; | |
2088 | } | |
2089 | } | |
5d3aeb0f | 2090 | |
cedd7b22 | 2091 | |
5d3aeb0f BW |
2092 | RemoveEmptyTabFrames(); |
2093 | ||
9a29fe70 | 2094 | m_curPage = wxNOT_FOUND; |
917f228a VZ |
2095 | |
2096 | // set new active pane unless we're being destroyed anyhow | |
18b40f30 | 2097 | if (new_active && !m_isBeingDeleted) |
849c353a | 2098 | SetSelectionToWindow(new_active); |
cedd7b22 | 2099 | |
5d3aeb0f | 2100 | return true; |
cd05bf23 BW |
2101 | } |
2102 | ||
e0dc13d4 BW |
2103 | // GetPageIndex() returns the index of the page, or -1 if the |
2104 | // page could not be located in the notebook | |
2105 | int wxAuiNotebook::GetPageIndex(wxWindow* page_wnd) const | |
2106 | { | |
2107 | return m_tabs.GetIdxFromWindow(page_wnd); | |
2108 | } | |
2109 | ||
2110 | ||
2111 | ||
cd05bf23 | 2112 | // SetPageText() changes the tab caption of the specified page |
a3a5df9d | 2113 | bool wxAuiNotebook::SetPageText(size_t page_idx, const wxString& text) |
4444d148 | 2114 | { |
cd05bf23 BW |
2115 | if (page_idx >= m_tabs.GetPageCount()) |
2116 | return false; | |
4444d148 | 2117 | |
cd05bf23 BW |
2118 | // update our own tab catalog |
2119 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
2120 | page_info.caption = text; | |
4444d148 | 2121 | |
cd05bf23 BW |
2122 | // update what's on screen |
2123 | wxAuiTabCtrl* ctrl; | |
2124 | int ctrl_idx; | |
2125 | if (FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
2126 | { | |
2127 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
2128 | info.caption = text; | |
2129 | ctrl->Refresh(); | |
639a4f7b | 2130 | ctrl->Update(); |
cd05bf23 | 2131 | } |
4444d148 | 2132 | |
cd05bf23 BW |
2133 | return true; |
2134 | } | |
2135 | ||
c3e016e4 JS |
2136 | // returns the page caption |
2137 | wxString wxAuiNotebook::GetPageText(size_t page_idx) const | |
2138 | { | |
2139 | if (page_idx >= m_tabs.GetPageCount()) | |
2140 | return wxEmptyString; | |
2141 | ||
2142 | // update our own tab catalog | |
2143 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
2144 | return page_info.caption; | |
2145 | } | |
e0dc13d4 | 2146 | |
11527fc9 VZ |
2147 | bool wxAuiNotebook::SetPageToolTip(size_t page_idx, const wxString& text) |
2148 | { | |
2149 | if (page_idx >= m_tabs.GetPageCount()) | |
2150 | return false; | |
2151 | ||
2152 | // update our own tab catalog | |
2153 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
2154 | page_info.tooltip = text; | |
2155 | ||
2156 | wxAuiTabCtrl* ctrl; | |
2157 | int ctrl_idx; | |
2158 | if (!FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
2159 | return false; | |
2160 | ||
2161 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
2162 | info.tooltip = text; | |
2163 | ||
2164 | // NB: we don't update the tooltip if it is already being displayed, it | |
2165 | // typically never happens, no need to code that | |
2166 | return true; | |
2167 | } | |
2168 | ||
2169 | wxString wxAuiNotebook::GetPageToolTip(size_t page_idx) const | |
2170 | { | |
2171 | if (page_idx >= m_tabs.GetPageCount()) | |
2172 | return wxString(); | |
2173 | ||
2174 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
2175 | return page_info.tooltip; | |
2176 | } | |
2177 | ||
e0dc13d4 BW |
2178 | bool wxAuiNotebook::SetPageBitmap(size_t page_idx, const wxBitmap& bitmap) |
2179 | { | |
2180 | if (page_idx >= m_tabs.GetPageCount()) | |
2181 | return false; | |
7baac3cb | 2182 | |
e0dc13d4 BW |
2183 | // update our own tab catalog |
2184 | wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
2185 | page_info.bitmap = bitmap; | |
7baac3cb | 2186 | |
e0dc13d4 | 2187 | // tab height might have changed |
ca0d4407 | 2188 | UpdateTabCtrlHeight(); |
7baac3cb | 2189 | |
e0dc13d4 BW |
2190 | // update what's on screen |
2191 | wxAuiTabCtrl* ctrl; | |
2192 | int ctrl_idx; | |
2193 | if (FindTab(page_info.window, &ctrl, &ctrl_idx)) | |
2194 | { | |
2195 | wxAuiNotebookPage& info = ctrl->GetPage(ctrl_idx); | |
2196 | info.bitmap = bitmap; | |
2197 | ctrl->Refresh(); | |
2198 | ctrl->Update(); | |
2199 | } | |
7baac3cb | 2200 | |
e0dc13d4 BW |
2201 | return true; |
2202 | } | |
2203 | ||
c3e016e4 JS |
2204 | // returns the page bitmap |
2205 | wxBitmap wxAuiNotebook::GetPageBitmap(size_t page_idx) const | |
2206 | { | |
2207 | if (page_idx >= m_tabs.GetPageCount()) | |
2208 | return wxBitmap(); | |
2209 | ||
2210 | // update our own tab catalog | |
2211 | const wxAuiNotebookPage& page_info = m_tabs.GetPage(page_idx); | |
2212 | return page_info.bitmap; | |
2213 | } | |
e0dc13d4 | 2214 | |
cd05bf23 | 2215 | // GetSelection() returns the index of the currently active page |
a3a5df9d | 2216 | int wxAuiNotebook::GetSelection() const |
cd05bf23 | 2217 | { |
9a29fe70 | 2218 | return m_curPage; |
cd05bf23 BW |
2219 | } |
2220 | ||
2221 | // SetSelection() sets the currently active page | |
873ff54b | 2222 | int wxAuiNotebook::SetSelection(size_t new_page) |
cd05bf23 | 2223 | { |
873ff54b | 2224 | return DoModifySelection(new_page, true); |
cd05bf23 BW |
2225 | } |
2226 | ||
849c353a VZ |
2227 | void wxAuiNotebook::SetSelectionToWindow(wxWindow *win) |
2228 | { | |
2229 | const int idx = m_tabs.GetIdxFromWindow(win); | |
9a83f860 | 2230 | wxCHECK_RET( idx != wxNOT_FOUND, wxT("invalid notebook page") ); |
849c353a | 2231 | |
ea34484c BW |
2232 | |
2233 | // since a tab was clicked, let the parent know that we received | |
2234 | // the focus, even if we will assign that focus immediately | |
2235 | // to the child tab in the SetSelection call below | |
2236 | // (the child focus event will also let wxAuiManager, if any, | |
2237 | // know that the notebook control has been activated) | |
03647350 | 2238 | |
ea34484c BW |
2239 | wxWindow* parent = GetParent(); |
2240 | if (parent) | |
2241 | { | |
2242 | wxChildFocusEvent eventFocus(this); | |
2243 | parent->GetEventHandler()->ProcessEvent(eventFocus); | |
2244 | } | |
2245 | ||
2246 | ||
849c353a VZ |
2247 | SetSelection(idx); |
2248 | } | |
2249 | ||
cd05bf23 BW |
2250 | // GetPageCount() returns the total number of |
2251 | // pages managed by the multi-notebook | |
a3a5df9d | 2252 | size_t wxAuiNotebook::GetPageCount() const |
cd05bf23 BW |
2253 | { |
2254 | return m_tabs.GetPageCount(); | |
2255 | } | |
2256 | ||
2257 | // GetPage() returns the wxWindow pointer of the | |
2258 | // specified page | |
a3a5df9d | 2259 | wxWindow* wxAuiNotebook::GetPage(size_t page_idx) const |
cd05bf23 BW |
2260 | { |
2261 | wxASSERT(page_idx < m_tabs.GetPageCount()); | |
4444d148 | 2262 | |
cd05bf23 BW |
2263 | return m_tabs.GetWindowFromIdx(page_idx); |
2264 | } | |
2265 | ||
2266 | // DoSizing() performs all sizing operations in each tab control | |
a3a5df9d | 2267 | void wxAuiNotebook::DoSizing() |
cd05bf23 | 2268 | { |
a3a5df9d | 2269 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2270 | size_t i, pane_count = all_panes.GetCount(); |
2271 | for (i = 0; i < pane_count; ++i) | |
2272 | { | |
2273 | if (all_panes.Item(i).name == wxT("dummy")) | |
2274 | continue; | |
2275 | ||
2276 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; | |
2277 | tabframe->DoSizing(); | |
2278 | } | |
2279 | } | |
2280 | ||
2281 | // GetActiveTabCtrl() returns the active tab control. It is | |
2282 | // called to determine which control gets new windows being added | |
a3a5df9d | 2283 | wxAuiTabCtrl* wxAuiNotebook::GetActiveTabCtrl() |
cd05bf23 | 2284 | { |
9a29fe70 | 2285 | if (m_curPage >= 0 && m_curPage < (int)m_tabs.GetPageCount()) |
cd05bf23 BW |
2286 | { |
2287 | wxAuiTabCtrl* ctrl; | |
2288 | int idx; | |
4444d148 | 2289 | |
cd05bf23 | 2290 | // find the tab ctrl with the current page |
9a29fe70 | 2291 | if (FindTab(m_tabs.GetPage(m_curPage).window, |
cd05bf23 | 2292 | &ctrl, &idx)) |
4444d148 | 2293 | { |
cd05bf23 BW |
2294 | return ctrl; |
2295 | } | |
2296 | } | |
4444d148 | 2297 | |
cd05bf23 | 2298 | // no current page, just find the first tab ctrl |
a3a5df9d | 2299 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2300 | size_t i, pane_count = all_panes.GetCount(); |
2301 | for (i = 0; i < pane_count; ++i) | |
2302 | { | |
2303 | if (all_panes.Item(i).name == wxT("dummy")) | |
2304 | continue; | |
4444d148 | 2305 | |
cd05bf23 BW |
2306 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
2307 | return tabframe->m_tabs; | |
2308 | } | |
4444d148 | 2309 | |
cd05bf23 BW |
2310 | // If there is no tabframe at all, create one |
2311 | wxTabFrame* tabframe = new wxTabFrame; | |
9a29fe70 | 2312 | tabframe->SetTabCtrlHeight(m_tabCtrlHeight); |
cd05bf23 | 2313 | tabframe->m_tabs = new wxAuiTabCtrl(this, |
9a29fe70 | 2314 | m_tabIdCounter++, |
cd05bf23 BW |
2315 | wxDefaultPosition, |
2316 | wxDefaultSize, | |
a0c2e4a0 | 2317 | wxNO_BORDER|wxWANTS_CHARS); |
702b1c7e | 2318 | tabframe->m_tabs->SetFlags(m_flags); |
b0d17f7c | 2319 | tabframe->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); |
cd05bf23 | 2320 | m_mgr.AddPane(tabframe, |
a3a5df9d | 2321 | wxAuiPaneInfo().Center().CaptionVisible(false)); |
4444d148 | 2322 | |
cd05bf23 | 2323 | m_mgr.Update(); |
4444d148 | 2324 | |
cd05bf23 BW |
2325 | return tabframe->m_tabs; |
2326 | } | |
2327 | ||
2328 | // FindTab() finds the tab control that currently contains the window as well | |
2329 | // as the index of the window in the tab control. It returns true if the | |
2330 | // window was found, otherwise false. | |
a3a5df9d | 2331 | bool wxAuiNotebook::FindTab(wxWindow* page, wxAuiTabCtrl** ctrl, int* idx) |
cd05bf23 | 2332 | { |
a3a5df9d | 2333 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2334 | size_t i, pane_count = all_panes.GetCount(); |
2335 | for (i = 0; i < pane_count; ++i) | |
2336 | { | |
2337 | if (all_panes.Item(i).name == wxT("dummy")) | |
2338 | continue; | |
4444d148 | 2339 | |
cd05bf23 | 2340 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
4444d148 | 2341 | |
cd05bf23 BW |
2342 | int page_idx = tabframe->m_tabs->GetIdxFromWindow(page); |
2343 | if (page_idx != -1) | |
2344 | { | |
2345 | *ctrl = tabframe->m_tabs; | |
2346 | *idx = page_idx; | |
2347 | return true; | |
2348 | } | |
2349 | } | |
4444d148 | 2350 | |
cd05bf23 BW |
2351 | return false; |
2352 | } | |
2353 | ||
d606b6e9 BW |
2354 | void wxAuiNotebook::Split(size_t page, int direction) |
2355 | { | |
2356 | wxSize cli_size = GetClientSize(); | |
54a8a78e | 2357 | |
d606b6e9 BW |
2358 | // get the page's window pointer |
2359 | wxWindow* wnd = GetPage(page); | |
2360 | if (!wnd) | |
2361 | return; | |
54a8a78e | 2362 | |
d606b6e9 BW |
2363 | // notebooks with 1 or less pages can't be split |
2364 | if (GetPageCount() < 2) | |
2365 | return; | |
54a8a78e | 2366 | |
d606b6e9 BW |
2367 | // find out which tab control the page currently belongs to |
2368 | wxAuiTabCtrl *src_tabs, *dest_tabs; | |
2369 | int src_idx = -1; | |
2370 | src_tabs = NULL; | |
2371 | if (!FindTab(wnd, &src_tabs, &src_idx)) | |
2372 | return; | |
2373 | if (!src_tabs || src_idx == -1) | |
2374 | return; | |
54a8a78e | 2375 | |
d606b6e9 BW |
2376 | // choose a split size |
2377 | wxSize split_size; | |
2378 | if (GetPageCount() > 2) | |
2379 | { | |
2380 | split_size = CalculateNewSplitSize(); | |
2381 | } | |
cedd7b22 | 2382 | else |
d606b6e9 BW |
2383 | { |
2384 | // because there are two panes, always split them | |
2385 | // equally | |
2386 | split_size = GetClientSize(); | |
2387 | split_size.x /= 2; | |
2388 | split_size.y /= 2; | |
2389 | } | |
54a8a78e VZ |
2390 | |
2391 | ||
d606b6e9 BW |
2392 | // create a new tab frame |
2393 | wxTabFrame* new_tabs = new wxTabFrame; | |
2394 | new_tabs->m_rect = wxRect(wxPoint(0,0), split_size); | |
9a29fe70 | 2395 | new_tabs->SetTabCtrlHeight(m_tabCtrlHeight); |
d606b6e9 | 2396 | new_tabs->m_tabs = new wxAuiTabCtrl(this, |
9a29fe70 | 2397 | m_tabIdCounter++, |
d606b6e9 BW |
2398 | wxDefaultPosition, |
2399 | wxDefaultSize, | |
a0c2e4a0 | 2400 | wxNO_BORDER|wxWANTS_CHARS); |
d606b6e9 BW |
2401 | new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); |
2402 | new_tabs->m_tabs->SetFlags(m_flags); | |
2403 | dest_tabs = new_tabs->m_tabs; | |
2404 | ||
2405 | // create a pane info structure with the information | |
2406 | // about where the pane should be added | |
9a29fe70 | 2407 | wxAuiPaneInfo paneInfo = wxAuiPaneInfo().Bottom().CaptionVisible(false); |
d606b6e9 | 2408 | wxPoint mouse_pt; |
54a8a78e | 2409 | |
d606b6e9 BW |
2410 | if (direction == wxLEFT) |
2411 | { | |
9a29fe70 | 2412 | paneInfo.Left(); |
d606b6e9 BW |
2413 | mouse_pt = wxPoint(0, cli_size.y/2); |
2414 | } | |
cedd7b22 | 2415 | else if (direction == wxRIGHT) |
d606b6e9 | 2416 | { |
9a29fe70 | 2417 | paneInfo.Right(); |
d606b6e9 BW |
2418 | mouse_pt = wxPoint(cli_size.x, cli_size.y/2); |
2419 | } | |
cedd7b22 | 2420 | else if (direction == wxTOP) |
d606b6e9 | 2421 | { |
9a29fe70 | 2422 | paneInfo.Top(); |
d606b6e9 BW |
2423 | mouse_pt = wxPoint(cli_size.x/2, 0); |
2424 | } | |
cedd7b22 | 2425 | else if (direction == wxBOTTOM) |
d606b6e9 | 2426 | { |
9a29fe70 | 2427 | paneInfo.Bottom(); |
d606b6e9 BW |
2428 | mouse_pt = wxPoint(cli_size.x/2, cli_size.y); |
2429 | } | |
54a8a78e | 2430 | |
9a29fe70 | 2431 | m_mgr.AddPane(new_tabs, paneInfo, mouse_pt); |
d606b6e9 | 2432 | m_mgr.Update(); |
54a8a78e | 2433 | |
d606b6e9 BW |
2434 | // remove the page from the source tabs |
2435 | wxAuiNotebookPage page_info = src_tabs->GetPage(src_idx); | |
2436 | page_info.active = false; | |
2437 | src_tabs->RemovePage(page_info.window); | |
2438 | if (src_tabs->GetPageCount() > 0) | |
2439 | { | |
2440 | src_tabs->SetActivePage((size_t)0); | |
2441 | src_tabs->DoShowHide(); | |
2442 | src_tabs->Refresh(); | |
2443 | } | |
2444 | ||
2445 | ||
2446 | // add the page to the destination tabs | |
2447 | dest_tabs->InsertPage(page_info.window, page_info, 0); | |
2448 | ||
2449 | if (src_tabs->GetPageCount() == 0) | |
2450 | { | |
2451 | RemoveEmptyTabFrames(); | |
2452 | } | |
2453 | ||
2454 | DoSizing(); | |
2455 | dest_tabs->DoShowHide(); | |
2456 | dest_tabs->Refresh(); | |
2457 | ||
2458 | // force the set selection function reset the selection | |
9a29fe70 | 2459 | m_curPage = -1; |
54a8a78e | 2460 | |
d606b6e9 | 2461 | // set the active page to the one we just split off |
849c353a | 2462 | SetSelectionToPage(page_info); |
54a8a78e | 2463 | |
d606b6e9 BW |
2464 | UpdateHintWindowSize(); |
2465 | } | |
2466 | ||
2467 | ||
9fbb7d80 | 2468 | void wxAuiNotebook::OnSize(wxSizeEvent& evt) |
cd05bf23 | 2469 | { |
9fbb7d80 | 2470 | UpdateHintWindowSize(); |
c58ba15f | 2471 | |
9fbb7d80 | 2472 | evt.Skip(); |
cd05bf23 BW |
2473 | } |
2474 | ||
3c778901 | 2475 | void wxAuiNotebook::OnTabClicked(wxAuiNotebookEvent& evt) |
cd05bf23 | 2476 | { |
cd05bf23 BW |
2477 | wxAuiTabCtrl* ctrl = (wxAuiTabCtrl*)evt.GetEventObject(); |
2478 | wxASSERT(ctrl != NULL); | |
4444d148 | 2479 | |
cd05bf23 BW |
2480 | wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection()); |
2481 | wxASSERT(wnd != NULL); | |
4444d148 | 2482 | |
849c353a | 2483 | SetSelectionToWindow(wnd); |
cd05bf23 BW |
2484 | } |
2485 | ||
3c778901 | 2486 | void wxAuiNotebook::OnTabBgDClick(wxAuiNotebookEvent& WXUNUSED(evt)) |
198be845 JS |
2487 | { |
2488 | // notify owner that the tabbar background has been double-clicked | |
2489 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, m_windowId); | |
2490 | e.SetEventObject(this); | |
2491 | GetEventHandler()->ProcessEvent(e); | |
2492 | } | |
2493 | ||
3c778901 | 2494 | void wxAuiNotebook::OnTabBeginDrag(wxAuiNotebookEvent&) |
cd05bf23 | 2495 | { |
9a29fe70 | 2496 | m_lastDragX = 0; |
cd05bf23 BW |
2497 | } |
2498 | ||
3c778901 | 2499 | void wxAuiNotebook::OnTabDragMotion(wxAuiNotebookEvent& evt) |
cd05bf23 BW |
2500 | { |
2501 | wxPoint screen_pt = ::wxGetMousePosition(); | |
2502 | wxPoint client_pt = ScreenToClient(screen_pt); | |
2503 | wxPoint zero(0,0); | |
4444d148 | 2504 | |
cd05bf23 | 2505 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
08c068a4 | 2506 | wxAuiTabCtrl* dest_tabs = GetTabCtrlFromPoint(client_pt); |
7baac3cb | 2507 | |
08c068a4 | 2508 | if (dest_tabs == src_tabs) |
cd05bf23 | 2509 | { |
3941df70 BW |
2510 | if (src_tabs) |
2511 | { | |
2512 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
2513 | } | |
7baac3cb | 2514 | |
08c068a4 | 2515 | // always hide the hint for inner-tabctrl drag |
cd05bf23 | 2516 | m_mgr.HideHint(); |
7baac3cb | 2517 | |
695c0088 BW |
2518 | // if tab moving is not allowed, leave |
2519 | if (!(m_flags & wxAUI_NB_TAB_MOVE)) | |
2520 | { | |
2521 | return; | |
2522 | } | |
7baac3cb | 2523 | |
08c068a4 BW |
2524 | wxPoint pt = dest_tabs->ScreenToClient(screen_pt); |
2525 | wxWindow* dest_location_tab; | |
7baac3cb | 2526 | |
08c068a4 BW |
2527 | // this is an inner-tab drag/reposition |
2528 | if (dest_tabs->TabHitTest(pt.x, pt.y, &dest_location_tab)) | |
2529 | { | |
2530 | int src_idx = evt.GetSelection(); | |
2531 | int dest_idx = dest_tabs->GetIdxFromWindow(dest_location_tab); | |
7baac3cb | 2532 | |
08c068a4 BW |
2533 | // prevent jumpy drag |
2534 | if ((src_idx == dest_idx) || dest_idx == -1 || | |
9a29fe70 VZ |
2535 | (src_idx > dest_idx && m_lastDragX <= pt.x) || |
2536 | (src_idx < dest_idx && m_lastDragX >= pt.x)) | |
08c068a4 | 2537 | { |
9a29fe70 | 2538 | m_lastDragX = pt.x; |
08c068a4 BW |
2539 | return; |
2540 | } | |
2541 | ||
2542 | ||
2543 | wxWindow* src_tab = dest_tabs->GetWindowFromIdx(src_idx); | |
2544 | dest_tabs->MovePage(src_tab, dest_idx); | |
2545 | dest_tabs->SetActivePage((size_t)dest_idx); | |
2546 | dest_tabs->DoShowHide(); | |
2547 | dest_tabs->Refresh(); | |
9a29fe70 | 2548 | m_lastDragX = pt.x; |
08c068a4 BW |
2549 | |
2550 | } | |
7baac3cb | 2551 | |
cd05bf23 BW |
2552 | return; |
2553 | } | |
4444d148 | 2554 | |
695c0088 | 2555 | |
5d3aeb0f BW |
2556 | // if external drag is allowed, check if the tab is being dragged |
2557 | // over a different wxAuiNotebook control | |
2558 | if (m_flags & wxAUI_NB_TAB_EXTERNAL_MOVE) | |
2559 | { | |
2560 | wxWindow* tab_ctrl = ::wxFindWindowAtPoint(screen_pt); | |
7baac3cb | 2561 | |
87e5fe69 BW |
2562 | // if we aren't over any window, stop here |
2563 | if (!tab_ctrl) | |
2564 | return; | |
7baac3cb | 2565 | |
13d0b605 | 2566 | // make sure we are not over the hint window |
345c78ca | 2567 | if (!wxDynamicCast(tab_ctrl, wxFrame)) |
5d3aeb0f | 2568 | { |
13d0b605 | 2569 | while (tab_ctrl) |
5d3aeb0f | 2570 | { |
345c78ca | 2571 | if (wxDynamicCast(tab_ctrl, wxAuiTabCtrl)) |
13d0b605 BW |
2572 | break; |
2573 | tab_ctrl = tab_ctrl->GetParent(); | |
5d3aeb0f | 2574 | } |
7baac3cb | 2575 | |
13d0b605 BW |
2576 | if (tab_ctrl) |
2577 | { | |
2578 | wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent(); | |
7baac3cb | 2579 | |
13d0b605 BW |
2580 | if (nb != this) |
2581 | { | |
87e5fe69 | 2582 | wxRect hint_rect = tab_ctrl->GetClientRect(); |
13d0b605 BW |
2583 | tab_ctrl->ClientToScreen(&hint_rect.x, &hint_rect.y); |
2584 | m_mgr.ShowHint(hint_rect); | |
2585 | return; | |
2586 | } | |
87e5fe69 BW |
2587 | } |
2588 | } | |
cedd7b22 | 2589 | else |
87e5fe69 BW |
2590 | { |
2591 | if (!dest_tabs) | |
2592 | { | |
2593 | // we are either over a hint window, or not over a tab | |
2594 | // window, and there is no where to drag to, so exit | |
2595 | return; | |
13d0b605 | 2596 | } |
5d3aeb0f BW |
2597 | } |
2598 | } | |
2599 | ||
2600 | ||
69685ee0 BW |
2601 | // if there are less than two panes, split can't happen, so leave |
2602 | if (m_tabs.GetPageCount() < 2) | |
2603 | return; | |
7baac3cb | 2604 | |
695c0088 BW |
2605 | // if tab moving is not allowed, leave |
2606 | if (!(m_flags & wxAUI_NB_TAB_SPLIT)) | |
695c0088 | 2607 | return; |
695c0088 | 2608 | |
3941df70 BW |
2609 | |
2610 | if (src_tabs) | |
2611 | { | |
2612 | src_tabs->SetCursor(wxCursor(wxCURSOR_SIZING)); | |
2613 | } | |
7baac3cb VZ |
2614 | |
2615 | ||
08c068a4 | 2616 | if (dest_tabs) |
cd05bf23 | 2617 | { |
08c068a4 | 2618 | wxRect hint_rect = dest_tabs->GetRect(); |
cd05bf23 BW |
2619 | ClientToScreen(&hint_rect.x, &hint_rect.y); |
2620 | m_mgr.ShowHint(hint_rect); | |
2621 | } | |
cedd7b22 | 2622 | else |
cd05bf23 | 2623 | { |
9a29fe70 | 2624 | m_mgr.DrawHintRect(m_dummyWnd, client_pt, zero); |
cd05bf23 BW |
2625 | } |
2626 | } | |
2627 | ||
2628 | ||
2629 | ||
3c778901 | 2630 | void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent& evt) |
cd05bf23 | 2631 | { |
cd05bf23 | 2632 | m_mgr.HideHint(); |
4444d148 | 2633 | |
7baac3cb | 2634 | |
3941df70 | 2635 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
9a83f860 | 2636 | wxCHECK_RET( src_tabs, wxT("no source object?") ); |
54a8a78e VZ |
2637 | |
2638 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
7baac3cb | 2639 | |
cd05bf23 BW |
2640 | // get the mouse position, which will be used to determine the drop point |
2641 | wxPoint mouse_screen_pt = ::wxGetMousePosition(); | |
2642 | wxPoint mouse_client_pt = ScreenToClient(mouse_screen_pt); | |
2643 | ||
2644 | ||
4444d148 | 2645 | |
5d3aeb0f BW |
2646 | // check for an external move |
2647 | if (m_flags & wxAUI_NB_TAB_EXTERNAL_MOVE) | |
cd05bf23 | 2648 | { |
5d3aeb0f | 2649 | wxWindow* tab_ctrl = ::wxFindWindowAtPoint(mouse_screen_pt); |
7baac3cb | 2650 | |
5d3aeb0f | 2651 | while (tab_ctrl) |
c69532f7 | 2652 | { |
345c78ca | 2653 | if (wxDynamicCast(tab_ctrl, wxAuiTabCtrl)) |
5d3aeb0f BW |
2654 | break; |
2655 | tab_ctrl = tab_ctrl->GetParent(); | |
c69532f7 | 2656 | } |
7baac3cb | 2657 | |
5d3aeb0f BW |
2658 | if (tab_ctrl) |
2659 | { | |
2660 | wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent(); | |
7baac3cb | 2661 | |
5d3aeb0f BW |
2662 | if (nb != this) |
2663 | { | |
2664 | // find out from the destination control | |
2665 | // if it's ok to drop this tab here | |
2666 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, m_windowId); | |
2667 | e.SetSelection(evt.GetSelection()); | |
2668 | e.SetOldSelection(evt.GetSelection()); | |
2669 | e.SetEventObject(this); | |
2670 | e.SetDragSource(this); | |
2671 | e.Veto(); // dropping must be explicitly approved by control owner | |
7baac3cb | 2672 | |
5d3aeb0f | 2673 | nb->GetEventHandler()->ProcessEvent(e); |
7baac3cb | 2674 | |
5d3aeb0f BW |
2675 | if (!e.IsAllowed()) |
2676 | { | |
2677 | // no answer or negative answer | |
2678 | m_mgr.HideHint(); | |
2679 | return; | |
2680 | } | |
7baac3cb | 2681 | |
5d3aeb0f BW |
2682 | // drop was allowed |
2683 | int src_idx = evt.GetSelection(); | |
2684 | wxWindow* src_page = src_tabs->GetWindowFromIdx(src_idx); | |
7baac3cb | 2685 | |
884a369a JS |
2686 | // Check that it's not an impossible parent relationship |
2687 | wxWindow* p = nb; | |
2688 | while (p && !p->IsTopLevel()) | |
2689 | { | |
2690 | if (p == src_page) | |
2691 | { | |
2692 | return; | |
2693 | } | |
2694 | p = p->GetParent(); | |
2695 | } | |
2696 | ||
5d3aeb0f BW |
2697 | // get main index of the page |
2698 | int main_idx = m_tabs.GetIdxFromWindow(src_page); | |
9a83f860 | 2699 | wxCHECK_RET( main_idx != wxNOT_FOUND, wxT("no source page?") ); |
849c353a | 2700 | |
7baac3cb | 2701 | |
5d3aeb0f | 2702 | // make a copy of the page info |
849c353a | 2703 | wxAuiNotebookPage page_info = m_tabs.GetPage(main_idx); |
7baac3cb | 2704 | |
5d3aeb0f BW |
2705 | // remove the page from the source notebook |
2706 | RemovePage(main_idx); | |
7baac3cb | 2707 | |
5d3aeb0f BW |
2708 | // reparent the page |
2709 | src_page->Reparent(nb); | |
7baac3cb VZ |
2710 | |
2711 | ||
5d3aeb0f BW |
2712 | // found out the insert idx |
2713 | wxAuiTabCtrl* dest_tabs = (wxAuiTabCtrl*)tab_ctrl; | |
2714 | wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); | |
2715 | ||
2716 | wxWindow* target = NULL; | |
2717 | int insert_idx = -1; | |
2718 | dest_tabs->TabHitTest(pt.x, pt.y, &target); | |
2719 | if (target) | |
2720 | { | |
2721 | insert_idx = dest_tabs->GetIdxFromWindow(target); | |
2722 | } | |
702b1c7e | 2723 | |
7baac3cb | 2724 | |
5d3aeb0f BW |
2725 | // add the page to the new notebook |
2726 | if (insert_idx == -1) | |
2727 | insert_idx = dest_tabs->GetPageCount(); | |
2728 | dest_tabs->InsertPage(page_info.window, page_info, insert_idx); | |
2729 | nb->m_tabs.AddPage(page_info.window, page_info); | |
2730 | ||
2731 | nb->DoSizing(); | |
2732 | dest_tabs->DoShowHide(); | |
2733 | dest_tabs->Refresh(); | |
7baac3cb | 2734 | |
5d3aeb0f | 2735 | // set the selection in the destination tab control |
849c353a | 2736 | nb->SetSelectionToPage(page_info); |
5d3aeb0f | 2737 | |
d92f353c JS |
2738 | // notify owner that the tab has been dragged |
2739 | wxAuiNotebookEvent e2(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, m_windowId); | |
2740 | e2.SetSelection(evt.GetSelection()); | |
2741 | e2.SetOldSelection(evt.GetSelection()); | |
2742 | e2.SetEventObject(this); | |
2743 | GetEventHandler()->ProcessEvent(e2); | |
2744 | ||
5d3aeb0f BW |
2745 | return; |
2746 | } | |
2747 | } | |
cd05bf23 | 2748 | } |
4444d148 WS |
2749 | |
2750 | ||
2751 | ||
5d3aeb0f BW |
2752 | |
2753 | // only perform a tab split if it's allowed | |
54a8a78e VZ |
2754 | wxAuiTabCtrl* dest_tabs = NULL; |
2755 | ||
69685ee0 | 2756 | if ((m_flags & wxAUI_NB_TAB_SPLIT) && m_tabs.GetPageCount() >= 2) |
cd05bf23 | 2757 | { |
5d3aeb0f BW |
2758 | // If the pointer is in an existing tab frame, do a tab insert |
2759 | wxWindow* hit_wnd = ::wxFindWindowAtPoint(mouse_screen_pt); | |
2760 | wxTabFrame* tab_frame = (wxTabFrame*)GetTabFrameFromTabCtrl(hit_wnd); | |
2761 | int insert_idx = -1; | |
2762 | if (tab_frame) | |
2763 | { | |
2764 | dest_tabs = tab_frame->m_tabs; | |
cd05bf23 | 2765 | |
5d3aeb0f BW |
2766 | if (dest_tabs == src_tabs) |
2767 | return; | |
7baac3cb VZ |
2768 | |
2769 | ||
5d3aeb0f BW |
2770 | wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); |
2771 | wxWindow* target = NULL; | |
2772 | dest_tabs->TabHitTest(pt.x, pt.y, &target); | |
2773 | if (target) | |
2774 | { | |
2775 | insert_idx = dest_tabs->GetIdxFromWindow(target); | |
2776 | } | |
2777 | } | |
54a8a78e | 2778 | else |
5d3aeb0f | 2779 | { |
ce15b45f | 2780 | wxPoint zero(0,0); |
9a29fe70 | 2781 | wxRect rect = m_mgr.CalculateHintRect(m_dummyWnd, |
ce15b45f BW |
2782 | mouse_client_pt, |
2783 | zero); | |
2784 | if (rect.IsEmpty()) | |
2785 | { | |
2786 | // there is no suitable drop location here, exit out | |
2787 | return; | |
2788 | } | |
7baac3cb | 2789 | |
5d3aeb0f BW |
2790 | // If there is no tabframe at all, create one |
2791 | wxTabFrame* new_tabs = new wxTabFrame; | |
9fbb7d80 | 2792 | new_tabs->m_rect = wxRect(wxPoint(0,0), CalculateNewSplitSize()); |
9a29fe70 | 2793 | new_tabs->SetTabCtrlHeight(m_tabCtrlHeight); |
5d3aeb0f | 2794 | new_tabs->m_tabs = new wxAuiTabCtrl(this, |
9a29fe70 | 2795 | m_tabIdCounter++, |
5d3aeb0f BW |
2796 | wxDefaultPosition, |
2797 | wxDefaultSize, | |
a0c2e4a0 | 2798 | wxNO_BORDER|wxWANTS_CHARS); |
b0d17f7c | 2799 | new_tabs->m_tabs->SetArtProvider(m_tabs.GetArtProvider()->Clone()); |
5d3aeb0f BW |
2800 | new_tabs->m_tabs->SetFlags(m_flags); |
2801 | ||
2802 | m_mgr.AddPane(new_tabs, | |
2803 | wxAuiPaneInfo().Bottom().CaptionVisible(false), | |
2804 | mouse_client_pt); | |
2805 | m_mgr.Update(); | |
2806 | dest_tabs = new_tabs->m_tabs; | |
2807 | } | |
4444d148 WS |
2808 | |
2809 | ||
4444d148 | 2810 | |
5d3aeb0f BW |
2811 | // remove the page from the source tabs |
2812 | wxAuiNotebookPage page_info = src_tabs->GetPage(evt.GetSelection()); | |
2813 | page_info.active = false; | |
2814 | src_tabs->RemovePage(page_info.window); | |
2815 | if (src_tabs->GetPageCount() > 0) | |
2816 | { | |
2817 | src_tabs->SetActivePage((size_t)0); | |
2818 | src_tabs->DoShowHide(); | |
2819 | src_tabs->Refresh(); | |
2820 | } | |
4444d148 | 2821 | |
cd05bf23 | 2822 | |
5d3aeb0f BW |
2823 | |
2824 | // add the page to the destination tabs | |
2825 | if (insert_idx == -1) | |
2826 | insert_idx = dest_tabs->GetPageCount(); | |
2827 | dest_tabs->InsertPage(page_info.window, page_info, insert_idx); | |
2828 | ||
2829 | if (src_tabs->GetPageCount() == 0) | |
2830 | { | |
2831 | RemoveEmptyTabFrames(); | |
2832 | } | |
2833 | ||
2834 | DoSizing(); | |
2835 | dest_tabs->DoShowHide(); | |
2836 | dest_tabs->Refresh(); | |
2837 | ||
68fd4f2c | 2838 | // force the set selection function reset the selection |
9a29fe70 | 2839 | m_curPage = -1; |
c58ba15f | 2840 | |
68fd4f2c | 2841 | // set the active page to the one we just split off |
849c353a | 2842 | SetSelectionToPage(page_info); |
c58ba15f | 2843 | |
9fbb7d80 | 2844 | UpdateHintWindowSize(); |
5d3aeb0f | 2845 | } |
d92f353c JS |
2846 | |
2847 | // notify owner that the tab has been dragged | |
2848 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, m_windowId); | |
2849 | e.SetSelection(evt.GetSelection()); | |
2850 | e.SetOldSelection(evt.GetSelection()); | |
2851 | e.SetEventObject(this); | |
2852 | GetEventHandler()->ProcessEvent(e); | |
cd05bf23 BW |
2853 | } |
2854 | ||
3941df70 BW |
2855 | |
2856 | ||
2bd82d72 VZ |
2857 | void wxAuiNotebook::OnTabCancelDrag(wxAuiNotebookEvent& command_evt) |
2858 | { | |
2859 | wxAuiNotebookEvent& evt = (wxAuiNotebookEvent&)command_evt; | |
2860 | ||
2861 | m_mgr.HideHint(); | |
2862 | ||
2863 | wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
2e92ad1b | 2864 | wxCHECK_RET( src_tabs, wxT("no source object?") ); |
2bd82d72 VZ |
2865 | |
2866 | src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); | |
2867 | } | |
2868 | ||
a3a5df9d | 2869 | wxAuiTabCtrl* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint& pt) |
cd05bf23 BW |
2870 | { |
2871 | // if we've just removed the last tab from the source | |
2872 | // tab set, the remove the tab control completely | |
a3a5df9d | 2873 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2874 | size_t i, pane_count = all_panes.GetCount(); |
2875 | for (i = 0; i < pane_count; ++i) | |
2876 | { | |
2877 | if (all_panes.Item(i).name == wxT("dummy")) | |
2878 | continue; | |
4444d148 | 2879 | |
cd05bf23 | 2880 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
22a35096 | 2881 | if (tabframe->m_tab_rect.Contains(pt)) |
cd05bf23 BW |
2882 | return tabframe->m_tabs; |
2883 | } | |
4444d148 | 2884 | |
cd05bf23 BW |
2885 | return NULL; |
2886 | } | |
2887 | ||
a3a5df9d | 2888 | wxWindow* wxAuiNotebook::GetTabFrameFromTabCtrl(wxWindow* tab_ctrl) |
cd05bf23 BW |
2889 | { |
2890 | // if we've just removed the last tab from the source | |
2891 | // tab set, the remove the tab control completely | |
a3a5df9d | 2892 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2893 | size_t i, pane_count = all_panes.GetCount(); |
2894 | for (i = 0; i < pane_count; ++i) | |
2895 | { | |
2896 | if (all_panes.Item(i).name == wxT("dummy")) | |
2897 | continue; | |
4444d148 | 2898 | |
cd05bf23 BW |
2899 | wxTabFrame* tabframe = (wxTabFrame*)all_panes.Item(i).window; |
2900 | if (tabframe->m_tabs == tab_ctrl) | |
2901 | { | |
2902 | return tabframe; | |
2903 | } | |
2904 | } | |
4444d148 | 2905 | |
cd05bf23 BW |
2906 | return NULL; |
2907 | } | |
2908 | ||
a3a5df9d | 2909 | void wxAuiNotebook::RemoveEmptyTabFrames() |
cd05bf23 | 2910 | { |
cd05bf23 BW |
2911 | // if we've just removed the last tab from the source |
2912 | // tab set, the remove the tab control completely | |
a3a5df9d | 2913 | wxAuiPaneInfoArray all_panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2914 | size_t i, pane_count = all_panes.GetCount(); |
2915 | for (i = 0; i < pane_count; ++i) | |
2916 | { | |
2917 | if (all_panes.Item(i).name == wxT("dummy")) | |
2918 | continue; | |
2919 | ||
2920 | wxTabFrame* tab_frame = (wxTabFrame*)all_panes.Item(i).window; | |
2921 | if (tab_frame->m_tabs->GetPageCount() == 0) | |
2922 | { | |
2923 | m_mgr.DetachPane(tab_frame); | |
4444d148 | 2924 | |
cd05bf23 BW |
2925 | // use pending delete because sometimes during |
2926 | // window closing, refreshs are pending | |
2927 | if (!wxPendingDelete.Member(tab_frame->m_tabs)) | |
4444d148 | 2928 | wxPendingDelete.Append(tab_frame->m_tabs); |
cedd7b22 | 2929 | |
13aaa50f | 2930 | tab_frame->m_tabs = NULL; |
4444d148 | 2931 | |
cd05bf23 | 2932 | delete tab_frame; |
cd05bf23 BW |
2933 | } |
2934 | } | |
4444d148 WS |
2935 | |
2936 | ||
cd05bf23 BW |
2937 | // check to see if there is still a center pane; |
2938 | // if there isn't, make a frame the center pane | |
a3a5df9d | 2939 | wxAuiPaneInfoArray panes = m_mgr.GetAllPanes(); |
cd05bf23 BW |
2940 | pane_count = panes.GetCount(); |
2941 | wxWindow* first_good = NULL; | |
2942 | bool center_found = false; | |
2943 | for (i = 0; i < pane_count; ++i) | |
2944 | { | |
2945 | if (panes.Item(i).name == wxT("dummy")) | |
2946 | continue; | |
2947 | if (panes.Item(i).dock_direction == wxAUI_DOCK_CENTRE) | |
2948 | center_found = true; | |
2949 | if (!first_good) | |
2950 | first_good = panes.Item(i).window; | |
2951 | } | |
2952 | ||
2953 | if (!center_found && first_good) | |
2954 | { | |
2955 | m_mgr.GetPane(first_good).Centre(); | |
cd05bf23 BW |
2956 | } |
2957 | ||
18b40f30 JS |
2958 | if (!m_isBeingDeleted) |
2959 | m_mgr.Update(); | |
cd05bf23 BW |
2960 | } |
2961 | ||
5bf3f27f | 2962 | void wxAuiNotebook::OnChildFocusNotebook(wxChildFocusEvent& evt) |
cd05bf23 | 2963 | { |
d4f4657a VZ |
2964 | evt.Skip(); |
2965 | ||
d16619f8 BW |
2966 | // if we're dragging a tab, don't change the current selection. |
2967 | // This code prevents a bug that used to happen when the hint window | |
2968 | // was hidden. In the bug, the focus would return to the notebook | |
2969 | // child, which would then enter this handler and call | |
2970 | // SetSelection, which is not desired turn tab dragging. | |
cedd7b22 | 2971 | |
d16619f8 BW |
2972 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); |
2973 | size_t i, pane_count = all_panes.GetCount(); | |
2974 | for (i = 0; i < pane_count; ++i) | |
2975 | { | |
2976 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
2977 | if (pane.name == wxT("dummy")) | |
2978 | continue; | |
2979 | wxTabFrame* tabframe = (wxTabFrame*)pane.window; | |
2980 | if (tabframe->m_tabs->IsDragging()) | |
2981 | return; | |
2982 | } | |
2983 | ||
2984 | ||
2985 | // change the tab selection to the child | |
2986 | // which was focused | |
cd05bf23 | 2987 | int idx = m_tabs.GetIdxFromWindow(evt.GetWindow()); |
9a29fe70 | 2988 | if (idx != -1 && idx != m_curPage) |
cd05bf23 | 2989 | { |
4444d148 | 2990 | SetSelection(idx); |
cd05bf23 BW |
2991 | } |
2992 | } | |
2993 | ||
5bf3f27f | 2994 | void wxAuiNotebook::OnNavigationKeyNotebook(wxNavigationKeyEvent& event) |
a0c2e4a0 JS |
2995 | { |
2996 | if ( event.IsWindowChange() ) { | |
2997 | // change pages | |
2998 | // FIXME: the problem with this is that if we have a split notebook, | |
2999 | // we selection may go all over the place. | |
3000 | AdvanceSelection(event.GetDirection()); | |
3001 | } | |
3002 | else { | |
3003 | // we get this event in 3 cases | |
3004 | // | |
3005 | // a) one of our pages might have generated it because the user TABbed | |
3006 | // out from it in which case we should propagate the event upwards and | |
3007 | // our parent will take care of setting the focus to prev/next sibling | |
3008 | // | |
3009 | // or | |
3010 | // | |
3011 | // b) the parent panel wants to give the focus to us so that we | |
3012 | // forward it to our selected page. We can't deal with this in | |
3013 | // OnSetFocus() because we don't know which direction the focus came | |
3014 | // from in this case and so can't choose between setting the focus to | |
3015 | // first or last panel child | |
3016 | // | |
3017 | // or | |
3018 | // | |
3019 | // c) we ourselves (see MSWTranslateMessage) generated the event | |
3020 | // | |
3021 | wxWindow * const parent = GetParent(); | |
3022 | ||
3023 | // the wxObject* casts are required to avoid MinGW GCC 2.95.3 ICE | |
3024 | const bool isFromParent = event.GetEventObject() == (wxObject*) parent; | |
3025 | const bool isFromSelf = event.GetEventObject() == (wxObject*) this; | |
3026 | ||
3027 | if ( isFromParent || isFromSelf ) | |
3028 | { | |
3029 | // no, it doesn't come from child, case (b) or (c): forward to a | |
3030 | // page but only if direction is backwards (TAB) or from ourselves, | |
3031 | if ( GetSelection() != wxNOT_FOUND && | |
3032 | (!event.GetDirection() || isFromSelf) ) | |
3033 | { | |
3034 | // so that the page knows that the event comes from it's parent | |
3035 | // and is being propagated downwards | |
3036 | event.SetEventObject(this); | |
3037 | ||
3038 | wxWindow *page = GetPage(GetSelection()); | |
3039 | if ( !page->GetEventHandler()->ProcessEvent(event) ) | |
3040 | { | |
3041 | page->SetFocus(); | |
3042 | } | |
3043 | //else: page manages focus inside it itself | |
3044 | } | |
3045 | else // otherwise set the focus to the notebook itself | |
3046 | { | |
3047 | SetFocus(); | |
3048 | } | |
3049 | } | |
3050 | else | |
3051 | { | |
3052 | // it comes from our child, case (a), pass to the parent, but only | |
3053 | // if the direction is forwards. Otherwise set the focus to the | |
3054 | // notebook itself. The notebook is always the 'first' control of a | |
3055 | // page. | |
3056 | if ( !event.GetDirection() ) | |
3057 | { | |
3058 | SetFocus(); | |
3059 | } | |
3060 | else if ( parent ) | |
3061 | { | |
3062 | event.SetCurrentFocus(this); | |
3063 | parent->GetEventHandler()->ProcessEvent(event); | |
3064 | } | |
3065 | } | |
3066 | } | |
3067 | } | |
cd05bf23 | 3068 | |
3c778901 | 3069 | void wxAuiNotebook::OnTabButton(wxAuiNotebookEvent& evt) |
cd05bf23 | 3070 | { |
cd05bf23 | 3071 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
4444d148 | 3072 | |
cd05bf23 | 3073 | int button_id = evt.GetInt(); |
4444d148 | 3074 | |
4953f8cf | 3075 | if (button_id == wxAUI_BUTTON_CLOSE) |
cd05bf23 | 3076 | { |
9b362935 | 3077 | int selection = evt.GetSelection(); |
4444d148 | 3078 | |
94473fa8 BW |
3079 | if (selection == -1) |
3080 | { | |
3081 | // if the close button is to the right, use the active | |
3082 | // page selection to determine which page to close | |
b27fdc38 | 3083 | selection = tabs->GetActivePage(); |
94473fa8 | 3084 | } |
884a369a | 3085 | |
cd05bf23 BW |
3086 | if (selection != -1) |
3087 | { | |
3088 | wxWindow* close_wnd = tabs->GetWindowFromIdx(selection); | |
4444d148 | 3089 | |
3fd8c988 BW |
3090 | // ask owner if it's ok to close the tab |
3091 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, m_windowId); | |
3092 | e.SetSelection(m_tabs.GetIdxFromWindow(close_wnd)); | |
d92f353c JS |
3093 | const int idx = m_tabs.GetIdxFromWindow(close_wnd); |
3094 | e.SetSelection(idx); | |
3fd8c988 BW |
3095 | e.SetOldSelection(evt.GetSelection()); |
3096 | e.SetEventObject(this); | |
7ebc40e8 | 3097 | GetEventHandler()->ProcessEvent(e); |
3fd8c988 BW |
3098 | if (!e.IsAllowed()) |
3099 | return; | |
3100 | ||
3101 | ||
89272c55 | 3102 | #if wxUSE_MDI |
345c78ca | 3103 | if (wxDynamicCast(close_wnd, wxAuiMDIChildFrame)) |
cd05bf23 BW |
3104 | { |
3105 | close_wnd->Close(); | |
3106 | } | |
760fdb67 | 3107 | else |
89272c55 | 3108 | #endif |
cd05bf23 BW |
3109 | { |
3110 | int main_idx = m_tabs.GetIdxFromWindow(close_wnd); | |
9a83f860 | 3111 | wxCHECK_RET( main_idx != wxNOT_FOUND, wxT("no page to delete?") ); |
760fdb67 | 3112 | |
cd05bf23 BW |
3113 | DeletePage(main_idx); |
3114 | } | |
d92f353c JS |
3115 | |
3116 | // notify owner that the tab has been closed | |
3117 | wxAuiNotebookEvent e2(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, m_windowId); | |
3118 | e2.SetSelection(idx); | |
3119 | e2.SetEventObject(this); | |
3120 | GetEventHandler()->ProcessEvent(e2); | |
cd05bf23 BW |
3121 | } |
3122 | } | |
3123 | } | |
3124 | ||
69f5e420 | 3125 | |
3c778901 | 3126 | void wxAuiNotebook::OnTabMiddleDown(wxAuiNotebookEvent& evt) |
69f5e420 BW |
3127 | { |
3128 | // patch event through to owner | |
3129 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
3130 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
3131 | ||
3132 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_DOWN, m_windowId); | |
3133 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
3134 | e.SetEventObject(this); | |
3135 | GetEventHandler()->ProcessEvent(e); | |
3136 | } | |
3137 | ||
3c778901 | 3138 | void wxAuiNotebook::OnTabMiddleUp(wxAuiNotebookEvent& evt) |
69f5e420 BW |
3139 | { |
3140 | // if the wxAUI_NB_MIDDLE_CLICK_CLOSE is specified, middle | |
3141 | // click should act like a tab close action. However, first | |
3142 | // give the owner an opportunity to handle the middle up event | |
3143 | // for custom action | |
cedd7b22 | 3144 | |
69f5e420 BW |
3145 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); |
3146 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
3147 | ||
3148 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_MIDDLE_UP, m_windowId); | |
3149 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
3150 | e.SetEventObject(this); | |
3151 | if (GetEventHandler()->ProcessEvent(e)) | |
3152 | return; | |
3153 | if (!e.IsAllowed()) | |
3154 | return; | |
cedd7b22 | 3155 | |
69f5e420 BW |
3156 | // check if we are supposed to close on middle-up |
3157 | if ((m_flags & wxAUI_NB_MIDDLE_CLICK_CLOSE) == 0) | |
3158 | return; | |
cedd7b22 | 3159 | |
69f5e420 BW |
3160 | // simulate the user pressing the close button on the tab |
3161 | evt.SetInt(wxAUI_BUTTON_CLOSE); | |
3162 | OnTabButton(evt); | |
3163 | } | |
3164 | ||
3c778901 | 3165 | void wxAuiNotebook::OnTabRightDown(wxAuiNotebookEvent& evt) |
69f5e420 BW |
3166 | { |
3167 | // patch event through to owner | |
3168 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
3169 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
3170 | ||
3171 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_DOWN, m_windowId); | |
3172 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
3173 | e.SetEventObject(this); | |
3174 | GetEventHandler()->ProcessEvent(e); | |
3175 | } | |
3176 | ||
3c778901 | 3177 | void wxAuiNotebook::OnTabRightUp(wxAuiNotebookEvent& evt) |
69f5e420 BW |
3178 | { |
3179 | // patch event through to owner | |
3180 | wxAuiTabCtrl* tabs = (wxAuiTabCtrl*)evt.GetEventObject(); | |
3181 | wxWindow* wnd = tabs->GetWindowFromIdx(evt.GetSelection()); | |
3182 | ||
3183 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP, m_windowId); | |
3184 | e.SetSelection(m_tabs.GetIdxFromWindow(wnd)); | |
3185 | e.SetEventObject(this); | |
3186 | GetEventHandler()->ProcessEvent(e); | |
3187 | } | |
3188 | ||
fc17828a JS |
3189 | // Sets the normal font |
3190 | void wxAuiNotebook::SetNormalFont(const wxFont& font) | |
3191 | { | |
9a29fe70 | 3192 | m_normalFont = font; |
fc17828a JS |
3193 | GetArtProvider()->SetNormalFont(font); |
3194 | } | |
3195 | ||
3196 | // Sets the selected tab font | |
3197 | void wxAuiNotebook::SetSelectedFont(const wxFont& font) | |
3198 | { | |
9a29fe70 | 3199 | m_selectedFont = font; |
fc17828a JS |
3200 | GetArtProvider()->SetSelectedFont(font); |
3201 | } | |
3202 | ||
3203 | // Sets the measuring font | |
3204 | void wxAuiNotebook::SetMeasuringFont(const wxFont& font) | |
3205 | { | |
3206 | GetArtProvider()->SetMeasuringFont(font); | |
3207 | } | |
3208 | ||
3209 | // Sets the tab font | |
3210 | bool wxAuiNotebook::SetFont(const wxFont& font) | |
3211 | { | |
3212 | wxControl::SetFont(font); | |
cd05bf23 | 3213 | |
fc17828a JS |
3214 | wxFont normalFont(font); |
3215 | wxFont selectedFont(normalFont); | |
3216 | selectedFont.SetWeight(wxBOLD); | |
3217 | ||
3218 | SetNormalFont(normalFont); | |
3219 | SetSelectedFont(selectedFont); | |
3220 | SetMeasuringFont(selectedFont); | |
3221 | ||
3222 | return true; | |
3223 | } | |
3224 | ||
3225 | // Gets the tab control height | |
3226 | int wxAuiNotebook::GetTabCtrlHeight() const | |
3227 | { | |
9a29fe70 | 3228 | return m_tabCtrlHeight; |
fc17828a JS |
3229 | } |
3230 | ||
3231 | // Gets the height of the notebook for a given page height | |
3232 | int wxAuiNotebook::GetHeightForPageHeight(int pageHeight) | |
3233 | { | |
3234 | UpdateTabCtrlHeight(); | |
3235 | ||
3236 | int tabCtrlHeight = GetTabCtrlHeight(); | |
3237 | int decorHeight = 2; | |
3238 | return tabCtrlHeight + pageHeight + decorHeight; | |
3239 | } | |
cd05bf23 | 3240 | |
a0c2e4a0 JS |
3241 | // Shows the window menu |
3242 | bool wxAuiNotebook::ShowWindowMenu() | |
3243 | { | |
3244 | wxAuiTabCtrl* tabCtrl = GetActiveTabCtrl(); | |
3245 | ||
3246 | int idx = tabCtrl->GetArtProvider()->ShowDropDown(tabCtrl, tabCtrl->GetPages(), tabCtrl->GetActivePage()); | |
3247 | ||
3248 | if (idx != -1) | |
3249 | { | |
3250 | wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, tabCtrl->GetId()); | |
3251 | e.SetSelection(idx); | |
3252 | e.SetOldSelection(tabCtrl->GetActivePage()); | |
3253 | e.SetEventObject(tabCtrl); | |
3254 | GetEventHandler()->ProcessEvent(e); | |
3255 | ||
3256 | return true; | |
3257 | } | |
3258 | else | |
3259 | return false; | |
3260 | } | |
cd05bf23 | 3261 | |
c52f18df | 3262 | void wxAuiNotebook::DoThaw() |
64178c36 JS |
3263 | { |
3264 | DoSizing(); | |
3265 | ||
c52f18df | 3266 | wxBookCtrlBase::DoThaw(); |
64178c36 JS |
3267 | } |
3268 | ||
873ff54b SL |
3269 | void wxAuiNotebook::SetPageSize (const wxSize& WXUNUSED(size)) |
3270 | { | |
3271 | wxFAIL_MSG("Not implemented for wxAuiNotebook"); | |
3272 | } | |
3273 | ||
3274 | int wxAuiNotebook::HitTest (const wxPoint& WXUNUSED(pt), long* WXUNUSED(flags)) const | |
3275 | { | |
3276 | wxFAIL_MSG("Not implemented for wxAuiNotebook"); | |
3277 | return wxNOT_FOUND; | |
3278 | } | |
3279 | ||
3280 | int wxAuiNotebook::GetPageImage(size_t WXUNUSED(n)) const | |
3281 | { | |
3282 | wxFAIL_MSG("Not implemented for wxAuiNotebook"); | |
3283 | return -1; | |
3284 | } | |
3285 | ||
3286 | bool wxAuiNotebook::SetPageImage(size_t n, int imageId) | |
3287 | { | |
3288 | return SetPageBitmap(n, GetImageList()->GetBitmap(imageId)); | |
3289 | } | |
3290 | ||
873ff54b SL |
3291 | int wxAuiNotebook::ChangeSelection(size_t n) |
3292 | { | |
3293 | return DoModifySelection(n, false); | |
3294 | } | |
3295 | ||
3296 | bool wxAuiNotebook::AddPage(wxWindow *page, const wxString &text, bool select, | |
3297 | int imageId) | |
3298 | { | |
3299 | if(HasImageList()) | |
3300 | { | |
3301 | return AddPage(page, text, select, GetImageList()->GetBitmap(imageId)); | |
3302 | } | |
3303 | else | |
3304 | { | |
3305 | return AddPage(page, text, select, wxNullBitmap); | |
3306 | } | |
3307 | } | |
3308 | ||
3309 | bool wxAuiNotebook::DeleteAllPages() | |
3310 | { | |
3311 | size_t count = GetPageCount(); | |
3312 | for(size_t i = 0; i < count; i++) | |
3313 | { | |
3314 | DeletePage(0); | |
3315 | } | |
3316 | return true; | |
3317 | } | |
3318 | ||
3319 | bool wxAuiNotebook::InsertPage(size_t index, wxWindow *page, | |
3320 | const wxString &text, bool select, | |
3321 | int imageId) | |
3322 | { | |
3323 | if(HasImageList()) | |
3324 | { | |
3325 | return InsertPage(index, page, text, select, | |
3326 | GetImageList()->GetBitmap(imageId)); | |
3327 | } | |
3328 | else | |
3329 | { | |
3330 | return InsertPage(index, page, text, select, wxNullBitmap); | |
3331 | } | |
3332 | } | |
3333 | ||
3334 | int wxAuiNotebook::DoModifySelection(size_t n, bool events) | |
3335 | { | |
9a29fe70 | 3336 | wxWindow* wnd = m_tabs.GetWindowFromIdx(n); |
873ff54b | 3337 | if (!wnd) |
9a29fe70 | 3338 | return m_curPage; |
873ff54b SL |
3339 | |
3340 | // don't change the page unless necessary; | |
3341 | // however, clicking again on a tab should give it the focus. | |
9a29fe70 | 3342 | if ((int)n == m_curPage) |
873ff54b SL |
3343 | { |
3344 | wxAuiTabCtrl* ctrl; | |
3345 | int ctrl_idx; | |
3346 | if (FindTab(wnd, &ctrl, &ctrl_idx)) | |
3347 | { | |
3348 | if (FindFocus() != ctrl) | |
3349 | ctrl->SetFocus(); | |
3350 | } | |
9a29fe70 | 3351 | return m_curPage; |
873ff54b SL |
3352 | } |
3353 | ||
3354 | bool vetoed = false; | |
3355 | ||
3356 | wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, m_windowId); | |
3357 | ||
3358 | if(events) | |
3359 | { | |
3360 | evt.SetSelection(n); | |
9a29fe70 | 3361 | evt.SetOldSelection(m_curPage); |
873ff54b SL |
3362 | evt.SetEventObject(this); |
3363 | GetEventHandler()->ProcessEvent(evt); | |
3364 | vetoed = !evt.IsAllowed(); | |
3365 | } | |
3366 | ||
3367 | if (!vetoed) | |
3368 | { | |
9a29fe70 VZ |
3369 | int old_curpage = m_curPage; |
3370 | m_curPage = n; | |
873ff54b SL |
3371 | |
3372 | // program allows the page change | |
3373 | if(events) | |
3374 | { | |
3375 | evt.SetEventType(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED); | |
3376 | (void)GetEventHandler()->ProcessEvent(evt); | |
3377 | } | |
3378 | ||
3379 | ||
3380 | wxAuiTabCtrl* ctrl; | |
3381 | int ctrl_idx; | |
3382 | if (FindTab(wnd, &ctrl, &ctrl_idx)) | |
3383 | { | |
3384 | m_tabs.SetActivePage(wnd); | |
3385 | ||
3386 | ctrl->SetActivePage(ctrl_idx); | |
3387 | DoSizing(); | |
3388 | ctrl->DoShowHide(); | |
3389 | ||
3390 | ctrl->MakeTabVisible(ctrl_idx, ctrl); | |
3391 | ||
3392 | // set fonts | |
3393 | wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes(); | |
3394 | size_t i, pane_count = all_panes.GetCount(); | |
3395 | for (i = 0; i < pane_count; ++i) | |
3396 | { | |
3397 | wxAuiPaneInfo& pane = all_panes.Item(i); | |
3398 | if (pane.name == wxT("dummy")) | |
3399 | continue; | |
3400 | wxAuiTabCtrl* tabctrl = ((wxTabFrame*)pane.window)->m_tabs; | |
3401 | if (tabctrl != ctrl) | |
9a29fe70 | 3402 | tabctrl->SetSelectedFont(m_normalFont); |
873ff54b | 3403 | else |
9a29fe70 | 3404 | tabctrl->SetSelectedFont(m_selectedFont); |
873ff54b SL |
3405 | tabctrl->Refresh(); |
3406 | } | |
3407 | ||
3408 | // Set the focus to the page if we're not currently focused on the tab. | |
3409 | // This is Firefox-like behaviour. | |
3410 | if (wnd->IsShownOnScreen() && FindFocus() != ctrl) | |
3411 | wnd->SetFocus(); | |
3412 | ||
3413 | return old_curpage; | |
3414 | } | |
3415 | } | |
3416 | ||
9a29fe70 | 3417 | return m_curPage; |
873ff54b SL |
3418 | } |
3419 | ||
3420 | ||
cd05bf23 | 3421 | #endif // wxUSE_AUI |