| 1 |
/* AbiSource Application Framework |
| 2 |
* Copyright (C) 1998-2000 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 |
|
| 22 |
#include "ut_string.h" |
| 23 |
#include "ut_assert.h" |
| 24 |
#include "ut_debugmsg.h" |
| 25 |
|
| 26 |
#include "xav_View.h" |
| 27 |
|
| 28 |
// This header defines some functions for Unix dialogs, |
| 29 |
// like centering them, measuring them, etc. |
| 30 |
#include "xap_UnixDialogHelper.h" |
| 31 |
|
| 32 |
#include "xap_App.h" |
| 33 |
#include "xap_UnixApp.h" |
| 34 |
#include "xap_Frame.h" |
| 35 |
#include "xap_Dialog_Id.h" |
| 36 |
#include "xap_Dlg_Zoom.h" |
| 37 |
#include "xap_Preview_Zoom.h" |
| 38 |
#include "xap_UnixDlg_Zoom.h" |
| 39 |
|
| 40 |
/*****************************************************************/ |
| 41 |
|
| 42 |
#define WIDGET_ID_TAG_KEY "id" |
| 43 |
|
| 44 |
/*****************************************************************/ |
| 45 |
|
| 46 |
XAP_Dialog * XAP_UnixDialog_Zoom::static_constructor(XAP_DialogFactory * pFactory, |
| 47 |
XAP_Dialog_Id id) |
| 48 |
{ |
| 49 |
return new XAP_UnixDialog_Zoom(pFactory,id); |
| 50 |
} |
| 51 |
|
| 52 |
XAP_UnixDialog_Zoom::XAP_UnixDialog_Zoom(XAP_DialogFactory * pDlgFactory, |
| 53 |
XAP_Dialog_Id id) |
| 54 |
: XAP_Dialog_Zoom(pDlgFactory,id) |
| 55 |
{ |
| 56 |
m_windowMain = NULL; |
| 57 |
|
| 58 |
m_radio200 = NULL; |
| 59 |
m_radio100 = NULL; |
| 60 |
m_radio75 = NULL; |
| 61 |
m_radioPageWidth = NULL; |
| 62 |
m_radioWholePage = NULL; |
| 63 |
m_radioPercent = NULL; |
| 64 |
|
| 65 |
m_spinPercent = NULL; |
| 66 |
|
| 67 |
m_radioGroup = NULL; |
| 68 |
} |
| 69 |
|
| 70 |
XAP_UnixDialog_Zoom::~XAP_UnixDialog_Zoom(void) |
| 71 |
{ |
| 72 |
} |
| 73 |
|
| 74 |
/*****************************************************************/ |
| 75 |
|
| 76 |
void XAP_UnixDialog_Zoom::s_radio_200_clicked(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 77 |
{ |
| 78 |
UT_return_if_fail(widget && dlg); |
| 79 |
dlg->event_Radio200Clicked(); |
| 80 |
} |
| 81 |
|
| 82 |
void XAP_UnixDialog_Zoom::s_radio_100_clicked(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 83 |
{ |
| 84 |
UT_return_if_fail(widget && dlg); |
| 85 |
dlg->event_Radio100Clicked(); |
| 86 |
} |
| 87 |
void XAP_UnixDialog_Zoom::s_radio_75_clicked(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 88 |
{ |
| 89 |
UT_return_if_fail(widget && dlg); |
| 90 |
dlg->event_Radio75Clicked(); |
| 91 |
} |
| 92 |
|
| 93 |
void XAP_UnixDialog_Zoom::s_radio_PageWidth_clicked(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 94 |
{ |
| 95 |
UT_return_if_fail(widget && dlg); |
| 96 |
dlg->event_RadioPageWidthClicked(); |
| 97 |
} |
| 98 |
|
| 99 |
void XAP_UnixDialog_Zoom::s_radio_WholePage_clicked(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 100 |
{ |
| 101 |
UT_return_if_fail(widget && dlg); |
| 102 |
dlg->event_RadioWholePageClicked(); |
| 103 |
} |
| 104 |
|
| 105 |
void XAP_UnixDialog_Zoom::s_radio_Percent_clicked(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 106 |
{ |
| 107 |
UT_return_if_fail(widget && dlg); |
| 108 |
dlg->event_RadioPercentClicked(); |
| 109 |
} |
| 110 |
|
| 111 |
void XAP_UnixDialog_Zoom::s_spin_Percent_changed(GtkWidget * widget, XAP_UnixDialog_Zoom * dlg) |
| 112 |
{ |
| 113 |
UT_return_if_fail(widget && dlg); |
| 114 |
dlg->event_SpinPercentChanged(); |
| 115 |
} |
| 116 |
|
| 117 |
/*****************************************************************/ |
| 118 |
|
| 119 |
void XAP_UnixDialog_Zoom::runModal(XAP_Frame * pFrame) |
| 120 |
{ |
| 121 |
m_pFrame = pFrame ; |
| 122 |
|
| 123 |
// Build the window's widgets and arrange them |
| 124 |
m_windowMain = _constructWindow(); |
| 125 |
UT_return_if_fail(m_windowMain); |
| 126 |
|
| 127 |
// Populate the window's data items |
| 128 |
_populateWindowData(); |
| 129 |
|
| 130 |
// attach a new graphics context to the drawing area |
| 131 |
// XAP_UnixApp * unixapp = static_cast<XAP_UnixApp *> (m_pApp); |
| 132 |
//UT_ASSERT(unixapp); |
| 133 |
|
| 134 |
// HACK : we call this TWICE so it generates an update on the buttons to |
| 135 |
// HACK : trigger a preview |
| 136 |
_populateWindowData(); |
| 137 |
|
| 138 |
switch ( abiRunModalDialog ( GTK_DIALOG(m_windowMain), pFrame, this, GTK_RESPONSE_CANCEL, false ) ) |
| 139 |
{ |
| 140 |
case GTK_RESPONSE_OK: |
| 141 |
m_answer = XAP_Dialog_Zoom::a_OK; |
| 142 |
break; |
| 143 |
default: |
| 144 |
m_answer = XAP_Dialog_Zoom::a_CANCEL; |
| 145 |
break; |
| 146 |
} |
| 147 |
|
| 148 |
_storeWindowData(); |
| 149 |
|
| 150 |
abiDestroyWidget (m_windowMain) ; |
| 151 |
} |
| 152 |
|
| 153 |
void XAP_UnixDialog_Zoom::event_Radio200Clicked(void) |
| 154 |
{ |
| 155 |
_enablePercentSpin(false); |
| 156 |
_updatePreviewZoomPercent(200); |
| 157 |
} |
| 158 |
|
| 159 |
void XAP_UnixDialog_Zoom::event_Radio100Clicked(void) |
| 160 |
{ |
| 161 |
_enablePercentSpin(false); |
| 162 |
_updatePreviewZoomPercent(100); |
| 163 |
} |
| 164 |
|
| 165 |
void XAP_UnixDialog_Zoom::event_Radio75Clicked(void) |
| 166 |
{ |
| 167 |
_enablePercentSpin(false); |
| 168 |
_updatePreviewZoomPercent(75); |
| 169 |
} |
| 170 |
|
| 171 |
void XAP_UnixDialog_Zoom::event_RadioPageWidthClicked(void) |
| 172 |
{ |
| 173 |
_enablePercentSpin(false); |
| 174 |
if ( m_pFrame ) |
| 175 |
_updatePreviewZoomPercent(m_pFrame->getCurrentView ()->calculateZoomPercentForPageWidth ()); |
| 176 |
} |
| 177 |
|
| 178 |
void XAP_UnixDialog_Zoom::event_RadioWholePageClicked(void) |
| 179 |
{ |
| 180 |
_enablePercentSpin(false); |
| 181 |
if ( m_pFrame ) |
| 182 |
_updatePreviewZoomPercent(m_pFrame->getCurrentView ()->calculateZoomPercentForWholePage ()); |
| 183 |
} |
| 184 |
|
| 185 |
void XAP_UnixDialog_Zoom::event_RadioPercentClicked(void) |
| 186 |
{ |
| 187 |
_enablePercentSpin(true); |
| 188 |
// call event_SpinPercentChanged() to do the fetch and update work |
| 189 |
event_SpinPercentChanged(); |
| 190 |
} |
| 191 |
|
| 192 |
void XAP_UnixDialog_Zoom::event_SpinPercentChanged(void) |
| 193 |
{ |
| 194 |
_updatePreviewZoomPercent(static_cast<UT_uint32>(gtk_spin_button_get_value_as_int( |
| 195 |
GTK_SPIN_BUTTON(m_spinPercent)))); |
| 196 |
} |
| 197 |
|
| 198 |
/*****************************************************************/ |
| 199 |
|
| 200 |
GtkWidget * XAP_UnixDialog_Zoom::_constructWindow(void) |
| 201 |
{ |
| 202 |
GtkWidget * window; |
| 203 |
const XAP_StringSet * pSS = m_pApp->getStringSet(); |
| 204 |
|
| 205 |
// load the dialog from the UI file |
| 206 |
#if GTK_CHECK_VERSION(3,0,0) |
| 207 |
GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_Zoom.ui"); |
| 208 |
#else |
| 209 |
GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_Zoom-2.ui"); |
| 210 |
#endif |
| 211 |
|
| 212 |
// Update our member variables with the important widgets that |
| 213 |
// might need to be queried or altered later |
| 214 |
window = GTK_WIDGET(gtk_builder_get_object(builder, "xap_UnixDlg_Zoom")); |
| 215 |
m_radioGroup = gtk_radio_button_get_group (GTK_RADIO_BUTTON ( GTK_WIDGET(gtk_builder_get_object(builder, "rbPercent200")) )); |
| 216 |
m_radio200 = GTK_WIDGET(gtk_builder_get_object(builder, "rbPercent200")); |
| 217 |
m_radio100 = GTK_WIDGET(gtk_builder_get_object(builder, "rbPercent100")); |
| 218 |
m_radio75 = GTK_WIDGET(gtk_builder_get_object(builder, "rbPercent75")); |
| 219 |
m_radioPageWidth = GTK_WIDGET(gtk_builder_get_object(builder, "rbPageWidth")); |
| 220 |
m_radioWholePage = GTK_WIDGET(gtk_builder_get_object(builder, "rbWholePage")); |
| 221 |
m_radioPercent = GTK_WIDGET(gtk_builder_get_object(builder, "rbPercent")); |
| 222 |
m_spinPercent = GTK_WIDGET(gtk_builder_get_object(builder, "sbPercent")); |
| 223 |
m_spinAdj = gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(m_spinPercent) ); |
| 224 |
|
| 225 |
// set the dialog title |
| 226 |
std::string s; |
| 227 |
pSS->getValueUTF8(XAP_STRING_ID_DLG_Zoom_ZoomTitle,s); |
| 228 |
abiDialogSetTitle(window, "%s", s.c_str()); |
| 229 |
|
| 230 |
// localize the strings in our dialog, and set tags for some widgets |
| 231 |
|
| 232 |
localizeLabelMarkup(GTK_WIDGET(gtk_builder_get_object(builder, "lbZoom")), pSS, XAP_STRING_ID_DLG_Zoom_RadioFrameCaption); |
| 233 |
|
| 234 |
localizeButton(m_radio200, pSS, XAP_STRING_ID_DLG_Zoom_200); |
| 235 |
g_object_set_data (G_OBJECT (m_radio200), WIDGET_ID_TAG_KEY, GINT_TO_POINTER(XAP_Frame::z_200)); |
| 236 |
|
| 237 |
localizeButton(m_radio100, pSS, XAP_STRING_ID_DLG_Zoom_100); |
| 238 |
g_object_set_data (G_OBJECT (m_radio100), WIDGET_ID_TAG_KEY, GINT_TO_POINTER(XAP_Frame::z_100)); |
| 239 |
|
| 240 |
localizeButton(m_radio75, pSS, XAP_STRING_ID_DLG_Zoom_75); |
| 241 |
g_object_set_data (G_OBJECT (m_radio75), WIDGET_ID_TAG_KEY, GINT_TO_POINTER(XAP_Frame::z_75)); |
| 242 |
|
| 243 |
localizeButton(m_radioPageWidth, pSS, XAP_STRING_ID_DLG_Zoom_PageWidth); |
| 244 |
g_object_set_data (G_OBJECT (m_radioPageWidth), WIDGET_ID_TAG_KEY, GINT_TO_POINTER(XAP_Frame::z_PAGEWIDTH)); |
| 245 |
|
| 246 |
localizeButton(m_radioWholePage, pSS, XAP_STRING_ID_DLG_Zoom_WholePage); |
| 247 |
g_object_set_data (G_OBJECT (m_radioWholePage), WIDGET_ID_TAG_KEY, GINT_TO_POINTER(XAP_Frame::z_WHOLEPAGE)); |
| 248 |
|
| 249 |
localizeButton(m_radioPercent, pSS, XAP_STRING_ID_DLG_Zoom_Percent); |
| 250 |
g_object_set_data (G_OBJECT (m_radioPercent), WIDGET_ID_TAG_KEY, GINT_TO_POINTER(XAP_Frame::z_PERCENT)); |
| 251 |
|
| 252 |
// Connect clicked signals so that our callbacks get called. |
| 253 |
g_signal_connect(G_OBJECT(m_radio200), "clicked", G_CALLBACK(s_radio_200_clicked), static_cast<gpointer>(this)); |
| 254 |
g_signal_connect(G_OBJECT(m_radio100), "clicked", G_CALLBACK(s_radio_100_clicked), static_cast<gpointer>(this)); |
| 255 |
g_signal_connect(G_OBJECT(m_radio75), "clicked", G_CALLBACK(s_radio_75_clicked), static_cast<gpointer>(this)); |
| 256 |
g_signal_connect(G_OBJECT(m_radioPageWidth), "clicked", G_CALLBACK(s_radio_PageWidth_clicked), static_cast<gpointer>(this)); |
| 257 |
g_signal_connect(G_OBJECT(m_radioWholePage), "clicked", G_CALLBACK(s_radio_WholePage_clicked), static_cast<gpointer>(this)); |
| 258 |
g_signal_connect(G_OBJECT(m_radioPercent), "clicked", G_CALLBACK(s_radio_Percent_clicked), static_cast<gpointer>(this)); |
| 259 |
|
| 260 |
// the zoom spin button |
| 261 |
g_signal_connect(G_OBJECT(m_spinAdj), "value_changed", G_CALLBACK(s_spin_Percent_changed), static_cast<gpointer>(this)); |
| 262 |
|
| 263 |
g_object_unref(G_OBJECT(builder)); |
| 264 |
|
| 265 |
return window; |
| 266 |
} |
| 267 |
|
| 268 |
void XAP_UnixDialog_Zoom::_populateWindowData(void) |
| 269 |
{ |
| 270 |
// The callbacks for these radio buttons aren't always |
| 271 |
// called when the dialog is being constructed, so we have to |
| 272 |
// set the widget's value, then manually enable/disable |
| 273 |
// the spin button. |
| 274 |
|
| 275 |
// enable the right button |
| 276 |
_enablePercentSpin(false); // default |
| 277 |
switch(getZoomType()) |
| 278 |
{ |
| 279 |
case XAP_Frame::z_200: |
| 280 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radio200), TRUE); |
| 281 |
_updatePreviewZoomPercent(200); |
| 282 |
break; |
| 283 |
case XAP_Frame::z_100: |
| 284 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radio100), TRUE); |
| 285 |
_updatePreviewZoomPercent(100); |
| 286 |
break; |
| 287 |
case XAP_Frame::z_75: |
| 288 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radio75), TRUE); |
| 289 |
_updatePreviewZoomPercent(75); |
| 290 |
break; |
| 291 |
case XAP_Frame::z_PAGEWIDTH: |
| 292 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radioPageWidth), TRUE); |
| 293 |
break; |
| 294 |
case XAP_Frame::z_WHOLEPAGE: |
| 295 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radioWholePage), TRUE); |
| 296 |
break; |
| 297 |
case XAP_Frame::z_PERCENT: |
| 298 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radioPercent), TRUE); |
| 299 |
_enablePercentSpin(true); // override |
| 300 |
_updatePreviewZoomPercent(getZoomPercent()); |
| 301 |
break; |
| 302 |
default: |
| 303 |
// if they haven't set anything yet, default to the 100% radio item |
| 304 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_radio100), TRUE); |
| 305 |
} |
| 306 |
|
| 307 |
gtk_spin_button_set_value(GTK_SPIN_BUTTON(m_spinPercent), static_cast<gfloat>(getZoomPercent())); |
| 308 |
} |
| 309 |
|
| 310 |
void XAP_UnixDialog_Zoom::_storeWindowData(void) |
| 311 |
{ |
| 312 |
for (GSList * item = m_radioGroup; item ; item = item->next) |
| 313 |
{ |
| 314 |
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(item->data))) |
| 315 |
{ |
| 316 |
m_zoomType = (XAP_Frame::tZoomType) |
| 317 |
GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item->data), WIDGET_ID_TAG_KEY)); |
| 318 |
break; |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
// store away percentage; the base class decides if it's important when |
| 323 |
// the caller requests the percent |
| 324 |
m_zoomPercent = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(m_spinPercent)); |
| 325 |
} |
| 326 |
|
| 327 |
void XAP_UnixDialog_Zoom::_enablePercentSpin(bool enable) |
| 328 |
{ |
| 329 |
UT_ASSERT(m_spinPercent); |
| 330 |
|
| 331 |
gtk_widget_set_sensitive(m_spinPercent, enable); |
| 332 |
} |