Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef __CONTROL_H__
  2. #define __CONTROL_H_
  3.  
  4. #include <pixlib3.h>
  5. #include "link.h"
  6.  
  7. typedef struct
  8. {
  9.   int  l;
  10.   int  t;
  11.   int  r;
  12.   int  b;
  13. }rect_t;
  14.  
  15. typedef struct ctx
  16. {
  17.   int  offset_x;
  18.   int  offset_y;
  19.   int *pixmap_data;
  20.   int  pixmap_pitch;
  21. }ctx_t;
  22.  
  23. ctx_t *get_window_ctx();
  24.  
  25. typedef struct tag_control  ctrl_t;
  26.  
  27. typedef int (handler_t)(ctrl_t*, uint32_t, uint32_t, uint32_t);
  28.  
  29. struct tag_control
  30. {
  31.     link_t     link;
  32.     link_t     child;
  33.  
  34.     handler_t *handler;
  35.     ctrl_t    *parent;
  36.  
  37.     ctx_t     *ctx;
  38.     uint32_t   id;
  39.     uint32_t   style;
  40.  
  41.     rect_t     rc;
  42.     int        w;
  43.     int        h;
  44. };
  45.  
  46.  
  47. typedef struct timer
  48. {
  49.     link_t       link;
  50.     ctrl_t      *ctrl;
  51.     uint32_t     exp_time;            /* expiration time               */
  52.     uint32_t     tmr_arg;             /* random argument               */
  53. } ostimer_t;
  54.  
  55.  
  56. typedef struct
  57. {
  58.     ctrl_t  ctrl;
  59.  
  60.     uint32_t     state;
  61.     ostimer_t    timer;
  62.  
  63.     char        *caption;
  64.     int          capt_len;
  65.  
  66.     void        *img_default;
  67.     void        *img_hilite;
  68.     void        *img_pressed;
  69. }button_t;
  70.  
  71. typedef struct
  72. {
  73.     ctrl_t  ctrl;
  74.     float   min;
  75.     float   max;
  76.     float   current;
  77.     int     pos;
  78. }progress_t;
  79.  
  80. typedef struct
  81. {
  82.     ctrl_t  ctrl;
  83.     int     min;
  84.     int     max;
  85.     int     current;
  86.     int     pos;
  87.     int     vol;
  88.     int     visible;
  89.     void    *img_level;
  90. }level_t;
  91.  
  92. typedef struct
  93. {
  94.     ctrl_t  ctrl;
  95.     int     min;
  96.     int     max;
  97.     int     current;
  98.     int     pos;
  99.     int     mode;
  100.     void    *img_slider;
  101.     void    *img_vol_slider;
  102. }slider_t;
  103.  
  104. typedef struct
  105. {
  106.     link_t       link;
  107.     link_t       child;
  108.  
  109.     handler_t   *handler;
  110.     ctrl_t      *parent;
  111.  
  112.     ctx_t       *ctx;
  113.     uint32_t     id;
  114.     uint32_t     style;
  115.  
  116.     rect_t       rc;
  117.     int          w;
  118.     int          h;
  119.  
  120.     uint32_t     state;
  121.  
  122.     int          pix_range;
  123.  
  124.     int          min_range;
  125.     int          max_range;
  126.     int          page_size;
  127.     int          thumb_pos;
  128.  
  129.     rect_t       tl_rect;
  130.     rect_t       br_rect;
  131.  
  132.     button_t    *btn_up;
  133.     button_t    *btn_down;
  134.     button_t    *thumb;
  135. }scroller_t;
  136.  
  137. #define  bPressed              2
  138. #define  bHighlight            1
  139.  
  140. #define  MSG_PAINT         0x001
  141. #define  MSG_KEY           0x002
  142. #define  MSG_BUTTON        0x003
  143. #define  MSG_DRAW_CLIENT   0x004
  144.  
  145. #define  MSG_LBTNDOWN      0x010
  146. #define  MSG_LBTNUP        0x011
  147. #define  MSG_RBTNDOWN      0x012
  148. #define  MSG_RBTNUP        0x013
  149. #define  MSG_MBTNDOWN      0x014
  150. #define  MSG_MBTNUP        0x015
  151. #define  MSG_WHEELDOWN     0x016
  152. #define  MSG_WHEELUP       0x017
  153.  
  154. #define  MSG_LBTNDBLCLK    0x018
  155.  
  156. #define  MSG_MOUSEMOVE     0x019
  157. #define  MSG_MOUSEENTER    0x01A
  158. #define  MSG_MOUSELEAVE    0x01B
  159.  
  160. #define  MSG_SIZE          0x020
  161.  
  162. #define  MSG_COMMAND       0x030
  163. #define  MSG_TIMER         0x031
  164.  
  165. #define  LBN_DBLCLK        0x100
  166. #define  LBOX_READDIR      0x100
  167. #define  LBOX_GETFILENAME  0x101
  168.  
  169. #define  PRG_PROGRESS      0x102
  170.  
  171. #define  ID_CLOSE              1
  172. #define  ID_MINIMIZE           2
  173. #define  ID_FULLSCREEN         3
  174.  
  175. #define  ID_SCROLLER_UP       10
  176. #define  ID_SCROLLER_DOWN     11
  177. #define  ID_SCROLLER_THUMB    12
  178.  
  179. #define  send_message( ctrl, msg, arg1, arg2)              \
  180.                 (ctrl)->handler( (ctrl_t*)(ctrl),          \
  181.                 (uint32_t)(msg), (uint32_t)(arg1), (uint32_t)(arg2))
  182.  
  183. static inline handler_t *subclass_control(ctrl_t *ctrl, handler_t *handler)
  184. {
  185.     handler_t *old = ctrl->handler;
  186.     ctrl->handler = handler;
  187.     return old;
  188. };
  189.  
  190. //int inline send_message(ctrl_t *ctrl, u32_t msg, u32_t arg1, u32_t arg2)
  191. //{
  192. //  return ctrl->handler(ctrl, msg, arg1, arg2);
  193. //};
  194.  
  195. static inline int pt_in_rect(rect_t *rc, int x, int y)
  196. {
  197.     if( (x >= rc->l) && (x <  rc->r) &&
  198.         (y >= rc->t) && (y <  rc->b) )
  199.         return 1;
  200.     return 0;
  201. };
  202.  
  203. ctrl_t *get_child(ctrl_t *ctrl, int x, int y);
  204.  
  205. ctrl_t *capture_mouse(ctrl_t *newm);
  206.  
  207. void blit_raw(ctx_t *ctx, void *raw, int x, int y, int w, int h, int pitch);
  208.  
  209. #define __ALIGN_MASK(x,mask)  (((x)+(mask))&~(mask))
  210. #define ALIGN(x,a)            __ALIGN_MASK(x,(typeof(x))(a)-1)
  211.  
  212.  
  213. #endif
  214.