1 | #ifndef TEXTBOX_H |
---|
2 | #define TEXTBOX_H |
---|
3 | |
---|
4 | //flag 1: unused |
---|
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 | if(flag == 2) |
---|
21 | textbox->wrap = YES; |
---|
22 | else |
---|
23 | textbox->wrap = NO; |
---|
24 | |
---|
25 | changetitle(messagebox, title); |
---|
26 | if(width != 0) messagebox->width = width; |
---|
27 | if(height != 0) messagebox->height = height; |
---|
28 | |
---|
29 | changetext(textbox, text); |
---|
30 | |
---|
31 | button = getscreennode(messagebox, "b1"); |
---|
32 | if(b1 != NULL) |
---|
33 | { |
---|
34 | changetext(button, b1); |
---|
35 | button->hidden = NO; |
---|
36 | } |
---|
37 | else |
---|
38 | button->hidden = YES; |
---|
39 | |
---|
40 | button = getscreennode(messagebox, "b2"); |
---|
41 | if(b2 != NULL) |
---|
42 | { |
---|
43 | changetext(button, b2); |
---|
44 | button->hidden = NO; |
---|
45 | } |
---|
46 | else |
---|
47 | button->hidden = YES; |
---|
48 | |
---|
49 | button = getscreennode(messagebox, "b3"); |
---|
50 | if(b3 != NULL) |
---|
51 | { |
---|
52 | changetext(button, b3); |
---|
53 | button->hidden = NO; |
---|
54 | } |
---|
55 | else |
---|
56 | button->hidden = YES; |
---|
57 | |
---|
58 | button = getscreennode(messagebox, "b4"); |
---|
59 | if(b4 != NULL) |
---|
60 | { |
---|
61 | changetext(button, b4); |
---|
62 | button->hidden = NO; |
---|
63 | } |
---|
64 | else |
---|
65 | button->hidden = YES; |
---|
66 | |
---|
67 | |
---|
68 | if(fromthread == 1) |
---|
69 | { |
---|
70 | m_lock(&status.drawingmutex, 0); |
---|
71 | m_lock(&status.rcmutex, 10); |
---|
72 | tmpscreencalc = status.screencalc; |
---|
73 | status.screencalc = 2; |
---|
74 | setnodeattr(messagebox, framebuffer); |
---|
75 | status.screencalc = tmpscreencalc; |
---|
76 | status.rcowner = messagebox; |
---|
77 | bg = savescreen(messagebox); |
---|
78 | tmpscreencalc = status.screencalc; |
---|
79 | status.screencalc = 0; |
---|
80 | drawscreen(messagebox, 2); |
---|
81 | } |
---|
82 | else |
---|
83 | drawscreen(messagebox, 0); |
---|
84 | |
---|
85 | if(fromthread != 1) |
---|
86 | addscreenrc(messagebox, textbox); |
---|
87 | |
---|
88 | while(rcret != RCTIMEOUT && rcret != rc1 && rcret != rc2 && rcret != rc3 && rcret != rc4) |
---|
89 | rcret = waitrc(messagebox, timeout * 1000, 0); |
---|
90 | |
---|
91 | if(fromthread != 1) |
---|
92 | delownerrc(messagebox); |
---|
93 | |
---|
94 | if(fromthread == 1) |
---|
95 | { |
---|
96 | clearscreennolock(messagebox); |
---|
97 | restorescreen(bg, messagebox); |
---|
98 | blitfb(); |
---|
99 | status.screencalc = tmpscreencalc; |
---|
100 | sleep(1); |
---|
101 | status.rcowner = NULL; |
---|
102 | m_unlock(&status.rcmutex, 3); |
---|
103 | m_unlock(&status.drawingmutex, 0); |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | clearscreen(messagebox); |
---|
108 | drawscreen(skin, 0); |
---|
109 | } |
---|
110 | |
---|
111 | debug(1000, "out"); |
---|
112 | |
---|
113 | if(rcret == rc1) return 1; |
---|
114 | else if(rcret == rc2) return 2; |
---|
115 | else if(rcret == rc3) return 3; |
---|
116 | else if(rcret == rc4) return 4; |
---|
117 | else return 0; |
---|
118 | } |
---|
119 | |
---|
120 | #endif |
---|