1 /*
2 * Author: William Chia-Wei Cheng (bill.cheng@acm.org)
3 *
4 * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5 *
6 * This file may be distributed under the terms of the Q Public License
7 * as defined by Trolltech AS of Norway and appearing in the file
8 * LICENSE.QPL included in the packaging of this file.
9 *
10 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * @(#)$Header: /mm2/home/cvs/bc-src/tgif/tdgtdraw.c,v 1.7 2011/05/16 16:22:00 william Exp $
19 */
20
21 #define _INCLUDE_FROM_TDGTDRAW_C_
22
23 #include "tgifdefs.h"
24 #include "patchlvl.h"
25 #include "tidget.h"
26
27 #include "button.e"
28 #include "color.e"
29 #include "cursor.e"
30 #include "font.e"
31 #include "menu.e"
32 #include "msg.e"
33 #include "raster.e"
34 #include "rect.e"
35 #include "setup.e"
36 #include "tdgtdraw.e"
37 #include "tidget.e"
38 #include "util.e"
39
40 static void RedrawTdgtDraw ARGS_DECL((TidgetInfo *pti));
41 static int TdgtDrawEventHandler ARGS_DECL((TidgetInfo *pti, XEvent *input,
42 TidgetInfo *handling_pti));
43 static int IsTdgtDrawEvent ARGS_DECL((TidgetInfo *pti, XEvent *input,
44 TidgetInfo **ppti_handler_tidget_return));
45 static void DestroyTdgtDraw ARGS_DECL((TidgetInfo *pti));
46 static void MapTdgtDraw ARGS_DECL((TidgetInfo *pti));
47 static void TdgtDrawMoveResize ARGS_DECL((TidgetInfo *pti, int x, int y,
48 int w, int h));
49 static int TdgtDrawSendCmd ARGS_DECL((TidgetInfo *pti, int cmd_type,
50 int cmd_arg, void *pv_cmd_userdata));
51
52 /* --------------------- RedrawTdgtDraw() --------------------- */
53
54 static
RedrawTdgtDraw(pti)55 void RedrawTdgtDraw(pti)
56 TidgetInfo *pti;
57 {
58 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
59
60 XClearWindow(mainDisplay, pTdgtDraw->pti->tci.win);
61
62 if (threeDLook) {
63 struct BBRec bbox;
64
65 SetBBRec(&bbox, 0, 0, pTdgtDraw->pti->tci.win_info.w,
66 pTdgtDraw->pti->tci.win_info.h);
67 switch (pTdgtDraw->pti->tci.state) {
68 case TGBS_NORMAL: break;
69 default:
70 TgDrawThreeDButton(mainDisplay, pTdgtDraw->pti->tci.win,
71 gTidgetManager.gc, &bbox, pTdgtDraw->pti->tci.state, 2, FALSE);
72 TidgetManagerResetGC();
73 break;
74 }
75 } else {
76 /*
77 * XDrawRectangle(mainDisplay, pTdgtDraw->pti->tci.win, gTidgetManager.gc,
78 * 0, 0, pTdgtDraw->pti->tci.win_info.w,
79 * pTdgtDraw->pti->tci.win_info.h);
80 */
81 }
82 if (pTdgtDraw->pf_redraw_callback != NULL) {
83 if ((pTdgtDraw->pf_redraw_callback)(pTdgtDraw)) {
84 /* do nothing */
85 }
86 }
87 }
88
89 /* --------------------- TdgtDrawEventHandler() --------------------- */
90
91 static
TdgtDrawEventHandler(pti,input,handling_pti)92 int TdgtDrawEventHandler(pti, input, handling_pti)
93 TidgetInfo *pti, *handling_pti;
94 XEvent *input;
95 {
96 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
97
98 if (pti != handling_pti) return FALSE;
99
100 if (input->type == Expose) {
101 XEvent ev;
102
103 RedrawTdgtDraw(pTdgtDraw->pti);
104 while (XCheckWindowEvent(mainDisplay, pTdgtDraw->pti->tci.win,
105 ExposureMask, &ev)) ;
106 } else if (pTdgtDraw->pf_ev_handler_callback != NULL) {
107 return (pTdgtDraw->pf_ev_handler_callback)(pTdgtDraw, input);
108 }
109 return FALSE;
110 }
111
112 /* --------------------- IsTdgtDrawEvent() --------------------- */
113
114 static
IsTdgtDrawEvent(pti,input,ppti_handler_tidget_return)115 int IsTdgtDrawEvent(pti, input, ppti_handler_tidget_return)
116 TidgetInfo *pti, **ppti_handler_tidget_return;
117 XEvent *input;
118 {
119 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
120
121 if (input->xany.window == pTdgtDraw->pti->tci.win) {
122 *ppti_handler_tidget_return = pti;
123 return TRUE;
124 }
125 return FALSE;
126 }
127
128 /* --------------------- DestroyTdgtDraw() --------------------- */
129
130 static
DestroyTdgtDraw(pti)131 void DestroyTdgtDraw(pti)
132 TidgetInfo *pti;
133 {
134 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
135
136 TdgtDrawReset(pTdgtDraw);
137
138 free(pTdgtDraw);
139 }
140
141 /* --------------------- MapTdgtDraw() --------------------- */
142
143 static
MapTdgtDraw(pti)144 void MapTdgtDraw(pti)
145 TidgetInfo *pti;
146 {
147 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
148
149 #ifdef MAPBEFORESELECT
150 XMapWindow(mainDisplay, pTdgtDraw->pti->tci.win);
151 XSelectInput(mainDisplay, pTdgtDraw->pti->tci.win,
152 ButtonReleaseMask | ButtonPressMask | KeyPressMask | ExposureMask |
153 PointerMotionMask | EnterWindowMask | LeaveWindowMask);
154 #else
155 XSelectInput(mainDisplay, pTdgtDraw->pti->tci.win,
156 ButtonReleaseMask | ButtonPressMask | KeyPressMask | ExposureMask |
157 PointerMotionMask | EnterWindowMask | LeaveWindowMask);
158 XMapWindow(mainDisplay, pTdgtDraw->pti->tci.win);
159 #endif
160 }
161
162 /* --------------------- TdgtDrawMoveResize() --------------------- */
163
164 static
TdgtDrawMoveResize(pti,x,y,w,h)165 void TdgtDrawMoveResize(pti, x, y, w, h)
166 TidgetInfo *pti;
167 int x, y, w, h;
168 {
169 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
170
171 /* there should be no need to resize a button */
172 pTdgtDraw->pti->tci.win_info.x = x;
173 pTdgtDraw->pti->tci.win_info.y = y;
174 pTdgtDraw->pti->tci.win_info.w = w;
175 pTdgtDraw->pti->tci.win_info.h = h;
176 XMoveResizeWindow(mainDisplay, pTdgtDraw->pti->tci.win, x, y, w, h);
177 }
178
179 /* --------------------- TdgtDrawSendCmd() --------------------- */
180
181 static
TdgtDrawSendCmd(pti,cmd_type,cmd_arg,pv_cmd_userdata)182 int TdgtDrawSendCmd(pti, cmd_type, cmd_arg, pv_cmd_userdata)
183 TidgetInfo *pti;
184 int cmd_type, cmd_arg;
185 void *pv_cmd_userdata;
186 {
187 TdgtDraw *pTdgtDraw=(TdgtDraw*)(pti->tidget);
188
189 if (pTdgtDraw->pf_sendcmd_callback != NULL) {
190 return ((pTdgtDraw->pf_sendcmd_callback)(pTdgtDraw, cmd_type, cmd_arg,
191 pv_cmd_userdata));
192 }
193 return FALSE;
194 }
195
196 /* --------------------- TdgtDrawReset() --------------------- */
197
TdgtDrawReset(pTdgtDraw)198 void TdgtDrawReset(pTdgtDraw)
199 TdgtDraw *pTdgtDraw;
200 {
201 if (pTdgtDraw->pf_reset_callback != NULL) {
202 if ((pTdgtDraw->pf_reset_callback)(pTdgtDraw)) {
203 /* do nothing */
204 }
205 }
206 }
207
208 /* --------------------- CreateTdgtDraw() --------------------- */
209
CreateTdgtDraw(parent_win,parent_tidgetinfo,ctl_id,x,y,client_w,client_h,h_pad,v_pad,state,pv_userdata)210 TdgtDraw *CreateTdgtDraw(parent_win, parent_tidgetinfo, ctl_id, x, y, client_w,
211 client_h, h_pad, v_pad, state, pv_userdata)
212 Window parent_win;
213 TidgetInfo *parent_tidgetinfo;
214 int ctl_id, x, y, client_w, client_h, h_pad, v_pad, state;
215 void *pv_userdata;
216 {
217 TdgtDraw *pTdgtDraw=NULL;
218 int w=client_w+(windowPadding<<1)+(h_pad<<1);
219 int h=client_h+(windowPadding<<1)+(v_pad<<1);
220
221 pTdgtDraw = (TdgtDraw*)malloc(sizeof(TdgtDraw));
222 if (pTdgtDraw == NULL) FailAllocMessage();
223 memset(pTdgtDraw, 0, sizeof(TdgtDraw));
224
225 pTdgtDraw->pti = NewTidgetInfo(parent_tidgetinfo, TIDGET_TYPE_DRAW,
226 pTdgtDraw, ctl_id, NULL);
227 if ((pTdgtDraw->pti->tci.win=XCreateSimpleWindow(mainDisplay, parent_win,
228 x, y, w, h, brdrW, myBorderPixel, myBgPixel)) == 0) {
229 FailToCreateWindowMessage("CreateTdgtDraw()", NULL, TRUE);
230 }
231 XSelectInput(mainDisplay, pTdgtDraw->pti->tci.win,
232 ButtonReleaseMask | ButtonPressMask | KeyPressMask | ExposureMask |
233 PointerMotionMask | EnterWindowMask | LeaveWindowMask);
234 SetTidgetInfoBasic(pTdgtDraw->pti, TIDGET_TYPE_DRAW, pTdgtDraw, parent_win,
235 x, y, w, h, h_pad, v_pad, state, NULL);
236 TidgetSetCallbacks(pTdgtDraw->pti,
237 RedrawTdgtDraw, TdgtDrawEventHandler, IsTdgtDrawEvent, DestroyTdgtDraw,
238 MapTdgtDraw, TdgtDrawMoveResize, TdgtDrawSendCmd);
239
240 pTdgtDraw->client_area.x = windowPadding + h_pad;
241 pTdgtDraw->client_area.y = windowPadding + v_pad;
242 pTdgtDraw->client_area.w = w-(windowPadding<<1)-(h_pad<<1);
243 pTdgtDraw->client_area.h = h-(windowPadding<<1)-(v_pad<<1);
244
245 pTdgtDraw->pv_userdata = pv_userdata;
246
247 return pTdgtDraw;
248 }
249
250 /* --------------------- TdgtDrawSetUserData() --------------------- */
251
TdgtDrawSetUserData(pTdgtDraw,pv_userdata)252 int TdgtDrawSetUserData(pTdgtDraw, pv_userdata)
253 TdgtDraw *pTdgtDraw;
254 void *pv_userdata;
255 {
256 pTdgtDraw->pv_userdata = pv_userdata;
257 RedrawTdgtDraw(pTdgtDraw->pti);
258
259 return TRUE;
260 }
261
262 /* --------------------- TdgtDrawGetUserData() --------------------- */
263
TdgtDrawGetUserData(pTdgtDraw)264 char *TdgtDrawGetUserData(pTdgtDraw)
265 TdgtDraw *pTdgtDraw;
266 {
267 return (char*)(pTdgtDraw->pv_userdata);
268 }
269
270 /* --------------------- TdgtDrawSetState() --------------------- */
271
TdgtDrawSetState(pTdgtDraw,new_state)272 int TdgtDrawSetState(pTdgtDraw, new_state)
273 TdgtDraw *pTdgtDraw;
274 int new_state;
275 {
276 int need_to_redraw=(pTdgtDraw->pti->tci.state != new_state);
277
278 pTdgtDraw->pti->tci.state = new_state;
279 if (need_to_redraw) {
280 RedrawTdgtDraw(pTdgtDraw->pti);
281 }
282 return TRUE;
283 }
284
285 /* --------------------- TdgtDrawGetState() --------------------- */
286
TdgtDrawGetState(pTdgtDraw)287 int TdgtDrawGetState(pTdgtDraw)
288 TdgtDraw *pTdgtDraw;
289 {
290 return pTdgtDraw->pti->tci.state;
291 }
292
293 /* --------------------- TdgtDrawSetRedrawCallback() --------------------- */
294
TdgtDrawSetRedrawCallback(pTdgtDraw,pf_redraw_callback)295 void TdgtDrawSetRedrawCallback(pTdgtDraw, pf_redraw_callback)
296 TdgtDraw *pTdgtDraw;
297 TdgtDrawRedrawCallbackFunc *pf_redraw_callback;
298 {
299 pTdgtDraw->pf_redraw_callback = pf_redraw_callback;
300 }
301
302 /* --------------------- TdgtDrawSetEvHandlerCallback() --------------------- */
303
TdgtDrawSetEvHandlerCallback(pTdgtDraw,pf_ev_handler_callback)304 void TdgtDrawSetEvHandlerCallback(pTdgtDraw, pf_ev_handler_callback)
305 TdgtDraw *pTdgtDraw;
306 TdgtDrawEvHandlerCallbackFunc *pf_ev_handler_callback;
307 {
308 pTdgtDraw->pf_ev_handler_callback = pf_ev_handler_callback;
309 }
310
311 /* --------------------- TdgtDrawSetResetCallback() --------------------- */
312
TdgtDrawSetResetCallback(pTdgtDraw,pf_reset_callback)313 void TdgtDrawSetResetCallback(pTdgtDraw, pf_reset_callback)
314 TdgtDraw *pTdgtDraw;
315 TdgtDrawResetCallbackFunc *pf_reset_callback;
316 {
317 pTdgtDraw->pf_reset_callback = pf_reset_callback;
318 }
319
320 /* --------------------- TdgtDrawSetSendCmdCallback() --------------------- */
321
TdgtDrawSetSendCmdCallback(pTdgtDraw,pf_sendcmd_callback)322 void TdgtDrawSetSendCmdCallback(pTdgtDraw, pf_sendcmd_callback)
323 TdgtDraw *pTdgtDraw;
324 TdgtDrawSendCmdCallbackFunc *pf_sendcmd_callback;
325 {
326 pTdgtDraw->pf_sendcmd_callback = pf_sendcmd_callback;
327 }
328
329 /* --------------------- Init & Clean Up --------------------- */
330
InitTdgtDraw()331 int InitTdgtDraw()
332 {
333 return TRUE;
334 }
335
CleanUpTdgtDraw()336 void CleanUpTdgtDraw()
337 {
338 }
339