1 # data file for the Fltk User Interface Designer (fluid)
5 decl {\#include <FL/Fl_Preferences.H>} {public local
8 decl {\#include <stdio.h>} {public local
11 decl {\#include <stdlib.h>} {private local
14 decl {\#include <FL/filename.H>} {private local
17 decl {\#include <FL/fl_ask.H>} {private local
20 decl {void readPrefs();} {public local
23 decl {void writePrefs();} {public local
26 Function {closeWindowCB( Fl_Widget*, void* )} {open private return_type void
28 code {Fl::delete_widget(myWindow);} {}
31 Function {saveAndCloseWindowCB( Fl_Widget*, void* )} {open private return_type void
34 Fl::delete_widget(myWindow);} {}
37 Function {} {open return_type int
40 label {My Preferences}
41 callback closeWindowCB open
42 xywh {394 64 298 311} type Double visible
46 callback closeWindowCB
51 callback saveAndCloseWindowCB
56 xywh {20 30 115 225} box ENGRAVED_FRAME align 5
60 xywh {25 55 45 20} align 5
63 xywh {75 55 55 20} down_box BORDER_BOX
76 xywh {25 100 105 20} down_box BORDER_BOX align 5
98 Fl_Round_Button wLeft {
100 xywh {35 120 95 25} type Radio down_box ROUND_DOWN_BOX
102 Fl_Round_Button wRight {
104 xywh {35 140 95 25} type Radio down_box ROUND_DOWN_BOX
111 Fl_Check_Button wShower {
113 xywh {25 180 105 25} down_box DOWN_BOX
115 Fl_Check_Button wShave {
117 xywh {25 200 105 25} down_box DOWN_BOX
119 Fl_Check_Button wBrush {
121 xywh {25 220 105 25} down_box DOWN_BOX
125 label {Breakfast::} open
126 xywh {160 30 115 225} box ENGRAVED_FRAME align 5
130 xywh {165 50 105 20} down_box BORDER_BOX align 5
145 Fl_Check_Button wMilk {
147 xywh {170 70 100 25} down_box DOWN_BOX
151 xywh {165 110 105 20} down_box BORDER_BOX align 5
170 Fl_Check_Button wButter {
172 xywh {170 130 100 25} down_box DOWN_BOX
176 xywh {165 163 30 20} type Int align 8
178 Fl_Value_Slider wMinutes {
180 xywh {175 185 70 20} type Horizontal align 8 minimum 2 maximum 6 value 3.1
184 xywh {165 225 105 20} align 5
188 code {readPrefs();} {}
191 Function {readPrefs()} {open return_type void
198 Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" );
200 char path[ FL_PATH_MAX ];
201 app.getUserdataPath( path, sizeof(path) );
203 Fl_Preferences bed( app, "Bed" );
204 bed.get( "alarm", buffer, "8:00", 79 );
205 wAlarm->value( buffer );
207 bed.get( "ampm", intValue, 0 );
208 wAmPm->value( intValue );
210 bed.get( "wear", intValue, 1 );
211 wWear->value( intValue );
214 bed.get( "side", side, 2 );
215 if ( side == 1 ) wLeft->value( 1 );
216 if ( side == 2 ) wRight->value( 1 );
219 bed.get( "taskFlags", tasks, 0x05 );
220 if ( tasks & 0x01 ) wShower->value( 1 );
221 if ( tasks & 0x02 ) wShave->value( 1 );
222 if ( tasks & 0x04 ) wBrush->value( 1 );
224 Fl_Preferences eat( app, "Breakfast" );
226 eat.get( "drink", intValue, 1 );
227 wDrink->value( intValue );
229 eat.get( "wMilk", boolValue, 0 );
230 wMilk->value( boolValue );
232 eat.get( "bread", intValue, 0 );
233 wBread->value( intValue );
235 eat.get( "wButter", boolValue, 1 );
236 wButter->value( boolValue );
238 eat.get( "nEggs", intValue, 2 );
239 sprintf( buffer, "%d", intValue );
240 wEggs->value( buffer );
242 eat.get( "minutes", doubleValue, 3.2 );
243 wMinutes->value( doubleValue );
246 eat.get( "newspaper", flexBuffer, "NY Tymes" );
247 wPaper->value( flexBuffer );
248 if ( flexBuffer ) free( flexBuffer );
250 eat.get( "foo", buffer, "bar", 80 );
252 /** sample code only:
253 Fl_Preferences prev( app, "PreviousStarts" );
256 prev.get( "n", n, 0 );
257 for ( i=0; i<n; i++ )
258 prev.get( Fl_Preferences::Name( i ), flexBuffer, "" );
262 eat.get( "binFoo", (void*)&hex, 0, 0, sizeof( unsigned int ) );
264 eat.get( "binFoo2", data, 0, 0 );
268 Function {writePrefs()} {open return_type void
270 code {Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" );
272 Fl_Preferences bed( app, "Bed" );
274 bed.set( "alarm", wAlarm->value() );
275 bed.set( "ampm", wAmPm->value() );
277 bed.set( "wear", wWear->value() );
280 if ( wLeft->value() ) side = 1;
281 if ( wRight->value() ) side = 2;
282 bed.set( "side", side );
285 if ( wShower->value() ) tasks |= 0x01;
286 if ( wShave->value() ) tasks |= 0x02;
287 if ( wBrush->value() ) tasks |= 0x04;
288 bed.set( "taskFlags", tasks );
290 Fl_Preferences eat( app, "Breakfast" );
292 eat.set( "drink", wDrink->value() );
293 eat.set( "wMilk", wMilk->value() );
294 eat.set( "bread", wBread->value() );
295 eat.set( "wButter", wButter->value() );
297 eat.set( "nEggs", wEggs->value() );
298 eat.set( "minutes", wMinutes->value() );
300 eat.set( "newspaper", wPaper->value() );
302 eat.set( "foo", "bar\\nfly\\rBackslash: \\\\ and bell: \\007 and delete: \\177\\n" );
304 eat.set( Fl_Preferences::Name( 3 ), "Test3" );
306 /* sample: create a sub-sub-group */
307 Fl_Preferences eatMore( eat, "More" );
309 eatMore.set( "more", "stuff" );
311 /* all the following searches should return 1 */
313 sum += app.groupExists( "Breakfast" ); /* find 'eat' relative to 'app' */
314 sum += app.groupExists( "Breakfast/More" ); /* find 'eat.eatMore' relative to 'app' */
315 sum += app.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
316 sum += eat.groupExists( "More" ); /* find 'eatMore' relative to 'eat' */
317 sum += eat.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
318 sum += eat.groupExists( "." ); /* find myself ('eat') */
319 sum += eat.groupExists( "./" ); /* find the topmost group ('app') */
321 fl_message( "Assertion failed:\\nNot all group entries were found!" );
323 /* sample code only: */
324 unsigned int hex = 0x2387efcd;
325 eat.set( "binFoo", (void*)&hex, sizeof( unsigned int ) );
326 eat.set( "binFoo2", (void*)&bed, 256 );} {selected