Subversion Repositories Kolibri OS

Rev

Rev 6470 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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 {
  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 */
  23. };
  24.  
  25. #define BUTTON_CLOSE 0x1
  26. #define BTN_QUIT 1
  27.  
  28. void kolibri_handle_event_redraw(kolibri_window* some_window)
  29. {
  30.   /*  Draw windows with system color table. */
  31.  
  32.   BeginDraw();
  33.  
  34.   DrawWindow(some_window->topleftx, some_window->toplefty,
  35.              some_window->sizex, some_window->sizey,
  36.              some_window->window_title,
  37.              kolibri_color_table.color_work_area, some_window->XY);
  38.  
  39.   /* Enumerate and draw all window elements here */
  40.   if(some_window->elements) /* Draw all elements added to window */
  41.     {
  42.       kolibri_window_element* current_element = some_window -> elements;
  43.  
  44.       do
  45.         {
  46.           /* The redraw_fn serves as draw_fn on initial draw */
  47.           if((int)kolibri_gui_op_table[current_element -> type].redraw_fn > 0)  // -1 if DLL link fail
  48.             kolibri_gui_op_table[current_element -> type].redraw_fn(current_element -> element);
  49.  
  50. //sie after fixing calling conventions no more needed
  51. /*
  52.           switch(current_element -> type)
  53.             {
  54.             case KOLIBRI_EDIT_BOX:
  55.             case KOLIBRI_CHECK_BOX:
  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.  
  60.               break;
  61.             }
  62. */
  63.           current_element = current_element -> next;
  64.  
  65.         } while(current_element != some_window->elements); /* Have we covered all elements? */
  66.     }
  67. }
  68.  
  69. void kolibri_handle_event_key(kolibri_window* some_window)
  70. {
  71.   /* Enumerate and trigger key handling functions of window elements here */
  72.   if(some_window->elements)
  73.     {
  74.       kolibri_window_element *current_element = some_window -> elements;
  75.  
  76.       do
  77.         {
  78.           /* Only execute if the function pointer isn't NULL */
  79.           if((int)kolibri_gui_op_table[current_element -> type].key_fn > 0)
  80.             kolibri_gui_op_table[current_element -> type].key_fn(current_element -> element);
  81.  
  82.           current_element = current_element -> next;
  83.         } while(current_element != some_window->elements); /* Have we covered all elements? */
  84.     }
  85. }
  86.  
  87. void kolibri_handle_event_mouse(kolibri_window* some_window)
  88. {
  89.   /* Enumerate and trigger mouse handling functions of window elements here */
  90.   if(some_window->elements)
  91.     {
  92.       kolibri_window_element *current_element = some_window -> elements;
  93.  
  94.       do
  95.         {
  96.           if((int)kolibri_gui_op_table[current_element -> type].mouse_fn > 0)
  97.             kolibri_gui_op_table[current_element -> type].mouse_fn(current_element -> element);
  98.  
  99.           current_element = current_element -> next;
  100.  
  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.  
  114.   if(boxlib_init_status == 0)
  115.     debug_board_write_str("ashmew2 is happy: Kolibri GUI Successfully Initialized.\n");
  116.   else
  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 */
  132.   __asm__ volatile("int $0x40"::"a"(40), "b"(0xC0000027));
  133.  
  134.   return boxlib_init_status;
  135. }
  136.  
  137. /* Note: The current implementation tries to automatically colors
  138.    GUI elements with system theme */
  139.  
  140. #endif /* KOLIBRI_GUI_H */
  141.