build git 2.17.1
[AROS-Contrib.git] / bgui / examples / MultiSelect.c
blob264dc49b5745cca805d0806b3331de6ecc1b1c68
1 /*
2 * @(#) $Header$
4 * MultiSelect.c
6 * (C) Copyright 1998 Manuel Lemos.
7 * (C) Copyright 1995 Jaba Development.
8 * (C) Copyright 1995 Jan van den Baard.
9 * All Rights Reserved.
11 * $Log$
12 * Revision 42.0 2000/05/09 22:20:02 mlemos
13 * Bumped to revision 42.0 before handing BGUI to AROS team
15 * Revision 41.11 2000/05/09 20:33:52 mlemos
16 * Bumped to revision 41.11
18 * Revision 1.2 2000/05/09 19:59:08 mlemos
19 * Merged with the branch Manuel_Lemos_fixes.
21 * Revision 1.1.2.3 1998/12/07 00:14:09 mlemos
22 * Made the listview be activated by the key indicated in the added label.
24 * Revision 1.1.2.2 1998/03/01 19:45:41 mlemos
25 * Fixed the display of empty lines.
27 * Revision 1.1.2.1 1998/02/28 17:45:38 mlemos
28 * Ian sources
33 /* Execute me to compile with DICE V3.0
34 dcc MultiSelect.c -proto -mi -ms -mRR -lbgui
35 quit
38 #include "DemoCode.h"
41 ** The entries shown in the list.
42 **/
43 UBYTE *ListEntries[] = {
44 ISEQ_C "This listview object has multi-",
45 ISEQ_C "selection turned on. You can",
46 ISEQ_C "multi-select the items by holding",
47 ISEQ_C "down the SHIFT-key while clicking",
48 ISEQ_C "on the different items or by clicking",
49 ISEQ_C "on an entry and dragging the mouse",
50 ISEQ_C "up or down.",
51 "",
52 ISEQ_C "If you check the \"No SHIFT\" checbox",
53 ISEQ_C "you can multi-select the items without",
54 ISEQ_C "using the SHIFT key",
55 NULL
59 ** Map-list.
60 **/
61 struct TagItem CheckToList[] = {
62 { GA_Selected, LISTV_MultiSelectNoShift },
63 { TAG_END }
67 ** Object ID's.
68 **/
69 #define ID_SHOW 1
70 #define ID_QUIT 2
71 #define ID_ALL 3
72 #define ID_NONE 4
74 VOID StartDemo( void )
76 struct Window *window;
77 Object *WO_Window, *GO_Quit, *GO_Show, *GO_List, *GO_Shift, *GO_All, *GO_None;
78 IPTR signal;
79 ULONG rc, tmp = 0;
80 BOOL running = TRUE;
83 * Create the window object.
85 WO_Window = WindowObject,
86 WINDOW_Title, "Multi-Selection Demo",
87 WINDOW_AutoAspect, TRUE,
88 WINDOW_SmartRefresh, TRUE,
89 WINDOW_RMBTrap, TRUE,
90 WINDOW_ScaleWidth, 30,
91 WINDOW_ScaleHeight, 30,
92 WINDOW_MasterGroup,
93 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
94 StartMember,
95 VGroupObject, HOffset( 4 ), VOffset( 4 ),
96 FRM_Type, FRTYPE_BUTTON,
97 FRM_Recessed, TRUE,
98 StartMember,
99 GO_List = ListviewObject,
100 LISTV_EntryArray, ListEntries,
101 LISTV_MultiSelect, TRUE,
102 Label("Se_lect next entry"),
103 Place(PLACE_ABOVE),
104 EndObject,
105 EndMember,
106 StartMember,
107 HGroupObject,
108 StartMember, GO_All = KeyButton( "_All", ID_ALL ), EndMember,
109 StartMember, GO_None = KeyButton( "N_one", ID_NONE ), EndMember,
110 EndObject, FixMinHeight,
111 EndMember,
112 EndObject,
113 EndMember,
114 StartMember,
115 HGroupObject, HOffset( 4 ), VOffset( 4 ),
116 FRM_Type, FRTYPE_BUTTON,
117 FRM_Recessed, TRUE,
118 VarSpace( DEFAULT_WEIGHT ),
119 StartMember, GO_Shift = KeyCheckBox( "_No SHIFT:", FALSE, 0 ), EndMember,
120 VarSpace( DEFAULT_WEIGHT ),
121 EndObject, FixMinHeight,
122 EndMember,
123 StartMember,
124 HGroupObject, Spacing( 4 ),
125 StartMember, GO_Show = KeyButton( "_Show", ID_SHOW ), EndMember,
126 VarSpace( DEFAULT_WEIGHT ),
127 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
128 EndObject, FixMinHeight,
129 EndMember,
130 EndObject,
131 EndObject;
134 ** Object created OK?
136 if ( WO_Window ) {
138 ** Assign the keys to the buttons.
140 tmp += GadgetKey( WO_Window, GO_Quit, "q" );
141 tmp += GadgetKey( WO_Window, GO_Show, "s" );
142 tmp += GadgetKey( WO_Window, GO_Shift, "n" );
143 tmp += GadgetKey( WO_Window, GO_All, "a" );
144 tmp += GadgetKey( WO_Window, GO_None, "o" );
145 tmp += GadgetKey( WO_Window, GO_List, "l" );
147 ** OK?
149 if ( tmp == 6 ) {
151 ** Add notification.
153 if ( AddMap( GO_Shift, GO_List, CheckToList )) {
155 ** try to open the window.
157 if (( window = WindowOpen( WO_Window ))) {
159 ** Obtain it's wait mask.
161 GetAttr( WINDOW_SigMask, WO_Window, &signal );
163 ** Event loop...
165 do {
166 Wait( signal );
168 ** Handle events.
170 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
172 ** Evaluate return code.
174 switch ( rc ) {
176 case WMHI_CLOSEWINDOW:
177 case ID_QUIT:
178 running = FALSE;
179 break;
181 case ID_ALL:
182 SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_SelectMulti, LISTV_Select_All, TAG_END );
183 break;
185 case ID_NONE:
186 SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_DeSelect, ~0, TAG_END );
187 break;
189 case ID_SHOW:
191 UBYTE *str;
194 ** Simply dump all selected entries
195 ** to the console.
197 if (( str = ( UBYTE * )FirstSelected( GO_List ))) {
198 do {
199 STRPTR text=str;
201 if(*text)
202 text++;
203 if(*text)
204 text++;
205 Tell( "%s\n", text);
206 str = ( UBYTE * )NextSelected( GO_List, str );
207 } while ( str );
208 } else
210 ** Oops. There are no selected
211 ** entries.
213 Tell( "No selections made!\n" );
214 break;
218 } while ( running );
219 } else
220 Tell( "Could not open the window\n" );
221 } else
222 Tell( "Unable to add notification\n" );
223 } else
224 Tell( "Could not assign gadget keys\n" );
226 ** Disposing of the window object will
227 ** also close the window if it is
228 ** already opened and it will dispose of
229 ** all objects attached to it.
231 DisposeObject( WO_Window );
232 } else
233 Tell( "Could not create the window object\n" );