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