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 /* Copyright (c) 1994,1995,1996 FUJITSU LIMITED */
24 /* All Rights Reserved */
27 * $XConsortium: MarkIconMotif.C /main/13 1996/11/19 15:03:42 cde-hal $
29 * Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
30 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
31 * States. Use of a copyright notice is precautionary only and does not
32 * imply publication or disclosure.
34 * This software contains confidential information and trade secrets of HaL
35 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
36 * without the prior express written permission of HaL Computer Systems, Inc.
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject to
40 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
41 * Technical Data and Computer Software clause at DFARS 252.227-7013.
42 * HaL Computer Systems, Inc.
43 * 1315 Dell Avenue, Campbell, CA 95008
50 #define C_WindowSystem
61 #define USES_OLIAS_FONT
63 #include <X11/IntrinsicP.h>
64 #include <X11/Intrinsic.h>
65 #include <X11/CoreP.h>
69 #include "Managers/CatMgr.hh"
70 #include "Other/XmStringLocalized.hh"
72 #include "Registration.hh"
75 #include <WWL/WXmSeparatorGadget.h>
76 #include <WWL/WXmLabelGadget.h>
77 #include <WWL/WXmPushButton.h>
82 #define CLASS MarkIcon
83 #include "create_macros.hh"
87 static void register_actions();
90 // /////////////////////////////////////////////////////////////////
92 // /////////////////////////////////////////////////////////////////
94 MarkIcon::MarkIcon (Widget parent,
95 Widget chooser_parent,
97 int ypos, int scrollbar_offset)
101 f_chooser_parent (chooser_parent)
103 static XtTranslations translations;
105 if (translations == NULL) {
109 translations = XtParseTranslationTable (
110 "<Btn1Down>:single_click()\n"
111 "<Btn1Down>(2):double_click()\n"
112 "<Key>osfHelp:Help()\n"
113 "<Key>Return:double_click()\n"
114 "Ctrl<Key>Return:double_click()\n"
115 "<Key>osfActivate: double_click()");
118 widget = WXmPushButton (parent, "mark_icon", WAutoManage);
120 XtOverrideTranslations(widget, translations);
122 // ON_ACTIVATE (*this, activate);
128 ON_DEBUG(cerr << "MarkIcon::MarkIcon -> ypos: " << ypos << " offset: " <<
129 scrollbar_offset << endl);
132 Y ((Position) ypos - scrollbar_offset);
133 TopOffset(ypos - scrollbar_offset);
138 // /////////////////////////////////////////////////////////////////
140 // /////////////////////////////////////////////////////////////////
143 MarkIcon::register_actions()
145 static bool registered = FALSE;
150 static XtActionsRec actions_list[] =
152 {(char*)"double_click", &MarkIcon::static_double_click},
153 {(char*)"single_click", &MarkIcon::static_single_click},
156 XtAppAddActions (window_system().app_context(), actions_list, XtNumber (actions_list));
161 // /////////////////////////////////////////////////////////////////
162 // static_double_click
163 // /////////////////////////////////////////////////////////////////
166 MarkIcon::static_double_click(Widget widget, XEvent *event, String *args, Cardinal *num_args)
169 ((MarkIcon *) WXmPushButton(widget).UserData())->double_click (event);
173 // /////////////////////////////////////////////////////////////////
174 // static_single_click
175 // /////////////////////////////////////////////////////////////////
178 MarkIcon::static_single_click(Widget widget, XEvent *event, String *args, Cardinal *num_args)
181 ((MarkIcon *) WXmPushButton(widget).UserData())->single_click (event);
186 // /////////////////////////////////////////////////////////////////
188 // /////////////////////////////////////////////////////////////////
191 MarkIcon::double_click(XEvent *event)
194 if (mark_count() == 1)
196 List_Iterator<MarkCanvas *> m (f_mark_list);
198 m.item()->mark_ptr()->edit();
200 else // mark_mark_count() > 1
202 assert (mark_count() > 1);
209 UAS_String title = CATGETS(Set_MarkChooser, 2, "Dtinfo: Edit Mark");
210 UAS_String btitle = CATGETS(Set_AgentLabel, 16, "Edit");
211 MarkChooser chooser (f_chooser_parent, f_mark_list,
212 (char*)title, (char*)btitle);
214 MarkCanvas *choice = chooser.get_choice();
218 choice->mark_ptr()->edit();
223 // /////////////////////////////////////////////////////////////////
225 // /////////////////////////////////////////////////////////////////
228 MarkIcon::single_click(XEvent *event)
231 if (mark_count() == 1)
233 List_Iterator<MarkCanvas *> m (f_mark_list);
237 m.item()->deselect();
239 else // mark_mark_count() > 1
241 assert (mark_count() > 1);
243 // Use the double click delay plus 30 milliseconds.
244 int delay = XtGetMultiClickTime (XtDisplay (widget)) + 30;
246 new WTimeOut (window_system().app_context(), delay, this,
247 (WTimeOutFunc) &MarkIcon::select_mark_timeout);
252 // /////////////////////////////////////////////////////////////////
254 // /////////////////////////////////////////////////////////////////
256 MarkIcon::~MarkIcon()
258 List_Iterator<MarkCanvas *> m (f_mark_list);
261 m.item()->set_mark_icon (NULL);
270 XtDestroyWidget (widget);
274 // /////////////////////////////////////////////////////////////////
276 // /////////////////////////////////////////////////////////////////
279 MarkIcon::highlight()
281 if (f_selected == FALSE)
283 ON_DEBUG(printf ("highlighting mark %p\n", this));
289 MarkIcon::select (MarkCanvas *)
297 // /////////////////////////////////////////////////////////////////
299 // /////////////////////////////////////////////////////////////////
302 MarkIcon::unhighlight()
304 if (f_selected == TRUE)
306 ON_DEBUG(printf ("unhighlighting mark %p\n", this));
312 MarkIcon::deselect (MarkCanvas *)
320 // /////////////////////////////////////////////////////////////////
322 // /////////////////////////////////////////////////////////////////
325 MarkIcon::update_icon (MarkCanvas *)
327 Pixmap button_pixmap = 0;
329 int multi = mark_count() > 1;
333 List_Iterator<MarkCanvas *> m (f_mark_list);
336 if (*(m.item()->mark_ptr()->notes()) != '\0')
346 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"anno_double",
347 Foreground(), Background());
349 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"anno_single",
350 Foreground(), Background());
354 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"mark_double",
355 Foreground(), Background());
357 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"mark_single",
358 Foreground(), Background());
361 if (button_pixmap && button_pixmap != XmUNSPECIFIED_PIXMAP) {
362 LabelPixmap(button_pixmap);
365 #ifdef BOOKMARK_DEBUG
366 cerr << "XmGetPixmap failed." << endl;
372 *buf = OLIAS_BOOKMARK_ICON;
374 List_Iterator<MarkCanvas *> m (f_mark_list);
377 if (*(m.item()->mark_ptr()->notes()) != '\0')
379 *buf = OLIAS_ANNOTATION_ICON;
385 // NOTE: Slight hack here. Depends on multi-icons being uppercase version
386 // of single icons. DJB 10/27/92
387 if (mark_count() > 1)
388 *buf = toupper (*buf);
390 if (f_icon_char != *buf)
399 // /////////////////////////////////////////////////////////////////
400 // insert - add a mark to this icon
401 // /////////////////////////////////////////////////////////////////
404 MarkIcon::insert (MarkCanvas *mark_canvas)
406 mark_canvas->set_mark_icon (this);
408 // Insert the new mark in the mark list in sorted order.
409 List_Iterator<MarkCanvas *> m (f_mark_list);
410 while (m && mark_canvas->offset() > m.item()->offset())
413 // Check for last mark in the icon (ie: start of list)
416 f_offset = mark_canvas->offset();
417 f_mark_list.append (mark_canvas);
421 f_mark_list.insert_before (m, mark_canvas);
425 // If mark_canvas is first item in list, we might have a problem
426 // since the later items in the list may no longer overlap it :-(
428 if (mark_canvas->selected())
431 update_icon (mark_canvas);
435 // /////////////////////////////////////////////////////////////////
436 // append - add to the end of the list 'o marks
437 // /////////////////////////////////////////////////////////////////
440 MarkIcon::append (MarkCanvas *mark_canvas)
442 mark_canvas->set_mark_icon (this);
443 f_mark_list.append (mark_canvas);
444 f_offset = mark_canvas->offset();
446 if (mark_canvas->selected())
449 update_icon (mark_canvas);
453 // /////////////////////////////////////////////////////////////////
454 // remove - remove a mark tml from this icon
455 // /////////////////////////////////////////////////////////////////
458 MarkIcon::remove (MarkCanvas *mark_canvas)
460 mark_canvas->set_mark_icon (NULL);
461 f_mark_list.remove (mark_canvas);
463 // See if we need to recompute the offset.
464 if (mark_count() > 0 && mark_canvas->offset() == f_offset)
466 List_Iterator<MarkCanvas *> m (f_mark_list);
468 f_offset = m.item()->offset();
474 // /////////////////////////////////////////////////////////////////
475 // activate - activate callback
476 // /////////////////////////////////////////////////////////////////
479 MarkIcon::activate (WCallback *wcb)
481 CALL_DATA (XmPushButtonCallbackStruct, pbcs);
483 if (mark_count() == 1)
485 List_Iterator<MarkCanvas *> m (f_mark_list);
486 if (pbcs->click_count == 1)
491 m.item()->deselect();
493 else if (pbcs->click_count == 2)
496 m.item()->mark_ptr()->edit();
499 else // mark_mark_count() > 1
501 assert (mark_count() > 1);
503 if (pbcs->click_count == 1)
505 // Use the double click delay plus 20 milliseconds.
506 int delay = XtGetMultiClickTime (XtDisplay (widget)) + 2000;
508 new WTimeOut (window_system().app_context(), delay, this,
509 (WTimeOutFunc) &MarkIcon::select_mark_timeout);
512 else if (pbcs->click_count == 2)
517 UAS_String title = CATGETS(Set_MarkChooser, 2, "Dtinfo: Edit Mark");
518 UAS_String btitle = CATGETS(Set_AgentLabel, 16, "Edit");
519 MarkChooser chooser (f_chooser_parent, f_mark_list,
520 (char*)title, (char*)btitle);
522 MarkCanvas *choice = chooser.get_choice();
526 choice->mark_ptr()->edit();
533 // /////////////////////////////////////////////////////////////////
534 // select_mark_timeout
535 // /////////////////////////////////////////////////////////////////
538 MarkIcon::select_mark_timeout()
540 // WTimeOut will destruct itself, do not delete g_timeout here
543 UAS_String title = CATGETS(Set_MarkChooser, 1, "Dtinfo: Select Mark");
544 UAS_String btitle = CATGETS(Set_AgentLabel, 161, "Ok");
545 MarkChooser chooser (f_chooser_parent, f_mark_list,
546 (char*)title, (char*)btitle);
548 MarkCanvas *choice = chooser.get_choice();
559 // /////////////////////////////////////////////////////////////////
560 // swap_colors - swap the foreground and background colors
561 // /////////////////////////////////////////////////////////////////
564 MarkIcon::swap_colors()
566 // Swap the fg and bg colors.
568 int multi = mark_count() > 1;
571 List_Iterator<MarkCanvas *> m (f_mark_list);
574 if (*(m.item()->mark_ptr()->notes()) != '\0')
582 Pixel background, foreground;
584 if (f_selected == FALSE) { // about to select
585 foreground = Background();
586 background = Foreground();
588 else { // about to de-select
589 foreground = Foreground();
590 background = Background();
593 Pixmap button_pixmap;
597 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"anno_double",
598 foreground, background);
600 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"anno_single",
601 foreground, background);
605 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"mark_double",
606 foreground, background);
608 button_pixmap = XmGetPixmap(window_system().screen(),(char*)"mark_single",
609 foreground, background);
612 if (button_pixmap && button_pixmap != XmUNSPECIFIED_PIXMAP) {
613 LabelPixmap(button_pixmap);