diff --git a/apps/program-handler/program-handler.c b/apps/program-handler/program-handler.c index 6fa48ffad..2f753169f 100644 --- a/apps/program-handler/program-handler.c +++ b/apps/program-handler/program-handler.c @@ -43,11 +43,12 @@ * * This file is part of the Contiki desktop OS * - * $Id: program-handler.c,v 1.2 2006/08/15 00:11:45 oliverschmidt Exp $ + * $Id: program-handler.c,v 1.3 2006/08/30 22:40:58 oliverschmidt Exp $ * */ #include +#include #include "contiki.h" #include "ctk/ctk.h" @@ -68,6 +69,27 @@ static struct ctk_menu contikimenu = {NULL, "Contiki", 7, 0, 0}; static struct dsc *contikidsc[MAX_NUMDSCS]; static unsigned char contikidsclast = 0; +#ifndef PROGRAM_HANDLER_CONF_QUIT_MENU +#define QUIT_MENU 0 +#else /* PROGRAM_HANDLER_CONF_QUIT_MENU */ +#define QUIT_MENU PROGRAM_HANDLER_CONF_QUIT_MENU +#endif /* PROGRAM_HANDLER_CONF_QUIT_MENU */ + +#if QUIT_MENU + +static unsigned char quitmenuitem; + +/* "Quit" dialog */ +static struct ctk_window quitdialog; +static struct ctk_label quitdialoglabel = + {CTK_LABEL(2, 1, 20, 1, "Really quit Contiki?")}; +static struct ctk_button quityesbutton = + {CTK_BUTTON(4, 3, 3, "Yes")}; +static struct ctk_button quitnobutton = + {CTK_BUTTON(16, 3, 2, "No")}; + +#endif /* QUIT_MENU */ + #if WITH_LOADER_ARCH /* "Run..." window */ static struct ctk_window runwindow; @@ -284,6 +306,9 @@ PROCESS_THREAD(program_handler_process, ev, data) make_windows(); #endif /* WITH_LOADER_ARCH */ +#if QUIT_MENU + quitmenuitem = ctk_menuitem_add(&contikimenu, "Quit"); +#endif /* QUIT_MENU */ displayname = NULL; @@ -302,6 +327,14 @@ PROCESS_THREAD(program_handler_process, ev, data) ctk_dialog_close(); } #endif /* WITH_LOADER_ARCH */ +#if QUIT_MENU + if(data == (process_data_t)&quityesbutton) { + ctk_draw_init(); + exit(EXIT_SUCCESS); + } else if(data == (process_data_t)&quitnobutton) { + ctk_dialog_close(); + } +#endif /* QUIT_MENU */ dscp = &contikidsc[0]; for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) { if(*dscp != NULL && @@ -330,6 +363,16 @@ PROCESS_THREAD(program_handler_process, ev, data) NULL); } #endif /* WITH_LOADER_ARCH */ +#if QUIT_MENU + if(contikimenu.active == quitmenuitem) { + ctk_dialog_new(&quitdialog, 24, 5); + CTK_WIDGET_ADD(&quitdialog, &quitdialoglabel); + CTK_WIDGET_ADD(&quitdialog, &quityesbutton); + CTK_WIDGET_ADD(&quitdialog, &quitnobutton); + CTK_WIDGET_FOCUS(&quitdialog, &quitnobutton); + ctk_dialog_open(&quitdialog); + } +#endif /* QUIT_MENU */ } #if CTK_CONF_SCREENSAVER } else if(ev == ctk_signal_screensaver_start) {