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 libraries 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),
122 f_pixmap_widget(NULL),
123 f_panner_state (PANNER_NONE),
124 f_current_scale (100),
126 f_message_area(NULL),
127 f_scale_button(NULL),
128 f_custom_scale(NULL),
132 f_graphic->pixmap_graphic()->agent(this);
134 UAS_Common::request ((UAS_Receiver<UAS_LibraryDestroyedMsg> *) this);
137 // /////////////////////////////////////////////////////////////////////////
139 // /////////////////////////////////////////////////////////////////////////
141 GraphicAgent::~GraphicAgent()
143 f_graphic->pixmap_graphic()->agent(NULL);
144 Pixmap pixmap = f_pixmap_widget->Picture();
145 if (pixmap && pixmap != f_graphic->pixmap_graphic()->pixmap())
147 XFreePixmap(XtDisplay(*f_pixmap_widget),
148 pixmap); // a scaled pixmap...give it back
155 // /////////////////////////////////////////////////////////////////////////
157 // /////////////////////////////////////////////////////////////////////////
160 GraphicAgent::popup()
169 // /////////////////////////////////////////////////////////////////////////
171 // /////////////////////////////////////////////////////////////////////////
174 GraphicAgent::display()
179 // assume all graphics are scalable for now.
184 Widget *kids = f_view_menu->Children() ;
185 int num_children = f_view_menu->NumChildren();
186 for (int i = 0 ; i < num_children; i++)
188 WXmPrimitive prim(kids[i]);
189 prim.SetSensitive(True);
197 GraphicAgent::receive(DisplayGraphic &message, void* /*client_data*/)
199 ON_DEBUG(cerr << "GraphicAgent::receive(DisplayGraphic( " <<
200 message.graphic()->locator() << "))" << endl);
202 ON_DEBUG(cerr << "local locator is " <<
203 f_graphic->locator() << endl);
205 if (message.graphic() == f_graphic)
207 ON_DEBUG(cerr << "GraphicAgent::receive(DISPLAY)" << endl);
213 GraphicAgent::receive(ReAttachGraphic &message, void* /*client_data*/)
219 GraphicAgent::receive (UAS_LibraryDestroyedMsg &msg, void* /*client_data*/)
221 if(f_node_ptr->lid() == (msg.fLib)->lid())
223 graphics_mgr().remove_detached((GraphicAgent*)this);
227 // /////////////////////////////////////////////////////////////////////////
229 // /////////////////////////////////////////////////////////////////////////
231 #define AM WAutoManage
233 GraphicAgent::create_ui()
235 XmStringLocalized mtfstring;
238 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "graphic");
239 window_system().register_shell (&f_shell);
241 string = CATGETS(Set_GraphicAgent, 1, "Dtinfo: Detached Graphic");
242 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
244 // just use "delete_response" instead
245 // add a destroy callback to nuke the agent when widget is destroyed.
246 f_shell.SetDestroyCallback (this, (WWL_FUN) &GraphicAgent::ui_destroyed);
248 DECL (WXmForm, form, f_shell, "form" );
249 DECLMC(WXmMenuBar, menu_bar, form, "menu_bar" );
252 // rtp: hard-wire the menu bar's background, since
253 // it comes up a bogus color. Copied from swm's
254 // change in NodeWindowAgentMotif.C
256 Pixel bg = form.Background();
257 menu_bar.Background(bg);
260 DECLM (WXmCascadeButton, file, menu_bar, "file" );
261 DECLMC(WXmPulldownMenu, file_menu, menu_bar, "file_menu" );
262 DECLM (WXmPushButton, attach, file_menu, "attach" );
263 DECLM (WXmPushButton, visit, file_menu, "visit" );
264 DECLM (WXmPushButton, close, file_menu, "close" );
266 XtVaSetValues(file, XmNlabelString,
267 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 1, "File")),
269 *CATGETS(Set_AgentLabel, 2, ""),
272 XtVaSetValues(attach, XmNlabelString,
273 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 167, "Attach")),
275 *CATGETS(Set_AgentLabel, 21, ""),
278 XtVaSetValues(visit, XmNlabelString,
279 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel,168,"Display Section")),
281 *CATGETS(Set_AgentLabel, 119, ""),
284 XtVaSetValues(close, XmNlabelString,
285 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 12, "Close")),
287 *CATGETS(Set_AgentLabel, 13, ""),
290 DECLM (WXmCascadeButton, pan, menu_bar, "panner" );
291 DECLMC(WXmPulldownMenu, panner_menu, menu_bar, "panner_menu" );
292 DECLM (WXmToggleButton, none, panner_menu, "none" );
293 DECLM (WXmToggleButton, up_left, panner_menu, "up_left" );
294 DECLM (WXmToggleButton, up_right, panner_menu, "up_right" );
295 DECLM (WXmToggleButton, low_left, panner_menu, "low_left" );
296 DECLM (WXmToggleButton, low_right, panner_menu, "low_right" );
298 XtVaSetValues(pan, XmNlabelString,
299 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 166, "Panner")),
301 *CATGETS(Set_AgentLabel, 9, ""),
304 XtVaSetValues(none, XmNlabelString,
305 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 178, "None")),
307 *CATGETS(Set_AgentLabel, 7, ""),
310 XtVaSetValues(up_left, XmNlabelString,
311 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 179, "Upper Left")),
313 *CATGETS(Set_AgentLabel, 254, ""),
316 XtVaSetValues(up_right, XmNlabelString,
317 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 180, "Upper Right")),
319 *CATGETS(Set_AgentLabel, 252, ""),
322 XtVaSetValues(low_left, XmNlabelString,
323 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 181, "Lower Left")),
325 *CATGETS(Set_AgentLabel, 113, ""),
328 XtVaSetValues(low_right, XmNlabelString,
329 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 182, "Lower Right")),
331 *CATGETS(Set_AgentLabel, 259, ""),
334 // NOTE: some code in this module depends upon the exact ordering of items
335 // view menu will only be sensitive for scalable graphics
336 DECL (WXmCascadeButton, view, menu_bar, "view" );
337 DECLMC(WXmPulldownMenu, view_menu, menu_bar, "view_menu" );
338 DECLM (WXmPushButton, fit_gr_to_win, view_menu, "fit_window" );
339 DECLM (WXmPushButton, fit_win_to_gr, view_menu, "fit_graphic" );
341 XtVaSetValues(view, XmNlabelString,
342 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 4, "View")),
344 *CATGETS(Set_AgentLabel, 5, ""),
347 XtVaSetValues(fit_gr_to_win, XmNlabelString,
348 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 169, "Fit to Window")),
350 *CATGETS(Set_AgentLabel, 35, ""),
354 XtVaSetValues(fit_win_to_gr, XmNlabelString,
355 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 170, "Fit to Graphic")),
357 *CATGETS(Set_AgentLabel, 37, ""),
360 DECLM (WXmSeparator, separator, view_menu, "separator" );
361 DECLM (WXmToggleButton, z_25, view_menu, "z_25" );
362 DECLM (WXmToggleButton, z_50, view_menu, "z_50" );
363 DECLM (WXmToggleButton, z_100, view_menu, "z_100" );
364 DECLM (WXmToggleButton, z_125, view_menu, "z_125" );
365 DECLM (WXmToggleButton, z_150, view_menu, "z_150" );
366 DECLM (WXmToggleButton, z_200, view_menu, "z_200" );
367 DECLM (WXmToggleButton, z_custom, view_menu, "z_custom" );
369 mtfstring = CATGETS(Set_AgentLabel, 171, "25 %");
370 XtVaSetValues(z_25, XmNlabelString, (XmString)mtfstring, NULL);
371 mtfstring = CATGETS(Set_AgentLabel, 172, "50 %");
372 XtVaSetValues(z_50, XmNlabelString, (XmString)mtfstring, NULL);
373 mtfstring = CATGETS(Set_AgentLabel, 173, "100 %");
374 XtVaSetValues(z_100, XmNlabelString, (XmString)mtfstring, NULL);
375 mtfstring = CATGETS(Set_AgentLabel, 174, "125 %");
376 XtVaSetValues(z_125, XmNlabelString, (XmString)mtfstring, NULL);
377 mtfstring = CATGETS(Set_AgentLabel, 175, "150 %");
378 XtVaSetValues(z_150, XmNlabelString, (XmString)mtfstring, NULL);
379 mtfstring = CATGETS(Set_AgentLabel, 176, "200 %");
380 XtVaSetValues(z_200, XmNlabelString, (XmString)mtfstring, NULL);
382 XtVaSetValues(z_custom, XmNlabelString,
383 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 177, "Custom...")),
385 *CATGETS(Set_AgentLabel, 13, ""),
389 f_scale_button = (WXmToggleButton*)(Widget)z_100 ;
390 f_custom_scale = (WXmToggleButton*)(Widget)z_custom ;
392 f_view_menu = (WXmPulldownMenu*)(Widget)view_menu ;
394 DECLM (WXmCascadeButton, help, menu_bar, "help" );
395 DECLMC(WXmPulldownMenu, help_menu, menu_bar, "help_menu" );
396 DECLM (WXmPushButton, on_window, help_menu, "on_window" );
397 DECLM (WXmPushButton, on_help, help_menu, "on_help" );
399 XtVaSetValues(help, XmNlabelString,
400 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 48, "Help")),
402 *CATGETS(Set_AgentLabel, 39, ""),
405 XtVaSetValues(on_window, XmNlabelString,
406 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 147, "On Window")),
408 *CATGETS(Set_AgentLabel, 35, ""),
411 XtVaSetValues(on_help, XmNlabelString,
412 (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 153, "On Help")),
414 *CATGETS(Set_AgentLabel, 39, ""),
417 DECLM (WXmLabel, message_area, form, "message");
418 f_message_area = (WXmLabel*)(Widget)message_area ;
420 DECLM (WXmSeparator, sep, form, "sep2");
422 DECL (WXmFrame, frame, form, "frame" );
423 DECL (WXmForm, subform, frame, "subform" );
424 DECLM (WXawPanner, panner, subform, "panner" );
425 DECLM (WXawPorthole, porthole, subform, "porthole" );
426 DECLM (WPixmap, pixmap, porthole, "pixmap" );
429 f_panner = (WXawPanner*)(Widget)panner ;
430 f_pixmap_widget = (WPixmap*)(Widget)pixmap ;
432 file.SubMenuId (file_menu);
433 view.SubMenuId (view_menu);
434 pan.SubMenuId (panner_menu);
435 help.SubMenuId (help_menu);
436 menu_bar.MenuHelpWidget (help);
440 PixmapGraphic &pgraphic = *(f_graphic->pixmap_graphic());
442 Graphic *graphic = f_graphic ;
443 UAS_String buffer = CATGETS(Set_GraphicAgent, 8, "Dtinfo: ");
444 UAS_String titleStr(graphic->title());
445 const char *title = titleStr ;
447 if (title == NULL || *title == '\0') // empty string
448 title = (char *)CATGETS(Set_GraphicAgent, 2, "Detached Graphic");
449 buffer = buffer + title;
451 f_shell.Title((char*)buffer);
452 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 (unsigned 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();
642 ON_DEBUG (printf ("Graphic jumping to <%s>\n", glocator));
643 ON_DEBUG (printf (" copying to %p\n", g_top_locator));
644 len = MIN(strlen(&glocator[8]), 4096 - 1);
645 *((char *) memcpy(g_top_locator, &glocator[8], len) + len) = '\0';
646 g_scroll_to_locator = TRUE;
647 f_node_ptr->retrieve();
652 GraphicAgent::porthole_report(WCallback *wcb)
654 XawPannerReport *repp = (XawPannerReport*)wcb->CallData();
655 XawPannerReport &rep = *repp;
656 ON_DEBUG(cerr << "got a porthole_report" << hex << rep.changed << endl);
657 if (rep.changed & (XawPRCanvasHeight | XawPRCanvasWidth)){
658 ON_DEBUG(cerr << "porthole height or width change" << endl);
660 WXawPorthole porthole(wcb->GetWidget());
661 WXawPanner panner((Widget)wcb->ClientData());
663 WCore picture(porthole.Children()[0]);
665 Dimension port_width = porthole.Width();
666 Dimension port_height = porthole.Height();
667 Dimension cwidth = panner.CanvasWidth();
668 Dimension cheight= panner.CanvasHeight();
670 ON_DEBUG(cerr << "Canvas ( " << cwidth << ", " << cheight << ")"<<endl);
671 ON_DEBUG(cerr << "Porthle( " << port_width << ", " << port_height << ")"
676 // re-adjust the slider
677 if (rep.changed & XawPRCanvasHeight)
679 ON_DEBUG(cerr << "adjust panner SliderHeight " << port_height <<
681 panner.SliderHeight(port_height, args);
684 if (rep.changed & XawPRCanvasWidth)
686 ON_DEBUG(cerr << "adjust panner SliderWidth " << port_width <<
688 panner.SliderWidth(port_width, args);
694 if ((cwidth <= port_width) &&
695 (cheight <= port_height))
697 ON_DEBUG(cerr << "PANNER UNmanage" << endl);
700 if (f_panner_state != PANNER_NONE)
708 GraphicAgent::panner_report(WCallback *wcb)
710 ON_DEBUG(cerr << "panner report " << endl);
711 XawPannerReport *repp = (XawPannerReport*)wcb->CallData();
712 XawPannerReport &rep = *repp;
717 WCore core((Widget)wcb->ClientData());
718 core.X(0 - rep.slider_x, args);
719 core.Y(0 - rep.slider_y, args);
725 GraphicAgent::adjust_panner(unsigned int state)
727 ON_DEBUG(cerr << "adjust_panner( " << state << ")" << endl);
728 if (state == f_panner_state)
731 f_panner_state = state ;
735 WXawPanner &panner(*f_panner) ;
738 case PANNER_UPPER_LEFT:
741 panner.LeftAttachment(XmATTACH_FORM, args);
742 panner.TopAttachment(XmATTACH_FORM, args);
743 panner.RightAttachment(XmATTACH_POSITION, args);
744 panner.RightPosition(20, args);
745 panner.BottomAttachment(XmATTACH_POSITION, args);
746 panner.BottomPosition(20, args);
749 case PANNER_UPPER_RIGHT:
752 panner.RightAttachment(XmATTACH_FORM, args);
753 panner.TopAttachment(XmATTACH_FORM, args);
754 panner.LeftAttachment(XmATTACH_POSITION, args);
755 panner.LeftPosition(80, args);
756 panner.BottomAttachment(XmATTACH_POSITION, args);
757 panner.BottomPosition(20, args);
760 case PANNER_LOWER_RIGHT:
763 panner.RightAttachment(XmATTACH_FORM, args);
764 panner.BottomAttachment(XmATTACH_FORM, args);
765 panner.LeftAttachment(XmATTACH_POSITION, args);
766 panner.LeftPosition(80, args);
767 panner.TopAttachment(XmATTACH_POSITION, args);
768 panner.TopPosition(80, args);
771 case PANNER_LOWER_LEFT:
774 panner.LeftAttachment(XmATTACH_FORM, args);
775 panner.BottomAttachment(XmATTACH_FORM, args);
776 panner.RightAttachment(XmATTACH_POSITION, args);
777 panner.RightPosition(20, args);
778 panner.TopAttachment(XmATTACH_POSITION, args);
779 panner.TopPosition(80, args);
795 // see if we can display it
797 Dimension cwidth = panner.CanvasWidth();
798 Dimension cheight = panner.CanvasHeight();
800 WXawPorthole porthole(XtParent(*f_panner)) ;
802 ON_DEBUG(cerr << "Panner - state: " << state << " canvas ( " << cwidth
803 << ", " << cheight << ") porthole ( " << porthole.Width() <<
804 ", " << porthole.Height() << ")" << endl);
806 if ((state != PANNER_NONE) &&
807 ((cwidth > porthole.Width()) ||
808 (cheight > porthole.Height())))
816 GraphicAgent::set_panner(WCallback *wcb)
818 // adjust panner to the Set state
819 WXmToggleButton button(wcb->GetWidget());
822 size_t state = (size_t)wcb->ClientData();
823 adjust_panner(state);
829 GraphicAgent::zoom_callback(WCallback *wcb)
831 ON_DEBUG (puts ("GraphicAgent::zoom_callback() called"));
832 WXmToggleButton button(wcb->GetWidget());
834 XmToggleButtonCallbackStruct &cbs =
835 *(XmToggleButtonCallbackStruct*)wcb->CallData();
838 ON_DEBUG(cerr << "cbs.set = " << cbs.set << endl);
839 ON_DEBUG(cerr << "cbs.rsn = " << cbs.reason << endl);
840 ON_DEBUG(cerr << "cbs.event = " << cbs.event << endl);
844 size_t scale = (size_t) wcb->ClientData();
848 f_scale_button = (WXmToggleButton*)(Widget)button ;
853 // we get called twice when selecting already selected custom button
854 // just do nothing second time around
862 UAS_String msg = CATGETS(Set_GraphicAgent, 6,
863 "Enter the new scaling percentage:");
864 UAS_String title = CATGETS(Set_GraphicAgent, 7, "Dtinfo: Set Scale");
865 scale = message_mgr().
866 get_integer((char*)msg, (char*)title, f_current_scale,
869 ON_DEBUG(cerr << "scale value is " << scale << endl);
870 if ((int)scale == -1)
872 // unset Custom option in list
873 if (((Widget)*f_scale_button) != ((Widget)button))
876 f_scale_button->Set(1);
882 f_scale_button = (WXmToggleButton*)(Widget)button ;
884 // maybe this should be a user option
885 //fit_window_to_graphic();
891 GraphicAgent::set_zoom(unsigned int scale)
893 // Deal with bogus values.
896 else if (scale > 999)
899 if (scale == f_current_scale)
904 XmStringLocalized mtfstring = CATGETS(Set_GraphicAgent, 5,
905 "Scaling illustration, please wait...");
907 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
909 XmUpdateDisplay((Widget)f_message_area);
911 f_current_scale = scale;
913 UAS_String f_graphic_content_type(f_graphic->content_type());
914 UAS_String temp_str = f_graphic->data();
917 f_graphic->pixmap_graphic(temp_str, f_graphic->data_length(),
918 f_graphic_content_type, scale);
919 install_new_picture(pgr);
922 if (f_graphic->content_type() == "application/CGM")
923 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
925 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
927 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
933 GraphicAgent::refresh(const UAS_Pointer<Graphic> &)
935 // refresh by clearing window and sending in expose event
936 XClearArea(XtDisplay(*f_pixmap_widget),
937 XtWindow(*f_pixmap_widget),
940 // update message area
941 XmStringLocalized mtfstring;
942 if (f_graphic->content_type() == "application/CGM")
943 mtfstring = CATGETS(Set_GraphicAgent, 4, "Vector illustration (scalable)");
945 mtfstring = CATGETS(Set_GraphicAgent, 9, "Raster illustration (scalable)");
947 XtVaSetValues((Widget)f_message_area, XmNlabelString, (XmString)mtfstring, NULL);
952 GraphicAgent::fit_graphic_to_window_callback(WCallback *)
958 unsigned int scale_factor;
962 // get size of graphic
963 gr_width = f_graphic->pixmap_graphic()->width();
964 gr_height = f_graphic->pixmap_graphic()->height();
966 WXawPorthole porthole(XtParent(*f_pixmap_widget));
968 dx = abs(porthole.Width() - f_graphic->pixmap_graphic()->width());
969 dy = abs(porthole.Height() - f_graphic->pixmap_graphic()->height());
972 (100 * porthole.Width()) / f_graphic->pixmap_graphic()->width();
975 (100 * porthole.Height()) / f_graphic->pixmap_graphic()->height();
979 wscale = (100 * porthole.Width()) / gr_width;
980 hscale = (100 * porthole.Height()) / gr_height;
982 // scaling from dimensions of original pixmap graphic
988 // fit graphic to window means custom scale, so
989 // toggle the button.
990 f_scale_button->Set(0);
991 f_scale_button = f_custom_scale;
992 f_scale_button->Set(1);
998 GraphicAgent::fit_window_to_graphic_callback(WCallback *)
1000 fit_window_to_graphic();
1003 GraphicAgent::fit_window_to_graphic()
1005 WXawPorthole porthole(XtParent(*f_pixmap_widget));
1006 WPixmap picture(*f_pixmap_widget) ;
1007 WXawPanner panner(*f_panner);
1009 // desired width of porthole is in panner.Canvas{Width,Height}
1010 Dimension cwidth = panner.CanvasWidth();
1011 Dimension cheight = panner.CanvasHeight() ;
1013 // menu_bar is first child of form which is first child of f_shell
1014 WComposite form(f_shell.Children()[0]);
1015 WComposite menu_bar(form.Children()[0]) ;
1016 // f_message_area is Children()[1]
1017 WXmSeparator separator(form.Children()[2]);
1019 // account for frame margins
1020 // frame is parent of subform is parent of panner
1021 WXmFrame frame(XtParent(XtParent(panner)));
1023 cheight += menu_bar.Height() + frame.MarginHeight() * 2 + frame.TopOffset()
1024 + frame.BottomOffset() + separator.Height() + 2 * separator.Margin() +
1025 separator.TopOffset() + separator.BottomOffset() +
1026 f_message_area->Height() + f_message_area->TopOffset() +
1027 f_message_area->BottomOffset() + f_message_area->MarginTop() +
1028 f_message_area->MarginBottom();// + 2 * f_message_area->MarginHeight();
1030 cwidth += frame.MarginWidth() * 2 + frame.LeftOffset() +
1031 frame.RightOffset();
1034 f_shell.Width(cwidth + 4, args);
1035 f_shell.Height(cheight + 4, args);
1042 GraphicAgent::install_new_picture(PixmapGraphic *pgr)
1044 // dispose of the old Pixmap if needed
1045 Pixmap pixmap = f_pixmap_widget->Picture() ;
1046 if (pixmap && (pixmap != f_graphic->pixmap_graphic()->pixmap()))
1047 XFreePixmap(XtDisplay(*f_pixmap_widget), pixmap); // a scaled pixmap...give it back
1050 // put the new Pixmap into the pixmap widget
1052 f_pixmap_widget->Picture(pgr->pixmap(), args) ; // install the new one
1053 f_pixmap_widget->Width(pgr->width(), args); // update size
1054 f_pixmap_widget->Height(pgr->height(), args);
1055 f_pixmap_widget->Set(args);
1057 // update some more UI crud
1060 WXawPorthole porthole(XtParent(*f_pixmap_widget));
1063 WXawPanner panner(*f_panner);
1064 panner.CanvasWidth(pgr->width(), args);
1065 panner.CanvasHeight(pgr->height(),args);
1066 panner.SliderWidth(porthole.Width(), args);
1067 panner.SliderHeight(porthole.Height(), args);
1070 if ((f_panner_state != PANNER_NONE) &&
1071 ((pgr->width() > porthole.Width()) ||
1072 (pgr->height() > porthole.Height())))
1084 if (pgr != f_graphic->pixmap_graphic())
1086 // clean up PixmapGraphic storage, but keep the X Pixmap
1087 // (its in the pixmap_widget)
1088 pgr->set_type(PixmapGraphic::PRESERVE) ;
1094 GraphicAgent::unset_scale_buttons()
1096 for (int i = 0 ; i < 10; i++)
1097 WXmToggleButton((*f_view_menu).Children()[i]).Set(False);