4 TimeEntry::TimeEntry(BC_WindowBase *gui,
14 this->output_day = output_day;
15 this->output_time = output_time;
16 this->time_format = time_format;
19 TimeEntry::~TimeEntry()
29 char* TimeEntry::day_table[] =
31 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "*"
34 int TimeEntry::day_to_int(char *day)
36 for(int i = 0; i < TOTAL_DAYS; i++)
37 if(!strcasecmp(day, day_table[i])) return i;
42 void TimeEntry::time_to_hours(char *result, double time)
44 int hour = (int)(time / 3600);
45 sprintf(result, "%d", hour);
48 void TimeEntry::time_to_minutes(char *result, double time)
50 int hour = (int)(time / 3600);
51 int minute = (int)(time / 60 - hour * 60);
52 sprintf(result, "%d", minute);
55 void TimeEntry::time_to_seconds(char *result, double time)
57 int hour = (int)(time / 3600);
58 int minute = (int)(time / 60 - hour * 60);
59 float second = (float)time - (int64_t)hour * 3600 - (int64_t)minute * 60;
60 sprintf(result, "%.3f", second);
63 #define DEFAULT_TIMEW 200
65 void TimeEntry::create_objects()
69 char string[BCTEXTLEN];
70 int time_w = DEFAULT_TIMEW;
76 gui->add_subwindow(day_text = new DayText(this,
82 day_table[*output_day]));
83 x += day_text->get_w();
84 time_w -= day_text->get_w();
85 gui->add_subwindow(day_tumbler = new DayTumbler(this,
89 x += day_tumbler->get_w();
90 time_w -= day_tumbler->get_w();
93 gui->add_subwindow(time_text = new TimeTextBox(this,
100 time_text->set_separators(Units::format_to_separators(time_format));
103 int TimeEntry::get_h()
105 return time_text->get_h();
108 int TimeEntry::get_w()
111 if(day_text) w += day_text->get_w();
112 if(day_tumbler) w += day_tumbler->get_w();
113 w += time_text->get_w();
117 void TimeEntry::reposition_window(int x, int y)
119 int time_w = DEFAULT_TIMEW;
126 day_text->reposition_window(x, y);
127 x += day_text->get_w();
128 time_w -= day_text->get_w();
129 day_tumbler->reposition_window(x, y);
130 x += day_tumbler->get_w();
131 time_w -= day_tumbler->get_w();
135 time_text->reposition_window(x, y, time_w);
138 void TimeEntry::update(int *day, double *time)
140 char string[BCTEXTLEN];
141 this->output_day = day;
142 this->output_time = time;
146 day_text->update(day_table[*day]);
150 time_text->update(Units::totext(string,
155 int TimeEntry::handle_event()
160 DayText::DayText(TimeEntry *timeentry,
167 : BC_TextBox(x, y, w, 1, text)
169 this->timeentry = timeentry;
171 this->table_items = table_items;
174 int DayText::handle_event()
176 *timeentry->output_day = TimeEntry::day_to_int(get_text());
177 timeentry->handle_event();
182 DayTumbler::DayTumbler(TimeEntry *timeentry,
188 this->timeentry = timeentry;
193 int DayTumbler::handle_up_event()
195 *timeentry->output_day += 1;
196 if(*timeentry->output_day >= text->table_items)
197 *timeentry->output_day = 0;
198 text->update(text->table[*timeentry->output_day]);
199 timeentry->handle_event();
203 int DayTumbler::handle_down_event()
205 *timeentry->output_day -= 1;
206 if(*timeentry->output_day < 0)
207 *timeentry->output_day = text->table_items - 1;
208 text->update(text->table[*timeentry->output_day]);
209 timeentry->handle_event();
215 TimeTextBox::TimeTextBox(TimeEntry *timeentry,
226 this->timeentry = timeentry;
229 int TimeTextBox::handle_event()
231 *timeentry->output_time = Units::text_to_seconds(get_text(),
233 timeentry->time_format,
236 timeentry->handle_event();