Subversion Repositories Kolibri OS

Rev

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

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