Subversion Repositories Kolibri OS

Rev

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