~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/ui/selectiondialog.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 "selectiondialog.h"
 
23
#include "mstring.h"
 
24
#include <Xm/XmAll.h>
 
25
 
 
26
SelectionDialog::SelectionDialog(Widget w): Dialog(w) {
 
27
        defaultValue = "";
 
28
        text = list = selectionLabel = 0;
 
29
}
 
30
 
 
31
void SelectionDialog::CreateWidget() {
 
32
        Arg args[9]; int i = 0;
 
33
        XtSetArg(args[i], XmNautoUnmanage, GetAutoUnmanage()); i++;
 
34
        SetWidget(XmCreateSelectionDialog(GetParent(), (char *)GetClassName(), args, i));
 
35
}
 
36
 
 
37
void SelectionDialog::Configure() {
 
38
        text = XmSelectionBoxGetChild(GetWidget(), XmDIALOG_TEXT);
 
39
        list = XmSelectionBoxGetChild(GetWidget(), XmDIALOG_LIST);
 
40
        selectionLabel = XmSelectionBoxGetChild(GetWidget(), 
 
41
                XmDIALOG_SELECTION_LABEL);
 
42
}
 
43
 
 
44
void SelectionDialog::SetTextString(const char *v) {
 
45
        if (!check(text))
 
46
                return;
 
47
        XmTextSetString(text, (char *)v);
 
48
}
 
49
 
 
50
void SelectionDialog::SetTextString(const string *v) {
 
51
        SetTextString(v->getstr());
 
52
}
 
53
 
 
54
void SelectionDialog::GetTextString(char *n) {
 
55
        if (!check(text))
 
56
                return;
 
57
        char *s = XmTextGetString(text);
 
58
        strcpy(n, s);
 
59
        XtFree(s);
 
60
}
 
61
 
 
62
void SelectionDialog::GetTextString(string *n) {
 
63
        char t[MAXNAME];
 
64
        GetTextString(t);
 
65
        *n = t;
 
66
}
 
67
 
 
68
void SelectionDialog::ManageTextString(bool b) {
 
69
        if (b)
 
70
                XtManageChild(text);
 
71
        else
 
72
                XtUnmanageChild(text);
 
73
}
 
74
 
 
75
void SelectionDialog::SetSelectionLabel(const char *v) {
 
76
        if (!check(GetWidget()))
 
77
                return;
 
78
        XmString t = CreateXmString(v);
 
79
        XtVaSetValues(GetWidget(), XmNselectionLabelString, t, 0);
 
80
        XmStringFree(t);
 
81
}
 
82
 
 
83
void SelectionDialog::ManageSelectionLabel(bool b) {
 
84
        if (b)
 
85
                XtManageChild(selectionLabel);
 
86
        else
 
87
                XtUnmanageChild(selectionLabel);
 
88
}
 
89
 
 
90
void SelectionDialog::SetDefaultValue(const char *s) {
 
91
        defaultValue = s;
 
92
}
 
93
 
 
94
void SelectionDialog::SetDefaultValue(const string *s) {
 
95
        SetDefaultValue(s->getstr());
 
96
}
 
97
 
 
98
void SelectionDialog::SetApplyCallback(XtCallbackProc fun, 
 
99
                XtPointer clientData) {
 
100
        if (!check(GetWidget()))
 
101
                return;
 
102
        XtAddCallback(GetWidget(), XmNapplyCallback, fun, clientData);
 
103
}
 
104
 
 
105
void SelectionDialog::SetApplyButtonLabel(const char *txt) {
 
106
        if (!check(GetWidget()))
 
107
                return;
 
108
        XmString t = CreateXmString(txt);
 
109
        XtVaSetValues(GetWidget(), XmNapplyLabelString, t, 0);
 
110
        XmStringFree(t);
 
111
}
 
112
 
 
113
void SelectionDialog::ManageApplyButton(bool b) {
 
114
        Widget button = XmSelectionBoxGetChild(GetWidget(), 
 
115
                                                XmDIALOG_APPLY_BUTTON);
 
116
        ManageWidget(button, b);
 
117
}
 
118
 
 
119
void SelectionDialog::ClearCB(Widget, XtPointer cd, XtPointer) {
 
120
        SelectionDialog *s = (SelectionDialog *)cd;
 
121
        s->SetTextString("");
 
122
}
 
123
 
 
124
void SelectionDialog::SetDefaultCB(Widget, XtPointer cd, XtPointer) {
 
125
        SelectionDialog *s = (SelectionDialog *)cd;
 
126
        s->SetTextString(s->GetDefaultValue());
 
127
}
 
128
 
 
129
void SelectionDialog::DeselectAllItems() {
 
130
        XmListDeselectAllItems(list);
 
131
}
 
132
 
 
133
void SelectionDialog::DeleteAllItems() {
 
134
        XmListDeleteAllItems(list);
 
135
}
 
136
 
 
137
void SelectionDialog::SelectItem(const string *s) {
 
138
        XmString xs = CreateXmString(s->getstr());
 
139
        XmListSelectItem(GetList(), xs, False);
 
140
        XmStringFree(xs);
 
141
}
 
142
 
 
143
void SelectionDialog::AddItem(const char *s, int pos) {
 
144
        XmString xs = CreateXmString(s);
 
145
        XmListAddItem(GetList(), xs, pos);
 
146
        XmStringFree(xs);
 
147
}
 
148
 
 
149
void SelectionDialog::AddItem(const string *s, int pos) {
 
150
        AddItem(s->getstr(), pos);
 
151
}
 
152
 
 
153
void SelectionDialog::SetEditable(bool b) {
 
154
        XmTextFieldSetEditable(GetText(), b);
 
155
}