Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #ifndef __WINLIB_H__
  2. #define __WINLIB_H__
  3.  
  4. #include <stdlib.h>
  5. #include <kos32sys.h>
  6. #include "control.h"
  7.  
  8. enum win_state{
  9.       NORMAL, MINIMIZED, ROLLED, MAXIMIZED, FULLSCREEN
  10. };
  11.  
  12.  
  13. typedef struct
  14. {
  15.     link_t       link;
  16.     link_t       child;
  17.  
  18.     handler_t   *handler;
  19.     ctrl_t      *parent;
  20.  
  21.     ctx_t       *ctx;
  22.     font_t      *font;
  23.  
  24.     uint32_t     id;
  25.     uint32_t     style;
  26.  
  27.     rect_t       rc;
  28.     int          w;
  29.     int          h;
  30.  
  31.     rect_t       saved;
  32.     rect_t       client;
  33.     int          clw;
  34.     int          clh;
  35.  
  36.     char        *caption_txt;
  37.     ctrl_t      *child_over;
  38.     ctrl_t      *child_focus;
  39.  
  40.     enum win_state win_state;
  41.     enum win_state saved_state;
  42.  
  43. }window_t;
  44.  
  45.  
  46. #define HANDLE_MSG(ctrl, message, fn)    \
  47.     case (message): return HANDLE_##message((ctrl), (arg1), (arg2), (fn))
  48.  
  49. /* void ctrl_on_draw(ctrl_t *ctrl) */
  50. #define HANDLE_MSG_DRAW(ctrl, arg1, arg2, fn) \
  51.     ((fn)(ctrl),0)
  52.  
  53. /* void ctrl_on_ownerdraw(ctrl_t *ctrl, ctrl_t *child) */
  54. #define HANDLE_MSG_OWNERDRAW(ctrl, arg1, arg2, fn) \
  55.     ((fn)((ctrl),((ctrl_t*)arg1)),0)
  56.  
  57. /* void ctrl_on_poschanging(ctrl_t *ctrl, rect_t *pos) */
  58. #define HANDLE_MSG_POSCHANGING(ctrl, arg1, arg2, fn) \
  59.     ((fn)((ctrl),((rect_t*)arg2)),0)
  60.  
  61. /* void ctrl_on_poschange(ctrl_t *ctrl, rect_t *pos) */
  62. #define HANDLE_MSG_POSCHANGE(ctrl, arg1, arg2, fn) \
  63.     ((fn)((ctrl),((rect_t*)arg2)),0)
  64.  
  65. /* void ctrl_on_mouseenter(ctrl_t *ctrl) */
  66. #define HANDLE_MSG_MOUSEENTER(ctrl, arg1, arg2, fn) \
  67.     ((fn)(ctrl),0)
  68.  
  69. /* void ctrl_on_mouseleave(ctrl_t *ctrl) */
  70. #define HANDLE_MSG_MOUSELEAVE(ctrl, arg1, arg2, fn) \
  71.     ((fn)(ctrl),0)
  72.  
  73. /* void ctrl_on_lbuttondown(ctrl_t *ctrl, int x, int y) */
  74. #define HANDLE_MSG_LBTNDOWN(ctrl, arg1, arg2, fn) \
  75.     ((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
  76.  
  77. #define HANDLE_MSG_LBTNDBLCLK(ctrl, arg1, arg2, fn) \
  78.     ((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
  79.  
  80. /* void ctrl_on_lbuttonup(ctrl_t *ctrl, int x, int y) */
  81. #define HANDLE_MSG_LBTNUP(ctrl, arg1, arg2, fn) \
  82.     ((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
  83.  
  84. /* void ctrl_on_mousemove(ctrl_t *ctrl, int x, int y) */
  85. #define HANDLE_MSG_MOUSEMOVE(ctrl, arg1, arg2, fn) \
  86.     ((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
  87.  
  88. /* void ctrl_on_command(ctrl_t *ctrl, int id, ctrl_t *child, int notify) */
  89. #define HANDLE_MSG_COMMAND(ctrl,arg1,arg2,fn)       \
  90.     ((fn)((ctrl),(int)(arg1 & 0xFFFF),(ctrl_t*)(arg2),(int)(arg1>>16)),0)
  91.  
  92. window_t  *create_window(char *caption, int style, int x, int y,
  93.                             int w, int h, handler_t handler);
  94. int handle_system_events(window_t *win);
  95. void show_window(window_t *win);
  96.  
  97. extern ctrl_t  *mouse_capture;
  98.  
  99. static inline ctrl_t *capture_mouse(ctrl_t *newm)
  100. {
  101.     ctrl_t *old = mouse_capture;
  102.  
  103.     mouse_capture = newm;
  104.  
  105.     __asm__ __volatile__(
  106.     "int $0x40"
  107.     ::"a"(40), "b"(0x80000027));
  108.  
  109.     return old;
  110. }
  111.  
  112. static void release_mouse(void)
  113. {
  114.     mouse_capture = NULL;
  115.     __asm__ __volatile__(
  116.     "int $0x40"
  117.     ::"a"(40), "b"(0xC0000027));
  118. }
  119.  
  120. extern font_t *sym_font;
  121.  
  122. int draw_text_ext(ctx_t *ctx, font_t *font, char *text, int len, rect_t *rc, color_t color);
  123.  
  124. #endif /* __WINLIB_H__  */
  125.