Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6391 ashmew2 1
#ifndef KOLIBRI_GUI_ELEMENTS_H
2
#define KOLIBRI_GUI_ELEMENTS_H
3
 
4
/* GUI Elements being used */
5
#include "kolibri_editbox.h"
6
#include "kolibri_checkbox.h"
7
#include "kolibri_button.h"
8
 
9
/* enum KOLIBRI_GUI_ELEMENT_TYPE contains all available GUI items from box_lib */
10
/* More elements can be added from other libraries as required */
11
enum KOLIBRI_GUI_ELEMENT_TYPE {
12
  KOLIBRI_EDIT_BOX,
13
  KOLIBRI_CHECK_BOX,
14
  KOLIBRI_RADIO_BUTTON,
15
  KOLIBRI_SCROLL_BAR,
16
  KOLIBRI_DYNAMIC_BUTTON,
17
  KOLIBRI_MENU_BAR,
18
  KOLIBRI_FILE_BROWSER,
19
  KOLIBRI_TREE_LIST,
20
  KOLIBRI_PATH_SHOW,
21
  KOLIBRI_TEXT_EDITOR,
22
  KOLIBRI_FRAME,
23
  KOLIBRI_PROGRESS_BAR,
24
 
25
  KOLIBRI_BUTTON,
26
 
27
  /* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */
28
  /* stay at correct value */
29
 
30
  KOLIBRI_NUM_GUI_ELEMENTS
31
};
32
 
33
/* Linked list which connects together all the elements drawn inside a GUI window */
34
struct kolibri_window_element {
35
  enum KOLIBRI_GUI_ELEMENT_TYPE type;
36
  void *element;
37
  struct kolibri_window_element *next, *prev;
38
};
39
 
40
/* Generic structure for supporting functions on various elements of Kolibri's GUI */
41
struct kolibri_element_operations {
42
  void (*redraw_fn)(void *);
43
  void (*mouse_fn)(void *);
44
  void (*key_fn)(void *);
45
};
46
 
47
/* Structure for a GUI Window on Kolibri. It also contains all the elements drawn in window */
48
struct kolibri_window {
49
  unsigned int topleftx, toplefty;
50
  unsigned int sizex, sizey;
51
  char *window_title;
52
 
53
  /* Refer to sysfuncs, value to be stored in EDX (Function 0) */
54
  unsigned int XY;
55
 
56
  struct kolibri_window_element *elements;
57
};
58
 
59
/*---------------------End of Structure and enum definitions---------------*/
60
/*---------------------Define various functions for initializing GUI-------*/
61
 
62
/* Master table containing operations for various GUI elements in one place */
63
struct kolibri_element_operations kolibri_gui_op_table[KOLIBRI_NUM_GUI_ELEMENTS];
64
 
65
void kolibri_init_gui_op_table(void)
66
{
67
/* Setting up functions for edit box GUI elements*/
68
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].redraw_fn = edit_box_draw;
69
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].mouse_fn = edit_box_mouse;
70
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].key_fn = editbox_key;
71
 
72
/* Setting up functions for check box GUI elements*/
73
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].redraw_fn = check_box_draw2;
74
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].mouse_fn = check_box_mouse2;
75
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].key_fn = NULL;
76
 
77
/* Setting up functions for Kolibri Buttons ( SysFunc 8 )*/
78
kolibri_gui_op_table[KOLIBRI_BUTTON].redraw_fn = draw_button;
79
kolibri_gui_op_table[KOLIBRI_BUTTON].mouse_fn = NULL;
80
kolibri_gui_op_table[KOLIBRI_BUTTON].key_fn = NULL;
81
}
82
 
83
/* Create a new main GUI window for KolibriOS */
84
/* tl stands for TOP LEFT. x and y are coordinates. */
85
 
86
struct kolibri_window * kolibri_new_window(int tlx, int tly, int sizex, int sizey, char *title)
87
{
88
  struct kolibri_window *new_win = (struct kolibri_window *)malloc(sizeof(struct kolibri_window));
89
 
90
  new_win->topleftx = tlx;
91
  new_win->toplefty = tly;
92
  new_win->sizex = sizex;
93
  new_win->sizey = sizey;
94
  new_win->window_title = title;
95
  new_win->XY = 0x00000013; /* All windows are skinned windows with caption for now */
96
  new_win->elements = NULL;
97
 
98
  return new_win;
99
}
100
 
101
/* Add an element to an existing window */
102
void kolibri_window_add_element(struct kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element)
103
{
104
  struct kolibri_window_element *new_element = (struct kolibri_window_element *)malloc(sizeof(struct kolibri_window_element));
105
 
106
  new_element -> type = element_type;
107
  new_element -> element = some_gui_element;
108
 
109
  if(!(some_window->elements)) /* No elements in window yet */
110
    {
111
      some_window->elements = new_element;
112
      some_window->elements -> prev = some_window->elements;
113
      some_window->elements -> next = some_window->elements;
114
    }
115
  else
116
    {
117
      struct kolibri_window_element *last_element = some_window -> elements -> prev;
118
 
119
      last_element -> next = new_element;
120
      new_element -> next = some_window -> elements; /* start of linked list  */
121
      some_window -> elements -> prev = new_element;
122
      new_element -> prev = last_element;
123
    }
124
}
125
 
126
#endif /* KOLIBRI_GUI_ELEMENTS_H */