Debian Codegraph @

libSoXt/src/SoXtImportInterest.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1995-96 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes : SoXtImportInterestList
46 |
47 | Author(s) : David Mott
48 |
49 ______________ S I L I C O N G R A P H I C S I N C . ____________
50 _______________________________________________________________________
51 */
52
53 #include "SoXtImportInterest.h"
54
55 ////////////////////////////////////////////////////////////////////////
56 //
57 // Description:
58 // Append to the paste interest list. cb will be called when dataType
59 // is pasted.
60 //
61 void
62 SoXtImportInterestList::append(
63 Atom dataType, SoXtClipboardImportCB *cb, void *userData)
64 //
65 ////////////////////////////////////////////////////////////////////////
66 {
67 // Remove this dataType if already registered
68 int which = find(dataType);
69 remove(which);
70
71 // If cb is set, add it to the list
72 if (cb != NULL) {
73 SoXtImportInterest *data = new SoXtImportInterest(dataType, cb, userData);
74 list.append(data);
75 }
76 }
77
78 ////////////////////////////////////////////////////////////////////////
79 //
80 // Description:
81 // Find an entry for the passed dataType in the paste list.
82 // Returns -1 if no entry found.
83 //
84 int
85 SoXtImportInterestList::find(Atom dataType)
86 //
87 ////////////////////////////////////////////////////////////////////////
88 {
89 for (int i = 0; i < list.getLength(); i++) {
90 SoXtImportInterest *data = (SoXtImportInterest *) list[i];
91 if (data->getDataType() == dataType)
92 return i;
93 }
94
95 return -1;
96 }
97
98 ////////////////////////////////////////////////////////////////////////
99 //
100 // Description:
101 // Remove the passed entry from the paste interest list.
102 //
103 void
104 SoXtImportInterestList::remove(int which)
105 //
106 ////////////////////////////////////////////////////////////////////////
107 {
108 if (which >= 0 && which < list.getLength()) {
109 SoXtImportInterest *data = (SoXtImportInterest *) list[which];
110 delete data;
111 list.remove(which);
112 }
113 }
114
115 ////////////////////////////////////////////////////////////////////////
116 //
117 // Description:
118 // Return the interest data for 'which' item in the list.
119 //
120 const SoXtImportInterest *
121 SoXtImportInterestList::get(int which)
122 //
123 ////////////////////////////////////////////////////////////////////////
124 {
125 if (which >= 0 && which < list.getLength())
126 return (SoXtImportInterest *) list[which];
127 else return NULL;
128 }
129
130 ////////////////////////////////////////////////////////////////////////
131 //
132 // Description:
133 // Return the data type for 'which' item in the list.
134 //
135 Atom
136 SoXtImportInterestList::getDataType(int which)
137 //
138 ////////////////////////////////////////////////////////////////////////
139 {
140 const SoXtImportInterest *data = get(which);
141 if (data != NULL)
142 return data->getDataType();
143 else return 0;
144 }
145