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