home *** CD-ROM | disk | FTP | other *** search
- // nmenu.cpp: example of TV menu nesting.
- // Robert J. Connolly, 9/91.
- // CIS: 72240,2664
- // BPROGB, DOSFRAMEWORKS
-
- #define Uses_TApplication
- #define Uses_TMenu
- #define Uses_TMenuBar
- #define Uses_TMenuItem
- #define Uses_TStatusLine
- #define Uses_TStatusItem
- #define Uses_TStatusDef
- #define Uses_TKeys
- #include <tv.h>
-
- //-------------------------------------------------------------------------
- class TMyApp : public TApplication
- {
- public:
- TMyApp(); // constructor to set the application up.
- static TMenuBar *initMenuBar( TRect r); // init menus.
- };
- //-------------------------------------------------------------------------
-
-
- //-------------------------------------------------------------------------
- TMyApp::TMyApp() : TProgInit( &TMyApp::initStatusLine,
- &TMyApp::initMenuBar,
- &TMyApp::initDeskTop )
- {
- }
- //-------------------------------------------------------------------------
-
- //-------------------------------------------------------------------------
- // initMenuBar: example nested menus.
- // -- After playing around with the TV menu system, I came up with the
- // following technique for coding menus.
- //
- // 1) Just forget TSubMenu and newLine().
- // 2) TMenuBar takes a pointer to a TMenu.
- // 3) TMenu takes a REFERENCE to a TMenuItem: *new *TMenuItem(...).
- // 3) TMenuItem has two constructors, each of which requires a pointer
- // to another TMenuItem (used for sequential entries in a given menu),
- // or 0 for the last entry, and the other form which has an additional
- // parameter for a pointer to a TMenu (another nested menu).
- //
- // To make it easier to visualize:
- //
- // TMenuBar
- // |
- // |--> TMenu-->*TMenuItem-->TMenuItem-->TMenuItem-->0
- // |
- // |--> TMenu-->*TMenuItem-->TMenuItem-->TMenuItem-->0
- // |
- // |-->TMenu-->*TMenuItem-->0
- //
- // Where: *TMxxx is a reference, and --> is a pointer argument to an
- // instance of type TMxxx.
- //
- // So, TMenu always starts a menu. TMenuItem provides the entries in
- // a menu, with a constructor form that allows the entry to be a branch
- // to a nested menu.
- //
- // Now, the only difficulty is remembering the order of the parameters
- // for each TMenuItem form and keeping the parantheses correct.
- //
- // Note: newLine just provides a reference to a TMenuItem of the
- // construction *new MenuItem(0,0,0,hcNoContext,0,0). Therefore,
- // a TMenuItem pointer with these arguments provides the line
- // seperator. see below.
- //
- // In the demo, the file menu nests to 3 levels, the edit menu does not
- // nest at all, and the rest nest to just 1 level.
- //-------------------------------------------------------------------------
-
- TMenuBar* TMyApp::initMenuBar( TRect r)
- {
- r.b.y = r.a.y + 1; // set bottom 1 line below top.
- return new TMenuBar
- (r,new TMenu(
-
- *new TMenuItem("~F~ile",kbAltF,new TMenu(
-
- *new TMenuItem("~P~ack",cmError,kbNoKey,hcNoContext,"",
- new TMenuItem("~R~eindex",cmError,kbNoKey,hcNoContext,"",
- new TMenuItem(0,0,0,hcNoContext,0, // newLine().
- new TMenuItem("~T~est",kbNoKey,new TMenu(
-
- *new TMenuItem("Test ~1~",cmError,kbNoKey,hcNoContext,"",
- new TMenuItem("Test ~2~",kbNoKey,new TMenu(
-
- *new TMenuItem("Test ~1~a",cmError,kbNoKey,hcNoContext,"",
- new TMenuItem("Test ~2~b",cmError,kbNoKey,hcNoContext,"",0))
-
- ), hcNoContext,0))
-
- ), hcNoContext,
-
- new TMenuItem(0,0,0,hcNoContext,0, // newLine().
- new TMenuItem("~E~xit",cmQuit,kbAltX,hcNoContext,"Alt-X",0))))))
-
- ), hcNoContext,
-
- new TMenuItem("~E~dit",cmError,kbNoKey,hcNoContext,"",
- new TMenuItem("~R~eport",kbNoKey,new TMenu(
-
- *new TMenuItem("~S~elect",cmError,kbNoKey,hcNoContext,"",
- new TMenuItem("~P~rint",cmError,kbNoKey,hcNoContext,"",0))
-
- ), hcNoContext,
-
- new TMenuItem("~W~indow",kbNoKey,new TMenu(
-
- *new TMenuItem("~N~ext",cmNext,kbF6,hcNoContext,"F6",
- new TMenuItem("~Z~oom",cmZoom,kbF5,hcNoContext,"F5",0))
-
- ), hcNoContext,0))))
- ));
- }
- //-------------------------------------------------------------------------
-
- //-------------------------------------------------------------------------
- int main()
- {
- TMyApp myApp;
- myApp.run();
- return 0;
- }
- //-------------------------------------------------------------------------