#include "ZApp.h" #include "ZMenuDef.h" #include "ZMain.h" #include "ZString.h" #include "ZUIFactory.h" #include "ZUIUtil.h" #include "ZHelloWorld_ResID.h" #define mcHello_Again mcUser + 1 #define mcHello_Pixmap mcUser + 2 #define mcHello_TextResource mcUser + 3 #define mcHello_TextHardCoded mcUser + 4 // ================================================== class ZHelloWorld_App : public ZApp { public: ZHelloWorld_App(); virtual ~ZHelloWorld_App(); // From ZWindowSupervisor via ZApp virtual void WindowSupervisorInstallMenus(ZMenuInstall& inMenuInstall); // From ZApp virtual void RunStarted(); }; // ================================================== int ZMain(int argc, char** argv) { try { ZHelloWorld_App theApp; theApp.Run(); } catch (...) {} return 1; } // ================================================== class ZHelloWorld_Window : public ZWindow, public ZPaneLocator { public: ZHelloWorld_Window(ZApp* inApp); ~ZHelloWorld_Window(); // From ZEventHr via ZWindow virtual void DoInstallMenus(ZMenuInstall* inMenuInstall); virtual void DoSetupMenus(ZMenuSetup* inMenuSetup); virtual bool DoMenuMessage(const ZMessage& inMenuMessage); // From ZPaneLocator virtual bool GetPaneLocation(ZSubPane* inPane, ZPoint& outLocation); protected: ZWindowPane* fWindowPane; ZUICaptionPane* fHelloPane; }; // ================================================== ZHelloWorld_App::ZHelloWorld_App() { ZUIUtil::sInitializeUIFactories(); } ZHelloWorld_App::~ZHelloWorld_App() { ZUIUtil::sTearDownUIFactories(); } void ZHelloWorld_App::WindowSupervisorInstallMenus(ZMenuInstall& inMenuInstall) { ZApp::WindowSupervisorInstallMenus(inMenuInstall); if (ZRef appleMenu = inMenuInstall.GetAppleMenu()) { appleMenu->RemoveAll(); appleMenu->Append(new ZMenuItem(mcAbout, "About " + this->GetAppName() + "...")); } ZRef fileMenu = new ZMenu; inMenuInstall.Append("&File", fileMenu); fileMenu->Append(mcClose, "&Close", 'W'); fileMenu->AppendSeparator(); fileMenu->Append(mcQuit, "&Quit", 'Q'); } void ZHelloWorld_App::RunStarted() { ZWindow* theWindow = new ZHelloWorld_Window(this); theWindow->Center(); theWindow->BringFront(); theWindow->GetLock().Release(); } // ================================================== static ZOSWindow* sCreateOSWindow(ZApp* inApp) { ZOSWindow::CreationAttributes attr; attr.fFrame = ZRect(0, 0, 200, 80); attr.fLook = ZOSWindow::lookDocument; attr.fLayer = ZOSWindow::layerDocument; attr.fResizable = true; attr.fHasSizeBox = true; attr.fHasCloseBox = true; attr.fHasZoomBox = true; attr.fHasMenuBar = true; attr.fHasTitleIcon = false; return inApp->CreateOSWindow( attr ); } ZHelloWorld_Window::ZHelloWorld_Window(ZApp* inApp) : ZWindow(inApp, sCreateOSWindow(inApp)), ZPaneLocator(nil) { this->SetTitle("Hello World Window"); this->SetBackInks(ZUIAttributeFactory::sGet()->GetInk_WindowBackground_Dialog(), new ZUIInk_Fixed(ZRGBColor::sYellow)); fWindowPane = new ZWindowPane(this, nil); fHelloPane = ZUIFactory::sGet()->Make_CaptionPane(fWindowPane, this, "Hello World!"); } ZHelloWorld_Window::~ZHelloWorld_Window() {} void ZHelloWorld_Window::DoInstallMenus(ZMenuInstall* inMenuInstall) { ZWindow::DoInstallMenus(inMenuInstall); ZRef helloMenu = new ZMenu; inMenuInstall->Append("&Hello", helloMenu); helloMenu->Append(mcHello_Again, "&Hello World Again!", 'H'); helloMenu->AppendSeparator(); helloMenu->Append(mcHello_Pixmap, "My New Niece"); helloMenu->Append(mcHello_TextResource, "Text Resource"); helloMenu->Append(mcHello_TextHardCoded, "Text (Hard coded)"); } void ZHelloWorld_Window::DoSetupMenus(ZMenuSetup* inMenuSetup) { ZWindow::DoSetupMenus(inMenuSetup); inMenuSetup->EnableItem(mcClose); inMenuSetup->EnableItem(mcHello_Again); inMenuSetup->EnableItem(mcHello_Pixmap); inMenuSetup->EnableItem(mcHello_TextResource); inMenuSetup->EnableItem(mcHello_TextHardCoded); } bool ZHelloWorld_Window::DoMenuMessage(const ZMessage& inMenuMessage) { switch (inMenuMessage.GetInt32("menuCommand")) { case mcClose: { this->CloseAndDispose(); break; } case mcHello_Again: { ZWindow* theWindow = new ZHelloWorld_Window(ZApp::sGet()); theWindow->Center(); theWindow->BringFront(); theWindow->GetLock().Release(); return true; } case mcHello_Pixmap: { ZDCPixmap thePixmap = ZUIUtil::sLoadPixmapFromBMPResource(kRSRC_BMP_Amy); fHelloPane->SetCaption(new ZUICaption_Pix(thePixmap), true); break; } case mcHello_TextResource: { string theText = ZString::sFromStrResource(kRSRC_STR_HelloWorld); ZRef theUIFont = ZUIAttributeFactory::sGet()->GetFont_SystemLarge(); ZRef theUICaption = new ZUICaption_Text(theText, theUIFont, 0); fHelloPane->SetCaption(theUICaption, true); break; } case mcHello_TextHardCoded: { string theText = ZString::sFromStrResource(kRSRC_STR_HelloWorld); ZDCFont theDCFont = ZDCFont::sApp9; theDCFont.SetStyle(theDCFont.GetStyle() | ZDCFont::underline); ZRef theUIFont = new ZUIFont_Fixed(theDCFont); ZRef theUICaption = new ZUICaption_Text("Hello World! (hard coded)", theUIFont, 0); fHelloPane->SetCaption(theUICaption, true); break; } } return ZWindow::DoMenuMessage(inMenuMessage); } bool ZHelloWorld_Window::GetPaneLocation(ZSubPane* inPane, ZPoint& outLocation) { if (inPane == fHelloPane) { ZPoint theSize = inPane->GetSize(); ZPoint superSize = inPane->GetSuperPane()->GetInternalSize(); outLocation = (superSize - theSize) / 2; return true; } return ZPaneLocator::GetPaneLocation(inPane, outLocation); } // ==================================================