Hugin trunk 0.1
Loading...
Searching...
No Matches
wxutils.cpp
Go to the documentation of this file.
1
8/* This program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License as published by the Free Software Foundation; either
11* version 2 of the License, or (at your option) any later version.
12*
13* This software is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16* General Public License for more details.
17*
18* You should have received a copy of the GNU General Public
19* License along with this software. If not, see
20* <http://www.gnu.org/licenses/>.
21*
22*/
23
24#include "wxutils.h"
25#include <wx/translation.h>
26
27namespace hugin_utils
28{
30{
31 if (timeSpan.IsNull())
32 {
33 return wxEmptyString;
34 };
35 if (timeSpan.GetHours() >= 1)
36 {
37 // longer than 1 h, format hours:minutes
38 return timeSpan.Format(_("%H:%M h"));
39 }
40 else
41 {
42 // shorter than 1 h
43 if (timeSpan.GetSeconds() > 60)
44 {
45 // format minutes:seconds
46 return timeSpan.Format(_("%M:%S min"));
47 }
48 else
49 {
50 if (timeSpan.GetSeconds() < 1)
51 {
52 // shorter then 1 s, don't display anything
53 return wxEmptyString;
54 }
55 else
56 {
57 // below 1 min, show only seconds
58 return timeSpan.Format(_("%S s"));
59 }
60 }
61 }
62}
63
64// utility functions
65#include <wx/config.h>
66
67void RestoreFramePosition(wxTopLevelWindow* frame, const wxString& basename, const bool ignoreMaximize)
68{
69 DEBUG_TRACE(basename.mb_str(wxConvLocal));
70 wxConfigBase* config = wxConfigBase::Get();
71
72 // get display size
73 int dx, dy;
74 wxDisplaySize(&dx, &dy);
75
76#ifndef __WXGTK__
77 // restoring the splitter positions properly when maximising doesn't work.
78 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
79 // so ignore it for now
80 if (!ignoreMaximize)
81 {
82 const bool maximized = config->Read("/" + basename + "/maximized", 0l) != 0;
83 if (maximized)
84 {
85 frame->Maximize();
86 return;
87 };
88 };
89#endif
90
91 //size
92 const int w = config->Read("/" + basename + "/width", -1l);
93 const int h = config->Read("/" + basename + "/height", -1l);
94 if (w > 0 && w <= dx)
95 {
96 frame->SetClientSize(w, h);
97 }
98 else
99 {
100 frame->Fit();
101 };
102 //position
103 RestoreFramePositionOnly(frame, basename);
104}
105
106void StoreFramePosition(wxTopLevelWindow* frame, const wxString& basename, const bool ignoreMaximize)
107{
108 DEBUG_TRACE(basename);
109 wxConfigBase* config = wxConfigBase::Get();
110
111#ifndef __WXGTK__
112 // restoring the splitter positions properly when maximising doesn't work.
113 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
114 if (!ignoreMaximize && frame->IsMaximized())
115 {
116 config->Write("/" + basename + "/maximized", 1l);
117 config->DeleteEntry("/" + basename + "/width");
118 config->DeleteEntry("/" + basename + "/height");
119 config->DeleteEntry("/" + basename + "/positionX");
120 config->DeleteEntry("/" + basename + "/positionY");
121 return;
122 };
123#endif
124 if (!frame->IsIconized())
125 {
126 wxSize sz = frame->GetClientSize();
127 config->Write("/" + basename + "/width", sz.GetWidth());
128 config->Write("/" + basename + "/height", sz.GetHeight());
129 wxPoint ps = frame->GetPosition();
130 config->Write("/" + basename + "/positionX", ps.x);
131 config->Write("/" + basename + "/positionY", ps.y);
132 }
133 else
134 {
135 config->DeleteEntry("/" + basename + "/width");
136 config->DeleteEntry("/" + basename + "/height");
137 config->DeleteEntry("/" + basename + "/positionX");
138 config->DeleteEntry("/" + basename + "/positionY");
139 };
140 config->Write("/" + basename + "/maximized", 0l);
141}
142
144{
145 wxConfigBase* config = wxConfigBase::Get();
146
147 // get display size
148 int dx, dy;
149 wxDisplaySize(&dx, &dy);
150 // get position
151 const int x = config->Read("/" + basename + "/positionX", -1l);
152 const int y = config->Read("/" + basename + "/positionY", -1l);
153 if (y >= 0 && x >= 0 && x < dx && y < dy)
154 {
155 frame->Move(x, y);
156 }
157 else
158 {
159 frame->Move(0, 44);
160 };
161}
162
164{
165 wxConfigBase* config = wxConfigBase::Get();
166 const wxPoint ps = frame->GetPosition();
167 config->Write("/" + basename + "/positionX", ps.x);
168 config->Write("/" + basename + "/positionY", ps.y);
169}
170
171#ifdef __WXMSW__
172#include <wx/msgdlg.h>
173#include <wx/settings.h>
174#endif
175
176int HuginMessageBox(const wxString& message, const wxString& caption, int style, wxWindow* parent)
177{
178#ifdef __WXMSW__
179 // with caption on Windows
181#else
182 // on Linux/Mac OS the message box has no caption (see guidelines of the os)
184#endif
185}
186
188{
189#ifdef __WXMSW__
190 // on Windows with caption, otherwise the same as on other systems
191 return std::make_unique<wxMessageDialog>(parent, message, caption, style);
192#else
193 // on Linux/Mac OS the message box has no caption (see guidelines of the os)
194 return std::make_unique<wxMessageDialog>(parent, message, wxEmptyString, style);
195#endif
196}
197
198bool AskUserOverwrite(const wxString& filename, const wxString& caption, wxWindow* parent)
199{
200 if (HuginMessageBox(wxString::Format(_("File %s already exists.\nShould this file overwritten?"), filename),
202 {
203 return true;
204 }
205 else
206 {
207 return false;
208 };
209}
210
212{
213 m_window = window;
214 m_window->Disable();
215}
216
218{
219 m_window->Enable();
220}
221
222}
DisableWindow(wxWindow *window)
Definition wxutils.cpp:211
#define WXIMPEX
#define DEBUG_TRACE(msg)
Definition utils.h:67
namespace for various utils
void StoreFramePositionOnly(wxTopLevelWindow *frame, const wxString &basename)
Definition wxutils.cpp:163
WXIMPEX wxString GetFormattedTimeSpan(const wxTimeSpan &timeSpan)
Definition wxutils.cpp:29
bool AskUserOverwrite(const wxString &filename, const wxString &caption, wxWindow *parent)
ask user if the given file should be overwritten, return true if the user confirmed the overwritting
Definition wxutils.cpp:198
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:176
void RestoreFramePositionOnly(wxTopLevelWindow *frame, const wxString &basename)
Definition wxutils.cpp:143
std::unique_ptr< wxMessageDialogBase > MessageDialog
Definition wxutils.h:90
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition wxutils.cpp:106
MessageDialog GetMessageDialog(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:187
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition wxutils.cpp:67
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41