home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-08 | 3.9 KB | 170 lines | [TEXT/CWIE] |
- // PopupMenuTest.cp
- // written by Constantine Spathis
-
- // App Specific Headers
- #include "LDynamicPopupMenu.h"
- #include "PopupTester.h"
-
- // PowerPlant Headers
- // PowerPlant Specific Headers - The reason for so many is for registering what we
- // use from powerplant
- #include <LWindow.h>
- #include <LStdControl.h>
- #include <UMemoryMgr.h>
- #include <UDrawingState.h>
- #include <LGrowZone.h>
- #include <UScreenPort.h>
- #include <URegistrar.h>
- #include <UReanimator.h>
- #include <PPobClasses.h>
- #include <UPowerTools.h>
- #include <PP_Messages.h>
-
-
- // ANSI Headers
- #include <stdio.h>
-
- void
- main()
- {
- InitializeHeap(4);
- InitializeToolbox();
- new LGrowZone(20000);
-
- PopupMenuTester theApp;
-
- theApp.Run();
- }
- // PopupMenuTester::PopupMenuTester()
- // 12/9/94 CS - Only on constructor needed
- PopupMenuTester::PopupMenuTester()
- {
- // Init screen stuff PP
- UScreenPort::Initialize();
-
- // Register PowerPlant Classes
- // Note I do not need everything that's why I don't call RegisterAllPPClasses to
- // do it for me.
- URegistrar::RegisterAllPPClasses();
-
- // App Classes
- URegistrar::RegisterClass('LDPM', (ClassCreatorFunc) LDynamicPopupMenu::CreateLDynamicPopupMenuStream);
- }
-
- // PopupMenuTester::~PopupMenuTester()
- // 12/9/94 CS - Typical destructor, not much to do.
- PopupMenuTester::~PopupMenuTester()
- {
- ;
- }
-
- // LApplication functions to override.
-
- // Boolean PopupMenuTester::ObeyCommand(
- // CommandT inCommand,
- // void *ioParam = nil)
- // 12/9/94 CS - Dispatch command handling return whether command was handled
- Boolean
- PopupMenuTester::ObeyCommand(
- CommandT inCommand,
- void *ioParam )
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- case cmd_New:
- LWindow* pWindow=LWindow::CreateWindow(1000,this);
- LDynamicPopupMenu* pPopupMenu=(LDynamicPopupMenu*)pWindow->FindPaneByID('LDPM');
- MenuHandle hTmpMenu=pPopupMenu->GetMacMenuH();
- pPopupMenu->AddListener(this);
- for(int i=0;i<10;i++){
- char str[64];
- sprintf(str,"Bjarne %d",i);
- pPopupMenu->AddCMenuItem(str);
- }
- // You must remember to call this function when you are
- // done creating the menu items. Note you can then
- // modify the items later w/o calling this function.
- pPopupMenu->FinishedCreatingMenu(2);
- break;
- default:
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
- // void PopupMenuTester::FindCommandStatus(CommandT inCommand,
- // Boolean &outEnabled,
- // Boolean &outUsesMark,
- // Char16 &outMark,
- // Str255 outName)
- // 12/10/94 CS - Determine if a command is still active, if no one else understands it.
- void
- PopupMenuTester::FindCommandStatus(CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
- case cmd_New:
- outEnabled = true;
- break;
- case cmd_Open:
- outEnabled = true;
- break;
- case cmd_PageSetup:
- outEnabled = true;
- break;
- case cmd_Print:
- outEnabled = false;
- break;
- case cmd_Close:
- outEnabled = false;
- break;
- default:
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
- // void PopupMenuTester::EventMouseDown(
- // const EventRecord &inMacEvent)
- // 12/10/94 CS - Mousedown event dispatching if it not handled by anyone else in the command
- // chain.
- void
- PopupMenuTester::EventMouseDown(
- const EventRecord &inMacEvent)
- {
- WindowPtr macWindowP;
-
- Int16 thePart = FindWindow(inMacEvent.where, &macWindowP);
-
- switch (thePart) {
- default:
- LApplication::EventMouseDown(inMacEvent);
- break;
- }
- }
- // void ListenToMessage(
- // MessageT inMessage,
- // void* ioParam)
- // 1/8/95 CS
- // Listen to popupmenu for this window
- void
- PopupMenuTester::ListenToMessage(
- MessageT inMessage,
- void* ioParam)
- {
- LDynamicPopupMenu* pPopupMenu=(LDynamicPopupMenu*)ioParam;
- // Ugly, ugly, ugly....
- if (inMessage!=msg_BroadcasterDied){
- pPopupMenu->SetValue(inMessage);
- }
- }
-