1 
2 ///////////////////////////////////////////////////////////
3 //                                                       //
4 //                         SAGA                          //
5 //                                                       //
6 //      System for Automated Geoscientific Analyses      //
7 //                                                       //
8 //           Application Programming Interface           //
9 //                                                       //
10 //                  Library: SAGA_GDI                    //
11 //                                                       //
12 //-------------------------------------------------------//
13 //                                                       //
14 //                    sgui_dialog.cpp                    //
15 //                                                       //
16 //                 Copyright (C) 2009 by                 //
17 //                      Olaf Conrad                      //
18 //                                                       //
19 //-------------------------------------------------------//
20 //                                                       //
21 // This file is part of 'SAGA - System for Automated     //
22 // Geoscientific Analyses'. SAGA is free software; you   //
23 // can redistribute it and/or modify it under the terms  //
24 // of the GNU General Public License as published by the //
25 // Free Software Foundation, either version 2 of the     //
26 // License, or (at your option) any later version.       //
27 //                                                       //
28 // SAGA is distributed in the hope that it will be       //
29 // useful, but WITHOUT ANY WARRANTY; without even the    //
30 // implied warranty of MERCHANTABILITY or FITNESS FOR A  //
31 // PARTICULAR PURPOSE. See the GNU General Public        //
32 // License for more details.                             //
33 //                                                       //
34 // You should have received a copy of the GNU General    //
35 // Public License along with this program; if not, see   //
36 // <http://www.gnu.org/licenses/>.                       //
37 //                                                       //
38 //-------------------------------------------------------//
39 //                                                       //
40 //    e-mail:     oconrad@saga-gis.org                   //
41 //                                                       //
42 //    contact:    Olaf Conrad                            //
43 //                Institute of Geography                 //
44 //                University of Hamburg                  //
45 //                Germany                                //
46 //                                                       //
47 ///////////////////////////////////////////////////////////
48 
49 //---------------------------------------------------------
50 #include <wx/wxprec.h>
51 
52 #ifdef __BORLANDC__
53 	#pragma hdrstop
54 #endif
55 
56 #include <wx/settings.h>
57 #include <wx/dc.h>
58 #include <wx/sizer.h>
59 #include <wx/stattext.h>
60 
61 #include <saga_api/saga_api.h>
62 
63 #include "sgdi_dialog.h"
64 
65 
66 ///////////////////////////////////////////////////////////
67 //														 //
68 //														 //
69 //														 //
70 ///////////////////////////////////////////////////////////
71 
72 //---------------------------------------------------------
BEGIN_EVENT_TABLE(CSGDI_Dialog,wxDialog)73 BEGIN_EVENT_TABLE(CSGDI_Dialog, wxDialog)
74 END_EVENT_TABLE()
75 
76 
77 ///////////////////////////////////////////////////////////
78 //														 //
79 //														 //
80 //														 //
81 ///////////////////////////////////////////////////////////
82 
83 //---------------------------------------------------------
84 CSGDI_Dialog::CSGDI_Dialog(const wxString &Name, int Style)
85 	: wxDialog((wxWindow *)SG_UI_Get_Window_Main(), wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
86 {
87 	if( Style & SGDI_DLG_STYLE_START_MAXIMISED )
88 	{
89 		Maximize();
90 	}
91 
92 	m_Ctrl_Color	= *wxBLACK;
93 
94 	m_pSizer_Ctrl	= new wxStaticBoxSizer(wxVERTICAL, this, wxT(""));
95 	m_pSizer_Output	= new wxStaticBoxSizer(wxVERTICAL, this, wxT(""));
96 
97 	wxSizer	*pSizer	= new wxBoxSizer(wxHORIZONTAL);
98 
99 	if( Style & SGDI_DLG_STYLE_CTRLS_RIGHT )
100 	{
101 		pSizer->Add(m_pSizer_Output	, 1, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
102 		pSizer->Add(m_pSizer_Ctrl	, 0, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
103 	}
104 	else
105 	{
106 		pSizer->Add(m_pSizer_Ctrl	, 0, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
107 		pSizer->Add(m_pSizer_Output	, 1, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
108 	}
109 
110 	pSizer->FitInside(this);
111 
112 	SetSizer(pSizer);
113 }
114 
115 //---------------------------------------------------------
~CSGDI_Dialog(void)116 CSGDI_Dialog::~CSGDI_Dialog(void)
117 {}
118 
119 
120 ///////////////////////////////////////////////////////////
121 //														 //
122 ///////////////////////////////////////////////////////////
123 
124 //---------------------------------------------------------
ShowModal(void)125 int CSGDI_Dialog::ShowModal(void)
126 {
127 	if( GetParent()->IsShownOnScreen() )
128 	{
129 		wxRect	r(GetParent()->GetScreenRect());
130 		r.Deflate((int)(0.1 * r.GetWidth()), (int)(0.1 * r.GetHeight()));
131 		SetSize(r);
132 	}
133 
134 	return( wxDialog::ShowModal() );
135 }
136 
137 
138 ///////////////////////////////////////////////////////////
139 //														 //
140 ///////////////////////////////////////////////////////////
141 
142 //---------------------------------------------------------
Add_Output(wxWindow * pOutput)143 bool CSGDI_Dialog::Add_Output(wxWindow *pOutput)
144 {
145 	m_pSizer_Output->Add(pOutput, 1, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
146 
147 	return( true );
148 }
149 
150 //---------------------------------------------------------
Add_Output(wxWindow * pOutput_A,wxWindow * pOutput_B,int Proportion_A,int Proportion_B)151 bool CSGDI_Dialog::Add_Output(wxWindow *pOutput_A, wxWindow *pOutput_B, int Proportion_A, int Proportion_B)
152 {
153 	m_pSizer_Output->Add(pOutput_A, Proportion_A, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
154 	m_pSizer_Output->Add(pOutput_B, Proportion_B, wxALL|wxEXPAND, SGDI_CTRL_SPACE);
155 
156 	return( true );
157 }
158 
159 
160 ///////////////////////////////////////////////////////////
161 //														 //
162 //														 //
163 //														 //
164 ///////////////////////////////////////////////////////////
165 
166 //---------------------------------------------------------
Add_Spacer(int Space)167 void CSGDI_Dialog::Add_Spacer(int Space)
168 {
169 	m_pSizer_Ctrl->AddSpacer(Space);
170 }
171 
172 //---------------------------------------------------------
Add_Button(const wxString & Name,int ID,const wxSize & Size)173 wxButton * CSGDI_Dialog::Add_Button(const wxString &Name, int ID, const wxSize &Size)
174 {
175 	wxButton	*pButton	= new wxButton(this, ID, Name, wxDefaultPosition, Size);
176 
177 	m_pSizer_Ctrl->Add(pButton, 0, wxALL|wxEXPAND, SGDI_CTRL_SMALLSPACE);
178 
179 	return( pButton );
180 }
181 
182 //---------------------------------------------------------
Add_Choice(const wxString & Name,const wxArrayString & Choices,int iSelect,int ID)183 wxChoice * CSGDI_Dialog::Add_Choice(const wxString &Name, const wxArrayString &Choices, int iSelect, int ID)
184 {
185 	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
186 	wxChoice		*pChoice	= new wxChoice(this, ID, wxDefaultPosition, wxDefaultSize, Choices);
187 
188 	pLabel	->SetForegroundColour(m_Ctrl_Color);
189 	pChoice	->SetSelection(iSelect);
190 
191 	m_pSizer_Ctrl->Add(pLabel , 0, wxLEFT|wxRIGHT|wxTOP   |wxEXPAND, SGDI_CTRL_SMALLSPACE);
192 	m_pSizer_Ctrl->Add(pChoice, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
193 
194 	return( pChoice );
195 }
196 
197 //---------------------------------------------------------
Add_CheckBox(const wxString & Name,bool bCheck,int ID)198 wxCheckBox * CSGDI_Dialog::Add_CheckBox(const wxString &Name, bool bCheck, int ID)
199 {
200 	wxCheckBox		*pCheckBox	= new wxCheckBox(this, ID, Name, wxDefaultPosition, wxDefaultSize, 0);
201 
202 	pCheckBox->SetForegroundColour(m_Ctrl_Color);
203 	pCheckBox->SetValue(bCheck);
204 
205 	m_pSizer_Ctrl->Add(pCheckBox, 0, wxALIGN_LEFT|wxALL, SGDI_CTRL_SMALLSPACE);
206 
207 	return( pCheckBox );
208 }
209 
210 //---------------------------------------------------------
Add_TextCtrl(const wxString & Name,int Style,const wxString & Text,int ID)211 wxTextCtrl * CSGDI_Dialog::Add_TextCtrl(const wxString &Name, int Style, const wxString &Text, int ID)
212 {
213 	int				Stretch		= Style & wxTE_MULTILINE;
214 
215 	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
216 	wxTextCtrl		*pTextCtrl	= new wxTextCtrl(this, ID, Text, wxDefaultPosition, SGDI_BTN_SIZE, Style);
217 
218 	pLabel	->SetForegroundColour(m_Ctrl_Color);
219 
220 	m_pSizer_Ctrl->Add(pLabel   ,       0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP            , SGDI_CTRL_SMALLSPACE);
221 	m_pSizer_Ctrl->Add(pTextCtrl, Stretch,                wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
222 
223 	if( Style & wxTE_READONLY )
224 	{
225 		pTextCtrl->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
226 	}
227 
228 	return( pTextCtrl );
229 }
230 
231 //-----------------------------------------------------------------------------
Add_Slider(const wxString & Name,double Value,double minValue,double maxValue,bool bValueAsPercent,int ID,int Width)232 CSGDI_Slider * CSGDI_Dialog::Add_Slider(const wxString &Name, double Value, double minValue, double maxValue, bool bValueAsPercent, int ID, int Width)
233 {
234 	if( bValueAsPercent && maxValue > minValue )
235 	{
236 		Value	= minValue + Value * (maxValue - minValue) / 100.0;
237 	}
238 
239 //	wxSizer			*pSizer_	= new wxBoxSizer(wxHORIZONTAL);
240 	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
241 	CSGDI_Slider	*pSlider	= new CSGDI_Slider(this, ID, Value, minValue, maxValue, wxDefaultPosition, wxSize(Width, wxDefaultCoord), wxSL_AUTOTICKS|wxSL_LABELS|wxSL_TOP);
242 
243 	pLabel			->SetForegroundColour(m_Ctrl_Color);
244 
245 //	pSizer_			->Add(new wxStaticText(this, wxID_ANY,  "0", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
246 //	pSizer_			->Add(pSlider, 0);
247 //	pSizer_			->Add(new wxStaticText(this, wxID_ANY, "10", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
248 
249 	m_pSizer_Ctrl	->Add(pLabel , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP            , SGDI_CTRL_SMALLSPACE);
250 //	m_pSizer_Ctrl	->Add(pSizer_, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
251 	m_pSizer_Ctrl	->Add(pSlider, 0,                wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
252 
253 	return( pSlider );
254 }
255 
256 //-----------------------------------------------------------------------------
Add_SpinCtrl(const wxString & Name,double Value,double minValue,double maxValue,bool bValueAsPercent,int ID,int Width)257 CSGDI_SpinCtrl * CSGDI_Dialog::Add_SpinCtrl(const wxString &Name, double Value, double minValue, double maxValue, bool bValueAsPercent, int ID, int Width)
258 {
259 //	wxSizer			*pSizer_	= new wxBoxSizer(wxHORIZONTAL);
260 	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
261 	CSGDI_SpinCtrl	*pSpinCtrl	= new CSGDI_SpinCtrl(this, ID, Value, minValue, maxValue, bValueAsPercent, wxDefaultPosition, wxSize(Width, wxDefaultCoord), wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER);
262 
263 	pLabel			->SetForegroundColour(m_Ctrl_Color);
264 
265 //	pSizer_			->Add(new wxStaticText(this, wxID_ANY,  "0", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
266 //	pSizer_			->Add(pSpinCtrl, 0);
267 //	pSizer_			->Add(new wxStaticText(this, wxID_ANY, "10", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER), 0, wxALIGN_BOTTOM);
268 
269 	m_pSizer_Ctrl	->Add(pLabel   , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP   , SGDI_CTRL_SMALLSPACE);
270 //	m_pSizer_Ctrl	->Add(pSizer_  , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM, SGDI_CTRL_SMALLSPACE);
271 	m_pSizer_Ctrl	->Add(pSpinCtrl, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, SGDI_CTRL_SMALLSPACE);
272 
273 	return( pSpinCtrl );
274 }
275 
276 //---------------------------------------------------------
Add_CustomCtrl(const wxString & Name,wxWindow * pControl)277 void CSGDI_Dialog::Add_CustomCtrl(const wxString &Name, wxWindow *pControl)
278 {
279 	wxStaticText	*pLabel		= new wxStaticText(this, wxID_ANY, Name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
280 
281 	pLabel	->SetForegroundColour(m_Ctrl_Color);
282 
283 	m_pSizer_Ctrl->Add(pLabel  , 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxTOP   , SGDI_CTRL_SMALLSPACE);
284 	m_pSizer_Ctrl->Add(pControl, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT|wxBOTTOM, SGDI_CTRL_SMALLSPACE);
285 }
286 
287 
288 ///////////////////////////////////////////////////////////
289 //														 //
290 //														 //
291 //														 //
292 ///////////////////////////////////////////////////////////
293 
294 //---------------------------------------------------------
295