Add platform file for Ipod 1G / 2G. Now only the front image is missing for building...
[Rockbox.git] / apps / gui / yesno.c
blob4f874df325ca41a93dc37e55e83a8719f58e7e95
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id $
10 * Copyright (C) 2005 by Kevin Ferrare
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "yesno.h"
21 #include "system.h"
22 #include "kernel.h"
23 #include "misc.h"
24 #include "lang.h"
25 #include "action.h"
28 * Initializes the yesno asker
29 * - yn : the yesno structure
30 * - main_message : the question the user has to answer
31 * - yes_message : message displayed if answer is 'yes'
32 * - no_message : message displayed if answer is 'no'
34 static void gui_yesno_init(struct gui_yesno * yn,
35 struct text_message * main_message,
36 struct text_message * yes_message,
37 struct text_message * no_message)
39 yn->main_message=main_message;
40 yn->result_message[YESNO_YES]=yes_message;
41 yn->result_message[YESNO_NO]=no_message;
42 yn->display=0;
46 * Attach the yesno to a screen
47 * - yn : the yesno structure
48 * - display : the screen to attach
50 static void gui_yesno_set_display(struct gui_yesno * yn,
51 struct screen * display)
53 yn->display=display;
57 * Draws the yesno
58 * - yn : the yesno structure
60 static void gui_yesno_draw(struct gui_yesno * yn)
62 struct screen * display=yn->display;
63 int nb_lines, line_shift=0;
65 gui_textarea_clear(display);
66 nb_lines=yn->main_message->nb_lines;
68 if(nb_lines+3<display->nb_lines)
69 line_shift=1;
70 nb_lines=gui_textarea_put_message(display, yn->main_message, line_shift);
72 /* Space remaining for yes / no text ? */
73 if(nb_lines+line_shift+2<=display->nb_lines)
75 if(nb_lines+line_shift+3<=display->nb_lines)
76 nb_lines++;
77 display->puts(0, nb_lines+line_shift, str(LANG_CONFIRM_WITH_PLAY_RECORDER));
78 display->puts(0, nb_lines+line_shift+1, str(LANG_CANCEL_WITH_ANY_RECORDER));
80 gui_textarea_update(display);
84 * Draws the yesno result
85 * - yn : the yesno structure
86 * - result : the result tha must be displayed :
87 * YESNO_NO if no
88 * YESNO_YES if yes
90 static bool gui_yesno_draw_result(struct gui_yesno * yn, enum yesno_res result)
92 struct text_message * message=yn->result_message[result];
93 if(message==NULL)
94 return false;
95 gui_textarea_put_message(yn->display, message, 0);
96 return(true);
98 #include "debug.h"
99 enum yesno_res gui_syncyesno_run(struct text_message * main_message,
100 struct text_message * yes_message,
101 struct text_message * no_message)
103 int i;
104 unsigned button;
105 int result=-1;
106 bool result_displayed;
107 struct gui_yesno yn[NB_SCREENS];
108 FOR_NB_SCREENS(i)
110 gui_yesno_init(&(yn[i]), main_message, yes_message, no_message);
111 gui_yesno_set_display(&(yn[i]), &(screens[i]));
112 gui_yesno_draw(&(yn[i]));
114 while (result==-1)
116 button = get_action(CONTEXT_YESNOSCREEN,TIMEOUT_BLOCK);
117 switch (button)
119 case ACTION_YESNO_ACCEPT:
120 result=YESNO_YES;
121 break;
122 case ACTION_NONE:
123 case SYS_CHARGER_DISCONNECTED:
124 /* ignore some SYS events that can happen */
125 continue;
126 default:
127 if(default_event_handler(button) == SYS_USB_CONNECTED)
128 return(YESNO_USB);
129 result = YESNO_NO;
132 FOR_NB_SCREENS(i)
133 result_displayed=gui_yesno_draw_result(&(yn[i]), result);
134 if(result_displayed)
135 sleep(HZ);
136 return(result);