home *** CD-ROM | disk | FTP | other *** search
- /*
- MULTMENU.CPP
-
- Jeffrey Willaim Gillette
- 18 October 1991
-
- MULTMENU is a TurboVision demo program that sets up two menus --
- menuBar1 and menuBar2. The user can toggle back and forth between
- them. This little exercise shows how to change active menus based
- on program mode. A little further work and you could build menus
- dynamically to implement, e.g., entries on the File menu for the most
- recently opened documents, or a Windows-style "Windows" menu.
-
- Additionally the menuBar1 menu has an item that can be alternatively
- selected and de-selected. The item will display an 'X' if it is on,
- no 'X' if it is off. This checkbox effect is accomplished by keeping
- a state flag and switching between two different name strings.
-
- The rest of this program is a bald-faced plagarism from one of the
- "TVGUID##.CPP" files included with TV.
- */
-
- #define Uses_TApplication
- #define Uses_TKeys
- #define Uses_TRect
- #define Uses_TMenuBar
- #define Uses_TSubMenu
- #define Uses_TMenuItem
- #define Uses_TStatusLine
- #define Uses_TStatusItem
- #define Uses_TStatusDef
- #define Uses_TDeskTop
- #define Uses_TEvent
- #include <tv.h>
-
- const int cmMenu1 = 201;
- const int cmMenu2 = 202;
- const int cmCheck = 203;
-
- const char *check = " X ~C~heck Item";
- const char *nocheck = " ~C~heck Item";
-
- class TMyApp : public TApplication
- {
-
- public:
- static TMenuBar *menuBar1, *menuBar2; // initMenuBar is static so
- static TMenuItem *checkMenuItem; // these must also be static
- int checkItemFlag;
-
- TMyApp();
- static TMenuBar *initMenuBar( TRect r );
- void handleEvent(TEvent& event);
- };
-
- TMenuBar *TMyApp::menuBar1, *TMyApp::menuBar2;
- TMenuItem *TMyApp::checkMenuItem;
-
- TMyApp::TMyApp() :
- TProgInit( &TMyApp::initStatusLine,
- &TMyApp::initMenuBar,
- &TMyApp::initDeskTop
- )
- {
- checkItemFlag = 1;
- }
-
- TMenuBar *TMyApp::initMenuBar( TRect r )
- {
-
- r.b.y = r.a.y + 1; // set bottom line 1 line below top line
-
- checkMenuItem = new TMenuItem(check, cmCheck, kbNoKey, hcNoContext, 0);
-
- menuBar1 = new TMenuBar( r,
- *new TSubMenu( "Menu ~1~", kbAlt1 )+
- *new TMenuItem( "Goto ~2~", cmMenu2, kbNoKey,hcNoContext, 0 )+
- newLine()+
- *checkMenuItem +
- newLine()+
- *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
- );
-
- menuBar2 = new TMenuBar( r,
- *new TSubMenu( "Menu ~2~", kbAlt2 )+
- *new TMenuItem( "Goto ~1~", cmMenu1, kbNoKey, hcNoContext, 0 )+
- newLine()+
- *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
- );
-
- return menuBar1;
- }
-
- void TMyApp::handleEvent(TEvent& event)
- {
- TApplication::handleEvent(event); // act like base!
- if( event.what == evCommand )
- {
- switch( event.message.command )
- {
- case cmMenu1: // make menuBar1 active
- remove(menuBar);
- menuBar = menuBar1;
- insert(menuBar1);
- break;
- case cmMenu2: // make menuBar2 active
- remove(menuBar);
- menuBar = menuBar2;
- insert(menuBar2);
- break;
- case cmCheck: // toggle checked menu item
- checkItemFlag = !checkItemFlag;
- checkMenuItem->name = checkItemFlag ?
- check : nocheck;
- break;
- default:
- return;
- }
- clearEvent( event ); // clear event after handling
- }
- }
-
-
-
- int main()
- {
- TMyApp myApp;
- myApp.run();
- return 0;
- }
-