2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: UIComponent.C /main/9 1998/07/23 17:57:36 mgreess $ */
27 * RESTRICTED CONFIDENTIAL INFORMATION:
29 * The information in this document is subject to special
30 * restrictions in a confidential disclosure agreement bertween
31 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
32 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33 * Sun's specific written approval. This documment and all copies
34 * and derivative works thereof must be returned or destroyed at
37 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 ///////////////////////////////////////////////////////////////////////////////
42 //////////////////////////////////////////////////////////////////////////////
43 // This example code is from the book:
45 // Object-Oriented Programming with C++ and OSF/Motif
48 // Prentice Hall, 1992
51 // Copyright 1991 by Prentice Hall
52 // All Rights Reserved
54 // Permission to use, copy, modify, and distribute this software for
55 // any purpose except publication and without fee is hereby granted, provided
56 // that the above copyright notice appear in all copies of the software.
57 ///////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////
61 ///////////////////////////////////////////////////////////////
62 // UIComponent.C: Base class for all C++/Motif UI components
63 ///////////////////////////////////////////////////////////////
65 #include "UIComponent.h"
69 UIComponent::UIComponent ( const char *name ) : BasicComponent ( name )
77 UIComponent::widgetDestroyedCallback( Widget,
81 UIComponent * obj = (UIComponent *) clientData;
83 obj->widgetDestroyed();
87 UIComponent::widgetDestroyed()
93 UIComponent::installDestroyHandler()
95 assert ( _w != NULL );
98 &UIComponent::widgetDestroyedCallback,
103 UIComponent::manage()
105 assert ( _w != NULL );
106 assert ( XtHasCallbacks ( _w, XmNdestroyCallback ) ==
108 XtManageChild ( _w );
112 UIComponent::displayInCurrentWorkspace()
114 Widget w = baseWidget();
115 while (w && !XtIsShell(w)) w = XtParent(w);
116 if (w && XtIsShell(w)) displayInCurrentWorkspace(w);
121 UIComponent::displayInCurrentWorkspace(Widget shell)
123 while (shell && !XtIsShell(shell)) shell = XtParent(shell);
125 // Make sure the shell is popped up and occupying the current workspace.
126 if (NULL != shell && XtIsShell(shell))
129 Display *display = XtDisplay(shell);
130 Window window = XtWindow(shell);
132 XtVaSetValues(shell, XmNiconic, False, NULL);
133 XRaiseWindow(display, window);
135 /* Get the current Workspace */
136 if (Success == DtWsmGetCurrentWorkspace(
138 XRootWindowOfScreen(XtScreen(shell)),
142 unsigned long num = 0;
145 if (Success==DtWsmGetWorkspacesOccupied(display, window, &ws, &num))
147 /* Already in this workspace? */
148 for (k = 0; k < num; k++)
149 if (ws[k] == pCurrent) break;
151 /* Add to the workspace */
154 size_t nbytes = sizeof(Atom) * (num+1);
155 ws = (Atom*) XtRealloc((char*) ws, nbytes);
157 DtWsmSetWorkspacesOccupied(display, window, ws, num + 1);
163 /* Change the hints to reflect the current workspace */
164 DtWsmSetWorkspacesOccupied(display, window, &pCurrent, 1);
169 UIComponent::~UIComponent()
171 // Make sure the widget hasn't already been destroyed
175 // Remove destroy callback so Xt can't call the callback
176 // with a pointer to an object that has already been freed
178 XtRemoveCallback ( _w,
180 &UIComponent::widgetDestroyedCallback,
186 UIComponent::getResources( const XtResourceList resources,
187 const int numResources )
191 assert ( _w != NULL );
192 assert ( resources != NULL );
194 // Retrieve the requested resources relative to the
195 // parent of this object's base widget
196 // Added support for doing getResources on the Application
198 if ( XtParent( _w ) )
199 XtGetSubresources ( XtParent( _w ),
208 XtGetSubresources ( _w ,
221 UIComponent::setDefaultResources( const Widget w,
222 const String *resourceSpec )
225 Display *dpy = XtDisplay ( w ); // Retrieve the display pointer
226 XrmDatabase rdb = NULL; // A resource data base
228 // Create an empty resource database
230 rdb = XrmGetStringDatabase ( "" );
232 // Add the Component resources, prepending the name of the component
235 while ( resourceSpec[i] != NULL )
237 char *buf = new char[1000];
238 sprintf(buf, "*%s%s", _name, resourceSpec[i++]);
239 XrmPutLineResource( &rdb, buf );
243 // Merge them into the Xt database, with lowest precendence
247 XrmDatabase db = XtDatabase(dpy);
248 XrmCombineDatabase(rdb, &db, FALSE);
251 #endif /* DEAD_WOOD */
253 #ifndef CAN_INLINE_VIRTUALS
255 UIComponent::className(void)
257 return "UIComponent";
259 #endif /* ! CAN_INLINE_VIRTUALS */