]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tabg.cpp | |
3 | // Purpose: Generic tabbed dialogs | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) | |
2b854a32 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "tabg.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
1e6feb95 VZ |
23 | #if wxUSE_TAB_DIALOG |
24 | ||
c801d85f | 25 | #ifndef WX_PRECOMP |
00dd3b18 MB |
26 | #include "wx/settings.h" |
27 | #include "wx/intl.h" | |
c801d85f KB |
28 | #endif |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | #include <stdarg.h> | |
33 | #include <math.h> | |
34 | ||
35 | #include "wx/tab.h" | |
36 | ||
4b5f3fe6 JS |
37 | // not defined: use old, square tab implementation (fills in tabs) |
38 | // defined: use new, rounded tab implementation (doesn't colour in tabs) | |
39 | // #define wxUSE_NEW_METHOD | |
40 | ||
c801d85f KB |
41 | IMPLEMENT_DYNAMIC_CLASS(wxTabControl, wxObject) |
42 | ||
43 | IMPLEMENT_DYNAMIC_CLASS(wxTabLayer, wxList) | |
44 | ||
45 | wxTabControl::wxTabControl(wxTabView *v) | |
46 | { | |
47 | m_view = v; | |
48 | m_isSelected = FALSE; | |
c801d85f KB |
49 | m_offsetX = 0; |
50 | m_offsetY = 0; | |
51 | m_width = 0; | |
52 | m_height = 0; | |
53 | m_id = 0; | |
54 | m_rowPosition = 0; | |
55 | m_colPosition = 0; | |
56 | } | |
57 | ||
58 | wxTabControl::~wxTabControl(void) | |
59 | { | |
60 | } | |
2b854a32 | 61 | |
c801d85f KB |
62 | void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) |
63 | { | |
64 | // Old, but in some ways better (drawing opaque tabs) | |
4b5f3fe6 | 65 | #ifndef wxUSE_NEW_METHOD |
c801d85f KB |
66 | if (!m_view) |
67 | return; | |
2b854a32 | 68 | |
c801d85f KB |
69 | // Top-left of tab view area |
70 | int viewX = m_view->GetViewRect().x; | |
71 | int viewY = m_view->GetViewRect().y; | |
2b854a32 | 72 | |
c801d85f KB |
73 | // Top-left of tab control |
74 | int tabX = GetX() + viewX; | |
75 | int tabY = GetY() + viewY; | |
76 | int tabHeightInc = 0; | |
77 | if (m_isSelected) | |
78 | { | |
4b5f3fe6 | 79 | tabHeightInc = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); |
c801d85f KB |
80 | tabY -= tabHeightInc; |
81 | } | |
2b854a32 | 82 | |
4b5f3fe6 | 83 | dc.SetPen(*wxTRANSPARENT_PEN); |
c801d85f KB |
84 | |
85 | // Draw grey background | |
4b5f3fe6 | 86 | if (m_view->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) |
c801d85f | 87 | { |
4b5f3fe6 | 88 | dc.SetBrush(*m_view->GetBackgroundBrush()); |
c801d85f KB |
89 | |
90 | // Add 1 because the pen is transparent. Under Motif, may be different. | |
02800301 JS |
91 | #ifdef __WXMOTIF__ |
92 | dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + tabHeightInc)); | |
93 | #else | |
c801d85f | 94 | dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc)); |
02800301 | 95 | #endif |
c801d85f | 96 | } |
2b854a32 | 97 | |
c801d85f | 98 | // Draw highlight and shadow |
4b5f3fe6 | 99 | dc.SetPen(*m_view->GetHighlightPen()); |
c801d85f KB |
100 | |
101 | // Calculate the top of the tab beneath. It's the height of the tab, MINUS | |
102 | // a bit if the tab below happens to be selected. Check. | |
103 | wxTabControl *tabBeneath = NULL; | |
104 | int subtractThis = 0; | |
105 | if (GetColPosition() > 0) | |
106 | tabBeneath = m_view->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition()); | |
107 | if (tabBeneath && tabBeneath->IsSelected()) | |
108 | subtractThis = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); | |
109 | ||
110 | // Vertical highlight: if first tab, draw to bottom of view | |
111 | if (tabX == m_view->GetViewRect().x && (m_view->GetTabStyle() & wxTAB_STYLE_DRAW_BOX)) | |
112 | dc.DrawLine(tabX, tabY, tabX, (m_view->GetViewRect().y + m_view->GetViewRect().height)); | |
113 | else if (tabX == m_view->GetViewRect().x) | |
114 | // Not box drawing, just to top of view. | |
115 | dc.DrawLine(tabX, tabY, tabX, (m_view->GetViewRect().y)); | |
116 | else | |
117 | dc.DrawLine(tabX, tabY, tabX, (tabY + GetHeight() + tabHeightInc - subtractThis)); | |
118 | ||
119 | dc.DrawLine(tabX, tabY, (tabX + GetWidth()), tabY); | |
4b5f3fe6 | 120 | dc.SetPen(*m_view->GetShadowPen()); |
c801d85f KB |
121 | |
122 | // Test if we're outside the right-hand edge of the view area | |
123 | if (((tabX + GetWidth()) >= m_view->GetViewRect().x + m_view->GetViewRect().width) && (m_view->GetTabStyle() & wxTAB_STYLE_DRAW_BOX)) | |
124 | { | |
125 | int bottomY = m_view->GetViewRect().y + m_view->GetViewRect().height + GetY() + m_view->GetTabHeight() + m_view->GetTopMargin(); | |
126 | // Add a tab height since we wish to draw to the bottom of the view. | |
127 | dc.DrawLine((tabX + GetWidth()), tabY, | |
128 | (tabX + GetWidth()), bottomY); | |
129 | ||
130 | // Calculate the far-right of the view, since we don't wish to | |
131 | // draw inside that | |
132 | int rightOfView = m_view->GetViewRect().x + m_view->GetViewRect().width + 1; | |
133 | ||
134 | // Draw the horizontal bit to connect to the view rectangle | |
135 | dc.DrawLine((wxMax((tabX + GetWidth() - m_view->GetHorizontalTabOffset()), rightOfView)), (bottomY-1), | |
136 | (tabX + GetWidth()), (bottomY-1)); | |
137 | ||
138 | // Draw black line to emphasize shadow | |
4b5f3fe6 | 139 | dc.SetPen(*wxBLACK_PEN); |
c801d85f KB |
140 | dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), |
141 | (tabX + GetWidth() + 1), bottomY); | |
142 | ||
143 | // Draw the horizontal bit to connect to the view rectangle | |
144 | dc.DrawLine((wxMax((tabX + GetWidth() - m_view->GetHorizontalTabOffset()), rightOfView)), (bottomY), | |
145 | (tabX + GetWidth() + 1), (bottomY)); | |
146 | } | |
147 | else | |
148 | { | |
149 | if (lastInRow) | |
150 | { | |
151 | // 25/5/97 UNLESS it's less than the max number of positions in this row | |
2b854a32 | 152 | |
c801d85f KB |
153 | int topY = m_view->GetViewRect().y - m_view->GetTopMargin(); |
154 | ||
1bc822df | 155 | int maxPositions = ((wxTabLayer *)m_view->GetLayers().Item(0)->GetData())->GetCount(); |
c801d85f KB |
156 | |
157 | // Only down to the bottom of the tab, not to the top of the view | |
4b5f3fe6 | 158 | if ( GetRowPosition() < (maxPositions - 1) ) |
c801d85f KB |
159 | topY = tabY + GetHeight() + tabHeightInc; |
160 | ||
02800301 JS |
161 | #ifdef __WXMOTIF__ |
162 | topY -= 1; | |
163 | #endif | |
164 | ||
c801d85f KB |
165 | // Shadow |
166 | dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), topY); | |
167 | // Draw black line to emphasize shadow | |
4b5f3fe6 | 168 | dc.SetPen(*wxBLACK_PEN); |
c801d85f KB |
169 | dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), |
170 | topY); | |
171 | } | |
172 | else | |
173 | { | |
174 | // Calculate the top of the tab beneath. It's the height of the tab, MINUS | |
175 | // a bit if the tab below (and next col along) happens to be selected. Check. | |
176 | wxTabControl *tabBeneath = NULL; | |
177 | int subtractThis = 0; | |
178 | if (GetColPosition() > 0) | |
179 | tabBeneath = m_view->FindTabControlForPosition(GetColPosition() - 1, GetRowPosition() + 1); | |
180 | if (tabBeneath && tabBeneath->IsSelected()) | |
181 | subtractThis = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight()); | |
182 | ||
02800301 JS |
183 | #ifdef __WXMOTIF__ |
184 | subtractThis += 1; | |
185 | #endif | |
186 | ||
c801d85f KB |
187 | // Draw only to next tab down. |
188 | dc.DrawLine((tabX + GetWidth()), tabY, | |
189 | (tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc - subtractThis)); | |
190 | ||
191 | // Draw black line to emphasize shadow | |
4b5f3fe6 | 192 | dc.SetPen(*wxBLACK_PEN); |
c801d85f KB |
193 | dc.DrawLine((tabX + GetWidth() + 1), (tabY+1), (tabX + GetWidth() + 1), |
194 | (tabY + GetHeight() + tabHeightInc - subtractThis)); | |
195 | } | |
196 | } | |
2b854a32 | 197 | |
c801d85f KB |
198 | // Draw centered text |
199 | int textY = tabY + m_view->GetVerticalTabTextSpacing() + tabHeightInc; | |
200 | ||
201 | if (m_isSelected) | |
02800301 | 202 | dc.SetFont(* m_view->GetSelectedTabFont()); |
c801d85f | 203 | else |
02800301 | 204 | dc.SetFont(* GetFont()); |
c801d85f KB |
205 | |
206 | wxColour col(m_view->GetTextColour()); | |
4b5f3fe6 | 207 | dc.SetTextForeground(col); |
c801d85f | 208 | dc.SetBackgroundMode(wxTRANSPARENT); |
4b5f3fe6 | 209 | long textWidth, textHeight; |
c801d85f KB |
210 | dc.GetTextExtent(GetLabel(), &textWidth, &textHeight); |
211 | ||
212 | int textX = (int)(tabX + (GetWidth() - textWidth)/2.0); | |
7fe7d506 JS |
213 | if (textX < (tabX + 2)) |
214 | textX = (tabX + 2); | |
215 | ||
216 | dc.SetClippingRegion(tabX, tabY, GetWidth(), GetHeight()); | |
c801d85f | 217 | dc.DrawText(GetLabel(), textX, textY); |
7fe7d506 | 218 | dc.DestroyClippingRegion(); |
c801d85f KB |
219 | |
220 | if (m_isSelected) | |
221 | { | |
4b5f3fe6 | 222 | dc.SetPen(*m_view->GetHighlightPen()); |
c801d85f KB |
223 | |
224 | // Draw white highlight from the tab's left side to the left hand edge of the view | |
225 | dc.DrawLine(m_view->GetViewRect().x, (tabY + GetHeight() + tabHeightInc), | |
226 | tabX, (tabY + GetHeight() + tabHeightInc)); | |
227 | ||
228 | // Draw white highlight from the tab's right side to the right hand edge of the view | |
229 | dc.DrawLine((tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc), | |
230 | m_view->GetViewRect().x + m_view->GetViewRect().width, (tabY + GetHeight() + tabHeightInc)); | |
231 | } | |
4b5f3fe6 JS |
232 | #else |
233 | // New HEL version with rounder tabs | |
c801d85f | 234 | |
2b854a32 VZ |
235 | if (!m_view) return; |
236 | ||
237 | int tabInc = 0; | |
238 | if (m_isSelected) | |
239 | { | |
240 | tabInc = m_view->GetTabSelectionHeight() - m_view->GetTabHeight(); | |
241 | } | |
242 | int tabLeft = GetX() + m_view->GetViewRect().x; | |
243 | int tabTop = GetY() + m_view->GetViewRect().y - tabInc; | |
244 | int tabRight = tabLeft + m_view->GetTabWidth(); | |
245 | int left = m_view->GetViewRect().x; | |
246 | int top = tabTop + m_view->GetTabHeight() + tabInc; | |
247 | int right = left + m_view->GetViewRect().width; | |
248 | int bottom = top + m_view->GetViewRect().height; | |
249 | ||
250 | if (m_isSelected) | |
251 | { | |
252 | // TAB is selected - draw TAB and the View's full outline | |
253 | ||
254 | dc.SetPen(*(m_view->GetHighlightPen())); | |
255 | wxPoint pnts[10]; | |
256 | int n = 0; | |
257 | pnts[n].x = left; pnts[n++].y = bottom; | |
258 | pnts[n].x = left; pnts[n++].y = top; | |
259 | pnts[n].x = tabLeft; pnts[n++].y = top; | |
260 | pnts[n].x = tabLeft; pnts[n++].y = tabTop + 2; | |
261 | pnts[n].x = tabLeft + 2; pnts[n++].y = tabTop; | |
262 | pnts[n].x = tabRight - 1; pnts[n++].y = tabTop; | |
263 | dc.DrawLines(n, pnts); | |
264 | if (!lastInRow) | |
265 | { | |
266 | dc.DrawLine( | |
267 | (tabRight + 2), | |
268 | top, | |
269 | right, | |
270 | top | |
271 | ); | |
272 | } | |
273 | ||
274 | dc.SetPen(*(m_view->GetShadowPen())); | |
275 | dc.DrawLine( | |
276 | tabRight, | |
277 | tabTop + 2, | |
278 | tabRight, | |
279 | top | |
280 | ); | |
281 | dc.DrawLine( | |
282 | right, | |
283 | top, | |
284 | right, | |
285 | bottom | |
286 | ); | |
287 | dc.DrawLine( | |
288 | right, | |
289 | bottom, | |
290 | left, | |
291 | bottom | |
292 | ); | |
293 | ||
294 | dc.SetPen(*wxBLACK_PEN); | |
295 | dc.DrawPoint( | |
296 | tabRight, | |
297 | tabTop + 1 | |
298 | ); | |
299 | dc.DrawPoint( | |
300 | tabRight + 1, | |
301 | tabTop + 2 | |
302 | ); | |
303 | if (lastInRow) | |
304 | { | |
305 | dc.DrawLine( | |
306 | tabRight + 1, | |
307 | bottom, | |
308 | tabRight + 1, | |
309 | tabTop + 1 | |
310 | ); | |
311 | } | |
312 | else | |
313 | { | |
314 | dc.DrawLine( | |
315 | tabRight + 1, | |
316 | tabTop + 2, | |
317 | tabRight + 1, | |
318 | top | |
319 | ); | |
320 | dc.DrawLine( | |
321 | right + 1, | |
322 | top, | |
323 | right + 1, | |
324 | bottom + 1 | |
325 | ); | |
326 | } | |
327 | dc.DrawLine( | |
328 | right + 1, | |
329 | bottom + 1, | |
330 | left + 1, | |
331 | bottom + 1 | |
332 | ); | |
333 | } | |
334 | else | |
335 | { | |
336 | // TAB is not selected - just draw TAB outline and RH edge | |
337 | // if the TAB is the last in the row | |
338 | ||
1bc822df | 339 | int maxPositions = ((wxTabLayer*)m_view->GetLayers().Item(0)->GetData())->GetCount(); |
2b854a32 VZ |
340 | wxTabControl* tabBelow = 0; |
341 | wxTabControl* tabBelowRight = 0; | |
342 | if (GetColPosition() > 0) | |
343 | { | |
344 | tabBelow = m_view->FindTabControlForPosition( | |
345 | GetColPosition() - 1, | |
346 | GetRowPosition() | |
347 | ); | |
348 | } | |
349 | if (!lastInRow && GetColPosition() > 0) | |
350 | { | |
351 | tabBelowRight = m_view->FindTabControlForPosition( | |
352 | GetColPosition() - 1, | |
353 | GetRowPosition() + 1 | |
354 | ); | |
355 | } | |
356 | ||
357 | float raisedTop = top - m_view->GetTabSelectionHeight() + | |
358 | m_view->GetTabHeight(); | |
359 | ||
360 | dc.SetPen(*(m_view->GetHighlightPen())); | |
361 | wxPoint pnts[10]; | |
362 | int n = 0; | |
363 | ||
364 | pnts[n].x = tabLeft; | |
365 | ||
366 | if (tabBelow && tabBelow->IsSelected()) | |
367 | { | |
368 | pnts[n++].y = (long)raisedTop; | |
369 | } | |
370 | else | |
371 | { | |
372 | pnts[n++].y = top; | |
373 | } | |
374 | pnts[n].x = tabLeft; pnts[n++].y = tabTop + 2; | |
375 | pnts[n].x = tabLeft + 2; pnts[n++].y = tabTop; | |
376 | pnts[n].x = tabRight - 1; pnts[n++].y = tabTop; | |
377 | dc.DrawLines(n, pnts); | |
378 | ||
379 | dc.SetPen(*(m_view->GetShadowPen())); | |
380 | if (GetRowPosition() >= maxPositions - 1) | |
381 | { | |
382 | dc.DrawLine( | |
383 | tabRight, | |
384 | (tabTop + 2), | |
385 | tabRight, | |
386 | bottom | |
387 | ); | |
388 | dc.DrawLine( | |
389 | tabRight, | |
390 | bottom, | |
391 | (tabRight - m_view->GetHorizontalTabOffset()), | |
392 | bottom | |
393 | ); | |
394 | } | |
395 | else | |
396 | { | |
397 | if (tabBelowRight && tabBelowRight->IsSelected()) | |
398 | { | |
399 | dc.DrawLine( | |
400 | tabRight, | |
401 | (long)raisedTop, | |
402 | tabRight, | |
403 | tabTop + 1 | |
404 | ); | |
405 | } | |
406 | else | |
407 | { | |
408 | dc.DrawLine( | |
409 | tabRight, | |
410 | top - 1, | |
411 | tabRight, | |
412 | tabTop + 1 | |
413 | ); | |
414 | } | |
415 | } | |
416 | ||
417 | dc.SetPen(*wxBLACK_PEN); | |
418 | dc.DrawPoint( | |
419 | tabRight, | |
420 | tabTop + 1 | |
421 | ); | |
422 | dc.DrawPoint( | |
423 | tabRight + 1, | |
424 | tabTop + 2 | |
425 | ); | |
426 | if (GetRowPosition() >= maxPositions - 1) | |
427 | { | |
428 | // draw right hand edge to bottom of view | |
429 | dc.DrawLine( | |
430 | tabRight + 1, | |
431 | bottom + 1, | |
432 | tabRight + 1, | |
433 | tabTop + 2 | |
434 | ); | |
435 | dc.DrawLine( | |
436 | tabRight + 1, | |
437 | bottom + 1, | |
438 | (tabRight - m_view->GetHorizontalTabOffset()), | |
439 | bottom + 1 | |
440 | ); | |
441 | } | |
442 | else | |
443 | { | |
444 | // draw right hand edge of TAB | |
445 | if (tabBelowRight && tabBelowRight->IsSelected()) | |
446 | { | |
447 | dc.DrawLine( | |
448 | tabRight + 1, | |
449 | (long)(raisedTop - 1), | |
450 | tabRight + 1, | |
451 | tabTop + 2 | |
452 | ); | |
453 | } | |
454 | else | |
455 | { | |
456 | dc.DrawLine( | |
457 | tabRight + 1, | |
458 | top - 1, | |
459 | tabRight + 1, | |
460 | tabTop + 2 | |
461 | ); | |
462 | } | |
463 | } | |
464 | } | |
465 | ||
466 | // Draw centered text | |
467 | dc.SetPen(*wxBLACK_PEN); | |
468 | if (m_isSelected) | |
469 | { | |
470 | dc.SetFont(*(m_view->GetSelectedTabFont())); | |
471 | } | |
472 | else | |
473 | { | |
474 | dc.SetFont(*(GetFont())); | |
475 | } | |
476 | ||
477 | wxColour col(m_view->GetTextColour()); | |
478 | dc.SetTextForeground(col); | |
479 | dc.SetBackgroundMode(wxTRANSPARENT); | |
480 | long textWidth, textHeight; | |
481 | dc.GetTextExtent(GetLabel(), &textWidth, &textHeight); | |
482 | ||
483 | float textX = (tabLeft + tabRight - textWidth) / 2; | |
484 | float textY = (tabInc + tabTop + m_view->GetVerticalTabTextSpacing()); | |
485 | ||
486 | dc.DrawText(GetLabel(), (long)textX, (long)textY); | |
c801d85f KB |
487 | #endif |
488 | } | |
489 | ||
490 | bool wxTabControl::HitTest(int x, int y) const | |
491 | { | |
492 | // Top-left of tab control | |
493 | int tabX1 = GetX() + m_view->GetViewRect().x; | |
494 | int tabY1 = GetY() + m_view->GetViewRect().y; | |
495 | ||
496 | // Bottom-right | |
497 | int tabX2 = tabX1 + GetWidth(); | |
498 | int tabY2 = tabY1 + GetHeight(); | |
2b854a32 | 499 | |
c801d85f KB |
500 | if (x >= tabX1 && y >= tabY1 && x <= tabX2 && y <= tabY2) |
501 | return TRUE; | |
502 | else | |
503 | return FALSE; | |
504 | } | |
505 | ||
506 | IMPLEMENT_DYNAMIC_CLASS(wxTabView, wxObject) | |
507 | ||
508 | wxTabView::wxTabView(long style) | |
509 | { | |
510 | m_noTabs = 0; | |
511 | m_tabStyle = style; | |
512 | m_tabSelection = -1; | |
513 | m_tabHeight = 20; | |
514 | m_tabSelectionHeight = m_tabHeight + 2; | |
515 | m_tabWidth = 80; | |
516 | m_tabHorizontalOffset = 10; | |
517 | m_tabHorizontalSpacing = 2; | |
518 | m_tabVerticalTextSpacing = 3; | |
519 | m_topMargin = 5; | |
520 | m_tabViewRect.x = 20; | |
521 | m_tabViewRect.y = 20; | |
522 | m_tabViewRect.width = 300; | |
523 | m_tabViewRect.x = 300; | |
524 | m_highlightColour = *wxWHITE; | |
525 | m_shadowColour = wxColour(128, 128, 128); | |
526 | m_backgroundColour = *wxLIGHT_GREY; | |
527 | m_textColour = *wxBLACK; | |
528 | m_highlightPen = wxWHITE_PEN; | |
529 | m_shadowPen = wxGREY_PEN; | |
530 | m_backgroundPen = wxLIGHT_GREY_PEN; | |
531 | m_backgroundBrush = wxLIGHT_GREY_BRUSH; | |
a756f210 VS |
532 | m_tabFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
533 | m_tabSelectedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
c67daf87 | 534 | m_window = (wxWindow *) NULL; |
c801d85f KB |
535 | } |
536 | ||
537 | wxTabView::~wxTabView() | |
538 | { | |
02800301 | 539 | ClearTabs(TRUE); |
c801d85f | 540 | } |
2b854a32 | 541 | |
c801d85f | 542 | // Automatically positions tabs |
4b5f3fe6 JS |
543 | // TODO: this should just add the tab to a list, and then |
544 | // a layout function (e.g. Realize) should be called when all tabs have been added. | |
545 | // The view rect could easily change as the view window is resized. | |
c801d85f KB |
546 | wxTabControl *wxTabView::AddTab(int id, const wxString& label, wxTabControl *existingTab) |
547 | { | |
548 | // First, find which layer we should be adding to. | |
1bc822df | 549 | wxNode *node = m_layers.GetLast(); |
c801d85f KB |
550 | if (!node) |
551 | { | |
552 | wxTabLayer *newLayer = new wxTabLayer; | |
553 | node = m_layers.Append(newLayer); | |
554 | } | |
555 | // Check if adding another tab control would go off the | |
556 | // right-hand edge of the layer. | |
1bc822df MB |
557 | wxTabLayer *tabLayer = (wxTabLayer *)node->GetData(); |
558 | wxNode *lastTabNode = tabLayer->GetLast(); | |
c801d85f KB |
559 | if (lastTabNode) |
560 | { | |
1bc822df | 561 | wxTabControl *lastTab = (wxTabControl *)lastTabNode->GetData(); |
c801d85f KB |
562 | // Start another layer (row). |
563 | // Tricky choice: can't just check if will be overlapping the edge, because | |
564 | // this happens anyway for 2nd and subsequent rows. | |
565 | // Should check this for 1st row, and then subsequent rows should not exceed 1st | |
566 | // in length. | |
1bc822df | 567 | if (((tabLayer == m_layers.GetFirst()->GetData()) && ((lastTab->GetX() + 2*lastTab->GetWidth() + GetHorizontalTabSpacing()) |
c801d85f | 568 | > GetViewRect().width)) || |
1bc822df | 569 | ((tabLayer != m_layers.GetFirst()->GetData()) && (tabLayer->GetCount() == ((wxTabLayer *)m_layers.GetFirst()->GetData())->GetCount()))) |
c801d85f KB |
570 | { |
571 | tabLayer = new wxTabLayer; | |
572 | m_layers.Append(tabLayer); | |
c67daf87 | 573 | lastTabNode = (wxNode *) NULL; |
c801d85f KB |
574 | } |
575 | } | |
1bc822df | 576 | int layer = m_layers.GetCount() - 1; |
2b854a32 | 577 | |
c801d85f KB |
578 | wxTabControl *tabControl = existingTab; |
579 | if (!existingTab) | |
580 | tabControl = OnCreateTabControl(); | |
1bc822df | 581 | tabControl->SetRowPosition(tabLayer->GetCount()); |
c801d85f | 582 | tabControl->SetColPosition(layer); |
2b854a32 | 583 | |
c67daf87 | 584 | wxTabControl *lastTab = (wxTabControl *) NULL; |
c801d85f | 585 | if (lastTabNode) |
1bc822df | 586 | lastTab = (wxTabControl *)lastTabNode->GetData(); |
2b854a32 | 587 | |
c801d85f KB |
588 | // Top of new tab |
589 | int verticalOffset = (- GetTopMargin()) - ((layer+1)*GetTabHeight()); | |
590 | // Offset from view top-left | |
591 | int horizontalOffset = 0; | |
592 | if (!lastTab) | |
593 | horizontalOffset = layer*GetHorizontalTabOffset(); | |
594 | else | |
595 | horizontalOffset = lastTab->GetX() + GetTabWidth() + GetHorizontalTabSpacing(); | |
2b854a32 | 596 | |
c801d85f KB |
597 | tabControl->SetPosition(horizontalOffset, verticalOffset); |
598 | tabControl->SetSize(GetTabWidth(), GetTabHeight()); | |
599 | tabControl->SetId(id); | |
600 | tabControl->SetLabel(label); | |
02800301 | 601 | tabControl->SetFont(* GetTabFont()); |
2b854a32 | 602 | |
c801d85f KB |
603 | tabLayer->Append(tabControl); |
604 | m_noTabs ++; | |
2b854a32 | 605 | |
c801d85f KB |
606 | return tabControl; |
607 | } | |
621793f4 JS |
608 | |
609 | // Remove the tab without deleting the window | |
610 | bool wxTabView::RemoveTab(int id) | |
611 | { | |
1bc822df | 612 | wxNode *layerNode = m_layers.GetFirst(); |
621793f4 JS |
613 | while (layerNode) |
614 | { | |
1bc822df MB |
615 | wxTabLayer *layer = (wxTabLayer *)layerNode->GetData(); |
616 | wxNode *tabNode = layer->GetFirst(); | |
621793f4 JS |
617 | while (tabNode) |
618 | { | |
1bc822df | 619 | wxTabControl *tab = (wxTabControl *)tabNode->GetData(); |
621793f4 JS |
620 | if (tab->GetId() == id) |
621 | { | |
622 | if (id == m_tabSelection) | |
623 | m_tabSelection = -1; | |
624 | delete tab; | |
625 | delete tabNode; | |
7fe7d506 | 626 | m_noTabs --; |
621793f4 JS |
627 | |
628 | // The layout has changed | |
f03fc89f | 629 | LayoutTabs(); |
621793f4 JS |
630 | return TRUE; |
631 | } | |
1bc822df | 632 | tabNode = tabNode->GetNext(); |
621793f4 | 633 | } |
1bc822df | 634 | layerNode = layerNode->GetNext(); |
621793f4 JS |
635 | } |
636 | return FALSE; | |
637 | } | |
7fe7d506 JS |
638 | |
639 | bool wxTabView::SetTabText(int id, const wxString& label) | |
640 | { | |
641 | wxTabControl* control = FindTabControlForId(id); | |
642 | if (!control) | |
643 | return FALSE; | |
644 | control->SetLabel(label); | |
645 | return TRUE; | |
646 | } | |
647 | ||
648 | wxString wxTabView::GetTabText(int id) const | |
649 | { | |
650 | wxTabControl* control = FindTabControlForId(id); | |
651 | if (!control) | |
652 | return wxEmptyString; | |
653 | else | |
654 | return control->GetLabel(); | |
655 | } | |
2b854a32 | 656 | |
4b5f3fe6 JS |
657 | // Returns the total height of the tabs component -- this may be several |
658 | // times the height of a tab, if there are several tab layers (rows). | |
659 | int wxTabView::GetTotalTabHeight() | |
660 | { | |
661 | int minY = 0; | |
662 | ||
1bc822df | 663 | wxNode *layerNode = m_layers.GetFirst(); |
4b5f3fe6 JS |
664 | while (layerNode) |
665 | { | |
1bc822df MB |
666 | wxTabLayer *layer = (wxTabLayer *)layerNode->GetData(); |
667 | wxNode *tabNode = layer->GetFirst(); | |
4b5f3fe6 JS |
668 | while (tabNode) |
669 | { | |
1bc822df | 670 | wxTabControl *tab = (wxTabControl *)tabNode->GetData(); |
4b5f3fe6 JS |
671 | |
672 | if (tab->GetY() < minY) | |
673 | minY = tab->GetY(); | |
674 | ||
1bc822df | 675 | tabNode = tabNode->GetNext(); |
4b5f3fe6 | 676 | } |
1bc822df | 677 | layerNode = layerNode->GetNext(); |
4b5f3fe6 JS |
678 | } |
679 | ||
680 | return - minY; | |
681 | } | |
682 | ||
c801d85f KB |
683 | void wxTabView::ClearTabs(bool deleteTabs) |
684 | { | |
1bc822df | 685 | wxNode *layerNode = m_layers.GetFirst(); |
c801d85f KB |
686 | while (layerNode) |
687 | { | |
1bc822df MB |
688 | wxTabLayer *layer = (wxTabLayer *)layerNode->GetData(); |
689 | wxNode *tabNode = layer->GetFirst(); | |
c801d85f KB |
690 | while (tabNode) |
691 | { | |
1bc822df | 692 | wxTabControl *tab = (wxTabControl *)tabNode->GetData(); |
c801d85f KB |
693 | if (deleteTabs) |
694 | delete tab; | |
1bc822df | 695 | wxNode *next = tabNode->GetNext(); |
c801d85f KB |
696 | delete tabNode; |
697 | tabNode = next; | |
698 | } | |
1bc822df | 699 | wxNode *nextLayerNode = layerNode->GetNext(); |
c801d85f KB |
700 | delete layer; |
701 | delete layerNode; | |
702 | layerNode = nextLayerNode; | |
703 | } | |
7fe7d506 | 704 | m_noTabs = 0; |
51babd09 | 705 | m_tabSelection = -1; |
c801d85f | 706 | } |
4b5f3fe6 JS |
707 | |
708 | ||
c801d85f | 709 | // Layout tabs (optional, e.g. if resizing window) |
f03fc89f | 710 | void wxTabView::LayoutTabs(void) |
c801d85f KB |
711 | { |
712 | // Make a list of the tab controls, deleting the wxTabLayers. | |
713 | wxList controls; | |
714 | ||
1bc822df | 715 | wxNode *layerNode = m_layers.GetFirst(); |
c801d85f KB |
716 | while (layerNode) |
717 | { | |
1bc822df MB |
718 | wxTabLayer *layer = (wxTabLayer *)layerNode->GetData(); |
719 | wxNode *tabNode = layer->GetFirst(); | |
c801d85f KB |
720 | while (tabNode) |
721 | { | |
1bc822df | 722 | wxTabControl *tab = (wxTabControl *)tabNode->GetData(); |
c801d85f | 723 | controls.Append(tab); |
1bc822df | 724 | wxNode *next = tabNode->GetNext(); |
c801d85f KB |
725 | delete tabNode; |
726 | tabNode = next; | |
727 | } | |
1bc822df | 728 | wxNode *nextLayerNode = layerNode->GetNext(); |
c801d85f KB |
729 | delete layer; |
730 | delete layerNode; | |
731 | layerNode = nextLayerNode; | |
732 | } | |
2b854a32 | 733 | |
c67daf87 | 734 | wxTabControl *lastTab = (wxTabControl *) NULL; |
2b854a32 | 735 | |
c801d85f KB |
736 | wxTabLayer *currentLayer = new wxTabLayer; |
737 | m_layers.Append(currentLayer); | |
2b854a32 | 738 | |
1bc822df | 739 | wxNode *node = controls.GetFirst(); |
c801d85f KB |
740 | while (node) |
741 | { | |
1bc822df | 742 | wxTabControl *tabControl = (wxTabControl *)node->GetData(); |
c801d85f KB |
743 | if (lastTab) |
744 | { | |
745 | // Start another layer (row). | |
746 | // Tricky choice: can't just check if will be overlapping the edge, because | |
747 | // this happens anyway for 2nd and subsequent rows. | |
748 | // Should check this for 1st row, and then subsequent rows should not exceed 1st | |
749 | // in length. | |
1bc822df | 750 | if (((currentLayer == m_layers.GetFirst()->GetData()) && ((lastTab->GetX() + 2*lastTab->GetWidth() + GetHorizontalTabSpacing()) |
c801d85f | 751 | > GetViewRect().width)) || |
1bc822df | 752 | ((currentLayer != m_layers.GetFirst()->GetData()) && (currentLayer->GetCount() == ((wxTabLayer *)m_layers.GetFirst()->GetData())->GetCount()))) |
c801d85f KB |
753 | { |
754 | currentLayer = new wxTabLayer; | |
755 | m_layers.Append(currentLayer); | |
c67daf87 | 756 | lastTab = (wxTabControl *) NULL; |
c801d85f KB |
757 | } |
758 | } | |
2b854a32 | 759 | |
1bc822df | 760 | int layer = m_layers.GetCount() - 1; |
c801d85f | 761 | |
1bc822df | 762 | tabControl->SetRowPosition(currentLayer->GetCount()); |
c801d85f | 763 | tabControl->SetColPosition(layer); |
2b854a32 | 764 | |
c801d85f KB |
765 | // Top of new tab |
766 | int verticalOffset = (- GetTopMargin()) - ((layer+1)*GetTabHeight()); | |
767 | // Offset from view top-left | |
768 | int horizontalOffset = 0; | |
769 | if (!lastTab) | |
770 | horizontalOffset = layer*GetHorizontalTabOffset(); | |
771 | else | |
772 | horizontalOffset = lastTab->GetX() + GetTabWidth() + GetHorizontalTabSpacing(); | |
2b854a32 | 773 | |
c801d85f KB |
774 | tabControl->SetPosition(horizontalOffset, verticalOffset); |
775 | tabControl->SetSize(GetTabWidth(), GetTabHeight()); | |
776 | ||
777 | currentLayer->Append(tabControl); | |
778 | lastTab = tabControl; | |
779 | ||
1bc822df | 780 | node = node->GetNext(); |
c801d85f KB |
781 | } |
782 | ||
783 | // Move the selected tab to the bottom | |
784 | wxTabControl *control = FindTabControlForId(m_tabSelection); | |
785 | if (control) | |
786 | MoveSelectionTab(control); | |
787 | ||
788 | } | |
789 | ||
790 | // Draw all tabs | |
791 | void wxTabView::Draw(wxDC& dc) | |
792 | { | |
7fe7d506 JS |
793 | // Don't draw anything if there are no tabs. |
794 | if (GetNumberOfTabs() == 0) | |
795 | return; | |
796 | ||
2b854a32 VZ |
797 | // Draw top margin area (beneath tabs and above view area) |
798 | if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) | |
799 | { | |
800 | dc.SetPen(*wxTRANSPARENT_PEN); | |
801 | dc.SetBrush(*GetBackgroundBrush()); | |
802 | ||
803 | // Add 1 because the pen is transparent. Under Motif, may be different. | |
804 | dc.DrawRectangle( | |
805 | m_tabViewRect.x, | |
806 | (m_tabViewRect.y - m_topMargin), | |
807 | (m_tabViewRect.width + 1), | |
808 | (m_topMargin + 1) | |
809 | ); | |
810 | } | |
811 | ||
812 | // Draw layers in reverse order | |
1bc822df | 813 | wxNode *node = m_layers.GetLast(); |
2b854a32 VZ |
814 | while (node) |
815 | { | |
1bc822df MB |
816 | wxTabLayer *layer = (wxTabLayer *)node->GetData(); |
817 | wxNode *node2 = layer->GetFirst(); | |
2b854a32 VZ |
818 | while (node2) |
819 | { | |
1bc822df MB |
820 | wxTabControl *control = (wxTabControl *)node2->GetData(); |
821 | control->OnDraw(dc, (node2->GetNext() == NULL)); | |
822 | node2 = node2->GetNext(); | |
2b854a32 VZ |
823 | } |
824 | ||
1bc822df | 825 | node = node->GetPrevious(); |
2b854a32 | 826 | } |
c801d85f KB |
827 | |
828 | ||
4b5f3fe6 | 829 | #ifndef wxUSE_NEW_METHOD |
2b854a32 VZ |
830 | if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX) |
831 | { | |
832 | dc.SetPen(* GetShadowPen()); | |
833 | ||
834 | // Draw bottom line | |
835 | dc.DrawLine( | |
836 | (GetViewRect().x + 1), | |
837 | (GetViewRect().y + GetViewRect().height), | |
838 | (GetViewRect().x + GetViewRect().width + 1), | |
839 | (GetViewRect().y + GetViewRect().height) | |
840 | ); | |
841 | ||
842 | // Draw right line | |
843 | dc.DrawLine( | |
844 | (GetViewRect().x + GetViewRect().width), | |
845 | (GetViewRect().y - GetTopMargin() + 1), | |
846 | (GetViewRect().x + GetViewRect().width), | |
847 | (GetViewRect().y + GetViewRect().height) | |
848 | ); | |
849 | ||
850 | dc.SetPen(* wxBLACK_PEN); | |
851 | ||
852 | // Draw bottom line | |
853 | dc.DrawLine( | |
854 | (GetViewRect().x), | |
855 | (GetViewRect().y + GetViewRect().height + 1), | |
02800301 | 856 | #if defined(__WXMOTIF__) |
2b854a32 | 857 | (GetViewRect().x + GetViewRect().width + 1), |
02800301 | 858 | #else |
2b854a32 | 859 | (GetViewRect().x + GetViewRect().width + 2), |
02800301 JS |
860 | #endif |
861 | ||
2b854a32 VZ |
862 | (GetViewRect().y + GetViewRect().height + 1) |
863 | ); | |
864 | ||
865 | // Draw right line | |
866 | dc.DrawLine( | |
867 | (GetViewRect().x + GetViewRect().width + 1), | |
868 | (GetViewRect().y - GetTopMargin()), | |
869 | (GetViewRect().x + GetViewRect().width + 1), | |
870 | (GetViewRect().y + GetViewRect().height + 1) | |
871 | ); | |
872 | } | |
c801d85f KB |
873 | #endif |
874 | } | |
2b854a32 | 875 | |
c801d85f KB |
876 | // Process mouse event, return FALSE if we didn't process it |
877 | bool wxTabView::OnEvent(wxMouseEvent& event) | |
878 | { | |
879 | if (!event.LeftDown()) | |
880 | return FALSE; | |
2b854a32 | 881 | |
e6575209 VZ |
882 | wxCoord x, y; |
883 | event.GetPosition(&x, &y); | |
2b854a32 | 884 | |
c67daf87 | 885 | wxTabControl *hitControl = (wxTabControl *) NULL; |
2b854a32 | 886 | |
1bc822df | 887 | wxNode *node = m_layers.GetFirst(); |
c801d85f KB |
888 | while (node) |
889 | { | |
1bc822df MB |
890 | wxTabLayer *layer = (wxTabLayer *)node->GetData(); |
891 | wxNode *node2 = layer->GetFirst(); | |
c801d85f KB |
892 | while (node2) |
893 | { | |
1bc822df | 894 | wxTabControl *control = (wxTabControl *)node2->GetData(); |
c801d85f KB |
895 | if (control->HitTest((int)x, (int)y)) |
896 | { | |
897 | hitControl = control; | |
c67daf87 UR |
898 | node = (wxNode *) NULL; |
899 | node2 = (wxNode *) NULL; | |
c801d85f KB |
900 | } |
901 | else | |
1bc822df | 902 | node2 = node2->GetNext(); |
c801d85f | 903 | } |
2b854a32 | 904 | |
c801d85f | 905 | if (node) |
1bc822df | 906 | node = node->GetNext(); |
c801d85f | 907 | } |
2b854a32 | 908 | |
c801d85f KB |
909 | if (!hitControl) |
910 | return FALSE; | |
2b854a32 | 911 | |
c801d85f | 912 | wxTabControl *currentTab = FindTabControlForId(m_tabSelection); |
2b854a32 | 913 | |
c801d85f KB |
914 | if (hitControl == currentTab) |
915 | return FALSE; | |
2b854a32 | 916 | |
c801d85f | 917 | ChangeTab(hitControl); |
2b854a32 | 918 | |
c801d85f KB |
919 | return TRUE; |
920 | } | |
921 | ||
922 | bool wxTabView::ChangeTab(wxTabControl *control) | |
923 | { | |
924 | wxTabControl *currentTab = FindTabControlForId(m_tabSelection); | |
925 | int oldTab = -1; | |
926 | if (currentTab) | |
927 | oldTab = currentTab->GetId(); | |
2b854a32 | 928 | |
c801d85f KB |
929 | if (control == currentTab) |
930 | return TRUE; | |
2b854a32 | 931 | |
1bc822df | 932 | if (m_layers.GetCount() == 0) |
c801d85f | 933 | return FALSE; |
2b854a32 | 934 | |
c801d85f KB |
935 | if (!OnTabPreActivate(control->GetId(), oldTab)) |
936 | return FALSE; | |
937 | ||
938 | // Move the tab to the bottom | |
939 | MoveSelectionTab(control); | |
940 | ||
941 | if (currentTab) | |
942 | currentTab->SetSelected(FALSE); | |
2b854a32 | 943 | |
c801d85f KB |
944 | control->SetSelected(TRUE); |
945 | m_tabSelection = control->GetId(); | |
946 | ||
947 | OnTabActivate(control->GetId(), oldTab); | |
2b854a32 | 948 | |
c801d85f KB |
949 | // Leave window refresh for the implementing window |
950 | ||
951 | return TRUE; | |
952 | } | |
953 | ||
954 | // Move the selected tab to the bottom layer, if necessary, | |
955 | // without calling app activation code | |
956 | bool wxTabView::MoveSelectionTab(wxTabControl *control) | |
957 | { | |
1bc822df | 958 | if (m_layers.GetCount() == 0) |
c801d85f | 959 | return FALSE; |
2b854a32 | 960 | |
1bc822df | 961 | wxTabLayer *firstLayer = (wxTabLayer *)m_layers.GetFirst()->GetData(); |
2b854a32 | 962 | |
c801d85f KB |
963 | // Find what column this tab is at, so we can swap with the one at the bottom. |
964 | // If we're on the bottom layer, then no need to swap. | |
965 | if (!firstLayer->Member(control)) | |
966 | { | |
967 | // Do a swap | |
968 | int col = 0; | |
969 | wxNode *thisNode = FindTabNodeAndColumn(control, &col); | |
970 | if (!thisNode) | |
971 | return FALSE; | |
1bc822df | 972 | wxNode *otherNode = firstLayer->Item(col); |
c801d85f KB |
973 | if (!otherNode) |
974 | return FALSE; | |
2b854a32 | 975 | |
c801d85f KB |
976 | // If this is already in the bottom layer, return now |
977 | if (otherNode == thisNode) | |
978 | return TRUE; | |
2b854a32 | 979 | |
1bc822df | 980 | wxTabControl *otherTab = (wxTabControl *)otherNode->GetData(); |
2b854a32 | 981 | |
c801d85f KB |
982 | // We now have pointers to the tab to be changed to, |
983 | // and the tab on the first layer. Swap tab structures and | |
984 | // position details. | |
2b854a32 | 985 | |
c801d85f KB |
986 | int thisX = control->GetX(); |
987 | int thisY = control->GetY(); | |
988 | int thisColPos = control->GetColPosition(); | |
989 | int otherX = otherTab->GetX(); | |
990 | int otherY = otherTab->GetY(); | |
991 | int otherColPos = otherTab->GetColPosition(); | |
2b854a32 | 992 | |
c801d85f KB |
993 | control->SetPosition(otherX, otherY); |
994 | control->SetColPosition(otherColPos); | |
995 | otherTab->SetPosition(thisX, thisY); | |
996 | otherTab->SetColPosition(thisColPos); | |
2b854a32 | 997 | |
c801d85f KB |
998 | // Swap the data for the nodes |
999 | thisNode->SetData(otherTab); | |
1000 | otherNode->SetData(control); | |
1001 | } | |
1002 | return TRUE; | |
1003 | } | |
1004 | ||
1005 | // Called when a tab is activated | |
1006 | void wxTabView::OnTabActivate(int /*activateId*/, int /*deactivateId*/) | |
1007 | { | |
1008 | } | |
2b854a32 | 1009 | |
c801d85f KB |
1010 | void wxTabView::SetHighlightColour(const wxColour& col) |
1011 | { | |
1012 | m_highlightColour = col; | |
1013 | m_highlightPen = wxThePenList->FindOrCreatePen(col, 1, wxSOLID); | |
1014 | } | |
1015 | ||
1016 | void wxTabView::SetShadowColour(const wxColour& col) | |
1017 | { | |
1018 | m_shadowColour = col; | |
1019 | m_shadowPen = wxThePenList->FindOrCreatePen(col, 1, wxSOLID); | |
1020 | } | |
1021 | ||
1022 | void wxTabView::SetBackgroundColour(const wxColour& col) | |
1023 | { | |
1024 | m_backgroundColour = col; | |
1025 | m_backgroundPen = wxThePenList->FindOrCreatePen(col, 1, wxSOLID); | |
1026 | m_backgroundBrush = wxTheBrushList->FindOrCreateBrush(col, wxSOLID); | |
1027 | } | |
1028 | ||
1029 | void wxTabView::SetTabSelection(int sel, bool activateTool) | |
1030 | { | |
51babd09 JS |
1031 | if ( sel==m_tabSelection ) |
1032 | return; | |
1033 | ||
c801d85f KB |
1034 | int oldSel = m_tabSelection; |
1035 | wxTabControl *control = FindTabControlForId(sel); | |
621793f4 | 1036 | wxTabControl *oldControl = FindTabControlForId(m_tabSelection); |
c801d85f KB |
1037 | |
1038 | if (!OnTabPreActivate(sel, oldSel)) | |
1039 | return; | |
2b854a32 | 1040 | |
c801d85f | 1041 | if (control) |
621793f4 JS |
1042 | control->SetSelected((sel != -1)); // TODO ?? |
1043 | else if (sel != -1) | |
c801d85f | 1044 | { |
621793f4 | 1045 | wxFAIL_MSG(_("Could not find tab for id")); |
c801d85f KB |
1046 | return; |
1047 | } | |
621793f4 JS |
1048 | |
1049 | if (oldControl) | |
1050 | oldControl->SetSelected(FALSE); | |
2b854a32 | 1051 | |
c801d85f | 1052 | m_tabSelection = sel; |
621793f4 JS |
1053 | |
1054 | if (control) | |
1055 | MoveSelectionTab(control); | |
2b854a32 | 1056 | |
c801d85f KB |
1057 | if (activateTool) |
1058 | OnTabActivate(sel, oldSel); | |
1059 | } | |
1060 | ||
1061 | // Find tab control for id | |
1062 | wxTabControl *wxTabView::FindTabControlForId(int id) const | |
1063 | { | |
1bc822df | 1064 | wxNode *node1 = m_layers.GetFirst(); |
c801d85f KB |
1065 | while (node1) |
1066 | { | |
1bc822df MB |
1067 | wxTabLayer *layer = (wxTabLayer *)node1->GetData(); |
1068 | wxNode *node2 = layer->GetFirst(); | |
c801d85f KB |
1069 | while (node2) |
1070 | { | |
1bc822df | 1071 | wxTabControl *control = (wxTabControl *)node2->GetData(); |
c801d85f KB |
1072 | if (control->GetId() == id) |
1073 | return control; | |
1bc822df | 1074 | node2 = node2->GetNext(); |
c801d85f | 1075 | } |
1bc822df | 1076 | node1 = node1->GetNext(); |
c801d85f | 1077 | } |
c67daf87 | 1078 | return (wxTabControl *) NULL; |
c801d85f KB |
1079 | } |
1080 | ||
1081 | // Find tab control for layer, position (starting from zero) | |
1082 | wxTabControl *wxTabView::FindTabControlForPosition(int layer, int position) const | |
1083 | { | |
1bc822df | 1084 | wxNode *node1 = m_layers.Item(layer); |
c801d85f | 1085 | if (!node1) |
c67daf87 | 1086 | return (wxTabControl *) NULL; |
1bc822df MB |
1087 | wxTabLayer *tabLayer = (wxTabLayer *)node1->GetData(); |
1088 | wxNode *node2 = tabLayer->Item(position); | |
c801d85f | 1089 | if (!node2) |
c67daf87 | 1090 | return (wxTabControl *) NULL; |
1bc822df | 1091 | return (wxTabControl *)node2->GetData(); |
c801d85f KB |
1092 | } |
1093 | ||
1094 | // Find the node and the column at which this control is positioned. | |
1095 | wxNode *wxTabView::FindTabNodeAndColumn(wxTabControl *control, int *col) const | |
1096 | { | |
1bc822df | 1097 | wxNode *node1 = m_layers.GetFirst(); |
c801d85f KB |
1098 | while (node1) |
1099 | { | |
1bc822df | 1100 | wxTabLayer *layer = (wxTabLayer *)node1->GetData(); |
c801d85f | 1101 | int c = 0; |
1bc822df | 1102 | wxNode *node2 = layer->GetFirst(); |
c801d85f KB |
1103 | while (node2) |
1104 | { | |
1bc822df | 1105 | wxTabControl *cnt = (wxTabControl *)node2->GetData(); |
c801d85f KB |
1106 | if (cnt == control) |
1107 | { | |
1108 | *col = c; | |
1109 | return node2; | |
1110 | } | |
1bc822df | 1111 | node2 = node2->GetNext(); |
c801d85f KB |
1112 | c ++; |
1113 | } | |
1bc822df | 1114 | node1 = node1->GetNext(); |
c801d85f | 1115 | } |
c67daf87 | 1116 | return (wxNode *) NULL; |
c801d85f KB |
1117 | } |
1118 | ||
1119 | int wxTabView::CalculateTabWidth(int noTabs, bool adjustView) | |
1120 | { | |
1121 | m_tabWidth = (int)((m_tabViewRect.width - ((noTabs - 1)*GetHorizontalTabSpacing()))/noTabs); | |
1122 | if (adjustView) | |
1123 | { | |
1124 | m_tabViewRect.width = noTabs*m_tabWidth + ((noTabs-1)*GetHorizontalTabSpacing()); | |
1125 | } | |
1126 | return m_tabWidth; | |
1127 | } | |
1128 | ||
1129 | /* | |
1130 | * wxTabbedDialog | |
1131 | */ | |
2b854a32 | 1132 | |
c801d85f KB |
1133 | IMPLEMENT_CLASS(wxTabbedDialog, wxDialog) |
1134 | ||
1135 | BEGIN_EVENT_TABLE(wxTabbedDialog, wxDialog) | |
1136 | EVT_CLOSE(wxTabbedDialog::OnCloseWindow) | |
1137 | EVT_MOUSE_EVENTS(wxTabbedDialog::OnMouseEvent) | |
1138 | EVT_PAINT(wxTabbedDialog::OnPaint) | |
1139 | END_EVENT_TABLE() | |
1140 | ||
debe6624 | 1141 | wxTabbedDialog::wxTabbedDialog(wxWindow *parent, wxWindowID id, |
c801d85f KB |
1142 | const wxString& title, |
1143 | const wxPoint& pos, const wxSize& size, | |
debe6624 | 1144 | long windowStyle, const wxString& name): |
c801d85f KB |
1145 | wxDialog(parent, id, title, pos, size, windowStyle, name) |
1146 | { | |
c67daf87 | 1147 | m_tabView = (wxTabView *) NULL; |
c801d85f KB |
1148 | } |
1149 | ||
1150 | wxTabbedDialog::~wxTabbedDialog(void) | |
1151 | { | |
1152 | if (m_tabView) | |
1153 | delete m_tabView; | |
1154 | } | |
2b854a32 | 1155 | |
c801d85f KB |
1156 | void wxTabbedDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) ) |
1157 | { | |
1158 | Destroy(); | |
1159 | } | |
1160 | ||
1161 | void wxTabbedDialog::OnMouseEvent(wxMouseEvent& event ) | |
1162 | { | |
1163 | if (m_tabView) | |
1164 | m_tabView->OnEvent(event); | |
1165 | } | |
1166 | ||
1167 | void wxTabbedDialog::OnPaint(wxPaintEvent& WXUNUSED(event) ) | |
1168 | { | |
1169 | wxPaintDC dc(this); | |
1170 | if (m_tabView) | |
1171 | m_tabView->Draw(dc); | |
1172 | } | |
1173 | ||
1174 | /* | |
1175 | * wxTabbedPanel | |
1176 | */ | |
2b854a32 | 1177 | |
c801d85f KB |
1178 | IMPLEMENT_CLASS(wxTabbedPanel, wxPanel) |
1179 | ||
1180 | BEGIN_EVENT_TABLE(wxTabbedPanel, wxPanel) | |
1181 | EVT_MOUSE_EVENTS(wxTabbedPanel::OnMouseEvent) | |
1182 | EVT_PAINT(wxTabbedPanel::OnPaint) | |
1183 | END_EVENT_TABLE() | |
1184 | ||
debe6624 JS |
1185 | wxTabbedPanel::wxTabbedPanel(wxWindow *parent, wxWindowID id, const wxPoint& pos, |
1186 | const wxSize& size, long windowStyle, const wxString& name): | |
c801d85f KB |
1187 | wxPanel(parent, id, pos, size, windowStyle, name) |
1188 | { | |
c67daf87 | 1189 | m_tabView = (wxTabView *) NULL; |
c801d85f KB |
1190 | } |
1191 | ||
1192 | wxTabbedPanel::~wxTabbedPanel(void) | |
1193 | { | |
1194 | delete m_tabView; | |
1195 | } | |
2b854a32 | 1196 | |
c801d85f KB |
1197 | void wxTabbedPanel::OnMouseEvent(wxMouseEvent& event) |
1198 | { | |
1199 | if (m_tabView) | |
1200 | m_tabView->OnEvent(event); | |
1201 | } | |
1202 | ||
1203 | void wxTabbedPanel::OnPaint(wxPaintEvent& WXUNUSED(event) ) | |
1204 | { | |
1205 | wxPaintDC dc(this); | |
1206 | if (m_tabView) | |
1207 | m_tabView->Draw(dc); | |
1208 | } | |
1209 | ||
1210 | /* | |
4b5f3fe6 | 1211 | * wxPanelTabView |
c801d85f | 1212 | */ |
2b854a32 | 1213 | |
c801d85f | 1214 | IMPLEMENT_CLASS(wxPanelTabView, wxTabView) |
2b854a32 | 1215 | |
c801d85f KB |
1216 | wxPanelTabView::wxPanelTabView(wxPanel *pan, long style): wxTabView(style), m_tabWindows(wxKEY_INTEGER) |
1217 | { | |
1218 | m_panel = pan; | |
c67daf87 | 1219 | m_currentWindow = (wxWindow *) NULL; |
c801d85f KB |
1220 | |
1221 | if (m_panel->IsKindOf(CLASSINFO(wxTabbedDialog))) | |
1222 | ((wxTabbedDialog *)m_panel)->SetTabView(this); | |
1223 | else if (m_panel->IsKindOf(CLASSINFO(wxTabbedPanel))) | |
1224 | ((wxTabbedPanel *)m_panel)->SetTabView(this); | |
1225 | ||
1226 | SetWindow(m_panel); | |
1227 | } | |
1228 | ||
1229 | wxPanelTabView::~wxPanelTabView(void) | |
1230 | { | |
1231 | ClearWindows(TRUE); | |
1232 | } | |
1233 | ||
1234 | // Called when a tab is activated | |
1235 | void wxPanelTabView::OnTabActivate(int activateId, int deactivateId) | |
1236 | { | |
1237 | if (!m_panel) | |
1238 | return; | |
2b854a32 | 1239 | |
c801d85f KB |
1240 | wxWindow *oldWindow = ((deactivateId == -1) ? 0 : GetTabWindow(deactivateId)); |
1241 | wxWindow *newWindow = GetTabWindow(activateId); | |
1242 | ||
1243 | if (oldWindow) | |
1244 | oldWindow->Show(FALSE); | |
1245 | if (newWindow) | |
1246 | newWindow->Show(TRUE); | |
2b854a32 | 1247 | |
c801d85f KB |
1248 | m_panel->Refresh(); |
1249 | } | |
1250 | ||
2b854a32 | 1251 | |
c801d85f KB |
1252 | void wxPanelTabView::AddTabWindow(int id, wxWindow *window) |
1253 | { | |
1254 | m_tabWindows.Append((long)id, window); | |
1255 | window->Show(FALSE); | |
1256 | } | |
1257 | ||
1258 | wxWindow *wxPanelTabView::GetTabWindow(int id) const | |
1259 | { | |
1260 | wxNode *node = m_tabWindows.Find((long)id); | |
1261 | if (!node) | |
c67daf87 | 1262 | return (wxWindow *) NULL; |
1bc822df | 1263 | return (wxWindow *)node->GetData(); |
c801d85f KB |
1264 | } |
1265 | ||
1266 | void wxPanelTabView::ClearWindows(bool deleteWindows) | |
1267 | { | |
1268 | if (deleteWindows) | |
1269 | m_tabWindows.DeleteContents(TRUE); | |
1270 | m_tabWindows.Clear(); | |
1271 | m_tabWindows.DeleteContents(FALSE); | |
1272 | } | |
1273 | ||
1274 | void wxPanelTabView::ShowWindowForTab(int id) | |
1275 | { | |
1276 | wxWindow *newWindow = GetTabWindow(id); | |
1277 | if (newWindow == m_currentWindow) | |
1278 | return; | |
1279 | if (m_currentWindow) | |
1280 | m_currentWindow->Show(FALSE); | |
1281 | newWindow->Show(TRUE); | |
1282 | newWindow->Refresh(); | |
1283 | } | |
1284 | ||
1e6feb95 | 1285 | #endif // wxUSE_TAB_DIALOG |