2 * $TOG: AddLibraryAgentMotif.C /main/10 1998/08/05 11:46:23 mgreess $
4 * (c) Copyright 1996 Digital Equipment Corporation.
5 * (c) Copyright 1996 Hewlett-Packard Company.
6 * (c) Copyright 1996 International Business Machines Corp.
7 * (c) Copyright 1996 Sun Microsystems, Inc.
8 * (c) Copyright 1996 Novell, Inc.
9 * (c) Copyright 1996 FUJITSU LIMITED.
10 * (c) Copyright 1996 Hitachi.
21 #define C_WindowSystem
24 #define C_AddLibraryAgent
29 #include "Other/XmStringLocalized.hh"
30 #include "Managers/CatMgr.hh"
34 #include "Registration.hh"
36 #define CLASS AddLibraryAgent
37 #include "create_macros.hh"
39 #include <WWL/WComposite.h>
40 #include <WWL/WXmSeparator.h>
42 AddLibraryAgent::AddLibraryAgent (Widget parent):
43 f_shell (parent, True, "add_library_agent"),
44 f_done (False), f_cancelled (False), f_file_sel (NULL) {
49 AddLibraryAgent::~AddLibraryAgent() {
51 XtDestroyWidget (XtParent(f_form));
55 AddLibraryAgent::create_ui (Widget parent) {
57 XmStringLocalized mtfstring;
60 window_system().register_full_modal_shell (&f_shell);
62 string = msg_catalog_mgr().catgets(Set_AddLibraryAgent, 1);
63 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
65 // order of these macros must match the .res file occurences for same
66 ASSN (WXmForm, f_form, f_shell, "form");
67 DECLM (WXmForm, sub_form, f_form, "sub_form");
68 DECLM (WXmLabel, label, sub_form, "theLabel");
69 DECLM (WXmPushButton, pick, sub_form, "pick");
70 ASSNM (WXmTextField, f_text, sub_form, "text");
71 DECLM (WXmSeparator, sep, f_form, "separator");
72 ASSNM (WXmPushButton, f_ok, f_form, "ok");
73 ASSNM (WXmPushButton, f_clr, f_form, "clear");
74 DECLM (WXmPushButton, canc, f_form, "cancel");
75 DECLM (WXmPushButton, help, f_form, "help");
77 mtfstring = msg_catalog_mgr().catgets(Set_AgentLabel, 160);
78 XtVaSetValues(label, XmNlabelString, (XmString)mtfstring, NULL);
79 mtfstring = msg_catalog_mgr().catgets(Set_AgentLabel, 161);
80 XtVaSetValues(f_ok, XmNlabelString, (XmString)mtfstring, NULL);
81 mtfstring = msg_catalog_mgr().catgets(Set_AgentLabel, 162);
82 XtVaSetValues(canc, XmNlabelString, (XmString)mtfstring, NULL);
84 mtfstring = CATGETS(Set_AgentLabel, 223, "Clear");
85 XtVaSetValues(f_clr, XmNlabelString, (XmString)mtfstring, NULL);
86 mtfstring = CATGETS(Set_AgentLabel, 270, "...");
87 XtVaSetValues(pick, XmNlabelString, (XmString)mtfstring, NULL);
88 mtfstring = CATGETS(Set_AgentLabel, 48, "Help");
89 XtVaSetValues(help, XmNlabelString, (XmString)mtfstring, NULL);
92 f_form.DefaultButton (f_ok);
93 SET_CALLBACK (f_text, ValueChanged, textChanged);
94 SET_CALLBACK (f_text, ModifyVerify, verifyNoSpace);
95 ON_ACTIVATE (pick, pick_dir);
96 ON_ACTIVATE (f_ok, ok);
97 ON_ACTIVATE (f_clr, clear);
98 ON_ACTIVATE (canc, cancel);
99 help_agent().add_activate_help (help, "add_infolib_help");
102 // XtVaSetValues(f_form, XmNinitialFocus, (Widget)f_text, NULL);
106 AddLibraryAgent::ok () {
112 AddLibraryAgent::clear () {
113 // autoUnmanage must be set to False for this button to work properly
115 XmTextFieldSetString( f_text, "" );
119 AddLibraryAgent::cancel () {
126 AddLibraryAgent::textChanged (WCallback *wcb) {
127 char *theText = XmTextFieldGetString (wcb->GetWidget());
128 if( theText && *theText ) {
129 f_ok.SetSensitive (True);
130 f_clr.SetSensitive (True);
134 f_ok.SetSensitive (False);
135 f_clr.SetSensitive (False);
141 AddLibraryAgent::verifyNoSpace (WCallback *wcb) {
142 CALL_DATA (XmTextVerifyCallbackStruct, tvp);
144 if (tvp->text != NULL) {
145 int length = tvp->text->length;
146 char *cp = tvp->text->ptr;
147 for ( ; length > 0; cp ++, length --) {
148 //if (*cp == ' ' || *cp == '\t' || *cp == '\n') {
149 if (*cp == '\t' || *cp == '\n') {
158 AddLibraryAgent::getInfolibName () {
160 f_done = f_cancelled = False;
162 XmProcessTraversal( (Widget)f_text, XmTRAVERSE_CURRENT );
163 // XtSetKeyboardFocus( (Widget)f_form, (Widget)f_text );
164 // ((WXmForm *) XtParent(XtParent (f_text)))->InitialFocus (f_text);
166 f_shell.MinWidth (f_shell.Width());
167 f_shell.MinHeight (f_shell.Height());
168 f_shell.MaxHeight (f_shell.Height());
170 XtAppContext app_context = window_system().app_context ();
173 XtAppNextEvent (app_context, &event);
174 XtDispatchEvent (&event);
178 return XmTextFieldGetString (f_text);
182 AddLibraryAgent::pick_dir () {
189 XmString title_str = XmStringCreateLocalized(
190 CATGETS(Set_AddLibraryAgent, 10, "Dtinfo: Infolib Selection"));
191 XmString no_libs_str = XmStringCreateLocalized(
192 CATGETS(Set_AddLibraryAgent, 11, "No Infolibs Present"));
193 XmString patt_str = XmStringCreateLocalized( "*.dti" );
194 XmString infolibs_str = XmStringCreateLocalized( "Infolibs" );
196 // default initial directory on first entry
197 char *buf = new char[256];
199 // Note: infolibs need to be placed in platform-portably-named
200 // LANG-type subdirectories, so the normalized CDE language
201 // string can be used for lookup. For now, must assume the
202 // user environment LANG is OK ...
204 if( tmpstr = getenv("LANG") )
205 sprintf( buf, "/usr/dt/infolib/%s/", tmpstr );
207 sprintf( buf, "/usr/dt/infolib/%s/", env().lang() );
209 XmString basedir_str = XmStringCreateLocalized( buf );
210 strcat( buf, "*.dti" );
211 XmString initdir_str = XmStringCreateLocalized( buf );
215 XtSetArg(args[n], XmNdialogTitle, title_str); n++;
216 XtSetArg(args[n], XmNdirectory, basedir_str); n++;
217 XtSetArg(args[n], XmNdirMask, initdir_str); n++;
218 XtSetArg(args[n], XmNfileListLabelString, infolibs_str); n++;
219 XtSetArg(args[n], XmNfileTypeMask, XmFILE_DIRECTORY); n++;
220 XtSetArg(args[n], XmNnoMatchString, no_libs_str); n++;
221 XtSetArg(args[n], XmNpattern, patt_str); n++;
222 XtSetArg(args[n], XmNpathMode, XmPATH_MODE_RELATIVE); n++;
224 f_file_sel = XmCreateFileSelectionDialog(
225 f_shell, "pick_dir_file", args, n );
227 XmStringFree(basedir_str);
228 XmStringFree(initdir_str);
229 XmStringFree(infolibs_str);
230 XmStringFree(patt_str);
231 XmStringFree(no_libs_str);
232 XmStringFree(title_str);
234 XtAddCallback ( f_file_sel,
236 &AddLibraryAgent::fileSelectedCallback,
238 XtAddCallback ( f_file_sel,
240 &AddLibraryAgent::cancelCallback,
243 XtManageChild( f_file_sel );
247 AddLibraryAgent::cancelCallback ( Widget w,
251 XtUnmanageChild ( w ); // Bring the file selection dialog down.
255 AddLibraryAgent::fileSelectedCallback ( Widget w,
256 XtPointer client_data,
257 XtPointer call_data )
259 AddLibraryAgent * obj = (AddLibraryAgent *) client_data;
261 XmFileSelectionBoxCallbackStruct *cb =
262 (XmFileSelectionBoxCallbackStruct *) call_data;
264 XmString xmstr = cb->value; // The selected file
267 if ( xmstr ) // Make sure a file was selected
269 // Extract the first character string matching the default
270 // character set from the compound string
272 status = XmStringGetLtoR ( xmstr, XmFONTLIST_DEFAULT_TAG, &name );
273 if(status && strlen(name)<1)
280 XmTextFieldSetString( (Widget) obj->f_text, name );
281 // XtSetKeyboardFocus( (Widget) obj->f_form, (Widget) obj->f_ok );
282 XmProcessTraversal( (Widget) obj->f_ok, XmTRAVERSE_CURRENT );
285 XtUnmanageChild ( w ); // Bring the file selection dialog down.