1 | #ifndef TEXTBOX_H |
---|
2 | #define TEXTBOX_H |
---|
3 | |
---|
4 | //flag 1: for barcode show |
---|
5 | //flag 2: enable wrap |
---|
6 | |
---|
7 | int textbox(char* title, char* text, char* b1, int rc1, char* b2, int rc2, char* b3, int rc3, char* b4, int rc4, int width, int height, int timeout, int flag) |
---|
8 | { |
---|
9 | debug(1000, "in"); |
---|
10 | int rcret = -1, tmpscreencalc = 0, fromthread = 0; |
---|
11 | struct skin* messagebox = getscreen("messagebox"); |
---|
12 | struct skin* textbox = getscreennode(messagebox, "textbox"); |
---|
13 | struct skin *button = NULL; |
---|
14 | struct skin* framebuffer = getscreen("framebuffer"); |
---|
15 | char* bg = NULL; |
---|
16 | |
---|
17 | if(pthread_self() != status.mainthread) |
---|
18 | fromthread = 1; |
---|
19 | |
---|
20 | //show barcode for cpuid |
---|
21 | if(flag == 1) |
---|
22 | { |
---|
23 | struct skin* tmp = addscreennode(messagebox, NULL, NULL); |
---|
24 | if(tmp != NULL) |
---|
25 | { |
---|
26 | char* tmpstr = NULL; |
---|
27 | |
---|
28 | tmpstr = ostrcat("*", getcpuid(), 0, 1); |
---|
29 | tmpstr = ostrcat(tmpstr, "*", 1, 0); |
---|
30 | changetext(tmp, tmpstr); |
---|
31 | free(tmpstr); tmpstr = NULL; |
---|
32 | tmp->fontsize = 40; |
---|
33 | tmp->halign = RIGHT; |
---|
34 | changefont(tmp, "free3of9x"); |
---|
35 | tmp->width = 100; |
---|
36 | tmp->prozwidth = 1; |
---|
37 | tmp->height = 40; |
---|
38 | tmp->del = 1; |
---|
39 | |
---|
40 | messagebox->hspace = 30; |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | if(flag == 2) |
---|
45 | textbox->wrap = YES; |
---|
46 | else |
---|
47 | textbox->wrap = NO; |
---|
48 | |
---|
49 | changetitle(messagebox, title); |
---|
50 | if(width != 0) messagebox->width = width; |
---|
51 | if(height != 0) messagebox->height = height; |
---|
52 | |
---|
53 | changetext(textbox, text); |
---|
54 | |
---|
55 | button = getscreennode(messagebox, "b1"); |
---|
56 | if(b1 != NULL) |
---|
57 | { |
---|
58 | changetext(button, b1); |
---|
59 | button->hidden = NO; |
---|
60 | } |
---|
61 | else |
---|
62 | button->hidden = YES; |
---|
63 | |
---|
64 | button = getscreennode(messagebox, "b2"); |
---|
65 | if(b2 != NULL) |
---|
66 | { |
---|
67 | changetext(button, b2); |
---|
68 | button->hidden = NO; |
---|
69 | } |
---|
70 | else |
---|
71 | button->hidden = YES; |
---|
72 | |
---|
73 | button = getscreennode(messagebox, "b3"); |
---|
74 | if(b3 != NULL) |
---|
75 | { |
---|
76 | changetext(button, b3); |
---|
77 | button->hidden = NO; |
---|
78 | } |
---|
79 | else |
---|
80 | button->hidden = YES; |
---|
81 | |
---|
82 | button = getscreennode(messagebox, "b4"); |
---|
83 | if(b4 != NULL) |
---|
84 | { |
---|
85 | changetext(button, b4); |
---|
86 | button->hidden = NO; |
---|
87 | } |
---|
88 | else |
---|
89 | button->hidden = YES; |
---|
90 | |
---|
91 | |
---|
92 | if(fromthread == 1) |
---|
93 | { |
---|
94 | m_lock(&status.drawingmutex, 0); |
---|
95 | m_lock(&status.rcmutex, 10); |
---|
96 | tmpscreencalc = status.screencalc; |
---|
97 | status.screencalc = 2; |
---|
98 | setnodeattr(messagebox, framebuffer); |
---|
99 | status.screencalc = tmpscreencalc; |
---|
100 | status.rcowner = messagebox; |
---|
101 | bg = savescreen(messagebox); |
---|
102 | tmpscreencalc = status.screencalc; |
---|
103 | status.screencalc = 0; |
---|
104 | drawscreen(messagebox, 2); |
---|
105 | } |
---|
106 | else |
---|
107 | drawscreen(messagebox, 0); |
---|
108 | |
---|
109 | if(fromthread != 1) |
---|
110 | addscreenrc(messagebox, textbox); |
---|
111 | |
---|
112 | while(rcret != RCTIMEOUT && rcret != rc1 && rcret != rc2 && rcret != rc3 && rcret != rc4) |
---|
113 | rcret = waitrc(messagebox, timeout * 1000, 0); |
---|
114 | |
---|
115 | if(fromthread != 1) |
---|
116 | delownerrc(messagebox); |
---|
117 | |
---|
118 | if(fromthread == 1) |
---|
119 | { |
---|
120 | clearscreennolock(messagebox); |
---|
121 | restorescreen(bg, messagebox); |
---|
122 | blitfb(0); |
---|
123 | status.screencalc = tmpscreencalc; |
---|
124 | sleep(1); |
---|
125 | status.rcowner = NULL; |
---|
126 | m_unlock(&status.rcmutex, 3); |
---|
127 | m_unlock(&status.drawingmutex, 0); |
---|
128 | } |
---|
129 | else |
---|
130 | { |
---|
131 | clearscreen(messagebox); |
---|
132 | drawscreen(skin, 0); |
---|
133 | } |
---|
134 | |
---|
135 | if(flag == 1) delmarkedscreennodes(messagebox, 1); |
---|
136 | |
---|
137 | debug(1000, "out"); |
---|
138 | |
---|
139 | if(rcret == rc1) return 1; |
---|
140 | else if(rcret == rc2) return 2; |
---|
141 | else if(rcret == rc3) return 3; |
---|
142 | else if(rcret == rc4) return 4; |
---|
143 | else return 0; |
---|
144 | } |
---|
145 | |
---|
146 | #endif |
---|