Subversion Repositories Kolibri OS

Rev

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