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>
81 #define CLASS MarkIcon
82 #include "create_macros.hh"
86 static void register_actions();
89 // /////////////////////////////////////////////////////////////////
91 // /////////////////////////////////////////////////////////////////
93 MarkIcon::MarkIcon (Widget parent,
94 Widget chooser_parent,
96 int ypos, int scrollbar_offset)
100 f_chooser_parent (chooser_parent)
102 static XtTranslations translations;
104 if (translations == NULL) {
108 translations = XtParseTranslationTable (
109 "<Btn1Down>:single_click()\n"
110 "<Btn1Down>(2):double_click()\n"
111 "<Key>osfHelp:Help()\n"
112 "<Key>Return:double_click()\n"
113 "Ctrl<Key>Return:double_click()\n"
114 "<Key>osfActivate: double_click()");
117 widget = WXmPushButton (parent, "mark_icon", WAutoManage);
119 XtOverrideTranslations(widget, translations);
121 // ON_ACTIVATE (*this, activate);
127 ON_DEBUG(cerr << "MarkIcon::MarkIcon -> ypos: " << ypos << " offset: " <<
128 scrollbar_offset << endl);
131 Y ((Position) ypos - scrollbar_offset);
132 TopOffset(ypos - scrollbar_offset);
137 // /////////////////////////////////////////////////////////////////
139 // /////////////////////////////////////////////////////////////////
142 MarkIcon::register_actions()
144 static bool registered = FALSE;
149 static XtActionsRec actions_list[] =
151 {"double_click", &MarkIcon::static_double_click},
152 {"single_click", &MarkIcon::static_single_click},
155 XtAppAddActions (window_system().app_context(), actions_list, XtNumber (actions_list));
160 // /////////////////////////////////////////////////////////////////
161 // static_double_click
162 // /////////////////////////////////////////////////////////////////
165 MarkIcon::static_double_click(Widget widget, XEvent *event, String *args, Cardinal *num_args)
168 ((MarkIcon *) WXmPushButton(widget).UserData())->double_click (event);
172 // /////////////////////////////////////////////////////////////////
173 // static_single_click
174 // /////////////////////////////////////////////////////////////////
177 MarkIcon::static_single_click(Widget widget, XEvent *event, String *args, Cardinal *num_args)
180 ((MarkIcon *) WXmPushButton(widget).UserData())->single_click (event);
185 // /////////////////////////////////////////////////////////////////
187 // /////////////////////////////////////////////////////////////////
190 MarkIcon::double_click(XEvent *event)
193 if (mark_count() == 1)
195 List_Iterator<MarkCanvas *> m (f_mark_list);
197 m.item()->mark_ptr()->edit();
199 else // mark_mark_count() > 1
201 assert (mark_count() > 1);
208 UAS_String title = CATGETS(Set_MarkChooser, 2, "Dtinfo: Edit Mark");
209 UAS_String btitle = CATGETS(Set_AgentLabel, 16, "Edit");
210 MarkChooser chooser (f_chooser_parent, f_mark_list,
211 (char*)title, (char*)btitle);
213 MarkCanvas *choice = chooser.get_choice();
217 choice->mark_ptr()->edit();
222 // /////////////////////////////////////////////////////////////////
224 // /////////////////////////////////////////////////////////////////
227 MarkIcon::single_click(XEvent *event)
230 if (mark_count() == 1)
232 List_Iterator<MarkCanvas *> m (f_mark_list);
236 m.item()->deselect();
238 else // mark_mark_count() > 1
240 assert (mark_count() > 1);
242 // Use the double click delay plus 30 milliseconds.
243 int delay = XtGetMultiClickTime (XtDisplay (widget)) + 30;
245 new WTimeOut (window_system().app_context(), delay, this,
246 (WTimeOutFunc) &MarkIcon::select_mark_timeout);
251 // /////////////////////////////////////////////////////////////////
253 // /////////////////////////////////////////////////////////////////
255 MarkIcon::~MarkIcon()
257 List_Iterator<MarkCanvas *> m (f_mark_list);
260 m.item()->set_mark_icon (NULL);
269 XtDestroyWidget (widget);
273 // /////////////////////////////////////////////////////////////////
275 // /////////////////////////////////////////////////////////////////
278 MarkIcon::highlight()
280 if (f_selected == FALSE)
282 ON_DEBUG(printf ("highlighting mark %p\n", this));
288 MarkIcon::select (MarkCanvas *)
296 // /////////////////////////////////////////////////////////////////
298 // /////////////////////////////////////////////////////////////////
301 MarkIcon::unhighlight()
303 if (f_selected == TRUE)
305 ON_DEBUG(printf ("unhighlighting mark %p\n", this));
311 MarkIcon::deselect (MarkCanvas *)
319 // /////////////////////////////////////////////////////////////////
321 // /////////////////////////////////////////////////////////////////
324 MarkIcon::update_icon (MarkCanvas *)
326 Pixmap button_pixmap = NULL;
328 int multi = mark_count() > 1;
332 List_Iterator<MarkCanvas *> m (f_mark_list);
335 if (*(m.item()->mark_ptr()->notes()) != '\0')
345 button_pixmap = XmGetPixmap(window_system().screen(), "anno_double",
346 Foreground(), Background());
348 button_pixmap = XmGetPixmap(window_system().screen(), "anno_single",
349 Foreground(), Background());
353 button_pixmap = XmGetPixmap(window_system().screen(), "mark_double",
354 Foreground(), Background());
356 button_pixmap = XmGetPixmap(window_system().screen(), "mark_single",
357 Foreground(), Background());
360 if (button_pixmap && button_pixmap != XmUNSPECIFIED_PIXMAP) {
361 LabelPixmap(button_pixmap);
364 #ifdef BOOKMARK_DEBUG
365 cerr << "XmGetPixmap failed." << endl;
371 *buf = OLIAS_BOOKMARK_ICON;
373 List_Iterator<MarkCanvas *> m (f_mark_list);
376 if (*(m.item()->mark_ptr()->notes()) != '\0')
378 *buf = OLIAS_ANNOTATION_ICON;
384 // NOTE: Slight hack here. Depends on multi-icons being uppercase version
385 // of single icons. DJB 10/27/92
386 if (mark_count() > 1)
387 *buf = toupper (*buf);
389 if (f_icon_char != *buf)
398 // /////////////////////////////////////////////////////////////////
399 // insert - add a mark to this icon
400 // /////////////////////////////////////////////////////////////////
403 MarkIcon::insert (MarkCanvas *mark_canvas)
405 mark_canvas->set_mark_icon (this);
407 // Insert the new mark in the mark list in sorted order.
408 List_Iterator<MarkCanvas *> m (f_mark_list);
409 while (m && mark_canvas->offset() > m.item()->offset())
412 // Check for last mark in the icon (ie: start of list)
415 f_offset = mark_canvas->offset();
416 f_mark_list.append (mark_canvas);
420 f_mark_list.insert_before (m, mark_canvas);
424 // If mark_canvas is first item in list, we might have a problem
425 // since the later items in the list may no longer overlap it :-(
427 if (mark_canvas->selected())
430 update_icon (mark_canvas);
434 // /////////////////////////////////////////////////////////////////
435 // append - add to the end of the list 'o marks
436 // /////////////////////////////////////////////////////////////////
439 MarkIcon::append (MarkCanvas *mark_canvas)
441 mark_canvas->set_mark_icon (this);
442 f_mark_list.append (mark_canvas);
443 f_offset = mark_canvas->offset();
445 if (mark_canvas->selected())
448 update_icon (mark_canvas);
452 // /////////////////////////////////////////////////////////////////
453 // remove - remove a mark tml from this icon
454 // /////////////////////////////////////////////////////////////////
457 MarkIcon::remove (MarkCanvas *mark_canvas)
459 mark_canvas->set_mark_icon (NULL);
460 f_mark_list.remove (mark_canvas);
462 // See if we need to recompute the offset.
463 if (mark_count() > 0 && mark_canvas->offset() == f_offset)
465 List_Iterator<MarkCanvas *> m (f_mark_list);
467 f_offset = m.item()->offset();
473 // /////////////////////////////////////////////////////////////////
474 // activate - activate callback
475 // /////////////////////////////////////////////////////////////////
478 MarkIcon::activate (WCallback *wcb)
480 CALL_DATA (XmPushButtonCallbackStruct, pbcs);
482 if (mark_count() == 1)
484 List_Iterator<MarkCanvas *> m (f_mark_list);
485 if (pbcs->click_count == 1)
490 m.item()->deselect();
492 else if (pbcs->click_count == 2)
495 m.item()->mark_ptr()->edit();
498 else // mark_mark_count() > 1
500 assert (mark_count() > 1);
502 if (pbcs->click_count == 1)
504 // Use the double click delay plus 20 milliseconds.
505 int delay = XtGetMultiClickTime (XtDisplay (widget)) + 2000;
507 new WTimeOut (window_system().app_context(), delay, this,
508 (WTimeOutFunc) &MarkIcon::select_mark_timeout);
511 else if (pbcs->click_count == 2)
516 UAS_String title = CATGETS(Set_MarkChooser, 2, "Dtinfo: Edit Mark");
517 UAS_String btitle = CATGETS(Set_AgentLabel, 16, "Edit");
518 MarkChooser chooser (f_chooser_parent, f_mark_list,
519 (char*)title, (char*)btitle);
521 MarkCanvas *choice = chooser.get_choice();
525 choice->mark_ptr()->edit();
532 // /////////////////////////////////////////////////////////////////
533 // select_mark_timeout
534 // /////////////////////////////////////////////////////////////////
537 MarkIcon::select_mark_timeout()
539 // WTimeOut will destruct itself, do not delete g_timeout here
542 UAS_String title = CATGETS(Set_MarkChooser, 1, "Dtinfo: Select Mark");
543 UAS_String btitle = CATGETS(Set_AgentLabel, 161, "Ok");
544 MarkChooser chooser (f_chooser_parent, f_mark_list,
545 (char*)title, (char*)btitle);
547 MarkCanvas *choice = chooser.get_choice();
558 // /////////////////////////////////////////////////////////////////
559 // swap_colors - swap the foreground and background colors
560 // /////////////////////////////////////////////////////////////////
563 MarkIcon::swap_colors()
565 // Swap the fg and bg colors.
567 int multi = mark_count() > 1;
570 List_Iterator<MarkCanvas *> m (f_mark_list);
573 if (*(m.item()->mark_ptr()->notes()) != '\0')
581 Pixel background, foreground;
583 if (f_selected == FALSE) { // about to select
584 foreground = Background();
585 background = Foreground();
587 else { // about to de-select
588 foreground = Foreground();
589 background = Background();
592 Pixmap button_pixmap;
596 button_pixmap = XmGetPixmap(window_system().screen(), "anno_double",
597 foreground, background);
599 button_pixmap = XmGetPixmap(window_system().screen(), "anno_single",
600 foreground, background);
604 button_pixmap = XmGetPixmap(window_system().screen(), "mark_double",
605 foreground, background);
607 button_pixmap = XmGetPixmap(window_system().screen(), "mark_single",
608 foreground, background);
611 if (button_pixmap && button_pixmap != XmUNSPECIFIED_PIXMAP) {
612 LabelPixmap(button_pixmap);