]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/wxrcedit/pe_adv.cpp
Better wxFile support, warning fixes and minor source cleaning.
[wxWidgets.git] / contrib / utils / wxrcedit / pe_adv.cpp
CommitLineData
12d9e308
VS
1/////////////////////////////////////////////////////////////////////////////
2// Author: Vaclav Slavik
3// Created: 2000/05/05
4// RCS-ID: $Id$
5// Copyright: (c) 2000 Vaclav Slavik
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9#ifdef __GNUG__
10 #pragma implementation "pe_adv.h"
11#endif
12
13// For compilers that support precompilation, includes "wx/wx.h".
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#include "wx/wx.h"
c74caa09 21#include "wx/xml/xml.h"
12d9e308 22#include "wx/tokenzr.h"
a62da4c5
VS
23#include "wx/wx.h"
24#include "wx/dialog.h"
25#include "wx/checklst.h"
12d9e308
VS
26#include "pe_basic.h"
27#include "pe_adv.h"
28#include "xmlhelpr.h"
29#include "editor.h"
30#include "preview.h"
31#include "wx/colordlg.h"
a62da4c5 32#include "wx/config.h"
12d9e308
VS
33
34
35
36wxWindow* PropEditCtrlFont::CreateEditCtrl()
37{
38 PropEditCtrlTxt::CreateEditCtrl();
dabbc6a5 39 m_TextCtrl->Disable();
12d9e308
VS
40 return m_TextCtrl;
41}
42
43
44
45wxTreeItemId PropEditCtrlFont::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
46{
47 wxTreeItemId ti = PropEditCtrlTxt::CreateTreeEntry(parent, pinfo);
a62da4c5
VS
48 m_PropFrame->AddSingleProp(PropertyInfo(_T("integer"), pinfo.Name + _T("/size"), wxEmptyString), &ti);
49 m_PropFrame->AddSingleProp(PropertyInfo(_T("text"), pinfo.Name + _T("/face"), wxEmptyString), &ti);
50 m_PropFrame->AddSingleProp(PropertyInfo(_T("choice"), pinfo.Name + _T("/style"), _T("normal,italic,slant")), &ti);
51 m_PropFrame->AddSingleProp(PropertyInfo(_T("choice"), pinfo.Name + _T("/weight"), _T("normal,light,bold")), &ti);
52 m_PropFrame->AddSingleProp(PropertyInfo(_T("choice"), pinfo.Name + _T("/family"), _T("default,decorative,roman,script,swiss,modern")), &ti);
53 m_PropFrame->AddSingleProp(PropertyInfo(_T("bool"), pinfo.Name + _T("/underlined"), wxEmptyString), &ti);
54 m_PropFrame->AddSingleProp(PropertyInfo(_T("text"), pinfo.Name + _T("/encoding"), wxEmptyString), &ti);
12d9e308
VS
55 return ti;
56}
57
58
59
60
a62da4c5
VS
61
62
12d9e308 63BEGIN_EVENT_TABLE(PropEditCtrlChoice, PropEditCtrl)
f80ea77b 64 EVT_CHOICE(wxID_ANY, PropEditCtrlChoice::OnChoice)
12d9e308
VS
65END_EVENT_TABLE()
66
67wxWindow* PropEditCtrlChoice::CreateEditCtrl()
68{
f80ea77b
WS
69 m_Choice = new wxChoice(this, wxID_ANY);
70
12d9e308
VS
71 return m_Choice;
72}
73
74
f80ea77b 75
12d9e308
VS
76void PropEditCtrlChoice::ReadValue()
77{
a62da4c5
VS
78 wxStringTokenizer tkn(m_PropInfo->MoreInfo, _T(","));
79 m_Choice->Clear();
80 while (tkn.HasMoreTokens())
81 m_Choice->Append(tkn.GetNextToken());
82
83 wxString sel = XmlReadValue(GetNode(), m_PropInfo->Name);
84 if (!!sel) m_Choice->SetStringSelection(sel);
12d9e308
VS
85}
86
87
88
89void PropEditCtrlChoice::WriteValue()
90{
a62da4c5
VS
91 XmlWriteValue(GetNode(), m_PropInfo->Name,
92 m_Choice->GetStringSelection());
12d9e308
VS
93}
94
95
96
859e5b17 97void PropEditCtrlChoice::OnChoice(wxCommandEvent& WXUNUSED(event))
12d9e308 98{
f80ea77b 99 if (CanSave())
26607f41
VS
100 {
101 WriteValue();
f80ea77b 102 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
26607f41 103 }
12d9e308
VS
104}
105
106
107
a62da4c5
VS
108
109
12d9e308
VS
110void PropEditCtrlColor::OnDetails()
111{
112 wxColour clr;
113 wxString txt = m_TextCtrl->GetValue();
114 long unsigned tmp;
f80ea77b 115
0d832cf7 116 if (txt.Length() == 7 && txt[0u] == _T('#') &&
12d9e308 117 wxSscanf(txt.c_str(), _T("#%lX"), &tmp) == 1)
19311d4e
WS
118 clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
119 (unsigned char)((tmp & 0x00FF00) >> 8),
120 (unsigned char)((tmp & 0x0000FF)));
6267a331 121
12d9e308
VS
122 clr = wxGetColourFromUser(NULL, clr);
123 if (clr.Ok())
124 {
125 txt.Printf(_T("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue());
126 m_TextCtrl->SetValue(txt);
127 WriteValue();
128 }
129}
130
131
a62da4c5
VS
132
133
134
135
136
137
138
139
140void PropEditCtrlFlags::OnDetails()
141{
142 wxString t,txt = m_TextCtrl->GetValue();
143 wxArrayString arr;
144 size_t i;
145 int j;
f80ea77b 146
a62da4c5
VS
147 wxStringTokenizer tkn(m_PropInfo->MoreInfo, _T(","));
148 while (tkn.HasMoreTokens())
149 arr.Add(tkn.GetNextToken());
150
151 wxConfigBase *cfg = wxConfigBase::Get();
f80ea77b
WS
152
153 wxDialog dlg(m_PropFrame, wxID_ANY, _("Flags"),
422d0ff0 154 wxPoint(cfg->Read(_T("flagsdlg_x"), wxDefaultCoord), cfg->Read(_T("flagsdlg_y"), wxDefaultCoord)),
a62da4c5
VS
155 wxSize(cfg->Read(_T("flagsdlg_w"), 300), cfg->Read(_T("flagsdlg_h"), 300)),
156 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
157 wxSizer *sz = new wxBoxSizer(wxVERTICAL);
f80ea77b 158 wxCheckListBox *lbox = new wxCheckListBox(&dlg, wxID_ANY);
a62da4c5
VS
159 sz->Add(lbox, 1, wxEXPAND | wxALL, 10);
160 wxSizer *sz2 = new wxBoxSizer(wxHORIZONTAL);
161 wxButton *btnok = new wxButton(&dlg, wxID_OK, _("OK"));
162 btnok->SetDefault();
163 sz2->Add(btnok);
164 sz2->Add(new wxButton(&dlg, wxID_CANCEL, _("Cancel")), 0, wxLEFT, 10);
165 sz->Add(sz2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
166
167 dlg.SetSizer(sz);
aaa2b34e 168 dlg.Layout();
f80ea77b 169
a62da4c5
VS
170 for (i = 0; i < arr.GetCount(); i++)
171 lbox->Append(arr[i]);
f80ea77b 172
a62da4c5
VS
173 tkn.SetString(txt, _T("| "));
174 while (tkn.HasMoreTokens())
175 {
176 t = tkn.GetNextToken();
177 j = arr.Index(t);
178 if (j != wxNOT_FOUND) lbox->Check(j);
179 }
f80ea77b
WS
180
181
a62da4c5 182 if (dlg.ShowModal() != wxID_OK) return;
f80ea77b 183
a62da4c5 184 txt.Empty();
f80ea77b 185
a62da4c5
VS
186 for (i = 0; i < arr.GetCount(); i++)
187 if (lbox->IsChecked(i))
188 txt << arr[i] << _T('|');
19311d4e 189 if (!txt.empty()) txt.RemoveLast();
a62da4c5
VS
190
191 m_TextCtrl->SetValue(txt);
192 WriteValue();
193
194 cfg->Write(_T("flagsdlg_x"), (long)dlg.GetPosition().x);
195 cfg->Write(_T("flagsdlg_y"), (long)dlg.GetPosition().y);
196 cfg->Write(_T("flagsdlg_w"), (long)dlg.GetSize().x);
197 cfg->Write(_T("flagsdlg_h"), (long)dlg.GetSize().y);
198}
199
200
26607f41
VS
201
202
203
204
205
206
207wxString PropEditCtrlFile::GetFileTypes()
208{
209 return m_PropInfo->MoreInfo;
210}
211
212
213
214void PropEditCtrlFile::OnDetails()
215{
216 wxString txt = m_TextCtrl->GetValue();
217 txt = wxPathOnly(EditorFrame::Get()->GetFileName()) + _T("/") + txt;
f80ea77b 218 wxString name = wxFileSelector(_("Choose file"),
26607f41
VS
219 wxPathOnly(txt),
220 wxFileNameFromPath(txt),
dabbc6a5 221 wxEmptyString,
26607f41
VS
222 GetFileTypes(),
223 wxOPEN | wxFILE_MUST_EXIST);
224 if (!name) return;
f80ea77b 225
26607f41
VS
226 // compute relative path:
227 wxArrayString axrc, afile;
228 wxStringTokenizer tkn;
229 tkn.SetString(name, _T("/\\"));
230 while (tkn.HasMoreTokens()) afile.Add(tkn.GetNextToken());
231 tkn.SetString(EditorFrame::Get()->GetFileName(), _T("/\\"));
232 while (tkn.HasMoreTokens()) axrc.Add(tkn.GetNextToken());
f80ea77b 233
26607f41
VS
234 if (afile.GetCount() == 0 || axrc.GetCount() == 0)
235 txt = name;
236 else
237 {
238 while (axrc[0] == afile[0])
239 {
ab958adb
GD
240 afile.RemoveAt(0u);
241 axrc.RemoveAt(0u);
26607f41
VS
242 }
243 size_t i;
244 txt.Empty();
245 for (i = 0; i < axrc.GetCount()-1/*w/o filename*/; i++) txt << _T("../");
246 for (i = 0; i < afile.GetCount(); i++) txt << afile[i] << _T("/");
247 txt.RemoveLast();
248 }
249
250 m_TextCtrl->SetValue(txt);
251 WriteValue();
252}
253
254
255
256wxString PropEditCtrlImageFile::GetFileTypes()
257{
19d0f58d 258 return _("GIF files (*.gif)|*.gif|JPEG files (*.jpg)|*.jpg|PNG files (*.png)|*.png|BMP files (*.bmp)|*.bmp|All files (*)|*");
26607f41 259}