Subversion Repositories Kolibri OS

Rev

Rev 6524 | Rev 6560 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6524 Rev 6526
1
#ifndef KOLIBRI_GUI_ELEMENTS_H
1
#ifndef KOLIBRI_GUI_ELEMENTS_H
2
#define KOLIBRI_GUI_ELEMENTS_H
2
#define KOLIBRI_GUI_ELEMENTS_H
3
 
3
 
4
#include "kolibri_colors.h"
4
#include "kolibri_colors.h"
5
 
5
 
6
/* enum KOLIBRI_GUI_ELEMENT_TYPE contains all available GUI items from box_lib */
6
/* enum KOLIBRI_GUI_ELEMENT_TYPE contains all available GUI items from box_lib */
7
/* More elements can be added from other libraries as required */
7
/* More elements can be added from other libraries as required */
8
enum KOLIBRI_GUI_ELEMENT_TYPE {
8
enum KOLIBRI_GUI_ELEMENT_TYPE {
9
  KOLIBRI_EDIT_BOX,
9
  KOLIBRI_EDIT_BOX,
10
  KOLIBRI_CHECK_BOX,
10
  KOLIBRI_CHECK_BOX,
11
  KOLIBRI_OPTIONGROUP,
11
  KOLIBRI_OPTIONGROUP,
12
  KOLIBRI_SCROLL_BAR_H,
12
  KOLIBRI_SCROLL_BAR_H,
13
  KOLIBRI_SCROLL_BAR_V,
13
  KOLIBRI_SCROLL_BAR_V,
14
  KOLIBRI_DYNAMIC_BUTTON,
14
  KOLIBRI_DYNAMIC_BUTTON,
15
  KOLIBRI_MENU_BAR,
15
  KOLIBRI_MENU_BAR,
16
  KOLIBRI_FILE_BROWSER,
16
  KOLIBRI_FILE_BROWSER,
17
  KOLIBRI_TREE_LIST,
17
  KOLIBRI_TREE_LIST,
18
  KOLIBRI_PATH_SHOW,
18
  KOLIBRI_PATH_SHOW,
19
  KOLIBRI_TEXT_EDITOR,
19
  KOLIBRI_TEXT_EDITOR,
20
  KOLIBRI_FRAME,
20
  KOLIBRI_FRAME,
21
  KOLIBRI_PROGRESS_BAR,
21
  KOLIBRI_PROGRESS_BAR,
22
  KOLIBRI_STATICTEXT,
22
  KOLIBRI_STATICTEXT,
23
  KOLIBRI_STATICNUM,
23
  KOLIBRI_STATICNUM,
24
  KOLIBRI_BUTTON,
24
  KOLIBRI_BUTTON,
25
  KOLIBRI_D_BUTTON,
25
  KOLIBRI_D_BUTTON,
26
  KOLIBRI_PATHSHOW,
26
  KOLIBRI_PATHSHOW,
27
 
27
 
28
  /* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */
28
  /* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */
29
  /* stay at correct value */
29
  /* stay at correct value */
30
 
30
 
31
  KOLIBRI_NUM_GUI_ELEMENTS
31
  KOLIBRI_NUM_GUI_ELEMENTS
32
};
32
};
33
 
33
 
34
#define X_Y(x,y) (((x)<<16)|(y))
34
#define X_Y(x,y) (((x)<<16)|(y))
35
 
35
 
36
/* Linked list which connects together all the elements drawn inside a GUI window */
36
/* Linked list which connects together all the elements drawn inside a GUI window */
37
typedef struct{
37
typedef struct{
38
  enum KOLIBRI_GUI_ELEMENT_TYPE type;
38
  enum KOLIBRI_GUI_ELEMENT_TYPE type;
39
  void *element;
39
  void *element;
40
  void *next, *prev;
40
  void *next, *prev;
41
}kolibri_window_element;
41
}kolibri_window_element;
42
 
42
 
43
typedef void (*cb_elem_boxlib)(void *) __attribute__((__stdcall__));
43
typedef void (*cb_elem_boxlib)(void *) __attribute__((__stdcall__));
44
 
