Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FormManager.h

Go to the documentation of this file.
00001 /** $Revision: 1.12 $
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_MANAGER__
00021 #define __FORM_MANAGER__
00022 
00023 #include "FreeCoinsRsc.h"
00024 #include "Form.h"
00025 #include <PalmOS.h>
00026 
00027 
00028 /** This class manages dispatching Form events, by using Form classes instead of the normal C mechanism provided by PalmOS.
00029     The current implementation is jusr a hack, but it seems to work rather well.
00030 
00031     The idea behind this is to keep a dictionary of form_id's and the associated form pointers.  This way any kind of
00032     events can be dispatched to the right form, provided the form registered with the manager (i.e. the manager know
00033     what form handles the form_id which is targeted by the incoming event.
00034 
00035     Please note that this class is a Singleton. Ummm sort of that is. more like a singleton hack. Point is that you are only meant
00036     to access it via the frm_mngr pointer, which in turn is automatically initialised at the first
00037     call to registerForm (so *DO NOT* calll any other method before register form)
00038 
00039     \todo class should be reimplemented. May be convenient to use a linked list instead of a fixed size array */
00040 
00041 class FormManager
00042 {
00043 public:
00044     /** returns a reference to FormManager. This is the only allowed way to access this class */
00045     static FormManager* instance();
00046     /** destroys the instance (if no forms are still registred) */
00047     static void destroyInstance() FORM_SECTION2;
00048     /** instructs the FormManger to destroy its instance immidiately if possible or when all forms have been de-registred */
00049     void suicide() FORM_SECTION2;
00050     /** this function  adds the details given by the paramaters to the forms array
00051         @param form_id id of the form to be added
00052         @param form pointer to the form to be added. All events will be re-routed via this pointer */
00053     void registerForm(UInt16 form_id, Form* form) FORM_SECTION2;
00054     /** removes a form from the forms array containing registred forms */
00055     void deregisterForm(UInt16 form_id) FORM_SECTION2;
00056     /** rearanges the forms array in such a way that the given form always receives the events
00057         first. This is useful when a given form has more than one instance, all active at the same
00058         time and they are all sharing the same form_id
00059         @param form_id id of the form resource
00060         @param form pointer to form to handle events for this resource first. */
00061     void bringToFront (UInt16 form_id, Form* form) FORM_SECTION2;
00062     /** dispatches event to the right form (if registred)
00063         @param event event to be dispatched */
00064     Boolean dispatchEvent(EventPtr event) FORM_SECTION2;
00065     /** dispatches a load event to a given form
00066         @param form_id form to dispatch load event to */
00067     Boolean dispatchLoadEvent(UInt16 form_id) FORM_SECTION2;
00068     /** dispatches a close event to a given form
00069         @param form_id form to dispatch load event to */    
00070     Boolean dispatchCloseEvent(UInt16 form_id) FORM_SECTION2;
00071 
00072 private:
00073     ///form information stored by the manager
00074     struct  form_info {
00075         ///id of the form
00076         UInt16  form_id;
00077         ///pointer to the form
00078         Form*   frm;
00079         ///flag signaling whether the form is active or not
00080         Boolean active;
00081     };
00082     
00083     ///maximum number of forms that can be handled (active at the same time)
00084     const static UInt8 max_forms=25;
00085 
00086     ///information on all forms
00087     form_info forms[max_forms];
00088 
00089     ///singleton reference to this class
00090     static FormManager* _instance;
00091     ///flag indicating whether the FormManager is required to kill itself. this cannot be accomplished while forms are still registred
00092     static Boolean _destroy_requested;
00093     ///number of forms currently registred with the FormManager
00094     static UInt8 _form_count;
00095 
00096     ///constructor; initialises the forms array (private to prevent accidental duplication)
00097     FormManager() FORM_SECTION2;
00098 };
00099 
00100 #endif

Generated on Thu Jan 16 23:11:12 2003 for FreeCoins by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002