home *** CD-ROM | disk | FTP | other *** search
- MODULE ComboBox;
- (*$ LargeVars:=FALSE *)
-
- (* $VER: ComboBox 1.002 (17 Oct 1993)
- **
- **
- ** This little Prog. will create a ComboBox as used in Windoze,
- ** but ofcourse better, because it's MUI :-)
- **
- ** $HISTORY:
- **
- ** 17 Oct 1993 : 001.002 : some little enhancements
- ** 17 Oct 1993 : 001.001 : created
- **
- **
- *)
-
-
- (***/ "IMPORTS" /***)
- IMPORT MD:MuiD;
- IMPORT ML:MuiL;
- IMPORT MM:MuiMacros;
- FROM MuiMacros IMPORT NoteButton, NoteClose, Child, set, get,
- STRING, STRPTR, STRARR, STRARRPTR,
- MakeHook, MakeID, AddMember, RemMember;
- FROM MuiSupport IMPORT fail, APTR, DoMethod, DOMethod;
- FROM UtilityD IMPORT HookPtr, tagEnd;
- FROM IntuitionD IMPORT WindowPtr;
- FROM ExecL IMPORT Wait;
- FROM SYSTEM IMPORT TAG, ADR, LONGSET, CAST;
- (******)
- (***/ "TYPE" /***)
- TYPE ComboArr = ARRAY[0..9] OF STRPTR; (* C-Array of strings *)
- tagbuffer = ARRAY[0..30] OF LONGINT; (* buffer for the tags *)
- (******)
- (***/ "CONST" /***)
- CONST True = 1; (* for the get routine of MuiMacros, because it *)
- False = 0; (* excepts just LONGINT and no BOOLEAN values *)
-
- IDOK = 1; (* for the notifies *)
- IDCancel = 2;
- IDPopUp = 3;
- IDPopOk = 4;
- IDPopCancel = 5;
- IDPopDouble = 6;
-
-
- (* The contents for our Combo-List *)
-
- ComboArray = ComboArr{ADR("Amiga 500"),
- ADR("Amiga 600"), ADR("Amiga 1000"),
- ADR("Amiga 1200"),
- ADR("Amiga 2000"),
- ADR("Amiga 3000"),
- ADR("Amiga 4000"),
- ADR("Amiga 4000T"),
- ADR("Amiga 5000 :-)"),
- NIL};
-
- (******)
- (***/ "VAR" /***)
- VAR
- app, window,
- OKBut, CancelBut,
- String, StringGroup,
- Label, Popup, image : APTR; (* for objects *)
- signals : LONGSET;
- msg : LONGINT;
- running :=BOOLEAN{TRUE};
- buffer, buffer1, buffer2 : tagbuffer; (* for tags *)
- PopUpHook : HookPtr;
- ListEntry : STRPTR; (* for the actual entry
- in our Popup-Listview
- This must be global,
- because otherwise
- it gets destroyed
- when the hook
- exits
- *)
- (******)
- (***/ "PopUpFunc" /***)
- (* So here is the hook function for the PopUp-Object *)
-
- PROCEDURE PopUpFunc (hook : HookPtr;
- obj : APTR;
- args : APTR) : APTR;
-
- VAR
- Popupwindow,
- PopupOKBut,
- PopupCancelBut,
- PopupList,
- PopupListview : APTR; (* for the objects *)
- left, top : LONGINT; (* to calculate our window- *)
- width, height : LONGINT; (* position *)
- win : WindowPtr; (* - dito - *)
- buffer : tagbuffer; (* don't forget this!!!! use NOT the global one *)
- window : APTR; (* the window, where the popup-obj
- resides in *)
- app : APTR; (* dito for the app-object *)
-
-
- BEGIN
-
-
- (*
- first of all get the window and application-objects of the
- popup-object, so that we do not need global vars
- *)
-
- get(obj, MD.maWindowObject, ADR(window));
- get(obj, MD.maApplicationObject, ADR(app));
-
-
- (*
- Now generate the objects and add it to the application
- by an omADDMEMBER-Call
- *)
-
- (* the buttons for the Popup-Object *)
- PopupOKBut := MM.Keybutton ("OK",'o');
- PopupCancelBut := MM.Keybutton ("Cancel",'c');
-
- (* Now the list for the Popup-Object
- We do not need a Construct, Destruct or Display-Hook,
- because we have a constant array of strings, so they
- do not need be copied.
- We also have simple strings, so that we have not to
- supply a display hook!
- *)
- PopupList := MM.ListObject(TAG(buffer,
- MD.maFrame, MD.mvFrameInputList,
- tagEnd));
-
- PopupListview := MM.ListviewObject(TAG(buffer,
- MD.maListviewList, PopupList,
- tagEnd));
-
- (* get position and dimension of the popup-object *)
- get(obj, MD.maHeight, ADR(height));
- get(obj, MD.maTopEdge, ADR(top));
- get(obj, MD.maLeftEdge, ADR(left));
- get(obj, MD.maWindow, ADR(win));
- get(obj, MD.maWidth, ADR(width));
-
- (* create window under the Popup-Object *)
- Popupwindow := MM.WindowObject(TAG(buffer,
- MD.maWindowTitle, ADR("Select computer"),
- MD.maWindowLeftEdge, win^.leftEdge+left,
- MD.maWindowTopEdge, win^.topEdge+height+top,
- MD.maWindowWidth, width,
- MD.maWindowDragBar, FALSE, (* no dragging *)
- MD.maWindowCloseGadget,FALSE, (* no closing *)
- MD.maWindowNoMenus, TRUE,
-
- MM.WindowContents,
- MM.VGroup(TAG(buffer1,
- Child, PopupListview,
- Child, MM.HGroup(TAG(buffer2,
- Child, PopupOKBut,
- Child, PopupCancelBut,
- tagEnd)),
- tagEnd)),
- tagEnd));
-
- (* Notify *)
- NoteButton(app, PopupOKBut, IDPopOk);
- NoteButton(app, PopupCancelBut, IDPopCancel);
- NoteClose(app, Popupwindow, IDPopCancel);
- (* IF someone doubleclicks on the list, send IDPopDouble *)
- DoMethod(PopupListview, TAG(buffer, MD.mmNotify,
- MD.maListviewDoubleClick, TRUE,
- app, 2,
- MD.mmApplicationReturnID, IDPopDouble));
-
- (* set up the cycle chain *)
- DoMethod(Popupwindow, TAG(buffer, MD.mmWindowSetCycleChain,
- PopupOKBut,
- PopupCancelBut,
- PopupListview,
- NIL));
-
- (* make the listview the default active object *)
- set(Popupwindow, MD.maWindowDefaultObject, PopupListview);
-
- (* Insert things in list *)
- DoMethod(PopupList, TAG(buffer, MD.mmListInsert,
- ADR(ComboArray), -1, MD.mvListInsertBottom));
-
- (* add window to application *)
- AddMember(app,Popupwindow);
-
- (* open window *)
- set(Popupwindow,MD.maWindowOpen,True);
- set(window, MD.maWindowSleep, True);
-
- (* MAIN LOOP *)
-
- WHILE running DO
- (* wait for signals IF necessary *)
- IF signals <> LONGSET{} THEN signals:=Wait(signals); END;
-
- (* get the message *)
- msg:=DOMethod(app,TAG(buffer,
- MD.mmApplicationInput,ADR(signals)));
-
- CASE msg OF
- | MD.mvApplicationReturnIDQuit : (* quit!
- this is easy here, because
- we have access to the
- running-Var
- otherwise you perhaps
- can provide a callback-hook
- for the quit-signal
- *)
- running:=FALSE;
- RETURN 0;
-
- | IDPopCancel : (* Close window *)
-
- set(Popupwindow, MD.maWindowOpen, False);
- set(window, MD.maWindowSleep, False);
- RETURN 0;
-
- | IDPopOk, IDPopDouble :
-
- (*
- now we have to put the actual listentry
- in the stringgadget
- *)
-
- (* copy the selected item into the string gadget *)
- DoMethod(PopupList, TAG(buffer, MD.mmListGetEntry,
- MD.mvListGetEntryActive, ADR(ListEntry)));
-
- IF ListEntry#NIL THEN
- set (obj, MD.maStringContents, ADR(ListEntry^));
- (* we can use 'obj' instead of 'String' because
- MUI will give this to all of the childs
- of the Popup-group! (a group with a string and an
- image object)
- *)
- END;
-
- (* Alternative implementation of copy-process
-
- get(PopupList, MD.maListActive, ADR(pos));
- IF pos#MD.mvListActiveOff THEN
- set(String, MD.maStringContents, ADR(ComboArray[pos]^));
- END;
- *)
-
- (* Close our window and wake up the one with the PopUp-Object *)
- set(Popupwindow, MD.maWindowOpen, False);
- set(window, MD.maWindowSleep, False);
-
- RemMember(app, Popupwindow);
- ML.mDisposeObject(Popupwindow); (* DON'T forget ! *)
- RETURN 0;
- ELSE
- END;
- END; (*WHILE*)
-
- RETURN 0;
- END PopUpFunc;
- (******)
- (***/ "Main program" /***)
- BEGIN
-
- (* define the Popup-Hook *)
- MakeHook(PopUpFunc,PopUpHook);
-
-
- (* Lets do the buttons for the main window *)
- OKBut := MM.Keybutton ("OK",'o');
- CancelBut := MM.Keybutton ("Cancel",'c');
-
-
- (* Now the string-gadget *)
- Label := MM.KeyLabel2("Computer",'m');
- String := MM.KeyString("Amiga 2000",200,'m');
-
- (* the PopUp-Object *)
- Popup := MM.Popup(String,PopUpHook,image,MD.miPopUp);
-
- (* now put all in a group *)
- StringGroup := MM.HGroup(TAG(buffer,
- Child, Label,
- Child, Popup));
-
-
- (* lets do the window *)
- window := MM.WindowObject(TAG(buffer,
- MD.maWindowTitle, ADR("ComboBoxDemo"),
- MD.maWindowScreenTitle, ADR("Denn auch der Darm istein FIFO-Speicher!"),
- MD.maWindowID, MakeID("COMB"),
- MM.WindowContents,
- MM.VGroup(TAG(buffer1,
- Child, StringGroup,
- Child, MM.HGroup(TAG(buffer2,
- Child, OKBut,
- Child, CancelBut,
- tagEnd)),
- tagEnd)),
- tagEnd));
-
- (* and at last the application-object *)
-
- app :=MM.ApplicationObject(TAG(buffer,
- MD.maApplicationTitle, ADR("Kochtopf's ComboBox"),
- MD.maApplicationAuthor, ADR("Christian Scholz"),
- MD.maApplicationVersion, ADR("$VER: ComboBox V1 (16.10.1993)"),
- MD.maApplicationCopyright, ADR("© 1993 by Christian 'Kochtopf' Scholz"),
- MD.maApplicationDescription,ADR("a little MUI ComboBox"),
- MD.maApplicationBase, ADR("Combo"),
- MM.SubWindow, window,
- tagEnd));
-
- IF app=NIL THEN fail(app,"failed to create application"); END;
-
- (* Notify *)
-
- NoteButton(app, OKBut, IDOK);
- NoteButton(app, CancelBut, MD.mvApplicationReturnIDQuit);
- NoteClose(app, window, MD.mvApplicationReturnIDQuit);
-
- (* the cycle chain *)
- DoMethod(window, TAG(buffer, MD.mmWindowSetCycleChain,
- String,
- image, (* use this and the popup-image
- can also be tab-cycled
- *)
- OKBut,
- CancelBut,
- NIL));
-
- set(window, MD.maWindowActiveObject, OKBut);
-
- (* Open the window *)
- set(window, MD.maWindowOpen, True);
-
-
- (* MAIN-LOOP *)
-
- WHILE running DO
-
- (* wait for signals IF necessary *)
- IF signals <> LONGSET{} THEN signals:=Wait(signals); END;
-
- (* get the message *)
- msg:=DOMethod(app,TAG(buffer,
- MD.mmApplicationInput,ADR(signals)));
-
- (* work on message *)
- CASE msg OF
- | MD.mvApplicationReturnIDQuit , IDOK: (* quit application *)
- running:=FALSE;
- ELSE
- END; (* CASE *)
-
- END; (* WHILE - Message-LOOP *)
-
- fail(app,"");
-
- (******)
-
- END ComboBox.
-
-
-