![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Thanks Rick, this is very useful.
Others, please note that this tool works with non-SWOOP (traditional)
dialogs just as well.
I extended the dialog compiler to automatically initialize and cleanup
the new id tool. I added the following just after the ID: definition:
----------------------------------------
PACKAGE DLGCOMP ( Extend Dialog package )
PRIVATE
-?
: END-DIALOG ( -- )
END-DIALOG
CREATE-IDS
IDSTRINGS/ ( cleanup ) ;
PUBLIC
-?
: DIALOG ( style -- )
USE-IDSTRINGS DIALOG ;
END-PACKAGE
----------------------------------------
Note that CREATE-IDS should not be used after END-DIALOG - it will
abort.
I added to above change to Rick's code below.
Mike
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com] On Behalf
Of Rick VanNorman
Sent: Monday, April 04, 2005 4:42 PM
To: sftalk_at_forth.com
Subject: [sftalk] Automatic resource id creation
I've been building dialog boxes lately with a tremendous number of
controls. I got very tired of having to manage a list of numbered
identifiers, and frustrated with having to deal with keeping too many
little bits in sync with each other.
So, I wrote a tool to let me automagically create control identifier
constants in the dialog box where they are used. Source code follows.
I hope this can be useful.
Rick
\ ----------------------------------------------------------------------
\ Automagic dialog control identifier creation=20
\ Copyright (c) 2005 Rick VanNorman "rick <at> neverslow <dot> com"
\ Free to use, modify, extend, or enjoy for any use whatsoever.
\ Please give credit, please give back any updates or fixes.
\ ----------------------------------------------------------------------
\ Automagically create resource identifier strings for dialogs.
\
\ The following package allows the programmer to automagically=20
\ create the constant identifiers for dialog box controls. With=20
\ it, there is no longer a need to manage a large set of resource=20
\ identifier constants apart from the dialog definition, nor=20
\ to program dialog boxes without named identifiers, relying=20
\ on your wits to keep track of the integer values for each=20
\ control.
\
\ The identifiers are created starting at an arbitrary value (I=20
\ chose 1000) and incrementing from there. The named identifiers=20
\ are defined as constants; the string "ID_" is prepended to=20
\ each name. Thus, using "ID: RUN" produces a constant whose name=20
\ is "ID_RUN". The constants cannot be generated during the=20
\ dialog definition because that would interfere with the dialog=20
\ template creation. The constants are created after the dialog=20
\ is defined by simply executing the word "CREATE-IDS". Then,=20
\ each identifier will be available as a named entity.
0 VALUE IDSTRINGS
0 VALUE IDN
: USE-IDSTRINGS ( -- )
IDSTRINGS 0=3D IF
65536 ALLOCATE THROW TO IDSTRINGS
THEN 0 IDSTRINGS ! 1000 TO IDN ;
: IDSTRINGS/ ( -- )
IDSTRINGS IF IDSTRINGS FREE THROW 0 TO IDSTRINGS THEN ;
: CREATE-IDS ( -- )
IDSTRINGS 0=3D THROW IDSTRINGS @+ EVALUATE
IDSTRINGS FREE THROW 0 TO IDSTRINGS ;
: >IDSTRINGS ( addr len -- ) IDSTRINGS XAPPEND ;
: ID: ( -- )
IDSTRINGS 0=3D IF USE-IDSTRINGS THEN
IDSTRINGS @ 65000 > THROW
IDN (.) >IDSTRINGS S" CONSTANT ID_" >IDSTRINGS
BL WORD COUNT >IDSTRINGS S" " >IDSTRINGS
IDN 1 +TO IDN ;
PACKAGE DLGCOMP ( Extend Dialog package )
PRIVATE
-?
: END-DIALOG ( -- )
END-DIALOG
CREATE-IDS
IDSTRINGS/ ( cleanup ) ;
PUBLIC
-?
: DIALOG ( style -- )
USE-IDSTRINGS DIALOG ;
END-PACKAGE
\ ----------------------------------------------------------------------
\ Simple dialog to illustrate the use of IDSTRINGS
DIALOG (SIMPLE)
[MODAL " Simple Example" 10 10 50 83 (CLASS SFDLG) ]
[PUSHBUTTON " &Run" ID: RUN 5 5 40 12 ]
[PUSHBUTTON " &Start" ID: START 5 20 40 12 ]
[PUSHBUTTON " &Test" ID: TEST 5 35 40 12 ]
[CTEXT " " ID: STAT 5 50 40 12 ]
[DEFPUSHBUTTON " E&xit" IDOK 5 65 40 12 ]
END-DIALOG
GENERICDIALOG SUBCLASS SIMPLE-DIALOG
: TEMPLATE ( -- a ) (SIMPLE) ;
IDOK COMMAND: ( -- ) 0 CLOSE-DIALOG ;
IDCANCEL COMMAND: ( -- ) 0 CLOSE-DIALOG ;
: SAY ( z -- )
mHWND ID_STAT ROT :: SetDlgItemText DROP ;
ID_RUN COMMAND: ( -- ) Z" Run" SAY ;
ID_START COMMAND: ( -- ) Z" Start" SAY ;
ID_TEST COMMAND: ( -- ) Z" Test" SAY ;
WM_INITDIALOG MESSAGE: ( -- ) Z" Status" SAY 0 ;
END-CLASS
: GO ( -- )
[OBJECTS SIMPLE-DIALOG MAKES SD OBJECTS]
0 SD MODAL DROP ;
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Tue Apr 05 2005 - 11:08:34 PDT
This archive was generated by hypermail 2.2.0 : Thu Dec 04 2008 - 03:04:19 PST