44
 
45
/* Generic structure for supporting functions on various elements of Kolibri's GUI */
45
/* Generic structure for supporting functions on various elements of Kolibri's GUI */
46
typedef struct {
46
typedef struct {
47
 	cb_elem_boxlib 	redraw_fn;
47
 	cb_elem_boxlib 	redraw_fn;
48
 	cb_elem_boxlib 	mouse_fn;
48
 	cb_elem_boxlib 	mouse_fn;
49
 	cb_elem_boxlib 	key_fn;
49
 	cb_elem_boxlib 	key_fn;
50
}kolibri_element_operations;
50
}kolibri_element_operations;
51
 
51
 
52
/* Structure for a GUI Window on Kolibri. It also contains all the elements drawn in window */
52
/* Structure for a GUI Window on Kolibri. It also contains all the elements drawn in window */
53
typedef struct{
53
typedef struct{
54
  unsigned int topleftx, toplefty;
54
  unsigned int topleftx, toplefty;
55
  unsigned int sizex, sizey;
55
  unsigned int sizex, sizey;
56
  char *window_title;
56
  char *window_title;
57
 
57
 
58
  /* Refer to sysfuncs, value to be stored in EDX (Function 0) */
58
  /* Refer to sysfuncs, value to be stored in EDX (Function 0) */
59
  unsigned int XY;
59
  unsigned int XY;
60
 
60
 
61
  kolibri_window_element *elements;
61
  kolibri_window_element *elements;
62
}kolibri_window;
62
}kolibri_window;
63
 
63
 
64
/*---------------------End of Structure and enum definitions---------------*/
64
/*---------------------End of Structure and enum definitions---------------*/
65
 
65
 
66
void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element); // forward declaration
66
void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element); // forward declaration
67
 
67
 
68
/* GUI Elements being used */
68
/* GUI Elements being used */
69
#include "kolibri_button.h"
69
#include "kolibri_button.h"
70
#include "kolibri_checkbox.h"
70
#include "kolibri_checkbox.h"
71
#include "kolibri_d_button.h"
71
#include "kolibri_d_button.h"
72
#include "kolibri_editbox.h"
72
#include "kolibri_editbox.h"
73
#include "kolibri_frame.h"
73
#include "kolibri_frame.h"
74
#include "kolibri_menubar.h"
74
#include "kolibri_menubar.h"
75
#include "kolibri_optionbox.h"
75
#include "kolibri_optionbox.h"
76
#include "kolibri_pathshow.h"
76
#include "kolibri_pathshow.h"
77
#include "kolibri_progressbar.h"
77
#include "kolibri_progressbar.h"
78
#include "kolibri_scrollbar.h"
78
#include "kolibri_scrollbar.h"
79
#include "kolibri_statictext.h"
79
#include "kolibri_statictext.h"
80
 
80
 
81
 
81
 
82
 
82
 
83
 
83
 
84
 
84
 
85
/*---------------------Define various functions for initializing GUI-------*/
85
/*---------------------Define various functions for initializing GUI-------*/
86
 
86
 
87
/* Master table containing operations for various GUI elements in one place */
87
/* Master table containing operations for various GUI elements in one place */
88
kolibri_element_operations kolibri_gui_op_table[KOLIBRI_NUM_GUI_ELEMENTS];
88
kolibri_element_operations kolibri_gui_op_table[KOLIBRI_NUM_GUI_ELEMENTS];
89
 
89
 
90
void kolibri_init_gui_op_table(void)
90
void kolibri_init_gui_op_table(void)
91
{
91
{
92
/* Setting up functions for edit box GUI elements*/
92
/* Setting up functions for edit box GUI elements*/
93
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].redraw_fn = (cb_elem_boxlib)edit_box_draw;
93
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].redraw_fn = (cb_elem_boxlib)edit_box_draw;
94
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].mouse_fn = (cb_elem_boxlib)edit_box_mouse;
94
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].mouse_fn = (cb_elem_boxlib)edit_box_mouse;
95
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].key_fn = (cb_elem_boxlib)editbox_key;
95
kolibri_gui_op_table[KOLIBRI_EDIT_BOX].key_fn = (cb_elem_boxlib)editbox_key;
96
 
