Contiki 2.5
Data Structures | Macros | Functions | Variables
CTK application functions

The CTK functions used by an application program. More...

Data Structures

struct  ctk_widget_button
 Instantiating macro for the ctk_icon widget. More...
 

Macros

#define CTK_SEPARATOR(x, y, w)   NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0)
 Instantiating macro for the ctk_separator widget. More...
 
#define CTK_BUTTON(x, y, w, text)   NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text
 Instantiating macro for the ctk_button widget. More...
 
#define CTK_LABEL(x, y, w, h, text)   NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text,
 Instantiating macro for the ctk_label widget. More...
 
#define CTK_HYPERLINK(x, y, w, text, url)   NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, url
 Instantiating macro for the ctk_hyperlink widget. More...
 
#define CTK_TEXTENTRY_CLEAR(e)
 Clears a text entry widget and sets the cursor to the start of the text line. More...
 
#define CTK_TEXTENTRY(x, y, w, h, text, len)
 Instantiating macro for the ctk_textentry widget. More...
 
#define CTK_ICON_ADD(icon, p)   ctk_icon_add((struct ctk_widget *)icon, p)
 Add an icon to the desktop. More...
 
#define CTK_WIDGET_ADD(win, widg)   ctk_widget_add(win, (struct ctk_widget *)widg)
 Add a widget to a window. More...
 
#define CTK_WIDGET_FOCUS(win, widg)   (win)->focused = (struct ctk_widget *)(widg)
 Set focus to a widget. More...
 
#define CTK_WIDGET_REDRAW(widg)   ctk_widget_redraw((struct ctk_widget *)widg)
 Add a widget to the redraw queue. More...
 
#define CTK_WIDGET_TYPE(w)   ((w)->type)
 Obtain the type of a widget. More...
 
#define CTK_WIDGET_SET_WIDTH(widget, width)
 Sets the width of a widget. More...
 
#define CTK_WIDGET_XPOS(w)   (((struct ctk_widget *)(w))->x)
 Retrieves the x position of a widget, relative to the window in which the widget is contained. More...
 
#define CTK_WIDGET_SET_XPOS(w, xpos)   ((struct ctk_widget *)(w))->x = (xpos)
 Sets the x position of a widget, relative to the window in which the widget is contained. More...
 
#define CTK_WIDGET_YPOS(w)   (((struct ctk_widget *)(w))->y)
 Retrieves the y position of a widget, relative to the window in which the widget is contained. More...
 
#define CTK_WIDGET_SET_YPOS(w, ypos)   ((struct ctk_widget *)(w))->y = (ypos)
 Sets the y position of a widget, relative to the window in which the widget is contained. More...
 
#define ctk_label_set_height(w, height)   (w)->widget.label.h = (height)
 Set the height of a label. More...
 
#define ctk_label_set_text(l, t)   (l)->text = (t)
 Set the text of a label. More...
 
#define ctk_button_set_text(b, t)   (b)->text = (t)
 Set the text of a button. More...
 

Functions

void ctk_mode_set (unsigned char m)
 Sets the current CTK mode. More...
 
unsigned char ctk_mode_get (void)
 Retrieves the current CTK mode. More...
 
void ctk_icon_add (CC_REGISTER_ARG struct ctk_widget *icon, struct process *p)
 Add an icon to the desktop. More...
 
void ctk_window_open (CC_REGISTER_ARG struct ctk_window *w)
 Open a window, or bring window to front if already open. More...
 
void ctk_window_close (struct ctk_window *w)
 Close a window if it is open. More...
 
void ctk_window_clear (struct ctk_window *w)
 Remove all widgets from a window. More...
 
void ctk_menu_add (struct ctk_menu *menu)
 Add a menu to the menu bar. More...
 
void ctk_menu_remove (struct ctk_menu *menu)
 Remove a menu from the menu bar. More...
 
void ctk_window_redraw (struct ctk_window *w)
 Redraw a window. More...
 
void ctk_window_new (struct ctk_window *window, unsigned char w, unsigned char h, char *title)
 Create a new window. More...
 
