WUtil: Aligned msgid for error message translations against latest code
[wmaker-crm.git] / src / geomview.c
blob3564ffacc4c873920319586e6069eaf79a48298c
2 #include <WINGs/WINGsP.h>
4 #include "geomview.h"
7 struct W_GeometryView {
8 W_Class widgetClass;
9 WMView *view;
11 WMColor *color;
12 WMColor *bgColor;
14 WMFont *font;
16 WMSize textSize;
18 union {
19 struct {
20 int x, y;
21 } pos;
22 struct {
23 unsigned width, height;
24 } size;
25 } data;
27 unsigned showPosition:1;
30 static void handleEvents(XEvent * event, void *clientData);
31 static void paint(WGeometryView * gview);
33 WGeometryView *WCreateGeometryView(WMScreen * scr)
35 WGeometryView *gview;
36 char buffer[64];
37 static W_Class widgetClass = 0;
39 if (!widgetClass) {
40 widgetClass = W_RegisterUserWidget();
43 gview = malloc(sizeof(WGeometryView));
44 if (!gview) {
45 return NULL;
47 memset(gview, 0, sizeof(WGeometryView));
49 gview->widgetClass = widgetClass;
51 gview->view = W_CreateTopView(scr);
52 if (!gview->view) {
53 wfree(gview);
55 return NULL;
57 gview->view->self = gview;
59 gview->font = WMSystemFontOfSize(scr, 12);
60 if (!gview->font) {
61 W_DestroyView(gview->view);
62 wfree(gview);
64 return NULL;
67 gview->bgColor = WMCreateRGBColor(scr, 0x3333, 0x6666, 0x9999, True);
68 gview->color = WMWhiteColor(scr);
70 WMCreateEventHandler(gview->view, ExposureMask, handleEvents, gview);
72 snprintf(buffer, sizeof(buffer), "%+05i, %+05i", 0, 0);
74 gview->textSize.width = WMWidthOfString(gview->font, buffer, strlen(buffer));
75 gview->textSize.height = WMFontHeight(gview->font);
77 WMSetWidgetBackgroundColor(gview, gview->bgColor);
79 W_ResizeView(gview->view, gview->textSize.width + 8, gview->textSize.height + 6);
81 return gview;
84 void WSetGeometryViewShownPosition(WGeometryView * gview, int x, int y)
86 gview->showPosition = 1;
87 gview->data.pos.x = x;
88 gview->data.pos.y = y;
90 paint(gview);
93 void WSetGeometryViewShownSize(WGeometryView * gview, unsigned width, unsigned height)
95 gview->showPosition = 0;
96 gview->data.size.width = width;
97 gview->data.size.height = height;
99 paint(gview);
102 static void paint(WGeometryView * gview)
104 char buffer[64];
106 if (gview->showPosition) {
107 snprintf(buffer, sizeof(buffer), "%+5i , %+5i ", gview->data.pos.x, gview->data.pos.y);
108 } else {
109 snprintf(buffer, sizeof(buffer), "%+5i x %+5i ",
110 gview->data.size.width, gview->data.size.height);
113 WMDrawImageString(W_VIEW_SCREEN(gview->view),
114 W_VIEW_DRAWABLE(gview->view),
115 gview->color, gview->bgColor, gview->font,
116 (W_VIEW_WIDTH(gview->view) - gview->textSize.width) / 2,
117 (W_VIEW_HEIGHT(gview->view) - gview->textSize.height) / 2, buffer, strlen(buffer));
119 W_DrawRelief(W_VIEW_SCREEN(gview->view), W_VIEW_DRAWABLE(gview->view),
120 0, 0, W_VIEW_WIDTH(gview->view), W_VIEW_HEIGHT(gview->view), WRSimple);
123 static void handleEvents(XEvent * event, void *clientData)
125 WGeometryView *gview = (WGeometryView *) clientData;
127 switch (event->type) {
128 case Expose:
129 paint(gview);
130 break;