Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,131 @@
/* $TOG: DtPrintinfo.C /main/6 1998/07/24 16:10:28 mgreess $ */
// User Interface headers
#include "DtApp.h"
#include "DtPrinterIcon.h"
#include "Invoke.h"
#ifndef NO_CDE
extern "C" {
#include <Dt/EnvControlP.h>
}
#endif
// Object headers
#include "PrintSubSys.h"
// Message header
#include "dtprintinfomsg.h"
nl_catd dtprintinfo_cat = NULL;
#include <stdlib.h> // This is for the getenv function
#include <unistd.h> // This is for the getuid function
#include <string.h>
#include <errno.h>
#if defined(aix) || defined(USL) || defined(__uxp__)
extern "C" { extern int seteuid(uid_t); }
#endif
#ifdef hpux
static char **msg_strings = NULL;
// Cannot use multiple catgets paramemter calls in functions because the
// previous catgets returned value is overwritten by later catgets calls
// Example: this would fail on HP systems
// sprintf(buf, "%s %s" catgets(...), catgets(...))
char *Catgets(nl_catd catd, int set_num, int msg_num, char *s)
{
if (!msg_strings)
return s;
if (!msg_strings[msg_num])
msg_strings[msg_num] = strdup(catgets(catd, set_num, msg_num, s));
return msg_strings[msg_num];
}
#endif
int main(int argc, char **argv)
{
#ifndef NO_CDE
_DtEnvControl(DT_ENV_SET);
#endif
// run as user's UID
#ifdef hpux
setresuid(getuid(), getuid(), (uid_t)0);
#else
seteuid(getuid());
#endif
setlocale(LC_ALL, "");
char *lang = getenv("LANG");
if (lang && strcmp(lang, "C"))
{
errno = 0;
#ifdef NL_CAT_LOCALE
dtprintinfo_cat = catopen("dtprintinfo", NL_CAT_LOCALE);
#else
dtprintinfo_cat = catopen("dtprintinfo", 0);
#endif
if ((nl_catd) errno || dtprintinfo_cat == (nl_catd) -1)
dtprintinfo_cat = NULL;
#ifdef hpux
else
msg_strings = (char **)calloc(LAST_MSG_NO, sizeof(char *));
#endif
}
if (!STRCMP(argv[1], "-help"))
{
char *output;
char *cmd = new char [strlen(LIST_QUEUES) + 30];
sprintf(cmd, "%s | awk '{print \"\\t\", $1}'", LIST_QUEUES);
Invoke *_thread = new Invoke(cmd, &output);
printf(MESSAGE(CommandLineHelpL), output);
printf("\n");
delete output;
delete [] cmd;
delete _thread;
return 0;
}
char *progname = strrchr(argv[0], '/');
if (progname)
progname++;
else
progname = argv[0];
if (!STRCMP(argv[1], "-populate"))
{
if (getuid() != 0)
{
fprintf(stderr, MESSAGE(RootUserL), progname, "-populate");
fprintf(stderr, "\n");
return 1;
}
PrintSubSystem *prt = new PrintSubSystem(NULL);
int n_queues = prt->NumChildren();
// Get Print Subsystem children, (these are queues)
Queue **queues = (Queue **)prt->Children();
int i;
for (i = 0; i < n_queues; i++)
{
DtPrinterIcon *icon = new DtPrinterIcon(NULL, NULL, queues[i],
INITIALIZE_PRINTERS);
icon->CreateActionFile();
delete icon;
}
return 0;
}
DtApp *app = new DtApp(progname, &argc, argv);
app->Visible(true);
app->Run();
return 0;
}

View File

@@ -0,0 +1,19 @@
!######################################################################
!#
!# Dtprintinfo
!#
!# Common Desktop Environment (CDE)
!#
!# Application Defaults for the Print Manager and Print Jobs applications
!#
!# (c) Copyright 1993, 1994 Hewlett-Packard Company
!# (c) Copyright 1993, 1994 International Business Machines Corp.
!# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
!# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary
!# of Novell, Inc.
!#
!#
!######################################################################
#include "Dt"

View File

@@ -0,0 +1,94 @@
XCOMM $TOG: Imakefile /main/21 1998/08/25 12:58:41 mgreess $
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
EXTRA_LOAD_FLAGS = ExtraLoadFlags $(UNSHARED_CXXLIB)
#define IHaveSubdirs
#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CXXDEBUGFLAGS=$(CXXDEBUGFLAGS)'
SUBDIRS = util libUI objects UI
MakeSubdirs($(SUBDIRS))
DependSubdirs($(SUBDIRS))
DTPRINTINFO_GEN = \
dtprintinfo_cat.h \
dtprintinfo_msg.h \
dtprintinfo.msg
all:: $(DTPRINTINFO_GEN)
#ifdef SunArchitecture
.NO_PARALLEL:
#endif
INCLUDES = -I. -I./UI -I./libUI -I./util -I./libUI/MotifUI \
-I./objects -I./objects/PrintObj
DEPLIBS = ./libUI/MotifUI/libMotifUI.a ./util/libUtil.a \
./UI/libDtPrintinfo.a ./objects/PrintObj/libPrintObj.a \
$(DEPDTHELPLIB) $(DEPDTWIDGETLIB) $(DEPDTSVCLIB) $(DEPTTLIB) \
$(DEPXMLIB) $(DEPXTOOLLIB) $(DEPXPLIB) $(DEPXLIB)
#ifdef SunArchitecture
LOCAL_LIBRARIES = ./UI/libDtPrintinfo.a ./util/libUtil.a \
./libUI/MotifUI/libMotifUI.a ./objects/PrintObj/libPrintObj.a \
$(DTWIDGETLIB) $(DTSVCLIB) $(TTLIB) $(XMLIB) $(XTOOLLIB) \
$(XPLIB) $(XLIB)
#else
LOCAL_LIBRARIES = ./UI/libDtPrintinfo.a ./util/libUtil.a \
./libUI/MotifUI/libMotifUI.a ./objects/PrintObj/libPrintObj.a \
$(DTHELPLIB) $(DTWIDGETLIB) $(DTSVCLIB) $(TTLIB) $(XMLIB) \
$(XTOOLLIB) $(XPLIB) $(XLIB)
#endif /* SunArchitecture */
SYS_LIBRARIES = DtClientSysLibs DtClientExtraLibs
AWK = awk
#ifdef SunArchitecture
AWK = nawk
#endif
#ifdef RsArchitecture
DEFINES = -DHAS_EXCEPTIONS
#endif
#ifdef USLArchitecture
AWK = nawk
#endif
#ifdef UXPArchitecture
AWK = nawk
#endif
#ifdef AlphaArchitecture
DEFINES = -D_TOOLTALK
#endif
/* special processing for message files */
SYM2NUM_CMD = ./sym2num
SRCS = DtPrintinfo.C
OBJS = libUI/BaseUI.o objects/BaseObj.o DtPrintinfo.o
PROGRAM = dtprintinfo
NormalCplusplusObjectRule()
ComplexCplusplusProgramTarget(dtprintinfo)
dtprintinfo_msg.h dtprintinfo.msg: dtprintinfo.msg.src
rm -f dtprintinfo_msg.h dtprintinfo.msg
$(SYM2NUM_CMD) dtprintinfo dtprintinfo.msg.src> dtprintinfo.msg
dtprintinfo_cat.h: dtprintinfo.msg.src
rm -f dtprintinfo_cat.h
${AWK} -f msg.awk dtprintinfo.msg.src > dtprintinfo_cat.h
includes:: dtprintinfo_cat.h dtprintinfo_msg.h
depend:: dtprintinfo_cat.h dtprintinfo_msg.h
clean::
$(RM) *.map $(DTPRINTINFO_GEN)

View File

@@ -0,0 +1,123 @@
/* $XConsortium: README /main/2 1996/07/15 14:15:33 drk $ */
Directories:
libUI - Contains base class for UI
libUI/MotifUI - Contains Motif UI classes
UI - Subclasses of objects in libUI/MotifUI. These objects
define the UI for dtprintinfo.
objects - Contains base class for objects
objects/PrintObj - Contains print queue objects
util - Contains utility classes
service - No longer used
Actions
The following actions are defined in /usr/dt/appconfig/types/C/print.dt.
DtPrintManager - runs 'dtprintinfo -all'
DtPrint (no args) - runs the DtPrintinfo action
DtPrint (with args) - runs the Print action
DtPrintinfo (no args) - runs 'dtprintinfo' to show the LPDEST or
default printer
DtPrintinfo (with args) - runs 'dtprintinfo -p <printer>' to show the
specific printer
The default printer actions are defined in /etc/dt/appconfig/types/C by
running 'dtprintinfo -populate'. There's a datatype (action definition)
file for each queue on the system name <printer>.dt.
<printer>_Print (no args) - runs the 'DtPrintinfo <printer>' action.
<printer>_Print (with args) - runs the 'Print' action.
Printer action files are created in $HOME/.dt/.Printers. These are empty
files named <printer>_Print and have the execute bit set. They are the
action files that are supplied when a printer is dragged from Print Manager
to the File Manager or Front Panel.
The CreateActionFile function in UI/DtPrinterIcon.C creates the system action
definition files in /etc/dt/appconfig/types/$LANG and customized action
definition in $HOME/.dt/types. The Apply function in UI/DtPrtProps.C modifies
action definition in $HOME/.dt/types.
Drag-n-Drop
The guts of drag-n-drop (DND) is coded in the libUI/MotifUI/DtDND.C file.
Currently, only the DtFILENAME_TRANSFER protocol is used. The printer
icons, DtPrinterIcon objects defined in UI/DtPrinterIcon.C, use the DtDND
class to handle files dropped on the printer icon and print job list box and
to handle dragging printers to other objects. When a file is dropped on a
printer or print job list box, dtprintinfo receives a filename and when
a printer is dragged to an object, dtprintinfo supplies the filename of
the action file (Example: $HOME/.dt/.Printers/<printer>_Print).
Widgets
libUI/MotifUI/Icon.c - Custom icon widget used by the IconObj class defined
in libUI/MotifUI/IconObj.C.
libUI/MotifUI/WorkArea.c - Custom container widget used by the Container
class defined in libUI/MotifUI/Container.C.
Classes
There are 2 class hierarchies: an UI class hierarchy and a object class
hierarchy. The Motif User Interface classes are defined in the
libUI/MotifUI directory. The printer objects are defined in the
objects/PrintObj directory. These classes are designed to be used as
libraries.
Action API's
The DtPrinterIcon class uses the DtDbLoad, DtActionInvoke, DtDbReloadNotify,
DtActionExists, DtActionIcon, DtActionDescription, and DtActionLabel
functions. The DtPrtProps class uses the DtActionInvoke function. The
Application class uses the DtDbLoad function.
Drag-n-Drop API's
The DtDND class uses the XmDropSiteUpdate, XmDropSiteConfigureStackingOrder,
DtDndDropRegister, and DtDndDragStart functions.
Remote Printer related API's
The ConnectToPrintServer function in objects/PrintObj/ParseJobs.C uses the
gethostbyname, gethostbyaddr, getservbyname, rresvport, and connect
functions to return a socket to a remote print server.
The SendPrintJobStatusReguest function writes to the socket a request for
long format printer status.
These two high level functions are called by the OpenClose function in
UI/DtApp.C and by the ProcessJobs function in objects/PrintObj/Queue.C
via the call to the RemotePrintJobs function in ParseJobs.C.
The RemotePrintJobs is a high level function that reads the socket for
the print status that's returned by the server. This functions waits for
the output, thus it blocks the dtprintinfo process. It is used during the
'Find Print Jobs' operation in the Print Manager version of dtprintinfo.
The OpenClose function in UI/DtApp.C uses the BaseUI->Thread function
function to gather the status returned by the print server so that the
dtprintinfo process does not block. This is accomplished by using the
the fcntl function to set the O_NDELAY bit on the socket and then using the
socket as the file descriptor in the XtAppAddInput function. Refer to the
CreateThread function in libUI/MotifUI/MotifThread.C.
Message Catalog
The message catalog uses symbolic tags and a MESSAGE macro that makes the
source code easier to read and modify. When building dtprintinfo the
dtprintinfo_cat.h and dtprintinfo_msg.h header are automatically generated
by the sym2num script, gencat, and awk msg.awk script. Here's a sample
output of creating the message header files.
rm -f dtprintinfo.cat dtprintinfo_msg.h dtprintinfo_cat.h
./sym2num dtprintinfo dtprintinfo.msg > msg.tmp
gencat dtprintinfo.cat msg.tmp
awk -f msg.awk dtprintinfo.msg > dtprintinfo_cat.h
rm -f msg.tmp

View File

@@ -0,0 +1,121 @@
/* $TOG: DtActions.C /main/4 1998/08/03 16:30:18 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "stdlib.h"
#include "DtActions.h"
#include "DtMainW.h"
#include "Button.h"
#include "Sep.h"
DtActions::DtActions(AnyUI *parent,
char *name,
char *mnemonic)
: Menu(parent, name, mnemonic)
{
// Empty
}
class DtAction : public Button {
public:
static void ActionCB(void *);
char *actionReferenceName;
ActionCallback actionCallback;
void *actionCallbackData;
~DtAction();
DtAction(char *category, AnyUI *parent, char *name, char *mnemonic,
char *acceleratorText, char *accelerator, char *actionReferenceName,
ActionCallback callbackCB, void *callback_data);
};
DtAction::DtAction(char *category,
AnyUI *parent,
char *name,
char *mnemonic,
char *acceleratorText,
char *accelerator,
char *actionName,
ActionCallback callbackCB,
void *callback_data)
: Button(category, parent, name, PUSH_BUTTON, NULL, NULL,
mnemonic, acceleratorText, accelerator)
{
actionReferenceName = strdup(actionName);
actionCallback = callbackCB;
actionCallbackData = callback_data;
Callback(ActionCB);
}
DtAction::~DtAction()
{
free(actionReferenceName);
}
void DtAction::ActionCB(void *callback_data)
{
DtAction *action = (DtAction *) callback_data;
BaseUI *obj = ((DtActions *)action->Parent())->SelectedObject();
if (obj && action->actionCallback)
(*action->actionCallback)(action->actionCallbackData, obj,
action->actionReferenceName);
}
void DtActions::AddSep(char *objectClassName)
{
new Sep(objectClassName, this);
}
void DtActions::AddAction(char *name, char *category, char *actionReferenceName,
ActionCallback callback, void *callback_data,
char *mnemonic, char *acceleratorText,
char *accelerator)
{
new DtAction(category, this, name, mnemonic, acceleratorText, accelerator,
actionReferenceName, callback, callback_data);
}
void DtActions::UpdateActions(int n_items, BaseUI *obj)
{
if (n_items == 1)
{
Active(true);
int i;
for (i = 0; i < _numChildren; i++)
{
if (!_children[i]->Category() ||
!STRCMP(_children[i]->Category(), obj->Category()))
_children[i]->Visible(true);
else
_children[i]->Visible(false);
}
}
else
Active(false);
selected_object = obj;
}
boolean DtActions::HandleHelpRequest()
{
DtMainW *window = (DtMainW *)Parent()->Parent();
if (Active())
{
if (strcmp(selected_object->Category(), "Queue"))
window->DisplayHelp("SelectedPrintJobMenuDE");
else
window->DisplayHelp("SelectedPrinterMenuDE");
}
else if (window->PrinterAppMode() == PRINT_MANAGER)
window->DisplayHelp("SelectedMenuDE");
else
window->DisplayHelp("PJSelectedMenuDE");
return true;
}

View File

@@ -0,0 +1,47 @@
/* $XConsortium: DtActions.h /main/3 1995/11/06 09:34:07 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTACTIONS_H
#define DTACTIONS_H
#include "Menu.h"
typedef void (*ActionCallback) (void *callback_data, BaseUI *object,
char *actionReferenceName);
class DtWorkArea;
class DtActions : public Menu
{
friend class DtWorkArea;
protected:
int n_categories;
char **categories;
void UpdateActions(int n_items, BaseUI *obj);
BaseUI *selected_object;
public:
DtActions(AnyUI *parent,
char *name,
char *mnemonic = NULL);
void AddAction(char *name, char *category,
char *actionReferenceName, ActionCallback callback,
void *callback_data, char *mnemonic = NULL,
char *acceleratorText = NULL, char *accelerator = NULL);
void AddSep(char *category);
BaseUI *SelectedObject() { return selected_object; }
boolean HandleHelpRequest();
};
#endif // DTACTIONS_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
/* $XConsortium: DtApp.h /main/3 1995/11/06 09:34:32 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTAPP_H
#define DTAPP_H
#include "Application.h"
#include "DtPrinterIcon.h"
#include "DtSetPref.h"
class DtMainW;
class BaseObj;
class DtPrtJobIcon;
extern const char *PROPERTY;
extern const char *HELP;
extern const char *FIND;
extern const char *EXIT;
extern const char *HIDE;
extern const char *RENAME;
extern const char *OPEN;
extern const char *CLOSE;
extern const char *PRINTERS_DIR;
class DtApp : public Application
{
friend void InitQueueDetails(BaseUI *obj, void *data);
friend void RemoteStatusCB(BaseUI *obj, char *output, int rc);
friend void TurnOffHourGlass(BaseUI *obj, void *data);
friend void OpenClose(void *data, BaseUI *obj);
friend void ActionCB(void *data, BaseUI *obj, char *actionReferenceName);
friend void UpdatePrintJobs(BaseUI *obj, void *data);
friend void PreferenceCB(void *data, PreferenceRequest req, char *value);
friend void FilterCB(void *data);
friend void ModifyCB(void *data);
friend boolean SelectPrintJobs(BaseUI *obj);
friend void FindCB(void *data);
friend void AddQueues(BaseUI *obj, void *data);
friend void RestoreAppCB(BaseUI *obj, void *data);
private:
static void InitQueueDetails(BaseUI *obj, void *data);
static void RemoteStatusCB(BaseUI *obj, char *output, int rc);
static void TurnOffHourGlass(BaseUI *obj, void *data);
static void OpenClose(void *data, BaseUI *obj);
static void ActionCB(void *data, BaseUI *obj, char *actionReferenceName);
static void UpdatePrintJobs(BaseUI *obj, void *data);
static void PreferenceCB(void *data, PreferenceRequest req, char *value);
static void FilterCB(void *data);
static void ModifyCB(void *data);
static boolean SelectPrintJobs(BaseUI *obj);
static void FindCB(void *data);
static void AddQueues(BaseUI *obj, void *data);
static void RestoreAppCB(BaseUI *obj, void *data);
void OpenClose(BaseUI *obj);
void PreferenceCB(PreferenceRequest req, char *value);
void FilterCB(BaseUI *container);
void UpdateStatusLine();
void UpdateQueues();
void RestoreApp();
void AddActions(BaseObj *dummy);
void ShowStatusDialog(DtPrinterIcon *);
void HandleShowDetailsLabelPreferenceRequest(IconStyle style);
void HandleDetailsPreferenceRequest(boolean details_on);
boolean ShowUserJob(DtPrtJobIcon *_job, char *user_name);
void ShowUserJobs(BaseUI *queue, char *user_name, boolean flag);
void HandleShowOnlyMinePreferenceRequest(boolean flag);
int connect_timeout; // connect timeout to contact server
long Frequency;
char *old_dbsearchpath;
boolean save_state;
public:
int old_uid;
PrinterApplicationMode app_mode;
DtPrinterIcon *single_printer;
DtMainW *window;
char *printer_dir;
char *lang;
char *home;
DtApp(char *progname, int *argc, char **argv);
~DtApp();
void SaveYourSelf();
char *SessionFile();
char *SessionPath() { return printer_dir; }
char *GetBottomString(BaseObj *job, boolean need_details);
void ActionCB(BaseUI *obj, char *actionReferenceName);
};
#endif // DTAPP_H

View File

@@ -0,0 +1,86 @@
/* $TOG: DtDetailsLabel.C /main/3 1998/07/24 16:11:46 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtDetailsLabel.h"
#include "Icon.h"
#include "WorkArea.h"
#include "dtprintinfomsg.h"
boolean DtDetailsLabel::first_time = true;
Pixmap DtDetailsLabel::blank_pixmap;
Pixmap DtDetailsLabel::blank_mask;
XmString DtDetailsLabel::bottom_label[2];
DtDetailsLabel::DtDetailsLabel(MotifUI *parent)
: MotifUI(parent, "Details", NULL)
{
if (first_time)
{
char *label = new char[strlen(MESSAGE(OwnerL)) + strlen(MESSAGE(SizeL)) +
strlen(MESSAGE(TimeL)) + strlen(MESSAGE(DateL)) +
strlen(MESSAGE(JobNumberL)) + 5];
sprintf(label, "%s\n%s\n%s\n%s", MESSAGE(SizeL),
MESSAGE(JobNumberL), MESSAGE(TimeL), MESSAGE(DateL));
bottom_label[0] = StringCreate(label);
sprintf(label, "%s\n%s\n%s\n%s\n%s",
MESSAGE(OwnerL), MESSAGE(SizeL),
MESSAGE(JobNumberL), MESSAGE(TimeL), MESSAGE(DateL));
bottom_label[1] = StringCreate(label);
Dimension highlight;
XtVaGetValues(parent->BaseWidget(),
XmNhighlightThickness, &highlight, NULL);
int height = 21 + 2 * highlight;
blank_pixmap = XCreatePixmap(display, root, 1, height, depth);
blank_mask = XCreatePixmap(display, root, 1, height, 1);
GC gc_mask = XCreateGC(display, blank_mask, 0, NULL);
XSetForeground(display, gc_mask, 0);
XFillRectangle(display, blank_mask, gc_mask, 0, 0, 1, height);
XFreeGC(display, gc_mask);
delete [] label;
first_time = false;
}
XmString top_string = StringCreate(MESSAGE(Position1L));
XmString label_string = StringCreate(MESSAGE(JobNameL));
Widget p = XtParent(parent->BaseWidget());
Pixel bg;
XtVaGetValues(p, XmNbackground, &bg, NULL);
_w = XtVaCreateManagedWidget("DtDetailsLabel", iconWidgetClass, p,
GuiNsuperNode, parent->BaseWidget(),
XmNalignment, XmALIGNMENT_END,
XmNtraversalOn, False,
XmNbackground, bg,
GuiNiconMarginThickness, 0,
XmNhighlightThickness, 0,
XmNlabelString, label_string,
GuiNtopLabelString, top_string,
XmNlabelPixmap, blank_pixmap,
GuiNiconMask, blank_mask,
GuiNpixmapPlacement, GuiPIXMAP_LEFT,
NULL);
StringFree(top_string);
StringFree(label_string);
XtAddCallback(_w, GuiNsingleClickCallback, &DtDetailsLabel::ClickCB, NULL);
XtAddCallback(_w, GuiNdoubleClickCallback, &DtDetailsLabel::ClickCB, NULL);
}
void DtDetailsLabel::Update(boolean show_only_my_jobs)
{
int i = 1;
if (show_only_my_jobs)
i = 0;
XtVaSetValues(_w, GuiNbottomLabelString, bottom_label[i], NULL);
}
void DtDetailsLabel::ClickCB(Widget w, XtPointer, XtPointer)
{
XtVaSetValues(w, GuiNselected, False, NULL);
}

View File

@@ -0,0 +1,32 @@
/* $XConsortium: DtDetailsLabel.h /main/3 1995/11/06 09:34:43 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTDETAILSLABEL_H
#define DTDETAILSLABEL_H
#include "MotifUI.h"
class DtDetailsLabel : public MotifUI {
static void ClickCB(Widget, XtPointer, XtPointer);
static boolean first_time;
static XmString bottom_label[];
static Pixmap blank_pixmap;
static Pixmap blank_mask;
public:
DtDetailsLabel(MotifUI *parent);
void Update(boolean show_only_my_jobs);
const UI_Class UIClass() { return LABEL; }
const char *const UIClassName() { return "DtDetailsLabel"; }
};
#endif // DTDETAILSLABEL_H

View File

@@ -0,0 +1,637 @@
/* $TOG: DtFindD.C /main/5 1998/07/24 16:12:13 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtFindD.h"
#include "DtMainW.h"
#include "DtApp.h"
#include "DtSetModList.h"
#include "DtWorkArea.h"
#include "Button.h"
#include "Prompt.h"
#include "LabelObj.h"
#include "Container.h"
#include "Sep.h"
#include "DtPrtJobIcon.h"
#include "dtprintinfomsg.h"
#include <unistd.h> // This is for the getuid function
DtJobList::DtJobList(AnyUI *parent)
: Container(parent, "found_container", SCROLLED_VERTICAL_ROW_COLUMN,
MULTIPLE_SELECT)
{
IconView(SMALL_ICON);
}
class _JobIcon : public IconObj
{
public:
DtPrtJobIcon *job_icon;
BaseUI *printer;
BaseUI *job_list;
_JobIcon(AnyUI *parent, DtPrtJobIcon *obj, IconFields);
};
_JobIcon::_JobIcon(AnyUI *parent, DtPrtJobIcon *obj, IconFields fields)
: IconObj(parent, (char *)obj->Name(), "DtPrtjb", NULL, NULL, NULL,
fields)
{
job_icon = obj;
job_list = obj->Parent();
printer = job_list->Parent();
}
void DtJobList::NotifySelected(BaseUI *obj)
{
Container::NotifySelected(obj);
int n_items;
Selection(&n_items);
DtFindD *findD = (DtFindD *) Parent();
if (n_items == 0)
{
findD->cancel_jobs->Active(false);
findD->goto_job->Active(false);
}
else
{
if (n_items == 1)
findD->goto_job->Active(true);
else
findD->goto_job->Active(false);
findD->cancel_jobs->Active(true);
}
}
DtFindD::DtFindD(MotifUI *parent,
char *name,
SelectProc select_proc)
: Dialog(parent, name)
{
_has_been_posted = false;
mainw = (DtMainW *) parent;
_select_proc = select_proc;
if (getuid() == 0) // check to see if we are root
prompt = new Prompt(this, MESSAGE(JobName1L));
else
prompt = new Prompt(this, MESSAGE(MyJobNameL));
prompt->AttachRight();
prompt->AttachLeft();
prompt->AttachTop();
Container *rc = new Container(this, "rc", HORIZONTAL_ROW_COLUMN,
MULTIPLE_SELECT);
if (getuid() == 0) // check to see if we are root
match_any_user = new Button(rc, MESSAGE(OnlyRootJobsL), TOGGLE_BUTTON);
else
match_any_user = NULL;
ignore_case = new Button(rc, MESSAGE(IgnoreCaseL), TOGGLE_BUTTON);
ignore_case->Selected(true);
exact_match = new Button(rc, MESSAGE(ExactMatchL), TOGGLE_BUTTON);
rc->AttachRight();
rc->AttachTop(prompt, 5);
Sep *sep = new Sep(this);
sep->AttachRight();
sep->AttachLeft();
sep->AttachTop(rc, 5);
field1 = new LabelObj(this, MESSAGE(JobName1L));
field1->AttachLeft(22);
field1->AttachTop(sep, 5);
field2 = new LabelObj(this, MESSAGE(PrinterL));
field2->AttachLeft(field1);
field2->AttachTop(sep, 5);
field3 = new LabelObj(this, MESSAGE(OwnerL));
field3->AttachLeft(field2);
field3->AttachTop(sep, 5);
field3->Visible(false);
field4 = new LabelObj(this, MESSAGE(PositionL));
field4->AttachLeft(field2);
field4->AttachRight();
field4->AttachTop(sep, 5);
Container *form = new Container(this, "form", FORM);
goto_job = new Button(form, MESSAGE(GotoL), PUSH_BUTTON, GotoCB, this);
goto_job->Active(false);
cancel_jobs = new Button(form, MESSAGE(CancelPrintJobsL), PUSH_BUTTON,
CancelJobsCB, this);
cancel_jobs->Active(false);
form->AttachBottom(5);
form->AttachRight();
form->AttachLeft();
goto_job->AttachBottom();
goto_job->AttachTop();
cancel_jobs->AttachBottom();
cancel_jobs->AttachTop();
found_container = new DtJobList(this);
found_container->AttachRight();
found_container->AttachLeft();
found_container->AttachBottom(form, 10);
found_container->AttachTop(field1);
start = new Button(this, MESSAGE(StartFindL), PUSH_BUTTON, StartCB, this);
stop = new Button(this, MESSAGE(StopFindL), PUSH_BUTTON, StopCB, this);
close_it = new Button(this, MESSAGE(CloseL), PUSH_BUTTON, CancelCB, this);
stop->Active(false);
help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
DefaultButton(start);
CancelButton(close_it);
}
DtFindD::~DtFindD()
{
// Empty
}
boolean DtFindD::SetVisiblity(boolean flag)
{
if (_has_been_posted == false)
{
Dialog::SetVisiblity(flag);
Refresh();
int width = StringWidth(Name()) + 30;
if (width < 400)
width = 400;
if (Width() < width)
Width(width);
_has_been_posted = true;
int w1 = cancel_jobs->Width();
int w2 = goto_job->Width();
int offset = (width - (w1 + w2)) / 3;
goto_job->AttachLeft(offset);
cancel_jobs->AttachRight(offset);
cancel_jobs->AttachLeft(NULL, 0);
}
found_container->DeleteChildren();
cancel_jobs->Active(false);
goto_job->Active(false);
if (match_any_user)
{
match_any_user->Selected(false);
match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
}
Dialog::SetVisiblity(flag);
if (flag)
prompt->SetFocus();
return true;
}
void DtFindD::UpdateMatchAnyUser()
{
if (match_any_user)
match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
}
boolean DtFindD::MatchAnyUser()
{
if (match_any_user)
{
if (match_any_user->Active() == false)
return false;
else
return (match_any_user->Selected() ? false : true);
}
else
return false;
}
void DtFindD::Start()
{
_working = true;
mainw->in_find = true;
mainw->WorkingCursor(true);
stop->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
help->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
stop->Active(true);
DefaultButton(stop);
close_it->Active(false);
start->Active(false);
prompt->Active(false);
ignore_case->Active(false);
exact_match->Active(false);
found_container->DeleteChildren();
cancel_jobs->Active(false);
goto_job->Active(false);
if (match_any_user)
match_any_user->Active(false);
found_container->BeginUpdate();
_cur_obj = 0;
if (mainw->container->NumChildren())
{
BaseUI *icon = mainw->container->Children()[0];
_prev_visible = icon->Visible();
_prev_opened = icon->Open();
}
AddTimeOut(CheckQueue, NULL, 200);
}
void DtFindD::Cancel()
{
Visible(false);
Stop();
}
void DtFindD::Stop()
{
if (_cur_obj > mainw->container->NumChildren())
return;
_cur_obj = mainw->container->NumChildren() + 1;
found_container->EndUpdate();
start->Active(true);
DefaultButton(start);
stop->Active(false);
close_it->Active(true);
prompt->Active(true);
ignore_case->Active(true);
exact_match->Active(true);
prompt->SetFocus();
if (mainw->setModList && mainw->setModList->Visible())
mainw->setModList->Reset();
if (match_any_user)
match_any_user->Active(mainw->setPrefD->ShowOnlyMyJobs() ? false : true);
if (Visible())
{
int n_matches;
BaseUI **matches;
char *value1 = NULL;
char *value = prompt->Value();
if (!value || *value == '\0')
value = ".*";
else if (*value == '*')
{
value1 = new char[strlen(value) + 2];
sprintf(value1, ".%s", value);
value = value1;
}
mainw->container->FindByName(value, 0, &n_matches, &matches,
_select_proc,
exact_match->Selected() ? false : true,
ignore_case->Selected() ? false : true);
delete [] value1;
if (n_matches)
{
IconFields fields = new IconFieldsRec;
int n_fields, i, w;
if (MatchAnyUser())
n_fields = 3;
else
n_fields = 2;
fields->n_fields = n_fields;
fields->field_spacing = 20;
fields->fields = new char *[n_fields];
fields->fields_widths = new int[n_fields];
fields->alignments = new LabelType[n_fields];
fields->draw_fields = NULL;
fields->selected = NULL;
fields->active = NULL;
fields->name_width = StringWidth(MESSAGE(JobName1L));
fields->fields_widths[0] = StringWidth(MESSAGE(PrinterL));
fields->alignments[0] = LEFT_JUSTIFIED;
if (n_fields == 3)
{
fields->fields_widths[1] = StringWidth(MESSAGE(OwnerL));
fields->fields_widths[2] = StringWidth(MESSAGE(PositionL));
fields->alignments[1] = LEFT_JUSTIFIED;
fields->alignments[2] = RIGHT_JUSTIFIED;
if (field3->Visible() == false)
{
field3->Visible(true);
field4->AttachLeft(field3);
}
}
else
{
fields->alignments[1] = RIGHT_JUSTIFIED;
fields->fields_widths[1] = StringWidth(MESSAGE(PositionL));
if (field4->Visible())
{
field4->AttachLeft(field2);
field3->Visible(false);
}
}
for (i = 0; i < n_matches; i++)
{
DtPrtJobIcon *job = (DtPrtJobIcon *)matches[i];
if ((w = StringWidth(job->Name())) > fields->name_width)
fields->name_width = w;
w = StringWidth(job->Parent()->Parent()->Name());
if (w > fields->fields_widths[0])
fields->fields_widths[0] = w;
if (n_fields == 3)
{
char *s = job->PrintJobObj()->AttributeValue((char *)OWNER);
if ((w = StringWidth(s)) > fields->fields_widths[1])
fields->fields_widths[1] = w;
}
}
if (fields->name_width % 2)
fields->name_width += 1;
if (fields->fields_widths[0] % 2)
fields->fields_widths[0] += 1;
if (n_fields == 3)
{
if (fields->fields_widths[1] % 2)
fields->fields_widths[1] += 1;
if (fields->fields_widths[2] % 2)
fields->fields_widths[2] += 1;
}
else
{
if (fields->fields_widths[1] % 2)
fields->fields_widths[1] += 1;
}
field1->Width(fields->name_width + 20);
field2->Width(fields->fields_widths[0] + 20);
field3->Width(fields->fields_widths[1] + 20);
if (n_fields == 3)
field4->Width(fields->fields_widths[2] + 20);
for (i = 0; i < n_matches; i++)
{
DtPrtJobIcon *job = (DtPrtJobIcon *)matches[i];
char number[9];
sprintf(number, "%d", job->Order() + 1);
fields->fields[0] = (char *)job->Parent()->Parent()->Name();
if (n_fields == 3)
{
char *s = job->PrintJobObj()->AttributeValue((char *)OWNER);
fields->fields[1] = s;
fields->fields[2] = number;
}
else
fields->fields[1] = number;
_JobIcon *icon = new _JobIcon(found_container, job, fields);
}
delete []matches;
delete fields->fields;
delete fields->fields_widths;
delete fields->alignments;
delete fields;
}
else
new LabelObj(found_container, MESSAGE(NoMatchesL));
}
mainw->WorkingCursor(false);
_working = false;
mainw->in_find = false;
}
void DtFindD::UpdateQueue()
{
if (_cur_obj < mainw->container->NumChildren())
{
BaseUI *icon = mainw->container->Children()[_cur_obj];
char *message = new char[200];
sprintf(message, MESSAGE(SearchL), icon->Name());
found_container->UpdateMessage(message);
delete [] message;
icon->Visible(true);
DtPrinterIcon *icon1 = (DtPrinterIcon *)icon;
icon1->waitForChildren = true;
icon1->Open(true);
icon1->waitForChildren = false;
boolean no_children;
if (icon1->QueueObj()->NumChildren() == 0)
no_children = true;
else
{
int n_matches;
char *value1 = NULL;
char *value = prompt->Value();
if (!value || *value == '\0')
value = ".*";
else if (*value == '*')
{
value1 = new char[strlen(value) + 2];
sprintf(value1, ".%s", value);
value = value1;
}
icon1->FindByName(value, 0, &n_matches, NULL, _select_proc,
exact_match->Selected() ? false : true,
ignore_case->Selected() ? false : true);
delete value1;
if (n_matches)
no_children = false;
else
no_children = true;
}
if (no_children)
{
if (_prev_visible == false)
icon->Visible(false);
if (_prev_opened == false)
icon->Open(false);
}
_cur_obj++;
if (_cur_obj < mainw->container->NumChildren())
{
icon = mainw->container->Children()[_cur_obj];
_prev_visible = icon->Visible();
_prev_opened = icon->Open();
}
AddTimeOut(CheckQueue, NULL, 200);
}
else if (_cur_obj == mainw->container->NumChildren())
Stop();
}
boolean DtFindD::HandleHelpRequest()
{
mainw->DisplayHelp("FindDialogDE");
return true;
}
void DtFindD::CheckQueue(BaseUI *obj, void *)
{
((DtFindD *)obj)->UpdateQueue();
}
BaseUI *DtFindD::FindJob(BaseUI *obj)
{
int i;
BaseUI *job = ((_JobIcon *)obj)->job_icon;
BaseUI **children = ((_JobIcon *)obj)->job_list->Children();
int n_children = ((_JobIcon *)obj)->job_list->NumChildren();
for (i = 0; i < n_children; i++)
if (job == children[i])
return children[i];
Dialog *dialog = new Dialog(mainw, (char *) Name(),
MESSAGE(NotFoundMessageL), INFORMATION,
MESSAGE(OKL));
dialog->Visible(true);
return NULL;
}
void DtFindD::GotoCB(void *data)
{
DtFindD *obj = (DtFindD *) data;
BaseUI **selection;
int n_items;
obj->found_container->Selection(&n_items, &selection);
if (n_items == 1)
{
BaseUI *print_job = obj->FindJob(selection[0]);
if (print_job)
{
print_job->MakeVisible();
print_job->Selected(true);
}
}
delete []selection;
}
void DtFindD::CancelJobsCB(void *data)
{
DtFindD *obj = (DtFindD *) data;
extern void ActionCB(void *data, BaseUI *obj, char *actionReferenceName);
BaseUI **selection;
int n_items;
obj->found_container->Selection(&n_items, &selection);
if (n_items)
{
int i;
for (i = 0; i < n_items; i++)
{
BaseUI *print_job = obj->FindJob(selection[i]);
if (print_job)
{
DtApp *app = (DtApp *)obj->mainw->Parent();
app->ActionCB(print_job, (char *)CANCEL_PRINT_JOB);
}
}
}
delete []selection;
}
void DtFindD::CloseCB()
{
Cancel();
}
void DtFindD::CancelCB(void *data)
{
DtFindD *obj = (DtFindD *) data;
obj->Cancel();
}
void DtFindD::StartCB(void *data)
{
DtFindD *obj = (DtFindD *) data;
obj->Start();
}
void DtFindD::StopCB(void *data)
{
DtFindD *obj = (DtFindD *) data;
obj->_cur_obj = obj->mainw->container->NumChildren();
}
void DtFindD::HelpCB(void *data)
{
DtFindD *obj = (DtFindD *) data;
obj->HandleHelpRequest();
}
void DtFindD::DeleteJobFromList(BaseUI *obj)
{
int i;
int n_children = found_container->NumChildren();
_JobIcon **children = (_JobIcon **)found_container->Children();
for (i = 0; i < n_children; i++)
{
if (obj->Parent() == children[i]->job_list)
{
if (children[i]->job_icon == obj)
{
children[i]->Selected(false);
delete children[i];
return;
}
}
}
}
void DtFindD::UpdatePrinter(BaseUI *printer)
{
int n_children = found_container->NumChildren();
if (n_children == 0)
return;
_JobIcon **children = (_JobIcon **)found_container->Children();
int i, w1;
int width = StringWidth(MESSAGE(PrinterL));
BaseUI *last_printer = NULL;
for (i = 0; i < n_children; i++)
{
if (last_printer != children[i]->printer)
{
last_printer = children[i]->printer;
if ((w1 = StringWidth(last_printer->Name())) > width)
width = w1;
}
}
if (width % 2)
width += 1;
// Create a widget and resize it to the desired width, then resize the
// row column to the width + margin space. I have to do this because
// the row column widget does not resize itself correctly.
Dimension wid;
XtVaGetValues(found_container->InnerWidget(), XmNwidth, &wid, NULL);
wid -= field2->Width();
wid += width;
new LabelObj(found_container, " ");
children = (_JobIcon **)found_container->Children();
children[n_children]->Order(0);
n_children++;
children[0]->Width((int)wid);
wid += 6;
XtVaSetValues(found_container->InnerWidget(), XmNwidth, (int)wid, NULL);
field2->Width(width + 20);
for (i = 1; i < n_children; i++)
{
if (printer == children[i]->printer)
children[i]->Field(0, (char *)printer->Name(), width);
else
children[i]->Field(0, NULL, width);
}
delete children[0];
}
void DtFindD::UpdatePositions(BaseUI *printer)
{
if (mainw->in_find)
return;
int n_children = found_container->NumChildren();
if (n_children == 0)
return;
_JobIcon **children = (_JobIcon **)found_container->Children();
int i, index = children[0]->NumberFields() - 1;
for (i = 0; i < n_children; i++)
{
if (printer == children[i]->printer)
children[i]->Field(index, children[i]->job_icon->TopString(), 0);
}
}

View File

@@ -0,0 +1,107 @@
/* $XConsortium: DtFindD.h /main/3 1995/11/06 09:35:06 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTFINDD_H
#define DTFINDD_H
#include "Dialog.h"
#include "Container.h"
class Button;
class LabelObj;
class Prompt;
class Container;
class DtMainW;
class DtFindD;
class DtJobList : public Container
{
private:
DtFindD *findD;
void NotifySelected(BaseUI *obj);
public:
DtJobList(AnyUI *parent);
};
class DtFindD : public Dialog {
friend class DtJobList;
friend void StartCB(void *);
friend void StopCB(void *);
friend void CancelCB(void *);
friend void GotoCB(void *);
friend void CancelJobsCB(void *);
friend void HelpCB(void *);
friend void CheckQueue(BaseUI *, void *);
private:
boolean _has_been_posted;
int _cur_obj;
DtMainW *mainw;
// dialog buttons
Button *start;
Button *stop;
Button *close_it;
Button *help;
Button *cancel_jobs;
Button *goto_job;
Button *ignore_case;
Button *exact_match;
Button *match_any_user;
DtJobList *found_container;
LabelObj *field1;
LabelObj *field2;
LabelObj *field3;
LabelObj *field4;
Prompt *prompt;
SelectProc _select_proc;
boolean _working;
boolean _prev_opened;
boolean _prev_visible;
static void StartCB(void *);
static void StopCB(void *);
static void CancelCB(void *);
static void GotoCB(void *);
static void CancelJobsCB(void *);
static void HelpCB(void *);
static void CheckQueue(BaseUI *, void *);
boolean SetVisiblity(boolean flag);
void CloseCB();
void Cancel();
void Stop();
void Start();
void UpdateQueue();
BaseUI *FindJob(BaseUI *obj);
boolean HandleHelpRequest();
public:
DtFindD(AnyUI *parent, char *name, SelectProc select_proc);
boolean Working() { return _working; }
boolean MatchAnyUser();
void UpdateMatchAnyUser();
void DeleteJobFromList(BaseUI *);
void UpdatePrinter(BaseUI *printer);
void UpdatePositions(BaseUI *printer);
virtual ~DtFindD();
};
#endif /* DTFINDD_H */

View File

@@ -0,0 +1,323 @@
/* $TOG: DtFindSet.C /main/5 1998/07/24 16:12:36 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtFindSet.h"
#include "DtPrtProps.h"
#include "DtMainW.h"
#include "Button.h"
#include "Container.h"
#include "IconObj.h"
#include "LabelObj.h"
#include "ComboBoxObj.h"
#include "HelpSystem.h"
#include "Invoke.h"
#include "dtprintinfomsg.h"
#include <stdio.h>
#include <pwd.h>
#include <unistd.h> // This is for the getuid function
#include <stdlib.h> // This is for the getenv function
const char *GET_DIRS =
"lang=${LANG:-C} ; "
"for i in $(echo $XMICONSEARCHPATH | sed -e 's/:/ /g' -e s/%L/$lang/g) ; "
"do "
"dirname $i ; "
"done | sort -u";
// Subclass IconObj in order to disable SetOpen method
class FindSetIcon : public IconObj
{
public:
FindSetIcon(AnyUI *parent, char *name, char *icon) :
IconObj(parent, name, icon) { }
boolean SetOpen(boolean) { return true; }
};
DtFindSet::DtFindSet(DtMainW *parent, char *name, CallerCallback _callback)
: Dialog(parent, name, MODAL)
{
mainw = parent;
callback = _callback;
last_position = -1;
helpSystem = NULL;
char *output;
Invoke *_thread = new Invoke(GET_DIRS, &output);
char *s, *s1 = output;
s = s1;
n_dirs = 0;
while (s && (s = strchr(s1, '\n')))
{
n_dirs++;
s1 = s + 1;
}
if (_thread->status || n_dirs == 0)
{
delete [] output;
struct passwd * pwInfo;
char *home = getenv("HOME");
if (home == NULL || strlen(home) == 0)
{
pwInfo = getpwuid(getuid());
home = pwInfo->pw_dir;
}
output = new char[strlen(home) + 80];
n_dirs = 3;
sprintf(output, "%s/.dt/icons\n"
"/usr/dt/appconfig/icons/C\n"
"/etc/dt/appconfig/icons/C\n", (home[1] ? home : "" ));
}
dirs = new char *[n_dirs];
filenames = new FileNames [n_dirs];
s = output;
int i;
for (i = 0; i < n_dirs; i++)
{
s1 = s;
s = strchr(s, '\n');
*s++ = '\0';
dirs[i] = strdup(s1);
filenames[i] = new FileNamesStruct;
filenames[i]->icons = NULL;
filenames[i]->read_it = true;
filenames[i]->n_icons = 0;
}
delete [] output;
delete _thread;
comboBox = new ComboBoxObj(this, ComboBoxCB, MESSAGE(IconFoldersL), dirs,
n_dirs);
icon_label = new LabelObj(this, MESSAGE(IconTitleL));
icons = new Container(this, "icons", SCROLLED_WORK_AREA);
icons->Height(250);
empty = new LabelObj(icons, MESSAGE(EmptyL));
empty->Visible(false);
comboBox->AttachTop(5);
comboBox->AttachLeft();
comboBox->AttachRight();
icon_label->AttachTop(comboBox, 10);
icon_label->AttachLeft();
icon_label->AttachRight();
icons->AttachTop(icon_label);
icons->AttachRight();
icons->AttachLeft();
icons->AttachBottom();
ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
DefaultButton(ok);
CancelButton(cancel);
}
DtFindSet::~DtFindSet()
{
int i;
for (i = 0; i < n_dirs; i++)
{
delete dirs[i];
delete filenames[i];
}
delete []dirs;
delete []filenames;
}
void DtFindSet::InitComboBox(BaseUI *obj, void * /*data*/)
{
DtFindSet *findSet = (DtFindSet *)obj;
findSet->Refresh();
ComboBoxCB(findSet->comboBox, findSet->dirs[0], 1);
}
boolean DtFindSet::SetVisiblity(boolean flag)
{
if (last_position == -1)
AddTimeOut(&DtFindSet::InitComboBox, NULL, 1000);
Dialog::SetVisiblity(flag);
return true;
}
void DtFindSet::Reset()
{
}
void DtFindSet::Apply()
{
BaseUI **items;
int n_items;
icons->Selection(&n_items, &items);
if (n_items && callback)
{
FindSetIcon *icon = (FindSetIcon *)items[0];
char *iconfile;
if (iconfile = strrchr(icon->IconFile(), '/'))
iconfile++;
else
iconfile = icon->IconFile();
(*callback)(caller, iconfile);
}
delete []items;
}
void DtFindSet::CloseCB()
{
Reset();
Visible(false);
}
void DtFindSet::OkCB(void *data)
{
DtFindSet *obj = (DtFindSet *) data;
obj->Apply();
obj->Visible(false);
}
void DtFindSet::ApplyCB(void *data)
{
DtFindSet *obj = (DtFindSet *) data;
obj->Apply();
}
void DtFindSet::CancelCB(void *data)
{
DtFindSet *obj = (DtFindSet *) data;
obj->Reset();
obj->Visible(false);
}
void DtFindSet::ResetCB(void *data)
{
DtFindSet *obj = (DtFindSet *) data;
obj->Reset();
}
void DtFindSet::HelpCB(void *data)
{
DtFindSet *obj = (DtFindSet *) data;
obj->HandleHelpRequest();
}
boolean DtFindSet::HandleHelpRequest()
{
char old_msg[200];
strcpy(old_msg, mainw->status_line->Name());
mainw->status_line->Name(MESSAGE(GettingHelpL));
mainw->WorkingCursor(true);
if (!helpSystem)
{
char *title = new char[120];
sprintf(title, "%s - %s", mainw->Name(), MESSAGE(HelpL));
helpSystem = new HelpSystem(this, title, "Printmgr", "FindSetDE",
QUICK_HELP);
helpSystem->Visible(true);
delete [] title;
}
else
{
helpSystem->Visible(true);
helpSystem->Refresh();
helpSystem->HelpVolume("Printmgr", "FindSetDE");
}
mainw->status_line->Name(old_msg);
mainw->WorkingCursor(false);
return true;
}
void DtFindSet::ComboBoxCB(ComboBoxObj *obj, char *dir, int position)
{
DtFindSet *findSet = (DtFindSet *)obj->Parent();
if (findSet->last_position == position)
return;
FileNames filenames;
int i;
char *buf = new char[400]; // This allows for a directory len of 240 bytes
findSet->PointerShape(HOUR_GLASS_CURSOR);
findSet->icons->BeginUpdate();
findSet->icons->SelectAll(false);
if (findSet->last_position > 0)
{
filenames = findSet->filenames[findSet->last_position - 1];
FindSetIcon **icon = filenames->icons;
for (i = 0; i < filenames->n_icons; i++, icon++)
(*icon)->Visible(false);
}
filenames = findSet->filenames[position - 1];
if (filenames->read_it)
{
sprintf(buf, "cd %s 2> /dev/null ; "
"/bin/ls -1 | grep '\\.l\\.pm$' | "
"sed 's/\\.l\\.pm//g' | "
"while read file ; do "
"if [ -f $file.m.pm -a -f $file.t.pm ] ; "
"then echo $file ; fi ; "
"done", dir);
char *output;
Invoke *_thread = new Invoke(buf, &output);
char *s, *s1 = output;
s = s1;
filenames->n_icons = 0;
while (s && (s = strchr(s1, '\n')))
{
filenames->n_icons++;
s1 = s + 1;
}
if (filenames->n_icons)
{
s = output;
filenames->icons = new FindSetIcon*[filenames->n_icons];
for (i = 0; i < filenames->n_icons; i++)
{
s1 = s;
s = strchr(s, '\n');
*s++ = '\0';
if (!(i % 10))
{
sprintf(buf, MESSAGE(LoadingIconsL), i, filenames->n_icons);
findSet->icons->UpdateMessage(buf);
}
sprintf(buf, "%s/%s", dir, s1);
filenames->icons[i] = new FindSetIcon(findSet->icons, s1, buf);
}
}
delete _thread;
delete output;
filenames->read_it = false;
}
else
{
FindSetIcon **icon = filenames->icons;
for (i = 0; i < filenames->n_icons; i++, icon++)
(*icon)->Visible(true);
}
findSet->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
findSet->icons->EndUpdate();
sprintf(buf, MESSAGE(IconTitleL), filenames->n_icons);
findSet->icon_label->Name(buf);
if (filenames->n_icons)
findSet->empty->Visible(false);
else
findSet->empty->Visible(true);
findSet->last_position = position;
delete [] buf;
}

View File

@@ -0,0 +1,88 @@
/* $XConsortium: DtFindSet.h /main/3 1995/11/06 09:35:17 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTFINDSET_H
#define DTFINDSET_H
#include "Dialog.h"
#include "Prompt.h"
class Button;
class DtMainW;
class LabelObj;
class Container;
class ComboBoxObj;
class FindSetIcon;
class HelpSystem;
typedef void (*CallerCallback)(BaseUI *caller, char *iconFile);
typedef struct
{
boolean read_it;
FindSetIcon **icons;
int n_icons;
} FileNamesStruct, *FileNames, **FileNamesList;
class DtFindSet : public Dialog {
friend void OkCB(void *data);
friend void ApplyCB(void *data);
friend void CancelCB(void *data);
friend void ResetCB(void *data);
friend void HelpCB(void *data);
friend void ComboBoxCB(ComboBoxObj *, char *, int);
friend void InitComboBox(BaseUI *, void *data);
static void OkCB(void *data);
static void ApplyCB(void *data);
static void CancelCB(void *data);
static void ResetCB(void *data);
static void HelpCB(void *data);
static void ComboBoxCB(ComboBoxObj *, char *, int);
static void InitComboBox(BaseUI *, void *data);
private:
DtMainW *mainw;
HelpSystem *helpSystem;
// dialog buttons
Button *ok;
Button *apply;
Button *cancel;
Button *reset;
Button *help;
char **dirs;
int n_dirs;
int last_position;
BaseUI *caller;
CallerCallback callback;
FileNamesList filenames;
ComboBoxObj *comboBox;
Container *icons;
LabelObj *empty;
LabelObj *icon_label;
boolean _has_been_posted;
void CloseCB();
boolean SetVisiblity(boolean);
boolean HandleHelpRequest();
public:
DtFindSet(DtMainW *, char *name, CallerCallback callback);
~DtFindSet();
void Caller(BaseUI *obj) { caller = obj; }
void Apply();
void Reset();
};
#endif // DTFINDSET_H

View File

@@ -0,0 +1,348 @@
/* $TOG: DtMainW.C /main/5 1998/07/24 16:12:56 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtMainW.h"
#include "Application.h"
#include "Menu.h"
#include "MenuBar.h"
#include "LabelObj.h"
#include "Sep.h"
#include "Button.h"
#include "IconObj.h"
#include "DtWorkArea.h"
#include "DtActions.h"
#include "DtSetModList.h"
#include "DtFindD.h"
#include "HelpSystem.h"
#include "BaseObj.h"
#include "dtprintinfomsg.h"
#include <stdlib.h>
#include <stdio.h>
static char *GetIcon(AnyUI *obj, PrinterApplicationMode app_mode)
{
if (app_mode == SINGLE_PRINTER)
{
if (obj->depth == 1)
return "Fpprnt.l.bm";
else
return "Fpprnt.l.pm";
}
else
{
if (obj->depth == 1)
return "FpPrtmg.l.bm";
else
return "FpPrtmg.l.pm";
}
}
DtMainW::DtMainW(char *category,
AnyUI *p,
char *name,
ContainerType container_type,
SelectionType select_type,
OpenCallback openCB,
void *openCallbackData,
PreferenceCallback prefCB,
void *prefCallbackData,
char *fileMenuName,
char *fileMenuMnemonic,
PrinterApplicationMode _app_mode)
: MainWindow(category, p, name, name, GetIcon(p, _app_mode))
{
Visible(true);
in_find = false;
working_curs = 0;
app_mode = _app_mode;
_openClose = openCB;
_prefCB = prefCB;
if (openCallbackData)
_openCallbackData = openCallbackData;
else
_openCallbackData = this;
if (prefCallbackData)
_prefCallbackData = prefCallbackData;
else
_prefCallbackData = this;
_fileMenuName = fileMenuName;
_fileMenuMnemonic = fileMenuMnemonic;
_container_type = container_type;
_select_type = select_type;
setModList = NULL;
setPrefD = NULL;
findD = NULL;
helpSystem = NULL;
findSetD = NULL;
action_data = (ActionData **) malloc(sizeof(ActionData *));
n_action_data = 0;
}
DtMainW::~DtMainW()
{
int i;
for (i = 0; i < n_action_data; i++)
{
delete action_data[i]->actionReferenceName;
delete action_data[i];
}
delete action_data;
}
void DtMainW::DisplayHelp(char *location_id, char *volume)
{
char old_msg[200];
strcpy(old_msg, status_line->Name());
status_line->Name(MESSAGE(GettingHelpL));
WorkingCursor(true);
if (!helpSystem)
{
char *title = new char[120];
sprintf(title, "%s - %s", Name(), MESSAGE(HelpL));
helpSystem = new HelpSystem(this, title, volume, location_id);
helpSystem->Visible(true);
delete [] title;
}
else
{
helpSystem->Visible(true);
helpSystem->Refresh();
helpSystem->HelpVolume(volume, location_id);
}
status_line->Name(old_msg);
WorkingCursor(false);
helpSystem->ToFront();
}
void DtMainW::Initialize()
{
mbar = new MenuBar(this);
Container *form = new DtWorkArea((char *) Category(), this, (char *)Name(),
FORM);
container = new DtWorkArea((char *) Category(), form, (char *)Name(),
_container_type, _select_type);
status_line = new LabelObj(form, " ", LEFT_JUSTIFIED, true);
status_line->AttachBottom();
status_line->AttachLeft();
status_line->AttachRight();
container->AttachTop();
container->AttachLeft();
container->AttachRight();
container->AttachBottom(status_line);
if (app_mode == SINGLE_PRINTER)
container->WidthHeight(600, 150);
else
container->WidthHeight(600, 400);
SetWorkWindow(form);
char *title = new char[100];
sprintf(title, MESSAGE(SetOptionsTitleL), Name());
setPrefD = new DtSetPref(this, title, container, _prefCB,
_prefCallbackData);
delete [] title;
fileMenu = new DtMenu(mbar, _fileMenuName, _fileMenuMnemonic,
"PrinterMenuDE");
exitB = new Button(fileMenu, MESSAGE(ExitChoiceL), PUSH_BUTTON, ExitCB, this,
MESSAGE(ExitMnemonicL), MESSAGE(ExitAcceleratorL));
actionsMenu = new DtActions(mbar, MESSAGE(SelectedMenuL),
MESSAGE(SelectedAcceleratorL));
actionsMenu->Active(false);
if (app_mode != CONFIG_PRINTERS)
{
viewMenu = new DtMenu(mbar, MESSAGE(ViewMenuL),
MESSAGE(ViewAcceleratorL), "ViewMenuDE");
setPref = new Button(viewMenu, MESSAGE(SetOptionsChoiceL), PUSH_BUTTON,
SetPrefCB, setPrefD, MESSAGE(SetOptionsMnemonicL));
}
else
viewMenu = NULL;
helpMenu = new DtMenu(mbar, MESSAGE(HelpChoiceL), MESSAGE(HelpMnemonicL),
"HelpMenuDE");
introduction = new Button(helpMenu, MESSAGE(OverviewChoiceL), PUSH_BUTTON,
HelpCB, this, MESSAGE(OverviewMnemonicL));
new Sep(helpMenu);
tasks = new Button(helpMenu, MESSAGE(TaskChoiceL), PUSH_BUTTON, TasksCB,
this, MESSAGE(TaskMnemonicL));
reference = new Button(helpMenu, MESSAGE(ReferenceChoiceL), PUSH_BUTTON,
ReferenceCB, this, MESSAGE(ReferenceMnemonicL));
onWindow = new Button(helpMenu, MESSAGE(OnItemChoiceL), PUSH_BUTTON,
OnItemCB, this, MESSAGE(OnItemMnemonicL));
new Sep(helpMenu);
usingHelp = new Button(helpMenu, MESSAGE(UsingHelpChoiceL), PUSH_BUTTON,
UsingHelpCB, this, MESSAGE(UsingHelpMnemonicL));
new Sep(helpMenu);
char *tmp;
if (app_mode == PRINT_MANAGER)
tmp = MESSAGE(AboutChoice1L);
else if (app_mode == SINGLE_PRINTER)
tmp = MESSAGE(AboutChoice2L);
else
tmp = MESSAGE(AboutChoice3L);
version = new Button(helpMenu, tmp, PUSH_BUTTON, AboutCB,
this, MESSAGE(AboutMnemonicL));
mbar->SetHelpMenu(helpMenu);
}
void DtMainW::SetPrefCB(void *data)
{
DtSetPref *obj = (DtSetPref *) data;
obj->Visible(true);
}
void DtMainW::ExitCB(void *data)
{
Application *app = (Application *)((BaseUI *)data)->Parent();
app->SaveMe();
delete (BaseObj *)((BaseUI *)data)->ApplicationData;
delete ((BaseUI *)data)->Parent();
exit (0);
}
void DtMainW::OpenClose(BaseUI *obj)
{
if (_openClose)
(*_openClose)(_openCallbackData, obj);
}
void DtMainW::DtAddAction(char *name, char *category, char *actionName,
ActionCallback callback, void *callback_data,
char *mnemonic, char *acceleratorText,
char *accelerator)
{
BaseUI *action1;
if (action1 = actionsMenu->FindByName(name))
action1->Category(NULL);
else
actionsMenu->AddAction(name, category, actionName, callback,
callback_data, mnemonic, acceleratorText,
accelerator);
int size = sizeof(ActionData *) * (n_action_data + 1);
action_data = (ActionData **) realloc(action_data, size);
action_data[n_action_data] = (ActionData *)malloc(sizeof(ActionData));
action_data[n_action_data]->actionReferenceName = strdup(actionName);
action_data[n_action_data]->callback_data = callback_data;
action_data[n_action_data]->actionCallback = callback;
Button *action = AddAction(name, category, &DtMainW::ActionCB, NULL,
mnemonic, acceleratorText, accelerator);
action->ApplicationData = action_data[n_action_data];
n_action_data++;
}
void DtMainW::DtAddSep(char *category)
{
actionsMenu->AddSep(category);
AddSep(category);
}
void DtMainW::ActionCB(void *callback_data)
{
Button *action = (Button *) callback_data;
DtMainW *window = (DtMainW *)action->Parent()->Parent()->Parent();
ActionData *cb = (ActionData *) action->ApplicationData;
if (cb->actionCallback)
{
if (window->container->ObjectExists(window->PopupObjectUniqueID))
{
(*cb->actionCallback)(cb->callback_data, window->PopupObject,
cb->actionReferenceName);
}
else
{
Dialog *dialog = new Dialog(window, (char *)window->Name(),
MESSAGE(NotFoundMessageL), INFORMATION,
MESSAGE(OKL));
dialog->Visible(true);
}
}
}
void DtMainW::HelpCB(void *data)
{
DtMainW * obj = (DtMainW *) data;
obj->DisplayHelp("_hometopic");
}
void DtMainW::ReferenceCB(void *data)
{
DtMainW * obj = (DtMainW *) data;
obj->DisplayHelp("Reference");
}
void DtMainW::TasksCB(void *data)
{
DtMainW * obj = (DtMainW *) data;
obj->DisplayHelp("Tasks");
}
void DtMainW::UsingHelpCB(void *data)
{
DtMainW * obj = (DtMainW *) data;
obj->DisplayHelp("_hometopic", "Help4Help");
}
void DtMainW::AboutCB(void *data)
{
DtMainW * obj = (DtMainW *) data;
obj->DisplayHelp("_copyright");
}
void DtMainW::OnItemCB(void *data)
{
DtMainW * obj = (DtMainW *) data;
obj->ContextualHelp();
}
boolean DtMainW::HandleHelpRequest()
{
if (app_mode == PRINT_MANAGER)
DisplayHelp("MainWindowDE");
else
DisplayHelp("PJMainWindowDE");
return true;
}
void DtMainW::WorkingCursor(boolean flag)
{
int i;
BaseUI **children = Children();
if (flag)
{
if (working_curs == 0)
for (i = 0; i < NumChildren(); i++, children++)
(*children)->PointerShape(HOUR_GLASS_CURSOR);
working_curs++;
}
else
{
working_curs--;
if (working_curs == 0)
for (i = 0; i < NumChildren(); i++, children++)
(*children)->PointerShape(LEFT_SLANTED_ARROW_CURSOR);
}
}
boolean DtMenu::HandleHelpRequest()
{
((DtMainW *)Parent()->Parent())->DisplayHelp(location_id);
return true;
}

View File

@@ -0,0 +1,144 @@
/* $XConsortium: DtMainW.h /main/3 1995/11/06 09:35:41 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTMAINW_H
#define DTMAINW_H
#include "MainWindow.h"
#include "Menu.h"
#include "MenuBar.h"
#include "DtActions.h"
#include "DtSetPref.h"
#include "DtPrinterIcon.h"
class Button;
class DtSetModList;
class DtWorkArea;
class DtFindD;
class LabelObj;
class HelpSystem;
class DtFindSet;
typedef void (*OpenCallback) (void *callback_data, BaseUI *object);
typedef struct
{
ActionCallback actionCallback;
void *callback_data;
char *actionReferenceName;
} ActionData;
class DtMenu : public Menu
{
public:
char *location_id;
DtMenu(MenuBar *parent, char *name, char *mnemonic, char *help_location_id) :
Menu(parent, name, mnemonic)
{
location_id = help_location_id;
}
boolean HandleHelpRequest();
};
class DtMainW : public MainWindow
{
friend void SetPrefCB(void *data);
friend void ExitCB(void *data);
friend void ActionCB(void *data);
friend void HelpCB(void *data);
friend void ReferenceCB(void *data);
friend void UsingHelpCB(void *data);
friend void TasksCB(void *data);
friend void AboutCB(void *data);
private:
OpenCallback _openClose;
PreferenceCallback _prefCB;
ContainerType _container_type;
SelectionType _select_type;
void *_openCallbackData;
void *_prefCallbackData;
char *_fileMenuName;
char *_fileMenuMnemonic;
ActionData **action_data;
int n_action_data;
int working_curs;
PrinterApplicationMode app_mode;
static void SetPrefCB(void *data);
static void ExitCB(void *data);
static void ActionCB(void *data);
static void OnItemCB(void *data);
static void HelpCB(void *data);
static void ReferenceCB(void *data);
static void UsingHelpCB(void *data);
static void TasksCB(void *data);
static void AboutCB(void *data);
boolean HandleHelpRequest();
public:
DtFindD * findD; // Find dialog
DtSetPref * setPrefD; // Set preferences dialog
DtSetModList *setModList; // Set printer list dialog
DtWorkArea * container; // Work Area
MenuBar * mbar; // Menu Bar
HelpSystem * helpSystem;
DtFindSet * findSetD;
// Pulldown menu structure
DtMenu *fileMenu;
Button *exitB;
DtMenu *viewMenu;
Button *setPref;
DtActions *actionsMenu;
DtMenu *helpMenu;
Button *introduction;
// ------------------- Separator
Button *tasks;
Button *reference;
Button *onWindow;
// ------------------- Separator
Button *usingHelp;
// ------------------- Separator
Button *version;
LabelObj *status_line;
boolean in_find;
DtMainW(char *category,
AnyUI *p,
char *name,
ContainerType container_type = SCROLLED_WORK_AREA,
SelectionType select_type = SINGLE_SELECT,
OpenCallback openCB = NULL,
void *openCallbackData = NULL,
PreferenceCallback prefCB = NULL,
void *prefCallbackData = NULL,
char *fileMenuName = NULL,
char *fileMenuMnemonic = NULL,
PrinterApplicationMode app_mode = SINGLE_PRINTER);
~DtMainW();
void DtAddAction(char *name, char *category,
char *actionReferenceName, ActionCallback callback,
void *callback_data, char *mnemonic = NULL,
char *acceleratorText = NULL, char *accelerator = NULL);
void WorkingCursor(boolean);
PrinterApplicationMode PrinterAppMode() { return app_mode; }
void DisplayHelp(char *location_id, char *volume = "Printmgr");
void DtAddSep(char *category);
void Initialize();
void OpenClose(BaseUI *obj);
};
#endif /* DTMAINW_H */

View File

@@ -0,0 +1,763 @@
/* $TOG: DtPrinterIcon.C /main/5 1998/07/24 16:13:14 mgreess $ */
#include "DtPrinterIcon.h"
#include "Button.h"
#include "DtMainW.h"
#include "Prompt.h"
#include "DtPrtProps.h"
#include "DtSetModList.h"
#include "DtFindD.h"
#include "DtDetailsLabel.h"
#include "Dt/Action.h"
#include <sys/stat.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h> // This is for the getuid function
#include <stdlib.h> // This is for the getenv function
#include <pwd.h>
#include "dtprintinfomsg.h"
const char *PROPS_PRINTER_ID = "PrinterPropsDE";
const char *PRINTER_ID = "PrinterDE";
const char *STATUS_FLAG = "Flag";
const char *PRINTER_ICON_FILE = "Fpprnt";
const char *PRINTERS_PERSONAL_DIR = ".dt/.Printers";
char DtPrinterIcon::homeDir[300] = "";
DtPrinterIcon::DtPrinterIcon(DtMainW *mainW, AnyUI *parent, Queue *que,
PrinterApplicationMode _app_mode)
: IconObj((char *) que->ObjectClassName(), parent,
GetPrinterLabel(que->Name(), _app_mode),
GetPrinterIcon(que->Name(), _app_mode))
{
app_mode = _app_mode;
queue = que;
status = NULL;
dnd = NULL;
#ifdef aix
_print_device_up = NULL;
#endif
// Return if initializing printers
if (app_mode == INITIALIZE_PRINTERS)
return;
char *buf = new char[300];
struct stat statbuff;
if (*homeDir == '\0')
{
struct passwd * pwInfo;
char *home = getenv("HOME");
if (home == NULL || strlen(home) == 0)
{
pwInfo = getpwuid(getuid());
home = pwInfo->pw_dir;
}
strcpy(homeDir, home);
sprintf(buf, "%s/%s", homeDir, PRINTERS_PERSONAL_DIR);
if (stat(buf, &statbuff) < 0)
{
sprintf(buf, "mkdir -p %s/%s", homeDir, PRINTERS_PERSONAL_DIR);
system(buf);
}
sprintf(buf, "%s/.dt/types", homeDir);
if (stat(buf, &statbuff) < 0)
{
sprintf(buf, "mkdir -p %s/.dt/types", homeDir);
system(buf);
}
DtDbReloadNotify(&DtPrinterIcon::ReloadNotifyCB, this);
}
sprintf(buf, "%s/%s/%s_Print", homeDir, PRINTERS_PERSONAL_DIR,
queue->Name());
if (stat(buf, &statbuff) < 0)
{
int fd = creat(buf, 0755);
close(fd);
}
else if (statbuff.st_mode != 0755)
chmod(buf, 0755);
mainw = mainW;
props = NULL;
container = NULL;
waitForChildren = false;
if (app_mode == PRINT_MANAGER)
expand = new Button(this, queue->DisplayName(), PUSH_BUTTON, OpenCloseCB,
NULL, NULL, NULL, NULL, "Dtplus");
else
expand = NULL;
if (app_mode != CONFIG_PRINTERS)
{
#ifdef aix
n_devices = queue->NumberDevices();
_print_device_up = new boolean[n_devices];
int i;
for (i = 0; i < n_devices; i++)
_print_device_up[i] = true;
#else
queue->ReadAttributes();
_print_device_up = true;
#endif
_print_queue_up = true;
flag = new IconObj((char *)STATUS_FLAG, this, NULL, "DtFlag");
flag->Visible(false);
details_label = new DtDetailsLabel(this);
_previous_show_only_my_jobs = mainw->setPrefD->ShowOnlyMyJobs() ?
false : true;
ShowDetailsLabel(IconView(), false);
}
else
{
flag = NULL;
details_label = NULL;
}
dnd = new DtDND(this, DndCB);
mainw->RegisterPopup(this);
ApplicationData = NULL;
if (app_mode == SINGLE_PRINTER)
{
mainw->IconName((char *)Name());
char *iconFile = GetPrinterIcon(que->Name(), _app_mode);
char *s = new char [strlen(iconFile) + 6];
if (depth == 1)
sprintf(s, "%s.l.bm", iconFile);
else
sprintf(s, "%s.l.pm", iconFile);
mainw->IconFile(s);
if (!mainw->IconFile())
{
*(s + strlen(iconFile) + 1) = 'm';
mainw->IconFile(s);
}
delete [] s;
}
delete [] buf;
}
DtPrinterIcon::~DtPrinterIcon()
{
delete dnd;
#ifdef aix
delete _print_device_up;
#endif
delete status;
}
char *DtPrinterIcon::Description()
{
static char buf[200];
sprintf(buf, "%s_Print", queue->Name());
char *desc = DtActionDescription(buf);
return (desc ? desc : "");
}
void DtPrinterIcon::PrintQueueUp(boolean _flag)
{
if (app_mode == CONFIG_PRINTERS)
return;
if (props)
status[0]->Value(_flag ? MESSAGE(UpL) : MESSAGE(DownL));
_print_queue_up = _flag;
ShowFlag();
}
#ifdef aix
void DtPrinterIcon::PrintDeviceUp(boolean _flag, int index)
{
if (app_mode == CONFIG_PRINTERS)
return;
if (index >= 0 && index < n_devices)
{
if (props)
status[index + 1]->Value(_flag ? MESSAGE(UpL) : MESSAGE(DownL));
_print_device_up[index] = _flag;
ShowFlag();
}
}
boolean DtPrinterIcon::PrintDeviceUp(int index)
{
if (app_mode != CONFIG_PRINTERS)
{
if (index >= 0 && index < n_devices)
return _print_device_up[index];
}
return false;
}
#else
void DtPrinterIcon::PrintDeviceUp(boolean _flag)
{
if (app_mode == CONFIG_PRINTERS)
return;
if (props)
status[1]->Value(_flag ? MESSAGE(UpL) : MESSAGE(DownL));
_print_device_up = _flag;
ShowFlag();
}
#endif
boolean DtPrinterIcon::SetName(char *_name)
{
IconObj::SetName(_name);
if (dnd)
dnd->UpdateRects();
return true;
}
boolean DtPrinterIcon::SetOpen(boolean _flag)
{
if (app_mode != CONFIG_PRINTERS)
IconObj::SetOpen(_flag);
return true;
}
DtPrinterContainer *DtPrinterIcon::CreateContainer()
{
if (!container)
{
container = new DtPrinterContainer((char *)Category(), this,
queue->DisplayName());
mainw->RegisterPopup(container);
container->dnd = new DtDND(container, DndCB);
container->ApplicationData = queue;
ApplicationData = container;
}
return container;
}
char *DtPrinterIcon::CreateActionFile()
{
static char filename[300];
FILE *fp;
struct stat statbuff;
boolean create_file;
char *buf = new char[300];
char *lang = getenv("LANG");
if (!(lang && *lang))
lang = "C";
if (app_mode == INITIALIZE_PRINTERS || app_mode == CONFIG_PRINTERS)
{
sprintf(filename, "/etc/dt/appconfig/types/%s", lang);
if (stat(filename, &statbuff) < 0)
{
sprintf(buf, "mkdir -p %s", filename);
system(buf);
}
sprintf(filename, "/etc/dt/appconfig/types/%s/%s.dt", lang,
queue->Name());
if (stat(filename, &statbuff) < 0 || statbuff.st_size == 0)
create_file = true;
else
create_file = false;
}
else
{
sprintf(buf, "%s/.dt/types/%s.dt", homeDir, queue->Name());
if (stat(buf, &statbuff) < 0 || statbuff.st_size == 0)
{
sprintf(buf, "/etc/dt/appconfig/types/%s/%s.dt", lang, queue->Name());
if (stat(buf, &statbuff) >= 0 && statbuff.st_size > 0)
{
sprintf(buf, "cp /etc/dt/appconfig/types/%s/%s.dt %s/.dt/types",
lang, queue->Name(), homeDir);
system(buf);
create_file = false;
}
else
create_file = true;
}
else
create_file = false;
sprintf(filename, "%s/.dt/types/%s.dt", homeDir, queue->Name());
}
if (create_file)
{
if (fp = fopen(filename, "w"))
{
time_t secs;
time(&secs);
fprintf(fp, "################################################################\n\n");
fprintf(fp, "# Actions and Datatypes for Printer \"%s\"\n\n", queue->Name());
fprintf(fp, "# Common Desktop Environment 1.0\n\n");
fprintf(fp, "# This file was created by the \"dtprintinfo\" program.\n\n");
strftime(buf, 300, "%c", localtime(&secs));
fprintf(fp, "# Date of creation: %s\n\n", buf);
fprintf(fp, "################################################################\n\n");
fprintf(fp, "ACTION %s_Print\n", queue->Name());
fprintf(fp, "{\n");
fprintf(fp, " ARG_TYPE *\n");
fprintf(fp, " LABEL %s\n", queue->Name());
fprintf(fp, " ICON %s\n", PRINTER_ICON_FILE);
fprintf(fp, " TYPE COMMAND\n");
fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
fprintf(fp, " EXEC_STRING env LPDEST=%s \\\n", queue->Name());
fprintf(fp, " /usr/dt/bin/dtaction Print %%(File)Arg_1%%\n");
sprintf(buf, MESSAGE(DefaultDescriptionL), queue->Name());
fprintf(fp, " DESCRIPTION %s\n", buf);
fprintf(fp, "}\n\n");
fprintf(fp, "ACTION %s_Print\n", queue->Name());
fprintf(fp, "{\n");
fprintf(fp, " ARG_COUNT 0\n");
fprintf(fp, " TYPE COMMAND\n");
fprintf(fp, " WINDOW_TYPE NO_STDIO\n");
fprintf(fp, " EXEC_STRING /usr/dt/bin/dtaction Dtprintinfo %s\n", queue->Name());
fprintf(fp, "}\n");
fflush(fp);
fclose(fp);
chmod(filename, 0644);
}
}
delete [] buf;
return filename;
}
void DtPrinterIcon::DndCB(BaseUI *obj, char **value, int * /*len*/,
DNDProtocol dndProtocol)
{
DtPrinterIcon *printer;
if (obj->UIClass() == ICON)
printer = (DtPrinterIcon *)obj;
else
printer = (DtPrinterIcon *)obj->Parent();
DtActionArg ap[1];
char *old_LPDEST = NULL;
ap[0].argClass = DtACTION_FILE;
char *buf = new char[100];
switch (dndProtocol)
{
case FILENAME_TRANSFER: // Dropping an Object on a printer
ap[0].u.file.name = *value;
if (printer->PrintActionExists())
sprintf(buf, "%s_Print", printer->queue->Name());
else
{
if (old_LPDEST = STRDUP(getenv("LPDEST")))
{
sprintf(buf, "LPDEST=%s", printer->queue->Name());
putenv(buf);
}
strcpy(buf, "Print");
}
DtActionInvoke(((AnyUI *)printer->mainw->Parent())->BaseWidget(), buf, ap,
1, NULL, NULL, NULL, True, NULL, NULL);
if (old_LPDEST)
{
sprintf(buf, "LPDEST=%s", old_LPDEST);
putenv(buf);
delete old_LPDEST;
}
break;
case CONVERT_DATA: // Dragging a printer to an object
if (printer->PrintActionExists())
{
struct stat statbuff;
*value = new char[strlen(homeDir) + strlen(PRINTERS_PERSONAL_DIR) +
strlen(printer->queue->Name()) + 10];
sprintf(*value, "%s/%s/%s_Print", homeDir, PRINTERS_PERSONAL_DIR,
printer->queue->Name());
if (stat(*value, &statbuff) < 0)
{
int fd = creat(*value, 0755);
close(fd);
}
}
else
*value = NULL;
break;
case DROP_ON_ROOT:
{
char *x = *value;
char *y = strchr(x, '\n');
*y++ = '\0';
char *filename = strchr(y, '\n');
*filename++ = '\0';
char *work_space = strchr(filename, '\n');
if (work_space)
*work_space++ = '\0';
}
break;
case TEXT_TRANSFER:
break;
case BUFFER_TRANSFER:
*value = new char[strlen(printer->queue->Name()) + 10];
sprintf(*value, "%s_Print", printer->queue->Name());
break;
case CONVERT_DELETE:
break;
case ANIMATE:
break;
}
delete [] buf;
}
boolean DtPrinterIcon::SetIcon(IconStyle style)
{
IconObj::SetIcon(style);
if (dnd)
dnd->UpdateRects();
ShowDetailsLabel(style, Visible());
return true;
}
boolean DtPrinterIcon::HandleHelpRequest()
{
mainw->DisplayHelp((char *)PRINTER_ID);
return true;
}
void DtPrinterIcon::UpdateExpand()
{
if (expand)
{
if (Open() == true)
expand->IconFile("Dtminus");
else
expand->IconFile("Dtplus");
}
ShowDetailsLabel(IconView(), true);
}
void DtPrinterIcon::Update()
{
char *cmd = new char[200];
sprintf(cmd, GET_QUEUE_STATUS, queue->Name());
Invoke *_thread = new Invoke(cmd);
PrintQueueUp(_thread->status ? false : true);
delete _thread;
#ifdef aix
int i;
for (i = 0; i < n_devices; i++)
{
sprintf(cmd, GET_DEVICE_STATUS, queue->Device(i));
_thread = new Invoke(cmd);
PrintDeviceUp(_thread->status ? false : true, i);
delete _thread;
}
#else
#ifdef sun
if (queue->IsRemote())
PrintDeviceUp(_print_queue_up);
else
{
sprintf(cmd, GET_DEVICE_STATUS, queue->Name());
_thread = new Invoke(cmd);
PrintDeviceUp(_thread->status ? false : true);
delete _thread;
}
#else
sprintf(cmd, GET_DEVICE_STATUS, queue->Name());
_thread = new Invoke(cmd);
PrintDeviceUp(_thread->status ? false : true);
delete _thread;
#endif
#endif
delete [] cmd;
}
void DtPrinterIcon::ShowFlag()
{
if (app_mode == CONFIG_PRINTERS)
return;
if (Visible() == false || mainw->setPrefD->ShowStatusFlags() == false)
{
flag->Visible(false);
return;
}
// Update problem flag's visiblity
#ifdef aix
boolean show_it;
if (_print_queue_up)
{
int i;
show_it = false;
for (i = 0; i < n_devices; i++)
if (_print_device_up[i] == false)
{
show_it = true;
break;
}
}
else
show_it = true;
flag->Visible(show_it);
#else
if (_print_queue_up && _print_device_up)
flag->Visible(false);
else
flag->Visible(true);
#endif
}
void DtPrinterIcon::NotifyVisiblity(BaseUI *obj)
{
if (app_mode == CONFIG_PRINTERS)
return;
if (obj == flag)
{
boolean show_it = Visible();
if (show_it)
{
if (mainw->setPrefD->ShowStatusFlags() == false)
show_it = false;
else
{
#ifdef aix
if (_print_queue_up)
{
show_it = false;
int i;
for (i = 0; i < n_devices; i++)
if (_print_device_up[i] == false)
{
show_it = true;
break;
}
}
else
show_it = true;
#else
if (_print_queue_up && _print_device_up)
show_it = false;
else
show_it = true;
#endif
}
}
if (flag->Visible() != show_it)
flag->Visible(show_it);
}
else if (obj == details_label)
{
boolean show_it = Visible();
if (show_it)
{
if (container && IconView() == DETAILS && Open())
{
if (container->NumChildren() == 0 ||
(container->Children()[0])->UIClass() == LABEL)
show_it = false;
else if (mainw->setPrefD->ShowDetailsLabel())
{
show_it = false;
int i;
BaseUI **children = container->Children();
for (i = 0; i < container->NumChildren(); i++)
if (children[i]->Visible())
{
show_it = true;
break;
}
}
else
show_it = mainw->setPrefD->ShowDetailsLabel();
}
else
show_it = false;
}
if (details_label->Visible() != show_it)
details_label->Visible(show_it);
}
}
void DtPrinterIcon::ShowDetailsLabel(IconStyle style, boolean is_visible)
{
if (app_mode == CONFIG_PRINTERS)
return;
if (_previous_show_only_my_jobs != mainw->setPrefD->ShowOnlyMyJobs())
{
_previous_show_only_my_jobs = mainw->setPrefD->ShowOnlyMyJobs();
details_label->Update(_previous_show_only_my_jobs);
}
if (container && style == DETAILS && is_visible && Open())
{
if (container->NumChildren() == 0 ||
(container->Children()[0])->UIClass() == LABEL)
details_label->Visible(false);
else if (mainw->setPrefD->ShowDetailsLabel())
{
boolean show_it = false;
int i;
BaseUI **children = container->Children();
for (i = 0; i < container->NumChildren(); i++)
if (children[i]->Visible())
{
show_it = true;
break;
}
details_label->Visible(show_it);
}
else
details_label->Visible(false);
}
else
details_label->Visible(false);
}
boolean DtPrinterIcon::SetVisiblity(boolean _flag)
{
if (_flag)
{
IconObj::SetVisiblity(_flag);
Update();
if (container && Open())
container->Visible(true);
ShowDetailsLabel(IconView(), _flag);
}
else
{
if (container)
{
container->Visible(false);
if (mainw->findD)
{
int i;
BaseUI **children = container->Children();
for (i = 0; i < container->NumChildren(); i++)
mainw->findD->DeleteJobFromList(children[i]);
}
}
IconObj::SetVisiblity(_flag);
}
if (dnd)
dnd->UpdateActivity(_flag);
return true;
}
void DtPrinterIcon::DisplayProps()
{
if (!props)
{
char *title = new char[200];
sprintf(title, MESSAGE(PrinterPropsTitleL), mainw->Name());
queue->ReadAttributes();
props = new DtPrtProps(mainw, title, this);
int n_matches = 0;
props->FindByName(MESSAGE(PrinterStatusL), 0, &n_matches,
(BaseUI***)&status);
delete [] title;
}
props->Visible(true);
}
void DtPrinterIcon::ReloadNotifyCB(XtPointer data)
{
DtPrinterIcon *printer = (DtPrinterIcon *)data;
DtDbLoad();
int i, n_siblings = printer->NumSiblings();
BaseUI **siblings = printer->Siblings();
for (i = 0; i < n_siblings; i++)
{
printer = (DtPrinterIcon *)siblings[i];
char *iconName = GetPrinterLabel(printer->queue->Name(),
printer->app_mode);
char *iconFile = GetPrinterIcon(printer->queue->Name(),
printer->app_mode);
if (strcmp(iconName, printer->Name()))
{
printer->Name(iconName);
if (printer->PrinterAppMode() == SINGLE_PRINTER)
printer->mainw->IconName(iconName);
if (printer->PrinterAppMode() == PRINT_MANAGER)
{
if (printer->mainw->findD && printer->mainw->findD->Visible())
printer->mainw->findD->UpdatePrinter(printer);
}
}
if (strcmp(iconFile, printer->IconFile()))
{
printer->IconFile(iconFile);
if (printer->PrinterAppMode() == SINGLE_PRINTER &&
iconFile && *iconFile)
{
char *s = new char [strlen(iconFile) + 6];
if (depth == 1)
sprintf(s, "%s.l.bm", iconFile);
else
sprintf(s, "%s.l.pm", iconFile);
printer->mainw->IconFile(s);
delete [] s;
}
}
if (printer->props && printer->props->Visible())
printer->props->Reset();
}
if (printer->mainw->setModList && printer->mainw->setModList->Visible())
printer->mainw->setModList->Reset();
}
void DtPrinterIcon::OpenCloseCB(void *data)
{
BaseUI *obj = ((BaseUI *)data)->Parent();
if (obj->Open())
obj->Open(false);
else
obj->Open(true);
}
boolean DtPrinterIcon::PrintActionExists()
{
boolean b;
char *buf = new char[60];
sprintf(buf, "%s_Print", queue->Name());
b = (DtActionExists(buf) ? true : false);
delete [] buf;
return b;
}
char *DtPrinterIcon::GetPrinterIcon(const char *printer,
PrinterApplicationMode _app_mode)
{
static char buf[200];
sprintf(buf, "%s_Print", printer);
if (_app_mode != INITIALIZE_PRINTERS && DtActionExists(buf))
{
char *iconfile = DtActionIcon(buf);
if (iconfile)
strcpy(buf, iconfile);
else
strcpy(buf, PRINTER_ICON_FILE);
}
else
strcpy(buf, PRINTER_ICON_FILE);
return buf;
}
char *DtPrinterIcon::GetPrinterLabel(const char *printer,
PrinterApplicationMode _app_mode)
{
static char buf[200];
sprintf(buf, "%s_Print", printer);
if (_app_mode != INITIALIZE_PRINTERS && DtActionExists(buf))
{
char *label = DtActionLabel(buf);
if (label)
strcpy(buf, label);
else
strcpy(buf, printer);
}
else
strcpy(buf, printer);
return buf;
}

View File

@@ -0,0 +1,127 @@
/* $XConsortium: DtPrinterIcon.h /main/3 1995/11/06 09:36:06 rswiston $ */
#ifndef DTPRINTERICON_H
#define DTPRINTERICON_H
#include "IconObj.h"
#include "Queue.h"
#include "Container.h"
#include "DtDND.h"
extern const char *PROPS_PRINTER_ID;
extern const char *PRINTER_ID;
extern const char *STATUS_FLAG;
extern const char *PRINTER_ICON_FILE;
typedef enum
{
SINGLE_PRINTER,
PRINT_MANAGER,
CONFIG_PRINTERS,
INITIALIZE_PRINTERS
} PrinterApplicationMode;
class DtMainW;
class DtPrtProps;
class IconObj;
class Container;
class Button;
class DtDetailsLabel;
class Prompt;
class DtPrinterContainer : public Container
{
public:
DtDND *dnd;
DtPrinterContainer(char *category, AnyUI *parent, char *name)
: Container(category, parent, name, SCROLLED_HORIZONTAL_ROW_COLUMN) { }
~DtPrinterContainer() { delete dnd; }
boolean DtPrinterContainer::SetVisiblity(boolean flag)
{
Container::SetVisiblity(flag);
dnd->UpdateActivity(flag);
return true;
}
};
class DtPrinterIcon : public IconObj
{
friend void DndCB(BaseUI *, char **, int *, DNDProtocol);
friend void OpenCloseCB(void *);
friend void AddPrintActionCB(BaseUI *, void *);
friend void ReloadNotifyCB(void *);
friend char * GetPrinterIcon(const char *, PrinterApplicationMode);
friend char * GetPrinterLabel(const char *, PrinterApplicationMode);
static void DndCB(BaseUI *, char **, int *, DNDProtocol);
static void OpenCloseCB(void *);
static void AddPrintActionCB(BaseUI *, void *);
static void ReloadNotifyCB(void *);
static char * GetPrinterIcon(const char *, PrinterApplicationMode);
static char * GetPrinterLabel(const char *, PrinterApplicationMode);
private:
static char homeDir[];
DtMainW *mainw;
DtDND *dnd;
Queue *queue;
Button *expand;
IconObj *flag;
DtDetailsLabel *details_label;
DtPrinterContainer *container;
DtPrtProps *props;
boolean _previous_show_only_my_jobs;
PrinterApplicationMode app_mode;
boolean _print_queue_up;
Prompt **status;
#ifdef aix
boolean *_print_device_up;
int n_devices;
#else
boolean _print_device_up;
#endif
void ShowFlag();
boolean SetVisiblity(boolean);
void NotifyVisiblity(BaseUI *);
boolean HandleHelpRequest();
boolean SetIcon(IconStyle);
boolean SetOpen(boolean);
boolean SetName(char *name);
public:
boolean updating;
boolean waitForChildren;
DtPrinterIcon(DtMainW *, AnyUI *parent, Queue *queue,
PrinterApplicationMode app_mode = SINGLE_PRINTER);
~DtPrinterIcon();
void DisplayProps();
void Update();
void UpdateExpand();
void PrintQueueUp(boolean);
boolean PrintQueueUp() { return _print_queue_up; }
#ifdef aix
void PrintDeviceUp(boolean, int index = 0);
boolean PrintDeviceUp(int index = 0);
#else
void PrintDeviceUp(boolean);
boolean PrintDeviceUp() { return _print_device_up; }
#endif
void ShowDetailsLabel(IconStyle, boolean is_visible);
char *CreateActionFile();
char *Description();
boolean PrintActionExists();
DtPrinterContainer *JobContainer() { return container; }
DtPrinterContainer *CreateContainer();
PrinterApplicationMode PrinterAppMode() { return app_mode; }
const char *HomeDir() { return homeDir; }
Queue *QueueObj() { return queue; }
};
#endif // DTPRINTERICON_H

View File

@@ -0,0 +1,146 @@
/* $XConsortium: DtProps.C /main/2 1995/07/17 14:03:51 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtProps.h"
#include "DtMainW.h"
#include "Button.h"
#include "Prompt.h"
#include "LabelObj.h"
#include "Container.h"
#include "BaseObj.h"
#include "dtprintinfomsg.h"
#include <stdio.h>
DtProps::DtProps(AnyUI *parent,
char *name,
char *location_id,
boolean editable,
int n_attributes,
Attribute **attributes)
: Dialog(parent, name)
{
mainw = (DtMainW *) parent;
_location_id = location_id;
_has_been_posted = false;
rc = new Container(this, "rc", VERTICAL_ROW_COLUMN);
int i, captionWidth = 0, width, columns = 0;
for (i = 0; i < n_attributes; i++)
{
if ((width = StringWidth(attributes[i]->DisplayName)) > captionWidth)
captionWidth = width;
if ((width = strlen(attributes[i]->DisplayValue)) > columns)
columns = width;
}
for (i = 0; i < n_attributes; i++)
{
boolean _editable;
if (EditableAfterCreate(attributes[i]))
_editable = true;
else
_editable = false;
if (attributes[i]->ValueListType == INFORMATION_LINE)
new LabelObj(rc, attributes[i]->DisplayName);
else
new Prompt(rc, attributes[i]->DisplayName, _editable, STRING_PROMPT,
attributes[i]->DisplayValue, NULL,
NULL, true, columns, 1, captionWidth + 8);
}
ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
if (editable)
{
cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
CancelButton(cancel);
}
else
CancelButton(ok);
help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
rc->AttachAll();
DefaultButton(ok);
}
DtProps::~DtProps()
{
// Empty
}
boolean DtProps::SetVisiblity(boolean flag)
{
if (_has_been_posted == false)
{
Dialog::SetVisiblity(flag);
Refresh();
int width = StringWidth(Name()) + 35;
if (Width() < width)
{
Dialog::SetVisiblity(flag);
Width(width);
}
_has_been_posted = true;
}
Dialog::SetVisiblity(flag);
return true;
}
void DtProps::Reset()
{
}
void DtProps::Apply()
{
}
void DtProps::CloseCB()
{
Reset();
Visible(false);
}
void DtProps::OkCB(void *data)
{
DtProps *obj = (DtProps *) data;
obj->Apply();
obj->Visible(false);
}
void DtProps::ApplyCB(void *data)
{
DtProps *obj = (DtProps *) data;
obj->Apply();
}
void DtProps::CancelCB(void *data)
{
DtProps *obj = (DtProps *) data;
obj->Reset();
obj->Visible(false);
}
void DtProps::ResetCB(void *data)
{
DtProps *obj = (DtProps *) data;
obj->Reset();
}
void DtProps::HelpCB(void *data)
{
DtProps *obj = (DtProps *) data;
obj->HandleHelpRequest();
}
boolean DtProps::HandleHelpRequest()
{
mainw->DisplayHelp(_location_id);
return true;
}

View File

@@ -0,0 +1,66 @@
/* $XConsortium: DtProps.h /main/3 1995/11/06 09:36:21 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTPROPS_H
#define DTPROPS_H
#include "Dialog.h"
#include "BaseObj.h"
class Button;
class Container;
class Prompt;
class DtMainW;
class DtProps : public Dialog {
friend void OkCB(void *data);
friend void ApplyCB(void *data);
friend void CancelCB(void *data);
friend void ResetCB(void *data);
friend void HelpCB(void *data);
static void OkCB(void *data);
static void ApplyCB(void *data);
static void CancelCB(void *data);
static void ResetCB(void *data);
static void HelpCB(void *data);
private:
DtMainW *mainw;
// dialog buttons
Button *ok;
Button *apply;
Button *cancel;
Button *reset;
Button *help;
Container *rc;
char *_location_id;
boolean _has_been_posted;
void CloseCB();
boolean SetVisiblity(boolean);
boolean HandleHelpRequest();
public:
DtProps(AnyUI *parent,
char *name,
char *location_id,
boolean editable,
int n_attrs,
Attribute **attrs);
virtual ~DtProps();
void Apply();
void Reset();
};
#endif // DTPROPS_H

View File

@@ -0,0 +1,98 @@
/* $TOG: DtPrtJobIcon.C /main/4 1998/07/24 16:13:33 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtPrtJobIcon.h"
#include "DtApp.h"
#include "DtMainW.h"
#include "DtProps.h"
#include "DtFindD.h"
const char *PRINTJOB_ID = "PrintJobDE";
const char *PROPS_PRINTJOB_ID = "PrintJobPropsDE";
static char *GetBotString(DtMainW *mainW, BaseUI *parent, PrintJob *job)
{
boolean need_details = (parent->IconView() == DETAILS ? true : false);
DtApp *app = (DtApp *)mainW->Parent();
return app->GetBottomString(job, need_details);
}
static char *GetTopString(int seq_num)
{
static char number[9];
sprintf(number, "%d", seq_num);
return number;
}
DtPrtJobIcon::DtPrtJobIcon(DtMainW *mainW, AnyUI *parent, PrintJob *job,
int seq_num)
: IconObj((char *) job->ObjectClassName(), parent, job->DisplayName(),
"DtPrtjb", NULL, GetTopString(seq_num),
GetBotString(mainW, parent, job))
{
mainw = mainW;
mainw->RegisterPopup(this);
ApplicationData = job;
strcpy(job_number, job->AttributeValue((char *)JOB_NUMBER));
print_job = job;
props = NULL;
}
DtPrtJobIcon::~DtPrtJobIcon()
{
if (Selected())
Selected(false);
if (mainw->findD)
mainw->findD->DeleteJobFromList(this);
delete props;
}
boolean DtPrtJobIcon::HandleHelpRequest()
{
mainw->DisplayHelp((char *)PRINTJOB_ID);
return true;
}
void DtPrtJobIcon::DisplayProps()
{
if (!props)
{
char *title = new char[200];
sprintf(title, MESSAGE(PrintJobPropsTitleL), mainw->Name());
props = new DtProps(mainw, title, (char *) PROPS_PRINTJOB_ID, false,
print_job->NumAttributes(),
print_job->Attributes());
delete [] title;
}
props->Visible(true);
props->ToFront();
}
void DtPrtJobIcon::PrintJobObj(PrintJob *job)
{
ApplicationData = job;
print_job = job;
if (strcmp(job_number, job->AttributeValue((char *)JOB_NUMBER)))
{
Name(job->DisplayName());
BottomString(GetBotString(mainw, Parent(), job));
strcpy(job_number, job->AttributeValue((char *)JOB_NUMBER));
if (props)
{
props->Visible(false);
delete props;
props = NULL;
DisplayProps();
}
}
}
void DtPrtJobIcon::NotifyVisiblity(BaseUI * /*obj*/)
{
// Empty
}

View File

@@ -0,0 +1,44 @@
/* $XConsortium: DtPrtJobIcon.h /main/3 1995/11/06 09:36:33 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTPRTJOBICON_H
#define DTPRTJOBICON_H
#include "IconObj.h"
#include "PrintJob.h"
class DtMainW;
class DtProps;
extern const char *PROPS_PRINTJOB_ID;
extern const char *PRINTJOB_ID;
class DtPrtJobIcon : public IconObj
{
DtMainW *mainw;
DtProps *props;
PrintJob *print_job;
char job_number[10];
boolean HandleHelpRequest();
void NotifyVisiblity(BaseUI *);
public:
DtPrtJobIcon(DtMainW *, AnyUI *parent, PrintJob *printJob,
int SequenceNumber);
~DtPrtJobIcon();
void DisplayProps();
void PrintJobObj(PrintJob *printJob);
PrintJob *PrintJobObj() { return print_job; }
const char *JobNumber() { return job_number; }
};
#endif // DTPRTJOBICON_H

View File

@@ -0,0 +1,319 @@
/* $TOG: DtPrtProps.C /main/4 1998/07/24 16:14:02 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtPrtProps.h"
#include "DtFindSet.h"
#include "DtMainW.h"
#include "DtPrinterIcon.h"
#include "Button.h"
#include "Container.h"
#include "Group.h"
#include "IconObj.h"
#include "LabelObj.h"
#include "Sep.h"
#include "Dt/Action.h"
#include "dtprintinfomsg.h"
#include <stdio.h>
#include <unistd.h> // This is for the getpid function
#include <stdlib.h> // This is for the getenv function
DtPrtProps::DtPrtProps(DtMainW *parent, char *name, DtPrinterIcon *_printer)
: Dialog(parent, name)
{
mainw = parent;
printer = _printer;
_iconFile = STRDUP(printer->IconFile());
findSetD = NULL;
_has_been_posted = false;
int i, captionWidth = 0, width, columns = 0;
int n_attributes = printer->QueueObj()->NumAttributes();
Attribute **attributes = printer->QueueObj()->Attributes();
if ((width = StringWidth(MESSAGE(IconLabelL))) > captionWidth)
captionWidth = width;
if ((width = StringWidth(MESSAGE(IconGroupTitleL))) > captionWidth)
captionWidth = width;
if ((width = StringWidth(MESSAGE(DescriptionL))) > captionWidth)
captionWidth = width;
if ((width = strlen(printer->Name())) > columns)
columns = width;
for (i = 0; i < n_attributes; i++)
{
if ((width = StringWidth(attributes[i]->DisplayName)) > captionWidth)
captionWidth = width;
if ((width = strlen(attributes[i]->DisplayValue)) > columns)
columns = width;
}
icon_prompt = new Prompt(this, MESSAGE(IconLabelL), true, STRING_PROMPT,
(char *)printer->Name(), NULL,
NULL, true, columns, 1, captionWidth + 8);
icon_prompt->AttachLeft();
icon_prompt->AttachRight();
icon_prompt->AttachTop(5);
Container *form = new Container(this, "form", FORM);
icon_group = new Group(form, NULL, FORM_BOX);
LabelObj *label = new LabelObj(form, MESSAGE(IconGroupTitleL),
RIGHT_JUSTIFIED);
label->AttachTop();
label->AttachBottom();
label->AttachLeft();
label->Width(captionWidth + 8);
icon_group->AttachTop();
icon_group->AttachBottom();
icon_group->AttachRight();
icon_group->AttachLeft(label);
// Creation of Large Icon
largeIcon = new IconObj(icon_group, NULL, printer->IconFile());
largeIcon->IconView(VERY_LARGE_ICON);
largeIcon->AttachLeft(10);
largeIcon->AttachTop(10);
largeIcon->AttachBottom(10);
// Creation of Medium Icon
mediumIcon = new IconObj(icon_group, NULL, printer->IconFile());
mediumIcon->IconView(MEDIUM_ICON);
mediumIcon->AttachLeft(largeIcon, 10);
mediumIcon->AttachBottom(10);
// Creation of Small Icon
smallIcon = new IconObj(icon_group, NULL, printer->IconFile());
smallIcon->IconView(SMALL_ICON);
smallIcon->AttachLeft(mediumIcon, 10);
smallIcon->AttachBottom(10);
// Creation of Find Set Button
find_set = new Button(icon_group, MESSAGE(FindSetL), PUSH_BUTTON, FindSetCB,
this);
find_set->AttachRight(10);
find_set->AttachLeft(smallIcon, 10);
find_set->AttachBottom(10);
form->AttachLeft();
form->AttachRight();
form->AttachTop(icon_prompt, 5);
Container *rc = new Container(this, "rc", VERTICAL_ROW_COLUMN);
for (i = 0; i < n_attributes; i++)
{
new Prompt(rc, attributes[i]->DisplayName, false, STRING_PROMPT,
attributes[i]->DisplayValue, NULL,
NULL, true, columns, 1, captionWidth + 8);
if (mainw->PrinterAppMode() != CONFIG_PRINTERS)
{
char *value;
if (i == 0)
value = _printer->PrintQueueUp() ? MESSAGE(UpL) : MESSAGE(DownL);
else
#ifdef aix
value = _printer->PrintDeviceUp(i - 1) ? MESSAGE(UpL) :
MESSAGE(DownL);
#else
value = _printer->PrintDeviceUp() ? MESSAGE(UpL) : MESSAGE(DownL);
#endif
new Prompt(rc, MESSAGE(PrinterStatusL), false, STRING_PROMPT,
value, NULL, NULL, true, columns, 1, captionWidth + 8);
}
}
rc->AttachRight();
rc->AttachLeft();
rc->AttachBottom();
Sep *sep = new Sep(this);
sep->AttachRight();
sep->AttachLeft();
sep->AttachBottom(rc, 5);
description = new Prompt(this, MESSAGE(DescriptionL), false,
MULTI_LINE_STRING_PROMPT, printer->Description(),
NULL, NULL, true, columns, 3, captionWidth + 8);
description->AttachLeft();
description->AttachRight();
description->AttachTop(form, 5);
description->AttachBottom(sep, 5);
ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
DefaultButton(ok);
CancelButton(cancel);
}
DtPrtProps::~DtPrtProps()
{
delete _iconFile;
}
boolean DtPrtProps::SetVisiblity(boolean flag)
{
Dialog::SetVisiblity(flag);
if (_has_been_posted == false)
{
_has_been_posted = true;
find_set->Height(find_set->Height() + 6);
}
else if (flag)
Reset();
return true;
}
void DtPrtProps::Reset()
{
if (strcmp(printer->IconFile(), _iconFile))
SetActionIcons(printer->IconFile());
icon_prompt->Value((char *)printer->Name());
description->Value(printer->Description());
}
void DtPrtProps::Apply()
{
char *buf;
int buf_len;
char *iconName = (char *)IconLabel();
char *iconFile = (char *)IconFileName();
if (!iconName || *iconName == '\0')
iconName = (char *)printer->Name();
if (!iconFile || *iconFile == '\0')
iconFile = (char *)PRINTER_ICON_FILE;
if (!strcmp(iconName, printer->Name()) &&
!strcmp(iconFile, printer->IconFile()))
{
// return since nothing changed
return;
}
char *save_msg = strdup(mainw->status_line->Name());
mainw->WorkingCursor(true);
mainw->status_line->Name(MESSAGE(UpdatingActionsL));
Refresh();
buf_len = strlen(printer->QueueObj()->Name()) +
(2 * strlen(printer->HomeDir())) + 50;
if (buf_len < 200)
buf_len = 200;
buf = new char [buf_len];
FILE *fp_src, *fp_dest;
char *filename = printer->CreateActionFile();
sprintf(buf, "%s.%ld", filename, (long)getpid());
if (fp_dest = fopen(buf, "w"))
{
if (fp_src = fopen(filename, "r"))
{
while (fgets(buf, buf_len, fp_src))
{
if (strstr(buf, "LABEL"))
fprintf(fp_dest, " LABEL %s\n",
iconName);
else if (strstr(buf, "ICON"))
fprintf(fp_dest, " ICON %s\n",
iconFile);
else
fprintf(fp_dest, "%s", buf);
}
fclose(fp_src);
}
}
fclose(fp_dest);
sprintf(buf, "%s.%ld", filename, (long)getpid());
rename(buf, filename);
DtActionInvoke(((AnyUI *)mainw->Parent())->BaseWidget(), "ReloadActions",
NULL, 0, NULL, NULL, NULL, True, NULL, NULL);
delete [] buf;
mainw->WorkingCursor(false);
mainw->status_line->Name(save_msg);
}
void DtPrtProps::CloseCB()
{
Reset();
Visible(false);
}
void DtPrtProps::OkCB(void *data)
{
DtPrtProps *obj = (DtPrtProps *) data;
obj->Apply();
obj->Visible(false);
}
void DtPrtProps::ApplyCB(void *data)
{
DtPrtProps *obj = (DtPrtProps *) data;
obj->Apply();
}
void DtPrtProps::CancelCB(void *data)
{
DtPrtProps *obj = (DtPrtProps *) data;
obj->Reset();
obj->Visible(false);
}
void DtPrtProps::ResetCB(void *data)
{
DtPrtProps *obj = (DtPrtProps *) data;
obj->Reset();
}
void DtPrtProps::HelpCB(void *data)
{
DtPrtProps *obj = (DtPrtProps *) data;
obj->HandleHelpRequest();
}
boolean DtPrtProps::HandleHelpRequest()
{
mainw->DisplayHelp((char *)PROPS_PRINTER_ID);
return true;
}
void DtPrtProps::SetActionIcons(const char *icon)
{
delete _iconFile;
_iconFile = STRDUP(icon);
largeIcon->IconFile((char*)icon);
mediumIcon->IconFile((char*)icon);
smallIcon->IconFile((char*)icon);
}
void DtPrtProps::CallerCB(BaseUI *caller, char *iconFile)
{
DtPrtProps *obj = (DtPrtProps *)caller;
delete obj->_iconFile;
obj->_iconFile = STRDUP(iconFile);
obj->smallIcon->IconFile(iconFile);
obj->mediumIcon->IconFile(iconFile);
obj->largeIcon->IconFile(iconFile);
}
void DtPrtProps::FindSetCB(void *data)
{
DtPrtProps *obj = (DtPrtProps *)data;
if (!obj->mainw->findSetD)
{
char *name = new char [strlen(obj->mainw->Name()) +
strlen(MESSAGE(FindSetTitleL))];
sprintf(name, MESSAGE(FindSetTitleL), obj->mainw->Name());
obj->mainw->findSetD = new DtFindSet(obj->mainw, name,
&DtPrtProps::CallerCB);
delete [] name;
}
obj->mainw->findSetD->Caller(obj);
obj->mainw->findSetD->Visible(true);
}

View File

@@ -0,0 +1,83 @@
/* $XConsortium: DtPrtProps.h /main/3 1995/11/06 09:36:44 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTPRTPROPS_H
#define DTPRTPROPS_H
#include "Dialog.h"
#include "Prompt.h"
class Button;
class DtMainW;
class Group;
class LabelObj;
class IconObj;
class DtPrinterIcon;
class DtFindSet;
class DtPrtProps : public Dialog {
friend class DtFindIcon;
friend void OkCB(void *data);
friend void ApplyCB(void *data);
friend void CancelCB(void *data);
friend void ResetCB(void *data);
friend void HelpCB(void *data);
friend void FindSetCB(void *data);
friend void CallerCB(BaseUI *, char *);
static void OkCB(void *data);
static void ApplyCB(void *data);
static void CancelCB(void *data);
static void ResetCB(void *data);
static void HelpCB(void *data);
static void FindSetCB(void *data);
static void CallerCB(BaseUI *, char *);
private:
DtMainW *mainw;
// dialog buttons
Button *ok;
Button *apply;
Button *cancel;
Button *reset;
Button *help;
Group *icon_group;
Prompt *icon_prompt;
Prompt *description;
DtFindSet *findSetD;
boolean _has_been_posted;
char *_iconFile;
DtPrinterIcon *printer;
IconObj *smallIcon;
IconObj *mediumIcon;
IconObj *largeIcon;
Button *find_set;
void SetActionIcons(const char *icon);
void CloseCB();
boolean SetVisiblity(boolean);
boolean HandleHelpRequest();
public:
DtPrtProps(DtMainW *, char *name, DtPrinterIcon *printer);
~DtPrtProps();
DtPrinterIcon *Printer() { return printer; }
void Printer(DtPrinterIcon *printer);
const char *IconFileName() { return _iconFile; }
char *IconLabel() { return icon_prompt->Value(); }
void IconLabel(char *value) { icon_prompt->Value(value); }
void Apply();
void Reset();
};
#endif // DTPRTPROPS_H

View File

@@ -0,0 +1,190 @@
/* $XConsortium: DtSetModList.C /main/2 1995/07/17 14:04:17 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtSetModList.h"
#include "DtMainW.h"
#include "DtWorkArea.h"
#include "Button.h"
#include "IconObj.h"
#include "LabelObj.h"
#include "Container.h"
#include "dtprintinfomsg.h"
DtSetModList::DtSetModList(AnyUI *parent,
char *name,
BaseUI *workarea,
ButtonCallback filterCB)
: Dialog(parent, name)
{
mainw = (DtMainW *) parent;
_has_been_posted = false;
_info = new LabelObj(this, MESSAGE(SelectPrintersToBeShowL));
_container = new Container(this, "FilterList", SCROLLED_VERTICAL_ROW_COLUMN,
MULTIPLE_SELECT);
_container->IconView(SMALL_ICON);
_filterCB = filterCB;
_workarea = (Container *) workarea;
Container *form = new Container(this, "Form", FORM);
_info->AttachRight();
_info->AttachLeft();
_info->AttachTop();
form->AttachBottom();
form->AttachRight();
form->AttachLeft();
_container->AttachBottom(form, 5);
_container->AttachRight();
_container->AttachLeft();
_container->AttachTop(_info);
select_all = new Button(form, MESSAGE(SelectAllL), PUSH_BUTTON, SelectAllCB,
_container);
unselect_all = new Button(form, MESSAGE(DeselectAllL), PUSH_BUTTON,
UnSelectAllCB, _container);
int i;
IconObj **objs = (IconObj **) workarea->Children();
for (i = 0; i < workarea->NumChildren(); i++)
{
if (objs[i]->UIClass() == ICON)
{
IconObj *icon = new IconObj(_container, (char *)objs[i]->Name(),
objs[i]->IconFile());
icon->ApplicationData = objs[i];
}
}
ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
apply = new Button(this, MESSAGE(ApplyL), PUSH_BUTTON, ApplyCB, this);
cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
DefaultButton(ok);
CancelButton(cancel);
Reset();
}
DtSetModList::~DtSetModList()
{
// Empty
}
boolean DtSetModList::SetVisiblity(boolean flag)
{
if (_has_been_posted == false)
{
int height;
if (_container->NumChildren())
{
BaseUI **kids = _container->Children();
height = (kids[0]->Height() + 4) * _container->NumChildren();
if (height > 300)
height = 300;
}
else
height = 200;
int width = StringWidth(Name()) + 30;
if (Width() < width)
{
width -= 10;
_container->WidthHeight(width, height);
}
else
_container->Height(height);
_has_been_posted = true;
int offset = (width - (select_all->Width() + unselect_all->Width())) / 3;
select_all->AttachLeft(offset);
unselect_all->AttachRight(offset);
unselect_all->AttachLeft(NULL, 0);
}
Reset();
Dialog::SetVisiblity(flag);
return true;
}
void DtSetModList::Reset()
{
int i;
IconObj **children = (IconObj **) _container->Children();
mainw->container->BeginUpdate();
for (i = 0; i < _container->NumChildren(); i++)
{
IconObj *icon = (IconObj *)children[i]->ApplicationData;
children[i]->Selected(icon->Visible());
if (strcmp(icon->Name(), children[i]->Name()))
children[i]->Name((char *)icon->Name());
if (strcmp(icon->IconFile(), children[i]->IconFile()))
children[i]->IconFile(icon->IconFile());
}
mainw->container->EndUpdate();
}
void DtSetModList::Apply()
{
if (_filterCB)
(*_filterCB)((void *)_container);
}
void DtSetModList::OkCB(void *data)
{
DtSetModList *obj = (DtSetModList *) data;
obj->Apply();
obj->Visible(false);
}
void DtSetModList::Cancel()
{
Reset();
Visible(false);
}
void DtSetModList::CloseCB()
{
Cancel();
}
void DtSetModList::CancelCB(void *data)
{
DtSetModList *obj = (DtSetModList *) data;
obj->Cancel();
}
void DtSetModList::ApplyCB(void *data)
{
DtSetModList *obj = (DtSetModList *) data;
obj->Apply();
}
void DtSetModList::SelectAllCB(void *data)
{
Container *obj = (Container *) data;
obj->SelectAll();
}
void DtSetModList::UnSelectAllCB(void *data)
{
Container *obj = (Container *) data;
obj->SelectAll(false);
}
void DtSetModList::HelpCB(void *data)
{
DtSetModList *obj = (DtSetModList *) data;
obj->HandleHelpRequest();
}
boolean DtSetModList::HandleHelpRequest()
{
mainw->DisplayHelp("ShowPrintersDE");
return true;
}

View File

@@ -0,0 +1,68 @@
/* $XConsortium: DtSetModList.h /main/3 1995/11/06 09:36:56 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTSETMODLIST_H
#define DTSETMODLIST_H
#include "Dialog.h"
class Button;
class Container;
class LabelObj;
class DtMainW;
class DtSetModList : public Dialog {
friend void OkCB(void *);
friend void ApplyCB(void *);
friend void CancelCB(void *);
friend void HelpCB(void *);
friend void SelectAllCB(void *);
friend void UnSelectAllCB(void *);
private:
boolean _has_been_posted;
Container *_container;
DtMainW *mainw;
Container *_workarea;
LabelObj *_info;
Button *select_all;
Button *unselect_all;
// dialog buttons
Button *ok;
Button *apply;
Button *cancel;
Button *help;
static void OkCB(void *);
static void ApplyCB(void *);
static void CancelCB(void *);
static void HelpCB(void *);
static void SelectAllCB(void *);
static void UnSelectAllCB(void *);
boolean SetVisiblity(boolean flag);
ButtonCallback _filterCB;
void CloseCB();
void Apply();
void Cancel();
boolean HandleHelpRequest();
public:
DtSetModList(AnyUI *parent, char *name, BaseUI *container,
ButtonCallback filterCB);
virtual ~DtSetModList();
void Reset();
};
#endif /* DTSETMODLIST_H */

View File

@@ -0,0 +1,312 @@
/* $XConsortium: DtSetPref.C /main/2 1995/07/17 14:04:26 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtSetPref.h"
#include "DtMainW.h"
#include "DtFindD.h"
#include "IconObj.h"
#include "Group.h"
#include "LabelObj.h"
#include "Container.h"
#include "Application.h"
#include "dtprintinfomsg.h"
DtSetPref::DtSetPref(AnyUI *parent,
char *name,
AnyUI *container,
PreferenceCallback callback,
void *callback_data)
: Dialog(parent, name, MODELESS, false)
{
mainw = (DtMainW *) parent;
_has_been_posted = false;
_container = container;
_callback = callback;
_callback_data = callback_data;
// initialize previous values
_previous_style = container->IconView();
_previous_status_flag = true;
_previous_status_line = true;
_previous_show_only_mine = false;
_previous_show_details_label = true;
_previous_update_interval = 30;
view_group = new Group(this, MESSAGE(RepresentationL));
by_icon = new Button(view_group, MESSAGE(LargeIconL), TOGGLE_BUTTON,
RepCB, this);
by_smallIcon = new Button(view_group, MESSAGE(SmallIconL), TOGGLE_BUTTON,
RepCB, this);
by_name = new Button(view_group, MESSAGE(NameOnlyL), TOGGLE_BUTTON,
RepCB, this);
by_properties = new Button(view_group, MESSAGE(DetailsL), TOGGLE_BUTTON,
RepCB, this);
Container *form = new Container(view_group, "form", FORM);
show_labels = new Button(form, MESSAGE(ShowLabelsL), TOGGLE_BUTTON);
show_labels->Selected(true);
show_labels->Active(false);
show_labels->AttachTop();
show_labels->AttachBottom();
show_labels->AttachRight();
show_labels->AttachLeft(20);
show_jobs = new Group(this, MESSAGE(JobsToShowL));
only_mine = new Button(show_jobs, MESSAGE(OnlyMineL), TOGGLE_BUTTON);
everyones = new Button(show_jobs, MESSAGE(EveryoneL), TOGGLE_BUTTON);
everyones->Selected(true);
update_group = new Group(this, MESSAGE(UpdateIntervalL), FORM_BOX);
update_interval = new ScaleObj(update_group, MESSAGE(IntervalL),
30, 0, 5, 300, 5, HORIZONTAL_SCALE, true);
update_interval->AttachAll();
update_group->AttachRight();
update_group->AttachLeft();
update_group->AttachBottom();
status = new Group(this, MESSAGE(StatusL), CHECK_BOX);
status_flag = new Button(status, MESSAGE(ProblemFlagL), TOGGLE_BUTTON);
status_flag->Selected(true);
status_line = new Button(status, MESSAGE(InformationLineL), TOGGLE_BUTTON);
status_line->Selected(true);
status->AttachRight();
status->AttachLeft(view_group, 5);
status->AttachBottom(update_group, 5);
view_group->AttachBottom(update_group, 5);
show_jobs->AttachBottom(status, 5);
view_group->AttachLeft();
view_group->AttachTop();
show_jobs->AttachLeft(view_group, 5);
show_jobs->AttachRight();
show_jobs->AttachTop();
ok = new Button(this, MESSAGE(OKL), PUSH_BUTTON, OkCB, this);
apply = new Button(this, MESSAGE(ApplyL), PUSH_BUTTON, ApplyCB, this);
cancel = new Button(this, MESSAGE(CancelL), PUSH_BUTTON, CancelCB, this);
help = new Button(this, MESSAGE(HelpL), PUSH_BUTTON, HelpCB, this);
DefaultButton(ok);
Reset();
}
DtSetPref::~DtSetPref()
{
// Empty
}
boolean DtSetPref::SetVisiblity(boolean flag)
{
Dialog::SetVisiblity(flag);
if (_has_been_posted == false)
{
_has_been_posted = true;
CancelButton(cancel);
}
return true;
}
void DtSetPref::ShowOnlyMyJobs(boolean value)
{
only_mine->Selected(value);
everyones->Selected(value ? false : true);
}
void DtSetPref::Representation(IconStyle value)
{
by_name->Selected(false);
by_icon->Selected(false);
by_smallIcon->Selected(false);
by_properties->Selected(false);
switch (value)
{
case NAME_ONLY: by_name->Selected(true); break;
case LARGE_ICON: by_icon->Selected(true); break;
case SMALL_ICON: by_smallIcon->Selected(true); break;
case DETAILS: by_properties->Selected(true); break;
}
show_labels->Active(by_properties->Selected());
}
void DtSetPref::Reset()
{
Representation(_previous_style);
status_flag->Selected(_previous_status_flag);
status_line->Selected(_previous_status_line);
(void)update_interval->Value();
update_interval->Value(_previous_update_interval);
ShowOnlyMyJobs(_previous_show_only_mine);
show_labels->Selected(_previous_show_details_label);
}
static void TurnOffHourGlass(BaseUI *obj, void *data)
{
((DtMainW *)obj)->WorkingCursor(false);
((Container *)data)->EndUpdate();
}
void DtSetPref::Apply()
{
IconStyle style;
boolean add_timeout = false;
if (by_name->Selected())
style = NAME_ONLY;
else if (by_icon->Selected())
style = LARGE_ICON;
else if (by_smallIcon->Selected())
style = SMALL_ICON;
else if (by_properties->Selected())
style = DETAILS;
if (_previous_style != style)
{
if (mainw->PrinterAppMode() == PRINT_MANAGER)
{
mainw->WorkingCursor(true);
_container->BeginUpdate();
add_timeout = true;
}
_container->IconView(style);
if (_callback)
{
if (_previous_style == DETAILS)
(*_callback)(_callback_data, DETAILS_OFF, NULL);
else if (style == DETAILS)
(*_callback)(_callback_data, DETAILS_ON, NULL);
}
_previous_style = style;
if (_callback)
{
if (_previous_show_details_label)
(*_callback)(_callback_data, SHOW_DETAILS_LABEL_ON, NULL);
else
(*_callback)(_callback_data, SHOW_DETAILS_LABEL_OFF, NULL);
}
}
if (_previous_status_flag != status_flag->Selected())
{
_previous_status_flag = status_flag->Selected();
if (_callback)
{
if (_previous_status_flag)
(*_callback)(_callback_data, STATUS_FLAG_ON, NULL);
else
(*_callback)(_callback_data, STATUS_FLAG_OFF, NULL);
}
}
if (_previous_status_line != status_line->Selected())
{
_previous_status_line = status_line->Selected();
if (_callback)
{
if (_previous_status_line)
(*_callback)(_callback_data, STATUS_LINE_ON, NULL);
else
(*_callback)(_callback_data, STATUS_LINE_OFF, NULL);
}
}
if (_previous_show_only_mine != only_mine->Selected())
{
if (mainw->PrinterAppMode() == PRINT_MANAGER)
{
mainw->WorkingCursor(true);
_container->BeginUpdate();
add_timeout = true;
}
_previous_show_only_mine = only_mine->Selected();
if (_callback)
{
if (_previous_show_only_mine)
(*_callback)(_callback_data, SHOW_ONLY_MINE_ON, NULL);
else
(*_callback)(_callback_data, SHOW_ONLY_MINE_OFF, NULL);
if (_previous_show_details_label)
(*_callback)(_callback_data, SHOW_DETAILS_LABEL_ON, NULL);
else
(*_callback)(_callback_data, SHOW_DETAILS_LABEL_OFF, NULL);
}
}
if (_previous_show_details_label != show_labels->Selected())
{
_previous_show_details_label = show_labels->Selected();
if (_callback)
{
if (_previous_show_details_label)
(*_callback)(_callback_data, SHOW_DETAILS_LABEL_ON, NULL);
else
(*_callback)(_callback_data, SHOW_DETAILS_LABEL_OFF, NULL);
}
}
if (update_interval->Value() != _previous_update_interval)
{
_previous_update_interval = update_interval->Value();
if (_callback)
(*_callback)(_callback_data, UPDATE_INTERVAL_CHANGED,
(char *) _previous_update_interval);
}
if (mainw->findD)
mainw->findD->UpdateMatchAnyUser();
if (add_timeout)
mainw->AddTimeOut(TurnOffHourGlass, _container, 1500);
}
void DtSetPref::OkCB(void *data)
{
DtSetPref *obj = (DtSetPref *) data;
obj->Apply();
obj->Visible(false);
}
void DtSetPref::Cancel()
{
Reset();
Visible(false);
}
void DtSetPref::CancelCB(void *data)
{
DtSetPref *obj = (DtSetPref *) data;
obj->Cancel();
}
void DtSetPref::CloseCB()
{
Cancel();
}
void DtSetPref::ApplyCB(void *data)
{
DtSetPref *obj = (DtSetPref *) data;
obj->Apply();
}
void DtSetPref::HelpCB(void *data)
{
DtSetPref *obj = (DtSetPref *) data;
obj->HandleHelpRequest();
}
void DtSetPref::RepCB(void *data)
{
DtSetPref *obj = (DtSetPref *) data;
obj->show_labels->Active(obj->by_properties->Selected());
}
boolean DtSetPref::HandleHelpRequest()
{
mainw->DisplayHelp("SetOptionsDE");
return true;
}

View File

@@ -0,0 +1,118 @@
/* $XConsortium: DtSetPref.h /main/3 1995/11/06 09:37:08 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTSETPREF_H
#define DTSETPREF_H
#include "Dialog.h"
#include "Button.h"
#include "ScaleObj.h"
class Group;
class DtMainW;
typedef enum
{
DETAILS_ON,
DETAILS_OFF,
STATUS_LINE_ON,
STATUS_LINE_OFF,
STATUS_FLAG_ON,
STATUS_FLAG_OFF,
SHOW_ONLY_MINE_ON,
SHOW_ONLY_MINE_OFF,
SHOW_DETAILS_LABEL_ON,
SHOW_DETAILS_LABEL_OFF,
UPDATE_INTERVAL_CHANGED
} PreferenceRequest;
typedef void (*PreferenceCallback) (void *callback_data, PreferenceRequest,
char *value);
class DtSetPref : public Dialog {
friend void OkCB(void *);
friend void ApplyCB(void *);
friend void CancelCB(void *);
friend void HelpCB(void *);
friend void RepCB(void *);
private:
boolean _has_been_posted;
IconStyle _previous_style;
boolean _previous_status_flag;
boolean _previous_status_line;
boolean _previous_show_only_mine;
boolean _previous_show_details_label;
int _previous_update_interval;
AnyUI *_container;
PreferenceCallback _callback;
void *_callback_data;
DtMainW *mainw;
Group *show_jobs;
Button *only_mine;
Button *everyones;
Group *status;
Button *status_line;
Button *status_flag;
Group *view_group;
Button *by_name;
Button *by_icon;
Button *by_smallIcon;
Button *by_properties;
Button *show_labels;
Group *update_group;
ScaleObj *update_interval;
// dialog buttons
Button *ok;
Button *apply;
Button *cancel;
Button *help;
static void OkCB(void *);
static void ApplyCB(void *);
static void CancelCB(void *);
static void HelpCB(void *);
static void RepCB(void *);
void CloseCB();
boolean SetVisiblity(boolean flag);
void Cancel();
void Reset();
boolean HandleHelpRequest();
public:
DtSetPref(AnyUI *parent, char *name, AnyUI *container,
PreferenceCallback callback, void *callback_data);
virtual ~DtSetPref();
void Apply();
boolean ShowStatusFlags() { return _previous_status_flag; }
boolean ShowStatusLine() { return _previous_status_line; }
boolean ShowOnlyMyJobs() { return _previous_show_only_mine; }
boolean ShowDetailsLabel() { return _previous_show_details_label; }
IconStyle Represetation() { return _previous_style; }
int UpdateInterval() { return _previous_update_interval; }
void Representation(IconStyle);
void ShowOnlyMyJobs(boolean);
void ShowStatusFlags(boolean value) { status_flag->Selected(value); }
void ShowStatusLine(boolean value) { status_line->Selected(value); }
void ShowDetailsLabel(boolean value) { show_labels->Selected(value); }
void UpdateInterval(int value) { update_interval->Value(value); }
};
#endif /* DTSETPREF_H */

View File

@@ -0,0 +1,46 @@
/* $XConsortium: DtWorkArea.C /main/2 1995/07/17 14:04:34 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "DtWorkArea.h"
#include "DtMainW.h"
#include "DtActions.h"
DtWorkArea::DtWorkArea(char *category,
AnyUI *parent,
char *name,
ContainerType container_type,
SelectionType select_type)
: Container(category, parent, name, container_type, select_type)
{
_mainW = (DtMainW *) parent->Parent();
}
void DtWorkArea::NotifySelected(BaseUI *obj)
{
Container::NotifySelected(obj);
if (_mainW->UIClass() != MAIN_WINDOW)
return;
BaseUI **selection;
int n_items;
Selection(&n_items, &selection);
if (n_items)
_mainW->actionsMenu->UpdateActions(n_items, selection[0]);
else
_mainW->actionsMenu->UpdateActions(n_items, NULL);
delete []selection;
}
void DtWorkArea::NotifyOpen(BaseUI *obj)
{
if (_mainW->UIClass() != MAIN_WINDOW)
return;
_mainW->OpenClose(obj);
}

View File

@@ -0,0 +1,33 @@
/* $XConsortium: DtWorkArea.h /main/3 1995/11/06 09:37:19 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTWORKAREA_H
#define DTWORKAREA_H
#include "Container.h"
class DtMainW;
class DtWorkArea : public Container
{
private:
DtMainW * _mainW;
void NotifySelected(BaseUI *obj);
void NotifyOpen(BaseUI *obj);
public:
DtWorkArea(char *category, AnyUI *parent, char *name,
ContainerType = SCROLLED_WORK_AREA,
SelectionType = SINGLE_SELECT);
};
#endif // DTWORKAREA_H

View File

@@ -0,0 +1,33 @@
XCOMM $XConsortium: Imakefile /main/6 1996/04/21 19:50:41 drk $
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName DtPrintinfo
#define LibHeaders NO
#define LibInstall NO
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
INCLUDES = -I. -I.. -I../libUI -I../libUI/MotifUI -I../objects -I../util -I../objects -I../objects/PrintObj
#ifdef RsArchitecture
DEFINES = -DHAS_EXCEPTIONS
#endif
SRCS = DtActions.C DtApp.C DtDetailsLabel.C \
DtFindD.C DtFindSet.C DtMainW.C \
DtPrinterIcon.C DtProps.C DtPrtJobIcon.C \
DtPrtProps.C DtSetModList.C DtSetPref.C \
DtWorkArea.C
OBJS = DtActions.o DtApp.o DtDetailsLabel.o \
DtFindD.o DtFindSet.o DtMainW.o \
DtPrinterIcon.o DtProps.o DtPrtJobIcon.o \
DtPrtProps.o DtSetModList.o DtSetPref.o \
DtWorkArea.o
#include <Library.tmpl>
DependTarget()

View File

@@ -0,0 +1,258 @@
$ $XConsortium: dtprintinfo.msg.src /main/1 1995/12/04 17:07:27 rswiston $
$quote "
$set DTPRINTER_SET
$ ----- These are the titles that appear on dialogs and the main window -----
ApplicationName1L "Print Manager"
ApplicationName2L "Printer Jobs"
$ Do not translate ApplicationName3L for this release
ApplicationName3L "Desktop Printers"
$ ----- Common Dialog Buttons -----
YesL "Yes"
NoL "No"
OKL "OK"
ApplyL "Apply"
CancelL "Cancel"
HelpL "Help"
$ ----- Find dialog -----
FindTitleL "%s - Find Print Jobs"
MyJobNameL "My Job's Name"
OnlyRootJobsL "Only root jobs"
IgnoreCaseL "Ignore case"
ExactMatchL "Exact match"
GotoL "Goto"
CancelPrintJobsL "Cancel Print Jobs"
PositionL "Position"
CloseL "Close"
StartFindL "Start Find"
StopFindL "Stop Find"
SearchL "\
Searching %s...\n\
\n\
Press Stop to interrupt"
$ Find Information dialog messages
NoMatchesL "No print jobs matched"
NotFoundMessageL "\
The print job no longer exists or\n\
the printer is closed."
$ ----- Modify Show Dialog -----
ModifyShowTitleL "%s - Modify the Show List"
SelectPrintersToBeShowL "Select printers to be shown"
SelectAllL "Select All"
DeselectAllL "Deselect All"
$ ----- Set Options Dialog -----
SetOptionsTitleL "%s - Set Options"
RepresentationL "Representation"
LargeIconL "Large Icon"
SmallIconL "Small Icon"
NameOnlyL "Name Only"
DetailsL "Details"
ShowLabelsL "Show Labels"
JobsToShowL "Jobs to Show"
OnlyMineL "Only Mine"
EveryoneL "Everyone's"
StatusL "Status"
ProblemFlagL "Problem Flag"
InformationLineL "Message Line"
UpdateIntervalL "Updates"
IntervalL "Interval (in seconds)"
$ ----- Print Job Properties Dialog -----
PrintJobPropsTitleL "%s - Print Job Properties"
PrinterL "Printer"
JobName1L "Job Name"
SubmittedL "Submitted"
BytesL "bytes"
Position1L "Position:"
JobNameL "Job Name:"
JobNumberL "Job Number:"
OwnerL "Owner:"
DateL "Date:"
TimeL "Time:"
SizeL "Size:"
$ ----- Printer Properties Dialog -----
PrinterPropsTitleL "%s - Printer Properties"
IconLabelL "Icon Label:"
IconGroupTitleL "Icons:"
FindSetL "Find Set..."
DescriptionL "Description:"
PrinterStatusL "Status:"
PrintQueueL "Printer Queue:"
DeviceL "Device Name:"
DeviceNL "Device %d:"
UpL "Up - In Service"
DownL "Down - Out of Service"
PrinterOnServerL "%1$s on %2$s"
DefaultDescriptionL "This is the %s printer queue."
$ %1 is the printer name and %2 is the server name, ex: "lp0 on warpspeed"
$ This is the value of the device field when the printer is on a remote system
$ ----- Find Set Dialog -----
FindSetTitleL "%s - Find Set"
IconFoldersL "Icon Folders:"
IconTitleL "Icons"
LoadingIconsL "Loading icons %1$d of %2$d..."
$ %1 is a counter and %2 is the total number of icons
$ ----- "Cancel" Print Job Confirmation Dialog -----
CancelTitleL "%s - Cancel %s"
CancelQuestionL "Are you sure you want to cancel %s?"
$ ----- Printer "Status" Dialog -----
PrinterStatusTitleL "%s - Printer Status"
PrinterDownL "The %s printer queue is out of service."
DeviceDownL "The %s device is out of service."
$ ----- Failed Action Dialog -----
FailedActionTitleL "%s - %s failed"
FailedMessageL "Could not apply the '%s' action to\n\
%s. See reason below.\n\n%s"
$ ----- Main Window Information Line Messages -----
GettingHelpL "Getting on line Help..."
SearchingL "Searching for printers..."
ShowingMyJobsL "Showing only my jobs"
PrintersHiddenL "%d Printers %d Hidden"
JobsL "%d Jobs"
UpdatingActionsL "Updating action database..."
UpdatingL "Updating %s..."
$ Do not translate EditLangL for this release
EditLangL "Editing in /etc/dt/appconfig/types/%s"
$ %s is the name of the printer
$ ----- Printer Menu Messages -----
PrinterMenuL "Printers"
PrinterAcceleratorL "P"
FindChoiceL "Find..."
FindMnemonicL "F"
FindAcceleratorL "Ctrl+F"
ExitChoiceL "Exit"
ExitMnemonicL "x"
ExitAcceleratorL "Alt+F4"
$ ----- Selected Menu Messages -----
SelectedMenuL "Selected"
SelectedAcceleratorL "S"
$ For Print Jobs Only - "Cancel" means to remove a print job from the printer.
$ This choice pops up the "Cancel" Print Job Confirmation
$ Dialog.
CancelChoiceL "Cancel"
CancelMnemonicL "C"
CancelAcceleratorL "Del"
$ For Printers Only
OpenChoiceL "Open"
OpenMnemonicL "O"
CloseChoiceL "Close"
CloseMnemonicL "C"
HideChoiceL "Hide"
HideMnemonicL "e"
$ Do not translate RenameChoiceL for this release
RenameChoiceL "Rename"
$ Do not translate RenameMnemonicL for this release
RenameMnemonicL "R"
$ Do not translate StartChoiceL for this release
StartChoiceL "Start queuing"
$ Do not translate StartMnemonicL for this release
StartMnemonicL "S"
$ Do not translate StopChoiceL for this release
StopChoiceL "Stop queuing"
$ Do not translate StopMnemonicL for this release
StopMnemonicL "t"
$ Do not translate EnableChoiceL for this release
EnableChoiceL "Enable printing"
$ Do not translate EnableMnemonicL for this release
EnableMnemonicL "E"
$ Do not translate DisableChoiceL for this release
DisableChoiceL "Disable printing"
$ Do not translate DisableMnemonicL for this release
DisableMnemonicL "D"
$ For Both Printers and Print Jobs
PropertiesChoiceL "Properties..."
PropertiesMnemonicL "P"
PropertiesAcceleratorL "Ctrl+Backspace"
HelpChoiceL "Help"
HelpMnemonicL "H"
$ ----- View Menu Messages -----
ViewMenuL "View"
ViewAcceleratorL "V"
SetOptionsChoiceL "Set Options..."
SetOptionsMnemonicL "O"
ModifyShowChoiceL "Modify the Show List..."
ModifyShowMnemonicL "M"
$ ----- Help Menu Messages -----
$ "Help" Menu uses the "HelpChoiceL" message
$ "Help" Accelerator uses the "HelpMnemonicL" message
OverviewChoiceL "Overview"
OverviewMnemonicL "v"
TaskChoiceL "Tasks"
TaskMnemonicL "T"
ReferenceChoiceL "Reference"
ReferenceMnemonicL "R"
OnItemChoiceL "On Item"
OnItemMnemonicL "O"
UsingHelpChoiceL "Using Help"
UsingHelpMnemonicL "U"
AboutChoice1L "About Print Manager"
AboutChoice2L "About Printer Jobs"
$ Do not translate AboutChoice3L for this release
AboutChoice3L "About Desktop Printers"
AboutMnemonicL "A"
$ ----- Misc Messages -----
EmptyL "[ Empty ]"
FoundNoPrintersL "Found no printers."
NotAvailableL "not available"
NoDefaultPrinter1L "There is no system default printer."
NoDefaultPrinter2L "\
See the Users Guide for information explaining how\n\
to set the default printer LPDEST environment."
$ %1 is the name of the program, and %2 is either '-edit' or '-populate'.
RootUserL "%1$s: You must be root to use the %2$s option."
$ ----- Command Line Help -----
$ This message is show when the user enters 'dtprintinfo -help'
$ on the command line. The %s is a printer list generated by the program.
CommandLineHelpL "\
dtprintinfo\n\
\n\
Starting dtprintinfo without any options, shows the LPDEST\n\
printer or the system default if LPDEST is not set.\n\
\n\
dtprintinfo -p <printer>\n\
\n\
To see a specific printer, use the -p option and one of\n\
the following print queue names:\n\
\n\
%s\
\n\
dtprintinfo -all\n\
\n\
To see all printers, use the -all option.\n\
\n\
dtprintinfo -populate\n\
\n\
The -populate option is available only for root. This\n\
option creates default printer actions for all printers\n\
in /etc/dt/appconfig/types/LANG. If LANG is not defined,\n\
the actions are created in /etc/dt/appconfig/types/C."
NoRemoteCancelL "The print server did not supply the print job number.\n\
Some print servers do not allow remote cancellation of\n\
print jobs. If you know this one does, please contact\n\
your print server administrator."
FindAcceleratorKeySeq "Ctrl<Key>f"

View File

@@ -0,0 +1,43 @@
/* $XConsortium: dtprintinfomsg.h /main/3 1995/11/06 09:33:49 rswiston $ */
#ifndef DTPRINTINFOMSG_H
#define DTPRINTINFOMSG_H
#if !defined(USL) && !defined(__uxp__)
/*
* if __cplusplus is defined, the system header files take care
* of themselves and putting this "extern C" here causes inconsistent linkage
* specifications.
*/
#ifdef __cplusplus
extern "C" {
#endif
#endif /* ! USL */
#include <nl_types.h>
#include <locale.h>
#if defined(USL) || defined(__uxp__)
#ifdef __cplusplus
extern "C" {
#endif
#endif /* USL */
#include "dtprintinfo_msg.h"
#include "dtprintinfo_cat.h"
extern nl_catd dtprintinfo_cat;
#ifdef hpux
extern char *Catgets(nl_catd catd, int set_num, int msg_num, char *s);
#define MESSAGE(msg) \
Catgets(dtprintinfo_cat,DTPRINTER_SET,msg,TXT_DTPRINTER_SET_ ## msg)
#else
#define MESSAGE(msg) \
catgets(dtprintinfo_cat,DTPRINTER_SET,msg,TXT_DTPRINTER_SET_ ## msg)
#endif
#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif
#endif /* DTPRINTINFOMSG_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,445 @@
/* $TOG: BaseUI.h /main/5 1998/04/06 13:31:37 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef BASEUI_H
#define BASEUI_H
#include <stdio.h>
#ifndef _BOOLEAN_
#define _BOOLEAN_
#if (defined(sun) && OSMAJORVERSION <= 5 && OSMINORVERSION <= 3)|| defined(USL) || defined(__uxp__)
#include <sys/types.h>
#define boolean boolean_t
#define true B_TRUE
#define false B_FALSE
#elif defined(linux)
#define false 0
#define true 0
#define boolean int
#else
typedef enum
{
false = 0,
true = 1
} boolean;
#endif
#endif
#ifndef STRDUP
#define STRDUP(string) (string ? strdup(string) : (char*) NULL)
#define STRCMP(s1, s2) (s1 && s2 ? strcmp(s1, s2) : (s1 ? 1 : -1))
#define STRLEN(string) (string ? strlen(string) : 0)
#endif
typedef enum
{
BASE_UI,
APPLICATION,
BUTTON,
COMBO_BOX,
CONTAINER,
DIALOG,
LABEL,
LIST,
GROUP,
HELP_SYSTEM,
ICON,
MAIN_WINDOW,
MENU,
MENU_BAR,
PROMPT,
SEPARATOR,
SPIN_BUTTON,
SCALE,
TEXT
} UI_Class;
typedef enum
{
MODELESS,
MODAL,
INFORMATION,
ERROR,
WORK_IN_PROGRESS,
FILE_SELECTION, // This type is always modal
DIRECTORY_SELECTION, // This type is always modal
FILE_DIRECTORY_SELECTION, // This type is always modal
QUESTION, // This type is always modal
WARNING, // This type is always modal
PROMPT_DIALOG, // This type is always modal
MODAL_WORK_IN_PROGRESS,
MODAL_ERROR,
MODAL_INFORMATION
} DialogType;
typedef enum
{
PULLDOWN_MENU,
OPTION_MENU,
POPUP_MENU
} MenuType;
typedef enum
{
LEFT_JUSTIFIED,
CENTERED,
RIGHT_JUSTIFIED
} LabelType;
typedef enum
{
VERTICAL_SCALE,
HORIZONTAL_SCALE
} ScaleType;
typedef enum
{
FIXED_LIST,
SCROLLED_LIST
} ListType;
typedef enum
{
READ_ONLY,
EDITABLE,
SCROLLED_READ_ONLY,
SCROLLED_EDITABLE
} TextType;
typedef enum
{
SINGLE_SELECT,
MULTIPLE_SELECT,
EXTENDED_SELECT,
BROWSE_SELECT
} SelectionType;
typedef enum
{
STRING_PROMPT,
MULTI_LINE_STRING_PROMPT,
INTEGER_PROMPT,
REAL_PROMPT
} PromptType;
typedef enum
{
CHECK_BOX,
RADIO_GROUP,
HORIZONTAL_CHECK_BOX,
HORIZONTAL_RADIO_GROUP,
FORM_BOX
} GroupType;
typedef enum
{
CANVAS,
FORM,
VERTICAL_ROW_COLUMN,
HORIZONTAL_ROW_COLUMN,
PANE,
WORK_AREA,
ICON_LIST,
SCROLLED_CANVAS,
SCROLLED_FORM,
SCROLLED_VERTICAL_ROW_COLUMN,
SCROLLED_HORIZONTAL_ROW_COLUMN,
SCROLLED_PANE,
SCROLLED_WORK_AREA,
SCROLLED_ICON_LIST
} ContainerType;
typedef enum
{
PUSH_BUTTON,
TOGGLE_BUTTON,
UP_ARROW_BUTTON,
DOWN_ARROW_BUTTON,
LEFT_ARROW_BUTTON,
RIGHT_ARROW_BUTTON
} ButtonType;
typedef enum
{
NO_LINE,
SINGLE_LINE,
DOUBLE_LINE,
SINGLE_DASHED_LINE,
DOUBLE_DASHED_LINE,
SHADOW_ETCHED_IN,
SHADOW_ETCHED_OUT,
SHADOW_ETCHED_IN_DASH,
SHADOW_ETCHED_OUT_DASH
} SeparatorStyle;
typedef enum
{
AS_PLACED,
GRID,
BROWSER,
TREE,
PROPERTIES
} ViewStyle;
typedef enum
{
NAME_ONLY,
VERY_LARGE_ICON,
LARGE_ICON,
MEDIUM_ICON,
SMALL_ICON,
TINY_ICON,
DETAILS
} IconStyle;
typedef enum
{
LEFT_SLANTED_ARROW_CURSOR,
RIGHT_SLANTED_ARROW_CURSOR,
WATCH_CURSOR,
HOUR_GLASS_CURSOR,
IBEAM_CURSOR,
CROSS_HAIRS_CURSOR
} PointerCursor;
class BaseUI;
typedef boolean (*SelectProc) (BaseUI *object);
typedef boolean (*CompareProc) (BaseUI **first, BaseUI **second);
typedef void (*TimeOutCallback) (BaseUI *object, void *callback_data);
typedef void (*ButtonCallback) (void *);
typedef void (*DialogCallback) (void *);
typedef boolean (*ValidationCallback) (void *client_data, void *call_data);
typedef void (*ThreadCallback) (BaseUI *obj, char *output, int rc);
const NO_SUBCLASS = -1;
class BaseUI {
public:
#ifdef DEBUG
static int indent;
static boolean trace_calls;
static void EnterFunction(char *message);
static void LeaveFunction(char *message);
#define TraceFunctionCalls(flag) trace_calls = flag
#else
#define EnterFunction(message)
#define LeaveFunction(message)
#define TraceFunctionCalls(flag)
#endif
protected:
static int _UniqueID;
char *_name;
char *_category;
int _id;
BaseUI *_parent;
BaseUI **_children;
int _numChildren;
BaseUI **_allChildren;
int _numAllChildren;
boolean _has_been_opened;
boolean _opened;
boolean _visible;
boolean _active;
boolean _selected;
boolean _update;
char *_update_message;
ViewStyle _viewStyle;
IconStyle _iconStyle;
BaseUI(BaseUI *parent,
const char *name,
const char *category = NULL);
// Derived classes must define these functions
virtual boolean SetVisiblity(boolean) = 0;
virtual boolean SetActivity(boolean) = 0;
virtual boolean SetSelected(boolean) = 0;
virtual boolean SetName(char *) = 0;
virtual boolean SetCategory(char *) = 0;
virtual boolean SetOpen(boolean) = 0;
virtual boolean SetView(ViewStyle) = 0;
virtual boolean SetIcon(IconStyle) = 0;
virtual boolean SetParent(BaseUI *new_parent) = 0;
virtual void SetAddTimeOut(TimeOutCallback, void *, long interval) = 0;
virtual void DoRefresh() = 0;
virtual void DoToFront() = 0;
virtual void DoContextualHelp() = 0;
virtual void DoBeginUpdate() = 0;
virtual void DoEndUpdate() = 0;
virtual void DoMakeVisible() = 0;
virtual boolean DoIsVisible() { return true; }
virtual void DoUpdateMessage(char *message) = 0;
virtual boolean SetOrder(int) = 0;
void SetVisible(boolean);
void AddToParent();
void DeleteFromParent();
void AddToParentContainer();
void DeleteFromParentContainer();
void _Find(void *, int, int *, BaseUI ***, SelectProc, boolean,
boolean, boolean, int);
BaseUI *_FindBy(char *, int, int *, BaseUI ***, SelectProc, boolean,
boolean, boolean);
// These messages are sent to all parents
// up to and including the parent container
virtual void NotifyCreate(BaseUI *) { } ;
virtual void NotifyDelete(BaseUI *) { } ;
virtual void NotifyVisiblity(BaseUI *) { } ;
virtual void NotifySelected(BaseUI *) { } ;
virtual void NotifyOpen(BaseUI *) { } ;
public:
// Not Used By Subclasses, for application programmers only
void *ApplicationData;
virtual ~BaseUI(); // destructor
virtual boolean HandleHelpRequest();
void ContextualHelp();
int UniqueID() { return _id; }
boolean ObjectExists(int unique_id);
// Set functions
void Visible(boolean); // Set visiblity, calls SetVisiblity
void Active(boolean); // Set sensitivity, calls SetActivity
void Selected(boolean); // Set selected status, calls SetSelected
void Open(boolean); // Set opened status, calls SetOpen
void Name(char *); // Set name, calls SetName
void Category(char *); // Set category, calls SetCategory
void ContainerView(ViewStyle); // Set container view, calls SetView
void IconView(IconStyle); // Set icon view, calls SetIcon
void Parent(BaseUI *new_parent); // Set parent, calls SetParent
virtual void Details(char *) { }
// Access functions
const boolean Visible() { return _visible; }
const boolean Active() { return _active; }
const boolean Selected() { return _selected; }
const boolean Open() { return _opened; }
const boolean HasBeenOpened() { return _has_been_opened; }
const char * Name() { return _name; }
const char * Category() { return _category; }
const ViewStyle ContainerView() { return _viewStyle; }
const IconStyle IconView() { return _iconStyle; }
virtual char * Details() { return NULL; }
BaseUI * Parent() { return _parent; }
BaseUI ** Children() { return _children; }
int NumChildren() { return _numChildren; }
BaseUI ** AllChildren() { return _allChildren; }
int NumAllChildren() { return _numAllChildren; }
// These are for children
BaseUI ** Siblings();
int NumSiblings();
BaseUI * ContainerParent();
int NumContainerChildren();
BaseUI ** ContainerChildren();
void DeleteChildren();
virtual void PointerShape(PointerCursor) { }
virtual PointerCursor PointerShape() { return LEFT_SLANTED_ARROW_CURSOR; }
virtual void AttachAll(int /*offset*/ = 0) { }
virtual void AttachTop(int /*offset*/ = 0) { }
virtual void AttachBottom(int /*offset */= 0) { }
virtual void AttachLeft(int /*offset */= 0) { }
virtual void AttachRight(int /*offset */= 0) { }
virtual void AttachTop( BaseUI *,
int /*offset*/ = 0, boolean /*opposite*/ = false) { }
virtual void AttachBottom(BaseUI *,
int /*offset*/ = 0, boolean /*opposite*/ = false) { }
virtual void AttachLeft( BaseUI *,
int /*offset*/ = 0, boolean /*opposite*/ = false) { }
virtual void AttachRight( BaseUI *,
int /*offset*/ = 0, boolean /*opposite*/ = false) { }
virtual void WidthHeight(int /*width*/, int /*height*/) { }
virtual void WidthHeight(int * /*width*/, int * /*height*/) { }
virtual void Width(int /*width*/) { }
virtual int Width() { return 0; }
virtual void Height(int /*height*/) { }
virtual int Height() { return 0; }
virtual void StringWidthHeight(const char * /*string*/, int * /*w*/,
int * /*h*/) { }
virtual int StringWidth(const char * /*string*/) { return 0; }
virtual int StringHeight(const char * /*string*/) { return 0; }
virtual void Thread(const char * /*cmd*/, ThreadCallback,
int /*buf_len*/ = 512) { }
virtual void Thread(int /*pid*/, int /*fd*/, ThreadCallback,
int /*buf_len*/ = 512) { }
virtual void Thread(int /*socket*/, ThreadCallback,
int /*buf_len*/ = 512) { }
// Add timeouts to object (interval is in terms of milliseconds)
void AddTimeOut(TimeOutCallback, void *callback_data, long interval);
virtual int MicroSleep(long milliseconds);
void Refresh();
void ToFront();
void BeginUpdate();
void EndUpdate();
void MakeVisible();
boolean IsVisible();
void UpdateMessage(const char *message);
BaseUI *FindByName(char *pattern,
int depth = 1,
int *n_mactches = NULL,
BaseUI ***matches = NULL,
SelectProc select_proc = NULL,
boolean regular_expression = false,
boolean case_sensitive = true);
BaseUI *FindByCategory(char *pattern,
int depth = 1,
int *n_mactches = NULL,
BaseUI ***matches = NULL,
SelectProc select_proc = NULL,
boolean regular_expression = false,
boolean case_sensitive = true);
void OrderByName(boolean flag); // Calls SetOrder
void GroupByCategory(boolean flag); // Calls SetOrder
int Order(); // Returns order
void Order(int new_position); // Calls SetOrder
// Dumps object to stdout
virtual void Dump(boolean verbose = false,
int level = 0);
// Dumps object heirarchy to stdout
void DumpHierarchy(boolean verbose = false,
int level = 0);
// Select/UnSelected all immediate children
virtual void SelectAll(boolean select_status = true);
// Select/UnSelected all children, and their children, etc...
virtual void SelectAllDescendants(boolean select_status = true);
// Open/Close all children, and their children, etc...
virtual void OpenAllDescendants(boolean opened = true);
// Get selected items
virtual void Selection(int *n_items,
BaseUI ***items = NULL);
virtual const UI_Class UIClass() { return BASE_UI; }
virtual const int UISubClass() { return NO_SUBCLASS; }
virtual const char *const UIClassName() { return "BaseUI"; }
};
#endif // BASEUI_H

View File

@@ -0,0 +1,37 @@
XCOMM $TOG: Imakefile /main/14 1998/08/25 12:59:12 mgreess $
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
EXTRA_LOAD_FLAGS = ExtraLoadFlags $(UNSHARED_CXXLIB)
#define IHaveSubdirs
#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CXXDEBUGFLAGS=$(CXXDEBUGFLAGS)'
SUBDIRS = MotifUI
MakeSubdirs($(SUBDIRS))
DependSubdirs($(SUBDIRS))
INCLUDES = -I. -I./MotifUI
DEPLIBS = ./MotifUI/libMotifUI.a DepDtClientLibs
LOCAL_LIBRARIES = ./MotifUI/libMotifUI.a DtClientLibs
SYS_LIBRARIES = DtClientSysLibs DtClientExtraLibs
#ifdef RsArchitecture
DEFINES = -DHAS_EXCEPTIONS
#endif
#ifdef AlphaArchitecture
DEFINES = -UNO_REGCOMP
#endif
SRCS = BaseUI.C Test.C
OBJS = BaseUI.o Test.o
NormalCplusplusObjectRule()
ComplexCplusplusProgramTarget(Test)
clean::
$(RM) *.map

View File

@@ -0,0 +1,363 @@
/* $TOG: Application.C /main/9 1998/07/24 16:14:41 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Application.h"
#include <sys/stat.h>
#include <Xm/Protocols.h>
#ifndef NO_CDE
extern "C" {
#include <Dt/Dt.h>
#include <Dt/EnvControlP.h>
#include <Dt/DbUtil.h>
#include <Dt/Action.h>
#include <Dt/Session.h>
}
#endif
#include <stdlib.h> // for putenv function
const char *SESSION_FLAG = "-session";
const char *SESSION_NAME = "session";
const char *SESSION_CLASSNAME = "Session";
const char *DEFAULT_FONT = "fixed";
typedef struct
{
XmFontList user_font;
XmFontList system_font;
char *session_file;
Dimension shadow_thickness;
} ApplicationArgs, *ApplicationArgsPtr;
static XtResource resources[] =
{
{"userFont", "XmCFontList", XmRFontList, sizeof(XmFontList),
XtOffsetOf (ApplicationArgs, user_font), XmRString,
#ifdef aix
(XtPointer) DEFAULT_FONT
#else
(XtPointer) "fixed"
#endif
},
{"systemFont", "XmCFontList", XmRFontList, sizeof(XmFontList),
XtOffsetOf (ApplicationArgs, system_font), XmRString,
#ifdef aix
(XtPointer) DEFAULT_FONT
},
{(char *)SESSION_NAME, (char *)SESSION_CLASSNAME, XtRString, sizeof(char *),
#else
(XtPointer) "fixed"
},
{"session", "Session", XtRString, sizeof(char *),
#endif
XtOffsetOf (ApplicationArgs, session_file), XmRString, (XtPointer) NULL,
},
{XmNshadowThickness, XmCShadowThickness, XmRHorizontalDimension,
sizeof (Dimension), XtOffsetOf (ApplicationArgs, shadow_thickness),
XmRImmediate, (XtPointer) 1
}
};
static XrmOptionDescRec options[] =
{
#ifdef aix
{(char *)SESSION_FLAG, (char *)SESSION_NAME, XrmoptionSepArg, NULL}
#else
{"-session", "session", XrmoptionSepArg, NULL}
#endif
};
extern "C" {
extern void XmeRenderTableGetDefaultFont(XmFontList, XFontStruct **);
}
Application::Application(char *name,
char *appClassName,
int *_argc,
char **_argv)
: MotifUI(NULL, name, appClassName, appClassName)
{
#ifndef NO_CDE
_DtEnvControl(DT_ENV_SET);
#endif
XtSetLanguageProc(NULL, NULL, NULL);
_w = XtVaAppInitialize(&appContext, appClassName, options, XtNumber(options),
_argc, _argv, NULL, XmNallowShellResize, true,
XmNtitle, name, XmNiconName, name, NULL);
topLevel = _w;
display = XtDisplay(_w);
root = RootWindowOfScreen(XtScreen(_w));
white = WhitePixelOfScreen(XtScreen(_w));
black = BlackPixelOfScreen(XtScreen(_w));
depth = DefaultDepthOfScreen(XtScreen(_w));
int numMouseButtons = XGetPointerMapping(display, (unsigned char *)NULL, 0);
bMenuButton = (numMouseButtons < 3) ? Button2 : Button3;
ApplicationArgs application_args;
XtGetApplicationResources(_w, &application_args, resources,
XtNumber(resources), NULL, 0);
userFont = application_args.user_font;
userFont = application_args.system_font;
session_info = NULL;
attributes = NULL;
values = NULL;
n_attrs = 0;
session_path = NULL;
fp = NULL;
if (session_file = application_args.session_file)
{
if (*session_file == '/')
session_path = strdup(session_file);
else
DtSessionRestorePath(topLevel, &session_path, session_file);
}
shadowThickness = application_args.shadow_thickness;
{
XmFontContext context;
if (XmFontListInitFontContext(&context, userFont))
{
XmFontListEntry entry = XmFontListNextEntry(context);
if (entry)
{
XmFontType _type_return;
fs = (XFontStruct *)XmFontListEntryGetFont(entry, &_type_return);
if (_type_return != XmFONT_IS_FONT)
XmeRenderTableGetDefaultFont(userFont, &fs);
font = fs->fid;
}
XmFontListFreeFontContext(context);
}
}
argc = *_argc;
argv = _argv;
InstallDestroyCB();
// If the user specified -display on the command line, we need
// to set the environment variable DISPLAY to this value so that
// any aixterms or X applications launched from this program
// go to the same display
new_display = new char [strlen("DISPLAY=") +
strlen(DisplayString(display)) + 1];
sprintf(new_display, "DISPLAY=%s", DisplayString(display));
putenv(new_display);
// Make the environment variable ENV set to nothing. This is so that
// we don't run the user's ENV every time we open a child process.
putenv("ENV=");
#ifndef NO_CDE
if (!DtAppInitialize(appContext, display, topLevel, argv[0], appClassName))
{
// Fatal Error: could not connect to the messaging system.
// DtAppInitialize() has already logged an appropriate error msg
exit(-1);
}
// Load the filetype/action dbs; DtInvokeAction() requires this
DtDbLoad();
#endif
Atom xa_WM_SAVE_YOURSELF = XInternAtom(display, "WM_SAVE_YOURSELF", False);
XmAddWMProtocols(topLevel, &xa_WM_SAVE_YOURSELF, 1);
XmAddWMProtocolCallback(topLevel, xa_WM_SAVE_YOURSELF, SaveSessionCB,
(XtPointer)this);
XmAddWMProtocolCallback(topLevel,
XmInternAtom(display, "WM_DELETE_WINDOW", False),
CloseCB, (XtPointer)this);
}
Application::~Application()
{
if (userFont)
XmFontListFree(userFont);
delete session_info;
delete attributes;
delete values;
delete new_display;
}
boolean Application::SetName(char *name)
{
if (!_w)
return false;
XtVaSetValues(_w, XmNtitle, name, XmNiconName, name, NULL);
return true;
}
boolean Application::SetVisiblity(boolean flag)
{
if (!_w)
return false;
if (flag)
{
XtRealizeWidget(_w);
XtVaSetValues(_w, XmNallowShellResize, False, NULL);
}
return true;
}
void Application::Run()
{
XtAppMainLoop(appContext);
}
void Application::SaveSessionCB(Widget, XtPointer client_data, XtPointer)
{
Application *obj = (Application *)client_data;
obj->SaveMe(true);
}
void Application::CloseCB(Widget, XtPointer client_data, XtPointer)
{
Application *obj = (Application *)client_data;
obj->SaveMe();
}
void Application::SaveMe(boolean save_as_session)
{
char *path = NULL, *name = NULL;
if (save_as_session)
DtSessionSavePath(topLevel, &path, &name);
else
{
name = SessionFile();
char *path1 = SessionPath();
path = new char[strlen(path1) + strlen(name) + 2];
sprintf(path, "%s/%s", path1, name);
name = NULL;
}
if (path && (fp = fopen(path, "w")))
{
SaveYourSelf();
fflush(fp);
fclose(fp);
fp = NULL;
}
if (save_as_session)
{
char **new_argv = NULL;
char **_argv;
int _argc;
XtVaGetValues(topLevel, XmNargc, &_argc, XmNargv, &_argv, NULL);
int i;
if (path && name)
{
if (_argc > 2 && !STRCMP(SESSION_FLAG, _argv[1]))
{
new_argv = new char *[_argc + 1];
for (i = 0; i < _argc; i++)
new_argv[i] = _argv[i];
new_argv[2] = name;
new_argv[i] = NULL;
}
else
{
int j;
new_argv = new char *[_argc + 3];
new_argv[0] = _argv[0];
new_argv[1] = (char *)SESSION_FLAG;
new_argv[2] = name;
for (i = 1, j = 3; i < _argc; i++, j++)
new_argv[j] = _argv[i];
new_argv[j] = NULL;
_argc += 2;
}
}
else
{
new_argv = new char *[_argc + 1];
for (i = 0; i < _argc; i++)
new_argv[i] = _argv[i];
new_argv[i] = NULL;
}
XSetCommand(display, XtWindow(topLevel), new_argv, _argc);
delete [] new_argv;
}
if (path)
XtFree(path);
if (name)
XtFree(name);
}
void Application::Save(char *attribute, char *value)
{
if (fp)
fprintf(fp, "%s\n%s\n", attribute, value);
}
char *Application::Restore(char *attribute)
{
char *value = NULL;
if (!session_info)
{
if (!session_path)
{
char *name = SessionFile();
char *path = SessionPath();
session_path = new char[strlen(path) + strlen(name) + 2];
sprintf(session_path, "%s/%s", path, name);
session_file = strdup(session_path);
}
struct stat statbuff;
if (stat(session_path, &statbuff) != -1)
{
FILE *fp1;
if (fp1 = fopen(session_path, "r"))
{
session_info = new char[statbuff.st_size + 1];
fread(session_info, (unsigned int)statbuff.st_size, 1, fp1);
fclose(fp1);
session_info[statbuff.st_size] = '\0';
char *s, *s1 = session_info;
s = s1;
while (s && (s = strchr(s1, '\n')))
{
n_attrs++;
s1 = s + 1;
}
n_attrs /= 2;
attributes = new char*[n_attrs];
values = new char*[n_attrs];
s = strtok(session_info, "\n");
int i = 0;
while (s && *s)
{
attributes[i] = s;
values[i] = strtok(NULL, "\n");
s = strtok(NULL, "\n");
i++;
}
}
}
if (!session_info)
session_info = strdup("");
}
int i;
for (i = 0; i < n_attrs; i++)
if (!STRCMP(attributes[i], attribute))
{
value = values[i];
break;
}
return value;
}

View File

@@ -0,0 +1,62 @@
/* $XConsortium: Application.h /main/3 1995/11/06 09:38:56 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef APPLICATION_H
#define APPLICATION_H
#include "MotifUI.h"
#include <stdio.h>
class Application : public MotifUI {
friend int main(int, char **);
friend void SaveSessionCB(Widget, XtPointer, XtPointer);
friend void CloseCB(Widget, XtPointer, XtPointer);
protected:
static void SaveSessionCB(Widget, XtPointer, XtPointer);
static void CloseCB(Widget, XtPointer, XtPointer);
XFontStruct *fs;
FILE *fp;
char **attributes;
char **values;
int n_attrs;
char *session_info;
char *session_file;
char *session_path;
char *new_display;
virtual void Run();
public:
int argc;
char **argv;
Application(char *name,
char *className,
int *argc,
char **argv);
virtual ~Application();
boolean SetVisiblity(boolean);
boolean SetName(char *);
virtual void SaveYourSelf() { }
virtual char *SessionFile() { return NULL; }
virtual char *SessionPath() { return NULL; }
void Save(char *attribute, char *value);
char *Restore(char *attribute);
void SaveMe(boolean save_as_session = false);
const UI_Class UIClass() { return APPLICATION; }
const char *const UIClassName() { return "Application"; }
};
#endif /* APPLICATION_H */

View File

@@ -0,0 +1,164 @@
/* $TOG: Button.C /main/3 1998/07/24 16:14:59 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Button.h"
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <Xm/ArrowB.h>
#include "WorkArea.h"
Button::Button(MotifUI *parent, char *name, ButtonType button_type,
ButtonCallback callback, void * callback_data,
char *mnemonic, char *acceleratorText,
char *accelerator, char *iconFile)
: MotifUI(parent, name, NULL)
{
CreateButton(parent, name, NULL, button_type, callback, callback_data,
mnemonic, acceleratorText, accelerator, iconFile);
}
Button::Button(char *category, MotifUI *parent, char *name,
ButtonType button_type, ButtonCallback callback,
void * callback_data, char *mnemonic, char *acceleratorText,
char *accelerator, char *iconFile)
: MotifUI(parent, name, category)
{
CreateButton(parent, name, category, button_type, callback, callback_data,
mnemonic, acceleratorText, accelerator, iconFile);
}
Button::~Button()
{
delete _iconFile;
}
void Button::IconFile(char *iconFile)
{
delete _iconFile;
_iconFile = STRDUP(iconFile);
if (_iconFile)
{
Pixmap pixmap;
char *s = new char[strlen(iconFile) + 6];
if (depth == 1)
{
Pixel bg;
XtVaGetValues(_w, XmNbackground, &bg, NULL);
if (bg == black)
sprintf(s, "%s.m.pm", iconFile);
else
sprintf(s, "%s.m.bm", iconFile);
}
else
sprintf(s, "%s.m.pm", iconFile);
GetPixmaps(_w, s, &pixmap);
delete [] s;
XtVaSetValues(_w, XmNlabelType, XmPIXMAP, XmNlabelPixmap, pixmap, NULL);
}
else
XtVaSetValues(_w, XmNlabelType, XmSTRING, NULL);
}
void Button::CreateButton(MotifUI *parent, char *name, char * /*category*/,
ButtonType button_type, ButtonCallback callback,
void * callback_data, char *mnemonic,
char *acceleratorText, char *accelerator, char *iconFile)
{
int IsArrow = false;
XmString xm_string = StringCreate(name);
Widget parentW;
Widget super_node = NULL;
_iconFile = NULL;
_button_type = button_type;
if (parent->UIClass() == DIALOG)
parentW = parent->BaseWidget();
else if (parent->UIClass() == ICON)
{
parentW = XtParent(parent->InnerWidget());
super_node = parent->InnerWidget();
}
else
parentW = parent->InnerWidget();
if (button_type == PUSH_BUTTON)
_w = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, parentW,
XmNlabelString, xm_string,
XmNaccelerator, accelerator,
XmNmultiClick, XmMULTICLICK_DISCARD,
GuiNsuperNode, super_node, NULL);
else if (button_type == TOGGLE_BUTTON)
_w = XtVaCreateManagedWidget("toggle", xmToggleButtonWidgetClass, parentW,
XmNlabelString, xm_string,
XmNaccelerator, accelerator,
XmNmultiClick, XmMULTICLICK_DISCARD,
GuiNsuperNode, super_node, NULL);
else
{
int dir;
switch (button_type)
{
case UP_ARROW_BUTTON: dir = XmARROW_UP;
case DOWN_ARROW_BUTTON: dir = XmARROW_DOWN;
case LEFT_ARROW_BUTTON: dir = XmARROW_LEFT;
case RIGHT_ARROW_BUTTON: dir = XmARROW_RIGHT;
}
_w = XtVaCreateManagedWidget("arrow", xmArrowButtonWidgetClass, parentW,
XmNmultiClick, XmMULTICLICK_DISCARD,
XmNarrowDirection, dir, NULL);
IsArrow = true;
}
StringFree(xm_string);
if (!IsArrow)
{
if (mnemonic)
XtVaSetValues(_w, XmNmnemonic, XStringToKeysym(mnemonic), NULL);
if (acceleratorText)
{
xm_string = StringCreate(acceleratorText);
XtVaSetValues(_w, XmNacceleratorText, xm_string, NULL);
StringFree(xm_string);
}
}
_callback = callback;
_callback_data = callback_data;
if (button_type == TOGGLE_BUTTON)
XtAddCallback(_w, XmNvalueChangedCallback, &Button::ActivateCB,
(XtPointer) this);
else
XtAddCallback(_w, XmNactivateCallback, &Button::ActivateCB,
(XtPointer) this);
InstallHelpCB();
IconFile(iconFile);
}
void Button::ActivateCB(Widget w,
XtPointer client_data,
XtPointer)
{
Button *obj = (Button *) client_data;
ButtonCallback callback;
if (XmIsToggleButton(w))
{
if (obj->Selected())
obj->Selected(false);
else
obj->Selected(true);
}
if ((callback = obj->_callback))
{
if (obj->_callback_data)
(*callback)(obj->_callback_data);
else
(*callback)(obj);
}
}

View File

@@ -0,0 +1,64 @@
/* $XConsortium: Button.h /main/3 1995/11/06 09:39:10 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef BUTTON_H
#define BUTTON_H
#include "MotifUI.h"
class Button : public MotifUI {
private:
ButtonCallback _callback;
void * _callback_data;
static void ActivateCB(Widget, XtPointer, XtPointer);
ButtonType _button_type;
char *_iconFile;
void CreateButton(MotifUI *, char *, char *, ButtonType, ButtonCallback,
void *, char *, char *, char *, char *);
public:
// If the callback_data is NULL, the this pointer will be the callback data
Button(MotifUI *parent,
char *name,
ButtonType button_type = PUSH_BUTTON,
ButtonCallback callback = NULL,
void * callback_data = NULL,
char *mnemonic = NULL,
char *acceleratorText = NULL,
char *accelerator = NULL,
char *iconFile = NULL);
Button(char *category,
MotifUI *parent,
char *name,
ButtonType button_type = PUSH_BUTTON,
ButtonCallback callback = NULL,
void * callback_data = NULL,
char *mnemonic = NULL,
char *acceleratorText = NULL,
char *accelerator = NULL,
char *iconFile = NULL);
~Button();
void Callback(ButtonCallback cb) { _callback = cb; }
void CallbackData(void *data) { _callback_data = data; }
ButtonCallback Callback() { return _callback; }
void * CallbackData() { return _callback_data; }
const char *IconFile() { return _iconFile; }
void IconFile(char *);
const UI_Class UIClass() { return BUTTON; }
const int UISubClass() { return _button_type; }
const char *const UIClassName() { return "Button"; }
};
#endif /* BUTTON_H */

View File

@@ -0,0 +1,138 @@
/* $XConsortium: ComboBoxObj.C /main/4 1995/11/06 09:39:21 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "ComboBoxObj.h"
#include <Xm/Label.h>
#include <Xm/Form.h>
#include <Xm/List.h>
#include <Xm/ComboBox.h>
ComboBoxObj::ComboBoxObj(MotifUI *parent,
#if defined(USL) || defined(__uxp__)
void (*callback)(ComboBoxObj *, char *, int),
#else
ComboBoxCallback callback,
#endif
char *name,
char **items,
int n_items)
: MotifUI(parent, name, NULL)
{
XmString *items_list;
int itemCount;
if (items && n_items)
{
items_list = new XmString [n_items];
int i;
if (n_items > 8)
itemCount = 8;
else
itemCount = n_items;
for (i = 0; i < n_items; i++)
items_list[i] = StringCreate(items[i]);
}
else
items_list = NULL;
_callback = callback;
if (name)
{
XmString xm_string = StringCreate(name);
_w = XtVaCreateManagedWidget("form", xmFormWidgetClass,
parent->InnerWidget(), NULL);
_label = XtVaCreateManagedWidget("form", xmLabelWidgetClass,
_w, XmNlabelString, xm_string,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM, NULL);
_combo_box = XtVaCreateManagedWidget("combo_box", xmComboBoxWidgetClass,
_w, XmNleftWidget, _label,
XmNleftAttachment, XmATTACH_WIDGET,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNcomboBoxType, XmDROP_DOWN_LIST,
(items_list ? XmNitems : NULL),
items_list,
XmNitemCount, n_items,
XmNvisibleItemCount, itemCount,
NULL);
StringFree(xm_string);
}
else
{
_w = XtVaCreateManagedWidget("combo_box", xmComboBoxWidgetClass,
parent->InnerWidget(),
XmNcomboBoxType, XmDROP_DOWN_LIST,
(items_list ? XmNitems : NULL), items_list,
XmNitemCount, n_items,
XmNvisibleItemCount, itemCount, NULL);
_label = NULL;
_combo_box = _w;
}
_list = XtNameToWidget(_combo_box, "*List");
XtAddCallback(_combo_box, XmNselectionCallback, &ComboBoxObj::SelectCB,
(XtPointer)this);
if (items_list)
{
int i;
for (i = 0; i < n_items; i++)
StringFree(items_list[i]);
delete items_list;
}
}
char * ComboBoxObj::Item(int item)
{
XmString *items;
int n_items;
XtVaGetValues(_list, XmNitems, &items, XmNitemCount, &n_items, NULL);
if (item < 0 || item > n_items - 1)
return NULL;
else
return StringExtract(items[item + 1]);
}
char * ComboBoxObj::Item(char *item)
{
XmString value = StringCreate(item);
int n = XmListItemExists(_list, value);
StringFree(value);
if (n)
return item;
else
return NULL;
}
void ComboBoxObj::Add(char *item)
{
XmString value = StringCreate(item);
XmComboBoxAddItem(_combo_box, value, 0, True);
StringFree(value);
}
void ComboBoxObj::Delete(char *item)
{
XmString value = StringCreate(item);
int n = XmListItemPos(_list, value);
if (n)
XmComboBoxDeletePos(_combo_box, n);
StringFree(value);
}
void ComboBoxObj::SelectCB(Widget, XtPointer client_data, XtPointer call_data)
{
ComboBoxObj *obj = (ComboBoxObj *) client_data;
XmComboBoxCallbackStruct * cb = (XmComboBoxCallbackStruct *)call_data;
if (obj->_callback)
{
char *item = obj->StringExtract(cb->item_or_text);
(*obj->_callback)(obj, item, cb->item_position);
XtFree(item);
}
}

View File

@@ -0,0 +1,52 @@
/* $XConsortium: ComboBoxObj.h /main/3 1995/11/06 09:39:32 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef COMBOBOXOBJ_H
#define COMBOBOXOBJ_H
#include "MotifUI.h"
class ComboBoxObj;
typedef void (*ComboBoxCallback) (ComboBoxObj *, char *item, int item_position);
class ComboBoxObj : public MotifUI {
friend void SelectCB(Widget, XtPointer, XtPointer);
private:
static void SelectCB(Widget, XtPointer, XtPointer);
Widget _label;
Widget _list;
Widget _combo_box;
ComboBoxCallback _callback;
public:
#if defined(USL) || defined(__uxp__)
ComboBoxObj(MotifUI * parent, void (*)(ComboBoxObj *, char *, int),
char *name, char **items, int n_items);
#else
ComboBoxObj(MotifUI * parent, ComboBoxCallback, char *name,
char **items, int n_items);
#endif
void Add(char *item);
void Delete(char *item);
char * Item(char *item);
char * Item(int index);
const Widget InnerWidget() { return _combo_box; }
const UI_Class UIClass() { return COMBO_BOX; }
const char *const UIClassName() { return "ComboBox"; }
};
#endif /* COMBOBOXOBJ_H */

View File

@@ -0,0 +1,545 @@
/* $XConsortium: Container.C /main/2 1995/07/17 14:05:19 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Container.h"
#include "IconObj.h"
#include <Xm/Xm.h>
#include <Xm/DropSMgr.h>
#include "Icon.h"
#include "WorkArea.h"
#include <Xm/ScrolledW.h>
#include <Xm/PanedW.h>
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/DrawingA.h>
#include <stdio.h>
Container::Container(MotifUI *parent,
char *name,
ContainerType container_type,
SelectionType select_type)
: MotifUI(parent, name, NULL)
{
CreateContainer(parent, name, NULL, container_type, select_type);
}
Container::Container(char *category,
MotifUI *parent,
char *name,
ContainerType container_type,
SelectionType select_type)
: MotifUI(parent, name, category)
{
CreateContainer(parent, name, category, container_type, select_type);
}
static XtTranslations trans_tbl = NULL;
static XtActionsRec action_table[] = {{"ResizeRC", NULL}};
void Container::CreateContainer(MotifUI *parent, char * /*name*/,
char * /*category*/,
ContainerType container_type,
SelectionType select_type)
{
Arg args[15];
int n;
Pixel pixel;
Widget parentW;
Widget superNode;
int radio_behavior = false;
int _shadowThickness;
if (!trans_tbl)
{
action_table[0].proc = (XtActionProc) ResizeRC;
trans_tbl = XtParseTranslationTable("<Configure>:ResizeRC()");
XtAppAddActions(appContext, action_table, XtNumber(action_table));
}
_xm_update_message = NULL;
_select_type = select_type;
_last_selected = NULL;
parentW = parent->InnerWidget();
if (GuiIsIcon(parentW))
superNode = parentW;
else
superNode = NULL;
if (!XtIsComposite(parentW))
parentW = XtParent(parentW);
if (select_type == SINGLE_SELECT)
radio_behavior = true;
switch (_container_type = container_type)
{
case FORM:
_w = XtVaCreateManagedWidget("form", xmFormWidgetClass,
parentW, NULL);
_workArea = _w;
break;
case SCROLLED_FORM:
_w = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass,
parentW, NULL);
_workArea = XtVaCreateManagedWidget("form", xmFormWidgetClass,
_w, NULL);
break;
case CANVAS:
_w = XtVaCreateManagedWidget("canvas", xmDrawingAreaWidgetClass,
parentW, NULL);
_workArea = _w;
break;
case SCROLLED_CANVAS:
_w = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass,
parentW, NULL);
_workArea = XtVaCreateManagedWidget("canvas", xmDrawingAreaWidgetClass,
_w, NULL);
break;
case HORIZONTAL_ROW_COLUMN:
_w = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, parentW,
XmNorientation, XmHORIZONTAL,
XmNradioBehavior, radio_behavior, NULL);
_workArea = _w;
break;
case SCROLLED_HORIZONTAL_ROW_COLUMN:
_w = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass, parentW,
GuiNisOpened, false, GuiNisWorkArea, true,
GuiNsuperNode, superNode, XmNspacing, 0,
XmNscrollBarDisplayPolicy, XmAS_NEEDED,
XmNscrollingPolicy, XmAUTOMATIC,
XmNheight, Parent()->Height(), NULL);
XtAddCallback(_w, XmNtraverseObscuredCallback, MakeChildVisible, NULL);
_workArea = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, _w,
XmNorientation, XmHORIZONTAL,
XmNradioBehavior, radio_behavior,
XmNpacking, XmPACK_TIGHT,
XmNadjustLast, False,
XmNuserData, this, NULL);
XtAddCallback(XtParent(_workArea), XmNresizeCallback,
ResizeSW, (XtPointer) this);
XtOverrideTranslations(_workArea, trans_tbl);
break;
case VERTICAL_ROW_COLUMN:
_w = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, parentW,
XmNradioBehavior, radio_behavior, NULL);
_workArea = _w;
break;
case SCROLLED_VERTICAL_ROW_COLUMN:
_w = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass, parentW,
GuiNisOpened, false, GuiNisWorkArea, true,
GuiNsuperNode, superNode, XmNspacing, 0,
XmNradioBehavior, radio_behavior,
XmNscrollBarDisplayPolicy, XmAS_NEEDED,
XmNscrollingPolicy, XmAUTOMATIC, NULL);
_workArea = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, _w,
XmNradioBehavior, radio_behavior,
NULL);
break;
case PANE:
_w = XtVaCreateManagedWidget("pane", xmPanedWindowWidgetClass,
parentW, NULL);
_workArea = _w;
break;
case SCROLLED_PANE:
_w = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass,
parentW, NULL);
_workArea = XtVaCreateManagedWidget("form", xmPanedWindowWidgetClass,
_w, NULL);
break;
case WORK_AREA:
_w = XtVaCreateManagedWidget("form", workAreaWidgetClass,
parentW, NULL);
_workArea = _w;
break;
case ICON_LIST:
_w = XtVaCreateManagedWidget("form", workAreaWidgetClass,
parentW, GuiNisList, True, NULL);
_workArea = _w;
break;
case SCROLLED_ICON_LIST:
case SCROLLED_WORK_AREA:
if (Parent()->UIClass() == DIALOG)
_shadowThickness = 0;
else
_shadowThickness = shadowThickness;
_w = XtVaCreateManagedWidget("form", xmFormWidgetClass,
parentW,
XmNshadowThickness, _shadowThickness,
XmNshadowType, XmSHADOW_OUT, NULL);
n = 0;
if (_container_type == SCROLLED_ICON_LIST)
{
XtSetArg(args[n], GuiNisList, True); n++;
}
else
{
XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
XtSetArg(args[n], XmNentryVerticalAlignment,
XmALIGNMENT_CONTENTS_BOTTOM);
n++;
}
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNtopOffset, 6); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftOffset, 6); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightOffset, 6); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomOffset, 6); n++;
XtSetArg(args[n], GuiNlineOffset, 20); n++;
XtSetArg(args[n], GuiNlineThickness, 2); n++;
XtSetArg(args[n], XmNuserData, this); n++;
_workArea = GuiCreateScrolledWorkArea(_w, "workArea", args, n);
XtManageChild(_workArea);
break;
}
if (_workArea == _w)
{
_clipWidget = _sw = _vbar = _hbar = NULL;
}
else
{
_clipWidget = XtParent(_workArea);
_sw = XtParent(_clipWidget);
XtVaGetValues(_sw, XmNverticalScrollBar, &_vbar,
XmNhorizontalScrollBar, &_hbar, NULL);
if (container_type == SCROLLED_HORIZONTAL_ROW_COLUMN)
XtUnmanageChild(_vbar);
if (depth > 1 &&
(container_type == SCROLLED_WORK_AREA ||
container_type == SCROLLED_ICON_LIST))
{
XtVaGetValues(_vbar, XmNtroughColor, &pixel, NULL);
XtVaSetValues(_workArea, XmNbackground, pixel, NULL);
XtVaSetValues(_clipWidget, XmNbackground, pixel, NULL);
}
}
InstallHelpCB();
InstallDestroyCB();
}
boolean Container::SetIcon(IconStyle)
{
if (_container_type == SCROLLED_HORIZONTAL_ROW_COLUMN)
XtAppAddTimeOut(appContext, 500, ResizeTimeOut, this);
return true;
}
void Container::DoBeginUpdate()
{
XtAddEventHandler(XtParent(_workArea), ExposureMask, FALSE,
&Container::UpdateAreaMessage, (XtPointer) this);
if (_container_type == SCROLLED_WORK_AREA ||
_container_type == WORK_AREA ||
_container_type == SCROLLED_ICON_LIST ||
_container_type == ICON_LIST)
{
if (XtIsRealized(_workArea))
XtUnmapWidget(_workArea);
GuiWorkAreaDisableRedisplay(_workArea);
XmDropSiteStartUpdate(XtParent(_workArea));
}
else
XtUnmanageChild(_workArea);
}
void Container::DoEndUpdate()
{
XtRemoveEventHandler(XtParent(_workArea), ExposureMask, FALSE,
&Container::UpdateAreaMessage, (XtPointer) this);
StringFree(_xm_update_message);
if (XtIsRealized(_workArea))
XClearArea(display, XtWindow(XtParent(_workArea)), 0, 0, 0, 0, TRUE);
_xm_update_message = NULL;
if (_container_type == SCROLLED_WORK_AREA ||
_container_type == WORK_AREA ||
_container_type == SCROLLED_ICON_LIST ||
_container_type == ICON_LIST)
{
if (XtIsRealized(_workArea))
XtMapWidget(_workArea);
GuiWorkAreaEnableRedisplay(_workArea);
XmDropSiteEndUpdate(XtParent(_workArea));
}
else
{
XtManageChild(_workArea);
if (_container_type == SCROLLED_HORIZONTAL_ROW_COLUMN)
XtAppAddTimeOut(appContext, 500, ResizeTimeOut, this);
}
}
void Container::DoUpdateMessage(char *message)
{
StringFree(_xm_update_message);
_xm_update_message = StringCreate(message);
if (XtIsRealized(_workArea))
XClearArea(display, XtWindow(XtParent(_workArea)), 0, 0, 0, 0, TRUE);
Refresh();
}
void Container::SelectionPolicy(SelectionType)
{
}
void Container::NotifyDelete(BaseUI *obj)
{
MotifUI::NotifyDelete(obj);
if (_last_selected == obj)
_last_selected = NULL;
if (_container_type == SCROLLED_HORIZONTAL_ROW_COLUMN)
XtAppAddTimeOut(appContext, 500, ResizeTimeOut, this);
}
void Container::NotifyVisiblity(BaseUI *obj)
{
if (_last_selected == obj)
_last_selected->Selected(false);
}
void Container::NotifySelected(BaseUI *obj)
{
switch (_select_type)
{
case SINGLE_SELECT:
if (_last_selected && _last_selected != obj)
{
if (obj->Selected())
_last_selected->Selected(false);
}
if (obj->Selected())
_last_selected = obj;
else
_last_selected = NULL;
break;
case MULTIPLE_SELECT:
break;
case EXTENDED_SELECT:
break;
case BROWSE_SELECT:
break;
}
}
// Open Animation stuff
static GC CreateGC(Widget w);
void Container::OpenAnimation(MotifUI *obj)
{
if (!_update || !_w || !XtIsRealized(_w))
return;
Dimension w, h, w2, h2;
int x0, y0, x1, y1, x2, y2, x_inc1, y_inc1, x_inc2, y_inc2, n;
Window window, area;
Widget widget;
GC gc;
if (_clipWidget)
widget = _clipWidget;
else
widget = _w;
XtVaGetValues(widget, XmNwidth, &w, XmNheight, &h, NULL);
XtVaGetValues(obj->BaseWidget(), XmNwidth, &w2, XmNheight, &h2, NULL);
area = XtWindow(widget);
x1 = (int)w2 / 2;
y1 = (int)h2 / 2;
XTranslateCoordinates(display, XtWindow(obj->BaseWidget()), area,
x1, y1, &x0, &y0, &window);
n = 8;
x_inc1 = -x0 / n;
if (x_inc1 == 0)
x_inc1 = -1;
y_inc1 = -y0 / n;
if (y_inc1 == 0)
y_inc1 = -1;
x_inc2 = (int)(w - x0) / n;
if (x_inc2 == 0)
x_inc2 = 1;
y_inc2 = (int)(h - y0) / n;
if (y_inc2 == 0)
y_inc2 = 1;
x1 = x0 + x_inc1;
y1 = y0 + y_inc1;
x2 = x0 + x_inc2;
y2 = y0 + y_inc2;
gc = CreateGC(widget);
while (--n)
{
XDrawRectangle(display, area, gc, x1, y1, x2 - x1, y2 - y1);
XFlush(display);
x1 += x_inc1;
y1 += y_inc1;
x2 += x_inc2;
y2 += y_inc2;
MicroSleep(OPEN_TIME);
}
n = 8;
x1 = x0 + x_inc1;
y1 = y0 + y_inc1;
x2 = x0 + x_inc2;
y2 = y0 + y_inc2;
while (--n)
{
XDrawRectangle(display, area, gc, x1, y1, x2 - x1, y2 - y1);
XFlush(display);
x1 += x_inc1;
y1 += y_inc1;
x2 += x_inc2;
y2 += y_inc2;
MicroSleep(OPEN_TIME);
}
XtReleaseGC(widget, gc);
}
static GC CreateGC(Widget w)
{
XGCValues values;
XtVaGetValues(w, XmNforeground, &values.foreground,
XmNbackground, &values.background, NULL);
// Set the fg to the XOR of the fg and bg, so if it is
// XOR'ed with bg, the result will be fg and vice-versa.
// This effectively achieves inverse video for the line.
values.foreground = values.foreground ^ values.background;
// Set the rubber band gc to use XOR mode and draw a dashed line.
values.function = GXxor;
values.subwindow_mode = IncludeInferiors;
return (XtGetGC(w, GCForeground | GCBackground |
GCSubwindowMode | GCFunction, &values));
}
void Container::UpdateAreaMessage(Widget widget, XtPointer client_data,
XEvent * /*event*/, Boolean * /*continued*/)
{
unsigned char direction;
XGCValues values;
XtGCMask valueMask;
Dimension width, height;
Dimension w, h;
int x, y;
static GC gc = (GC) NULL;
Container *container = (Container *) client_data;
if (!container->_xm_update_message)
return;
if (!gc)
{
XtVaGetValues(widget, XmNforeground, &values.foreground, NULL);
if (container->font)
valueMask = GCFont | GCForeground;
else
valueMask = GCForeground;
values.font = container->font;
gc = XCreateGC(display, root, valueMask, &values);
}
XClearArea(display, XtWindow(widget), 0, 0, 0, 0, FALSE);
XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL);
XtVaGetValues(container->_workArea, XmNstringDirection, &direction, NULL);
XmStringExtent(container->userFont, container->_xm_update_message, &w, &h);
x = (Dimension)(width - w) / 2;
y = (Dimension)(height - h) / 2;
XmStringDraw(display, XtWindow(widget), container->userFont,
container->_xm_update_message,
gc, x, y, w, XmALIGNMENT_CENTER, direction, NULL);
}
void Container::MakeChildVisible(Widget widget, XtPointer, XtPointer call_data)
{
XmTraverseObscuredCallbackStruct *cb;
Widget w;
cb = (XmTraverseObscuredCallbackStruct *) call_data;
w = cb->traversal_destination;
XmScrollVisible(widget, w, 0, 0);
}
void Container::ResizeTimeOut(void *data, XtIntervalId * /*id*/)
{
Container *obj = (Container *)data;
int h4 = obj->Parent()->Height();
Dimension h1, h2, h3;
if (obj->NumChildren())
{
Dimension max_height;
MotifUI **children = (MotifUI **)obj->Children();
int i;
XtWidgetGeometry preferred;
max_height = 0;
for (i = 0; i < obj->NumChildren(); i++)
{
if (XtIsManaged(children[i]->BaseWidget()))
{
XtQueryGeometry(children[i]->BaseWidget(), NULL, &preferred);
if ((h1 = preferred.height) > max_height)
{
max_height = h1;
break;
}
}
}
Position y;
if (max_height)
XtVaGetValues(children[0]->BaseWidget(), XmNy, &y, NULL);
else
y = 0;
h1 = max_height + (2 * y);
}
else
XtVaGetValues(obj->_workArea, XmNheight, &h1, NULL);
XtVaGetValues(obj->_clipWidget, XmNheight, &h2, NULL);
XtVaGetValues(obj->_w, XmNheight, &h3, NULL);
h3 = h3 - h2 + h1;
if (h2 != h1)
{
if (h4 > (int)h3)
h3 = h4;
else if (obj->NumChildren() == 0)
return;
h4 = h3;
}
else if (h4 <= (int)h3)
return;
XtVaSetValues(obj->_w, XmNheight, h4, NULL);
obj->Refresh();
XtVaGetValues(obj->_w, XmNheight, &h3, NULL);
if (h3 != h4)
XtAppAddTimeOut(obj->appContext, 500, ResizeTimeOut, obj);
}
void Container::ResizeSW(Widget w, XtPointer client_data, XtPointer)
{
// Don't calculate resize here, since the scroll bar hasn't been
// updated. Instead, add a sufficient timeout to calculate the resize
// after the scroll bar has updated it's XmNvalue resource
XtAppAddTimeOut(XtWidgetToApplicationContext(w),
500, ResizeTimeOut, client_data);
}
void Container::ResizeRC(Widget w, XEvent *, String *, int *)
{
Container *obj;
XtVaGetValues(w, XmNuserData, &obj, NULL);
XtAppAddTimeOut(obj->appContext, 500, ResizeTimeOut, obj);
}

View File

@@ -0,0 +1,78 @@
/* $XConsortium: Container.h /main/3 1995/11/06 09:39:43 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef CONTAINER_H
#define CONTAINER_H
#include "MotifUI.h"
const long OPEN_TIME = 40000L;
class Container : public MotifUI {
friend void UpdateAreaMessage(Widget, XtPointer, XEvent *, Boolean *);
friend void MakeChildVisible(Widget, XtPointer, XtPointer);
friend void ResizeTimeOut(void *, XtIntervalId *id);
friend void ResizeSW(Widget, XtPointer, XtPointer);
friend void ResizeRC(Widget, XEvent *, String *, int *);
static void UpdateAreaMessage(Widget, XtPointer, XEvent *, Boolean *);
static void MakeChildVisible(Widget, XtPointer, XtPointer);
static void ResizeTimeOut(void *, XtIntervalId *id);
static void ResizeSW(Widget, XtPointer, XtPointer);
static void ResizeRC(Widget, XEvent *, String *, int *);
protected:
Widget _sw;
Widget _workArea;
Widget _clipWidget;
Widget _vbar;
Widget _hbar;
XmString _xm_update_message;
BaseUI *_last_selected;
IconStyle _style;
IconStyle _previous_style;
ContainerType _container_type;
SelectionType _select_type;
virtual boolean SetIcon(IconStyle);
void NotifySelected(BaseUI *);
void NotifyDelete(BaseUI *);
void NotifyVisiblity(BaseUI *);
void DoBeginUpdate();
void DoEndUpdate();
void DoUpdateMessage(char *);
void CreateContainer(MotifUI *,char *, char *, ContainerType, SelectionType);
public:
Container(MotifUI *parent,
char *name,
ContainerType container_type = SCROLLED_WORK_AREA,
SelectionType select_type = SINGLE_SELECT);
Container(char *category,
MotifUI *parent,
char *name,
ContainerType container_type = SCROLLED_WORK_AREA,
SelectionType select_type = SINGLE_SELECT);
void OpenAnimation(MotifUI *obj);
void SelectionPolicy(SelectionType);
const SelectionType SelectionPolicy() { return _select_type; }
const Widget InnerWidget() { return _workArea; }
const UI_Class UIClass() { return CONTAINER; }
const int UISubClass() { return _container_type; }
const char *const UIClassName() { return "Container"; }
};
#endif /* CONTAINER_H */

View File

@@ -0,0 +1,240 @@
/* $TOG: Debug.c /main/5 1998/04/06 13:32:19 mgreess $ */
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <X11/Intrinsic.h>
#include <X11/Xlibint.h>
#define INT_MESSAGE3 "XIO: fatal IO error %d (%s) on X server \"%s\"\r\n"
#define INT_MESSAGE4 " after %lu requests (%lu known processed) with %d events remaining.\r\n"
#define INT_MESSAGE5 " The connection was probably broken by a server shudown or KillClient.\r\n"
static int PrintXError(Display *dpy, XErrorEvent *event, FILE *fp);
static char *SysErrorMsg(int n);
/* Error Handlers */
static int XIOError(Display *dpy);
static int XError(Display *dpy, XErrorEvent *event);
static void _XtError(String);
static Boolean G_DumpCore;
void
Debug(
XtAppContext app_context
)
{
XSetErrorHandler(XError);
XSetIOErrorHandler(XIOError);
XtAppSetErrorHandler(app_context, _XtError);
G_DumpCore = True;
}
/*
* NAME: XError
* FUNCTION:
* RETURNS:
*/
static int
XError(
Display *dpy,
XErrorEvent *event
)
{
if (PrintXError(dpy, event, stderr) == 0)
return 0;
if (G_DumpCore)
kill(getpid(), SIGQUIT);
else
exit(1);
}
/*
* NAME: XIOError
* FUNCTION:
* RETURNS:
*/
static int
XIOError(
Display *dpy
)
{
fprintf(stderr, INT_MESSAGE3,
errno, SysErrorMsg (errno), DisplayString (dpy));
fprintf(stderr, INT_MESSAGE4,
NextRequest(dpy) - 1, LastKnownRequestProcessed(dpy), QLength(dpy));
if (errno == EPIPE)
fprintf(stderr, INT_MESSAGE5);
if (G_DumpCore)
kill(getpid(), SIGQUIT);
else
exit(1);
}
/*
* NAME: SysErrorMsg
* FUNCTION:
* RETURNS:
*/
static char *
SysErrorMsg(
int n
)
{
#if !defined(linux)
extern char *sys_errlist[];
extern int sys_nerr;
#endif
char *s = ((n >= 0 && n < sys_nerr) ? sys_errlist[n] : "unknown error");
return (s ? s : "no such error");
}
/*
* NAME: PrintXError
* FUNCTION:
* RETURNS:
*/
static int
PrintXError(
Display *dpy,
XErrorEvent *event,
FILE *fp
)
{
char buffer[BUFSIZ];
char mesg[BUFSIZ];
char number[32];
char *mtype = "XlibMessage";
register _XExtension *ext = (_XExtension *)NULL;
_XExtension *bext = (_XExtension *)NULL;
XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
fprintf(fp, "%s: %s\n ", mesg, buffer);
XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
mesg, BUFSIZ);
fprintf(fp, mesg, event->request_code);
if (event->request_code < 128)
{
sprintf(number, "%d", event->request_code);
XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
}
else
{
for (ext = dpy->ext_procs;
ext && (ext->codes.major_opcode != event->request_code);
ext = ext->next)
;
if (ext)
strcpy(buffer, ext->name);
else
buffer[0] = '\0';
}
fprintf(fp, " (%s)\n", buffer);
if (event->request_code >= 128)
{
XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
mesg, BUFSIZ);
fputs(" ", fp);
fprintf(fp, mesg, event->minor_code);
if (ext)
{
sprintf(mesg, "%s.%d", ext->name, event->minor_code);
XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
fprintf(fp, " (%s)", buffer);
}
fputs("\n", fp);
}
if (event->error_code >= 128)
{
/* kludge, try to find the extension that caused it */
buffer[0] = '\0';
for (ext = dpy->ext_procs; ext; ext = ext->next)
{
if (ext->error_string)
(*ext->error_string)(dpy, event->error_code, &ext->codes,
buffer, BUFSIZ);
if (buffer[0])
{
bext = ext;
break;
}
if (ext->codes.first_error &&
ext->codes.first_error < (int)event->error_code &&
(!bext || ext->codes.first_error > bext->codes.first_error))
bext = ext;
}
if (bext)
sprintf(buffer, "%s.%d", bext->name,
event->error_code - bext->codes.first_error);
else
strcpy(buffer, "Value");
XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
if (mesg[0])
{
fputs(" ", fp);
fprintf(fp, mesg, event->resourceid);
fputs("\n", fp);
}
/* let extensions try to print the values */
for (ext = dpy->ext_procs; ext; ext = ext->next)
{
if (ext->error_values)
(*ext->error_values)(dpy, event, fp);
}
}
else if ((event->error_code == BadWindow) ||
(event->error_code == BadPixmap) ||
(event->error_code == BadCursor) ||
(event->error_code == BadFont) ||
(event->error_code == BadDrawable) ||
(event->error_code == BadColor) ||
(event->error_code == BadGC) ||
(event->error_code == BadIDChoice) ||
(event->error_code == BadValue) ||
(event->error_code == BadAtom))
{
if (event->error_code == BadValue)
XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%lx",
mesg, BUFSIZ);
else if (event->error_code == BadAtom)
XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%lx",
mesg, BUFSIZ);
else
XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%lx",
mesg, BUFSIZ);
fputs(" ", fp);
fprintf(fp, mesg, event->resourceid);
fputs("\n", fp);
}
XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%ld",
mesg, BUFSIZ);
fputs(" ", fp);
fprintf(fp, mesg, event->serial);
XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%ld",
mesg, BUFSIZ);
fputs("\n ", fp);
fprintf(fp, mesg, dpy->request);
fputs("\n", fp);
if (event->error_code == BadImplementation)
return 0;
return 1;
}
/*
* NAME: XtError
* FUNCTION:
* RETURNS:
*/
static void
_XtError(
String string
)
{
(void)fprintf(stderr, "XtToolkit Error: %s\n", string);
if (G_DumpCore)
kill(getpid(), SIGQUIT);
else
exit(1);
}

View File

@@ -0,0 +1,550 @@
/* $XConsortium: Dialog.C /main/3 1996/01/19 15:09:18 lehors $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Dialog.h"
#include "Prompt.h"
#include "Button.h"
#include <Xm/MessageB.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/FileSB.h>
#include <Xm/AtomMgr.h>
#include <Xm/Protocols.h>
#include <Xm/MwmUtil.h>
#include <Xm/BulletinBP.h>
// Constructor for a generic dialog
Dialog::Dialog(MotifUI *parent, char *title, DialogType dialog_type,
boolean has_resize_controls, DialogCallback help_callback,
void * help_callback_data, DialogCallback apply_callback,
void * apply_callback_data, DialogCallback reset_callback,
void * reset_callback_data, ValidationCallback CB,
void * validation_data)
: MotifUI(parent, title, NULL)
{
Arg args[10];
int n;
XmString xm_string = StringCreate(title);
_validation_callback = CB;
_validation_callback_data = validation_data;
_help_callback = help_callback;
_help_callback_data = help_callback_data;
_apply_callback = apply_callback;
_apply_callback_data = apply_callback_data;
_reset_callback = reset_callback;
_reset_callback_data = reset_callback_data;
_cancel_button = NULL;
_cancel_widget = NULL;
n = 0;
if (has_resize_controls == false)
{
long mwmDecorations;
mwmDecorations = (MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU);
XtSetArg(args[n], XmNmwmDecorations, mwmDecorations); n++;
}
XtSetArg(args[n], XmNdialogTitle, xm_string); n++;
XtSetArg(args[n], XmNmarginHeight, 5); n++;
XtSetArg(args[n], XmNmarginWidth, 5); n++;
XtSetArg(args[n], XmNallowShellResize, true); n++;
XtSetArg(args[n], XmNautoUnmanage, false); n++;
switch (_dialog_type = dialog_type)
{
default:
case MODELESS:
case INFORMATION:
case ERROR:
case WORK_IN_PROGRESS:
XtSetArg(args[n], XmNdialogStyle, XmDIALOG_MODELESS); n++;
_dialog_type = MODELESS;
break;
case MODAL:
case FILE_SELECTION:
case QUESTION:
case WARNING:
case PROMPT_DIALOG:
case MODAL_WORK_IN_PROGRESS:
case MODAL_ERROR:
case MODAL_INFORMATION:
XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
_dialog_type = MODAL;
break;
};
if (parent->UIClass() == APPLICATION)
{
XtSetArg(args[n], XmNdialogType, XmDIALOG_TEMPLATE); n++;
_w = XmCreateMessageBox(parent->InnerWidget(), title, args, n);
XtManageChild(_w);
}
else
_w = XmCreateTemplateDialog(parent->InnerWidget(), title, args, n);
_clientArea = XtVaCreateManagedWidget("form", xmFormWidgetClass, _w, NULL);
StringFree(xm_string);
XmAddWMProtocolCallback(XtParent(_w),
XmInternAtom(display, "WM_DELETE_WINDOW", False),
&Dialog::CloseCB, (XtPointer) this);
InstallHelpCB();
}
// Constructor for info, error, work-in-progress
Dialog::Dialog(MotifUI *parent, char *title, char *message,
DialogType dialog_type, char *ok_label, char *cancel_label,
char *help_label, DialogCallback help,
void * help_callback_data, char * /*icon*/)
: MotifUI(parent, title, NULL)
{
Arg args[15];
long mwmDecorations;
mwmDecorations = (MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU);
XmString xm_string = StringCreate(title);
XmString xm_message = StringCreate(message);
XmString ok_string = StringCreate(ok_label);
XmString cancel_string = StringCreate(cancel_label);
XmString help_string = StringCreate(help_label);
XtSetArg(args[0], XmNdialogTitle, xm_string);
XtSetArg(args[1], XmNmarginHeight, 5);
XtSetArg(args[2], XmNmarginWidth, 5);
XtSetArg(args[3], XmNallowShellResize, true);
XtSetArg(args[4], XmNautoUnmanage, false);
XtSetArg(args[5], XmNmessageString, xm_message);
XtSetArg(args[6], XmNmwmDecorations, mwmDecorations);
XtSetArg(args[7], XmNokLabelString, ok_string);
XtSetArg(args[8], XmNcancelLabelString, cancel_string);
XtSetArg(args[9], XmNhelpLabelString, help_string);
_help_callback = help;
_help_callback_data = help_callback_data;
_apply_callback = NULL;
_apply_callback_data = NULL;
_reset_callback = NULL;
_reset_callback_data = NULL;
switch (_dialog_type = dialog_type)
{
case INFORMATION:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_MODELESS);
_w = XmCreateInformationDialog(parent->InnerWidget(), title, args, 11);
break;
case QUESTION:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
_w = XmCreateQuestionDialog(parent->InnerWidget(), title, args, 11);
break;
case WARNING:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
_w = XmCreateWarningDialog(parent->InnerWidget(), title, args, 11);
break;
case ERROR:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_MODELESS);
_w = XmCreateErrorDialog(parent->InnerWidget(), title, args, 11);
break;
case WORK_IN_PROGRESS:
mwmDecorations = (MWM_DECOR_BORDER | MWM_DECOR_TITLE);
XtSetArg(args[6], XmNmwmDecorations, mwmDecorations);
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_MODELESS);
_w = XmCreateWorkingDialog(parent->InnerWidget(), title, args, 11);
break;
case MODAL_WORK_IN_PROGRESS:
mwmDecorations = (MWM_DECOR_BORDER | MWM_DECOR_TITLE);
XtSetArg(args[6], XmNmwmDecorations, mwmDecorations);
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
_w = XmCreateWorkingDialog(parent->InnerWidget(), title, args, 11);
break;
case MODAL_ERROR:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
_w = XmCreateErrorDialog(parent->InnerWidget(), title, args, 11);
break;
case MODAL_INFORMATION:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
_w = XmCreateInformationDialog(parent->InnerWidget(), title, args, 11);
break;
case MODAL:
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
_w = XmCreateMessageDialog(parent->InnerWidget(), title, args, 11);
break;
default:
_dialog_type = MODELESS;
XtSetArg(args[10], XmNdialogStyle, XmDIALOG_MODELESS);
_w = XmCreateMessageDialog(parent->InnerWidget(), title, args, 11);
break;
}
if (_dialog_type == QUESTION || _dialog_type == WARNING)
XtAddCallback(_w, XmNcancelCallback, &Dialog::DialogCB, (XtPointer) this);
else
XtUnmanageChild(XmMessageBoxGetChild(_w, XmDIALOG_CANCEL_BUTTON));
if (help)
XtAddCallback(_w, XmNhelpCallback, &Dialog::DialogCB, (XtPointer) this);
else
XtUnmanageChild(XmMessageBoxGetChild(_w, XmDIALOG_HELP_BUTTON));
if (_dialog_type == WORK_IN_PROGRESS ||
_dialog_type == MODAL_WORK_IN_PROGRESS)
XtUnmanageChild(XmMessageBoxGetChild(_w, XmDIALOG_OK_BUTTON));
else
XtAddCallback(_w, XmNokCallback, &Dialog::DialogCB, (XtPointer) this);
XmAddWMProtocolCallback(XtParent(_w),
XmInternAtom(display, "WM_DELETE_WINDOW", False),
&Dialog::CloseCB, (XtPointer) this);
InstallHelpCB();
StringFree(xm_string);
StringFree(xm_message);
StringFree(cancel_string);
StringFree(ok_string);
StringFree(help_string);
_clientArea = _w;
}
// Constructor for prompt
Dialog::Dialog(MotifUI *parent, char *title, char *caption, boolean editable,
PromptType prompt_type, char *default_value,
boolean echo_input, ValidationCallback validation_callback,
void * validation_callback_data, DialogCallback help_callback,
void * help_callback_data, DialogCallback apply_callback,
void * apply_callback_data, DialogCallback reset_callback,
void * reset_callback_data, char *message, char *icon)
: MotifUI(parent, title, NULL)
{
Arg args[8];
int n;
XmString xm_string = StringCreate(title);
XmString xm_message;
Pixmap pixmap;
_dialog_type = PROMPT_DIALOG;
_validation_callback = validation_callback;
_validation_callback_data = validation_callback_data;
_help_callback = help_callback;
_help_callback_data = help_callback_data;
_apply_callback = apply_callback;
_apply_callback_data = apply_callback_data;
_reset_callback = reset_callback;
_reset_callback_data = reset_callback_data;
n = 0;
XtSetArg(args[n], XmNdialogTitle, xm_string); n++;
XtSetArg(args[n], XmNmarginHeight, 5); n++;
XtSetArg(args[n], XmNmarginWidth, 5); n++;
XtSetArg(args[n], XmNallowShellResize, true); n++;
XtSetArg(args[n], XmNautoUnmanage, false); n++;
XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
if (message && *message)
{
xm_message = StringCreate(message);
XtSetArg(args[n], XmNmessageString, xm_message); n++;
if (icon && *icon)
{
pixmap = 0;
// XtSetArg(args[n], XmNsymbolPixmap, pixmap); n++;
}
}
_w = XmCreateMessageDialog(parent->InnerWidget(), title, args, n);
StringFree(xm_string);
if (xm_message && *message)
StringFree(xm_message);
if (help_callback)
{
XtAddCallback(_w, XmNhelpCallback, &Dialog::DialogCB, (XtPointer) this);
}
else
{
XtUnmanageChild(XmMessageBoxGetChild(_w, XmDIALOG_HELP_BUTTON));
}
_prompt = new Prompt(this, caption, editable, prompt_type, default_value,
validation_callback, validation_callback_data,
echo_input);
XmAddWMProtocolCallback(XtParent(_w),
XmInternAtom(display, "WM_DELETE_WINDOW", False),
&Dialog::CloseCB, (XtPointer) this);
InstallHelpCB();
}
// Constructor for file selection
Dialog::Dialog(MotifUI *parent, char *title, char *base_directory,
char *search_pattern, DialogType dialog_type,
DialogCallback help, void * /*help_callback_data*/)
: MotifUI(parent, title, NULL)
{
Arg args[9];
XmString title_string = StringCreate(title);
XmString directory_string = StringCreate(base_directory);
XmString pattern_string = StringCreate(search_pattern);
XtSetArg(args[0], XmNdialogTitle, title_string);
XtSetArg(args[1], XmNmarginHeight, 5);
XtSetArg(args[2], XmNmarginWidth, 5);
XtSetArg(args[3], XmNallowShellResize, true);
XtSetArg(args[4], XmNautoUnmanage, false);
XtSetArg(args[5], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
switch (_dialog_type = dialog_type)
{
default:
case FILE_SELECTION:
_dialog_type = FILE_SELECTION;
XtSetArg(args[6], XmNfileTypeMask, XmFILE_REGULAR);
break;
case DIRECTORY_SELECTION:
XtSetArg(args[6], XmNfileTypeMask, XmFILE_DIRECTORY);
break;
case FILE_DIRECTORY_SELECTION:
XtSetArg(args[6], XmNfileTypeMask, XmFILE_ANY_TYPE);
break;
}
XtSetArg(args[7], XmNdirectory, directory_string);
XtSetArg(args[8], XmNpattern, pattern_string);
_w = XmCreateFileSelectionDialog(parent->InnerWidget(), title, args, 9);
StringFree(title_string);
StringFree(directory_string);
StringFree(pattern_string);
if (help)
{
_help_callback_data = _help_callback_data;
XtAddCallback(_w, XmNhelpCallback, &Dialog::DialogCB, (XtPointer) this);
}
else
{
XtUnmanageChild(XmMessageBoxGetChild(_w, XmDIALOG_HELP_BUTTON));
}
XmAddWMProtocolCallback(XtParent(_w),
XmInternAtom(display, "WM_DELETE_WINDOW", False),
&Dialog::CloseCB, (XtPointer) this);
InstallHelpCB();
}
Dialog::~Dialog()
{
// Empty
}
void Dialog::DefaultButton(MotifUI *button)
{
XtVaSetValues(_w, XmNdefaultButton, button->BaseWidget(), NULL);
}
void Dialog::CancelButtonCB(Widget, XtPointer client_data, XtPointer)
{
Dialog *obj = (Dialog *)client_data;
if (obj->_cancel_button)
{
XtCallCallbacks(obj->_cancel_button->BaseWidget(), XmNactivateCallback,
obj->_cancel_button);
}
}
void Dialog::CancelButton(MotifUI *button)
{
if (!_cancel_widget)
{
_cancel_widget = XtVaCreateWidget("cancel_button",
xmPushButtonWidgetClass, _w, NULL);
XtAddCallback(_cancel_widget, XmNactivateCallback, CancelButtonCB, this);
BB_CancelButton(_w) = _cancel_widget;
}
_cancel_button = (Button *)button;
}
void Dialog::Width(int w)
{
XtVaSetValues(XtParent(_w), XmNallowShellResize, true, NULL);
MotifUI::Width(w);
XtVaSetValues(XtParent(_w), XmNallowShellResize, false, NULL);
}
void Dialog::Height(int w)
{
XtVaSetValues(XtParent(_w), XmNallowShellResize, true, NULL);
MotifUI::Height(w);
XtVaSetValues(XtParent(_w), XmNallowShellResize, false, NULL);
}
void Dialog::WidthHeight(int w, int h)
{
XtVaSetValues(XtParent(_w), XmNallowShellResize, true, NULL);
MotifUI::WidthHeight(w, h);
XtVaSetValues(XtParent(_w), XmNallowShellResize, false, NULL);
}
boolean Dialog::SetName(char *name)
{
XmString xm_message = StringCreate(name);
XtVaSetValues(_w, XmNmessageString, xm_message, NULL);
StringFree(xm_message);
return true;
}
boolean Dialog::SetVisiblity(boolean flag)
{
MotifUI::SetVisiblity(flag);
if (flag == false)
return true;
boolean is_modal;
switch (_dialog_type)
{
case MODELESS:
case INFORMATION:
case ERROR:
case WORK_IN_PROGRESS:
is_modal = false;
break;
default:
is_modal = true;
}
ToFront();
XtVaSetValues(XtParent(_w), XmNallowShellResize, False, NULL);
if (is_modal)
{
_status = -1;
while (_status == -1 || XtAppPending(appContext))
XtAppProcessEvent(appContext, XtIMAll);
if (_status)
_rc = true;
else
_rc = false;
}
return true;
}
const boolean Dialog::Answer(char **string)
{
if (_rc)
{
if (_dialog_type == PROMPT_DIALOG ||
_dialog_type == FILE_SELECTION ||
_dialog_type == DIRECTORY_SELECTION ||
_dialog_type == FILE_DIRECTORY_SELECTION)
{
*string = STRDUP(_string);
}
}
else
*string = NULL;
return _rc;
}
void Dialog::OK()
{
if (Apply() == true)
{
Visible(false);
_rc = true;
_status = 1;
}
if (_dialog_type != PROMPT_DIALOG &&
_dialog_type != QUESTION &&
_dialog_type != WARNING)
delete this;
}
void Dialog::Cancel()
{
Reset();
Visible(false);
_rc = false;
_status = 0;
if (_dialog_type != PROMPT_DIALOG &&
_dialog_type != QUESTION &&
_dialog_type != WARNING)
delete this;
}
boolean Dialog::Apply()
{
boolean rc = true;
if (_dialog_type == PROMPT_DIALOG)
{
_string = _prompt->Value();
if (_validation_callback)
rc = (*_validation_callback)(_validation_callback_data, _string);
else
rc = true;
if (rc == true)
{
if (_apply_callback)
(*_apply_callback)(_apply_callback_data);
_prompt->DefaultValue(_string);
}
}
return rc;
}
void Dialog::Reset()
{
if (_reset_callback)
(*_reset_callback)(_reset_callback_data);
if (_dialog_type == PROMPT_DIALOG)
_prompt->Reset();
}
void Dialog::Help()
{
if (_help_callback)
(*_help_callback)(_help_callback_data);
}
void Dialog::CloseCB()
{
Cancel();
}
void Dialog::CloseCB(Widget, XtPointer client_data, XtPointer /*call_data*/)
{
Dialog *dialog = (Dialog *) client_data;
dialog->CloseCB();
}
void Dialog::DialogCB(Widget, XtPointer client_data, XtPointer call_data)
{
XmFileSelectionBoxCallbackStruct *cb;
Dialog *dialog = (Dialog *) client_data;
cb = (XmFileSelectionBoxCallbackStruct *) call_data;
switch (cb->reason)
{
case XmCR_HELP: dialog->Help(); break;
case XmCR_OK:
if (dialog->_dialog_type == FILE_SELECTION ||
dialog->_dialog_type == DIRECTORY_SELECTION ||
dialog->_dialog_type == FILE_DIRECTORY_SELECTION)
dialog->_string = dialog->StringExtract(cb->value);
dialog->OK();
break;
case XmCR_CANCEL: dialog->Cancel(); break;
default: break;
}
}
void Dialog::ResetCB(void *data)
{
Dialog *dialog = (Dialog *) data;
dialog->Reset();
}
void Dialog::ApplyCB(void *data)
{
Dialog *dialog = (Dialog *) data;
dialog->Apply();
}

View File

@@ -0,0 +1,141 @@
/* $XConsortium: Dialog.h /main/3 1995/11/06 09:40:07 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DIALOG_H
#define DIALOG_H
#include "MotifUI.h"
class Button;
class Prompt;
class Dialog : public MotifUI {
friend void DialogCB(Widget, XtPointer, XtPointer);
friend void CloseCB(Widget, XtPointer, XtPointer);
friend void CancelButtonCB(Widget, XtPointer, XtPointer);
friend void ResetCB(void *);
friend void ApplyCB(void *);
private:
Widget _clientArea;
Widget _cancel_widget;
DialogType _dialog_type;
boolean _rc;
char *_string;
Prompt *_prompt;
Button *_reset_button;
Button *_apply_button;
Button *_cancel_button;
void * _cancel_callback_data;
void * _help_callback_data;
void * _reset_callback_data;
void * _apply_callback_data;
void * _validation_callback_data;
DialogCallback _cancel_callback;
DialogCallback _help_callback;
DialogCallback _reset_callback;
DialogCallback _apply_callback;
ValidationCallback _validation_callback;
static void DialogCB(Widget, XtPointer, XtPointer);
static void CloseCB(Widget, XtPointer, XtPointer);
static void CancelButtonCB(Widget, XtPointer, XtPointer);
static void ResetCB(void *);
static void ApplyCB(void *);
int _status;
void OK();
void Cancel();
void Reset();
boolean Apply();
void Help();
protected:
virtual boolean SetVisiblity(boolean);
boolean SetName(char *);
void Width(int w);
int Width() { return MotifUI::Width(); }
void Height(int h);
int Height() { return MotifUI::Height(); }
void WidthHeight(int w, int h);
void WidthHeight(int *w, int *h) { MotifUI::WidthHeight(w, h); }
const Widget InnerWidget() { return _clientArea; }
public:
// Constructor for a generic MODELESS or MODAL dialog
Dialog(MotifUI *parent,
char *name,
DialogType dialog_type = MODELESS,
boolean has_resize_controls = true,
DialogCallback cancel_callback = NULL,
void * help_callback_data = NULL,
DialogCallback apply_callback = NULL,
void * apply_callback_data = NULL,
DialogCallback reset_callback = NULL,
void * reset_callback_data = NULL,
ValidationCallback CB = NULL,
void * validation_data = NULL);
// Constructor for info, error, work-in-progress, question, warning
Dialog(MotifUI *parent,
char *title,
char *message,
DialogType dialog_type = INFORMATION,
char *ok_label = "OK",
char *cancel_label = "Cancel",
char *help_label = "Help",
DialogCallback helpCB = NULL, // If NULL, no help button is created
void *help_data = NULL,
char *icon = NULL); // If NULL, use default icon
// Constructor for prompt
Dialog(MotifUI *parent,
char *title,
char *caption, // This appears left of a input field
boolean editable,
PromptType prompt_type,
char *default_value, // If NULL, no reset button is created
boolean echo_input = true,
ValidationCallback CB = NULL,
void * validation_data = NULL,
DialogCallback helpCB = NULL, // If NULL, no help button is created
void * help_data = NULL,
DialogCallback applyCB = NULL,
void * apply_data = NULL,
DialogCallback resetCB = NULL,
void * reset_data = NULL,
char *message = NULL, // The message above the input field
char *icon = NULL); // If NULL, no icon will be shown
// Constructor for file and directory selection
Dialog(MotifUI *parent,
char *title,
char *base_directory,
char *search_pattern,
DialogType dialog_type = FILE_SELECTION,
DialogCallback help = NULL, // If NULL, no help button is created
void * help_data = NULL);
virtual ~Dialog();
virtual void CloseCB();
void DefaultButton(MotifUI *);
void CancelButton(MotifUI *);
const boolean Answer(char **string); // user must delete string
const boolean Answer() { return _rc; }
const UI_Class UIClass() { return DIALOG; }
const int UISubClass() { return _dialog_type; }
const char *const UIClassName() { return "Dialog"; }
};
#endif /* DIALOG_H */

View File

@@ -0,0 +1,717 @@
/* $TOG: DtDND.C /main/7 1998/08/03 08:58:53 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "stdlib.h"
#include "DtDND.h"
#include "IconObj.h"
#include "Icon.h"
#include "Dt/Dnd.h"
#include <Xm/DragCP.h>
#include <Dt/Wsm.h>
#include <Dt/Action.h>
#include <stdio.h>
extern "C" {
extern XtPointer _XmStringUngenerate (
XmString string,
XmStringTag tag,
XmTextType tag_type,
XmTextType output_type);
}
#define DRAG_THRESHOLD 10
// Absolute value macro
#ifndef ABS
#define ABS(x) (((x) > 0) ? (x) : (-(x)))
#endif
boolean DtDND::FirstTime = true;
XtCallbackRec DtDND::transferCBRec[] =
{
{&DtDND::TransferCB, NULL}, {NULL, NULL}
};
XtCallbackRec DtDND::convertCBRec[] =
{
{&DtDND::ConvertCB, NULL}, {NULL, NULL}
};
XtCallbackRec DtDND::dragFinishCBRec[] =
{
{&DtDND::DragFinishCB, NULL}, {NULL, NULL}
};
XtCallbackRec DtDND::dropOnRootCBRec[] =
{
{&DtDND::DropOnRootCB, NULL}, {NULL, NULL}
};
XtCallbackRec DtDND::animateCBRec[] =
{
{&DtDND::AnimateCB, NULL}, {NULL, NULL}
};
boolean DtDND::DoingDrag = false;
GC DtDND::gc;
GC DtDND::gc_mask;
DtDND::DtDND(MotifUI *_obj, DNDCallback _dndCB, boolean _can_drop_on_root)
{
if (FirstTime)
{
MotifUI *tmp = (MotifUI *)_obj;
Pixmap tmp_pixmap;
BaseUI *parent = _obj;
while (parent->Parent())
parent = parent->Parent();
tmp_pixmap = XCreatePixmap(tmp->display, tmp->root, 1, 1, tmp->depth);
gc = XCreateGC(tmp->display, tmp_pixmap, 0, NULL);
tmp_pixmap = XCreatePixmap(tmp->display, tmp->root, 1, 1, 1);
gc_mask = XCreateGC(tmp->display, tmp_pixmap, 0, NULL);
XSetFont(tmp->display, gc, tmp->font);
FirstTime = false;
}
obj = _obj;
can_drop_on_root = _can_drop_on_root;
dndCB = _dndCB;
dragIcon = NULL;
sourceIcon = NULL;
// Set up Drop
transferCBRec[0].closure = (XtPointer)this;
animateCBRec[0].closure = (XtPointer)this;
if (obj->UIClass() == ICON)
{
GetRects();
XtVaSetValues(obj->BaseWidget(), XmNshadowThickness, 2, NULL);
Arg args[6];
XtSetArg(args[0], XmNdropSiteType, XmDROP_SITE_SIMPLE);
XtSetArg(args[1], XmNanimationStyle, XmDRAG_UNDER_SHADOW_IN);
XtSetArg(args[2], XmNnumDropRectangles, 2);
XtSetArg(args[3], XmNdropRectangles, &rects);
XtSetArg(args[4], DtNdropAnimateCallback, animateCBRec);
XtSetArg(args[5], DtNtextIsBuffer, True);
DtDndDropRegister(obj->BaseWidget(), DtDND_FILENAME_TRANSFER|
DtDND_BUFFER_TRANSFER,
(unsigned char)XmDROP_COPY, transferCBRec, args, 6);
// Set up Drag on Button1
XtAddEventHandler(obj->BaseWidget(), Button1MotionMask, False,
(XtEventHandler)DragMotionHandler, (XtPointer)this);
// Set up Drag on Button2 if not using it for BMenu already
if (MotifUI::bMenuButton != Button2)
{
XtAddEventHandler(obj->BaseWidget(), Button2MotionMask, False,
(XtEventHandler)DragMotionHandler, (XtPointer)this);
}
}
else
{
Arg args[2];
XtSetArg(args[0], DtNdropAnimateCallback, animateCBRec);
XtSetArg(args[1], DtNtextIsBuffer, True);
DtDndDropRegister(obj->BaseWidget(), DtDND_FILENAME_TRANSFER|
DtDND_BUFFER_TRANSFER,
(unsigned char)XmDROP_COPY, transferCBRec, args, 2);
}
pixmap = 0L;
mask = 0L;
name = NULL;
iconFile = NULL;
string = NULL;
}
DtDND::~DtDND()
{
MotifUI *icon = (MotifUI *)obj;
if (pixmap && pixmap != XmUNSPECIFIED_PIXMAP)
XFreePixmap(icon->display, pixmap);
if (mask && mask != XmUNSPECIFIED_PIXMAP)
XFreePixmap(icon->display, mask);
free(name);
delete iconFile;
XmStringFree(string);
if (sourceIcon)
{
XtDestroyWidget(sourceIcon);
sourceIcon = NULL;
}
if (dragIcon)
{
XtDestroyWidget(dragIcon);
dragIcon = NULL;
}
}
void DtDND::GetDragPixmaps()
{
IconObj *icon = (IconObj *)obj;
Pixmap tmp_pixmap, tmp_mask;
delete iconFile;
free(name);
XmStringFree(string);
if (pixmap && pixmap != XmUNSPECIFIED_PIXMAP)
XFreePixmap(icon->display, pixmap);
if (mask && mask != XmUNSPECIFIED_PIXMAP)
XFreePixmap(icon->display, mask);
mask = 0L;
pixmap = 0L;
name = strdup(icon->Name());
icon_size = icon->IconView();
selected = icon->Selected();
iconFile = new char[strlen(icon->IconFile()) + 6];
Dimension height, width;
unsigned int w, h, junk;
XtVaGetValues(icon->BaseWidget(), XmNbackground, &bg, XmNforeground, &fg,
GuiNselectColor, &selectColor, XmNalignment, &alignment,
GuiNshowSelectedPixmap, &showSelectedPixmap,
XmNstringDirection, &stringDirection,
GuiNtextSelectColor, &textSelectColor,
XmNlabelString, &string, XmNfontList, &fontList, NULL);
XmStringExtent(fontList, string, &width, &height);
if (icon_size == LARGE_ICON)
string_border_width = 1;
else
string_border_width = 0;
height += 2 * string_border_width;
width += 2 * string_border_width;
s_x = s_y = string_border_width;
p_x = p_y = 0;
s_w = width;
s_h = height;
p_w = p_h = 0;
switch (icon_size)
{
case DETAILS:
case SMALL_ICON:
sprintf(iconFile, "%s.t.pm", icon->IconFile());
icon->GetPixmaps(icon->BaseWidget(), iconFile, &tmp_pixmap, &tmp_mask);
if (tmp_pixmap && tmp_pixmap != XmUNSPECIFIED_PIXMAP)
{
XGetGeometry(icon->display, tmp_pixmap, (Window *) &junk,
(int *) &junk, (int *) &junk, &w, &h, &junk, &junk);
p_w = w;
p_h = h;
w += 2;
s_x += w;
width += w;
if (h > height)
{
s_y = (h - height) / 2;
height = h;
}
else
p_y = (height - h) / 2;
}
break;
case LARGE_ICON:
sprintf(iconFile, "%s.m.pm", icon->IconFile());
icon->GetPixmaps(icon->BaseWidget(), iconFile, &tmp_pixmap, &tmp_mask);
if (tmp_pixmap && tmp_pixmap != XmUNSPECIFIED_PIXMAP)
{
XGetGeometry(icon->display, tmp_pixmap, (Window *) &junk,
(int *) &junk, (int *) &junk, &w, &h, &junk, &junk);
p_w = w;
p_h = h;
h += 2;
s_y += h;
height += h;
if (w > width)
width = w;
}
break;
default:
sprintf(iconFile, "%s.m.pm", icon->IconFile());
icon->GetPixmaps(icon->BaseWidget(), iconFile, &tmp_pixmap, &tmp_mask);
break;
}
// Create pixmap
pixmap = XCreatePixmap(icon->display, icon->root, width, height,
icon->depth);
if (icon_size != NAME_ONLY &&
tmp_pixmap && tmp_pixmap != XmUNSPECIFIED_PIXMAP)
{
mask = XCreatePixmap(icon->display, icon->root, width, height, 1);
// Clear mask
XSetForeground(icon->display, gc_mask, 0);
XFillRectangle(icon->display, mask, gc_mask, 0, 0, width, height);
// Set Mask Bits
XSetForeground(icon->display, gc_mask, 1);
if (icon_size == LARGE_ICON)
{
#ifndef hpux
if (tmp_mask && tmp_mask != XmUNSPECIFIED_PIXMAP)
{
XSetClipOrigin(icon->display, gc_mask, p_x, p_y);
XSetClipMask(icon->display, gc_mask, tmp_mask);
XFillRectangle(icon->display, mask, gc_mask, p_x, p_y, p_w, p_h);
XSetClipMask(icon->display, gc_mask, None);
XSetClipOrigin(icon->display, gc_mask, 0, 0);
}
else
#endif
XFillRectangle(icon->display, mask, gc_mask, p_x, p_y, p_w, p_h);
}
else
XFillRectangle(icon->display, mask, gc_mask, p_x, p_y, p_w - 1,
p_h - 1);
if (icon_size == LARGE_ICON)
XFillRectangle(icon->display, mask, gc_mask, s_x - string_border_width,
s_y - string_border_width,
s_w + 2 * string_border_width,
s_h + 2 * string_border_width);
else
XFillRectangle(icon->display, mask, gc_mask, s_x, s_y, s_w - 1,
s_h - 1);
}
// If selected use selectColor as background
if (showSelectedPixmap && selected)
bg = selectColor;
// Copy Pixmap to new pixmap
XSetClipMask(icon->display, gc, None);
XSetFillStyle(icon->display, gc, FillSolid);
XSetForeground(icon->display, gc, bg);
if (icon_size == LARGE_ICON)
XFillRectangle(icon->display, pixmap, gc, p_x, p_y, p_w, p_h);
else
XFillRectangle(icon->display, pixmap, gc, p_x, p_y, p_w - 1, p_h - 1);
XSetClipOrigin(icon->display, gc, p_x, p_y);
if (tmp_mask && tmp_mask != XmUNSPECIFIED_PIXMAP)
XSetClipMask(icon->display, gc, tmp_mask);
else
XSetClipMask(icon->display, gc, None);
if (icon_size == LARGE_ICON)
XCopyArea(icon->display, tmp_pixmap, pixmap, gc, 0, 0, p_w, p_h,
p_x, p_y);
else
XCopyArea(icon->display, tmp_pixmap, pixmap, gc, 0, 0, p_w - 1, p_h - 1,
p_x, p_y);
XSetClipMask(icon->display, gc, None);
XSetClipOrigin(icon->display, gc, 0, 0);
DrawString();
Arg args[11];
int n = 0;
w = width;
h = height;
XtSetArg(args[n], XmNwidth, w); n++;
XtSetArg(args[n], XmNheight, h); n++;
XtSetArg(args[n], XmNmaxWidth, w); n++;
XtSetArg(args[n], XmNmaxHeight, h); n++;
XtSetArg(args[n], XmNdepth, icon->depth); n++;
XtSetArg(args[n], XmNforeground, bg); n++;
XtSetArg(args[n], XmNbackground, fg); n++;
XtSetArg(args[n], XmNpixmap, pixmap); n++;
if (mask)
{
XtSetArg(args[n], XmNmask, mask);
n++;
}
dragIcon = XmCreateDragIcon(icon->BaseWidget(), "dragIcon", args, n);
n = 0;
if (icon_size == LARGE_ICON)
sprintf(iconFile, "%s.m.bm", icon->IconFile());
else
sprintf(iconFile, "%s.t.bm", icon->IconFile());
icon->GetPixmaps(icon->BaseWidget(), iconFile, &tmp_pixmap);
if (!(tmp_pixmap && tmp_pixmap != XmUNSPECIFIED_PIXMAP))
{
static Pixmap l_pixmap = (Pixmap)NULL, s_pixmap = (Pixmap)NULL;
if (icon_size == LARGE_ICON)
{
if (!l_pixmap)
{
l_pixmap = XCreatePixmap(icon->display, icon->root, p_w, p_h, 1);
XFillRectangle(icon->display, l_pixmap, gc_mask, 0, 0, p_w, p_h);
}
tmp_pixmap = l_pixmap;
}
else
{
if (icon_size == NAME_ONLY)
{
p_w = 16;
p_h = 16;
}
if (!s_pixmap)
{
s_pixmap = XCreatePixmap(icon->display, icon->root, p_w, p_h, 1);
XFillRectangle(icon->display, s_pixmap, gc_mask, 0, 0, p_w, p_h);
}
tmp_pixmap = s_pixmap;
}
}
if (icon_size == NAME_ONLY)
{
w = 16;
h = 16;
}
else
{
w = p_w;
h = p_h;
}
XtSetArg(args[n], XmNwidth, w); n++;
XtSetArg(args[n], XmNheight, h); n++;
XtSetArg(args[n], XmNmaxWidth, w); n++;
XtSetArg(args[n], XmNmaxHeight, h); n++;
XtSetArg(args[n], XmNdepth, 1); n++;
XtSetArg(args[n], XmNforeground, icon->black); n++;
XtSetArg(args[n], XmNbackground, icon->white); n++;
XtSetArg(args[n], XmNpixmap, tmp_pixmap); n++;
if (tmp_mask && tmp_mask != XmUNSPECIFIED_PIXMAP)
{
XtSetArg(args[n], XmNmask, tmp_mask);
n++;
}
sourceIcon = XmCreateDragIcon(icon->BaseWidget(), "sourceIcon", args, n);
strcpy(iconFile, icon->IconFile());
}
void DtDND::DrawString()
{
IconObj *icon = (IconObj *)obj;
// Draw String
if (selected)
XSetForeground(icon->display, gc, selectColor);
else
XSetForeground(icon->display, gc, bg);
if (icon_size == LARGE_ICON)
XFillRectangle(icon->display, pixmap, gc, s_x - string_border_width,
s_y - string_border_width, s_w + 2 * string_border_width,
s_h + 2 * string_border_width);
else
XFillRectangle(icon->display, pixmap, gc, s_x, s_y, s_w - 1, s_h - 1);
// If selected use selectColor as background
if (selected)
XSetForeground(icon->display, gc, textSelectColor);
else
XSetForeground(icon->display, gc, fg);
XmStringDraw(icon->display, pixmap, fontList, string, gc, s_x, s_y, s_w,
alignment, stringDirection, NULL);
}
void DtDND::GetRects()
{
Dimension shadow, highlight, margin;
XtVaGetValues(obj->BaseWidget(), XmNhighlightThickness, &highlight,
GuiNiconMarginThickness, &margin,
GuiNiconShadowThickness, &shadow, NULL);
margin += (shadow + highlight);
GuiIconGetRects(obj->BaseWidget(), &rects[0], &rects[1]);
rects[0].x -= margin;
rects[0].y -= margin;
rects[0].width += (2 * margin);
rects[0].height += (2 * margin);
rects[1].x -= margin;
rects[1].y -= margin;
rects[1].width += (2 * margin);
rects[1].height += (2 * margin);
}
void DtDND::UpdateActivity(boolean flag)
{
Arg args[3];
int n = 0;
if (flag)
{
XtSetArg(args[n], XmNdropSiteOperations, XmDROP_COPY | XmDROP_MOVE); n++;
XtSetArg(args[n], XmNdropSiteActivity, XmDROP_SITE_ACTIVE); n++;
if (obj->UIClass() == ICON)
XtSetArg(args[n], XmNanimationStyle, XmDRAG_UNDER_SHADOW_IN);
else
XtSetArg(args[n], XmNanimationStyle, XmDRAG_UNDER_HIGHLIGHT);
n++;
}
else
{
XtSetArg(args[n], XmNdropSiteOperations, XmDROP_NOOP); n++;
XtSetArg(args[n], XmNdropSiteActivity, XmDROP_SITE_INACTIVE); n++;
XtSetArg(args[n], XmNanimationStyle, XmDRAG_UNDER_NONE); n++;
}
XmDropSiteUpdate(obj->BaseWidget(), args, n);
if (flag)
XmDropSiteConfigureStackingOrder(obj->BaseWidget(), NULL, XmABOVE);
else
XmDropSiteConfigureStackingOrder(obj->BaseWidget(), NULL, XmBELOW);
}
void DtDND::UpdateRects()
{
Arg args[2];
GetRects();
XtSetArg(args[0], XmNnumDropRectangles, 2);
XtSetArg(args[1], XmNdropRectangles, &rects);
XmDropSiteUpdate(obj->BaseWidget(), args, 2);
}
void DtDND::AnimateCB(Widget /*widget*/, XtPointer client_data,
XtPointer call_data)
{
DtDND *obj = (DtDND *)client_data;
if (obj->dndCB)
{
DtDndDropAnimateCallbackStruct *animateInfo;
animateInfo = (DtDndDropAnimateCallbackStruct *) call_data;
int i = 0, numItems;
numItems = animateInfo->dropData->numItems;
//for (i = 0; i < numItems; i++)
{
(*obj->dndCB)(obj->obj, NULL, NULL, ANIMATE);
}
}
}
void DtDND::TransferCB(Widget /*widget*/, XtPointer client_data,
XtPointer call_data)
{
DtDndTransferCallbackStruct *transferInfo;
transferInfo = (DtDndTransferCallbackStruct *) call_data;
char *value;
int len, i, numItems;
DtDND *obj = (DtDND *)client_data;
numItems = transferInfo->dropData->numItems;
switch (transferInfo->dropData->protocol)
{
case DtDND_FILENAME_TRANSFER:
if (obj->dndCB)
{
for (i = 0; i < numItems; i++)
{
value = transferInfo->dropData->data.files[i];
len = strlen(value);
(*obj->dndCB)(obj->obj, &value, &len, FILENAME_TRANSFER);
}
}
break;
case DtDND_TEXT_TRANSFER:
if (obj->dndCB)
{
for (i = 0; i < numItems; i++)
{
value = (char *) _XmStringUngenerate(
transferInfo->dropData->data.strings[i], NULL,
XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
len = strlen(value);
(*obj->dndCB)(obj->obj, &value, &len, TEXT_TRANSFER);
if (NULL != value)
XtFree(value);
}
}
break;
case DtDND_BUFFER_TRANSFER:
if (obj->dndCB)
{
(*obj->dndCB)(obj->obj, &value, &len, BUFFER_TRANSFER);
DtActionArg *aap = new DtActionArg[numItems];
memset(aap, 0, numItems * sizeof(DtActionArg));
for (i = 0; i < numItems; i++)
{
aap[i].argClass = DtACTION_BUFFER;
aap[i].u.buffer.bp = transferInfo->dropData->data.buffers[i].bp;
aap[i].u.buffer.size = transferInfo->dropData->data.buffers[i].size;
aap[i].u.buffer.name = transferInfo->dropData->data.buffers[i].name;
}
MotifUI *tmp = (MotifUI *)obj->obj;
DtActionInvoke(tmp->topLevel, value, aap, numItems, NULL, NULL, NULL,
1, NULL, NULL);
delete aap;
delete value;
}
break;
default:
transferInfo->status = DtDND_FAILURE;
break;
}
}
void DtDND::DragMotionHandler(Widget /*widget*/, XtPointer client_data,
XEvent *event, Boolean * /*continued*/)
{
static int initialX = -1;
static int initialY = -1;
int diffX, diffY;
DtDND *obj = (DtDND *)client_data;
if (obj->DoingDrag)
return;
// If the drag is just starting, set initial button down coords
if (initialX == -1 && initialY == -1)
{
initialX = event->xmotion.x;
initialY = event->xmotion.y;
}
// Find out how far pointer has moved since button press
diffX = initialX - event->xmotion.x;
diffY = initialY - event->xmotion.y;
if ((ABS(diffX) >= DRAG_THRESHOLD) ||
(ABS(diffY) >= DRAG_THRESHOLD))
{
obj->DoingDrag = true;
obj->StartDrag(event);
initialX = -1;
initialY = -1;
}
}
void DtDND::DragFinishCB(Widget /*widget*/, XtPointer client_data,
XtPointer /*callData*/)
{
DtDND *obj = (DtDND *) client_data;
obj->DoingDrag = false;
}
void DtDND::StartDrag(XEvent *event)
{
IconObj *icon = (IconObj *)obj;
convertCBRec[0].closure = (XtPointer)this;
dragFinishCBRec[0].closure = (XtPointer)this;
dropOnRootCBRec[0].closure = (XtPointer)this;
if ((!STRCMP(name, icon->Name()) || !STRCMP(iconFile, icon->IconFile()) ||
icon_size != icon->IconView()) && dragIcon)
{
XtDestroyWidget(dragIcon);
XtDestroyWidget(sourceIcon);
dragIcon = NULL;
sourceIcon = NULL;
}
if (!dragIcon)
GetDragPixmaps();
else if (selected != icon->Selected())
{
selected = icon->Selected();
DrawString();
}
Arg arg[3];
XtSetArg(arg[0], DtNsourceIcon, (XtArgVal)dragIcon);
XtSetArg(arg[1], XmNsourceCursorIcon, (XtArgVal)sourceIcon);
XtSetArg(arg[2], DtNdropOnRootCallback, dropOnRootCBRec);
Widget dc = DtDndDragStart(obj->BaseWidget(), event, DtDND_FILENAME_TRANSFER,
1, (unsigned char)(XmDROP_COPY | XmDROP_MOVE),
convertCBRec, dragFinishCBRec, arg,
can_drop_on_root ? 3 : 2);
if (dc)
{
XmDragContext xmDragContext = (XmDragContext) dc;
XtVaSetValues((Widget)xmDragContext->drag.curDragOver,
XmNdragOverMode, XmPIXMAP, NULL);
}
else
fprintf(stderr, "DtDndDragStart returned NULL.\n");
}
void DtDND::ConvertCB(Widget /*dragContext*/, XtPointer client_data,
XtPointer call_data)
{
char *value;
DtDndConvertCallbackStruct *convertInfo;
int len, i, numFiles;
DtDND *obj = (DtDND *) client_data;
convertInfo = (DtDndConvertCallbackStruct *) call_data;
numFiles = convertInfo->dragData->numItems;
switch (convertInfo->reason)
{
case DtCR_DND_CONVERT_DATA:
if (obj->dndCB)
{
for (i = 0; i < numFiles; i++)
{
value = NULL;
(*obj->dndCB)(obj->obj, &value, &len, CONVERT_DATA);
if (value && *value)
convertInfo->dragData->data.files[i] = value;
else
{
convertInfo->status = DtDND_FAILURE;
return;
}
}
}
break;
case DtCR_DND_CONVERT_DELETE:
if (obj->dndCB)
{
for (i = 0; i < numFiles; i++)
{
value = convertInfo->dragData->data.files[i];
len = strlen(value);
(*obj->dndCB)(obj->obj, &value, &len, CONVERT_DELETE);
}
}
break;
}
}
void DtDND::DropOnRootCB(Widget /*dragContext*/, XtPointer client_data,
XtPointer call_data)
{
char *value;
int len, x, y, i, numFiles;
DtDND *obj = (DtDND *) client_data;
DtDndDropCallbackStruct *fileList = (DtDndDropCallbackStruct *)call_data;
MotifUI *tmp = (MotifUI *)obj->obj;
Atom pCurrent;
char *workspace_name = NULL;
if (DtWsmGetCurrentWorkspace(tmp->display, tmp->root, &pCurrent) ==
Success)
{
workspace_name = XGetAtomName(tmp->display, pCurrent);
}
numFiles = fileList->dropData->numItems;
fileList->completeMove = False;
x = fileList->x;
y = fileList->y;
int max_len = 0;
for(i = 0; i < numFiles; i++)
if ((len = strlen(fileList->dropData->data.files[i])) > max_len)
max_len = len;
if (workspace_name)
value = new char[max_len + strlen(workspace_name) + 30];
else
value = new char[max_len + 30];
for(i = 0; i < numFiles; i++)
{
if (workspace_name)
sprintf(value, "%d\n%d\n%s \n%s", x, y,
fileList->dropData->data.files[i], workspace_name);
else
sprintf(value, "%d\n%d\n%s", x, y, fileList->dropData->data.files[i]);
len = strlen(value);
(*obj->dndCB)(obj->obj, &value, &len, DROP_ON_ROOT);
y += 20;
x += 20;
}
delete value;
}

View File

@@ -0,0 +1,94 @@
/* $XConsortium: DtDND.h /main/3 1995/11/06 09:40:32 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef DTDND_H
#define DTDND_H
#include "MotifUI.h"
typedef enum
{
FILENAME_TRANSFER,
TEXT_TRANSFER,
DROP_ON_ROOT,
BUFFER_TRANSFER,
CONVERT_DATA,
CONVERT_DELETE,
ANIMATE
} DNDProtocol;
typedef void (*DNDCallback) (BaseUI *, char **value, int *len, DNDProtocol);
class DtDND {
friend void TransferCB(Widget, XtPointer, XtPointer);
friend void ConvertCB(Widget, XtPointer, XtPointer);
friend void DragFinishCB(Widget, XtPointer, XtPointer);
friend void DropOnRootCB(Widget, XtPointer, XtPointer);
friend void AnimateCB(Widget, XtPointer, XtPointer);
friend void DragMotionHandler(Widget, XtPointer, XEvent *, Boolean *);
static void TransferCB(Widget, XtPointer, XtPointer);
static void ConvertCB(Widget, XtPointer, XtPointer);
static void DragFinishCB(Widget, XtPointer, XtPointer);
static void DropOnRootCB(Widget, XtPointer, XtPointer);
static void AnimateCB(Widget, XtPointer, XtPointer);
static void DragMotionHandler(Widget, XtPointer, XEvent *, Boolean *);
private:
static boolean FirstTime;
static boolean DoingDrag;
static XtCallbackRec transferCBRec[];
static XtCallbackRec convertCBRec[];
static XtCallbackRec dragFinishCBRec[];
static XtCallbackRec dropOnRootCBRec[];
static XtCallbackRec animateCBRec[];
static GC gc;
static GC gc_mask;
MotifUI *obj;
Widget dragIcon;
Widget sourceIcon;
DNDCallback dndCB;
XRectangle rects[2];
Pixmap pixmap;
Pixmap mask;
char *name;
char *iconFile;
Position s_x, s_y;
Pixel bg, fg;
unsigned char stringDirection;
Pixel textSelectColor;
XmString string;
Pixel selectColor;
unsigned char alignment;
Boolean showSelectedPixmap;
XmFontList fontList;
int string_border_width;
int p_x, p_y;
int p_w, p_h, s_w, s_h;
boolean selected;
boolean can_drop_on_root;
IconStyle icon_size;
void GetRects();
void GetDragPixmaps();
void DrawString();
void StartDrag(XEvent *);
public:
DtDND(MotifUI *obj, DNDCallback dndCB, boolean can_drop_on_root = false);
~DtDND();
void UpdateActivity(boolean);
void UpdateRects();
};
#endif // DTDND_H

View File

@@ -0,0 +1,73 @@
/* $XConsortium: Group.C /main/2 1995/07/17 14:05:44 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Group.h"
#include "Dialog.h"
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/RowColumn.h>
#include <Xm/Form.h>
Group::Group(MotifUI *parent,
char *name,
GroupType group_type)
: MotifUI(parent, name, NULL)
{
Widget parentW;
_group_type = group_type;
parentW = parent->InnerWidget();
XmString xm_string = StringCreate(name);
_w = XtVaCreateManagedWidget(name, xmFrameWidgetClass, parentW, NULL);
if (name)
_label = XtVaCreateManagedWidget(name, xmLabelWidgetClass, _w,
XmNchildType, XmFRAME_TITLE_CHILD,
XmNlabelString, xm_string, NULL);
else
_label = XtVaCreateWidget(name, xmLabelWidgetClass, _w,
XmNchildType, XmFRAME_TITLE_CHILD,
XmNlabelString, xm_string, NULL);
if (group_type == FORM_BOX)
_rc = XtVaCreateManagedWidget(name, xmFormWidgetClass, _w, NULL);
else
{
boolean flag;
int orientaion;
if (group_type == RADIO_GROUP || group_type == HORIZONTAL_RADIO_GROUP)
flag = true;
else
flag = false;
if (group_type == HORIZONTAL_CHECK_BOX ||
group_type == HORIZONTAL_RADIO_GROUP)
orientaion = XmHORIZONTAL;
else
orientaion = XmVERTICAL;
_rc = XtVaCreateManagedWidget(name, xmRowColumnWidgetClass, _w,
XmNradioBehavior, flag,
XmNorientation, orientaion, NULL);
}
StringFree(xm_string);
}
boolean Group::SetName(char *name)
{
if (name)
{
XmString xm_string = StringCreate(name);
XtVaSetValues(_label, XmNlabelString, xm_string, NULL);
StringFree(xm_string);
XtManageChild(_label);
}
else
XtUnmanageChild(_label);
return true;
}

View File

@@ -0,0 +1,38 @@
/* $XConsortium: Group.h /main/3 1995/11/06 09:40:43 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef GROUP_H
#define GROUP_H
#include "MotifUI.h"
class Group : public MotifUI {
private:
Widget _label;
Widget _rc;
GroupType _group_type;
public:
Group(MotifUI *parent,
char *name,
GroupType group_type = RADIO_GROUP);
const Widget InnerWidget() { return _rc; }
const UI_Class UIClass() { return GROUP; }
const int UISubClass() { return _group_type; }
const char *const UIClassName() { return "Group"; }
// Override SetName, need to set label name, not BaseWidget
boolean SetName(char *);
};
#endif /* GROUP_H */

View File

@@ -0,0 +1,115 @@
/* $XConsortium: HelpSystem.C /main/2 1995/07/17 14:05:53 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "HelpSystem.h"
#include <stdio.h>
#include <Xm/AtomMgr.h>
#include <Xm/Protocols.h>
#include <Dt/Help.h>
#include <Dt/HelpDialog.h>
#include <Dt/HelpQuickD.h>
#include <Dt/Wsm.h>
HelpSystem::HelpSystem(MotifUI *parent,
char *name,
char *volume,
char *location_id,
HelpStyle style)
: MotifUI(parent, name, NULL)
{
CreateHelpDialog(parent, name, volume, location_id, style);
}
HelpSystem::HelpSystem(char *category,
MotifUI *parent,
char *name,
char *volume,
char *location_id,
HelpStyle style)
: MotifUI(parent, name, category)
{
CreateHelpDialog(parent, name, volume, location_id, style);
}
void HelpSystem::CreateHelpDialog(MotifUI *parent, char *name, char *volume,
char *location_id, HelpStyle style)
{
Arg args[6];
int n;
_style = style;
n = 0;
XtSetArg(args[n], XmNtitle, name); n++;
XtSetArg(args[n], XmNautoUnmanage, false); n++;
XtSetArg(args[n], DtNshowNewWindowButton, false); n++;
XtSetArg(args[n], DtNhelpType, DtHELP_TYPE_TOPIC); n++;
XtSetArg(args[n], DtNhelpVolume, volume); n++;
XtSetArg(args[n], DtNlocationId, location_id); n++;
if (_style == HELP_DIALOG)
_w = DtCreateHelpDialog(parent->InnerWidget(), "helpDlg", args, n);
else
_w = DtCreateHelpQuickDialog(parent->InnerWidget(), "helpDlg", args, n);
DtWsmRemoveWorkspaceFunctions(display, XtWindow(XtParent(_w)));
XtAddCallback(_w, DtNhyperLinkCallback,
(XtCallbackProc)HyperlinkCB, (XtPointer) this);
XtAddCallback(_w, DtNcloseCallback, (XtCallbackProc)CloseCB,
(XtPointer) this);
XmAddWMProtocolCallback(XtParent(_w),
XmInternAtom(display, "WM_DELETE_WINDOW", False),
&HelpSystem::CloseCB, (XtPointer) this);
}
boolean HelpSystem::SetVisiblity(boolean flag)
{
MotifUI::SetVisiblity(flag);
if (flag == true && XtIsRealized(XtParent(_w)))
XtMapWidget(XtParent(_w));
return true;
}
void HelpSystem::HyperlinkCB(Widget, XtPointer data, XtPointer)
{
HelpSystem *obj = (HelpSystem *)data;
}
void HelpSystem::CloseCB(Widget, XtPointer data, XtPointer)
{
HelpSystem *obj = (HelpSystem *)data;
obj->Visible(false);
}
char *HelpSystem::HelpVolume()
{
char *value;
XtVaGetValues(_w, DtNhelpVolume, &value, NULL);
return value;
}
char *HelpSystem::LocationID()
{
char *value;
XtVaGetValues(_w, DtNlocationId, &value, NULL);
return value;
}
void HelpSystem::LocationID(char *locationId)
{
//if (strcmp(LocationID(), locationId))
XtVaSetValues(_w, DtNhelpType, DtHELP_TYPE_TOPIC,
DtNlocationId, locationId, NULL);
}
void HelpSystem::HelpVolume(char *helpVolume, char *locationId)
{
//if (strcmp(HelpVolume(), helpVolume) || strcmp(LocationID(), locationId))
XtVaSetValues(_w, DtNhelpVolume, helpVolume, DtNlocationId, locationId,
DtNhelpType, DtHELP_TYPE_TOPIC, NULL);
}

View File

@@ -0,0 +1,60 @@
/* $XConsortium: HelpSystem.h /main/3 1995/11/06 09:40:54 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef HELP_SYSTEM_H
#define HELP_SYSTEM_H
#include "MotifUI.h"
typedef enum
{
HELP_DIALOG,
QUICK_HELP
} HelpStyle;
class HelpSystem : public MotifUI {
friend void HyperlinkCB(Widget, XtPointer, XtPointer);
friend void CloseCB(Widget, XtPointer, XtPointer);
private:
static void HyperlinkCB(Widget, XtPointer, XtPointer);
static void CloseCB(Widget, XtPointer, XtPointer);
void CreateHelpDialog(MotifUI *, char *, char *, char *, HelpStyle);
boolean SetVisiblity(boolean flag);
HelpStyle _style;
public:
HelpSystem(MotifUI * parent,
char * name,
char * volume = NULL,
char * location_id = "_hometopic",
HelpStyle style = HELP_DIALOG);
HelpSystem(char *category,
MotifUI * parent,
char * name,
char * volume = NULL,
char * location_id = "_hometopic",
HelpStyle style = HELP_DIALOG);
char *HelpVolume();
char *LocationID();
void HelpVolume(char *volume,
char *location = "_hometopic");
void LocationID(char *location);
const UI_Class UIClass() { return HELP_SYSTEM; }
const int UISubClass() { return _style; }
const char *const UIClassName() { return "HelpSystem"; }
};
#endif // HELP_SYSTEM_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,158 @@
/* $XConsortium: Icon.h /main/3 1995/11/06 09:41:27 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
/*****************************************************************************
*
* Icon.h - widget public header file
*
******************************************************************************/
#ifndef _Icon_h
#define _Icon_h
#ifdef __cplusplus
extern "C" {
#endif
externalref WidgetClass iconWidgetClass;
typedef struct _IconClassRec *IconWidgetClass;
typedef struct _IconRec *IconWidget;
enum {
GuiSINGLE_CLICK,
GuiDOUBLE_CLICK
};
enum {
GuiPIXMAP_TOP,
GuiPIXMAP_BOTTOM,
GuiPIXMAP_LEFT,
GuiPIXMAP_RIGHT
};
enum {
GuiNORTHWEST_GRAVITY,
GuiNORTH_GRAVITY,
GuiNORTHEAST_GRAVITY,
GuiWEST_GRAVITY,
GuiCENTER_GRAVITY,
GuiEAST_GRAVITY,
GuiSOUTHWEST_GRAVITY,
GuiSOUTH_GRAVITY,
GuiSOUTHEAST_GRAVITY
};
typedef struct
{
int reason;
XEvent *event;
Boolean prev_selected;
XmString string;
int field_index;
XmString field_string;
} GuiIconCallbackStruct, *GuiIconCallback;
typedef struct
{
Boolean free_data;
Dimension name_width;
int n_fields;
int field_spacing;
XmString *fields;
Dimension *widths;
unsigned char *alignments;
Boolean *draw_fields;
Boolean *selected;
Boolean *active;
} GuiIconFieldsStruct, *GuiIconFields, **GuiIconFieldsList;
#define GuiIsIcon(w) XtIsSubclass((w), iconWidgetClass)
/* Icon Resources */
extern const char gui_icon_strings[];
#define GuiNtopLabelString ((char*)&gui_icon_strings[0])
#define GuiNbottomLabelString ((char*)&gui_icon_strings[15])
#define GuiNpixmapPlacement ((char*)&gui_icon_strings[33])
#define GuiCPixmapPlacement ((char*)&gui_icon_strings[49])
#define GuiRPixmapPlacement ((char*)&gui_icon_strings[65])
#define GuiNdoubleClickCallback ((char*)&gui_icon_strings[81])
#define GuiNsingleClickCallback ((char*)&gui_icon_strings[101])
#define GuiNselected ((char*)&gui_icon_strings[121])
#define GuiCSelected ((char*)&gui_icon_strings[130])
#define GuiNiconShadowType ((char*)&gui_icon_strings[139])
#define GuiCIconShadowType ((char*)&gui_icon_strings[154])
#define GuiNiconShadowThickness ((char*)&gui_icon_strings[169])
#define GuiCIconShadowThickness ((char*)&gui_icon_strings[189])
#define GuiNtextSelectColor ((char*)&gui_icon_strings[209])
#define GuiCTextSelectColor ((char*)&gui_icon_strings[225])
#define GuiNselectColor ((char*)&gui_icon_strings[241])
#define GuiCSelectColor ((char*)&gui_icon_strings[253])
#define GuiNselectColorPersistent ((char*)&gui_icon_strings[265])
#define GuiCSelectColorPersistent ((char*)&gui_icon_strings[287])
#define GuiNshowSelectedPixmap ((char*)&gui_icon_strings[309])
#define GuiCShowSelectedPixmap ((char*)&gui_icon_strings[328])
#define GuiNiconMarginThickness ((char*)&gui_icon_strings[347])
#define GuiCIconMarginThickness ((char*)&gui_icon_strings[367])
#define GuiNactive ((char*)&gui_icon_strings[387])
#define GuiCActive ((char*)&gui_icon_strings[394])
#define GuiNiconMask ((char*)&gui_icon_strings[401])
#define GuiCIconMask ((char*)&gui_icon_strings[410])
#define GuiNshrinkOutline ((char*)&gui_icon_strings[419])
#define GuiCShrinkOutline ((char*)&gui_icon_strings[433])
#define GuiNfields ((char *)&gui_icon_strings[447])
#define GuiCFields ((char *)&gui_icon_strings[454])
#define GuiNstatePixmap ((char *)&gui_icon_strings[461])
#define GuiNstateIconMask ((char *)&gui_icon_strings[473])
#define GuiCStateIconMask ((char *)&gui_icon_strings[487])
#define GuiNstateGravity ((char *)&gui_icon_strings[501])
#define GuiCStateGravity ((char *)&gui_icon_strings[514])
#define GuiRStateGravity ((char *)&gui_icon_strings[514])
/* Public functions */
extern void GuiIconSetFieldNameWidth(
Widget, /* GuiIconWidget */
Dimension name_width);
extern Dimension GuiIconGetFieldNameWidth(Widget);
extern void GuiIconSetField(
Widget, /* GuiIconWidget */
int index,
XmString new_string, /* NULL does not change value */
Dimension new_width, /* 0 does not change value */
unsigned char alignments,
Boolean draw_field,
Boolean selected,
Boolean active);
extern void GuiIconGetField(
Widget,
int index,
XmString *string,
Dimension *width,
unsigned char *alignments,
Boolean *draw_field,
Boolean *selected,
Boolean *active);
extern void GuiIconGetRects(
Widget, /* GuiIconWidget */
XRectangle *, /* Pixmap Rectangle Return */
XRectangle * /* Label Rectangle Return */
);
#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif
#endif /* _Icon_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,563 @@
/* $TOG: IconObj.C /main/4 1998/07/24 16:15:38 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "IconObj.h"
#include "Icon.h"
#include "WorkArea.h"
#include <stdlib.h>
#include <stdio.h>
// #define LargeIconJustification XmALIGNMENT_CENTER
#define LargeIconJustification XmALIGNMENT_BEGINNING
IconObj::IconObj(MotifUI *parent, char *name, char *iconFile, char *details,
char *topString, char *bottomString, IconFields fields)
: MotifUI(parent, name, NULL)
{
CreateIconObj(parent, name, NULL, iconFile, details, topString,
bottomString, fields);
}
IconObj::IconObj(char *category, MotifUI *parent, char *name, char *iconFile,
char *details, char *topString, char *bottomString,
IconFields fields)
: MotifUI(parent, name, category)
{
CreateIconObj(parent, name, category, iconFile, details, topString,
bottomString, fields);
}
IconObj::~IconObj()
{
delete _topString;
delete _bottomString;
delete _details;
delete _iconFile;
delete _stateIconName;
}
void IconObj::CreateIconObj(MotifUI *parent, char *name, char * /*category*/,
char *iconFile, char *details, char *topString,
char *bottomString, IconFields _fields)
{
Pixmap pixmap;
Pixmap mask;
Pixel bg;
Widget p, super_node;
XmString xm_string, xm_topString, xm_bottomString;
char *s;
int shrinkOutline = false;
int pixmapPlacement;
int alignment;
int isOpened;
GuiIconFields gui_fields;
if (fields = _fields)
{
int i;
gui_fields = new GuiIconFieldsStruct;
gui_fields->free_data = True;
gui_fields->name_width = fields->name_width;
gui_fields->field_spacing = fields->field_spacing;
gui_fields->n_fields = fields->n_fields;
gui_fields->selected = new Boolean[fields->n_fields];
gui_fields->draw_fields = new Boolean[fields->n_fields];
gui_fields->active = new Boolean[fields->n_fields];
gui_fields->widths = new Dimension[fields->n_fields];
gui_fields->alignments = new unsigned char[fields->n_fields];
gui_fields->fields = new XmString[fields->n_fields];
unsigned char alignment;
for (i = 0; i < fields->n_fields; i++)
{
gui_fields->widths[i] = fields->fields_widths[i];
switch (fields->alignments[i])
{
case LEFT_JUSTIFIED: alignment = XmALIGNMENT_BEGINNING; break;
case CENTERED: alignment = XmALIGNMENT_CENTER; break;
case RIGHT_JUSTIFIED: alignment = XmALIGNMENT_END; break;
}
gui_fields->alignments[i] = alignment;
if (fields->active)
gui_fields->active[i] = (Boolean)fields->active[i];
else
gui_fields->active[i] = True;
if (fields->draw_fields)
gui_fields->draw_fields[i] = (Boolean)fields->draw_fields[i];
else
gui_fields->draw_fields[i] = True;
gui_fields->selected[i] = False;
gui_fields->fields[i] = StringCreate(fields->fields[i]);
}
}
else
gui_fields = NULL;
// Get small and large pixmaps and masks
char icon_type = 'p';
if (depth == 1)
icon_type = 'b';
_iconFile = new char [strlen(iconFile) + 6];
_topString = STRDUP(topString);
_bottomString = STRDUP(bottomString);
_details = STRDUP(details);
if (display == NULL)
{
strcpy(_iconFile, iconFile);
_stateIconName = NULL;
return;
}
sprintf(_iconFile, "%s.t.%cm", iconFile, icon_type);
GetPixmaps(parent->BaseWidget(), _iconFile, &_smallPixmap, &_smallMask);
sprintf(_iconFile, "%s.m.%cm", iconFile, icon_type);
GetPixmaps(parent->BaseWidget(), _iconFile, &_largePixmap, &_largeMask);
strcpy(_iconFile, iconFile);
s = name;
BaseUI *par = Parent();
if (par && par->UISubClass() == ICON_LIST ||
par->UISubClass() == SCROLLED_ICON_LIST)
isOpened = true;
else
isOpened = false;
switch (IconView())
{
case NAME_ONLY:
pixmapPlacement = GuiPIXMAP_LEFT;
alignment = XmALIGNMENT_BEGINNING;
pixmap = mask = XmUNSPECIFIED_PIXMAP;
break;
case LARGE_ICON:
if (ContainerView() == TREE ||
(Parent()->UIClass() == CONTAINER &&
Parent()->UISubClass() == SCROLLED_VERTICAL_ROW_COLUMN))
{
isOpened = true;
pixmapPlacement = GuiPIXMAP_LEFT;
}
else
pixmapPlacement = GuiPIXMAP_TOP;
if (isOpened)
alignment = XmALIGNMENT_BEGINNING;
else
alignment = LargeIconJustification;
shrinkOutline = true;
pixmap = _largePixmap;
mask = _largeMask;
break;
case DETAILS:
s = new char [STRLEN(name) + STRLEN(details) + 2];
if (details)
sprintf(s, "%s %s", name, details);
else
strcpy(s, name);
// no break
case SMALL_ICON:
alignment = XmALIGNMENT_BEGINNING;
pixmapPlacement = GuiPIXMAP_LEFT;
pixmap = _smallPixmap;
mask = _smallMask;
break;
}
// Get Parent and colors
p = parent->InnerWidget();
if (!XtIsComposite(p))
p = XtParent(p);
XtVaGetValues(p, XmNbackground, &bg, NULL);
// If p is a icon then set superNode to it, otherwise set superNode to NULL
super_node = GuiIsIcon(parent->BaseWidget()) ? parent->BaseWidget() : NULL;
xm_string = StringCreate(s);
xm_topString = StringCreate(topString);
xm_bottomString = StringCreate(bottomString);
Pixel text_select_color = black;
Pixel select_color = white;
if (select_color == bg)
{
text_select_color = white;
select_color = black;
}
_w = XtVaCreateManagedWidget(name, iconWidgetClass, p, GuiNiconMask, mask,
XmNlabelPixmap, pixmap, GuiNisOpened, isOpened,
XmNalignment, alignment,
GuiNsuperNode, super_node,
GuiNpixmapPlacement, pixmapPlacement,
GuiNshrinkOutline, shrinkOutline,
GuiNselectColorPersistent, true,
GuiNselectColor, select_color,
GuiNtextSelectColor, text_select_color,
XmNlabelString, xm_string,
GuiNfields, gui_fields,
XmNbackground, bg,
GuiNtopLabelString, xm_topString,
GuiNbottomLabelString, xm_bottomString,
XmNuserData, this, NULL);
StringFree(xm_string);
StringFree(xm_topString);
StringFree(xm_bottomString);
// Delete s if style = details
if (IconView() == DETAILS)
delete s;
_previous_style = IconView();
XtAddCallback(_w, GuiNsingleClickCallback, &IconObj::SingleClickCB,
(XtPointer) this);
XtAddCallback(_w, GuiNdoubleClickCallback, &IconObj::DoubleClickCB,
(XtPointer) this);
InstallHelpCB();
_stateIconName = NULL;
}
void IconObj::StateIconFile(char *stateIconName)
{
delete _stateIconName;
_stateIconName = STRDUP(stateIconName);
SetStateIconFile(IconView());
}
void IconObj::SetStateIconFile(IconStyle style)
{
Pixmap _statePixmap = XmUNSPECIFIED_PIXMAP;
Pixmap _stateMask = XmUNSPECIFIED_PIXMAP;
if (_stateIconName && style != NAME_ONLY)
{
char icon_type = 'p';
if (depth == 1)
icon_type = 'b';
char *tmp = new char[strlen(_stateIconName) + 6];
if (style == LARGE_ICON)
sprintf(tmp, "%s.m.%cm", _stateIconName, icon_type);
else
sprintf(tmp, "%s.t.%cm", _stateIconName, icon_type);
GetPixmaps(_w, tmp, &_statePixmap, &_stateMask);
delete [] tmp;
}
XtVaSetValues(_w, GuiNstatePixmap, _statePixmap,
GuiNstateIconMask, _stateMask, NULL);
}
void IconObj::StateIconGravity(StateGravity stateGravity)
{
XtVaSetValues(_w, GuiNstateGravity, stateGravity, NULL);
_state_gravity = stateGravity;
}
int IconObj::NumberFields()
{
GuiIconFields gui_fields;
XtVaGetValues(_w, GuiNfields, &gui_fields, NULL);
if (gui_fields)
return gui_fields->n_fields;
else
return 0;
}
void IconObj::Field(int index, char **string, int *width, boolean *visible,
boolean *active)
{
XmString s;
Dimension wid;
unsigned char alignment;
Boolean draw_field;
Boolean selected;
Boolean _active;
GuiIconGetField(_w, index, &s, &wid, &alignment, &draw_field, &selected,
&_active);
if (width)
*width = (int)wid;
if (string)
*string = StringExtract(s);
if (visible)
*visible = draw_field ? true : false;
if (active)
*active = _active ? true : false;
}
void IconObj::Field(int index, char *string, int width, boolean visible,
boolean active)
{
XmString s;
Dimension wid;
unsigned char alignment;
Boolean draw_field;
Boolean selected;
Boolean _active;
GuiIconGetField(_w, index, &s, &wid, &alignment, &draw_field, &selected,
&_active);
draw_field = visible;
_active = active;
wid = (Dimension) width;
s = StringCreate(string);
GuiIconSetField(_w, index, s, wid, alignment, draw_field, selected, _active);
}
void IconObj::BottomString(char *bottomString)
{
delete _bottomString;
_bottomString = STRDUP(bottomString);
XmString xm_string = StringCreate(bottomString);
XtVaSetValues(_w, GuiNbottomLabelString, xm_string, NULL);
StringFree(xm_string);
}
void IconObj::TopString(char *topString)
{
delete _topString;
_topString = STRDUP(topString);
XmString xm_string = StringCreate(topString);
XtVaSetValues(_w, GuiNtopLabelString, xm_string, NULL);
StringFree(xm_string);
}
void IconObj::IconFile(char *iconFile)
{
delete _iconFile;
_iconFile = new char [strlen(iconFile) + 6];
// Get small and large pixmaps and masks
char icon_type = 'p';
if (depth == 1)
icon_type = 'b';
_iconFile = new char [strlen(iconFile) + 6];
sprintf(_iconFile, "%s.t.%cm", iconFile, icon_type);
GetPixmaps(_w, _iconFile, &_smallPixmap, &_smallMask);
sprintf(_iconFile, "%s.m.%cm", iconFile, icon_type);
GetPixmaps(_w, _iconFile, &_largePixmap, &_largeMask);
Pixmap vlargePixmap, vlargeMask;
switch (IconView())
{
case VERY_LARGE_ICON:
sprintf(_iconFile, "%s.l.%cm", iconFile, icon_type);
GetPixmaps(_w, _iconFile, &vlargePixmap, &vlargeMask);
XtVaSetValues(_w, XmNlabelPixmap, vlargePixmap, GuiNiconMask, vlargeMask,
NULL);
break;
case LARGE_ICON:
case MEDIUM_ICON:
XtVaSetValues(_w, XmNlabelPixmap, _largePixmap, GuiNiconMask, _largeMask,
NULL);
break;
case SMALL_ICON:
case TINY_ICON:
XtVaSetValues(_w, XmNlabelPixmap, _smallPixmap, GuiNiconMask, _smallMask,
NULL);
break;
}
strcpy(_iconFile, iconFile);
}
void IconObj::SetDetail()
{
if (!_details)
return;
char *name = new char [strlen(_name) + strlen(_details) + 3];
sprintf(name, "%s %s", _name, _details);
XmString xm_string = StringCreate(name);
XtVaSetValues(_w, XmNlabelString, xm_string, NULL);
StringFree(xm_string);
delete [] name;
}
void IconObj::Details(char *details)
{
delete _details;
_details = STRDUP(details);
if (IconView() == DETAILS)
SetDetail();
}
boolean IconObj::SetName(char *_name)
{
return MotifUI::SetName(_name);
}
boolean IconObj::SetOpen(boolean flag)
{
int pixmapPlacement;
int alignment;
int isOpened;
BaseUI *parent = Parent();
if (ContainerView() == TREE)
isOpened = flag;
else if (parent && parent->UISubClass() == ICON_LIST ||
parent->UISubClass() == SCROLLED_ICON_LIST)
isOpened = true;
else
isOpened = flag;
if (IconView() == LARGE_ICON)
{
if (ContainerView() == TREE ||
(parent->UIClass() == CONTAINER &&
parent->UISubClass() == SCROLLED_VERTICAL_ROW_COLUMN))
{
isOpened = true;
pixmapPlacement = GuiPIXMAP_LEFT;
}
else
{
pixmapPlacement = GuiPIXMAP_TOP;
}
if (isOpened)
alignment = XmALIGNMENT_BEGINNING;
else
alignment = LargeIconJustification;
}
else
{
alignment = XmALIGNMENT_BEGINNING;
pixmapPlacement = GuiPIXMAP_LEFT;
}
XtVaSetValues(_w, XmNalignment, alignment, GuiNisOpened, isOpened,
GuiNpixmapPlacement, pixmapPlacement, NULL);
return true;
}
boolean IconObj::SetIcon(IconStyle style)
{
Pixmap pixmap, mask;
int shrinkOutline = false;
int pixmapPlacement;
int alignment;
int isOpened;
BaseUI *parent = Parent();
if (ContainerView() == TREE)
isOpened = true;
else if (parent && parent->UISubClass() == ICON_LIST ||
parent->UISubClass() == SCROLLED_ICON_LIST)
isOpened = true;
else
isOpened = Open();
switch (style)
{
case NAME_ONLY:
pixmapPlacement = GuiPIXMAP_LEFT;
alignment = XmALIGNMENT_BEGINNING;
if (_name)
{
pixmap = XmUNSPECIFIED_PIXMAP;
mask = XmUNSPECIFIED_PIXMAP;
}
else
{
pixmap = _smallPixmap;
mask = _smallMask;
}
break;
case VERY_LARGE_ICON:
case LARGE_ICON:
case MEDIUM_ICON:
if (ContainerView() == TREE ||
(parent->UIClass() == CONTAINER &&
parent->UISubClass() == SCROLLED_VERTICAL_ROW_COLUMN))
{
isOpened = true;
pixmapPlacement = GuiPIXMAP_LEFT;
}
else
pixmapPlacement = GuiPIXMAP_TOP;
if (isOpened)
alignment = XmALIGNMENT_BEGINNING;
else
alignment = LargeIconJustification;
shrinkOutline = true;
if (style == VERY_LARGE_ICON)
{
if (depth == 1)
strcat(_iconFile, ".l.bm");
else
strcat(_iconFile, ".l.pm");
GetPixmaps(_w, _iconFile, &pixmap, &mask);
_iconFile[strlen(_iconFile) - 5] = '\0';
}
else
{
pixmap = _largePixmap;
mask = _largeMask;
}
break;
case DETAILS:
SetDetail();
// no break
case SMALL_ICON:
case TINY_ICON:
alignment = XmALIGNMENT_BEGINNING;
pixmapPlacement = GuiPIXMAP_LEFT;
pixmap = _smallPixmap;
mask = _smallMask;
break;
}
if (_previous_style == DETAILS)
{
XmString xm_string = StringCreate(_name);
XtVaSetValues(_w, XmNlabelPixmap, pixmap, GuiNiconMask, mask,
XmNlabelString, xm_string, XmNalignment, alignment,
GuiNpixmapPlacement, pixmapPlacement,
GuiNisOpened, isOpened,
GuiNshrinkOutline, shrinkOutline, NULL);
StringFree(xm_string);
}
else
XtVaSetValues(_w, XmNlabelPixmap, pixmap, GuiNiconMask, mask,
GuiNpixmapPlacement, pixmapPlacement,
XmNalignment, alignment, GuiNisOpened, isOpened,
GuiNshrinkOutline, shrinkOutline, NULL);
_previous_style = style;
if (_stateIconName)
SetStateIconFile(style);
return true;
}
void IconObj::SingleClickCB(Widget,
XtPointer client_data,
XtPointer)
{
IconObj *obj = (IconObj *) client_data;
if (!obj->Name())
return;
if (obj->Selected())
obj->Selected(false);
else
obj->Selected(true);
}
void IconObj::DoubleClickCB(Widget,
XtPointer client_data,
XtPointer)
{
IconObj *obj = (IconObj *) client_data;
if (obj->Name())
{
if (obj->Selected())
obj->Selected(false);
else
obj->Selected(true);
XmUpdateDisplay(obj->BaseWidget());
}
if (obj->Open())
obj->Open(false);
else
obj->Open(true);
}

View File

@@ -0,0 +1,116 @@
/* $XConsortium: IconObj.h /main/3 1995/11/06 09:41:52 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef ICONOBJ_H
#define ICONOBJ_H
#include "MotifUI.h"
typedef struct
{
int name_width;
int n_fields;
int field_spacing;
char **fields;
int *fields_widths;
LabelType *alignments;
boolean *draw_fields;
boolean *selected;
boolean *active;
} IconFieldsRec, *IconFields, **IconFieldsList;
typedef enum {
NORTHWEST_GRAVITY,
NORTH_GRAVITY,
NORTHEAST_GRAVITY,
WEST_GRAVITY,
CENTER_GRAVITY,
EAST_GRAVITY,
SOUTHWEST_GRAVITY,
SOUTH_GRAVITY,
SOUTHEAST_GRAVITY
} StateGravity;
class IconObj : public MotifUI {
private:
static void SingleClickCB(Widget, XtPointer, XtPointer);
static void DoubleClickCB(Widget, XtPointer, XtPointer);
char *_details;
char *_iconFile;
char *_topString;
char *_bottomString;
IconStyle _previous_style;
Pixmap _smallPixmap;
Pixmap _smallMask;
Pixmap _largePixmap;
Pixmap _largeMask;
IconFields fields;
StateGravity _state_gravity;
char *_stateIconName;
void SetDetail();
void SetStateIconFile(IconStyle);
void CreateIconObj(MotifUI *, char *, char *, char *, char *, char *,
char *, IconFields);
protected:
// Override SetView and SetOpen for icon
virtual boolean SetIcon(IconStyle);
virtual boolean SetOpen(boolean);
virtual boolean SetName(char *);
public:
IconObj(MotifUI *parent,
char *name,
char *icon,
char *details = NULL,
char *topString = NULL,
char *bottomString = NULL,
IconFields fields = NULL);
IconObj(char *category,
MotifUI *parent,
char *name,
char *icon,
char *details = NULL,
char *topString = NULL,
char *bottomString = NULL,
IconFields fields = NULL);
~IconObj();
void Details(char *); // Set details
char *Details() { return _details; } // Access details
void TopString(char *); // Set top string
char *TopString() { return _topString; } // Access top string
void BottomString(char *); // Set bottom string
char *BottomString() { return _bottomString; } // Access bottom string
void IconFile(char *); // Set top string
char *IconFile() { return _iconFile; } // Access top string
void StateIconFile(char *); // Set top string
char *StateIconFile() { return _stateIconName; }// Access top string
void StateIconGravity(StateGravity);
StateGravity StateIconGravity() { return _state_gravity; }
void Field(int index, char *string, int width, boolean visible = true,
boolean active = true);
void Field(int index, char **string, int *width, boolean *visible,
boolean *active);
int NumberFields();
const UI_Class UIClass() { return ICON; }
const char *const UIClassName() { return "IconObj"; }
};
#endif /* ICONOBJ_H */

View File

@@ -0,0 +1,118 @@
/* $XConsortium: IconP.h /main/4 1995/11/06 09:42:03 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
/*****************************************************************************
*
* IconP.H - widget private header file
*
******************************************************************************/
#ifndef _IconP_h
#define _IconP_h
#include <Xm/XmP.h>
#include <Xm/PrimitiveP.h>
#include "Icon.h"
#ifdef __cplusplus
extern "C" {
#endif
#define Max(x, y) (((x) > (y)) ? (x) : (y))
typedef struct _IconClassPart {
int reserved;
} IconClassPart;
typedef struct _IconClassRec {
CoreClassPart core_class;
XmPrimitiveClassPart primitive_class;
IconClassPart icon_class;
} IconClassRec;
extern IconClassRec iconClassRec;
typedef struct _IconPart {
/* Public Resources */
XmString label;
XmString top_label;
XmString bottom_label;
Pixmap pixmap;
Pixmap mask;
Pixmap state_pixmap;
Pixmap state_mask;
unsigned char state_gravity;
Pixel select_color;
XmFontList font;
unsigned char alignment;
unsigned char string_direction;
unsigned char icon_placement;
unsigned char icon_shadow_type;
Boolean active;
Boolean select_color_persistent;
Boolean shrink_outline;
Boolean word_wrap;
Boolean selected;
Boolean show_selected_pixmap;
Boolean resize_width;
Boolean resize_height;
Dimension icon_shadow_thickness;
Dimension icon_margin_thickness; /* margin around widget */
XtCallbackList single_click_callback;
XtCallbackList double_click_callback;
GuiIconFields fields;
/* Private stuff */
GC gc;
GC stipple_gc;
GC selected_fg_gc;
GC selected_bg_gc;
GC mask_gc;
GC state_mask_gc;
GC mask_stipple_gc;
Pixel select_label_color;
XmString wrapped_label;
XmRegion shadow_region;
XmRegion highlight_region;
Position pixmap_x;
Position pixmap_y;
Position label_x;
Position label_y;
Position top_label_x;
Position top_label_y;
Position bottom_label_x;
Position bottom_label_y;
Position state_pixmap_x;
Position state_pixmap_y;
Dimension pixmap_width;
Dimension pixmap_height;
Dimension top_label_width;
Dimension top_label_height;
Dimension bottom_label_width;
Dimension bottom_label_height;
Dimension label_width;
Dimension label_height;
Dimension state_pixmap_width;
Dimension state_pixmap_height;
Time old_time;
Boolean old_shrink_outline;
} IconPart;
typedef struct _IconRec {
CorePart core;
XmPrimitivePart primitive;
IconPart icon;
} IconRec;
#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif
#endif /* _IconP_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,37 @@
XCOMM $XConsortium: Imakefile /main/4 1996/04/21 19:52:09 drk $
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName MotifUI
#define LibHeaders NO
#define LibInstall NO
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
INCLUDES = -I. -I..
#ifdef RsArchitecture
EXTRA_DEFINES = -DHAS_EXCEPTIONS
#endif
SRCS = Application.C Button.C ComboBoxObj.C \
Container.C Debug.c Dialog.C \
DtDND.C Group.C HelpSystem.C \
Icon.c IconObj.C LabelObj.C \
MainWindow.C Menu.C MenuBar.C \
MotifThread.C MotifUI.C Prompt.C \
ScaleObj.C Sep.C WorkArea.c
OBJS = Application.o Button.o ComboBoxObj.o \
Container.o Debug.o Dialog.o \
DtDND.o Group.o HelpSystem.o \
Icon.o IconObj.o LabelObj.o \
MainWindow.o Menu.o MenuBar.o \
MotifThread.o MotifUI.o Prompt.o \
ScaleObj.o Sep.o WorkArea.o
#include <Library.tmpl>
DependTarget()

View File

@@ -0,0 +1,69 @@
/* $XConsortium: LabelObj.C /main/2 1995/07/17 14:06:12 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "LabelObj.h"
#include <Xm/Label.h>
#include <Xm/Frame.h>
#include "WorkArea.h"
LabelObj::LabelObj(MotifUI *parent,
char *name,
LabelType style,
boolean has_border)
: MotifUI(parent, name, NULL)
{
XmString xm_string = StringCreate(name);
Widget p, super_node;
Pixel bg;
int alignment;
switch (_style = style)
{
case LEFT_JUSTIFIED: alignment = XmALIGNMENT_BEGINNING; break;
case CENTERED: alignment = XmALIGNMENT_CENTER; break;
case RIGHT_JUSTIFIED: alignment = XmALIGNMENT_END; break;
}
p = parent->InnerWidget();
if (!XtIsComposite(p))
p = XtParent(p);
XtVaGetValues(p, XmNbackground, &bg, NULL);
// If p is a icon then set superNode to it, otherwise set superNode to NULL
super_node = parent->UIClass() == ICON ? parent->BaseWidget() : NULL;
if (has_border)
{
_w = XtVaCreateManagedWidget(name, xmFrameWidgetClass, p,
XmNbackground, bg, XmNuserData, this,
XmNshadowType, XmSHADOW_OUT,
XmNshadowThickness, shadowThickness, NULL);
p = _w;
}
_label = XtVaCreateManagedWidget(name, xmLabelWidgetClass, p,
XmNlabelString, xm_string,
GuiNsuperNode, super_node,
XmNalignment, alignment,
XmNbackground, bg, XmNuserData, this, NULL);
if (!has_border)
_w = _label;
StringFree(xm_string);
}
void LabelObj::LabelStyle(LabelType style)
{
int alignment;
switch (_style = style)
{
case LEFT_JUSTIFIED: alignment = XmALIGNMENT_BEGINNING; break;
case CENTERED: alignment = XmALIGNMENT_CENTER; break;
case RIGHT_JUSTIFIED: alignment = XmALIGNMENT_END; break;
}
XtVaSetValues(_label, XmNalignment, alignment, NULL);
}

View File

@@ -0,0 +1,36 @@
/* $XConsortium: LabelObj.h /main/3 1995/11/06 09:42:24 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef LABELOBJ_H
#define LABELOBJ_H
#include "MotifUI.h"
class LabelObj : public MotifUI {
private:
Widget _label;
LabelType _style;
public:
LabelObj(MotifUI * parent,
char *name,
LabelType style = LEFT_JUSTIFIED,
boolean has_border = false);
void LabelStyle(LabelType style);
LabelType LabelStyle() { return _style; }
const Widget InnerWidget() { return _label; }
const UI_Class UIClass() { return LABEL; }
const char *const UIClassName() { return "LabelObj"; }
};
#endif /* LABELOBJ_H */

View File

@@ -0,0 +1,263 @@
/* $XConsortium: MainWindow.C /main/3 1995/11/06 09:42:36 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "MainWindow.h"
#include "Menu.h"
#include "IconObj.h"
#include "Button.h"
#include "Sep.h"
#include <Xm/MainW.h>
#include <Xm/RowColumn.h>
#include "Icon.h"
XtActionsRec MainWindow::actions[] =
{
{"PopupMenu", (XtActionProc) &MainWindow::KeyboardPopupMenu}
};
class PopupMenuContainer : public MotifUI
{
public:
PopupMenuContainer(MotifUI *);
};
PopupMenuContainer::PopupMenuContainer(MotifUI *parent) :
MotifUI(parent, "PopupMenuContainer", NULL)
{
_w = parent->BaseWidget();
}
MainWindow::MainWindow(MotifUI *parent,
char *name,
char *widgetName,
char *icon,
char *icon_name)
: MotifUI(parent, name, NULL, widgetName)
{
CreateMainWindow(parent, name, widgetName, icon, icon_name);
}
MainWindow::MainWindow(char *category,
MotifUI *parent,
char *name,
char *widgetName,
char *icon,
char *icon_name)
: MotifUI(parent, name, category, widgetName)
{
CreateMainWindow(parent, name, widgetName, icon, icon_name);
}
void MainWindow::CreateMainWindow(MotifUI *parent, char * /*name*/,
char *widgetName, char *_icon,
char *_icon_name)
{
_w = XtVaCreateManagedWidget(widgetName, xmMainWindowWidgetClass,
parent->BaseWidget(), NULL);
XtAppAddActions(appContext, actions, XtNumber(actions));
trans = XtParseTranslationTable("#override\n <Key> osfMenu: PopupMenu()");
XtAddEventHandler(_w, ButtonPressMask, FALSE, PopupMenu, (XtPointer) this);
XtOverrideTranslations(_w, trans);
popups = new PopupMenuContainer(this);
XtVaSetValues(_w, XmNuserData, this, NULL);
LastPopupMenu = NULL;
icon = NULL;
icon_name = NULL;
IconFile(_icon);
IconName(_icon_name);
InstallHelpCB();
}
MainWindow::~MainWindow()
{
delete icon;
delete icon_name;
}
void MainWindow::IconFile(char *_icon)
{
if (_icon)
{
Pixmap pixmap, mask;
GetPixmaps(_w, _icon, &pixmap, &mask);
delete icon;
if (pixmap != XmUNSPECIFIED_PIXMAP)
{
if (depth == 1)
XtVaSetValues(XtParent(_w), XmNiconPixmap, pixmap, NULL);
else
XtVaSetValues(XtParent(_w), XmNiconPixmap, pixmap,
(mask ? XmNiconMask : NULL), mask, NULL);
icon = STRDUP(_icon);
}
else
icon = NULL;
}
}
void MainWindow::IconName(char *_icon_name)
{
delete icon_name;
if (!_icon_name)
icon_name = STRDUP(Name());
else
icon_name = STRDUP(_icon_name);
if (icon_name)
XtVaSetValues(XtParent(_w), XmNiconName, icon_name, NULL);
}
void MainWindow::SetWorkWindow(MotifUI *obj)
{
XtVaSetValues(_w, XmNworkWindow, obj->BaseWidget(), NULL);
}
Button *MainWindow::AddAction(char *name, char *category,
ButtonCallback callback,
void *callback_data, char *mnemonic,
char *acceleratorText, char *accelerator)
{
Menu *menu = (Menu *)popups->FindByCategory(category);
if (!menu)
{
menu = new Menu(category, popups, true, "", "", NULL, POPUP_MENU);
XtVaSetValues(menu->InnerWidget(), XmNpopupEnabled, False, NULL);
}
return new Button(category, menu, name, PUSH_BUTTON, callback, callback_data,
mnemonic, acceleratorText, accelerator);
}
void MainWindow::RegisterPopup(MotifUI *obj)
{
Menu *menu = (Menu *)popups->FindByCategory((char *)obj->Category());
if (!menu)
{
menu = new Menu((char *)obj->Category(), popups, true, "", "",
NULL, POPUP_MENU);
XtVaSetValues(menu->InnerWidget(), XmNpopupEnabled, False, NULL);
}
XtAddEventHandler(obj->InnerWidget(), ButtonPressMask, FALSE,
PopupMenu, (XtPointer) this);
XtOverrideTranslations(obj->InnerWidget(), trans);
XtVaSetValues(obj->InnerWidget(), XmNuserData, obj, NULL);
if (obj->UIClass() == CONTAINER)
{
switch (obj->UISubClass())
{
case SCROLLED_CANVAS:
case SCROLLED_FORM:
case SCROLLED_VERTICAL_ROW_COLUMN:
case SCROLLED_HORIZONTAL_ROW_COLUMN:
case SCROLLED_PANE:
case SCROLLED_WORK_AREA:
case SCROLLED_ICON_LIST:
XtAddEventHandler(XtParent(obj->InnerWidget()), ButtonPressMask, FALSE,
PopupMenu, (XtPointer) this);
XtOverrideTranslations(XtParent(obj->InnerWidget()), trans);
XtVaSetValues(XtParent(obj->InnerWidget()), XmNuserData, obj, NULL);
break;
}
}
}
void MainWindow::AddSep(char *category)
{
Menu *menu = (Menu *)popups->FindByCategory(category);
if (!menu)
{
menu = new Menu(category, popups, true, "", "", NULL, POPUP_MENU);
XtVaSetValues(menu->InnerWidget(), XmNpopupEnabled, False, NULL);
}
new Sep(category, menu);
}
void MainWindow::KeyboardPopupMenu(Widget widget, XEvent *event,
String * /*params*/,
Cardinal * /*num_params*/)
{
Widget focus_widget;
if (!(focus_widget = XmGetFocusWidget(widget)))
focus_widget = widget;
MotifUI *obj;
MainWindow *window;
XtVaGetValues(focus_widget, XmNuserData, &obj, NULL);
window = (MainWindow *) obj;
while (window->UIClass() != MAIN_WINDOW)
window = (MainWindow *) window->Parent();
window->PostMenu(obj, event);
}
void MainWindow::PopupMenu(Widget widget, XtPointer client_data,
XEvent *event, Boolean * /*continued*/)
{
XRectangle pixmap_rect, label_rect;
XButtonEvent * ev;
Window child, parent, root;
int root_x, root_y, win_x, win_y;
unsigned int modMask;
Display * display = XtDisplay(widget);
ev = (XButtonEvent *) event;
if (ev->button != MotifUI::bMenuButton)
return;
child = XtWindow(widget);
while (child)
{
parent = child;
XQueryPointer(display, parent, &root,
&child, &root_x, &root_y, &win_x, &win_y, &modMask);
}
if (XtWindowToWidget(display, parent))
widget = XtWindowToWidget(display, parent);
MainWindow *window = (MainWindow *) client_data;
MotifUI *obj;
XtVaGetValues(widget, XmNuserData, &obj, NULL);
if (!obj)
obj = window;
if (obj->UIClass() == ICON)
{
GuiIconGetRects(widget, &pixmap_rect, &label_rect);
if (!(PointInRect(pixmap_rect, win_x, win_y) ||
PointInRect(label_rect, win_x, win_y)))
{
XtVaGetValues(XtParent(widget), XmNuserData, &obj, NULL);
}
}
window->PostMenu(obj, event);
}
void MainWindow::PostMenu(MotifUI *obj, XEvent *event)
{
BaseUI *popup_menu = popups->FindByCategory((char *)obj->Category());
if (LastPopupMenu)
XtVaSetValues(LastPopupMenu, XmNpopupEnabled, False, NULL);
Widget widget = NULL;
if (popup_menu)
{
popup_menu->Name((char *)obj->Name());
PopupObject = obj;
PopupObjectUniqueID = PopupObject->UniqueID();
widget = ((MotifUI *) popup_menu)->BaseWidget();
XtVaSetValues(widget, XmNpopupEnabled, True, NULL);
if (event->type == ButtonPress)
{
XmMenuPosition(widget, (XButtonPressedEvent *) event);
XtManageChild(widget);
}
}
else
{
PopupObject = NULL;
PopupObjectUniqueID = 0;
}
LastPopupMenu = widget;
}

View File

@@ -0,0 +1,78 @@
/* $XConsortium: MainWindow.h /main/3 1995/11/06 09:42:47 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "MotifUI.h"
class PopupMenuContainer;
class Button;
class MainWindow : public MotifUI {
friend void KeyboardPopupMenu(Widget, XEvent *, String *, Cardinal *);
friend void PopupMenu(Widget, XtPointer, XEvent *, Boolean *);
protected:
static XtActionsRec actions[];
static void KeyboardPopupMenu(Widget, XEvent *, String *, Cardinal *);
static void PopupMenu(Widget, XtPointer, XEvent *, Boolean *);
void PostMenu(MotifUI *, XEvent *);
PopupMenuContainer *popups;
Widget LastPopupMenu;
XtTranslations trans;
char *icon;
char *icon_name;
// Derived classes must define Initialize
virtual void Initialize() = 0;
void CreateMainWindow(MotifUI *parent, char *name, char *widgetName,
char *icon, char *icon_name);
public:
MainWindow(MotifUI *parent,
char *name,
char *widgetName,
char *icon = NULL,
char *icon_name = NULL);
MainWindow(char *category,
MotifUI *parent,
char *name,
char *widgetName,
char *icon = NULL,
char *icon_name = NULL);
virtual ~MainWindow();
void IconFile(char *icon);
void IconName(char *icon_name);
char *IconFile() { return icon; }
char *IconName() { return icon_name; }
Button *AddAction(char *name, char *category, ButtonCallback callback,
void *callback_data, char *mnemonic = NULL,
char *acceleratorText = NULL, char *accelerator = NULL);
void RegisterPopup(MotifUI *object);
void AddSep(char *category);
void SetWorkWindow(MotifUI *obj);
BaseUI *PopupObject;
int PopupObjectUniqueID;
const UI_Class UIClass() { return MAIN_WINDOW; }
const char *const UIClassName() { return "MainWindow"; }
};
#endif /* MAINWINDOW_H */

View File

@@ -0,0 +1,136 @@
/* $XConsortium: Menu.C /main/3 1995/11/06 09:42:58 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Menu.h"
#include "MainWindow.h"
#include <Xm/RowColumn.h>
#include <Xm/Label.h>
#include <Xm/Separator.h>
#include <Xm/CascadeB.h>
Menu::Menu(MotifUI *parent, char *name, char *mnemonic, MenuType menu_type)
: MotifUI(parent, name, NULL)
{
CreateMenu(parent->InnerWidget(), name, NULL, mnemonic, menu_type);
}
Menu::Menu(MotifUI *parent, boolean /*has_title*/, char *title,
char *name, char *mnemonic, MenuType menu_type)
: MotifUI(parent, name, NULL)
{
CreateMenu(parent->InnerWidget(), name, NULL, mnemonic, menu_type);
CreateTitle(parent->InnerWidget(), NULL, title);
}
Menu::Menu(char *category, MotifUI *parent, char *name, char *mnemonic,
MenuType menu_type)
: MotifUI(parent, name, category)
{
CreateMenu(parent->InnerWidget(), name, category, mnemonic, menu_type);
}
Menu::Menu(char *category, MotifUI *parent, boolean /*has_title*/,
char *title, char *name, char *mnemonic, MenuType menu_type)
: MotifUI(parent, name, category)
{
CreateMenu(parent->InnerWidget(), name, category, mnemonic, menu_type);
CreateTitle(parent->InnerWidget(), category, title);
}
void Menu::SetRadio(boolean flag)
{
XtVaSetValues(_w, XmNradioBehavior, flag, NULL);
}
boolean Menu::SetActivity(boolean flag)
{
XtSetSensitive(_cascadeButton, flag);
return true;
}
void Menu::CreateMenu(Widget parent, char *name, char * /*category*/,
char *mnemonic, MenuType menu_type)
{
XmString xm_string = StringCreate(name);
_title = NULL;
_sep = NULL;
switch (_menu_type = menu_type)
{
case PULLDOWN_MENU:
_w = XmCreatePulldownMenu(parent, "pulldown_menu", NULL, 0);
break;
case OPTION_MENU:
_w = XmCreateOptionMenu(parent, "option_menu", NULL, 0);
break;
case POPUP_MENU:
_w = XmCreatePopupMenu(parent, "popup_menu", NULL, 0);
XtVaSetValues(_w, XmNwhichButton, MotifUI::bMenuButton, NULL);
break;
}
if (_menu_type != POPUP_MENU)
{
_cascadeButton = XtVaCreateManagedWidget("cascadeButton",
xmCascadeButtonWidgetClass,
parent,
XmNlabelString, xm_string,
XmNsubMenuId, _w, NULL);
if (depth == 1)
{
Pixel bg;
XtVaGetValues(_cascadeButton, XmNbackground, &bg, NULL);
if (bg == white)
{
XtVaSetValues(_w, XmNuserData, (XtPointer)this, NULL);
XtAddCallback(_w, XmNmapCallback, &(Menu::MapCB), NULL);
XtAddCallback(_w, XmNunmapCallback, &(Menu::MapCB), NULL);
}
}
}
StringFree(xm_string);
if (mnemonic)
XtVaSetValues(_cascadeButton,
XmNmnemonic, XStringToKeysym(mnemonic), NULL);
InstallHelpCB();
}
void Menu::CreateTitle(Widget /*parent*/, char *title, char * /*category*/)
{
XmString xm_string = StringCreate(title);
if (_title)
XtVaSetValues(_title, XmNlabelString, xm_string, NULL);
else
{
_title = XtVaCreateManagedWidget("title", xmLabelWidgetClass, _w,
XmNlabelString, xm_string, NULL);
_sep = XtVaCreateManagedWidget("separator", xmSeparatorWidgetClass, _w,
XmNseparatorType, XmDOUBLE_LINE, NULL);
}
StringFree(xm_string);
}
boolean Menu::SetName(char *name)
{
CreateTitle(_w, name, (char *) Category());
return true;
}
void Menu::MapCB(Widget w, XtPointer /*client_data*/, XtPointer /*call_data*/)
{
Menu *obj;
XtVaGetValues(w, XmNuserData, &obj, NULL);
Pixel fg;
XtVaGetValues(obj->_cascadeButton, XmNforeground, &fg, NULL);
if (fg == white)
fg = black;
else
fg = white;
XtVaSetValues(obj->_cascadeButton, XmNforeground, fg, NULL);
}

View File

@@ -0,0 +1,66 @@
/* $XConsortium: Menu.h /main/3 1995/11/06 09:43:09 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef MENU_H
#define MENU_H
#include "MotifUI.h"
class Menu : public MotifUI {
static void MapCB(Widget, XtPointer, XtPointer);
friend void MapCB(Widget, XtPointer, XtPointer);
protected:
Widget _cascadeButton;
Widget _title;
Widget _sep;
MenuType _menu_type;
void CreateMenu(Widget parent, char *name, char *category,
char *mnemonic, MenuType menu_type);
void CreateTitle(Widget, char *title, char *category);
boolean SetName(char *name);
public:
Menu(char *category,
MotifUI *parent,
char *name,
char *mnemonic = NULL,
MenuType menu_type = PULLDOWN_MENU);
Menu(char *category,
MotifUI *parent,
boolean has_title,
char *title,
char *name,
char *mnemonic = NULL,
MenuType menu_type = PULLDOWN_MENU);
Menu(MotifUI *parent,
char *name,
char *mnemonic = NULL,
MenuType menu_type = PULLDOWN_MENU);
Menu(MotifUI *parent,
boolean has_title,
char *title,
char *name,
char *mnemonic = NULL,
MenuType menu_type = PULLDOWN_MENU);
void SetRadio(boolean flag);
Widget GetCascade() { return _cascadeButton; }
boolean SetActivity(boolean flag);
const UI_Class UIClass() { return MENU; }
const int UISubClass() { return _menu_type; }
const char *const UIClassName() { return "Menu"; }
};
#endif /* MENU_H */

View File

@@ -0,0 +1,33 @@
/* $XConsortium: MenuBar.C /main/2 1995/07/17 14:06:37 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "MenuBar.h"
#include "Menu.h"
#include <Xm/RowColumn.h>
MenuBar::MenuBar(MotifUI *parent,
char *name)
: MotifUI(parent, name, NULL)
{
_w = XtVaCreateManagedWidget("menuBar", xmRowColumnWidgetClass,
parent->InnerWidget(),
XmNrowColumnType, XmMENU_BAR, NULL);
XtVaSetValues(parent->InnerWidget(), XmNmenuBar, _w, NULL);
InstallHelpCB();
}
void MenuBar::SetHelpMenu(Menu *menu)
{
XtVaSetValues(_w, XmNmenuHelpWidget, menu->GetCascade(), NULL);
}
MenuBar::~MenuBar()
{
// Empty
}

View File

@@ -0,0 +1,30 @@
/* $XConsortium: MenuBar.h /main/3 1995/11/06 09:43:42 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef MENUBAR_H
#define MENUBAR_H
#include "MotifUI.h"
class Menu;
class MenuBar : public MotifUI {
public:
MenuBar(MotifUI *parent,
char *name = "MenuBar");
virtual ~MenuBar();
void SetHelpMenu(Menu *);
const UI_Class UIClass() { return MENU_BAR; }
const char *const UIClassName() { return "MenuBar"; }
};
#endif /* MENUBAR_H */

View File

@@ -0,0 +1,161 @@
/* $TOG: MotifThread.C /main/3 1998/07/24 16:15:54 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "MotifThread.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
MotifThread::MotifThread(MotifUI *obj, const char *cmd,
MotifThreadCallback cb, ThreadCallback cb1,
int buf_len)
{
CreateThread(obj, cmd, -1, -1, cb, cb1, buf_len);
}
MotifThread::MotifThread(MotifUI *obj, int pid, int fd,
MotifThreadCallback cb, ThreadCallback cb1,
int buf_len)
{
CreateThread(obj, NULL, pid, fd, cb, cb1, buf_len);
}
MotifThread::MotifThread(MotifUI *obj, int socket,
MotifThreadCallback cb, ThreadCallback cb1,
int buf_len)
{
CreateThread(obj, NULL, -1, socket, cb, cb1, buf_len);
}
void MotifThread::CreateThread(MotifUI *_obj, const char *cmd, int _pid,
int _fd, MotifThreadCallback _cb,
ThreadCallback _cb1, int _buf_len)
{
int m_stdout[2];
cb = _cb;
cb1 = _cb1;
obj = _obj;
output = NULL;
out1 = NULL;
inputID = 0;
if (_buf_len < 0)
buf_len = 512;
else
buf_len = _buf_len;
if (cmd)
{
fd = -1;
if (pipe(m_stdout) < 0)
{
output = strdup(strerror(errno));
status = -1;
Halt();
return;
}
if ((pid = fork()) == 0) // In Child
{
close(m_stdout[0]);
close(1);
dup(m_stdout[1]);
close(m_stdout[1]);
execlp("/bin/ksh", "ksh", "-c", cmd, NULL);
char *msg = strerror(errno);
write(1, msg, strlen(msg));
exit(-1);
}
else if (pid == -1)
{
close(m_stdout[0]);
output = strdup(strerror(errno));
status = -1;
Halt();
return;
}
close(m_stdout[1]);
fd = m_stdout[0];
}
else
{
pid = (pid_t)_pid;
fd = _fd;
}
fcntl(fd, F_SETFL, O_NDELAY);
len = buf_len;
ctr = 1;
output = (char *)malloc(buf_len);
out1 = output;
out2 = out1 + buf_len - 1;
long mask = XtInputReadMask | XtInputExceptMask;
inputID = XtAppAddInput(obj->appContext, fd, (XtPointer)mask,
&(MotifThread::GetOutputCB), this);
}
MotifThread::~MotifThread()
{
if (fd >= 0)
Halt();
if (inputID)
XtRemoveInput(inputID);
free(output);
}
void MotifThread::Halt()
{
if (out1)
*out1 = '\0';
close(fd);
fd = -1;
if (pid != -1)
{
pid_t w;
while ((w = wait(&status)) != pid && w != -1);
status = (status >> 8) & 0xFF;
}
else
status = 0;
(*cb)(this, obj, cb1);
}
void MotifThread::GetOutput()
{
int n = read(fd, out1, len);
if (n == len)
{
len = buf_len;
ctr++;
output = (char *)realloc(output, (ctr * len));
out1 = output + ((ctr - 1) * len);
out2 = out1 + len - 1;
}
else if (n > 0)
{
out1 += n;
len = out2 - out1 + 1;
}
else
Halt();
}
void MotifThread::GetOutputCB(XtPointer closure, int * /*fid*/,
XtInputId * /*id*/)
{
MotifThread *obj = (MotifThread *)closure;
obj->GetOutput();
}

View File

@@ -0,0 +1,55 @@
/* $XConsortium: MotifThread.h /main/3 1995/11/06 09:43:54 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef MOTIF_THREAD_H
#define MOTIF_THREAD_H
#include "MotifUI.h"
class MotifThread;
class MotifUI;
typedef void (*MotifThreadCallback) (MotifThread *, BaseUI *, ThreadCallback);
class MotifThread
{
friend void GetOutputCB(XtPointer, int *fid, XtInputId *id);
private:
MotifThreadCallback cb;
ThreadCallback cb1;
XtInputId inputID;
pid_t pid;
int buf_len;
int fd;
int len;
int ctr;
char *out1;
char *out2;
MotifUI *obj;
static void GetOutputCB(XtPointer, int *fid, XtInputId *id);
void GetOutput();
void CreateThread(MotifUI *, const char *, int, int,
MotifThreadCallback, ThreadCallback, int);
public:
char *output;
int status;
MotifThread(MotifUI *, const char *cmd, MotifThreadCallback, ThreadCallback,
int buf_len);
MotifThread(MotifUI *, int pid, int fd, MotifThreadCallback, ThreadCallback,
int buf_len);
MotifThread(MotifUI *, int socket, MotifThreadCallback, ThreadCallback,
int buf_len);
~MotifThread();
void Halt();
};
#endif // MOTIF_THREAD_H

View File

@@ -0,0 +1,987 @@
/* $TOG: MotifUI.C /main/8 1998/08/03 08:59:09 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "MotifUI.h"
#include "Menu.h"
#include "Dialog.h"
#include "Icon.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <X11/cursorfont.h>
#include <X11/IntrinsicP.h>
#ifdef NO_CDE
#include "xpm.h"
#include <X11/keysym.h>
#else
#include <Dt/xpm.h>
#include <Dt/Help.h>
#endif
#include <Xm/ToggleB.h>
#include <Xm/RowColumn.h>
#include <Xm/ScrolledW.h>
#include <Xm/MainW.h>
PixmapLookupList MotifUI::pixmap_table = NULL;
XtAppContext MotifUI::appContext = NULL;
XmFontList MotifUI::userFont = NULL;
Display * MotifUI::display = NULL;
Widget MotifUI::topLevel;
Window MotifUI::root;
Font MotifUI::font;
Pixel MotifUI::black;
Pixel MotifUI::white;
int MotifUI::shadowThickness;
int MotifUI::depth;
int MotifUI::bMenuButton;
int MotifUI::n_pixmaps = 0;
PointerCursor MotifUI::pointer_style = LEFT_SLANTED_ARROW_CURSOR;
MotifUI::MotifUI(MotifUI *parent,
const char *name,
const char *category,
const char *widgetName)
: BaseUI(parent, name, category)
{
_w = NULL;
if (widgetName)
_widgetName = STRDUP(widgetName);
else
_widgetName = STRDUP(name);
}
MotifUI::~MotifUI()
{
if (_w)
XtRemoveCallback(_w, XmNdestroyCallback, &MotifUI::WidgetDestroyCB,
(XtPointer) this);
delete _widgetName;
}
void MotifUI::ThreadCB(MotifThread *_thread, BaseUI *obj, ThreadCallback cb)
{
(*cb)(obj, _thread->output, _thread->status);
delete _thread;
}
void MotifUI::Thread(const char *cmd, ThreadCallback cb, int buf_len)
{
new MotifThread(this, cmd, &(MotifUI::ThreadCB), cb, buf_len);
}
void MotifUI::Thread(int pid, int fd, ThreadCallback cb, int buf_len)
{
new MotifThread(this, pid, fd, &(MotifUI::ThreadCB), cb, buf_len);
}
void MotifUI::Thread(int socket, ThreadCallback cb, int buf_len)
{
new MotifThread(this, socket, &(MotifUI::ThreadCB), cb, buf_len);
}
void MotifUI::SetFocus()
{
DoSetFocus(_w);
}
void MotifUI::DoSetFocus(Widget w)
{
XmProcessTraversal(w, XmTRAVERSE_CURRENT);
}
boolean MotifUI::DoIsVisible()
{
boolean rc = true;
if (_w)
{
if (UIClass() == APPLICATION)
{
if (XtIsRealized(_w))
{
XWindowAttributes attributes;
XGetWindowAttributes(display, XtWindow(_w), &attributes);
if (attributes.map_state == IsUnmapped)
rc = false;
}
}
else if (XmGetVisibility(_w) == XmVISIBILITY_FULLY_OBSCURED)
rc = false;
}
return rc;
}
void MotifUI::DoMakeVisible()
{
Widget sw = XtParent(_w);
if (sw && !XmIsScrolledWindow(sw))
sw = XtParent(sw);
if (sw && !XmIsScrolledWindow(sw))
sw = XtParent(sw);
if (sw && XmIsScrolledWindow(sw) && !XmIsMainWindow(sw))
XmScrollVisible(sw, _w, 0, 0);
}
void MotifUI::DoContextualHelp()
{
Widget context_widget, shell;
#ifdef NO_CDE
XEvent event;
static Cursor cursor = (Cursor) NULL;
if (cursor == (Cursor) NULL)
cursor = XCreateFontCursor(display, XC_question_arrow);
#endif
BaseUI *window = this;
while (window->UIClass() != MAIN_WINDOW)
window = window->Parent();
shell = ((MotifUI *)window)->_w;
#ifdef NO_CDE
context_widget = XmTrackingEvent(shell, cursor, False, &event);
if (event.type == KeyPress || event.type == KeyRelease)
{
int offset;
KeySym keySym;
// Look for ESC key press and stop if we get one
if (event.xkey.state & ShiftMask)
offset = 1;
else
offset = 0;
keySym = XLookupKeysym((XKeyEvent *)&event, offset);
if (keySym == XK_Escape)
return;
}
if (context_widget != NULL)
{
#else
int returnVal = DtHelpReturnSelectedWidgetId(shell, NULL, &context_widget);
if (returnVal == DtHELP_SELECT_VALID)
{
#endif
XmAnyCallbackStruct cb;
cb.reason = XmCR_HELP;
#ifdef NO_CDE
cb.event = &event;
#endif
while (context_widget != NULL)
{
// If there is no help at this widget, back track to find help
if (XtHasCallbacks(context_widget, XmNhelpCallback) ==
XtCallbackHasSome)
{
XtCallCallbacks(context_widget, XmNhelpCallback, &cb);
break;
}
else
context_widget = XtParent(context_widget);
}
}
}
void MotifUI::WidgetHelpCB(Widget,
XtPointer clientData,
XtPointer)
{
MotifUI * obj = (MotifUI *) clientData;
obj->HandleHelpRequest();
}
void MotifUI::WidgetDestroyCB(Widget,
XtPointer clientData,
XtPointer)
{
MotifUI * obj = (MotifUI *) clientData;
obj->WidgetDestroyed();
}
void MotifUI::WidgetDestroyed()
{
_w = NULL;
delete _widgetName;
}
void MotifUI::DoRefresh()
{
if (_w)
XmUpdateDisplay(_w);
}
void MotifUI::DoToFront()
{
if (_w)
{
if (XtIsShell(XtParent(_w)))
XRaiseWindow(display, XtWindow(XtParent(_w)));
else
XRaiseWindow(display, XtWindow(_w));
}
}
void MotifUI::InstallDestroyCB()
{
if (_w)
XtAddCallback(_w, XmNdestroyCallback, &MotifUI::WidgetDestroyCB,
(XtPointer) this);
}
void MotifUI::InstallHelpCB()
{
if (!_w)
return;
if (UIClass() == MENU && UISubClass() != POPUP_MENU)
XtAddCallback(((Menu*)this)->GetCascade(), XmNhelpCallback,
&MotifUI::WidgetHelpCB, (XtPointer) this);
else
XtAddCallback(_w, XmNhelpCallback, &MotifUI::WidgetHelpCB,
(XtPointer) this);
}
boolean MotifUI::SetSelected(boolean flag)
{
if (!_w)
return false;
if (GuiIsIcon(_w))
XtVaSetValues(_w, GuiNselected, flag, NULL);
else if (XmIsToggleButton(_w))
XmToggleButtonSetState(_w, flag, False);
return true;
}
boolean MotifUI::SetName(char *name)
{
if (!InnerWidget())
return false;
XmString xm_string = StringCreate(name);
XtVaSetValues(InnerWidget(), XmNlabelString, xm_string, NULL);
StringFree(xm_string);
return true;
}
boolean MotifUI::SetActivity(boolean flag)
{
if (!_w)
return false;
if (GuiIsIcon(_w))
XtVaSetValues(_w, GuiNactive, flag, NULL);
else
XtSetSensitive(_w, flag);
return true;
}
boolean MotifUI::SetVisiblity(boolean flag)
{
if (!_w)
return false;
if (flag)
XtManageChild(_w);
else
XtUnmanageChild(_w);
return true;
}
void MotifUI::GetResources(const XtResourceList resources,
const int numResources)
{
if (_w && resources)
XtGetSubresources(XtParent(_w), (XtPointer) this, _widgetName,
className(), resources, numResources, NULL, 0);
}
void MotifUI::SetDefaultResources(const Widget,
const String *resources)
{
XrmDatabase rdb = NULL;
int i;
rdb = XrmGetStringDatabase("");
i = 0;
while (resources[i])
{
char *buf = new char[1000];
sprintf(buf, "%s%s", _name, resources[i]);
XrmPutLineResource(&rdb, buf);
i++;
delete [] buf;
}
if (rdb)
{
XrmMergeDatabases(XtDatabase(display), &rdb);
XrmSetDatabase(display, rdb);
}
}
void MotifUI::NotifyDelete(BaseUI *obj)
{
MotifUI *p = (MotifUI *) obj;
if (p->_w)
{
XtRemoveCallback(_w, XmNdestroyCallback, &MotifUI::WidgetDestroyCB,
(XtPointer) this);
XtDestroyWidget(p->_w);
p->_w = NULL;
}
}
void MotifUI::Width(int width)
{
XtVaSetValues(this->BaseWidget(), XmNwidth, width, NULL);
}
int MotifUI::Width()
{
Dimension w;
XtVaGetValues(this->BaseWidget(), XmNwidth, &w, NULL);
return (int) w;
}
void MotifUI::Height(int height)
{
XtVaSetValues(this->BaseWidget(), XmNheight, height, NULL);
}
int MotifUI::Height()
{
Dimension h;
XtVaGetValues(this->BaseWidget(), XmNheight, &h, NULL);
return (int) h;
}
void MotifUI::WidthHeight(int width, int height)
{
XtVaSetValues(this->BaseWidget(), XmNwidth, width, XmNheight, height, NULL);
}
void MotifUI::WidthHeight(int *width, int *height)
{
Dimension w, h;
XtVaGetValues(this->BaseWidget(), XmNwidth, &w, XmNheight, &h, NULL);
*width = (int) w;
*height = (int) h;
}
void MotifUI::AttachAll(int offset)
{
XtVaSetValues(this->BaseWidget(),
XmNtopAttachment, XmATTACH_NONE,
XmNbottomAttachment, XmATTACH_NONE,
XmNleftAttachment, XmATTACH_NONE,
XmNrightAttachment, XmATTACH_NONE,
NULL);
XtVaSetValues(this->BaseWidget(),
XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, offset,
XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, offset,
XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, offset,
XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, offset,
NULL);
}
void MotifUI::AttachTop(int offset)
{
XtVaSetValues(this->BaseWidget(), XmNtopAttachment, XmATTACH_NONE, NULL);
XtVaSetValues(this->BaseWidget(), XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, offset, NULL);
}
void MotifUI::AttachBottom(int offset)
{
XtVaSetValues(this->BaseWidget(), XmNbottomAttachment, XmATTACH_NONE, NULL);
XtVaSetValues(this->BaseWidget(), XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, offset, NULL);
}
void MotifUI::AttachLeft(int offset)
{
XtVaSetValues(this->BaseWidget(), XmNleftAttachment, XmATTACH_NONE, NULL);
XtVaSetValues(this->BaseWidget(), XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, offset, NULL);
}
void MotifUI::AttachRight(int offset)
{
XtVaSetValues(this->BaseWidget(), XmNrightAttachment, XmATTACH_NONE, NULL);
XtVaSetValues(this->BaseWidget(), XmNrightAttachment, XmATTACH_FORM,
XmNrightOffset, offset, NULL);
}
void MotifUI::AttachTop(BaseUI *obj, int offset, boolean opposite)
{
XtVaSetValues(this->BaseWidget(), XmNtopAttachment, XmATTACH_NONE, NULL);
if (obj)
{
Widget w = ((MotifUI *)obj)->BaseWidget();
int attachment;
if (opposite)
attachment = XmATTACH_OPPOSITE_WIDGET;
else
attachment = XmATTACH_WIDGET;
XtVaSetValues(this->BaseWidget(), XmNtopAttachment, attachment,
XmNtopWidget, w, XmNtopOffset, offset, NULL);
}
}
void MotifUI::AttachBottom(BaseUI *obj, int offset, boolean opposite)
{
XtVaSetValues(this->BaseWidget(), XmNbottomAttachment, XmATTACH_NONE, NULL);
if (obj)
{
Widget w = ((MotifUI *)obj)->BaseWidget();
int attachment;
if (opposite)
attachment = XmATTACH_OPPOSITE_WIDGET;
else
attachment = XmATTACH_WIDGET;
XtVaSetValues(this->BaseWidget(), XmNbottomAttachment, attachment,
XmNbottomWidget, w, XmNbottomOffset, offset, NULL);
}
}
void MotifUI::AttachLeft(BaseUI *obj, int offset, boolean opposite)
{
XtVaSetValues(this->BaseWidget(), XmNleftAttachment, XmATTACH_NONE, NULL);
if (obj)
{
int attachment;
if (opposite)
attachment = XmATTACH_OPPOSITE_WIDGET;
else
attachment = XmATTACH_WIDGET;
Widget w = ((MotifUI *)obj)->BaseWidget();
XtVaSetValues(this->BaseWidget(), XmNleftAttachment, attachment,
XmNleftWidget, w, XmNleftOffset, offset, NULL);
}
}
void MotifUI::AttachRight(BaseUI *obj, int offset, boolean opposite)
{
XtVaSetValues(this->BaseWidget(), XmNrightAttachment, XmATTACH_NONE, NULL);
if (obj)
{
Widget w = ((MotifUI *)obj)->BaseWidget();
int attachment;
if (opposite)
attachment = XmATTACH_OPPOSITE_WIDGET;
else
attachment = XmATTACH_WIDGET;
XtVaSetValues(this->BaseWidget(), XmNrightAttachment, attachment,
XmNrightWidget, w, XmNrightOffset, offset, NULL);
}
}
void MotifUI::StringWidthHeight(const char *string, int *width, int *height)
{
Dimension w, h;
XmString xm_string = StringCreate((char *)string);
XmStringExtent(userFont, xm_string, &w, &h);
*width = w;
*height = h;
StringFree(xm_string);
}
int MotifUI::StringWidth(const char *string)
{
int dummy;
int width;
StringWidthHeight(string, &width, &dummy);
return width;
}
int MotifUI::StringHeight(const char *string)
{
int dummy;
int height;
StringWidthHeight(string, &dummy, &height);
return height;
}
boolean MotifUI::SetOrder(int new_position)
{
if (XmIsRowColumn(((MotifUI *)Parent())->InnerWidget()))
XtVaSetValues(BaseWidget(), XmNpositionIndex, new_position, NULL);
return true;
}
void MotifUI::Dump(boolean verbose,
int level)
{
if (verbose)
{
BaseUI::Dump(true, level);
int i;
for (i = -2; i < level; i++) printf(" ");
printf("BaseWidget : %08lx\n", _w);
}
else
BaseUI::Dump(false, level);
}
// Time out stuff
typedef struct
{
TimeOutCallback fp;
BaseUI *obj;
void *callback_data;
} TimeOutCallbackData;
static void
ObjectTimeProc(XtPointer callback_data, XtIntervalId * /*id*/)
{
TimeOutCallbackData *data = (TimeOutCallbackData *) callback_data;
(*data->fp)(data->obj, data->callback_data);
delete data;
data = NULL;
}
void MotifUI::SetAddTimeOut(TimeOutCallback timeoutCB,
void *callback_data,
long interval)
{
if (!_w)
return;
TimeOutCallbackData * data = new TimeOutCallbackData;
data->fp = timeoutCB;
data->obj = this;
data->callback_data = callback_data;
XtAppAddTimeOut(appContext, (unsigned long) interval, ObjectTimeProc, data);
}
void MotifUI::FillBackground(Widget widget, Pixmap pixmap, Pixmap mask)
{
static Pixmap temp = 0L;
static GC gc = 0L;
static unsigned int old_width = 0, old_height = 0, old_depth = 0;
unsigned int width, height, junk, dep;
Window root;
XGCValues xgc;
XGetGeometry(display, pixmap, &root, (int *) &junk,
(int *) &junk, &width, &height, &junk, &dep);
if (temp &&
(old_width < width || old_height < height || old_depth != dep))
{
// Free resources
XFreeGC(display, gc);
XFreePixmap(display, temp);
temp = 0L;
gc = 0L;
}
old_width = width;
old_height = height;
old_depth = dep;
if (dep == 1 && UIClass() == MAIN_WINDOW)
XtVaGetValues(widget, XmNforeground, &xgc.foreground, NULL);
else
XtVaGetValues(widget, XmNbackground, &xgc.foreground, NULL);
if (!temp)
{
temp = XCreatePixmap(display, RootWindowOfScreen(XtScreen(widget)),
width, height, dep);
xgc.function = GXcopy;
gc = XCreateGC(display, pixmap, GCForeground|GCFunction, &xgc);
}
else
XSetForeground(display, gc, xgc.foreground);
XFillRectangle(display, temp, gc, 0, 0, width, height);
if (mask != XmUNSPECIFIED_PIXMAP)
XSetClipMask(display, gc, mask);
else
XSetClipMask(display, gc, None);
XCopyArea(display, pixmap, temp, gc, 0, 0, width, height, 0, 0);
XSetClipMask(display, gc, None);
XCopyArea(display, temp, pixmap, gc, 0, 0, width, height, 0, 0);
}
// Pixmap caching utility
void MotifUI::GetPixmaps(Widget w,
char *name,
Pixmap *pixmap,
Pixmap *mask)
{
// Try to find pixmap in cache
PixmapLookupList pixmaps = pixmap_table;
int i;
for (i = 0; i < n_pixmaps; i++, pixmaps++)
if (!strcmp((**pixmaps).name, name))
{
*pixmap = (**pixmaps).pixmap;
if (mask)
*mask = (**pixmaps).mask;
return;
}
Pixmap _mask;
char *s;
SubstitutionRec subs[1];
char *bmPath;
char *PIXMAP_DIR = "/usr/dt/appconfig/icons/%L/%B:"
"/usr/dt/appconfig/icons/C/%B:"
"/usr/include/X11/bitmaps/%B";
if (*name == '/')
s = name;
else
{
#ifdef NO_CDE
if ((s = getenv("XBMLANGPATH")) && *s)
#else
if ((s = getenv("XMICONSEARCHPATH")) && *s)
#endif
{
bmPath = new char [strlen(s) + strlen(PIXMAP_DIR) + 2];
sprintf(bmPath, "%s:%s", PIXMAP_DIR, s);
}
else
bmPath = PIXMAP_DIR;
subs[0].match = 'B';
subs[0].substitution = name;
s = XtFindFile(bmPath, subs, XtNumber(subs), NULL);
if (bmPath != PIXMAP_DIR)
delete [] bmPath;
}
struct stat statbuf;
if (!s || stat(s, &statbuf) < 0)
{
*pixmap = XmUNSPECIFIED_PIXMAP;
if (mask)
*mask = XmUNSPECIFIED_PIXMAP;
return;
}
int len = strlen(s);
if (!strcmp(s + len - 3, ".pm"))
{
XpmAttributes attributes;
memset((char *)&attributes, 0, sizeof(XpmAttributes));
#ifdef NO_CDE
XpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes);
#else
_DtXpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes);
#endif
if (_mask)
FillBackground(w, *pixmap, _mask);
#ifdef NO_CDE
XpmFreeAttributes(&attributes);
#else
_DtXpmFreeAttributes(&attributes);
#endif
}
else
{
if (UIClass() == MAIN_WINDOW)
*pixmap = XmGetPixmapByDepth(XtScreen(w), s, white, black, depth);
else
*pixmap = XmGetPixmapByDepth(XtScreen(w), s, black, white, depth);
char *s1 = new char [len + 3];
strcpy(s1, s);
strcpy(s1 + len - 3, "_m.bm");
if (stat(s1, &statbuf) < 0)
_mask = XmUNSPECIFIED_PIXMAP;
else
{
_mask = XmGetPixmapByDepth(XtScreen(w), s1, white, black, 1);
FillBackground(w, *pixmap, _mask);
}
delete [] s1;
}
if (mask)
*mask = _mask;
if (s != name)
XtFree(s);
// Add pixmap to table
if (!(n_pixmaps % 8))
{
pixmaps = new PixmapLookup [n_pixmaps + 8];
for (i = 0; i < n_pixmaps; i++)
pixmaps[i] = pixmap_table[i];
for (i = n_pixmaps; i < n_pixmaps + 8; i++)
pixmaps[i] = new PixmapLookupStruct;
delete []pixmap_table;
pixmap_table = pixmaps;
}
pixmap_table[n_pixmaps]->name = strdup(name);
pixmap_table[n_pixmaps]->pixmap = *pixmap;
pixmap_table[n_pixmaps]->mask = _mask;
n_pixmaps++;
}
// Cursor Shape support
#define time32_width 32
#define time32_height 32
#define time32_x_hot 15
#define time32_y_hot 15
static unsigned char time32_bits[] = {
0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
#define time32m_width 32
#define time32m_height 32
static unsigned char time32m_bits[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
#define time16_x_hot 7
#define time16_y_hot 7
#define time16_width 16
#define time16_height 16
static unsigned char time16_bits[] = {
0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
#define time16m_width 16
#define time16m_height 16
static unsigned char time16m_bits[] = {
0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
Cursor MotifUI::InitHourGlassCursor()
{
unsigned int width;
unsigned int height;
unsigned int xHotspot;
unsigned int yHotspot;
Pixmap pixmap;
Pixmap maskPixmap;
XColor xcolors[2];
char * bits;
char * maskBits;
Cursor cursor = None;
if (XQueryBestCursor(display, root, 32, 32, &width, &height))
{
if ((width >= 32) && (height >= 32))
{
width = time32_width;
height = time32_height;
bits = (char *)time32_bits;
maskBits = (char *)time32m_bits;
xHotspot = time32_x_hot;
yHotspot = time32_y_hot;
}
else
{
width = time16_width;
height = time16_height;
bits = (char *)time16_bits;
maskBits = (char *)time16m_bits;
xHotspot = time16_x_hot;
yHotspot = time16_y_hot;
}
pixmap = XCreateBitmapFromData(display, root, bits, width, height);
maskPixmap = XCreateBitmapFromData(display, root, maskBits,
width, height);
xcolors[0].pixel = black;
xcolors[1].pixel = white;
XQueryColors(display,
DefaultColormapOfScreen(DefaultScreenOfDisplay (display)),
xcolors, 2);
cursor = XCreatePixmapCursor(display, pixmap, maskPixmap,
&(xcolors[0]), &(xcolors[1]), xHotspot, yHotspot);
XFreePixmap(display, pixmap);
XFreePixmap(display, maskPixmap);
}
return cursor;
}
PointerCursor MotifUI::PointerShape()
{
return pointer_style;
}
void MotifUI::PointerShape(PointerCursor style)
{
static Cursor left = (Cursor) 0L;
static Cursor right = (Cursor) 0L;
static Cursor watch = (Cursor) 0L;
static Cursor hour_glass = (Cursor) 0L;
static Cursor ibeam = (Cursor) 0L;
static Cursor cross_hair = (Cursor) 0L;
if (!_w)
return;
Cursor cursor;
switch (pointer_style = style)
{
case LEFT_SLANTED_ARROW_CURSOR:
if (!left)
left = XCreateFontCursor(display, XC_left_ptr);
cursor = left;
break;
case RIGHT_SLANTED_ARROW_CURSOR:
if (!right)
right = XCreateFontCursor(display, XC_right_ptr);
cursor = right;
break;
case WATCH_CURSOR:
if (!watch)
watch = XCreateFontCursor(display, XC_watch);
cursor = watch;
break;
case HOUR_GLASS_CURSOR:
if (!hour_glass)
hour_glass = InitHourGlassCursor();
cursor = hour_glass;
break;
case IBEAM_CURSOR:
if (!ibeam)
ibeam = XCreateFontCursor(display, XC_xterm);
cursor = ibeam;
break;
case CROSS_HAIRS_CURSOR:
if (!cross_hair)
cross_hair = XCreateFontCursor(display, XC_crosshair);
cursor = cross_hair;
break;
default: cursor = None; break;
}
if (XtIsRealized(_w))
XDefineCursor(display, XtWindow(_w), cursor);
}
static int G_width;
static void VerbosePass1(Widget w, int level)
{
int i;
if (level == 0)
G_width = 0;
int new_width = (level * 3) + strlen(XrmQuarkToString(w->core.xrm_name)) +
strlen(w->core.widget_class->core_class.class_name) + 3;
if (new_width > G_width)
G_width = new_width;
if (XtIsWidget(w))
for (i = 0; i < w->core.num_popups; i++)
VerbosePass1(w->core.popup_list[i], level + 1);
if (XtIsComposite(w))
{
CompositeWidget cw = (CompositeWidget) w;
for (i = 0; i < cw->composite.num_children; i++)
VerbosePass1(cw->composite.children[i], level + 1);
}
}
void MotifUI::DumpWidget(Widget w, boolean verbose, int level)
{
int i;
for (i = 0; i < level; i++)
printf(" ");
printf("%s : %s", XrmQuarkToString(w->core.xrm_name),
w->core.widget_class->core_class.class_name);
if (verbose)
{
int n = (level * 3) + strlen(XrmQuarkToString(w->core.xrm_name)) +
strlen(w->core.widget_class->core_class.class_name) + 3;
for ( ; n < G_width; n++)
printf(" ");
if (XtIsManaged(w))
printf(" Managed ");
else
printf(" Unmanaged");
if (XtIsSensitive(w))
printf(" Sensitive ");
else
printf(" Insensitive");
if (XtIsRealized(w))
printf(" Realized ");
else
printf(" Unrealized");
if (w->core.visible)
printf(" Visible\n");
else
printf(" Invisible\n");
}
else
printf("\n");
}
void MotifUI::DumpWidgets(Widget w, boolean verbose, int level)
{
DumpWidget(w, verbose, level);
int i;
if (XtIsWidget(w))
{
for (i = 0; i < w->core.num_popups; i++)
DumpWidgets(w->core.popup_list[i], verbose, level + 1);
}
if (XtIsComposite(w))
{
CompositeWidget cw = (CompositeWidget) w;
for (i = 0; i < cw->composite.num_children; i++)
DumpWidgets(cw->composite.children[i], verbose, level + 1);
}
}
void MotifUI::DumpUIHierarchy(boolean verbose, int level)
{
if (verbose)
VerbosePass1(_w, 0);
DumpWidgets(_w, verbose, level);
}

View File

@@ -0,0 +1,179 @@
/* $XConsortium: MotifUI.h /main/6 1996/10/21 17:29:46 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef MOTIFUI_H
#define MOTIFUI_H
#include <Xm/Xm.h>
#if defined(USL) || defined(__uxp__)
#undef STRDUP /* get rid of memutil.h definition. Use def in BaseUI.h. */
#endif
#include "BaseUI.h"
#include "MotifThread.h"
extern "C" {
extern XtPointer _XmStringUngenerate (
XmString string,
XmStringTag tag,
XmTextType tag_type,
XmTextType output_type);
}
#define AnyUI MotifUI
#define HasDumpUI 1
#define PointInRect(RECT, X, Y) \
(X >= (int) (RECT).x && \
Y >= (int) (RECT).y && \
X <= (int) (RECT).x + (int) (RECT).width && \
Y <= (int) (RECT).y + (int) (RECT).height)
typedef struct
{
char *name;
Pixmap pixmap;
Pixmap mask;
} PixmapLookupStruct, *PixmapLookup, **PixmapLookupList;
class DtDND;
class MotifThread;
class MotifUI : public BaseUI {
friend class DtDND;
private:
static void WidgetDestroyCB(Widget, XtPointer, XtPointer);
static void WidgetHelpCB(Widget, XtPointer, XtPointer);
Cursor InitHourGlassCursor();
static void DumpWidget(Widget w, boolean verbose = false, int level = 0);
static void DumpWidgets(Widget w, boolean verbose = false, int level = 0);
static void ThreadCB(MotifThread *_thread, BaseUI *obj, ThreadCallback cb);
protected:
Widget _w;
char *_widgetName;
MotifUI(MotifUI *parent,
const char *name,
const char *category,
const char *widgetName = NULL);
void InstallDestroyCB();
void InstallHelpCB();
virtual void WidgetDestroyed();
void GetPixmaps(Widget widget, char *iconFile, Pixmap *pixmap,
Pixmap *mask = NULL);
void FillBackground(Widget widget, Pixmap pixmap, Pixmap mask);
void SetDefaultResources(const Widget, const String *);
void GetResources(const XtResourceList, const int);
XmString StringCreate(char *string)
{ if (string) return XmStringCreateLocalized(string);
else return NULL;
}
void StringFree(XmString string)
{ if (string) XmStringFree(string); string = NULL; }
char * StringExtract(XmString string)
{ char *s = NULL;
s = (char *) _XmStringUngenerate(
string, NULL,
XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
return s; };
// Definitions for BaseUI virtual functions
virtual boolean SetCategory(char * /*name*/) { return true; }
virtual boolean SetName(char *name);
virtual boolean SetActivity(boolean flag);
virtual boolean SetVisiblity(boolean flag);
virtual boolean SetSelected(boolean flag);
void DoSetFocus(Widget);
void DoRefresh();
void DoToFront();
void DoContextualHelp();
virtual void DoMakeVisible();
virtual boolean DoIsVisible();
virtual void DoBeginUpdate() { }
virtual void DoEndUpdate() { }
virtual void DoUpdateMessage(char * /*message*/) { }
virtual boolean SetOrder(int new_postion);
// Containers widgets should override SetView
virtual boolean SetView(ViewStyle) { return true; }
// Containers and icon widgets should override these
virtual boolean SetOpen(boolean) { return true; }
// Icon widgets should override these
virtual boolean SetIcon(IconStyle) { return true; }
virtual boolean SetParent(BaseUI *) { return true; }
virtual void NotifyDelete(BaseUI *);
static PixmapLookupList pixmap_table;
static int n_pixmaps;
static PointerCursor pointer_style;
public:
static Widget topLevel;
static Display *display;
static XtAppContext appContext;
static XmFontList userFont;
static Font font;
static Window root;
static Pixel black;
static Pixel white;
static int depth;
static int shadowThickness;
static int bMenuButton;
virtual ~MotifUI();
void Thread(const char *cmd, ThreadCallback, int buf_len);
void Thread(int pid, int fd, ThreadCallback, int buf_len);
void Thread(int socket, ThreadCallback, int buf_len);
virtual void SetFocus();
void PointerShape(PointerCursor style);
PointerCursor PointerShape();
virtual void WidthHeight(int w, int h);
virtual void WidthHeight(int *w, int *h);
virtual void Width(int w);
virtual int Width();
virtual void Height(int h);
virtual int Height();
void AttachAll(int offset = 0);
void AttachTop(int offset = 0);
void AttachBottom(int offset = 0);
void AttachLeft(int offset = 0);
void AttachRight(int offset = 0);
void AttachTop(BaseUI *, int offset = 0, boolean opposite = false);
void AttachBottom(BaseUI *, int offset = 0, boolean opposite = false);
void AttachLeft(BaseUI *, int offset = 0, boolean opposite = false);
void AttachRight(BaseUI *, int offset = 0, boolean opposite = false);
void StringWidthHeight(const char *string, int *w, int *h);
int StringWidth(const char *string);
int StringHeight(const char *string);
void SetAddTimeOut(TimeOutCallback, void *callback_data, long interval);
void DumpUIHierarchy(boolean verbose = false, int level = 0);
const Widget BaseWidget() { return _w; }
virtual const Widget InnerWidget() { return _w; }
void Dump(boolean verbose = false,
int level = 0);
// returns a classname to be used in GetResources
virtual const char *const className() { return "MotifUI"; }
};
#endif /* MOTIFUI_H */

View File

@@ -0,0 +1,172 @@
/* $TOG: Prompt.C /main/4 1998/08/03 08:59:18 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "stdlib.h"
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/Text.h>
#include "Prompt.h"
#include "Dialog.h"
Prompt::Prompt(MotifUI *parent,
char *name,
boolean editable,
PromptType prompt_type,
char *default_value,
ValidationCallback /*CB*/,
void * /*validation_data*/,
boolean /*echo_input*/,
int n_columns,
int n_rows,
int captionWidth)
: MotifUI(parent, name, NULL)
{
int editMode;
int wordWrap;
Widget parentW;
Pixel bg;
parentW = parent->InnerWidget();
_prompt_type = prompt_type;
_value = NULL;
if (_default_value)
_default_value = STRDUP(default_value);
else
_default_value = strdup("");
if (_prompt_type == MULTI_LINE_STRING_PROMPT)
{
wordWrap = true;
editMode = XmMULTI_LINE_EDIT;
}
else
{
wordWrap = false;
editMode = XmSINGLE_LINE_EDIT;
}
XtVaGetValues(parentW, XmNbackground, &bg, NULL);
_w = XtVaCreateManagedWidget(name, xmFormWidgetClass, parentW, NULL);
XmString xm_string = StringCreate(name);
_caption = XtVaCreateManagedWidget(name, xmLabelWidgetClass, _w,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNalignment, XmALIGNMENT_END,
XmNlabelString, xm_string,
XmNwidth, captionWidth, NULL);
StringFree(xm_string);
if (editMode == XmMULTI_LINE_EDIT && editable == false)
{
Widget _frame;
_frame = XtVaCreateManagedWidget(name, xmFrameWidgetClass, _w,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment,
(name ? XmATTACH_WIDGET : XmATTACH_FORM),
XmNleftWidget, _caption,
XmNrightAttachment, XmATTACH_FORM,
XmNshadowType, XmSHADOW_ETCHED_IN,
XmNshadowThickness, 2, NULL);
_text = XtVaCreateManagedWidget(name, xmTextWidgetClass, _frame,
XmNvalue, default_value,
XmNrows, n_rows, XmNcolumns, n_columns,
XmNeditMode, editMode,
XmNwordWrap, wordWrap,
XmNeditable, editable,
XmNbackground, bg,
XmNcursorPositionVisible, false,
XmNtraversalOn, false,
XmNshadowThickness, 0, NULL);
}
else
_text = XtVaCreateManagedWidget(name, xmTextWidgetClass, _w,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment,
(name ? XmATTACH_WIDGET : XmATTACH_FORM),
XmNleftWidget, _caption,
XmNrightAttachment, XmATTACH_FORM,
XmNvalue, default_value,
XmNrows, n_rows, XmNcolumns, n_columns,
XmNeditMode, editMode,
XmNwordWrap, wordWrap,
editable ? NULL : XmNeditable, editable,
XmNbackground, bg,
XmNcursorPositionVisible, false,
XmNtraversalOn, false,
XmNshadowThickness, 0,
NULL);
}
Prompt::~Prompt()
{
free(_default_value);
XtFree(_value);
}
void Prompt::Reset()
{
Value(_default_value);
}
void Prompt::DefaultValue(char *value)
{
free(_default_value);
_default_value = STRDUP(value);
}
void Prompt::Value(int *number)
{
XtFree(_value);
_value = XmTextGetString(_text);
sscanf(_value, "%d", number);
}
void Prompt::Value(float *number)
{
XtFree(_value);
_value = XmTextGetString(_text);
sscanf(_value, "%f", number);
}
char * Prompt::Value()
{
XtFree(_value);
_value = XmTextGetString(_text);
return _value;
}
boolean Prompt::Value(int number)
{
char value[50];
sprintf(value, "%d", number);
XmTextSetString(_text, value);
return true;
}
boolean Prompt::Value(float number)
{
char value[50];
sprintf(value, "%f", number);
XmTextSetString(_text, value);
return true;
}
boolean Prompt::Value(char *string)
{
XmTextSetString(_text, string);
return true;
}

View File

@@ -0,0 +1,62 @@
/* $XConsortium: Prompt.h /main/3 1995/11/06 09:44:30 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PROMPT_H
#define PROMPT_H
#include "MotifUI.h"
class Prompt : public MotifUI {
private:
Widget _caption;
Widget _text;
PromptType _prompt_type;
char *_default_value;
char *_value;
ValidationCallback CB;
void * validation_data;
public:
Prompt(MotifUI * parent,
char *name = "prompt",
boolean editable = true,
PromptType prompt_type = STRING_PROMPT,
char *default_value = NULL,
ValidationCallback CB = NULL,
void * validation_data = NULL,
boolean echo_input = true,
int n_column = 20,
int n_rows = 1,
int captionWidth = 0);
~Prompt();
void SetFocus() { DoSetFocus(_text); }
void Reset(); // Reset to default value
char * Value(); // Access value as STRING
void Value(int *); // Access value as INTEGER
void Value(float *); // Access value as REAL_NUMBER
boolean Value(int); // Set value
boolean Value(float); // Set value
boolean Value(char *); // Set value
void DefaultValue(char *); // Set value
char * DefaultValue() { return _default_value; }
const UI_Class UIClass() { return PROMPT; }
const int UISubClass() { return _prompt_type; }
const char *const UIClassName() { return "Prompt"; }
};
#endif /* PROMPT_H */

View File

@@ -0,0 +1,234 @@
/* $XConsortium: ScaleObj.C /main/2 1995/07/17 14:07:10 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "ScaleObj.h"
#include <Xm/Scale.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
ScaleObj::ScaleObj(MotifUI *parent,
char *title,
int value,
int numDecimalPoints,
int max,
int min,
int scaleMultiple,
ScaleType style,
boolean showValue)
: MotifUI(parent, title, NULL)
{
CreateScale(parent, title, value, numDecimalPoints, max, min, scaleMultiple,
style, showValue);
}
ScaleObj::ScaleObj(char *category,
MotifUI *parent,
char *title,
int value,
int numDecimalPoints,
int max,
int min,
int scaleMultiple,
ScaleType style,
boolean showValue)
: MotifUI(parent, title, category)
{
CreateScale(parent, title, value, numDecimalPoints, max, min, scaleMultiple,
style, showValue);
}
void ScaleObj::CreateScale(MotifUI *parent, char *title, int value,
int numDecimalPoints, int max, int min,
int scaleMultiple, ScaleType style, boolean showValue)
{
_style = style;
_value = value;
_numDecimalPoints = numDecimalPoints;
_max = max;
_min = min;
_scaleMultiple = scaleMultiple;
_style = style;
_showValue = showValue;
CheckValues(false);
int orientation;
short points = _numDecimalPoints;
if (_style == VERTICAL_SCALE)
orientation = XmVERTICAL;
else
orientation = XmHORIZONTAL;
XmString xm_string = StringCreate(title);
_w = XtVaCreateManagedWidget(title, xmFormWidgetClass,
parent->InnerWidget(), NULL);
_minLabel = XtVaCreateWidget(title, xmLabelWidgetClass, _w,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM, NULL);
_maxLabel = XtVaCreateWidget(title, xmLabelWidgetClass, _w,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM, NULL);
_scale = XtVaCreateManagedWidget(title, xmScaleWidgetClass, _w,
XmNmaximum, _max,
XmNminimum, _min, XmNvalue, _value,
XmNscaleMultiple, _scaleMultiple,
XmNdecimalPoints, points,
XmNtitleString, xm_string,
XmNshowValue, _showValue,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNorientation, orientation, NULL);
StringFree(xm_string);
SetString(_minLabel, _min);
SetString(_maxLabel, _max);
ShowValue(_showValue);
}
boolean ScaleObj::SetName(char *name)
{
XmString xm_string = StringCreate(name);
XtVaSetValues(_w, XmNtitleString, xm_string, NULL);
StringFree(xm_string);
return true;
}
void ScaleObj::CheckValues(boolean do_it)
{
if (_min > _max)
{
int tmp = _min;
_min = _max;
_max = tmp;
}
if ((_max - _min) == 0)
_max += 1;
if (_numDecimalPoints < 0)
_numDecimalPoints = 0;
if (_value > _max)
_value = _max;
else if (_value < _min)
_value = _min;
if (_scaleMultiple < 0)
_scaleMultiple = 1;
else if (_scaleMultiple > (_max - _min))
{
if ((_scaleMultiple = (_max - _min) / 10) == 0)
_scaleMultiple = 1;
}
if (do_it)
{
short points = _numDecimalPoints;
XtVaSetValues(_scale, XmNmaximum, _max, XmNminimum, _min,
XmNscaleMultiple, _scaleMultiple,
XmNdecimalPoints, points, XmNvalue, _value, NULL);
}
}
void ScaleObj::SetString(Widget w, int value)
{
char number[20];
if (_numDecimalPoints == 0)
sprintf(number, "%d", value);
else
{
char fmt[10];
sprintf(fmt, "%%.%df", _numDecimalPoints);
int n = 1, i;
for (i = 0; i < _numDecimalPoints; i++)
n *= 10;
sprintf(number, fmt, (float) value / n);
}
XmString xm_string = StringCreate(number);
XtVaSetValues(w, XmNlabelString, xm_string, NULL);
StringFree(xm_string);
}
void ScaleObj::Style(ScaleType value)
{
int orientation;
if (value == VERTICAL_SCALE)
orientation = XmVERTICAL;
else
orientation = XmHORIZONTAL;
XtVaSetValues(_scale, XmNorientation, orientation, NULL);
}
int ScaleObj::Value()
{
XtVaGetValues(_scale, XmNvalue, &_value, NULL);
return _value;
}
void ScaleObj::Value(int value)
{
if (_value == value)
return;
_value = value;
CheckValues(true);
}
void ScaleObj::NumDecimalPoints(int value)
{
_numDecimalPoints = value;
CheckValues(true);
}
void ScaleObj::Maximum(int value)
{
if (_max == value)
return;
_max = value;
int old_min = _min;
CheckValues(true);
SetString(_maxLabel, _max);
if (old_min != _min)
SetString(_minLabel, _min);
}
void ScaleObj::Minumum(int value)
{
if (_min == value)
return;
_min = value;
int old_max = _max;
CheckValues(true);
SetString(_minLabel, _min);
if (old_max != _max)
SetString(_maxLabel, _max);
}
void ScaleObj::Multiple(int value)
{
_scaleMultiple = value;
CheckValues(true);
}
void ScaleObj::ShowValue(boolean value)
{
_showValue = value;
if (_showValue)
{
XtManageChild(_minLabel);
XtManageChild(_maxLabel);
XtVaSetValues(_scale, XmNshowValue, _showValue, XmNleftWidget, _minLabel,
XmNleftAttachment, XmATTACH_WIDGET,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, _maxLabel, NULL);
}
else
{
XtUnmanageChild(_minLabel);
XtUnmanageChild(_maxLabel);
XtVaSetValues(_scale, XmNshowValue, _showValue,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM, NULL);
}
}

View File

@@ -0,0 +1,81 @@
/* $XConsortium: ScaleObj.h /main/3 1995/11/06 09:44:42 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef SCALEOBJ_H
#define SCALEOBJ_H
#include "MotifUI.h"
class ScaleObj : public MotifUI {
private:
ScaleType _style;
int _value;
int _numDecimalPoints;
int _max;
int _min;
int _scaleMultiple;
boolean _showValue;
Widget _scale;
Widget _minLabel;
Widget _maxLabel;
void SetString(Widget w, int value);
void CheckValues(boolean);
void CreateScale(MotifUI *, char *, int, int, int, int, int, ScaleType,
boolean);
boolean SetName(char *name);
public:
ScaleObj(MotifUI * parent,
char *title,
int value,
int numDecimalPoints = 0,
int max = 100,
int min = 1,
int scaleMultiple = 5,
ScaleType style = VERTICAL_SCALE,
boolean showValue = false);
ScaleObj(char *category,
MotifUI * parent,
char *title,
int value,
int numDecimalPoints = 0,
int max = 100,
int min = 1,
int scaleMultiple = 5,
ScaleType style = VERTICAL_SCALE,
boolean showValue = false);
void Style(ScaleType);
void Value(int);
void NumDecimalPoints(int);
void Maximum(int);
void Minumum(int);
void Multiple(int);
void ShowValue(boolean);
ScaleType Style() { return _style; }
int Value();
int NumDecimalPoints() { return _numDecimalPoints; }
int Maximum() { return _max; }
int Minumum() { return _min; }
int Multiple() { return _scaleMultiple; }
boolean ShowValue() { return _showValue; }
const Widget InnerWidget() { return _scale; }
const UI_Class UIClass() { return SCALE; }
const int UISubClass() { return _style; }
const char *const UIClassName() { return "Scale"; }
};
#endif /* SCALEOBJ_H */

View File

@@ -0,0 +1,34 @@
/* $XConsortium: Sep.C /main/2 1995/07/17 14:07:18 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Sep.h"
#include <Xm/Separator.h>
Sep::Sep(MotifUI *parent,
SeparatorStyle style)
: MotifUI(parent, "sep", NULL)
{
_style = style;
_w = XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass,
parent->InnerWidget(),
XmNseparatorType, style, NULL);
}
Sep::Sep(char *category,
MotifUI *parent,
SeparatorStyle style)
: MotifUI(parent, "sep", category)
{
_style = style;
_w = XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass,
parent->InnerWidget(),
XmNseparatorType, style, NULL);
}

View File

@@ -0,0 +1,34 @@
/* $XConsortium: Sep.h /main/3 1995/11/06 09:44:53 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef SEP_H
#define SEP_H
#include "MotifUI.h"
class Sep : public MotifUI {
private:
SeparatorStyle _style;
public:
Sep(MotifUI * parent,
SeparatorStyle style = SHADOW_ETCHED_IN);
Sep(char *category,
MotifUI * parent,
SeparatorStyle style = SHADOW_ETCHED_IN);
const UI_Class UIClass() { return SEPARATOR; }
const int UISubClass() { return _style; }
const char *const UIClassName() { return "Sep"; }
};
#endif /* SEP_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
/* $XConsortium: WorkArea.h /main/3 1995/11/06 09:45:18 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef WORKAREA_H
#define WORKAREA_H
#ifdef __cplusplus
extern "C" {
#endif
externalref WidgetClass workAreaWidgetClass;
typedef struct _WorkAreaClassRec *WorkAreaWidgetClass;
typedef struct _WorkAreaRec *WorkAreaWidget;
enum {
GuiATTACH_TOP,
GuiATTACH_BOTTOM,
GuiATTACH_LEFT,
GuiATTACH_RIGHT
};
#define GuiIsWorkArea(w) XtIsSubclass((w), workAreaWidgetClass)
extern const char gui_workarea_strings[];
#define GuiNisList ((char*)&gui_workarea_strings[0])
#define GuiNattachment ((char*)&gui_workarea_strings[7])
#define GuiCAttachment ((char*)&gui_workarea_strings[18])
#define GuiRAttachment ((char*)&gui_workarea_strings[29])
#define GuiNisWorkArea ((char*)&gui_workarea_strings[40])
#define GuiNautoResizeWidth ((char*)&gui_workarea_strings[51])
#define GuiNisOpened ((char*)&gui_workarea_strings[67])
#define GuiNisTransient ((char*)&gui_workarea_strings[76])
#define GuiNlineThickness ((char*)&gui_workarea_strings[88])
#define GuiCLineThickness ((char*)&gui_workarea_strings[102])
#define GuiNlineOffset ((char*)&gui_workarea_strings[116])
#define GuiCLineOffset ((char*)&gui_workarea_strings[127])
#define GuiNnodeLineLength ((char*)&gui_workarea_strings[138])
#define GuiCNodeLineLength ((char*)&gui_workarea_strings[153])
#define GuiNnumberSubNodes ((char*)&gui_workarea_strings[168])
#define GuiCNumberSubNodes ((char*)&gui_workarea_strings[183])
#define GuiNnumberColumns ((char*)&gui_workarea_strings[198])
#define GuiCNumberColumns ((char*)&gui_workarea_strings[212])
#define GuiNsubNodes ((char*)&gui_workarea_strings[226])
#define GuiCSubNodes ((char*)&gui_workarea_strings[235])
#define GuiNhorizontalSpace ((char*)&gui_workarea_strings[244])
#define GuiNverticalSpace ((char*)&gui_workarea_strings[260])
#define GuiCSpace ((char*)&gui_workarea_strings[274])
#define GuiNsuperNode ((char*)&gui_workarea_strings[280])
#define GuiCSuperNode ((char*)&gui_workarea_strings[290])
extern Widget GuiCreateWorkArea(
Widget parent,
char *name,
ArgList arglist,
Cardinal argcount);
extern Widget GuiCreateScrolledWorkArea(
Widget parent,
char *name,
ArgList arglist,
Cardinal argcount);
/*
* Use the following two functions to improve performance when managing and
* unmanaging many children all at once.
*/
extern void GuiWorkAreaEnableRedisplay(Widget /* workArea widget */);
extern void GuiWorkAreaDisableRedisplay(Widget /* workArea widget */);
/*
* GuiWorkAreaReorderChildren reorders a parent's subnodes. Can be use to sort
* or move subnodes. The subnode list can be a subset of the parents's
* subnodes and it can be moved relative to another position (widget).
* The default position is to start the reorder as the first subnode.
*
* If position == parent_subnode, start reorder as first subnode.
* If position == NULL, subnode_list[n_subnodes] will be the last sub_node
* of parent_subnode. If position is a widget in the parent's subnodes,
* start the reorder after it.
*/
extern void GuiWorkAreaReorderChildren(
Widget parent_subnode,
WidgetList subnode_list,
int n_subnodes,
Widget position);
#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif
#endif /* WORKAREA_H */

View File

@@ -0,0 +1,89 @@
/* $XConsortium: WorkAreaP.h /main/3 1995/11/06 09:45:29 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef WORKAREAP_H
#define WORKAREAP_H
#include <Xm/ManagerP.h>
#include "WorkArea.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _WorkAreaClassPart {
int ignore;
} WorkAreaClassPart;
typedef struct _WorkAreaClassRec {
CoreClassPart core_class;
CompositeClassPart composite_class;
ConstraintClassPart constraint_class;
XmManagerClassPart manager_class;
WorkAreaClassPart workArea_class;
} WorkAreaClassRec;
externalref WorkAreaClassRec workAreaClassRec;
typedef struct _WorkAreaPart {
/* public resources */
Dimension horizontal_spacing;
Dimension vertical_spacing;
Dimension line_thickness;
Dimension line_offset;
Dimension node_line_length;
unsigned char alignment;
unsigned char vertical_alignment;
unsigned char packing;
Boolean auto_resize_width;
Boolean is_list;
/* private resources */
Dimension old_width;
Dimension old_height;
Boolean delay_layout; /* Set with GuiWorkAreaDoLayout function */
GC gc;
Widget workArea_root;
} WorkAreaPart;
typedef struct _WorkAreaRec {
CorePart core;
CompositePart composite;
ConstraintPart constraint;
XmManagerPart manager;
WorkAreaPart workArea;
} WorkAreaRec;
typedef struct _WorkAreaConstraintsPart {
/* public resources */
Widget super_node;
Boolean is_workArea;
unsigned char orientation;
unsigned char attachment;
Boolean is_opened;
Boolean is_transient;
WidgetList sub_nodes; /* Can only be queried. Can be set indirectly
with the GuiWorkAreaReorderChildren function */
int n_sub_nodes;
int n_columns; /* Used when orientation is horizontal. Zero
means there are infinite columns */
Position x, y; /* Can be set if is_transient == TRUE */
} WorkAreaConstraintsPart;
typedef struct _WorkAreaConstraintsRec {
WorkAreaConstraintsPart workArea;
} WorkAreaConstraintsRec, *WorkAreaConstraints;
#define WORKAREA_CONSTRAINT(w) ((WorkAreaConstraints)((w)->core.constraints))
#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif
#endif /* WORKAREAP_H */

View File

@@ -0,0 +1,144 @@
/* $XConsortium: Test.C /main/2 1995/07/17 14:07:26 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Application.h"
#include "MainWindow.h"
#include "MenuBar.h"
#include "Menu.h"
#include "Button.h"
#include "Container.h"
#include "IconObj.h"
#include "Sep.h"
#include <stdlib.h>
#include <stdio.h>
static void ExitCB(void *data)
{
delete ((BaseUI *)data)->Parent();
exit (0);
}
static void PrintUICB(void *data)
{
((AnyUI *) data)->DumpUIHierarchy(true);
}
static void PrintObjectsCB(void *data)
{
((BaseUI *) data)->DumpHierarchy();
}
class TestWindow : public MainWindow
{
public:
Container *container;
TestWindow(MotifUI *p,char *name) : MainWindow(p,name,NULL,"Fpprnt.l.pm") { }
void Initialize();
};
void TestWindow::Initialize()
{
MenuBar *mbar;
Menu *menu;
mbar = new MenuBar(this);
container = new Container("PrinterSubSystem", this, "Printers");
container->WidthHeight(600, 400);
container->ContainerView(TREE);
SetWorkWindow(container);
// File menu
menu = new Menu(mbar, "File", "F");
new Button(menu, "Exit", PUSH_BUTTON, ExitCB, this, "x", "ALT+F4");
// Edit menu
menu = new Menu(mbar, "Edit", "E");
new Button(menu, "Cut", PUSH_BUTTON, NULL, NULL, "t", "Shift+Del");
new Button(menu, "Copy", PUSH_BUTTON, NULL, NULL, "C", "Ctrl+Ins");
new Button(menu, "Paste", PUSH_BUTTON, NULL, NULL, "P", "Shift+Ins");
new Button(menu, "Delete", PUSH_BUTTON, NULL, NULL, "D");
// View menu
menu = new Menu(mbar, "View", "V");
new Button(menu, "New", PUSH_BUTTON, NULL, NULL, "N");
new Sep(menu);
new Button(menu, "Select All", PUSH_BUTTON, NULL, NULL, "S", "Ctrl+/");
new Button(menu, "Unselect All", PUSH_BUTTON, NULL, NULL, "U", "Ctrl+\\");
new Sep(menu);
new Button(menu, "Set Preferences...", PUSH_BUTTON, NULL, NULL, "P");
new Sep(menu);
new Button(menu, "Save Settings...", PUSH_BUTTON, NULL, NULL, "t");
// Actions Menu
menu = new Menu(mbar, "Actions", "A");
new Button(menu, "Monitor", PUSH_BUTTON, NULL, NULL, "M");
new Button(menu, "Cancel Job", PUSH_BUTTON, NULL, NULL, "C");
// Help Menu
menu = new Menu(mbar, "Help", "H");
new Button(menu, "Introduction", PUSH_BUTTON, NULL, NULL, "I");
new Sep(menu);
new Button(menu, "Tasks", PUSH_BUTTON, NULL, NULL, "T");
new Button(menu, "Reference", PUSH_BUTTON, NULL, NULL, "R");
new Button(menu, "On Item", PUSH_BUTTON, NULL, NULL, "O");
new Sep(menu);
new Button(menu, "Using Help", PUSH_BUTTON, NULL, NULL, "U");
new Sep(menu);
new Button(menu, "Version", PUSH_BUTTON, NULL, NULL, "V");
mbar->SetHelpMenu(menu);
// Debug menu
menu = new Menu(mbar, "Debug", "G");
new Button(menu, "Print Objects", PUSH_BUTTON, PrintObjectsCB, Parent());
new Button(menu, "Print UI", PUSH_BUTTON, PrintUICB, Parent());
}
int main(int argc,
char **argv)
{
Application *app = new Application("Printer", "Dtprinter", &argc, argv);
TestWindow *window = new TestWindow(app, "Printer");
window->Initialize();
window->AddAction("Exit", "PrinterSubSystem", ExitCB, NULL, "x", "Alt+F4");
window->AddAction("Properties...", "Queue", NULL, NULL, "p",
"Ctrl+Backspace");
window->AddSep("Queue");
window->AddAction("Start", "Queue", NULL, NULL, "S");
window->AddAction("Stop", "Queue", NULL, NULL, "t");
window->AddSep("Queue");
window->AddAction("Monitor", "Queue", NULL, NULL, "M");
window->AddAction("Cancel", "PrintJob", NULL, NULL, "C");
window->RegisterPopup(window->container);
IconObj *lp0 = new IconObj("Queue", window->container, "lp0", "Fpprnt");
window->RegisterPopup(lp0);
IconObj *tmp = new IconObj("PrintJob", lp0, "job1", "DtPrtjb");
window->RegisterPopup(tmp);
tmp = new IconObj("PrintJob", lp0, "job2", "DtPrtjb");
window->RegisterPopup(tmp);
tmp = new IconObj("PrintJob", lp0, "job3", "DtPrtjb");
window->RegisterPopup(tmp);
IconObj *lp1 = new IconObj("Queue", window->container, "lp1", "Fpprnt");
window->RegisterPopup(lp1);
tmp = new IconObj("PrintJob", lp1, "job4", "DtPrtjb");
window->RegisterPopup(tmp);
tmp = new IconObj("PrintJob", lp1, "job5", "DtPrtjb");
window->RegisterPopup(tmp);
app->Visible(true);
app->Run();
return 0;
}

View File

@@ -0,0 +1,28 @@
#
# file: msg.awk
#
#
BEGIN{
}
/^\$set/ { SET_NAME = $2 }
# if a line does not start with $, and the first character of the second
# argument is a double quote, then delete the first argument from $0,
# then delete $1 from $0, concatenate TXT_,SET_NAME,_, and $1, and print
# $0 (w/t $1)
/^[^\$]/ { if (substr($2,1,1) == "\"")
{ arg1=$1;
sub($1,"",$0);
print "#define TXT_" SET_NAME "_" arg1 " " $0
}
else
print $0
}
/^$/ { print $0 } # print line if blank
/^\$/ { sub(/^\$/ ,"/*",$0);
sub( /$/," */",$0);
print $0; # C style comments
}
END {
}

View File

@@ -0,0 +1,532 @@
/* $TOG: BaseObj.C /main/4 1998/08/03 16:30:23 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "BaseObj.h"
#include <string.h>
#include <stdlib.h>
const char *ACTION_NOT_FOUND = "ActionNotFound";
BaseObj::BaseObj(BaseObj *parent,
const char *name)
{
_name = STRDUP(name);
_displayName = NULL;
_details = NULL;
_parent = parent;
_init_children = false;
_init_attributes = false;
_children = NULL;
_numChildren = 0;
_numActions = 0;
_numAttributes = 0;
_actions = NULL;
_attributes = NULL;
_lastActionName = NULL;
_lastActionOutput = NULL;
_lastActionStatus = 0;
AddToParent();
BaseObj *p = _parent;
while (p)
{
p->NotifyCreate(this);
p = p->_parent;
}
}
BaseObj::~BaseObj()
{
int i;
DeleteChildren();
DeleteFromParent();
BaseObj *parent = _parent;
while (parent)
{
parent->NotifyDelete(this);
parent = parent->_parent;
}
for (i = 0; i < _numAttributes; i++)
{
delete _attributes[i]->ReferenceName;
delete _attributes[i]->Value;
delete _attributes[i]->DisplayName;
delete _attributes[i]->DisplayValue;
delete _attributes[i]->DefaultValue;
delete _attributes[i]->DisplayDefaultValue;
delete _attributes[i]->Help;
delete _attributes[i]->ContextualHelp;
delete _attributes[i]->Listing;
delete _attributes[i]->Dependancies;
delete _attributes[i];
}
delete []_attributes;
for (i = 0; i < _numActions; i++)
{
delete _actions[i]->ReferenceName;
delete _actions[i]->DisplayName;
delete _actions[i]->Nmemonic;
delete _actions[i]->AcceleratorText;
delete _actions[i]->Accelerator;
delete _actions[i]->Help;
delete _actions[i]->ContextualHelp;
delete _actions[i]->Dependancies;
delete _actions[i];
}
delete []_actions;
delete []_children;
free(_lastActionName);
delete [] _lastActionOutput;
free(_details);
free(_displayName);
free(_name);
}
char *BaseObj::DisplayName()
{
if (!_displayName)
{
InitDisplayName();
if (!_displayName)
_displayName = STRDUP(_name);
}
return _displayName;
}
void BaseObj::ReadAttributes()
{
if (_init_attributes == false)
{
LoadAttributes(_numAttributes, _attributes);
_init_attributes = true;
}
}
char *BaseObj::Details()
{
if (!_details)
{
InitDetails();
if (!_details)
_details = STRDUP("");
}
return _details;
}
void BaseObj::UpdateDetails()
{
free(_details);
_details = NULL;
(void) Details();
}
void BaseObj::UpdateChildren()
{
DeleteChildren();
InitChildren();
_init_children = true;
}
BaseObj **BaseObj::Children()
{
if (_init_children == false)
{
InitChildren();
_init_children = true;
}
return _children;
}
int BaseObj::NumChildren()
{
if (_init_children == false)
{
InitChildren();
_init_children = true;
}
return _numChildren;
}
void BaseObj::DeleteAction(const char *name)
{
Action *action;
if (!HasAction(name, &action))
return;
Action **new_actions;
int i, index;
index = 0;
new_actions = new Action*[_numActions - 1];
for (i = 0; i < _numActions; i++)
if (_actions[i] != action)
new_actions[index++] = _actions[i];
delete action->ReferenceName;
delete action->DisplayName;
delete action->Nmemonic;
delete action->AcceleratorText;
delete action->Accelerator;
delete action->Help;
delete action->ContextualHelp;
delete action->Dependancies;
delete action;
delete []_actions;
_actions = new_actions;
_numActions--;
}
void BaseObj::DeleteAttribute(const char *name)
{
Attribute *attribute;
if (!HasAttribute(name, &attribute))
return;
Attribute **new_attributes;
int i, index;
index = 0;
new_attributes = new Attribute*[_numAttributes - 1];
for (i = 0; i < _numAttributes; i++)
if (_attributes[i] != attribute)
new_attributes[index++] = _attributes[i];
delete attribute->ReferenceName;
delete attribute->Value;
delete attribute->DisplayName;
delete attribute->DisplayValue;
delete attribute->DefaultValue;
delete attribute->DisplayDefaultValue;
delete attribute->Help;
delete attribute->ContextualHelp;
delete attribute->Listing;
delete attribute->Dependancies;
delete attribute;
delete []_attributes;
_attributes = new_attributes;
_numAttributes--;
}
void BaseObj::AddAttribute(const char *ReferenceName,
const char *DisplayName,
const char *Help,
const char *ContextualHelp,
Characteristics Mask,
ValueList ValueListType,
const char *Listing,
const char *Dependancies,
const char *DefaultValue,
const char *DisplayDefaultValue)
{
Attribute **new_attributes;
int i;
new_attributes = new Attribute*[_numAttributes + 1];
for (i = 0; i < _numAttributes; i++)
new_attributes[i] = _attributes[i];
delete []_attributes;
_attributes = new_attributes;
Attribute *attribute = new Attribute;
attribute->ReferenceName = STRDUP(ReferenceName);
attribute->Value = NULL;
attribute->DisplayName = STRDUP(DisplayName);
attribute->DisplayValue = NULL;
attribute->DefaultValue = STRDUP(DefaultValue);
attribute->DisplayDefaultValue = STRDUP(DisplayDefaultValue);
attribute->Mask = Mask;
attribute->Help = STRDUP(Help);
attribute->ContextualHelp = STRDUP(ContextualHelp);
attribute->Listing = STRDUP(Listing);
attribute->ValueListType = ValueListType;
attribute->Dependancies = STRDUP(Dependancies);
_attributes[_numAttributes] = attribute;
_numAttributes++;
}
void BaseObj::AddAction(ActionHandler Handler,
const char *ReferenceName,
const char *DisplayName,
const char *Nmemonic,
const char *Help,
const char *ContextualHelp,
boolean InputRequired,
const char *AcceleratorText,
const char *Accelerator,
const char *Dependancies)
{
Action **new_actions;
int i;
new_actions = new Action*[_numActions + 1];
for (i = 0; i < _numActions; i++)
new_actions[i] = _actions[i];
delete []_actions;
_actions = new_actions;
Action *action = new Action;
action->Handler = Handler;
action->ReferenceName = STRDUP(ReferenceName);
action->DisplayName = STRDUP(DisplayName);
action->Nmemonic = STRDUP(Nmemonic);
action->AcceleratorText = STRDUP(AcceleratorText);
action->Accelerator = STRDUP(Accelerator);
action->InputRequired = InputRequired;
action->Help = STRDUP(Help);
action->ContextualHelp = STRDUP(ContextualHelp);
action->Dependancies = STRDUP(Dependancies);
_actions[_numActions] = action;
_numActions++;
}
void BaseObj::AddToParent()
{
if (!_parent)
return;
BaseObj **new_children;
int i;
new_children = new BaseObj*[_parent->_numChildren + 1];
for (i = 0; i < _parent->_numChildren; i++)
new_children[i] = _parent->_children[i];
delete []_parent->_children;
_parent->_children = new_children;
_parent->_children[_parent->_numChildren] = this;
_parent->_numChildren++;
}
void BaseObj::DeleteFromParent()
{
if (!_parent)
return;
BaseObj **new_children;
int i, index;
index = 0;
new_children = new BaseObj*[_parent->_numChildren - 1];
for (i = 0; i < _parent->_numChildren; i++)
if (_parent->_children[i] != this)
new_children[index++] = _parent->_children[i];
delete []_parent->_children;
_parent->_children = new_children;
_parent->_numChildren--;
}
int BaseObj::NumSiblings()
{
if (_parent)
return _parent->_numChildren;
else
return 0;
}
BaseObj ** BaseObj::Siblings()
{
if (_parent)
return _parent->_children;
else
return NULL;
}
boolean BaseObj::HasAction(const char *actionName,
Action **action)
{
int i;
for (i = 0; i < _numActions; i++)
if (!strcmp(_actions[i]->ReferenceName, actionName))
{
*action = _actions[i];
return true;
}
return false;
}
boolean BaseObj::HasAction(Action *action)
{
Action *dummy;
if (action)
return HasAction(action->ReferenceName, &dummy);
else
return false;
}
boolean BaseObj::HasAction(const char *actionName)
{
Action *dummy;
return HasAction(actionName, &dummy);
}
boolean BaseObj::SendAction(Action *action,
BaseObj *requestor)
{
boolean status;
delete [] _lastActionOutput;
free(_lastActionName);
_lastActionOutput = NULL;
_lastActionName = strdup(action->ReferenceName);
if ((status = HasAction(action)) == true)
_lastActionStatus = (*action->Handler)(this, &_lastActionOutput,
requestor);
else
{
_lastActionStatus = -1;
int len = strlen("'%s' is not an action of %s") +
strlen(ObjectClassName()) + strlen(action->ReferenceName);
_lastActionOutput = new char [len];
sprintf(_lastActionOutput, "'%s' is not an action of %s",
ObjectClassName(), action->ReferenceName);
}
return status;
}
boolean BaseObj::SendAction(const char *actionName,
BaseObj *requestor)
{
Action *action;
(void) HasAction(actionName, &action);
return SendAction(action, requestor);
}
char * BaseObj::AttributeValue(char *referenceName)
{
Attribute *dummy;
ReadAttributes();
if (HasAttribute(referenceName, &dummy))
return dummy->Value;
else
return NULL;
}
boolean BaseObj::HasAttribute(const char *attributeName,
Attribute **attribute)
{
int i;
for (i = 0; i < _numAttributes; i++)
if (!strcmp(_attributes[i]->ReferenceName, attributeName))
{
*attribute = _attributes[i];
return true;
}
return false;
}
boolean BaseObj::HasAttribute(Attribute *attribute)
{
Attribute *dummy;
return HasAttribute(attribute->ReferenceName, &dummy);
}
boolean BaseObj::HasAttribute(const char *attributeName)
{
Attribute *dummy;
return HasAttribute(attributeName, &dummy);
}
void BaseObj::DeleteChildren()
{
if (_numChildren)
{
BaseObj **kids = new BaseObj*[_numChildren];
int i, n = _numChildren;
// Save children first before deleting a child since the destructor
// updates the _children variable
for (i = 0; i < n; i++)
kids[i] = _children[i];
for (i = 0; i < n; i++)
delete kids[i];
delete []kids;
}
}
// Dump object
void BaseObj::Dump(boolean verbose, int level)
{
int i, j;
for (i = 0; i < level; i++) printf(" ");
printf("%s : %s\n", Name(), ObjectClassName());
if (verbose)
{
for (i = -1; i <= level; i++) printf(" ");
printf("Display Name = '%s'\n", _displayName);
for (i = -1; i <= level; i++) printf(" ");
printf("Details = '%s'\n", _details);
for (i = -1; i <= level; i++) printf(" ");
printf("Number Actions = %d\n", _numActions);
for (j = 0; j < _numActions; j++)
{
for (i = -2; i <= level; i++) printf(" ");
printf("Action.%s = '%s'\n", _actions[j]->ReferenceName,
_actions[j]->DisplayName);
}
for (i = -1; i <= level; i++) printf(" ");
printf("Number Attributes = %d\n", _numAttributes);
for (j = 0; j < _numAttributes; j++)
{
for (i = -2; i <= level; i++) printf(" ");
printf("Attribute.%s = '%s'\n", _attributes[j]->ReferenceName,
_attributes[j]->DisplayValue);
}
for (i = -1; i <= level; i++) printf(" ");
printf("Number Children = %d\n", _numChildren);
}
}
// Dump object hierarchy
void BaseObj::DumpHierarchy(boolean verbose, int level)
{
int i;
Dump(verbose, level);
for (i = 0; i < _numChildren; i++)
_children[i]->DumpHierarchy(verbose, level + 1);
}
void BaseObj::Error(const char *message)
{
// Log Error
printf("%s: (%s) %s\n", ObjectClassName(), Name(), message);
}
int BaseObj::RunCommand(const char *command,
char **std_out,
char **std_err)
{
int status;
Invoke *_thread = new Invoke(command, std_out, std_err);
status = _thread->status;
delete _thread;
return status;
}

View File

@@ -0,0 +1,249 @@
/* $TOG: BaseObj.h /main/5 1998/04/06 13:34:28 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef BASEOBJ_H
#define BASEOBJ_H
#include <stdio.h>
#include "Invoke.h"
#ifndef _BOOLEAN_
#define _BOOLEAN_
#if (defined(sun) && OSMAJORVERSION <= 5 && OSMINORVERSION <= 3)|| defined(USL) || defined(__uxp__)
#include <sys/types.h>
#define boolean boolean_t
#define true B_TRUE
#define false B_FALSE
#elif defined(linux)
#define false 0
#define true 0
#define boolean int
#else
typedef enum
{
false = 0,
true = 1
} boolean;
#endif
#endif
#ifndef STRDUP
#define STRDUP(string) (string ? strdup(string) : NULL)
#define STRCMP(s1, s2) (s1 && s2 ? strcmp(s1, s2) : (s1 ? 1 : -1))
#define STRLEN(string) (string ? strlen(string) : 0)
#endif
typedef enum
{
STRING,
MULT_LINE_STRING,
INTEGER,
REAL,
FILE_NAME,
DIRECTORY_NAME,
HOST_NAME,
USER_NAME,
GROUP_NAME,
DATE,
TIME,
MONEY,
HOUR,
MINUTE,
SECOND,
DAY,
MONTH,
YEAR
} AttributeType;
typedef enum
{
OPTIONAL = 0,
ALLOW_DIRECT_ENTRY = 1,
REQUIRED = 2,
EDITABLE_AFTER_CREATE = 4,
EDITABLE_DURING_CREATE = 8,
ECHO_INPUT = 16
} Characteristics;
typedef enum
{
INFORMATION_LINE,
NO_LIST,
SINGLE_SELECT_LIST,
MULTI_SELECT_LIST,
RANGE,
MULTI_SELECT_MIN_RANGE,
MULTI_SELECT_MAX_RANGE,
MULTI_SELECT_RANGE
} ValueList;
#define AllowDirectEntry(attr) (attr->Mask & ALLOW_DIRECT_ENTRY)
#define IsRequired(attr) (attr->Mask & REQUIRED)
#define EditableAfterCreate(attr) (attr->Mask & EDITABLE_AFTER_CREATE)
#define EditableDuringCreate(attr) (attr->Mask & EDITABLE_DURING_CREATE)
#define EchoInput(attr) (attr->Mask & ECHO_INPUT)
typedef struct
{
char *ReferenceName;
AttributeType Type;
Characteristics Mask;
char *DisplayName;
char *Value;
char *DisplayValue;
char *DefaultValue;
char *DisplayDefaultValue;
char *Help;
char *ContextualHelp;
ValueList ValueListType;
char *Listing;
char *Dependancies;
// The base class initializes the next 4 variables
int n_values;
char **CompiledValueList;
char **CompiledDisplayValueList;
char **CompiledHelpValueList;
} Attribute;
class BaseObj;
typedef int (*ActionHandler) (BaseObj *, char **output, BaseObj *requestor);
typedef struct
{
ActionHandler Handler;
char *ReferenceName;
char *DisplayName;
char *Nmemonic;
char *Help;
char *ContextualHelp;
char *AcceleratorText;
char *Accelerator;
boolean InputRequired;
char *Dependancies;
} Action;
extern const char *ACTION_NOT_FOUND;
class BaseObj {
protected:
char *_name;
char *_displayName;
char *_details;
BaseObj *_parent;
BaseObj **_children;
int _numChildren;
Attribute **_attributes;
int _numAttributes;
Action **_actions;
int _numActions;
boolean _init_children;
boolean _init_attributes;
char *_lastActionName;
char *_lastActionOutput;
int _lastActionStatus;
BaseObj(BaseObj *parent,
const char *name);
void AddToParent();
void DeleteFromParent();
void DeleteAttribute(const char *ReferenceName);
void AddAttribute(const char *ReferenceName,
const char *DisplayName = NULL,
const char *Help = NULL,
const char *ContextualHelp = NULL,
Characteristics Mask = OPTIONAL,
ValueList ValueListType = NO_LIST,
const char *Listing = NULL,
const char *Dependancies = NULL,
const char *DefaultValue = NULL,
const char *DisplayDefaultValue = NULL);
void DeleteAction(const char *ReferenceName);
void AddAction(ActionHandler Handler,
const char *ReferenceName,
const char *DisplayName = NULL,
const char *Nmemonic = NULL,
const char *Help = NULL,
const char *ContextualHelp = NULL,
boolean InputRequired = false,
const char *AcceleratorText = NULL,
const char *Accelerator = NULL,
const char *Dependancies = NULL);
// Derived classes should redefine these functions
virtual void InitChildren() { _children = NULL; _numChildren = 0; }
virtual void InitDetails() { }
virtual void LoadAttributes(int /*n_attrs*/, Attribute ** /*attrs*/) { }
virtual void InitDisplayName() { }
// These messages are sent to all parents
virtual void NotifyCreate(BaseObj *) { } ;
virtual void NotifyDelete(BaseObj *) { } ;
public:
virtual ~BaseObj(); // destructor
boolean HasAttribute(Attribute *action);
boolean HasAttribute(const char *ReferenceName);
boolean HasAttribute(const char *ReferenceName, Attribute **action);
boolean HasAction(Action *action);
boolean HasAction(const char *ReferenceName);
boolean HasAction(const char *ReferenceName, Action **action);
boolean SendAction(Action *action,
BaseObj *requestor = NULL);
boolean SendAction(const char *ReferenceName,
BaseObj *requestor = NULL);
char * LastActionName() { return _lastActionName; }
char * LastActionOutput() { return _lastActionOutput; }
int LastActionStatus() { return _lastActionStatus; }
const char * Name() { return _name; }
char * DisplayName();
char * Details();
char * AttributeValue(char *ReferenceName);
BaseObj * Parent() { return _parent; }
const int NumActions() { return _numActions; }
const int NumAttributes() { return _numAttributes; }
Action **Actions() { return _actions; }
Attribute **Attributes() { return _attributes; }
BaseObj ** Children();
int NumChildren();
void ReadAttributes();
void UpdateChildren();
void UpdateDetails();
void DeleteChildren();
void SetInitChildren() { _init_children = true; }
int RunCommand(const char *command,
char **std_out = NULL,
char **std_err = NULL);
// These are for children
BaseObj ** Siblings();
int NumSiblings();
// Log Error message
void Error(const char *message);
// Dumps object to stdout
void Dump(boolean verbose = false,
int level = 0);
// Dumps object heirarchy to stdout
void DumpHierarchy(boolean verbose = false,
int level = 0);
virtual const char *const ObjectClassName() { return "BaseObj"; }
};
#endif // BASEOBJ_H

View File

@@ -0,0 +1,31 @@
XCOMM $TOG: Imakefile /main/5 1998/08/25 12:59:24 mgreess $
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
#define IHaveSubdirs
#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CXXDEBUGFLAGS=$(CXXDEBUGFLAGS)'
SUBDIRS = PrintObj
MakeSubdirs($(SUBDIRS))
DependSubdirs($(SUBDIRS))
INCLUDES = -I. -I.. -I./PrintObj -I../util
#ifdef SunArchitecture
.NO_PARALLEL:
#endif
#ifdef RsArchitecture
EXTRA_DEFINES = -DHAS_EXCEPTIONS
#endif
SRCS = BaseObj.C
OBJS = BaseObj.o
NormalCplusplusObjectRule()
all:: $(OBJS)
clean::
$(RM) *.map

View File

@@ -0,0 +1,28 @@
XCOMM $XConsortium: Imakefile /main/4 1996/04/21 19:52:17 drk $
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName PrintObj
#define LibHeaders NO
#define LibInstall NO
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
INCLUDES = -I. -I.. -I../.. -I../../util
#ifdef RsArchitecture
DEFINES = -DHAS_EXCEPTIONS
#endif
#ifdef AlphaArchitecture
DEFINES = -UNO_REGCOMP
#endif
SRCS = ParseJobs.C PrintJob.C PrintSubSys.C Queue.C
OBJS = ParseJobs.o PrintJob.o PrintSubSys.o Queue.o
#include <Library.tmpl>
DependTarget()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
/* $XConsortium: ParseJobs.h /main/3 1995/11/06 09:46:45 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PARSEJOBS_H
#define PARSEJOBS_H
typedef enum
{
UNKNOWN_OUTPUT,
AIX_V2_OUTPUT,
AIX_V3_OUTPUT,
BSD_OUTPUT
} JobOutputType;
extern JobOutputType DetermineOutput(char *output);
// returns socket to print server, or -1 if error
// timeout is in seconds, a default of 5 is used if timeout <= 0.
extern int ConnectToPrintServer(const char *server, int timeout);
// return 0 if error, otherwise return 1 if successful
extern int SendPrintJobStatusReguest(int sockfd, const char *printer);
extern void LocalPrintJobs(
char *printer,
char **return_job_list,
int *return_n_jobs);
extern int RemotePrintJobs(
char *server,
char *printer,
char **return_job_list,
int *return_n_jobs);
extern int ParseRemotePrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
extern int ParseBSDPrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
extern int ParseAIXv3PrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
extern int ParseAIXv2PrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
#endif // PARSEJOBS_H

View File

@@ -0,0 +1,107 @@
/* $TOG: PrintJob.C /main/6 1998/07/24 16:17:39 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "PrintJob.h"
// Object Class Name
const char *PRINTJOB = "PrintJob";
// Actions
const char *CANCEL_PRINT_JOB = "CancelPrintJob";
// Attributes
const char *PRINTJOB_NAME = "PrintJobName";
const char *OWNER = "Owner";
const char *JOB_NUMBER = "JobNumber";
const char *JOB_SIZE = "JobSize";
const char *SUBMITTED = "Submitted";
const char *DATE_SUBMITTED = "DateSubmitted";
const char *TIME_SUBMITTED = "TimeSubmitted";
PrintJob::PrintJob(BaseObj *parent,
char *JobName,
char *JobNumber,
char *Owner,
char *Date,
char *Time,
char *Size)
: BaseObj(parent, JobName)
{
AddAction(&PrintJob::CancelJob, CANCEL_PRINT_JOB, MESSAGE(CancelChoiceL),
MESSAGE(CancelMnemonicL), NULL, NULL, true,
MESSAGE(CancelAcceleratorL), "<Key>osfDelete");
char *Help = NULL, *ContextualHelp = NULL, *Listing = NULL;
Characteristics Mask = OPTIONAL;
ValueList ValueListType = NO_LIST;
int n = 0;
AddAttribute(PRINTJOB_NAME, MESSAGE(JobNameL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(JobName);
_attributes[n]->DisplayValue = STRDUP(JobName);
n++;
AddAttribute(OWNER, MESSAGE(OwnerL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Owner);
_attributes[n]->DisplayValue = STRDUP(Owner);
n++;
AddAttribute(JOB_NUMBER, MESSAGE(JobNumberL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(JobNumber);
_attributes[n]->DisplayValue = STRDUP(JobNumber);
_jobNumber = _attributes[n]->DisplayValue;
n++;
AddAttribute(JOB_SIZE, MESSAGE(SizeL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Size);
_attributes[n]->DisplayValue = STRDUP(Size);
n++;
ValueListType = INFORMATION_LINE;
AddAttribute(SUBMITTED, MESSAGE(SubmittedL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Time);
_attributes[n]->DisplayValue = STRDUP(Time);
n++;
ValueListType = NO_LIST;
char *message = new char [strlen(MESSAGE(TimeL)) + 4];
sprintf(message, " %s", MESSAGE(TimeL));
AddAttribute(TIME_SUBMITTED, message,
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Time);
_attributes[n]->DisplayValue = STRDUP(Time);
delete [] message;
n++;
message = new char [strlen(MESSAGE(DateL)) + 4];
sprintf(message, " %s", MESSAGE(DateL));
AddAttribute(DATE_SUBMITTED, message,
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Date);
_attributes[n]->DisplayValue = STRDUP(Date);
delete [] message;
}
PrintJob::~PrintJob()
{
// Empty
}
int PrintJob::CancelJob(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
static char command[256];
PrintJob *me = (PrintJob *) obj;
#ifdef aix
sprintf(command, "enq -P%s -x%s", me->Parent()->Name(), me->_jobNumber);
#elif __osf__
sprintf(command, "lprm -P%s %s", me->Parent()->Name(), me->_jobNumber);
#else
sprintf(command, "cancel %s-%s", me->Parent()->Name(), me->_jobNumber);
#endif
return me->RunCommand(command, NULL, output);
}

View File

@@ -0,0 +1,54 @@
/* $XConsortium: PrintJob.h /main/3 1995/11/06 09:47:08 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PRINTJOB_H
#define PRINTJOB_H
#include "BaseObj.h"
#include "dtprintinfomsg.h"
#include <string.h>
// Object Class Name
extern const char *PRINTJOB;
// Actions
extern const char *CANCEL_PRINT_JOB;
// Attributes
extern const char *PRINTJOB_NAME;
extern const char *OWNER;
extern const char *JOB_NUMBER;
extern const char *JOB_SIZE;
extern const char *SUBMITTED;
extern const char *DATE_SUBMITTED;
extern const char *TIME_SUBMITTED;
class PrintJob : public BaseObj {
friend int CancelJob(BaseObj *, char **output, BaseObj *requestor);
protected:
char *_jobNumber;
static int CancelJob(BaseObj *, char **output, BaseObj *requestor);
public:
PrintJob(BaseObj *parent, char *JobName, char *JobNumber, char *Owner,
char *Date, char *Time, char *Size);
virtual ~PrintJob();
const char *JobNumber() { return _jobNumber; }
virtual const char *const ObjectClassName() { return PRINTJOB; }
};
#endif // PRINTJOB_H

View File

@@ -0,0 +1,86 @@
/* $XConsortium: PrintSubSys.C /main/4 1996/01/17 18:02:47 lehors $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "PrintSubSys.h"
#include "Queue.h"
#include <string.h>
#ifdef aix
const char *LIST_QUEUES = "lsallq | grep -v '^bsh$' | sort";
#else
#ifdef hpux
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"awk '"
" $2 == \"for\" "
" { "
" x = match($3, /:/); "
" print substr($3, 1, x-1)"
" }' | sort";
#else
#ifdef __osf__
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"nawk '"
" $2 == \"for\" "
" { print $10 }' "
" | sort";
#else
#ifdef __uxp__
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"nawk '"
" $4 == \"for\" "
" { "
" x = match($5, /:/); "
" print substr($5, 1, x-1)"
" }' | sort";
#else
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"nawk '"
" $2 == \"for\" "
" { "
" x = match($3, /:/); "
" print substr($3, 1, x-1)"
" }' | sort";
#endif
#endif
#endif
#endif
// Object Class Name
const char *PRINTSUBSYSTEM = "PrintSubSystem";
PrintSubSystem::PrintSubSystem(BaseObj *parent)
: BaseObj(parent, "PrintSubSystem")
{
_displayName = strdup(MESSAGE(PrinterMenuL));
_details = strdup("Status Number Owner Date Time Size");
}
PrintSubSystem::~PrintSubSystem()
{
// Empty
}
void PrintSubSystem::InitChildren()
{
char *std_out;
if (RunCommand(LIST_QUEUES, &std_out))
{
Error("InitChildren method could not list queues.");
}
else
{
char *queue = strtok(std_out, " \n");
while (queue && *queue)
{
new Queue(this, queue);
queue = strtok(NULL, " \n");
}
}
delete std_out;
}

View File

@@ -0,0 +1,36 @@
/* $XConsortium: PrintSubSys.h /main/3 1995/11/06 09:47:33 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PRINTSUBSYS_H
#define PRINTSUBSYS_H
#include "BaseObj.h"
#include "dtprintinfomsg.h"
// Object Class Name
extern const char *PRINTSUBSYSTEM;
// List Children command;
extern const char *LIST_QUEUES;
class PrintSubSystem : public BaseObj {
protected:
void InitChildren();
public:
PrintSubSystem(BaseObj *parent);
virtual ~PrintSubSystem();
virtual const char *const ObjectClassName() { return PRINTSUBSYSTEM; }
};
#endif // PRINTSUBSYS_H

View File

@@ -0,0 +1,440 @@
/* $TOG: Queue.C /main/4 1998/07/24 16:17:58 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Queue.h"
#include "PrintJob.h"
#include "ParseJobs.h"
#include <stdlib.h>
extern "C" {
#include <Dt/DtNlUtils.h>
}
#ifdef aix
const char *GET_ATTRS = "lsque -cq%s |awk -F: 'NR == 2 {print $2,$6,$9}' OFS=:";
const char *GET_QUEUE_STATUS = "LANG=C enq -As -P%s | "
"egrep 'READY|RUNNING' > /dev/null";
const char *GET_DEVICE_STATUS = "LANG=C enq -As -P%s | "
"egrep 'READY|RUNNING' > /dev/null";
const char *START_QUEUE_CMD = "enq -U -P%s";
const char *STOP_QUEUE_CMD = "enq -D -P%s";
#else
#ifdef hpux
const char *GET_ATTRS = "LANG=C lpstat -v%s 2>&1 | awk '"
"BEGIN { device=\"\"; rhost=\"\"; rp=\"\" } "
"/device for/ { device = $4 } "
"/remote to/ { rhost = $5; rp = $3 } "
"END { print device,rhost,rp }' OFS=:";
const char *GET_QUEUE_STATUS = "LANG=C lpstat -i -a%s | awk '"
"{if ($2 == \"not\") {exit 1} else {exit 0}}'";
const char *GET_DEVICE_STATUS = "LANG=C lpstat -i -p%s | "
"awk '/disabled/ {exit 1}'";
const char *START_QUEUE_CMD = "/usr/lib/accept %s";
const char *STOP_QUEUE_CMD = "/usr/lib/reject %s";
const char *START_PRINTING_CMD = "enable %s";
const char *STOP_PRINTING_CMD = "disable %s";
#else
const char *GET_ATTRS = "LANG=C lpstat -v %s 2>&1 | nawk '"
"BEGIN { device=\"\"; rhost=\"\"; rp=\"\" } "
"/device for/ { device = $4 } "
"/system for/ { rhost = $4; x = match($7, /\\)/); "
" if (x == 0) "
" rp = substr($3, 1, match($3, /:/) - 1); "
" else "
" rp = substr($7, 1, x - 1) } "
"END { print device,rhost,rp }' OFS=:";
const char *GET_QUEUE_STATUS = "LANG=C lpstat -a%s | awk '"
"{if ($2 == \"not\") {exit 1} else {exit 0}}'";
const char *GET_DEVICE_STATUS = "LANG=C lpstat -p%s | "
"awk '/disabled/ {exit 1}'";
const char *START_QUEUE_CMD = "/usr/sbin/accept %s";
const char *STOP_QUEUE_CMD = "/usr/sbin/reject %s";
const char *START_PRINTING_CMD = "enable %s";
const char *STOP_PRINTING_CMD = "disable %s";
#endif
#endif
// Object Class Name
const char *QUEUE = "Queue";
// Actions
const char *START_QUEUE = "StartQueue";
const char *STOP_QUEUE = "StopQueue";
#ifndef aix
const char *START_PRINTING = "StartPrinting";
const char *STOP_PRINTING = "StopPrinting";
#endif
// Attributes
const char *ICON_NAME = "IconName";
const char *PRINTER_QUEUE = "PrinterQueue";
const char *QUEUE_DEVICE = "QueueDevice";
Queue::Queue(BaseObj *parent,
char *_name)
: BaseObj(parent, _name)
{
if (getenv("DO_ADMIN"))
{
AddAction(&Queue::Start, START_QUEUE, MESSAGE(StartChoiceL),
MESSAGE(StartMnemonicL));
AddAction(&Queue::Stop, STOP_QUEUE, MESSAGE(StopChoiceL),
MESSAGE(StopMnemonicL));
#ifndef aix
AddAction(&Queue::StartPrint, START_PRINTING, MESSAGE(EnableChoiceL),
MESSAGE(EnableMnemonicL));
AddAction(&Queue::StopPrint, STOP_PRINTING, MESSAGE(DisableChoiceL),
MESSAGE(DisableMnemonicL));
#endif
}
#ifdef aix
local_devices = NULL;
n_devices = 0;
#endif
remote_server = NULL;
remote_printer = NULL;
is_remote = false;
_loaded_attributes = false;
char *Help = NULL, *ContextualHelp = NULL, *Listing = NULL;
Characteristics Mask = EDITABLE_AFTER_CREATE;
ValueList ValueListType = NO_LIST;
// AddAttribute(ICON_NAME, MESSAGE(IconNameL),
// Help, ContextualHelp, Mask, ValueListType, Listing);
Mask = OPTIONAL;
AddAttribute(PRINTER_QUEUE, MESSAGE(PrintQueueL),
Help, ContextualHelp, Mask, ValueListType, Listing);
AddAttribute(QUEUE_DEVICE, MESSAGE(DeviceL),
Help, ContextualHelp, Mask, ValueListType, Listing);
}
Queue::~Queue()
{
#ifdef aix
int i;
for (i = 0; i < n_devices; i++)
delete local_devices[i];
delete local_devices;
#endif
delete remote_server;
delete remote_printer;
}
void Queue::LoadAttributes(int /*n_attrs*/, Attribute **attrs)
{
char *command = new char[500];
sprintf(command, GET_ATTRS, Name());
char *output;
RunCommand(command, &output);
delete [] command;
char *s = output, *s1;
char *dollar[3];
int i;
for (i = 0; i < 3; i++)
{
if (s1 = strchr(s, ':'))
*s1++ = '\0';
else if (s1 = strchr(s, '\n'))
*s1++ = '\0';
dollar[i] = s;
s = s1;
}
i = 0;
attrs[i]->Value = strdup(Name());
attrs[i]->DisplayValue = strdup(Name());
i++;
if (_loaded_attributes == false)
{
if (*dollar[2]) // It's a remote printer
{
#ifdef aix
n_devices = 1;
local_devices = new char *[1];
local_devices[0] = new char[strlen(Name()) + strlen(dollar[0]) + 2];
sprintf(local_devices[0], "%s:%s", Name(), dollar[0]);
#endif
is_remote = true;
char *new_value = new char [strlen(MESSAGE(PrinterOnServerL)) +
strlen(dollar[1]) + strlen(dollar[2])];
remote_server = strdup(dollar[1]);
remote_printer = strdup(dollar[2]);
sprintf(new_value, MESSAGE(PrinterOnServerL), remote_printer,
remote_server);
attrs[i]->Value = strdup(new_value);
attrs[i]->DisplayValue = strdup(new_value);
delete [] new_value;
}
else // It's a local printer
{
#ifdef aix
if (strchr(dollar[0], ',')) // AIX can have multiple devices per queue
{
DeleteAttribute(QUEUE_DEVICE);
char *device = new char [strlen(MESSAGE(DeviceNL)) + 4];
s = dollar[0];
while (s && *s)
{
if (s1 = strchr(s, ','))
s1++;
s = s1;
n_devices++;
}
local_devices = new char *[n_devices];
n_devices = 0;
s = dollar[0];
while (s && *s)
{
sprintf(device, MESSAGE(DeviceNL), n_devices + 1);
AddAttribute(QUEUE_DEVICE, device,
NULL, NULL, OPTIONAL, NO_LIST, NULL);
if (s1 = strchr(s, ','))
*s1++ = '\0';
_attributes[i]->Value = strdup(s);
_attributes[i]->DisplayValue = strdup(s);
local_devices[n_devices] = new char[strlen(Name()) + strlen(s)+2];
sprintf(local_devices[n_devices], "%s:%s", Name(), s);
i++;
s = s1;
n_devices++;
}
delete [] device;
}
else
#endif
{
#ifdef aix
n_devices = 1;
local_devices = new char *[1];
local_devices[0] = new char[strlen(Name()) + strlen(dollar[0]) + 2];
sprintf(local_devices[0], "%s:%s", Name(), dollar[0]);
#endif
attrs[i]->Value = strdup(dollar[0]);
attrs[i]->DisplayValue = strdup(dollar[0]);
}
}
_loaded_attributes = true;
}
delete output;
}
#ifdef aix
char *Queue::Device(int index)
{
if (_loaded_attributes == false)
ReadAttributes();
if (index >= 0 && index <= n_devices)
return local_devices[index];
else
return NULL;
}
int Queue::NumberDevices()
{
if (_loaded_attributes == false)
ReadAttributes();
return n_devices;
}
#endif
int Queue::Start(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
int rc;
char *command = new char[100];
#ifdef aix
if (queue->n_devices > 1)
{
sprintf(command, START_QUEUE_CMD, "$d");
int i, len;
len = 30 + strlen(command) + queue->n_devices;
for (i = 0; i < queue->n_devices; i++)
len += strlen(queue->local_devices[i]);
char *cmd = new char[len];
strcpy(cmd, "for d in");
for (i = 0; i < queue->n_devices; i++)
{
strcat(cmd, " ");
strcat(cmd, queue->local_devices[i]);
}
strcat(cmd, " ; do ");
strcat(cmd, command);
strcat(cmd, "; done");
rc = queue->RunCommand(cmd, NULL, output);
delete [] cmd;
}
else
#endif
{
sprintf(command, START_QUEUE_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
}
delete [] command;
return rc;
}
int Queue::Stop(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
char *command = new char[100];
int rc;
#ifdef aix
if (queue->n_devices > 1)
{
sprintf(command, STOP_QUEUE_CMD, "$d");
int i, len;
len = 30 + strlen(command) + queue->n_devices;
for (i = 0; i < queue->n_devices; i++)
len += strlen(queue->local_devices[i]);
char *cmd = new char[len];
strcpy(cmd, "for d in");
for (i = 0; i < queue->n_devices; i++)
{
strcat(cmd, " ");
strcat(cmd, queue->local_devices[i]);
}
strcat(cmd, " ; do ");
strcat(cmd, command);
strcat(cmd, "; done");
rc = queue->RunCommand(cmd, NULL, output);
delete [] cmd;
}
else
#endif
{
sprintf(command, STOP_QUEUE_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
}
delete [] command;
return rc;
}
#ifndef aix
int Queue::StartPrint(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
char *command = new char[100];
int rc;
sprintf(command, STOP_PRINTING_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
delete [] command;
return rc;
}
int Queue::StopPrint(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
char *command = new char[100];
int rc;
sprintf(command, STOP_PRINTING_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
delete [] command;
return rc;
}
#endif
void Queue::InitChildren()
{
if (_loaded_attributes == false)
ReadAttributes();
ProcessJobs();
}
void Queue::ProcessJobs(char *jobs)
{
char *job_list;
int n_jobs;
// Get remote jobs first
if (is_remote)
{
int rc;
if (jobs)
rc = ParseRemotePrintJobs(remote_printer, jobs, &job_list, &n_jobs);
else
rc = RemotePrintJobs(remote_server, remote_printer, &job_list,
&n_jobs);
remote_up = rc ? true : false;
ParseOutput(job_list, n_jobs);
#ifdef sun
return;
#endif
}
// Get local jobs next
#ifdef aix
if (is_remote)
LocalPrintJobs(local_devices[0], &job_list, &n_jobs);
else
LocalPrintJobs((char*)Name(), &job_list, &n_jobs);
#else
LocalPrintJobs((char*)Name(), &job_list, &n_jobs);
#endif
ParseOutput(job_list, n_jobs);
}
void Queue::ParseOutput(char *job_list, int n_jobs)
{
int i;
char *printer = DtStrtok(job_list, "|");
for (i = 0; i < n_jobs; i++)
{
char *JobName = DtStrtok(NULL, "|");
char *JobNumber = DtStrtok(NULL, "|");
char *Owner = DtStrtok(NULL, "|");
char *Date = DtStrtok(NULL, "|");
char *Time = DtStrtok(NULL, "|");
char *tmp = DtStrtok(NULL, "\n");
char *Size = new char [strlen(tmp) + strlen(MESSAGE(BytesL)) + 2];
sprintf(Size, "%s %s", tmp, MESSAGE(BytesL));
new PrintJob(this, JobName, JobNumber, Owner, Date, Time, Size);
delete [] Size;
printer = DtStrtok(NULL, "|");
}
}
void Queue::ParseRemoteStatus(char *output)
{
SetInitChildren();
DeleteChildren();
if (_loaded_attributes == false)
ReadAttributes();
ProcessJobs(output);
}
boolean Queue::IsRemote()
{
if (_loaded_attributes == false)
ReadAttributes();
return is_remote;
}
const char *Queue::RemotePrinter()
{
if (_loaded_attributes == false)
ReadAttributes();
return remote_printer;
}
const char *Queue::Server()
{
if (_loaded_attributes == false)
ReadAttributes();
return remote_server;
}

View File

@@ -0,0 +1,89 @@
/* $XConsortium: Queue.h /main/3 1995/11/06 09:47:44 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef QUEUE_H
#define QUEUE_H
#include "BaseObj.h"
#include "dtprintinfomsg.h"
// Object Class Name
extern const char *QUEUE;
// Actions
extern const char *START_QUEUE;
extern const char *STOP_QUEUE;
#ifndef aix
extern const char *START_PRINTING;
extern const char *STOP_PRINTING;
#endif
// Attributes
extern const char *ICON_NAME;
extern const char *PRINTER_QUEUE;
extern const char *QUEUE_DEVICE;
// Status Commands
extern const char *GET_QUEUE_STATUS;
extern const char *GET_DEVICE_STATUS;
class Queue : public BaseObj {
friend int Start(BaseObj *, char **output, BaseObj *requestor);
friend int Stop(BaseObj *, char **output, BaseObj *requestor);
#ifndef aix
friend int StartPrint(BaseObj *, char **output, BaseObj *requestor);
friend int StopPrint(BaseObj *, char **output, BaseObj *requestor);
#endif
protected:
static int Start(BaseObj *, char **output, BaseObj *requestor);
static int Stop(BaseObj *, char **output, BaseObj *requestor);
#ifndef aix
static int StartPrint(BaseObj *, char **output, BaseObj *requestor);
static int StopPrint(BaseObj *, char **output, BaseObj *requestor);
#endif
boolean _loaded_attributes;
void InitChildren();
void LoadAttributes(int numAttributes, Attribute **attributes);
void ParseOutput(char *, int);
void ProcessJobs(char *jobs = NULL);
boolean is_remote;
boolean remote_up;
#ifdef aix
char **local_devices;
int n_devices;
#endif
char *remote_server;
char *remote_printer;
public:
Queue(BaseObj *parent, char *name);
virtual ~Queue();
const char *Server();
const char *RemotePrinter();
#ifdef aix
char *Device(int index = 0);
int NumberDevices();
#endif
boolean IsRemote();
boolean RemoteUp() { return remote_up; }
void ParseRemoteStatus(char *output);
virtual const char *const ObjectClassName() { return QUEUE; }
};
#endif // QUEUE_H

View File

@@ -0,0 +1,68 @@
#! /bin/ksh
#
# file: sym2num
#
# purpose: 1. to create a header file containing the identifiers
# and replacement list consisting of the symbols used
# in a message set as well as the messages themselves.
#
# 2. to provide output to standard out which can be used
# by gencat.
#
typeset -u CAP_SYMBOL_NAME
(( $# != 2 )) && { print "usage: sym2num <symbol name> <source file>" ;\
exit 1 ; }
SYMBOL_NAME=$1
CAP_SYMBOL_NAME=$1 # capitalized symbol name
SOURCE_FILE=$2
inc_file=${SYMBOL_NAME}_msg.h # include file
#### Step 1: Create a header file ####
# write first five lines to "<symbolname>_msg.h"
cat <<! > ${inc_file}
#ifndef _H_${CAP_SYMBOL_NAME}_MSG
#define _H_${CAP_SYMBOL_NAME}_MSG
#include <limits.h>
#include <nl_types.h>
#define MF_${CAP_SYMBOL_NAME} "${SYMBOL_NAME}.cat"
/* The following was generated from ${SOURCE_FILE}. */
!
# locate all lines which start with "$set", and then increment
# the set counter and reset the message counter to zero.
awk '/^\$set/ { SET_NAME=$2; SET_COUNT++; MES_COUNT=0;
printf( "\n/* definitions for set %s */\n", SET_NAME );
printf( "#define %s %s\n\n", SET_NAME, SET_COUNT) } #to be continued
# find all lines which begin with a combination of letters, numbers
# and underscores followed by spaces and then a quotation mark,
# and increment the message counter.
/^[0-9A-Za-z_]+[ |\t]*\"/ { MES_NAME=$1; MES_COUNT++;
printf( "#define %s %s\n", MES_NAME, MES_COUNT) }
END {print "#define LAST_MSG_NO "MES_COUNT"\n\n#endif"}' \
${SOURCE_FILE} >> ${inc_file}
#### Step 2: Create input to gencat ####
# cat the definition statements of the include file and cat them to
# the source message file. The awk file only creates define statements
# and blank lines. The output should be sent to the preprocessor.
# There are two differences between sym2num and mkcatdefs: sym2num
# does not create a $delset line, and sym2num converts all symbols
# to numbers, even those in comment statements.
if [[ -f /usr/ccs/lib/cpp ]] #IBM & SUN
then
cpp_path=/usr/ccs/lib
elif [[ -f /lib/cpp ]] #HP
then
cpp_path=/lib
fi
( cat ${inc_file} | sed -n /define/p ; cat ${SOURCE_FILE} ) | \
${cpp_path}/cpp -P | sed '/^$/d' | sed 's/^\([1-9][0-9]*\)[ ]*\(.*\)/\1 \2/'

View File

@@ -0,0 +1,24 @@
XCOMM $XConsortium: Imakefile /main/4 1996/04/21 19:50:47 drk $
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName Util
#define LibHeaders NO
#define LibInstall NO
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
INCLUDES = -I.
#ifdef RsArchitecture
EXTRA_DEFINES = -DHAS_EXCEPTIONS
#endif
SRCS = Invoke.C Process.C
OBJS = Invoke.o Process.o
#include <Library.tmpl>
DependTarget()

View File

@@ -0,0 +1,339 @@
/* $TOG: Invoke.C /main/7 1997/07/30 15:42:39 samborn $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Invoke.h"
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#include <values.h>
#ifdef _AIX
#include <strings.h> /* need to get bzero defined */
#endif /* _AIX */
const BUFFER_SIZE = 512;
Invoke::Invoke(const char *command, // Command to Run
char **out_ptr, // ptr to output buffer ptr
char **err_ptr, // ptr to error buffer ptr
uid_t _uid) // run command as this UID
{
int m_stdout[2], m_stderr[2]; // progname file descriptors
pid_t c_pid; // child's pid
pid_t w; // temp vars
int out_num,err_num; // # of chars read
char *out_tmp, *err_tmp; // temp buffer ptrs
char *out_end,*err_end; // ptr to end of buffer
int outb_size,errb_size; // buffer size
int out_count, err_count; // # of buffers allocated
int trap_out,trap_err; // flags; if >0, trap output
fd_set rdmask; // for select system call
fd_set wrmask; // for select system call
fd_set exmask; // for select system call
int Nfdsmsgs;
struct sigaction action; // parameters of sigaction
struct sigaction oldsigint_act;
struct sigaction oldsigquit_act;
status = 0;
trap_out = (out_ptr != NULL);
trap_err = (err_ptr != NULL);
// initialize internal variables
out_num = err_num = 0;
// setup pipes if specified
if (trap_out)
{
*out_ptr = 0;
if (pipe(m_stdout) < 0)
{
status = -1;
return;
}
}
if (trap_err)
{
*err_ptr = 0;
if (pipe(m_stderr) < 0)
{
if (trap_out)
close(m_stdout[0]);
status = -1;
return;
}
}
if (trap_err)
Nfdsmsgs = m_stderr[0] + 1;
else if (trap_out)
Nfdsmsgs = m_stdout[0] + 1;
else
Nfdsmsgs = 0;
// ignore these signals
memset(&action, '\0', sizeof (struct sigaction));
memset(&oldsigquit_act, '\0', sizeof (struct sigaction));
memset(&oldsigint_act, '\0', sizeof (struct sigaction));
#if defined(__OSF1__) || defined(__osf__)
action.sa_handler = (void (*)(int))SIG_IGN;
#elif defined(USL) || defined(__uxp__) || \
( defined(sun) && OSMAJORVERSION == 5 && OSMINORVERSION <= 4)
action.sa_handler = (void (*)())SIG_IGN;
#else
action.sa_handler = SIG_IGN;
#endif
sigaction(SIGINT, &action, &oldsigint_act);
sigaction(SIGQUIT, &action, &oldsigquit_act);
if ((c_pid = fork()) == 0)
{ // ------------------------ child process --------------------------
if (_uid != (uid_t)-1)
setuid(_uid);
if (trap_out)
{ // duplicate stdout
close(m_stdout[0]);
close(1);
dup(m_stdout[1]);
close(m_stdout[1]);
}
if (trap_err)
{ // duplicate stderr
close(m_stderr[0]);
close(2);
dup(m_stderr[1]);
close(m_stderr[1]);
}
// start the program
execlp("/bin/ksh", "ksh", "-c", command, (char *) 0);
exit(-1);
}
else if (c_pid == -1)
{
if (trap_err)
close(m_stderr[0]);
if (trap_out)
close(m_stdout[0]);
status = -1;
return;
}
// -------------------------- parent process --------------------------
// restore signals
sigaction(SIGINT, &oldsigint_act, NULL);
sigaction(SIGQUIT, &oldsigquit_act, NULL);
// close the write side of the pipe for the parent
if (trap_out)
{
close(m_stdout[1]);
fcntl(m_stdout[0], F_SETFL, O_NDELAY);
}
if (trap_err)
{
close(m_stderr[1]);
fcntl(m_stderr[0], F_SETFL, O_NDELAY);
}
if (!trap_out && !trap_err)
{ // no piped output
// wait for the child to die
while ((w = wait(&status)) != c_pid && w != -1)
;
status = (status >> 8) & 0xFF;
return;
}
// initialize buffer pointers
if (trap_out)
{
*out_ptr = (char *) malloc(BUFFER_SIZE);
if (*out_ptr == NULL)
{
close(m_stdout[0]);
if (trap_err)
close(m_stderr[0]);
status = -1;
return;
}
out_tmp = *out_ptr;
out_end = *out_ptr + BUFFER_SIZE - 1;
out_count = 1;
outb_size = BUFFER_SIZE;
}
if (trap_err)
{
*err_ptr = (char *) malloc(BUFFER_SIZE);
if (*err_ptr == NULL)
{
close(m_stderr[0]);
if (trap_out)
close(m_stdout[0]);
status = -1;
return;
}
*err_ptr = (char *) malloc(BUFFER_SIZE);
err_tmp = *err_ptr;
err_end = *err_ptr + BUFFER_SIZE - 1;
err_count = 1;
errb_size = BUFFER_SIZE;
}
while (trap_out || trap_err)
{
// reset the file descriptor masks
FD_ZERO(&rdmask);
FD_ZERO(&wrmask);
FD_ZERO(&exmask);
// set the bit masks for the descriptors to be checked
if (trap_out)
FD_SET(m_stdout[0], &rdmask);
if (trap_err)
FD_SET(m_stderr[0], &rdmask);
// check the status
if (select(Nfdsmsgs,&rdmask,&wrmask,&exmask,(struct timeval *)NULL) == -1)
{
if (errno == EINTR)
continue;
else
{
if (trap_out)
close(m_stdout[0]);
if (trap_err)
close(m_stderr[0]);
status = -1;
return;
}
}
if (trap_out && FD_ISSET(m_stdout[0], &rdmask))
{
// read the child's stdout
if ((out_num = read(m_stdout[0], out_tmp, outb_size)) < 0)
{
close(m_stdout[0]);
if (trap_err)
close(m_stderr[0]);
status = -1;
return;
}
if (out_num == 0)
{
// no more to read
trap_out = 0;
close(m_stdout[0]);
*out_tmp = '\0';
}
else if (out_num == outb_size)
{
// filled up a buffer; allocate another one
out_count++;
*out_ptr = (char *)realloc(*out_ptr, (out_count * BUFFER_SIZE));
if (*out_ptr == NULL)
{
close(m_stdout[0]);
if (trap_err)
close(m_stderr[0]);
status = -1;
return;
}
out_tmp = *out_ptr + ((out_count - 1) * BUFFER_SIZE);
out_end = out_tmp + BUFFER_SIZE - 1;
outb_size = BUFFER_SIZE;
}
else if (out_num > 0)
{
// read less than a full buffer; reset amount to read next
out_tmp += out_num;
outb_size = out_end - out_tmp + 1;
outb_size = (outb_size > 0) ? outb_size : 0;
}
} // if trap_out
if (trap_err && FD_ISSET(m_stderr[0], &rdmask))
{
// read the child's stderr
if ((err_num = read(m_stderr[0], err_tmp, errb_size)) == -1)
{
if (trap_out)
close(m_stdout[0]);
close(m_stderr[0]);
status = -1;
return;
}
if (err_num == 0)
{
// no more to read
trap_err = 0;
close(m_stderr[0]);
*err_tmp = '\0';
}
else if (err_num == errb_size)
{
// filled up a buffer; allocate another one
err_count++;
*err_ptr = (char *)realloc(*err_ptr, (err_count * BUFFER_SIZE));
if (*err_ptr == NULL)
{
close(m_stderr[0]);
if (trap_out)
close(m_stdout[0]);
status = -1;
return;
}
err_tmp = *err_ptr + ((err_count - 1) * BUFFER_SIZE);
err_end = err_tmp + BUFFER_SIZE - 1;
errb_size = BUFFER_SIZE;
}
else if (err_num > 0)
{
// read less than a full buffer; reset amount to read next
err_tmp += err_num;
errb_size = err_end - err_tmp + 1;
errb_size = (errb_size > 0) ? errb_size : 0;
}
} // if trap_err
} // while trap_out or trap_err
while ((w = wait(&status)) != c_pid && w != -1);
status = (status >> 8) & 0xFF;
}

View File

@@ -0,0 +1,28 @@
/* $XConsortium: Invoke.h /main/4 1996/10/01 16:09:57 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef INVOKE_H
#define INVOKE_H
#include <sys/types.h>
#include <stdio.h>
class Invoke
{
public:
int status;
Invoke(const char *command,
char **std_out = NULL,
char **std_err = NULL,
uid_t uid = (uid_t)-1); // To run the command as another, set uid >= 0
};
#endif // INVOKE_H

View File

@@ -0,0 +1,111 @@
/* $XConsortium: Process.C /main/3 1996/10/01 16:10:01 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Process.h"
#include "Invoke.h"
#include <string.h>
#include <stdlib.h>
Process::Process()
{
#ifdef aix
(void)Invoke("ps -e -F \"pid ppid uid command\"", &procs);
#else
(void)Invoke("/bin/ps -el | awk '{printf(\"%s %s %s %s\\n\",$4,$5,$3,$NF)}'",
&procs);
#endif
pprocs = (char **)malloc(sizeof(char *));
NumProcs = 0;
strtok(procs, "\n");
while(pprocs[NumProcs] = strtok(NULL, "\n"))
{
NumProcs++;
pprocs = (char **)realloc(pprocs, sizeof(char *) * (NumProcs + 1));
}
last_pid = -1;
}
Process::~Process()
{
free(procs);
free(pprocs);
}
char *Process::GetByPid(pid_t _pid)
{
int i;
if (last_pid == _pid)
return last_proc;
if (_pid)
for (i = 0; i < NumProcs; i++)
{
long long_pid, long_ppid, long_uid;
sscanf(pprocs[i], "%ld %ld %ld", &long_pid, &long_ppid, &long_uid);
pid = (pid_t)long_pid;
ppid = (pid_t)long_ppid;
uid = (uid_t)long_uid;
if (_pid == pid)
{
last_pid = _pid;
last_proc = pprocs[i];
return pprocs[i];
}
}
return NULL;
}
pid_t Process::Parent(pid_t pid)
{
char *proc = GetByPid(pid);
if (proc)
return ppid;
else
return (pid_t)-1;
}
uid_t Process::UID(pid_t pid)
{
char *proc = GetByPid(pid);
if (proc)
return uid;
else
return (uid_t)-1;
}
char *Process::Command(pid_t _pid)
{
char *proc = GetByPid(_pid);
if (proc)
{
char *s;
// Find first field
for (s = proc; *s == ' '; s++)
;
for ( ; *s != ' '; s++)
;
// Find second field
for ( ; *s == ' '; s++)
;
for ( ; *s != ' '; s++)
;
// Find third field
for ( ; *s == ' '; s++)
;
for ( ; *s != ' '; s++)
;
// Find fourth field
for ( ; *s == ' '; s++)
;
return s;
}
else
return NULL;
}

View File

@@ -0,0 +1,36 @@
/* $XConsortium: Process.h /main/4 1996/10/01 16:10:06 drk $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PROCESS_H
#define PROCESS_H
#include <sys/types.h>
class Process {
int NumProcs;
pid_t last_pid;
char **pprocs;
char *procs;
char *last_proc;
char *GetByPid(pid_t);
uid_t uid;
pid_t pid;
pid_t ppid;
public:
Process();
~Process();
pid_t Parent(pid_t pid);
uid_t UID(pid_t pid);
char *Command(pid_t pid);
};
#endif // PROCESS_H