home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
coders
/
jËzyki_programowania
/
amigae
/
e_v3.2a
/
pdsrc
/
gtlv.e
< prev
next >
Wrap
Text File
|
1995-05-29
|
8KB
|
234 lines
/*--------------------------------------------------------------------*
E Source generated by SRCGEN v0.1
Demo showing how to create, manage, and cleanup a gadtools listview.
Includes button gadgets and a string gadget for functionality.
AUTHOR: B. Wills + SRCGEN :-)
*--------------------------------------------------------------------*/
OPT OSVERSION=37
MODULE 'gadtools', 'libraries/gadtools', 'intuition/intuition',
'intuition/screens', 'graphics/text',
'exec/lists', 'exec/nodes', 'utility/tagitem'
/*-- Function return values. --*/
ENUM NONE, NOCONTEXT, NOGADGET, NOWB, NOVISUAL, OPENGT, NOWINDOW, NOMENUS, MEM
/*-- Gadget IDs. --*/
ENUM ADDBUTTON_ID, DELETEBUTTON_ID, STRING_ID, LISTVIEW_ID
RAISE "MEM" IF New()=NIL,
"MEM" IF String()=NIL
/*-- Standard SrcGen stuff. --*/
DEF win=NIL:PTR TO window,
scr=NIL:PTR TO screen,
glist=NIL,
visual=NIL,
infos:PTR TO gadget,
messageClass,
offx, offy, tattr
/*-- Listview and supporting gadgets. --*/
DEF list=NIL:PTR TO mlh, /* Exec list holds listview items */
listView=NIL:PTR TO gadget, /* Listview gadget */
addButton=NIL:PTR TO gadget, /* Button gadget to add an item */
deleteButton=NIL:PTR TO gadget, /* Button gadget to delete an item */
stringGadget=NIL:PTR TO gadget, /* String gadget, value added to listview */
stringGadgetValue:PTR TO CHAR /* Pointer to string gadget buffer */
PROC initList(l:PTR TO mlh)
/*-- Initialize an exec list. --*/
l.head:=l+4
l.tail:=NIL
l.tailpred:=l
ENDPROC
PROC setupScreen()
/*-- Open libraries and get screen info. --*/
IF (gadtoolsbase:=OpenLibrary('gadtools.library',37))=NIL THEN RETURN OPENGT
IF (scr:=LockPubScreen('Workbench'))=NIL THEN RETURN NOWB
IF (visual:=GetVisualInfoA(scr,NIL))=NIL THEN RETURN NOVISUAL
offy:=scr.wbortop+Int(scr.rastport+58)-10
tattr:=['topaz.font',8,0,0]:textattr
ENDPROC NONE
PROC closeScreen()
/*-- Free resources, close screen and libraries. --*/
IF glist THEN FreeGadgets(glist)
IF visual THEN FreeVisualInfo(visual)
IF scr THEN UnlockPubScreen(NIL,scr)
IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
ENDPROC
PROC createGadgets()
/*-- Initialize gadget structures and create 'em. --*/
DEF g, stringInfo:PTR TO stringinfo
/*-- Init exec list to hold listview items. Starts out empty. --*/
list:=New(SIZEOF mlh)
initList(list)
IF (g:=CreateContext({glist}))=NIL THEN RETURN NOCONTEXT
IF (g:=listView:=CreateGadgetA(LISTVIEW_KIND, g,
[offx+7, offy+13, 243, 100,
'My Mondo List', tattr, LISTVIEW_ID, 0, visual, 0]:newgadget,
[GTLV_LABELS, list,
GTLV_SHOWSELECTED, NIL, TAG_DONE]))=NIL THEN RETURN NOGADGET
IF (g:=stringGadget:=CreateGadgetA(STRING_KIND,g,
[offx+7, offy+111, 243, 12,
'', tattr, STRING_ID, 0, visual, 0]:newgadget,
[GTST_MAXCHARS,25, TAG_DONE]))=NIL THEN RETURN NOGADGET
/*-- This is where the string gadget buffer is hidden. --*/
stringInfo:=stringGadget.specialinfo
stringGadgetValue:=stringInfo.buffer
/*-------------------------------------------------------*/
IF (g:=addButton:=CreateGadgetA(BUTTON_KIND, g,
[offx+58, offy+111+15, 65, 17,
'Add', tattr, ADDBUTTON_ID, 16, visual, 0]:newgadget,
[TAG_DONE]))=NIL THEN RETURN NOGADGET
IF (g:=deleteButton:=CreateGadgetA(BUTTON_KIND, g,
[offx+129, offy+111+15, 65, 17,
'Delete', tattr, DELETEBUTTON_ID, 16, visual, 0]:newgadget,
[TAG_DONE]))=NIL THEN RETURN NOGADGET
ENDPROC NONE
PROC openWindow()
IF createGadgets()<>NONE THEN RETURN NOGADGET
/*-- Note WA_IDCMP to get messages from the listview gadget: --*/
IF (win:=OpenWindowTagList(NIL,
[WA_LEFT, 38,
WA_TOP, 14,
WA_WIDTH, offx+257,
WA_HEIGHT, offy+150,
WA_IDCMP, (IDCMP_REFRESHWINDOW OR IDCMP_CLOSEWINDOW OR IDCMP_GADGETUP OR
IDCMP_MOUSEMOVE OR LISTVIEWIDCMP OR SCROLLERIDCMP),
WA_FLAGS, (WFLG_DRAGBAR OR WFLG_DEPTHGADGET OR WFLG_CLOSEGADGET OR
WFLG_SMART_REFRESH OR WFLG_ACTIVATE),
WA_TITLE,NIL,
WA_CUSTOMSCREEN, scr,
WA_MINWIDTH, 67,
WA_MINHEIGHT, 21,
WA_MAXWIDTH, $2C0,
WA_MAXHEIGHT, 277,
WA_AUTOADJUST, 1,
WA_GADGETS, glist,
TAG_DONE]))=NIL THEN RETURN NOWINDOW
Gt_RefreshWindow(win, NIL)
ENDPROC NONE
PROC closeWindow()
IF win THEN CloseWindow(win)
ENDPROC
PROC wait4message(win:PTR TO window)
DEF mes:PTR TO intuimessage, type
REPEAT
type:=0
IF mes:=Gt_GetIMsg(win.userport)
type:=mes.class
SELECT type
CASE IDCMP_GADGETUP
/*-- Any old gadget will do. The address is used --*/
/*-- to identify which one sent the message. --*/
infos:=mes.iaddress
infos.gadgetid:=mes.code
CASE IDCMP_REFRESHWINDOW
Gt_BeginRefresh(win)
Gt_EndRefresh(win,TRUE)
type:=0
ENDSELECT
Gt_ReplyIMsg(mes)
ELSE
WaitPort(win.userport)
ENDIF
UNTIL type
ENDPROC type
PROC addToList()
DEF newNode=NIL:PTR TO ln, node:PTR TO ln,
len, done=FALSE, itemPosition=0
/*-- Don't add if there's nothing in the string gadget. --*/
IF (len:=StrLen(stringGadgetValue))=0 THEN RETURN
/*-- Create a node and a string to add to the listview. --*/
newNode:=New(SIZEOF ln)
newNode.name:=String(len)
StrCopy(newNode.name, stringGadgetValue, ALL)
/*-- Detach the exec list from the listview gadget. --*/
Gt_SetGadgetAttrsA (listView, win, NIL, [GTLV_LABELS, -1, TAG_DONE])
/*-- Decide where to insert the new item. Sorted on first character. --*/
node:=list.head
IF list.tailpred=list
AddHead(list, newNode)
ELSEIF Char(node.name)>stringGadgetValue[]
AddHead(list, newNode)
ELSEIF node=list.tailpred
AddTail(list, newNode)
ELSE
WHILE done=FALSE
node:=node.succ
INC itemPosition
IF Char(node.name)>stringGadgetValue[]
done:=TRUE
ELSEIF node.succ=NIL
done:=TRUE
ENDIF
ENDWHILE
Insert(list, newNode, node.pred)
ENDIF
/*-- Reattach the exec list to the listview gadget. --*/
Gt_SetGadgetAttrsA (listView, win, NIL,
[GTLV_LABELS, list,
GTLV_TOP, itemPosition,
TAG_DONE])
ENDPROC
PROC deleteFromList(itemPosition)
DEF node:PTR TO ln, i
/*-- Don't delete if no item is selected. --*/
IF (itemPosition=-1) OR (list.tailpred=list) THEN RETURN
/*-- Detach the exec list from the listview gadget. --*/
Gt_SetGadgetAttrsA (listView, win, NIL, [GTLV_LABELS, -1, TAG_DONE])
/*-- Find the node that corresponds to itemPosition in the exec list. --*/
node:=list.head
FOR i:=1 TO itemPosition DO node:=node.succ
/*-- Remove and deallocate the node's data. --*/
Remove(node)
Dispose(node.name)
Dispose(node)
/*-- Reattach the exec list to the listview gadget. --*/
Gt_SetGadgetAttrsA (listView, win, NIL,
[GTLV_LABELS, list, TAG_DONE])
ENDPROC
PROC main() HANDLE
DEF listItemPosition=-1 /* sentinel value, indicates no selection */
IF setupScreen()=NONE
IF openWindow()=NONE
REPEAT
messageClass:=wait4message(win)
SELECT messageClass
CASE IDCMP_GADGETUP
SELECT infos /* pointer to gadget */
CASE addButton
addToList() /* requires a value in the string gadget */
CASE deleteButton
deleteFromList(listItemPosition) /* requires a selection */
listItemPosition:=-1 /* sentinel value=no selection */
CASE listView
listItemPosition:=infos.gadgetid /* note the use of this field! */
ENDSELECT
CASE IDCMP_INTUITICKS
NOP /* these are being sent for some shitty reason }:-( */
ENDSELECT
UNTIL messageClass=IDCMP_CLOSEWINDOW
closeWindow()
ENDIF
ENDIF
closeScreen()
CleanUp(0)
EXCEPT
WriteF('Exception: "\s"\n', [exception, 0])
closeWindow()
closeScreen()
CleanUp(0)
ENDPROC