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