source: git/src/aboutdlg.cc @ 0edddb4

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 0edddb4 was 0edddb4, checked in by Olly Betts <olly@…>, 9 years ago

src/aboutdlg.cc,src/aboutdlg.h: Make the button to dismiss the
"About" dialog "OK" rather than "Close", which seems more logical,
and also allows the dialog to be closed by pressing "Escape".

  • Property mode set to 100644
File size: 6.7 KB
Line 
1//
2//  aboutdlg.cc
3//
4//  About box handling for Aven.
5//
6//  Copyright (C) 2001-2003 Mark R. Shinwell.
7//  Copyright (C) 2001,2002,2003,2004,2005,2006,2010,2014,2015 Olly Betts
8//
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.
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
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18//
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
21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22//
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include "aboutdlg.h"
29#include "aven.h"
30#include "gla.h"
31#include "message.h"
32
33#include <wx/clipbrd.h>
34#include <wx/confbase.h>
35#include <wx/image.h>
36
37BEGIN_EVENT_TABLE(AboutDlg, wxDialog)
38    EVT_TIMER(about_TIMER, AboutDlg::OnTimer)
39    EVT_BUTTON(wxID_COPY, AboutDlg::OnCopy)
40END_EVENT_TABLE()
41
42void
43AboutDlg::OnTimer(wxTimerEvent &)
44{
45    wxImage::AddHandler(new wxJPEGHandler);
46    bitmap.LoadFile(img_path + wxT("osterei.jpg"), wxBITMAP_TYPE_JPEG);
47    ((wxStaticBitmap*)FindWindowById(501, this))->SetBitmap(bitmap);
48}
49
50void
51AboutDlg::OnCopy(wxCommandEvent &)
52{
53    if (wxTheClipboard->Open()) {
54        wxTheClipboard->SetData(new wxTextDataObject(info));
55        wxTheClipboard->Close();
56        // (Try to) make the selection persist after aven exits.
57        (void)wxTheClipboard->Flush();
58    }
59}
60
61AboutDlg::AboutDlg(wxWindow* parent, const wxIcon & app_icon) :
62    /* TRANSLATORS: for the title of the About box */
63    wxDialog(parent, 500, wxString::Format(wmsg(/*About %s*/205), APP_NAME)),
64    timer(this, about_TIMER)
65{
66    img_path = wxString(wmsg_cfgpth());
67    img_path += wxCONFIG_PATH_SEPARATOR;
68    img_path += wxT("images");
69    img_path += wxCONFIG_PATH_SEPARATOR;
70
71    wxBoxSizer* horiz = new wxBoxSizer(wxHORIZONTAL);
72    wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL);
73
74    if (!bitmap.Ok()) {
75        bitmap.LoadFile(img_path + APP_ABOUT_IMAGE, wxBITMAP_TYPE_PNG);
76    }
77    if (bitmap.Ok()) {
78        wxStaticBitmap* static_bitmap = new wxStaticBitmap(this, 501, bitmap);
79        horiz->Add(static_bitmap, 0 /* horizontally unstretchable */, wxALL,
80                   2 /* border width */);
81    }
82    horiz->Add(vert, 0, wxALL, 2);
83
84    wxString id(APP_NAME wxT(" "VERSION"\n"));
85    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
86     * - it should be translated to the terminology that cavers using the
87     * language would use.
88     *
89     * This string is used in the about box (summarising the purpose of aven).
90     */
91    id += wmsg(/*Survey visualisation tool*/209);
92    wxBoxSizer* title = new wxBoxSizer(wxHORIZONTAL);
93    wxStaticBitmap* static_bitmap = new wxStaticBitmap(this, 599, wxBitmap());
94    static_bitmap->SetIcon(app_icon);
95    title->Add(static_bitmap, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 8);
96    title->Add(new wxStaticText(this, 502, id), 0, wxALL, 2);
97
98    wxStaticText* copyright = new wxStaticText(this, 503,
99                                        wxT(COPYRIGHT_MSG_UTF8"\n"AVEN_COPYRIGHT_MSG_UTF8));
100
101    wxString licence_str;
102    /* TRANSLATORS: Summary paragraph for the GPLv2 - there are translations for
103     * some languages here:
104     * http://www.gnu.org/licenses/old-licenses/gpl-2.0-translations.html */
105    wxString l(wmsg(/*This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at your option) any later version.*/219));
106    wxClientDC dc(this);
107    dc.SetFont(this->GetFont());
108    do {
109        unsigned int a = 72;
110        if (a >= l.length()) {
111            a = l.length();
112        } else {
113            while (a > 1 && l[a] != ' ') --a;
114        }
115
116        while (a > 1) {
117            wxCoord w, h;
118            dc.GetTextExtent(l.substr(0, a), &w, &h);
119            if (w <= 380) break;
120            do { --a; } while (a > 1 && l[a] != ' ');
121        }
122
123        if (!licence_str.empty()) licence_str += '\n';
124        licence_str += l.substr(0, a);
125        if (a < l.length() && l[a] == ' ') ++a;
126        l.erase(0, a);
127    } while (!l.empty());
128
129    wxStaticText* licence = new wxStaticText(this, 504, licence_str);
130
131    vert->Add(10, 5, 0, wxTOP, 5);
132    vert->Add(title, 0, wxLEFT | wxRIGHT, 20);
133    vert->Add(10, 5, 0, wxTOP, 5);
134
135    vert->Add(copyright, 0, wxLEFT | wxRIGHT, 20);
136    vert->Add(10, 5, 0, wxTOP, 5);
137
138    vert->Add(licence, 0, wxLEFT | wxRIGHT, 20);
139    vert->Add(10, 5, 0, wxTOP, 5);
140
141    // TRANSLATORS: for about box:
142    vert->Add(new wxStaticText(this, 505, wmsg(/*System Information:*/390)),
143              0, wxLEFT | wxRIGHT, 20);
144
145    info = wxGetOsDescription();
146#if wxCHECK_VERSION(2,9,2)
147    info += wxT("\n");
148    wxString version = wxGetLibraryVersionInfo().GetVersionString();
149    info += version;
150    if (version != wxVERSION_STRING)
151        info += wxT(" (built with ") wxVERSION_STRING wxT(")");
152    info +=
153#else
154    info += wxT("\nBuilt with ") wxVERSION_STRING
155#endif
156#ifdef __WXGTK__
157# if defined __WXGTK26__
158        wxT(" (GTK+ >= 2.6)\n");
159# elif defined __WXGTK24__
160        wxT(" (GTK+ >= 2.4)\n");
161# elif defined __WXGTK20__
162        wxT(" (GTK+ >= 2.0)\n");
163# elif defined __WXGTK12__
164        wxT(" (GTK+ >= 1.2)\n");
165# else
166        wxT(" (GTK+ < 1.2)\n");
167# endif
168#elif defined __WXMOTIF__
169# if defined __WXMOTIF20__
170        wxT(" (Motif >= 2.0)\n");
171# else
172        wxT(" (Motif < 2.0)\n");
173# endif
174#elif defined __WXX11__
175        wxT(" (X11)\n");
176#else
177        wxT("\n");
178#endif
179    int bpp = wxDisplayDepth();
180    /* TRANSLATORS: bpp is "Bits Per Pixel" */
181    info += wxString::Format(wmsg(/*Display Depth: %d bpp*/196), bpp);
182    /* TRANSLATORS: appended to previous message if the display is colour */
183    if (wxColourDisplay()) info += wmsg(/* (colour)*/197);
184    info += wxT('\n');
185    info += wxString(GetGLSystemDescription().c_str(), wxConvUTF8);
186
187    // Use a readonly multiline text edit for the system info so users can
188    // easily cut and paste it into an email when reporting bugs.
189    vert->Add(new wxTextCtrl(this, 506, info, wxDefaultPosition,
190                             wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY),
191              1, wxLEFT | wxRIGHT | wxEXPAND, 20);
192
193    vert->Add(10, 5, 0, wxALIGN_BOTTOM | wxTOP, 5);
194
195    wxBoxSizer* bottom = new wxBoxSizer(wxHORIZONTAL);
196    bottom->Add(5, 5, 1);
197    bottom->Add(new wxButton(this, wxID_COPY), 0, wxRIGHT | wxBOTTOM, 6);
198    wxButton* close = new wxButton(this, wxID_OK);
199    bottom->Add(close, 0, wxRIGHT | wxBOTTOM, 15);
200    vert->Add(bottom, 0, wxEXPAND | wxLEFT | wxRIGHT, 0);
201    vert->SetMinSize(0, bitmap.GetHeight());
202
203    SetSizer(horiz);
204    close->SetDefault();
205
206    horiz->SetSizeHints(this);
207
208    timer.Start(42000);
209}
Note: See TracBrowser for help on using the repository browser.