home *** CD-ROM | disk | FTP | other *** search
- /*========================================================*/
- /* POPUP.CPP */
- /* (C) 1993 Michael Maier & DMV-Verlag */
- /* Das Programm demonstriert, wie ein POPUP-Menü bei */
- /* einem Klick auf die rechte Maustaste auf dem Desktop */
- /* an der Position des Mauscursors angezeigt werden kann. */
- /* Compiler: Turbo C++ 3.0, Borland C++ 3.1 */
- /*========================================================*/
-
- #define Uses_TEventQueue
- #define Uses_TEvent
- #define Uses_TApplication
- #define Uses_TKeys
- #define Uses_TRect
- #define Uses_TMenu
- #define Uses_TMenuBar
- #define Uses_TSubMenu
- #define Uses_TMenuItem
- #define Uses_TMenuBox
- #define Uses_TStatusLine
- #define Uses_TStatusItem
- #define Uses_TStatusDef
- #define Uses_TDeskTop
- #define Uses_TView
- #define Uses_TWindow
- #define Uses_MsgBox
- #include <tv.h>
-
- #include <stdio.h>
- #include <dos.h>
-
- const int cmNew = 200;
- const int cmOpen = 201;
- const int cmSave = 202;
- const int cmPopUp = 203;
- const int cmHelpme = 204;
-
- const int hcNew = 1000;
- const int hcOpen = 1001;
- const int hcSave = 1002;
- const int hcExit = 1003;
- const int hcZoom = 1004;
- const int hcNext = 1005;
- const int hcClose = 1006;
- const int hcFile = 1007;
- const int hcWindow = 1008;
- const int hcCopy = 1009;
- const int hcCut = 1010;
- const int hcPaste = 1011;
- const int hcHelpme = 1012;
-
- const char *apstrHilfetexte[] =
- {
- "Legt eine neue Datei an",
- "Lädt eine bestehende Datei in den Speicher",
- "Speichert die Datei auf Diskette",
- "Verläßt das Programm",
- "Vergrößert das aktive Fenster",
- "Wechselt zum nächsten Fenster",
- "Schließt das aktive Fenster",
- "Enthält Funktionen zum Dateihandling/Programmende",
- "Enthält Funktionen zum Fensterhandling",
- "Kopiert markierten Block in das Clipboard",
- "Schneidet markierten Bereich aus",
- "Fügt Block aus dem Clipboard ein",
- "Gibt einen Hilfetext aus",
- NULL
- };
-
- void MausPosButtonStatus(MouseEventType& event)
- {
- union REGS regs;
-
- regs.x.ax = 0x03; /* Funktionnummer ins AX-Register */
- regs.x.bx = 0x00; /* BX-Register löschen, da in ihm der */
- /* Status der Mausbuttons übergeben wird */
- int86(0x33, ®s, ®s); /* und Interrupt aufrufen */
-
- event.buttons = regs.x.bx; /* Mausbuttonstatus merken */
- event.where.x = regs.x.cx >> 3; /* Koordinaten in Text- */
- event.where.y = regs.x.dx >> 3; /* modus umrechnen */
- event.doubleClick = False;
- }
-
- class THintStatusLine: public TStatusLine
- {
- public:
- THintStatusLine(const TRect& bounds, TStatusDef& aDefs);
- virtual const char* hint (ushort aHelpCtx);
- };
-
-
- THintStatusLine::THintStatusLine(const TRect& bounds,
- TStatusDef& aDefs): TStatusLine(bounds, aDefs)
- {
- };
-
-
- const char *THintStatusLine::hint (ushort aHelpCtx)
- {
- if (aHelpCtx >= hcNew && aHelpCtx <= hcHelpme)
- return(apstrHilfetexte[aHelpCtx - 1000]);
- else
- return("");
- };
-
- class THintStatusApp : public TApplication
- {
- public:
- THintStatusApp();
- static TStatusLine *initStatusLine(TRect r);
- static TMenuBar *initMenuBar(TRect r);
- virtual void handleEvent(TEvent& event);
- void PopUpMenu(ushort x, ushort y);
- };
-
- THintStatusApp::THintStatusApp():
- TProgInit(&THintStatusApp::initStatusLine,
- &THintStatusApp::initMenuBar,
- &THintStatusApp::initDeskTop)
- {
- }
-
- TMenuBar *THintStatusApp::initMenuBar(TRect r)
- {
- r.b.y = r.a.y + 1;
-
- TSubMenu& sub1 =
- *new TSubMenu("~D~atei", kbAltF ) +
- *new TMenuItem("~N~eu", cmNew, kbF4, hcNew, "F4") +
- *new TMenuItem("~Ö~ffnen", cmOpen, kbF3, hcOpen, "F3")+
- *new TMenuItem("~S~peichern", cmSave, kbF2, hcSave,
- "F2") + newLine() +
- *new TMenuItem("Quit", cmQuit, cmQuit, hcExit,
- "Alt-X");
-
- sub1.helpCtx = hcFile;
-
- TSubMenu& sub2 =
- *new TSubMenu("~F~enster", kbAltW) +
- *new TMenuItem("~N~ächstes", cmNext, kbF6, hcNext,"F6")+
- *new TMenuItem("~V~ergrößern", cmZoom, kbF5, hcZoom,
- "F5") +
- *new TMenuItem("~S~chließen", cmClose, kbAltF3,
- hcClose, "Alt-F3");
-
- sub2.helpCtx = hcWindow;
-
- return(new TMenuBar(r, sub1 + sub2));
- }
-
- TStatusLine *THintStatusApp::initStatusLine(TRect r)
- {
- r.a.y = r.b.y - 1;
- return new THintStatusLine(r, *new TStatusDef(0, 0xFFFF) +
- *new TStatusItem("~F10~ Menu", kbF10, cmMenu) +
- *new TStatusItem("", kbAltX, cmQuit));
- }
-
- int main()
- {
- THintStatusApp HintStatusApp;
- HintStatusApp.run();
- return(0);
- }
-
- void THintStatusApp::PopUpMenu(ushort x, ushort y)
- {
- TMenuItem& ItemList =
- *new TMenuItem("~C~opy", cmCopy, kbAltC, hcCopy, "",
- new TMenuItem("C~u~t", cmCut, kbAltU, hcCut, "",
- new TMenuItem("~P~aste", cmPaste, kbAltP, hcPaste, "",
- new TMenuItem("~H~ilfe", cmHelpme, kbAltH, hcHelpme,
- ""))));
-
- TMenu* PopUp = new TMenu(ItemList);
-
- TRect& r = getExtent();
- --r.a.x += x;
- --r.a.y += y;
-
- TMenuBox* Box = (TMenuBox*)
- validView(new TMenuBox(r, PopUp, 0));
- if (Box)
- {
- int RetCode = execView(Box);
- destroy(Box);
- TEvent event;
- event.what = evCommand;
- event.message.command = RetCode;
- putEvent(event);
- }
- }
-
- void THintStatusApp::handleEvent(TEvent& event)
- {
- MouseEventType MouseEvent;
-
- if (event.what == evMouseDown)
- {
- MausPosButtonStatus(MouseEvent);
- if (MouseEvent.buttons & mbRightButton)
- {
- event.what = evCommand;
- event.message.command = cmPopUp;
- }
- }
-
- TApplication::handleEvent(event);
-
- if (event.what == evCommand)
- {
- switch(event.message.command)
- {
- case cmPopUp:
- PopUpMenu(MouseEvent.where.x, MouseEvent.where.y);
- break;
- case cmCopy:
- messageBox("Menüpunkt COPY wurde gewählt",
- mfInformation | mfOKButton);
- break;
- case cmCut:
- messageBox("Menüpunkt CUT wurde gewählt",
- mfInformation | mfOKButton);
- break;
- case cmPaste:
- messageBox("Menüpunkt PASTE wurde gewählt",
- mfInformation | mfOKButton);
- break;
- case cmHelpme:
- messageBox("Menüpunkt HILFE wurde gewählt",
- mfInformation | mfOKButton);
- break;
- default:
- return;
- }
- clearEvent(event);
- }
- }
-
- /*========================================================*/
- /* Ende von POPUP.CPP */
-