blob: d588295a7ec381ddb9cb7a4fee208b3b29ab9c41 [file] [log] [blame]
adamdunkels3023dee2003-07-04 10:54:51 +00001/*
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.
adamdunkelsd311bf12004-07-04 20:17:37 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkels3023dee2003-07-04 10:54:51 +000015 * 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 *
adamdunkelsd311bf12004-07-04 20:17:37 +000032 * $Id: weblinks.c,v 1.3 2004/07/04 20:17:38 adamdunkels Exp $
adamdunkels3023dee2003-07-04 10:54:51 +000033 *
34 */
35
36
37#include "ctk.h"
38#include "ctk-draw.h"
adamdunkelsd311bf12004-07-04 20:17:37 +000039#include "ek.h"
adamdunkels3023dee2003-07-04 10:54:51 +000040#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)}
54struct link {
55 struct ctk_hyperlink hyperlink;
56 struct ctk_label description;
57};
58
59static 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
86static struct ctk_window window;
87static struct ctk_label hintslabel1 =
88 {CTK_LABEL(1, 1, 39, 1, "Open the web browser in the background,")};
89static struct ctk_label hintslabel2 =
90 {CTK_LABEL(1, 2, 24, 1, "then click on the links.")};
91
92
adamdunkelsd311bf12004-07-04 20:17:37 +000093/*static DISPATCHER_SIGHANDLER(weblinks_sighandler, s, data);
adamdunkels3023dee2003-07-04 10:54:51 +000094static struct dispatcher_proc p =
95 {DISPATCHER_PROC("Web links", NULL, weblinks_sighandler, NULL)};
adamdunkelsd311bf12004-07-04 20:17:37 +000096 static ek_id_t id;*/
97EK_EVENTHANDLER(eventhandler, ev, data);
98EK_PROCESS(p, "Web links", EK_PRIO_NORMAL,
99 eventhandler, NULL, NULL);
100static ek_id_t id = EK_ID_NONE;
adamdunkels3023dee2003-07-04 10:54:51 +0000101
102/*-----------------------------------------------------------------------------------*/
adamdunkelseb4ecc62003-08-25 12:42:41 +0000103LOADER_INIT_FUNC(weblinks_init, arg)
adamdunkels3023dee2003-07-04 10:54:51 +0000104{
adamdunkelseb4ecc62003-08-25 12:42:41 +0000105 arg_free(arg);
adamdunkels3023dee2003-07-04 10:54:51 +0000106
107 if(id == EK_ID_NONE) {
adamdunkelsd311bf12004-07-04 20:17:37 +0000108 id = ek_start(&p);
109 } else {
110 ctk_window_open(&window);
111 }
112}
113/*-----------------------------------------------------------------------------------*/
114static void
115quit(void)
116{
117 ctk_window_close(&window);
118 ek_exit();
119 id = EK_ID_NONE;
120 LOADER_UNLOAD();
121}
122/*-----------------------------------------------------------------------------------*/
123EK_EVENTHANDLER(eventhandler, ev, data)
124{
125 unsigned char y, i;
126 EK_EVENTHANDLER_ARGS(ev, data);
127
128 if(ev == EK_EVENT_INIT) {
adamdunkels3023dee2003-07-04 10:54:51 +0000129
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
adamdunkelsd311bf12004-07-04 20:17:37 +0000151 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)) {
adamdunkels3023dee2003-07-04 10:54:51 +0000156 quit();
157 }
158}
159/*-----------------------------------------------------------------------------------*/