96
 
97
/* Setting up functions for check box GUI elements*/
97
/* Setting up functions for check box GUI elements*/
98
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].redraw_fn = (cb_elem_boxlib)check_box_draw2;
98
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].redraw_fn = (cb_elem_boxlib)check_box_draw2;
99
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].mouse_fn = (cb_elem_boxlib)check_box_mouse2;
99
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].mouse_fn = (cb_elem_boxlib)check_box_mouse2;
100
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].key_fn = NULL;
100
kolibri_gui_op_table[KOLIBRI_CHECK_BOX].key_fn = NULL;
101
 
101
 
102
/* Setting up functions for Kolibri Buttons ( SysFunc 8 )*/
102
/* Setting up functions for Kolibri Buttons ( SysFunc 8 )*/
103
kolibri_gui_op_table[KOLIBRI_BUTTON].redraw_fn = (cb_elem_boxlib)draw_button;
103
kolibri_gui_op_table[KOLIBRI_BUTTON].redraw_fn = (cb_elem_boxlib)draw_button;
104
kolibri_gui_op_table[KOLIBRI_BUTTON].mouse_fn = NULL;
104
kolibri_gui_op_table[KOLIBRI_BUTTON].mouse_fn = NULL;
105
kolibri_gui_op_table[KOLIBRI_BUTTON].key_fn = NULL;
105
kolibri_gui_op_table[KOLIBRI_BUTTON].key_fn = NULL;
106
 
106
 
107
/* Setting up functions for progress bar GUI elements*/
107
/* Setting up functions for progress bar GUI elements*/
108
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].redraw_fn = (cb_elem_boxlib)progressbar_draw;
108
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].redraw_fn = (cb_elem_boxlib)progressbar_draw;
109
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].mouse_fn = NULL;
109
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].mouse_fn = NULL;
110
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].key_fn = NULL;
110
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].key_fn = NULL;
111
 
111
 
112
/* Setting up functions for frame GUI elements*/
112
/* Setting up functions for frame GUI elements*/
113
kolibri_gui_op_table[KOLIBRI_FRAME].redraw_fn = (cb_elem_boxlib)frame_draw;
113
kolibri_gui_op_table[KOLIBRI_FRAME].redraw_fn = (cb_elem_boxlib)frame_draw;
114
kolibri_gui_op_table[KOLIBRI_FRAME].mouse_fn = NULL;
114
kolibri_gui_op_table[KOLIBRI_FRAME].mouse_fn = NULL;
115
kolibri_gui_op_table[KOLIBRI_FRAME].key_fn = NULL;
115
kolibri_gui_op_table[KOLIBRI_FRAME].key_fn = NULL;
116
 
116
 
117
/* scrollbars */
117
/* scrollbars */
118
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].redraw_fn = (cb_elem_boxlib)scrollbar_h_draw;
118
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].redraw_fn = (cb_elem_boxlib)scrollbar_h_draw;
119
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].mouse_fn = (cb_elem_boxlib)scrollbar_h_mouse;
119
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].mouse_fn = (cb_elem_boxlib)scrollbar_h_mouse;
120
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].key_fn = NULL;
120
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].key_fn = NULL;
121
 
121
 
122
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].redraw_fn = (cb_elem_boxlib)scrollbar_v_draw;
122
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].redraw_fn = (cb_elem_boxlib)scrollbar_v_draw;
123
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].mouse_fn = (cb_elem_boxlib)scrollbar_v_mouse;
123
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].mouse_fn = (cb_elem_boxlib)scrollbar_v_mouse;
124
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].key_fn = NULL;
124
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].key_fn = NULL;
125
 
125
 
