Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef KOLIBRI_EDITBOX_H
  2. #define KOLIBRI_EDITBOX_H
  3.  
  4. #include "kolibri_colors.h"
  5.  
  6. struct edit_box {
  7.   unsigned int width;
  8.     unsigned int left;
  9.     unsigned int top;
  10.     unsigned int color;
  11.     unsigned int shift_color;
  12.     unsigned int focus_border_color;
  13.     unsigned int blur_border_color;
  14.     unsigned int text_color;
  15.     unsigned int max;
  16.     char *text;
  17.     unsigned int mouse_variable;
  18.     unsigned int flags;
  19.  
  20. /* The following struct members are not used by the users of API */
  21.     unsigned int size;
  22.     unsigned int pos;
  23.     unsigned int offset;
  24.     unsigned int cl_curs_x;
  25.     unsigned int cl_curs_y;
  26.     unsigned int shift;
  27.     unsigned int shift_old;
  28. };
  29.  
  30. /* Initializes an Editbox with sane settings, sufficient for most use.
  31.    This will let you create a box and position it somewhere on the screen.
  32.    The text_buffer is a pointer to a character array and needs to be as long as
  33.    AT LEAST MAX_CHARS + 1.If the text_buffer is smaller, it will crash if user
  34.    types more characters than what will fit into the text buffer.
  35.  
  36.    Allocating buffer space automatically so that programmer can be carefree now.
  37.    This also automatically adjusts the size of edit box so that it can hold enough characters.
  38.  
  39.    All you need is :
  40.  
  41.    tlx,tly = Coordinates of the beginning of the edit box.
  42.    max_chars = Limit of number of characters user can enter into edit box.
  43. */
  44.  
  45. struct edit_box* kolibri_new_edit_box(unsigned int tlx, unsigned int tly, unsigned int max_chars)
  46. {
  47.     unsigned int PIXELS_PER_CHAR = 7;
  48.     struct edit_box *new_textbox = (struct edit_box *)malloc(sizeof(struct edit_box));
  49.     char *text_buffer = (char *)calloc(max_chars + 1, sizeof(char));
  50.  
  51.     /* Update blur_border_color and shift_color from box_lib.mac macro */
  52.     /* edit_boxes_set_sys_color */
  53.  
  54.     new_textbox -> width = max_chars * PIXELS_PER_CHAR;
  55.     new_textbox -> left = tlx;
  56.     new_textbox -> top = tly;
  57.     new_textbox -> color = 0xFFFFFF; /* Always make white edit boxes */
  58.     new_textbox -> shift_color = 0x6a9480;
  59.     new_textbox -> focus_border_color = kolibri_color_table.color_work_graph;
  60.     new_textbox -> blur_border_color = 0x6a9480;
  61.     new_textbox -> text_color = kolibri_color_table.color_work_text; /* Always black text when typing */
  62.     new_textbox -> max = max_chars;
  63.     new_textbox -> text = text_buffer;
  64.     new_textbox -> mouse_variable = 1; /* let the mouse take control? */
  65.     new_textbox -> flags = 0x00000000;
  66.     /* If these lines are uncommented, the executable will crash for no reason at start */
  67.     /* Even though these lines are not ever read it ALWAYS causes a crash, even crashes MTDBG. What gives? */
  68.  
  69.     new_textbox -> size = 0;
  70.     new_textbox -> pos = 0;
  71.     new_textbox -> offset = 0;
  72.     new_textbox -> cl_curs_x = 0;
  73.     new_textbox -> cl_curs_y = 0;
  74.     new_textbox -> shift = 0;
  75.     new_textbox -> shift_old = 0;
  76.  
  77.     return new_textbox;
  78. }
  79.  
  80. extern void (*edit_box_draw)(struct edit_box *) __attribute__((__stdcall__));
  81.  
  82. /* editbox_key is a wrapper written in assembly to handle key press events for editboxes */
  83. /* because inline assembly in GCC is a PITA and interferes with the EAX (AH) register */
  84. /* which edit_box_key requires */
  85. extern void editbox_key(struct edit_box *) __attribute__((__stdcall__));
  86.  
  87. extern void (*edit_box_mouse)(struct edit_box *) __attribute__((__stdcall__));
  88. extern volatile unsigned press_key;
  89. #endif /* KOLIBRI_EDITBOX_H */
  90.