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 = MIDDLE; |
---|
34 | tmp->valign = CENTER; |
---|
35 | |
---|
36 | changefont(tmp, "free3of9x"); |
---|
37 | tmp->width = 150; |
---|
38 | tmp->height = 50; |
---|
39 | tmp->bgcol = 0xffffff; |
---|
40 | tmp->fontcol = 0x000001; |
---|
41 | tmp->posx = 900; |
---|
42 | tmp->del = 1; |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | if(flag == 2) |
---|
47 | textbox->wrap = YES; |
---|
48 | else |
---|
49 | textbox->wrap = NO; |
---|
50 | |
---|
51 | changetitle(messagebox, title); |
---|
52 | if(width != 0) messagebox->width = width; |
---|
53 | if(height != 0) messagebox->height = height; |
---|
54 | |
---|
55 | changetext(textbox, text); |
---|
56 | |
---|
57 | button = getscreennode(messagebox, "b1"); |
---|
58 | if(b1 != NULL) |
---|
59 | { |
---|
60 | changetext(button, b1); |
---|
61 | button->hidden = NO; |
---|
62 | } |
---|
63 | else |
---|
64 | button->hidden = YES; |
---|
65 | |
---|
66 | button = getscreennode(messagebox, "b2"); |
---|
67 | if(b2 != NULL) |
---|
68 | { |
---|
69 | changetext(button, b2); |
---|
70 | button->hidden = NO; |
---|
71 | } |
---|
72 | else |
---|
73 | button->hidden = YES; |
---|
74 | |
---|
75 | button = getscreennode(messagebox, "b3"); |
---|
76 | if(b3 != NULL) |
---|
77 | { |
---|
78 | changetext(button, b3); |
---|
79 | button->hidden = NO; |
---|
80 | } |
---|
81 | else |
---|
82 | button->hidden = YES; |
---|
83 | |
---|
84 | button = getscreennode(messagebox, "b4"); |
---|
85 | if(b4 != NULL) |
---|
86 | { |
---|
87 | changetext(button, b4); |
---|
88 | button->hidden = NO; |
---|
89 | } |
---|
90 | else |
---|
91 | button->hidden = YES; |
---|
92 | |
---|
93 | |
---|
94 | if(fromthread == 1) |
---|
95 | { |
---|
96 | m_lock(&status.drawingmutex, 0); |
---|
97 | m_lock(&status.rcmutex, 10); |
---|
98 | tmpscreencalc = status.screencalc; |
---|
99 | status.screencalc = 2; |
---|
100 | setnodeattr(messagebox, framebuffer); |
---|
101 | status.screencalc = tmpscreencalc; |
---|
102 | status.rcowner = messagebox; |
---|
103 | bg = savescreen(messagebox); |
---|
104 | tmpscreencalc = status.screencalc; |
---|
105 | status.screencalc = 0; |
---|
106 | drawscreen(messagebox, 2); |
---|
107 | } |
---|
108 | else |
---|
109 | drawscreen(messagebox, 0); |
---|
110 | |
---|
111 | if(fromthread != 1) |
---|
112 | addscreenrc(messagebox, textbox); |
---|
113 | |
---|
114 | while(rcret != RCTIMEOUT && rcret != rc1 && rcret != rc2 && rcret != rc3 && rcret != rc4) |
---|
115 | rcret = waitrc(messagebox, timeout * 1000, 0); |
---|
116 | |
---|
117 | if(fromthread != 1) |
---|
118 | delownerrc(messagebox); |
---|
119 | |
---|
120 | if(fromthread == 1) |
---|
121 | { |
---|
122 | clearscreennolock(messagebox); |
---|
123 | restorescreen(bg, messagebox); |
---|
124 | blitfb(0); |
---|
125 | status.screencalc = tmpscreencalc; |
---|
126 | sleep(1); |
---|
127 | status.rcowner = NULL; |
---|
128 | m_unlock(&status.rcmutex, 3); |
---|
129 | m_unlock(&status.drawingmutex, 0); |
---|
130 | } |
---|
131 | else |
---|
132 | { |
---|
133 | clearscreen(messagebox); |
---|
134 | drawscreen(skin, 0); |
---|
135 | } |
---|
136 | |
---|
137 | if(flag == 1) delmarkedscreennodes(messagebox, 1); |
---|
138 | |
---|
139 | debug(1000, "out"); |
---|
140 | |
---|
141 | if(rcret == rc1) return 1; |
---|
142 | else if(rcret == rc2) return 2; |
---|
143 | else if(rcret == rc3) return 3; |
---|
144 | else if(rcret == rc4) return 4; |
---|
145 | else return 0; |
---|
146 | } |
---|
147 | |
---|
148 | #endif |
---|