Thanks again for the comments. I think there must be an error of mine, but I
cannot find it/them. I manage to reduce the code to ~150 lines, which I copy
below. If someone out there dares compiling it and giving it a try, I would be
very greatful for the comments.
The key point is the function _buildMenuBar(). I still have the problem that
not all the menu entries get printed, and the menu does not work. Unless I take
out the for() loop at the end of the _buildMenuBar() function. But I would like
to have that for() loop to search for a particular item and inactivate it, just
as it is made in Erco's tips page.
TIA
p.
----------------------------------------------------
The compile line reads:
g++ -I. -fexceptions -O2 -Wall `fltk-config --cxxflags` -L. -O2 `fltk-config
--ldflags` -o crazymenu crazymenu.cxx
and the ugly code is "crazymenu.cxx":
#include <iostream>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
class ChasePoints : public Fl_Double_Window
{
public:
ChasePoints( void )
: Fl_Double_Window( 991, 644 ), _menuBar( 0 ),
_mainWindowWidth( 991 ), _mainWindowHeight( 644 )
{ _buildMenuBar();
Fl_Double_Window::end();
Fl_Double_Window::resizable( this );
Fl_Double_Window::size_range( _mainWindowWidth, _mainWindowHeight );
}
virtual ~ChasePoints() { if( _menuBar ) delete _menuBar; }
Fl_Double_Window* mainWindow( void )
{ return static_cast< Fl_Double_Window* >( this ); }
static void openSequence_handler( Fl_Widget*, void * );
static void closeSequence_handler( Fl_Widget*, void* );
static void saveFile_handler( Fl_Widget*, void* );
static void saveAsFile_handler( Fl_Widget*, void* );
static void quit_handler( Fl_Widget*, void* );
static void copySequence_handler( Fl_Widget*, void* );
static void pasteSequence_handler( Fl_Widget*, void* );
static void pasteAsNewSequence_handler( Fl_Widget*, void* );
static void newList_handler( Fl_Widget*, void* );
static void preferences_handler( Fl_Widget*, void* );
static void monitor_handler( Fl_Widget*, void* );
static void showHelp_handler( Fl_Widget*, void* );
static void info_handler( Fl_Widget*, void* );
protected:
void openSequence_handler( Fl_Widget* )
{ std::cout << "ChasePoints::openSequence()." << std::endl; }
void closeSequence_handler( Fl_Widget* )
{ std::cout << "closeSequence()." << std::endl; }
void saveFile_handler( Fl_Widget* )
{ std::cout << "ChasePoints::saveFile()." << std::endl; }
void saveAsFile_handler( Fl_Widget* )
{ std::cout << "ChasePoints::saveAsFile()." << std::endl; }
void quit_handler( Fl_Widget* )
{ std::cout << "ChasePoints::quit()." << std::endl; }
void copySequence_handler( Fl_Widget* )
{ std::cout << "ChasePoints::copySequence()." << std::endl; }
void pasteSequence_handler( Fl_Widget* )
{ std::cout << "ChasePoints::pasteSequence()." << std::endl; }
void pasteAsNewSequence_handler( Fl_Widget* )
{ std::cout << "ChasePoints::pasteAsNewSequence()." << std::endl; }
void newList_handler( Fl_Widget* )
{ std::cout << "ChasePoints::newList()." << std::endl; }
void preferences_handler( Fl_Widget* )
{ std::cout << "ChasePoints::preferences()." << std::endl; }
void monitor_handler( Fl_Widget* ) { }
void showHelp_handler( Fl_Widget* )
{ std::cout << "ChasePoints::showHelp()." << std::endl; }
void info_handler( Fl_Widget* )
{ std::cout << "ChasePoints::info()." << std::endl; }
private:
Fl_Menu_Bar* _menuBar;
int _mainWindowWidth, _mainWindowHeight;
void _buildMenuBar( void )
{ _menuBar = new Fl_Menu_Bar( 0, 0, _mainWindowWidth, 30 );
_menuBar->add( "&File", 0, 0, 0, FL_SUBMENU );
_menuBar->add( "File/&Open sequence", FL_CTRL + 'o',
(Fl_Callback*)openSequence_handler, this, 0 );
_menuBar->add( "File/&Close sequence", FL_CTRL + 'w',
(Fl_Callback*)closeSequence_handler, this, 0 );
_menuBar->add( "File/&Save", FL_CTRL + 's',
(Fl_Callback*)saveFile_handler, this, 0 );
_menuBar->add( "File/&Save as", FL_CTRL + FL_SHIFT + 's',
(Fl_Callback*)saveAsFile_handler, this, 0 );
_menuBar->add( "File/&Quit", FL_CTRL + 'q',
(Fl_Callback*)quit_handler, this, 0 );
_menuBar->add( "&Edit", 0, 0, 0, FL_SUBMENU );
_menuBar->add( "Edit/&Copy", FL_CTRL + 'c',
(Fl_Callback*)copySequence_handler, this, 0 );
_menuBar->add( "Edit/&Paste", FL_CTRL + 'p',
(Fl_Callback*)pasteSequence_handler, this, 0 );
_menuBar->add( "Edit/&Paste as new", FL_CTRL + FL_SHIFT + 'p',
(Fl_Callback*)pasteAsNewSequence_handler, this, 0 );
_menuBar->add( "&View", 0, 0, 0, FL_SUBMENU );
_menuBar->add( "View/&Preferences", FL_CTRL + 'p',
(Fl_Callback*)preferences_handler, this, 0 );
_menuBar->add( "View/&Monitor", FL_CTRL + 'm',
(Fl_Callback*)monitor_handler, this, 0 );
_menuBar->add( "&Help", 0, 0, 0, FL_SUBMENU );
_menuBar->add( "Help/&Help window", FL_CTRL + 'h',
(Fl_Callback*)showHelp_handler, this, 0 );
_menuBar->add( "Help/&Info", FL_CTRL + FL_SHIFT + 'i',
(Fl_Callback*)info_handler, this, 0 );
for( int t = 0; t < _menuBar->size(); ++t )
{ Fl_Menu_Item *m = (Fl_Menu_Item*)&(_menuBar->menu()[t]);
std::cout << m->label() << std::endl;
}
}
};
void ChasePoints::openSequence_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->openSequence_handler( w ); }
void ChasePoints::closeSequence_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->closeSequence_handler( w ); }
void ChasePoints::newList_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->newList_handler( w ); }
void ChasePoints::saveFile_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->saveFile_handler( w ); }
void ChasePoints::saveAsFile_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->saveAsFile_handler( w ); }
void ChasePoints::quit_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->quit_handler( w ); }
void ChasePoints::copySequence_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->copySequence_handler( w ); }
void ChasePoints::pasteSequence_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->pasteSequence_handler( w ); }
void ChasePoints::pasteAsNewSequence_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->pasteAsNewSequence_handler( w ); }
void ChasePoints::preferences_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->preferences_handler( w ); }
void ChasePoints::monitor_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->monitor_handler( w ); }
void ChasePoints::showHelp_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->showHelp_handler( w ); }
void ChasePoints::info_handler( Fl_Widget* w, void* v )
{ ((ChasePoints*)v)->info_handler( w ); }
int main( int argc, char* argv[] )
{
ChasePoints chasePoints;
Fl_Window* window = chasePoints.mainWindow();
window->show( argc, argv );
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk