Re: [Fxruby-users] MenuTitle and MiddleMouseButton
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <jl...@cf...> - 2003-09-10 14:31:13
|
Recheis Meinrad wrote: > the middle mouse button has no specific function in a gui. > that's why i chose it to select widgets in my dialog editor. > but the problem is: > > MenuTitle, MenuCommand, ComboBox and others# > dont support this event. > > what can i overwrite in menutitle to be able to receive > SEL_MIDDLEBUTTONPRESS? You are right, it looks like FXMenuTitle doesn't forward SEL_MIDDLEBUTTONPRESS (or SEL_MIDDLEBUTTONPRESS, or SEL_RIGHTBUTTONxxx) to its target. I probably need to check with Jeroen to see why he did that and if it can be changed for FOX 1.2. At any rate, the ugly workaround for FOX 1.0 is to subclass FXMenuTitle, intercept the SEL_MIDDLEBUTTONPRESS message that the event loop (FXApp) sends directly to the FXMenuTitle, and then do what we would have expected it to do in the first place (forward the message to the target). Below is some sample code to get you started: require 'fox' include Fox class MyMenuTitle < FXMenuTitle include Responder def initialize(*args) super FXMAPFUNC(SEL_MIDDLEBUTTONPRESS, 0, :onMiddleBtnPress) FXMAPFUNC(SEL_MIDDLEBUTTONRELEASE, 0, :onMiddleBtnRelease) end def onMiddleBtnPress(sender, sel, evt) if enabled? if (target != nil) && (target.handle(self, MKUINT(selector, SEL_MIDDLEBUTTONPRESS), evt) != 0) return 1 end end return 0 end def onMiddleBtnRelease(sender, sel, evt) if enabled? if (target != nil) && (target.handle(self, MKUINT(selector, SEL_MIDDLEBUTTONRELEASE), evt) != 0) return 1 end end return 0 end end class MainWindow < FXMainWindow def initialize(app) # Initialize base class super(app, "Middle Mouse Test", nil, nil, DECOR_ALL, 0, 0, 200, 200) # Menubar menubar = FXMenubar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X) # File menu filemenu = FXMenuPane.new(self) FXMenuCommand.new(filemenu, "New") FXMenuCommand.new(filemenu, "Open...") FXMenuCommand.new(filemenu, "Save") FXMenuCommand.new(filemenu, "Quit", nil, app, FXApp::ID_QUIT) menuTitle = MyMenuTitle.new(menubar, "&File", nil, filemenu) menuTitle.connect(SEL_MIDDLEBUTTONPRESS) { puts "foo" } end # Start def create # Create window super # Show the main window show(PLACEMENT_SCREEN) end end if __FILE__ == $0 # Make an application application = FXApp.new("MiddleMouse", "FXRuby") # Create main window window = MainWindow.new(application) # Create the application application.create # Run application.run end Hope this helps, Lyle |