Mercurial > projects > dwt-addons
annotate dwtx/jface/action/ToolBarContributionItem.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | ea8ff534f622 |
children | 04b47443bb01 |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
90 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
25 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
14 module dwtx.jface.action.ToolBarContributionItem; | |
15 | |
16 import dwtx.jface.action.IContributionItem; | |
17 import dwtx.jface.action.ContributionItem; | |
18 import dwtx.jface.action.MenuManager; | |
19 import dwtx.jface.action.IToolBarManager; | |
20 import dwtx.jface.action.ToolBarManager; | |
21 import dwtx.jface.action.ActionContributionItem; | |
22 import dwtx.jface.action.SubContributionItem; | |
23 import dwtx.jface.action.ICoolBarManager; | |
24 import dwtx.jface.action.Separator; | |
25 import dwtx.jface.action.IContributionManager; | |
26 | |
27 import tango.util.collection.ArraySeq; | |
28 // import java.util.Iterator; | |
29 | |
30 import dwt.DWT; | |
31 import dwt.events.DisposeEvent; | |
32 import dwt.events.DisposeListener; | |
33 import dwt.events.SelectionAdapter; | |
34 import dwt.events.SelectionEvent; | |
35 import dwt.graphics.Point; | |
36 import dwt.graphics.Rectangle; | |
37 import dwt.widgets.Control; | |
38 import dwt.widgets.CoolBar; | |
39 import dwt.widgets.CoolItem; | |
40 import dwt.widgets.Event; | |
41 import dwt.widgets.Listener; | |
42 import dwt.widgets.Menu; | |
43 import dwt.widgets.ToolBar; | |
44 import dwt.widgets.ToolItem; | |
45 import dwtx.core.runtime.Assert; | |
46 import dwtx.jface.internal.provisional.action.IToolBarContributionItem; | |
47 import dwtx.jface.util.Policy; | |
48 | |
49 import dwt.dwthelper.utils; | |
50 import tango.io.Stdout; | |
51 | |
52 /** | |
53 * The <code>ToolBarContributionItem</code> class provides a wrapper for tool | |
54 * bar managers when used in cool bar managers. It extends <code>ContributionItem</code> | |
55 * but and provides some additional methods to customize the size of the cool | |
56 * item and to retrieve the underlying tool bar manager. | |
57 * <p> | |
58 * This class may be instantiated; it is not intended to be subclassed. | |
59 * </p> | |
60 * | |
61 * @since 3.0 | |
90 | 62 * @noextend This class is not intended to be subclassed by clients. |
25 | 63 */ |
64 public class ToolBarContributionItem : ContributionItem, IToolBarContributionItem { | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
65 alias ContributionItem.fill fill; |
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
66 alias ContributionItem.update update; |
25 | 67 |
68 public IContributionManager getParent() { | |
69 return super.getParent(); | |
70 } | |
71 | |
72 /** | |
73 * A constant used by <code>setMinimumItemsToShow</code> and <code>getMinimumItemsToShow</code> | |
74 * to indicate that all tool items should be shown in the cool item. | |
75 */ | |
76 public static const int SHOW_ALL_ITEMS = -1; | |
77 | |
78 /** | |
79 * The pull down menu used to list all hidden tool items if the current | |
80 * size is less than the preffered size. | |
81 */ | |
82 private MenuManager chevronMenuManager = null; | |
83 | |
84 /** | |
85 * The widget created for this item; <code>null</code> before creation | |
86 * and after disposal. | |
87 */ | |
88 private CoolItem coolItem = null; | |
89 | |
90 /** | |
91 * Current height of cool item | |
92 */ | |
93 private int currentHeight = -1; | |
94 | |
95 /** | |
96 * Current width of cool item. | |
97 */ | |
98 private int currentWidth = -1; | |
99 | |
100 /** | |
101 * A flag indicating that this item has been disposed. This prevents future | |
102 * method invocations from doing things they shouldn't. | |
103 */ | |
104 private bool disposed = false; | |
105 | |
106 /** | |
107 * Mininum number of tool items to show in the cool item widget. | |
108 */ | |
109 private int minimumItemsToShow = SHOW_ALL_ITEMS; | |
110 | |
111 /** | |
112 * The tool bar manager used to manage the tool items contained in the cool | |
113 * item widget. | |
114 */ | |
115 private ToolBarManager toolBarManager = null; | |
116 | |
117 /** | |
118 * Enable/disable chevron support. | |
119 */ | |
120 private bool useChevron = true; | |
121 | |
122 /** | |
123 * Convenience method equivalent to <code>ToolBarContributionItem(new ToolBarManager(), null)</code>. | |
124 */ | |
125 public this() { | |
126 this(new ToolBarManager(), null); | |
127 } | |
128 | |
129 /** | |
130 * Convenience method equivalent to <code>ToolBarContributionItem(toolBarManager, null)</code>. | |
131 * | |
132 * @param toolBarManager | |
133 * the tool bar manager | |
134 */ | |
135 public this(IToolBarManager toolBarManager) { | |
136 this(toolBarManager, null); | |
137 } | |
138 | |
139 /** | |
140 * Creates a tool bar contribution item. | |
141 * | |
142 * @param toolBarManager | |
143 * the tool bar manager to wrap | |
144 * @param id | |
145 * the contribution item id, or <code>null</code> if none | |
146 */ | |
147 public this(IToolBarManager toolBarManager, String id) { | |
148 super(id); | |
149 Assert.isTrue( null !is cast(ToolBarManager)toolBarManager ); | |
150 this.toolBarManager = cast(ToolBarManager) toolBarManager; | |
151 } | |
152 | |
153 /** | |
154 * Checks whether this contribution item has been disposed. If it has, and | |
155 * the tracing options are active, then it prints some debugging | |
156 * information. | |
157 * | |
158 * @return <code>true</code> if the item is disposed; <code>false</code> | |
159 * otherwise. | |
160 * | |
161 */ | |
162 private final bool checkDisposed() { | |
163 if (disposed) { | |
164 if (Policy.TRACE_TOOLBAR) { | |
165 Stdout.formatln("Method invocation on a disposed tool bar contribution item."); //$NON-NLS-1$ | |
166 ExceptionPrintStackTrace( new Exception(null), Stdout ); | |
167 } | |
168 | |
169 return true; | |
170 } | |
171 | |
172 return false; | |
173 } | |
174 | |
175 /* | |
176 * (non-Javadoc) | |
177 * | |
178 * @see dwtx.jface.action.IContributionItem#dispose() | |
179 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
180 public override void dispose() { |
25 | 181 // Dispose of the ToolBar and all its contributions |
182 if (toolBarManager !is null) { | |
183 toolBarManager.dispose(); | |
184 toolBarManager = null; | |
185 } | |
186 | |
187 /* | |
188 * We need to dispose the cool item or we might be left holding a cool | |
189 * item with a disposed control. | |
190 */ | |
191 if ((coolItem !is null) && (!coolItem.isDisposed())) { | |
192 coolItem.dispose(); | |
193 coolItem = null; | |
194 } | |
195 | |
196 // Mark this item as disposed. | |
197 disposed = true; | |
198 } | |
199 | |
200 /* | |
201 * (non-Javadoc) | |
202 * | |
203 * @see dwtx.jface.action.IContributionItem#fill(dwt.widgets.CoolBar, | |
204 * int) | |
205 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
206 public override void fill(CoolBar coolBar, int index) { |
25 | 207 if (checkDisposed()) { |
208 return; | |
209 } | |
210 | |
211 if (coolItem is null && coolBar !is null) { | |
212 ToolBar oldToolBar = toolBarManager.getControl(); | |
213 ToolBar toolBar = toolBarManager.createControl(coolBar); | |
214 if ((oldToolBar !is null) && (oldToolBar.opEquals(toolBar))) { | |
215 // We are using an old tool bar, so we need to update. | |
216 toolBarManager.update(true); | |
217 } | |
218 | |
219 // Do not create a coolItem if the toolbar is empty | |
220 if (toolBar.getItemCount() < 1) { | |
221 return; | |
222 } | |
223 int flags = DWT.DROP_DOWN; | |
224 if (index >= 0) { | |
225 coolItem = new CoolItem(coolBar, flags, index); | |
226 } else { | |
227 coolItem = new CoolItem(coolBar, flags); | |
228 } | |
229 // sets the back reference | |
230 coolItem.setData(this); | |
231 // Add the toolbar to the CoolItem widget | |
232 coolItem.setControl(toolBar); | |
233 | |
234 // Handle Context Menu | |
235 // ToolBarManager.createControl can actually return a pre-existing control. | |
236 // Only add the listener if the toolbar was newly created (bug 62097). | |
237 if (oldToolBar !is toolBar) { | |
238 toolBar.addListener(DWT.MenuDetect, new class Listener { | |
239 | |
240 public void handleEvent(Event event) { | |
241 // if the toolbar does not have its own context menu then | |
242 // handle the event | |
243 if (toolBarManager.getContextMenuManager() is null) { | |
244 handleContextMenu(event); | |
245 } | |
246 } | |
247 }); | |
248 } | |
249 | |
250 // Handle for chevron clicking | |
251 if (getUseChevron()) { | |
252 // Chevron Support | |
253 coolItem.addSelectionListener(new class SelectionAdapter { | |
254 | |
255 public void widgetSelected(SelectionEvent event) { | |
256 if (event.detail is DWT.ARROW) { | |
257 handleChevron(event); | |
258 } | |
259 } | |
260 }); | |
261 } | |
262 | |
263 // Handle for disposal | |
264 coolItem.addDisposeListener(new class DisposeListener { | |
265 | |
266 public void widgetDisposed(DisposeEvent event) { | |
267 handleWidgetDispose(event); | |
268 } | |
269 }); | |
270 | |
271 // Sets the size of the coolItem | |
272 updateSize(true); | |
273 } | |
274 } | |
275 | |
276 /** | |
277 * Returns a consistent set of wrap indices. The return value will always | |
278 * include at least one entry and the first entry will always be zero. | |
279 * CoolBar.getWrapIndices() is inconsistent in whether or not it returns an | |
280 * index for the first row. | |
281 */ | |
282 private int[] getAdjustedWrapIndices(int[] wraps) { | |
283 int[] adjustedWrapIndices; | |
284 if (wraps.length is 0) { | |
285 adjustedWrapIndices = [ 0 ]; | |
286 } else { | |
287 if (wraps[0] !is 0) { | |
288 adjustedWrapIndices = new int[wraps.length + 1]; | |
289 adjustedWrapIndices[0] = 0; | |
290 for (int i = 0; i < wraps.length; i++) { | |
291 adjustedWrapIndices[i + 1] = wraps[i]; | |
292 } | |
293 } else { | |
294 adjustedWrapIndices = wraps; | |
295 } | |
296 } | |
297 return adjustedWrapIndices; | |
298 } | |
299 | |
300 /** | |
301 * Returns the current height of the corresponding cool item. | |
302 * | |
303 * @return the current height | |
304 */ | |
305 public int getCurrentHeight() { | |
306 if (checkDisposed()) { | |
307 return -1; | |
308 } | |
309 return currentHeight; | |
310 } | |
311 | |
312 /** | |
313 * Returns the current width of the corresponding cool item. | |
314 * | |
315 * @return the current size | |
316 */ | |
317 public int getCurrentWidth() { | |
318 if (checkDisposed()) { | |
319 return -1; | |
320 } | |
321 return currentWidth; | |
322 } | |
323 | |
324 /** | |
325 * Returns the minimum number of tool items to show in the cool item. | |
326 * | |
327 * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code> | |
328 * if a value was not set | |
329 * @see #setMinimumItemsToShow(int) | |
330 */ | |
331 public int getMinimumItemsToShow() { | |
332 if (checkDisposed()) { | |
333 return -1; | |
334 } | |
335 return minimumItemsToShow; | |
336 } | |
337 | |
338 /** | |
339 * Returns the internal tool bar manager of the contribution item. | |
340 * | |
341 * @return the tool bar manager, or <code>null</code> if one is not | |
342 * defined. | |
343 * @see IToolBarManager | |
344 */ | |
345 public IToolBarManager getToolBarManager() { | |
346 if (checkDisposed()) { | |
347 return null; | |
348 } | |
349 return toolBarManager; | |
350 } | |
351 | |
352 /** | |
353 * Returns whether chevron support is enabled. | |
354 * | |
355 * @return <code>true</code> if chevron support is enabled, <code>false</code> | |
356 * otherwise | |
357 */ | |
358 public bool getUseChevron() { | |
359 if (checkDisposed()) { | |
360 return false; | |
361 } | |
362 return useChevron; | |
363 } | |
364 | |
365 /** | |
366 * Create and display the chevron menu. | |
367 */ | |
368 private void handleChevron(SelectionEvent event) { | |
369 CoolItem item = cast(CoolItem) event.widget; | |
370 Control control = item.getControl(); | |
371 if (!(cast(ToolBar)control ) ) { | |
372 return; | |
373 } | |
374 CoolBar coolBar = item.getParent(); | |
375 ToolBar toolBar = cast(ToolBar) control; | |
376 Rectangle toolBarBounds = toolBar.getBounds(); | |
377 ToolItem[] items = toolBar.getItems(); | |
378 auto hidden = new ArraySeq!(Object); | |
379 for (int i = 0; i < items.length; ++i) { | |
380 Rectangle itemBounds = items[i].getBounds(); | |
381 if (!((itemBounds.x + itemBounds.width <= toolBarBounds.width) && (itemBounds.y | |
382 + itemBounds.height <= toolBarBounds.height))) { | |
383 hidden.append(items[i]); | |
384 } | |
385 } | |
386 | |
387 // Create a pop-up menu with items for each of the hidden buttons. | |
388 if (chevronMenuManager !is null) { | |
389 chevronMenuManager.dispose(); | |
390 } | |
391 chevronMenuManager = new MenuManager(); | |
392 foreach( it; hidden ){ | |
393 ToolItem toolItem = cast(ToolItem) it; | |
394 IContributionItem data = cast(IContributionItem) toolItem.getData(); | |
395 if (cast(ActionContributionItem)data ) { | |
396 ActionContributionItem contribution = new ActionContributionItem( | |
397 (cast(ActionContributionItem) data).getAction()); | |
398 chevronMenuManager.add(contribution); | |
399 } else if (cast(SubContributionItem)data ) { | |
400 IContributionItem innerData = (cast(SubContributionItem) data) | |
401 .getInnerItem(); | |
402 if (cast(ActionContributionItem)innerData ) { | |
403 ActionContributionItem contribution = new ActionContributionItem( | |
404 (cast(ActionContributionItem) innerData).getAction()); | |
405 chevronMenuManager.add(contribution); | |
406 } | |
407 } else if (data.isSeparator()) { | |
408 chevronMenuManager.add(new Separator()); | |
409 } | |
410 } | |
411 Menu popup = chevronMenuManager.createContextMenu(coolBar); | |
412 Point chevronPosition = coolBar.toDisplay(event.x, event.y); | |
413 popup.setLocation(chevronPosition.x, chevronPosition.y); | |
414 popup.setVisible(true); | |
415 } | |
416 | |
417 /** | |
418 * Handles the event when the toobar item does not have its own context | |
419 * menu. | |
420 * | |
421 * @param event | |
422 * the event object | |
423 */ | |
424 private void handleContextMenu(Event event) { | |
425 ToolBar toolBar = toolBarManager.getControl(); | |
426 // If parent has a menu then use that one | |
427 Menu parentMenu = toolBar.getParent().getMenu(); | |
428 if ((parentMenu !is null) && (!parentMenu.isDisposed())) { | |
429 toolBar.setMenu(parentMenu); | |
430 // Hook listener to remove menu once it has disapeared | |
431 parentMenu.addListener(DWT.Hide, new class Listener { | |
432 | |
433 public void handleEvent(Event innerEvent) { | |
434 ToolBar innerToolBar = toolBarManager.getControl(); | |
435 if (innerToolBar !is null) { | |
436 innerToolBar.setMenu(null); | |
437 Menu innerParentMenu = innerToolBar.getParent() | |
438 .getMenu(); | |
439 if (innerParentMenu !is null) { | |
440 innerParentMenu.removeListener(DWT.Hide, this); | |
441 } | |
442 } | |
443 } | |
444 }); | |
445 } | |
446 } | |
447 | |
448 /** | |
449 * Handles the disposal of the widget. | |
450 * | |
451 * @param event | |
452 * the event object | |
453 */ | |
454 private void handleWidgetDispose(DisposeEvent event) { | |
455 coolItem = null; | |
456 } | |
457 | |
458 /** | |
459 * A contribution item is visible iff its internal state is visible <em>or</em> | |
460 * the tool bar manager contains something other than group markers and | |
461 * separators. | |
462 * | |
463 * @return <code>true</code> if the tool bar manager contains something | |
464 * other than group marks and separators, and the internal state is | |
465 * set to be visible. | |
466 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
467 public override bool isVisible() { |
25 | 468 if (checkDisposed()) { |
469 return false; | |
470 } | |
471 | |
472 bool visibleItem = false; | |
473 if (toolBarManager !is null) { | |
474 IContributionItem[] contributionItems = toolBarManager.getItems(); | |
475 for (int i = 0; i < contributionItems.length; i++) { | |
476 IContributionItem contributionItem = contributionItems[i]; | |
477 if ((!contributionItem.isGroupMarker()) | |
478 && (!contributionItem.isSeparator())) { | |
479 visibleItem = true; | |
480 break; | |
481 } | |
482 } | |
483 } | |
484 | |
485 return (visibleItem || super.isVisible()); | |
486 } | |
487 | |
488 /* | |
489 * (non-Javadoc) | |
490 * | |
491 * @see dwtx.jface.action.IContributionItem#saveWidgetState() | |
492 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
493 public override void saveWidgetState() { |
25 | 494 if (checkDisposed()) { |
495 return; | |
496 } | |
497 if (coolItem is null) { | |
498 return; | |
499 } | |
500 | |
501 //1. Save current size | |
502 CoolBar coolBar = coolItem.getParent(); | |
503 bool isLastOnRow = false; | |
504 int lastIndex = coolBar.getItemCount() - 1; | |
505 int coolItemIndex = coolBar.indexOf(coolItem); | |
506 int[] wrapIndicies = getAdjustedWrapIndices(coolBar.getWrapIndices()); | |
507 // Traverse through all wrap indicies backwards | |
508 for (int row = wrapIndicies.length - 1; row >= 0; row--) { | |
509 if (wrapIndicies[row] <= coolItemIndex) { | |
510 | |
511 int nextRow = row + 1; | |
512 int nextRowStartIndex; | |
513 if (nextRow > (wrapIndicies.length - 1)) { | |
514 nextRowStartIndex = lastIndex + 1; | |
515 } else { | |
516 nextRowStartIndex = wrapIndicies[nextRow]; | |
517 } | |
518 | |
519 // Check to see if its the last item on the row | |
520 if (coolItemIndex is (nextRowStartIndex - 1)) { | |
521 isLastOnRow = true; | |
522 } | |
523 break; | |
524 } | |
525 } | |
526 | |
527 // Save the preferred size as actual size for the last item on a row | |
528 int nCurrentWidth; | |
529 if (isLastOnRow) { | |
530 nCurrentWidth = coolItem.getPreferredSize().x; | |
531 } else { | |
532 nCurrentWidth = coolItem.getSize().x; | |
533 } | |
534 setCurrentWidth(nCurrentWidth); | |
535 setCurrentHeight(coolItem.getSize().y); | |
536 } | |
537 | |
538 /** | |
539 * Sets the current height of the cool item. Update(SIZE) should be called | |
540 * to adjust the widget. | |
541 * | |
542 * @param currentHeight | |
543 * the current height to set | |
544 */ | |
545 public void setCurrentHeight(int currentHeight) { | |
546 if (checkDisposed()) { | |
547 return; | |
548 } | |
549 this.currentHeight = currentHeight; | |
550 } | |
551 | |
552 /** | |
553 * Sets the current width of the cool item. Update(SIZE) should be called | |
554 * to adjust the widget. | |
555 * | |
556 * @param currentWidth | |
557 * the current width to set | |
558 */ | |
559 public void setCurrentWidth(int currentWidth) { | |
560 if (checkDisposed()) { | |
561 return; | |
562 } | |
563 this.currentWidth = currentWidth; | |
564 } | |
565 | |
566 /** | |
567 * Sets the minimum number of tool items to show in the cool item. If this | |
568 * number is less than the total tool items, a chevron will appear and the | |
569 * hidden tool items appear in a drop down menu. By default, all the tool | |
570 * items are shown in the cool item. | |
571 * | |
572 * @param minimumItemsToShow | |
573 * the minimum number of tool items to show. | |
574 * @see #getMinimumItemsToShow() | |
575 * @see #setUseChevron(bool) | |
576 */ | |
577 public void setMinimumItemsToShow(int minimumItemsToShow) { | |
578 if (checkDisposed()) { | |
579 return; | |
580 } | |
581 this.minimumItemsToShow = minimumItemsToShow; | |
582 } | |
583 | |
584 /** | |
585 * Enables or disables chevron support for the cool item. By default, | |
586 * chevron support is enabled. | |
587 * | |
588 * @param value | |
589 * <code>true</code> to enable chevron support, <code>false</code> | |
590 * otherwise. | |
591 */ | |
592 public void setUseChevron(bool value) { | |
593 if (checkDisposed()) { | |
594 return; | |
595 } | |
596 useChevron = value; | |
597 } | |
598 | |
599 /* | |
600 * (non-Javadoc) | |
601 * | |
602 * @see dwtx.jface.action.IContributionItem#update(java.lang.String) | |
603 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
604 public override void update(String propertyName) { |
25 | 605 if (checkDisposed()) { |
606 return; | |
607 } | |
608 if (coolItem !is null) { | |
609 IToolBarManager manager = getToolBarManager(); | |
610 if (manager !is null) { | |
611 manager.update(true); | |
612 } | |
613 | |
614 if ((propertyName is null) | |
615 || propertyName.equals(ICoolBarManager.SIZE)) { | |
616 updateSize(true); | |
617 } | |
618 } | |
619 } | |
620 | |
621 /** | |
622 * Updates the cool items' preferred, minimum, and current size. The | |
623 * preferred size is calculated based on the tool bar size and extra trim. | |
624 * | |
625 * @param changeCurrentSize | |
626 * <code>true</code> if the current size should be changed to | |
627 * the preferred size, <code>false</code> to not change the | |
628 * current size | |
629 */ | |
630 private void updateSize(bool changeCurrentSize) { | |
631 if (checkDisposed()) { | |
632 return; | |
633 } | |
634 // cannot set size if coolItem is null | |
635 if (coolItem is null || coolItem.isDisposed()) { | |
636 return; | |
637 } | |
638 bool locked = false; | |
639 CoolBar coolBar = coolItem.getParent(); | |
640 try { | |
641 // Fix odd behaviour with locked tool bars | |
642 if (coolBar !is null) { | |
643 if (coolBar.getLocked()) { | |
644 coolBar.setLocked(false); | |
645 locked = true; | |
646 } | |
647 } | |
648 ToolBar toolBar = cast(ToolBar) coolItem.getControl(); | |
649 if ((toolBar is null) || (toolBar.isDisposed()) | |
650 || (toolBar.getItemCount() <= 0)) { | |
651 // if the toolbar does not contain any items then dispose of | |
652 // coolItem | |
653 coolItem.setData(null); | |
654 Control control = coolItem.getControl(); | |
655 if ((control !is null) && !control.isDisposed()) { | |
656 control.dispose(); | |
657 coolItem.setControl(null); | |
658 } | |
659 if (!coolItem.isDisposed()) { | |
660 coolItem.dispose(); | |
661 } | |
662 } else { | |
663 // If the toolbar item exists then adjust the size of the cool | |
664 // item | |
665 Point toolBarSize = toolBar.computeSize(DWT.DEFAULT, | |
666 DWT.DEFAULT); | |
667 // Set the preffered size to the size of the toolbar plus trim | |
668 Point preferredSize = coolItem.computeSize(toolBarSize.x, | |
669 toolBarSize.y); | |
670 coolItem.setPreferredSize(preferredSize); | |
671 // note setMinimumSize must be called before setSize, see PR | |
672 // 15565 | |
673 // Set minimum size | |
674 if (getMinimumItemsToShow() !is SHOW_ALL_ITEMS) { | |
675 int toolItemWidth = toolBar.getItems()[0].getWidth(); | |
676 int minimumWidth = toolItemWidth * getMinimumItemsToShow(); | |
677 coolItem.setMinimumSize(minimumWidth, toolBarSize.y); | |
678 } else { | |
679 coolItem.setMinimumSize(toolBarSize.x, toolBarSize.y); | |
680 } | |
681 if (changeCurrentSize) { | |
682 // Set current size to preferred size | |
683 coolItem.setSize(preferredSize); | |
684 } | |
685 } | |
686 } finally { | |
687 // If the cool bar was locked, then set it back to locked | |
688 if ((locked) && (coolBar !is null)) { | |
689 coolBar.setLocked(true); | |
690 } | |
691 } | |
692 } | |
693 | |
694 } |