Update of /cvsroot/easycalc/PPCport/discarded/calc-dia In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv27240 Added Files: config.h DIA.c DIA.h DIA.txt resize.c resize.h resizeconsts.h sects.h util_dia.h Log Message: 1.25b --- NEW FILE: config.h --- /* File name: config.h Copyright 2006 Ton van Overbeek This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. * * Summary * Config file for PalmResize DIA support in EasyCalc. * */ #ifndef _CONFIG_H_ #define _CONFIG_H_ #ifdef SONY_SDK #define SUPPORT_DIA_SONY #endif #ifdef HANDERA_SDK #define SUPPORT_DIA_HANDERA #endif #endif --- NEW FILE: DIA.h --- /* $Id: DIA.h,v 1.1 2009/11/02 17:29:23 mapibid Exp $ */ /******************************************************************************* Copyright (c) 2004, Alexander R. Pruss All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #ifndef _ARP_DIA_H #define _ARP_DIA_H #ifndef _Str #define _Str(x) #x #endif /* */ //#include "viewer.h" #include "resize.h" typedef enum { DIA_HARDWARE_NONE = 0, DIA_HARDWARE_HANDERA, DIA_HARDWARE_SONY1, DIA_HARDWARE_SONY2, DIA_HARDWARE_PALM10, DIA_HARDWARE_PALM11, DIA_HARDWARE_UNKNOWN } DIAHardwareType; #ifdef SUPPORT_DIA extern DIAHardwareType InitializeDIA(void) DIA_SECTION; extern void TerminateDIA(void) DIA_SECTION; extern void SetDIAState(DIAStateType state) DIA_SECTION; extern void SetDIAAllowResize(Boolean allow) DIA_SECTION; extern Boolean HandleResizeNotification(UInt32 notificationType) DIA_SECTION; extern DIAStateType GetDIAState(void) DIA_SECTION; extern void SetCustomDIAPolicy(UInt16 formID) DIA_SECTION; extern DIAHardwareType GetDIAHardware(void) DIA_SECTION; extern void SetDIAConstraints(WinHandle winH, Boolean defaultBig, Boolean allowBig) DIA_SECTION; /* Check which DIA state covers more screen space */ extern Int16 CompareDIAState(DIAStateType x, DIAStateType y) DIA_SECTION; extern void GetHiddenStatusBarArea(RectangleType * area) DIA_SECTION; /* These two functions should NOT be used by code other than that in resize.c and DIA.c. */ extern void PushCoordinateSystemToStandard(void) DIA_SECTION; extern void PopCoordinateSystem(void) DIA_SECTION; extern FontID HanderaAdjustFont(FontID font) DIA_SECTION; extern Coord HanderaCoord(Coord x) DIA_SECTION; #else /* */ #define InitializeDIA() DIA_HARDWARE_NONE #define TerminateDIA() #define SetDIAState( s ) #define SetDIAAllowResize( a ) #define HandleResizeNotification( n ) false #define GetDIAState() DIA_STATE_MAX #define SetCustomDIAPolicy( f ) #define GetDIAHardware() DIA_HARDWARE_NONE #define SetDIAConstraints( w, d, a ) #define CompareDIAState( x, y ) 0 #define GetHiddenStatusBarArea( a ) MemSet( a, sizeof( RectangleType ), 0 ) #define HanderaAdjustFont( font ) ( font ) #define HanderaCoord( x ) ( x ) #endif /* */ #endif /* _ARP_DIA_H */ --- NEW FILE: DIA.txt --- $Id: DIA.txt,v 1.1 2009/11/02 17:29:23 mapibid Exp $ The code in DIA.c does the low-level stuff of communicating with the DIA hardware or more generally hardware that supports non-standard screen sizes. The code has been tested with Sony OS4, Sony OS5 (portrait and landscape), Handera (portrait), Palm OS5.2+ (portrait and landscape), Dana Alphasmart (wide or tall). This code is covered by the following license: Copyright (c) 2004, Alexander R. Pruss All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the PalmResize Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. To support DIA in your application, you need to do a couple of things. 0. Obtain the Sony SDK: http://www.jp.sonystyle.com/Clie-dev/develop_tool/index.html if you want to support Sony code. Obtain the Handera SDK if you want to support Handera code. 1. To support Sony, compile DIA.c with -DSUPPORT_DIA_SONY. To support Handera, compile DIA.c with -DSUPPORT_DIA_HANDERA. Additionally, you must always have -DSUPPORT_DIA if you want any DIA support, or you can put #define SUPPORT_DIA in a config.h file (which must in any case be available but can be empty). HAVE_SILKSCREEN is a synonym for SUPPORT_DIA. Also, ensure that you have a sects.h file that correctly sets the code sections for DIA_SECTION and RESIZE_SECTION. If your application doesn't do sectioning, you can just do: #define DIA_SECTION #define RESIZE_SECTION You also need to ensure that you have defined SafeMemPtrNew() and SafeMemPtrFree() code and you have prototypes for these in util.h. SafeMemPtrFree() should return if fed a NULL pointer, else call MemPtrFree(), and SafeMemPtrNew() should produce a fatal application error if MemPtrNew() fails. If you don't care about error checking, you can always do something like: #define SafeMemPtrNew MemPtrNew #define SafeMemPtrFree( p ) if ( ( p ) != NULL ) MemPtrFree( ( p ) ) For Palm DIA support, you need the 5r3 SDK, and all should be well: no need for special #defines. 2. In your application initialization (E.g., StartApplication()) code, call InitializeResizeSupport( indexDIADataID ) make sure this happens before the event handlers for your forms are set. In your application de-initialization, call TerminateResizeSupport(). 3. In the place in your application where you handle notifications, before processing any notifications, add a call to: Boolean HandleResizeNotification( UInt32 notificationType ) This routine returns true if it has handled a resize notification, in which case you do not need to handle the notification yourself. Note that the relevant notification is automatically registered for by InitializeResizeSupport() and that the notification type depends on your hardware platform. 4. Before setting the event handler for form formID, call SetResizePolicy( formID ). 5. In each form event handler, make sure that before doing any handling yourself, you call the function: Boolean ResizeHandleEvent( EventType* event ) RESIZE_SECTION; If this function returns true, your event handler should return true; otherwise, you should handle the event yourself. This applies even to form event handlers where you do not want any resizing. However, you do not need to include resize data resources for such forms--just the call to ResizeHandleEvent(). Earlier versions of PalmResize required calling separate handling functions for different event types. This is deprecated now and may no longer work in the future. 5. Modify your .rcp file to include information on how to resize forms. This is done by including a number of WORDLIST (wrdl) resources. The first and the only non-optional one is an index resource of word pairs. WORDLIST ID indexDIADataID BEGIN fromID1 toID1 fromID2 toID2 ... END The ID indexDIADataID is the same as the one in the InitializeResizeSupport() call. The list of word pairs then each contains the ID of a form resource followed by the ID of the WORDLIST resource that contains the DIA resize data for that form. DIA is disabled for any forms not listed in the index: virtual graffiti is popped up and resize is disabled if possible. It is perfectly acceptable to have no forms in the index or not all of them. Unless this conflicts with other WORDLIST IDs you might be using, it is easiest to use the same ID for the resize data as for the form, so PalmBible+'s index, for instance, starts: frmMain frmMain frmVersionInfo frmVersionInfo frmMemoEdit frmMemoEdit 6. Now include specific information on how to resize the forms in your application. You should #include "resizeconsts.h" in your .rcp file to define various bitmapped flags. Each set of information has the following format: WORDLIST ID resizeFormID BEGIN formFlags binNumber preferredState // Object data objectNum1 flags1 0 objectNum2 flags2 0 ... END formFlags is either 0 or a combination of: DIA_FORM_KEEP_LAST DIA_FORM_USE_BIN DIA_FORM_NO_RESIZE DIA_FORM_HANDERA These flags, as all flags, can be added together, e.g.: DIA_FORM_KEEP_LAST + DIA_FORM_USE_BIN DIA_FORM_KEEP_LAST: The form keeps the DIA state that was in force before it was opened, unless the form uses a bin, and the bin has defined data. If this flag is set, binNumber is ignored (but must still be included--perhaps set to zero). DIA_FORM_USE_BIN: A given application can include a number of "DIA state bins." All forms that use the same bin share the same DIA setting, and if a user resizes a form in the bin, all the other forms in the bin are resized. For instance, modal dialogs might be put all in one bin. Or, items which do not require graffiti might be put in another bin. When an application starts up, unless the bin data is loaded from the application's preferences database, each bin entry is undefined. The DIA_FORM_USE_BIN flag interacts with the DIA_FORM_KEEP_LAST flag as follows: if the bin has not yet been defined, the bin and the form get the DIA state in force when the form was opened. Without a DIA_FORM_KEEP_LAST flag, the bin starts off being set to preferredState. Without either of these flags, whenever the form is opened, the DIA is set to preferredState. DIA_FORM_HANDERA: The form is pre-measured for Handera 240x240 screens and does not need to be re-adjusted for them. Otherwise, if DIA support is linked in, the form is re-adjusted from 160x160 to 240x240. preferredState is one of: DIA_STATE_MAX DIA_STATE_MIN DIA_STATE_NO_STATUS_BAR If DIA_FORM_KEEP_LAST is specified, this is ignored but must still be included. The MAX and MIN refer to the size of the DIA area. Thus, with DIA_STATE_MAX, the screen is typically minimized to the standard 160x160 (or 320x320) area. With DIA_STATE_MIN, the DIA is contracted, and the maximum screen size is available. DIA_STATE_NO_STATUS_BAR is the same as DIA_STATE_MIN on Handera units, but on the Sony NR/NX/NZ/UX/TH and Palm DIA devices it opens a full screen mode with no status bar. Make sure you give the user a way of exiting this! Sony recommends you do this by letting the user tap on the place where the status bar used to be in order to restore the status bar. Finally, you get a list of object resize data. This is the part of the resize information that will take the most work. By default, objects do not resize--they stay the same size, and the same position relative to the top left corner of the display. Any objects which you want to move or resize with DIA changes must be listed here. The first object (whose objectNum1 is ignored, but must still be included, e.g., set to 0) is always the form itself, and its resizing is relative to the whole screen. The other objects resize relative to the form. At least the form itself must be included. Each object resize line starts with the object ID (ignored for the form itself, and set to the special value GSI_OBJECT_ID (65280) for the graffiti state indicator--make sure this value is not used for anything else in your form), then has a word specifying a combination of flags or 0 if the object does not need to change size or position, followed by a reserved word that should contain 0. The object flags are a combination of: DIA_X_RATIO DIA_Y_RATIO DIA_W_RATIO DIA_H_RATIO DIA_X_RIGHT DIA_Y_BOTTOM DIA_X_PLUS_DW DIA_Y_PLUS_DH DIA_W_PLUS_DW DIA_H_PLUS_DH DIA_X_PLUS_1_2_DW DIA_Y_PLUS_1_2_DH DIA_W_PLUS_1_2_DW DIA_H_PLUS_1_2_DH DIA_X_PLUS_1_3_DW DIA_Y_PLUS_1_3_DH DIA_W_PLUS_1_3_DW DIA_H_PLUS_1_3_DH DIA_X_PLUS_2_3_DW DIA_Y_PLUS_2_3_DH DIA_W_PLUS_2_3_DW DIA_H_PLUS_2_3_DH DIA_X_PLUS_1_4_DW DIA_Y_PLUS_1_4_DH DIA_W_PLUS_1_4_DW DIA_H_PLUS_1_4_DH DIA_X_PLUS_3_4_DW DIA_Y_PLUS_3_4_DH DIA_W_PLUS_3_4_DW DIA_H_PLUS_3_4_DH These flags specify how the four relevant positioning values are changed. These values are X (horizontal coordinate), Y (vertical coordinate), W (width), H (height). You can at most include one DIA_X_* flag, one DIA_Y_* flag, one DIA_W* and one DIA_H* flag. If you omit a flag for one of the positioning values, the value is unchanged. The positioning values have the following meanings: *_RATIO : Keep the ration of the value relative to the extent of the form/display (i.e., for objects other than the form, extent of the form, and for the form, extent of the display) constant. Thus, if the object was originally 37% of the height of the form down in the form, then DIA_Y_RATIO will try to keep the object at 37% of the height of the resized form down in the form. If the object took up half of the width of the form, it will still do so if you set DIA_W_RATIO. X_RIGHT : This ensures that the distance from the right edge of the screen to the right edge of the object does not change with resizing. If the form is widened, the object moves right. Y_BOTTOM : This ensures that the distance from the bottom edge of the screen to the bottom edge of the object does not change with resizing. If the form is lengthened, the object moves down. *_PLUS_D[WH] : This says that the value should have added to it the amount of the change in the width (DW) or height (DH) that the form/display had. *_PLUS_*_D[WH] : This is the same as *_PLUS_D[WH] except only the specified fraction of the change in the width or height is added. The fraction is one of 1_2 (1/2), 1_3 (1/3), 2_3 (2/3), 1_4 (1/4) or 3_4 (1/4). Use this when you have two to four objects horizontally or vertically arranged which you would like to resize equally. Make sure that objects to the right or below them get the right *_PLUS_*_D[WH] or X_RIGHT or Y_BOTTOM attributes. For instance, if you have two side-by-side list boxes, you might do: listbox1 DIA_W_PLUS_1_2_DW+DIA_H_PLUS_DH 0 listbox2 DIA_X_PLUS_1_2_DW+DIA_W_PLUS_1_2_DW+DIA_H_PLUS_DH 0 This way, listbox1 and listbox2 each get the full benefit of any form lengthening (DIA_H_PLUS_DH), and each get half of the benefit of the form widening (DIA_W_PLUS_1_2_DW). Moreover, we made sure that listbox2 would be placed further to the right to compensate for listbox1 widening, as needed. Additionally, there is a DIA_H_GRANULAR attribute which forces the height for a list or field to be an integral number of rows, unless this would force the height to be zero. 7. Unfortunately, currently (as of pilrc 3.2 beta 1), pilrc does not support arithmetic in WORDLIST resources. This is a serious problem for adding up flags. The recommended solution is the following. Run the .rcp file through cpp, after first changing final \ to @backslash@ with sed (otherwise multiline strings are mangled; if there aren't any such, nevermind). Then run the resulting file through the doaddition.pl perl script which (a) does the arithmetic inside WORDLIST resources and changes each final @backslash@ back to \. doaddition.pl is not very smart. Make sure that WORDLIST is all caps and that WORDLIST, BEGIN and END are all flush on the left margin in the .rcp file. The following should do the trick: sed 's/\\$$/@backslash@/' < file.rcp | cpp | perl doaddition.pl > file.rcp.out Then run pilrc on file.rcp.out. 8. If you have the Sony status bar hidden, Sony recommends that you allow the user to restore the area via a tap in that hidden area. To this end, you can use void GetHiddenStatusBarArea( RectangleType* area ) to get the area covered by the status bar (in current coordinates under OS5, and in standard coordinates otherwise). If the status bar is showing, an empty rectangle is returned. 9. Finally, you can call void ResizeRefreshCurrentForm( void ); to refresh the current form's DIA settings and redraw the form. Normally there should be no need to call this if you've followed the above instructions. A need to call this suggests a bug in resize.c or in your code. But this may be a temporary work-around until the bug is fixed. 10. For Handera support, your .rcp file should contain: HEX "sKst" ID 1000 0x00 0x00 0x00 0x00 You also need the Handera SDK. It's no longer available from the Handera website. You can get it from the non-free directory of the source distribution of the latest PalmBible+ release: palmbibleplus.sf.net . Moreover, to avoid using 2/3 size fonts, you should replace all calls FntSetFont( f ) with calls FntSetFont( HanderaAdjustFont( f ) ). You can also use HanderaCoord( x ) to convert from standard 160x160 coordinates to 240x240. Both functions just return their argument unchanged not on a Handera system. 11. For Dana AlphaSmart support, your .rcp file should contain: HEX "wTap" ID 1000 0x00 0x00 0x00 0x01 12. You can save and restore the user's DIA bin settings to prefs, so that each bin keeps the same state between sessions. To restore settings, right after calling InitializeResizeSupport(), call extern void LoadResizePrefs( UInt32 appID, UInt16 prefID ) RESIZE_SECTION; with your apps appID and with a prefID you aren't using as a preference ID for anything else. To save settings, right before calling TerminateResizeSupport(), call: extern void SaveResizePrefs( UInt32 appID, UInt16 prefID, Int16 version ) RESIZE_SECTION; The arguments have the same meaning, except you need to specify a version number for your pref. You can just put 0 each time if you want. 13. If you need to make additional modifications to your form after a resize, these modifications should be made in a handler for winDisplayChangedEvent. Note that after a ResizeSupportInitialize() call, this event is emitted on all supported hardware when the silk/DIA area resizes or when the screen orientation changes, so you don't have to worry about the fact that, say, normally Sony OS4 units don't emit it. If you opt to use the deprecated method of calling ResizeHandleWinDisplayChangedEvent() from the handler instead of calling ResizeHandleEvent(), you should make custom modifications after ResizeHandleWinDisplayChangedEvent() is done. Note that you can reliably count on a frmUpdateFormEvent happening (with updateCode == redrawUpdateCode) at some point soon after the winDisplayChangedEvent handler gets done, so you do not need to enqueue a frmUpdateFormEvent yourself. You can also do all your changes from within a frmUpdateFormEvent handler. Such additional changes need to be made, for instance, for tables. While palmResize will resize the outside dimensions, you need to decide whether to resize the cells, insert more cells, or whatever. 14. A demo of how to run palmResize is in the demo directory. You may need to edit the Makefile to get it to compile. --- NEW FILE: resizeconsts.h --- /* $Id: resizeconsts.h,v 1.1 2009/11/02 17:29:23 mapibid Exp $ */ /******************************************************************************* Copyright (c) 2004, Alexander R. Pruss All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the PalmResize Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /* Object attribute flags */ #define DIA_MASK_X 15 /* 0x000F */ #define DIA_MASK_Y 240 /* 0x00F0 */ #define DIA_MASK_W 1792 /* 0x0700 */ #define DIA_MASK_H 28672 /* 0x7000 */ #define DIA_SHIFT_X 0 #define DIA_SHIFT_Y 4 #define DIA_SHIFT_W 8 #define DIA_SHIFT_H 12 #define DIA_X_FIX 0 /* 0x0000 */ #define DIA_Y_FIX 0 /* 0x0000 */ #define DIA_W_FIX 0 /* 0x0000 */ #define DIA_H_FIX 0 /* 0x0000 */ #define DIA_X_RATIO 7 /* 0x0007 */ #define DIA_Y_RATIO 112 /* 0x0070 */ #define DIA_W_RATIO 1792 /* 0x0700 */ #define DIA_H_RATIO 28672 /* 0x7000 */ #define DIA_X_RIGHT 8 /* 0x0008 */ #define DIA_Y_BOTTOM 128 /* 0x0080 */ #define DIA_X_PLUS_DW 1 /* 0x0001 */ #define DIA_Y_PLUS_DH 16 /* 0x0010 */ #define DIA_W_PLUS_DW 256 /* 0x0100 */ #define DIA_H_PLUS_DH 4096 /* 0x1000 */ #define DIA_X_PLUS_1_2_DW 2 /* 0x0002 */ #define DIA_Y_PLUS_1_2_DH 32 /* 0x0020 */ #define DIA_W_PLUS_1_2_DW 512 /* 0x0200 */ #define DIA_H_PLUS_1_2_DH 8192 /* 0x2000 */ #define DIA_X_PLUS_1_3_DW 3 /* 0x0003 */ #define DIA_Y_PLUS_1_3_DH 48 /* 0x0030 */ #define DIA_W_PLUS_1_3_DW 768 /* 0x0300 */ #define DIA_H_PLUS_1_3_DH 12288 /* 0x3000 */ #define DIA_X_PLUS_2_3_DW 4 /* 0x0004 */ #define DIA_Y_PLUS_2_3_DH 64 /* 0x0040 */ #define DIA_W_PLUS_2_3_DW 1024 /* 0x0400 */ #define DIA_H_PLUS_2_3_DH 16384 /* 0x4000 */ #define DIA_X_PLUS_1_4_DW 5 /* 0x0005 */ #define DIA_Y_PLUS_1_4_DH 80 /* 0x0050 */ #define DIA_W_PLUS_1_4_DW 1280 /* 0x0500 */ #define DIA_H_PLUS_1_4_DH 20480 /* 0x5000 */ #define DIA_X_PLUS_3_4_DW 6 /* 0x0006 */ #define DIA_Y_PLUS_3_4_DH 96 /* 0x0060 */ #define DIA_W_PLUS_3_4_DW 1536 /* 0x0600 */ #define DIA_H_PLUS_3_4_DH 24576 /* 0x6000 */ #define DIA_H_GRANULAR 32768 /* 0x8000 */ /* Form attribute flags */ /* Try to keep the same DIA state as in previous form */ #define DIA_FORM_KEEP_LAST 1 /* Keep the same DIA state as previous form using the same bin */ /* If DIA_FORM_KEEP_LAST and DIA_FORM_USE_BIN are both set, then we keep last DIA state to get the initial DIA state for the bin the first time a form from that bin is used. */ #define DIA_FORM_USE_BIN 2 /* Disable DIA state change */ #define DIA_FORM_NO_RESIZE 4 /* Handera-specific form */ #define DIA_FORM_HANDERA 8 #define STD_EXTENT_X 160 #define STD_EXTENT_Y 160 #define MAX_EXTENT_X 4096 #define MAX_EXTENT_Y 4096 #define DIA_STATE_MAX 0 #define DIA_STATE_MIN 1 #define DIA_STATE_NO_STATUS_BAR 2 #define DIA_STATE_UNDEFINED 255 /* No actual object is allowed to have this--this is used within resize config info */ #define GSI_OBJECT_ID 65280 /* 0xFF00 */ --- NEW FILE: sects.h --- /* File name: sects.h Copyright 2006 Ton van Overbeek This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. * * Summary * Section defines for PalmResize DIA support in EasyCalc. * */ #ifndef _SECTS_H_ #define _SECTS_H_ #include "segment.h" #define RESIZE_SECTION GRAPH_SECTION #define DIA_SECTION GRAPH_SECTION #endif --- NEW FILE: DIA.c --- /* $Id: DIA.c,v 1.1 2009/11/02 17:29:23 mapibid Exp $ */ /******************************************************************************* Copyright (c) 2004, Alexander R. Pruss All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include "resize.h" #include "DIA.h" #ifdef SUPPORT_DIA_HANDERA #include <Vga.h> #include <Silk.h> #endif #ifdef SUPPORT_DIA_SONY #include <SonyCLIE.h> #ifndef vskResizeVertically # define vskResizeVertically 1 #endif #ifndef vskResizeHorizontally # define vskResizeHorizontally 2 #endif #endif #define COORDSYS_STACK_LEN 10 #ifdef SUPPORT_DIA static DIAHardwareType hardware = DIA_HARDWARE_NONE; static UInt32 displayChangeNotification = 0; static Boolean haveNotification; static UInt16 card; static LocalID db; static Boolean palmHiRes; static UInt16 coordSysStack[10]; static UInt16 coordSysStackPtr = 0; #ifdef SUPPORT_DIA_SONY static Boolean sony1AllowResize = false; static UInt16 sonyRefNum; #endif #ifdef SUPPORT_DIA_HANDERA static VgaRotateModeType savedHanderaRotation; static VgaScreenModeType savedHanderaScreenMode; #endif #ifdef SUPPORT_DIA_HANDERA static DIAHardwareType InitializeHandera(void) { UInt32 version; if (_TRGSilkFeaturePresent(&version)) { VgaRotateModeType rotation; VgaScreenModeType screenMode; VgaGetScreenMode(&screenMode, &rotation); savedHanderaScreenMode = screenMode; savedHanderaRotation = rotation; if (screenMode != screenMode1To1) VgaSetScreenMode(screenMode1To1, rotation); return DIA_HARDWARE_HANDERA; } else { return DIA_HARDWARE_NONE; } } #else # define InitializeHandera() DIA_HARDWARE_NONE #endif #ifdef SUPPORT_DIA_SONY static DIAHardwareType InitializeSony(void) { Err err; UInt32 version; err = SysLibFind(sonySysLibNameSilk, &sonyRefNum); if (err == sysErrLibNotFound) { err = SysLibLoad('libr', sonySysFileCSilkLib, &sonyRefNum); } if (err != errNone) return DIA_HARDWARE_NONE; if (errNone == FtrGet(sonySysFtrCreator, sonySysFtrNumVskVersion, &version)) { /* * Version 2 and up */ err = VskOpen(sonyRefNum); if (errNone == err) return DIA_HARDWARE_SONY2; } else { /* * Version 1 and up */ err = SilkLibOpen(sonyRefNum); if (errNone == err) { /* * Make sure we are in a Hi-Res mode */ UInt32 width; UInt32 height; UInt16 sonyHiResRefNum; err = SysLibFind(sonySysLibNameHR, &sonyHiResRefNum); if (err == sysErrLibNotFound) err = SysLibLoad('libr', sonySysFileCHRLib, &sonyHiResRefNum); if (err == errNone) { err = HROpen(sonyHiResRefNum); HRWinScreenMode(sonyHiResRefNum, winScreenModeGet, &width, &height, NULL, NULL); if (width < hrWidth) { width = hrWidth; height = hrHeight; if (errNone != HRWinScreenMode(sonyHiResRefNum, winScreenModeSet, &width, &height, NULL, NULL)) { HRClose(sonyHiResRefNum); return DIA_HARDWARE_NONE; } } HRClose(sonyHiResRefNum); } else return DIA_HARDWARE_NONE; } SilkLibDisableResize(sonyRefNum); sony1AllowResize = false; return DIA_HARDWARE_SONY1; } return DIA_HARDWARE_NONE; } #else # define InitializeSony() DIA_HARDWARE_NONE #endif #ifdef HAVE_PALM_DIA_SDK static DIAHardwareType InitializePalm(void) { UInt32 version; Err err; err = FtrGet(pinCreator, pinFtrAPIVersion, &version); if (err != errNone) return DIA_HARDWARE_NONE; if (pinAPIVersion1_1 <= version) return DIA_HARDWARE_PALM11; else if (pinAPIVersion1_0 <= version) return DIA_HARDWARE_PALM10; else return DIA_HARDWARE_NONE; } #else # define InitializePalm() DIA_HARDWARE_NONE #endif /* Check if this is an unknown device with non-standard screen size so we can make proper use of the screen size. */ static DIAHardwareType InitializeUnknown(void) { Coord extentX; Coord extentY; PushCoordinateSystemToStandard(); WinGetDisplayExtent(&extentX, &extentY); PopCoordinateSystem(); if (extentX != STD_EXTENT_X || extentY != STD_EXTENT_Y) return DIA_HARDWARE_UNKNOWN; else return DIA_HARDWARE_NONE; } static void RegisterNotification(void) { Err err; haveNotification = false; switch (hardware) { #ifdef SUPPORT_DIA_SONY case DIA_HARDWARE_SONY1: case DIA_HARDWARE_SONY2: displayChangeNotification = sysNotifyDisplayChangeEvent; break; #endif #ifdef SUPPORT_DIA_HANDERA case DIA_HARDWARE_HANDERA: displayChangeNotification = trgNotifySilkEvent; break; #endif #ifdef HAVE_PALM_DIA_SDK case DIA_HARDWARE_PALM10: case DIA_HARDWARE_PALM11: displayChangeNotification = sysNotifyDisplayResizedEvent; break; #endif default: return; } err = SysCurAppDatabase(&card, &db); if (err != errNone) return; err = SysNotifyRegister(card, db, displayChangeNotification, NULL, sysNotifyNormalPriority, 0); haveNotification = (err == errNone); } static void UnregisterNotification(void) { if (haveNotification) { SysNotifyUnregister(card, db, displayChangeNotification, sysNotifyNormalPriority); haveNotification = false; } } DIAHardwareType InitializeDIA(void) { Err err; UInt32 version; err = FtrGet(sysFtrCreator, sysFtrNumWinVersion, &version); palmHiRes = (err == errNone && 4 <= version); hardware = InitializeHandera(); if (hardware == DIA_HARDWARE_NONE) hardware = InitializePalm(); if (hardware == DIA_HARDWARE_NONE) hardware = InitializeSony(); if (hardware == DIA_HARDWARE_NONE) hardware = InitializeUnknown(); RegisterNotification(); return hardware; } void TerminateDIA(void) { UnregisterNotification(); if (GetDIAState() == DIA_STATE_NO_STATUS_BAR) SetDIAState(DIA_STATE_MIN); switch (hardware) { #ifdef SUPPORT_DIA_SONY case DIA_HARDWARE_SONY1: SilkLibClose(sonyRefNum); break; case DIA_HARDWARE_SONY2: VskClose(sonyRefNum); break; #endif #ifdef SUPPORT_DIA_HANDERA case DIA_HARDWARE_HANDERA:{ VgaRotateModeType rotation; VgaScreenModeType screenMode; VgaGetScreenMode(&screenMode, &rotation); if (screenMode != savedHanderaScreenMode || savedHanderaRotation != rotation) { VgaSetScreenMode(savedHanderaScreenMode, savedHanderaRotation); } } #endif default: break; } hardware = DIA_HARDWARE_NONE; } void SetDIAState(DIAStateType state) { if (DIA_HARDWARE_HANDERA == hardware && GetDIAState() == state) return; switch (hardware) { #ifdef SUPPORT_DIA_SONY case DIA_HARDWARE_SONY1:{ Boolean oldAllow; oldAllow = sony1AllowResize; if (!oldAllow) SetDIAAllowResize(true); switch (state) { case DIA_STATE_MAX: SilkLibResizeDispWin(sonyRefNum, silkResizeNormal); break; case DIA_STATE_MIN: SilkLibResizeDispWin(sonyRefNum, silkResizeToStatus); break; case DIA_STATE_NO_STATUS_BAR: SilkLibResizeDispWin(sonyRefNum, silkResizeMax); break; default: break; } break; if (!oldAllow) SetDIAAllowResize(false); } case DIA_HARDWARE_SONY2:{ Boolean oldAllow; UInt16 allowState; if (errNone == VskGetState(sonyRefNum, vskStateEnable, &allowState)) oldAllow = (allowState != 0); else oldAllow = false; if (!oldAllow) { SetDIAAllowResize(true); } switch (state) { case DIA_STATE_MAX: VskSetState(sonyRefNum, vskStateResize, vskResizeMax); break; case DIA_STATE_MIN: VskSetState(sonyRefNum, vskStateResize, vskResizeMin); break; case DIA_STATE_NO_STATUS_BAR: VskSetState(sonyRefNum, vskStateResize, vskResizeNone); break; default: break; } break; if (!oldAllow) SetDIAAllowResize(false); } #endif #ifdef SUPPORT_DIA_HANDERA case DIA_HARDWARE_HANDERA: switch (state) { case DIA_STATE_MAX: SilkMaximizeWindow(); break; case DIA_STATE_MIN: case DIA_STATE_NO_STATUS_BAR: SilkMinimizeWindow(); break; default: break; } break; #endif #ifdef HAVE_PALM_DIA_SDK case DIA_HARDWARE_PALM10: case DIA_HARDWARE_PALM11: switch (state) { case DIA_STATE_MAX: StatShow(); PINSetInputAreaState(pinInputAreaOpen); break; case DIA_STATE_MIN: PINSetInputAreaState(pinInputAreaClosed); StatShow(); break; case DIA_STATE_NO_STATUS_BAR: StatHide(); if (PINGetInputAreaState() == pinInputAreaOpen) PINSetInputAreaState(pinInputAreaClosed); /* extra hide for some devices */ if ( GetDIAState() != DIA_STATE_NO_STATUS_BAR ) StatHide(); break; default: break; } break; #endif default: break; } } DIAStateType GetDIAState(void) { switch (hardware) { #ifdef SUPPORT_DIA_SONY case DIA_HARDWARE_SONY1:{ Coord extentY; PushCoordinateSystemToStandard(); WinGetDisplayExtent(NULL, &extentY); PopCoordinateSystem(); if (240 <= extentY) return DIA_STATE_NO_STATUS_BAR; else if (225 <= extentY) return DIA_STATE_MIN; else return DIA_STATE_MAX; break; } case DIA_HARDWARE_SONY2:{ UInt16 state; Err err; err = VskGetState(sonyRefNum, vskStateResize, &state); if (err != errNone) return DIA_STATE_UNDEFINED; switch (state) { case vskResizeMax: return DIA_STATE_MAX; case vskResizeMin: return DIA_STATE_MIN; case vskResizeNone: return DIA_STATE_NO_STATUS_BAR; default: return DIA_STATE_UNDEFINED; } } #endif #ifdef SUPPORT_DIA_HANDERA case DIA_HARDWARE_HANDERA: if (SilkWindowMaximized()) return DIA_STATE_MAX; else return DIA_STATE_MIN; #endif #ifdef HAVE_PALM_DIA_SDK case DIA_HARDWARE_PALM10: case DIA_HARDWARE_PALM11: switch (PINGetInputAreaState()) { case pinInputAreaOpen: return DIA_STATE_MAX; case pinInputAreaClosed: case pinInputAreaNone:{ Err err; UInt32 value; err = StatGetAttribute(statAttrBarVisible, &value); if (err != errNone || value != 0) return DIA_STATE_MIN; else return DIA_STATE_NO_STATUS_BAR; } default: return DIA_STATE_UNDEFINED; } #endif default: return DIA_STATE_MAX; } } void SetDIAAllowResize(Boolean allow) { switch (hardware) { #ifdef SUPPORT_DIA_SONY case DIA_HARDWARE_SONY2: if (allow) { /* * If available, enable horizontal resize */ if (0x03 <= VskGetAPIVersion(sonyRefNum)) VskSetState(sonyRefNum, vskStateEnable, vskResizeHorizontally); /* * Enable vertical resize */ VskSetState(sonyRefNum, vskStateEnable, vskResizeVertically); } else { VskSetState(sonyRefNum, vskStateEnable, 0); } break; case DIA_HARDWARE_SONY1: if (allow) SilkLibEnableResize(sonyRefNum); else SilkLibDisableResize(sonyRefNum); sony1AllowResize = allow; break; #endif #ifdef HAVE_PALM_DIA_SDK case DIA_HARDWARE_PALM11: case DIA_HARDWARE_PALM10: PINSetInputTriggerState(allow ? pinInputTriggerEnabled : pinInputTriggerDisabled); SysSetOrientationTriggerState(allow ? sysOrientationTriggerEnabled : sysOrientationTriggerDisabled); break; #endif /* * Note: On Handera, resizing is always enabled */ default: break; } } static Boolean MatchLastExtents(void) { static Coord lastX; static Coord lastY; Coord extentX; Coord extentY; extentX = lastX; extentY = lastY; PushCoordinateSystemToStandard(); WinGetDisplayExtent(&lastX, &lastY); PopCoordinateSystem(); return extentX == lastX && extentY == lastY; } Boolean HandleResizeNotification(UInt32 notificationType) { switch (notificationType) { #ifdef SUPPORT_DIA_SONY case sysNotifyDisplayChangeEvent: #endif #ifdef HAVE_PALM_DIA_SDK case sysNotifyDisplayResizedEvent: #endif #ifdef SUPPORT_DIA_HANDERA case trgNotifySilkEvent: #endif { EventType e; if (!MatchLastExtents()) { SetHaveWinDisplayChangedEvent(true); if (hardware != DIA_HARDWARE_PALM11) { MemSet(&e, sizeof(EventType), 0); e.eType = winDisplayChangedEvent; EvtAddUniqueEventToQueue(&e, 0, true); } } return true; } default: return false; } } void SetCustomDIAPolicy(UInt16 formID) { #ifdef HAVE_PALM_DIA_SDK if (hardware == DIA_HARDWARE_PALM10 || hardware == DIA_HARDWARE_PALM11) { FormType *formPtr; formPtr = FrmGetFormPtr(formID); if (formPtr != NULL) { FrmSetDIAPolicyAttr(formPtr, frmDIAPolicyCustom); } } #endif } DIAHardwareType GetDIAHardware(void) { return hardware; } void SetDIAConstraints(WinHandle winH, Boolean big, Boolean allowBig) { #ifdef HAVE_PALM_DIA_SDK if (hardware == DIA_HARDWARE_PALM10 || hardware == DIA_HARDWARE_PALM11) { PushCoordinateSystemToStandard(); WinSetConstraintsSize(winH, STD_EXTENT_Y, big ? MAX_EXTENT_Y : STD_EXTENT_Y, allowBig ? MAX_EXTENT_Y : STD_EXTENT_Y, STD_EXTENT_X, big ? MAX_EXTENT_X : STD_EXTENT_X, allowBig ? MAX_EXTENT_X : STD_EXTENT_X); PopCoordinateSystem(); } #endif } /* Check which DIA state covers more screen space */ Int16 CompareDIAState(DIAStateType x, DIAStateType y) { if (y == DIA_STATE_UNDEFINED) y = DIA_STATE_MAX; if (x == DIA_STATE_UNDEFINED) x = DIA_STATE_MAX; if (x == y) return 0; switch (x) { case DIA_STATE_MIN: return y == DIA_STATE_NO_STATUS_BAR ? 1 : -1; case DIA_STATE_NO_STATUS_BAR: return -1; case DIA_STATE_MAX: default: return 1; } } static UInt16 SafeWinSetCoordinateSystem(UInt16 coordSys) { if (!palmHiRes || NULL == WinGetDrawWindow()) return kCoordinatesStandard; else return WinSetCoordinateSystem(coordSys); } void PushCoordinateSystemToStandard(void) { coordSysStack[coordSysStackPtr++] = SafeWinSetCoordinateSystem(kCoordinatesStandard); } void PopCoordinateSystem(void) { SafeWinSetCoordinateSystem(coordSysStack[--coordSysStackPtr]); } void GetHiddenStatusBarArea(RectangleType * area) { MemSet(area, sizeof(RectangleType), 0); if (DIA_STATE_NO_STATUS_BAR != GetDIAState()) { return; } switch (hardware) { case DIA_HARDWARE_SONY2: case DIA_HARDWARE_SONY1: case DIA_HARDWARE_PALM11: case DIA_HARDWARE_PALM10:{ Coord extentX; Coord extentY; WinGetDisplayExtent(&extentX, &extentY); switch (extentX) { case 160: /* 160 x 240 */ area->topLeft.x = 0; area->topLeft.y = 225; area->extent.x = 160; area->extent.y = 240 - 225; break; case 240: /* 240 x 160 */ area->topLeft.x = 225; area->topLeft.y = 0; area->extent.x = 240 - 225; area->extent.y = 160; break; case 320: /* 320 x 480 */ area->topLeft.x = 0; area->topLeft.y = 450; area->extent.x = 320; area->extent.y = 480 - 450; break; case 480: /* 480 x 320 */ area->topLeft.x = 450; area->topLeft.y = 0; area->extent.x = 480 - 450; area->extent.y = 320; break; default: break; } break; } default: break; } } FontID HanderaAdjustFont(FontID font) { #ifdef SUPPORT_DIA_HANDERA if (hardware == DIA_HARDWARE_HANDERA && 0 == (font & fntAppFontCustomBase)) return VgaBaseToVgaFont(font); else #endif return font; } Coord HanderaCoord(Coord x) { #ifdef SUPPORT_DIA_HANDERA return hardware == DIA_HARDWARE_HANDERA ? x * 3 / 2 : x; #else return x; #endif } #endif --- NEW FILE: util_dia.h --- /* File name: util_dia.h Copyright 2006 Ton van Overbeek This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. * * Summary * Utility definitions for PalmResize DIA support. * */ #ifndef _UTIL_DIA_H_ #define _UTIL_DIA_H_ #define SafeMemPtrNew MemPtrNew #define SafeMemPtrFree(p) if ((p) != NULL) MemPtrFree((p)) #endif --- NEW FILE: resize.h --- /* $Id: resize.h,v 1.1 2009/11/02 17:29:23 mapibid Exp $ */ /******************************************************************************* Copyright (c) 2004, Alexander R. Pruss All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #ifndef PLUCKER_RESIZE_H #define PLUCKER_RESIZE_H //#include "viewer.h" #include <PalmOS.h> //#include "PalmBible.h" #include "config.h" #include "sects.h" #if ! defined( SUPPORT_DIA ) && defined( HAVE_SILKSCREEN ) # define SUPPORT_DIA #endif /* */ #if ! defined( SUPPORT_DIA_SONY ) && defined( HAVE_SONY_SDK ) # define SUPPORT_DIA_SONY #endif /* */ #if ! defined( SUPPORT_DIA_HANDERA ) && defined( HAVE_HANDERA_SDK ) # define SUPPORT_DIA_HANDERA #endif /* */ #ifndef winDisplayChangedEvent # define winDisplayChangedEvent 0x4101 #else /* */ # define HAVE_PALM_DIA_SDK #endif /* */ #include "resizeconsts.h" #define WORD_LIST_TYPE 'wrdl' typedef struct { UInt16 objectID; UInt16 flags; UInt16 reserved; } DIAConfigEntryType; typedef UInt8 DIAStateType; typedef struct { UInt16 sizeInWords; UInt16 flags; UInt16 bin; UInt16 preferredState; DIAConfigEntryType objectList[0]; } DIAConfigType; typedef struct { UInt16 from; UInt16 to; } DIAIndexEntryType; typedef struct { UInt16 count; DIAIndexEntryType mapList[0]; } DIAIndexType; typedef struct { UInt16 formID; UInt16 numObjects; Boolean open; MemHandle configHandle; Coord lastExtentX; Coord lastExtentY; RectangleType lastBounds; Boolean forceRedraw; DIAConfigType * config; RectangleType * originalBounds; } DIAFormEntryType; #ifdef SUPPORT_DIA extern void InitializeResizeSupport(UInt16 formMapId) RESIZE_SECTION; extern void TerminateResizeSupport(void) RESIZE_SECTION; extern void SetResizePolicy(UInt16 formID) RESIZE_SECTION; extern Boolean ResizeHandleFrmOpenEvent(void) RESIZE_SECTION; extern Boolean ResizeHandleFrmCloseEvent(void) RESIZE_SECTION; extern Boolean ResizeHandleWinDisplayChangedEvent(void) RESIZE_SECTION; extern Boolean ResizeHandleWinExitEvent(void) RESIZE_SECTION; extern Boolean ResizeHandleWinEnterEvent(void) RESIZE_SECTION; extern Boolean ResizeHandleFrmRedrawUpdateCode(void) RESIZE_SECTION; extern void LoadResizePrefs(UInt32 appID, UInt16 prefID) RESIZE_SECTION; extern void SaveResizePrefs(UInt32 appID, UInt16 prefID, Int16 version) RESIZE_SECTION; extern void ResizeRefreshCurrentForm(void) RESIZE_SECTION; extern void SetHaveWinDisplayChangedEvent(Boolean value) RESIZE_SECTION; extern Boolean ResizeForm(UInt16 formID) RESIZE_SECTION; extern Boolean ResizeHandleEvent(EventType * event) RESIZE_SECTION; #else /* */ #define InitializeResizeSupport( x ) #define TerminateResizeSupport() #define SetResizePolicy( x ) #define ResizeHandleFrmOpenEvent() true #define ResizeHandleFrmCloseEvent() true #define ResizeHandleWinDisplayChangedEvent() true #define ResizeHandleWinExitEvent() true #define ResizeHandleWinEnterEvent() true #define LoadResizePrefs( a, b ) #define SaveResizePrefs( a, b, c ) #define ResizeRefreshCurrentForm() #define SetHaveWinDisplayChangedEvent( x ) #define ResizeHandleFrmRedrawUpdateCode() true #define ResizeForm( a ) false #define ResizeHandleEvent( e ) false #endif /* */ #endif /* _ARP_RESIZE_H */ --- NEW FILE: resize.c --- /* $Id: resize.c,v 1.1 2009/11/02 17:29:23 mapibid Exp $ */ /******************************************************************************* Copyright (c) 2004, Alexander R. Pruss All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <PalmOS.h> #include <LstGlue.h> #include "util_dia.h" #include "DIA.h" #ifdef SUPPORT_DIA_HANDERA #include <Vga.h> #endif #ifdef SUPPORT_DIA #define DebugInfo(s) /* { char _tempstring[500];StrPrintF(_tempstring,"%s(%d) ",s,active.formID);\ ClipboardAppendItem(clipboardText,_tempstring,StrLen(_tempstring)); } */ typedef struct { UInt16 formID; FormType *formPtr; UInt16 index; UInt16 flags; DIAFormEntryType *entry; } ResizeTemporaryData; static void UniqueUpdateForm( UInt16 formID, UInt16 code ); static DIAFormEntryType *formList = NULL; static DIAStateType *bins; static UInt16 numBins; static UInt16 formCount = 0; static ResizeTemporaryData active; static Boolean haveWinDisplayChangedEvent = false; RESIZE_SECTION static UInt16 StandardExtent(void) { #ifdef SUPPORT_DIA_HANDERA if (GetDIAHardware() == DIA_HARDWARE_HANDERA) return 240; else #endif return 160; } /* Update form, but only once */ void UniqueUpdateForm(UInt16 formID, UInt16 code) { EventType e; MemSet(&e, sizeof(EventType), 0); e.eType = frmUpdateEvent; e.data.frmUpdate.formID = formID; e.data.frmUpdate.updateCode = code; EvtAddUniqueEventToQueue(&e, 0, true); DebugInfo("Queuing frmUpdateForm"); } /* Same as FrmGetObjectIndex() but works with GSI_OBJECT_ID, too */ RESIZE_SECTION static UInt16 MyFrmGetObjectIndex(FormPtr formPtr, UInt16 id) { UInt16 i; if (id != GSI_OBJECT_ID) return FrmGetObjectIndex(formPtr, id); for (i = FrmGetNumberOfObjects(formPtr) - 1; 0 < i; i--) { if (FrmGetObjectType(formPtr, i) == frmGraffitiStateObj) { return i; } } return 0; } RESIZE_SECTION static void WinGlueGetBounds(WinHandle winH, RectangleType * rect) { Err err; UInt32 version; err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &version); if (err == errNone && 0x04003000 <= version) { WinGetBounds(winH, rect); } else { WinHandle oldH; oldH = WinSetDrawWindow(winH); WinGetDrawWindowBounds(rect); WinSetDrawWindow(oldH); } } RESIZE_SECTION static void SafeFrmGetObjectBounds(const FormType* formPtr, UInt16 objectIndex, RectangleType* rect) { WinHandle oldWin; oldWin = WinSetDrawWindow(FrmGetWindowHandle(formPtr)); FrmGetObjectBounds(formPtr, objectIndex, rect); if (oldWin != NULL) WinSetDrawWindow(oldWin); } RESIZE_SECTION static void SafeFrmSetObjectBounds(FormType* formPtr, UInt16 objectIndex, RectangleType* rect) { WinHandle oldWin; oldWin = WinSetDrawWindow(FrmGetWindowHandle(formPtr)); FrmSetObjectBounds(formPtr, objectIndex, rect); if (oldWin != NULL) WinSetDrawWindow(oldWin); } RESIZE_SECTION static void AddForm(UInt16 indexInList, MemHandle handle, UInt16 formID) { UInt16 numObjects; DIAConfigType *config; formList[indexInList].configHandle = handle; if (handle == NULL) { return; } config = (DIAConfigType *) MemHandleLock(handle); numObjects = ((config->sizeInWords + 1) * sizeof(UInt16) - sizeof(DIAConfigType)) / sizeof(DIAConfigEntryType); formList[indexInList].formID = formID; formList[indexInList].config = config; formList[indexInList].numObjects = numObjects; formList[indexInList].open = false; if (config->flags & DIA_FORM_USE_BIN && numBins < 1 + config->bin) numBins = 1 + config->bin; } /* This sets up the original bounds array as needed */ RESIZE_SECTION static void InitialSetupForm(UInt16 indexInList) { RectangleType *originalBounds; FormType *formPtr; UInt16 numObjects; UInt16 i; numObjects = formList[indexInList].numObjects; if (numObjects == 0) return; if (formList[indexInList].originalBounds != NULL) return; formPtr = FrmGetFormPtr(formList[indexInList].formID); if (formPtr == NULL) return; originalBounds = (RectangleType *) SafeMemPtrNew(numObjects * sizeof(RectangleType)); formList[indexInList].originalBounds = originalBounds; /* * First object is the form itself */ WinGlueGetBounds(FrmGetWindowHandle(formPtr), &(originalBounds[0])); /* * Now on to the other objects */ for (i = 1; i < numObjects; i++) { UInt16 objectIndex; objectIndex = MyFrmGetObjectIndex(formPtr, formList[indexInList].config->objectList[i].objectID); SafeFrmGetObjectBounds(formPtr, objectIndex, &(originalBounds[i])); } } /* Adjust one coordinate */ RESIZE_SECTIO... [truncated message content] |