1 /* AbiSource Application Framework
2  * Copyright (C) 1998 AbiSource, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA.
18  */
19 
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 
24 #include "ut_assert.h"
25 #include "ut_string.h"
26 #include "ut_debugmsg.h"
27 
28 #include "xap_Dlg_Zoom.h"
29 #include "xap_Preview_Zoom.h"
30 #include "xap_Dialog_Id.h"
31 #include "xap_DialogFactory.h"
32 #include "xap_Dlg_MessageBox.h"
33 
34 #include "xav_View.h"
35 
XAP_Dialog_Zoom(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)36 XAP_Dialog_Zoom::XAP_Dialog_Zoom(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
37 	: XAP_Dialog_NonPersistent(pDlgFactory,id, "interface/dialogzoom")
38 {
39 	m_answer = a_OK;
40 
41 	// this should really never appear, since setZoomPercent()
42 	// should always be called before the dialog is shown
43 	m_zoomPercent = 100;
44 
45 	m_zoomPreview = NULL;
46 	m_pFrame = 0 ;
47 }
48 
~XAP_Dialog_Zoom(void)49 XAP_Dialog_Zoom::~XAP_Dialog_Zoom(void)
50 {
51 	DELETEP(m_zoomPreview);
52 }
53 
getAnswer(void) const54 XAP_Dialog_Zoom::tAnswer XAP_Dialog_Zoom::getAnswer(void) const
55 {
56 	// let our caller know if user hit ok, cancel, etc.
57 	return m_answer;
58 }
59 
setZoomPercent(UT_uint32 zoom)60 void XAP_Dialog_Zoom::setZoomPercent(UT_uint32 zoom)
61 {
62 	// store the percentage within limits clipping if necessary
63 	if      (zoom < XAP_DLG_ZOOM_MINIMUM_ZOOM) m_zoomPercent = XAP_DLG_ZOOM_MINIMUM_ZOOM;
64 	else if (zoom > XAP_DLG_ZOOM_MAXIMUM_ZOOM) m_zoomPercent = XAP_DLG_ZOOM_MAXIMUM_ZOOM;
65 	else                                       m_zoomPercent = zoom;
66 }
67 
getZoomType(void)68 XAP_Frame::tZoomType XAP_Dialog_Zoom::getZoomType(void)
69 {
70 	return m_zoomType;
71 }
72 
getZoomPercent(void)73 UT_uint32 XAP_Dialog_Zoom::getZoomPercent(void)
74 {
75 
76 	// we deliver based on special cases first, then the custom percentage
77 	switch(m_zoomType)
78 	{
79 	case XAP_Frame::z_200:
80 		return 200;
81 	case XAP_Frame::z_100:
82 		return 100;
83 	case XAP_Frame::z_75:
84 		return 75;
85 	case XAP_Frame::z_PAGEWIDTH:
86 	  if ( m_pFrame )
87 	    return m_pFrame->getCurrentView ()->calculateZoomPercentForPageWidth () ;
88 	case XAP_Frame::z_WHOLEPAGE:
89 	  if ( m_pFrame )
90 	    return m_pFrame->getCurrentView ()->calculateZoomPercentForWholePage () ;
91 	case XAP_Frame::z_PERCENT:
92 		// fall through
93 	default:
94 		if (m_zoomPercent > XAP_DLG_ZOOM_MINIMUM_ZOOM)
95 			return m_zoomPercent;
96 		else
97 			return XAP_DLG_ZOOM_MINIMUM_ZOOM;
98 	}
99 
100 	// fallback
101 	return 100 ;
102 }
103 
104 /************************************************************************/
105 
_updatePreviewZoomPercent(UT_uint32 percent)106 void XAP_Dialog_Zoom::_updatePreviewZoomPercent(UT_uint32 percent)
107 {
108 	if (m_zoomPreview)
109 	{
110 		m_zoomPreview->setZoomPercent(percent);
111 		m_zoomPreview->draw();
112 	}
113 	if (m_pFrame)
114 		m_pFrame->quickZoom(percent);
115 }
116 
_createPreviewFromGC(GR_Graphics * gc,UT_uint32 width,UT_uint32 height)117 void XAP_Dialog_Zoom::_createPreviewFromGC(GR_Graphics * gc,
118 										   UT_uint32 width,
119 										   UT_uint32 height)
120 {
121 	UT_ASSERT(gc);
122 
123 	m_zoomPreview = new XAP_Preview_Zoom(gc);
124 	UT_ASSERT(m_zoomPreview);
125 
126 	m_zoomPreview->setWindowSize(width, height);
127 	m_zoomPreview->setString("10-pt Times New Roman");
128 	m_zoomPreview->setFont(XAP_Preview_Zoom::font_NORMAL);
129 	m_zoomPreview->setZoomPercent(m_zoomPercent);
130 
131 }
132