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. |
adamdunkels | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +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 | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 32 | * $Id: weblinks.c,v 1.3 2004/07/04 20:17:38 adamdunkels Exp $ |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
| 36 | |
| 37 | #include "ctk.h" |
| 38 | #include "ctk-draw.h" |
adamdunkels | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 39 | #include "ek.h" |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 40 | #include "loader.h" |
| 41 | |
| 42 | #include "program-handler.h" |
| 43 | |
| 44 | #include "www.h" |
| 45 | |
| 46 | #include <string.h> |
| 47 | |
| 48 | #define WIDTH 45 |
| 49 | #define HEIGHT 16 |
| 50 | |
| 51 | #define LINK(name, descr, url) \ |
| 52 | {CTK_HYPERLINK(1, 0, sizeof(name) - 1, name, url)}, \ |
| 53 | {CTK_LABEL(1, 20, sizeof(descr) - 1, 1, descr)} |
| 54 | struct link { |
| 55 | struct ctk_hyperlink hyperlink; |
| 56 | struct ctk_label description; |
| 57 | }; |
| 58 | |
| 59 | static struct link links[] = |
| 60 | { |
| 61 | {LINK("Contiki", |
| 62 | "The Contiki web site", |
| 63 | "http://dunkels.com/adam/contiki/index-text.html")}, |
| 64 | {LINK("Contiki AVR", |
| 65 | "The server software", |
| 66 | "http://dunkels.com/adam/contiki/ports/avr-text.html")}, |
| 67 | {LINK("Ethernut", |
| 68 | "The server hardware", |
| 69 | "http://www.ethernut.de/en/")}, |
| 70 | {LINK("cc65", |
| 71 | "The 6502 C cross compiler", |
| 72 | "http://www.cc65.org/")}, |
| 73 | {LINK("Google", |
| 74 | "Google", |
| 75 | "http://www.google.com/")}, |
| 76 | {LINK("OSNews", |
| 77 | "Exploring the future of computing", |
| 78 | "http://www.osnews.com/")}, |
| 79 | {LINK("Slashdot", |
| 80 | "News for nerds, stuff that matters", |
| 81 | "http://slashdot.org/")}, |
| 82 | }; |
| 83 | |
| 84 | #define NUMLINKS 7 |
| 85 | |
| 86 | static struct ctk_window window; |
| 87 | static struct ctk_label hintslabel1 = |
| 88 | {CTK_LABEL(1, 1, 39, 1, "Open the web browser in the background,")}; |
| 89 | static struct ctk_label hintslabel2 = |
| 90 | {CTK_LABEL(1, 2, 24, 1, "then click on the links.")}; |
| 91 | |
| 92 | |
adamdunkels | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 93 | /*static DISPATCHER_SIGHANDLER(weblinks_sighandler, s, data); |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 94 | static struct dispatcher_proc p = |
| 95 | {DISPATCHER_PROC("Web links", NULL, weblinks_sighandler, NULL)}; |
adamdunkels | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 96 | static ek_id_t id;*/ |
| 97 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 98 | EK_PROCESS(p, "Web links", EK_PRIO_NORMAL, |
| 99 | eventhandler, NULL, NULL); |
| 100 | static ek_id_t id = EK_ID_NONE; |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 101 | |
| 102 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | eb4ecc6 | 2003-08-25 12:42:41 +0000 | [diff] [blame] | 103 | LOADER_INIT_FUNC(weblinks_init, arg) |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 104 | { |
adamdunkels | eb4ecc6 | 2003-08-25 12:42:41 +0000 | [diff] [blame] | 105 | arg_free(arg); |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 106 | |
| 107 | if(id == EK_ID_NONE) { |
adamdunkels | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 108 | id = ek_start(&p); |
| 109 | } else { |
| 110 | ctk_window_open(&window); |
| 111 | } |
| 112 | } |
| 113 | /*-----------------------------------------------------------------------------------*/ |
| 114 | static void |
| 115 | quit(void) |
| 116 | { |
| 117 | ctk_window_close(&window); |
| 118 | ek_exit(); |
| 119 | id = EK_ID_NONE; |
| 120 | LOADER_UNLOAD(); |
| 121 | } |
| 122 | /*-----------------------------------------------------------------------------------*/ |
| 123 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 124 | { |
| 125 | unsigned char y, i; |
| 126 | EK_EVENTHANDLER_ARGS(ev, data); |
| 127 | |
| 128 | if(ev == EK_EVENT_INIT) { |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 129 | |
| 130 | ctk_window_new(&window, WIDTH, HEIGHT, "Web links"); |
| 131 | |
| 132 | CTK_WIDGET_ADD(&window, &hintslabel1); |
| 133 | CTK_WIDGET_ADD(&window, &hintslabel2); |
| 134 | |
| 135 | y = 4; |
| 136 | for(i = 0; i < NUMLINKS; ++i) { |
| 137 | |
| 138 | CTK_WIDGET_SET_XPOS(&(links[i].hyperlink), 1); |
| 139 | CTK_WIDGET_SET_YPOS(&(links[i].hyperlink), y); |
| 140 | CTK_WIDGET_ADD(&window, &(links[i].hyperlink)); |
| 141 | |
| 142 | CTK_WIDGET_SET_XPOS(&(links[i].description), |
| 143 | strlen(links[i].hyperlink.text) + 2); |
| 144 | CTK_WIDGET_SET_YPOS(&(links[i].description), y); |
| 145 | CTK_WIDGET_ADD(&window, &(links[i].description)); |
| 146 | |
| 147 | ++y; |
| 148 | |
| 149 | } |
| 150 | |
adamdunkels | d311bf1 | 2004-07-04 20:17:37 +0000 | [diff] [blame] | 151 | ctk_window_open(&window); |
| 152 | |
| 153 | } else if(ev == EK_EVENT_REQUEST_EXIT || |
| 154 | (ev == ctk_signal_window_close && |
| 155 | data == (ek_data_t)&window)) { |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 156 | quit(); |
| 157 | } |
| 158 | } |
| 159 | /*-----------------------------------------------------------------------------------*/ |