1 /**
2  *
3  * $Id: Selection.c,v 1.1 2004/08/28 19:22:45 dannybackx Exp $
4  *
5  * Copyright (C) 1995 Free Software Foundation, Inc.
6  * Copyright (C) 1995-2001 LessTif Development Team
7  *
8  * This file is part of the GNU LessTif Library.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  **/
25 
26 static const char rcsid[] = "$Id: Selection.c,v 1.1 2004/08/28 19:22:45 dannybackx Exp $";
27 
28 #include <LTconfig.h>
29 
30 #include <string.h>
31 
32 #include <XmI/XmI.h>
33 #include <Xm/XmP.h>
34 #include <Xm/AtomMgr.h>
35 #include <Xm/TextP.h>
36 #include <Xm/TextFP.h>
37 #include <Xm/TextSelP.h>
38 #include <Xm/TextFSelP.h>
39 
40 #include <XmI/DebugUtil.h>
41 
42 
43 Boolean
_XmTextFieldConvert(Widget w,Atom * selection,Atom * target,Atom * type,XtPointer * value,unsigned long * length,int * format)44 _XmTextFieldConvert(Widget w,
45 		    Atom *selection,
46 		    Atom *target,
47 		    Atom *type,
48 		    XtPointer *value,
49 		    unsigned long *length,
50 		    int *format)
51 {
52     return False;
53 }
54 
55 void
_XmTextFieldLoseSelection(Widget w,Atom * selection)56 _XmTextFieldLoseSelection(Widget w, Atom *selection)
57 {
58 }
59 
60 Boolean
_XmTextConvert(Widget w,Atom * selection,Atom * target,Atom * type,XtPointer * value,unsigned long * length,int * format)61 _XmTextConvert(Widget w,
62 	       Atom *selection,
63 	       Atom *target,
64 	       Atom *type,
65 	       XtPointer *value,
66 	       unsigned long *length,
67 	       int *format)
68 {
69     char    *value_ptr;
70     Boolean get_sel_flag;
71     Boolean motif_sel_flag;
72     Boolean secondary_sel_flag;
73     Boolean primary_sel_flag;
74     Boolean destination_sel_flag;
75     Atom    encoding;
76     Atom    motif_drop_atom;
77     Atom    time_stamp_atom;
78     Atom    compound_text_atom;
79     Atom    text_atom;
80     Atom    multiple_atom;
81     Atom    targets_atom;
82     Atom    delete_atom;
83     Atom    insert_selection_atom;
84     Atom    motif_destination_atom;
85     XmTextSource    source_ts2;
86     char    	*source_string;
87     XmTextPosition     right_tp;
88     XmTextPosition     left_tp;
89     char    *list;
90     Arg     args;
91     Widget  wid;
92     XTextProperty   text_prop_ret;
93     int     count;
94     Widget  wid2;
95     int     status;
96 
97     motif_destination_atom = XmInternAtom( XtDisplay(w), "MOTIF_DESTINATION",
98     	    	    	    	    	   False );
99     insert_selection_atom = XmInternAtom( XtDisplay(w), "INSERT_SELECTION",
100     	    	    	    	    	  False );
101     delete_atom = XmInternAtom( XtDisplay(w), "DELETE", False );
102     targets_atom = XmInternAtom( XtDisplay(w), "TARGETS", False );
103     multiple_atom = XmInternAtom( XtDisplay(w), "MULTIPLE", False );
104     text_atom = XmInternAtom( XtDisplay(w), "TEXT" , False );
105     compound_text_atom = XmInternAtom( XtDisplay(w), "COMPOUND_TEXT", False );
106     time_stamp_atom = XmInternAtom( XtDisplay(w), "TIMESTAMP", False );
107     motif_drop_atom = XmInternAtom( XtDisplay(w), "_MOTIF_DROP", False );
108     left_tp = 0;
109     right_tp = 0;
110     count = 0;
111     list = "ABC";
112     if ( *selection == motif_drop_atom )
113     {
114 	XtSetArg( args, XmNclientData, &wid );
115     	XtGetValues( w, &args, 1 );
116     	wid2 = wid;
117     }
118     else
119     {
120     	wid2 = w;
121     }
122 
123     if ( wid2 == NULL )
124     {
125     	return False;
126     }
127 
128     source_ts2 = Text_Source(wid2);
129     status = XmbTextListToTextProperty( XtDisplay(wid2), &list,
130     	    	    	    	     1, XTextStyle, &text_prop_ret );
131     encoding = 0x270f;
132     if ( status  == Success )
133     {
134     	encoding = text_prop_ret.encoding;
135     }
136     XFree( (char *)text_prop_ret.value );
137     if ( *selection == XA_PRIMARY )
138     {
139     	get_sel_flag = (Text_Source(wid2)->GetSelection)( source_ts2, &left_tp,
140 	    	    	    	    	    	 &right_tp);
141     	primary_sel_flag = True;
142     	motif_sel_flag = False;
143     	destination_sel_flag = False;
144     	secondary_sel_flag = False;
145     }
146     else if ( *selection == motif_destination_atom )
147     {
148     	get_sel_flag = Text_Input(wid)->data->sel_start;
149     	destination_sel_flag = True;
150     	motif_sel_flag = False;
151     	primary_sel_flag = False;
152     	secondary_sel_flag = False;
153     }
154     else if ( *selection == XA_SECONDARY )
155     {
156     	get_sel_flag = _XmTextGetSel2( (XmTextWidget)wid2, &left_tp,
157 	    	    	    	       &right_tp );
158     	secondary_sel_flag = True;
159     	motif_sel_flag = False;
160 
161     	primary_sel_flag = False;
162     	destination_sel_flag = False;
163     }
164     else if ( *selection == motif_drop_atom )
165     {
166     	get_sel_flag = (Text_Source(wid2)->GetSelection)( source_ts2, &left_tp,
167 	    	    	    	    	    	    	  &right_tp );
168     	motif_sel_flag = True;
169     	secondary_sel_flag = False;
170 
171     	primary_sel_flag = False;
172     	destination_sel_flag = False;
173     }
174     else
175     {
176 	return False;
177     }
178 
179     if ( *target == targets_atom )
180     {
181     	value_ptr = XtMalloc( 10 * sizeof( void *) );
182     	*value = value_ptr;
183     	*value_ptr++ = encoding;
184     	*value_ptr++ = targets_atom;
185     	*value_ptr++ = multiple_atom;
186     	*value_ptr++ = time_stamp_atom;
187     	count += 4;
188     	if ( primary_sel_flag == False || destination_sel_flag == False )
189 	{
190 	    *value_ptr++ = insert_selection_atom;
191     	    count += 1;
192 	}
193     	if ( primary_sel_flag == True
194     	|| secondary_sel_flag == True
195 	|| motif_sel_flag == True )
196 	{
197     	    *value_ptr++ = compound_text_atom;
198     	    *value_ptr++ = text_atom;
199     	    *value_ptr++ = 31;
200     	    count += 3;
201 	}
202     	if ( primary_sel_flag == True || motif_sel_flag == True )
203 	{
204     	    *value_ptr++ = delete_atom;
205 	    count += 1;
206 	}
207     	*type = 4;
208     	*length = count;
209 
210     	*format = 0x20;
211     	return True;
212     }
213     else if ( *target == time_stamp_atom )
214     {
215     	value_ptr = XtMalloc( sizeof(void *) );
216     	if ( primary_sel_flag == True )
217 	{
218     	    *value_ptr = source_ts2->data->prim_time;
219 	}
220 	else if ( destination_sel_flag == True )
221 	{
222     	    *value_ptr = Text_Input(wid2)->data->sec_time;
223 	}
224 	else if ( secondary_sel_flag == True || motif_sel_flag == True )
225 	{
226     	    *value_ptr = Text_Input(wid2)->data->lasttime;
227     	}
228     	*value = value_ptr;
229     	*type = 0x14;
230     	*length = 4;
231     	*format = 0x20;
232     	return True;
233     }
234     else if ( *target == XA_STRING )
235     {
236     	*type = 0x1f;
237     	*format = 8;
238     	if ( destination_sel_flag == True || get_sel_flag == False )
239 	{
240     	    return False;
241 	}
242     	source_string = _XmStringSourceGetString( (XmTextWidget)wid2,
243 	    	    	    	left_tp, right_tp, False );
244     	status = XmbTextListToTextProperty( XtDisplay(wid2), &source_string,
245 	    	    	    	    	  1, 0, (XTextProperty*)&right_tp );
246     	XtFree( source_string );
247     	if ( status == Success || status > 0 )
248 	{
249     	    value_ptr = XtMalloc( text_prop_ret.nitems );
250     	    *value = value_ptr;
251     	    memcpy( value_ptr, text_prop_ret.value,
252 	    	    text_prop_ret.nitems );
253     	    XFree( text_prop_ret.value );
254     	    *length = text_prop_ret.nitems;
255     	    return True;
256     	}
257 	else
258 	{
259 	    *value = NULL;
260     	    *length = 0x1c;
261     	    return False;
262 	}
263     }
264     else if ( *target == text_atom )
265     {
266     	if ( destination_sel_flag == True || get_sel_flag == False )
267 	{
268     	    return False;
269 	}
270     	source_string = _XmStringSourceGetString( (XmTextWidget)wid2,
271 	    	    	    	    	    	  left_tp, right_tp,
272 						  False );
273     	status = XmbTextListToTextProperty( XtDisplay(wid2), &source_string,
274 	    	    	    	    1, XStdICCTextStyle, &text_prop_ret );
275     	*type = text_prop_ret.encoding;
276     	*format = text_prop_ret.format;
277     	XtFree( source_string );
278     	if ( status == Success || status > 0 )
279 	{
280     	    value_ptr = XtMalloc( text_prop_ret.nitems );
281     	    *value = value_ptr;
282     	    memcpy( value_ptr, text_prop_ret.value,
283 	    	    text_prop_ret.nitems );
284     	    XFree( text_prop_ret.value );
285     	    *length = text_prop_ret.nitems;
286     	    return True;
287 	}
288         *value = NULL;
289         *length = 0;
290     	return False;
291     }
292     else if ( *target == encoding )
293     {
294     	*type = encoding;
295     	*format = 0x8;
296         if ( destination_sel_flag == True || get_sel_flag == False )
297 	{
298     	    return False;
299 	}
300     	value_ptr = _XmStringSourceGetString( (XmTextWidget)wid2, left_tp,
301 	    	    	    	    	      right_tp, False );
302     	*value = value_ptr;
303     	*length = strlen( value_ptr );
304     	return True;
305     }
306     else if ( *target == compound_text_atom )
307     {
308     	*type = compound_text_atom;
309     	*format = 0x8;
310     	if ( destination_sel_flag == True || get_sel_flag == False )
311 	{
312     	    return False;
313 	}
314     	source_string = _XmStringSourceGetString( (XmTextWidget)wid2, left_tp,
315 	    	    	    	    	    	  right_tp, False );
316     	status = XmbTextListToTextProperty( XtDisplay(wid2), &source_string,
317 	    	    	    	    	    1, XCompoundTextStyle,
318 				    	    &text_prop_ret );
319     	XtFree( source_string );
320     	if ( status == Success || status > 0 )
321 	{
322     	    value_ptr = XtMalloc( sizeof(void *) );
323     	    *value = value_ptr;
324     	    memcpy( value_ptr, text_prop_ret.value, text_prop_ret.nitems );
325     	    XFree( text_prop_ret.value );
326     	    *length = text_prop_ret.nitems;
327             return True;
328 	}
329 	else
330 	{
331             *value = NULL;
332             *length = 0;
333     	    return False;
334     	}
335     }
336     else if ( *target == insert_selection_atom )
337     {
338     	if ( secondary_sel_flag == True )
339 	{
340     	    return False;
341 	}
342 #if 0
343     	return ConvertInsertSelection( w, selection, type, value,
344 	    	    	    	       length, format );
345 #else
346 	return False;
347 #endif
348     }
349     else if ( *target == delete_atom )
350     {
351     	if ( primary_sel_flag == False && motif_sel_flag == False )
352 	{
353 	    return False;
354     	}
355 	/* the other flags are valid FIXME */
356     	return False;
357     }
358     else
359     {
360     	return False;
361     }
362 }
363 
364 void
_XmTextLoseSelection(Widget w,Atom * selection)365 _XmTextLoseSelection(Widget w, Atom *selection)
366 {
367 }
368