/* Project CADshell Mechanical Design Research Lab Mechanical Engineering - Engineering Mechanics Dept. Michigan Technological University Copyright (C) 2001. All Rights Reserved. FILE: controls_main.h MODULE: CADshell REQUIRES LIBRARIES: libXm, libXt, libX11 AUTHOR(S): Bernie Bettig OVERVIEW ======== Class declaration for sh_MainWindow (sh_FramedControl), sh_MenuBar (sh_CompositeControl), sh_PulldownMenu (sh_CompositeControl), sh_ToolBox (sh_CompositeControl), sh_StatusBar (sh_CompositeControl). */ #if !defined(__controls_main_h) #define __controls_main_h #include "controls.h" #include /* ------------------------------------------------------------------------------ sh_MainWindow class declaration Summary: Implements main popup window of application and includes event processing loop. An sh_MainWindow control must be created before any other controls. After all other initial controls have been created, the sh_MainWindow::Run() method must be called to start event handling. There can only be one sh_MainWindow object per program. Events: "AboutToCloseProgram" - "Close" selected in main window frame popup menu. Normal Usage: int main() { sh_MainWindow *main_win = new sh_MainWindow; // Create other windows ... main_win.Run(); // this function never returns return 0; } ------------------------------------------------------------------------------ */ class sh_MainWindow : public sh_FramedControl { public: // Initialization functions sh_MainWindow(const char *caption, sh_EventHandler *m_tool = NULL); virtual void Run(); // Realizes (creates) main window and starts event loop virtual void MainLoop(); virtual void ProcessNextEvent(); // Unlike EventLoop(), this function must be called repeatedly for each event. virtual void SetCaption(const char *caption); virtual void Realize(); virtual void FlushDisplay(); virtual void StopClose() { stopClose = true; } virtual XtAppContext GetAppContext() { return app; } virtual Widget GetTopWidget() { return topWidget; } // Get Pointer to MainWindow static sh_MainWindow * GetMainWindow() { return the_mainWindow; } protected: XtAppContext app; Widget topWidget; static sh_MainWindow *the_mainWindow; // the one and only sh_MainWindow instance (pointer set in constructor) static void MainWindowCloseCB(Widget, XtPointer, XtPointer call_data ); bool stopClose; }; /* ------------------------------------------------------------------------------ sh_MenuBar class declaration Summary: implements main menu bar for application. Functions: AddPullDownMenu() - simply creates a sh_PulldownMenu instance. AddMenuButton() - creates an sh_Button; keeps track of which m_tools go with which button (e.g. to grey out inactive menu items). ConstructMenu() - called in CADshell to construct menu from file. parseMenu() - recursive function for ConstructMenu() ------------------------------------------------------------------------------ */ class sh_PulldownMenu; class sh_MenuBar : public sh_CompositeControl { public: sh_MenuBar(sh_CompositeControl *parent, sh_EventHandler *m_tool = NULL); ~sh_MenuBar(); virtual sh_PulldownMenu *AddPulldownMenu(const char *label, char key = 0, sh_CompositeControl *parent = 0); virtual void AddMenuButton(sh_CompositeControl *parent, sh_EventHandler *m_tool, const char *label = 0, char key = 0); virtual Widget GetMenuWidget(sh_EventHandler *t); virtual void ConstructMenu(const char *menuFile); protected: void parseMenu(FILE *file, sh_CompositeControl *parent); Widget *menuWidgets; // Needed for greying out inactive menu items. sh_EventHandler **menuTools; int numMenuWidgets; }; /* ------------------------------------------------------------------------------ sh_PulldownMenu class declaration Summary: implements a pulldown menu. ------------------------------------------------------------------------------ */ class sh_PulldownMenu : public sh_CompositeControl { public: sh_PulldownMenu(sh_CompositeControl *parent, const char *label, char mnemonicKey = 0); }; /* ------------------------------------------------------------------------------ sh_ToolBox class declaration Summary: implements m_toolbox to hold buttons. Functions: ConstructToolBox() - may be called in CADshell to construct m_toolbox from resource file. SetButton() - make button appear depressed. UnsetButton() - make button appear up. ToggleButton() - flip button appearance between Set and Unset. ------------------------------------------------------------------------------ */ class sh_ToolBox : public sh_CompositeControl { public: sh_ToolBox(sh_CompositeControl *parent, bool vertical = true); ~sh_ToolBox(); virtual void ConstructToolBox(const char *resFileName); virtual void SetButton(sh_EventHandler *m_tool); virtual void UnsetButton(sh_EventHandler *m_tool); virtual void ToggleButton(sh_EventHandler *m_tool); protected: Widget *m_toolBoxWidgets; // Needed for setting and unsetting m_toolBox buttons sh_EventHandler **m_toolBoxTools; int numToolBoxWidgets; virtual void AddToolBoxButton(sh_EventHandler *m_tool, const char *label = 0); }; /* ------------------------------------------------------------------------------ sh_StatusBar class declaration Summary: implements a text label to display status message. There are two modes: (i) displaying process status or (ii) displaying command text. Normally the command text is displayed, however if there is a process status to be displayed, it will recieve priority and will be displayed instead. Once the process status is set to NULL again, the display reverts back to the command text. Functions: SetCommandText() - use to set the command text. Give NULL value to clear command display SetProcessStatusText() - use to set the process status. Give NULL value to clear process status display. ------------------------------------------------------------------------------ */ class sh_StatusBar : public sh_CompositeControl { public: sh_StatusBar(sh_CompositeControl *parent); virtual void SetCommandText(const char *text); virtual void SetProcessStatusText(const char *text); protected: char *commandText; }; #endif