void ctk_menu_new (CC_REGISTER_ARG struct ctk_menu *menu, char *title)
 Creates a new menu. More...
 
unsigned char ctk_menuitem_add (CC_REGISTER_ARG struct ctk_menu *menu, char *name)
 Adds a menu item to a menu. More...
 
void ctk_widget_redraw (struct ctk_widget *widget)
 Redraws a widget. More...
 
void CC_FASTCALL ctk_widget_add (CC_REGISTER_ARG struct ctk_window *window, CC_REGISTER_ARG struct ctk_widget *widget)
 Adds a widget to a window. More...
 
unsigned char ctk_desktop_width (struct ctk_desktop *d)
 Gets the width of the desktop. More...
 
unsigned char ctk_desktop_height (struct ctk_desktop *d)
 Gets the height of the desktop. More...
 

Variables

CCIF process_event_t ctk_signal_keypress
 Emitted for every key being pressed. More...
 
CCIF process_event_t ctk_signal_widget_activate
 Emitted when a widget is activated (pressed). More...
 
CCIF process_event_t ctk_signal_widget_select
 Emitted when a widget is selected. More...
 
CCIF process_event_t ctk_signal_menu_activate
 Emitted when a menu item is activated. More...
 
CCIF process_event_t ctk_signal_window_close
 Emitted when a window is closed. More...
 
CCIF process_event_t ctk_signal_button_activate
 Same as ctk_signal_widget_activate. More...
 
CCIF process_event_t ctk_signal_button_hover
 Same as ctk_signal_widget_select. More...
 
CCIF process_event_t ctk_signal_hyperlink_activate
 Emitted when a hyperlink is activated. More...
 
CCIF process_event_t ctk_signal_hyperlink_hover
 Same as ctk_signal_widget_select. More...
 

Detailed Description

The CTK functions used by an application program.

Macro Definition Documentation

#define CTK_BUTTON (   x,
  y,
  w,
  text 
)    NULL, NULL, x, y, CTK_WIDGET_BUTTON, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text

Instantiating macro for the ctk_button widget.

This macro is used when instantiating a ctk_button widget and is intended to be used together with a struct assignment like this:

struct ctk_button but =
{CTK_BUTTON(0, 0, 2, "Ok")};
Parameters
xThe x position of the widget, relative to the widget's window.
yThe y position of the widget, relative to the widget's window.
wThe widget's width.
textThe button text.

Definition at line 141 of file ctk.h.

#define ctk_button_set_text (   b,
 
)    (b)->text = (t)

Set the text of a button.

Parameters
bThe CTK button widget.
tThe new text of the button.

Definition at line 858 of file ctk.h.

#define CTK_HYPERLINK (   x,
  y,
  w,
  text,
  url 
)    NULL, NULL, x, y, CTK_WIDGET_HYPERLINK, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, url

Instantiating macro for the ctk_hyperlink widget.

This macro is used when instantiating a ctk_hyperlink widget and is intended to be used together with a struct assignment like this:

struct ctk_hyperlink hlink =
{CTK_HYPERLINK(0, 0, 7, "Contiki", "http://dunkels.com/adam/contiki/")};
Parameters
xThe x position of the widget, relative to the widget's window.
yThe y position of the widget, relative to the widget's window.
wThe widget's width.
textThe hyperlink text.
urlThe hyperlink URL.

Definition at line 203 of file ctk.h.

#define CTK_ICON_ADD (   icon,
 
)    ctk_icon_add((struct ctk_widget *)icon, p)

Add an icon to the desktop.

Parameters
iconThe icon to be added.
pThe process ID of the process that owns the icon.

Definition at line 742 of file ctk.h.

#define CTK_LABEL (   x,
  y,
  w,
  h,
  text 
)    NULL, NULL, x, y, CTK_WIDGET_LABEL, w, h, CTK_WIDGET_FLAG_INITIALIZER(0) text,

Instantiating macro for the ctk_label widget.

