[0060ba5] | 1 | // |
---|
[203d2a7] | 2 | // aven.cc |
---|
[0060ba5] | 3 | // |
---|
[5809313] | 4 | // Main class for Aven. |
---|
[0060ba5] | 5 | // |
---|
[3675a18] | 6 | // Copyright (C) 2001 Mark R. Shinwell. |
---|
[668b930] | 7 | // Copyright (C) 2002,2003,2004,2005,2006,2011,2013,2014,2015,2016,2017,2018 Olly Betts |
---|
[0060ba5] | 8 | // |
---|
[89231c4] | 9 | // This program is free software; you can redistribute it and/or modify |
---|
| 10 | // it under the terms of the GNU General Public License as published by |
---|
| 11 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | // (at your option) any later version. |
---|
[0060ba5] | 13 | // |
---|
| 14 | // This program is distributed in the hope that it will be useful, |
---|
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[89231c4] | 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | // GNU General Public License for more details. |
---|
[0060ba5] | 18 | // |
---|
[89231c4] | 19 | // You should have received a copy of the GNU General Public License |
---|
| 20 | // along with this program; if not, write to the Free Software |
---|
[ecbc6c18] | 21 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[5809313] | 22 | // |
---|
[0060ba5] | 23 | |
---|
[b462168] | 24 | #include <config.h> |
---|
| 25 | |
---|
[9990aab] | 26 | #define MSG_SETUP_PROJ_SEARCH_PATH 1 |
---|
| 27 | |
---|
[5809313] | 28 | #include "aven.h" |
---|
[78924eb] | 29 | #include "log.h" |
---|
[caa5fda] | 30 | #include "gla.h" |
---|
[5809313] | 31 | #include "mainfrm.h" |
---|
[706b033] | 32 | |
---|
[d07944e] | 33 | #include "cmdline.h" |
---|
[93c3f97] | 34 | #include "message.h" |
---|
[c49e27f] | 35 | #include "useful.h" |
---|
[0060ba5] | 36 | |
---|
| 37 | #include <assert.h> |
---|
[c49e27f] | 38 | #include <stdio.h> |
---|
[0060ba5] | 39 | |
---|
[e0ffc2c] | 40 | #include <wx/confbase.h> |
---|
[573f4e9] | 41 | #include <wx/image.h> |
---|
[e0ffc2c] | 42 | #if wxUSE_DISPLAY |
---|
| 43 | // wxDisplay was added in wx 2.5; but it may not be built for mingw (because |
---|
| 44 | // the header seems to be missing). |
---|
[ca18348] | 45 | #include <wx/display.h> |
---|
| 46 | #endif |
---|
[573f4e9] | 47 | |
---|
[faf83be] | 48 | #ifdef __WXMSW__ |
---|
| 49 | #include <windows.h> |
---|
| 50 | #endif |
---|
| 51 | |
---|
[879e9c3] | 52 | static const struct option long_opts[] = { |
---|
| 53 | /* const char *name; int has_arg (0 no_argument, 1 required_*, 2 optional_*); int *flag; int val; */ |
---|
| 54 | {"survey", required_argument, 0, 's'}, |
---|
| 55 | {"print", no_argument, 0, 'p'}, |
---|
| 56 | {"help", no_argument, 0, HLP_HELP}, |
---|
| 57 | {"version", no_argument, 0, HLP_VERSION}, |
---|
| 58 | {0, 0, 0, 0} |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | #define short_opts "s:p" |
---|
| 62 | |
---|
| 63 | static struct help_msg help[] = { |
---|
[45af761] | 64 | /* <-- */ |
---|
[736f7df] | 65 | /* TRANSLATORS: --help output for --survey option. |
---|
| 66 | * |
---|
| 67 | * "this" has been added to English translation */ |
---|
[45af761] | 68 | {HLP_ENCODELONG(0), /*only load the sub-survey with this prefix*/199, 0}, |
---|
[736f7df] | 69 | /* TRANSLATORS: --help output for aven --print option */ |
---|
[45af761] | 70 | {HLP_ENCODELONG(1), /*print and exit (requires a 3d file)*/119, 0}, |
---|
| 71 | {0, 0, 0} |
---|
[879e9c3] | 72 | }; |
---|
| 73 | |
---|
[5627cbb] | 74 | #ifdef __WXMSW__ |
---|
[5809313] | 75 | IMPLEMENT_APP(Aven) |
---|
[5627cbb] | 76 | #else |
---|
| 77 | IMPLEMENT_APP_NO_MAIN(Aven) |
---|
| 78 | IMPLEMENT_WX_THEME_SUPPORT |
---|
| 79 | #endif |
---|
[0060ba5] | 80 | |
---|
[5809313] | 81 | Aven::Aven() : |
---|
[2c1d2f4] | 82 | m_Frame(NULL), m_pageSetupData(NULL) |
---|
[0060ba5] | 83 | { |
---|
[1f81f3d] | 84 | wxFont::SetDefaultEncoding(wxFONTENCODING_UTF8); |
---|
[0060ba5] | 85 | } |
---|
| 86 | |
---|
[2c1d2f4] | 87 | Aven::~Aven() |
---|
| 88 | { |
---|
[81f1266] | 89 | delete m_pageSetupData; |
---|
[2c1d2f4] | 90 | } |
---|
| 91 | |
---|
[5627cbb] | 92 | static int getopt_first_response = 0; |
---|
| 93 | |
---|
[5440c295] | 94 | static char ** utf8_argv; |
---|
| 95 | |
---|
[5627cbb] | 96 | #ifdef __WXMSW__ |
---|
| 97 | bool Aven::Initialize(int& my_argc, wxChar **my_argv) |
---|
| 98 | { |
---|
[faf83be] | 99 | const wxChar * cmd_line = GetCommandLineW(); |
---|
| 100 | |
---|
[b208d0b] | 101 | // Horrible bodge to handle therion's assumptions about the "Process" |
---|
| 102 | // file association. |
---|
[faf83be] | 103 | if (cmd_line) { |
---|
| 104 | // None of these are valid aven command line options, so this is not |
---|
| 105 | // going to be triggered accidentally. |
---|
[ccaf632] | 106 | const wxChar * p = wxStrstr(cmd_line, |
---|
| 107 | wxT("aven.exe\" --quiet --log --output=")); |
---|
[faf83be] | 108 | if (p) { |
---|
| 109 | // Just change the command name in the command line string - that |
---|
| 110 | // way the quoting should match what the C runtime expects. |
---|
| 111 | wxString cmd(cmd_line, p - cmd_line); |
---|
| 112 | cmd += "cavern"; |
---|
| 113 | cmd += p + 4; |
---|
| 114 | exit(wxExecute(cmd, wxEXEC_SYNC)); |
---|
| 115 | } |
---|
[b208d0b] | 116 | } |
---|
| 117 | |
---|
[faf83be] | 118 | int utf8_argc; |
---|
| 119 | { |
---|
| 120 | // wxWidgets doesn't split up the command line in the standard way, so |
---|
| 121 | // redo it ourselves using the standard API function. |
---|
| 122 | // |
---|
| 123 | // Warning: The returned array from this has no terminating NULL |
---|
| 124 | // element. |
---|
| 125 | wxChar ** new_argv = NULL; |
---|
| 126 | if (cmd_line) |
---|
| 127 | new_argv = CommandLineToArgvW(cmd_line, &utf8_argc); |
---|
| 128 | bool failed = (new_argv == NULL); |
---|
| 129 | if (failed) { |
---|
| 130 | wxChar * p; |
---|
| 131 | FormatMessage( |
---|
| 132 | FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, |
---|
| 133 | NULL, |
---|
| 134 | GetLastError(), |
---|
| 135 | 0, |
---|
| 136 | (LPWSTR)&p, |
---|
| 137 | 4096, |
---|
| 138 | NULL); |
---|
| 139 | wxString m = "CommandLineToArgvW failed: "; |
---|
| 140 | m += p; |
---|
| 141 | wxMessageBox(m, APP_NAME, wxOK | wxCENTRE | wxICON_EXCLAMATION); |
---|
| 142 | LocalFree(p); |
---|
| 143 | utf8_argc = my_argc; |
---|
| 144 | new_argv = my_argv; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | // Convert wide characters to UTF-8. |
---|
| 148 | utf8_argv = new char * [utf8_argc + 1]; |
---|
| 149 | for (int i = 0; i < utf8_argc; ++i){ |
---|
[8562abc] | 150 | utf8_argv[i] = strdup(wxString(new_argv[i]).utf8_str()); |
---|
[faf83be] | 151 | } |
---|
| 152 | utf8_argv[utf8_argc] = NULL; |
---|
| 153 | |
---|
| 154 | if (!failed) LocalFree(new_argv); |
---|
[5627cbb] | 155 | } |
---|
| 156 | |
---|
[5440c295] | 157 | msg_init(utf8_argv); |
---|
[f1cbf74] | 158 | select_charset(CHARSET_UTF8); |
---|
[293eec8] | 159 | /* Want --version and decent --help output, which cmdline does for us. |
---|
[f1cbf74] | 160 | * wxCmdLine is much less good. |
---|
| 161 | */ |
---|
[736f7df] | 162 | /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions |
---|
| 163 | * - it should be translated to the terminology that cavers using the |
---|
| 164 | * language would use. |
---|
[b49ac56] | 165 | * |
---|
[736f7df] | 166 | * Part of aven --help */ |
---|
[d8dbdff] | 167 | cmdline_set_syntax_message(/*[SURVEY_FILE]*/269, 0, NULL); |
---|
[faf83be] | 168 | cmdline_init(utf8_argc, utf8_argv, short_opts, long_opts, NULL, help, 0, 1); |
---|
[5627cbb] | 169 | getopt_first_response = cmdline_getopt(); |
---|
[faf83be] | 170 | |
---|
| 171 | // The argc and argv arguments don't actually get used here. |
---|
| 172 | int dummy_argc = 0; |
---|
| 173 | return wxApp::Initialize(dummy_argc, NULL); |
---|
[f1cbf74] | 174 | } |
---|
[5627cbb] | 175 | #else |
---|
[b49ac56] | 176 | int main(int argc, char **argv) |
---|
[0060ba5] | 177 | { |
---|
[96c239c] | 178 | #ifdef __WXGTK3__ |
---|
[47f55ed] | 179 | # if !(wxUSE_GLCANVAS_EGL-0) |
---|
| 180 | // The GLX-based wxGLCanvas doesn't work under Wayland, and the code |
---|
| 181 | // segfaults: https://trac.wxwidgets.org/ticket/17702 |
---|
| 182 | // |
---|
| 183 | // Therefore we force X11 unless we're using the EGL-based wxGLCanvas |
---|
| 184 | // (which was added in wxWidgets 3.1.5 and hasn't been backported to |
---|
| 185 | // 3.0.x). |
---|
| 186 | // |
---|
[96c239c] | 187 | // Setting GDK_BACKEND=x11 is the recommended workaround, and it seems to |
---|
[b0908ea] | 188 | // work to set it here. GTK2 doesn't support Wayland, so doesn't need |
---|
| 189 | // this. |
---|
[96c239c] | 190 | setenv("GDK_BACKEND", "x11", 1); |
---|
[47f55ed] | 191 | # endif |
---|
[96c239c] | 192 | #endif |
---|
[705adee9] | 193 | |
---|
[27b8b59] | 194 | #ifdef __WXMAC__ |
---|
[879e9c3] | 195 | // MacOS passes a magic -psn_XXXX command line argument in argv[1] which |
---|
| 196 | // wx ignores for us, but in wxApp::Initialize() which hasn't been |
---|
| 197 | // called yet. So we need to remove it ourselves. |
---|
[5627cbb] | 198 | if (argc > 1 && strncmp(argv[1], "-psn_", 5) == 0) { |
---|
| 199 | --argc; |
---|
| 200 | memmove(argv + 1, argv + 2, argc * sizeof(char *)); |
---|
[879e9c3] | 201 | } |
---|
| 202 | #endif |
---|
| 203 | // Call msg_init() and start processing the command line first so that |
---|
| 204 | // we can respond to --help and --version even without an X display. |
---|
[5627cbb] | 205 | msg_init(argv); |
---|
| 206 | select_charset(CHARSET_UTF8); |
---|
[293eec8] | 207 | /* Want --version and decent --help output, which cmdline does for us. |
---|
[5627cbb] | 208 | * wxCmdLine is much less good. |
---|
| 209 | */ |
---|
[d8dbdff] | 210 | cmdline_set_syntax_message(/*[SURVEY_FILE]*/269, 0, NULL); |
---|
[5627cbb] | 211 | cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 0, 1); |
---|
[879e9c3] | 212 | getopt_first_response = cmdline_getopt(); |
---|
[5627cbb] | 213 | |
---|
[5440c295] | 214 | utf8_argv = argv; |
---|
[5627cbb] | 215 | |
---|
[f891a0c] | 216 | #if wxUSE_UNICODE |
---|
[5627cbb] | 217 | wxWCharBuffer buf(wxConvFileName->cMB2WX(argv[0])); |
---|
| 218 | wxChar * wargv[2]; |
---|
| 219 | if (buf) { |
---|
| 220 | wargv[0] = wxStrdup(buf); |
---|
| 221 | } else { |
---|
| 222 | // Eep - couldn't convert the executable's name to wide characters! |
---|
| 223 | wargv[0] = wxStrdup(APP_NAME); |
---|
| 224 | } |
---|
| 225 | wargv[1] = NULL; |
---|
| 226 | int wargc = 1; |
---|
| 227 | return wxEntry(wargc, wargv); |
---|
[495cd3e] | 228 | #else |
---|
[a212391] | 229 | char *dummy_argv[2] = { argv[0], NULL }; |
---|
| 230 | int dummy_argc = 1; |
---|
| 231 | return wxEntry(dummy_argc, dummy_argv); |
---|
[495cd3e] | 232 | #endif |
---|
[879e9c3] | 233 | } |
---|
[5627cbb] | 234 | #endif |
---|
[879e9c3] | 235 | |
---|
| 236 | bool Aven::OnInit() |
---|
| 237 | { |
---|
[4013d9c] | 238 | wxLog::SetActiveTarget(new MyLogWindow()); |
---|
[421b7d2] | 239 | |
---|
[d607cea] | 240 | { |
---|
[b1876d3] | 241 | // Suppress message box warnings about messages not found. |
---|
[71ea9e1] | 242 | wxLogNull logNo; |
---|
| 243 | wxLocale *loc = new wxLocale(); |
---|
[8a05a7a] | 244 | loc->AddCatalogLookupPathPrefix(wmsg_cfgpth()); |
---|
[b1876d3] | 245 | wxString msg_lang_str(msg_lang, wxConvUTF8); |
---|
| 246 | const char *lang = msg_lang2 ? msg_lang2 : msg_lang; |
---|
| 247 | wxString lang_str(lang, wxConvUTF8); |
---|
[f1d5d26] | 248 | loc->Init(msg_lang_str, lang_str, msg_lang_str); |
---|
[71ea9e1] | 249 | // The existence of the wxLocale object is enough - no need to keep a |
---|
| 250 | // pointer to it! |
---|
[003d953] | 251 | } |
---|
[93c3f97] | 252 | |
---|
[668b930] | 253 | const char* opt_survey = NULL; |
---|
[3ee64fb] | 254 | bool print_and_exit = false; |
---|
[421b7d2] | 255 | |
---|
[0580c6a] | 256 | while (true) { |
---|
[879e9c3] | 257 | int opt; |
---|
| 258 | if (getopt_first_response) { |
---|
| 259 | opt = getopt_first_response; |
---|
| 260 | getopt_first_response = 0; |
---|
| 261 | } else { |
---|
| 262 | opt = cmdline_getopt(); |
---|
| 263 | } |
---|
[d07944e] | 264 | if (opt == EOF) break; |
---|
| 265 | if (opt == 's') { |
---|
[668b930] | 266 | if (opt_survey != NULL) { |
---|
| 267 | // FIXME: Not a helpful error, but this is temporary until |
---|
| 268 | // we actually hook up support for specifying multiple |
---|
| 269 | // --survey options properly here. |
---|
| 270 | cmdline_syntax(); |
---|
| 271 | exit(1); |
---|
| 272 | } |
---|
| 273 | opt_survey = optarg; |
---|
[d07944e] | 274 | } |
---|
[3ee64fb] | 275 | if (opt == 'p') { |
---|
| 276 | print_and_exit = true; |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | |
---|
[5440c295] | 280 | if (print_and_exit && !utf8_argv[optind]) { |
---|
[3ee64fb] | 281 | cmdline_syntax(); // FIXME : not a helpful error... |
---|
| 282 | exit(1); |
---|
[d07944e] | 283 | } |
---|
[068b4f2] | 284 | |
---|
[5627cbb] | 285 | wxString fnm; |
---|
[5440c295] | 286 | if (utf8_argv[optind]) { |
---|
| 287 | fnm = wxString(utf8_argv[optind], wxConvUTF8); |
---|
| 288 | if (fnm.empty() && *(utf8_argv[optind])) { |
---|
[c49e27f] | 289 | ReportError(wxT("File argument's filename has bad encoding")); |
---|
[5627cbb] | 290 | return false; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | |
---|
[caa5fda] | 294 | if (!GLACanvas::check_visual()) { |
---|
| 295 | wxString m; |
---|
| 296 | /* TRANSLATORS: %s will be replaced with "Aven" currently (and |
---|
| 297 | * perhaps by "Survex" or other things in future). */ |
---|
| 298 | m.Printf(wmsg(/*This version of %s requires OpenGL to work, but it isn’t available.*/405), APP_NAME); |
---|
| 299 | wxMessageBox(m, APP_NAME, wxOK | wxCENTRE | wxICON_EXCLAMATION); |
---|
| 300 | exit(1); |
---|
[5892e08] | 301 | } |
---|
| 302 | |
---|
[573f4e9] | 303 | wxImage::AddHandler(new wxPNGHandler); |
---|
[08d2074] | 304 | |
---|
[4909e6bc] | 305 | // Obtain the screen geometry. |
---|
| 306 | #if wxUSE_DISPLAY |
---|
| 307 | wxRect geom = wxDisplay().GetGeometry(); |
---|
| 308 | #else |
---|
| 309 | wxRect geom; |
---|
| 310 | wxClientDisplayRect(&geom.x, &geom.y, &geom.width, &geom.height); |
---|
| 311 | #endif |
---|
| 312 | |
---|
[3db0798] | 313 | wxPoint pos(wxDefaultPosition); |
---|
[ca18348] | 314 | int width, height; |
---|
[5627cbb] | 315 | wxConfigBase::Get()->Read(wxT("width"), &width, 0); |
---|
| 316 | if (width > 0) wxConfigBase::Get()->Read(wxT("height"), &height, 0); |
---|
[30621f5] | 317 | // We used to persist full screen mode (-1 was maximized, |
---|
| 318 | // -2 full screen), but people would get stuck in full |
---|
| 319 | // screen mode, unsure how to exit. |
---|
| 320 | bool maximized = (width <= -1); |
---|
[3db0798] | 321 | if (width <= 0 || height <= 0) { |
---|
| 322 | pos.x = geom.x; |
---|
| 323 | pos.y = geom.y; |
---|
| 324 | width = geom.width; |
---|
| 325 | height = geom.height; |
---|
[486ae6a] | 326 | |
---|
[3db0798] | 327 | // Calculate a reasonable size for our window. |
---|
| 328 | pos.x += width / 8; |
---|
| 329 | pos.y += height / 8; |
---|
| 330 | width = width * 3 / 4; |
---|
| 331 | height = height * 3 / 4; |
---|
[4909e6bc] | 332 | } else { |
---|
| 333 | // Impose a minimum size for sanity, and make sure the window fits on |
---|
| 334 | // the display (in case the current display is smaller than the one |
---|
| 335 | // in use when the window size was saved). (480x320) is about the |
---|
| 336 | // smallest usable size for aven's window. |
---|
| 337 | const int min_width = min(geom.width, 480); |
---|
| 338 | const int min_height = min(geom.height, 320); |
---|
| 339 | if (width < min_width || height < min_height) { |
---|
| 340 | if (width < min_width) { |
---|
| 341 | width = min_width; |
---|
| 342 | } |
---|
| 343 | if (height < min_height) { |
---|
| 344 | height = min_height; |
---|
| 345 | } |
---|
| 346 | pos.x = geom.x + (geom.width - width) / 4; |
---|
| 347 | pos.y = geom.y + (geom.height - height) / 4; |
---|
| 348 | } |
---|
[3db0798] | 349 | } |
---|
[486ae6a] | 350 | |
---|
| 351 | // Create the main window. |
---|
[3db0798] | 352 | m_Frame = new MainFrm(APP_NAME, pos, wxSize(width, height)); |
---|
| 353 | |
---|
[30621f5] | 354 | // Select maximised if that's the saved state. |
---|
| 355 | if (maximized) { |
---|
[3db0798] | 356 | m_Frame->Maximize(); |
---|
| 357 | } |
---|
[068b4f2] | 358 | |
---|
[5440c295] | 359 | if (utf8_argv[optind]) { |
---|
[668b930] | 360 | if (!opt_survey) opt_survey = ""; |
---|
| 361 | m_Frame->OpenFile(fnm, wxString(opt_survey, wxConvUTF8)); |
---|
[d07944e] | 362 | } |
---|
[068b4f2] | 363 | |
---|
[3ee64fb] | 364 | if (print_and_exit) { |
---|
[4ed8154] | 365 | m_Frame->PrintAndExit(); |
---|
[3ee64fb] | 366 | return true; |
---|
| 367 | } |
---|
| 368 | |
---|
[5809313] | 369 | m_Frame->Show(true); |
---|
[526775d] | 370 | #ifdef _WIN32 |
---|
| 371 | m_Frame->SetFocus(); |
---|
| 372 | #endif |
---|
[0060ba5] | 373 | return true; |
---|
| 374 | } |
---|
| 375 | |
---|
[e0ffc2c] | 376 | wxPageSetupDialogData * |
---|
| 377 | Aven::GetPageSetupDialogData() |
---|
| 378 | { |
---|
[2c1d2f4] | 379 | if (!m_pageSetupData) m_pageSetupData = new wxPageSetupDialogData; |
---|
[e0ffc2c] | 380 | #ifdef __WXGTK__ |
---|
| 381 | // Fetch paper margins stored on disk. |
---|
| 382 | int left, right, top, bottom; |
---|
| 383 | wxConfigBase * cfg = wxConfigBase::Get(); |
---|
| 384 | // These default margins were chosen by looking at all the .ppd files |
---|
| 385 | // on my machine. |
---|
[5627cbb] | 386 | cfg->Read(wxT("paper_margin_left"), &left, 7); |
---|
| 387 | cfg->Read(wxT("paper_margin_right"), &right, 7); |
---|
| 388 | cfg->Read(wxT("paper_margin_top"), &top, 14); |
---|
| 389 | cfg->Read(wxT("paper_margin_bottom"), &bottom, 14); |
---|
[2c1d2f4] | 390 | m_pageSetupData->SetMarginTopLeft(wxPoint(left, top)); |
---|
| 391 | m_pageSetupData->SetMarginBottomRight(wxPoint(right, bottom)); |
---|
[e0ffc2c] | 392 | #endif |
---|
[2c1d2f4] | 393 | return m_pageSetupData; |
---|
[e0ffc2c] | 394 | } |
---|
| 395 | |
---|
| 396 | void |
---|
| 397 | Aven::SetPageSetupDialogData(const wxPageSetupDialogData & psdd) |
---|
| 398 | { |
---|
[2c1d2f4] | 399 | if (!m_pageSetupData) m_pageSetupData = new wxPageSetupDialogData; |
---|
| 400 | *m_pageSetupData = psdd; |
---|
[e0ffc2c] | 401 | #ifdef __WXGTK__ |
---|
| 402 | wxPoint topleft = psdd.GetMarginTopLeft(); |
---|
| 403 | wxPoint bottomright = psdd.GetMarginBottomRight(); |
---|
| 404 | |
---|
| 405 | // Store user specified paper margins on disk/in registry. |
---|
| 406 | wxConfigBase * cfg = wxConfigBase::Get(); |
---|
[5627cbb] | 407 | cfg->Write(wxT("paper_margin_left"), topleft.x); |
---|
| 408 | cfg->Write(wxT("paper_margin_right"), bottomright.x); |
---|
| 409 | cfg->Write(wxT("paper_margin_top"), topleft.y); |
---|
| 410 | cfg->Write(wxT("paper_margin_bottom"), bottomright.y); |
---|
[e0ffc2c] | 411 | cfg->Flush(); |
---|
| 412 | #endif |
---|
| 413 | } |
---|
| 414 | |
---|
[ddc0994] | 415 | #ifdef __WXMAC__ |
---|
| 416 | void |
---|
| 417 | Aven::MacOpenFiles(const wxArrayString & filenames) |
---|
| 418 | { |
---|
| 419 | if (filenames.size() != 1) { |
---|
| 420 | ReportError(wxT("Aven can only load one file at a time")); |
---|
| 421 | return; |
---|
| 422 | } |
---|
| 423 | m_Frame->OpenFile(filenames[0], wxString()); |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | void |
---|
| 427 | Aven::MacPrintFiles(const wxArrayString & filenames) |
---|
| 428 | { |
---|
| 429 | if (filenames.size() != 1) { |
---|
| 430 | ReportError(wxT("Aven can only print one file at a time")); |
---|
| 431 | return; |
---|
| 432 | } |
---|
| 433 | m_Frame->OpenFile(filenames[0], wxString()); |
---|
| 434 | m_Frame->PrintAndExit(); |
---|
| 435 | } |
---|
| 436 | #endif |
---|
| 437 | |
---|
[5809313] | 438 | void Aven::ReportError(const wxString& msg) |
---|
[0060ba5] | 439 | { |
---|
[c8b5fa5] | 440 | if (!m_Frame) { |
---|
| 441 | wxMessageBox(msg, APP_NAME, wxOK | wxICON_ERROR); |
---|
| 442 | return; |
---|
| 443 | } |
---|
[7015222] | 444 | wxMessageDialog dlg(m_Frame, msg, APP_NAME, wxOK | wxICON_ERROR); |
---|
| 445 | dlg.ShowModal(); |
---|
[0060ba5] | 446 | } |
---|
[59fda0a] | 447 | |
---|
[8a05a7a] | 448 | const wxString & |
---|
| 449 | wmsg_cfgpth() |
---|
| 450 | { |
---|
| 451 | static wxString path; |
---|
| 452 | if (path.empty()) |
---|
| 453 | path = wxString(msg_cfgpth(), wxConvUTF8); |
---|
| 454 | return path; |
---|
| 455 | } |
---|
| 456 | |
---|
[a9a32f2] | 457 | // called to report errors by message.c |
---|
| 458 | extern "C" void |
---|
| 459 | aven_v_report(int severity, const char *fnm, int line, int en, va_list ap) |
---|
| 460 | { |
---|
[c49e27f] | 461 | wxString m; |
---|
| 462 | if (fnm) { |
---|
| 463 | m = wxString(fnm, wxConvUTF8); |
---|
| 464 | if (line) m += wxString::Format(wxT(":%d"), line); |
---|
| 465 | m += wxT(": "); |
---|
| 466 | } |
---|
| 467 | |
---|
[37d6b84] | 468 | if (severity == DIAG_WARN) { |
---|
[c49e27f] | 469 | m += wmsg(/*warning*/4); |
---|
| 470 | m += wxT(": "); |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | char buf[1024]; |
---|
[9b5f251] | 474 | vsnprintf(buf, sizeof(buf), msg(en), ap); |
---|
[c49e27f] | 475 | m += wxString(buf, wxConvUTF8); |
---|
| 476 | if (wxTheApp == NULL) { |
---|
| 477 | // We haven't initialised the Aven app object yet. |
---|
| 478 | if (!wxInitialize()) { |
---|
| 479 | fputs(buf, stderr); |
---|
| 480 | PUTC('\n', stderr); |
---|
| 481 | exit(1); |
---|
| 482 | } |
---|
| 483 | wxMessageBox(m, APP_NAME, wxOK | wxICON_ERROR); |
---|
| 484 | wxUninitialize(); |
---|
| 485 | } else { |
---|
| 486 | wxGetApp().ReportError(m); |
---|
| 487 | } |
---|
[a9a32f2] | 488 | } |
---|