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