delint: unused on AROS
[AROS-Contrib.git] / bgui / examples / TextField.c
blob564cf1b0ed38af8a330b412335533a17b9e8d7c7
1 /*
2 * @(#) $Header$
4 * TextField.c
6 * (C) Copyright 1998 Manuel Lemos.
7 * All Rights Reserved.
9 * $Log$
10 * Revision 42.0 2000/05/09 22:20:08 mlemos
11 * Bumped to revision 42.0 before handing BGUI to AROS team
13 * Revision 41.11 2000/05/09 20:33:57 mlemos
14 * Bumped to revision 41.11
16 * Revision 1.2 2000/05/09 19:59:12 mlemos
17 * Merged with the branch Manuel_Lemos_fixes.
19 * Revision 1.1.2.1 1999/07/30 22:11:47 mlemos
20 * Initial revision.
26 #include "DemoCode.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include <intuition/icclass.h>
33 #include <gadgets/textfield.h>
34 #include <proto/textfield.h>
35 #include <proto/iffparse.h>
38 ** Library base pointers.
39 **/
40 struct Library *TextFieldBase = NULL;
43 ** Object ID's
44 **/
45 #define ID_RIGHTPROP 1
46 #define ID_TEXTFIELD 2
49 ** And were in...
50 **/
51 VOID StartDemo( void )
53 Object *WN_Window, *GO_Textfield, *GO_Master, *GO_RightProp;
54 struct Window *win;
55 ULONG winsig = 0L, sigrec, rc;
56 BOOL running = TRUE;
59 ** Open the libraries. Get display information etc...
60 **/
61 if ( TextFieldBase = OpenLibrary( TEXTFIELD_NAME, TEXTFIELD_VER )) {
63 struct ClipboardHandle *clip_handle, *undo_handle;
64 struct IntuiText text1_title;
66 text1_title.FrontPen = 0;
67 text1_title.BackPen = 1; /* don't really need to set for JAM1 */
68 text1_title.DrawMode = JAM1;
69 text1_title.LeftEdge = 0;
70 text1_title.TopEdge = 0;
71 text1_title.ITextFont = NULL;
72 text1_title.IText = NULL;
73 text1_title.NextText = NULL;
75 /* Open the clipboard; no need to verify */
76 clip_handle = OpenClipboard(0);
77 undo_handle = OpenClipboard(42);
80 ** Create a small window.
81 **/
82 WN_Window = WindowObject,
83 WINDOW_Title, "Text field",
84 WINDOW_RMBTrap, TRUE,
85 WINDOW_ScaleWidth, 20,
86 WINDOW_ScaleHeight, 20,
87 WINDOW_AutoAspect, TRUE,
89 WINDOW_RBorderGroup,
90 VGroupObject,
91 StartMember,
92 GO_RightProp = PropObject,
93 PGA_Top, 0,
94 PGA_Total, 1,
95 PGA_Visible, 1,
96 PGA_Arrows, TRUE,
97 PGA_Freedom, FREEVERT,
98 PGA_NewLook, TRUE,
99 GA_ID, ID_RIGHTPROP,
100 EndObject,
101 EndMember,
102 EndObject,
104 WINDOW_MasterGroup,
105 GO_Master = VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
106 StartMember,
107 GO_Textfield = ExternalObject,
108 EXT_MinWidth, 30,
109 EXT_MinHeight, 30,
110 EXT_Class, TEXTFIELD_GetClass(),
111 EXT_NoRebuild, TRUE,
113 FRM_Type, FRTYPE_RIDGE,
115 GA_FollowMouse, TRUE,
116 GA_IntuiText, &text1_title,
117 GA_ID, ID_TEXTFIELD,
119 TEXTFIELD_Text, (ULONG)"Right Amiga C - Copy\nRight Amiga X - Cut\nRight Amiga V - Paste\n",
120 TEXTFIELD_UserAlign, TRUE,
121 TEXTFIELD_BlinkRate, 500000,
122 TEXTFIELD_TabSpaces, 4,
123 TEXTFIELD_NonPrintChars,TRUE,
124 TEXTFIELD_ClipStream, clip_handle,
125 TEXTFIELD_UndoStream, undo_handle,
127 EndObject,
128 EndMember,
129 EndObject,
130 EndObject;
132 if ( WN_Window ) {
135 ** Open up the window.
137 if ( win = WindowOpen( WN_Window )) {
139 ** Obtain window sigmask.
141 GetAttr( WINDOW_SigMask, WN_Window, &winsig );
143 ** Wait for messages.
145 ActivateGadget((struct Gadget *)GO_Textfield,win,NULL);
146 do {
147 sigrec = Wait( winsig );
150 ** Window signal?
152 if ( sigrec & winsig ) {
153 while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
154 switch ( rc ) {
156 case WMHI_CLOSEWINDOW:
158 ** The end.
160 running = FALSE;
161 break;
163 case ID_RIGHTPROP:
165 Object *object;
166 ULONG top,visible,total;
168 GetAttr( EXT_Object, GO_Textfield, ( ULONG * )&object);
169 GetAttr( TEXTFIELD_Top, object, &top);
170 GetAttr( PGA_Visible, GO_RightProp, &visible);
171 GetAttr( PGA_Total, GO_RightProp, &total);
172 if(visible>total)
173 visible=total;
174 SetGadgetAttrs((struct Gadget *)object,win,NULL,
175 TEXTFIELD_Top,top,
176 TEXTFIELD_Visible,visible,
177 TEXTFIELD_Lines,total,
178 TAG_END);
181 case ID_TEXTFIELD:
183 Object *object;
184 ULONG top,visible,total;
186 GetAttr( EXT_Object, GO_Textfield, ( ULONG * )&object);
187 GetAttr( TEXTFIELD_Top, object, &top);
188 GetAttr( TEXTFIELD_Visible, object, &visible);
189 GetAttr( TEXTFIELD_Lines, object, &total);
190 if(visible>total)
191 visible=total;
192 SetGadgetAttrs((struct Gadget *)GO_RightProp,win,NULL,
193 PGA_Top,top,
194 PGA_Visible,visible,
195 PGA_Total,total,
196 TAG_END);
201 } while ( running );
204 ** Kill the window.
206 DisposeObject( WN_Window );
209 /* Close the clipboard */
210 if (undo_handle) {
211 CloseClipboard(undo_handle);
213 if (clip_handle) {
214 CloseClipboard(clip_handle);
218 ** Close the textfield.gadget.
220 CloseLibrary( TextFieldBase );
222 else
224 struct bguiRequest req;
226 memset(&req,'\0',sizeof(req));
227 req.br_GadgetFormat = "_Ok";
228 req.br_TextFormat = ISEQ_C "This program requires Mark Thomas' gadgets/textfield.gadget\ninstalled in your LIBS: directory.\n\n You may find it at: " ISEQ_U ISEQ_FILL "aminet://dev/gui/textfield.lha" ISEQ_N ".";
229 req.br_Flags = BREQF_AUTO_ASPECT|BREQF_FAST_KEYS;
230 req.br_ReqPos = POS_CENTERMOUSE;
231 req.br_Underscore = '_';
233 BGUI_RequestA( NULL, &req, NULL);