Subversion Repositories Kolibri OS

Rev

Rev 6479 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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