Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
27 namespace hugin_utils
28 {
29 WXIMPEX wxString GetFormattedTimeSpan(const wxTimeSpan& timeSpan)
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 
67 void RestoreFramePosition(wxTopLevelWindow* frame, const wxString& basename)
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 #if ( __WXGTK__ )
77  // restoring the splitter positions properly when maximising doesn't work.
78  // Disabling maximise on wxWidgets >= 2.6.0 and gtk
79  //size
80  const int w = config->Read("/" + basename + "/width", -1l);
81  const int h = config->Read("/" + basename + "/height", -1l);
82  if (w > 0 && w <= dx)
83  {
84  frame->SetClientSize(w, h);
85  }
86  else
87  {
88  frame->Fit();
89  };
90  //position
91  const int x = config->Read("/" + basename + "/positionX", -1l);
92  const int y = config->Read("/" + basename + "/positionY", -1l);
93  if (y >= 0 && x >= 0 && x < dx && y < dy)
94  {
95  frame->Move(x, y);
96  }
97  else
98  {
99  frame->Move(0, 44);
100  };
101 #else
102  const bool maximized = config->Read("/" + basename + "/maximized", 0l) != 0;
103  if (maximized)
104  {
105  frame->Maximize();
106  }
107  else
108  {
109  //size
110  const int w = config->Read("/" + basename + "/width", -1l);
111  const int h = config->Read("/" + basename + "/height", -1l);
112  if (w > 0 && w <= dx)
113  {
114  frame->SetClientSize(w, h);
115  }
116  else
117  {
118  frame->Fit();
119  };
120  //position
121  const int x = config->Read("/" + basename + "/positionX", -1l);
122  const int y = config->Read("/" + basename + "/positionY", -1l);
123  if (y >= 0 && x >= 0 && x < dx && y < dy)
124  {
125  frame->Move(x, y);
126  }
127  else
128  {
129  frame->Move(0, 44);
130  };
131  };
132 #endif
133 }
134 
135 void StoreFramePosition(wxTopLevelWindow* frame, const wxString& basename)
136 {
137  DEBUG_TRACE(basename);
138  wxConfigBase* config = wxConfigBase::Get();
139 
140 #if ( __WXGTK__ )
141  // restoring the splitter positions properly when maximising doesn't work.
142  // Disabling maximise on wxWidgets >= 2.6.0 and gtk
143  wxSize sz = frame->GetClientSize();
144  config->Write("/" + basename + "/width", sz.GetWidth());
145  config->Write("/" + basename + "/height", sz.GetHeight());
146  wxPoint ps = frame->GetPosition();
147  config->Write("/" + basename + "/positionX", ps.x);
148  config->Write("/" + basename + "/positionY", ps.y);
149  config->Write("/" + basename + "/maximized", 0);
150 #else
151  if ((!frame->IsMaximized()) && (!frame->IsIconized()))
152  {
153  const wxSize sz = frame->GetClientSize();
154  config->Write("/" + basename + "/width", sz.GetWidth());
155  config->Write("/" + basename + "/height", sz.GetHeight());
156  wxPoint ps = frame->GetPosition();
157  config->Write("/" + basename + "/positionX", ps.x);
158  config->Write("/" + basename + "/positionY", ps.y);
159  config->Write("/" + basename + "/maximized", 0);
160  }
161  else
162  {
163  if (frame->IsMaximized())
164  {
165  config->Write("/" + basename + "/maximized", 1l);
166  };
167  };
168 #endif
169 }
170 
171 
172 }
#define DEBUG_TRACE(msg)
Definition: utils.h:67
WXIMPEX wxString GetFormattedTimeSpan(const wxTimeSpan &timeSpan)
Definition: wxutils.cpp:29
#define WXIMPEX
Definition: hugin_shared.h:40
IMPEX double h[25][1024]
Definition: emor.cpp:169
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Definition: wxutils.cpp:135
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Definition: wxutils.cpp:67