//--------------------------------------------------------------------------- // // Geoworks (R) application software and GEOS (R) operating system // software copyright (C) 1990-1998 Geoworks. All rights reserved. // United States Patents 5327529, 5237651, and 5438662. U.K. Patents // 0375703 and 0631677. German Patents P3854269.2-08 and // 69307728.1-08. French Patents 0375703 and 0631677. Other // international patents pending. // // This software is the confidential and proprietary information of // Geoworks ("Confidential Information"). You shall not disclose // such Confidential Information and shall use it only in accordance // with the terms of the license agreement you entered into with // Geoworks. // // PROJECT: GEOS_SC Documentation // MODULE: Flex UI Chapter // FILE: helloapp.cpp // // VERSION: 2.0 // // DESCRIPTION: // // An application that uses a layout to manage a label with a frame. // //--------------------------------------------------------------------------- #include // For data types and ec checking. #include // For creating objects in the user interface. #include // For looks in the user interface. #include // For subclassing the resident application. #include // For using localization resources. #include "resource.h" // For the resource strings. #include "helloapp.h" // For the defined methods in the class. // // Strings that are not user-visible and should not be localized. // const TCHAR * const HELLOAPP_NAME = _TEXT("helloUI"); // // Our subclass of ResidentApplication, which registers this application // with the system, and provides a way for this app to create its AppBase. // class HelloAppResidentApplication : public ResidentApplication { public: HelloAppResidentApplication() : ResidentApplication(HELLOAPP_NAME) {}; virtual AppBase *CreateAppBase(void) { return new HelloApp; } }; static HelloAppResidentApplication helloApp; // // Any attributes that we want to specify about our app - in this case, we // specify the name, but we could also specify an image, maybe a // non-standard stack size or thread priority, etc. // static AppNameAttribute helloAppName(&helloApp, HELLOAPP_APP_TEXT); //--------------------------------------------------------------------------- // HelloApp::HelloApp() //--------------------------------------------------------------------------- // // SYNOPSIS: The constructor initializes variables to the initial values // and sets the variable _helloAppUIBuilt to false, signifying // that the user interface has not been built. // SCOPE: Public // RETURN: nothing // //--------------------------------------------------------------------------- HelloApp::HelloApp() : _helloAppMainFrame(NULL), _helloAppUIBuilt(FALSE) { } /* End of HelloApp::HelloApp() */ //--------------------------------------------------------------------------- // HelloApp::SetAppContext() //--------------------------------------------------------------------------- // // SYNOPSIS: Checks to see if the application is already running. // If it is, it calls the helper function BuildHelloAppUI to // build the user interface. // SCOPE: Public // RETURN: nothing // PARAMETERS: [in] context - The application context. // //--------------------------------------------------------------------------- void HelloApp::SetAppContext(const TCHAR *context) { if (!_helloAppUIBuilt) { if (BuildHelloAppUI() != SUCCESS) { EC_WARN("Unable to build user interface."); Exit(); } else { _helloAppUIBuilt = TRUE; } } // // Since we do not use the context parameter, we must pass it to the // USE_IT macro to suppress compiler warnings. // USE_IT(context); } //--------------------------------------------------------------------------- // HelloApp::BuildHelloAppUI() //--------------------------------------------------------------------------- // // SYNOPSIS: Called by SetAppContext to build the user interface. // Attempts to create and add elements of the user interface. // If any element cannot be created or added, FAILURE is // returned and SetAppContext will call the Exit method to // destroy the user interface. // SCOPE: Private // RETURN: SUCCESS or FAILURE // //--------------------------------------------------------------------------- Result HelloApp::BuildHelloAppUI(void) { // // Create a frame to hold the user interface of our application // and make sure it was created successfully. // Return FAILURE if it was not. // _helloAppMainFrame = theUIFactory->CreateFlexFrame(HINT_FRAME_WITH_NO_CLOSE_BUTTON, HELLOAPP_APP_TEXT); if (NULL == _helloAppMainFrame) { EC_WARN("Unable to create the main frame."); return FAILURE; } // // Attempt to add the main window to the application. // If we fail, we must delete the frame and return FAILURE. // if (Add(_helloAppMainFrame) != SUCCESS) { EC_WARN("Unable to add the main frame."); delete _helloAppMainFrame; return FAILURE; } // // Create a flow layout that centers the components horizontally, and has // 0 for a gap between components. If the layout is created successfully, // add it to the frame. // HorizontalFlowLayout *frameLayout = new HorizontalFlowLayout(0); if (NULL == frameLayout) { EC_WARN("Unable to create layout."); return FAILURE; } _helloAppMainFrame->SetLayout(frameLayout); // // Create a label to display the text. // FlexLabel *helloLabel = theUIFactory->CreateFlexLabel(); if (NULL == helloLabel) { EC_WARN("Unable to create the label."); return FAILURE; } // // Attempt to add the label to the frame. // If we fail, we must delete the label and return FAILURE. // if (_helloAppMainFrame->Add(helloLabel) != SUCCESS) { EC_WARN("Unable to add label to the frame."); delete helloLabel; return FAILURE; } // // Set the label text. // helloLabel->SetText(HELLOAPP_TEXT); // // Make the main window visible. // _helloAppMainFrame->SetVisible(TRUE); // // Return SUCCESS once we have built all of the user interface. // return SUCCESS; } /* End of HelloApp::SetAppContext() */ //------------------------------------------------------------------------ // HelloApp::Exit() //------------------------------------------------------------------------ // // SYNOPSIS: Use Exit to clean up when the application quits. This // includes deleting any elements of the user interface, // such as layouts, that were not created by theUIFactory. // SCOPE: Public // RETURN: nothing // //------------------------------------------------------------------------ void HelloApp::Exit(void) { // // Delete the layout for the main frame. // if (_helloAppMainFrame) { delete _helloAppMainFrame->RemoveLayout(); } // // Set the boolean for the application. // _helloAppUIBuilt = FALSE; AppBase::Exit(); } /* End of HelloApp::Exit() */