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/tgcwheel.c,v 1.5 2011/06/02 15:53:08 william Exp $
19 */
20
21 #define _INCLUDE_FROM_TGCWHEEL__C_
22
23 #include "tgifdefs.h"
24 #include "tidget.h"
25
26 #include "auxtext.e"
27 #include "dialog.e"
28 #include "font.e"
29 #include "msg.e"
30 #include "setup.e"
31 #include "strtbl.e"
32 #include "tgcwheel.e"
33 #include "tgcwdl.e"
34 #include "tidget.e"
35 #include "util.e"
36
37 /* --------------------- Init & Clean Up --------------------- */
38
TgColorWheel_CleanUp(dpy,win)39 void TgColorWheel_CleanUp(dpy, win)
40 Display *dpy;
41 Window win;
42 {
43 if (gColorWheelInfo.initialized) {
44 if (gColorWheelInfo.dialogbox_tidgetinfo != NULL) {
45 DestroyTdgtColorWheelDialogBox(dpy,
46 gColorWheelInfo.dialogbox_tidgetinfo);
47 }
48 }
49 if (gColorWheelInfo.hs_pixmap != None) {
50 XFreePixmap(mainDisplay, gColorWheelInfo.hs_pixmap);
51 }
52 if (gColorWheelInfo.v_pixmap != None) {
53 XFreePixmap(mainDisplay, gColorWheelInfo.v_pixmap);
54 }
55 memset(&gColorWheelInfo, 0, sizeof(ColorWheelInfo));
56
57 CleanUpTdgtColorWheelDlg();
58 }
59
TgColorWheel_Init(dpy,win,arg)60 int TgColorWheel_Init(dpy, win, arg)
61 Display *dpy;
62 Window win;
63 char *arg;
64 {
65 memset(&gColorWheelInfo, 0, sizeof(ColorWheelInfo));
66
67 gColorWheelInfo.hs_pixmap = XCreatePixmap(mainDisplay, rootWindow, HS_WIDTH,
68 HS_HEIGHT, mainDepth);
69 if (arg != NULL) {
70 UtilStrCpyN(gColorWheelInfo.color_str, sizeof(gColorWheelInfo.color_str),
71 arg);
72 }
73 if (gColorWheelInfo.hs_pixmap == None) {
74 FailAllocPixmapMessage(HS_WIDTH, HS_HEIGHT);
75 TgColorWheel_CleanUp(dpy, win);
76 return FALSE;
77 }
78 gColorWheelInfo.v_pixmap = XCreatePixmap(mainDisplay, rootWindow, V_WIDTH,
79 V_HEIGHT, mainDepth);
80 if (gColorWheelInfo.v_pixmap == None) {
81 FailAllocPixmapMessage(V_WIDTH, V_HEIGHT);
82 TgColorWheel_CleanUp(dpy, win);
83 return FALSE;
84 }
85 if (!InitTdgtColorWheelDlg()) {
86 TgColorWheel_CleanUp(dpy, win);
87
88 return FALSE;
89 }
90 return TRUE;
91 }
92
CleanUpColorWheel()93 void CleanUpColorWheel()
94 {
95 TgColorWheel_CleanUp(mainDisplay, drawWindow);
96 }
97
InitColorWheel()98 int InitColorWheel()
99 {
100 return TgColorWheel_Init(mainDisplay, drawWindow, NULL);
101 }
102
103 /* --------------------- TgColorWheel_SendKey --------------------- */
104
105 static XComposeStatus c_stat;
106
TgColorWheel_SendKey(dpy,win,key_ev,buf)107 int TgColorWheel_SendKey(dpy, win, key_ev, buf)
108 Display *dpy;
109 Window win;
110 XKeyEvent *key_ev;
111 char *buf;
112 /* return FALSE means key_ev will be handled without modifications */
113 {
114 int has_ch=0;
115 char s[80];
116 KeySym key_sym=(KeySym)0;
117
118 has_ch = XLookupString(key_ev, s, sizeof(s), &key_sym, &c_stat);
119 TranslateKeys(s, &key_sym);
120
121 return FALSE;
122 }
123
124 /* --------------------- TgColorWheel_HandleCntrlSpace --------------------- */
125
TgColorWheel_HandleCntrlSpace(dpy,win)126 int TgColorWheel_HandleCntrlSpace(dpy, win)
127 Display *dpy;
128 Window win;
129 {
130 if (!gColorWheelInfo.initialized) {
131 gColorWheelInfo.initialized = TRUE;
132 /* create window */
133 gColorWheelInfo.dialogbox_tidgetinfo =
134 CreateTdgtColorWheelDialogBox(dpy, rootWindow);
135 if (gColorWheelInfo.dialogbox_tidgetinfo == NULL) {
136 /* print a message */
137 }
138 }
139 if (gColorWheelInfo.dialogbox_tidgetinfo == NULL) {
140 return FALSE;
141 }
142 if (!gColorWheelInfo.mapped) {
143 ShowTdgtColorWheelDialogBox();
144 TdgtColorWheelDlgLoop(gColorWheelInfo.dialogbox_tidgetinfo);
145 } else {
146 HideTdgtColorWheelDialogBox();
147 }
148 return FALSE;
149 }
150
151 /* --------------------- TgColorWheel_HandleCreateText --------------------- */
152
TgColorWheel_HandleCreateText(dpy,win)153 int TgColorWheel_HandleCreateText(dpy, win)
154 Display *dpy;
155 Window win;
156 {
157 if (gColorWheelInfo.initialized && gColorWheelInfo.mapped) {
158 HideTdgtColorWheelDialogBox();
159 }
160 return TRUE;
161 }
162
163