Subversion Repositories Kolibri OS

Rev

Rev 6612 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6391 ashmew2 1
#ifndef KOLIBRI_EDITBOX_H
2
#define KOLIBRI_EDITBOX_H
3
 
4
#include "kolibri_colors.h"
6470 siemargl 5
 
6
/*  flags meaning
7
ed_figure_only= 1000000000000000b   ;одни символы
6612 siemargl 8
ed_always_focus= 100000000000000b   // всегда с курсором (фокусом)
9
ed_focus=                     10b   ;фокус ввода приложения, мышится самостоятельно
6470 siemargl 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
6479 siemargl 28
ed_mouse_on_off= not (ed_mouse_on)
29
ed_ctrl_on =          1000000000b
30
ed_ctrl_off = not (ed_ctrl_on)
31
ed_alt_on =          10000000000b
32
ed_alt_off = not (ed_alt_on)
33
ed_disabled=        100000000000b
6470 siemargl 34
*/
6391 ashmew2 35
 
6479 siemargl 36
typedef struct edit_box_t {
6470 siemargl 37
  unsigned int width;
6391 ashmew2 38
    unsigned int left;
6470 siemargl 39
    unsigned int top;
40
    unsigned int color;
41
    unsigned int shift_color;   // selected text color
42
    unsigned int focus_border_color;
6391 ashmew2 43
    unsigned int blur_border_color;
44
    unsigned int text_color;
45
    unsigned int max;
6612 siemargl 46
    char        *text;
47
    void        *mouse_variable; // must be pointer edit_box** to save focused editbox
6391 ashmew2 48
    unsigned int flags;
49
 
6470 siemargl 50
    unsigned int size;  // used symbols in buffer without trailing zero
51
    unsigned int pos;  // cursor position
6391 ashmew2 52
/* The following struct members are not used by the users of API */
53
    unsigned int offset;
54
    unsigned int cl_curs_x;
55
    unsigned int cl_curs_y;
56
    unsigned int shift;
57
    unsigned int shift_old;
6690 siemargl 58
    unsigned int height;
59
    unsigned int char_width;
6457 punk_joker 60
}edit_box;
6391 ashmew2 61
 
6470 siemargl 62
/* Initializes an Editbox with sane settings, sufficient for most use.
63
   This will let you create a box and position it somewhere on the screen.
64
   The text_buffer is a pointer to a character array and needs to be as long as
65
   AT LEAST MAX_CHARS + 1.If the text_buffer is smaller, it will crash if user
6391 ashmew2 66
   types more characters than what will fit into the text buffer.
67
 
68
   Allocating buffer space automatically so that programmer can be carefree now.
69
   This also automatically adjusts the size of edit box so that it can hold enough characters.
70
 
6470 siemargl 71
   All you need is :
6391 ashmew2 72
 
6470 siemargl 73
   tlx,tly = Coordinates of the beginning of the edit box.
6391 ashmew2 74
   max_chars = Limit of number of characters user can enter into edit box.
75
*/
76
 
6612 siemargl 77
edit_box* kolibri_new_edit_box(unsigned int tlx, unsigned int tly, unsigned int max_chars, void *editbox_interlock)
6391 ashmew2 78
{
79
    unsigned int PIXELS_PER_CHAR = 7;
6479 siemargl 80
    edit_box *new_textbox = (edit_box *)calloc(1, sizeof(edit_box));
81
    char *text_buffer = (char *)calloc(max_chars + 2, sizeof(char)); // +2 as asked in box_lib src
6391 ashmew2 82
 
83
    /* Update blur_border_color and shift_color from box_lib.mac macro */
84
    /* edit_boxes_set_sys_color */
85
 
86
    new_textbox -> width = max_chars * PIXELS_PER_CHAR;
87
    new_textbox -> left = tlx;
6470 siemargl 88
    new_textbox -> top = tly;
6391 ashmew2 89
    new_textbox -> color = 0xFFFFFF; /* Always make white edit boxes */
6470 siemargl 90
    new_textbox -> shift_color = 0x6a9480;
91
    new_textbox -> focus_border_color = kolibri_color_table.color_work_graph;
6391 ashmew2 92
    new_textbox -> blur_border_color = 0x6a9480;
93
    new_textbox -> text_color = kolibri_color_table.color_work_text; /* Always black text when typing */
94
    new_textbox -> max = max_chars;
95
    new_textbox -> text = text_buffer;
6479 siemargl 96
    new_textbox -> mouse_variable = editbox_interlock;
6393 punk_joker 97
    new_textbox -> flags = 0x00000000;
6391 ashmew2 98
 
99
    return new_textbox;
100
}
101
 
6457 punk_joker 102
extern void (*edit_box_draw)(edit_box *) __attribute__((__stdcall__));
6391 ashmew2 103
 
6612 siemargl 104
extern void (*edit_box_key)(edit_box *) __attribute__((__stdcall__));
6391 ashmew2 105
/* editbox_key is a wrapper written in assembly to handle key press events for editboxes */
106
/* because inline assembly in GCC is a PITA and interferes with the EAX (AH) register */
107
/* which edit_box_key requires */
6612 siemargl 108
__attribute__((__stdcall__)) void editbox_key(edit_box *e, oskey_t ch)
109
/// если flags не содержит ed_focus, игнорирует ввод
110
/// если flags содержит ed_mouse_on или ed_disabled, игнорирует ввод
111
/// на вводе ожидает ch - код клавиши, только в режиме ASCII
112
{
113
    __asm__ __volatile__ (
114
             "push %2\n\t"
115
             "call *%1 \n\t"::"a"(ch.val), "m"(edit_box_key), "m"(e):);
116
}
6391 ashmew2 117
 
6612 siemargl 118
extern void (*edit_box_mouse)(edit_box *) __attribute__((__stdcall__));
119
/// при щелчке не левой кнопкой, обнуляет *mouse_variable! и сбрасывает флаг ed_mouse_on
120
 
121
 
6470 siemargl 122
extern void (*edit_box_set_text)(edit_box *, char *) __attribute__((__stdcall__));
6393 punk_joker 123
extern volatile unsigned press_key;
6391 ashmew2 124
#endif /* KOLIBRI_EDITBOX_H */