Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Subclassing Text control.


I'm working of a code that will be shipped on Windows only.
As I need to get raw keyCode from window API (as I need virtual keys inputs), I  would like to redefine Control.WM_KEYDOWN(int,int) method.
I choose to subclass org.eclipse.swt.widgets.Text class and redefine WM_KEYDOWN() method (see code below).
Running my program produces the following ouputs:

MyText.checkSubclass()
MyText.MyText()
//hit 'k' key : output the following line 16 times (? why)
MyText.$1.modifiyText()
MyText.$1.modifiyText()
MyText.$1.modifiyText()

I'm surprised that I never see trace I've put inside redefined WM_KEYDOWN() method, whereas I can see traces I've put inside modifyListener,
even if Eclipse Java editor show me that I'm redefining this method (little green triangle in outline).

What is wrong in my code ?
How can I get raw virtual keyCode on windows using a SWT  Text control ?

I'm suspecting that as this code is including in an Eclipse plugin, it uses different ClassLoader that org.eclipse.swt plugin,
meaning that my class "org.eclipse.swt.widget.MyText" is (virtually) defined in a separate package than the "org.eclipse.swt.widget.Control"
class. And because WM_KEYDOWN() method have package visibilty, the method I think I'm redefining in the class MyText() is simply
another method which doesn't redefine Control.WM_KEYDOW.

Thanks for your help.

Arnaud.

PS: Code for MyText class:

package org.eclipse.swt.widgets; //please note I'm using original swt's package name, even if my class is inside another plugin.

import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.internal.win32.LRESULT;
import org.eclipse.swt.internal.win32.OS;

public class MyText extends Text
{
  public MyText( Composite c, int style )
  {
      super( c, style );
System.out.println("MyText.MyText()");
      addModifyListener( new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            MyText.this.setText(""); //autoerase text
System.out.println("MyText.$1.modifiyText()");            
        }
      });
  }
 
  LRESULT WM_KEYDOWN (int wParam, int lParam)
  {
System.out.println("MyText.WM_KEYDOWN("+wParam+", "+lParam+")");
      return super.WM_KEYDOWN( wParam, lParam );
  }
 
  protected void checkSubclass()
  {
System.out.println("MyText.checkSubclass()");  
  }
}

Back to the top