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
24 * $TOG: GraphicAgentMotif.C /main/30 1998/04/17 11:32:58 mgreess $
26 * Copyright (c) 1992 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include <tml/tml_objects.hxx>
57 #define C_PixmapGraphic
64 #define C_GhostScriptEventMgr
68 #define C_GraphicAgent
71 #include <WWL/WTopLevelShell.h>
72 #include <WWL/WXmMenu.h>
73 #include <WWL/WXmForm.h>
74 #include <WWL/WXmPushButton.h>
75 #include <WWL/WXmToggleButton.h>
76 #include <WWL/WXmFrame.h>
77 #include <WWL/WXmSeparator.h>
79 #include "Managers/CatMgr.hh"
80 #include "Other/XmStringLocalized.hh"
87 #include "Registration.hh"
89 #include "Widgets/WXawPorthole.h"
90 #include "Widgets/WXawPanner.h"
91 #include "Widgets/WPixmap.h"
93 #include "utility/funcs.h"
95 #define CLASS GraphicAgent
96 #include "create_macros.hh"
98 enum { PANNER_UPPER_LEFT,
108 return i1 < i2 ? i1 : i2 ;
111 // /////////////////////////////////////////////////////////////////////////
113 // /////////////////////////////////////////////////////////////////////////
115 GraphicAgent::GraphicAgent (UAS_Pointer<UAS_Common> &node_ptr,
116 UAS_Pointer<Graphic> &gr)
118 f_node_ptr(node_ptr),
120 f_panner_state (PANNER_NONE),
121 f_current_scale (100),
122 f_scale_button(NULL),
126 f_graphic->pixmap_graphic()->agent(this);
128 UAS_Common::request ((UAS_Receiver<UAS_LibraryDestroyedMsg> *) this);
131 // /////////////////////////////////////////////////////////////////////////
133 // /////////////////////////////////////////////////////////////////////////
135 GraphicAgent::~GraphicAgent()
137 f_graphic->pixmap_graphic()->agent(NULL);
138 Pixmap pixmap = f_pixmap_widget->Picture();
139 if (pixmap && pixmap != f_graphic->pixmap_graphic()->pixmap())
141 XFreePixmap(XtDisplay(*f_pixmap_widget),
142 pixmap); // a scaled pixmap...give it back
149 // /////////////////////////////////////////////////////////////////////////
151 // /////////////////////////////////////////////////////////////////////////
154 GraphicAgent::popup()
163 // /////////////////////////////////////////////////////////////////////////
165 // /////////////////////////////////////////////////////////////////////////
168 GraphicAgent::display()
173 // assume all graphics are scalable for now.
178 Widget *kids = f_view_menu->Children() ;
179 int num_children = f_view_menu->NumChildren();
180 for (int i = 0 ; i < num_children; i++)
182 WXmPrimitive prim(kids[i]);
183 prim.SetSensitive(True);
191 GraphicAgent::receive(DisplayGraphic &message, void* /*client_data*/)
193 ON_DEBUG(cerr << "GraphicAgent::receive(DisplayGraphic( " <<
194 message.graphic()->locator() << "))" << endl);
196 ON_DEBUG(cerr << "local locator is " <<
197 f_graphic->locator() << endl);
199 if (message.graphic() == f_graphic)
201 ON_DEBUG(cerr << "GraphicAgent::receive(DISPLAY)" << endl);
207 GraphicAgent::receive(ReAttachGraphic &message, void* /*client_data*/)
213 GraphicAgent::receive (UAS_LibraryDestroyedMsg &msg, void* /*client_data*/)
215 if(f_node_ptr->lid() == (msg.fLib)->lid())
217 graphics_mgr().remove_detached((GraphicAgent*)this);
221 // /////////////////////////////////////////////////////////////////////////
223 // /////////////////////////////////////////////////////////////////////////
225 #define AM WAutoManage
227 GraphicAgent::create_ui()
229 XmStringLocalized mtfstring;
232 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "graphic");
233 window_system().register_shell (&f_shell);
235 string = CATGETS(Set_GraphicAgent, 1, "Dtinfo: Detached Graphic");
236 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
238 // just use "delete_response" instead
239 // add a destroy callback to nuke the agent when widget is destroyed.
240 f_shell.SetDestroyCallback (this, (WWL_FUN) &GraphicAgent::ui_destroyed);
242 DECL (WXmForm, form, f_shell, "form" );
243 DECLM (WXmMenuBar, menu_bar, form, "menu_bar" );
246 // rtp: hard-wire the menu bar's background, since
247 // it comes up a bogus color. Copied from swm's
248 // change in NodeWindowAgentMotif.C
250 Pixel bg = form.Background();
251 menu_bar.Background(bg);
254 DECLM (WXmCascadeButton, file, menu_bar, "file" );
255 DECLM (WXmPulldownMenu, file_menu, menu_bar, "file_menu" );
256 DECLM (WXmPushButton, attach, file_menu, "attach" );
257 DECLM (WXmPushButton, visit, file_menu, "visit" );
258 DECLM (WXmPushButton, close, file_menu, "close" );
260 XtVaSetValues(file, XmNlabelString,
261 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 1, "File")),
263 *CATGETS(Set_AgentLabel, 2, ""),
266 XtVaSetValues(attach, XmNlabelString,
267 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 167, "Attach")),
269 *CATGETS(Set_AgentLabel, 21, ""),
272 XtVaSetValues(visit, XmNlabelString,
273 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel,168,"Display Section")),
275 *CATGETS(Set_AgentLabel, 119, ""),
278 XtVaSetValues(close, XmNlabelString,
279 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 12, "Close")),
281 *CATGETS(Set_AgentLabel, 13, ""),
284 DECLM (WXmCascadeButton, pan, menu_bar, "panner" );
285 DECLM (WXmPulldownMenu, panner_menu, menu_bar, "panner_menu" );
286 DECLM (WXmToggleButton, none, panner_menu, "none" );
287 DECLM (WXmToggleButton, up_left, panner_menu, "up_left" );
288 DECLM (WXmToggleButton, up_right, panner_menu, "up_right" );
289 DECLM (WXmToggleButton, low_left, panner_menu, "low_left" );
290 DECLM (WXmToggleButton, low_right, panner_menu, "low_right" );
292 XtVaSetValues(pan, XmNlabelString,
293 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 166, "Panner")),
295 *CATGETS(Set_AgentLabel, 9, ""),
298 XtVaSetValues(none, XmNlabelString,
299 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 178, "None")),
301 *CATGETS(Set_AgentLabel, 7, ""),
304 XtVaSetValues(up_left, XmNlabelString,
305 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 179, "Upper Left")),
307 *CATGETS(Set_AgentLabel, 254, ""),
310 XtVaSetValues(up_right, XmNlabelString,
311 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 180, "Upper Right")),
313 *CATGETS(Set_AgentLabel, 252, ""),
316 XtVaSetValues(low_left, XmNlabelString,
317 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 181, "Lower Left")),
319 *CATGETS(Set_AgentLabel, 113, ""),
322 XtVaSetValues(low_right, XmNlabelString,
323 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 182, "Lower Right")),
325 *CATGETS(Set_AgentLabel, 259, ""),
328 // NOTE: some code in this module depends upon the exact ordering of items
329 // view menu will only be sensitive for scalable graphics
330 DECL (WXmCascadeButton, view, menu_bar, "view" );
331 DECLM (WXmPulldownMenu, view_menu, menu_bar, "view_menu" );
332 DECLM (WXmPushButton, fit_gr_to_win, view_menu, "fit_window" );
333 DECLM (WXmPushButton, fit_win_to_gr, view_menu, "fit_graphic" );
335 XtVaSetValues(view, XmNlabelString,
336 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 4, "View")),
338 *CATGETS(Set_AgentLabel, 5, ""),
341 XtVaSetValues(fit_gr_to_win, XmNlabelString,
342 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 169, "Fit to Window")),
344 *CATGETS(Set_AgentLabel, 35, ""),
348 XtVaSetValues(fit_win_to_gr, XmNlabelString,
349 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 170, "Fit to Graphic")),
351 *CATGETS(Set_AgentLabel, 37, ""),
354 DECLM (WXmSeparator, separator, view_menu, "separator" );
355 DECLM (WXmToggleButton, z_25, view_menu, "z_25" );
356 DECLM (WXmToggleButton, z_50, view_menu, "z_50" );
357 DECLM (WXmToggleButton, z_100, view_menu, "z_100" );
358 DECLM (WXmToggleButton, z_125, view_menu, "z_125" );
359 DECLM (WXmToggleButton, z_150, view_menu, "z_150" );
360 DECLM (WXmToggleButton, z_200, view_menu, "z_200" );
361 DECLM (WXmToggleButton, z_custom, view_menu, "z_custom" );
363 mtfstring = CATGETS(Set_AgentLabel, 171, "25 %");
364 XtVaSetValues(z_25, XmNlabelString, (XmString)mtfstring, NULL);
365 mtfstring = CATGETS(Set_AgentLabel, 172, "50 %");
366 XtVaSetValues(z_50, XmNlabelString, (XmString)mtfstring, NULL);
367 mtfstring = CATGETS(Set_AgentLabel, 173, "100 %");
368 XtVaSetValues(z_100, XmNlabelString, (XmString)mtfstring, NULL);
369 mtfstring = CATGETS(Set_AgentLabel, 174, "125 %");
370 XtVaSetValues(z_125, XmNlabelString, (XmString)mtfstring, NULL);
371 mtfstring = CATGETS(Set_AgentLabel, 175, "150 %");
372 XtVaSetValues(z_150, XmNlabelString, (XmString)mtfstring, NULL);
373 mtfstring = CATGETS(Set_AgentLabel, 176, "200 %");
374 XtVaSetValues(z_200, XmNlabelString, (XmString)mtfstring, NULL);
376 XtVaSetValues(z_custom, XmNlabelString,
377 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 177, "Custom...")),
379 *CATGETS(Set_AgentLabel, 13, ""),
383 f_scale_button = (WXmToggleButton*)(Widget)z_100 ;
384 f_custom_scale = (WXmToggleButton*)(Widget)z_custom ;
386 f_view_menu = (WXmPulldownMenu*)(Widget)view_menu ;
388 DECLM (WXmCascadeButton, help, menu_bar, "help" );
389 DECLM (WXmPulldownMenu, help_menu, menu_bar, "help_menu" );
390 DECLM (WXmPushButton, on_window, help_menu, "on_window" );
391 DECLM (WXmPushButton, on_help, help_menu, "on_help" );
393 XtVaSetValues(help, XmNlabelString,
394 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 48, "Help")),
396 *CATGETS(Set_AgentLabel, 39, ""),
399 XtVaSetValues(on_window, XmNlabelString,
400 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 147, "On Window")),
402 *CATGETS(Set_AgentLabel, 35, ""),
405 XtVaSetValues(on_help, XmNlabelString,
406 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 153, "On Help")),
408 *CATGETS(Set_AgentLabel, 39, ""),
411 DECLM (WXmLabel, message_area, form, "message");
412 f_message_area = (WXmLabel*)(Widget)message_area ;
414 DECLM (WXmSeparator, sep, form, "sep2");
416 DECL (WXmFrame, frame, form, "frame" );
417 DECL (WXmForm, subform, frame, "subform" );
418 DECLM (WXawPanner, panner, subform, "panner" );
419 DECLM (WXawPorthole, porthole, subform, "porthole" );
420 DECLM (WPixmap, pixmap, porthole, "pixmap" );
423 f_panner = (WXawPanner*)(Widget)panner ;
424 f_pixmap_widget = (WPixmap*)(Widget)pixmap ;
426 file.SubMenuId (file_menu);
427 view.SubMenuId (view_menu);
428 pan.SubMenuId (panner_menu);
429 help.SubMenuId (help_menu);
430 menu_bar.MenuHelpWidget (help);
434 PixmapGraphic &pgraphic = *(f_graphic->pixmap_graphic());
436 Graphic *graphic = f_graphic ;
437 UAS_String titleStr(graphic->title());
438 const char *title = titleStr ;
440 if (title == NULL || *title == '\0') // empty string
441 title = (char *)CATGETS(Set_GraphicAgent, 2, "Detached Graphic");
445 UAS_String buffer = CATGETS(Set_GraphicAgent, 8, "Dtinfo: ");
446 buffer = buffer + title;
448 f_shell.Title((char*)buffer);
449 f_shell.IconName((char*)buffer);
454 panner.CanvasWidth (pgraphic.width(), args);
455 panner.CanvasHeight (pgraphic.height(), args);
458 SET_CALLBACK_D (porthole,Report,porthole_report,(Widget) panner);
459 install_new_picture(&pgraphic);
460 SET_CALLBACK_D (panner,Report,panner_report,(Widget) pixmap);
462 ON_ACTIVATE (visit,visit_node);
463 ON_ACTIVATE (close,close_window);
464 ON_ACTIVATE (attach,reattach);
466 SET_CALLBACK_D (none,ValueChanged,set_panner,PANNER_NONE);
467 SET_CALLBACK_D (up_left,ValueChanged,set_panner,PANNER_UPPER_LEFT);
468 SET_CALLBACK_D (up_right,ValueChanged,set_panner,PANNER_UPPER_RIGHT);
469 SET_CALLBACK_D (low_left,ValueChanged,set_panner,PANNER_LOWER_LEFT);
470 SET_CALLBACK_D (low_right,ValueChanged,set_panner,PANNER_LOWER_RIGHT);
472 ON_ACTIVATE (fit_gr_to_win,fit_graphic_to_window_callback);
473 ON_ACTIVATE (fit_win_to_gr,fit_window_to_graphic_callback);
475 SET_CALLBACK_D (z_25,ValueChanged,zoom_callback,25);
476 SET_CALLBACK_D (z_50,ValueChanged,zoom_callback,50);
477 SET_CALLBACK_D (z_100,ValueChanged,zoom_callback,100);
478 SET_CALLBACK_D (z_125,ValueChanged,zoom_callback,125);
479 SET_CALLBACK_D (z_150,ValueChanged,zoom_callback,150);
480 SET_CALLBACK_D (z_200,ValueChanged,zoom_callback,200);
481 SET_CALLBACK_D (z_custom,ValueChanged,zoom_callback,0);
483 help_agent().add_activate_help (on_window, "graphic_on_window");
484 help_agent().add_activate_help (on_help, "graphic_on_help");
488 // menubars for scalable graphics
490 // assume all graphics are scalable
491 bool scalable = True;
494 if (f_graphic->content_type() == "application/CGM")
495 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
497 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
501 #if !defined(VF_DEBUG)
502 for (int i = 0 ; i < view_menu.NumChildren(); i++)
503 WRect(view_menu.Children()[i]).SetSensitive(False);
505 mtfstring = CATGETS(Set_GraphicAgent, 3,
506 "Raster illustration (non-scalable)");
510 if (f_graphic->content_type() != "application/postscript") {
512 #if !defined(VF_DEBUG)
513 for (int i = 0 ; i < view_menu.NumChildren(); i++)
514 WRect(view_menu.Children()[i]).SetSensitive(False);
516 mtfstring = CATGETS(Set_GraphicAgent, 3,
517 "Raster illustration (non-scalable)");
520 mtfstring = CATGETS(Set_GraphicAgent, 4,
521 "Vector illustration (scalable)");
525 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
527 // porthole.Manage();
529 subform.ShadowThickness(0);
531 form.ShadowThickness(0);
534 // when panner first appears, it should be in upper-left corner
536 adjust_panner (PANNER_UPPER_LEFT);
538 // Set Max width/height if not scalable
542 Display *display = XtDisplay(f_shell);
543 Screen *retScr = XtScreen(f_shell);
544 int screen = XScreenNumberOfScreen(retScr);
545 int dw = DisplayWidth(display, screen);
546 int dh = DisplayHeight(display, screen);
548 Dimension width = dw, height = dh;
550 //if (f_graphic->content_type() == "application/CGM")
552 // assume all graphics are scalable
556 // set max size of window
557 height = min(height, dh - 100);
558 width = min(width, dw - 100);
560 f_shell.Set (WArgList (XmNmaxHeight, height,
564 // don't allow window to shrink smaller than original size
565 f_shell.Get (WArgList (XmNheight, (XtArgVal) &height,
567 height = min(height, dh - 100);
569 f_shell.Set (WArgList (XmNminHeight, height,
574 f_shell.Get (WArgList (XmNheight, (XtArgVal) &height,
577 height = min(height, dh - 100);
578 width = min(width, dw - 100);
580 f_shell.Set (WArgList (XmNmaxHeight, height,
588 GraphicAgent::close_window()
594 // /////////////////////////////////////////////////////////////////
595 // ui_destroyed - user nuked Motif window, so kill myself
596 // /////////////////////////////////////////////////////////////////
599 GraphicAgent::ui_destroyed()
601 // Set f_shell to NULL, since Xt is destroying it for us.
608 GraphicAgent::attach_graphic()
615 GraphicAgent::reattach()
617 graphics_mgr().reattach_graphic(f_graphic);
619 // UAS_String idata(*image_data);
620 // PixmapGraphic *pgr = f_graphic->pixmap_graphic();
622 // ON_DEBUG(cerr << "Graphic Agent reattach" << endl);
623 // f_graphic->set_detached(FALSE);
625 // pixmap_graphic()->
626 // UAS_Sender<ReAttachGraphic>::send_message(ReAttachGraphic(f_graphic));
628 // graphics_mgr().remove_detached((GraphicAgent*)this);
634 GraphicAgent::visit_node()
636 extern char g_top_locator[];
637 extern bool g_scroll_to_locator;
638 const char *glocator = f_graphic->locator();
639 ON_DEBUG (printf ("Graphic jumping to <%s>\n", glocator));
640 ON_DEBUG (printf (" copying to %p\n", g_top_locator));
641 strcpy (g_top_locator, &glocator[8]);
642 g_scroll_to_locator = TRUE;
643 f_node_ptr->retrieve();
648 GraphicAgent::porthole_report(WCallback *wcb)
650 XawPannerReport *repp = (XawPannerReport*)wcb->CallData();
651 XawPannerReport &rep = *repp;
652 ON_DEBUG(cerr << "got a porthole_report" << hex << rep.changed << endl);
653 if (rep.changed & (XawPRCanvasHeight | XawPRCanvasWidth)){
654 ON_DEBUG(cerr << "porthole height or width change" << endl);
656 WXawPorthole porthole(wcb->GetWidget());
657 WXawPanner panner((Widget)wcb->ClientData());
659 WCore picture(porthole.Children()[0]);
661 Dimension port_width = porthole.Width();
662 Dimension port_height = porthole.Height();
663 Dimension cwidth = panner.CanvasWidth();
664 Dimension cheight= panner.CanvasHeight();
666 ON_DEBUG(cerr << "Canvas ( " << cwidth << ", " << cheight << ")"<<endl);
667 ON_DEBUG(cerr << "Porthle( " << port_width << ", " << port_height << ")"
672 // re-adjust the slider
673 if (rep.changed & XawPRCanvasHeight)
675 ON_DEBUG(cerr << "adjust panner SliderHeight " << port_height <<
677 panner.SliderHeight(port_height, args);
680 if (rep.changed & XawPRCanvasWidth)
682 ON_DEBUG(cerr << "adjust panner SliderWidth " << port_width <<
684 panner.SliderWidth(port_width, args);
690 if ((cwidth <= port_width) &&
691 (cheight <= port_height))
693 ON_DEBUG(cerr << "PANNER UNmanage" << endl);
696 if (f_panner_state != PANNER_NONE)
704 GraphicAgent::panner_report(WCallback *wcb)
706 ON_DEBUG(cerr << "panner report " << endl);
707 XawPannerReport *repp = (XawPannerReport*)wcb->CallData();
708 XawPannerReport &rep = *repp;
713 WCore core((Widget)wcb->ClientData());
714 core.X(0 - rep.slider_x, args);
715 core.Y(0 - rep.slider_y, args);
721 GraphicAgent::adjust_panner(unsigned int state)
723 ON_DEBUG(cerr << "adjust_panner( " << state << ")" << endl);
724 if (state == f_panner_state)
727 f_panner_state = state ;
731 WXawPanner &panner(*f_panner) ;
734 case PANNER_UPPER_LEFT:
737 panner.LeftAttachment(XmATTACH_FORM, args);
738 panner.TopAttachment(XmATTACH_FORM, args);
739 panner.RightAttachment(XmATTACH_POSITION, args);
740 panner.RightPosition(20, args);
741 panner.BottomAttachment(XmATTACH_POSITION, args);
742 panner.BottomPosition(20, args);
745 case PANNER_UPPER_RIGHT:
748 panner.RightAttachment(XmATTACH_FORM, args);
749 panner.TopAttachment(XmATTACH_FORM, args);
750 panner.LeftAttachment(XmATTACH_POSITION, args);
751 panner.LeftPosition(80, args);
752 panner.BottomAttachment(XmATTACH_POSITION, args);
753 panner.BottomPosition(20, args);
756 case PANNER_LOWER_RIGHT:
759 panner.RightAttachment(XmATTACH_FORM, args);
760 panner.BottomAttachment(XmATTACH_FORM, args);
761 panner.LeftAttachment(XmATTACH_POSITION, args);
762 panner.LeftPosition(80, args);
763 panner.TopAttachment(XmATTACH_POSITION, args);
764 panner.TopPosition(80, args);
767 case PANNER_LOWER_LEFT:
770 panner.LeftAttachment(XmATTACH_FORM, args);
771 panner.BottomAttachment(XmATTACH_FORM, args);
772 panner.RightAttachment(XmATTACH_POSITION, args);
773 panner.RightPosition(20, args);
774 panner.TopAttachment(XmATTACH_POSITION, args);
775 panner.TopPosition(80, args);
791 // see if we can display it
793 Dimension cwidth = panner.CanvasWidth();
794 Dimension cheight = panner.CanvasHeight();
796 WXawPorthole porthole(XtParent(*f_panner)) ;
798 ON_DEBUG(cerr << "Panner - state: " << state << " canvas ( " << cwidth
799 << ", " << cheight << ") porthole ( " << porthole.Width() <<
800 ", " << porthole.Height() << ")" << endl);
802 if ((state != PANNER_NONE) &&
803 ((cwidth > porthole.Width()) ||
804 (cheight > porthole.Height())))
812 GraphicAgent::set_panner(WCallback *wcb)
814 // adjust panner to the Set state
815 WXmToggleButton button(wcb->GetWidget());
818 unsigned int state = (unsigned int)wcb->ClientData();
819 adjust_panner(state);
825 GraphicAgent::zoom_callback(WCallback *wcb)
827 ON_DEBUG (puts ("GraphicAgent::zoom_callback() called"));
828 WXmToggleButton button(wcb->GetWidget());
829 XmToggleButtonCallbackStruct &cbs =
830 *(XmToggleButtonCallbackStruct*)wcb->CallData();
832 ON_DEBUG(cerr << "cbs.set = " << cbs.set << endl);
833 ON_DEBUG(cerr << "cbs.rsn = " << cbs.reason << endl);
834 ON_DEBUG(cerr << "cbs.event = " << cbs.event << endl);
838 int scale = (unsigned int) wcb->ClientData();
842 f_scale_button = (WXmToggleButton*)(Widget)button ;
847 // we get called twice when selecting already selected custom button
848 // just do nothing second time around
856 UAS_String msg = CATGETS(Set_GraphicAgent, 6,
857 "Enter the new scaling percentage:");
858 UAS_String title = CATGETS(Set_GraphicAgent, 7, "Dtinfo: Set Scale");
859 scale = message_mgr().
860 get_integer((char*)msg, (char*)title, f_current_scale,
863 ON_DEBUG(cerr << "scale value is " << scale << endl);
866 // unset Custom option in list
867 if (((Widget)*f_scale_button) != ((Widget)button))
870 f_scale_button->Set(1);
876 f_scale_button = (WXmToggleButton*)(Widget)button ;
878 // maybe this should be a user option
879 //fit_window_to_graphic();
885 GraphicAgent::set_zoom(unsigned int scale)
887 // Deal with bogus values.
890 else if (scale > 999)
893 if (scale == f_current_scale)
898 XmStringLocalized mtfstring = CATGETS(Set_GraphicAgent, 5,
899 "Scaling illustration, please wait...");
901 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
903 XmUpdateDisplay((Widget)f_message_area);
905 f_current_scale = scale;
907 UAS_String f_graphic_content_type(f_graphic->content_type());
908 UAS_String temp_str = f_graphic->data();
911 f_graphic->pixmap_graphic(temp_str, f_graphic->data_length(),
912 f_graphic_content_type, scale);
913 install_new_picture(pgr);
916 if (f_graphic->content_type() == "application/CGM")
917 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
919 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
921 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
927 GraphicAgent::refresh(const UAS_Pointer<Graphic> &)
929 // refresh by clearing window and sending in expose event
930 XClearArea(XtDisplay(*f_pixmap_widget),
931 XtWindow(*f_pixmap_widget),
934 // update message area
935 XmStringLocalized mtfstring;
936 if (f_graphic->content_type() == "application/CGM")
937 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
939 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
941 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
946 GraphicAgent::fit_graphic_to_window_callback(WCallback *)
951 unsigned int scale_factor;
953 // get size of graphic
954 gr_width = f_graphic->pixmap_graphic()->width();
955 gr_height = f_graphic->pixmap_graphic()->height();
958 WXawPorthole porthole(XtParent(*f_pixmap_widget));
959 dx = abs(porthole.Width() - f_graphic->pixmap_graphic()->width());
960 dy = abs(porthole.Height() - f_graphic->pixmap_graphic()->height());
963 (100 * porthole.Width()) / f_graphic->pixmap_graphic()->width();
966 (100 * porthole.Height()) / f_graphic->pixmap_graphic()->height();
969 wscale = (100 * porthole.Width()) / gr_width;
970 hscale = (100 * porthole.Height()) / gr_height;
972 // scaling from dimensions of original pixmap graphic
978 // fit graphic to window means custom scale, so
979 // toggle the button.
980 f_scale_button->Set(0);
981 f_scale_button = f_custom_scale;
982 f_scale_button->Set(1);
988 GraphicAgent::fit_window_to_graphic_callback(WCallback *)
990 fit_window_to_graphic();
993 GraphicAgent::fit_window_to_graphic()
995 WXawPorthole porthole(XtParent(*f_pixmap_widget));
996 WPixmap picture(*f_pixmap_widget) ;
997 WXawPanner panner(*f_panner);
999 // desired width of porthole is in panner.Canvas{Width,Height}
1000 Dimension cwidth = panner.CanvasWidth();
1001 Dimension cheight = panner.CanvasHeight() ;
1003 // menu_bar is first child of form which is first child of f_shell
1004 WComposite form(f_shell.Children()[0]);
1005 WComposite menu_bar(form.Children()[0]) ;
1006 // f_message_area is Children()[1]
1007 WXmSeparator separator(form.Children()[2]);
1009 // account for frame margins
1010 // frame is parent of subform is parent of panner
1011 WXmFrame frame(XtParent(XtParent(panner)));
1013 cheight += menu_bar.Height() + frame.MarginHeight() * 2 + frame.TopOffset()
1014 + frame.BottomOffset() + separator.Height() + 2 * separator.Margin() +
1015 separator.TopOffset() + separator.BottomOffset() +
1016 f_message_area->Height() + f_message_area->TopOffset() +
1017 f_message_area->BottomOffset() + f_message_area->MarginTop() +
1018 f_message_area->MarginBottom();// + 2 * f_message_area->MarginHeight();
1020 cwidth += frame.MarginWidth() * 2 + frame.LeftOffset() +
1021 frame.RightOffset();
1024 f_shell.Width(cwidth + 4, args);
1025 f_shell.Height(cheight + 4, args);
1032 GraphicAgent::install_new_picture(PixmapGraphic *pgr)
1034 // dispose of the old Pixmap if needed
1035 Pixmap pixmap = f_pixmap_widget->Picture() ;
1036 if (pixmap && (pixmap != f_graphic->pixmap_graphic()->pixmap()))
1037 XFreePixmap(XtDisplay(*f_pixmap_widget), pixmap); // a scaled pixmap...give it back
1040 // put the new Pixmap into the pixmap widget
1042 f_pixmap_widget->Picture(pgr->pixmap(), args) ; // install the new one
1043 f_pixmap_widget->Width(pgr->width(), args); // update size
1044 f_pixmap_widget->Height(pgr->height(), args);
1045 f_pixmap_widget->Set(args);
1047 // update some more UI crud
1050 WXawPorthole porthole(XtParent(*f_pixmap_widget));
1053 WXawPanner panner(*f_panner);
1054 panner.CanvasWidth(pgr->width(), args);
1055 panner.CanvasHeight(pgr->height(),args);
1056 panner.SliderWidth(porthole.Width(), args);
1057 panner.SliderHeight(porthole.Height(), args);
1060 if ((f_panner_state != PANNER_NONE) &&
1061 ((pgr->width() > porthole.Width()) ||
1062 (pgr->height() > porthole.Height())))
1074 if (pgr != f_graphic->pixmap_graphic())
1076 // clean up PixmapGraphic storage, but keep the X Pixmap
1077 // (its in the pixmap_widget)
1078 pgr->set_type(PixmapGraphic::PRESERVE) ;
1084 GraphicAgent::unset_scale_buttons()
1086 for (int i = 0 ; i < 10; i++)
1087 WXmToggleButton((*f_view_menu).Children()[i]).Set(False);