]>
Commit | Line | Data |
---|---|---|
8e08b761 | 1 | ///////////////////////////////////////////////////////////////////////////// |
4cbc57f0 JS |
2 | // Name: dyntbar.cpp |
3 | // Purpose: wxDynamicToolBar implementation | |
8e08b761 JS |
4 | // Author: Aleksandras Gluchovas |
5 | // Modified by: | |
6 | // Created: ??/10/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Aleksandras Gluchovas | |
c82c42d4 | 9 | // Licence: wxWindows license |
8e08b761 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dyntbar.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
8e08b761 JS |
19 | #ifdef __BORLANDC__ |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #include "wx/utils.h" // import wxMin,wxMax macros | |
28 | ||
29 | #include "wx/fl/dyntbar.h" | |
30 | #include "wx/fl/newbmpbtn.h" | |
31 | ||
592cae95 | 32 | IMPLEMENT_DYNAMIC_CLASS( wxDynamicToolBar, wxObject ) |
8e08b761 | 33 | |
349f1d8e | 34 | BEGIN_EVENT_TABLE( wxDynamicToolBar, wxToolBarBase ) |
8e08b761 | 35 | |
4cbc57f0 JS |
36 | EVT_SIZE ( wxDynamicToolBar::OnSize ) |
37 | EVT_PAINT( wxDynamicToolBar::OnPaint ) | |
38 | //EVT_ERASE_BACKGROUND( wxDynamicToolBar::OnEraseBackground ) | |
8e08b761 JS |
39 | |
40 | END_EVENT_TABLE() | |
41 | ||
b2995a23 | 42 | /***** Implementation for class wxToolLayoutItem *****/ |
81eeaed8 | 43 | |
b2995a23 GT |
44 | IMPLEMENT_DYNAMIC_CLASS(wxToolLayoutItem, wxObject) |
45 | ||
46 | ||
8e08b761 | 47 | /***** Implementation for class wxDynToolInfo *****/ |
81eeaed8 | 48 | |
8e08b761 JS |
49 | IMPLEMENT_DYNAMIC_CLASS(wxDynToolInfo, wxToolLayoutItem) |
50 | ||
51 | /***** Implementation for class wxDynamicToolBar *****/ | |
52 | ||
53 | wxDynamicToolBar::wxDynamicToolBar() | |
4cbc57f0 JS |
54 | : mpLayoutMan( NULL ), |
55 | mSepartorSize( 8 ), | |
56 | mVertGap ( 0 ), | |
57 | mHorizGap( 0 ) | |
8e08b761 JS |
58 | { |
59 | } | |
60 | ||
81eeaed8 | 61 | wxDynamicToolBar::wxDynamicToolBar(wxWindow *parent, const wxWindowID id, |
4cbc57f0 JS |
62 | const wxPoint& pos, const wxSize& size, |
63 | const long style, const int orientation, | |
64 | const int RowsOrColumns, const wxString& name ) | |
65 | : mpLayoutMan( NULL ), | |
66 | mSepartorSize( 8 ), | |
67 | mVertGap ( 0 ), | |
68 | mHorizGap( 0 ) | |
8e08b761 | 69 | { |
4cbc57f0 | 70 | Create(parent, id, pos, size, style, orientation, RowsOrColumns, name); |
8e08b761 | 71 | |
4cbc57f0 | 72 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE) ); |
8e08b761 JS |
73 | } |
74 | ||
81eeaed8 WS |
75 | bool wxDynamicToolBar::Create(wxWindow *parent, const wxWindowID id, |
76 | const wxPoint& pos, | |
4cbc57f0 | 77 | const wxSize& size, |
81eeaed8 WS |
78 | const long style, |
79 | const int WXUNUSED(orientation), const int WXUNUSED(RowsOrColumns), | |
4cbc57f0 | 80 | const wxString& name) |
8e08b761 | 81 | { |
4cbc57f0 | 82 | // cut&pasted from wxtbatsmpl.h |
8e08b761 | 83 | |
4cbc57f0 | 84 | if ( ! wxWindow::Create(parent, id, pos, size, style, name) ) |
c82c42d4 | 85 | return false; |
8e08b761 | 86 | |
4cbc57f0 | 87 | SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); |
8e08b761 | 88 | |
c82c42d4 | 89 | return true; |
8e08b761 JS |
90 | } |
91 | ||
92 | bool wxDynamicToolBar::Realize(void) | |
93 | { | |
4cbc57f0 | 94 | // FOR NOW:: nothing |
c82c42d4 | 95 | return true; |
8e08b761 JS |
96 | } |
97 | ||
98 | wxDynamicToolBar::~wxDynamicToolBar(void) | |
99 | { | |
4cbc57f0 | 100 | if ( mpLayoutMan ) |
8e08b761 JS |
101 | delete mpLayoutMan; |
102 | ||
103 | size_t i; | |
4cbc57f0 | 104 | for( i = 0; i != mTools.Count(); ++i ) |
8e08b761 | 105 | { |
4cbc57f0 | 106 | delete mTools[i]; |
8e08b761 JS |
107 | } |
108 | } | |
109 | ||
81eeaed8 WS |
110 | void wxDynamicToolBar::AddTool( int toolIndex, |
111 | wxWindow* pToolWindow, | |
196be0f1 | 112 | const wxSize& WXUNUSED(size) |
4cbc57f0 | 113 | ) |
8e08b761 | 114 | { |
4cbc57f0 | 115 | wxDynToolInfo* pInfo = new wxDynToolInfo(); |
8e08b761 | 116 | |
4cbc57f0 JS |
117 | pInfo->mpToolWnd = pToolWindow; |
118 | pInfo->mIndex = toolIndex; | |
c82c42d4 | 119 | pInfo->mIsSeparator = false; |
8e08b761 | 120 | |
4cbc57f0 JS |
121 | int x,y; |
122 | pToolWindow->GetSize( &x, &y ); | |
123 | pInfo->mRealSize.x = x; | |
124 | pInfo->mRealSize.y = y; | |
125 | pInfo->mRect.width = x; | |
126 | pInfo->mRect.height = y; | |
8e08b761 | 127 | |
4cbc57f0 | 128 | mTools.Add( pInfo ); |
8e08b761 JS |
129 | } |
130 | ||
81eeaed8 | 131 | void wxDynamicToolBar::AddTool( int toolIndex, |
8252c9ca | 132 | const wxString& imageFileName, |
81eeaed8 | 133 | wxBitmapType imageFileType, |
8252c9ca GD |
134 | const wxString& labelText, bool alignTextRight, |
135 | bool isFlat ) | |
8e08b761 | 136 | { |
4cbc57f0 | 137 | wxNewBitmapButton* pBtn = |
8e08b761 | 138 | |
4cbc57f0 | 139 | new wxNewBitmapButton( imageFileName, imageFileType, |
81eeaed8 WS |
140 | labelText, |
141 | ( alignTextRight ) | |
142 | ? NB_ALIGN_TEXT_RIGHT | |
4cbc57f0 JS |
143 | : NB_ALIGN_TEXT_BOTTOM, |
144 | isFlat | |
145 | ); | |
8e08b761 | 146 | |
4cbc57f0 | 147 | pBtn->Create( this, toolIndex ); |
8e08b761 | 148 | |
4cbc57f0 | 149 | pBtn->Reshape(); |
81eeaed8 | 150 | |
4cbc57f0 | 151 | AddTool( toolIndex, pBtn ); |
8e08b761 JS |
152 | } |
153 | void wxDynamicToolBar::AddTool( int toolIndex, wxBitmap labelBmp, | |
4cbc57f0 JS |
154 | const wxString& labelText, bool alignTextRight, |
155 | bool isFlat ) | |
8e08b761 | 156 | { |
4cbc57f0 | 157 | wxNewBitmapButton* pBtn = |
8e08b761 | 158 | |
4cbc57f0 | 159 | new wxNewBitmapButton( labelBmp, |
81eeaed8 WS |
160 | labelText, |
161 | ( alignTextRight ) | |
162 | ? NB_ALIGN_TEXT_RIGHT | |
4cbc57f0 JS |
163 | : NB_ALIGN_TEXT_BOTTOM, |
164 | isFlat | |
165 | ); | |
8e08b761 | 166 | |
4cbc57f0 | 167 | pBtn->Create( this, toolIndex ); |
8e08b761 | 168 | |
4cbc57f0 | 169 | pBtn->Reshape(); |
81eeaed8 | 170 | |
4cbc57f0 | 171 | AddTool( toolIndex, pBtn ); |
8e08b761 JS |
172 | } |
173 | ||
174 | ||
81eeaed8 WS |
175 | wxToolBarToolBase* |
176 | wxDynamicToolBar::AddTool(const int toolIndex, const wxBitmap& bitmap, | |
196be0f1 | 177 | const wxBitmap& WXUNUSED(pushedBitmap), |
81eeaed8 | 178 | const bool WXUNUSED(toggle), const long WXUNUSED(xPos), |
196be0f1 JS |
179 | const long WXUNUSED(yPos), wxObject *WXUNUSED(clientData), |
180 | const wxString& helpString1, const wxString& WXUNUSED(helpString2)) | |
8e08b761 | 181 | { |
4cbc57f0 | 182 | wxNewBitmapButton* pBmpBtn = new wxNewBitmapButton( bitmap ); |
8e08b761 | 183 | |
4cbc57f0 | 184 | pBmpBtn->Create( this, toolIndex ); |
8e08b761 | 185 | |
4cbc57f0 | 186 | pBmpBtn->Reshape(); |
8e08b761 | 187 | |
45da7759 JS |
188 | #if wxUSE_TOOLTIPS |
189 | pBmpBtn->SetToolTip( helpString1 ); | |
81eeaed8 WS |
190 | #else |
191 | wxUnusedVar( helpString1 ); | |
45da7759 JS |
192 | #endif // wxUSE_TOOLTIPS |
193 | ||
4cbc57f0 | 194 | AddTool( toolIndex, pBmpBtn ); |
8e08b761 | 195 | |
4cbc57f0 | 196 | return NULL; |
8e08b761 JS |
197 | } |
198 | ||
199 | ||
200 | wxDynToolInfo* wxDynamicToolBar::GetToolInfo( int toolIndex ) | |
201 | { | |
202 | size_t i; | |
4cbc57f0 | 203 | for( i = 0; i != mTools.Count(); ++i ) |
8e08b761 | 204 | { |
4cbc57f0 | 205 | if ( mTools[i]->mIndex == toolIndex ) |
8e08b761 JS |
206 | return mTools[i]; |
207 | } | |
208 | ||
4cbc57f0 | 209 | return NULL; |
8e08b761 JS |
210 | } |
211 | ||
212 | void wxDynamicToolBar::RemveTool( int toolIndex ) | |
213 | { | |
214 | size_t i; | |
4cbc57f0 | 215 | for( i = 0; i != mTools.Count(); ++i ) |
8e08b761 | 216 | { |
81eeaed8 | 217 | if ( mTools[i]->mIndex == toolIndex ) |
4cbc57f0 JS |
218 | { |
219 | if ( mTools[i]->mpToolWnd ) | |
220 | { | |
221 | mTools[i]->mpToolWnd->Destroy(); | |
222 | } | |
8e08b761 JS |
223 | delete mTools[i]; // HVL To be tested!!! |
224 | #if wxCHECK_VERSION(2,3,2) | |
4cbc57f0 | 225 | mTools.RemoveAt(i); |
8e08b761 | 226 | #else |
4cbc57f0 | 227 | mTools.Remove(i); |
8e08b761 | 228 | #endif |
4cbc57f0 | 229 | Layout(); |
8e08b761 | 230 | |
4cbc57f0 JS |
231 | return; |
232 | } | |
8e08b761 | 233 | } |
4cbc57f0 | 234 | // TODO:: if not found, should it be an assertion? |
8e08b761 JS |
235 | } |
236 | ||
237 | void wxDynamicToolBar::AddSeparator( wxWindow* pSepartorWnd ) | |
238 | { | |
4cbc57f0 JS |
239 | wxDynToolInfo* pInfo = new wxDynToolInfo(); |
240 | ||
241 | pInfo->mpToolWnd = pSepartorWnd; | |
242 | pInfo->mIndex = -1; | |
c82c42d4 | 243 | pInfo->mIsSeparator = true; |
4cbc57f0 | 244 | |
ba09d3bb | 245 | // Do we draw a separator or is a other object? |
4cbc57f0 JS |
246 | if ( pSepartorWnd ) |
247 | { | |
ba09d3bb JS |
248 | // hvl => Is there a way to know if it was already created? |
249 | // hvl => shouldn't the pSepartorWnd be created? (like one should expect?) | |
250 | // pSepartorWnd->Create( this, -1 ); | |
4cbc57f0 JS |
251 | |
252 | int x,y; | |
253 | pSepartorWnd->GetSize( &x, &y ); | |
254 | pInfo->mRealSize.x = x; | |
255 | pInfo->mRealSize.y = y; | |
256 | ||
257 | pInfo->mRect.width = x; | |
258 | pInfo->mRect.height = y; | |
259 | } | |
260 | else | |
261 | { | |
ba09d3bb JS |
262 | // Init x and y to the default. |
263 | pInfo->mRealSize.x = 0; | |
4cbc57f0 JS |
264 | pInfo->mRealSize.y = 0; |
265 | ||
ba09d3bb | 266 | // Init height and width to the normal size of a separator. |
4cbc57f0 | 267 | pInfo->mRect.width = mSepartorSize; |
ba09d3bb | 268 | pInfo->mRect.height = mSepartorSize; |
4cbc57f0 JS |
269 | } |
270 | ||
271 | mTools.Add( pInfo ); | |
8e08b761 JS |
272 | } |
273 | ||
196be0f1 | 274 | void wxDynamicToolBar::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) |
8e08b761 | 275 | { |
4cbc57f0 | 276 | // FOR NOW:: nothing |
8e08b761 JS |
277 | } |
278 | ||
196be0f1 | 279 | void wxDynamicToolBar::OnSize( wxSizeEvent& WXUNUSED(event) ) |
8e08b761 | 280 | { |
4cbc57f0 | 281 | //SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ); |
8e08b761 | 282 | |
4cbc57f0 | 283 | Layout(); |
8e08b761 JS |
284 | } |
285 | ||
286 | void wxDynamicToolBar::DrawSeparator( wxDynToolInfo& info, wxDC& dc ) | |
287 | { | |
4cbc57f0 JS |
288 | // check the orientation of separator |
289 | if ( info.mRect.width < info.mRect.height ) | |
290 | { | |
291 | int midX = info.mRect.x + info.mRect.width/2 - 1; | |
292 | ||
293 | dc.SetPen( *wxGREY_PEN ); | |
294 | dc.DrawLine( midX, info.mRect.y, | |
295 | midX, info.mRect.y + info.mRect.height+1 ); | |
296 | ||
297 | dc.SetPen( *wxWHITE_PEN ); | |
298 | dc.DrawLine( midX+1, info.mRect.y, | |
299 | midX+1, info.mRect.y + info.mRect.height+1 ); | |
300 | } | |
301 | else | |
302 | { | |
303 | int midY = info.mRect.y + info.mRect.height/2 - 1; | |
304 | ||
305 | dc.SetPen( *wxGREY_PEN ); | |
306 | dc.DrawLine( info.mRect.x, midY, | |
307 | info.mRect.x + info.mRect.width+1, midY ); | |
308 | ||
309 | dc.SetPen( *wxWHITE_PEN ); | |
310 | dc.DrawLine( info.mRect.x, midY + 1, | |
311 | info.mRect.x + info.mRect.width+1, midY + 1 ); | |
312 | } | |
8e08b761 JS |
313 | } |
314 | ||
196be0f1 | 315 | void wxDynamicToolBar::OnPaint( wxPaintEvent& WXUNUSED(event) ) |
8e08b761 | 316 | { |
4cbc57f0 | 317 | // draw separators if any |
4cbc57f0 | 318 | wxPaintDC dc(this); |
8e08b761 JS |
319 | |
320 | size_t i; | |
4cbc57f0 | 321 | for( i = 0; i != mTools.Count(); ++i ) |
ba09d3bb | 322 | { |
81eeaed8 | 323 | if ( mTools[i]->mIsSeparator ) |
4cbc57f0 JS |
324 | { |
325 | // check if separator doesn't have it's own window | |
326 | // if so, then draw it using built-in drawing method | |
4cbc57f0 | 327 | if ( !mTools[i]->mpToolWnd ) |
4cbc57f0 JS |
328 | DrawSeparator( *mTools[i], dc ); |
329 | } | |
ba09d3bb | 330 | } |
8e08b761 JS |
331 | } |
332 | ||
333 | // FOR NOW:: quick fix | |
334 | #include "wx/choice.h" | |
335 | ||
336 | void wxDynamicToolBar::SizeToolWindows() | |
337 | { | |
c82c42d4 WS |
338 | bool bStateCheckDone = false; |
339 | bool bHorzSeparator = false; | |
ba09d3bb JS |
340 | int maxWidth = 0; |
341 | int maxHeight = 0; | |
342 | ||
8e08b761 | 343 | size_t i; |
4cbc57f0 JS |
344 | for( i = 0; i != mTools.Count(); ++i ) |
345 | { | |
346 | wxDynToolInfo& info = *mTools[i]; | |
347 | ||
81eeaed8 | 348 | if ( !info.mIsSeparator ) |
4cbc57f0 | 349 | { |
81eeaed8 | 350 | // center real rectangle within the rectangle |
4cbc57f0 JS |
351 | // provided by the layout manager |
352 | ||
353 | int x = info.mRect.x; | |
354 | int y = info.mRect.y + (info.mRect.height - info.mRealSize.y)/2; | |
355 | ||
356 | // FOR NOW FOR NOW:: quick & dirty fix | |
357 | if ( info.mpToolWnd->IsKindOf( CLASSINFO( wxChoice ) ) ) | |
358 | { | |
81eeaed8 WS |
359 | info.mpToolWnd->SetSize( x, y, |
360 | info.mRealSize.x - 3, | |
ba09d3bb | 361 | info.mRealSize.y); |
4cbc57f0 JS |
362 | } |
363 | else | |
ba09d3bb | 364 | { |
81eeaed8 WS |
365 | info.mpToolWnd->SetSize( x, y, |
366 | info.mRealSize.x, | |
ba09d3bb JS |
367 | info.mRealSize.y ); |
368 | } | |
4cbc57f0 | 369 | } |
ba09d3bb JS |
370 | else |
371 | { | |
81eeaed8 | 372 | // We performer this code here, so we only execute it when we have |
ba09d3bb JS |
373 | // separators and we do it only once (all to do with performance...) |
374 | if (!bStateCheckDone) | |
375 | { | |
c82c42d4 | 376 | bStateCheckDone = true; |
81eeaed8 | 377 | |
ba09d3bb | 378 | size_t j; |
8552e6f0 | 379 | wxDynToolInfo *pInfo; |
ba09d3bb JS |
380 | wxDynToolInfo *pPrevInfo = NULL; |
381 | int nVertSeparators = 0; | |
382 | ||
383 | for( j = 0; j != mTools.Count(); ++j ) | |
384 | { | |
385 | pInfo = mTools[j]; | |
81eeaed8 | 386 | |
ba09d3bb | 387 | // Count all Vert Separators. |
81eeaed8 | 388 | if ( pInfo->mIsSeparator ) |
ba09d3bb JS |
389 | nVertSeparators++; |
390 | ||
391 | // Check if the new row starts with a Separator. | |
392 | if ( pPrevInfo && pInfo->mIsSeparator && | |
393 | // pPrevInfo->mRect.x >= pInfo->mRect.x && | |
394 | pPrevInfo->mRect.y < pInfo->mRect.y) | |
395 | { | |
81eeaed8 WS |
396 | // If the Separator is shown on the next row and it's |
397 | // the only object on the row it would mean that the | |
ba09d3bb JS |
398 | // Separator should be shown as Horizontal one. |
399 | if (j+1 != mTools.Count()) | |
400 | { | |
401 | if (pInfo->mRect.y < mTools[j+1]->mRect.y) | |
402 | nVertSeparators--; | |
403 | } | |
404 | else | |
405 | { | |
406 | nVertSeparators--; | |
407 | } | |
408 | } | |
409 | ||
410 | pPrevInfo = pInfo; | |
411 | ||
412 | maxWidth = wxMax(pInfo->mRect.width, maxWidth); | |
413 | maxHeight = wxMax(pInfo->mRect.height, maxHeight); | |
414 | } | |
81eeaed8 | 415 | |
ba09d3bb JS |
416 | bHorzSeparator = nVertSeparators == 0; |
417 | } | |
81eeaed8 | 418 | |
ba09d3bb JS |
419 | // Check if we should draw Horz or Vert... |
420 | if ( !bHorzSeparator ) | |
421 | { | |
422 | info.mRect.width = mSepartorSize; | |
423 | info.mRect.height = maxHeight; | |
424 | } | |
425 | else | |
426 | { | |
427 | info.mRect.width = maxWidth; | |
428 | info.mRect.height = mSepartorSize; | |
429 | } | |
4cbc57f0 | 430 | |
3103e8a9 | 431 | // Do we need to set a new size to a separator object? |
ba09d3bb JS |
432 | if ( info.mpToolWnd ) |
433 | { | |
434 | info.mpToolWnd->SetSize( info.mRect.x, | |
81eeaed8 WS |
435 | info.mRect.y, |
436 | info.mRect.width, | |
ba09d3bb JS |
437 | info.mRect.height); |
438 | } | |
439 | ||
440 | } | |
4cbc57f0 | 441 | } |
8e08b761 JS |
442 | } |
443 | ||
444 | bool wxDynamicToolBar::Layout() | |
445 | { | |
4cbc57f0 JS |
446 | int x,y; |
447 | GetSize( &x, &y ); | |
448 | wxSize wndDim(x,y); | |
449 | wxSize result; | |
8e08b761 | 450 | size_t i; |
ba09d3bb JS |
451 | wxDynToolInfo *pInfo; |
452 | ||
453 | // Reset the size of separators... | |
4cbc57f0 | 454 | for( i = 0; i != mTools.Count(); ++i ) |
ba09d3bb JS |
455 | { |
456 | pInfo = mTools[i]; | |
81eeaed8 WS |
457 | |
458 | if ( pInfo->mIsSeparator ) | |
ba09d3bb JS |
459 | { |
460 | pInfo->mRect.width = mSepartorSize; | |
461 | pInfo->mRect.height = mSepartorSize; | |
462 | } | |
463 | } | |
8e08b761 | 464 | |
ba09d3bb JS |
465 | // Calc and set the best layout |
466 | GetPreferredDim( wndDim, result ); | |
8e08b761 | 467 | |
4cbc57f0 | 468 | SizeToolWindows(); |
c82c42d4 | 469 | return true; |
8e08b761 JS |
470 | } |
471 | ||
472 | void wxDynamicToolBar::GetPreferredDim( const wxSize& givenDim, wxSize& prefDim ) | |
473 | { | |
4cbc57f0 JS |
474 | if ( !mpLayoutMan ) |
475 | mpLayoutMan = CreateDefaultLayout(); | |
8e08b761 | 476 | |
4cbc57f0 | 477 | wxLayoutItemArrayT items; |
8e08b761 | 478 | |
4cbc57f0 | 479 | // safe conversion |
8e08b761 | 480 | size_t i; |
4cbc57f0 | 481 | for( i = 0; i != mTools.Count(); ++i ) |
8e08b761 JS |
482 | items.Add( mTools[i] ); |
483 | ||
ba09d3bb | 484 | mpLayoutMan->Layout( givenDim, prefDim, items, mVertGap, mHorizGap ); |
8e08b761 JS |
485 | } |
486 | ||
487 | void wxDynamicToolBar::SetLayout( LayoutManagerBase* pLayout ) | |
488 | { | |
4cbc57f0 | 489 | if ( mpLayoutMan ) |
8e08b761 JS |
490 | delete mpLayoutMan; |
491 | ||
4cbc57f0 | 492 | mpLayoutMan = pLayout; |
8e08b761 | 493 | |
4cbc57f0 | 494 | Layout(); |
8e08b761 JS |
495 | } |
496 | ||
083f7497 | 497 | void wxDynamicToolBar::EnableTool(int toolIndex, bool enable ) |
8e08b761 | 498 | { |
4cbc57f0 | 499 | wxDynToolInfo* pInfo = GetToolInfo( toolIndex ); |
8e08b761 | 500 | |
4cbc57f0 | 501 | if ( !pInfo ) |
8e08b761 JS |
502 | return; |
503 | ||
4cbc57f0 | 504 | if ( pInfo->mIsSeparator || !pInfo->mpToolWnd ) |
8e08b761 JS |
505 | return; |
506 | ||
4cbc57f0 | 507 | pInfo->mpToolWnd->Enable( enable ); |
8e08b761 JS |
508 | } |
509 | ||
510 | /***** Implementation for class BagLayout *****/ | |
511 | ||
81eeaed8 | 512 | void BagLayout::Layout( const wxSize& parentDim, |
4cbc57f0 JS |
513 | wxSize& resultingDim, |
514 | wxLayoutItemArrayT& items, | |
515 | int horizGap, | |
81eeaed8 | 516 | int vertGap |
4cbc57f0 | 517 | ) |
8e08b761 | 518 | { |
4cbc57f0 JS |
519 | int maxWidth = 0; |
520 | int curY = 0; | |
521 | int nRows = 0; | |
8e08b761 | 522 | |
4cbc57f0 | 523 | size_t i = 0; |
8e08b761 | 524 | |
4cbc57f0 JS |
525 | while( i < items.Count() ) |
526 | { | |
527 | int curX = 0; | |
528 | int height = 0; | |
529 | // int nItems = 0; | |
8e08b761 | 530 | |
4cbc57f0 JS |
531 | // int firstItem = i; |
532 | int itemsInRow = 0; | |
8e08b761 | 533 | |
4cbc57f0 | 534 | if ( nRows > 0 ) |
8e08b761 JS |
535 | curY += vertGap; |
536 | ||
4cbc57f0 | 537 | // step #1 - arrange horizontal positions of items in the row |
8e08b761 | 538 | |
4cbc57f0 JS |
539 | do |
540 | { | |
541 | if ( itemsInRow > 0 ) | |
8e08b761 JS |
542 | curX += horizGap; |
543 | ||
4cbc57f0 | 544 | wxRect& r = items[i]->mRect; |
8e08b761 | 545 | |
4cbc57f0 | 546 | if ( curX + r.width > parentDim.x ) |
8e08b761 | 547 | { |
81eeaed8 | 548 | if ( itemsInRow > 0 ) |
8e08b761 JS |
549 | break; |
550 | } | |
4cbc57f0 JS |
551 | r.x = curX; |
552 | r.y = curY; | |
8e08b761 | 553 | |
4cbc57f0 | 554 | curX += r.width; |
8e08b761 | 555 | |
4cbc57f0 | 556 | height = wxMax( height, r.height ); |
8e08b761 | 557 | |
4cbc57f0 JS |
558 | ++itemsInRow; |
559 | ++i; | |
8e08b761 | 560 | |
4cbc57f0 | 561 | } while( i < items.Count() ); |
8e08b761 | 562 | |
4cbc57f0 | 563 | curY += height; |
8e08b761 | 564 | |
4cbc57f0 JS |
565 | maxWidth = wxMax( maxWidth, curX ); |
566 | } | |
8e08b761 | 567 | |
4cbc57f0 JS |
568 | resultingDim.x = maxWidth; |
569 | resultingDim.y = curY; | |
8e08b761 JS |
570 | } |
571 | ||
572 | //////// stuff from 2.1.15 /////////// | |
573 | ||
196be0f1 | 574 | wxToolBarToolBase* wxDynamicToolBar::FindToolForPosition( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) ) const |
8e08b761 | 575 | { |
4cbc57f0 | 576 | return NULL; |
8e08b761 JS |
577 | } |
578 | ||
196be0f1 | 579 | bool wxDynamicToolBar::DoInsertTool( size_t WXUNUSED(pos), wxToolBarToolBase* WXUNUSED(tool) ) |
8e08b761 | 580 | { |
c82c42d4 | 581 | return true; |
8e08b761 JS |
582 | } |
583 | ||
196be0f1 | 584 | bool wxDynamicToolBar::DoDeleteTool( size_t WXUNUSED(pos), wxToolBarToolBase* WXUNUSED(tool) ) |
8e08b761 | 585 | { |
c82c42d4 | 586 | return true; |
8e08b761 JS |
587 | } |
588 | ||
196be0f1 | 589 | void wxDynamicToolBar::DoEnableTool( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(enable) ) |
8e08b761 JS |
590 | { |
591 | } | |
592 | ||
196be0f1 | 593 | void wxDynamicToolBar::DoToggleTool( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(toggle) ) |
8e08b761 JS |
594 | { |
595 | } | |
596 | ||
196be0f1 | 597 | void wxDynamicToolBar::DoSetToggle( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(toggle) ) |
8e08b761 JS |
598 | { |
599 | } | |
600 | ||
81eeaed8 WS |
601 | wxToolBarToolBase* wxDynamicToolBar::CreateTool( int WXUNUSED(id), |
602 | const wxString& WXUNUSED(label), | |
603 | const wxBitmap& WXUNUSED(bmpNormal), | |
604 | const wxBitmap& WXUNUSED(bmpDisabled), | |
605 | wxItemKind WXUNUSED(kind), | |
606 | wxObject *WXUNUSED(clientData), | |
607 | const wxString& WXUNUSED(shortHelp), | |
196be0f1 JS |
608 | const wxString& WXUNUSED(longHelp) |
609 | ) | |
8e08b761 | 610 | { |
4cbc57f0 | 611 | return NULL; |
8e08b761 JS |
612 | } |
613 | ||
196be0f1 | 614 | wxToolBarToolBase* wxDynamicToolBar::CreateTool( wxControl* WXUNUSED(control) ) |
8e08b761 | 615 | { |
4cbc57f0 | 616 | return NULL; |
8e08b761 JS |
617 | } |
618 |