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 WMU widget->u.m
22 
GMcreatewidget(Gwidget_t * parent,Gwidget_t * widget,int attrn,Gwattr_t * attrp)23 int GMcreatewidget (
24     Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp
25 ) {
26     int ai;
27 
28     for (ai = 0; ai < attrn; ai++) {
29         switch (attrp[ai].id) {
30         case G_ATTRUSERDATA:
31             widget->udata = attrp[ai].u.u;
32             break;
33         default:
34             Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
35             return -1;
36         }
37     }
38     if (!(widget->w = CreatePopupMenu ())) {
39         Gerr (POS, G_ERRCANNOTCREATEWIDGET);
40         return -1;
41     }
42     WMU->count = 0;
43     return 0;
44 }
45 
GMsetwidgetattr(Gwidget_t * widget,int attrn,Gwattr_t * attrp)46 int GMsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
47     int ai;
48 
49     for (ai = 0; ai < attrn; ai++) {
50         switch (attrp[ai].id) {
51         case G_ATTRUSERDATA:
52             widget->udata = attrp[ai].u.u;
53             break;
54         default:
55             Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
56             return -1;
57         }
58     }
59     return 0;
60 }
61 
GMgetwidgetattr(Gwidget_t * widget,int attrn,Gwattr_t * attrp)62 int GMgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {
63     int ai;
64 
65     for (ai = 0; ai < attrn; ai++) {
66         switch (attrp[ai].id) {
67         case G_ATTRUSERDATA:
68             attrp[ai].u.u = widget->udata;
69             break;
70         default:
71             Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
72             return -1;
73         }
74     }
75     return 0;
76 }
77 
GMdestroywidget(Gwidget_t * widget)78 int GMdestroywidget (Gwidget_t *widget) {
79     DestroyMenu (widget->w);
80     return 0;
81 }
82 
GMmenuaddentries(Gwidget_t * widget,int en,char ** ep)83 int GMmenuaddentries (Gwidget_t *widget, int en, char **ep) {
84     int ei;
85 
86     for (ei = 0; ei < en; ei++)
87         AppendMenu (widget->w, MF_ENABLED | MF_STRING, WMU->count++, ep[ei]);
88     return 0;
89 }
90 
GMmenudisplay(Gwidget_t * parent,Gwidget_t * widget)91 int GMmenudisplay (Gwidget_t *parent, Gwidget_t *widget) {
92     MSG msg;
93     POINT p;
94     UINT flag;
95 
96     /* FIXME not only right button */
97     menupoped = TRUE;
98     menuselected = -1;
99     GetCursorPos (&p);
100     if (GetAsyncKeyState (VK_LBUTTON) < 0)
101         flag = TPM_LEFTALIGN | TPM_LEFTBUTTON;
102     else
103         flag = TPM_LEFTALIGN | TPM_RIGHTBUTTON;
104     TrackPopupMenu (widget->w, flag, p.x, p.y, 0, parent->w, NULL);
105     PostMessage (parent->w, WM_COMMAND, 999, 0);
106     if (!GetMessage(&msg, parent->w, WM_COMMAND, WM_COMMAND))
107         panic1 (POS, "GMmenudisplay", "exit code in GetMessage");
108     TranslateMessage(&msg);
109     DispatchMessage(&msg);
110     Gpopdownflag = TRUE;
111     return menuselected;
112 }
113