SophiaFramework UNIVERSE 5.3 |
Here the code of the HelloWorld applet including processings such as suspend or resume, which is automatically generated by Application Wizard of SophiaFramework UNIVERSE is described.
The maximum code of the application class of the HelloWorld applet, which is automatically generated by Application Wizard of SophiaFramework UNIVERSE, is as follows:
Example 9.38. Declaration
// // USRApplication.hpp // // This source code was automatically // generated by SophiaFramework UNIVERSE 5.3 // #ifndef __USRAPPLICATION_HPP #define __USRAPPLICATION_HPP #define TARGET_BUILD_DEBUG #include <SophiaFramework.hpp> #include "USRApplication.bid" SFMTYPEDEFCLASS(USRApplication) class USRApplication: public SFYApplication { SFMSEALCOPY(USRApplication) public: static SFCInvokerPtr Factory(Void); private: explicit USRApplication(Void) static_throws; virtual ~USRApplication(Void); XANDLER_DECLARE_VOIDRENDER(OnRenderRequest) XANDLER_DECLARE_VOIDSTART(OnAppStart) XANDLER_DECLARE_VOIDSTOP(OnAppStop) XANDLER_DECLARE_VOIDRESUME(OnAppResume) XANDLER_DECLARE_VOIDSUSPEND(OnAppSuspend) XANDLER_DECLARE_BOOLVOID(OnAppNoClose) XANDLER_DECLARE_BOOLVOID(OnAppNoSleep) XANDLER_DECLARE_BOOLEVENT(OnKey) XANDLER_DECLARE_BOOLEVENT(OnKeyPress) XANDLER_DECLARE_BOOLEVENT(OnKeyRelease) }; #endif // __USRAPPLICATION_HPP //
Example 9.39. Implementation
// // USRApplication.cpp // // This source code was automatically // generated by SophiaFramework UNIVERSE 5.3 // #include "USRApplication.hpp" // boot loader SFCApplet::FactorySPP SFCApplet::Boot(AEECLSID id, SFXAnsiStringPtr license) { // here place the license code *license = "heap://"; return (id == AEECLSID_USRAPPLICATION) ? (&USRApplication::Factory): (null); } // factory function to create the instance of the user-defined application class SFCInvokerPtr USRApplication::Factory(Void) { return::new USRApplication; } // constructor USRApplication::USRApplication(Void) static_throws { // here register the various handlers if (static_try()) { // register the drawing handler static_throw(RegisterHandler( SFXEventRange(SFEVT_RESPONDER_RENDER, SFEVT_RESPONDER_RENDER, SFP16_RENDER_REQUEST, SFP16_RENDER_REQUEST), XANDLER_INTERNAL(OnRenderRequest) )); } if (static_try()) { // register the applet-bootup handler static_throw(RegisterHandler( SFXEventRange(SFEVT_APP_START, SFEVT_APP_START, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnAppStart) )); } if (static_try()) { // register the applet-termination handler static_throw(RegisterHandler( SFXEventRange(SFEVT_APP_STOP, SFEVT_APP_STOP, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnAppStop) )); } if (static_try()) { // register the applet-resume handler static_throw(RegisterHandler( SFXEventRange(SFEVT_APP_RESUME, SFEVT_APP_RESUME, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnAppResume) )); } if (static_try()) { // register the applet-suspend handler static_throw(RegisterHandler( SFXEventRange(SFEVT_APP_SUSPEND, SFEVT_APP_SUSPEND, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnAppSuspend) )); } if (static_try()) { // register the applet-termination confirmation handler static_throw(RegisterHandler( SFXEventRange(SFEVT_APP_NO_CLOSE, SFEVT_APP_NO_CLOSE, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnAppNoClose) )); } if (static_try()) { // register the applet-sleep-confirmation handler static_throw(RegisterHandler( SFXEventRange(SFEVT_APP_NO_SLEEP, SFEVT_APP_NO_SLEEP, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnAppNoSleep) )); } if (static_try()) { // register the key handler static_throw(RegisterHandler( SFXEventRange(SFEVT_KEY, SFEVT_KEY, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnKey) )); } if (static_try()) { // register the key-press handler static_throw(RegisterHandler( SFXEventRange(SFEVT_KEY_PRESS, SFEVT_KEY_PRESS, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnKeyPress) )); } if (static_try()) { // register the key-release handler static_throw(RegisterHandler( SFXEventRange(SFEVT_KEY_RELEASE, SFEVT_KEY_RELEASE, SFP16_BEGIN, SFP16_END), XANDLER_INTERNAL(OnKeyRelease) )); } } // destructor USRApplication::~USRApplication(Void) { } // drawing handler XANDLER_IMPLEMENT_VOIDRENDER(USRApplication, OnRenderRequest, invoker, reason, graphics) { // avoid outputting warning messagess for unsed variable unused(invoker); unused(reason); // here describe the drawing processing when the SFEVT_RESPONDER_RENDER event is received // draw on the device screen graphics->DrawSingleText("Hello World", GetLocalBound(), SFXRGBColor(0x00, 0x00, 0x00, 0x00)); return; } // applet-bootup handler XANDLER_IMPLEMENT_VOIDSTART(USRApplication, OnAppStart, invoker, environment) { // avoid outputting warning messages for unsed variable unused(invoker); unused(environment); // here describe the applet-bootup processing when the SFEVT_APP_START event is received return; } // applet-termination handler XANDLER_IMPLEMENT_VOIDSTOP(USRApplication, OnAppStop, invoker, quitable) { // avoid outputting warning messages for unsed variable unused(invoker); unused(quitable); // here describe the applet-termination processing when the SFEVT_APP_STOP event is received return; } // applet-resume handler XANDLER_IMPLEMENT_VOIDRESUME(USRApplication, OnAppResume, invoker, environment) { // avoid outputting warning messages for unsed variable unused(invoker); unused(environment); // here describe the applet-resume processing when the SFEVT_APP_RESUME event is received return; } // applet-suspend handler XANDLER_IMPLEMENT_VOIDSUSPEND(USRApplication, OnAppSuspend, invoker, reason, info) { // avoid outputting warning messages for unsed variable unused(invoker); unused(reason); unused(info); // here describe the applet-suspend processing when the SFEVT_APP_SUSPEND event is received return; } // applet-terminate-confirmation handler XANDLER_IMPLEMENT_BOOLVOID(USRApplication, OnAppNoClose, invoker) { // avoid outputting warning messages for unsed variable unused(invoker); // return "true" if you refuse to terminate the applet return false; } // applet-sleep-confirmation handler XANDLER_IMPLEMENT_BOOLVOID(USRApplication, OnAppNoSleep, invoker) { // avoid outputting warning messages for unsed variable unused(invoker); // return "true" if you refuse to sleep the applet return false; } // key handler XANDLER_IMPLEMENT_BOOLEVENT(USRApplication, OnKey, invoker, event) { // avoid outputting warning messages for unsed variable unused(invoker); // here describe processing when the SFEVT_KEY event is received // terminate the applet if the SFEVT_KEY event of the SELECT key is recieved switch (event.GetP16()) { case AVK_SELECT: Terminate(); return true; } return false; } // key-press handler XANDLER_IMPLEMENT_BOOLEVENT(USRApplication, OnKeyPress, invoker, event) { // avoid outputting warning messages for unsed variable unused(invoker); unused(event); // here describe processing when the SFEVT_KEY_PRESS event is received return false; } // key release handler XANDLER_IMPLEMENT_BOOLEVENT(USRApplication, OnKeyRelease, invoker, event) { // avoid outputting warning messages for unsed variable unused(invoker); unused(event); // here describe processing when the SFEVT_KEY_RELEASE event is received return false; }
The minimum code of the application class of the applet, which is automatically generated by Application Wizard of SophiaFramework UNIVERSE, is as follows:
Example 9.40. Declaration
// // USRApplication.hpp // // This source code was automatically // generated by SophiaFramework UNIVERSE 5.3 // #ifndef __USRAPPLICATION_HPP #define __USRAPPLICATION_HPP #define TARGET_BUILD_DEBUG #include <SophiaFramework.hpp> #include "USRApplication.bid" SFMTYPEDEFCLASS(USRApplication) class USRApplication: public SFYApplication { SFMSEALCOPY(USRApplication) public: static SFCInvokerPtr Factory(Void); private: explicit USRApplication(Void) static_throws; virtual ~USRApplication(Void); }; #endif // __USRAPPLICATION_HPP //
Example 9.41. Implementation
// // USRApplication.cpp // // This source code was automatically // generated by SophiaFramework UNIVERSE 5.3 // #include "USRApplication.hpp" // boot loader SFCApplet::FactorySPP SFCApplet::Boot(AEECLSID id, SFXAnsiStringPtr license) { // here place the license code *license = "heap://"; return (id == AEECLSID_USRAPPLICATION) ? (&USRApplication::Factory): (null); } // factory function to create the instance of the user-defined application class SFCInvokerPtr USRApplication::Factory(Void) { return::new USRApplication; } // constructor USRApplication::USRApplication(Void) static_throws { // here register various handlers } // destructor USRApplication::~USRApplication(Void) { }
The method to change the text input control editor(default: SFXEditor) which the application class contains internally is as follows:
Tip | |
---|---|
In case the text input problem dependent on the device occurs, you have to define and implement the user-defined text input control editor and replace the dafault text input control editor(SFXEditor) with it. By updating the content of the Open function or the OnBypass function in the following implementation of the SFXEditor class, the the text input problem dependent on the device can be resolved. |
Example 9.42. Method to change the text input control editor
// 1. Create the user-defined "SFXUserEditor" class derived from the SFXBaseEditor class class SFXUserEditor : public SFXBaseEditor { // ... (omitted) ... }; // 2. Pass the SFXUserEditor instance through the argument of the constructor of the user application class // Factory function SFCInvokerPtr USRApplication::Factory(Void) { return ::new USRApplication(::new SFXUserEditor); } // 3. Set the argument of the SFYApplication's constructor to the SFXUserEditor instance // Constructor USRApplication::USRApplication(SFXBaseEditorPtr editor) : SFYApplication(editor) static_throws { if (static_try()) { // ... (omitted) ... } }
The implementation of the SFXEditor class as the default text input control editor is as follows:
Example 9.43. Implementation of the SFXEditor class
------------------------------------------------------------------------------------------------------------ /** *** File : SFXEditor.f.hpp **/ #ifndef __SOPHIAFRAMEWORK_SFXEDITOR_FHPP #define __SOPHIAFRAMEWORK_SFXEDITOR_FHPP #include <SFXGeneral/SFXEnvironment.h.hpp> SFMTYPEDEFCLASS(SFXEditor) #endif // __SOPHIAFRAMEWORK_SFXEDITOR_FHPP // ------------------------------------------------------------------------------------------------------------ /** *** File : SFXEditor.h.hpp **/ #ifndef __SOPHIAFRAMEWORK_SFXEDITOR_HHPP #define __SOPHIAFRAMEWORK_SFXEDITOR_HHPP #include <SFXGeneral/SFXEnvironment.h.hpp> #include <SFXGeneral/SFXBaseEditor.h.hpp> #include <SFXGeneral/SFXEditor.f.hpp> #include <SFXGeneral/SFXEditProperty.f.hpp> #include <SFCCore/SFCApplication.h.hpp> #include <SFBWrapper/SFBTextCtl.h.hpp> class SFXEditor : public SFXBaseEditor { SFMSEALCOPY(SFXEditor) private: SFBTextCtlSmp _textctl; SFBMenuCtlSmp _menuctl; SFXEditPropertyPtr _property; CallbackSPP _spp; VoidPtr _reference; public: explicit SFXEditor (Void); virtual ~SFXEditor (Void); virtual SFCError Open (SFXEditPropertyPtr property, CallbackSPP spp, VoidPtr reference); Void Close (Void); private: XALLBACK_DECLARE_SFCAPPLICATION(OnBypass) }; #include <SFXGeneral/SFXEditor.i.hpp> #endif // __SOPHIAFRAMEWORK_SFXEDITOR_HHPP // ------------------------------------------------------------------------------------------------------------ /** *** File : SFXEditor.i.hpp **/ #ifndef __SOPHIAFRAMEWORK_SFXEDITOR_IHPP #define __SOPHIAFRAMEWORK_SFXEDITOR_IHPP #endif // __SOPHIAFRAMEWORK_SFXEDITOR_IHPP // ------------------------------------------------------------------------------------------------------------ /** *** File : SFXEditor.i.cpp **/ #include <SFXGeneral/SFXEditor.h.hpp> #include <SFXGeneral/SFXDevice.h.hpp> #include <SFXGeneral/SFXEditProperty.h.hpp> #define ITEM_NAME ("Done") #define LABEL_OK 0 /*public */SFXEditor::SFXEditor(Void) : _property(null) { }// SFXEditor::SFXEditor // /*public */SFXEditor::~SFXEditor(Void) { Close(); }// SFXEditor::~SFXEditor // /*public virtual*/SFCError SFXEditor::Open(SFXEditPropertyPtr property, CallbackSPP spp, VoidPtr reference) { #if defined TARGET_ENVIRONMENT_SIMULATOR || defined TARGET_LANGUAGE_ENGLISH static SFXRGBColor::AtomRecConst color[] = { {{{0x00, 0xFF, 0xFF, 0xFF}}}, {{{0x00, 0x00, 0x00, 0x00}}} }; #endif SFBDisplaySmp display; SFXWideString string; SFXRectangle remember; SFXRectangle rectangle; UInt32 flag; SFCError error(SFERR_NO_ERROR); if (property != null) { _property = property; if ((display = SFBDisplay::GetInstance()) != null) { display->GetClipRect(&remember); display->SetClipRect(SFXRectangle::EmptyInstance()); if ((_textctl = SFBTextCtl::NewInstance(GetSFBTextCtlClassID(), &error)) != null) { if ((_menuctl = SFBMenuCtl::NewInstance(GetSFBMenuCtlClassID(), &error)) != null) { if ((error = string.Set(ITEM_NAME)) == SFERR_NO_ERROR) { if (_menuctl->AddItem(LABEL_OK, &string, reinterpret_cast<UInt32>(_menuctl.Get()))) { _textctl->SetSoftKeyMenu(_menuctl); #if defined TARGET_ENVIRONMENT_SIMULATOR || defined TARGET_LANGUAGE_ENGLISH flag = TP_FRAME | TP_MULTILINE | TP_FIXSETRECT; #else flag = TP_NODRAW | TP_FRAME | TP_NOUPDATE | TP_FIXSETRECT; #endif if (_property->GetPasswordMode()) { flag |= TP_PASSWORD; } _textctl->SetProperties(flag); rectangle.Set(SFXGrid::ZeroInstance(), SFXDevice().GetScreenSize()); rectangle.SubBottom(_menuctl->GetRect().GetHeight()); _textctl->SetRect(rectangle); _textctl->SetMaxSize(_property->GetMaximumLength()); _textctl->SetInputMode(_property->GetInputMode()); if (_textctl->SetText(_property->GetText())) { if ((error = RegisterBypass(XALLBACK_INTERNAL(OnBypass))) == SFERR_NO_ERROR) { _spp = spp; _reference = reference; } } else { error = SFERR_FAILED; } } else { error = SFERR_FAILED; } } } } if (error != SFERR_NO_ERROR) { Close(); } display->SetClipRect(remember); if (error == SFERR_NO_ERROR) { #if defined TARGET_ENVIRONMENT_SIMULATOR || defined TARGET_LANGUAGE_ENGLISH display->SetColor(CLR_USER_TEXT, color[1]); display->SetColor(CLR_USER_BACKGROUND, color[0]); display->SetColor(CLR_USER_LINE, color[1]); #endif _textctl->SetActive(true); _textctl->SetCursorPos(TC_CURSORSTART); } } else { error = SFERR_FAILED; } } else { error = SFERR_INVALID_PARAM; } return error; }// SFXEditor::Open // /*public */Void SFXEditor::Close(Void) { if (_textctl != null) { _textctl->SetSoftKeyMenu(SFBMenuCtlSmp::EmptyInstance()); _textctl->SetActive(false); } UnregisterBypass(XALLBACK_INTERNAL(OnBypass)); _textctl.Release(); _menuctl.Release(); _property = null; return; }// SFXEditor::Close // /*private */XALLBACK_IMPLEMENT_SFCAPPLICATION(SFXEditor, OnBypass, event) { SFXWideString string; SFCError error; Bool result(false); result = _textctl->HandleEvent(event); if (!result) { #if defined TARGET_ENVIRONMENT_SIMULATOR result = _menuctl->HandleEvent(event); #endif } switch (event.GetType()) { case SFEVT_APP_RESUME: result = true; break; case SFEVT_APP_SUSPEND: result = true; break; case SFEVT_KEY: case SFEVT_KEY_PRESS: case SFEVT_KEY_RELEASE: #if TARGET_VERSION_LT(3, 0, 0) case SFEVT_KEY_HELD: #endif result = true; break; case SFEVT_COMMAND: if (!result) { switch (event.GetP16()) { case LABEL_OK: if ((error = string.Set(_textctl->GetTextPtr())) == SFERR_NO_ERROR) { if ((error = _property->SetText(string.Substring(0, _property->GetMaximumLength()))) == SFERR_NO_ERROR) { _property->SetInputMode(_textctl->GetInputMode()); } } Close(); if (_spp != null) { (*_spp)(error, _reference); } if ((application = SFCApplication::GetInstance()) != null) { application->RenderDeviceScreen(); } break; default: break; } result = true; } break; default: break; } return result; }// XALLBACK_IMPLEMENT_SFCAPPLICATION(SFXEditor, OnBypass) //
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |