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"
88 #include "Registration.hh"
90 #include "Widgets/WXawPorthole.h"
91 #include "Widgets/WXawPanner.h"
92 #include "Widgets/WPixmap.h"
94 #include "utility/funcs.h"
96 #define CLASS GraphicAgent
97 #include "create_macros.hh"
99 enum { PANNER_UPPER_LEFT,
109 return i1 < i2 ? i1 : i2 ;
112 // /////////////////////////////////////////////////////////////////////////
114 // /////////////////////////////////////////////////////////////////////////
116 GraphicAgent::GraphicAgent (UAS_Pointer<UAS_Common> &node_ptr,
117 UAS_Pointer<Graphic> &gr)
119 f_node_ptr(node_ptr),
121 f_panner_state (PANNER_NONE),
122 f_current_scale (100),
123 f_scale_button(NULL),
127 f_graphic->pixmap_graphic()->agent(this);
129 UAS_Common::request ((UAS_Receiver<UAS_LibraryDestroyedMsg> *) this);
132 // /////////////////////////////////////////////////////////////////////////
134 // /////////////////////////////////////////////////////////////////////////
136 GraphicAgent::~GraphicAgent()
138 f_graphic->pixmap_graphic()->agent(NULL);
139 Pixmap pixmap = f_pixmap_widget->Picture();
140 if (pixmap && pixmap != f_graphic->pixmap_graphic()->pixmap())
142 XFreePixmap(XtDisplay(*f_pixmap_widget),
143 pixmap); // a scaled pixmap...give it back
150 // /////////////////////////////////////////////////////////////////////////
152 // /////////////////////////////////////////////////////////////////////////
155 GraphicAgent::popup()
164 // /////////////////////////////////////////////////////////////////////////
166 // /////////////////////////////////////////////////////////////////////////
169 GraphicAgent::display()
174 // assume all graphics are scalable for now.
179 Widget *kids = f_view_menu->Children() ;
180 int num_children = f_view_menu->NumChildren();
181 for (int i = 0 ; i < num_children; i++)
183 WXmPrimitive prim(kids[i]);
184 prim.SetSensitive(True);
192 GraphicAgent::receive(DisplayGraphic &message, void* /*client_data*/)
194 ON_DEBUG(cerr << "GraphicAgent::receive(DisplayGraphic( " <<
195 message.graphic()->locator() << "))" << endl);
197 ON_DEBUG(cerr << "local locator is " <<
198 f_graphic->locator() << endl);
200 if (message.graphic() == f_graphic)
202 ON_DEBUG(cerr << "GraphicAgent::receive(DISPLAY)" << endl);
208 GraphicAgent::receive(ReAttachGraphic &message, void* /*client_data*/)
214 GraphicAgent::receive (UAS_LibraryDestroyedMsg &msg, void* /*client_data*/)
216 if(f_node_ptr->lid() == (msg.fLib)->lid())
218 graphics_mgr().remove_detached((GraphicAgent*)this);
222 // /////////////////////////////////////////////////////////////////////////
224 // /////////////////////////////////////////////////////////////////////////
226 #define AM WAutoManage
228 GraphicAgent::create_ui()
230 XmStringLocalized mtfstring;
233 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "graphic");
234 window_system().register_shell (&f_shell);
236 string = CATGETS(Set_GraphicAgent, 1, "Dtinfo: Detached Graphic");
237 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
239 // just use "delete_response" instead
240 // add a destroy callback to nuke the agent when widget is destroyed.
241 f_shell.SetDestroyCallback (this, (WWL_FUN) &GraphicAgent::ui_destroyed);
243 DECL (WXmForm, form, f_shell, "form" );
244 DECLMC(WXmMenuBar, menu_bar, form, "menu_bar" );
247 // rtp: hard-wire the menu bar's background, since
248 // it comes up a bogus color. Copied from swm's
249 // change in NodeWindowAgentMotif.C
251 Pixel bg = form.Background();
252 menu_bar.Background(bg);
255 DECLM (WXmCascadeButton, file, menu_bar, "file" );
256 DECLMC(WXmPulldownMenu, file_menu, menu_bar, "file_menu" );
257 DECLM (WXmPushButton, attach, file_menu, "attach" );
258 DECLM (WXmPushButton, visit, file_menu, "visit" );
259 DECLM (WXmPushButton, close, file_menu, "close" );
261 XtVaSetValues(file, XmNlabelString,
262 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 1, "File")),
264 *CATGETS(Set_AgentLabel, 2, ""),
267 XtVaSetValues(attach, XmNlabelString,
268 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 167, "Attach")),
270 *CATGETS(Set_AgentLabel, 21, ""),
273 XtVaSetValues(visit, XmNlabelString,
274 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel,168,"Display Section")),
276 *CATGETS(Set_AgentLabel, 119, ""),
279 XtVaSetValues(close, XmNlabelString,
280 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 12, "Close")),
282 *CATGETS(Set_AgentLabel, 13, ""),
285 DECLM (WXmCascadeButton, pan, menu_bar, "panner" );
286 DECLMC(WXmPulldownMenu, panner_menu, menu_bar, "panner_menu" );
287 DECLM (WXmToggleButton, none, panner_menu, "none" );
288 DECLM (WXmToggleButton, up_left, panner_menu, "up_left" );
289 DECLM (WXmToggleButton, up_right, panner_menu, "up_right" );
290 DECLM (WXmToggleButton, low_left, panner_menu, "low_left" );
291 DECLM (WXmToggleButton, low_right, panner_menu, "low_right" );
293 XtVaSetValues(pan, XmNlabelString,
294 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 166, "Panner")),
296 *CATGETS(Set_AgentLabel, 9, ""),
299 XtVaSetValues(none, XmNlabelString,
300 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 178, "None")),
302 *CATGETS(Set_AgentLabel, 7, ""),
305 XtVaSetValues(up_left, XmNlabelString,
306 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 179, "Upper Left")),
308 *CATGETS(Set_AgentLabel, 254, ""),
311 XtVaSetValues(up_right, XmNlabelString,
312 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 180, "Upper Right")),
314 *CATGETS(Set_AgentLabel, 252, ""),
317 XtVaSetValues(low_left, XmNlabelString,
318 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 181, "Lower Left")),
320 *CATGETS(Set_AgentLabel, 113, ""),
323 XtVaSetValues(low_right, XmNlabelString,
324 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 182, "Lower Right")),
326 *CATGETS(Set_AgentLabel, 259, ""),
329 // NOTE: some code in this module depends upon the exact ordering of items
330 // view menu will only be sensitive for scalable graphics
331 DECL (WXmCascadeButton, view, menu_bar, "view" );
332 DECLMC(WXmPulldownMenu, view_menu, menu_bar, "view_menu" );
333 DECLM (WXmPushButton, fit_gr_to_win, view_menu, "fit_window" );
334 DECLM (WXmPushButton, fit_win_to_gr, view_menu, "fit_graphic" );
336 XtVaSetValues(view, XmNlabelString,
337 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 4, "View")),
339 *CATGETS(Set_AgentLabel, 5, ""),
342 XtVaSetValues(fit_gr_to_win, XmNlabelString,
343 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 169, "Fit to Window")),
345 *CATGETS(Set_AgentLabel, 35, ""),
349 XtVaSetValues(fit_win_to_gr, XmNlabelString,
350 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 170, "Fit to Graphic")),
352 *CATGETS(Set_AgentLabel, 37, ""),
355 DECLM (WXmSeparator, separator, view_menu, "separator" );
356 DECLM (WXmToggleButton, z_25, view_menu, "z_25" );
357 DECLM (WXmToggleButton, z_50, view_menu, "z_50" );
358 DECLM (WXmToggleButton, z_100, view_menu, "z_100" );
359 DECLM (WXmToggleButton, z_125, view_menu, "z_125" );
360 DECLM (WXmToggleButton, z_150, view_menu, "z_150" );
361 DECLM (WXmToggleButton, z_200, view_menu, "z_200" );
362 DECLM (WXmToggleButton, z_custom, view_menu, "z_custom" );
364 mtfstring = CATGETS(Set_AgentLabel, 171, "25 %");
365 XtVaSetValues(z_25, XmNlabelString, (XmString)mtfstring, NULL);
366 mtfstring = CATGETS(Set_AgentLabel, 172, "50 %");
367 XtVaSetValues(z_50, XmNlabelString, (XmString)mtfstring, NULL);
368 mtfstring = CATGETS(Set_AgentLabel, 173, "100 %");
369 XtVaSetValues(z_100, XmNlabelString, (XmString)mtfstring, NULL);
370 mtfstring = CATGETS(Set_AgentLabel, 174, "125 %");
371 XtVaSetValues(z_125, XmNlabelString, (XmString)mtfstring, NULL);
372 mtfstring = CATGETS(Set_AgentLabel, 175, "150 %");
373 XtVaSetValues(z_150, XmNlabelString, (XmString)mtfstring, NULL);
374 mtfstring = CATGETS(Set_AgentLabel, 176, "200 %");
375 XtVaSetValues(z_200, XmNlabelString, (XmString)mtfstring, NULL);
377 XtVaSetValues(z_custom, XmNlabelString,
378 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 177, "Custom...")),
380 *CATGETS(Set_AgentLabel, 13, ""),
384 f_scale_button = (WXmToggleButton*)(Widget)z_100 ;
385 f_custom_scale = (WXmToggleButton*)(Widget)z_custom ;
387 f_view_menu = (WXmPulldownMenu*)(Widget)view_menu ;
389 DECLM (WXmCascadeButton, help, menu_bar, "help" );
390 DECLMC(WXmPulldownMenu, help_menu, menu_bar, "help_menu" );
391 DECLM (WXmPushButton, on_window, help_menu, "on_window" );
392 DECLM (WXmPushButton, on_help, help_menu, "on_help" );
394 XtVaSetValues(help, XmNlabelString,
395 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 48, "Help")),
397 *CATGETS(Set_AgentLabel, 39, ""),
400 XtVaSetValues(on_window, XmNlabelString,
401 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 147, "On Window")),
403 *CATGETS(Set_AgentLabel, 35, ""),
406 XtVaSetValues(on_help, XmNlabelString,
407 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 153, "On Help")),
409 *CATGETS(Set_AgentLabel, 39, ""),
412 DECLM (WXmLabel, message_area, form, "message");
413 f_message_area = (WXmLabel*)(Widget)message_area ;
415 DECLM (WXmSeparator, sep, form, "sep2");
417 DECL (WXmFrame, frame, form, "frame" );
418 DECL (WXmForm, subform, frame, "subform" );
419 DECLM (WXawPanner, panner, subform, "panner" );
420 DECLM (WXawPorthole, porthole, subform, "porthole" );
421 DECLM (WPixmap, pixmap, porthole, "pixmap" );
424 f_panner = (WXawPanner*)(Widget)panner ;
425 f_pixmap_widget = (WPixmap*)(Widget)pixmap ;
427 file.SubMenuId (file_menu);
428 view.SubMenuId (view_menu);
429 pan.SubMenuId (panner_menu);
430 help.SubMenuId (help_menu);
431 menu_bar.MenuHelpWidget (help);
435 PixmapGraphic &pgraphic = *(f_graphic->pixmap_graphic());
437 Graphic *graphic = f_graphic ;
438 UAS_String titleStr(graphic->title());
439 const char *title = titleStr ;
441 if (title == NULL || *title == '\0') // empty string
442 title = (char *)CATGETS(Set_GraphicAgent, 2, "Detached Graphic");
446 UAS_String buffer = CATGETS(Set_GraphicAgent, 8, "Dtinfo: ");
447 buffer = buffer + title;
449 f_shell.Title((char*)buffer);
450 f_shell.IconName((char*)buffer);
455 panner.CanvasWidth (pgraphic.width(), args);
456 panner.CanvasHeight (pgraphic.height(), args);
459 SET_CALLBACK_D (porthole,Report,porthole_report,(Widget) panner);
460 install_new_picture(&pgraphic);
461 SET_CALLBACK_D (panner,Report,panner_report,(Widget) pixmap);
463 ON_ACTIVATE (visit,visit_node);
464 ON_ACTIVATE (close,close_window);
465 ON_ACTIVATE (attach,reattach);
467 SET_CALLBACK_D (none,ValueChanged,set_panner,PANNER_NONE);
468 SET_CALLBACK_D (up_left,ValueChanged,set_panner,PANNER_UPPER_LEFT);
469 SET_CALLBACK_D (up_right,ValueChanged,set_panner,PANNER_UPPER_RIGHT);
470 SET_CALLBACK_D (low_left,ValueChanged,set_panner,PANNER_LOWER_LEFT);
471 SET_CALLBACK_D (low_right,ValueChanged,set_panner,PANNER_LOWER_RIGHT);
473 ON_ACTIVATE (fit_gr_to_win,fit_graphic_to_window_callback);
474 ON_ACTIVATE (fit_win_to_gr,fit_window_to_graphic_callback);
476 SET_CALLBACK_D (z_25,ValueChanged,zoom_callback,25);
477 SET_CALLBACK_D (z_50,ValueChanged,zoom_callback,50);
478 SET_CALLBACK_D (z_100,ValueChanged,zoom_callback,100);
479 SET_CALLBACK_D (z_125,ValueChanged,zoom_callback,125);
480 SET_CALLBACK_D (z_150,ValueChanged,zoom_callback,150);
481 SET_CALLBACK_D (z_200,ValueChanged,zoom_callback,200);
482 SET_CALLBACK_D (z_custom,ValueChanged,zoom_callback,0);
484 help_agent().add_activate_help (on_window, (char*)"graphic_on_window");
485 help_agent().add_activate_help (on_help, (char*)"graphic_on_help");
489 // menubars for scalable graphics
491 // assume all graphics are scalable
492 bool scalable = True;
495 if (f_graphic->content_type() == "application/CGM")
496 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
498 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
502 #if !defined(VF_DEBUG)
503 for (int i = 0 ; i < view_menu.NumChildren(); i++)
504 WRect(view_menu.Children()[i]).SetSensitive(False);
506 mtfstring = CATGETS(Set_GraphicAgent, 3,
507 "Raster illustration (non-scalable)");
511 if (f_graphic->content_type() != "application/postscript") {
513 #if !defined(VF_DEBUG)
514 for (int i = 0 ; i < view_menu.NumChildren(); i++)
515 WRect(view_menu.Children()[i]).SetSensitive(False);
517 mtfstring = CATGETS(Set_GraphicAgent, 3,
518 "Raster illustration (non-scalable)");
521 mtfstring = CATGETS(Set_GraphicAgent, 4,
522 "Vector illustration (scalable)");
526 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
528 // porthole.Manage();
530 subform.ShadowThickness(0);
532 form.ShadowThickness(0);
535 // when panner first appears, it should be in upper-left corner
537 adjust_panner (PANNER_UPPER_LEFT);
539 // Set Max width/height if not scalable
543 Display *display = XtDisplay(f_shell);
544 Screen *retScr = XtScreen(f_shell);
545 int screen = XScreenNumberOfScreen(retScr);
546 int dw = DisplayWidth(display, screen);
547 int dh = DisplayHeight(display, screen);
549 Dimension width = dw, height = dh;
551 //if (f_graphic->content_type() == "application/CGM")
553 // assume all graphics are scalable
557 // set max size of window
558 height = min(height, dh - 100);
559 width = min(width, dw - 100);
561 f_shell.Set (WArgList (XmNmaxHeight, height,
565 // don't allow window to shrink smaller than original size
566 f_shell.Get (WArgList (XmNheight, (XtArgVal) &height,
568 height = min(height, dh - 100);
570 f_shell.Set (WArgList (XmNminHeight, height,
575 f_shell.Get (WArgList (XmNheight, (XtArgVal) &height,
578 height = min(height, dh - 100);
579 width = min(width, dw - 100);
581 f_shell.Set (WArgList (XmNmaxHeight, height,
589 GraphicAgent::close_window()
595 // /////////////////////////////////////////////////////////////////
596 // ui_destroyed - user nuked Motif window, so kill myself
597 // /////////////////////////////////////////////////////////////////
600 GraphicAgent::ui_destroyed()
602 // Set f_shell to NULL, since Xt is destroying it for us.
609 GraphicAgent::attach_graphic()
616 GraphicAgent::reattach()
618 graphics_mgr().reattach_graphic(f_graphic);
620 // UAS_String idata(*image_data);
621 // PixmapGraphic *pgr = f_graphic->pixmap_graphic();
623 // ON_DEBUG(cerr << "Graphic Agent reattach" << endl);
624 // f_graphic->set_detached(FALSE);
626 // pixmap_graphic()->
627 // UAS_Sender<ReAttachGraphic>::send_message(ReAttachGraphic(f_graphic));
629 // graphics_mgr().remove_detached((GraphicAgent*)this);
635 GraphicAgent::visit_node()
637 extern char g_top_locator[];
638 extern bool g_scroll_to_locator;
639 const char *glocator = f_graphic->locator();
640 ON_DEBUG (printf ("Graphic jumping to <%s>\n", glocator));
641 ON_DEBUG (printf (" copying to %p\n", g_top_locator));
642 strcpy (g_top_locator, &glocator[8]);
643 g_scroll_to_locator = TRUE;
644 f_node_ptr->retrieve();
649 GraphicAgent::porthole_report(WCallback *wcb)
651 XawPannerReport *repp = (XawPannerReport*)wcb->CallData();
652 XawPannerReport &rep = *repp;
653 ON_DEBUG(cerr << "got a porthole_report" << hex << rep.changed << endl);
654 if (rep.changed & (XawPRCanvasHeight | XawPRCanvasWidth)){
655 ON_DEBUG(cerr << "porthole height or width change" << endl);
657 WXawPorthole porthole(wcb->GetWidget());
658 WXawPanner panner((Widget)wcb->ClientData());
660 WCore picture(porthole.Children()[0]);
662 Dimension port_width = porthole.Width();
663 Dimension port_height = porthole.Height();
664 Dimension cwidth = panner.CanvasWidth();
665 Dimension cheight= panner.CanvasHeight();
667 ON_DEBUG(cerr << "Canvas ( " << cwidth << ", " << cheight << ")"<<endl);
668 ON_DEBUG(cerr << "Porthle( " << port_width << ", " << port_height << ")"
673 // re-adjust the slider
674 if (rep.changed & XawPRCanvasHeight)
676 ON_DEBUG(cerr << "adjust panner SliderHeight " << port_height <<
678 panner.SliderHeight(port_height, args);
681 if (rep.changed & XawPRCanvasWidth)
683 ON_DEBUG(cerr << "adjust panner SliderWidth " << port_width <<
685 panner.SliderWidth(port_width, args);
691 if ((cwidth <= port_width) &&
692 (cheight <= port_height))
694 ON_DEBUG(cerr << "PANNER UNmanage" << endl);
697 if (f_panner_state != PANNER_NONE)
705 GraphicAgent::panner_report(WCallback *wcb)
707 ON_DEBUG(cerr << "panner report " << endl);
708 XawPannerReport *repp = (XawPannerReport*)wcb->CallData();
709 XawPannerReport &rep = *repp;
714 WCore core((Widget)wcb->ClientData());
715 core.X(0 - rep.slider_x, args);
716 core.Y(0 - rep.slider_y, args);
722 GraphicAgent::adjust_panner(unsigned int state)
724 ON_DEBUG(cerr << "adjust_panner( " << state << ")" << endl);
725 if (state == f_panner_state)
728 f_panner_state = state ;
732 WXawPanner &panner(*f_panner) ;
735 case PANNER_UPPER_LEFT:
738 panner.LeftAttachment(XmATTACH_FORM, args);
739 panner.TopAttachment(XmATTACH_FORM, args);
740 panner.RightAttachment(XmATTACH_POSITION, args);
741 panner.RightPosition(20, args);
742 panner.BottomAttachment(XmATTACH_POSITION, args);
743 panner.BottomPosition(20, args);
746 case PANNER_UPPER_RIGHT:
749 panner.RightAttachment(XmATTACH_FORM, args);
750 panner.TopAttachment(XmATTACH_FORM, args);
751 panner.LeftAttachment(XmATTACH_POSITION, args);
752 panner.LeftPosition(80, args);
753 panner.BottomAttachment(XmATTACH_POSITION, args);
754 panner.BottomPosition(20, args);
757 case PANNER_LOWER_RIGHT:
760 panner.RightAttachment(XmATTACH_FORM, args);
761 panner.BottomAttachment(XmATTACH_FORM, args);
762 panner.LeftAttachment(XmATTACH_POSITION, args);
763 panner.LeftPosition(80, args);
764 panner.TopAttachment(XmATTACH_POSITION, args);
765 panner.TopPosition(80, args);
768 case PANNER_LOWER_LEFT:
771 panner.LeftAttachment(XmATTACH_FORM, args);
772 panner.BottomAttachment(XmATTACH_FORM, args);
773 panner.RightAttachment(XmATTACH_POSITION, args);
774 panner.RightPosition(20, args);
775 panner.TopAttachment(XmATTACH_POSITION, args);
776 panner.TopPosition(80, args);
792 // see if we can display it
794 Dimension cwidth = panner.CanvasWidth();
795 Dimension cheight = panner.CanvasHeight();
797 WXawPorthole porthole(XtParent(*f_panner)) ;
799 ON_DEBUG(cerr << "Panner - state: " << state << " canvas ( " << cwidth
800 << ", " << cheight << ") porthole ( " << porthole.Width() <<
801 ", " << porthole.Height() << ")" << endl);
803 if ((state != PANNER_NONE) &&
804 ((cwidth > porthole.Width()) ||
805 (cheight > porthole.Height())))
813 GraphicAgent::set_panner(WCallback *wcb)
815 // adjust panner to the Set state
816 WXmToggleButton button(wcb->GetWidget());
819 size_t state = (size_t)wcb->ClientData();
820 adjust_panner(state);
826 GraphicAgent::zoom_callback(WCallback *wcb)
828 ON_DEBUG (puts ("GraphicAgent::zoom_callback() called"));
829 WXmToggleButton button(wcb->GetWidget());
830 XmToggleButtonCallbackStruct &cbs =
831 *(XmToggleButtonCallbackStruct*)wcb->CallData();
833 ON_DEBUG(cerr << "cbs.set = " << cbs.set << endl);
834 ON_DEBUG(cerr << "cbs.rsn = " << cbs.reason << endl);
835 ON_DEBUG(cerr << "cbs.event = " << cbs.event << endl);
839 size_t scale = (size_t) wcb->ClientData();
843 f_scale_button = (WXmToggleButton*)(Widget)button ;
848 // we get called twice when selecting already selected custom button
849 // just do nothing second time around
857 UAS_String msg = CATGETS(Set_GraphicAgent, 6,
858 "Enter the new scaling percentage:");
859 UAS_String title = CATGETS(Set_GraphicAgent, 7, "Dtinfo: Set Scale");
860 scale = message_mgr().
861 get_integer((char*)msg, (char*)title, f_current_scale,
864 ON_DEBUG(cerr << "scale value is " << scale << endl);
867 // unset Custom option in list
868 if (((Widget)*f_scale_button) != ((Widget)button))
871 f_scale_button->Set(1);
877 f_scale_button = (WXmToggleButton*)(Widget)button ;
879 // maybe this should be a user option
880 //fit_window_to_graphic();
886 GraphicAgent::set_zoom(unsigned int scale)
888 // Deal with bogus values.
891 else if (scale > 999)
894 if (scale == f_current_scale)
899 XmStringLocalized mtfstring = CATGETS(Set_GraphicAgent, 5,
900 "Scaling illustration, please wait...");
902 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
904 XmUpdateDisplay((Widget)f_message_area);
906 f_current_scale = scale;
908 UAS_String f_graphic_content_type(f_graphic->content_type());
909 UAS_String temp_str = f_graphic->data();
912 f_graphic->pixmap_graphic(temp_str, f_graphic->data_length(),
913 f_graphic_content_type, scale);
914 install_new_picture(pgr);
917 if (f_graphic->content_type() == "application/CGM")
918 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
920 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
922 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
928 GraphicAgent::refresh(const UAS_Pointer<Graphic> &)
930 // refresh by clearing window and sending in expose event
931 XClearArea(XtDisplay(*f_pixmap_widget),
932 XtWindow(*f_pixmap_widget),
935 // update message area
936 XmStringLocalized mtfstring;
937 if (f_graphic->content_type() == "application/CGM")
938 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
940 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
942 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
947 GraphicAgent::fit_graphic_to_window_callback(WCallback *)
952 unsigned int scale_factor;
954 // get size of graphic
955 gr_width = f_graphic->pixmap_graphic()->width();
956 gr_height = f_graphic->pixmap_graphic()->height();
959 WXawPorthole porthole(XtParent(*f_pixmap_widget));
960 dx = abs(porthole.Width() - f_graphic->pixmap_graphic()->width());
961 dy = abs(porthole.Height() - f_graphic->pixmap_graphic()->height());
964 (100 * porthole.Width()) / f_graphic->pixmap_graphic()->width();
967 (100 * porthole.Height()) / f_graphic->pixmap_graphic()->height();
970 wscale = (100 * porthole.Width()) / gr_width;
971 hscale = (100 * porthole.Height()) / gr_height;
973 // scaling from dimensions of original pixmap graphic
979 // fit graphic to window means custom scale, so
980 // toggle the button.
981 f_scale_button->Set(0);
982 f_scale_button = f_custom_scale;
983 f_scale_button->Set(1);
989 GraphicAgent::fit_window_to_graphic_callback(WCallback *)
991 fit_window_to_graphic();
994 GraphicAgent::fit_window_to_graphic()
996 WXawPorthole porthole(XtParent(*f_pixmap_widget));
997 WPixmap picture(*f_pixmap_widget) ;
998 WXawPanner panner(*f_panner);
1000 // desired width of porthole is in panner.Canvas{Width,Height}
1001 Dimension cwidth = panner.CanvasWidth();
1002 Dimension cheight = panner.CanvasHeight() ;
1004 // menu_bar is first child of form which is first child of f_shell
1005 WComposite form(f_shell.Children()[0]);
1006 WComposite menu_bar(form.Children()[0]) ;
1007 // f_message_area is Children()[1]
1008 WXmSeparator separator(form.Children()[2]);
1010 // account for frame margins
1011 // frame is parent of subform is parent of panner
1012 WXmFrame frame(XtParent(XtParent(panner)));
1014 cheight += menu_bar.Height() + frame.MarginHeight() * 2 + frame.TopOffset()
1015 + frame.BottomOffset() + separator.Height() + 2 * separator.Margin() +
1016 separator.TopOffset() + separator.BottomOffset() +
1017 f_message_area->Height() + f_message_area->TopOffset() +
1018 f_message_area->BottomOffset() + f_message_area->MarginTop() +
1019 f_message_area->MarginBottom();// + 2 * f_message_area->MarginHeight();
1021 cwidth += frame.MarginWidth() * 2 + frame.LeftOffset() +
1022 frame.RightOffset();
1025 f_shell.Width(cwidth + 4, args);
1026 f_shell.Height(cheight + 4, args);
1033 GraphicAgent::install_new_picture(PixmapGraphic *pgr)
1035 // dispose of the old Pixmap if needed
1036 Pixmap pixmap = f_pixmap_widget->Picture() ;
1037 if (pixmap && (pixmap != f_graphic->pixmap_graphic()->pixmap()))
1038 XFreePixmap(XtDisplay(*f_pixmap_widget), pixmap); // a scaled pixmap...give it back
1041 // put the new Pixmap into the pixmap widget
1043 f_pixmap_widget->Picture(pgr->pixmap(), args) ; // install the new one
1044 f_pixmap_widget->Width(pgr->width(), args); // update size
1045 f_pixmap_widget->Height(pgr->height(), args);
1046 f_pixmap_widget->Set(args);
1048 // update some more UI crud
1051 WXawPorthole porthole(XtParent(*f_pixmap_widget));
1054 WXawPanner panner(*f_panner);
1055 panner.CanvasWidth(pgr->width(), args);
1056 panner.CanvasHeight(pgr->height(),args);
1057 panner.SliderWidth(porthole.Width(), args);
1058 panner.SliderHeight(porthole.Height(), args);
1061 if ((f_panner_state != PANNER_NONE) &&
1062 ((pgr->width() > porthole.Width()) ||
1063 (pgr->height() > porthole.Height())))
1075 if (pgr != f_graphic->pixmap_graphic())
1077 // clean up PixmapGraphic storage, but keep the X Pixmap
1078 // (its in the pixmap_widget)
1079 pgr->set_type(PixmapGraphic::PRESERVE) ;
1085 GraphicAgent::unset_scale_buttons()
1087 for (int i = 0 ; i < 10; i++)
1088 WXmToggleButton((*f_view_menu).Children()[i]).Set(False);