~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/qmon/Xmt310/Xmt/XmCSText.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Motif Tools Library, Version 3.1
 
3
 * $Id$
 
4
 * 
 
5
 * Written by David Flanagan.
 
6
 * Copyright (c) 1992-2001 by David Flanagan.
 
7
 * All Rights Reserved.  See the file COPYRIGHT for details.
 
8
 * This is open source software.  See the file LICENSE for details.
 
9
 * There is no warranty for this software.  See NO_WARRANTY for details.
 
10
 *
 
11
 * $Log$
 
12
 * Revision 1.1.1.1  2001/07/18 11:06:03  root
 
13
 * Initial checkin.
 
14
 *
 
15
 * Revision 1.2  2001/06/12 16:25:28  andre
 
16
 * *** empty log message ***
 
17
 *
 
18
 *
 
19
 */
 
20
 
 
21
/*
 
22
 * This file courtesy of Tony Hefner.
 
23
 */
 
24
 
 
25
#include <stdlib.h>
 
26
#include <Xmt/Xmt.h>
 
27
 
 
28
#if XmVersion == 2000
 
29
 
 
30
#include <Xmt/WidgetType.h>
 
31
#include <Xmt/QuarksP.h>
 
32
#include <Xm/CSText.h>
 
33
 
 
34
/* ARGSUSED */
 
35
#if NeedFunctionPrototypes
 
36
static void setvalue(Widget w, XtPointer address, XrmQuark type, Cardinal size)
 
37
#else
 
38
static void setvalue(w, address, type, size)
 
39
Widget w;
 
40
XtPointer address;
 
41
XrmQuark type;
 
42
Cardinal size;
 
43
#endif
 
44
{
 
45
    XmString xmString = NULL;
 
46
 
 
47
    if (type == XmtQString) {
 
48
        /* Convert the value to an XmString. */
 
49
        xmString = XmtCreateLocalizedXmString(w, *(String *)address);
 
50
        XmCSTextSetString(w, xmString);
 
51
    }
 
52
    else if (type == XmtQBuffer) {
 
53
        /* Convert the value to an XmString. */
 
54
        xmString = XmtCreateLocalizedXmString(w, (char *)address);
 
55
        XmCSTextSetString(w, xmString);
 
56
    }
 
57
    else
 
58
        XmtWarningMsg("XmtDialogSetDialogValues", "xmcstext",
 
59
                      "Type mismatch:\n\tCan't set value from resource of type '%s'.  String or Buffer expected.",
 
60
                   XrmQuarkToString(type));
 
61
 
 
62
    if (xmString) XmStringFree(xmString);
 
63
}
 
64
 
 
65
#if NeedFunctionPrototypes
 
66
static void getvalue(Widget w, XtPointer address, XrmQuark type, Cardinal size)
 
67
#else
 
68
static void getvalue(w, address, type, size)
 
69
Widget w;
 
70
XtPointer address;
 
71
XrmQuark type;
 
72
Cardinal size;
 
73
#endif
 
74
{
 
75
    int nChars;
 
76
    int bufferSize;
 
77
 
 
78
    if (type == XmtQString) {
 
79
        String buffer;
 
80
 
 
81
        /* Find out how many characters are in the widget buffer. */
 
82
        nChars = XmCSTextGetLastPosition(w);
 
83
 
 
84
        /* Calculate the buffer size for the entire contents. */
 
85
        bufferSize = (nChars * MB_CUR_MAX) + 1;
 
86
 
 
87
        buffer = XtMalloc(bufferSize);
 
88
 
 
89
        /* Now read out the contents. */
 
90
        XmCSTextGetSubstring(w, 0, nChars, bufferSize, buffer);
 
91
 
 
92
        *(String *)address = buffer;
 
93
    }
 
94
    else if (type == XmtQBuffer) {
 
95
        /* Find out how many characters are in the widget buffer. */
 
96
        nChars = XmCSTextGetLastPosition(w);
 
97
 
 
98
        /* Calculate the buffer size for the entire contents. */
 
99
        bufferSize = (nChars * MB_CUR_MAX) + 1;
 
100
 
 
101
        if (size >= nChars)
 
102
            XmCSTextGetSubstring(w, 0, nChars, size, (char *)address);
 
103
        else {
 
104
            XmCSTextGetSubstring(w, 0, size, size, (char *)address);
 
105
 
 
106
            XmtWarningMsg("XmtDialogGetDialogValues", "xmcstextTrunc",
 
107
                          "The input value is %d characters long\n\tand does not fit into a buffer %d characters long.\n\tThe trailing characters have been truncated.",
 
108
                          nChars, size);
 
109
        }
 
110
    }
 
111
    else
 
112
        XmtWarningMsg("XmtDialogGetDialogValues", "xmtextType",
 
113
                      "Type mismatch:\n\tCan't set input value on a resource of type '%s'.  String or Buffer expected.",
 
114
                      XrmQuarkToString(type));
 
115
}
 
116
 
 
117
static XmtWidgetType cstext = {
 
118
    "XmCSText",
 
119
    NULL,
 
120
    (XmtWidgetConstructor) XmCreateCSText,
 
121
    setvalue,
 
122
    getvalue,
 
123
};
 
124
 
 
125
static XmtWidgetType scstext = {
 
126
    "XmScrolledCSText",
 
127
    NULL,
 
128
    (XmtWidgetConstructor) XmCreateScrolledCSText,
 
129
    setvalue,
 
130
    getvalue,
 
131
};
 
132
 
 
133
#if NeedFunctionPrototypes
 
134
void XmtRegisterXmCSText(void)
 
135
#else
 
136
void XmtRegisterXmCSText()
 
137
#endif
 
138
{
 
139
    _XmtInitQuarks();
 
140
    XmtRegisterWidgetTypes(&cstext, 1);
 
141
}
 
142
 
 
143
#if NeedFunctionPrototypes
 
144
void XmtRegisterXmScrolledCSText(void)
 
145
#else
 
146
void XmtRegisterXmScrolledCSText()
 
147
#endif
 
148
{
 
149
    _XmtInitQuarks();
 
150
    XmtRegisterWidgetTypes(&scstext, 1);
 
151
}
 
152
 
 
153
#else  /* if XmVersion = 2000 */
 
154
/* just so the compiler doesn't complain about an empty file. */
 
155
static char XmtDummy;
 
156
#endif