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