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

« back to all changes in this revision

Viewing changes to src/ui/togglelistdialog.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 1997, 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 "togglelistdialog.h"
 
23
#include "util.h"
 
24
#include "mstring.h"
 
25
#include "bitmap.h"
 
26
#include <Xm/XmAll.h>
 
27
 
 
28
ToggleListDialog::ToggleListDialog(Widget w, bool b): PromptDialog(w) { 
 
29
        toggleFun = 0;
 
30
        promptVisible = b;
 
31
        numToggles = 0;
 
32
        toggleList = 0;
 
33
        clientData = 0;
 
34
}
 
35
 
 
36
ToggleListDialog::~ToggleListDialog() {
 
37
        if (toggleList)
 
38
                delete[] toggleList;
 
39
}
 
40
 
 
41
void ToggleListDialog::CreateWidget() {
 
42
        Arg args[9]; int i = 0;
 
43
        XtSetArg(args[i], XmNautoUnmanage, GetAutoUnmanage()); i++;
 
44
        SetWidget(XmCreatePromptDialog(GetParent(), (char *)GetClassName(), args, i));
 
45
}
 
46
 
 
47
void ToggleListDialog::Configure() {
 
48
        PromptDialog::Configure();
 
49
        ManageHelpButton(False);
 
50
        if (!promptVisible) {
 
51
                ManageSelectionLabel(False);
 
52
                ManageTextString(False);
 
53
        }
 
54
}
 
55
 
 
56
void ToggleListDialog::SetToggleChangedCallback(XtCallbackProc fun, 
 
57
                XtPointer cd) {
 
58
        toggleFun = fun;
 
59
        clientData = cd;
 
60
        for (unsigned i=0; i<numToggles; i++)
 
61
                XtAddCallback(toggleList[i], XmNvalueChangedCallback, 
 
62
                                toggleFun, clientData);
 
63
}
 
64
 
 
65
void ToggleListDialog::CreateToggles(const string *label, 
 
66
                List<string *> *items) {
 
67
        char wname[12] = "toggle_box";
 
68
        Widget toggleBox = XmCreateRadioBox(GetWidget(), wname, 0, 0);
 
69
        int i = 0;
 
70
        numToggles = 0;
 
71
        toggleList = new Widget[items->count()];
 
72
        if (*label != "") {
 
73
                Widget frame = XtVaCreateManagedWidget("frame",
 
74
                        xmFrameWidgetClass, toggleBox, 0);
 
75
                XtVaCreateManagedWidget(label->getstr(),
 
76
                        xmLabelWidgetClass, frame,
 
77
                        XmNchildType, XmFRAME_TITLE_CHILD, 0);
 
78
        }
 
79
        for (items->first(); !items->done(); items->next()) {
 
80
                const char *s = items->cur()->getstr();
 
81
                XmString btn = CreateXmString(s);
 
82
                Widget w = XtVaCreateManagedWidget(s,
 
83
                                xmToggleButtonWidgetClass, toggleBox,
 
84
                                XmNuserData, i,
 
85
                                XmNhighlightThickness, 0,
 
86
                                XmNset, i==0, 0);
 
87
                toggleList[numToggles] = w;
 
88
                numToggles++;
 
89
                i++;
 
90
                if (toggleFun)
 
91
                        XtAddCallback(w, XmNvalueChangedCallback, toggleFun, 
 
92
                                clientData);
 
93
                XmStringFree(btn);
 
94
        }
 
95
        XtManageChild(toggleBox);
 
96
}
 
97
 
 
98
void ToggleListDialog::CreateToggles(List<string *> *items) {
 
99
        string empty = "";
 
100
        CreateToggles(&empty, items);
 
101
}
 
102
 
 
103
void ToggleListDialog::SetToggleBitmap(unsigned i, Bitmap *bitmap) {
 
104
        if (check(i < numToggles)) {
 
105
                Widget tb = toggleList[i];
 
106
                Pixmap pixmap = bitmap->CreatePixmap(tb, GetDisplay());
 
107
                XtVaSetValues(tb, 
 
108
                        XmNlabelType, XmPIXMAP,
 
109
                        XmNlabelPixmap, pixmap, 0);
 
110
        }
 
111
}
 
112
 
 
113
void ToggleListDialog::SetToggleText(unsigned i, const string *txt) {
 
114
        if (check(i < numToggles)) {
 
115
                XmString s = CreateXmString(txt->getstr());
 
116
                XtVaSetValues(toggleList[i], XmNlabelString, s, 0);
 
117
                XmStringFree(s);
 
118
        }
 
119
}
 
120
 
 
121
void ToggleListDialog::GetToggleText(unsigned i, string *txt) {
 
122
        if (check(i < numToggles)) {
 
123
                XmString s = CreateXmString("");
 
124
                XtVaGetValues(toggleList[i], XmNlabelString, &s, 0);
 
125
                char *str;
 
126
                if (XmStringGetLtoR(s, XmFONTLIST_DEFAULT_TAG, &str)) {
 
127
                        *txt = str;
 
128
                        XtFree(str);
 
129
                }
 
130
                XmStringFree(s);
 
131
        }
 
132
}
 
133
 
 
134
unsigned ToggleListDialog::NumToggles() {
 
135
        return numToggles;
 
136
}
 
137
 
 
138
void ToggleListDialog::SetValue(unsigned n) {
 
139
        if (check(n < numToggles))
 
140
                XmToggleButtonSetState(toggleList[n], True, True);
 
141
}
 
142
 
 
143
int ToggleListDialog::GetValue() {
 
144
        for (unsigned i=0; i<numToggles; i++) {
 
145
                if (XmToggleButtonGetState(toggleList[i]))
 
146
                        return i;
 
147
        }
 
148
        return -1;
 
149
}