added font and flags properties to wxrcedit

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8697 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2000-11-05 22:50:58 +00:00
parent f4b6093eee
commit a62da4c56f
7 changed files with 146 additions and 21 deletions

View File

@ -20,12 +20,16 @@
#include "wx/wx.h"
#include "wx/xml/xml.h"
#include "wx/tokenzr.h"
#include "wx/wx.h"
#include "wx/dialog.h"
#include "wx/checklst.h"
#include "pe_basic.h"
#include "pe_adv.h"
#include "xmlhelpr.h"
#include "editor.h"
#include "preview.h"
#include "wx/colordlg.h"
#include "wx/config.h"
@ -41,12 +45,21 @@ wxWindow* PropEditCtrlFont::CreateEditCtrl()
wxTreeItemId PropEditCtrlFont::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
{
wxTreeItemId ti = PropEditCtrlTxt::CreateTreeEntry(parent, pinfo);
m_PropFrame->AddSingleProp(PropertyInfo(_T("integer"), pinfo.Name + _T("/size"), wxEmptyString), &ti);
m_PropFrame->AddSingleProp(PropertyInfo(_T("text"), pinfo.Name + _T("/face"), wxEmptyString), &ti);
m_PropFrame->AddSingleProp(PropertyInfo(_T("choice"), pinfo.Name + _T("/style"), _T("normal,italic,slant")), &ti);
m_PropFrame->AddSingleProp(PropertyInfo(_T("choice"), pinfo.Name + _T("/weight"), _T("normal,light,bold")), &ti);
m_PropFrame->AddSingleProp(PropertyInfo(_T("choice"), pinfo.Name + _T("/family"), _T("default,decorative,roman,script,swiss,modern")), &ti);
m_PropFrame->AddSingleProp(PropertyInfo(_T("bool"), pinfo.Name + _T("/underlined"), wxEmptyString), &ti);
m_PropFrame->AddSingleProp(PropertyInfo(_T("text"), pinfo.Name + _T("/encoding"), wxEmptyString), &ti);
return ti;
}
BEGIN_EVENT_TABLE(PropEditCtrlChoice, PropEditCtrl)
EVT_CHOICE(-1, PropEditCtrlChoice::OnChoice)
END_EVENT_TABLE()
@ -54,8 +67,7 @@ END_EVENT_TABLE()
wxWindow* PropEditCtrlChoice::CreateEditCtrl()
{
m_Choice = new wxChoice(this, -1);
m_Choice->Append(_T("false"));
m_Choice->Append(_T("true"));
return m_Choice;
}
@ -63,22 +75,34 @@ wxWindow* PropEditCtrlChoice::CreateEditCtrl()
void PropEditCtrlChoice::ReadValue()
{
wxStringTokenizer tkn(m_PropInfo->MoreInfo, _T(","));
m_Choice->Clear();
while (tkn.HasMoreTokens())
m_Choice->Append(tkn.GetNextToken());
wxString sel = XmlReadValue(GetNode(), m_PropInfo->Name);
if (!!sel) m_Choice->SetStringSelection(sel);
}
void PropEditCtrlChoice::WriteValue()
{
XmlWriteValue(GetNode(), m_PropInfo->Name,
m_Choice->GetStringSelection());
}
void PropEditCtrlChoice::OnChoice(wxCommandEvent& event)
{
if (CanSave()) WriteValue();
}
void PropEditCtrlColor::OnDetails()
{
wxColour clr;
@ -100,3 +124,72 @@ void PropEditCtrlColor::OnDetails()
}
void PropEditCtrlFlags::OnDetails()
{
wxString t,txt = m_TextCtrl->GetValue();
wxArrayString arr;
size_t i;
int j;
wxStringTokenizer tkn(m_PropInfo->MoreInfo, _T(","));
while (tkn.HasMoreTokens())
arr.Add(tkn.GetNextToken());
wxConfigBase *cfg = wxConfigBase::Get();
wxDialog dlg(m_PropFrame, -1, _("Flags"),
wxPoint(cfg->Read(_T("flagsdlg_x"), -1), cfg->Read(_T("flagsdlg_y"), -1)),
wxSize(cfg->Read(_T("flagsdlg_w"), 300), cfg->Read(_T("flagsdlg_h"), 300)),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
wxSizer *sz = new wxBoxSizer(wxVERTICAL);
wxCheckListBox *lbox = new wxCheckListBox(&dlg, -1);
sz->Add(lbox, 1, wxEXPAND | wxALL, 10);
wxSizer *sz2 = new wxBoxSizer(wxHORIZONTAL);
wxButton *btnok = new wxButton(&dlg, wxID_OK, _("OK"));
btnok->SetDefault();
sz2->Add(btnok);
sz2->Add(new wxButton(&dlg, wxID_CANCEL, _("Cancel")), 0, wxLEFT, 10);
sz->Add(sz2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
dlg.SetSizer(sz);
dlg.SetAutoLayout(TRUE);
for (i = 0; i < arr.GetCount(); i++)
lbox->Append(arr[i]);
tkn.SetString(txt, _T("| "));
while (tkn.HasMoreTokens())
{
t = tkn.GetNextToken();
j = arr.Index(t);
if (j != wxNOT_FOUND) lbox->Check(j);
}
if (dlg.ShowModal() != wxID_OK) return;
txt.Empty();
for (i = 0; i < arr.GetCount(); i++)
if (lbox->IsChecked(i))
txt << arr[i] << _T('|');
if (!txt.IsEmpty()) txt.RemoveLast();
m_TextCtrl->SetValue(txt);
WriteValue();
cfg->Write(_T("flagsdlg_x"), (long)dlg.GetPosition().x);
cfg->Write(_T("flagsdlg_y"), (long)dlg.GetPosition().y);
cfg->Write(_T("flagsdlg_w"), (long)dlg.GetSize().x);
cfg->Write(_T("flagsdlg_h"), (long)dlg.GetSize().y);
}

View File

@ -64,5 +64,18 @@ class PropEditCtrlColor : public PropEditCtrlTxt
class PropEditCtrlFlags : public PropEditCtrlTxt
{
public:
PropEditCtrlFlags(PropertiesFrame *propFrame)
: PropEditCtrlTxt(propFrame) {}
virtual bool HasDetails() { return TRUE; }
virtual void OnDetails();
};
#endif

View File

@ -49,6 +49,9 @@ void PropEditCtrl::OnButtonClear(wxCommandEvent& event)
void PropEditCtrl::BeginEdit(const wxRect& rect, wxTreeItemId ti)
{
m_PropInfo = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
m_TreeItem = ti;
m_CanSave = FALSE;
if (!m_Created)
{
@ -68,9 +71,6 @@ void PropEditCtrl::BeginEdit(const wxRect& rect, wxTreeItemId ti)
m_TheCtrl->SetFocus();
m_PropInfo = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
m_TreeItem = ti;
SetSize(rect.x, rect.y, rect.width, rect.height);
Show(TRUE);
ReadValue();

View File

@ -48,7 +48,7 @@ class PropsTree: public wxRemotelyScrolledTreeCtrl
// Reset the device origin since it may have been set
dc.SetDeviceOrigin(0, 0);
wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
wxPen pen(wxColour(_T("BLACK")), 1, wxSOLID);
dc.SetPen(pen);
dc.SetBrush(* wxTRANSPARENT_BRUSH);
@ -221,7 +221,7 @@ PropertiesFrame::PropertiesFrame()
m_EditCtrls.Put(_T("coord"), new PropEditCtrlCoord(this));
m_EditCtrls.Put(_T("color"), new PropEditCtrlColor(this));
m_EditCtrls.Put(_T("dimension"), new PropEditCtrlDim(this));
m_EditCtrls.Put(_T("flags"), new PropEditCtrlTxt(this));
m_EditCtrls.Put(_T("flags"), new PropEditCtrlFlags(this));
m_EditCtrls.Put(_T("integer"), new PropEditCtrlInt(this));
m_EditCtrls.Put(_T("not_implemented"), new PropEditCtrlNull(this));
m_EditCtrls.Put(_T("text"), new PropEditCtrlTxt(this));
@ -280,10 +280,12 @@ void PropertiesFrame::AddProps(PropertyInfoArray& plist)
void PropertiesFrame::AddSingleProp(const PropertyInfo& pinfo)
void PropertiesFrame::AddSingleProp(const PropertyInfo& pinfo, wxTreeItemId *root)
{
PropEditCtrl *pec = (PropEditCtrl*)m_EditCtrls.Get(pinfo.Type);
wxTreeItemId tid = m_tree->GetRootItem();
wxTreeItemId tid;
if (root != NULL) tid = *root;
else tid = m_tree->GetRootItem();
if (pec == NULL)
wxLogError(_("Unknown property type '%s'!"), pinfo.Type.c_str());

View File

@ -32,7 +32,7 @@ class PropertiesFrame : public wxFrame
void ClearProps();
void AddProps(PropertyInfoArray& plist);
void AddSingleProp(const PropertyInfo& pinfo);
void AddSingleProp(const PropertyInfo& pinfo, wxTreeItemId *root = NULL);
static PropertiesFrame *Get();

View File

@ -403,7 +403,7 @@ void wxTreeCompanionWindow::OnPaint(wxPaintEvent& event)
if (!m_treeCtrl)
return;
wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
wxPen pen(wxColour(_T("BLACK")), 1, wxSOLID);
dc.SetPen(pen);
dc.SetBrush(* wxTRANSPARENT_BRUSH);
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));

View File

@ -55,19 +55,36 @@ wxXmlNode *XmlFindNode(wxXmlNode *parent, const wxString& path)
wxXmlNode *XmlCreateNode(wxXmlNode *parent, const wxString& name)
{
wxXmlNode *n;
wxString nm;
wxStringTokenizer tkn(name, _T("/"));
n = parent;
while (tkn.HasMoreTokens())
{
parent = n;
nm = tkn.GetNextToken();
n = XmlFindNodeSimple(parent, nm);
if (n) continue;
// n == NULL:
n = new wxXmlNode(wxXML_ELEMENT_NODE, nm);
parent->AddChild(n);
}
n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString));
return n;
}
void XmlWriteValue(wxXmlNode *parent, const wxString& name, const wxString& value)
{
wxXmlNode *n = XmlFindNode(parent, name);
if (n == NULL)
{
wxString pname = name.BeforeLast(_T('/'));
if (pname.IsEmpty()) pname = name;
wxXmlNode *p = XmlFindNode(parent, pname);
if (p == NULL) p = parent;
n = new wxXmlNode(wxXML_ELEMENT_NODE, name.AfterLast(_T('/')));
p->AddChild(n);
n->AddChild(new wxXmlNode(wxXML_TEXT_NODE, wxEmptyString));
}
if (n == NULL)
n = XmlCreateNode(parent, name);
n = n->GetChildren();