(mm) | Balloon help in Motif application | ||||||||||||||
Home | Software | Count | |||||||||||||||
Software: GWT GWTOAuthLogin iPhone/iPad iOSExamples BiteByteConverter X/Motif ansi xterm grabc mdgclock miv mplaymidi mppp mxascii mcmap mxcmap mxconsole mxkill mxshowfont qtip xmastm yrolo Web privategpt mhttpd web counter upload.pl TimeTrack.pl mod_auth_ldap Games fltkmm iphonemm Go (cross-platform) go-xbuild-go mailsend-go markdown-toc-go gomail-fork githubdownloadcount genmake-go github-profilegen-go hod-go applehealth2csv Java cdcl cdclgwt jdgclock Libraries libcalen libmcfg libsll libmsock Java cdcl cdclgwt jdgclock Libraries libcalen libmcfg libsll libmsock Misc cubic-fix bangla font dpr genmake hod smtp.pl vhtml phones_ldap showpic_ldap mbasecalc fluid_hack kdialppp strip2csv googlecode-upload mrdialog RNCryptor-C MS Windows mwinclip.pl mbasecalc mailsend wiv mouse_mover |
Introduction
Writing balloon help
We will write the Qtip library in C. Let declare an internal data structure with two members, an object of type Widget and a pointer to char: typedef struct _QtipData { Widget widget; /* widget to bind help for */ char *text; /* help text, can be NULL */ } QtipData;Here, text is the help text (can be NULL) and widget
is the push button or any other type of widget to bind the help for.
Let's write the Qtip() function now.
Note, you do not need to type the code described below, a library with
source code (commented) and documentation is supplied.
1 void Qtip(Widget widget,char *text) 2 { 3 QtipData *data=(QtipData *) 4 XtNew(QtipData); 5 6 if (text != (char *) NULL) 7 data->text=XtNewString(text); 8 else 9 data->text=(char *) NULL; 10 11 data->widget=widget; 12 13 /* 14 ** check if the widget is a subclass of Core Widget class 15 */ 16 if (XtIsWidget(widget) == False) 17 { 18 return; 19 } 20 21 XtAddEventHandler(widget, 22 EnterWindowMask | LeaveWindowMask, 23 False, 24 (XtEventHandler) QtipCb, 25 (XtPointer) data); 26 }At line 3, we allocate enough memory for the structure. From line 6 to 11, we filled the members of the structure QtipData .
At line 16, we make sure that the widget passed to the function is not a gadget. If it is a gadget, the function will return silently. We can not use gadgets, because among other limitations, gadgets can not have event handlers. At line 21, we registered an event handler for the widget. This event handler detects when the mouse pointer is moved in and out of the widget.
At line 22,
Notice At line 10, we register a timeout routine,that is a routine will be called after a certain time is elapsed.
At line 12,
At line 13, The code segment from line 19-33 gets executed when the mouse pointer is moved out of the widget. At line 24, if timeout is still not reached, we remove the timeout. At line 29, if the tip window is up, we bring it down.
Now let us look at some segments of the function At line 48, we create a label widget on the shell widget. At line 60, we check if a help text is passed, if so, create a motif compound string out of it (line 62). If no help text is passed, we use the push button's label text as the help message (line 65).
At line 70 and 71, we determine the width and height of the help message.
Note the variable
At line 78 and 79, we obtain the width (w) and height (h) of the push button widget respectively. Please refer to Figure 1. In Figure 1, the window with message Open File is a tip window.
I decided to position the tip window at half way (w/2) from widget's left
edget and 2 pixels below (h+2) the widget's bottom edge.
At line 87, the Xt function
At line 92, we call At line 98, we set the help text to the label widget. If you remember, we created the label on top of the tip shell. At line 105, we free the help text (compound string), because motif library already made a copy of it when we set the text to the label at line 98. If we do not free it, it will create a "memory leak". And finally we manage the tip shell widget at line 108, so that it shows up on our screen.
Qtip library
#include <qtip.h> void Qtip(Widget widget,char *text) where, widget specifies the widget to bind help for text specifies the quick tip text (can be NULL)If text is passed as NULL, the library will try to use the
widget's label text as help message. If help text is passed to the function,
it can not be changed, therefore, it is better to pass NULL. This way, the
help message can be changed any time just by changing the X resources.
Obtaining source
qtip1.1.tar.gz is gzip compressed tar file. If you do not have gzip, it is available at ftp://prep.ai.mit.edu/pub/gnu/gzip-1.2.4.tar
Steps to compile
guzip < qtip1.1.tar.gz | tar xvf -To compile the library, at the shell prompt, type: cd qtip1.1 xmkmf makeTo compile the demo program, type: cd demo xmkmf makeTo run the demo program, type: ./qtip_demo
Example
/* ** an example of using Qtip() function call to add balloon help ** to compile: ** cc qtip_simple.c -o qtip_simple -I.. -L.. -lQtip -lXm -lXt -lX11 */ #include <qtip.h> /* bitmap for push button */ #define open_width 20 #define open_height 20 static char open_bits[] = { 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x30, 0x0a, 0xfc, 0x00, 0x0a, 0xfc, 0x10, 0x0c, 0xff, 0x7f, 0x0f, 0xff, 0x7f, 0x00, 0xff, 0x7f, 0x00, 0xff, 0x7f, 0x00, 0xff, 0xff, 0x0f, 0xbf, 0xaa, 0x0a, 0x3f, 0x55, 0x05, 0xdf, 0xaa, 0x06, 0x4f, 0x55, 0x03, 0xaf, 0xaa, 0x02, 0xa7, 0xaa, 0x01, 0x57, 0x55, 0x01, 0xab, 0xaa, 0x00, 0x55, 0xd5, 0x00, 0xff, 0x7f, 0x00}; /* fallback resources */ static char *app_defaults[]= { "Foo*background: gray", "Foo*keyboardFocusPolicy: pointer", "Foo*tipLabel*fontList: -*-helvetica-medium-r-*-*-*-120-*-*-*-*-iso8859-*", "Foo*tipShell.borderWidth: 1", "Foo*tipShell.borderColor: red", "Foo*tipLabel.background: #FFFFCC", "Foo*tipLabel.foreground: black", NULL }; int main(int argc,char **argv) { Widget toplevelW, pushbW; XtAppContext app; Pixmap pixmap; Display *display; unsigned int depth; int screen; Window rootw; Pixel bg, fg; /* ** create toplevel shell, note the class of the app is Foo */ toplevelW=XtVaAppInitialize(&app,"Foo", NULL,0,&argc,argv,app_defaults,NULL); display=XtDisplay(toplevelW); rootw=XDefaultRootWindow(display); screen=XDefaultScreen(display); depth=XDefaultDepth(display,screen); /* create the push button widget (not gadget) */ pushbW=XtVaCreateManagedWidget("Open File", xmPushButtonWidgetClass,toplevelW, NULL); /* get the background and foreground color */ XtVaGetValues(pushbW, XmNforeground,&fg, XmNbackground,&bg, NULL); /* create pixmap from X11 bitmap */ pixmap=XCreatePixmapFromBitmapData(display,rootw, open_bits, open_width, open_height, (unsigned long) fg, (unsigned long) bg, depth); /* set the pixmap to the button */ if (pixmap != (Pixmap) NULL) { XtVaSetValues(pushbW, XmNlabelType,XmPIXMAP, XmNlabelPixmap,pixmap, NULL); } /* ** now call Qtip() to bind balloon help. ** Note, we'r passing the text argument as NULL, so the ** function will use the label text of the button as ** help message */ Qtip(pushbW, (char *) NULL); XtManageChild(pushbW); XtRealizeWidget(toplevelW); XtAppMainLoop(app); return (0); /* won't be here*/ }X Resources The appearance of the quick tip window can be controlled via several X resources. If no X resource is set, the appearance will be inherited from the application's top level shell and XmLabel.
Here is an example of an X resources file of an application whose class name
is Foo.
License - BSD
URL of this page: |
||||||||||||||
back | Page updated: Thu Oct 9 05:02:23 2025 GMT Copyright © 2025 muquit@gmail.com. |