1 /* $XConsortium: ScrollFrameT.c /main/5 1995/07/15 20:55:20 drk $ */
2 /*
3  * Motif
4  *
5  * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6  *
7  * These libraries and programs are free software; you can
8  * redistribute them and/or modify them under the terms of the GNU
9  * Lesser General Public License as published by the Free Software
10  * Foundation; either version 2 of the License, or (at your option)
11  * any later version.
12  *
13  * These libraries and programs are distributed in the hope that
14  * they will be useful, but WITHOUT ANY WARRANTY; without even the
15  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU Lesser General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with these librararies and programs; if not, write
21  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22  * Floor, Boston, MA 02110-1301 USA
23  */
24 /*
25  * HISTORY
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 
33 #include "XmI.h"
34 #include <Xm/TraitP.h>
35 #include <Xm/ScrollFrameT.h>
36 #include <Xm/NavigatorT.h>
37 #include "MessagesI.h"
38 #include "ScrollFramTI.h"
39 
40 #define SWMessage3      _XmMMsgScrollFrameT_0000
41 #define SWMessage4      _XmMMsgScrollFrameT_0001
42 
43 
44 
45 /************************************************************************
46  *
47  *  _XmSFAddNavigator convenience function
48  *    Entering here, sf is an initialized scrollframe, and
49  *    scroll_frame_data is always valid (but the move_cb field can be
50  *    NULL, for pure APP_DEFINED case support).
51  *
52  *************************************<->***********************************/
53 void
_XmSFAddNavigator(Widget sf,Widget nav,Mask dimMask,XmScrollFrameData scroll_frame_data)54 _XmSFAddNavigator(
55     Widget sf,
56     Widget nav,
57     Mask dimMask,
58     XmScrollFrameData scroll_frame_data)
59 {
60     XmNavigatorTrait nav_trait ;
61     XmNavigatorDataRec nav_data ;
62 
63     if ((nav_trait = (XmNavigatorTrait)
64 	 XmeTraitGet((XtPointer) XtClass(nav), XmQTnavigator)) != NULL) {
65 
66 	/* check for NULL move_cb */
67 	if (scroll_frame_data->move_cb)
68 	    nav_trait -> changeMoveCB(nav, scroll_frame_data->move_cb,
69 				      (XtPointer) scroll_frame_data->scrollable,
70 				      True) ;
71 
72 	nav_data.valueMask = NavDimMask ;
73 	nav_data.dimMask = dimMask ;
74 	nav_trait -> setValue(nav, &nav_data, False);
75 
76 	if (scroll_frame_data->num_nav_list ==
77 	    scroll_frame_data->num_nav_slots) {
78 	    /* Allocate more space */
79 	    scroll_frame_data->num_nav_slots +=  2;
80 	    scroll_frame_data->nav_list =
81 		(WidgetList) XtRealloc((char*)scroll_frame_data->nav_list,
82 			scroll_frame_data->num_nav_slots * sizeof(Widget));
83 	}
84 
85 	scroll_frame_data->nav_list[scroll_frame_data->num_nav_list] = nav;
86 	scroll_frame_data->num_nav_list++;
87 
88     } else {
89 	XmeWarning(sf, SWMessage3);
90     }
91 
92 }
93 
94 
95 
96 
97 
98 
99 /************************************************************************
100  *
101  *  _XmSFRemoveNavigator convenience function
102  *
103  *************************************<->***********************************/
104 void
_XmSFRemoveNavigator(Widget sf,Widget nav,XmScrollFrameData scroll_frame_data)105 _XmSFRemoveNavigator(
106     Widget sf,
107     Widget nav,
108     XmScrollFrameData scroll_frame_data)
109 {
110     Cardinal	     position, i;
111     XmNavigatorTrait nav_trait ;
112 
113     if ((nav_trait = (XmNavigatorTrait)
114 	 XmeTraitGet((XtPointer) XtClass(nav), XmQTnavigator)) != NULL) {
115 
116 	/* remove the move callback */
117 	if (scroll_frame_data->move_cb)
118 	    nav_trait -> changeMoveCB(nav, scroll_frame_data->move_cb,
119 				(XtPointer) scroll_frame_data->scrollable,
120 				False) ;
121     }  else {
122 	XmeWarning(sf, SWMessage4);
123 	return ;
124     }
125 
126     for (position = 0; position<scroll_frame_data->num_nav_list; position++) {
127         if (scroll_frame_data->nav_list[position] == nav) {
128 	    break;
129 	}
130     }
131     if (position == scroll_frame_data->num_nav_list) return;
132 
133 
134     scroll_frame_data->num_nav_list--;
135     for (i = position; i < scroll_frame_data->num_nav_list; i++) {
136         scroll_frame_data->nav_list[i] = scroll_frame_data->nav_list[i+1];
137     }
138 
139 }
140 
141 
142 /************************************************************************
143  *
144  *  _XmSFUpdateNavigatorsValues convenience function
145  *
146  *************************************<->***********************************/
147 void
_XmSFUpdateNavigatorsValue(Widget sf,XmNavigatorData nav_data,Boolean notify)148 _XmSFUpdateNavigatorsValue(
149         Widget sf,
150         XmNavigatorData nav_data,
151         Boolean notify)
152 {
153     Cardinal i, num_nav_list ;
154     Widget * nav_list ;
155     Boolean inited ;
156 
157     /* there is a possibility that the SW was not inited for
158        navigation business: APP_DEFINED where no scrollbar have
159        been added yet */
160     inited =  ((XmScrollFrameTrait)
161 	       XmeTraitGet((XtPointer) XtClass(sf), XmQTscrollFrame))
162 	->getInfo(sf, NULL, &nav_list, &num_nav_list);
163 
164     if (!inited) return ;
165 
166     /* loop over the associated navigator list and call the change value
167        method for each navigator */
168     /* Updating the first navigator only if notify is True is not
169        enough, since the dimension is pertinent */
170 
171     for (i=0; i < num_nav_list; i++) {
172 	Widget nav = nav_list[i] ;
173 	XmNavigatorSetValueProc	nav_setValue =
174 	    ((XmNavigatorTrait)
175 	     XmeTraitGet((XtPointer) XtClass(nav), XmQTnavigator))->setValue;
176 
177 	nav_setValue(nav, nav_data, notify);
178     }
179 }
180 
181