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