Skip to main content

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

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

Back to the top