# data file for the FLTK User Interface Designer (FLUID)
version 2,0030 
header_name {.h} 
code_name {.cpp} 
gridx 5 
gridy 5 
snap 3
decl {\#include <efltk/Fl_Config.h>} {public
} 

decl {\#include <stdio.h>} {public
} 

decl {\#include <stdlib.h>} {} 

decl {\#include <efltk/filename.h>} {} 

decl {void readPrefs();} {public
} 

decl {void writePrefs();} {public
} 

Function {closeWindowCB( Fl_Widget*, void* )} {open private return_type void
} {
  code {delete myWindow;} {}
} 

Function {saveAndCloseWindowCB( Fl_Widget*, void* )} {open private return_type void
} {
  code {writePrefs();
  delete myWindow;} {}
} 

Function {} {open return_type int
} {
  code {Fl::args(argc, argv);} {}
  Fl_Window myWindow {
    label {My Preferences}
    callback closeWindowCB open
    xywh {39 237 298 311} visible
  } {
    Fl_Button {} {
      label Cancel
      callback closeWindowCB
      xywh {210 275 75 25}
    }
    Fl_Button {} {
      label OK
      callback saveAndCloseWindowCB
      xywh {125 275 75 25}
    }
    Fl_Group {} {
      label {Get Up:} open
      xywh {20 30 115 225} align 5 box BORDER_FRAME color 37
    } {
      Fl_Input wAlarm {
        label {Alarm at:}
        xywh {5 25 45 20} align 5
      }
      Fl_Choice wAmPm {open
        xywh {55 25 55 20}
      } {
        Fl_Item {} {
          label {a.m.}
          }
        Fl_Item {} {
          label {p.m.}
          }
      }
      Fl_Choice wWear {
        label {Wear:} open
        xywh {5 70 105 20} align 5
      } {
        Fl_Item {} {
          label shoes
          }
        Fl_Item {} {
          label sandals
          }
        Fl_Item {} {
          label {flip flops}
          }
        Fl_Item {} {
          label {bare foot}
          }
      }
      Fl_Check_Button wShower {
        label shower
        xywh {5 155 105 20}
      }
      Fl_Check_Button wShave {
        label shave
        xywh {5 175 105 20}
      }
      Fl_Check_Button wBrush {
        label {brush teeth}
        xywh {5 195 105 20}
      }
      Fl_Group {} {open
        xywh {5 95 105 60}
      } {
        Fl_Round_Button wLeft {
          label {left side}
          xywh {0 0 105 20} type RADIO
        }
        Fl_Round_Button wRight {
          label {right side}
          xywh {0 20 105 20} type RADIO
        }
        Fl_Box {} {
          label {of the bed}
          xywh {20 40 80 15} align 20
        }
      }
    }
    Fl_Group {} {
      label {Breakfast::} open
      xywh {160 30 115 225} align 5 box BORDER_FRAME color 37
    } {
      Fl_Choice wDrink {
        label {Drink:} open
        xywh {5 20 105 20} align 5
      } {
        Fl_Item {} {
          label coffee
          }
        Fl_Item {} {
          label tea
          }
        Fl_Item {} {
          label juice
          }
      }
      Fl_Check_Button wMilk {
        label {with milk}
        xywh {10 40 100 25}
      }
      Fl_Choice wBread {
        label {Bread:} open
        xywh {5 80 105 20} align 5
      } {
        Fl_Item {} {
          label wheat
          }
        Fl_Item {} {
          label white
          }
        Fl_Item {} {
          label rye
          }
        Fl_Item {} {
          label {sour doh}
          }
      }
      Fl_Check_Button wButter {
        label {with butter}
        xywh {10 100 100 25}
      }
      Fl_Input wEggs {
        label eggs
        xywh {5 133 30 20} type Int align 8
      }
      Fl_Value_Slider wMinutes {
        label {min.} selected
        xywh {5 155 80 20} type HORIZONTAL align 8 maximum 2 value 1
      }
      Fl_Input wPaper {
        label {Newspaper:}
        xywh {5 195 105 20} align 5
      }
    }
  }
  code {readPrefs();} {}
} 

Function {readPrefs()} {open return_type void
} {
  code {int boolValue;
int intValue;
char buffer[80];
double doubleValue;

Fl_Config app( "efltk", "pref_test", Fl_Config::USER );

    app.set_section( "Bed" );
    app.read("alarm", buffer, "8:00", sizeof(buffer) );
    wAlarm->value( buffer );

    app.read("ampm", intValue, 0 );
    wAmPm->value( intValue );

    app.read( "wear", intValue, 1 );
    wWear->value( intValue );

    int side;
    app.read( "side", side, 2 );
    if ( side == 1 ) wLeft->value( 1 );
    if ( side == 2 ) wRight->value( 1 );

    int tasks;
    app.read( "taskFlags", tasks, 0x05 );
    if ( tasks & 0x01 ) wShower->value( 1 );
    if ( tasks & 0x02 ) wShave->value( 1 );
    if ( tasks & 0x04 ) wBrush->value( 1 );

  app.set_section( "Breakfast" );

    app.read( "drink", intValue,1 );
    wDrink->value( intValue );

    app.read( "wMilk", boolValue, 0 );
    wMilk->value( boolValue );

    app.read( "bread", intValue, 0 );
    wBread->value( intValue );

    app.read( "wButter", boolValue,1 );
    wButter->value( boolValue );

    app.read( "nEggs", intValue, 2 );
    char tmp[16]; sprintf( tmp, "%d", intValue );
    wEggs->value( tmp );

    app.read( "minutes", doubleValue, 3.2 );
    wMinutes->value( doubleValue );

    char *flexBuffer=0;
    app.read( "newspaper", flexBuffer, "NY Tymes" );
    wPaper->value( flexBuffer );
    if ( !flexBuffer && !app.error() ) delete []flexBuffer;} {}
} 

Function {writePrefs()} {open return_type void
} {
  code {Fl_Config app("efltk", "pref_test", Fl_Config::USER);

    app.set_section("Bed");
    app.write( "alarm", wAlarm->value() );
    app.write( "ampm", wAmPm->value() );
    app.write( "wear", wWear->value() );

    int side = 0;
    if ( wLeft->value() ) side = 1;
    if ( wRight->value() ) side = 2;
    app.write( "side", side );

    int tasks = 0;
    if ( wShower->value() ) tasks |= 0x01;
    if ( wShave->value() ) tasks |= 0x02;
    if ( wBrush->value() ) tasks |= 0x04;
    app.write( "taskFlags", tasks );

    app.set_section("Breakfast");
    app.write( "drink", wDrink->value() );
    app.write( "wMilk", wMilk->value() );
    app.write( "bread", wBread->value() );
    app.write( "wButter", wButter->value() );

    app.write( "nEggs", wEggs->value() );
    app.write( "minutes", (double)wMinutes->value() );

    app.write( "newspaper", wPaper->value() );} {}
} 
