3 * Widget for testing double-clicks
7 #include <WINGs/WINGsP.h>
12 typedef struct W_DoubleTest
{
25 /* some forward declarations */
27 static void destroyDoubleTest(_DoubleTest
*dPtr
);
28 static void paintDoubleTest(_DoubleTest
*dPtr
);
31 static void handleEvents(XEvent
*event
, void *data
);
32 static void handleActionEvents(XEvent
*event
, void *data
);
36 /* our widget class ID */
37 static W_Class DoubleTestClass
= 0;
41 * Initializer for our widget. Must be called before creating any
42 * instances of the widget.
45 InitDoubleTest(WMScreen
*scr
)
47 /* register our widget with WINGs and get our widget class ID */
48 if (!DoubleTestClass
) {
49 DoubleTestClass
= W_RegisterUserWidget();
52 return DoubleTestClass
;
57 * Our widget fabrication plant.
60 CreateDoubleTest(WMWidget
*parent
, char *text
)
65 InitDoubleTest(WMWidgetScreen(parent
));
67 /* allocate some storage for our new widget instance */
68 dPtr
= wmalloc(sizeof(DoubleTest
));
70 memset(dPtr
, 0, sizeof(DoubleTest
));
72 /* set the class ID */
73 dPtr
->widgetClass
= DoubleTestClass
;
75 dPtr
->view
= W_CreateView(W_VIEW(parent
));
81 dPtr
->view
->self
= dPtr
;
83 dPtr
->text
= wstrdup(text
);
85 WMCreateEventHandler(dPtr
->view
, ExposureMask
/* this allows us to know when we should paint */
86 |StructureNotifyMask
, /* this allows us to know things like when we are destroyed */
89 WMCreateEventHandler(dPtr
->view
, ButtonPressMask
,handleActionEvents
, dPtr
);
97 paintDoubleTest(_DoubleTest
*dPtr
)
99 W_Screen
*scr
= dPtr
->view
->screen
;
102 XFillRectangle(scr
->display
, dPtr
->view
->window
, WMColorGC(scr
->white
),
103 0, 0, dPtr
->view
->size
.width
, dPtr
->view
->size
.height
);
105 XClearWindow(scr
->display
, dPtr
->view
->window
);
108 W_DrawRelief(scr
, dPtr
->view
->window
, 0, 0, dPtr
->view
->size
.width
,
109 dPtr
->view
->size
.height
, dPtr
->on
? WRSunken
: WRRaised
);
113 y
= (dPtr
->view
->size
.height
-scr
->normalFont
->height
)/2;
114 W_PaintText(dPtr
->view
, dPtr
->view
->window
, scr
->normalFont
,
115 dPtr
->on
, dPtr
->on
+y
, dPtr
->view
->size
.width
, WACenter
,
116 WMColorGC(scr
->black
), False
, dPtr
->text
, strlen(dPtr
->text
));
123 handleEvents(XEvent
*event
, void *data
)
125 _DoubleTest
*dPtr
= (_DoubleTest
*)data
;
128 switch (event
->type
) {
130 if (event
->xexpose
.count
!=0)
132 paintDoubleTest(dPtr
);
136 destroyDoubleTest(dPtr
);
144 deactivate(void *data
)
146 _DoubleTest
*dPtr
= (_DoubleTest
*)data
;
150 paintDoubleTest(dPtr
);
157 handleActionEvents(XEvent
*event
, void *data
)
159 _DoubleTest
*dPtr
= (_DoubleTest
*)data
;
160 extern _WINGsConfiguration WINGsConfiguration
;
162 switch (event
->type
) {
164 if (WMIsDoubleClick(event
)) {
166 WMDeleteTimerHandler(dPtr
->timer
);
168 dPtr
->on
= !dPtr
->on
;
170 paintDoubleTest(dPtr
);
172 dPtr
->timer
=WMAddTimerHandler(WINGsConfiguration
.doubleClickDelay
,
175 paintDoubleTest(dPtr
);
184 destroyDoubleTest(_DoubleTest
*dPtr
)
187 WMDeleteTimerHandler(dPtr
->timer
);