This macro is used when instantiating a ctk_label widget and is intended to be used together with a struct assignment like this:

struct ctk_label lab =
{CTK_LABEL(0, 0, 5, 1, "Label")};
Parameters
xThe x position of the widget, relative to the widget's window.
yThe y position of the widget, relative to the widget's window.
wThe widget's width.
hThe height of the label.
textThe label text.

Definition at line 172 of file ctk.h.

#define ctk_label_set_height (   w,
  height 
)    (w)->widget.label.h = (height)

Set the height of a label.

Parameters
wThe CTK label widget.
heightThe new height of the label.

Definition at line 841 of file ctk.h.

#define ctk_label_set_text (   l,
 
)    (l)->text = (t)

Set the text of a label.

Parameters
lThe CTK label widget.
tThe new text of the label.

Definition at line 850 of file ctk.h.

#define CTK_SEPARATOR (   x,
  y,
 
)    NULL, NULL, x, y, CTK_WIDGET_SEPARATOR, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0)

Instantiating macro for the ctk_separator widget.

This macro is used when instantiating a ctk_separator widget and is intended to be used together with a struct assignment like this:

struct ctk_separator sep =
{CTK_SEPARATOR(0, 0, 23)};
Parameters
xThe x position of the widget, relative to the widget's window.
yThe y position of the widget, relative to the widget's window.
wThe widget's width.

Definition at line 112 of file ctk.h.

#define CTK_TEXTENTRY (   x,
  y,
  w,
  h,
  text,
  len 
)
Value:
NULL, NULL, x, y, CTK_WIDGET_TEXTENTRY, w, 1, CTK_WIDGET_FLAG_INITIALIZER(0) text, len, \
CTK_TEXTENTRY_NORMAL, 0, 0, NULL

Instantiating macro for the ctk_textentry widget.

This macro is used when instantiating a ctk_textentry widget and is intended to be used together with a struct assignment like this:

struct ctk_textentry tentry =
{CTK_TEXTENTRY(0, 0, 30, 1, textbuffer, 50)};
Note
The height of the text entry widget is obsolete and not intended to be used.
Parameters
xThe x position of the widget, relative to the widget's window.
yThe y position of the widget, relative to the widget's window.
wThe widget's width.
hThe text entry height (obsolete).
textA pointer to the buffer that should be edited.
lenThe length of the text buffer

Definition at line 276 of file ctk.h.

#define CTK_TEXTENTRY_CLEAR (   e)
Value:
do { memset((e)->text, 0, (e)->h * ((e)->len + 1)); \
(e)->xpos = 0; (e)->ypos = 0; } while(0)

Clears a text entry widget and sets the cursor to the start of the text line.

Parameters
eThe text entry widget to be cleared.

Definition at line 232 of file ctk.h.

#define CTK_WIDGET_ADD (   win,
  widg 
)    ctk_widget_add(win, (struct ctk_widget *)widg)

Add a widget to a window.

Parameters
winThe window to which the widget should be added.
widgThe widget to be added.

Definition at line 753 of file ctk.h.

#define CTK_WIDGET_FOCUS (   win,
  widg 
)    (win)->focused = (struct ctk_widget *)(widg)

Set focus to a widget.

Parameters
winThe widget's window.
widgThe widget

Definition at line 764 of file ctk.h.

#define CTK_WIDGET_REDRAW (   widg)    ctk_widget_redraw((struct ctk_widget *)widg)

Add a widget to the redraw queue.

Parameters
widgThe widget to be redrawn.

Definition at line 772 of file ctk.h.

#define CTK_WIDGET_SET_WIDTH (   widget,
  width 
)
Value:
do { \
((struct ctk_widget *)(widget))->w = (width); } while(0)

Sets the width of a widget.

Parameters
widgetThe widget.
widthThe width of the widget, in characters.

Definition at line 790 of file ctk.h.

#define CTK_WIDGET_SET_XPOS (   w,
  xpos 
)    ((struct ctk_widget *)(w))->x = (xpos)

Sets the x position of a widget, relative to the window in which the widget is contained.

