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