Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] 'Create' event

Hello Damien,

There is no SWT.Create event, yet. But, if you are looking for an event to manage the styling try using the SWT.Skin event. It is sent when the widget is created and when Widget.reskin() is called. Please see Snippet333 (http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet333.java) for an example on using it.

Thanks,

Lakshmi P Shanmugam



On Mon, Dec 2, 2013 at 8:16 PM, Damien Dudouit <ddudouit@xxxxxxx> wrote:
Hello,

I have been using SWT professionally for many years, creating many custom widgets, and I'm missing the ability to do the following :

    Display.getDefault().addFilter(SWT.Create, new Listener() {
      public void handleEvent(Event event) {
        ...
      }
    });

The SWT.Create constant and event do no exist yet. It is the opposite to SWT.Dispose.

It probably doesn't make sense to notify this event at the widget level since the widget must be created/instanciated to add a listener to it but it does at the Display.addFilter level.

The main use for me would be to manage styling accross the application :

    Display.getDefault().addFilter(SWT.Create, new Listener() {
      public void handleEvent(Event event) {
        if (event.widget instanceof Control) {
          ((Control) event.widget).setFont(myDefaultFont);
        }
      }
    });

Another use could be when implementing a widgets tree inspector.


At the end of the Control constructor, it could be something like this :

public Control (Composite parent, int style) {
    super (parent, style);
    this.parent = parent;
    createWidget ();

    Event event = new Event();
    event.type = SWT.Create;
    event.widget = this;
    display.filterEvent(event);

}

In any case, it must come after the setDefaultFont () method to be useful for styling :

void createWidget () {
    state |= DRAG_DETECT;
    foreground = background = "">     checkOrientation (parent);
    createHandle ();
    checkBackground ();
    checkBuffered ();
    checkComposited ();
    register ();
    subclass ();
    setDefaultFont ();
    checkMirrored ();
    checkBorder ();
    checkGesture ();
    if ((state & PARENT_BACKGROUND) != 0) {
        setBackground ();
    }
}

Best regards,

Damien

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




--
Lakshmi

Back to the top