Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Browser widget mousedown event.

I am creating a browser based kiosk solution and was hoping to use SWTs browser widget to run a web application inside.  One requirement I have is the use of an "attract loop" which becomes active after a set amount of user inactivity.  This timer is reset everytime there is a mouse click.  I tried adding a mousedown event listener (addMouseListener) to the org.eclipse.swt.browser.Browser object but it doesn't seem to capture the mousedown event.  My guess is when a click occurs in the browser window that is created the mousedown event is occurring inside the IE object that SWT has instantiated and this mousedown event is not passed up to the org.eclipse.swt.browser.Browser object that wraps it.  Is this a safe assumption?  Is there a workaround to capturing a mouseclick in the browser window?

Thanks for your help.

Seth

A very dirty and plataform specific workaround is this (I used with success for myself).
Hope this helps.

Antonio

--------------

import org.eclipse.swt.*;
import org.eclipse.swt.awt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.win32.*;


public class OSHandler
{
 Callback callback;
 int oldProc, newProc;
 int controlToBindHandle;


 OSHandler(Browser browser)
 {
  controlToBindHandle=browser.handle;

  oldProc=OS.GetWindowLong(controlToBindHandle, OS.GWL_WNDPROC);
  callback=new Callback(this, "windowProc", 4);
  newProc=callback.getAddress();
  OS.SetWindowLong(controlToBindHandle, OS.GWL_WNDPROC, newProc);
 }

 // call this before disposing the browser!
 public void restoreWndProc()
 {
  OS.SetWindowLong(controlToBindHandle, OS.GWL_WNDPROC, oldProc);
 }

 public void leftButtonDown(int childHwnd, int x, int y)
 {
  System.out.println("leftButtonDown: x = "+x+", y = "+y);
 }

 public void middleButtonDown(int childHwnd, int x, int y)
 {
  System.out.println("middleButtonDown: x = "+x+", y = "+y);
 }

 public void rightButtonDown(int childHwnd, int x, int y)
 {
  System.out.println("rightButtonDown: x = "+x+", y = "+y);
 }




 int windowProc(int hwnd, int msg, int wParam, int lParam)
 {
  int res;

  switch (msg)
  {
   case OS.WM_PARENTNOTIFY:
   {
    int fwEvent=(short)(wParam & 0xFFFF); // event flags
    int childHwnd=(short)(wParam >> 16);  // identifier of child window

    switch (fwEvent)
    {
     case OS.WM_LBUTTONDOWN:
     case OS.WM_MBUTTONDOWN:
     case OS.WM_RBUTTONDOWN:
     {
      int x=(short)(lParam & 0xFFFF);
      int y=(short)(lParam >> 16);

      switch (fwEvent)
      {
       case OS.WM_LBUTTONDOWN:leftButtonDown(childHwnd, x, y);break;
       case OS.WM_MBUTTONDOWN:middleButtonDown(childHwnd, x, y);break;
       case OS.WM_RBUTTONDOWN:rightButtonDown(childHwnd, x, y);break;
      }
     }
    }

    res=OS.CallWindowProc(oldProc, hwnd, msg, wParam, lParam);
   } break;

   default:res=OS.CallWindowProc(oldProc, hwnd, msg, wParam, lParam);
  }


  return res;
 }



}















Back to the top