~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/ui/ntogglelistdialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1998, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "ntogglelistdialog.h"
 
23
#include "util.h"
 
24
#include "mstring.h"
 
25
#include "bitmap.h"
 
26
#include <Xm/XmAll.h>
 
27
 
 
28
NToggleListDialog::NToggleListDialog(Widget w, bool b): PromptDialog(w) { 
 
29
        promptVisible = b;
 
30
        optionsVisible = False;
 
31
}
 
32
 
 
33
NToggleListDialog::~NToggleListDialog() {
 
34
        for (toggleList.first(); !toggleList.done(); toggleList.next())
 
35
                delete toggleList.cur();
 
36
}
 
37
 
 
38
void NToggleListDialog::CreateWidget() {
 
39
        Arg args[9]; int i = 0;
 
40
        XtSetArg(args[i], XmNautoUnmanage, GetAutoUnmanage()); i++;
 
41
        SetWidget(XmCreatePromptDialog(GetParent(), (char *)GetClassName(), args, i));
 
42
}
 
43
 
 
44
void NToggleListDialog::Configure() {
 
45
        PromptDialog::Configure();
 
46
        if (!promptVisible) {
 
47
                ManageSelectionLabel(False);
 
48
                ManageTextString(False);
 
49
        }
 
50
        ManageCancelButton(True);
 
51
        ManageHelpButton(True);
 
52
        SetHelpButtonLabel("Default");
 
53
        SetOKButtonLabel("Apply");
 
54
        SetCancelButtonLabel("Dismiss");
 
55
        SetCancelCallback(Dialog::UnmanageCB, this);
 
56
}
 
57
 
 
58
void NToggleListDialog::SetToggleChangedCallback(
 
59
                unsigned n, XtCallbackProc fun, XtPointer cd) {
 
60
        if (check(n < toggleList.count())) {
 
61
                List<Widget> *toggles = toggleList[n];
 
62
                for (unsigned i=0; i<toggles->count(); i++)
 
63
                        XtAddCallback((*toggles)[i], 
 
64
                                XmNvalueChangedCallback, fun, cd);
 
65
        }
 
66
}
 
67
 
 
68
void NToggleListDialog::CreateToggleLists(
 
69
        List<string *> *labels, List<List<string *> *> *items,
 
70
        List<string *> *options) {
 
71
        if (!check(labels->count() == items->count()))
 
72
                return;
 
73
        if (options != 0) {
 
74
                if (!check(labels->count() == options->count()))
 
75
                        return;
 
76
                optionsVisible = True;
 
77
        }
 
78
        Arg args[10];
 
79
        int n = 0;
 
80
        XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
 
81
        char wname[8] = "widget";
 
82
        Widget rc = XmCreateRowColumn(GetWidget(), wname, args, n);
 
83
        for (unsigned j=0; j<labels->count(); j++) {
 
84
                Widget rc2 = XmCreateRowColumn(rc, wname, 0, 0);
 
85
                Widget frame = XtVaCreateManagedWidget(wname,
 
86
                        xmFrameWidgetClass, rc2, 0);
 
87
                XtVaCreateManagedWidget((*labels)[j]->getstr(),
 
88
                        xmLabelWidgetClass, frame,
 
89
                        XmNchildType, XmFRAME_TITLE_CHILD, 0);
 
90
                Widget box = XmCreateRadioBox(frame, wname, 0, 0);
 
91
                List<string *> *t = (*items)[j];
 
92
                int i = 0;
 
93
                List<Widget> *toggles = new List<Widget>;
 
94
                for (t->first(); !t->done(); t->next()) {
 
95
                        i++;
 
96
                        const char *s = t->cur()->getstr();
 
97
                        Widget w = XtVaCreateManagedWidget(s,
 
98
                                xmToggleButtonWidgetClass, box,
 
99
                                XmNuserData, i,
 
100
                                XmNhighlightThickness, 0,
 
101
                                XmNset, i==0, 0);
 
102
                        toggles->add(w);
 
103
                }
 
104
                toggleList.add(toggles);
 
105
                XtManageChild(box);
 
106
                if (options != 0) {
 
107
                        const char *s = (*options)[j]->getstr();
 
108
                        Widget w = XtVaCreateManagedWidget(s,
 
109
                                xmToggleButtonWidgetClass, rc2,
 
110
                                XmNhighlightThickness, 0,
 
111
                                XmNset, 0, 0);
 
112
                        optionList.add(w);
 
113
                }
 
114
                XtManageChild(rc2);
 
115
        }
 
116
        XtManageChild(rc);
 
117
}
 
