Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] popup menu


I just fixed the bug you were seeing before I answered the original question.  You will need the code from HEAD to test it.

Can me move future discussions like this to eclipse.platform.swt?  Thanks.



Frédéric Dreier <lists@xxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

09/08/2005 01:10 AM

Please respond to
"Eclipse Platform SWT component developers list."

To
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
cc
Subject
Re: [platform-swt-dev] popup menu





Hi Steve,

I do not use key listener (or I don't know that I do). I have based my
menu on an example of the Book "SWT/JFace in action" using the
MenuManager. I use such code with Tree without getting this effect. Here is an example :


import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;

/**
* @since XXX
*/
public class MyCanevas extends Canvas implements PaintListener,
MouseListener {
   MenuManager manager;

   static int counter= 0;

   public MyCanevas (final Composite parent, int style) {
       super(parent, style);
       addPaintListener(this);
       setBounds(0, 0, 100, 100);
       addMouseListener(this);
   }

   public void paintControl (PaintEvent arg0) {
       GC gc= arg0.gc;
     
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
     
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
       gc.fillRectangle(getBounds());
     
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
     
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
       gc.fillRectangle(35, 40, 30, 20);
       //      
       manager= new MenuManager("#PopupMenu");
       manager.setRemoveAllWhenShown(false);
       manager.addMenuListener(new IMenuListener() {
           public void menuAboutToShow (IMenuManager manager) {
               System.out.println("about to show...");
               manager.add(new DummyAction("[" + counter + "]"));
               counter++;
               System.out.println(">>> " + manager.getItems().length);
           }
       });
   }

   public void mouseDoubleClick (MouseEvent arg0) {
   }

   public void mouseDown (MouseEvent arg0) {
       System.out.println("mouse down");
       setMenu(manager.createContextMenu(this));

   }

   public void mouseUp (MouseEvent arg0) {
   }

   public static class DummyAction extends Action {
       public DummyAction (String text) {
           super(text);
       }
   }

   public static void main (String[] args) {
       Win wwin= new Win();
       wwin.setBlockOnOpen(true);
       wwin.open();
       Display.getCurrent().dispose();
       System.exit(0);
   }

   public static class Win extends ApplicationWindow {
       public Win () {
           super(null);
       }

       protected Control createContents (Composite parent) {
           new Container(parent);
           parent.setLocation(100, 100);
           return parent;
       }
   }

   public static class Container extends Composite {
       public Container (Composite parent) {
           super(parent, SWT.NONE);
           setLayout(new FillLayout());
           MyCanevas c= new MyCanevas(this, SWT.BORDER | SWT.V_SCROLL |
SWT.H_SCROLL
               | SWT.NO_BACKGROUND);
           c.setBounds(0, 0, 100, 100);
           setBounds(0, 0, 100, 100);

           pack();
       }
   }
}






















Steve Northover a écrit :

>
> Fixed > 20050907
>
> Make sure that you do not add a key listener.  If you do, you will
> automatically get the standard menu back so that users can enter
> international text.
>
>
>
> *Frédéric Dreier <lists@xxxxxxxxx>*
> Sent by: platform-swt-dev-bounces@xxxxxxxxxxx
>
> 09/07/2005 04:37 AM
> Please respond to
> "Eclipse Platform SWT component developers list."
>
>
>                  
> To
>                  platform-swt-dev@xxxxxxxxxxx
> cc
>                  
> Subject
>                  [platform-swt-dev] popup menu
>
>
>
>                  
>
>
>
>
>
> Hi,
>
> I have implemented a component by subclassing the Canvas class. My
> problem appears when I set a Menu on it (popup): when displayed a "Input
> Method" menu item is automaticaly added (under Linux).
>
> It seems to be related to the createIMMenu() methods in Menu.class. But
> I have no Idea how to "switch it off".
>
>
> Thanks for your help,
>
> Frederic
>
>
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
>------------------------------------------------------------------------
>
>_______________________________________________
>platform-swt-dev mailing list
>platform-swt-dev@xxxxxxxxxxx
>https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>  
>

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top