[fxruby-users] FXMenuTiltle with no focus - A Workaround
Gérard Ménochet
gerard.menochet at wanadoo.fr
Fri Oct 27 17:13:11 EDT 2006
Hi,
For those who are interested, I think I have found a decent solution for a
little problem which was a very very big concern for me.
(Fox 1.6.0)
The workaround does nothing with FXMenuTitle (eh oui), just SEL_FOCUSIN ,
SEL_UPDATE on FXMenubar and a
small method - getLastObjectWithFocus() - cast an eye on this program and
try it !!!!
require 'fox16'
include Fox
class MenuTitleWorkaround < FXMainWindow
def initialize(pApp)
@focus = nil
super(pApp, "FXMenuTitle - Workaround", nil, nil, DECOR_ALL, 20, 20,
800, 600)
menuBar = FXMenuBar.new(self, LAYOUT_SIDE_TOP | LAYOUT_FILL_X)
menuBar.connect(SEL_FOCUSIN) do |sender, selector, data|
if @focus != nil
@focus.setFocus()
@focus = nil
end
0
end
menuBar.connect(SEL_UPDATE) do |sender, selector, data|
@focus = getLastObjectWithFocus()
0
end
menuPane = FXMenuPane.new(menuBar)
FXMenuCommand.new( menuPane, "&firstMenuCommand")
a = FXMenuCommand.new( menuPane, "&Quit")
a.connect(SEL_COMMAND) do |sender, selector, data|
getApp.handle(self, MKUINT(FXApp::ID_QUIT, SEL_COMMAND), nil)
end
self.accelTable.addAccel(fxparseAccel("Alt+F4"), getApp(),
FXSEL(SEL_COMMAND, FXApp::ID_QUIT))
FXMenuTitle.new( menuBar, "&File", nil, menuPane)
menuPane = FXMenuPane.new(menuBar)
FXMenuCommand.new( menuPane, "&What you want")
FXMenuCommand.new( menuPane, "&Ect")
FXMenuTitle.new( menuBar, "&Edit", nil, menuPane)
splitter =
FXSplitter.new(self,LAYOUT_FILL_X|LAYOUT_FILL_Y|SPLITTER_TRACKING|SPLITTER_V
ERTICAL|SPLITTER_REVERSED)
c = FXText.new(splitter, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y)
c.setText("Feeding gas into centrifuges can produce fuel for nuclear power
plants")
d = FXText.new(splitter, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y)
d.setText("The move is being seen as an act of international defiance by
Teheran")
d.setFocus()
end
def getLastObjectWithFocus(objectClass = nil)
childrenArray = self.children
objectWithFocusArray = []
childrenArray.each do |child|
if child.hasFocus?() and (objectClass == nil or
child.kind_of?(objectClass))
objectWithFocusArray << child
end
child.children.each do |grandChild|
childrenArray << grandChild
end
end
if objectWithFocusArray.length > 0
return objectWithFocusArray[objectWithFocusArray.length - 1 ]
else
return nil
end
end
def create
super
show(PLACEMENT_SCREEN)
end
end
exit if __FILE__ != $0
puts Fox.fxrubyversion()
app=FXApp.new()
app.threadsEnabled=false # ok
app.setDefaultCursor(DEF_MOVE_CURSOR,FXCursor.new(app))
w=MenuTitleWorkaround.new(app)
app.create
w.show
app.run
see you
Gérard Ménochet
More information about the fxruby-users
mailing list