]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/pe_adv.cpp
added font and flags properties to wxrcedit
[wxWidgets.git] / contrib / utils / wxrcedit / pe_adv.cpp
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"
21 #include "wx/xml/xml.h"
22 #include "wx/tokenzr.h"
23 #include "wx/wx.h"
24 #include "wx/dialog.h"
25 #include "wx/checklst.h"
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"
32 #include "wx/config.h"
33
34
35
36 wxWindow* PropEditCtrlFont::CreateEditCtrl()
37 {
38 PropEditCtrlTxt::CreateEditCtrl();
39 m_TextCtrl->Enable(FALSE);
40 return m_TextCtrl;
41 }
42
43
44
45 wxTreeItemId PropEditCtrlFont::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
46 {
47 wxTreeItemId ti = PropEditCtrlTxt::CreateTreeEntry(parent, pinfo);
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);
55 return ti;
56 }
57
58
59
60
61
62
63 BEGIN_EVENT_TABLE(PropEditCtrlChoice, PropEditCtrl)
64 EVT_CHOICE(-1, PropEditCtrlChoice::OnChoice)
65 END_EVENT_TABLE()
66
67 wxWindow* PropEditCtrlChoice::CreateEditCtrl()
68 {
69 m_Choice = new wxChoice(this, -1);
70
71 return m_Choice;
72 }
73
74
75
76 void PropEditCtrlChoice::ReadValue()
77 {
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);
85 }
86
87
88
89 void PropEditCtrlChoice::WriteValue()
90 {
91 XmlWriteValue(GetNode(), m_PropInfo->Name,
92 m_Choice->GetStringSelection());
93 }
94
95
96
97 void PropEditCtrlChoice::OnChoice(wxCommandEvent& event)
98 {
99 if (CanSave()) WriteValue();
100 }
101
102
103
104
105
106 void PropEditCtrlColor::OnDetails()
107 {
108 wxColour clr;
109 wxString txt = m_TextCtrl->GetValue();
110 long unsigned tmp;
111
112 if (txt.Length() == 7 && txt[0] == _T('#') &&
113 wxSscanf(txt.c_str(), _T("#%lX"), &tmp) == 1)
114 clr = wxColour((tmp & 0xFF0000) >> 16,
115 (tmp & 0x00FF00) >> 8,
116 (tmp & 0x0000FF));
117 clr = wxGetColourFromUser(NULL, clr);
118 if (clr.Ok())
119 {
120 txt.Printf(_T("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue());
121 m_TextCtrl->SetValue(txt);
122 WriteValue();
123 }
124 }
125
126
127
128
129
130
131
132
133
134
135 void PropEditCtrlFlags::OnDetails()
136 {
137 wxString t,txt = m_TextCtrl->GetValue();
138 wxArrayString arr;
139 size_t i;
140 int j;
141
142 wxStringTokenizer tkn(m_PropInfo->MoreInfo, _T(","));
143 while (tkn.HasMoreTokens())
144 arr.Add(tkn.GetNextToken());
145
146 wxConfigBase *cfg = wxConfigBase::Get();
147
148 wxDialog dlg(m_PropFrame, -1, _("Flags"),
149 wxPoint(cfg->Read(_T("flagsdlg_x"), -1), cfg->Read(_T("flagsdlg_y"), -1)),
150 wxSize(cfg->Read(_T("flagsdlg_w"), 300), cfg->Read(_T("flagsdlg_h"), 300)),
151 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
152 wxSizer *sz = new wxBoxSizer(wxVERTICAL);
153 wxCheckListBox *lbox = new wxCheckListBox(&dlg, -1);
154 sz->Add(lbox, 1, wxEXPAND | wxALL, 10);
155 wxSizer *sz2 = new wxBoxSizer(wxHORIZONTAL);
156 wxButton *btnok = new wxButton(&dlg, wxID_OK, _("OK"));
157 btnok->SetDefault();
158 sz2->Add(btnok);
159 sz2->Add(new wxButton(&dlg, wxID_CANCEL, _("Cancel")), 0, wxLEFT, 10);
160 sz->Add(sz2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
161
162 dlg.SetSizer(sz);
163 dlg.SetAutoLayout(TRUE);
164
165 for (i = 0; i < arr.GetCount(); i++)
166 lbox->Append(arr[i]);
167
168 tkn.SetString(txt, _T("| "));
169 while (tkn.HasMoreTokens())
170 {
171 t = tkn.GetNextToken();
172 j = arr.Index(t);
173 if (j != wxNOT_FOUND) lbox->Check(j);
174 }
175
176
177 if (dlg.ShowModal() != wxID_OK) return;
178
179 txt.Empty();
180
181 for (i = 0; i < arr.GetCount(); i++)
182 if (lbox->IsChecked(i))
183 txt << arr[i] << _T('|');
184 if (!txt.IsEmpty()) txt.RemoveLast();
185
186 m_TextCtrl->SetValue(txt);
187 WriteValue();
188
189 cfg->Write(_T("flagsdlg_x"), (long)dlg.GetPosition().x);
190 cfg->Write(_T("flagsdlg_y"), (long)dlg.GetPosition().y);
191 cfg->Write(_T("flagsdlg_w"), (long)dlg.GetSize().x);
192 cfg->Write(_T("flagsdlg_h"), (long)dlg.GetSize().y);
193 }
194
195