adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
adamdunkels | 06f897e | 2004-06-06 05:59:20 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 15 | * products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | * |
| 30 | * This file is part of the Contiki desktop environment |
| 31 | * |
adamdunkels | c2bd043 | 2004-09-12 17:52:58 +0000 | [diff] [blame] | 32 | * $Id: about.c,v 1.14 2004/09/12 17:52:58 adamdunkels Exp $ |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 36 | #include <string.h> |
| 37 | |
| 38 | #include "ek.h" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 39 | #include "ctk.h" |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 40 | #include "ctk-draw.h" |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 41 | |
| 42 | #include "petsciiconv.h" |
| 43 | |
| 44 | #include "loader.h" |
| 45 | |
| 46 | static struct ctk_window aboutdialog; |
| 47 | static struct ctk_label aboutlabel1 = |
oliverschmidt | ff2a56f | 2004-07-11 12:20:23 +0000 | [diff] [blame] | 48 | {CTK_LABEL(2, 0, 28, 1, "The Contiki Operating System")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 49 | static struct ctk_label aboutlabel2 = |
adamdunkels | 192ecd3 | 2003-04-11 20:10:28 +0000 | [diff] [blame] | 50 | {CTK_LABEL(3, 2, 28, 1, "A modern, Internet-enabled")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 51 | static struct ctk_label aboutlabel3 = |
adamdunkels | 192ecd3 | 2003-04-11 20:10:28 +0000 | [diff] [blame] | 52 | {CTK_LABEL(6, 3, 20, 1, "operating system and")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 53 | static struct ctk_label aboutlabel4 = |
adamdunkels | 192ecd3 | 2003-04-11 20:10:28 +0000 | [diff] [blame] | 54 | {CTK_LABEL(6, 4, 20, 1, "desktop environment.")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 55 | |
adamdunkels | 6908cef | 2004-08-09 20:04:08 +0000 | [diff] [blame] | 56 | static char abouturl_petscii[] = "http://www.sics.se/~adam/contiki/"; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 57 | static char abouturl_ascii[40]; |
| 58 | static struct ctk_hyperlink abouturl = |
adamdunkels | 6908cef | 2004-08-09 20:04:08 +0000 | [diff] [blame] | 59 | {CTK_HYPERLINK(0, 6, 32, "http://www.sics.se/~adam/contiki/", |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 60 | abouturl_ascii)}; |
| 61 | static struct ctk_button aboutclose = |
adamdunkels | 192ecd3 | 2003-04-11 20:10:28 +0000 | [diff] [blame] | 62 | {CTK_BUTTON(12, 8, 5, "Close")}; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 63 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 64 | EK_EVENTHANDLER(about_eventhandler, ev, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 65 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 66 | EK_PROCESS(p, "About Contiki", EK_PRIO_NORMAL, about_eventhandler, NULL, NULL); |
| 67 | /*static DISPATCHER_SIGHANDLER(about_sighandler, s, data); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 68 | static struct dispatcher_proc p = |
| 69 | {DISPATCHER_PROC("About Contiki", NULL, about_sighandler, NULL)}; |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 70 | static ek_id_t id;*/ |
| 71 | static ek_id_t id = EK_ID_NONE; |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 72 | |
| 73 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 74 | LOADER_INIT_FUNC(about_init, arg) |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 75 | { |
adamdunkels | 8bb5cca | 2003-08-24 22:41:31 +0000 | [diff] [blame] | 76 | arg_free(arg); |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 77 | |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 78 | if(id == EK_ID_NONE) { |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 79 | /* id = dispatcher_start(&p); */ |
| 80 | id = ek_start(&p); |
| 81 | } |
| 82 | /* ctk_desktop_redraw(aboutdialog.desktop);*/ |
| 83 | } |
| 84 | /*-----------------------------------------------------------------------------------*/ |
| 85 | static void |
| 86 | about_quit(void) |
| 87 | { |
| 88 | ctk_dialog_close(); |
| 89 | ek_exit(); |
| 90 | id = EK_ID_NONE; |
adamdunkels | c2bd043 | 2004-09-12 17:52:58 +0000 | [diff] [blame] | 91 | LOADER_UNLOAD(); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 92 | } |
| 93 | /*-----------------------------------------------------------------------------------*/ |
| 94 | /*static DISPATCHER_SIGHANDLER(about_sighandler, s, data)*/ |
| 95 | EK_EVENTHANDLER(about_eventhandler, ev, data) |
| 96 | { |
| 97 | unsigned char width; |
| 98 | EK_EVENTHANDLER_ARGS(ev, data); |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 99 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 100 | if(ev == EK_EVENT_INIT) { |
adamdunkels | e9cc25a | 2003-04-28 23:20:23 +0000 | [diff] [blame] | 101 | width = ctk_desktop_width(NULL); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 102 | |
| 103 | strcpy(abouturl_ascii, abouturl_petscii); |
| 104 | petsciiconv_toascii(abouturl_ascii, sizeof(abouturl_ascii)); |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 105 | |
| 106 | if(width > 34) { |
| 107 | ctk_dialog_new(&aboutdialog, 32, 9); |
| 108 | } else { |
| 109 | ctk_dialog_new(&aboutdialog, width - 2, 9); |
| 110 | } |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 111 | CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1); |
| 112 | CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2); |
| 113 | CTK_WIDGET_ADD(&aboutdialog, &aboutlabel3); |
| 114 | CTK_WIDGET_ADD(&aboutdialog, &aboutlabel4); |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 115 | if(width > 34) { |
| 116 | CTK_WIDGET_ADD(&aboutdialog, &abouturl); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 117 | CTK_WIDGET_SET_FLAG(&abouturl, CTK_WIDGET_FLAG_MONOSPACE); |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 118 | } else { |
| 119 | CTK_WIDGET_SET_XPOS(&aboutlabel1, 0); |
| 120 | CTK_WIDGET_SET_XPOS(&aboutlabel2, 0); |
| 121 | CTK_WIDGET_SET_XPOS(&aboutlabel3, 0); |
| 122 | CTK_WIDGET_SET_XPOS(&aboutlabel4, 0); |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 123 | |
adamdunkels | 0855d56 | 2003-04-24 17:21:59 +0000 | [diff] [blame] | 124 | CTK_WIDGET_SET_XPOS(&aboutclose, 0); |
| 125 | } |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 126 | CTK_WIDGET_ADD(&aboutdialog, &aboutclose); |
| 127 | CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose); |
| 128 | |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 129 | /* dispatcher_listen(ctk_signal_button_activate); |
| 130 | dispatcher_listen(ctk_signal_hyperlink_activate);*/ |
| 131 | ctk_dialog_open(&aboutdialog); |
| 132 | |
| 133 | } else if(ev == EK_EVENT_REQUEST_EXIT) { |
| 134 | about_quit(); |
| 135 | } else if(ev == ctk_signal_button_activate) { |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 136 | if(data == (ek_data_t)&aboutclose) { |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 137 | about_quit(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 138 | } |
adamdunkels | f2f8cb2 | 2004-07-04 11:35:07 +0000 | [diff] [blame] | 139 | } else if(ev == ctk_signal_hyperlink_activate) { |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 140 | if((struct ctk_widget *)data == (struct ctk_widget *)&abouturl) { |
adamdunkels | 0137b44 | 2003-04-08 23:27:33 +0000 | [diff] [blame] | 141 | about_quit(); |
adamdunkels | 4292c86 | 2003-04-08 17:56:43 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | /*-----------------------------------------------------------------------------------*/ |