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