source: git/src/aboutdlg.cc @ b2b1f6b

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

src/aboutdlg.cc,src/aboutdlg.h: Put the wxIcon into the
wxStaticBitmap directly, rather than converting it to a wxBitmap.

  • Property mode set to 100644
File size: 6.6 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)
40    EVT_BUTTON(wxID_CLOSE, AboutDlg::OnClose)
41END_EVENT_TABLE()
42
43void
44AboutDlg::OnTimer(wxTimerEvent &)
45{
46    wxImage::AddHandler(new wxJPEGHandler);
47    bitmap.LoadFile(img_path + wxT("osterei.jpg"), wxBITMAP_TYPE_JPEG);
48    ((wxStaticBitmap*)FindWindowById(501, this))->SetBitmap(bitmap);
49}
50
51void
52AboutDlg::OnCopy(wxCommandEvent &)
53{
54    if (wxTheClipboard->Open()) {
55        wxTheClipboard->SetData(new wxTextDataObject(info));
56        wxTheClipboard->Close();
57        // (Try to) make the selection persist after aven exits.
58        (void)wxTheClipboard->Flush();
59    }
60}
61
62void
63AboutDlg::OnClose(wxCommandEvent &)
64{
65    Close();
66}
67
68AboutDlg::AboutDlg(wxWindow* parent, const wxIcon & app_icon) :
69    /* TRANSLATORS: for the title of the About box */
70    wxDialog(parent, 500, wxString::Format(wmsg(/*About %s*/205), APP_NAME)),
71    timer(this, about_TIMER)
72{
73    img_path = wxString(wmsg_cfgpth());
74    img_path += wxCONFIG_PATH_SEPARATOR;
75    img_path += wxT("images");
76    img_path += wxCONFIG_PATH_SEPARATOR;
77
78    wxBoxSizer* horiz = new wxBoxSizer(wxHORIZONTAL);
79    wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL);
80
81    if (!bitmap.Ok()) {
82        bitmap.LoadFile(img_path + APP_ABOUT_IMAGE, wxBITMAP_TYPE_PNG);
83    }
84    if (bitmap.Ok()) {
85        wxStaticBitmap* static_bitmap = new wxStaticBitmap(this, 501, bitmap);
86        horiz->Add(static_bitmap, 0 /* horizontally unstretchable */, wxALL,
87                   2 /* border width */);
88    }
89    horiz->Add(vert, 0, wxALL, 2);
90
91    wxString id(APP_NAME wxT(" "VERSION"\n"));
92    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
93     * - it should be translated to the terminology that cavers using the
94     * language would use.
95     *
96     * This string is used in the about box (summarising the purpose of aven).
97     */
98    id += wmsg(/*Survey visualisation tool*/209);
99    wxBoxSizer* title = new wxBoxSizer(wxHORIZONTAL);
100    wxStaticBitmap* static_bitmap = new wxStaticBitmap(this, 599, wxBitmap());
101    static_bitmap->SetIcon(app_icon);
102    title->Add(static_bitmap, 0, wxALIGN_CENTRE_VERTICAL|wxRIGHT, 8);
103    title->Add(new wxStaticText(this, 502, id), 0, wxALL, 2);
104
105    wxStaticText* copyright = new wxStaticText(this, 503,
106                                        wxT(COPYRIGHT_MSG_UTF8"\n"AVEN_COPYRIGHT_MSG_UTF8));
107
108    wxString licence_str;
109    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));
110    wxClientDC dc(this);
111    dc.SetFont(this->GetFont());
112    do {
113        unsigned int a = 72;
114        if (a >= l.length()) {
115            a = l.length();
116        } else {
117            while (a > 1 && l[a] != ' ') --a;
118        }
119
120        while (a > 1) {
121            wxCoord w, h;
122            dc.GetTextExtent(l.substr(0, a), &w, &h);
123            if (w <= 380) break;
124            do { --a; } while (a > 1 && l[a] != ' ');
125        }
126
127        if (!licence_str.empty()) licence_str += '\n';
128        licence_str += l.substr(0, a);
129        if (a < l.length() && l[a] == ' ') ++a;
130        l.erase(0, a);
131    } while (!l.empty());
132
133    wxStaticText* licence = new wxStaticText(this, 504, licence_str);
134
135    vert->Add(10, 5, 0, wxTOP, 5);
136    vert->Add(title, 0, wxLEFT | wxRIGHT, 20);
137    vert->Add(10, 5, 0, wxTOP, 5);
138
139    vert->Add(copyright, 0, wxLEFT | wxRIGHT, 20);
140    vert->Add(10, 5, 0, wxTOP, 5);
141
142    vert->Add(licence, 0, wxLEFT | wxRIGHT, 20);
143    vert->Add(10, 5, 0, wxTOP, 5);
144
145    // TRANSLATORS: for about box:
146    vert->Add(new wxStaticText(this, 505, wmsg(/*System Information:*/390)),
147              0, wxLEFT | wxRIGHT, 20);
148
149    info = wxGetOsDescription();
150#if wxCHECK_VERSION(2,9,2)
151    info += wxT("\n");
152    wxString version = wxGetLibraryVersionInfo().GetVersionString();
153    info += version;
154    if (version != wxVERSION_STRING)
155        info += wxT(" (built with ") wxVERSION_STRING wxT(")");
156    info +=
157#else
158    info += wxT("\nBuilt with ") wxVERSION_STRING
159#endif
160#ifdef __WXGTK__
161# if defined __WXGTK26__
162        wxT(" (GTK+ >= 2.6)\n");
163# elif defined __WXGTK24__
164        wxT(" (GTK+ >= 2.4)\n");
165# elif defined __WXGTK20__
166        wxT(" (GTK+ >= 2.0)\n");
167# elif defined __WXGTK12__
168        wxT(" (GTK+ >= 1.2)\n");
169# else
170        wxT(" (GTK+ < 1.2)\n");
171# endif
172#elif defined __WXMOTIF__
173# if defined __WXMOTIF20__
174        wxT(" (Motif >= 2.0)\n");
175# else
176        wxT(" (Motif < 2.0)\n");
177# endif
178#elif defined __WXX11__
179        wxT(" (X11)\n");
180#else
181        wxT("\n");
182#endif
183    int bpp = wxDisplayDepth();
184    /* TRANSLATORS: bpp is "Bits Per Pixel" */
185    info += wxString::Format(wmsg(/*Display Depth: %d bpp*/196), bpp);
186    /* TRANSLATORS: appended to previous message if the display is colour */
187    if (wxColourDisplay()) info += wmsg(/* (colour)*/197);
188    info += wxT('\n');
189    info += wxString(GetGLSystemDescription().c_str(), wxConvUTF8);
190
191    // Use a readonly multiline text edit for the system info so users can
192    // easily cut and paste it into an email when reporting bugs.
193    vert->Add(new wxTextCtrl(this, 506, info, wxDefaultPosition,
194                             wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY),
195              1, wxLEFT | wxRIGHT | wxEXPAND, 20);
196
197    vert->Add(10, 5, 0, wxALIGN_BOTTOM | wxTOP, 5);
198
199    wxBoxSizer* bottom = new wxBoxSizer(wxHORIZONTAL);
200    bottom->Add(5, 5, 1);
201    bottom->Add(new wxButton(this, wxID_COPY), 0, wxRIGHT | wxBOTTOM, 6);
202    wxButton* close = new wxButton(this, wxID_CLOSE);
203    bottom->Add(close, 0, wxRIGHT | wxBOTTOM, 15);
204    vert->Add(bottom, 0, wxEXPAND | wxLEFT | wxRIGHT, 0);
205    vert->SetMinSize(0, bitmap.GetHeight());
206
207    SetSizer(horiz);
208    close->SetDefault();
209
210    horiz->SetSizeHints(this);
211
212    timer.Start(42000);
213}
Note: See TracBrowser for help on using the repository browser.