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