1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3
4 /*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14 /* Lefteris Koutsofios - AT&T Labs Research */
15
16 #include "common.h"
17 #include "g.h"
18 #include "gcommon.h"
19 #include "mem.h"
20
21 #define WLU widget->u.l
22
GLcreatewidget(Gwidget_t * parent,Gwidget_t * widget,int attrn,Gwattr_t * attrp)23 int GLcreatewidget (
24 Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp
25 ) {
26 PIXsize_t ps;
27 DWORD wflags;
28 char *s;
29 int ai;
30
31 if (!parent) {
32 Gerr (POS, G_ERRNOPARENTWIDGET);
33 return -1;
34 }
35 wflags = WS_CHILDWINDOW;
36 WLU->func = NULL;
37 ps.x = ps.y = MINLWSIZE;
38 s = "";
39 for (ai = 0; ai < attrn; ai++) {
40 switch (attrp[ai].id) {
41 case G_ATTRSIZE:
42 GETSIZE (attrp[ai].u.s, ps, MINLWSIZE);
43 break;
44 case G_ATTRBORDERWIDTH:
45 wflags |= WS_BORDER;
46 break;
47 case G_ATTRTEXT:
48 s = attrp[ai].u.t;
49 break;
50 case G_ATTRWINDOWID:
51 Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
52 return -1;
53 case G_ATTREVENTCB:
54 WLU->func = attrp[ai].u.func;
55 break;
56 case G_ATTRUSERDATA:
57 widget->udata = attrp[ai].u.u;
58 break;
59 default:
60 Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
61 return -1;
62 }
63 }
64 Gadjustwrect (parent, &ps);
65 if (!(widget->w = CreateWindow (
66 "LabelClass", s, wflags, 0, 0, ps.x, ps.y,
67 parent->w, (HMENU) (widget - &Gwidgets[0]), hinstance, NULL
68 ))) {
69 Gerr (POS, G_ERRCANNOTCREATEWIDGET);
70 return -1;
71 }
72 ShowWindow (widget->w, SW_SHOW);
73 UpdateWindow (widget->w);
74 if (parent && parent->type == G_ARRAYWIDGET)
75 Gawinsertchild (parent, widget);
76 return 0;
77 }
78
GLsetwidgetattr(Gwidget_t * widget,int attrn,Gwattr_t * attrp)79 int GLsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
80 Gwidget_t *parent;
81 PIXsize_t ps;
82 RECT r;
83 DWORD wflags1;
84 int ai;
85
86 parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
87 wflags1 = SWP_NOMOVE | SWP_NOZORDER;
88 for (ai = 0; ai < attrn; ai++) {
89 switch (attrp[ai].id) {
90 case G_ATTRSIZE:
91 GETSIZE (attrp[ai].u.s, ps, MINLWSIZE);
92 Gadjustwrect (parent, &ps);
93 SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps.x, ps.y, wflags1);
94 r.top = r.left = 0;
95 r.bottom = ps.y, r.right = ps.x;
96 InvalidateRect (widget->w, NULL, FALSE);
97 break;
98 case G_ATTRBORDERWIDTH:
99 Gerr (POS, G_ERRCANNOTSETATTR2, "borderwidth");
100 return -1;
101 case G_ATTRTEXT:
102 SetWindowText (widget->w, attrp[ai].u.t);
103 GetClientRect (widget->w, &r);
104 InvalidateRect (widget->w, &r, TRUE);
105 break;
106 case G_ATTRWINDOWID:
107 Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
108 return -1;
109 case G_ATTREVENTCB:
110 attrp[ai].u.func = WLU->func;
111 break;
112 case G_ATTRUSERDATA:
113 widget->udata = attrp[ai].u.u;
114 break;
115 default:
116 Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
117 return -1;
118 }
119 }
120 return 0;
121 }
122
GLgetwidgetattr(Gwidget_t * widget,int attrn,Gwattr_t * attrp)123 int GLgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
124 RECT r;
125 int ai;
126
127 for (ai = 0; ai < attrn; ai++) {
128 switch (attrp[ai].id) {
129 case G_ATTRSIZE:
130 GetWindowRect (widget->w, &r);
131 attrp[ai].u.s.x = r.right - r.left;
132 attrp[ai].u.s.y = r.bottom - r.top;
133 break;
134 case G_ATTRBORDERWIDTH:
135 Gerr (POS, G_ERRCANNOTGETATTR, "borderwidth");
136 return -1;
137 case G_ATTRTEXT:
138 GetWindowText (widget->w, &Gbufp[0], Gbufn);
139 attrp[ai].u.t = &Gbufp[0];
140 break;
141 case G_ATTRWINDOWID:
142 sprintf (&Gbufp[0], "0x%lx", widget->w);
143 attrp[ai].u.t = &Gbufp[0];
144 break;
145 case G_ATTREVENTCB:
146 attrp[ai].u.func = WLU->func;
147 break;
148 case G_ATTRUSERDATA:
149 attrp[ai].u.u = widget->udata;
150 break;
151 default:
152 Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
153 return -1;
154 }
155 }
156 return 0;
157 }
158
GLdestroywidget(Gwidget_t * widget)159 int GLdestroywidget (Gwidget_t *widget) {
160 Gwidget_t *parent;
161
162 parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
163 if (parent && parent->type == G_ARRAYWIDGET)
164 Gawdeletechild (parent, widget);
165 DestroyWindow (widget->w);
166 return 0;
167 }
168