Calculator application
[Applications]

The calculator application demonstrates some of the available widgets in the Widget toolkit. More...

Collaboration diagram for Calculator application:

Data Structures

struct  calc_context
 Calculator application context. More...

Enumerations

enum  command_id {
  RADIO_DEC_ID = 123, RADIO_HEX_ID, BUTTON_EXIT_ID, DUMMY_ID,
  SLIDER_ID, CHECK_BOX_ID, RADIO_BUTTON_1_ID, RADIO_BUTTON_2_ID,
  BUTTON_QUIT_ID
}
enum  calc_mode { CALC_DEC, CALC_HEX }
 

The calculator modes.

More...

Functions

static void calc_update_display (struct calc_context *calc)
 Update calculator display.
static bool calc_frame_command_handler (struct wtk_basic_frame *frame, win_command_t command_data)
 Frame handler for calculator.
void app_calc_launch (struct workqueue_task *task)
 Start calculator app.

Keypad configuration



#define POS_X   10
 Start position for keypad.
#define POS_Y   50
 Start position for keypad.
#define SIZE_X   45
 Size of each key.
#define SIZE_Y   35
 Size of each key.
#define SPACE_X   (SIZE_X + 10)
 Size of each key including space to next key.
#define SPACE_Y   (SIZE_Y + 10)
 Size of each key including space to next key.
#define KEYS_PR_ROW   4
 Number of keys pr row.

Calculator display configuration



#define MAX_VALUE   999999
 Max value to display.
#define MAX_DIGITS   (10+1)
 Max digits needed to store display value and terminating null byte.

Detailed Description

The calculator application demonstrates some of the available widgets in the Widget toolkit.

The application allows the user to enter numbers and perform the arithmetic operations addition, subtraction, multiplication and division on them. The user has the choice between decimal and hexadecimal representation of the values.


Define Documentation

#define KEYS_PR_ROW   4

Number of keys pr row.

Definition at line 80 of file app_calc.c.

#define MAX_DIGITS   (10+1)

Max digits needed to store display value and terminating null byte.

Definition at line 93 of file app_calc.c.

Referenced by calc_update_display().

#define MAX_VALUE   999999

Max value to display.

Definition at line 91 of file app_calc.c.

Referenced by calc_frame_command_handler().

#define POS_X   10

Start position for keypad.

Definition at line 68 of file app_calc.c.

#define POS_Y   50

Start position for keypad.

Definition at line 70 of file app_calc.c.

#define SIZE_X   45

Size of each key.

Definition at line 72 of file app_calc.c.

#define SIZE_Y   35

Size of each key.

Definition at line 74 of file app_calc.c.

#define SPACE_X   (SIZE_X + 10)

Size of each key including space to next key.

Definition at line 76 of file app_calc.c.

#define SPACE_Y   (SIZE_Y + 10)

Size of each key including space to next key.

Definition at line 78 of file app_calc.c.


Enumeration Type Documentation

enum calc_mode

The calculator modes.

Enumerator:
CALC_DEC 

Calculator is in decimal mode.

CALC_HEX 

Calculator is in hexadecimal mode.

Definition at line 116 of file app_calc.c.

enum command_id

Command event IDs

Note:
The widgets are given command event IDs starting at 123 to avoid values in the ASCII character code range used for the keypad button widgets.
The command IDs cannot be 0, since this value is reserved for no command event callback for certain widgets.
Enumerator:
RADIO_DEC_ID 

Command event ID for DEC radio button.

RADIO_HEX_ID 

Command event ID for HEX radio button.

BUTTON_EXIT_ID 

Command event ID for exit button.

DUMMY_ID 

Unused command event ID.

SLIDER_ID 

Command event ID for slider.

CHECK_BOX_ID 

Command event ID for check box.

RADIO_BUTTON_1_ID 

Command event ID for button 1.

RADIO_BUTTON_2_ID 

Command event ID for button 2.

BUTTON_QUIT_ID 

Command event ID for quit button.

Definition at line 106 of file app_calc.c.


Function Documentation

void app_calc_launch ( struct workqueue_task task  ) 

Start calculator app.

Allocates the application context and creates all widgets for it.

The command event IDs of the keypad button widgets correspond to ASCII character codes that correspond to their value or function.

If memory allocation or widget creation fails, the application exits immediately.

Parameters:
task Workqueue task used to start the calculator.
static bool calc_frame_command_handler ( struct wtk_basic_frame frame,
win_command_t  command_data 
) [static]

Frame handler for calculator.

Handle all the command events of the calculator, i.e., the keypad and radio buttons.

See also:
wtk_basic_frame_command_handler_t
Parameters:
frame Pointer to the application frame
command_data The command event ID

Definition at line 184 of file app_calc.c.

References app_desktop_restart(), BUTTON_EXIT_ID, CALC_DEC, CALC_HEX, calc_update_display(), calc_context::disp_value, max_s, MAX_VALUE, membag_free(), memcpy(), min_s, calc_context::mode, calc_context::old_sysfont, calc_context::operator, RADIO_DEC_ID, RADIO_HEX_ID, calc_context::stack_value, sysfont, and wtk_basic_frame_get_custom_data().

static void calc_update_display ( struct calc_context calc  )  [static]

Update calculator display.

Update the display of the calculator with the new value, in the selected number base.

Parameters:
calc Context for calculator

Definition at line 156 of file app_calc.c.

References assert, CALC_HEX, calc_context::disp_value, calc_context::display_lbl, MAX_DIGITS, calc_context::mode, snprintf(), calc_context::text, and wtk_label_change().

Referenced by calc_frame_command_handler().

Generated on Thu Apr 29 14:09:59 2010 for display-demo by  doxygen 1.6.3