Added quit menu option.

This commit is contained in:
oliverschmidt 2006-08-30 22:40:58 +00:00
parent fba087810d
commit b55b0e0367

View file

@ -43,11 +43,12 @@
* *
* This file is part of the Contiki desktop OS * 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 <string.h> #include <string.h>
#include <stdlib.h>
#include "contiki.h" #include "contiki.h"
#include "ctk/ctk.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 struct dsc *contikidsc[MAX_NUMDSCS];
static unsigned char contikidsclast = 0; 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 #if WITH_LOADER_ARCH
/* "Run..." window */ /* "Run..." window */
static struct ctk_window runwindow; static struct ctk_window runwindow;
@ -284,6 +306,9 @@ PROCESS_THREAD(program_handler_process, ev, data)
make_windows(); make_windows();
#endif /* WITH_LOADER_ARCH */ #endif /* WITH_LOADER_ARCH */
#if QUIT_MENU
quitmenuitem = ctk_menuitem_add(&contikimenu, "Quit");
#endif /* QUIT_MENU */
displayname = NULL; displayname = NULL;
@ -302,6 +327,14 @@ PROCESS_THREAD(program_handler_process, ev, data)
ctk_dialog_close(); ctk_dialog_close();
} }
#endif /* WITH_LOADER_ARCH */ #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]; dscp = &contikidsc[0];
for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) { for(i = 0; i < CTK_CONF_MAXMENUITEMS; ++i) {
if(*dscp != NULL && if(*dscp != NULL &&
@ -330,6 +363,16 @@ PROCESS_THREAD(program_handler_process, ev, data)
NULL); NULL);
} }
#endif /* WITH_LOADER_ARCH */ #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 #if CTK_CONF_SCREENSAVER
} else if(ev == ctk_signal_screensaver_start) { } else if(ev == ctk_signal_screensaver_start) {