/********************************************************************************
*  Menu.cpp                                                                     *
/*******************************************************************************/

#include <fx.h>

// Generated by reswrap from file new_gif.gif 
const unsigned char new_gif[]=
{
  0x47,0x49,0x46,0x38,0x39,0x61,0x10,0x00,0x10,0x00,0xf2,0x00,0x00,0xb2,0xc0,0xdc,
  0xff,0xff,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0xbf,0xbf,0xbf,0xff,0xff,0xff,0x00,
  0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x01,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,
  0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x03,0x44,0x08,0x0a,0xb1,0xfe,0xab,0x41,0xd8,
  0xea,0x7c,0x21,0x8b,0x2d,0x68,0xfe,0x9f,0x30,0x5c,0x1f,0x41,0x14,0x42,0x31,0x62,
  0x42,0x40,0x04,0x05,0x1a,0xaf,0x4e,0x7b,0xc6,0xe2,0xa0,0x3f,0x6d,0xec,0xfb,0x83,
  0xce,0x22,0xf5,0xfb,0x05,0x6b,0x45,0xa3,0x50,0x41,0x4c,0xaa,0x96,0x80,0x66,0xf2,
  0x38,0x74,0xce,0xa0,0x39,0x9d,0x56,0x8b,0xe5,0x78,0xbd,0x80,0x04,0x00,0x3b
};


// Window class
class Window : public FXMainWindow
{
  FXDECLARE(Window)
protected:
  Window() {}

protected:
  FXMenubar *Menubar;
  FXMenuPane *FileMenu;
  FXMenuPane *OptionMenu;
  FXMenuPane *SubMenu;
  FXMenuPane *SubSubMenu;
  FXMenuPane *RadioMenu;
  FXMenuPane *HelpMenu;
  FXuint choice;

public:
  long onNew(FXObject*,FXSelector,void*);
  long onOption1(FXObject*,FXSelector,void*);
  long onOption2(FXObject*,FXSelector,void*);
  long onCmdRadio(FXObject*,FXSelector,void*);
  long onUpdRadio(FXObject*,FXSelector,void*);
  long onAbout(FXObject*,FXSelector,void*);

public:
  // Messages for our class
  enum
  {
    ID_NEW = FXMainWindow::ID_LAST,
    ID_OPTION_1,
    ID_OPTION_2,
    ID_RADIO_1,
    ID_RADIO_2,
    ID_RADIO_3,
    ID_ABOUT,
    ID_LAST
  };

public:
  Window(FXApp *app);
  virtual void create();
  virtual ~Window();
};

// Message Map for the Window class
FXDEFMAP(Window) WindowMap[]=
{
  //____Message_Type_________________ID(S)__________________________Message_Handler___
  FXMAPFUNC (SEL_COMMAND,  Window::ID_NEW,                          Window::onNew),
  FXMAPFUNC (SEL_COMMAND,  Window::ID_OPTION_1,                     Window::onOption1),
  FXMAPFUNC (SEL_COMMAND,  Window::ID_OPTION_2,                     Window::onOption2),
  FXMAPFUNCS(SEL_COMMAND,  Window::ID_RADIO_1,Window::ID_RADIO_3,   Window::onCmdRadio),
  FXMAPFUNCS(SEL_UPDATE,   Window::ID_RADIO_1,Window::ID_RADIO_3,   Window::onUpdRadio),
  FXMAPFUNC (SEL_COMMAND,  Window::ID_ABOUT,                        Window::onAbout)
};

// Macro for the ScribbleApp class hierarchy implementation
FXIMPLEMENT(Window,FXMainWindow,WindowMap,ARRAYNUMBER(WindowMap))


/*******************************************************************************/


