MorePalmOS
A development library for developing Palm OS applications

MoreForm.c

Go to the documentation of this file.
00001 /******************************************************************************
00002  * MorePalmOS
00003  * Copyright (c) 2004 Steven Fisher
00004  *
00005  * Distributed under the Boost Software License, Version 1.0. See accompanying
00006  * license file License.txt or <http://www.boost.org/LICENSE_1_0.txt>.
00007  *
00008  * http://morepalmos.sourceforge.net
00009  *
00010  *   MorePalmOS is the humble begining of an attempt to provide a library for
00011  *   Palm OS development which works around system bugs, illustrate how to
00012  *   use system calls, and provide "glue code" for programming Palm OS
00013  *   applications in a more straightforward way while minimally impacting
00014  *   code size.
00015  *****************************************************************************/
00016 
00017 #include "MorePrefix.h"
00018 #include "MoreForm.h"
00019 #include "MoreField.h"
00020 #include "MorePrivate.h"
00021 
00022 #include <Control.h>
00023 
00024 void MFrmHandleAppOpenFormEvt( ResourceID_t formID,
00025                 FormEventHandlerType* handler )
00026 {
00027         FormType* formP = FrmInitForm( formID );
00028         FrmSetActiveForm( formP );              
00029         FrmSetEventHandler( formP, handler );
00030 }
00031 
00032 //-----------------------------------------------------------------------------
00033 
00034 FrmObjectID_t MFrmHandleModalForm( ResourceID_t formID,
00035                 FormEventHandlerType* handler )
00036 {
00037         FormType* previousFormP = FrmGetActiveForm( );
00038         FormType* dialogP = FrmInitForm( formID );
00039         UInt16 button;
00040         FrmSetActiveForm( dialogP );
00041         if ( handler )
00042         {
00043                 FrmSetEventHandler( dialogP, handler );
00044         };
00045         FrmPopupForm( formID );
00046         button = FrmDoDialog( dialogP );
00047         FrmReturnToForm( previousFormP ? FrmGetFormId( previousFormP ) : 0 );
00048         return button;
00049 }
00050 
00051 //-----------------------------------------------------------------------------
00052 
00053 FrmObject_t* MFrmGetObjPtrByID( const FormType* formP, FrmObjectID_t id )
00054 {
00055         _validate_const_form_ptr( formP );
00056         return FrmGetObjectPtr( formP, _validate_object_idx( formP,
00057                                 FrmGetObjectIndex( formP, id ) ) );
00058 }
00059 
00060 FrmObject_t* MFrmGetObjPtrByIdx( const FormType* formP, FrmObjectIdx_t idx )
00061 {
00062         _validate_const_form_ptr( formP );
00063         return FrmGetObjectPtr( formP, idx );
00064 }
00065 
00066 //-----------------------------------------------------------------------------
00067 
00068 FrmObject_t* MFrmGetObjPtrOfTypeByID( const FormType* formP, FrmObjectID_t id,
00069                 FormObjectKind kind )
00070 {
00071         FrmObjectIdx_t idx = FrmGetObjectIndex( formP, _validate_object_id( formP, id ) );
00072         _validate_object_idx( formP, idx );
00073         if ( ( idx != frmInvalidObjectId ) && ( FrmGetObjectType( formP, idx ) == kind ) )
00074                 return FrmGetObjectPtr( formP, idx );
00075         else
00076                 return NULL;
00077 }
00078 
00079 FrmObject_t* MFrmGetObjPtrOfTypeByIdx( const FormType* formP, FrmObjectIdx_t idx,
00080                 FormObjectKind kind )
00081 {
00082         _validate_object_idx( formP, idx );
00083         if ( ( idx != frmInvalidObjectId ) && ( FrmGetObjectType( formP, idx ) == kind ) )
00084                 return FrmGetObjectPtr( formP, idx );
00085         else
00086                 return NULL;
00087 }
00088 
00089 FrmObject_t* MFrmGetObjPtrOfTypeByPtr( const FormType* formP, FrmObject_t* ptr,
00090                 FormObjectKind kind )
00091 {
00092         FrmObjectIdx_t idx = FrmGetObjectIndexFromPtr( formP, _validate_object_ptr( ptr ) );
00093         _validate_object_idx( formP, idx );
00094         if ( ( idx != frmInvalidObjectId ) && ( FrmGetObjectType( formP, idx ) == kind ) )
00095                 return FrmGetObjectPtr( formP, idx );
00096         else
00097                 return NULL;
00098 }
00099 
00100 //-----------------------------------------------------------------------------
00101 
00102 FormObjectKind MFrmGetObjTypeByID( const FormType* formP, FrmObjectID_t id )
00103 {
00104         _validate_object_id( formP, id );
00105         return FrmGetObjectType( formP, _validate_object_idx( formP,
00106                                         FrmGetObjectIndex( formP, id ) ) );
00107 }
00108 
00109 FormObjectKind MFrmGetObjTypeByIdx( const FormType* formP, FrmObjectIdx_t idx )
00110 {
00111         _validate_object_idx( formP, idx );
00112         return FrmGetObjectType( formP, idx );
00113 }
00114 
00115 FormObjectKind MFrmGetObjTypeByPtr( const FormType* formP, FrmObject_t* objectP )
00116 {
00117         return FrmGetObjectType( formP, FrmGetObjectIndexFromPtr( formP, objectP ) );
00118 }
00119 
00120 //-----------------------------------------------------------------------------
00121 
00122 void MFrmSetObjVisibleByID( FormType* formP, FrmObjectID_t id,
00123                 Boolean visible )
00124 {
00125         _validate_object_id( formP, id );
00126 
00127         MFrmSetObjVisibleByIdx( formP, FrmGetObjectIndex( formP, id ), visible );
00128 }
00129 
00130 void MFrmSetObjVisibleByIdx( FormType* formP, FrmObjectIdx_t idx,
00131                 Boolean visible )
00132 {
00133         _validate_object_idx( formP, idx );
00134         if ( visible )
00135                 FrmShowObject( formP, idx );
00136         else
00137                 FrmHideObject( formP, idx );
00138 }
00139 
00140 void MFrmSetObjVisibleByPtr( FormType* formP, FrmObject_t* objectP,
00141                 Boolean visible )
00142 {
00143         _validate_form_ptr( formP );
00144         _validate_object_ptr( objectP );
00145         MFrmSetObjVisibleByIdx( formP, FrmGetObjectIndexFromPtr( formP, objectP ),
00146                         visible );
00147 }
00148 
00149 //-----------------------------------------------------------------------------
00150 
00151 void MFrmReload( )
00152 {
00153         FrmGotoForm( FrmGetActiveFormID( ) );
00154 }
00155 
00156 //-----------------------------------------------------------------------------
00157 
00158 void MFrmSetFocusByID( FormType* formP, FrmObjectID_t objectId )
00159 {
00160         _validate_object_id( formP, objectId );
00161         FrmSetFocus( formP, FrmGetObjectIndex( formP, objectId ) );
00162 }
00163 
00164 void MFrmSetFocusByPtr( FormType* formP, FrmObject_t* objectP )
00165 {
00166         _validate_form_ptr( formP );
00167         _validate_object_ptr( objectP );
00168         FrmSetFocus( formP, FrmGetObjectIndexFromPtr( formP, objectP ) );
00169 }
00170 
00171 //-----------------------------------------------------------------------------
00172 
00173 void MFrmNudgeObjXYByID( FormType* formP, FrmObjectID_t id,
00174                 Coord deltaX, Coord deltaY, Boolean redraw )
00175 {
00176         _validate_object_id( formP, id );
00177         MFrmNudgeObjXYByIdx( formP, FrmGetObjectIndex( formP, id ),
00178                         deltaX, deltaY, redraw );
00179 }
00180 
00181 void MFrmNudgeObjXYByIdx( FormType* formP, FrmObjectIdx_t idx,
00182                 Coord deltaX, Coord deltaY, Boolean redraw )
00183 {
00184         Coord x, y;
00185         _validate_object_idx( formP, idx );
00186 
00187         FrmGetObjectPosition( formP, idx, &x, &y );
00188 
00189         if ( redraw )
00190         {
00191                 FrmHideObject( formP, idx );
00192         }
00193 
00194         FrmSetObjectPosition( formP, idx, x + deltaX, y + deltaY );
00195 
00196         if ( redraw )
00197         {
00198                 FrmShowObject( formP, idx );
00199         }
00200 }
00201 
00202 void MFrmNudgeObjXYByPtr( FormType* formP, FrmObject_t* objectP,
00203                 Coord deltaX, Coord deltaY, Boolean redraw )
00204 {
00205         _validate_object_ptr( objectP );
00206         MFrmNudgeObjXYByIdx( formP, FrmGetObjectIndexFromPtr( formP, objectP ),
00207                         deltaX, deltaY, redraw );
00208 }

SourceForge.net Logo