//--------------------------------------------------------------------------- // // 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: Tutorial chapter // FILE: tutsamp.cpp // // VERSION: 2.2 // //--------------------------------------------------------------------------- #include //for standard GEOS-SC types #include //for UI factory #include //for UI hints #include //for string functions (strcpy) #include "tutsamp.h" //for our class definition #include "resource.h" //for our user-visible strings // Sets the name the system uses for the application static AppNameAttribute tutsampAppName(&tutsampApp, TUTSAMPAPP_FRAME_TITLE); //--------------------------------------------------------------------------- // TutorialApp::TutorialApp() //--------------------------------------------------------------------------- // // DESCRIPTION: Constructor for this application's App object. // This constructor is useful in that it initializes the // _builtUI flag before we enter the Application's // life-cycle. // SCOPE: public // PARAMETERS: None. // RETURN: None. // //--------------------------------------------------------------------------- TutorialApp::TutorialApp() : _builtUI( FALSE ), _layout( NULL ) {}; // End of TutorialApp::TutorialApp() //--------------------------------------------------------------------------- // TutorialApp::SetAppContext() //--------------------------------------------------------------------------- // // SYNOPSIS: Called when this application is started up or switched to. // It checks if it previously built the UI; if not it // calls BuildUI() to create the UI. // // It then reads the context string, if any. // // SCOPE: public // RETURN: void // PARAMETERS: [in] context - The application context // //--------------------------------------------------------------------------- /* virtual */ void TutorialApp::SetAppContext(const TCHAR *context) { // // If we have not already build the application's UI, // call our helper function to do so. // if ((!_builtUI) && BuildUI() != SUCCESS) { EC_WARN("Could not create UI."); // Call Exit to quit the application and clean up. Exit(); } if (context) { if (Tstrcmp( context, _TEXT("+")) == 0) { _helloworldLabel->SetVisible(TRUE); return; } if (Tstrcmp( context, _TEXT("-")) == 0) { _helloworldLabel->SetVisible(FALSE); return; } EC_WARN("Unrecognized context string"); } } // End of TutorialApp::SetAppContext() //--------------------------------------------------------------------------- // TutorialApp::GetAppContext() //--------------------------------------------------------------------------- // // SYNOPSIS: Returns a string identifying the application state. // The state is whether the label is currently displayed. // SCOPE: public // RETURN: TCHAR * - a string we create with the new operator // indicating the current application state. // //--------------------------------------------------------------------------- /* virtual */ TCHAR * TutorialApp::GetAppContext(void) { if (_builtUI != TRUE ) { return NULL; } TCHAR scratch[30]; if (_helloworldLabel->IsVisible() == TRUE) { Tstrcpy( scratch, _TEXT("+")); } else { Tstrcpy( scratch, _TEXT("-")); } TCHAR *context = new TCHAR[Tstrlen( scratch ) + 1 ]; if ( context == NULL ) { EC_WARN("Could not allocate context string; will not save context."); return NULL; } Tstrcpy( context, scratch ); return context; } // End of TutorialApp::GetAppContext //--------------------------------------------------------------------------- // TutorialApp::Exit() //--------------------------------------------------------------------------- // // SYNOPSIS: Called when the application quits. // SCOPE: Private // RETURN: nothing // STRATEGY: We do not have to clean up UI elements that have been added // under the AppBase. We do have to delete any layouts and // listeners attached to those objects however. // //--------------------------------------------------------------------------- /* virtual */ void TutorialApp::Exit(void) { delete _layout; // Call inherited method to get default behavior. AppBase::Exit(); } // End of TutorialApp::Exit() //--------------------------------------------------------------------------- // BuildUI() //--------------------------------------------------------------------------- // // SYNOPSIS: Puts up UI for our application. // SCOPE: public // RETURN: SUCCESS or FAILURE // This function fails if any of the UI creation functions // fail. // PARAMETERS: None. // ERRORS: This function cleans up the memory for any UI elements that // have been created, but not yet added to the UI tree under // the AppBase. // //--------------------------------------------------------------------------- Result TutorialApp::BuildUI(void) { // // Create the frame. It will act as the main screen of our application. // FlexFrame *frame = theUIFactory->CreateFlexFrame( HINT_FRAME_WITH_NO_CLOSE_BUTTON, TUTSAMPAPP_FRAME_TITLE ); if (frame == NULL) { EC_WARN("Couldn't create frame."); return FAILURE; } if (Add(frame) != SUCCESS) { EC_WARN("Couldn't add frame to the AppBase."); delete frame; return FAILURE; } _layout = new VerticalFlowLayout; if ( _layout == NULL ) { EC_WARN("Couldn't allocate frame's layout"); return FAILURE; } frame->SetLayout(_layout); FlexButton *button = theUIFactory->CreateFlexButton( HINT_BUTTON_JAVA_LOOK_AND_FEEL); if (button == NULL) { EC_WARN("Couldn't create button."); return FAILURE; } if ( frame->Add(button) != SUCCESS ) { EC_WARN("Couldn't add button to the frame."); delete button; return FAILURE; } button->SetLabelString(TUTSAMPAPP_BUTTON_LABEL); if ( button->AddActionListener(*this) != SUCCESS ) { EC_WARN("Couldn't add action listener to the button."); return FAILURE; } _helloworldLabel = theUIFactory->CreateFlexLabel(); if ( _helloworldLabel == NULL ) { EC_WARN("Couldn't create label."); return FAILURE; } if ( frame->Add(_helloworldLabel) != SUCCESS ) { EC_WARN("Couldn't add label to the frame."); delete _helloworldLabel; return FAILURE; } _helloworldLabel->SetText(TUTSAMPAPP_LABEL_TEXT); _helloworldLabel->SetVisible( FALSE ); frame->SetVisible(TRUE); _builtUI = TRUE; return SUCCESS; } // End of TutorialApp::BuildUI() //--------------------------------------------------------------------------- // TutorialApp::ActionPerformed() //--------------------------------------------------------------------------- // // SYNOPSIS: When the button is pressed this method is called. // We update the display. // SCOPE: Private // PARAMETERS: [in] event - Structure with information about the // button press. We'll ignore it. // RETURN: nothing // //--------------------------------------------------------------------------- /* virtual */ void TutorialApp::ActionPerformed(ActionEvent& event) { USE_IT( event ); if (_helloworldLabel->IsVisible()) { _helloworldLabel->SetVisible(FALSE); } else { _helloworldLabel->SetVisible(TRUE); } } // End of TutorialApp::ActionPerformed()