126
kolibri_gui_op_table[KOLIBRI_STATICTEXT].redraw_fn = (cb_elem_boxlib)statictext_draw;
126
kolibri_gui_op_table[KOLIBRI_STATICTEXT].redraw_fn = (cb_elem_boxlib)statictext_draw;
127
kolibri_gui_op_table[KOLIBRI_STATICTEXT].mouse_fn = NULL;
127
kolibri_gui_op_table[KOLIBRI_STATICTEXT].mouse_fn = NULL;
128
kolibri_gui_op_table[KOLIBRI_STATICTEXT].key_fn = NULL;
128
kolibri_gui_op_table[KOLIBRI_STATICTEXT].key_fn = NULL;
129
 
129
 
130
kolibri_gui_op_table[KOLIBRI_STATICNUM].redraw_fn = (cb_elem_boxlib)staticnum_draw;
130
kolibri_gui_op_table[KOLIBRI_STATICNUM].redraw_fn = (cb_elem_boxlib)staticnum_draw;
131
kolibri_gui_op_table[KOLIBRI_STATICNUM].mouse_fn = NULL;
131
kolibri_gui_op_table[KOLIBRI_STATICNUM].mouse_fn = NULL;
132
kolibri_gui_op_table[KOLIBRI_STATICNUM].key_fn = NULL;
132
kolibri_gui_op_table[KOLIBRI_STATICNUM].key_fn = NULL;
133
 
133
 
134
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].redraw_fn = (cb_elem_boxlib)option_box_draw;
134
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].redraw_fn = (cb_elem_boxlib)option_box_draw;
135
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].mouse_fn = (cb_elem_boxlib)option_box_mouse;
135
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].mouse_fn = (cb_elem_boxlib)option_box_mouse;
136
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].key_fn = NULL;
136
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].key_fn = NULL;
137
 
137
 
138
kolibri_gui_op_table[KOLIBRI_MENU_BAR].redraw_fn = (cb_elem_boxlib)menu_bar_draw;
138
kolibri_gui_op_table[KOLIBRI_MENU_BAR].redraw_fn = (cb_elem_boxlib)menu_bar_draw;
139
kolibri_gui_op_table[KOLIBRI_MENU_BAR].mouse_fn = (cb_elem_boxlib)menu_bar_mouse;
139
kolibri_gui_op_table[KOLIBRI_MENU_BAR].mouse_fn = (cb_elem_boxlib)menu_bar_mouse;
140
kolibri_gui_op_table[KOLIBRI_MENU_BAR].key_fn = NULL;
140
kolibri_gui_op_table[KOLIBRI_MENU_BAR].key_fn = NULL;
141
 
141
 
142
kolibri_gui_op_table[KOLIBRI_D_BUTTON].redraw_fn = (cb_elem_boxlib)dynamic_button_draw;
142
kolibri_gui_op_table[KOLIBRI_D_BUTTON].redraw_fn = (cb_elem_boxlib)dynamic_button_draw;
143
kolibri_gui_op_table[KOLIBRI_D_BUTTON].mouse_fn = (cb_elem_boxlib)dynamic_button_mouse;
143
kolibri_gui_op_table[KOLIBRI_D_BUTTON].mouse_fn = (cb_elem_boxlib)dynamic_button_mouse;
144
kolibri_gui_op_table[KOLIBRI_D_BUTTON].key_fn = NULL;
144
kolibri_gui_op_table[KOLIBRI_D_BUTTON].key_fn = NULL;
145
debug_board_printf("KOLIBRI_D_BUTTON (%x,%x,%x)\n", dynamic_button_draw, dynamic_button_mouse, 0);
145
debug_board_printf("KOLIBRI_D_BUTTON (%x,%x,%x)\n", dynamic_button_draw, dynamic_button_mouse, 0);
146
 
146
 
