Thread: FLTK Event Handling

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246

    FLTK Event Handling

    In FLTK when you create a widget you may assign a callback function to it. This event handler cannot be a non static class member. From what I read and understood there are three ways you can handle the events:
    1- Let a static member do the job.
    2- Let a static member call a non static member which does the job.
    3- Create one static method which uses the user-data passed to it (callback second argument) as is called back to recognize which widget is the event source so it can call other methods to do the job respectively.

    A combination of above methods can be used of course which make the matter more complex. I can write one static member to handle all button events and another one to handle window events.

    Which method is better? What FLTK creators had in mind? FLTK documentation doesn't care to explain the matter. Is it really nice to create one static and one inline method for each event handler? is there an article to explain the matter?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by siavoshkc View Post
    This event handler cannot be a non static class member.
    GTK+ is the same way, in a C++ program. My personal preference would be to use a (private) static member that does the work directly. It involves less complexity (only one function call required), and it's a bit clearer as well. Someday, someone will create a GUI toolkit that uses modern C++ features like std::function and lambda functions for its event handlers. Until then, you just have to make do with what you have. Qt uses a slightly different mechanism, that produces automatically generated code, that hooks up events (signals) and handlers (slots) by name, catches the events, and calls the handlers directly.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    So I also use one static private function. Now the question is how to choose a specific differentiator value for each handler. For example we can give a button integer 1 and another 2 two. Then in the static member switch by that number. I look for a maintainable and preferably automatic way to do so.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I'd have a separate static member function for each control. Especially if the controls do relatively distinct things.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    I want to have one static member for all callbacks.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by siavoshkc View Post
    I want to have one static member for all callbacks.
    For what reason? How does it make the code clearer and easier to maintain?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    This static member should call non static members to handle the callback. In the mean time I have a pair of one static and one non static function for each handler (As been told by FLTK manual) which is messy.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Made only one static member which receives "this" and do the job by itself. Thanks.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. event handling help needed
    By leo2008 in forum Windows Programming
    Replies: 1
    Last Post: 11-04-2012, 04:52 AM
  2. Event handling in threaded C++
    By John Erlandsson in forum Linux Programming
    Replies: 9
    Last Post: 04-18-2012, 08:51 AM
  3. PnP event handling
    By jaypatel in forum C Programming
    Replies: 1
    Last Post: 06-24-2011, 07:00 AM
  4. Event handling
    By gvector1 in forum C# Programming
    Replies: 4
    Last Post: 07-09-2003, 03:32 AM
  5. Event Handling
    By jaypro78 in forum C++ Programming
    Replies: 1
    Last Post: 12-15-2001, 09:55 AM