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_EDITBOX_H
  2. #define KOLIBRI_EDITBOX_H
  3.  
  4. #include "kolibri_colors.h"
  5.  
  6. /*  flags meaning
  7. ed_figure_only= 1000000000000000b   ;îäíè ñèìâîëû
  8. ed_always_focus= 100000000000000b
  9. ed_focus=                     10b   ;ôîêóñ ïðèëîæåíèÿ
  10. ed_pass=                       1b   ;ïîëå ñ ïàðîëåì
  11. ed_shift_on=                1000b   ;åñëè íå óñòàíîâëåí -çíà÷èò âïåðâûå íàæàò shift,åñëè áûë óñòàíîâëåí, çíà÷èò ìû óæå ÷òî - òî äåëàëè óäåðæèâàÿ shift
  12. ed_shift_on_off=1111111111110111b
  13. ed_shift=                    100b   ;âêëþ÷àåòñÿ ïðè íàæàòèè íà shift ò.å. åñëè íàæèìàþ
  14. ed_shift_off=   1111111111111011b
  15. ed_shift_bac=              10000b   ;áèò äëÿ î÷èñòêè âûäåëåíîãî shift ò.å. ïðè óñòàíîâêå ãîâîðèò ÷òî åñòü âûäåëåíèå
  16. ed_shift_bac_cl=1111111111101111b   ;î÷èñòêà ïðè óäàëåíèè âûäåëåíèÿ
  17. ed_shift_cl=    1111111111100011b
  18. ed_shift_mcl=   1111111111111011b
  19. ed_left_fl=               100000b
  20. ed_right_fl=    1111111111011111b
  21. ed_offset_fl=            1000000b
  22. ed_offset_cl=   1111111110111111b
  23. ed_insert=              10000000b
  24. ed_insert_cl=   1111111101111111b
  25. ed_mouse_on =          100000000b
  26. ed_mous_adn_b=         100011000b
  27. ed_mouse_on_off=1111111011111111b
  28. */
  29.  
  30. typedef struct {
  31.   unsigned int width;
  32.     unsigned int left;
  33.     unsigned int top;
  34.     unsigned int color;
  35.     unsigned int shift_color;   // selected text color
  36.     unsigned int focus_border_color;
  37.     unsigned int blur_border_color;
  38.     unsigned int text_color;
  39.     unsigned int max;
  40.     char *text;
  41.     unsigned int mouse_variable; // mus be int* pointer to saved mouse pos ??
  42.     unsigned int flags;
  43.  
  44.     unsigned int size;  // used symbols in buffer without trailing zero
  45.     unsigned int pos;  // cursor position
  46. /* The following struct members are not used by the users of API */
  47.     unsigned int offset;
  48.     unsigned int cl_curs_x;
  49.     unsigned int cl_curs_y;
  50.     unsigned int shift;
  51.     unsigned int shift_old;
  52. }edit_box;
  53.  
  54. /* Initializes an Editbox with sane settings, sufficient for most use.
  55.    This will let you create a box and position it somewhere on the screen.
  56.    The text_buffer is a pointer to a character array and needs to be as long as
  57.    AT LEAST MAX_CHARS + 1.If the text_buffer is smaller, it will crash if user
  58.    types more characters than what will fit into the text buffer.
  59.  
  60.    Allocating buffer space automatically so that programmer can be carefree now.
  61.    This also automatically adjusts the size of edit box so that it can hold enough characters.
  62.  
  63.    All you need is :
  64.  
  65.    tlx,tly = Coordinates of the beginning of the edit box.
  66.    max_chars = Limit of number of characters user can enter into edit box.
  67. */
  68.  
  69. edit_box* kolibri_new_edit_box(unsigned int tlx, unsigned int tly, unsigned int max_chars)
  70. {
  71.     unsigned int PIXELS_PER_CHAR = 7;
  72.     edit_box *new_textbox = (edit_box *)malloc(sizeof(edit_box));
  73.     char *text_buffer = (char *)calloc(max_chars + 1, sizeof(char));
  74.  
  75.     /* Update blur_border_color and shift_color from box_lib.mac macro */
  76.     /* edit_boxes_set_sys_color */
  77.  
  78.     new_textbox -> width = max_chars * PIXELS_PER_CHAR;
  79.     new_textbox -> left = tlx;
  80.     new_textbox -> top = tly;
  81.     new_textbox -> color = 0xFFFFFF; /* Always make white edit boxes */
  82.     new_textbox -> shift_color = 0x6a9480;
  83.     new_textbox -> focus_border_color = kolibri_color_table.color_work_graph;
  84.     new_textbox -> blur_border_color = 0x6a9480;
  85.     new_textbox -> text_color = kolibri_color_table.color_work_text; /* Always black text when typing */
  86.     new_textbox -> max = max_chars;
  87.     new_textbox -> text = text_buffer;
  88.     new_textbox -> mouse_variable = 1; /* let the mouse take control? */
  89.     new_textbox -> flags = 0x00000000;
  90.     /* If these lines are uncommented, the executable will crash for no reason at start */
  91.     /* Even though these lines are not ever read it ALWAYS causes a crash, even crashes MTDBG. What gives? */
  92.  
  93.     new_textbox -> size = 0;
  94.     new_textbox -> pos = 0;
  95.     new_textbox -> offset = 0;
  96.     new_textbox -> cl_curs_x = 0;
  97.     new_textbox -> cl_curs_y = 0;
  98.     new_textbox -> shift = 0;
  99.     new_textbox -> shift_old = 0;
  100.  
  101.     return new_textbox;
  102. }
  103.  
  104. extern void (*edit_box_draw)(edit_box *) __attribute__((__stdcall__));
  105.  
  106. /* editbox_key is a wrapper written in assembly to handle key press events for editboxes */
  107. /* because inline assembly in GCC is a PITA and interferes with the EAX (AH) register */
  108. /* which edit_box_key requires */
  109. extern void editbox_key(edit_box *) __attribute__((__stdcall__));
  110.  
  111. extern void (*edit_box_mouse)(edit_box *) __attribute__((__stdcall__));
  112. extern void (*edit_box_set_text)(edit_box *, char *) __attribute__((__stdcall__));
  113. extern volatile unsigned press_key;
  114. #endif /* KOLIBRI_EDITBOX_H */
  115.