// Make window
Window::Window(FXApp* App):
  FXMainWindow (App,"Menu",NULL,NULL,DECOR_ALL,0,0,400,200)
{
  // Make menu bar
  Menubar=new FXMenubar(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X);

  // File menu
  FileMenu = new FXMenuPane(this);
    new FXMenuCommand (FileMenu,"&New",new FXGIFIcon(getApp(),new_gif),this,ID_NEW);
    new FXMenuSeparator (FileMenu);
    new FXMenuCommand (FileMenu,"&Quit\tCtl+Q",NULL,getApp(),FXApp::ID_QUIT);
  new FXMenuTitle (Menubar,"&File",NULL,FileMenu);

  // Option menu
  OptionMenu = new FXMenuPane(this);
    new FXMenuCommand (OptionMenu,"Option 1",NULL,this,ID_OPTION_1);
    new FXMenuCommand (OptionMenu,"Option 2",NULL,this,ID_OPTION_2);
  new FXMenuTitle(Menubar,"&Option",NULL,OptionMenu);

  // SubMenu
  SubMenu = new FXMenuPane(this);
    SubSubMenu = new FXMenuPane(this);
      new FXMenuCommand(SubSubMenu,"&One");
      new FXMenuCommand(SubSubMenu,"&Two");
      new FXMenuCommand(SubSubMenu,"Th&ree");
      new FXMenuCommand(SubSubMenu,"&Four");
    new FXMenuCascade (SubMenu,"Menu",NULL,SubSubMenu);
  new FXMenuTitle(Menubar,"&Sub",NULL,SubMenu);

  // Radio Menu
  RadioMenu = new FXMenuPane(this);
    new FXMenuCommand (RadioMenu,"Radio 1",NULL,this,ID_RADIO_1,0);
    new FXMenuCommand (RadioMenu,"Radio 2",NULL,this,ID_RADIO_2,0);
    new FXMenuCommand (RadioMenu,"Radio 3",NULL,this,ID_RADIO_3,0);
  new FXMenuTitle(Menubar,"&Radio",NULL,RadioMenu);
  choice = 1;
  onCmdRadio (RadioMenu,ID_RADIO_1,NULL);

  // Help Menu
  HelpMenu = new FXMenuPane(this);
    new FXMenuCommand (HelpMenu,"&About",NULL,this,ID_ABOUT);
  new FXMenuTitle(Menubar,"&Help",NULL,HelpMenu,LAYOUT_RIGHT);

  // Install an accelerator for Alt-F4 keys combination
  getAccelTable()->addAccel(fxparseaccel("Alt-F4"),getApp(),MKUINT(FXApp::ID_QUIT,SEL_COMMAND));
}


// Clean up
Window::~Window()
{
  delete Menubar;
  delete FileMenu;
}

// Start
void Window::create()
{
  FXMainWindow::create();
  show(PLACEMENT_SCREEN);
}

// File/New
long Window::onNew(FXObject*,FXSelector,void*)
{
  FXMessageBox::information(this,MBOX_OK,"Information","Menu: File\\New");
  return 1;
}


// Option/Option1

long Window::onOption1(FXObject *sender,FXSelector,void*)

{

  FXMenuCommand *cmd = (FXMenuCommand*)sender;

  cmd -> isChecked() ? cmd -> uncheck () : cmd -> check ();
  return 1;

}


// Option/Option2
long Window::onOption2(FXObject *sender,FXSelector,void*)
{
  FXMenuCommand *cmd = (FXMenuCommand*)sender;
  cmd -> isChecked() ? cmd -> uncheck () : cmd -> check ();
  return 1;
}

// Set choice
long Window::onCmdRadio(FXObject*,FXSelector sel,void*)
{
  choice = SELID(sel);
  return 1;
}

// Update menu
long Window::onUpdRadio(FXObject* sender,FXSelector sel,void*)
{
  FXMenuCommand *cmd=(FXMenuCommand*)sender;
  (SELID(sel)==choice) ? cmd->checkRadio() : cmd->uncheckRadio();
  return 1;
}

// Help/About
long Window::onAbout(FXObject*,FXSelector,void*)
{
  FXMessageBox::information(this,MBOX_OK,"About","FOX menu example\nJanusz Ganczarski 2001");
  return 1;
}

/*******************************************************************************/

// Main program
int main(int argc,char *argv[])
{
  // Make application
  FXApp Application("Menu","Test");

  // Open display
  Application.init(argc,argv);

  // Create window object
  new Window(&Application);

  // Create app
  Application.create();

  // Run
  return Application.run();
}