void addWindowSubclass() { long /*int*/ hwndChild = OS.GetWindow(browser.handle, OS.GW_CHILD); if (SubclassProc == null) { SubclassProc = new Callback(MozillaDelegate.class, "windowProc", 4); // $NON-NLS-1$ MozillaProc = OS.GetWindowLongPtr(hwndChild, OS.GWL_WNDPROC); } OS.SetWindowLongPtr(hwndChild, OS.GWL_WNDPROC, SubclassProc.getAddress()); }
private void installMouseHook() { if (mouseCallback == null) { mouseCallback = new Callback(this, "MouseProc", 3); newAddress = mouseCallback.getAddress(); if (newAddress == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); int threadId = Extension.GetCurrentThreadId(); oldAddress = Extension.SetWindowsHookEx(Win32.WH_MOUSE, newAddress, 0, threadId); shell.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (mouseCallback != null) { Extension.UnhookWindowsHookEx(oldAddress); mouseCallback.dispose(); mouseCallback = null; newAddress = 0; } } }); } }
static { menuItemSelectedFunc = new Callback(ToolBar.class, "MenuItemSelectedProc", 2); if (menuItemSelectedFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); }
/** See Apple Technical Q&A 1079 (http://developer.apple.com/qa/qa2001/qa1079.html) */ @Override public void initPlatformMenu(Display display, final PlatformMenuActions actions) { // Callback target Object target = new Object() { int commandProc(int nextHandler, int theEvent, int userData) { if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) { HICommand command = new HICommand(); OS.GetEventParameter( theEvent, OS.kEventParamDirectObject, OS.typeHICommand, null, HICommand.sizeof, null, command); switch (command.commandID) { case kHICommandPreferences: actions.doPreferences(); return OS.noErr; case kHICommandAbout: actions.doAbout(); return OS.noErr; case OS.kHICommandQuit: actions.doExitApplication(); return OS.noErr; default: break; } } return OS.eventNotHandledErr; } }; final Callback commandCallback = new Callback(target, "commandProc", 3); // $NON-NLS-1$ int commandProc = commandCallback.getAddress(); if (commandProc == 0) { commandCallback.dispose(); return; // give up } // Install event handler for commands int[] mask = new int[] {OS.kEventClassCommand, OS.kEventProcessCommand}; OS.InstallEventHandler( OS.GetApplicationEventTarget(), commandProc, mask.length / 2, mask, 0, null); // create About Eclipse menu command int[] outMenu = new int[1]; short[] outIndex = new short[1]; if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, outMenu, outIndex) == OS.noErr && outMenu[0] != 0) { int menu = outMenu[0]; int l = fAboutActionName.length(); char buffer[] = new char[l]; fAboutActionName.getChars(0, l, buffer, 0); int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, buffer, l); OS.InsertMenuItemTextWithCFString(menu, str, (short) 0, 0, kHICommandAbout); OS.CFRelease(str); // add separator between About & Preferences OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, OS.kMenuItemAttrSeparator, 0); // enable pref menu OS.EnableMenuCommand(menu, kHICommandPreferences); // disable services menu OS.DisableMenuCommand(menu, kHICommandServices); } // schedule disposal of callback object display.disposeExec( new Runnable() { public void run() { commandCallback.dispose(); } }); }