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 librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: utils.c /main/5 1996/10/17 09:36:36 mustafa $ */
24 /************************************<+>*************************************
25 ****************************************************************************
30 * DESCRIPTION: Utility routines
32 * FUNCTIONS: Create_Action_Area
39 * help_hyperyperlink_callback
41 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
42 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
43 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
44 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
46 ****************************************************************************
47 ************************************<+>*************************************/
50 #include <X11/Intrinsic.h>
51 #include <X11/StringDefs.h>
54 #include <Xm/VendorSEP.h>
57 #include <Xm/BulletinB.h>
59 /* Copied from Xm/BaseClassI.h */
60 extern XmWidgetExtData _XmGetWidgetExtData(
62 #if NeedWidePrototypes
63 unsigned int extType) ;
65 unsigned char extType) ;
66 #endif /* NeedWidePrototypes */
68 #include <Dt/HelpDialog.h>
71 #include "sharedFuncs.h"
75 /*............... definitions for Help .............................*/
85 /* Help volume tags used to attach a certian help volume
86 * to a particular call back. Look to function help_callback
89 #define HELP_USING_HELP_VOLUME "Help4Help"
90 #define HELP_USING_STR "_HomeTopic"
91 #define HELP_VOLUME "Filemgr"
92 #define HELP_HELP_MENU_STR "Reference"
93 #define HELP_INTRODUCTION_STR "_HomeTopic"
94 #define HELP_DIR_COPY_STR "FMCopyDirDialogStatusDE"
95 #define HELP_DIR_ERROR_STR "FMCopyDIrDialogErrorDE"
96 #define HELP_OVERWRITE_STR "FMCopyDirOverDialogDE"
97 #define HELP_VERSION_STR "FMHelpMenuDE"
98 #define STOPW_HELP_STR "FMCopyFoldWarnDialogDE"
100 /*--------------------------------------------------------------------
102 *------------------------------------------------------------------*/
107 XtPointer client_data,
110 XtUnmapWidget(XtParent(widget));
114 help_hyperyperlink_callback(
116 XtPointer client_data,
119 DtHelpDialogCallbackStruct *pHyper = (DtHelpDialogCallbackStruct *) call_data;
121 switch(pHyper->hyperType)
123 case DtHELP_LINK_JUMP_NEW:
124 Display_Help(pHyper->helpVolume, pHyper->locationId);
134 XtPointer client_data,
137 char *helpVolume, *locationId;
140 topic = (int) client_data;
141 helpVolume = HELP_VOLUME;
146 locationId = HELP_HELP_MENU_STR;
148 case HELP_INTRODUCTION:
149 locationId = HELP_INTRODUCTION_STR;
152 locationId = HELP_DIR_COPY_STR;
155 locationId = HELP_DIR_ERROR_STR;
158 locationId = HELP_OVERWRITE_STR;
161 locationId = HELP_USING_STR;
162 helpVolume = HELP_USING_HELP_VOLUME;
165 locationId = HELP_VERSION_STR;
167 case STOPW_HELP_DIALOG:
168 locationId = STOPW_HELP_STR;
171 locationId = HELP_USING_STR;
172 helpVolume = HELP_USING_HELP_VOLUME;
175 Help(helpVolume, locationId);
179 /*--------------------------------------------------------------------
181 *------------------------------------------------------------------*/
191 XmVendorShellExtObject vendorExt;
192 XmWidgetExtData extData;
193 int xOffset, yOffset;
194 int pHeight, myHeight, sHeight;
195 int pWidth, myWidth, sWidth;
196 enum { posRight, posBelow, posLeft, posAbove } pos;
199 /* get x, y offsets for the parent's window frame */
200 extData = _XmGetWidgetExtData(parent, XmSHELL_EXTENSION);
203 vendorExt = (XmVendorShellExtObject)extData->widget;
204 xOffset = vendorExt->vendor.xOffset;
205 yOffset = vendorExt->vendor.yOffset;
208 xOffset = yOffset = 0;
210 /* get size/position of screen, parent, and widget */
211 sHeight = HeightOfScreen(XtScreen(parent));;
212 sWidth = WidthOfScreen(XtScreen(parent));
213 pX = XtX(parent) - xOffset;
214 pY = XtY(parent) - yOffset;
215 pHeight = XtHeight(parent) + yOffset + xOffset;
216 pWidth = XtWidth(parent) + 2*xOffset;
217 myHeight = XtHeight(w) + yOffset + xOffset;
218 myWidth = XtWidth(w) + 2*xOffset;
221 XWindowAttributes attr;
223 XGetWindowAttributes(XtDisplay(parent), XtWindow(parent), &attr);
227 * Determine how much space would be left if the child was positioned
228 * to the right, below, left, or above the parent. Choose the child
229 * positioning so that the maximum space is left.
232 space = sWidth - (pX + pWidth + myWidth);
234 if (sHeight - (pY + pHeight + myHeight) > space)
237 space = sHeight - (pY + pHeight + myHeight);
240 if (pX - myWidth > space)
243 space = pX - myWidth;
246 if (pY - myHeight > space)
249 space = pY - myHeight;
252 /* Given relative positioning, determine x, y coordinates for the child */
257 *newX = pX + pWidth + 5;
258 *newY = pY + (pHeight - myHeight)/2;
262 *newX = pX + (pWidth - myWidth)/2;
263 *newY = pY + pHeight + 5;
267 *newX = pX - myWidth - 5;
268 *newY = pY + (pHeight - myHeight)/2;
272 *newX = pX + (pWidth - myWidth)/2;
273 *newY = pY - myHeight - 5;
288 XtSetArg(args[n], XmNtitle, GETMESSAGE(6, 5, "Directory Copy Help")); n++;
289 dialog = DtCreateHelpDialog(G_toplevel, "helpDlg", args, n);
291 XtAddCallback(dialog, DtNhyperLinkCallback,
292 (XtCallbackProc)help_hyperyperlink_callback, NULL);
293 XtAddCallback(dialog, DtNcloseCallback,
294 (XtCallbackProc)help_close_callback, NULL);
306 G_help_dialog = Get_Help_Dialog();
309 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
310 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
311 XtSetArg(args[n], DtNlocationId, locationId); n++;
312 XtSetValues(G_help_dialog, args, n);
314 XtManageChild(G_help_dialog);
315 XtMapWidget(XtParent(G_help_dialog));
326 if(G_help_dialog == NULL)
329 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
330 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
331 XtSetArg(args[n], DtNlocationId, locationId); n++;
332 XtSetArg (args[n], XmNtitle, GETMESSAGE(6, 5, "Directory Copy Help")); n++;
334 G_help_dialog = DtCreateHelpDialog(G_toplevel, "helpDlg", args, n);
336 XtAddCallback(G_help_dialog, DtNhyperLinkCallback,
337 (XtCallbackProc)help_hyperyperlink_callback, NULL);
338 XtAddCallback(G_help_dialog, DtNcloseCallback,
339 (XtCallbackProc)help_close_callback, NULL);
341 XtManageChild(G_help_dialog);
346 XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
347 XtSetArg(args[n], DtNhelpVolume, helpVolume); n++;
348 XtSetArg(args[n], DtNlocationId, locationId); n++;
349 XtSetValues(G_help_dialog, args, n);
352 XtMapWidget(XtParent(G_help_dialog));
357 /*--------------------------------------------------------------------
361 * Use of this function requires #include "sharedFuncs.h"
362 * The source for Create_Action_Area is in dtfile/OverWrite.c and
363 * dtfile/dtcopy/utils.c. Because it uses GETMESSAGE, it could not
364 * be placed in dtcopy/sharedFunc.c.
366 *------------------------------------------------------------------*/
370 Widget parent_widget,
371 ActionAreaDefn actions,
372 Widget *pushbutton_array)
374 Widget action_area, widget;
380 if (actions.defaultAction < 0 || actions.defaultAction > actions.numActions-1)
381 actions.defaultAction = 0;
383 fractbase_value = (TIGHTNESS * actions.numActions) - 1;
384 action_area = XtVaCreateManagedWidget("action_area", xmFormWidgetClass ,parent_widget,
385 XmNfractionBase, fractbase_value,
386 XmNleftAttachment, XmATTACH_FORM,
387 XmNrightAttachment, XmATTACH_FORM,
388 XmNbottomAttachment, XmATTACH_FORM,
391 for (i=0; i < actions.numActions ;i++ )
393 xm_string = XmStringCreateLocalized(GETMESSAGE(actions.actionList[i].msg_set,
394 actions.actionList[i].msg_num,
395 actions.actionList[i].label));
396 widget = XtVaCreateManagedWidget(actions.actionList[i].label,
397 xmPushButtonWidgetClass, action_area,
398 XmNleftAttachment, (i ? XmATTACH_POSITION: XmATTACH_FORM),
399 XmNleftPosition, (TIGHTNESS * i),
400 XmNtopAttachment, XmATTACH_FORM,
401 XmNbottomAttachment, XmATTACH_FORM,
403 ((i != (actions.numActions - 1)) ? XmATTACH_POSITION: XmATTACH_FORM),
404 XmNrightPosition, ((TIGHTNESS*i) + (TIGHTNESS - 1)),
405 XmNshowAsDefault, (i == actions.defaultAction),
406 XmNdefaultButtonShadowThickness, 1,
407 XmNlabelString, xm_string,
409 XmStringFree(xm_string);
413 if (actions.actionList[i].callback)
415 XtAddCallback(widget, XmNactivateCallback,
416 actions.actionList[i].callback, actions.actionList[i].data);
419 if (i == actions.defaultAction)
422 XtVaGetValues (action_area, XmNmarginHeight, &h, NULL);
423 XtVaGetValues (widget, XmNheight, &height, NULL);
426 XtVaSetValues (action_area,
427 XmNdefaultButton, widget,
428 XmNpaneMaximum, height,
429 XmNpaneMinimum, height,
434 if (pushbutton_array != NULL)
435 pushbutton_array[i] = widget;
439 XtManageChild(action_area);
442 } /* end Create_Action_Area */