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