Change to the linux kernel coding style
[wmaker-crm.git] / src / geomview.c
1
2 #include <WINGs/WINGsP.h>
3
4 typedef struct W_GeometryView {
5 W_Class widgetClass;
6 WMView *view;
7
8 WMColor *color;
9 WMColor *bgColor;
10
11 WMFont *font;
12
13 WMSize textSize;
14
15 union {
16 struct {
17 int x, y;
18 } pos;
19 struct {
20 unsigned width, height;
21 } size;
22 } data;
23
24 unsigned showPosition:1;
25 } WGeometryView;
26
27 static void handleEvents(XEvent * event, void *clientData);
28 static void paint(WGeometryView * gview);
29
30 WGeometryView *WCreateGeometryView(WMScreen * scr)
31 {
32 WGeometryView *gview;
33 char buffer[64];
34 static W_Class widgetClass = 0;
35
36 if (!widgetClass) {
37 widgetClass = W_RegisterUserWidget();
38 }
39
40 gview = malloc(sizeof(WGeometryView));
41 if (!gview) {
42 return NULL;
43 }
44 memset(gview, 0, sizeof(WGeometryView));
45
46 gview->widgetClass = widgetClass;
47
48 gview->view = W_CreateTopView(scr);
49 if (!gview->view) {
50 wfree(gview);
51
52 return NULL;
53 }
54 gview->view->self = gview;
55
56 gview->font = WMSystemFontOfSize(scr, 12);
57 if (!gview->font) {
58 W_DestroyView(gview->view);
59 wfree(gview);
60
61 return NULL;
62 }
63
64 gview->bgColor = WMCreateRGBColor(scr, 0x3333, 0x6666, 0x9999, True);
65 gview->color = WMWhiteColor(scr);
66
67 WMCreateEventHandler(gview->view, ExposureMask, handleEvents, gview);
68
69 snprintf(buffer, sizeof(buffer), "%+05i, %+05i", 0, 0);
70
71 gview->textSize.width = WMWidthOfString(gview->font, buffer, strlen(buffer));
72 gview->textSize.height = WMFontHeight(gview->font);
73
74 WMSetWidgetBackgroundColor(gview, gview->bgColor);
75
76 W_ResizeView(gview->view, gview->textSize.width + 8, gview->textSize.height + 6);
77
78 return gview;
79 }
80
81 void WSetGeometryViewShownPosition(WGeometryView * gview, int x, int y)
82 {
83 gview->showPosition = 1;
84 gview->data.pos.x = x;
85 gview->data.pos.y = y;
86
87 paint(gview);
88 }
89
90 void WSetGeometryViewShownSize(WGeometryView * gview, unsigned width, unsigned height)
91 {
92 gview->showPosition = 0;
93 gview->data.size.width = width;
94 gview->data.size.height = height;
95
96 paint(gview);
97 }
98
99 static void paint(WGeometryView * gview)
100 {
101 char buffer[64];
102
103 if (gview->showPosition) {
104 snprintf(buffer, sizeof(buffer), "%+5i , %+5i ", gview->data.pos.x, gview->data.pos.y);
105 } else {
106 snprintf(buffer, sizeof(buffer), "%+5i x %+5i ",
107 gview->data.size.width, gview->data.size.height);
108 }
109
110 WMDrawImageString(W_VIEW_SCREEN(gview->view),
111 W_VIEW_DRAWABLE(gview->view),
112 gview->color, gview->bgColor, gview->font,
113 (W_VIEW_WIDTH(gview->view) - gview->textSize.width) / 2,
114 (W_VIEW_HEIGHT(gview->view) - gview->textSize.height) / 2, buffer, strlen(buffer));
115
116 W_DrawRelief(W_VIEW_SCREEN(gview->view), W_VIEW_DRAWABLE(gview->view),
117 0, 0, W_VIEW_WIDTH(gview->view), W_VIEW_HEIGHT(gview->view), WRSimple);
118 }
119
120 static void handleEvents(XEvent * event, void *clientData)
121 {
122 WGeometryView *gview = (WGeometryView *) clientData;
123
124 switch (event->type) {
125 case Expose:
126 paint(gview);
127 break;
128
129 }
130 }