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 WBU widget->u.b
22
GBcreatewidget(Gwidget_t * parent,Gwidget_t * widget,int attrn,Gwattr_t * attrp)23 int GBcreatewidget (
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 | BS_PUSHBUTTON;
36 WBU->func = NULL;
37 ps.x = ps.y = MINBWSIZE;
38 s = "button";
39 for (ai = 0; ai < attrn; ai++) {
40 switch (attrp[ai].id) {
41 case G_ATTRSIZE:
42 GETSIZE (attrp[ai].u.s, ps, MINBWSIZE);
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_ATTRBUTTONCB:
54 WBU->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 "BUTTON", 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
GBsetwidgetattr(Gwidget_t * widget,int attrn,Gwattr_t * attrp)79 int GBsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
80 Gwidget_t *parent;
81 PIXsize_t ps;
82 DWORD wflags1;
83 int ai;
84
85 parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
86 wflags1 = SWP_NOMOVE | SWP_NOZORDER;
87 for (ai = 0; ai < attrn; ai++) {
88 switch (attrp[ai].id) {
89 case G_ATTRSIZE:
90 GETSIZE (attrp[ai].u.s, ps, MINBWSIZE);
91 Gadjustwrect (parent, &ps);
92 SetWindowPos (widget->w, (HWND) NULL, 0, 0, ps.x, ps.y, wflags1);
93 break;
94 case G_ATTRBORDERWIDTH:
95 Gerr (POS, G_ERRCANNOTSETATTR2, "borderwidth");
96 return -1;
97 case G_ATTRTEXT:
98 SetWindowText (widget->w, attrp[ai].u.t);
99 break;
100 case G_ATTRWINDOWID:
101 Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");
102 return -1;
103 case G_ATTRBUTTONCB:
104 WBU->func = attrp[ai].u.func;
105 break;
106 case G_ATTRUSERDATA:
107 widget->udata = attrp[ai].u.u;
108 break;
109 default:
110 Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
111 return -1;
112 }
113 }
114 return 0;
115 }
116
GBgetwidgetattr(Gwidget_t * widget,int attrn,Gwattr_t * attrp)117 int GBgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
118 RECT r;
119 int ai;
120
121 for (ai = 0; ai < attrn; ai++) {
122 switch (attrp[ai].id) {
123 case G_ATTRSIZE:
124 GetWindowRect (widget->w, &r);
125 attrp[ai].u.s.x = r.right - r.left;
126 attrp[ai].u.s.y = r.bottom - r.top;
127 break;
128 case G_ATTRBORDERWIDTH:
129 Gerr (POS, G_ERRCANNOTGETATTR, "borderwidth");
130 return -1;
131 case G_ATTRTEXT:
132 GetWindowText (widget->w, &Gbufp[0], Gbufn);
133 attrp[ai].u.t = &Gbufp[0];
134 break;
135 case G_ATTRWINDOWID:
136 sprintf (&Gbufp[0], "0x%lx", widget->w);
137 attrp[ai].u.t = &Gbufp[0];
138 break;
139 case G_ATTRBUTTONCB:
140 attrp[ai].u.func = WBU->func;
141 break;
142 case G_ATTRUSERDATA:
143 attrp[ai].u.u = widget->udata;
144 break;
145 default:
146 Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
147 return -1;
148 }
149 }
150 return 0;
151 }
152
GBdestroywidget(Gwidget_t * widget)153 int GBdestroywidget (Gwidget_t *widget) {
154 Gwidget_t *parent;
155
156 parent = (widget->pwi == -1) ? NULL : &Gwidgets[widget->pwi];
157 if (parent && parent->type == G_ARRAYWIDGET)
158 Gawdeletechild (parent, widget);
159 DestroyWindow (widget->w);
160 return 0;
161 }
162