118
 
 
119
void NToggleListDialog::SetItemBitmap(unsigned n, unsigned i, Bitmap *bitmap) {
 
120
        if (check(n < toggleList.count())) {
 
121
                List<Widget> *toggles = toggleList[n];
 
122
                if (check(i < toggles->count())) {
 
123
                        Widget tb = (*toggles)[i];
 
124
                        Pixmap pixmap = bitmap->CreatePixmap(tb, GetDisplay());
 
125
                        XtVaSetValues(tb,
 
126
                                XmNlabelType, XmPIXMAP,
 
127
                                XmNlabelPixmap, pixmap, 0);
 
128
                }
 
129
        }
 
130
}
 
131
 
 
132
 
 
133
void NToggleListDialog::SetItem(unsigned n, unsigned i, const string *txt) {
 
134
        if (check(n < toggleList.count())) {
 
135
                List<Widget> *toggles = toggleList[n];
 
136
                if (check(i < toggles->count())) {
 
137
                        XmString s = CreateXmString(txt->getstr());
 
138
                        XtVaSetValues((*toggles)[i], XmNlabelString, s, 0);
 
139
                        XmStringFree(s);
 
140
                }
 
141
        }
 
142
}
 
143
 
 
144
void NToggleListDialog::GetItem(unsigned n, unsigned i, string *txt) {
 
145
        if (check(n < toggleList.count())) {
 
146
                List<Widget> *toggles = toggleList[n];
 
147
                if (check(i < toggles->count())) {
 
148
                        XmString s = CreateXmString("");
 
149
                        XtVaGetValues((*toggles)[i], XmNlabelString, &s, 0);
 
150
                        char *str;
 
151
                        if (XmStringGetLtoR(s, XmFONTLIST_DEFAULT_TAG, &str)) {
 
152
                                *txt = str;
 
153
                                XtFree(str);
 
154
                        }
 
155
                        XmStringFree(s);
 
156
                }
 
157
        }
 
158
}
 
159
 
 
160
void NToggleListDialog::SetValue(unsigned n, unsigned i) {
 
161
        if (check(n < toggleList.count())) {
 
162
                List<Widget> *toggles = toggleList[n];
 
163
                if (check(i < toggles->count()))
 
164
                        XmToggleButtonSetState((*toggles)[i], True, True);
 
165
        }
 
166
}
 
167
 
 
168
void NToggleListDialog::SetValueOfText(unsigned n, const string *t) {
 
169
        if (check(n < toggleList.count())) {
 
170
                List<Widget> *toggles = toggleList[n];
 
171
                for (unsigned i=0; i<toggles->count(); i++) {
 
172
                        XmString s = CreateXmString("");
 
173
                        XtVaGetValues((*toggles)[i], XmNlabelString, &s, 0);
 
174
                        char *str;
 
175
                        if (XmStringGetLtoR(s, XmFONTLIST_DEFAULT_TAG, &str)) {
 
176
                                if (*t == str) {
 
177
                                        XmToggleButtonSetState((*toggles)[i], 
 
178
                                                True, True);
 
179
                                        XmStringFree(s);
 
180
                                        XtFree(str);
 
181
                                        return;
 
182
                                }
 
183
                                XtFree(str);
 
184
                        }
 
185
                        XmStringFree(s);
 
186
                }
 
187
        }
 
188
}
 
189
 
 
190
int NToggleListDialog::GetValue(unsigned n) {
 
191
        if (check(n < toggleList.count())) {
 
192
                List<Widget> *toggles = toggleList[n];
 
193
                for (unsigned i=0; i<toggles->count(); i++) {
 
194
                        if (XmToggleButtonGetState((*toggles)[i]))
 
195
                                return i;
 
196
                }
 
197
        }
 
198
        return -1;
 
199
}
 
200
 
 
201
int NToggleListDialog::GetOptionValue(unsigned n) {
 
202
        if (!optionsVisible)
 
203
                return -1;
 
204
        else if (!check(n < optionList.count()))
 
205
                return -1;
 
206
        else 
 
207
                return (XmToggleButtonGetState(optionList[n]));
 
208
}
 
209
 
 
210
void NToggleListDialog::SetOptionValue(unsigned n, bool b) {
 
211
        if (optionsVisible && check(n < optionList.count()))
 
212
                XmToggleButtonSetState(optionList[n], b, True);
 
213
}
 
214
 
 
215
void NToggleListDialog::SetPromptVisible(bool b) {
 
216
        if (promptVisible == b)
 
217
                return;
 
218
        promptVisible = b;
 
219
        ManageSelectionLabel(b);
 
220
        ManageTextString(b);
 
221
}
 
222
 
 
223
void NToggleListDialog::SetOptionsVisible(bool b) {
 
224
        if (optionsVisible == b)
 
225
                return;
 
226
        optionsVisible = b;
 
227
        for (optionList.first(); !optionList.done(); optionList.next()) {
 
228
                Widget w = optionList.cur();
 
229
                if (b)
 
230
                        XtManageChild(w);
 
231
                else
 
232
                        XtUnmanageChild(w);
 
233
        }
 
234
}