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

« back to all changes in this revision

Viewing changes to src/ui/scaledialog.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 "scaledialog.h"
 
23
#include "util.h"
 
24
#include "mstring.h"
 
25
#include <Xm/XmAll.h>
 
26
 
 
27
ScaleDialog::ScaleDialog(Widget w): MessageDialog(w) {
 
28
        initValue = 1;
 
29
        defaultValue = 1;
 
30
        valueChangeFun = 0;
 
31
}
 
32
 
 
33
void ScaleDialog::CreateWidget() {
 
34
        Arg args[9]; int i = 0;
 
35
        XtSetArg(args[i], XmNautoUnmanage, GetAutoUnmanage()); i++;
 
36
        SetWidget(XmCreateMessageDialog(GetParent(), (char *)GetClassName(), args, i));
 
37
        scale = XtVaCreateManagedWidget("scale",
 
38
                        xmScaleWidgetClass, GetWidget(),
 
39
                        XmNorientation, XmHORIZONTAL,
 
40
                        XmNshowValue, True, 0);
 
41
}
 
42
 
 
43
void ScaleDialog::Configure() {
 
44
        SetHelpButtonLabel("Default");
 
45
        SetHelpCallback(SetDefaultCB, this);
 
46
        SetCancelCallback(SetInitCB, this);
 
47
}
 
48
 
 
49
void ScaleDialog::SetScaleValues(int min, int max, int init, int decimal, 
 
50
                int def) {
 
51
        if (!check(scale))
 
52
                return;
 
53
        XtVaSetValues(scale, 
 
54
                XmNmaximum, max,
 
55
                XmNminimum, min,
 
56
                XmNvalue, init,
 
57
                XmNdecimalPoints, decimal, 0);
 
58
        initValue = init;
 
59
        defaultValue = def;
 
60
}
 
61
 
 
62
void ScaleDialog::SetScaleLabel(const char *text) {
 
63
        if (!check(scale))
 
64
                return;
 
65
        XmString text_string = CreateXmString(text);
 
66
        // XtVaTypedArg, XmNtitleString, XmRString, text, strlen(text),
 
67
        XtVaSetValues(scale, XmNtitleString, text_string, 0);
 
68
        XmStringFree(text_string);
 
69
}
 
70
 
 
71
void ScaleDialog::SetValueChangedCallback(XtCallbackProc fun, XtPointer cd) {
 
72
        if (!check(scale))
 
73
                return;
 
74
        XtRemoveAllCallbacks(scale, XmNvalueChangedCallback);
 
75
        if (fun) {
 
76
                XtAddCallback(scale, XmNvalueChangedCallback, fun, cd);
 
77
                valueChangeFun = fun;
 
78
                clientData = cd;
 
79
        }
 
80
        else
 
81
                valueChangeFun = 0;
 
82
}
 
83
 
 
84
void ScaleDialog::SetDefaultCB(Widget, XtPointer cd, XtPointer) {
 
85
        ScaleDialog *d = (ScaleDialog *)cd;
 
86
        d->SetScaleValue(d->GetDefaultValue());
 
87
}
 
88
 
 
89
void ScaleDialog::SetInitCB(Widget, XtPointer cd, XtPointer) {
 
90
        ScaleDialog *d = (ScaleDialog *)cd;
 
91
        d->SetScaleValue(d->GetInitValue());
 
92
}
 
93
 
 
94
void ScaleDialog::SetScaleValue(int val) {
 
95
        if (!check(scale))
 
96
                return;
 
97
        int oldval = GetScaleValue();
 
98
        if (oldval != val) {
 
99
                XmScaleSetValue(scale, val);
 
100
                if (valueChangeFun) {
 
101
                        XmScaleCallbackStruct cbs;
 
102
                        cbs.value = val;
 
103
                        cbs.event = 0;
 
104
                        cbs.reason = XmCR_VALUE_CHANGED;
 
105
                        (*valueChangeFun)(scale, clientData, (XtPointer) &cbs);
 
106
                }
 
107
        }
 
108
}
 
109
 
 
110
int ScaleDialog::GetScaleValue() {
 
111
        if (!check(scale))
 
112
                return 1; 
 
113
        int val;
 
114
        XmScaleGetValue(scale, &val);
 
115
        return val;
 
116
}