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 WXIMPEX wxString GetFormattedTimeSpan(const wxTimeSpan& timeSpan)
28 {
29  if (timeSpan.IsNull())
30  {
31  return wxEmptyString;
32  };
33  if (timeSpan.GetHours() >= 1)
34  {
35  // longer than 1 h, format hours:minutes
36  return timeSpan.Format(_("%H:%M h"));
37  }
38  else
39  {
40  // shorter than 1 h
41  if (timeSpan.GetSeconds() > 60)
42  {
43  // format minutes:seconds
44  return timeSpan.Format(_("%M:%S min"));
45  }
46  else
47  {
48  if (timeSpan.GetSeconds() < 1)
49  {
50  // shorter then 1 s, don't display anything
51  return wxEmptyString;
52  }
53  else
54  {
55  // below 1 min, show only seconds
56  return timeSpan.Format(_("%S s"));
57  }
58  }
59  }
60 }
61 
62 // utility functions
63 #include <wx/config.h>
64 
65 void RestoreFramePosition(wxTopLevelWindow* frame, const wxString& basename)
66 {
67  DEBUG_TRACE(basename.mb_str(wxConvLocal));
68  wxConfigBase* config = wxConfigBase::Get();
69 
70  // get display size
71  int dx, dy;
72  wxDisplaySize(&dx, &dy);
73 
74 #if ( __WXGTK__ )
75  // restoring the splitter positions properly when maximising doesn't work.
76  // Disabling maximise on wxWidgets >= 2.6.0 and gtk
77  //size
78  const int w = config->Read(wxT("/") + basename + wxT("/width"), -1l);
79  const int h = config->Read(wxT("/") + basename + wxT("/height"), -1l);
80  if (w > 0 && w <= dx)
81  {
82  frame->SetClientSize(w, h);
83  }
84  else
85  {
86  frame->Fit();
87  };
88  //position
89  const int x = config->Read(wxT("/") + basename + wxT("/positionX"), -1l);
90  const int y = config->Read(wxT("/") + basename + wxT("/positionY"), -1l);
91  if (y >= 0 && x >= 0 && x < dx && y < dy)
92  {
93  frame->Move(x, y);
94  }
95  else
96  {
97  frame->Move(0, 44);
98  };
99 #else
100  const bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
101  if (maximized)
102  {
103  frame->Maximize();
104  }
105  else
106  {
107  //size
108  const int w = config->Read(wxT("/") + basename + wxT("/width"), -1l);
109  const int h = config->Read(wxT("/") + basename + wxT("/height"), -1l);
110  if (w > 0 && w <= dx)
111  {
112  frame->SetClientSize(w, h);
113  }
114  else
115  {
116  frame->Fit();
117  };
118  //position
119  const int x = config->Read(wxT("/") + basename + wxT("/positionX"), -1l);
120  const int y = config->Read(wxT("/") + basename + wxT("/positionY"), -1l);
121  if (y >= 0 && x >= 0 && x < dx && y < dy)
122  {
123  frame->Move(x, y);
124  }
125  else
126  {
127  frame->Move(0, 44);
128  };
129  };
130 #endif
131 }
132 
133 void StoreFramePosition(wxTopLevelWindow* frame, const wxString& basename)
134 {
135  DEBUG_TRACE(basename);
136  wxConfigBase* config = wxConfigBase::Get();
137 
138 #if ( __WXGTK__ )
139  // restoring the splitter positions properly when maximising doesn't work.
140  // Disabling maximise on wxWidgets >= 2.6.0 and gtk
141  wxSize sz = frame->GetClientSize();
142  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
143  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
144  wxPoint ps = frame->GetPosition();
145  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
146  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
147  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
148 #else
149  if ((!frame->IsMaximized()) && (!frame->IsIconized()))
150  {
151  const wxSize sz = frame->GetClientSize();
152  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
153  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
154  wxPoint ps = frame->GetPosition();
155  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
156  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
157  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
158  }
159  else
160  {
161  if (frame->IsMaximized())
162  {
163  config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
164  };
165  };
166 #endif
167 }
WXIMPEX wxString GetFormattedTimeSpan(const wxTimeSpan &timeSpan)
Definition: wxutils.cpp:27
#define DEBUG_TRACE(msg)
Definition: utils.h:67
#define WXIMPEX
Definition: hugin_shared.h:40
IMPEX double h[25][1024]
Definition: emor.cpp:169
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: wxutils.cpp:133
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: wxutils.cpp:65