Subversion Repositories Kolibri OS

Rev

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

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