00001 /** $Revision: 1.14 $ 00002 Last updated: $Date: 2002/09/24 19:46:42 $ 00003 00004 Copyright (C) 2001-2002 Vlad Mereuta <dizzy@users.sourceforge.net> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00019 00020 #ifndef __FORM__ 00021 #define __FORM__ 00022 #include <PalmOS.h> 00023 #include "MiscFunc.h" 00024 00025 /** Generic form 00026 All you need to do is derive a class from this one and override the main handle event methods 00027 There are several ways in which forms can be used. If the same form is used in several other forms (with no changes) then it 00028 may be best to implement that form as a singleton and use the reference from other forms. 00029 If the form (say A) is used only once in another form (say B), that an A object can be created inside B. Note that if you use 00030 forms with popup() the A has to be alive for roughly the same amount of time as B. 00031 00032 However, if you use a dialog form (i.e. form closes and returns as soon as a button is pressed) you can define the form object 00033 local to the section it is needed in. 00034 00035 When defining a new form you need to make sure that the Form constructor is called with your form's resource id as a parameter. 00036 This registers the form with the FormManager. If you overload the destructor, you need to call FormManager::instance()->deregisterForm(form_id); 00037 00038 \todo some of the handle functions will need parameters, they will appear as they will get used 00039 */ 00040 class Form 00041 { 00042 public: 00043 /** definition for table selection event. This definition is copied from Core/UI/Event.h */ 00044 typedef struct tblSelect { 00045 UInt16 tableID; 00046 struct TableType *pTable; 00047 Int16 row; 00048 Int16 column; 00049 }; 00050 /** definition for popup item selection event. This definition is copied from Core/UI/Event.h */ 00051 typedef struct popSelect { 00052 UInt16 controlID; 00053 struct ControlType *controlP; 00054 UInt16 listID; 00055 struct ListType *listP; 00056 Int16 selection; 00057 Int16 priorSelection; 00058 }; 00059 00060 /** The form constructor 00061 \todo remove the default =0 as soon as all the form classes have been ported 00062 @param id the identifier of the form resource this form is to serve. make sure you set this */ 00063 Form(UInt16 id) FORM_SECTION2; 00064 00065 /** destructor- unregisters the form */ 00066 virtual ~Form() FORM_SECTION2; 00067 00068 ///returns the saved attribute 00069 Boolean getSaved() { return saved; } 00070 00071 /** sets the saved attribute 00072 @param b the saved state */ 00073 void setSaved(Boolean b) { saved = b; } 00074 00075 /** sets the caller id attribute 00076 @param t the id of the caller */ 00077 void setCallerFormId(UInt16 t) { caller_form_id = t; } 00078 00079 /** use this to obtail the form pointer (to the actual form, not to the object 00080 @return pointer to form managed by class */ 00081 virtual FormPtr getFormPointer() { return frm; } 00082 00083 /** executes popup for the current form */ 00084 virtual void popup() FORM_SECTION2; 00085 00086 /** executes popup for another form, setting the caller_form_id for the popedup form to the 00087 id of the current form 00088 @param form pointer to the form to execute popup for */ 00089 virtual void popup (Form* form) FORM_SECTION2; 00090 00091 /** executes the form as a dialog 00092 @param parent_form if set it will set the active form to the given form pointer */ 00093 UInt16 doDialog(FormPtr parent_form=NULL) FORM_SECTION2; 00094 00095 /** event handler for the form; this function calls automatically the other handle* functions 00096 @param EventPtr pointer to the incoming event 00097 @return true if event was handled, false othewise */ 00098 virtual Boolean handleEvent(EventPtr) FORM_SECTION2; 00099 00100 /** wrapper for FrmGetObjectIndex 00101 @param object_id id of the object (in the current form) to obtain the index for 00102 @return index of the given object */ 00103 UInt16 getObjectIndex (UInt16 object_id) FORM_SECTION2; 00104 00105 ///this function is called when the form is loaded 00106 virtual Boolean handleLoadEvent() FORM_SECTION2; 00107 ///this function is called when the form is closed 00108 virtual Boolean handleCloseEvent() FORM_SECTION2; 00109 00110 protected: 00111 ///pointer to the form 00112 FormPtr frm; 00113 ///true if the form was saved, false otherwise 00114 Boolean saved; 00115 ///the id of the caller form; can be used to enable returning to the correct caller after finishing 00116 UInt16 caller_form_id; 00117 ///the id of the form resource 00118 UInt16 form_id; 00119 00120 ///called when key down event occurs 00121 virtual Boolean handleKeyDownEvent(WChar key_id, UInt16 modifiers) FORM_SECTION2; 00122 ///called when form open event occurs 00123 virtual Boolean handleOpenEvent() FORM_SECTION2; 00124 /** called when ctl select event occurs 00125 @param control_id id of the control for which the event was generated */ 00126 virtual Boolean handleCtlSelectEvent(UInt16 control_id) FORM_SECTION2; 00127 /** called when a table select event occurs 00128 @param tbl_select forwarded tblSelect event data */ 00129 virtual Boolean handleTblSelectEvent(tblSelect& tbl_select) FORM_SECTION2; 00130 /** called when a list select event occurs 00131 @param item item in the list that has been selected (0 based) */ 00132 virtual Boolean handleLstSelectEvent(UInt16 item) FORM_SECTION2; 00133 /** called when a menu event occurs */ 00134 virtual Boolean handleMenuEvent(UInt16 menu_item_id) FORM_SECTION2; 00135 /** called when a form update event occurs 00136 @param update_code the update code signalled */ 00137 virtual Boolean handleUpdateEvent(UInt16 update_code) FORM_SECTION2; 00138 ///handles events generated by the pen up 00139 virtual Boolean handlePenDownEvent (Int16 x_coord, Int16 y_coord) FORM_SECTION2; 00140 /** handles events generated by item selection in popup 00141 @param pop_select forwarded popSelect event data */ 00142 virtual Boolean handlePopSelect (popSelect& pop_select) FORM_SECTION2; 00143 /** handles events generated when field are changed */ 00144 virtual Boolean handleFldChangedEvent() FORM_SECTION2; 00145 /** handles events generated by the scrollbar */ 00146 virtual Boolean handleSclRepeatEvent(UInt16 new_value, UInt16 value) FORM_SECTION2; 00147 }; 00148 00149 00150 #endif