From 80c5b70c439e0135adc890e5bd4fe88e365cfa29 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 29 Apr 2002 21:04:13 +0000 Subject: [PATCH] Add preferences demo. Change all reference to matthiasmm.com to fltk.org. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2137 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Preferences.cxx | 6 +- test/Makefile | 8 +- test/demo.menu | 3 +- test/makedepend | 8 ++ test/preferences.cxx | 262 ++++++++++++++++++++++++++++++++++++++++ test/preferences.h | 42 +++++++ visualc/preferences.dsp | 97 +++++++++++++++ 7 files changed, 420 insertions(+), 6 deletions(-) create mode 100644 test/preferences.cxx create mode 100644 test/preferences.h create mode 100644 visualc/preferences.dsp diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index 3eae0bcb3..362a48209 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Preferences.cxx,v 1.1.2.4 2002/04/29 20:57:31 easysw Exp $" +// "$Id: Fl_Preferences.cxx,v 1.1.2.5 2002/04/29 21:04:12 easysw Exp $" // // Preferences methods for the Fast Light Tool Kit (FLTK). // @@ -54,7 +54,7 @@ char Fl_Preferences::nameBuffer[]; * i application: vendor unique application name, i.e. "PreferencesTest" * multiple preferences files can be created per application. * Must be a valid file name. - * example: Fl_Preferences base( Fl_Preferences::USER, "matthiasm.com", "test01"); + * example: Fl_Preferences base( Fl_Preferences::USER, "fltk.org", "test01"); */ Fl_Preferences::Fl_Preferences( enum Root root, const char *vendor, const char *application ) { @@ -935,5 +935,5 @@ char Fl_Preferences::Node::remove() // -// End of "$Id: Fl_Preferences.cxx,v 1.1.2.4 2002/04/29 20:57:31 easysw Exp $". +// End of "$Id: Fl_Preferences.cxx,v 1.1.2.5 2002/04/29 21:04:12 easysw Exp $". // diff --git a/test/Makefile b/test/Makefile index ac110f549..14cc56193 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.19.2.7.2.33 2002/04/29 14:32:13 easysw Exp $" +# "$Id: Makefile,v 1.19.2.7.2.34 2002/04/29 21:04:12 easysw Exp $" # # Test/example program makefile for the Fast Light Tool Kit (FLTK). # @@ -74,6 +74,7 @@ CPPFILES =\ pack.cxx \ pixmap_browser.cxx \ pixmap.cxx \ + preferences.cxx \ radio.cxx \ resizebox.cxx \ resize.cxx \ @@ -130,6 +131,7 @@ ALL = \ pack$(EXEEXT) \ pixmap$(EXEEXT) \ pixmap_browser$(EXEEXT) \ + preferences$(EXEEXT) \ radio$(EXEEXT) \ resize$(EXEEXT) \ resizebox$(EXEEXT) \ @@ -302,6 +304,8 @@ pixmap_browser$(EXEEXT): pixmap_browser.o $(CXX) -I.. $(CXXFLAGS) pixmap_browser.o -o $@ $(LINKFLTK) $(IMAGELIBS) $(LDLIBS) $(POSTBUILD) $@ ../FL/mac.r +preferences$(EXEEXT): preferences.o + radio$(EXEEXT): radio.o radio.cxx: radio.fl @@ -376,5 +380,5 @@ shape$(EXEEXT): shape.o # -# End of "$Id: Makefile,v 1.19.2.7.2.33 2002/04/29 14:32:13 easysw Exp $". +# End of "$Id: Makefile,v 1.19.2.7.2.34 2002/04/29 21:04:12 easysw Exp $". # diff --git a/test/demo.menu b/test/demo.menu index 37c566686..b5a96d922 100644 --- a/test/demo.menu +++ b/test/demo.menu @@ -64,10 +64,11 @@ @main:Other\nTests:@o @o:Color Choosers:color_chooser r @o:File Chooser:file_chooser - @o:XForms Emulation:forms @o:Fonts:fonts @o:HelpDialog:help + @o:Preferences:preferences @o:Threading:threads + @o:XForms Emulation:forms @main:Tutorial\nfrom\nManual:@j @j:ask\n(modified):ask diff --git a/test/makedepend b/test/makedepend index 505ff6f51..12d2e6649 100644 --- a/test/makedepend +++ b/test/makedepend @@ -264,6 +264,14 @@ pixmap.o: ../FL/Fl_Group.H ../FL/Fl_Widget.H ../FL/Fl_Button.H pixmap.o: ../FL/Fl_Pixmap.H ../FL/Fl_Image.H ../FL/x.H ../FL/Fl_Window.H pixmap.o: porsche.xpm ../FL/Fl_Toggle_Button.H ../FL/Fl_Button.H pixmap.o: ../FL/Fl_Multi_Label.H +preferences.o: preferences.h ../FL/Fl.H ../FL/Enumerations.H +preferences.o: ../FL/Fl_Export.H ../FL/Fl_Preferences.H ../FL/Fl_Window.H +preferences.o: ../FL/Fl_Group.H ../FL/Fl_Widget.H ../FL/Fl_Button.H +preferences.o: ../FL/Fl_Group.H ../FL/Fl_Input.H ../FL/Fl_Input_.H +preferences.o: ../FL/Fl_Choice.H ../FL/Fl_Round_Button.H +preferences.o: ../FL/Fl_Light_Button.H ../FL/Fl_Button.H ../FL/Fl_Box.H +preferences.o: ../FL/Fl_Check_Button.H ../FL/Fl_Value_Slider.H +preferences.o: ../FL/Fl_Slider.H ../FL/Fl_Valuator.H ../FL/filename.H radio.o: radio.h ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H radio.o: ../FL/Fl_Window.H ../FL/Fl_Group.H ../FL/Fl_Widget.H radio.o: ../FL/Fl_Button.H ../FL/Fl_Return_Button.H ../FL/Fl_Button.H diff --git a/test/preferences.cxx b/test/preferences.cxx new file mode 100644 index 000000000..6c8de6308 --- /dev/null +++ b/test/preferences.cxx @@ -0,0 +1,262 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.0100 + + +#include "preferences.h" +#include +#include +void readPrefs(); +void writePrefs(); + +static void closeWindowCB( Fl_Widget*, void* ) { + delete myWindow; +} + +static void saveAndCloseWindowCB( Fl_Widget*, void* ) { + writePrefs(); + delete myWindow; +} + +Fl_Window *myWindow=(Fl_Window *)0; + +Fl_Input *wAlarm=(Fl_Input *)0; + +Fl_Choice *wAmPm=(Fl_Choice *)0; + +Fl_Menu_Item menu_wAmPm[] = { + {"a.m.", 0, 0, 0, 0, 0, 0, 14, 0}, + {"p.m.", 0, 0, 0, 0, 0, 0, 14, 0}, + {0} +}; + +Fl_Choice *wWear=(Fl_Choice *)0; + +Fl_Menu_Item menu_wWear[] = { + {"shoes", 0, 0, 0, 0, 0, 0, 14, 0}, + {"sandals", 0, 0, 0, 0, 0, 0, 14, 0}, + {"flip flops", 0, 0, 0, 0, 0, 0, 14, 0}, + {"bare foot", 0, 0, 0, 0, 0, 0, 14, 0}, + {0} +}; + +Fl_Round_Button *wLeft=(Fl_Round_Button *)0; + +Fl_Round_Button *wRight=(Fl_Round_Button *)0; + +Fl_Check_Button *wShower=(Fl_Check_Button *)0; + +Fl_Check_Button *wShave=(Fl_Check_Button *)0; + +Fl_Check_Button *wBrush=(Fl_Check_Button *)0; + +Fl_Choice *wDrink=(Fl_Choice *)0; + +Fl_Menu_Item menu_wDrink[] = { + {"coffee", 0, 0, 0, 0, 0, 0, 14, 0}, + {"tea", 0, 0, 0, 0, 0, 0, 14, 0}, + {"juice", 0, 0, 0, 0, 0, 0, 14, 0}, + {0} +}; + +Fl_Check_Button *wMilk=(Fl_Check_Button *)0; + +Fl_Choice *wBread=(Fl_Choice *)0; + +Fl_Menu_Item menu_wBread[] = { + {"wheat", 0, 0, 0, 0, 0, 0, 14, 0}, + {"white", 0, 0, 0, 0, 0, 0, 14, 0}, + {"rye", 0, 0, 0, 0, 0, 0, 14, 0}, + {"sour doh", 0, 0, 0, 0, 0, 0, 14, 0}, + {0} +}; + +Fl_Check_Button *wButter=(Fl_Check_Button *)0; + +Fl_Input *wEggs=(Fl_Input *)0; + +Fl_Value_Slider *wMinutes=(Fl_Value_Slider *)0; + +Fl_Input *wPaper=(Fl_Input *)0; + +int main(int argc, char **argv) { + Fl_Window* w; + { Fl_Window* o = myWindow = new Fl_Window(298, 311, "My Preferences"); + w = o; + o->callback((Fl_Callback*)closeWindowCB); + { Fl_Button* o = new Fl_Button(210, 275, 75, 25, "Cancel"); + o->callback((Fl_Callback*)closeWindowCB); + } + { Fl_Button* o = new Fl_Button(125, 275, 75, 25, "OK"); + o->callback((Fl_Callback*)saveAndCloseWindowCB); + } + { Fl_Group* o = new Fl_Group(20, 30, 115, 225, "Get Up:"); + o->box(FL_ENGRAVED_FRAME); + o->align(FL_ALIGN_TOP_LEFT); + { Fl_Input* o = wAlarm = new Fl_Input(25, 55, 45, 20, "Alarm at:"); + o->align(FL_ALIGN_TOP_LEFT); + } + { Fl_Choice* o = wAmPm = new Fl_Choice(75, 55, 55, 20); + o->down_box(FL_BORDER_BOX); + o->menu(menu_wAmPm); + } + { Fl_Choice* o = wWear = new Fl_Choice(25, 100, 105, 20, "Wear:"); + o->down_box(FL_BORDER_BOX); + o->align(FL_ALIGN_TOP_LEFT); + o->menu(menu_wWear); + } + { Fl_Round_Button* o = wLeft = new Fl_Round_Button(35, 120, 95, 25, "left side"); + o->down_box(FL_ROUND_DOWN_BOX); + } + { Fl_Round_Button* o = wRight = new Fl_Round_Button(35, 140, 95, 25, "right side"); + o->down_box(FL_ROUND_DOWN_BOX); + } + new Fl_Box(38, 160, 95, 20, "of the bed"); + { Fl_Check_Button* o = wShower = new Fl_Check_Button(25, 180, 105, 25, "shower"); + o->down_box(FL_DOWN_BOX); + } + { Fl_Check_Button* o = wShave = new Fl_Check_Button(25, 200, 105, 25, "shave"); + o->down_box(FL_DOWN_BOX); + } + { Fl_Check_Button* o = wBrush = new Fl_Check_Button(25, 220, 105, 25, "brush teeth"); + o->down_box(FL_DOWN_BOX); + } + o->end(); + } + { Fl_Group* o = new Fl_Group(160, 30, 115, 225, "Breakfast::"); + o->box(FL_ENGRAVED_FRAME); + o->align(FL_ALIGN_TOP_LEFT); + { Fl_Choice* o = wDrink = new Fl_Choice(165, 50, 105, 20, "Drink:"); + o->down_box(FL_BORDER_BOX); + o->align(FL_ALIGN_TOP_LEFT); + o->menu(menu_wDrink); + } + { Fl_Check_Button* o = wMilk = new Fl_Check_Button(170, 70, 100, 25, "with milk"); + o->down_box(FL_DOWN_BOX); + } + { Fl_Choice* o = wBread = new Fl_Choice(165, 110, 105, 20, "Bread:"); + o->down_box(FL_BORDER_BOX); + o->align(FL_ALIGN_TOP_LEFT); + o->menu(menu_wBread); + } + { Fl_Check_Button* o = wButter = new Fl_Check_Button(170, 130, 100, 25, "with butter"); + o->down_box(FL_DOWN_BOX); + } + { Fl_Input* o = wEggs = new Fl_Input(165, 163, 30, 20, "eggs"); + o->type(2); + o->align(FL_ALIGN_RIGHT); + } + { Fl_Value_Slider* o = wMinutes = new Fl_Value_Slider(175, 185, 70, 20, "min."); + o->type(1); + o->minimum(2); + o->maximum(6); + o->value(3.1); + o->align(FL_ALIGN_RIGHT); + } + { Fl_Input* o = wPaper = new Fl_Input(165, 225, 105, 20, "Newspaper:"); + o->align(FL_ALIGN_TOP_LEFT); + } + o->end(); + } + o->end(); + } + readPrefs(); + w->show(argc, argv); + return Fl::run(); +} + +void readPrefs() { + char boolValue; +int intValue; +char buffer[80]; +double doubleValue; + +Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" ); + + char path[ FL_PATH_MAX ]; + app.getUserdataPath( path ); + + Fl_Preferences bed( app, "Bed" ); + bed.get( "alarm", buffer, "8:00", 80 ); + wAlarm->value( buffer ); + + bed.get( "ampm", intValue, 0 ); + wAmPm->value( intValue ); + + bed.get( "wear", intValue, 1 ); + wWear->value( intValue ); + + int side; + bed.get( "side", side, 2 ); + if ( side == 1 ) wLeft->value( 1 ); + if ( side == 2 ) wRight->value( 1 ); + + int todo; + bed.get( "todoFlags", todo, 0x05 ); + if ( todo & 0x01 ) wShower->value( 1 ); + if ( todo & 0x02 ) wShave->value( 1 ); + if ( todo & 0x04 ) wBrush->value( 1 ); + + Fl_Preferences eat( app, "Breakfast" ); + + eat.get( "drink", intValue, 1 ); + wDrink->value( intValue ); + + eat.get( "wMilk", boolValue, 0 ); + wMilk->value( boolValue ); + + eat.get( "bread", intValue, 0 ); + wBread->value( intValue ); + + eat.get( "wButter", boolValue, 1 ); + wButter->value( boolValue ); + + eat.get( "nEggs", intValue, 2 ); + sprintf( buffer, "%d", intValue ); + wEggs->value( buffer ); + + eat.get( "minutes", doubleValue, 3.2 ); + wMinutes->value( doubleValue ); + + char *flexBuffer; + eat.get( "newspaper", flexBuffer, "NY Tymes" ); + wPaper->value( flexBuffer ); + if ( flexBuffer ) free( flexBuffer ); + + eat.get( "foo", buffer, "bar", 80 ); +} + +void writePrefs() { + Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" ); + + Fl_Preferences bed( app, "Bed" ); + + bed.set( "alarm", wAlarm->value() ); + bed.set( "ampm", wAmPm->value() ); + + bed.set( "wear", wWear->value() ); + + int side = 0; + if ( wLeft->value() ) side = 1; + if ( wRight->value() ) side = 2; + bed.set( "side", side ); + + int todo = 0; + if ( wShower->value() ) todo |= 0x01; + if ( wShave->value() ) todo |= 0x02; + if ( wBrush->value() ) todo |= 0x04; + bed.set( "todoFlags", todo ); + + Fl_Preferences eat( app, "Breakfast" ); + + eat.set( "drink", wDrink->value() ); + eat.set( "wMilk", wMilk->value() ); + eat.set( "bread", wBread->value() ); + eat.set( "wButter", wButter->value() ); + + eat.set( "nEggs", wEggs->value() ); + eat.set( "minutes", wMinutes->value() ); + + eat.set( "newspaper", wPaper->value() ); + + eat.set( "foo", "bar\nfly\rBackslash: \\ and bell: \007 and delete: \177\n" ); + +} diff --git a/test/preferences.h b/test/preferences.h new file mode 100644 index 000000000..54206e639 --- /dev/null +++ b/test/preferences.h @@ -0,0 +1,42 @@ +// generated by Fast Light User Interface Designer (fluid) version 1.0100 + +#ifndef preferences_h +#define preferences_h +#include +#include +#include +#include +extern void closeWindowCB(Fl_Window*, void*); +extern Fl_Window *myWindow; +#include +extern void closeWindowCB(Fl_Button*, void*); +extern void saveAndCloseWindowCB(Fl_Button*, void*); +#include +#include +extern Fl_Input *wAlarm; +#include +extern Fl_Choice *wAmPm; +extern Fl_Choice *wWear; +#include +extern Fl_Round_Button *wLeft; +extern Fl_Round_Button *wRight; +#include +#include +extern Fl_Check_Button *wShower; +extern Fl_Check_Button *wShave; +extern Fl_Check_Button *wBrush; +extern Fl_Choice *wDrink; +extern Fl_Check_Button *wMilk; +extern Fl_Choice *wBread; +extern Fl_Check_Button *wButter; +extern Fl_Input *wEggs; +#include +extern Fl_Value_Slider *wMinutes; +extern Fl_Input *wPaper; +extern Fl_Menu_Item menu_wAmPm[]; +extern Fl_Menu_Item menu_wWear[]; +extern Fl_Menu_Item menu_wDrink[]; +extern Fl_Menu_Item menu_wBread[]; +void readPrefs(); +void writePrefs(); +#endif diff --git a/visualc/preferences.dsp b/visualc/preferences.dsp new file mode 100644 index 000000000..ed1e64142 --- /dev/null +++ b/visualc/preferences.dsp @@ -0,0 +1,97 @@ +# Microsoft Developer Studio Project File - Name="preferences" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=preferences - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "preferences.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "preferences.mak" CFG="preferences - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "preferences - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "preferences - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "preferences - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /GX /Os /Ob2 /I "." /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 fltk.lib wsock32.lib comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libcd" /out:"../test/preferences.exe" /libpath:"..\lib" +# SUBTRACT LINK32 /pdb:none /incremental:yes + +!ELSEIF "$(CFG)" == "preferences - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "preferences_" +# PROP BASE Intermediate_Dir "preferences_" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "preferences_" +# PROP Intermediate_Dir "preferences_" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /Gm /GX /ZI /Od /I "." /I ".." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 fltkd.lib wsock32.lib comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcd" /out:"../test/preferencesd.exe" /pdbtype:sept /libpath:"..\lib" +# SUBTRACT LINK32 /pdb:none /incremental:no + +!ENDIF + +# Begin Target + +# Name "preferences - Win32 Release" +# Name "preferences - Win32 Debug" +# Begin Source File + +SOURCE=..\test\preferences.cxx +# End Source File +# End Target +# End Project