1
////////////////////////////////////////////////////////////////////////////////
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).
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.
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.
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
21
////////////////////////////////////////////////////////////////////////////////
22
#include "ntogglelistdialog.h"
28
NToggleListDialog::NToggleListDialog(Widget w, bool b): PromptDialog(w) {
30
optionsVisible = False;
33
NToggleListDialog::~NToggleListDialog() {
34
for (toggleList.first(); !toggleList.done(); toggleList.next())
35
delete toggleList.cur();
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));
44
void NToggleListDialog::Configure() {
45
PromptDialog::Configure();
47
ManageSelectionLabel(False);
48
ManageTextString(False);
50
ManageCancelButton(True);
51
ManageHelpButton(True);
52
SetHelpButtonLabel("Default");
53
SetOKButtonLabel("Apply");
54
SetCancelButtonLabel("Dismiss");
55
SetCancelCallback(Dialog::UnmanageCB, this);
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);
68
void NToggleListDialog::CreateToggleLists(
69
List<string *> *labels, List<List<string *> *> *items,
70
List<string *> *options) {
71
if (!check(labels->count() == items->count()))
74
if (!check(labels->count() == options->count()))
76
optionsVisible = True;
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];
93
List<Widget> *toggles = new List<Widget>;
94
for (t->first(); !t->done(); t->next()) {
96
const char *s = t->cur()->getstr();
97
Widget w = XtVaCreateManagedWidget(s,
98
xmToggleButtonWidgetClass, box,
100
XmNhighlightThickness, 0,
104
toggleList.add(toggles);
107
const char *s = (*options)[j]->getstr();
108
Widget w = XtVaCreateManagedWidget(s,
109
xmToggleButtonWidgetClass, rc2,
110
XmNhighlightThickness, 0,
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());
126
XmNlabelType, XmPIXMAP,
127
XmNlabelPixmap, pixmap, 0);
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);
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);
151
if (XmStringGetLtoR(s, XmFONTLIST_DEFAULT_TAG, &str)) {
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);
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);
175
if (XmStringGetLtoR(s, XmFONTLIST_DEFAULT_TAG, &str)) {
177
XmToggleButtonSetState((*toggles)[i],
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]))
201
int NToggleListDialog::GetOptionValue(unsigned n) {
204
else if (!check(n < optionList.count()))
207
return (XmToggleButtonGetState(optionList[n]));
210
void NToggleListDialog::SetOptionValue(unsigned n, bool b) {
211
if (optionsVisible && check(n < optionList.count()))
212
XmToggleButtonSetState(optionList[n], b, True);
215
void NToggleListDialog::SetPromptVisible(bool b) {
216
if (promptVisible == b)
219
ManageSelectionLabel(b);
223
void NToggleListDialog::SetOptionsVisible(bool b) {
224
if (optionsVisible == b)
227
for (optionList.first(); !optionList.done(); optionList.next()) {
228
Widget w = optionList.cur();