Skip to content

Commit

Permalink
add enumeration for window identifiers to C and E code
Browse files Browse the repository at this point in the history
add check for duplicate window identifiers when generating code
change "window name" to "window identifier"
add window indentifier validation
update version to 0.10.0-beta
add example E source to the manual
  • Loading branch information
dmcoles committed Jan 16, 2024
1 parent e17d2b9 commit 12782d7
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 52 deletions.
199 changes: 196 additions & 3 deletions Rebuild_manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,12 @@ struct Library *WindowBase = NULL,
*IconBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;

//Window_3
//window ids
//this enumeration will contain all of the window ids contained in the
//rebuild project.
enum win { window_3_id = 3 };

//Window_3 gadgets
//this enumeration should be used to access the main_gadgets array. the names
//of the enumerations have the reaction gadget id's on the end so these names
//will never change even if the design is update (eg another gadget added).
Expand Down Expand Up @@ -487,8 +492,9 @@ void window_3( void )
main_gadgets[6] = 0;

//call the code to display the window
//the window id is 3 and it has no menu structure.
runWindow( window_object, 3, 0, main_gadgets );
//the window id is window_3_id from the window ids enumeration and
//it has no menu structure.
runWindow( window_object, window_3_id, 0, main_gadgets );

if ( window_object ) DisposeObject( window_object );
}
Expand All @@ -502,6 +508,193 @@ int main( int argc, char **argv )
cleanup();
}

Here is the same example GUI design in E

OPT OSVERSION=37

MODULE 'reaction/reaction_macros',
'reaction/reaction_lib',
'window','classes/window',
'gadgets/layout','layout',
'libraries/gadtools','gadtools',
'icon',
'button','gadgets/button',
'string','gadgets/string',
'label','images/label',
'images/bevel',
'amigalib/boopsi',
'exec',
'intuition/intuition',
'intuition/imageclass',
'intuition/screens',
'intuition/gadgetclass'


->window ids
ENUM WINLOGON_ID = 3

->winLogon gadgets
ENUM LAYOUT_5, STRING_6, STRING_7, LAYOUT_8, BUTTON_9, BUTTON_10
ENUM LAYOUT_5_ID = 5, STRING_6_ID = 6, STRING_7_ID = 7, LAYOUT_8_ID = 8,
BUTTON_9_ID = 9, BUTTON_10_ID = 10

DEF gScreen=0,gVisInfo=0,gDrawInfo=0,gAppPort=0

PROC setup()
IF (windowbase:=OpenLibrary('window.class',0))=NIL THEN Throw("LIB","win")
IF (layoutbase:=OpenLibrary('gadgets/layout.gadget',0))=NIL THEN Throw("LIB","layo")
IF (gadtoolsbase:=OpenLibrary('gadtools.library',0))=NIL THEN Throw("LIB","gadt")
IF (iconbase:=OpenLibrary('icon.library',0))=NIL THEN Throw("LIB","icon")
IF (buttonbase:=OpenLibrary('gadgets/button.gadget',0))=NIL THEN Throw("LIB","btn")
IF (stringbase:=OpenLibrary('gadgets/string.gadget',0))=NIL THEN Throw("LIB","strn")
IF (labelbase:=OpenLibrary('images/label.image',0))=NIL THEN Throw("LIB","labl")
IF (gScreen:=LockPubScreen(NIL))=NIL THEN Raise("pub")
IF (gVisInfo:=GetVisualInfoA(gScreen, [TAG_END]))=NIL THEN Raise("visi")
IF (gDrawInfo:=GetScreenDrawInfo(gScreen))=NIL THEN Raise("dinf")
IF (gAppPort:=CreateMsgPort())=NIL THEN Raise("port")
ENDPROC

PROC cleanup()
IF gVisInfo THEN FreeVisualInfo(gVisInfo)
IF gDrawInfo THEN FreeScreenDrawInfo(gScreen,gDrawInfo)
IF gAppPort THEN DeleteMsgPort(gAppPort)
IF gScreen THEN UnlockPubScreen(NIL,gScreen)

IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
IF iconbase THEN CloseLibrary(iconbase)
IF windowbase THEN CloseLibrary(windowbase)
IF layoutbase THEN CloseLibrary(layoutbase)
IF buttonbase THEN CloseLibrary(buttonbase)
IF stringbase THEN CloseLibrary(stringbase)
IF labelbase THEN CloseLibrary(labelbase)
ENDPROC

PROC runWindow(windowObject,windowId, menuStrip, winGadgets:PTR TO LONG) HANDLE
DEF running=TRUE
DEF win:PTR TO window,wsig,code,msg,sig,result

IF (win:=RA_OpenWindow(windowObject))
GetAttr( WINDOW_SIGMASK, windowObject, {wsig} )
IF menuStrip THEN SetMenuStrip( win, menuStrip )

WHILE running
sig:=Wait(wsig)
IF (sig AND (wsig))
WHILE ((result:=RA_HandleInput(windowObject,{code}+2)) <> WMHI_LASTMSG)
msg:=(result AND WMHI_CLASSMASK)
SELECT msg
CASE WMHI_CLOSEWINDOW
running:=FALSE
CASE WMHI_GADGETUP
WriteF('gadget press\n')
CASE WMHI_MENUPICK
WriteF('menu pick\n')
CASE WMHI_ICONIFY
RA_Iconify(windowObject)
CASE WMHI_UNICONIFY
win:=RA_OpenWindow(windowObject)
IF menuStrip THEN SetMenuStrip( win, menuStrip )
ENDSELECT
ENDWHILE
ENDIF
ENDWHILE
ENDIF
EXCEPT DO
RA_CloseWindow(windowObject)
ENDPROC

PROC winlogon() HANDLE
DEF windowObject
DEF mainGadgets[7]:ARRAY OF LONG


windowObject:=WindowObject,
WA_TITLE, 'Please log in...',
WA_LEFT, 5,
WA_TOP, 20,
WA_WIDTH, 250,
WA_HEIGHT, 80,
WA_MINWIDTH, 150,
WA_MINHEIGHT, 80,
WA_MAXWIDTH, 8192,
WA_MAXHEIGHT, 8192,
WINDOW_APPPORT, gAppPort,
WA_CLOSEGADGET, TRUE,
WA_DEPTHGADGET, TRUE,
WA_SIZEGADGET, TRUE,
WA_DRAGBAR, TRUE,
WINDOW_POSITION, WPOS_CENTERSCREEN,
WINDOW_ICONTITLE, 'MyApp',
WA_NOCAREREFRESH, TRUE,
WA_IDCMP, IDCMP_GADGETDOWN OR IDCMP_GADGETUP OR IDCMP_CLOSEWINDOW,
WINDOW_PARENTGROUP, VLayoutObject,
LAYOUT_SPACEOUTER, TRUE,
LAYOUT_DEFERLAYOUT, TRUE,
LAYOUT_ADDCHILD, mainGadgets[LAYOUT_5]:=LayoutObject,
GA_ID, LAYOUT_5_ID,
LAYOUT_ORIENTATION, LAYOUT_ORIENT_VERT,
LAYOUT_ADDCHILD, mainGadgets[STRING_6]:=StringObject,
GA_ID, STRING_6_ID,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
STRINGA_MAXCHARS, 80,
StringEnd,
CHILD_LABEL, LabelObject,
LABEL_TEXT, 'User name',
LabelEnd,
LAYOUT_ADDCHILD, mainGadgets[STRING_7]:=StringObject,
GA_ID, STRING_7_ID,
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
STRINGA_MAXCHARS, 80,
StringEnd,
CHILD_LABEL, LabelObject,
LABEL_TEXT, 'Password',
LabelEnd,
LAYOUT_ADDCHILD, mainGadgets[LAYOUT_8]:=LayoutObject,
GA_ID, LAYOUT_8_ID,
LAYOUT_ORIENTATION, LAYOUT_ORIENT_HORIZ,
LAYOUT_ADDCHILD, mainGadgets[BUTTON_9]:=ButtonObject,
GA_ID, BUTTON_9_ID,
GA_TEXT, 'OK',
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
BUTTON_TEXTPEN, 1,
BUTTON_BACKGROUNDPEN, 0,
BUTTON_FILLTEXTPEN, 1,
BUTTON_FILLPEN, 3,
ButtonEnd,
LAYOUT_ADDCHILD, mainGadgets[BUTTON_10]:=ButtonObject,
GA_ID, BUTTON_10_ID,
GA_TEXT, 'Cancel',
GA_RELVERIFY, TRUE,
GA_TABCYCLE, TRUE,
BUTTON_TEXTPEN, 1,
BUTTON_BACKGROUNDPEN, 0,
BUTTON_FILLTEXTPEN, 1,
BUTTON_FILLPEN, 3,
ButtonEnd,
LayoutEnd,
LayoutEnd,
LayoutEnd,
WindowEnd
mainGadgets[6]:=0

