Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryQActionContributionItem.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 
15 
18 
19 #include <QMenu>
20 
21 namespace berry {
22 
23 QActionContributionItem::QActionContributionItem(QAction* action, const QString& id)
24  : ContributionItem(id), action(action)
25 {
26 }
27 
29 {
30  if (const QActionContributionItem* aci = dynamic_cast<const QActionContributionItem*>(o))
31  {
32  return action == aci->action;
33  }
34  return false;
35 }
36 
38 {
39  return qHash(action);
40 }
41 
42 void QActionContributionItem::Fill(QStatusBar* /*parent*/)
43 {
44 // if (widget == null && parent != null) {
45 // int flags = SWT.PUSH;
46 // if (action != null) {
47 // if (action.getStyle() == IAction.AS_CHECK_BOX) {
48 // flags = SWT.TOGGLE;
49 // }
50 // if (action.getStyle() == IAction.AS_RADIO_BUTTON) {
51 // flags = SWT.RADIO;
52 // }
53 // }
54 
55 // Button b = new Button(parent, flags);
56 // b.setData(this);
57 // b.addListener(SWT.Dispose, getButtonListener());
58 // // Don't hook a dispose listener on the parent
59 // b.addListener(SWT.Selection, getButtonListener());
60 // if (action.getHelpListener() != null) {
61 // b.addHelpListener(action.getHelpListener());
62 // }
63 // widget = b;
64 
65 // update(null);
66 
67 // // Attach some extra listeners.
68 // action.addPropertyChangeListener(propertyListener);
69 // if (action != null) {
70 // String commandId = action.getActionDefinitionId();
71 // ExternalActionManager.ICallback callback = ExternalActionManager
72 // .getInstance().getCallback();
73 
74 // if ((callback != null) && (commandId != null)) {
75 // callback.addPropertyChangeListener(commandId,
76 // actionTextListener);
77 // }
78 // }
79 // }
80 }
81 
82 void QActionContributionItem::Fill(QMenu* parent, QAction* before)
83 {
84  if (parent != nullptr)
85  {
86  if (before)
87  {
88  parent->insertAction(before, action);
89  }
90  else
91  {
92  parent->addAction(action);
93  }
94  action->setData(QVariant::fromValue(Object::Pointer(this)));
95  action->setProperty("contributionItem", QVariant::fromValue(Object::Pointer(this)));
96  //action.addListener(SWT.Dispose, getMenuItemListener());
97  //action.addListener(SWT.Selection, getMenuItemListener());
98  //if (action.getHelpListener() != null)
99  //{
100  // mi.addHelpListener(action.getHelpListener());
101  //}
102 
103  if (action->menu())
104  {
105 // // just create a proxy for now, if the user shows it then
106 // // fill it in
107 // Menu subMenu = new Menu(parent);
108 // subMenu.addListener(SWT.Show, getMenuCreatorListener());
109 // subMenu.addListener(SWT.Hide, getMenuCreatorListener());
110 // mi.setMenu(subMenu);
111  }
112 
113  Update(QString());
114 
115 // // Attach some extra listeners.
116 // action.addPropertyChangeListener(propertyListener);
117 // if (action != null) {
118 // String commandId = action.getActionDefinitionId();
119 // ExternalActionManager.ICallback callback = ExternalActionManager
120 // .getInstance().getCallback();
121 
122 // if ((callback != null) && (commandId != null)) {
123 // callback.addPropertyChangeListener(commandId,
124 // actionTextListener);
125 // }
126 // }
127  }
128 }
129 
130 void QActionContributionItem::Fill(QToolBar* /*parent*/, QAction* /*before*/)
131 {
132 // if (widget == null && parent != null) {
133 // int flags = SWT.PUSH;
134 // if (action != null) {
135 // int style = action.getStyle();
136 // if (style == IAction.AS_CHECK_BOX) {
137 // flags = SWT.CHECK;
138 // } else if (style == IAction.AS_RADIO_BUTTON) {
139 // flags = SWT.RADIO;
140 // } else if (style == IAction.AS_DROP_DOWN_MENU) {
141 // flags = SWT.DROP_DOWN;
142 // }
143 // }
144 
145 // ToolItem ti = null;
146 // if (index >= 0) {
147 // ti = new ToolItem(parent, flags, index);
148 // } else {
149 // ti = new ToolItem(parent, flags);
150 // }
151 // ti.setData(this);
152 // ti.addListener(SWT.Selection, getToolItemListener());
153 // ti.addListener(SWT.Dispose, getToolItemListener());
154 
155 // widget = ti;
156 
157 // update(null);
158 
159 // // Attach some extra listeners.
160 // action.addPropertyChangeListener(propertyListener);
161 // if (action != null) {
162 // String commandId = action.getActionDefinitionId();
163 // ExternalActionManager.ICallback callback = ExternalActionManager
164 // .getInstance().getCallback();
165 
166 // if ((callback != null) && (commandId != null)) {
167 // callback.addPropertyChangeListener(commandId,
168 // actionTextListener);
169 // }
170 // }
171 // }
172 }
173 
175 {
176  return action;
177 }
178 
180 {
181  //holdMenu = null;
182 }
183 
184 ContributionItem::Modes QActionContributionItem::GetMode() const
185 {
186  return mode;
187 }
188 
190 {
191 // if (qobject_cast<QMenu*>(action->parentWidget()))
192 // {
193 // // Optimization. Only recreate the item is the check or radio style
194 // // has changed.
195 // boolean itemIsCheck = (widget.getStyle() & SWT.CHECK) != 0;
196 // boolean actionIsCheck = getAction() != null
197 // && getAction().getStyle() == IAction.AS_CHECK_BOX;
198 // boolean itemIsRadio = (widget.getStyle() & SWT.RADIO) != 0;
199 // boolean actionIsRadio = getAction() != null
200 // && getAction().getStyle() == IAction.AS_RADIO_BUTTON;
201 // return (itemIsCheck != actionIsCheck)
202 // || (itemIsRadio != actionIsRadio);
203 // }
204  return false;
205 }
206 
208 {
209  return action != nullptr && action->isEnabled();
210 }
211 
213 {
214  return ContributionItem::IsVisible() && IsCommandActive();
215 }
216 
218 {
219  this->mode = mode;
220  Update();
221 }
222 
224 {
225  Update(QString());
226 }
227 
228 void QActionContributionItem::Update(const QString& /*propertyName*/)
229 {
230 // if (widget != 0)
231 // {
232 // // determine what to do
233 // boolean textChanged = propertyName == null
234 // || propertyName.equals(IAction.TEXT);
235 // boolean imageChanged = propertyName == null
236 // || propertyName.equals(IAction.IMAGE);
237 // boolean tooltipTextChanged = propertyName == null
238 // || propertyName.equals(IAction.TOOL_TIP_TEXT);
239 // boolean enableStateChanged = propertyName == null
240 // || propertyName.equals(IAction.ENABLED)
241 // || propertyName
242 // .equals(IContributionManagerOverrides.P_ENABLED);
243 // boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX || action
244 // .getStyle() == IAction.AS_RADIO_BUTTON)
245 // && (propertyName == null || propertyName
246 // .equals(IAction.CHECKED));
247 
248 // if (widget instanceof ToolItem) {
249 // ToolItem ti = (ToolItem) widget;
250 // String text = action.getText();
251 // // the set text is shown only if there is no image or if forced
252 // // by MODE_FORCE_TEXT
253 // boolean showText = text != null
254 // && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action));
255 
256 // // only do the trimming if the text will be used
257 // if (showText && text != null) {
258 // text = Action.removeAcceleratorText(text);
259 // text = Action.removeMnemonics(text);
260 // }
261 
262 // if (textChanged) {
263 // String textToSet = showText ? text : ""; //$NON-NLS-1$
264 // boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0;
265 // if (rightStyle || !ti.getText().equals(textToSet)) {
266 // // In addition to being required to update the text if
267 // // it
268 // // gets nulled out in the action, this is also a
269 // // workaround
270 // // for bug 50151: Using SWT.RIGHT on a ToolBar leaves
271 // // blank space
272 // ti.setText(textToSet);
273 // }
274 // }
275 
276 // if (imageChanged) {
277 // // only substitute a missing image if it has no text
278 // updateImages(!showText);
279 // }
280 
281 // if (tooltipTextChanged || textChanged) {
282 // String toolTip = action.getToolTipText();
283 // if ((toolTip == null) || (toolTip.length() == 0)) {
284 // toolTip = text;
285 // }
286 
287 // ExternalActionManager.ICallback callback = ExternalActionManager
288 // .getInstance().getCallback();
289 // String commandId = action.getActionDefinitionId();
290 // if ((callback != null) && (commandId != null)
291 // && (toolTip != null)) {
292 // String acceleratorText = callback
293 // .getAcceleratorText(commandId);
294 // if (acceleratorText != null
295 // && acceleratorText.length() != 0) {
296 // toolTip = JFaceResources.format(
297 // "Toolbar_Tooltip_Accelerator", //$NON-NLS-1$
298 // new Object[] { toolTip, acceleratorText });
299 // }
300 // }
301 
302 // // if the text is showing, then only set the tooltip if
303 // // different
304 // if (!showText || toolTip != null && !toolTip.equals(text)) {
305 // ti.setToolTipText(toolTip);
306 // } else {
307 // ti.setToolTipText(null);
308 // }
309 // }
310 
311 // if (enableStateChanged) {
312 // boolean shouldBeEnabled = action.isEnabled()
313 // && isEnabledAllowed();
314 
315 // if (ti.getEnabled() != shouldBeEnabled) {
316 // ti.setEnabled(shouldBeEnabled);
317 // }
318 // }
319 
320 // if (checkChanged) {
321 // boolean bv = action.isChecked();
322 
323 // if (ti.getSelection() != bv) {
324 // ti.setSelection(bv);
325 // }
326 // }
327 // return;
328 // }
329 
330 // if (widget instanceof MenuItem) {
331 // MenuItem mi = (MenuItem) widget;
332 
333 // if (textChanged) {
334 // int accelerator = 0;
335 // String acceleratorText = null;
336 // IAction updatedAction = getAction();
337 // String text = null;
338 // accelerator = updatedAction.getAccelerator();
339 // ExternalActionManager.ICallback callback = ExternalActionManager
340 // .getInstance().getCallback();
341 
342 // // Block accelerators that are already in use.
343 // if ((accelerator != 0) && (callback != null)
344 // && (callback.isAcceleratorInUse(accelerator))) {
345 // accelerator = 0;
346 // }
347 
348 // /*
349 // * Process accelerators on GTK in a special way to avoid Bug
350 // * 42009. We will override the native input method by
351 // * allowing these reserved accelerators to be placed on the
352 // * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]".
353 // */
354 // final String commandId = updatedAction
355 // .getActionDefinitionId();
356 // if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback)
357 // && (commandId != null)) {
358 // final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;
359 // final IKeyLookup lookup = KeyLookupFactory.getDefault();
360 // final TriggerSequence[] triggerSequences = bindingManagerCallback
361 // .getActiveBindingsFor(commandId);
362 // for (int i = 0; i < triggerSequences.length; i++) {
363 // final TriggerSequence triggerSequence = triggerSequences[i];
364 // final Trigger[] triggers = triggerSequence
365 // .getTriggers();
366 // if (triggers.length == 1) {
367 // final Trigger trigger = triggers[0];
368 // if (trigger instanceof KeyStroke) {
369 // final KeyStroke currentKeyStroke = (KeyStroke) trigger;
370 // final int currentNaturalKey = currentKeyStroke
371 // .getNaturalKey();
372 // if ((currentKeyStroke.getModifierKeys() == (lookup
373 // .getCtrl() | lookup.getShift()))
374 // && ((currentNaturalKey >= '0' && currentNaturalKey <= '9')
375 // || (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) {
376 // accelerator = currentKeyStroke
377 // .getModifierKeys()
378 // | currentNaturalKey;
379 // acceleratorText = triggerSequence
380 // .format();
381 // break;
382 // }
383 // }
384 // }
385 // }
386 // }
387 
388 // if (accelerator == 0) {
389 // if ((callback != null) && (commandId != null)) {
390 // acceleratorText = callback
391 // .getAcceleratorText(commandId);
392 // }
393 // }
394 
395 // IContributionManagerOverrides overrides = null;
396 
397 // if (getParent() != null) {
398 // overrides = getParent().getOverrides();
399 // }
400 
401 // if (overrides != null) {
402 // text = getParent().getOverrides().getText(this);
403 // }
404 
405 // mi.setAccelerator(accelerator);
406 
407 // if (text == null) {
408 // text = updatedAction.getText();
409 // }
410 
411 // if (text != null && acceleratorText == null) {
412 // // use extracted accelerator text in case accelerator
413 // // cannot be fully represented in one int (e.g.
414 // // multi-stroke keys)
415 // acceleratorText = LegacyActionTools
416 // .extractAcceleratorText(text);
417 // if (acceleratorText == null && accelerator != 0) {
418 // acceleratorText = Action
419 // .convertAccelerator(accelerator);
420 // }
421 // }
422 
423 // if (text == null) {
424 // text = ""; //$NON-NLS-1$
425 // } else {
426 // text = Action.removeAcceleratorText(text);
427 // }
428 
429 // if (acceleratorText == null) {
430 // mi.setText(text);
431 // } else {
432 // mi.setText(text + '\t' + acceleratorText);
433 // }
434 // }
435 
436 // if (imageChanged) {
437 // updateImages(false);
438 // }
439 
440 // if (enableStateChanged) {
441 // boolean shouldBeEnabled = action.isEnabled()
442 // && isEnabledAllowed();
443 
444 // if (mi.getEnabled() != shouldBeEnabled) {
445 // mi.setEnabled(shouldBeEnabled);
446 // }
447 // }
448 
449 // if (checkChanged) {
450 // boolean bv = action.isChecked();
451 
452 // if (mi.getSelection() != bv) {
453 // mi.setSelection(bv);
454 // }
455 // }
456 
457 // return;
458 // }
459 
460 // if (widget instanceof Button) {
461 // Button button = (Button) widget;
462 
463 // if (imageChanged) {
464 // updateImages(false);
465 // }
466 
467 // if (textChanged) {
468 // String text = action.getText();
469 // boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action));
470 // // only do the trimming if the text will be used
471 // if (showText) {
472 // text = Action.removeAcceleratorText(text);
473 // }
474 // String textToSet = showText ? text : ""; //$NON-NLS-1$
475 // button.setText(textToSet);
476 // }
477 
478 // if (tooltipTextChanged) {
479 // button.setToolTipText(action.getToolTipText());
480 // }
481 
482 // if (enableStateChanged) {
483 // boolean shouldBeEnabled = action.isEnabled()
484 // && isEnabledAllowed();
485 
486 // if (button.getEnabled() != shouldBeEnabled) {
487 // button.setEnabled(shouldBeEnabled);
488 // }
489 // }
490 
491 // if (checkChanged) {
492 // boolean bv = action.isChecked();
493 
494 // if (button.getSelection() != bv) {
495 // button.setSelection(bv);
496 // }
497 // }
498 // return;
499 // }
500 //}
501 }
502 
504 {
505  if (this->GetParent() == nullptr)
506  {
507  return true;
508  }
509  int value = GetParent()->GetOverrides()->GetEnabled(this);
510  return (value == -1) ? true : value;
511 }
512 
513 //QString QActionContributionItem::ShortenText(const QString& textValue, QToolButton* item)
514 //{
515 //if (textValue == null) {
516 // return null;
517 //}
518 
519 //GC gc = new GC(item.getParent());
520 
521 //int maxWidth = item.getImage().getBounds().width * 4;
522 
523 //if (gc.textExtent(textValue).x < maxWidth) {
524 // gc.dispose();
525 // return textValue;
526 //}
527 
528 //for (int i = textValue.length(); i > 0; i--) {
529 // String test = textValue.substring(0, i);
530 // test = test + ellipsis;
531 // if (gc.textExtent(test).x < maxWidth) {
532 // gc.dispose();
533 // return test;
534 // }
535 
536 //}
537 //gc.dispose();
539 //return textValue;
540 //}
541 
542 //Listener QActionContributionItem::GetToolItemListener()
543 //{
544 //if (toolItemListener == null) {
545 // toolItemListener = new Listener() {
546 // public void handleEvent(Event event) {
547 // switch (event.type) {
548 // case SWT.Dispose:
549 // handleWidgetDispose(event);
550 // break;
551 // case SWT.Selection:
552 // Widget ew = event.widget;
553 // if (ew != null) {
554 // handleWidgetSelection(event, ((ToolItem) ew)
555 // .getSelection());
556 // }
557 // break;
558 // }
559 // }
560 // };
561 //}
562 //return toolItemListener;
563 //}
564 
565 //void QActionContributionItem::HandleWidgetDispose(Event e)
566 //{
568 //if (e.widget == widget) {
569 // // Dispose of the menu creator.
570 // if (action.getStyle() == IAction.AS_DROP_DOWN_MENU
571 // && menuCreatorCalled) {
572 // IMenuCreator mc = action.getMenuCreator();
573 // if (mc != null) {
574 // mc.dispose();
575 // }
576 // }
577 
578 // // Unhook all of the listeners.
579 // action.removePropertyChangeListener(propertyListener);
580 // if (action != null) {
581 // String commandId = action.getActionDefinitionId();
582 // ExternalActionManager.ICallback callback = ExternalActionManager
583 // .getInstance().getCallback();
584 
585 // if ((callback != null) && (commandId != null)) {
586 // callback.removePropertyChangeListener(commandId,
587 // actionTextListener);
588 // }
589 // }
590 
591 // // Clear the widget field.
592 // widget = null;
593 
594 // disposeOldImages();
595 //}
596 //}
597 
598 //void QActionContributionItem::HandleWidgetSelection(Event e, bool selection)
599 //{
600 
601 //Widget item = e.widget;
602 //if (item != null) {
603 // int style = item.getStyle();
604 
605 // if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) {
606 // if (action.getStyle() == IAction.AS_CHECK_BOX) {
607 // action.setChecked(selection);
608 // }
609 // } else if ((style & SWT.RADIO) != 0) {
610 // if (action.getStyle() == IAction.AS_RADIO_BUTTON) {
611 // action.setChecked(selection);
612 // }
613 // } else if ((style & SWT.DROP_DOWN) != 0) {
614 // if (e.detail == 4) { // on drop-down button
615 // if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
616 // IMenuCreator mc = action.getMenuCreator();
617 // menuCreatorCalled = true;
618 // ToolItem ti = (ToolItem) item;
619 // // we create the menu as a sub-menu of "dummy" so that
620 // // we can use
621 // // it in a cascading menu too.
622 // // If created on a SWT control we would get an SWT
623 // // error...
624 // // Menu dummy= new Menu(ti.getParent());
625 // // Menu m= mc.getMenu(dummy);
626 // // dummy.dispose();
627 // if (mc != null) {
628 // Menu m = mc.getMenu(ti.getParent());
629 // if (m != null) {
630 // // position the menu below the drop down item
631 // Point point = ti.getParent().toDisplay(
632 // new Point(e.x, e.y));
633 // m.setLocation(point.x, point.y); // waiting
634 // // for SWT
635 // // 0.42
636 // m.setVisible(true);
637 // return; // we don't fire the action
638 // }
639 // }
640 // }
641 // }
642 // }
643 
644 // ExternalActionManager.IExecuteCallback callback = null;
645 // String actionDefinitionId = action.getActionDefinitionId();
646 // if (actionDefinitionId != null) {
647 // Object obj = ExternalActionManager.getInstance()
648 // .getCallback();
649 // if (obj instanceof ExternalActionManager.IExecuteCallback) {
650 // callback = (ExternalActionManager.IExecuteCallback) obj;
651 // }
652 // }
653 
654 // // Ensure action is enabled first.
655 // // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be
656 // // executed while disabled.
657 // if (action.isEnabled()) {
658 // boolean trace = Policy.TRACE_ACTIONS;
659 
660 // long ms = 0L;
661 // if (trace) {
662 // ms = System.currentTimeMillis();
663 // System.out.println("Running action: " + action.getText()); //$NON-NLS-1$
664 // }
665 
666 // IPropertyChangeListener resultListener = null;
667 // if (callback != null) {
668 // resultListener = new IPropertyChangeListener() {
669 // public void propertyChange(PropertyChangeEvent event) {
670 // // Check on result
671 // if (event.getProperty().equals(IAction.RESULT)) {
672 // if (event.getNewValue() instanceof Boolean) {
673 // result = (Boolean) event.getNewValue();
674 // }
675 // }
676 // }
677 // };
678 // action.addPropertyChangeListener(resultListener);
679 // callback.preExecute(action, e);
680 // }
681 
682 // action.runWithEvent(e);
683 
684 // if (callback != null) {
685 // if (result == null || result.equals(Boolean.TRUE)) {
686 // callback.postExecuteSuccess(action, Boolean.TRUE);
687 // } else {
688 // callback.postExecuteFailure(action,
689 // new ExecutionException(action.getText()
690 // + " returned failure.")); //$NON-NLS-1$
691 // }
692 // }
693 
694 // if (resultListener!=null) {
695 // result = null;
696 // action.removePropertyChangeListener(resultListener);
697 // }
698 // if (trace) {
699 // System.out.println((System.currentTimeMillis() - ms)
700 // + " ms to run action: " + action.getText()); //$NON-NLS-1$
701 // }
702 // } else {
703 // if (callback != null) {
704 // callback.notEnabled(action, new NotEnabledException(action
705 // .getText()
706 // + " is not enabled.")); //$NON-NLS-1$
707 // }
708 // }
709 //}
710 //}
711 
712 //bool QActionContributionItem::HasImages(Action* actionToCheck) const
713 //{
714 // return actionToCheck.getImageDescriptor() != null
715 // || actionToCheck.getHoverImageDescriptor() != null
716 // || actionToCheck.getDisabledImageDescriptor() != null;
717 //}
718 
719 bool QActionContributionItem::IsCommandActive() const
720 {
721  return action ? action->isVisible() : true;
722 }
723 
724 //bool QActionContributionItem::UpdateImages(bool forceImage)
725 //{
726 
727 // ResourceManager parentResourceManager = JFaceResources.getResources();
728 
729 // if (widget instanceof ToolItem) {
730 // if (USE_COLOR_ICONS) {
731 // ImageDescriptor image = action.getHoverImageDescriptor();
732 // if (image == null) {
733 // image = action.getImageDescriptor();
734 // }
735 // ImageDescriptor disabledImage = action
736 // .getDisabledImageDescriptor();
737 
738 // // Make sure there is a valid image.
739 // if (image == null && forceImage) {
740 // image = ImageDescriptor.getMissingImageDescriptor();
741 // }
742 
743 // LocalResourceManager localManager = new LocalResourceManager(
744 // parentResourceManager);
745 
746 // // performance: more efficient in SWT to set disabled and hot
747 // // image before regular image
748 // ((ToolItem) widget)
749 // .setDisabledImage(disabledImage == null ? null
750 // : localManager
751 // .createImageWithDefault(disabledImage));
752 // ((ToolItem) widget).setImage(image == null ? null
753 // : localManager.createImageWithDefault(image));
754 
755 // disposeOldImages();
756 // imageManager = localManager;
757 
758 // return image != null;
759 // }
760 // ImageDescriptor image = action.getImageDescriptor();
761 // ImageDescriptor hoverImage = action.getHoverImageDescriptor();
762 // ImageDescriptor disabledImage = action.getDisabledImageDescriptor();
763 
764 // // If there is no regular image, but there is a hover image,
765 // // convert the hover image to gray and use it as the regular image.
766 // if (image == null && hoverImage != null) {
767 // image = ImageDescriptor.createWithFlags(action
768 // .getHoverImageDescriptor(), SWT.IMAGE_GRAY);
769 // } else {
770 // // If there is no hover image, use the regular image as the
771 // // hover image,
772 // // and convert the regular image to gray
773 // if (hoverImage == null && image != null) {
774 // hoverImage = image;
775 // image = ImageDescriptor.createWithFlags(action
776 // .getImageDescriptor(), SWT.IMAGE_GRAY);
777 // }
778 // }
779 
780 // // Make sure there is a valid image.
781 // if (hoverImage == null && image == null && forceImage) {
782 // image = ImageDescriptor.getMissingImageDescriptor();
783 // }
784 
785 // // Create a local resource manager to remember the images we've
786 // // allocated for this tool item
787 // LocalResourceManager localManager = new LocalResourceManager(
788 // parentResourceManager);
789 
790 // // performance: more efficient in SWT to set disabled and hot image
791 // // before regular image
792 // ((ToolItem) widget).setDisabledImage(disabledImage == null ? null
793 // : localManager.createImageWithDefault(disabledImage));
794 // ((ToolItem) widget).setHotImage(hoverImage == null ? null
795 // : localManager.createImageWithDefault(hoverImage));
796 // ((ToolItem) widget).setImage(image == null ? null : localManager
797 // .createImageWithDefault(image));
798 
799 // // Now that we're no longer referencing the old images, clear them
800 // // out.
801 // disposeOldImages();
802 // imageManager = localManager;
803 
804 // return image != null;
805 // } else if (widget instanceof Item || widget instanceof Button) {
806 
807 // // Use hover image if there is one, otherwise use regular image.
808 // ImageDescriptor image = action.getHoverImageDescriptor();
809 // if (image == null) {
810 // image = action.getImageDescriptor();
811 // }
812 // // Make sure there is a valid image.
813 // if (image == null && forceImage) {
814 // image = ImageDescriptor.getMissingImageDescriptor();
815 // }
816 
817 // // Create a local resource manager to remember the images we've
818 // // allocated for this widget
819 // LocalResourceManager localManager = new LocalResourceManager(
820 // parentResourceManager);
821 
822 // if (widget instanceof Item) {
823 // ((Item) widget).setImage(image == null ? null : localManager
824 // .createImageWithDefault(image));
825 // } else if (widget instanceof Button) {
826 // ((Button) widget).setImage(image == null ? null : localManager
827 // .createImageWithDefault(image));
828 // }
829 
830 // // Now that we're no longer referencing the old images, clear them
831 // // out.
832 // disposeOldImages();
833 // imageManager = localManager;
834 
835 // return image != null;
836 // }
837 // return false;
838 //}
839 
840 //void QActionContributionItem::DisposeOldImages()
841 //{
842 // if (imageManager != null) {
843 // imageManager.dispose();
844 // imageManager = null;
845 // }
846 //}
847 
848 //Listener QActionContributionItem::getMenuCreatorListener() {
849 // if (menuCreatorListener == null) {
850 // menuCreatorListener = new Listener() {
851 // public void handleEvent(Event event) {
852 // switch (event.type) {
853 // case SWT.Show:
854 // handleShowProxy((Menu) event.widget);
855 // break;
856 // case SWT.Hide:
857 // handleHideProxy((Menu) event.widget);
858 // break;
859 // }
860 // }
861 // };
862 // }
863 // return menuCreatorListener;
864 //}
865 
866 //void QActionContributionItem::HandleShowProxy(QMenu* proxy)
867 //{
868 // proxy.removeListener(SWT.Show, getMenuCreatorListener());
869 // IMenuCreator mc = action.getMenuCreator();
870 // menuCreatorCalled = true;
871 // if (mc == null) {
872 // return;
873 // }
874 // holdMenu = mc.getMenu(proxy.getParentMenu());
875 // if (holdMenu == null) {
876 // return;
877 // }
878 // copyMenu(holdMenu, proxy);
879 //}
880 
881 //void QActionContributionItem::CopyMenu(QMenu* realMenu, QMenu* proxy) {
882 // if (realMenu.isDisposed() || proxy.isDisposed()) {
883 // return;
884 // }
885 
886 // // we notify the real menu so it can populate itself if it was
887 // // listening for SWT.Show
888 // realMenu.notifyListeners(SWT.Show, null);
889 
890 // final Listener passThrough = new Listener() {
891 // public void handleEvent(Event event) {
892 // if (!event.widget.isDisposed()) {
893 // Widget realItem = (Widget) event.widget.getData();
894 // if (!realItem.isDisposed()) {
895 // int style = event.widget.getStyle();
896 // if (event.type == SWT.Selection
897 // && ((style & (SWT.TOGGLE | SWT.CHECK | SWT.RADIO)) != 0)
898 // && realItem instanceof MenuItem) {
899 // ((MenuItem) realItem)
900 // .setSelection(((MenuItem) event.widget)
901 // .getSelection());
902 // }
903 // event.widget = realItem;
904 // realItem.notifyListeners(event.type, event);
905 // }
906 // }
907 // }
908 // };
909 
910 // MenuItem[] items = realMenu.getItems();
911 // for (int i = 0; i < items.length; i++) {
912 // final MenuItem realItem = items[i];
913 // final MenuItem proxyItem = new MenuItem(proxy, realItem.getStyle());
914 // proxyItem.setData(realItem);
915 // proxyItem.setAccelerator(realItem.getAccelerator());
916 // proxyItem.setEnabled(realItem.getEnabled());
917 // proxyItem.setImage(realItem.getImage());
918 // proxyItem.setSelection(realItem.getSelection());
919 // proxyItem.setText(realItem.getText());
920 
921 // // pass through any events
922 // proxyItem.addListener(SWT.Selection, passThrough);
923 // proxyItem.addListener(SWT.Arm, passThrough);
924 // proxyItem.addListener(SWT.Help, passThrough);
925 
926 // final Menu itemMenu = realItem.getMenu();
927 // if (itemMenu != null) {
928 // // create a proxy for any sub menu items
929 // final Menu subMenu = new Menu(proxy);
930 // subMenu.setData(itemMenu);
931 // proxyItem.setMenu(subMenu);
932 // subMenu.addListener(SWT.Show, new Listener() {
933 // public void handleEvent(Event event) {
934 // event.widget.removeListener(SWT.Show, this);
935 // if (event.type == SWT.Show) {
936 // copyMenu(itemMenu, subMenu);
937 // }
938 // }
939 // });
940 // subMenu.addListener(SWT.Help, passThrough);
941 // subMenu.addListener(SWT.Hide, passThrough);
942 // }
943 // }
944 //}
945 
946 //void QActionContributionItem::HandleHideProxy(QMenu* proxy)
947 //{
948 // proxy.removeListener(SWT.Hide, getMenuCreatorListener());
949 // proxy.getDisplay().asyncExec(new Runnable() {
950 // public void run() {
951 // if (!proxy.isDisposed()) {
952 // MenuItem parentItem = proxy.getParentItem();
953 // proxy.dispose();
954 // parentItem.setMenu(holdMenu);
955 // }
956 // if (holdMenu != null && !holdMenu.isDisposed()) {
957 // holdMenu.notifyListeners(SWT.Hide, null);
958 // }
959 // holdMenu = null;
960 // }
961 // });
962 //}
963 
964 }
IContributionManager * GetParent() const
bool IsVisible() const override
virtual SmartPointer< IContributionManagerOverrides > GetOverrides()=0
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
bool operator==(const Object *o) const override
void Fill(QStatusBar *parent) override
unsigned int uint
QActionContributionItem(QAction *action, const QString &id)
uint qHash(const berry::Object &o)