|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Intercepting and reviewing FXText messages, especially KEY_PRESS|SEL_INSERTEDHi All,
I am new to the list, and FXRuby, this being my first post. I have hit a little snag, I am futzing around with a texteditor and everything works fine, but I would like to add in a snippet like functionality, but I seem to be at a loss for how to do it. How I imagine it would be done is. I have created a Dispatcher class, this class handles most messages in the program, adding a new tab/editor, displaying x or why. What I would like to do is have my Dispatcher class intercept messages to and from the FXText, and then perform some actions on the FXText. If someone presses the TAB key, I would want to intercept that, grab the text before the cursor, see if a snippet has been defined, if so, add the text in, otherwise, send the TAB key to the FXText like normal and let it do it's thing. Some code: #dispatcher.rb class Dispatcher def initialize(owner,sender,sel,event) puts "Dispatcher Called with: #{owner}, #{sender}, #{sel}, #{event}" end end #content_pane.rb ... def add_buffer(name) FXHorizontalFrame.new(@tab_book, FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y) do |frame| @buffers << FXText.new(frame,:opts => TEXT_WORDWRAP|LAYOUT_FILL) @current_buffer = @buffers.last @current_buffer.setFocus end end ... Essentially, what I imagine is this: #content_pane.rb def add_buffer(name) ... #pseudo Code @buffers.last.connect(message) do |sender,sel,event| Dispatcher.new(self,sender,sel,event) end #end pseudo code ... end #dispatcher.rb ... #pseudo code def handle_text_widget_message(sender,sel,event) if event.code == code_i_want then #do something here else send_message_to(sender,sel,event) end end #end pseudocode ... I may be completely off my rocker and doing things retarded, as I am mainly a webprogrammer, and very new to GUI programming and how it works, so if there is a better, or more standard way of doing it, please point it out to me, or reference documents that might help, anything will be greatly appreciated. While writing this, I realize that I can use SEL_KEYRELEASE and get the info I want, however, I would like to get it before insertion,a nd not have to handle determining key behavior for the widget, like backspace, and insert etc. Many thanks in advance, Jason _______________________________________________ fxruby-users mailing list fxruby-users@... http://rubyforge.org/mailman/listinfo/fxruby-users |
|
|
Re: Intercepting and reviewing FXText messages, especially KEY_PRESS|SEL_INSERTEDOn Mon, May 19, 2008 at 4:55 AM, Jason Martin <jason@...> wrote:
> I may be completely off my rocker and doing things retarded, as I am mainly > a webprogrammer, and very new to GUI programming and how it works, so if > there is a better, or more standard way of doing it, please point it out to > me, or reference documents that might help, anything will be greatly > appreciated. While writing this, I realize that I can use SEL_KEYRELEASE and > get the info I want, however, I would like to get it before insertion,a nd > not have to handle determining key behavior for the widget, like backspace, > and insert etc. Well, if you catch the SEL_KEYPRESS message (instead of SEL_KEYRELEASE) you can interecept the Tab key press before any text gets inserted, right? And if you determine that there is some "snippet" text before the current cursor position, you would (I guess) insert the expanded text and then return true to indicate that your message handler handled the event and FXText's regular SEL_KEYPRESS handler doesn't need to do anything else with it. If you instead determine that there is no "snippet" text to try to expand, you'd want to return false from the message handler so that the default SEL_KEYPRESS processing kicks in. Hope this helps, Lyle > > Many thanks in advance, > Jason > > _______________________________________________ > fxruby-users mailing list > fxruby-users@... > http://rubyforge.org/mailman/listinfo/fxruby-users > _______________________________________________ fxruby-users mailing list fxruby-users@... http://rubyforge.org/mailman/listinfo/fxruby-users |
|
|
Re: Intercepting and reviewing FXText messages, especially KEY_PRESS|SEL_INSERTED
Lyle Johnson wrote:
Hi Lyle,Well, if you catch the SEL_KEYPRESS message (instead of SEL_KEYRELEASE) you can interecept the Tab key press before any text gets inserted, right? And if you determine that there is some "snippet" text before the current cursor position, you would (I guess) insert the expanded text and then return true to indicate that your message handler handled the event and FXText's regular SEL_KEYPRESS handler doesn't need to do anything else with it. If you instead determine that there is no "snippet" text to try to expand, you'd want to return false from the message handler so that the default SEL_KEYPRESS processing kicks in. Hope this helps, Lyle Thanks, that was the piece of info I was looking for, I am sure it's written somewhere, but I missed it. I didn't know that returning false would cause the keypress/message to be sent on. I guess I thought it kinda died there on the operating table... /jason _______________________________________________ fxruby-users mailing list fxruby-users@... http://rubyforge.org/mailman/listinfo/fxruby-users |
| Free Forum Powered by Nabble | Forum Help |