You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
9.6KB

  1. // generated by Fast Light User Interface Designer (fluid) version 1.0300
  2. #include "preferences.h"
  3. #include <stdlib.h>
  4. #include <FL/filename.H>
  5. #include <FL/fl_ask.H>
  6. void readPrefs();
  7. void writePrefs();
  8. static void closeWindowCB( Fl_Widget*, void* ) {
  9. Fl::delete_widget(myWindow);
  10. }
  11. static void saveAndCloseWindowCB( Fl_Widget*, void* ) {
  12. writePrefs();
  13. Fl::delete_widget(myWindow);
  14. }
  15. Fl_Double_Window *myWindow=(Fl_Double_Window *)0;
  16. Fl_Input *wAlarm=(Fl_Input *)0;
  17. Fl_Choice *wAmPm=(Fl_Choice *)0;
  18. Fl_Menu_Item menu_wAmPm[] = {
  19. {"a.m.", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  20. {"p.m.", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  21. {0,0,0,0,0,0,0,0,0}
  22. };
  23. Fl_Choice *wWear=(Fl_Choice *)0;
  24. Fl_Menu_Item menu_wWear[] = {
  25. {"shoes", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  26. {"sandals", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  27. {"flip flops", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  28. {"bare foot", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  29. {0,0,0,0,0,0,0,0,0}
  30. };
  31. Fl_Round_Button *wLeft=(Fl_Round_Button *)0;
  32. Fl_Round_Button *wRight=(Fl_Round_Button *)0;
  33. Fl_Check_Button *wShower=(Fl_Check_Button *)0;
  34. Fl_Check_Button *wShave=(Fl_Check_Button *)0;
  35. Fl_Check_Button *wBrush=(Fl_Check_Button *)0;
  36. Fl_Choice *wDrink=(Fl_Choice *)0;
  37. Fl_Menu_Item menu_wDrink[] = {
  38. {"coffee", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  39. {"tea", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  40. {"juice", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  41. {0,0,0,0,0,0,0,0,0}
  42. };
  43. Fl_Check_Button *wMilk=(Fl_Check_Button *)0;
  44. Fl_Choice *wBread=(Fl_Choice *)0;
  45. Fl_Menu_Item menu_wBread[] = {
  46. {"wheat", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  47. {"white", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  48. {"rye", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  49. {"sour doh", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
  50. {0,0,0,0,0,0,0,0,0}
  51. };
  52. Fl_Check_Button *wButter=(Fl_Check_Button *)0;
  53. Fl_Int_Input *wEggs=(Fl_Int_Input *)0;
  54. Fl_Value_Slider *wMinutes=(Fl_Value_Slider *)0;
  55. Fl_Input *wPaper=(Fl_Input *)0;
  56. int main(int argc, char **argv) {
  57. { myWindow = new Fl_Double_Window(298, 311, "My Preferences");
  58. myWindow->callback((Fl_Callback*)closeWindowCB);
  59. { Fl_Button* o = new Fl_Button(210, 275, 75, 25, "Cancel");
  60. o->callback((Fl_Callback*)closeWindowCB);
  61. } // Fl_Button* o
  62. { Fl_Button* o = new Fl_Button(125, 275, 75, 25, "OK");
  63. o->callback((Fl_Callback*)saveAndCloseWindowCB);
  64. } // Fl_Button* o
  65. { Fl_Group* o = new Fl_Group(20, 30, 115, 225, "Get Up:");
  66. o->box(FL_ENGRAVED_FRAME);
  67. o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  68. { wAlarm = new Fl_Input(25, 55, 45, 20, "Alarm at:");
  69. wAlarm->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  70. } // Fl_Input* wAlarm
  71. { wAmPm = new Fl_Choice(75, 55, 55, 20);
  72. wAmPm->down_box(FL_BORDER_BOX);
  73. wAmPm->menu(menu_wAmPm);
  74. } // Fl_Choice* wAmPm
  75. { wWear = new Fl_Choice(25, 100, 105, 20, "Wear:");
  76. wWear->down_box(FL_BORDER_BOX);
  77. wWear->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  78. wWear->menu(menu_wWear);
  79. } // Fl_Choice* wWear
  80. { Fl_Group* o = new Fl_Group(35, 120, 98, 60);
  81. { wLeft = new Fl_Round_Button(35, 120, 95, 25, "left side");
  82. wLeft->type(102);
  83. wLeft->down_box(FL_ROUND_DOWN_BOX);
  84. } // Fl_Round_Button* wLeft
  85. { wRight = new Fl_Round_Button(35, 140, 95, 25, "right side");
  86. wRight->type(102);
  87. wRight->down_box(FL_ROUND_DOWN_BOX);
  88. } // Fl_Round_Button* wRight
  89. { new Fl_Box(38, 160, 95, 20, "of the bed");
  90. } // Fl_Box* o
  91. o->end();
  92. } // Fl_Group* o
  93. { wShower = new Fl_Check_Button(25, 180, 105, 25, "shower");
  94. wShower->down_box(FL_DOWN_BOX);
  95. } // Fl_Check_Button* wShower
  96. { wShave = new Fl_Check_Button(25, 200, 105, 25, "shave");
  97. wShave->down_box(FL_DOWN_BOX);
  98. } // Fl_Check_Button* wShave
  99. { wBrush = new Fl_Check_Button(25, 220, 105, 25, "brush teeth");
  100. wBrush->down_box(FL_DOWN_BOX);
  101. } // Fl_Check_Button* wBrush
  102. o->end();
  103. } // Fl_Group* o
  104. { Fl_Group* o = new Fl_Group(160, 30, 115, 225, "Breakfast::");
  105. o->box(FL_ENGRAVED_FRAME);
  106. o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  107. { wDrink = new Fl_Choice(165, 50, 105, 20, "Drink:");
  108. wDrink->down_box(FL_BORDER_BOX);
  109. wDrink->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  110. wDrink->menu(menu_wDrink);
  111. } // Fl_Choice* wDrink
  112. { wMilk = new Fl_Check_Button(170, 70, 100, 25, "with milk");
  113. wMilk->down_box(FL_DOWN_BOX);
  114. } // Fl_Check_Button* wMilk
  115. { wBread = new Fl_Choice(165, 110, 105, 20, "Bread:");
  116. wBread->down_box(FL_BORDER_BOX);
  117. wBread->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  118. wBread->menu(menu_wBread);
  119. } // Fl_Choice* wBread
  120. { wButter = new Fl_Check_Button(170, 130, 100, 25, "with butter");
  121. wButter->down_box(FL_DOWN_BOX);
  122. } // Fl_Check_Button* wButter
  123. { wEggs = new Fl_Int_Input(165, 163, 30, 20, "eggs");
  124. wEggs->type(2);
  125. wEggs->align(Fl_Align(FL_ALIGN_RIGHT));
  126. } // Fl_Int_Input* wEggs
  127. { wMinutes = new Fl_Value_Slider(175, 185, 70, 20, "min.");
  128. wMinutes->type(1);
  129. wMinutes->minimum(2);
  130. wMinutes->maximum(6);
  131. wMinutes->value(3.1);
  132. wMinutes->align(Fl_Align(FL_ALIGN_RIGHT));
  133. } // Fl_Value_Slider* wMinutes
  134. { wPaper = new Fl_Input(165, 225, 105, 20, "Newspaper:");
  135. wPaper->align(Fl_Align(FL_ALIGN_TOP_LEFT));
  136. } // Fl_Input* wPaper
  137. o->end();
  138. } // Fl_Group* o
  139. myWindow->end();
  140. } // Fl_Double_Window* myWindow
  141. readPrefs();
  142. myWindow->show(argc, argv);
  143. return Fl::run();
  144. }
  145. void readPrefs() {
  146. int boolValue;
  147. int intValue;
  148. char buffer[80];
  149. double doubleValue;
  150. Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" );
  151. char path[ FL_PATH_MAX ];
  152. app.getUserdataPath( path, sizeof(path) );
  153. Fl_Preferences bed( app, "Bed" );
  154. bed.get( "alarm", buffer, "8:00", 79 );
  155. wAlarm->value( buffer );
  156. bed.get( "ampm", intValue, 0 );
  157. wAmPm->value( intValue );
  158. bed.get( "wear", intValue, 1 );
  159. wWear->value( intValue );
  160. int side;
  161. bed.get( "side", side, 2 );
  162. if ( side == 1 ) wLeft->value( 1 );
  163. if ( side == 2 ) wRight->value( 1 );
  164. int tasks;
  165. bed.get( "taskFlags", tasks, 0x05 );
  166. if ( tasks & 0x01 ) wShower->value( 1 );
  167. if ( tasks & 0x02 ) wShave->value( 1 );
  168. if ( tasks & 0x04 ) wBrush->value( 1 );
  169. Fl_Preferences eat( app, "Breakfast" );
  170. eat.get( "drink", intValue, 1 );
  171. wDrink->value( intValue );
  172. eat.get( "wMilk", boolValue, 0 );
  173. wMilk->value( boolValue );
  174. eat.get( "bread", intValue, 0 );
  175. wBread->value( intValue );
  176. eat.get( "wButter", boolValue, 1 );
  177. wButter->value( boolValue );
  178. eat.get( "nEggs", intValue, 2 );
  179. sprintf( buffer, "%d", intValue );
  180. wEggs->value( buffer );
  181. eat.get( "minutes", doubleValue, 3.2 );
  182. wMinutes->value( doubleValue );
  183. char *flexBuffer;
  184. eat.get( "newspaper", flexBuffer, "NY Tymes" );
  185. wPaper->value( flexBuffer );
  186. if ( flexBuffer ) free( flexBuffer );
  187. eat.get( "foo", buffer, "bar", 80 );
  188. /** sample code only:
  189. Fl_Preferences prev( app, "PreviousStarts" );
  190. {
  191. int i, n;
  192. prev.get( "n", n, 0 );
  193. for ( i=0; i<n; i++ )
  194. prev.get( Fl_Preferences::Name( i ), flexBuffer, "" );
  195. }
  196. unsigned int hex;
  197. eat.get( "binFoo", (void*)&hex, 0, 0, sizeof( unsigned int ) );
  198. void *data;
  199. eat.get( "binFoo2", data, 0, 0 );
  200. **/
  201. }
  202. void writePrefs() {
  203. Fl_Preferences app( Fl_Preferences::USER, "fltk.org", "test/preferences" );
  204. Fl_Preferences bed( app, "Bed" );
  205. bed.set( "alarm", wAlarm->value() );
  206. bed.set( "ampm", wAmPm->value() );
  207. bed.set( "wear", wWear->value() );
  208. int side = 0;
  209. if ( wLeft->value() ) side = 1;
  210. if ( wRight->value() ) side = 2;
  211. bed.set( "side", side );
  212. int tasks = 0;
  213. if ( wShower->value() ) tasks |= 0x01;
  214. if ( wShave->value() ) tasks |= 0x02;
  215. if ( wBrush->value() ) tasks |= 0x04;
  216. bed.set( "taskFlags", tasks );
  217. Fl_Preferences eat( app, "Breakfast" );
  218. eat.set( "drink", wDrink->value() );
  219. eat.set( "wMilk", wMilk->value() );
  220. eat.set( "bread", wBread->value() );
  221. eat.set( "wButter", wButter->value() );
  222. eat.set( "nEggs", wEggs->value() );
  223. eat.set( "minutes", wMinutes->value() );
  224. eat.set( "newspaper", wPaper->value() );
  225. eat.set( "foo", "bar\nfly\rBackslash: \\ and bell: \007 and delete: \177\n" );
  226. eat.set( Fl_Preferences::Name( 3 ), "Test3" );
  227. /* sample: create a sub-sub-group */
  228. Fl_Preferences eatMore( eat, "More" );
  229. eatMore.set( "more", "stuff" );
  230. /* all the following searches should return 1 */
  231. int sum = 0;
  232. sum += app.groupExists( "Breakfast" ); /* find 'eat' relative to 'app' */
  233. sum += app.groupExists( "Breakfast/More" ); /* find 'eat.eatMore' relative to 'app' */
  234. sum += app.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
  235. sum += eat.groupExists( "More" ); /* find 'eatMore' relative to 'eat' */
  236. sum += eat.groupExists( "./Breakfast/More" ); /* find 'eat.eatMore' relative to Preferences */
  237. sum += eat.groupExists( "." ); /* find myself ('eat') */
  238. sum += eat.groupExists( "./" ); /* find the topmost group ('app') */
  239. if ( sum != 7 )
  240. fl_message( "Assertion failed:\nNot all group entries were found!" );
  241. /* sample code only: */
  242. unsigned int hex = 0x2387efcd;
  243. eat.set( "binFoo", (void*)&hex, sizeof( unsigned int ) );
  244. eat.set( "binFoo2", (void*)&bed, 256 );
  245. }