I wrote:
>> In fltk1 / fluid, if I create the following conceptual hierarchy
>> 
>> UserInterface : WidgetClass (set to Fl_Double_Window)
>>  m_menuGroup : Group
>>   m_menuBar : Menu_Bar
>>    m_fileMenu : Submenu
>>     m_quitMenuItem : MenuItem


Then I explained further:
> //static
> void UserInterface::onFileQuit1(Fl_Menu_Item* widget)
> {
>     UserInterface* userInterface = ?; // what goes here?
>     userInterface->doFileQuit(widget, userInterface);
> }


OK, after adding print statements and experimenting in fluid, I've
found what appears to work. The hard part was working out which
widget was being passed to the static callback, and its type.

I added a fileItem MenuItem, and called printf in the Callback tab
in fluid, and found that fluid created the static member function:

//static
void UserInterface::cb_m_fileItem(Fl_Menu_* o, void* v) {
  ((UserInterface*)(o->parent()->parent()->user_data()))->cb_m_fileItem_i(o,v);
}

Printf's showed that the Fl_Menu_* o parameter corresponds to the
Fl_Menu_Bar* m_menuBar. I don't understand why fluid also includes
the additiona ->user_data() call. I've reduced the onFileQuit1 and
onFileQuit2 static member functions into just onFileQuit:

//static
void UserInterface::onFileQuit(Fl_Menu_* widget) {
  Fl_Menu_Bar* menuBar = (Fl_Menu_Bar*)widget;
  Fl_Group* menuGroup = (Fl_Group*)(menuBar->parent());
  UserInterface* userInterface = (UserInterface*)(menuGroup->parent());
  userInterface->doFileQuit(widget, userInterface);
}

which is just a more explicit version of what fluid generated, but
without the confusing user_data() call, so that I will know what I
have to modify if I change the hierarchy in the future.

So to answer my own questions:

> 1. What widget type do I need in the xxFileQuit() declarations ?

The callback needs an Fl_Menu_* parameter corresponding to m_menuBar

> 2. What parent() magic do I need to get onFileQuit1() to work ?

UserInterface* userInterface = (UserInterface*)(o->parent()->parent());

> 3. Is there an obscure fluid way to pass 'this' to onFileQuit2() ?

I don't know the answer to this, but I suspect that there is not.

Cheers
Duncan


# data file for the Fltk User Interface Designer (fluid)
version 1.0109 
header_name {.h} 
code_name {.cxx}
decl {\#include <stdio.h>} {} 

widget_class UserInterface {
  user_data this
  callback onWindowClose open
  xywh {977 21 200 100} type Double
  class Fl_Double_Window visible
} {
  Fl_Group m_menuGroup {open
    xywh {0 0 200 25}
  } {
    Fl_Menu_Bar m_menuBar {open
      xywh {0 0 200 25}
    } {
      Submenu m_fileMenu {
        label File open
        xywh {0 0 63 25}
      } {
        MenuItem m_fileQuit {
          label Quit
          callback onFileQuit selected
          xywh {0 0 30 25}
        }
        MenuItem m_fileItem {
          label item
          callback {printf("fileItemCallback(widget=%p, userData=%p)\\n", o, 
v);}
          xywh {0 0 30 20}
        }
      }
    }
  }
  Function {onWindowClose(Fl_Double_Window* widget, void* userData)} 
{return_type {static void}
  } {
    code {UserInterface* userInterface = (UserInterface*)userData;
userInterface->doWindowClose(widget, userData);} {}
  }
  Function {doWindowClose(Fl_Double_Window* widget, void *userData)} 
{return_type void
  } {
    code {printf("doWindowClose(widget=%p, userData=%p\\n", widget, userData);} 
{}
  }
  Function {onFileQuit(Fl_Menu_* widget)} {return_type {static void}
  } {
    code {Fl_Menu_Bar* menuBar = (Fl_Menu_Bar*)widget;
Fl_Group* menuGroup = (Fl_Group*)(menuBar->parent());
UserInterface* userInterface = (UserInterface*)(menuGroup->parent());
userInterface->doFileQuit(widget, userInterface);} {}
  }
  Function {doFileQuit(Fl_Menu_* widget, void* userData)} {return_type void
  } {
    code {printf("doFileQuit(widget=%p, userData=%p\\n", widget, userData);} {}
  }
} 

Function {} {open
} {
  code {UserInterface ui(200, 100, "Ui");
ui.show(argc, argv);} {}
} 



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to