runWindow(windowObject,WINLOGON_ID,NIL,mainGadgets)

EXCEPT DO
IF windowObject THEN DisposeObject(windowObject);
ENDPROC

PROC main() HANDLE
setup()

winlogon()

EXCEPT DO
cleanup()
ENDPROC


8. Tooltype settings

Expand Down
59 changes: 41 additions & 18 deletions cSourceGen.e
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ OPT MODULE,LARGE
EXPORT OBJECT cSrcGen OF srcGen
ENDOBJECT

ENUM ENUM_IDS, ENUM_IDENTS, ENUM_IDXS

PROC create(fser:PTR TO fileStreamer, libsused:PTR TO CHAR,definitionOnly,useIds) OF cSrcGen
SUPER self.create(fser,libsused,definitionOnly,useIds)
self.type:=CSOURCE_GEN
Expand All @@ -20,17 +22,21 @@ PROC create(fser:PTR TO fileStreamer, libsused:PTR TO CHAR,definitionOnly,useIds
self.indent:=0
ENDPROC

PROC createEnum(windowName:PTR TO CHAR, listObjects:PTR TO stdlist, ids) OF cSrcGen
PROC createEnum(enumName:PTR TO CHAR, listObjects:PTR TO stdlist, enumType) OF cSrcGen
DEF n=0, j
DEF listObject:PTR TO reactionObject
DEF tempStr[255]:STRING

self.write('enum ')
IF ids
StringF(tempStr,'\s_id { ',windowName)
ELSE
StringF(tempStr,'\s_idx { ',windowName)
ENDIF
SELECT enumType
CASE ENUM_IDS
StringF(tempStr,'\s_id { ',enumName)
CASE ENUM_IDXS
StringF(tempStr,'\s_idx { ',enumName)
CASE ENUM_IDENTS
StringF(tempStr,'\s { ',enumName)
ENDSELECT

LowerStr(tempStr)
self.write(tempStr)
n:=0
Expand All @@ -47,12 +53,13 @@ PROC createEnum(windowName:PTR TO CHAR, listObjects:PTR TO stdlist, ids) OF cSrc
ENDIF
listObject:=listObjects.item(j)
listObject.gadindex:=j

StrCopy(tempStr,listObject.ident)
LowerStr(tempStr)
self.write(tempStr)
n:=n+StrLen(tempStr)

IF ids
IF (enumType=ENUM_IDS) OR (enumType=ENUM_IDENTS)
StringF(tempStr,'_id = \d',listObject.id)
self.write(tempStr)
n:=n+StrLen(tempStr)
Expand All @@ -62,13 +69,14 @@ PROC createEnum(windowName:PTR TO CHAR, listObjects:PTR TO stdlist, ids) OF cSrc
self.writeLine(' };')
ENDPROC

PROC genHeader(screenObject:PTR TO screenObject,rexxObject:PTR TO rexxObject, windowNames:PTR TO stringlist, windowLayouts:PTR TO stdlist, sharedPort) OF cSrcGen
PROC genHeader(screenObject:PTR TO screenObject,rexxObject:PTR TO rexxObject, windowItems:PTR TO stdlist, windowLayouts:PTR TO stdlist, sharedPort) OF cSrcGen
DEF tempStr[200]:STRING
DEF menuItem:PTR TO menuItem
DEF itemName[200]:STRING
DEF commKey[10]:STRING
DEF itemType
DEF hasarexx,i,j,n
DEF windowObject:PTR TO reactionObject
DEF layoutObject:PTR TO reactionObject
DEF listObjects:PTR TO stdlist
DEF listObject:PTR TO reactionObject
Expand Down Expand Up @@ -181,8 +189,9 @@ PROC genHeader(screenObject:PTR TO screenObject,rexxObject:PTR TO rexxObject, wi
self.writeLine('')
ENDIF

FOR i:=0 TO windowNames.count()-1
StrCopy(tempStr,windowNames.item(i))
FOR i:=0 TO windowItems.count()-1
windowObject:=windowItems.item(i)
StrCopy(tempStr,windowObject.ident)
LowerStr(tempStr)
self.write('void ')
self.write(tempStr)
Expand Down Expand Up @@ -533,14 +542,24 @@ PROC genHeader(screenObject:PTR TO screenObject,rexxObject:PTR TO rexxObject, wi

NEW listObjects.stdlist(20)
self.writeLine('')
FOR i:=0 TO windowNames.count()-1
FOR i:=0 TO windowItems.count()-1
windowObject:=windowItems.item(i)
listObjects.add(windowObject)
ENDFOR
self.writeLine('//window ids')
self.createEnum('win',listObjects,ENUM_IDENTS)
self.writeLine('')

listObjects.clear()
FOR i:=0 TO windowItems.count()-1
layoutObject:=windowLayouts.item(i)
windowObject:=windowItems.item(i)
listObjects.clear()
layoutObject.findObjectsByType(listObjects,-1)
StringF(tempStr,'//\s',windowNames.item(i))
StringF(tempStr,'//\s gadgets',windowObject.ident)
self.writeLine(tempStr)
self.createEnum(windowNames.item(i),listObjects,FALSE)
IF self.useIds THEN self.createEnum(windowNames.item(i),listObjects,TRUE)
self.createEnum(windowObject.ident,listObjects,ENUM_IDXS)
IF self.useIds THEN self.createEnum(windowObject.ident,listObjects,ENUM_IDS)
ENDFOR
END listObjects
self.writeLine('')
Expand Down Expand Up @@ -877,7 +896,7 @@ PROC genWindowHeader(count, windowObject:PTR TO windowObject, menuObject:PTR TO
DEF listStr
DEF drawlist:PTR TO drawlist

StrCopy(tempStr,windowObject.name)
StrCopy(tempStr,windowObject.ident)
LowerStr(tempStr)
self.write('void ')
self.write(tempStr)
Expand Down Expand Up @@ -1075,10 +1094,14 @@ PROC genWindowFooter(count, windowObject:PTR TO windowObject, menuObject:PTR TO
DEF reactionObject:PTR TO reactionObject
DEF listStr
DEF tempStr[200]:STRING
DEF windowName[200]:STRING
DEF i

StringF(tempStr,' main_gadgets[\d] = 0;',count)
self.writeLine(tempStr)

StrCopy(windowName,windowObject.ident)
LowerStr(windowName)

IF self.definitionOnly
self.writeLine('}')
Expand All @@ -1088,10 +1111,10 @@ PROC genWindowFooter(count, windowObject:PTR TO windowObject, menuObject:PTR TO

self.writeLine('')
IF menuObject.menuItems.count()>0
StringF(tempStr,' runWindow( window_object, \d, menu_strip, main_gadgets );',windowObject.id)
StringF(tempStr,' runWindow( window_object, \s_id, menu_strip, main_gadgets );',windowName)
self.writeLine(tempStr)
ELSE
StringF(tempStr,' runWindow( window_object, \d, 0, main_gadgets );',windowObject.id)
StringF(tempStr,' runWindow( window_object, \s_id, 0, main_gadgets );',windowName)
self.writeLine(tempStr)
ENDIF
self.writeLine('')
Expand Down Expand Up @@ -1192,7 +1215,7 @@ PROC genFooter(windowObject:PTR TO windowObject, rexxObject:PTR TO rexxObject) O
ENDIF


StringF(tempStr,' \s',windowObject.name)
StringF(tempStr,' \s',windowObject.ident)
LowerStr(tempStr)
StrAdd(tempStr,'();')
self.writeLine(tempStr)
Expand Down
Loading

0 comments on commit 12782d7

Please sign in to comment.