Parameters
wThe widget.
xposThe x position of the widget.

Definition at line 809 of file ctk.h.

#define CTK_WIDGET_SET_YPOS (   w,
  ypos 
)    ((struct ctk_widget *)(w))->y = (ypos)

Sets the y position of a widget, relative to the window in which the widget is contained.

Parameters
wThe widget.
yposThe y position of the widget.

Definition at line 827 of file ctk.h.

#define CTK_WIDGET_TYPE (   w)    ((w)->type)

Obtain the type of a widget.

Parameters
wThe widget.

Definition at line 781 of file ctk.h.

#define CTK_WIDGET_XPOS (   w)    (((struct ctk_widget *)(w))->x)

Retrieves the x position of a widget, relative to the window in which the widget is contained.

Parameters
wThe widget.
Returns
The x position of the widget.

Definition at line 800 of file ctk.h.

#define CTK_WIDGET_YPOS (   w)    (((struct ctk_widget *)(w))->y)

Retrieves the y position of a widget, relative to the window in which the widget is contained.

Parameters
wThe widget.
Returns
The y position of the widget.

Definition at line 818 of file ctk.h.

Function Documentation

unsigned char ctk_desktop_height ( struct ctk_desktop *  d)

Gets the height of the desktop.

Parameters
dThe desktop.
Returns
The height of the desktop, in characters.
Note
The d parameter is currently unused and must be set to NULL.

Definition at line 966 of file ctk.c.

CCIF unsigned char ctk_desktop_width ( struct ctk_desktop *  d)

Gets the width of the desktop.

Parameters
dThe desktop.
Returns
The width of the desktop, in characters.
Note
The d parameter is currently unused and must be set to NULL.

Definition at line 951 of file ctk.c.

void ctk_icon_add ( CC_REGISTER_ARG struct ctk_widget icon,
struct process *  p 
)

Add an icon to the desktop.

Parameters
iconThe icon to be added.
pThe process that owns the icon.

Definition at line 305 of file ctk.c.

References ctk_widget_add().

void ctk_menu_add ( struct ctk_menu menu)

Add a menu to the menu bar.

Parameters
menuThe menu to be added.
Note
Do not call this function multiple times for the same menu, as no check is made to see if the menu already is in the menu bar.

Definition at line 505 of file ctk.c.

References ctk_menu::next, and NULL.

void ctk_menu_new ( CC_REGISTER_ARG struct ctk_menu menu,
char *  title 
)

Creates a new menu.

This function sets up the internal structure of the menu, but does not add it to the menubar. Use the function ctk_menu_add() for that purpose.

Parameters
menuThe menu to be created.
titleThe title of the menu.

Definition at line 776 of file ctk.c.

References NULL, and ctk_window::title.

void ctk_menu_remove ( struct ctk_menu menu)

Remove a menu from the menu bar.

Parameters
menuThe menu to be removed.

Definition at line 533 of file ctk.c.

References ctk_menu::next, and NULL.

unsigned char ctk_menuitem_add ( CC_REGISTER_ARG struct ctk_menu menu,
char *  name 
)

Adds a menu item to a menu.

In CTK, each menu item is identified by a number which is unique within each menu. When a menu item is selected, a ctk_menuitem_activated signal is emitted and the menu item number is passed as signal data with the signal.

Parameters
menuThe menu to which the menu item should be added.
nameThe name of the menu item.
Returns
The number of the menu item.

Definition at line 801 of file ctk.c.

unsigned char ctk_mode_get ( void  )

Retrieves the current CTK mode.

Returns
The current CTK mode.

Definition at line 292 of file ctk.c.

void ctk_mode_set ( unsigned char  m)

Sets the current CTK mode.

The CTK mode can be either CTK_MODE_NORMAL, CTK_MODE_SCREENSAVER or CTK_MODE_EXTERNAL. CTK_MODE_NORMAL is the normal mode, in which keypresses and mouse pointer movements are processed and the screen is redrawn. In CTK_MODE_SCREENSAVER, no screen redraws are performed and the first key press or pointer movement will cause the ctk_signal_screensaver_stop to be emitted. In the CTK_MODE_EXTERNAL mode, key presses and pointer movements are ignored and no screen redraws are made.

