2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $TOG: cmtt.c /main/4 1999/09/20 10:29:41 mgreess $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
51 static char sccsid[] = "@(#)cmtt.c 1.13 95/05/01 Copyr 1993 Sun Microsystems, Inc.";
53 #include <EUSCompat.h>
61 #include <Dt/UserMsg.h>
69 static Tt_message load_cb();
72 static const char *ptype = "Sun_DtCm";
81 XIconifyWindow(XtDisplay(win),
83 XScreenNumberOfScreen(XtScreen(win)));
85 XtPopup(win, XtGrabNone);
86 XMapWindow(XtDisplay(win), XtWindow(win));
94 OKCB (Widget dialog, XtPointer client_data, XtPointer call_data)
96 XtUnmanageChild((Widget) client_data);
100 DieFromToolTalkError(Calendar *c, char *errfmt, Tt_status status)
103 Widget dialog, dialogShell;
104 char *errmsg, *statmsg, *title;
105 XmString xms_errmsg, xms_ok, xms_title;
108 if (! tt_is_err(status)) return;
110 statmsg = tt_status_message(status);
111 errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
112 sprintf(errmsg, errfmt, statmsg);
114 xms_ok = XmStringCreateLocalized(catgets(c->DT_catd, 2, 3, "OK"));
115 xms_errmsg = XmStringCreateLocalized(errmsg);
116 xms_title = XmStringCreateLocalized(catgets(c->DT_catd, 2, 1,
117 "Calendar - Warning"));
120 XtSetArg(args[n], XmNautoUnmanage, False); n++;
121 XtSetArg(args[n], XmNokLabelString, xms_ok); n++;
122 XtSetArg(args[n], XmNdialogTitle, xms_title); n++;
123 XtSetArg(args[n], XmNmessageString, xms_errmsg); n++;
124 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
126 dialog = XmCreateWarningDialog(c->frame, "IconEditorError", args, n);
127 XtAddCallback(dialog, XmNokCallback, OKCB, (XtPointer) dialog);
128 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
129 XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
132 * Disable the frame menu from dialog since we don't want the user
133 * to be able to close dialogs with the frame menu
135 dialogShell = XtParent(dialog);
137 XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU); n++;
138 XtSetValues(dialogShell, args, n);
139 XtManageChild(dialog);
140 XtRealizeWidget(dialogShell);
142 _DtSimpleError("Dtcm", DtWarning, NULL, errmsg);
145 XmStringFree(xms_ok);
146 XmStringFree(xms_errmsg);
147 XmStringFree(xms_title);
152 * Initialize tooltalk. Can be called multiple times: the first call
153 * initializes tooltalk, subsequent calls are no-ops.
156 * -1 Error. Tooltalk not initialized
157 * 0 Tooltalk already initialized
158 * 1 Tooltalk succussfully intialized
164 XtAppContext context,
177 ttenv = (char *)getenv("TT_SESSION");
178 if (!ttenv || strlen(ttenv) == 0) {
179 session = tt_X_session(XDisplayString(c->xcontext->display));
180 tt_default_session_set(session);
184 c->tt_procid = ttdt_open(&ttfd, toolname, "SunSoft", "%I", 1);
185 status = tt_ptr_error(c->tt_procid);
186 if (tt_is_err(status)) {
193 * Declare our ptype, and register the callback to handle
194 * Edit/Display/Compose requests
196 status = ttmedia_ptype_declare(ptype, 0, load_cb, (void *)c, 1);
197 if (tt_is_err(status)) {
198 fprintf(stderr, "cmtt_init could not declare ptype: %s\n",
199 tt_status_message(status));
204 ttdt_session_join(0, NULL, shell, c, 1);
206 XtAppAddInput(context, ttfd, (XtPointer)XtInputReadMask,
207 tttk_Xt_input_handler, c->tt_procid);
209 /* Process the message that started us, if any */
210 tttk_Xt_input_handler( 0, 0, 0 );
225 DP(("contract_cb(msg=%d, op=%d, shell=%d, data=%d, cntrct=%d)\n",
226 msg, op, shell, clientdata, contract));
230 case TTDT_GET_STATUS:
235 /* For now do nothing */
240 * Handle Edit, Display and Compose requests
248 unsigned char *contents,
259 Tt_pattern *contract_pats;
261 DP(("load_cb(msg=%d, op=%d, diag=%d, contents=%d, len=%d, file=%s, \
262 docname=%s, data=%d)\n",
263 msg, op, diagnosis, contents, len, file ? file : "<nil>",
264 docname ? docname : "<nil>", clientdata));
266 c = (Calendar *)clientdata;
268 if (diagnosis != TT_OK) {
269 if (tt_message_status(msg) == TT_WRN_START_MESSAGE) {
271 * Error in start message! we may want to exit
272 * here, but for now let toolkit handle error
277 /* Let toolkit handle the error */
281 contract_pats = ttdt_message_accept(msg, contract_cb, clientdata,
284 if ((status = tt_ptr_error(contract_pats)) != TT_OK) {
285 fprintf(stderr, "dtcm: load_cb could not accept message: %s\n",
286 tt_status_message(status));
289 tttk_patterns_destroy(contract_pats);
295 } else if (len > 0) {
296 p = (char *)contents;
298 tttk_message_fail( msg, TT_DESKTOP_ENODATA, 0, 1 );
303 if (cmfns_lookup_calendar(p, addr_buf, sizeof(addr_buf)) == 1) {
304 cm_iconic(c->frame, 0);
305 switch_it(c, addr_buf, main_win);
309 tt_message_reply(msg);
311 tt_free((caddr_t)contents);