Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] MenuItem's not generating ArmEvents

On Windows CE, MenuItem's don't seem to generate ArmEvents when they are 
clicked.  I've tested this against the XP release as well, and it works 
fine there.  This bug seems to be only on CE.

You can check this bug using the very same code from one of SWT snippets.  
I have attached that same code here for your convenience.  

Do you think this might be a platform limitation, or a genuine bug?

This bug was tested using the 3.1M1 release, but was also present in 3.0.

Fred Potter
fpotter@xxxxxxxxxxxxxxxxx
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * Control example snippet: update a status line when an item is armed
 *
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Snippet152 {

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    FormLayout layout = new FormLayout();
    shell.setLayout(layout);
    final Label label = new Label(shell, SWT.BORDER);
    Listener armListener = new Listener() {
        public void handleEvent(Event event) {
            MenuItem item = (MenuItem) event.widget;
            label.setText(item.getText());
            label.update();
        }
    };
    Listener showListener = new Listener() {
        public void handleEvent(Event event) {
            Menu menu = (Menu) event.widget;
            MenuItem item = menu.getParentItem();
            if (item != null) {
                label.setText(item.getText());
                label.update();
            }
        }
    };
    Listener hideListener = new Listener() {
        public void handleEvent(Event event) {
            label.setText("");
            label.update();
        }
    };
    FormData labelData = new FormData();
    labelData.left = new FormAttachment(0);
    labelData.right = new FormAttachment(100);
    labelData.bottom = new FormAttachment(100);
    label.setLayoutData(labelData);
    Menu menuBar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(menuBar);
    MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
    fileItem.setText("File");
    fileItem.addListener(SWT.Arm, armListener);
    MenuItem editItem = new MenuItem(menuBar, SWT.CASCADE);
    editItem.setText("Edit");
    editItem.addListener(SWT.Arm, armListener);
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    fileMenu.addListener(SWT.Hide, hideListener);
    fileMenu.addListener(SWT.Show, showListener);
    fileItem.setMenu(fileMenu);
    String[] fileStrings = { "New", "Close", "Exit" };
    for (int i = 0; i < fileStrings.length; i++) {
        MenuItem item = new MenuItem(fileMenu, SWT.PUSH);
        item.setText(fileStrings[i]);
        item.addListener(SWT.Arm, armListener);
    }
    Menu editMenu = new Menu(shell, SWT.DROP_DOWN);
    editMenu.addListener(SWT.Hide, hideListener);
    editMenu.addListener(SWT.Show, showListener);
    String[] editStrings = { "Cut", "Copy", "Paste" };
    editItem.setMenu(editMenu);
    for (int i = 0; i < editStrings.length; i++) {
        MenuItem item = new MenuItem(editMenu, SWT.PUSH);
        item.setText(editStrings[i]);
        item.addListener(SWT.Arm, armListener);
    }
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}

}


Back to the top