|
|
DataMuseum.dkPresents historical artifacts from the history of: Regnecentalen RC-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Regnecentalen RC-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T U x
Length: 13198 (0x338e)
Types: TextFile
Notes: UNIX file
Names: »xmfonts.c«
└─⟦a0a611847⟧ Bits:30004636/disk1.imd INTERACTIVE Motif Environment Development System
└─⟦a0a611847⟧ UNIX Filesystem
└─⟦this⟧ »xt/new/usr/lib/X11/examples/xmsamplers/xmfonts.c«
#ifdef REV_INFO
#ifndef lint
static char SCCSID[] = "OSF/Motif: @(#)xmfonts.c 1.2 - 89/08/31 - 11:18:50";
#endif /* lint */
#endif /* REV_INFO */
/**---------------------------------------------------------------------
***
*** file: xmfonts.c
***
***
***
*** (c) Copyright 1989 by Open Software Foundation, Inc.
*** All Rights Reserved.
***
*** (c) Copyright 1989 by Hewlett-Packard Company.
***
***
*** defaults: xmfonts.c depends on these defaults:
!
*allowShellResize: true
*borderWidth: 0
*highlightThickness: 2
*traversalOn: true
*keyboardFocusPolicy: explicit
*menuAccelerator: <Key>KP_F2
*fontList: vr-20
!
xmfonts*XmScrolledWindow.height: 432
xmfonts*XmScrolledWindow.width: 690
xmfonts*menu_bar*background: #58f
!
***-------------------------------------------------------------------*/
\f
/*-------------------------------------------------------------
** Include Files
*/
#include <stdio.h>
#include <string.h>
#ifndef __TYPES__
#define __TYPES__
#include <sys/types.h>
#endif /* __TYPES__ */
#ifdef SYS_DIR
#include <sys/dir.h>
#else
#ifdef NDIR
#include <ndir.h>
#else
#include <dirent.h>
#endif
#endif
#include <X11/Intrinsic.h>
#include <X11/IntrinsicP.h>
#include <X11/CoreP.h>
#include <X11/Shell.h>
#include <Xm/Xm.h>
#include <Xm/BulletinB.h>
#include <Xm/CascadeB.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/MainW.h>
#include <Xm/MessageB.h>
#include <Xm/PushB.h>
#include <Xm/PushBG.h>
#include <Xm/RowColumn.h>
#include <Xm/ScrollBar.h>
#include <Xm/ScrolledW.h>
\f
/*-------------------------------------------------------------
** Forward Declarations
*/
void main (); /* main logic for application */
Widget CreateApplication (); /* create main window */
Widget CreateFontSample (); /* create font display window */
Widget CreateHelp (); /* create help window */
void SelectFontCB (); /* callback for font buttons */
void CloseCB (); /* callback for close button */
void HelpCB (); /* callback for help button */
void QuitCB (); /* callback for quit button */
/*-------------------------------------------------------------
** Global Variables
*/
#define MAX_ARGS 20
#define TITLE_STRING "X Font Sampler"
typedef struct {
char *fontpath;
} ApplicationData, *ApplicationDataPtr;
ApplicationData AppData;
#define XtNfontPath "fontPath"
#define XtCFontPath "FontPath"
static XtResource resources[] = {
{ XtNfontPath, XtCFontPath, XmRString, sizeof(String),
XtOffset(ApplicationDataPtr, fontpath), XmRString, "/usr/lib/X11/fonts" }
};
static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
\f
/*-------------------------------------------------------------
** main - main logic for application
*/
void main (argc,argv)
unsigned int argc;
char **argv;
{
Display *display; /* Display */
Widget app_shell; /* ApplicationShell */
Widget main_window; /* MainWindow */
/* Initialize toolkit and open the display.
*/
XtToolkitInitialize();
display = XtOpenDisplay (NULL, NULL, argv[0], "XMdemos", NULL, 0,
&argc, argv);
if (!display) {
XtWarning ("xfonts: Can't open display, exiting...");
exit (0);
}
/* Create application shell.
*/
app_shell = XtAppCreateShell (argv[0], "XMdemos",
applicationShellWidgetClass, display, NULL, 0);
XtGetApplicationResources(app_shell,
&AppData,
resources,
XtNumber(resources),
NULL,
0);
/* Create and realize main application window.
*/
main_window = CreateApplication (app_shell);
XtRealizeWidget (app_shell);
/* Get and dispatch events.
*/
XtMainLoop ();
}
\f
/*-------------------------------------------------------------
** CreateApplication - create main window
*/
Widget CreateApplication (parent)
Widget parent; /* parent widget */
{
Widget main_window; /* MainWindow */
Widget menu_bar; /* MenuBar */
Widget menu_pane; /* MenuPane */
Widget cascade; /* CascadeButton */
Widget frame; /* Frame */
Widget swindow; /* ScrolledWindow */
Widget row_column; /* RowColumn */
Widget button; /* PushButtonGadget */
Widget hsb, vsb; /* ScrollBars */
Arg args[MAX_ARGS]; /* arg list */
register int n; /* arg count */
DIR *dirp; /* directory pointer */
#if (defined SYS_DIR) || (defined NDIR)
struct direct *item; /* entry in directory */
#else
struct dirent *item; /* entry in directory */
#endif
char name[15]; /* name string */
int len; /* string length */
XmString label_string;
/* Create MainWindow.
*/
n = 0;
main_window = XmCreateMainWindow (parent, "main1", args, n);
XtManageChild (main_window);
/* Create MenuBar in MainWindow.
*/
n = 0;
menu_bar = XmCreateMenuBar (main_window, "menu_bar", args, n);
XtManageChild (menu_bar);
/* Create "Exit" PulldownMenu.
*/
n = 0;
menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n);
n = 0;
button = XmCreatePushButton (menu_pane, "Quit", args, n);
XtManageChild (button);
XtAddCallback (button, XmNactivateCallback, QuitCB, NULL);
n = 0;
XtSetArg (args[n], XmNsubMenuId, menu_pane); n++;
cascade = XmCreateCascadeButton (menu_bar, "Exit", args, n);
XtManageChild (cascade);
/* Create "Help" button.
*/
n = 0;
cascade = XmCreateCascadeButton (menu_bar, "Help", args, n);
XtManageChild (cascade);
XtAddCallback (cascade, XmNactivateCallback, HelpCB, NULL);
n = 0;
XtSetArg (args[n], XmNmenuHelpWidget, cascade); n++;
XtSetValues (menu_bar, args, n);
/* Create Frame MainWindow and ScrolledWindow in Frame.
*/
n = 0;
XtSetArg (args[n], XmNmarginWidth, 2); n++;
XtSetArg (args[n], XmNmarginHeight, 2); n++;
XtSetArg (args[n], XmNshadowThickness, 1); n++;
XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
frame = XmCreateFrame (main_window, "frame", args, n);
XtManageChild (frame);
n = 0;
XtSetArg (args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
XtSetArg (args[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
swindow = XmCreateScrolledWindow (frame, "swindow", args, n);
XtManageChild (swindow);
/* Create RowColumn in ScrolledWindow to manage buttons.
*/
n = 0;
XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
XtSetArg (args[n], XmNnumColumns, 5); n++;
row_column = XmCreateRowColumn (swindow, "row_column", args, n);
XtManageChild (row_column);
/* Set MainWindow areas and add tab groups
*/
XmMainWindowSetAreas (main_window, menu_bar, NULL, NULL, NULL,
frame);
n = 0;
XtSetArg (args[n], XmNhorizontalScrollBar, &hsb); n++;
XtSetArg (args[n], XmNverticalScrollBar, &vsb); n++;
XtGetValues (main_window, args, n);
XmAddTabGroup (row_column);
if (hsb)
XmAddTabGroup (hsb);
if (vsb)
XmAddTabGroup (vsb);
/* Create a PushButton widget for each font.
*/
/* open the font directory */
dirp = opendir (AppData.fontpath);
/* read one entry each time through the loop */
for (item = readdir (dirp); item != NULL; item = readdir (dirp))
{
len = (strlen (item -> d_name));
/* discard entries that don't end in ".xxx" */
if ((len < 5) || (item -> d_name[len-4] != '.')) continue;
/* copy the name (except extension) from the entry */
strncpy (name, item -> d_name, len-4);
name[len-4] = '\0';
/* create PushButton in RowCol */
n = 0;
label_string = XmStringCreateLtoR(name, charset);
XtSetArg (args[n], XmNlabelString, label_string); n++;
button = XmCreatePushButtonGadget (row_column, name, args, n);
XtManageChild (button);
XtAddCallback (button, XmNarmCallback, SelectFontCB, NULL);
XmStringFree (label_string);
}
/* Return MainWindow.
*/
return (main_window);
}
\f
/*-------------------------------------------------------------
** CreateFontSample - create font display window
*/
Widget CreateFontSample (parent)
Widget parent; /* parent widget */
{
Widget message_box; /* MessageBox Dialog */
Widget button;
Arg args[MAX_ARGS]; /* arg list */
register int n; /* arg count */
char *name = NULL; /* font name */
XFontStruct *font = NULL; /* font pointer */
XmFontList fontlist = NULL; /* fontlist pointer */
static char message[BUFSIZ]; /* text sample */
XmString name_string = NULL;
XmString message_string = NULL;
XmString button_string = NULL;
/* Get font name.
*/
n = 0;
XtSetArg (args[n], XmNlabelString, &name_string); n++;
XtGetValues (parent, args, n);
XmStringGetLtoR (name_string, charset, &name);
/* Load font and generate message to display.
*/
if (name)
font = XLoadQueryFont (XtDisplay (XtParent (parent)), name);
if (!font)
sprintf (message, "Unable to load font: %s\0", name);
else
{
fontlist = XmFontListCreate (font, charset);
sprintf (message, "\
This is font %s.\n\
The quick brown fox jumps over the lazy dog.\0", name);
}
message_string = XmStringCreateLtoR (message, charset);
button_string = XmStringCreateLtoR ("Close", charset);
/* Create MessageBox dialog.
*/
n = 0;
if (fontlist)
{
XtSetArg (args[n], XmNlabelFontList, fontlist); n++;
}
XtSetArg (args[n], XmNdialogTitle, name_string); n++;
XtSetArg (args[n], XmNokLabelString, button_string); n++;
XtSetArg (args[n], XmNmessageString, message_string); n++;
message_box = XmCreateMessageDialog (XtParent (XtParent(parent)), "fontbox",
args, n);
button = XmMessageBoxGetChild (message_box, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild (button);
button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (button);
/* Free strings and return MessageBox.
*/
if (fontlist) XtFree (fontlist);
if (name_string) XtFree (name_string);
if (message_string) XtFree (message_string);
if (button_string) XtFree (button_string);
return (message_box);
}
\f
/*-------------------------------------------------------------
** CreateHelp - create help window
*/
Widget CreateHelp (parent)
Widget parent; /* parent widget */
{
Widget button;
Widget message_box; /* Message Dialog */
Arg args[MAX_ARGS]; /* arg list */
register int n; /* arg count */
static char message[BUFSIZ]; /* help text */
XmString title_string = NULL;
XmString message_string = NULL;
XmString button_string = NULL;
/* Generate message to display.
*/
sprintf (message, "\
These are buttons for the fonts in the X11 font directory. \n\
The button label is the name of the font. When you select \n\
a button, a small window will display a sample of the font. \n\n\
Press the 'close' button to close a font window. \n\
Select 'quit' from the 'exit' menu to exit this application.\0");
message_string = XmStringCreateLtoR (message, charset);
button_string = XmStringCreateLtoR ("Close", charset);
title_string = XmStringCreateLtoR ("xmfonts help", charset);
/* Create MessageBox dialog.
*/
n = 0;
XtSetArg (args[n], XmNdialogTitle, title_string); n++;
XtSetArg (args[n], XmNokLabelString, button_string); n++;
XtSetArg (args[n], XmNmessageString, message_string); n++;
message_box = XmCreateMessageDialog (parent, "helpbox", args, n);
button = XmMessageBoxGetChild (message_box, XmDIALOG_CANCEL_BUTTON);
XtUnmanageChild (button);
button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
XtUnmanageChild (button);
/* Free strings and return MessageBox.
*/
if (title_string) XtFree (title_string);
if (message_string) XtFree (message_string);
if (button_string) XtFree (button_string);
return (message_box);
}
\f
/*-------------------------------------------------------------
** SelectFontCB - callback for font buttons
*/
void SelectFontCB (w, client_data, call_data)
Widget w; /* widget id */
caddr_t client_data; /* data from application */
caddr_t call_data; /* data from widget class */
{
Widget message_box;
/* Create font sample window.
*/
message_box = CreateFontSample (w);
/* Display font sample window.
*/
XtManageChild (message_box);
}
\f
/*-------------------------------------------------------------
** CloseCB - callback for close button
*/
void CloseCB (w, client_data, call_data)
Widget w; /* widget id */
caddr_t client_data; /* font pointer */
caddr_t call_data; /* data from widget class */
{
XFontStruct *font = (XFontStruct *) client_data;
Widget message_box = XtParent (w);
Widget shell = XtParent (message_box);
/* Free font.
*/
if (font) XFreeFont (XtDisplay (w), font);
/* Unmanage and destroy widgets.
*/
XtUnmanageChild (message_box);
XtDestroyWidget (shell);
}
\f
/*-------------------------------------------------------------
** HelpCB - callback for help button
*/
void HelpCB (w, client_data, call_data)
Widget w; /* widget id */
caddr_t client_data; /* data from application */
caddr_t call_data; /* data from widget class */
{
Widget message_box; /* MessageBox */
/* Create help window.
*/
message_box = CreateHelp (w);
/* Display help window.
*/
XtManageChild (message_box);
}
\f
/*-------------------------------------------------------------
** QuitCB - callback for quit button
*/
void QuitCB (w, client_data, call_data)
Widget w; /* widget id */
caddr_t client_data; /* data from applicaiton */
caddr_t call_data; /* data from widget class */
{
/* Terminate the application.
*/
exit (0);
}