147
kolibri_gui_op_table[KOLIBRI_PATHSHOW].redraw_fn = (cb_elem_boxlib)path_show_draw;
147
kolibri_gui_op_table[KOLIBRI_PATHSHOW].redraw_fn = (cb_elem_boxlib)path_show_draw;
148
kolibri_gui_op_table[KOLIBRI_PATHSHOW].mouse_fn = NULL;
148
kolibri_gui_op_table[KOLIBRI_PATHSHOW].mouse_fn = NULL;
149
kolibri_gui_op_table[KOLIBRI_PATHSHOW].key_fn = NULL;
149
kolibri_gui_op_table[KOLIBRI_PATHSHOW].key_fn = NULL;
150
debug_board_printf("KOLIBRI_PATHSHOW (%x,%x,%x)\n", path_show_draw, 0, 0);
150
debug_board_printf("KOLIBRI_PATHSHOW (%x,%x,%x)\n", path_show_draw, 0, path_show_prepare);
151
}
151
}
152
 
152
 
153
/* Create a new main GUI window for KolibriOS */
153
/* Create a new main GUI window for KolibriOS */
154
/* tl stands for TOP LEFT. x and y are coordinates. */
154
/* tl stands for TOP LEFT. x and y are coordinates. */
155
 
155
 
156
kolibri_window * kolibri_new_window(int tlx, int tly, int sizex, int sizey, char *title)
156
kolibri_window * kolibri_new_window(int tlx, int tly, int sizex, int sizey, char *title)
157
{
157
{
158
  kolibri_window *new_win = (kolibri_window *)malloc(sizeof(kolibri_window));
158
  kolibri_window *new_win = (kolibri_window *)malloc(sizeof(kolibri_window));
159
 
159
 
160
  new_win->topleftx = tlx;
160
  new_win->topleftx = tlx;
161
  new_win->toplefty = tly;
161
  new_win->toplefty = tly;
162
  new_win->sizex = sizex;
162
  new_win->sizex = sizex;
163
  new_win->sizey = sizey;
163
  new_win->sizey = sizey;
164
  new_win->window_title = title;
164
  new_win->window_title = title;
165
  new_win->XY = 0x33;
165
  new_win->XY = 0x33;
166
  new_win->elements = NULL;
166
  new_win->elements = NULL;
167
 
167
 
168
  return new_win;
168
  return new_win;
169
}
169
}
170
 
170
 
171
/* Add an element to an existing window */
171
/* Add an element to an existing window */
172
void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element)
172
void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element)
173
{
173
{
174
  kolibri_window_element *new_element = (kolibri_window_element *)malloc(sizeof(kolibri_window_element));
174
  kolibri_window_element *new_element = (kolibri_window_element *)malloc(sizeof(kolibri_window_element));
175
 
175
 
176
  new_element -> type = element_type;
176
  new_element -> type = element_type;
177
  new_element -> element = some_gui_element;
177
  new_element -> element = some_gui_element;
178
 
178
 
179
  if(!(some_window->elements)) /* No elements in window yet */
179
  if(!(some_window->elements)) /* No elements in window yet */
180
    {
180
    {
181
      some_window->elements = new_element;
181
      some_window->elements = new_element;
182
      some_window->elements -> prev = some_window->elements;
182
      some_window->elements -> prev = some_window->elements;
183
      some_window->elements -> next = some_window->elements;
183
      some_window->elements -> next = some_window->elements;
184
    }
184
    }
185
  else
185
  else
186
    {
186
    {
187
      kolibri_window_element *last_element = some_window -> elements -> prev;
187
      kolibri_window_element *last_element = some_window -> elements -> prev;
188
 
188
 
189
      last_element -> next = new_element;
189
      last_element -> next = new_element;
190
      new_element -> next = some_window -> elements; /* start of linked list  */
190
      new_element -> next = some_window -> elements; /* start of linked list  */
191
      some_window -> elements -> prev = new_element;
191
      some_window -> elements -> prev = new_element;
192
      new_element -> prev = last_element;
192
      new_element -> prev = last_element;
193
    }
193
    }
194
}
194
}
195
 
195
 
196
#endif /* KOLIBRI_GUI_ELEMENTS_H */
196
#endif /* KOLIBRI_GUI_ELEMENTS_H */
197
 
197
 
198
/*>
198
/*>
199
 
199
 
200
/*>
200
/*>