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