8 typedef struct W_ColorWell
{
22 unsigned int active
:1;
23 unsigned int bordered
:1;
28 static void destroyColorWell(ColorWell
*cPtr
);
29 static void paintColorWell(ColorWell
*cPtr
);
31 static void handleEvents(XEvent
*event
, void *data
);
33 static void handleDragEvents(XEvent
*event
, void *data
);
35 static void handleActionEvents(XEvent
*event
, void *data
);
37 static void resizeColorWell();
39 W_ViewProcedureTable _ColorWellViewProcedures
= {
47 static WMDragSourceProcs dragProcs
= {
52 #define DEFAULT_WIDTH 60
53 #define DEFAULT_HEIGHT 30
54 #define DEFAULT_BORDER_WIDTH 6
62 WMCreateColorWell(WMWidget
*parent
)
66 cPtr
= wmalloc(sizeof(ColorWell
));
67 memset(cPtr
, 0, sizeof(ColorWell
));
69 cPtr
->widgetClass
= WC_ColorWell
;
71 cPtr
->view
= W_CreateView(W_VIEW(parent
));
77 cPtr
->colorView
= W_CreateView(cPtr
->view
);
78 if (!cPtr
->colorView
) {
79 W_DestroyView(cPtr
->view
);
84 WMCreateEventHandler(cPtr
->view
, ExposureMask
|StructureNotifyMask
85 |ClientMessageMask
, handleEvents
, cPtr
);
87 WMCreateEventHandler(cPtr
->colorView
, ExposureMask
, handleEvents
, cPtr
);
89 WMCreateEventHandler(cPtr
->colorView
, ButtonPressMask
|Button1MotionMask
,
90 handleDragEvents
, cPtr
);
92 WMCreateEventHandler(cPtr
->view
, ButtonPressMask
, handleActionEvents
,
95 cPtr
->colorView
->flags
.mapWhenRealized
= 1;
97 resizeColorWell(cPtr
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
104 WMSetColorWellColor(WMColorWell
*cPtr
, WMColor
*color
)
107 WMReleaseColor(cPtr
->color
);
109 cPtr
->color
= WMRetainColor(color
);
111 if (cPtr
->colorView
->flags
.realized
&& cPtr
->colorView
->flags
.mapped
)
112 paintColorWell(cPtr
);
117 WMGetColorWellColor(WMColorWell
*cPtr
)
122 #define MIN(a,b) ((a) > (b) ? (b) : (a))
125 resizeColorWell(WMColorWell
*cPtr
, unsigned int width
, unsigned int height
)
129 if (width
< MIN_WIDTH
)
131 if (height
< MIN_HEIGHT
)
134 bw
= (int)((float)MIN(width
, height
)*0.24);
136 W_ResizeView(cPtr
->view
, width
, height
);
138 W_ResizeView(cPtr
->colorView
, width
-2*bw
, height
-2*bw
);
140 if (cPtr
->colorView
->pos
.x
!=bw
|| cPtr
->colorView
->pos
.y
!=bw
)
141 W_MoveView(cPtr
->colorView
, bw
, bw
);
146 paintColorWell(ColorWell
*cPtr
)
148 W_Screen
*scr
= cPtr
->view
->screen
;
150 W_DrawRelief(scr
, cPtr
->view
->window
, 0, 0, cPtr
->view
->size
.width
,
151 cPtr
->view
->size
.height
, WRRaised
);
153 W_DrawRelief(scr
, cPtr
->colorView
->window
, 0, 0,
154 cPtr
->colorView
->size
.width
, cPtr
->colorView
->size
.height
,
158 WMPaintColorSwatch(cPtr
->color
, cPtr
->colorView
->window
,
159 2, 2, cPtr
->colorView
->size
.width
-4,
160 cPtr
->colorView
->size
.height
-4);
166 handleEvents(XEvent
*event
, void *data
)
168 ColorWell
*cPtr
= (ColorWell
*)data
;
170 CHECK_CLASS(data
, WC_ColorWell
);
173 switch (event
->type
) {
175 if (event
->xexpose
.count
!=0)
177 paintColorWell(cPtr
);
181 destroyColorWell(cPtr
);
189 makeDragPixmap(WMColorWell
*cPtr
)
191 WMScreen
*scr
= cPtr
->view
->screen
;
194 pix
= XCreatePixmap(scr
->display
, W_DRAWABLE(scr
), 16, 16, scr
->depth
);
196 XFillRectangle(scr
->display
, pix
, WMColorGC(cPtr
->color
), 0, 0, 15, 15);
198 XDrawRectangle(scr
->display
, pix
, WMColorGC(scr
->black
), 0, 0, 15, 15);
200 return WMCreatePixmapFromXPixmaps(scr
, pix
, None
, 16, 16, scr
->depth
);
206 handleDragEvents(XEvent
*event
, void *data
)
208 WMColorWell
*cPtr
= (ColorWell
*)data
;
210 switch (event
->type
) {
212 if (event
->xbutton
.button
== Button1
) {
213 cPtr
->ipoint
.x
= event
->xbutton
.x
;
214 cPtr
->ipoint
.y
= event
->xbutton
.y
;
219 if (event
->xmotion
.state
& Button1Mask
) {
220 if (abs(cPtr
->ipoint
.x
- event
->xmotion
.x
) > 4
221 || abs(cPtr
->ipoint
.y
- event
->xmotion
.y
) > 4) {
227 pixmap
= makeDragPixmap(cPtr
);
229 WMDragImageFromView(cPtr
->view
, pixmap
, cPtr
->view
->pos
,
232 WMReleasePixmap(pixmap
);
242 handleActionEvents(XEvent
*event
, void *data
)
244 /* WMColorWell *cPtr = (ColorWell*)data;*/
250 destroyColorWell(ColorWell
*cPtr
)
253 WMReleaseColor(cPtr
->color
);