1 /*
2 **
3 ** zoom.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 **
31 */
32 
33 #include "ac_config.h"
34 
35 
36 /*
37 #define MESSAGES
38 */
39 #include "message.h"
40 
41 #include <stdlib.h>
42 
43 #   include <sys/types.h>
44 #   include <sys/stat.h>
45 
46 
47 #include "paths.h"
48 #include INC_X11(Intrinsic.h)
49 #include INC_X11(StringDefs.h)
50 #include INC_X11(Shell.h)
51 #include INC_XAW(Cardinals.h)
52 #include "Aaa.h"
53 #include "Button.h"
54 #include "Clip.h"
55 #include "Frame.h"
56 #include "Ghostview.h"
57 
58 #include "types.h"
59 #include "config.h"
60 #include "callbacks.h"
61 #include "ps.h"
62 #include "doc_misc.h"
63 #include "main_resources.h"
64 #include "main_globals.h"
65 #include "popup.h"
66 #include "widgets_misc.h"
67 #include "zoom.h"
68 
69 static char* zoom_popup      = "zoomPopup";
70 static char* zoom_control    = "zoomControl";
71 static char* zoom_page       = "page";
72 static char* zoom_dismiss    = "dismiss";
73 #if 0
74 static char* zoom_redisplay  = "redisplay";
75 #endif
76 
77 /*##################################################################*/
78 /* zoom_createZoom */
79 /* popup zoom window */
80 /*##################################################################*/
81 
82 void
zoom_createZoom(Widget w _GL_UNUSED,XtPointer call_data)83 zoom_createZoom(Widget w _GL_UNUSED, XtPointer call_data)
84 {
85     Arg args[25];
86     Cardinal n;
87     struct stat sbuf;
88 
89     GhostviewReturnStruct *p = (GhostviewReturnStruct *)call_data;
90     Boolean b;
91     int llx;
92     int lly;
93     int urx;
94     int ury;
95     int bottom_margin;
96     int left_margin;
97     int right_margin;
98     int top_margin;
99     int i;
100     XtPageOrientation xto;
101     Widget zshell,zcontrol,zviewFrame,zviewClip,zviewControl,zpage,zdismiss;
102     FILE *zoomfile;
103     char *filename;
104 
105     BEGINMESSAGE(zoom_createZoom)
106 
107     if (!(gv_psfile != NULL || (gv_gs_arguments && *gv_gs_arguments))) {
108        INFMESSAGE(no file) ENDMESSAGE(zoom_createZoom)
109        return;
110     }
111 
112     if (strcmp(gv_filename, "-")) {
113        stat(gv_filename, &sbuf);
114        if (mtime != sbuf.st_mtime) {
115 	  INFMESSAGE1(file has changed) ENDMESSAGE1(zoom_createZoom)return;
116        }
117     }
118 
119     filename = (gv_filename_dsc ? gv_filename_dsc : (gv_filename_unc ? gv_filename_unc : gv_filename));
120 
121     llx = p->psx;
122     lly = p->psy;
123     urx = p->psx + p->width  - 1; if (urx<llx) urx=llx;
124     ury = p->psy + p->height - 1; if (ury<lly) ury=lly;
125     IIMESSAGE(llx,lly) IIMESSAGE(urx,ury)
126 
127     /* Make sure zoom window doesn't go off the edge of the page */
128     if (llx < current_llx) {	llx = current_llx;	urx = llx + p->width;	}
129     if (lly < current_lly) {	lly = current_lly;	ury = lly + p->height;	}
130     if (urx > current_urx) {	urx = current_urx;	llx = urx - p->width;	}
131     if (ury > current_ury) {	ury = current_ury;	lly = ury - p->height;	}
132     if (llx < current_llx)	llx = current_llx;
133     if (lly < current_lly)	lly = current_lly;
134     bottom_margin = lly - current_lly;
135     left_margin   = llx - current_llx;
136     right_margin  = current_urx - urx;
137     top_margin    = current_ury - ury;
138 
139 							       n=0;
140        XtSetArg(args[n], XtNminWidth,  70);		       n++;
141        XtSetArg(args[n], XtNminHeight, 70);		       n++;
142        XtSetArg(args[n], XtNallowShellResize, True);	       n++;
143     zshell = XtCreatePopupShell(zoom_popup, topLevelShellWidgetClass,toplevel,args,n);
144 
145                                				       n=0;
146        XtSetArg(args[n], XtNminimumWidth, 70);			n++;
147        XtSetArg(args[n], XtNminimumHeight,70);			n++;
148     zcontrol = XtCreateManagedWidget(zoom_control,aaaWidgetClass,zshell,args,n);
149 
150 								n=0;
151    zviewFrame = XtCreateManagedWidget("zviewFrame", frameWidgetClass,zcontrol,args,n);
152 
153 									n=0;
154    zviewClip = XtCreateManagedWidget("zviewClip", clipWidgetClass,zviewFrame,args,n);
155        XtAddCallback(zviewClip, XtNreportCallback,cb_pageAdjustNotify,(XtPointer)NULL);
156 
157 									n=0;
158    zviewControl = XtCreateManagedWidget("zviewControl", aaaWidgetClass,zviewClip,args,n);
159 
160    xto     = doc_convDocOrientToXtOrient(gv_orientation, gv_swap_landscape );
161 
162 							       n=0;
163        XtSetArg(args[n], XtNorientation,xto);                  n++;
164        XtSetArg(args[n], XtNllx, llx);      	               n++;
165        XtSetArg(args[n], XtNlly, lly);      	               n++;
166        XtSetArg(args[n], XtNurx, urx);      	               n++;
167        XtSetArg(args[n], XtNury, ury);      	               n++;
168        XtSetArg(args[n], XtNbottomMargin, bottom_margin);      n++;
169        XtSetArg(args[n], XtNleftMargin, left_margin);          n++;
170        XtSetArg(args[n], XtNrightMargin, right_margin);        n++;
171        XtSetArg(args[n], XtNtopMargin, top_margin);            n++;
172        XtSetArg(args[n], XtNbottomMargin, bottom_margin);      n++;
173        XtSetArg(args[n], XtNlxdpi, (1000*p->xdpi));            n++;
174        XtSetArg(args[n], XtNlydpi, (1000*p->ydpi));            n++;
175        XtSetArg(args[n], XtNinterpreter,gv_gs_interpreter);    n++;
176        b = gv_gs_safeDir ? True : False;
177        XtSetArg(args[n], XtNsafeDir,b);                        n++;
178        b = gv_gs_safer ? True : False;
179        XtSetArg(args[n], XtNsafer,b);                          n++;
180        b = gv_gs_quiet ? True : False;
181        XtSetArg(args[n], XtNquiet,b);                          n++;
182        b = app_res.use_bpixmap ? True : False;
183        XtSetArg(args[n], XtNuseBackingPixmap,b);               n++;
184        XtSetArg(args[n], XtNarguments,gv_gs_arguments);        n++;
185        if (!toc_text) {
186           XtSetArg(args[n], XtNfilename, filename);	       n++;
187        }
188     zpage = XtCreateManagedWidget(zoom_page, ghostviewWidgetClass,zviewControl, args, n);
189     num_ghosts++;
190     XtAddCallback(zpage, XtNcallback, cb_track, (XtPointer)NULL);
191     XtAddCallback(zpage, XtNmessageCallback, cb_message, (XtPointer)zpage);
192     XtAddCallback(zpage, XtNdestroyCallback, cb_destroyGhost,(XtPointer)zpage);
193 
194 							    n=0;
195     zdismiss = XtCreateManagedWidget(zoom_dismiss, buttonWidgetClass,zcontrol, args, n);
196     XtAddCallback(zdismiss, XtNcallback,cb_destroy,(XtPointer)zshell);
197     XtInstallAccelerators(zcontrol, zdismiss);
198 
199     XtRealizeWidget(zshell);
200     {
201        Dimension page_width,page_height;
202        INFMESSAGE(adjusting size)
203                                                                n=0;
204        XtSetArg(args[n], XtNpreferredWidth,  &page_width);     n++;
205        XtSetArg(args[n], XtNpreferredHeight, &page_height);    n++;
206        XtGetValues(zpage, args, n);
207        IIMESSAGE(page_width,page_height)
208                                                                n=0;
209        XtSetArg(args[n], XtNwidth,  page_width);               n++;
210        XtSetArg(args[n], XtNheight, page_height);              n++;
211        XtSetValues(zpage, args, n);
212     }
213     XtInstallAccelerators(zcontrol,zdismiss);
214     widgets_preferButton(zdismiss,1);
215 
216     {
217       GhostviewReturnStruct rs;
218       INFMESSAGE(positioning zoom popup)
219       IIMESSAGE(llx,lly) IIMESSAGE(urx,ury)
220       GhostviewGetAreaOfBB(page,llx,lly,urx,ury,&rs);
221       popup_positionPopup(
222           zshell,page,POPUP_POSITION_POS_CENTER,
223           ((int)(rs.psx)+(int)(rs.width/2)),
224           ((int)(rs.psy)+(int)(rs.height/2))
225       );
226     }
227     GhostviewSetup(zpage);
228 
229     cb_positionPage(zpage,(XtPointer)1,(XtPointer)NULL);
230 
231     XSetWMProtocols(gv_display, XtWindow(zshell), &wm_delete_window, 1);
232     XtPopup(zshell, XtGrabNone);
233 
234     if (toc_text) {
235 	if (!filename) {
236 	    zoomfile = NULL;
237 	} else if (strcmp(filename, "-")) {
238 	    zoomfile = fopen(filename, "r");
239 	} else {
240 	    zoomfile = stdin;
241         }
242 	if (zoomfile == NULL) {
243 	    ENDMESSAGE(zoom_createZoom)
244 	    return;
245 	}
246 
247         GhostviewEnableInterpreter(zpage);
248 
249 	GhostviewSendPS(zpage, zoomfile, doc->beginprolog,
250 			doc->lenprolog, False);
251 	GhostviewSendPS(zpage, zoomfile, doc->beginsetup,
252 			doc->lensetup, False);
253 	if (doc->pageorder == DESCEND)
254 	    i = (doc->numpages - 1) - current_page;
255 	else
256 	    i = current_page;
257 	GhostviewSendPS(zpage, zoomfile, doc->pages[i].begin,
258 			doc->pages[i].len, True);
259     } else GhostviewEnableInterpreter(zpage);
260     ENDMESSAGE(zoom_createZoom)
261 }
262 
263 
264 
265 #if 0
266 							    n=0;
267     zredisplay = XtCreateManagedWidget(zoom_redisplay, buttonWidgetClass,zcontrol, args, n);
268     if (toc_text) {
269        INFMESSAGE(have useful toc)
270        XtAddCallback(zredisplay, XtNcallback, cb_redisplay, (XtPointer)current_page);
271     } else {
272        INFMESSAGE(doc frame does not have useful toc)
273        XtAddCallback(zredisplay, XtNcallback, cb_redisplay, (XtPointer)0);
274     }
275 #endif
276