adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2003, 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. |
| 14 | * 3. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the Contiki desktop environment |
| 34 | * |
| 35 | * $Id: weblinks.c,v 1.1 2003/07/04 10:54:51 adamdunkels Exp $ |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | |
| 40 | #include "ctk.h" |
| 41 | #include "ctk-draw.h" |
| 42 | #include "dispatcher.h" |
| 43 | #include "loader.h" |
| 44 | |
| 45 | #include "program-handler.h" |
| 46 | |
| 47 | #include "www.h" |
| 48 | |
| 49 | #include <string.h> |
| 50 | |
| 51 | #define WIDTH 45 |
| 52 | #define HEIGHT 16 |
| 53 | |
| 54 | #define LINK(name, descr, url) \ |
| 55 | {CTK_HYPERLINK(1, 0, sizeof(name) - 1, name, url)}, \ |
| 56 | {CTK_LABEL(1, 20, sizeof(descr) - 1, 1, descr)} |
| 57 | struct link { |
| 58 | struct ctk_hyperlink hyperlink; |
| 59 | struct ctk_label description; |
| 60 | }; |
| 61 | |
| 62 | static struct link links[] = |
| 63 | { |
| 64 | {LINK("Contiki", |
| 65 | "The Contiki web site", |
| 66 | "http://dunkels.com/adam/contiki/index-text.html")}, |
| 67 | {LINK("Contiki AVR", |
| 68 | "The server software", |
| 69 | "http://dunkels.com/adam/contiki/ports/avr-text.html")}, |
| 70 | {LINK("Ethernut", |
| 71 | "The server hardware", |
| 72 | "http://www.ethernut.de/en/")}, |
| 73 | {LINK("cc65", |
| 74 | "The 6502 C cross compiler", |
| 75 | "http://www.cc65.org/")}, |
| 76 | {LINK("Google", |
| 77 | "Google", |
| 78 | "http://www.google.com/")}, |
| 79 | {LINK("OSNews", |
| 80 | "Exploring the future of computing", |
| 81 | "http://www.osnews.com/")}, |
| 82 | {LINK("Slashdot", |
| 83 | "News for nerds, stuff that matters", |
| 84 | "http://slashdot.org/")}, |
| 85 | }; |
| 86 | |
| 87 | #define NUMLINKS 7 |
| 88 | |
| 89 | static struct ctk_window window; |
| 90 | static struct ctk_label hintslabel1 = |
| 91 | {CTK_LABEL(1, 1, 39, 1, "Open the web browser in the background,")}; |
| 92 | static struct ctk_label hintslabel2 = |
| 93 | {CTK_LABEL(1, 2, 24, 1, "then click on the links.")}; |
| 94 | |
| 95 | |
| 96 | static DISPATCHER_SIGHANDLER(weblinks_sighandler, s, data); |
| 97 | static struct dispatcher_proc p = |
| 98 | {DISPATCHER_PROC("Web links", NULL, weblinks_sighandler, NULL)}; |
| 99 | static ek_id_t id; |
| 100 | |
| 101 | /*-----------------------------------------------------------------------------------*/ |
| 102 | LOADER_INIT_FUNC(weblinks_init) |
| 103 | { |
| 104 | unsigned char y, i; |
| 105 | |
| 106 | if(id == EK_ID_NONE) { |
| 107 | id = dispatcher_start(&p); |
| 108 | |
| 109 | ctk_window_new(&window, WIDTH, HEIGHT, "Web links"); |
| 110 | |
| 111 | CTK_WIDGET_ADD(&window, &hintslabel1); |
| 112 | CTK_WIDGET_ADD(&window, &hintslabel2); |
| 113 | |
| 114 | y = 4; |
| 115 | for(i = 0; i < NUMLINKS; ++i) { |
| 116 | |
| 117 | CTK_WIDGET_SET_XPOS(&(links[i].hyperlink), 1); |
| 118 | CTK_WIDGET_SET_YPOS(&(links[i].hyperlink), y); |
| 119 | CTK_WIDGET_ADD(&window, &(links[i].hyperlink)); |
| 120 | |
| 121 | CTK_WIDGET_SET_XPOS(&(links[i].description), |
| 122 | strlen(links[i].hyperlink.text) + 2); |
| 123 | CTK_WIDGET_SET_YPOS(&(links[i].description), y); |
| 124 | CTK_WIDGET_ADD(&window, &(links[i].description)); |
| 125 | |
| 126 | ++y; |
| 127 | |
| 128 | } |
| 129 | |
| 130 | dispatcher_listen(ctk_signal_window_close); |
| 131 | } |
| 132 | ctk_window_open(&window); |
| 133 | } |
| 134 | /*-----------------------------------------------------------------------------------*/ |
| 135 | static void |
| 136 | quit(void) |
| 137 | { |
| 138 | ctk_window_close(&window); |
| 139 | dispatcher_exit(&p); |
| 140 | id = EK_ID_NONE; |
| 141 | LOADER_UNLOAD(); |
| 142 | } |
| 143 | /*-----------------------------------------------------------------------------------*/ |
| 144 | static |
| 145 | DISPATCHER_SIGHANDLER(weblinks_sighandler, s, data) |
| 146 | { |
| 147 | unsigned char i; |
| 148 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
| 149 | |
| 150 | if(s == ctk_signal_window_close && |
| 151 | data == (ek_data_t)&window) { |
| 152 | quit(); |
| 153 | } |
| 154 | } |
| 155 | /*-----------------------------------------------------------------------------------*/ |