Contiki 3.x
about.c
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.
14  * 3. The name of the author may not be used to endorse or promote
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  *
32  *
33  */
34 
35 #include <string.h>
36 
37 #include "contiki.h"
38 #include "ctk/ctk.h"
39 #include "lib/petsciiconv.h"
40 
41 static struct ctk_window aboutdialog;
42 static struct ctk_label aboutlabel1 =
43  {CTK_LABEL(2, 0, 28, 1, "The Contiki Operating System")};
44 static struct ctk_label aboutlabel2 =
45  {CTK_LABEL(3, 2, 28, 1, "A modern, Internet-enabled")};
46 static struct ctk_label aboutlabel3 =
47  {CTK_LABEL(6, 3, 20, 1, "operating system and")};
48 static struct ctk_label aboutlabel4 =
49  {CTK_LABEL(6, 4, 20, 1, "desktop environment.")};
50 
51 static char abouturl_petscii[] = "http://www.sics.se/~adam/contiki/";
52 static char abouturl_ascii[40];
53 static struct ctk_hyperlink abouturl =
54  {CTK_HYPERLINK(0, 6, 32, "http://www.sics.se/~adam/contiki/",
55  abouturl_ascii)};
56 static struct ctk_button aboutclose =
57  {CTK_BUTTON(12, 8, 5, "Close")};
58 
59 
60 PROCESS(about_process, "About Contiki");
61 
62 AUTOSTART_PROCESSES(&about_process);
63 
64 /*-----------------------------------------------------------------------------------*/
65 static void
66 about_quit(void)
67 {
68  ctk_dialog_close();
69  process_exit(&about_process);
70  LOADER_UNLOAD();
71 }
72 /*-----------------------------------------------------------------------------------*/
73 PROCESS_THREAD(about_process, ev, data)
74 {
75  unsigned char width;
76 
77  PROCESS_BEGIN();
78 
79  width = ctk_desktop_width(NULL);
80 
81  strcpy(abouturl_ascii, abouturl_petscii);
82  petsciiconv_toascii(abouturl_ascii, sizeof(abouturl_ascii));
83 
84  if(width > 34) {
85  ctk_dialog_new(&aboutdialog, 32, 9);
86  } else {
87  ctk_dialog_new(&aboutdialog, width - 2, 9);
88  }
89  CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1);
90  CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2);
91  CTK_WIDGET_ADD(&aboutdialog, &aboutlabel3);
92  CTK_WIDGET_ADD(&aboutdialog, &aboutlabel4);
93  if(width > 34) {
94  CTK_WIDGET_ADD(&aboutdialog, &abouturl);
95  CTK_WIDGET_SET_FLAG(&abouturl, CTK_WIDGET_FLAG_MONOSPACE);
96  } else {
97  CTK_WIDGET_SET_XPOS(&aboutlabel1, 0);
98  CTK_WIDGET_SET_XPOS(&aboutlabel2, 0);
99  CTK_WIDGET_SET_XPOS(&aboutlabel3, 0);
100  CTK_WIDGET_SET_XPOS(&aboutlabel4, 0);
101 
102  CTK_WIDGET_SET_XPOS(&aboutclose, 0);
103  }
104  CTK_WIDGET_ADD(&aboutdialog, &aboutclose);
105  CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose);
106 
107  ctk_dialog_open(&aboutdialog);
108 
109  while(1) {
111  if(ev == PROCESS_EVENT_EXIT) {
112  about_quit();
113  PROCESS_EXIT();
114  } else if(ev == ctk_signal_button_activate) {
115  if(data == (process_data_t)&aboutclose) {
116  about_quit();
117  PROCESS_EXIT();
118  }
119  } else if(ev == ctk_signal_hyperlink_activate) {
120  if((struct ctk_widget *)data == (struct ctk_widget *)&abouturl) {
121  about_quit();
122  PROCESS_EXIT();
123  }
124  }
125  }
126 
127  PROCESS_END();
128 }
129 /*-----------------------------------------------------------------------------------*/
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
Definition: ctk.h:752
process_event_t ctk_signal_button_activate
Same as ctk_signal_widget_activate.
Definition: ctk.c:126
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
Definition: ctk.h:763
#define PROCESS_EXIT()
Exit the currently running process.
Definition: process.h:200
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
unsigned char ctk_desktop_width(struct ctk_desktop *d)
Gets the width of the desktop.
Definition: ctk.c:950
#define NULL
The null pointer.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
Definition: ctk.h:171
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define CTK_WIDGET_SET_XPOS(w, xpos)
Sets the x position of a widget, relative to the window in which the widget is contained.
Definition: ctk.h:808
PETSCII/ASCII conversion functions.
#define LOADER_UNLOAD()
Unload a program from memory.
Definition: loader.h:104
process_event_t ctk_signal_hyperlink_activate
Emitted when a hyperlink is activated.
Definition: ctk.c:126
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
Definition: process.h:141
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Definition: ctk.h:140
#define CTK_HYPERLINK(x, y, w, text, url)
Instantiating macro for the ctk_hyperlink widget.
Definition: ctk.h:202
Representation of a CTK window.
Definition: ctk.h:506
The generic CTK widget structure that contains all other widget structures.
Definition: ctk.h:444
CTK header file.
void process_exit(struct process *p)
Cause a process to exit.
Definition: process.c:202