home *** CD-ROM | disk | FTP | other *** search
- //========================================================================
- // The following routines have been uploaded to the Borland Forum BPROGB
- // on CompuServe by the Technical Support staff. They are provided as a
- // courtesy and not as part of a Borland product; and, as such, are
- // provided without the assurance of technical support or any specific
- // guarantees.
- //========================================================================
- // Turbo Vision - nested menus
- //
- // - This sample code demonstrates creating nested menus using the
- // TSubMenu class.
- //========================================================================
- #define Uses_MsgBox
- #define Uses_TApplication
- #define Uses_TButton
- #define Uses_TDeskTop
- #define Uses_TDialog
- #define Uses_TKeys
- #define Uses_TMenu
- #define Uses_TMenuBar
- #define Uses_TMenuItem
- #define Uses_TStaticText
- #define Uses_TStatusDef
- #define Uses_TStatusItem
- #define Uses_TStatusLine
- #define Uses_TSubMenu
- #include <tv.h>
-
- //========================================================================
- // global data
- //------------------------------------------------------------------------
- const cmAbout = 100; // user request: about box
- const cmItem1 = 101; // user request: Item 1
- const cmItem2 = 102; // user request: Item 2
-
- //========================================================================
- // class definitions
- //------------------------------------------------------------------------
- class TV6 : public TApplication {
- // main application class
-
- public:
- TV6();
-
- // virtual functions to be locally redefined
- static TStatusLine *initStatusLine(TRect r);
- static TMenuBar *initMenuBar(TRect r);
- void handleEvent (TEvent &event);
-
- // declare new functions
- void AboutBox();
-
- };
-
- //========================================================================
- // implementation of class TV6
- //------------------------------------------------------------------------
- TV6::TV6() : TProgInit( &TV6::initStatusLine,
- &TV6::initMenuBar, &TApplication::initDeskTop )
- {
- }
-
- //------------------------------------------------------------------------
- // define status line
- //------------------------------------------------------------------------
- TStatusLine *TV6::initStatusLine(TRect r)
- {
- r.a.y = r.b.y - 1;
- return new TStatusLine (r,
- *new TStatusDef( 0, 0xffff ) +
- *new TStatusItem ("~Alt-X~ Exit", kbAltX, cmQuit) +
- *new TStatusItem ("~Alt-F3~ Close", kbAltF3, cmClose) +
- *new TStatusItem ("~F10~ Menu", kbF10, cmMenu)
- );
- }
-
- //------------------------------------------------------------------------
- // define menu bar
- //------------------------------------------------------------------------
- TMenuBar *TV6::initMenuBar(TRect r)
- {
- r.b.y = r.a.y + 1;
- TMenuBar *newMenu = new TMenuBar(r,
- *new TSubMenu( "~\360~", kbAltSpace ) +
- *new TMenuItem( "~A~bout", cmAbout, kbAltA, hcNoContext ) +
- newLine() +
- *new TMenuItem( "Exit", 0, new TMenu(
- *new TMenuItem( "Exit & ~S~ave", cmQuit, kbAltX, hcNoContext, 0,
- new TMenuItem( "Exit & ~A~bandon", cmQuit, kbAltY, hcNoContext, 0,
- new TMenuItem( "Just ~Q~uit", cmQuit, kbAltZ, hcNoContext, 0
- )))), hcNoContext) +
- *new TSubMenu( "~D~o It", kbAltF) +
- *new TMenuItem( "~I~tem 1", cmItem1, kbNoKey, hcNoContext, 0 )+
- *new TMenuItem( "I~t~em 2", cmItem2, kbNoKey, hcNoContext, 0 )
- );
- newMenu->options |= 0xff;
- return newMenu;
- }
-
- //------------------------------------------------------------------------
- // event-handler
- //------------------------------------------------------------------------
- void TV6::handleEvent (TEvent &event)
- {
- TApplication::handleEvent (event);
- if (event.what == evCommand)
- {
- switch (event.message.command)
- {
- case cmAbout: // 'about' box
- AboutBox();
- break;
- case cmItem1: // selected menu item 1
- messageBox( "\003Item 1 selected", mfInformation );
- break;
- case cmItem2: // selected menu item 2
- messageBox( "\003Item 2 selected", mfInformation );
- break;
- }
- clearEvent (event);
- }
- }
-
- //------------------------------------------------------------------------
- // create modal About dialog box
- //------------------------------------------------------------------------
- void TV6::AboutBox()
- {
- // instantiate the basic dialog box
- TDialog *pd = new TDialog( TRect(0, 0, 30, 12), "About");
- if (pd)
- {
- //text strings centered within TRect extents
- pd->insert (new TStaticText(TRect(1, 2, 29, 7),
- "\003Turbo Vision\n"
- "\003\n"
- "\003Example Program\n"
- "\003\n"
- "\003Nested Menus"));
- pd->insert (new TButton( TRect(3,9,27,11), "~O~key-d~O~key",
- cmOK, bfDefault));
-
- //center box on desktop
- pd->options |= ofCentered;
-
- // execute the modal dialog box
- deskTop->execView (pd);
- }
- destroy (pd);
- }
-
- //========================================================================
- int main(void)
- {
- TV6 tv6App;
- tv6App.run();
- return 0;
- }
-
-