File: tooltip.c

package info (click to toggle)
mpsql 2.1-2
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 3,528 kB
  • ctags: 4,886
  • sloc: ansic: 35,184; makefile: 3,761; sh: 44
file content (93 lines) | stat: -rw-r--r-- 3,715 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/************************************************************************/
/* Module : tooltip.c					                */
/* Purpose: tooltip module              	                        */
/* By     : Keith R. Davis					        */
/* Date   : 6/10/97					                */
/* Notes  : Copyright(c) 1996-98 Mutiny Bay Software                    */
/*          Some of this code was lifted from a snippet w/ no author    */
/************************************************************************/

#include <Mrm/MrmAppl.h>

static Widget sTooltipPopup = NULL;
static Widget sFrame = NULL;
static Widget sLabel = NULL;
static XmFontList sFontList;

#define BORDER 2

/************************************************************************/
/* Function: InitializeTooltip                                          */
/* Purpose : inits the tooltip shell                                    */
/* Params  : display   : app's shell display 		                */
/*	     className : app's classname 	                        */
/* Returns : nothing			                                */
/************************************************************************/

void InitializeTooltip (Display *display, char *className)
{
  sTooltipPopup = XtVaAppCreateShell ("tooltip", className,
				      applicationShellWidgetClass,
                                      display,
                                      XmNoverrideRedirect, True,
                                      NULL);
  sFrame = (Widget) XmCreateFrame (sTooltipPopup, "frame", NULL, 0);
  XtVaSetValues (sFrame, XmNshadowThickness, 0,
		 XmNborderWidth, 1,
                 XmNmarginWidth, BORDER,
                 XmNmarginHeight, BORDER, NULL);
  sLabel = (Widget) XmCreateLabel (sFrame, "label", NULL, 0);
  XtVaGetValues (sLabel,                                                   
		 XmNfontList, &sFontList,
		 NULL);
  XtManageChild (sFrame);
  XtManageChild (sLabel);
  return;
}

/************************************************************************/
/* Function: PopdownTooltip                				*/
/* Purpose : removes the tooltip window                                 */
/* Params  : none                                                       */
/* Returns : nothing			                                */
/************************************************************************/

void PopdownTooltip (Widget w, XtPointer clientdata, XtPointer callData)
{
  XtPopdown (sTooltipPopup);
  return;
}

/************************************************************************/
/* Function: PopupTooltip                      			        */
/* Purpose : displays the tooltip window                         	*/
/* Params  : button : widget displaying tooltip                         */
/* Returns : nothing			                                */
/************************************************************************/

void PopupTooltip (Widget button)
{
  XmString labelString = NULL;
  Dimension labelWidth = 0;
  Dimension labelHeight = 0;
  Dimension height = 0;
  Position root_x = 0;
  Position root_y = 0;
  
  XtVaGetValues (button, XmNlabelString, &labelString,
		 XmNheight, &height, NULL);
  XtVaSetValues (sLabel, XmNlabelString, labelString, NULL);
  labelWidth  = XmStringWidth  (sFontList, labelString);
  labelHeight = XmStringHeight (sFontList, labelString);
  XtTranslateCoords (button, (Position) 0, (Position) 0,
		     &root_x, &root_y);
  XtVaSetValues (sTooltipPopup,
		 XmNx,      root_x,
		 XmNy,      root_y + height,
		 XmNwidth,  labelWidth + (BORDER * 2 + 2),
		 XmNheight, labelHeight + (BORDER + 4),
		 NULL);
  XtAddCallback (button, XmNdestroyCallback, PopdownTooltip, NULL);
  XtPopup (sTooltipPopup, XtGrabNone);
}