00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 # include <ail.hpp>
00012 #endif
00013
00014 #ifndef __PALM_APP_INC__
00015 # include <PalmApp.inc>
00016 #endif
00017
00018 #ifdef __PALM_OS__
00019
00020 __BEGIN_NAMESPACE__
00022
00023
00024 PalmApp::PalmApp()
00025 : LaunchCode(0), ExitCode(errNone), Flags(0), Timeout(PalmApp::eTimeout)
00026 {
00027
00028 }
00029
00030 PalmApp::~PalmApp()
00031 {
00032 }
00033
00034 void PalmApp::InitInstance()
00035 {
00036 }
00037
00038 void PalmApp::ExitInstance()
00039 {
00040 }
00041
00042 bool PalmApp::Idle(int32 _count)
00043 {
00044 return _count < 1;
00045 }
00046
00047 bool PalmApp::PretranslateI()
00048 {
00049 return false;
00050 }
00051
00052 bool PalmApp::PretranslateII()
00053 {
00054 return false;
00055 }
00056
00057 bool PalmApp::AppHandleEvent()
00058 {
00059
00060 if(CurrEvent.eType == frmLoadEvent)
00061 {
00062 FormType* form = ::FrmInitForm(CurrEvent.data.frmLoad.formID);
00063
00064 if(form != null)
00065 {
00066 ::FrmSetActiveForm(form);
00067 ::FrmSetEventHandler(form, PalmEventManager::DispatchEvent);
00068 return true;
00069 }
00070 }
00071 return false;
00072 }
00073
00074 bool PalmApp::IsIdleEvent()
00075 {
00076
00077 bool power_off = false;
00078
00079 if(CurrEvent.eType == keyDownEvent)
00080 {
00081 if(CurrEvent.data.keyDown.modifiers & commandKeyMask && (CurrEvent.data.keyDown.chr == autoOffChr || CurrEvent.data.keyDown.chr == hardPowerChr))
00082 {
00083 power_off = true;
00084 }
00085 }
00086 return power_off == false && CurrEvent.eType != ctlRepeatEvent && CurrEvent.eType != sclRepeatEvent;
00087 }
00088
00089 #pragma stack_cleanup on
00090
00091 void PalmApp::Run()
00092 {
00093 volatile bool idle = true;
00094 volatile int32 count = 0;
00095
00096
00097 ::WinSetActiveWindow(0);
00098
00099 for(;;)
00100 {
00101 while(idle && !::EvtEventAvail() && !::EvtSysEventAvail(false))
00102 {
00103 if(!Idle(count++))
00104 {
00105 idle = false;
00106 }
00107 }
00108
00109 do
00110 {
00111 if(!RetriveEvent())
00112 {
00113 return;
00114 }
00115
00116 if(IsIdleEvent())
00117 {
00118 idle = true, count = 0;
00119 }
00120 }
00121 while(::EvtEventAvail() || !::EvtSysEventAvail(false));
00122 }
00123 }
00124
00125 bool PalmApp::RetriveEvent()
00126 {
00127 ::EvtGetEvent(&CurrEvent, GetTimeout());
00128
00129 #ifdef __PROCESS_NIL_EVENT__
00130 if(CurrEvent.eType == nilEvent)
00131 {
00132
00133 ExitCode = PalmApp::eUnknownCode;
00134 return false;
00135 }
00136 #endif
00137
00138 if(CurrEvent.eType == appStopEvent)
00139 {
00140
00141 return false;
00142 }
00143
00144 if(!PretranslateI())
00145 {
00146 if(!::SysHandleEvent(&CurrEvent))
00147 {
00148 if(!PretranslateII())
00149 {
00150 uint16 err;
00151
00152 if(!::MenuHandleEvent(null, &CurrEvent, &err))
00153 {
00154 if(!AppHandleEvent())
00155 {
00156 ::FrmDispatchEvent(&CurrEvent);
00157 }
00158 }
00159 }
00160 }
00161 }
00162 return true;
00163 }
00164
00165 #pragma stack_cleanup off
00166
00167 uint32 PalmApp::PilotMain(uint16 _command, void* _command_pbp, uint16 _flags)
00168 {
00169
00170 SetLaunchCode(_command);
00171 SetFlags(_flags);
00172 SetCommandPBP(_command_pbp);
00173 SetExitCode(errNone);
00174
00175
00176 try
00177 {
00178 InitInstance();
00179
00180 if(ExitCode == PalmApp::eOk)
00181 {
00182 Run();
00183 }
00184
00185 ExitInstance();
00186 }
00187 catch(PalmError&)
00188 {
00189 NON_FATAL_ERROR("The Application unexpectedly terminated");
00190 }
00191 catch(...)
00192 {
00193 FATAL_ERROR("The Application unexpectedly terminated");
00194 }
00195 return ExitCode;
00196 }
00197
00198 void PalmApp::Quit()
00199 {
00200 EventType event;
00201 event.eType = appStopEvent;
00202 ::EvtAddEventToQueue(&event);
00203 }
00205
00206
00207 void PalmApp::XPalmApp::LoadErrorDescriptions()
00208 {
00209
00210 PalmError::LoadErrorDescriptions();
00211 }
00213
00214
00215 extern "C" uint32 PilotMainCStub(uint16, void*, uint16)
00216 {
00217 return errNone;
00218 }
00220 __END_NAMESPACE__
00221
00222 #endif // __PALM_OS__
00223