Parameters
mThe mode.

Definition at line 281 of file ctk.c.

void CC_FASTCALL ctk_widget_add ( CC_REGISTER_ARG struct ctk_window window,
CC_REGISTER_ARG struct ctk_widget widget 
)

Adds a widget to a window.

This function adds a widget to a window. The order of which the widgets are added is important, as it sets the order to which widgets are cycled with the widget selection keys.

Parameters
windowThe window to which the widhet should be added.
widgetThe widget to be added.

Definition at line 926 of file ctk.c.

References CTK_WIDGET_LABEL, and CTK_WIDGET_SEPARATOR.

Referenced by ctk_icon_add().

CCIF void ctk_widget_redraw ( struct ctk_widget widget)

Redraws a widget.

This function will set a flag which causes the widget to be redrawn next time the CTK process is scheduled.

Parameters
widgetThe widget that is to be redrawn.
Note
This function should usually not be called directly since it requires typecasting of the widget parameter. The wrapper macro CTK_WIDGET_REDRAW() does the required typecast and should be used instead.

Definition at line 903 of file ctk.c.

References NULL.

void ctk_window_clear ( struct ctk_window w)

Remove all widgets from a window.

Parameters
wThe window to be cleared.

Definition at line 486 of file ctk.c.

References ctk_window::active, ctk_window::focused, ctk_window::inactive, and NULL.

void ctk_window_close ( struct ctk_window w)

Close a window if it is open.

If the window is not open, this function does nothing.

Parameters
wThe window to be closed.

Definition at line 401 of file ctk.c.

References ctk_window::next, NULL, ctk_window::prev, and ctk_window::w.

void ctk_window_new ( struct ctk_window window,
unsigned char  w,
unsigned char  h,
char *  title 
)

Create a new window.

Creates a new window. The memory for the window structure must already be allocated by the caller, and is usually done with a static declaration.

This function sets up the internal structure of the ctk_window struct and creates the move and close buttons, but it does not open the window. The window must be explicitly opened by calling the ctk_window_open() function.

Parameters
windowThe window to be created.
wThe width of the new window.
hThe height of the new window.
titleThe title of the new window.

Definition at line 733 of file ctk.c.

void ctk_window_open ( CC_REGISTER_ARG struct ctk_window w)

Open a window, or bring window to front if already open.

Parameters
wThe window to be opened.

Definition at line 348 of file ctk.c.

References ctk_window::next, NULL, ctk_window::prev, and ctk_window::w.

void ctk_window_redraw ( struct ctk_window w)

Redraw a window.

This function redraws the window, but only if it is the foremost one on the desktop.

Parameters
wThe window to be redrawn.

Definition at line 653 of file ctk.c.

References ctk_draw_dialog(), ctk_draw_window(), CTK_FOCUS_WINDOW, and NULL.

Variable Documentation

CCIF process_event_t ctk_signal_button_activate

Same as ctk_signal_widget_activate.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_button_hover

Same as ctk_signal_widget_select.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_hyperlink_activate

Emitted when a hyperlink is activated.

The signal is broadcast to all listeners.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_hyperlink_hover

Same as ctk_signal_widget_select.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_keypress

Emitted for every key being pressed.

The key is passed as signal data.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_menu_activate

Emitted when a menu item is activated.

The number of the menu item is passed as signal data.

Definition at line 152 of file ctk.c.

CCIF process_event_t ctk_signal_widget_activate

Emitted when a widget is activated (pressed).

A pointer to the widget is passed as signal data.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_widget_select

Emitted when a widget is selected.

A pointer to the widget is passed as signal data.

Definition at line 127 of file ctk.c.

CCIF process_event_t ctk_signal_window_close

Emitted when a window is closed.

A pointer to the window is passed as signal data.

Definition at line 156 of file ctk.c.