Change to the linux kernel coding style
[wmaker-crm.git] / src / geomview.c
Commit [+]AuthorDateLineData
dd1d0846 kojima2000-01-14 16:46:43 +00001
a20aebde dan2001-01-18 19:21:56 +00002#include <WINGs/WINGsP.h>
dd1d0846 kojima2000-01-14 16:46:43 +00003
dd1d0846 kojima2000-01-14 16:46:43 +00004typedef struct W_GeometryView {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02005 W_Class widgetClass;
6 WMView *view;
6830b057 dan2004-10-12 21:28:27 +00007
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02008 WMColor *color;
9 WMColor *bgColor;
27b9e27a dan2004-10-18 01:30:02 +000010
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020011 WMFont *font;
6830b057 dan2004-10-12 21:28:27 +000012
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020013 WMSize textSize;
6830b057 dan2004-10-12 21:28:27 +000014
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020015 union {
16 struct {
17 int x, y;
18 } pos;
19 struct {
20 unsigned width, height;
21 } size;
22 } data;
6830b057 dan2004-10-12 21:28:27 +000023
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020024 unsigned showPosition:1;
dd1d0846 kojima2000-01-14 16:46:43 +000025} WGeometryView;
26
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020027static void handleEvents(XEvent * event, void *clientData);
28static void paint(WGeometryView * gview);
dd1d0846 kojima2000-01-14 16:46:43 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030WGeometryView *WCreateGeometryView(WMScreen * scr)
dd1d0846 kojima2000-01-14 16:46:43 +000031{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020032 WGeometryView *gview;
33 char buffer[64];
34 static W_Class widgetClass = 0;
6830b057 dan2004-10-12 21:28:27 +000035
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 if (!widgetClass) {
37 widgetClass = W_RegisterUserWidget();
38 }
6830b057 dan2004-10-12 21:28:27 +000039
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020040 gview = malloc(sizeof(WGeometryView));
41 if (!gview) {
42 return NULL;
43 }
44 memset(gview, 0, sizeof(WGeometryView));
6830b057 dan2004-10-12 21:28:27 +000045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020046 gview->widgetClass = widgetClass;
dd1d0846 kojima2000-01-14 16:46:43 +000047
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020048 gview->view = W_CreateTopView(scr);
49 if (!gview->view) {
50 wfree(gview);
dd1d0846 kojima2000-01-14 16:46:43 +000051
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020052 return NULL;
53 }
54 gview->view->self = gview;
dd1d0846 kojima2000-01-14 16:46:43 +000055
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020056 gview->font = WMSystemFontOfSize(scr, 12);
57 if (!gview->font) {
58 W_DestroyView(gview->view);
59 wfree(gview);
dd1d0846 kojima2000-01-14 16:46:43 +000060
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020061 return NULL;
62 }
dd1d0846 kojima2000-01-14 16:46:43 +000063
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020064 gview->bgColor = WMCreateRGBColor(scr, 0x3333, 0x6666, 0x9999, True);
65 gview->color = WMWhiteColor(scr);
dd1d0846 kojima2000-01-14 16:46:43 +000066
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020067 WMCreateEventHandler(gview->view, ExposureMask, handleEvents, gview);
dd1d0846 kojima2000-01-14 16:46:43 +000068
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020069 snprintf(buffer, sizeof(buffer), "%+05i, %+05i", 0, 0);
dd1d0846 kojima2000-01-14 16:46:43 +000070
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020071 gview->textSize.width = WMWidthOfString(gview->font, buffer, strlen(buffer));
72 gview->textSize.height = WMFontHeight(gview->font);
6830b057 dan2004-10-12 21:28:27 +000073
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020074 WMSetWidgetBackgroundColor(gview, gview->bgColor);
27b9e27a dan2004-10-18 01:30:02 +000075
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076 W_ResizeView(gview->view, gview->textSize.width + 8, gview->textSize.height + 6);
dd1d0846 kojima2000-01-14 16:46:43 +000077
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020078 return gview;
dd1d0846 kojima2000-01-14 16:46:43 +000079}
80
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020081void WSetGeometryViewShownPosition(WGeometryView * gview, int x, int y)
dd1d0846 kojima2000-01-14 16:46:43 +000082{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020083 gview->showPosition = 1;
84 gview->data.pos.x = x;
85 gview->data.pos.y = y;
6830b057 dan2004-10-12 21:28:27 +000086
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020087 paint(gview);
dd1d0846 kojima2000-01-14 16:46:43 +000088}
89
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020090void WSetGeometryViewShownSize(WGeometryView * gview, unsigned width, unsigned height)
dd1d0846 kojima2000-01-14 16:46:43 +000091{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020092 gview->showPosition = 0;
93 gview->data.size.width = width;
94 gview->data.size.height = height;
6830b057 dan2004-10-12 21:28:27 +000095
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020096 paint(gview);
dd1d0846 kojima2000-01-14 16:46:43 +000097}
98
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020099static void paint(WGeometryView * gview)
dd1d0846 kojima2000-01-14 16:46:43 +0000100{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200101 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);
dd1d0846 kojima2000-01-14 16:46:43 +0000118}
119
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200120static void handleEvents(XEvent * event, void *clientData)
dd1d0846 kojima2000-01-14 16:46:43 +0000121{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200122 WGeometryView *gview = (WGeometryView *) clientData;
6830b057 dan2004-10-12 21:28:27 +0000123
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200124 switch (event->type) {
125 case Expose:
126 paint(gview);
127 break;
6830b057 dan2004-10-12 21:28:27 +0000128
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200129 }
dd1d0846 kojima2000-01-14 16:46:43 +0000130}