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
26 * $TOG: Icon.C /main/8 1998/10/27 19:42:30 mgreess $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
43 #ifdef DEBUG_CB_REASON
44 #define PRINTCB(str) printf("%s\n",str)
52 #include "DtMailEditor.hh"
54 #include <Dt/Editor.h>
56 #include <X11/keysym.h>
57 #include <X11/StringDefs.h>
58 #include <X11/Intrinsic.h>
61 #include <X11/Xutil.h>
62 #include <Xm/ColorObjP.h>
65 Attachment *classparent,
67 XmString label, /* label string */
68 unsigned short /* type */,
71 ) : UIComponent (name)
73 #define MAX_NUM_COLORS 8
76 char *type = NULL, *icon_name = NULL;
77 char *icon_filename = NULL, *host_prefix = NULL;
80 int btn1_transfer = 0;
82 short act, inact, prim, second, text;
83 XmPixelSet pixels[XmCO_NUM_COLORS];
85 _parent = classparent;
90 // Get the pixmap image file name for this attachment.
91 bp = _parent->getBodyPart();
92 bp->getContents(mail_error, NULL, NULL, &type, NULL, NULL, NULL);
94 // Retrieve the host name.
95 host_prefix = DtDtsDataTypeToAttributeValue(type,
99 // Get the name of the icon.
100 icon_name = (char *) DtDtsDataTypeToAttributeValue(type,
103 // Retrieve icon file name
104 icon_filename = XmGetIconFileName(XtScreen(parent),
111 XmeGetColorObjData(XtScreen(parent), &colorUse, pixels, XmCO_NUM_COLORS,
112 &act, &inact, &prim, &second, &text);
113 _cur_fg = pixels[text].fg;
114 _cur_bg = pixels[text].sc;
117 XtSetArg (args[n], XmNshadowThickness, 0); n++;
118 XtSetArg (args[n], XmNfillOnArm, FALSE); n++;
119 XtSetArg (args[n], XmNhighlightThickness, 2); n++;
120 XtSetArg (args[n], XmNimageName, icon_filename); n++;
121 XtSetArg (args[n], XmNstring, label); n++;
122 XtSetArg( args[n], XmNalignment, XmALIGNMENT_CENTER); n++;
123 XtSetArg( args[n], XmNpixmapPosition, XmPIXMAP_TOP); n++;
124 XtSetArg( args[n], XmNbehavior, XmICON_DRAG); n++;
125 XtSetArg( args[n], XmNfillMode, XmFILL_PARENT); n++;
126 XtSetArg( args[n], XmNbackground, _cur_bg); n++;
127 XtSetArg( args[n], XmNforeground, _cur_fg); n++;
129 _w = _DtCreateIcon(parent,"iconGadget", args,n);
131 XtAddEventHandler(XtParent(_w), Button1MotionMask, FALSE,
132 (XtEventHandler)&Icon::dragMotionHandler,
135 XtVaGetValues((Widget)XmGetXmDisplay(XtDisplay(XtParent(_w))),
136 "enableBtn1Transfer", &btn1_transfer,
139 if (btn1_transfer != True) {
140 XtAddEventHandler(XtParent(_w), Button2MotionMask, FALSE,
141 (XtEventHandler)&Icon::dragMotionHandler,
148 (XtCallbackProc)&Icon::iconCallback,
158 DtDtsFreeAttributeValue(host_prefix);
162 DtDtsFreeAttributeValue(icon_name);
166 XtFree(icon_filename);
167 icon_filename = NULL;
173 int btn1_transfer = 0;
178 (XtCallbackProc)&Icon::iconCallback,
181 XtRemoveEventHandler(XtParent(_w), Button1MotionMask, FALSE,
182 (XtEventHandler)&Icon::dragMotionHandler,
185 XtVaGetValues((Widget)XmGetXmDisplay(XtDisplay(XtParent(_w))),
186 "enableBtn1Transfer", &btn1_transfer,
189 if (btn1_transfer != True) {
190 XtRemoveEventHandler(XtParent(_w), Button2MotionMask, FALSE,
191 (XtEventHandler)&Icon::dragMotionHandler,
198 Icon::iconCallback(Widget , XtPointer client_data, XtPointer call_data)
200 DtIconCallbackStruct *cb = (DtIconCallbackStruct *)call_data;
201 Icon *obj = (Icon *)client_data;
204 if ((event = cb->event) != (XEvent *) NULL) {
206 * The following seems rather bogus.... to make assumptions
207 * about the context of a ButtonPress before decoding
208 * the reason for the callback.
210 if ((event->type == ButtonPress) &&
211 (! IsModifierKey(XLookupKeysym((XKeyEvent *) event, 0)))) {
212 if (event->xbutton.state & ControlMask)
214 /* Cntrl Button press processing*/
215 // Need to handle it. Postponed...
222 case XmCR_UNHIGHLIGHT:
223 PRINTCB("unhighlight");
226 PRINTCB("highlight");
243 case XmCR_DEFAULT_ACTION:
244 PRINTCB("default_action");
245 obj->defaultAction();
256 Icon::dragMotionHandler(
258 XtPointer clientData,
261 Icon *icon = (Icon *) clientData;
263 icon->parent()->parent()->owner()->attachDragMotionHandler(widget, event);
274 XtSetArg( args[n], XmNbackground, _cur_fg); n++;
275 XtSetArg( args[n], XmNforeground, _cur_bg); n++;
276 XtSetValues(_w, args, n);
287 // deselect others in all cases
288 _parent->set_selected();
290 if(_is_armed == TRUE)
303 if(_is_armed == FALSE || _is_selected == TRUE )
314 if(_is_selected == FALSE)
317 _is_selected = FALSE;
324 Icon::primitiveSelect()
326 if(_is_selected == TRUE || _is_armed == TRUE)
339 if(_is_selected == TRUE)
346 Icon::defaultAction()
349 _parent->handleDoubleClick();