Subversion Repositories Kolibri OS

Rev

Rev 6395 | Rev 6457 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6391 ashmew2 1
#ifndef KOLIBRI_GUI_H
2
#define KOLIBRI_GUI_H
3
 
6395 siemargl 4
#include  /* for malloc() */
6391 ashmew2 5
#include 
6
 
7
#include "kolibri_debug.h" /* work with debug board */
8
 
9
/* boxlib loader */
10
#include "kolibri_boxlib.h"
11
 
12
/* All supported GUI elements included */
13
#include "kolibri_gui_elements.h"
14
 
15
enum KOLIBRI_GUI_EVENTS {
16
  KOLIBRI_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
17
  KOLIBRI_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
18
  KOLIBRI_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
19
  KOLIBRI_EVENT_MOUSE = 6     /* Mouse activity (movement, button press) was detected */
20
};
21
 
22
void kolibri_handle_event_redraw(struct kolibri_window* some_window)
23
{
24
  /*  Draw windows with system color table. */
25
 
26
  BeginDraw();
27
 
6395 siemargl 28
  DrawWindow(some_window->topleftx, some_window->toplefty,
6391 ashmew2 29
	     some_window->sizex, some_window->sizey,
30
	     some_window->window_title,
31
	     kolibri_color_table.color_work_area, some_window->XY);
6395 siemargl 32
 
6391 ashmew2 33
  /* Enumerate and draw all window elements here */
34
  if(some_window->elements) /* Draw all elements added to window */
35
    {
6395 siemargl 36
      struct kolibri_window_element* current_element = some_window -> elements;
37
 
6391 ashmew2 38
      do
39
	{
40
	  /* The redraw_fn serves as draw_fn on initial draw */
41
	  if(kolibri_gui_op_table[current_element -> type].redraw_fn)
42
	    kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element);
6395 siemargl 43
 
44
//sie after fixing calling conventions no more needed
45
/*
6391 ashmew2 46
	  switch(current_element -> type)
47
	    {
48
	    case KOLIBRI_EDIT_BOX:
49
	    case KOLIBRI_CHECK_BOX:
6395 siemargl 50
	      __asm__ volatile("push $0x13371337"::); / * Random value pushed to balance stack * /
51
						      / * otherwise edit_box_draw leaves stack unbalanced * /
52
						      / * and GCC jumps like a crazy motha' fucka' * /
53
 
6391 ashmew2 54
	      break;
55
	    }
6395 siemargl 56
*/
57
	  current_element = current_element -> next;
6391 ashmew2 58
 
59
	} while(current_element != some_window->elements); /* Have we covered all elements? */
60
    }
61
}
62
 
63
void kolibri_handle_event_key(struct kolibri_window* some_window)
64
{
65
  /* Enumerate and trigger key handling functions of window elements here */
6395 siemargl 66
  if(some_window->elements)
6391 ashmew2 67
    {
6395 siemargl 68
      struct kolibri_window_element *current_element = some_window -> elements;
6391 ashmew2 69
 
70
      do
71
	{
72
	  /* Only execute if the function pointer isn't NULL */
73
	  if(kolibri_gui_op_table[current_element -> type].key_fn)
74
	    kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element);
6395 siemargl 75
 
6391 ashmew2 76
	  current_element = current_element -> next;
77
	} while(current_element != some_window->elements); /* Have we covered all elements? */
78
    }
79
}
80
 
81
void kolibri_handle_event_mouse(struct kolibri_window* some_window)
82
{
83
  /* Enumerate and trigger mouse handling functions of window elements here */
6395 siemargl 84
  if(some_window->elements)
6391 ashmew2 85
    {
6395 siemargl 86
      struct kolibri_window_element *current_element = some_window -> elements;
6391 ashmew2 87
 
88
      do
89
	{
90
	  if(kolibri_gui_op_table[current_element -> type].mouse_fn)
91
	    kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element);
92
 
93
	  current_element = current_element -> next;
6395 siemargl 94
 
6391 ashmew2 95
	} while(current_element != some_window->elements); /* Have we covered all elements? */
96
    }
97
}
98
 
99
void kolibri_exit(void)
100
{
101
  __asm__ volatile ("int $0x40"::"a"(-1));
102
}
103
 
104
int kolibri_gui_init(void)
105
{
106
  int boxlib_init_status = kolibri_boxlib_init();
107
 
6395 siemargl 108
  if(boxlib_init_status == 0)
6391 ashmew2 109
    debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n");
6395 siemargl 110
  else
6391 ashmew2 111
    {
112
      debug_board_write_str("ashmew2 is sad: Kolibri GUI Failed to initialize.\n");
113
      kolibri_exit();
114
    }
115
 
116
  /* Initialize the global operation table which handles event functions of */
117
  /* each individual element type */
118
  kolibri_init_gui_op_table();
119
 
120
  /* Get the current color table for Kolibri and store in global table*/
121
  kolibri_get_system_colors(&kolibri_color_table);
122
 
123
  /* Set up system events for buttons, mouse and keyboard and redraw */
124
  /* Also set filters so that window receives mouse events only when active
125
     and mouse inside window */
6395 siemargl 126
  __asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027));
127
 
128
  return boxlib_init_status;
6391 ashmew2 129
}
130
 
6395 siemargl 131
/* Note: The current implementation tries to automatically colors
6391 ashmew2 132
   GUI elements with system theme */
133
 
134
#endif /* KOLIBRI_GUI_H */