added XML resources library
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7831 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# $Id$
|
||||
|
||||
CONTRIB_SUBDIRS=ogl mmedia stc
|
||||
CONTRIB_SUBDIRS=ogl mmedia stc xml
|
||||
|
||||
all:
|
||||
@for d in $(CONTRIB_SUBDIRS); do (cd $$d && $(MAKE)); done
|
||||
|
||||
31
contrib/src/xml/Makefile.in
Normal file
31
contrib/src/xml/Makefile.in
Normal file
@@ -0,0 +1,31 @@
|
||||
# $Id$
|
||||
|
||||
top_srcdir = @top_srcdir@/..
|
||||
top_builddir = ../../..
|
||||
libsrc_dir = contrib/src/xml
|
||||
|
||||
TARGET_LIBNAME=libwxxml
|
||||
|
||||
LIBVERSION_CURRENT=0
|
||||
LIBVERSION_REVISION=1
|
||||
LIBVERSION_AGE=0
|
||||
|
||||
HEADER_PATH=$(top_srcdir)/contrib/include/wx
|
||||
HEADER_SUBDIR=xml
|
||||
|
||||
HEADERS=xh_all.h xh_bttn.h xh_chckb.h xh_chckl.h xh_choic.h xh_combo.h \
|
||||
xh_dlg.h xh_gauge.h xh_html.h xh_menu.h xh_notbk.h xh_panel.h \
|
||||
xh_radbt.h xh_radbx.h xh_sizer.h xh_slidr.h xh_spin.h xh_stbmp.h \
|
||||
xh_sttxt.h xh_text.h xml.h xmlio.h xmlres.h
|
||||
|
||||
|
||||
OBJECTS=xml.o xmlbin.o xmlbinz.o xmlpars.o xmlres.o xmlrsall.o \
|
||||
xh_bttn.o xh_chckb.o xh_chckl.o xh_choic.o xh_combo.o xh_dlg.o \
|
||||
xh_gauge.o xh_html.o xh_menu.o xh_notbk.o xh_panel.o xh_radbt.o \
|
||||
xh_radbx.o xh_sizer.o xh_slidr.o xh_spin.o xh_stbmp.o xh_sttxt.o \
|
||||
xh_text.o \
|
||||
|
||||
APPEXTRADEFS=-I$(top_srcdir)/contrib/include
|
||||
|
||||
include $(top_builddir)/src/makelib.env
|
||||
|
||||
47
contrib/src/xml/xh_bttn.cpp
Normal file
47
contrib/src/xml/xh_bttn.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_bttn.cpp
|
||||
// Purpose: XML resource for buttons
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_bttn.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_bttn.h"
|
||||
#include "wx/button.h"
|
||||
|
||||
|
||||
wxObject *wxButtonXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxButton *button = new wxButton(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("label")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle());
|
||||
button->SetName(GetName());
|
||||
if (GetBool(_T("default"), 0) == 1) button->SetDefault();
|
||||
SetupWindow(button);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxButtonXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("button");
|
||||
}
|
||||
|
||||
|
||||
56
contrib/src/xml/xh_chckb.cpp
Normal file
56
contrib/src/xml/xh_chckb.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_chckb.cpp
|
||||
// Purpose: XML resource for wxCheckBox
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_chckb.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_chckb.h"
|
||||
#include "wx/checkbox.h"
|
||||
|
||||
#if wxUSE_CHECKBOX
|
||||
|
||||
wxCheckBoxXmlHandler::wxCheckBoxXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
}
|
||||
|
||||
wxObject *wxCheckBoxXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxCheckBox *control = new wxCheckBox(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("label")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
control->SetValue( GetBool( _T("checked")));
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxCheckBoxXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("checkbox");
|
||||
}
|
||||
|
||||
#endif
|
||||
115
contrib/src/xml/xh_chckl.cpp
Normal file
115
contrib/src/xml/xh_chckl.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_chckl.cpp
|
||||
// Purpose: XML resource for wxCheckList
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_chckl.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_chckl.h"
|
||||
#include "wx/checklst.h"
|
||||
|
||||
wxCheckListXmlHandler::wxCheckListXmlHandler()
|
||||
: wxXmlResourceHandler(), m_InsideBox(FALSE)
|
||||
{
|
||||
// no styles
|
||||
}
|
||||
|
||||
wxObject *wxCheckListXmlHandler::DoCreateResource()
|
||||
{
|
||||
if( m_Node->GetName() == _T("checklist"))
|
||||
{
|
||||
// need to build the list of strings from children
|
||||
m_InsideBox = TRUE;
|
||||
CreateChildren( NULL, TRUE /* only this handler */);
|
||||
wxString *strings = (wxString *) NULL;
|
||||
if( strList.GetCount() > 0 )
|
||||
{
|
||||
strings = new wxString[strList.GetCount()];
|
||||
int count = strList.GetCount();
|
||||
for( int i = 0; i < count; i++ )
|
||||
strings[i]=strList[i];
|
||||
}
|
||||
|
||||
|
||||
wxCheckListBox *control = new wxCheckListBox(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetPosition(), GetSize(),
|
||||
strList.GetCount(),
|
||||
strings,
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
// step through children myself (again.)
|
||||
wxXmlNode *n = GetParamNode(_T("children"));
|
||||
if (n) n = n->GetChildren();
|
||||
int i = 0;
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() != wxXML_ELEMENT_NODE ||
|
||||
n->GetName() != _T("item" ))
|
||||
{ n = n->GetNext(); continue; }
|
||||
|
||||
// checking boolean is a bit ugly here (see GetBool() )
|
||||
wxString v = n->GetPropVal(_T("checked"), wxEmptyString);
|
||||
v.MakeLower();
|
||||
if (v)
|
||||
{
|
||||
if( v == _T("1") || v == _T("t") || v == _T("yes") ||
|
||||
v == _T("on") || v == _T("true") )
|
||||
{
|
||||
control->Check( i, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
n = n->GetNext();
|
||||
}
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
if( strings != NULL )
|
||||
delete [] strings;
|
||||
strList.Clear(); // dump the strings
|
||||
|
||||
return control;
|
||||
}
|
||||
else
|
||||
{
|
||||
// on the inside now.
|
||||
// handle <item checked="boolean">Label</item>
|
||||
|
||||
// add to the list
|
||||
strList.Add( GetNodeContent(m_Node) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxCheckListXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return( node->GetName() == _T("checklist") ||
|
||||
( m_InsideBox &&
|
||||
node->GetName() == _T("item" ))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
95
contrib/src/xml/xh_choic.cpp
Normal file
95
contrib/src/xml/xh_choic.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_choic.cpp
|
||||
// Purpose: XML resource for wxChoice
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_choic.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_choic.h"
|
||||
#include "wx/choice.h"
|
||||
|
||||
wxChoiceXmlHandler::wxChoiceXmlHandler()
|
||||
: wxXmlResourceHandler() , m_InsideBox(FALSE)
|
||||
{
|
||||
ADD_STYLE(wxCB_SORT);
|
||||
}
|
||||
|
||||
wxObject *wxChoiceXmlHandler::DoCreateResource()
|
||||
{
|
||||
if( m_Node->GetName() == _T("choice"))
|
||||
{
|
||||
// find the selection
|
||||
long selection = GetLong( _T("selection"), -1 );
|
||||
|
||||
// need to build the list of strings from children
|
||||
m_InsideBox = TRUE;
|
||||
CreateChildren( NULL, TRUE /* only this handler */);
|
||||
wxString *strings = (wxString *) NULL;
|
||||
if( strList.GetCount() > 0 )
|
||||
{
|
||||
strings = new wxString[strList.GetCount()];
|
||||
int count = strList.GetCount();
|
||||
for( int i = 0; i < count; i++ )
|
||||
strings[i]=strList[i];
|
||||
}
|
||||
|
||||
|
||||
wxChoice *control = new wxChoice(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetPosition(), GetSize(),
|
||||
strList.GetCount(),
|
||||
strings,
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
if( selection != -1 )
|
||||
control->SetSelection( selection );
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
if( strings != NULL )
|
||||
delete [] strings;
|
||||
strList.Clear(); // dump the strings
|
||||
|
||||
return control;
|
||||
}
|
||||
else
|
||||
{
|
||||
// on the inside now.
|
||||
// handle <item>Label</item>
|
||||
|
||||
// add to the list
|
||||
strList.Add( GetNodeContent(m_Node) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxChoiceXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return( node->GetName() == _T("choice") ||
|
||||
( m_InsideBox &&
|
||||
node->GetName() == _T("item" ))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
101
contrib/src/xml/xh_combo.cpp
Normal file
101
contrib/src/xml/xh_combo.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_combo.cpp
|
||||
// Purpose: XML resource for wxRadioBox
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_combo.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_combo.h"
|
||||
#include "wx/combobox.h"
|
||||
|
||||
#if wxUSE_COMBOBOX
|
||||
|
||||
wxComboBoxXmlHandler::wxComboBoxXmlHandler()
|
||||
: wxXmlResourceHandler() , m_InsideBox(FALSE)
|
||||
{
|
||||
ADD_STYLE(wxCB_SIMPLE);
|
||||
ADD_STYLE(wxCB_SORT);
|
||||
ADD_STYLE(wxCB_READONLY);
|
||||
ADD_STYLE(wxCB_DROPDOWN);
|
||||
}
|
||||
|
||||
wxObject *wxComboBoxXmlHandler::DoCreateResource()
|
||||
{
|
||||
if( m_Node->GetName() == _T("combobox"))
|
||||
{
|
||||
// find the selection
|
||||
long selection = GetLong( _T("selection"), -1 );
|
||||
|
||||
// need to build the list of strings from children
|
||||
m_InsideBox = TRUE;
|
||||
CreateChildren( NULL, TRUE /* only this handler */);
|
||||
wxString *strings = (wxString *) NULL;
|
||||
if( strList.GetCount() > 0 )
|
||||
{
|
||||
strings = new wxString[strList.GetCount()];
|
||||
int count = strList.GetCount();
|
||||
for( int i = 0; i < count; i++ )
|
||||
strings[i]=strList[i];
|
||||
}
|
||||
|
||||
|
||||
wxComboBox *control = new wxComboBox(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("value")),
|
||||
GetPosition(), GetSize(),
|
||||
strList.GetCount(),
|
||||
strings,
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
if( selection != -1 )
|
||||
control->SetSelection( selection );
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
if( strings != NULL )
|
||||
delete [] strings;
|
||||
strList.Clear(); // dump the strings
|
||||
|
||||
return control;
|
||||
}
|
||||
else
|
||||
{
|
||||
// on the inside now.
|
||||
// handle <item>Label</item>
|
||||
|
||||
// add to the list
|
||||
strList.Add( GetNodeContent(m_Node) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxComboBoxXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return( node->GetName() == _T("combobox") ||
|
||||
( m_InsideBox &&
|
||||
node->GetName() == _T("item" ))
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
75
contrib/src/xml/xh_dlg.cpp
Normal file
75
contrib/src/xml/xh_dlg.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_dlg.cpp
|
||||
// Purpose: XML resource for dialogs
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_dlg.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_dlg.h"
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
|
||||
|
||||
wxDialogXmlHandler::wxDialogXmlHandler() : wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE(wxSTAY_ON_TOP);
|
||||
ADD_STYLE(wxCAPTION);
|
||||
ADD_STYLE(wxDEFAULT_DIALOG_STYLE);
|
||||
ADD_STYLE(wxTHICK_FRAME);
|
||||
ADD_STYLE(wxSYSTEM_MENU);
|
||||
ADD_STYLE(wxRESIZE_BORDER);
|
||||
ADD_STYLE(wxRESIZE_BOX);
|
||||
ADD_STYLE(wxDIALOG_MODAL);
|
||||
ADD_STYLE(wxDIALOG_MODELESS);
|
||||
|
||||
ADD_STYLE(wxNO_3D);
|
||||
ADD_STYLE(wxTAB_TRAVERSAL);
|
||||
ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxDialogXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxDialog *dlg = wxDynamicCast(m_Instance, wxDialog);
|
||||
|
||||
wxASSERT_MSG(dlg, _("XML resource: Cannot create dialog without instance."));
|
||||
|
||||
dlg->Create(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("title")),
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
GetStyle(_T("style"), wxDEFAULT_DIALOG_STYLE),
|
||||
GetName());
|
||||
dlg->SetClientSize(GetSize());
|
||||
dlg->Move(GetPosition());
|
||||
SetupWindow(dlg);
|
||||
|
||||
CreateChildren(dlg);
|
||||
|
||||
return dlg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxDialogXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("dialog");
|
||||
}
|
||||
|
||||
|
||||
73
contrib/src/xml/xh_gauge.cpp
Normal file
73
contrib/src/xml/xh_gauge.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_gauge.cpp
|
||||
// Purpose: XML resource for wxGauge
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_gauge.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_gauge.h"
|
||||
#include "wx/gauge.h"
|
||||
|
||||
#if wxUSE_GAUGE
|
||||
|
||||
wxGaugeXmlHandler::wxGaugeXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxGA_HORIZONTAL );
|
||||
ADD_STYLE( wxGA_VERTICAL );
|
||||
ADD_STYLE( wxGA_PROGRESSBAR );
|
||||
ADD_STYLE( wxGA_SMOOTH ); // windows only
|
||||
}
|
||||
|
||||
wxObject *wxGaugeXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxGauge *control = new wxGauge(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetLong( _T("range"), wxGAUGE_DEFAULT_RANGE),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
if( HasParam( _T("value") ))
|
||||
{
|
||||
control->SetValue( GetLong( _T("value") ));
|
||||
}
|
||||
if( HasParam( _T("shadow") ))
|
||||
{
|
||||
control->SetShadowWidth( GetLong( _T("shadow") ));
|
||||
}
|
||||
if( HasParam( _T("bezel") ))
|
||||
{
|
||||
control->SetBezelFace( GetLong( _T("bezel") ));
|
||||
}
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxGaugeXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("gauge");
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_GAUGE
|
||||
71
contrib/src/xml/xh_html.cpp
Normal file
71
contrib/src/xml/xh_html.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_html.cpp
|
||||
// Purpose: XML resource for wxHtmlWindow
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_html.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_html.h"
|
||||
|
||||
#if wxUSE_HTML
|
||||
|
||||
#include "wx/html/htmlwin.h"
|
||||
|
||||
|
||||
wxHtmlWindowXmlHandler::wxHtmlWindowXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxHW_SCROLLBAR_NEVER );
|
||||
ADD_STYLE( wxHW_SCROLLBAR_AUTO );
|
||||
}
|
||||
|
||||
wxObject *wxHtmlWindowXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxHtmlWindow *control = new wxHtmlWindow(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle( _T("style" ), wxHW_SCROLLBAR_AUTO),
|
||||
GetName()
|
||||
);
|
||||
|
||||
if( HasParam( _T("borders") ))
|
||||
{
|
||||
control->SetBorders( GetLong( _T("borders" )));
|
||||
}
|
||||
|
||||
if( HasParam( _T("url") ))
|
||||
{
|
||||
control->LoadPage( GetParamValue( _T("url" )));
|
||||
}
|
||||
else if( HasParam( _T("htmlcode") ))
|
||||
{
|
||||
control->SetPage( GetText(_T("htmlcode")) );
|
||||
}
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxHtmlWindowXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("htmlwindow");
|
||||
}
|
||||
|
||||
#endif // wxUSE_HTML
|
||||
126
contrib/src/xml/xh_menu.cpp
Normal file
126
contrib/src/xml/xh_menu.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_menu.cpp
|
||||
// Purpose: XML resource for menus and menubars
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_menu.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_menu.h"
|
||||
#include "wx/menu.h"
|
||||
|
||||
|
||||
wxMenuXmlHandler::wxMenuXmlHandler() :
|
||||
wxXmlResourceHandler(), m_InsideMenu(FALSE)
|
||||
{
|
||||
ADD_STYLE(wxMENU_TEAROFF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxMenuXmlHandler::DoCreateResource()
|
||||
{
|
||||
if (m_Node->GetName() == _T("menu"))
|
||||
{
|
||||
wxMenu *menu = new wxMenu(GetStyle());
|
||||
wxString title = GetText(_T("label"));
|
||||
wxString help = GetText(_T("help"));
|
||||
|
||||
bool oldins = m_InsideMenu;
|
||||
m_InsideMenu = TRUE;
|
||||
CreateChildren(menu, TRUE/*only this handler*/);
|
||||
m_InsideMenu = oldins;
|
||||
|
||||
wxMenuBar *p_bar = wxDynamicCast(m_Parent, wxMenuBar);
|
||||
if (p_bar)
|
||||
p_bar->Append(menu, title);
|
||||
else
|
||||
{
|
||||
wxMenu *p_menu = wxDynamicCast(m_Parent, wxMenu);
|
||||
if (p_menu)
|
||||
p_menu->Append(GetID(), title, menu, help);
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
wxMenu *p_menu = wxDynamicCast(m_Parent, wxMenu);
|
||||
|
||||
if (m_Node->GetName() == _T("separator"))
|
||||
p_menu->AppendSeparator();
|
||||
else if (m_Node->GetName() == _T("break"))
|
||||
p_menu->Break();
|
||||
else
|
||||
{
|
||||
int id = GetID();
|
||||
bool checkable = GetBool(_T("checkable"));
|
||||
p_menu->Append(id, GetText(_T("label")),
|
||||
GetText(_T("help")), checkable);
|
||||
if (id != -1)
|
||||
{
|
||||
p_menu->Enable(id, GetBool(_T("enabled"), TRUE));
|
||||
if (checkable) p_menu->Check(id, GetBool(_T("checked")));
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("menu") ||
|
||||
(m_InsideMenu &&
|
||||
(node->GetName() == _T("menuitem") ||
|
||||
node->GetName() == _T("break") ||
|
||||
node->GetName() == _T("separator"))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE(wxMB_DOCKABLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxMenuBarXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxMenuBar *menubar = new wxMenuBar(GetStyle());
|
||||
CreateChildren(menubar);
|
||||
return menubar;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("menubar");
|
||||
}
|
||||
|
||||
95
contrib/src/xml/xh_notbk.cpp
Normal file
95
contrib/src/xml/xh_notbk.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_notbk.cpp
|
||||
// Purpose: XML resource for wxBoxSizer
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_notbk.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_notbk.h"
|
||||
|
||||
#if wxUSE_NOTEBOOK
|
||||
|
||||
#include "wx/log.h"
|
||||
#include "wx/notebook.h"
|
||||
|
||||
wxNotebookXmlHandler::wxNotebookXmlHandler()
|
||||
: wxXmlResourceHandler(), m_IsInside(FALSE), m_Notebook(NULL)
|
||||
{
|
||||
ADD_STYLE(wxNB_FIXEDWIDTH);
|
||||
ADD_STYLE(wxNB_LEFT);
|
||||
ADD_STYLE(wxNB_RIGHT);
|
||||
ADD_STYLE(wxNB_BOTTOM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxNotebookXmlHandler::DoCreateResource()
|
||||
{
|
||||
if (m_Node->GetName() == _T("page"))
|
||||
{
|
||||
wxXmlNode *n = GetParamNode(_T("child"))->GetChildren();
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE)
|
||||
{
|
||||
bool old_ins = m_IsInside;
|
||||
m_IsInside = FALSE;
|
||||
m_IsInside = old_ins;
|
||||
wxObject *item = CreateResFromNode(n, m_Notebook, NULL);
|
||||
wxWindow *wnd = wxDynamicCast(item, wxWindow);
|
||||
|
||||
if (wnd)
|
||||
m_Notebook->AddPage(wnd, GetText(_T("label")),
|
||||
GetBool(_T("selected"), 0));
|
||||
else
|
||||
wxLogError(_T("Error in resource."));
|
||||
return wnd;
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
wxLogError(_T("Error in resource: no control within notebook's <page> tag."));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
else {
|
||||
wxNotebook *nb = new wxNotebook(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle( _T("style" )),
|
||||
GetName());
|
||||
|
||||
wxNotebook *old_par = m_Notebook;
|
||||
m_Notebook = nb;
|
||||
bool old_ins = m_IsInside;
|
||||
m_IsInside = TRUE;
|
||||
CreateChildren(m_Notebook, TRUE/*only this handler*/);
|
||||
m_IsInside = old_ins;
|
||||
m_Notebook = old_par;
|
||||
|
||||
return nb;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return ((!m_IsInside && node->GetName() == _T("notebook")) ||
|
||||
(m_IsInside && node->GetName() == _T("page")));
|
||||
}
|
||||
|
||||
#endif
|
||||
52
contrib/src/xml/xh_panel.cpp
Normal file
52
contrib/src/xml/xh_panel.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_panel.cpp
|
||||
// Purpose: XML resource for panels
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_panel.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_panel.h"
|
||||
#include "wx/panel.h"
|
||||
|
||||
|
||||
wxPanelXmlHandler::wxPanelXmlHandler() : wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE(wxNO_3D);
|
||||
ADD_STYLE(wxTAB_TRAVERSAL);
|
||||
ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxPanelXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxPanel *panel = new wxPanel(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(_T("style"), 0),
|
||||
GetName());
|
||||
SetupWindow(panel);
|
||||
CreateChildren(panel);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
bool wxPanelXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("panel");
|
||||
}
|
||||
65
contrib/src/xml/xh_radbt.cpp
Normal file
65
contrib/src/xml/xh_radbt.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_radbt.cpp
|
||||
// Purpose: XML resource for wxRadioButton
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_radbt.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_radbt.h"
|
||||
#include "wx/radiobut.h"
|
||||
|
||||
#if wxUSE_RADIOBOX
|
||||
|
||||
wxRadioButtonXmlHandler::wxRadioButtonXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxRB_GROUP );
|
||||
}
|
||||
|
||||
wxObject *wxRadioButtonXmlHandler::DoCreateResource()
|
||||
{
|
||||
/* BOBM - implementation note.
|
||||
* once the wxBitmapRadioButton is implemented.
|
||||
* look for a bitmap property. If not null,
|
||||
* make it a wxBitmapRadioButton instead of the
|
||||
* normal radio button.
|
||||
*/
|
||||
|
||||
wxRadioButton *control = new wxRadioButton(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("label")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
control->SetValue( GetBool(_T("value"), 0));
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxRadioButtonXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("radiobutton");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
102
contrib/src/xml/xh_radbx.cpp
Normal file
102
contrib/src/xml/xh_radbx.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_radbx.cpp
|
||||
// Purpose: XML resource for wxRadioBox
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_radbx.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_radbx.h"
|
||||
#include "wx/radiobox.h"
|
||||
|
||||
#if wxUSE_RADIOBOX
|
||||
|
||||
wxRadioBoxXmlHandler::wxRadioBoxXmlHandler()
|
||||
: wxXmlResourceHandler() , m_InsideBox(FALSE)
|
||||
{
|
||||
ADD_STYLE(wxRA_SPECIFY_COLS);
|
||||
ADD_STYLE(wxRA_HORIZONTAL);
|
||||
ADD_STYLE(wxRA_SPECIFY_ROWS);
|
||||
ADD_STYLE(wxRA_VERTICAL);
|
||||
}
|
||||
|
||||
wxObject *wxRadioBoxXmlHandler::DoCreateResource()
|
||||
{
|
||||
if( m_Node->GetName() == _T("radiobox"))
|
||||
{
|
||||
// find the selection
|
||||
long selection = GetLong( _T("selection"), -1 );
|
||||
|
||||
// need to build the list of strings from children
|
||||
m_InsideBox = TRUE;
|
||||
CreateChildren( NULL, TRUE /* only this handler */, GetParamNode(_T("buttons")));
|
||||
wxString *strings = (wxString *) NULL;
|
||||
if( strList.GetCount() > 0 )
|
||||
{
|
||||
strings = new wxString[strList.GetCount()];
|
||||
int count = strList.GetCount();
|
||||
for( int i = 0; i < count; i++ )
|
||||
strings[i]=strList[i];
|
||||
}
|
||||
|
||||
|
||||
wxRadioBox *control = new wxRadioBox(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("label")),
|
||||
GetPosition(), GetSize(),
|
||||
strList.GetCount(),
|
||||
strings,
|
||||
GetLong( _T("dimension"), 0 ),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
if( selection != -1 )
|
||||
control->SetSelection( selection );
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
if( strings != NULL )
|
||||
delete [] strings;
|
||||
strList.Clear(); // dump the strings
|
||||
|
||||
return control;
|
||||
}
|
||||
else
|
||||
{
|
||||
// on the inside now.
|
||||
// handle <item selected="boolean">Label</item>
|
||||
|
||||
// add to the list
|
||||
strList.Add( GetNodeContent(m_Node) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxRadioBoxXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return( node->GetName() == _T("radiobox") ||
|
||||
( m_InsideBox &&
|
||||
node->GetName() == _T("item" ))
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
195
contrib/src/xml/xh_sizer.cpp
Normal file
195
contrib/src/xml/xh_sizer.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_sizer.cpp
|
||||
// Purpose: XML resource for wxBoxSizer
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_sizer.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_sizer.h"
|
||||
#include "wx/sizer.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/statbox.h"
|
||||
#include "wx/notebook.h"
|
||||
|
||||
wxSizerXmlHandler::wxSizerXmlHandler()
|
||||
: wxXmlResourceHandler(), m_IsInside(FALSE), m_ParentSizer(NULL)
|
||||
{
|
||||
ADD_STYLE(wxHORIZONTAL);
|
||||
ADD_STYLE(wxVERTICAL);
|
||||
|
||||
// and flags
|
||||
ADD_STYLE(wxLEFT);
|
||||
ADD_STYLE(wxRIGHT);
|
||||
ADD_STYLE(wxTOP);
|
||||
ADD_STYLE(wxBOTTOM);
|
||||
ADD_STYLE(wxNORTH);
|
||||
ADD_STYLE(wxSOUTH);
|
||||
ADD_STYLE(wxEAST);
|
||||
ADD_STYLE(wxWEST);
|
||||
ADD_STYLE(wxALL);
|
||||
|
||||
ADD_STYLE(wxGROW);
|
||||
ADD_STYLE(wxEXPAND);
|
||||
ADD_STYLE(wxSHAPED);
|
||||
ADD_STYLE(wxSTRETCH_NOT);
|
||||
|
||||
ADD_STYLE(wxALIGN_CENTER);
|
||||
ADD_STYLE(wxALIGN_CENTRE);
|
||||
ADD_STYLE(wxALIGN_LEFT);
|
||||
ADD_STYLE(wxALIGN_TOP);
|
||||
ADD_STYLE(wxALIGN_RIGHT);
|
||||
ADD_STYLE(wxALIGN_BOTTOM);
|
||||
ADD_STYLE(wxALIGN_CENTER_HORIZONTAL);
|
||||
ADD_STYLE(wxALIGN_CENTRE_HORIZONTAL);
|
||||
ADD_STYLE(wxALIGN_CENTER_VERTICAL);
|
||||
ADD_STYLE(wxALIGN_CENTRE_VERTICAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxSizerXmlHandler::DoCreateResource()
|
||||
{
|
||||
if (m_Node->GetName() == _T("sizeritem"))
|
||||
{
|
||||
wxXmlNode *n = GetParamNode(_T("window"))->GetChildren();
|
||||
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE)
|
||||
{
|
||||
bool old_ins = m_IsInside;
|
||||
m_IsInside = FALSE;
|
||||
wxObject *item = CreateResFromNode(n, m_Parent, NULL);
|
||||
m_IsInside = old_ins;
|
||||
wxSizer *sizer = wxDynamicCast(item, wxSizer);
|
||||
wxWindow *wnd = wxDynamicCast(item, wxWindow);
|
||||
|
||||
if (sizer)
|
||||
m_ParentSizer->Add(sizer, GetLong(_T("option")),
|
||||
GetStyle(_T("flag")), GetLong(_T("border")));
|
||||
else if (wnd)
|
||||
m_ParentSizer->Add(wnd, GetLong(_T("option")),
|
||||
GetStyle(_T("flag")), GetLong(_T("border")));
|
||||
else
|
||||
wxLogError(_T("Error in resource."));
|
||||
|
||||
return item;
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
wxLogError(_T("Error in resource: no control/sizer within sizer's <item> tag."));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
else if (m_Node->GetName() == _T("spacer"))
|
||||
{
|
||||
wxCHECK_MSG(m_ParentSizer, NULL, _T("Incorrect syntax of XML resource: spacer not within sizer!"));
|
||||
wxSize sz = GetSize();
|
||||
m_ParentSizer->Add(sz.x, sz.y,
|
||||
GetLong(_T("option")), GetStyle(_T("flag")), GetLong(_T("border")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if wxUSE_NOTEBOOK
|
||||
else if (m_Node->GetName() == _T("notebooksizer"))
|
||||
{
|
||||
wxCHECK_MSG(m_ParentSizer, NULL, _T("Incorrect syntax of XML resource: notebooksizer not within sizer!"));
|
||||
|
||||
wxSizer *old_par = m_ParentSizer;
|
||||
m_ParentSizer = NULL;
|
||||
|
||||
wxNotebook *nb = NULL;
|
||||
wxObject *item;
|
||||
wxXmlNode *n = GetParamNode(_T("window"))->GetChildren();
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE)
|
||||
{
|
||||
item = CreateResFromNode(n, m_Parent, NULL);
|
||||
nb = wxDynamicCast(item, wxNotebook);
|
||||
break;
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
|
||||
m_ParentSizer = old_par;
|
||||
|
||||
wxCHECK_MSG(nb, NULL, _T("Incorrect syntax of XML resource: notebooksizer must contain a notebook!"));
|
||||
return new wxNotebookSizer(nb);
|
||||
}
|
||||
#endif
|
||||
|
||||
else {
|
||||
wxSizer *sizer = NULL;
|
||||
|
||||
wxXmlNode *parentNode = m_Node->GetParent()->GetParent();
|
||||
|
||||
wxCHECK_MSG(m_ParentSizer != NULL ||
|
||||
((parentNode->GetName() == _T("panel") ||
|
||||
parentNode->GetName() == _T("dialog")) &&
|
||||
parentNode->GetType() == wxXML_ELEMENT_NODE), NULL,
|
||||
_T("Incorrect use of sizer: parent is not 'dialog' or 'panel'."));
|
||||
|
||||
if (m_Node->GetName() == _T("boxsizer"))
|
||||
sizer = new wxBoxSizer(GetStyle(_T("orient"), wxHORIZONTAL));
|
||||
|
||||
else if (m_Node->GetName() == _T("staticboxsizer"))
|
||||
{
|
||||
sizer = new wxStaticBoxSizer(
|
||||
new wxStaticBox(m_ParentAsWindow, -1, GetText(_T("label"))),
|
||||
GetStyle(_T("orient"), wxHORIZONTAL));
|
||||
}
|
||||
|
||||
wxSizer *old_par = m_ParentSizer;
|
||||
m_ParentSizer = sizer;
|
||||
bool old_ins = m_IsInside;
|
||||
m_IsInside = TRUE;
|
||||
CreateChildren(m_Parent, TRUE/*only this handler*/);
|
||||
m_IsInside = old_ins;
|
||||
m_ParentSizer = old_par;
|
||||
|
||||
if (m_ParentSizer == NULL) // setup window:
|
||||
{
|
||||
m_ParentAsWindow->SetAutoLayout(TRUE);
|
||||
m_ParentAsWindow->SetSizer(sizer);
|
||||
|
||||
wxXmlNode *nd = m_Node;
|
||||
m_Node = parentNode;
|
||||
if (GetSize() == wxDefaultSize)
|
||||
sizer->Fit(m_ParentAsWindow);
|
||||
m_Node = nd;
|
||||
|
||||
if (m_ParentAsWindow->GetWindowStyle() & (wxRESIZE_BOX | wxRESIZE_BORDER))
|
||||
sizer->SetSizeHints(m_ParentAsWindow);
|
||||
}
|
||||
|
||||
return sizer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxSizerXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return ((!m_IsInside && node->GetName() == _T("boxsizer")) ||
|
||||
(!m_IsInside && node->GetName() == _T("staticboxsizer")) ||
|
||||
#if wxUSE_NOTEBOOK
|
||||
(!m_IsInside && node->GetName() == _T("notebooksizer")) ||
|
||||
#endif
|
||||
(m_IsInside && node->GetName() == _T("sizeritem")) ||
|
||||
(m_IsInside && node->GetName() == _T("spacer")));
|
||||
}
|
||||
93
contrib/src/xml/xh_slidr.cpp
Normal file
93
contrib/src/xml/xh_slidr.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_slidr.cpp
|
||||
// Purpose: XML resource for wxSlider
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_slidr.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_slidr.h"
|
||||
#include "wx/slider.h"
|
||||
|
||||
#if wxUSE_SLIDER
|
||||
|
||||
wxSliderXmlHandler::wxSliderXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxSL_HORIZONTAL );
|
||||
ADD_STYLE( wxSL_VERTICAL );
|
||||
ADD_STYLE( wxSL_AUTOTICKS );
|
||||
ADD_STYLE( wxSL_LABELS );
|
||||
ADD_STYLE( wxSL_LEFT );
|
||||
ADD_STYLE( wxSL_TOP );
|
||||
ADD_STYLE( wxSL_RIGHT );
|
||||
ADD_STYLE( wxSL_BOTTOM );
|
||||
ADD_STYLE( wxSL_BOTH );
|
||||
ADD_STYLE( wxSL_SELRANGE );
|
||||
}
|
||||
|
||||
wxObject *wxSliderXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxSlider *control = new wxSlider(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetLong( _T("value"), wxSL_DEFAULT_VALUE),
|
||||
GetLong( _T("min"), wxSL_DEFAULT_MIN),
|
||||
GetLong( _T("max"), wxSL_DEFAULT_MAX),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetName()
|
||||
);
|
||||
|
||||
if( HasParam( _T("tickfreq") ))
|
||||
{
|
||||
control->SetTickFreq( GetLong( _T("tickfreq") ), 0 );
|
||||
}
|
||||
if( HasParam( _T("pagesize") ))
|
||||
{
|
||||
control->SetPageSize( GetLong( _T("pagesize") ) );
|
||||
}
|
||||
if( HasParam( _T("linesize") ))
|
||||
{
|
||||
control->SetLineSize( GetLong( _T("linesize") ));
|
||||
}
|
||||
if( HasParam( _T("thumb") ))
|
||||
{
|
||||
control->SetThumbLength( GetLong( _T("thumb") ));
|
||||
}
|
||||
if( HasParam( _T("tick") ))
|
||||
{
|
||||
control->SetTick( GetLong( _T("tick") ));
|
||||
}
|
||||
if( HasParam( _T("selmin") ) && HasParam( _T("selmax")) )
|
||||
{
|
||||
control->SetSelection( GetLong( _T("selmin") ), GetLong( _T("selmax")) );
|
||||
}
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxSliderXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("slider");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
98
contrib/src/xml/xh_spin.cpp
Normal file
98
contrib/src/xml/xh_spin.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_spin.cpp
|
||||
// Purpose: XML resource for wxSpinButton
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_spin.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_spin.h"
|
||||
#include "wx/spinctrl.h"
|
||||
|
||||
#if wxUSE_SPINBTN
|
||||
|
||||
wxSpinButtonXmlHandler::wxSpinButtonXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxSP_HORIZONTAL );
|
||||
ADD_STYLE( wxSP_VERTICAL );
|
||||
ADD_STYLE( wxSP_ARROW_KEYS );
|
||||
ADD_STYLE( wxSP_WRAP );
|
||||
}
|
||||
|
||||
wxObject *wxSpinButtonXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxSpinButton *control = new wxSpinButton(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle( _T("style"), wxSP_VERTICAL | wxSP_ARROW_KEYS ),
|
||||
GetName()
|
||||
);
|
||||
|
||||
control->SetValue( GetLong( _T("value"), wxSP_DEFAULT_VALUE) );
|
||||
control->SetRange( GetLong( _T("min"), wxSP_DEFAULT_MIN),
|
||||
GetLong( _T("max"), wxSP_DEFAULT_MAX) );
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxSpinButtonXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("spinbutton");
|
||||
}
|
||||
|
||||
#endif // wxUSE_SPINBTN
|
||||
|
||||
#if wxUSE_SPINCTRL
|
||||
|
||||
wxSpinCtrlXmlHandler::wxSpinCtrlXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxSP_HORIZONTAL );
|
||||
ADD_STYLE( wxSP_VERTICAL );
|
||||
ADD_STYLE( wxSP_ARROW_KEYS );
|
||||
ADD_STYLE( wxSP_WRAP );
|
||||
}
|
||||
|
||||
wxObject *wxSpinCtrlXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxSpinCtrl *control = new wxSpinCtrl(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("label")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle( _T("style"), wxSP_ARROW_KEYS ),
|
||||
GetLong( _T("min"), wxSP_DEFAULT_MIN),
|
||||
GetLong( _T("max"), wxSP_DEFAULT_MAX),
|
||||
GetLong( _T("value"), wxSP_DEFAULT_VALUE),
|
||||
GetName()
|
||||
);
|
||||
|
||||
SetupWindow(control);
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxSpinCtrlXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("spinctrl");
|
||||
}
|
||||
|
||||
#endif // wxUSE_SPINCTRL
|
||||
58
contrib/src/xml/xh_stbmp.cpp
Normal file
58
contrib/src/xml/xh_stbmp.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_stbmp.cpp
|
||||
// Purpose: XML resource for wxStaticBitmap
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/04/22
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_stbmp.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_stbmp.h"
|
||||
#include "wx/statbmp.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/bitmap.h"
|
||||
|
||||
wxStaticBitmapXmlHandler::wxStaticBitmapXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
}
|
||||
|
||||
wxObject *wxStaticBitmapXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxImage img(GetParamValue(_T("bitmap")));
|
||||
wxSize sz = GetSize();
|
||||
|
||||
if (!(sz == wxDefaultSize)) img.Rescale(sz.x, sz.y);
|
||||
|
||||
wxStaticBitmap *bmp = new wxStaticBitmap(m_ParentAsWindow,
|
||||
GetID(),
|
||||
img.ConvertToBitmap(),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
GetName()
|
||||
);
|
||||
SetupWindow(bmp);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxStaticBitmapXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("staticbitmap");
|
||||
}
|
||||
|
||||
|
||||
52
contrib/src/xml/xh_sttxt.cpp
Normal file
52
contrib/src/xml/xh_sttxt.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_sttxt.cpp
|
||||
// Purpose: XML resource for wxStaticText
|
||||
// Author: Bob Mitchell
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Bob Mitchell and Verant Interactive
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_sttxt.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_sttxt.h"
|
||||
#include "wx/stattext.h"
|
||||
|
||||
wxStaticTextXmlHandler::wxStaticTextXmlHandler()
|
||||
: wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE( wxST_NO_AUTORESIZE );
|
||||
}
|
||||
|
||||
wxObject *wxStaticTextXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxStaticText *text = new wxStaticText(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("label")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
GetName()
|
||||
);
|
||||
SetupWindow(text);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxStaticTextXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("statictext");
|
||||
}
|
||||
|
||||
|
||||
57
contrib/src/xml/xh_text.cpp
Normal file
57
contrib/src/xml/xh_text.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xh_text.cpp
|
||||
// Purpose: XML resource for wxTextCtrl
|
||||
// Author: Aleksandras Gluchovas
|
||||
// Created: 2000/03/21
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Aleksandras Gluchovas
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xh_text.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xh_text.h"
|
||||
#include "wx/textctrl.h"
|
||||
|
||||
wxTextCtrlXmlHandler::wxTextCtrlXmlHandler() : wxXmlResourceHandler()
|
||||
{
|
||||
ADD_STYLE(wxTE_PROCESS_ENTER);
|
||||
ADD_STYLE(wxTE_PROCESS_TAB);
|
||||
ADD_STYLE(wxTE_MULTILINE);
|
||||
ADD_STYLE(wxTE_PASSWORD);
|
||||
ADD_STYLE(wxTE_READONLY);
|
||||
ADD_STYLE(wxHSCROLL);
|
||||
}
|
||||
|
||||
wxObject *wxTextCtrlXmlHandler::DoCreateResource()
|
||||
{
|
||||
wxTextCtrl *text = new wxTextCtrl(m_ParentAsWindow,
|
||||
GetID(),
|
||||
GetText(_T("value")),
|
||||
GetPosition(), GetSize(),
|
||||
GetStyle(),
|
||||
wxDefaultValidator,
|
||||
GetText(_T("name"))
|
||||
);
|
||||
SetupWindow(text);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxTextCtrlXmlHandler::CanHandle(wxXmlNode *node)
|
||||
{
|
||||
return node->GetName() == _T("textctrl");
|
||||
}
|
||||
|
||||
|
||||
424
contrib/src/xml/xml.cpp
Normal file
424
contrib/src/xml/xml.cpp
Normal file
@@ -0,0 +1,424 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xml.cpp
|
||||
// Purpose: wxXmlDocument - XML parser & data holder class
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xml.h"
|
||||
#pragma implementation "xmlio.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/datstrm.h"
|
||||
#include "wx/zstream.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
|
||||
#include "wx/xml/xml.h"
|
||||
#include "wx/xml/xmlio.h"
|
||||
|
||||
|
||||
|
||||
wxXmlNode::wxXmlNode(wxXmlNode *parent,wxXmlNodeType type,
|
||||
const wxString& name, const wxString& content,
|
||||
wxXmlProperty *props, wxXmlNode *next)
|
||||
: m_Type(type), m_Name(name), m_Content(content),
|
||||
m_Properties(props), m_Parent(parent),
|
||||
m_Children(NULL), m_Next(next)
|
||||
{
|
||||
if (m_Parent)
|
||||
{
|
||||
if (m_Parent->m_Children)
|
||||
{
|
||||
m_Next = m_Parent->m_Children;
|
||||
m_Parent->m_Children = this;
|
||||
}
|
||||
else
|
||||
m_Parent->m_Children = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxXmlNode::wxXmlNode(wxXmlNodeType type, const wxString& name,
|
||||
const wxString& content)
|
||||
: m_Type(type), m_Name(name), m_Content(content),
|
||||
m_Properties(NULL), m_Parent(NULL),
|
||||
m_Children(NULL), m_Next(NULL)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
wxXmlNode::wxXmlNode(const wxXmlNode& node)
|
||||
{
|
||||
m_Next = NULL;
|
||||
m_Parent = NULL;
|
||||
DoCopy(node);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxXmlNode& wxXmlNode::operator=(const wxXmlNode& node)
|
||||
{
|
||||
delete m_Properties;
|
||||
delete m_Children;
|
||||
DoCopy(node);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlNode::DoCopy(const wxXmlNode& node)
|
||||
{
|
||||
m_Type = node.m_Type;
|
||||
m_Name = node.m_Name;
|
||||
m_Content = node.m_Content;
|
||||
m_Children = NULL;
|
||||
|
||||
wxXmlNode *n = node.m_Children;
|
||||
while (n)
|
||||
{
|
||||
AddChild(new wxXmlNode(*n));
|
||||
n = n->GetNext();
|
||||
}
|
||||
|
||||
m_Properties = NULL;
|
||||
wxXmlProperty *p = node.m_Properties;
|
||||
while (p)
|
||||
{
|
||||
AddProperty(p->GetName(), p->GetValue());
|
||||
p = p->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool wxXmlNode::HasProp(const wxString& propName) const
|
||||
{
|
||||
wxXmlProperty *prop = GetProperties();
|
||||
|
||||
while (prop)
|
||||
{
|
||||
if (prop->GetName() == propName) return TRUE;
|
||||
prop = prop->GetNext();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlNode::GetPropVal(const wxString& propName, wxString *value) const
|
||||
{
|
||||
wxXmlProperty *prop = GetProperties();
|
||||
|
||||
while (prop)
|
||||
{
|
||||
if (prop->GetName() == propName)
|
||||
{
|
||||
*value = prop->GetValue();
|
||||
return TRUE;
|
||||
}
|
||||
prop = prop->GetNext();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxXmlNode::GetPropVal(const wxString& propName, const wxString& defaultVal) const
|
||||
{
|
||||
wxString tmp;
|
||||
if (GetPropVal(propName, &tmp))
|
||||
return tmp;
|
||||
else
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlNode::AddChild(wxXmlNode *child)
|
||||
{
|
||||
if (m_Children == NULL)
|
||||
m_Children = child;
|
||||
else
|
||||
{
|
||||
wxXmlNode *ch = m_Children;
|
||||
while (ch->m_Next) ch = ch->m_Next;
|
||||
ch->m_Next = child;
|
||||
}
|
||||
child->m_Next = NULL;
|
||||
child->m_Parent = this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlNode::InsertChild(wxXmlNode *child, wxXmlNode *before_node)
|
||||
{
|
||||
wxASSERT_MSG(before_node->GetParent() == this, _T("wxXmlNode::InsertChild - the node has incorrect parent"));
|
||||
|
||||
if (m_Children == before_node)
|
||||
m_Children = child;
|
||||
else
|
||||
{
|
||||
wxXmlNode *ch = m_Children;
|
||||
while (ch->m_Next != before_node) ch = ch->m_Next;
|
||||
ch->m_Next = child;
|
||||
}
|
||||
|
||||
child->m_Parent = this;
|
||||
child->m_Next = before_node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlNode::RemoveChild(wxXmlNode *child)
|
||||
{
|
||||
if (m_Children == NULL)
|
||||
return FALSE;
|
||||
else if (m_Children == child)
|
||||
{
|
||||
m_Children = child->m_Next;
|
||||
child->m_Parent = NULL;
|
||||
child->m_Next = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxXmlNode *ch = m_Children;
|
||||
while (ch->m_Next)
|
||||
{
|
||||
if (ch->m_Next == child)
|
||||
{
|
||||
ch->m_Next = child->m_Next;
|
||||
child->m_Parent = NULL;
|
||||
child->m_Next = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
ch = ch->m_Next;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlNode::AddProperty(const wxString& name, const wxString& value)
|
||||
{
|
||||
AddProperty(new wxXmlProperty(name, value, NULL));
|
||||
}
|
||||
|
||||
void wxXmlNode::AddProperty(wxXmlProperty *prop)
|
||||
{
|
||||
if (m_Properties == NULL)
|
||||
m_Properties = prop;
|
||||
else
|
||||
{
|
||||
wxXmlProperty *p = m_Properties;
|
||||
while (p->GetNext()) p = p->GetNext();
|
||||
p->SetNext(prop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlNode::DeleteProperty(const wxString& name)
|
||||
{
|
||||
if (m_Properties == NULL)
|
||||
return FALSE;
|
||||
|
||||
else if (m_Properties->GetName() == name)
|
||||
{
|
||||
wxXmlProperty *prop = m_Properties;
|
||||
m_Properties = prop->GetNext();
|
||||
prop->SetNext(NULL);
|
||||
delete prop;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
wxXmlProperty *p = m_Properties;
|
||||
while (p->GetNext())
|
||||
{
|
||||
if (p->GetNext()->GetName() == name)
|
||||
{
|
||||
wxXmlProperty *prop = p->GetNext();
|
||||
p->SetNext(prop->GetNext());
|
||||
prop->SetNext(NULL);
|
||||
delete prop;
|
||||
return TRUE;
|
||||
}
|
||||
p = p->GetNext();
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
wxXmlDocument::wxXmlDocument(const wxString& filename, wxXmlIOType io_type)
|
||||
: wxObject(), m_Root(NULL)
|
||||
{
|
||||
if (!Load(filename, io_type))
|
||||
{
|
||||
delete m_Root;
|
||||
m_Root = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxXmlDocument::wxXmlDocument(wxInputStream& stream, wxXmlIOType io_type)
|
||||
: wxObject(), m_Root(NULL)
|
||||
{
|
||||
if (!Load(stream, io_type))
|
||||
{
|
||||
delete m_Root;
|
||||
m_Root = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxXmlDocument::wxXmlDocument(const wxXmlDocument& doc)
|
||||
{
|
||||
DoCopy(doc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxXmlDocument& wxXmlDocument::operator=(const wxXmlDocument& doc)
|
||||
{
|
||||
delete m_Root;
|
||||
DoCopy(doc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlDocument::DoCopy(const wxXmlDocument& doc)
|
||||
{
|
||||
m_Version = doc.m_Version;
|
||||
m_Encoding = doc.m_Encoding;
|
||||
m_Root = new wxXmlNode(*doc.m_Root);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlDocument::Load(const wxString& filename, wxXmlIOType io_type)
|
||||
{
|
||||
wxFileInputStream stream(filename);
|
||||
return Load(stream, io_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlDocument::Load(wxInputStream& stream, wxXmlIOType io_type)
|
||||
{
|
||||
wxNode *n = sm_Handlers->GetFirst();
|
||||
while (n)
|
||||
{
|
||||
wxXmlIOHandler *h = (wxXmlIOHandler*) n->GetData();
|
||||
|
||||
if ((io_type == wxXML_IO_AUTO || io_type == h->GetType()) &&
|
||||
h->CanLoad(stream))
|
||||
{
|
||||
return h->Load(stream, *this);
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
wxLogError(_("Cannot find XML I/O handler capable of loading this format."));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlDocument::Save(const wxString& filename, wxXmlIOType io_type) const
|
||||
{
|
||||
wxFileOutputStream stream(filename);
|
||||
return Save(stream, io_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlDocument::Save(wxOutputStream& stream, wxXmlIOType io_type) const
|
||||
{
|
||||
wxNode *n = sm_Handlers->GetFirst();
|
||||
while (n)
|
||||
{
|
||||
wxXmlIOHandler *h = (wxXmlIOHandler*) n->GetData();
|
||||
if (io_type == h->GetType() && h->CanSave())
|
||||
{
|
||||
return h->Save(stream, *this);
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
wxLogError(_("Cannot find XML I/O handler capable of saving in this format."));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
wxList *wxXmlDocument::sm_Handlers = NULL;
|
||||
|
||||
void wxXmlDocument::AddHandler(wxXmlIOHandler *handler)
|
||||
{
|
||||
if (sm_Handlers == NULL)
|
||||
{
|
||||
sm_Handlers = new wxList;
|
||||
sm_Handlers->DeleteContents(TRUE);
|
||||
}
|
||||
sm_Handlers->Append(handler);
|
||||
}
|
||||
|
||||
|
||||
void wxXmlDocument::CleanUpHandlers()
|
||||
{
|
||||
delete sm_Handlers;
|
||||
sm_Handlers = NULL;
|
||||
}
|
||||
|
||||
|
||||
void wxXmlDocument::InitStandardHandlers()
|
||||
{
|
||||
AddHandler(new wxXmlIOHandlerBin);
|
||||
AddHandler(new wxXmlIOHandlerLibxml);
|
||||
}
|
||||
|
||||
|
||||
#include "wx/module.h"
|
||||
|
||||
class wxXmlModule: public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxXmlModule)
|
||||
public:
|
||||
wxXmlModule() {}
|
||||
bool OnInit() { wxXmlDocument::InitStandardHandlers(); return TRUE; };
|
||||
void OnExit() { wxXmlDocument::CleanUpHandlers(); };
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxXmlModule, wxModule)
|
||||
161
contrib/src/xml/xmlbin.cpp
Normal file
161
contrib/src/xml/xmlbin.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xmlbin.cpp
|
||||
// Purpose: wxXmlIOHandlerBin
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/07/24
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
// nothing, already in xml.cpp
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/datstrm.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
|
||||
#include "wx/xml/xmlio.h"
|
||||
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerBin::CanLoad(wxInputStream& stream)
|
||||
{
|
||||
bool canread;
|
||||
canread = (ReadHeader(stream) == _T("XMLBIN "));
|
||||
stream.SeekI(-9, wxFromCurrent);
|
||||
return canread;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxXmlIOHandlerBin::ReadHeader(wxInputStream& stream)
|
||||
{
|
||||
wxUint8 version;
|
||||
char cheader[8];
|
||||
|
||||
stream.Read(cheader, 8);
|
||||
cheader[7] = 0;
|
||||
stream.Read(&version, 1);
|
||||
|
||||
if (version != 1) return wxEmptyString;
|
||||
else return wxString(cheader);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlIOHandlerBin::WriteHeader(wxOutputStream& stream, const wxString& header)
|
||||
{
|
||||
char cheader[8];
|
||||
size_t i;
|
||||
wxUint8 version = 1;
|
||||
|
||||
for (i = 0; i < header.Length(); i++) cheader[i] = header[i];
|
||||
for (; i < 7; i++) cheader[i] = ' ';
|
||||
cheader[7] = 0;
|
||||
stream.Write(cheader, 8);
|
||||
stream.Write(&version, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool SaveBinNode(wxDataOutputStream& ds, wxXmlNode *node)
|
||||
{
|
||||
if (node)
|
||||
{
|
||||
ds << (wxUint8)1 <<
|
||||
(wxUint8)node->GetType() <<
|
||||
node->GetName() << node->GetContent();
|
||||
|
||||
wxXmlProperty *prop = node->GetProperties();
|
||||
while (prop)
|
||||
{
|
||||
ds << (wxUint8)1;
|
||||
ds << prop->GetName() << prop->GetValue();
|
||||
prop = prop->GetNext();
|
||||
|
||||
}
|
||||
ds << (wxUint8)0;
|
||||
|
||||
SaveBinNode(ds, node->GetNext());
|
||||
SaveBinNode(ds, node->GetChildren());
|
||||
}
|
||||
else
|
||||
ds << (wxUint8)0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerBin::Save(wxOutputStream& stream, const wxXmlDocument& doc)
|
||||
{
|
||||
WriteHeader(stream, "XMLBIN ");
|
||||
wxDataOutputStream ds(stream);
|
||||
ds << doc.GetVersion() << doc.GetEncoding();
|
||||
SaveBinNode(ds, doc.GetRoot());
|
||||
return stream.LastError() == wxSTREAM_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static wxXmlProperty *LoadBinProp(wxDataInputStream& ds)
|
||||
{
|
||||
wxUint8 dummy;
|
||||
ds >> dummy;
|
||||
if (dummy == 0) return NULL;
|
||||
|
||||
wxString name, value;
|
||||
ds >> name >> value;
|
||||
return new wxXmlProperty(name, value, LoadBinProp(ds));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static wxXmlNode *LoadBinNode(wxDataInputStream& ds, wxXmlNode *parent)
|
||||
{
|
||||
wxUint8 type;
|
||||
wxString name, content;
|
||||
wxUint8 dummy;
|
||||
|
||||
ds >> dummy;
|
||||
if (dummy == 0) return NULL;
|
||||
ds >> type >> name >> content;
|
||||
|
||||
wxXmlProperty *prop = LoadBinProp(ds);
|
||||
|
||||
wxXmlNode *nd = new wxXmlNode(parent, (wxXmlNodeType)type, name, content,
|
||||
prop, LoadBinNode(ds, parent));
|
||||
LoadBinNode(ds, nd);
|
||||
return nd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerBin::Load(wxInputStream& stream, wxXmlDocument& doc)
|
||||
{
|
||||
ReadHeader(stream);
|
||||
wxDataInputStream ds(stream);
|
||||
wxString tmp;
|
||||
|
||||
ds >> tmp;
|
||||
doc.SetVersion(tmp);
|
||||
ds >> tmp;
|
||||
doc.SetEncoding(tmp);
|
||||
|
||||
doc.SetRoot(LoadBinNode(ds, NULL));
|
||||
|
||||
return (doc.GetRoot() != NULL);
|
||||
}
|
||||
|
||||
|
||||
59
contrib/src/xml/xmlbinz.cpp
Normal file
59
contrib/src/xml/xmlbinz.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xmlbinz.cpp
|
||||
// Purpose: wxXmlIOHandlerBinZ
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/07/24
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
// nothing, already in xml.cpp
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/datstrm.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/zstream.h"
|
||||
|
||||
#include "wx/xml/xmlio.h"
|
||||
|
||||
#if wxUSE_ZLIB
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerBinZ::CanLoad(wxInputStream& stream)
|
||||
{
|
||||
bool canread;
|
||||
canread = (ReadHeader(stream) == _T("XMLBINZ"));
|
||||
stream.SeekI(-9, wxFromCurrent);
|
||||
return canread;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerBinZ::Save(wxOutputStream& stream, const wxXmlDocument& doc)
|
||||
{
|
||||
WriteHeader(stream, "XMLBINZ");
|
||||
wxZlibOutputStream costr(stream, 9);
|
||||
return wxXmlIOHandlerBin::Save(costr, doc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerBinZ::Load(wxInputStream& stream, wxXmlDocument& doc)
|
||||
{
|
||||
ReadHeader(stream);
|
||||
wxZlibInputStream costr(stream);
|
||||
return wxXmlIOHandlerBin::Load(stream, doc);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
283
contrib/src/xml/xmlpars.cpp
Normal file
283
contrib/src/xml/xmlpars.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xmlpars.cpp
|
||||
// Purpose: wxXmlDocument - XML parser
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
// nothing - already in xml.cpp
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/dynlib.h"
|
||||
#include "wx/xml/xmlio.h"
|
||||
|
||||
#include <libxml/parser.h>
|
||||
|
||||
// dynamically loaded functions from libxml:
|
||||
typedef xmlParserCtxtPtr (*type_xmlCreatePushParserCtxt)
|
||||
(xmlSAXHandlerPtr sax, void *, const char *, int, const char *);
|
||||
typedef xmlNodePtr (*type_xmlNewText)(const xmlChar *);
|
||||
typedef xmlAttrPtr (*type_xmlSetProp)(xmlNodePtr, const xmlChar *, const xmlChar *);
|
||||
typedef int (*type_xmlParseChunk)(xmlParserCtxtPtr, const char *, int, int);
|
||||
typedef void (*type_xmlFreeParserCtxt)(xmlParserCtxtPtr);
|
||||
typedef xmlDocPtr (*type_xmlNewDoc)(const xmlChar *);
|
||||
typedef void (*type_xmlFreeDoc)(xmlDocPtr);
|
||||
typedef xmlNodePtr (*type_xmlNewDocNode)(xmlDocPtr, xmlNsPtr, const xmlChar *, const xmlChar *);
|
||||
typedef void (*type_xmlDocDumpMemory)(xmlDocPtr, xmlChar**, int *);
|
||||
typedef xmlNodePtr (*type_xmlAddChild)(xmlNodePtr, xmlNodePtr);
|
||||
typedef xmlNodePtr (*type_xmlNewChild)(xmlNodePtr, xmlNsPtr, const xmlChar *, const xmlChar *);
|
||||
typedef xmlChar * (*type_xmlNodeListGetString)(xmlDocPtr, xmlNodePtr, int);
|
||||
typedef xmlNodePtr (*type_xmlDocGetRootElement)(xmlDocPtr);
|
||||
typedef xmlNodePtr (*type_xmlDocSetRootElement)(xmlDocPtr doc, xmlNodePtr root);
|
||||
|
||||
static struct
|
||||
{
|
||||
wxDllType Handle;
|
||||
|
||||
type_xmlCreatePushParserCtxt xmlCreatePushParserCtxt;
|
||||
type_xmlNewText xmlNewText;
|
||||
type_xmlSetProp xmlSetProp;
|
||||
type_xmlParseChunk xmlParseChunk;
|
||||
type_xmlFreeParserCtxt xmlFreeParserCtxt;
|
||||
type_xmlNewDoc xmlNewDoc;
|
||||
type_xmlFreeDoc xmlFreeDoc;
|
||||
type_xmlNewDocNode xmlNewDocNode;
|
||||
type_xmlDocDumpMemory xmlDocDumpMemory;
|
||||
type_xmlAddChild xmlAddChild;
|
||||
type_xmlNewChild xmlNewChild;
|
||||
type_xmlNodeListGetString xmlNodeListGetString;
|
||||
type_xmlDocGetRootElement xmlDocGetRootElement;
|
||||
type_xmlDocSetRootElement xmlDocSetRootElement;
|
||||
} gs_libxmlDLL;
|
||||
|
||||
static bool gs_libxmlLoaded = FALSE;
|
||||
static bool gs_libxmlLoadFailed = FALSE;
|
||||
|
||||
|
||||
|
||||
static void ReleaseLibxml()
|
||||
{
|
||||
if (gs_libxmlLoaded)
|
||||
{
|
||||
wxLogDebug("Releasing libxml.so.2");
|
||||
wxDllLoader::UnloadLibrary(gs_libxmlDLL.Handle);
|
||||
}
|
||||
gs_libxmlLoaded = FALSE;
|
||||
gs_libxmlLoadFailed = FALSE;
|
||||
}
|
||||
|
||||
|
||||
static bool LoadLibxml()
|
||||
{
|
||||
if (gs_libxmlLoaded) return TRUE;
|
||||
if (gs_libxmlLoadFailed) return FALSE;
|
||||
gs_libxmlLoadFailed = TRUE;
|
||||
|
||||
wxLogDebug("Loading libxml.so.2...");
|
||||
#ifdef __UNIX__
|
||||
gs_libxmlDLL.Handle =
|
||||
wxDllLoader::LoadLibrary(_T("libxml.so.2"), &gs_libxmlLoaded);
|
||||
#endif
|
||||
|
||||
if (!gs_libxmlLoaded) return FALSE;
|
||||
|
||||
#define LOAD_SYMBOL(sym) \
|
||||
gs_libxmlDLL.sym = \
|
||||
(type_##sym)wxDllLoader::GetSymbol(gs_libxmlDLL.Handle, _T(#sym)); \
|
||||
if (!gs_libxmlDLL.sym) { ReleaseLibxml(); return FALSE; }
|
||||
|
||||
LOAD_SYMBOL(xmlCreatePushParserCtxt)
|
||||
LOAD_SYMBOL(xmlNewText)
|
||||
LOAD_SYMBOL(xmlSetProp)
|
||||
LOAD_SYMBOL(xmlParseChunk)
|
||||
LOAD_SYMBOL(xmlFreeParserCtxt)
|
||||
LOAD_SYMBOL(xmlNewDoc)
|
||||
LOAD_SYMBOL(xmlFreeDoc)
|
||||
LOAD_SYMBOL(xmlNewDocNode)
|
||||
LOAD_SYMBOL(xmlDocDumpMemory)
|
||||
LOAD_SYMBOL(xmlAddChild)
|
||||
LOAD_SYMBOL(xmlNewChild)
|
||||
LOAD_SYMBOL(xmlNodeListGetString)
|
||||
LOAD_SYMBOL(xmlDocGetRootElement)
|
||||
LOAD_SYMBOL(xmlDocSetRootElement)
|
||||
|
||||
#undef LOAD_SYMBOL
|
||||
|
||||
gs_libxmlLoadFailed = FALSE;
|
||||
|
||||
wxLogDebug("...succeed");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerLibxml::CanLoad(wxInputStream& stream)
|
||||
{
|
||||
if (!LoadLibxml()) return FALSE;
|
||||
char cheader[7];
|
||||
cheader[6] = 0;
|
||||
stream.Read(cheader, 6);
|
||||
stream.SeekI(-6, wxFromCurrent);
|
||||
return strcmp(cheader, "<?xml ") == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerLibxml::CanSave()
|
||||
{
|
||||
return LoadLibxml();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static wxXmlProperty *CreateWXProperty(xmlDocPtr doc, xmlAttrPtr attr)
|
||||
{
|
||||
if (attr == NULL) return NULL;
|
||||
|
||||
unsigned char *val =
|
||||
gs_libxmlDLL.xmlNodeListGetString(doc, attr->children, 1);
|
||||
wxXmlProperty *prop =
|
||||
new wxXmlProperty(attr->name, val, CreateWXProperty(doc, attr->next));
|
||||
free(val);
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static wxXmlNode *CreateWXNode(xmlDocPtr doc, wxXmlNode *parent, xmlNodePtr node)
|
||||
{
|
||||
if (node == NULL) return NULL;
|
||||
|
||||
wxXmlNode *nd = new wxXmlNode(parent, (wxXmlNodeType)node->type,
|
||||
node->name, node->content,
|
||||
CreateWXProperty(doc, node->properties),
|
||||
CreateWXNode(doc, parent, node->next));
|
||||
CreateWXNode(doc, nd, node->children);
|
||||
return nd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerLibxml::Load(wxInputStream& stream, wxXmlDocument& doc)
|
||||
{
|
||||
if (!LoadLibxml()) return FALSE;
|
||||
|
||||
xmlDocPtr dc;
|
||||
xmlParserCtxtPtr ctxt;
|
||||
|
||||
char buffer[1024];
|
||||
int res;
|
||||
|
||||
res = stream.Read(buffer, 4).LastRead();
|
||||
if (res > 0)
|
||||
{
|
||||
bool okay = TRUE;
|
||||
ctxt = gs_libxmlDLL.xmlCreatePushParserCtxt(NULL, NULL,
|
||||
buffer, res, ""/*docname*/);
|
||||
while ((res = stream.Read(buffer, 1024).LastRead()) > 0)
|
||||
if (gs_libxmlDLL.xmlParseChunk(ctxt, buffer, res, 0) != 0)
|
||||
okay = FALSE;
|
||||
if (gs_libxmlDLL.xmlParseChunk(ctxt, buffer, 0, 1) != 0) okay = FALSE;
|
||||
dc = ctxt->myDoc;
|
||||
gs_libxmlDLL.xmlFreeParserCtxt(ctxt);
|
||||
|
||||
doc.SetVersion(dc->version);
|
||||
doc.SetEncoding(dc->encoding);
|
||||
doc.SetRoot(CreateWXNode(dc, NULL, gs_libxmlDLL.xmlDocGetRootElement(dc)));
|
||||
|
||||
gs_libxmlDLL.xmlFreeDoc(dc);
|
||||
|
||||
return okay;
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void CreateLibxmlNode(xmlNodePtr node, wxXmlNode *wxnode)
|
||||
{
|
||||
node->type = (xmlElementType)wxnode->GetType();
|
||||
|
||||
wxXmlProperty *prop = wxnode->GetProperties();
|
||||
while (prop)
|
||||
{
|
||||
gs_libxmlDLL.xmlSetProp(node, (xmlChar*)prop->GetName().mb_str(),
|
||||
(xmlChar*)prop->GetValue().mb_str());
|
||||
prop = prop->GetNext();
|
||||
}
|
||||
|
||||
wxXmlNode *child = wxnode->GetChildren();
|
||||
xmlNodePtr n;
|
||||
xmlChar *content, *name;
|
||||
|
||||
while (child)
|
||||
{
|
||||
name = (xmlChar*)child->GetName().mb_str();
|
||||
if (!child->GetContent()) content = NULL;
|
||||
else content = (xmlChar*)child->GetContent().mb_str();
|
||||
if (child->GetType() == wxXML_TEXT_NODE)
|
||||
gs_libxmlDLL.xmlAddChild(node, n = gs_libxmlDLL.xmlNewText(content));
|
||||
else
|
||||
n = gs_libxmlDLL.xmlNewChild(node, NULL, name, content);
|
||||
CreateLibxmlNode(n, child);
|
||||
child = child->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlIOHandlerLibxml::Save(wxOutputStream& stream, const wxXmlDocument& doc)
|
||||
{
|
||||
if (!LoadLibxml()) return FALSE;
|
||||
|
||||
xmlDocPtr dc;
|
||||
|
||||
wxASSERT_MSG(doc.GetRoot() != NULL, _("Trying to save empty document!"));
|
||||
|
||||
dc = gs_libxmlDLL.xmlNewDoc((xmlChar*)doc.GetVersion().mb_str());
|
||||
|
||||
gs_libxmlDLL.xmlDocSetRootElement(dc,
|
||||
gs_libxmlDLL.xmlNewDocNode(dc, NULL,
|
||||
(xmlChar*)doc.GetRoot()->GetName().mb_str(), NULL));
|
||||
CreateLibxmlNode(gs_libxmlDLL.xmlDocGetRootElement(dc), doc.GetRoot());
|
||||
|
||||
xmlChar *buffer;
|
||||
int size;
|
||||
|
||||
gs_libxmlDLL.xmlDocDumpMemory(dc, &buffer, &size);
|
||||
gs_libxmlDLL.xmlFreeDoc(dc);
|
||||
stream.Write(buffer, size);
|
||||
free(buffer);
|
||||
return stream.LastWrite() == (unsigned)size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "wx/module.h"
|
||||
|
||||
class wxXmlLibxmlModule: public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxXmlLibxmlModule)
|
||||
public:
|
||||
wxXmlLibxmlModule() {}
|
||||
bool OnInit() { return TRUE; }
|
||||
void OnExit() { ReleaseLibxml(); }
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxXmlLibxmlModule, wxModule)
|
||||
688
contrib/src/xml/xmlres.cpp
Normal file
688
contrib/src/xml/xmlres.cpp
Normal file
@@ -0,0 +1,688 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xmlres.cpp
|
||||
// Purpose: XML resources
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xmlres.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/panel.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/module.h"
|
||||
|
||||
#include "wx/xml/xml.h"
|
||||
#include "wx/xml/xmlres.h"
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords);
|
||||
|
||||
|
||||
wxXmlResource::wxXmlResource()
|
||||
{
|
||||
m_Handlers.DeleteContents(TRUE);
|
||||
}
|
||||
|
||||
wxXmlResource::wxXmlResource(const wxString& filemask, int type)
|
||||
{
|
||||
m_Handlers.DeleteContents(TRUE);
|
||||
Load(filemask, type);
|
||||
}
|
||||
|
||||
wxXmlResource::~wxXmlResource()
|
||||
{
|
||||
ClearHandlers();
|
||||
}
|
||||
|
||||
|
||||
bool wxXmlResource::Load(const wxString& filemask, int type)
|
||||
{
|
||||
wxString fnd;
|
||||
wxXmlResourceDataRecord *drec;
|
||||
|
||||
#if wxUSE_FILESYSTEM
|
||||
wxFileSystem fsys;
|
||||
# define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
|
||||
# define wxXmlFindNext fsys.FindNext()
|
||||
#else
|
||||
# define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
|
||||
# define wxXmlFindNext wxFindNextFile()
|
||||
wxASSERT_MSG(type != wxXML_ARCHIVE, wxT("ZIP archive XML resources supported only with wxUSE_FILESYSTEM set to 1!"));
|
||||
#endif
|
||||
fnd = wxXmlFindFirst;
|
||||
while (!!fnd)
|
||||
{
|
||||
#if wxUSE_FILESYSTEM
|
||||
if (type == wxXML_ARCHIVE)
|
||||
{
|
||||
wxFileSystem fs2;
|
||||
wxString fnd2;
|
||||
|
||||
fnd2 = fs2.FindFirst(fnd + wxT("#zip:*.xmb"), wxFILE);
|
||||
while (!!fnd2)
|
||||
{
|
||||
drec = new wxXmlResourceDataRecord;
|
||||
drec->File = fnd2;
|
||||
m_Data.Add(drec);
|
||||
fnd2 = fs2.FindNext();
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
drec = new wxXmlResourceDataRecord;
|
||||
drec->File = fnd;
|
||||
m_Data.Add(drec);
|
||||
}
|
||||
fnd = wxXmlFindNext;
|
||||
}
|
||||
# undef wxXmlFindFirst
|
||||
# undef wxXmlFindNext
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlResource::AddHandler(wxXmlResourceHandler *handler)
|
||||
{
|
||||
m_Handlers.Append(handler);
|
||||
handler->SetParentResource(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlResource::ClearHandlers()
|
||||
{
|
||||
m_Handlers.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxMenu *wxXmlResource::LoadMenu(const wxString& name)
|
||||
{
|
||||
return (wxMenu*)CreateResFromNode(FindResource(name, wxT("menu")), NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxMenuBar *wxXmlResource::LoadMenuBar(const wxString& name)
|
||||
{
|
||||
return (wxMenuBar*)CreateResFromNode(FindResource(name, wxT("menubar")), NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxDialog *wxXmlResource::LoadDialog(wxWindow *parent, const wxString& name)
|
||||
{
|
||||
wxDialog *dialog = new wxDialog;
|
||||
if (!LoadDialog(dialog, parent, name))
|
||||
{ delete dialog; return NULL; }
|
||||
else return dialog;
|
||||
}
|
||||
|
||||
bool wxXmlResource::LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name)
|
||||
{
|
||||
return CreateResFromNode(FindResource(name, wxT("dialog")), parent, dlg) != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxPanel *wxXmlResource::LoadPanel(wxWindow *parent, const wxString& name)
|
||||
{
|
||||
wxPanel *panel = new wxPanel;
|
||||
if (!LoadPanel(panel, parent, name))
|
||||
{ delete panel; return NULL; }
|
||||
else return panel;
|
||||
}
|
||||
|
||||
bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name)
|
||||
{
|
||||
return CreateResFromNode(FindResource(name, wxT("panel")), parent, panel) != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlResource::UpdateResources()
|
||||
{
|
||||
bool modif;
|
||||
# if wxUSE_FILESYSTEM
|
||||
wxFSFile *file;
|
||||
wxFileSystem fsys;
|
||||
# endif
|
||||
|
||||
for (size_t i = 0; i < m_Data.GetCount(); i++)
|
||||
{
|
||||
modif = (m_Data[i].Doc == NULL);
|
||||
|
||||
if (!modif)
|
||||
{
|
||||
# if wxUSE_FILESYSTEM
|
||||
file = fsys.OpenFile(m_Data[i].File);
|
||||
modif = file && file->GetModificationTime() > m_Data[i].Time;
|
||||
if (!file)
|
||||
wxLogError(_("Cannot open file '%s'."), m_Data[i].File.c_str());
|
||||
delete file;
|
||||
# else
|
||||
modif = wxDateTime(wxFileModificationTime(m_Data[i].File)) > m_Data[i].Time;
|
||||
# endif
|
||||
}
|
||||
|
||||
if (modif)
|
||||
{
|
||||
wxInputStream *stream;
|
||||
|
||||
# if wxUSE_FILESYSTEM
|
||||
file = fsys.OpenFile(m_Data[i].File);
|
||||
stream = file->GetStream();
|
||||
# else
|
||||
stream = new wxFileInputStream(m_Data[i].File);
|
||||
# endif
|
||||
|
||||
if (stream)
|
||||
{
|
||||
delete m_Data[i].Doc;
|
||||
m_Data[i].Doc = new wxXmlDocument;
|
||||
}
|
||||
if (!stream || !m_Data[i].Doc->Load(*stream))
|
||||
wxLogError(_("Cannot load resources from file '%s'."), m_Data[i].File.c_str());
|
||||
|
||||
if (m_Data[i].Doc->GetRoot()->GetName() != _T("resource"))
|
||||
wxLogError(_("Invalid XML resource '%s': doesn't have root node 'resource'."), m_Data[i].File.c_str());
|
||||
|
||||
# if wxUSE_FILESYSTEM
|
||||
delete file;
|
||||
# else
|
||||
delete stream;
|
||||
# endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxXmlNode *wxXmlResource::FindResource(const wxString& name, const wxString& type)
|
||||
{
|
||||
UpdateResources(); //ensure everything is up-to-date
|
||||
|
||||
wxString dummy;
|
||||
for (size_t f = 0; f < m_Data.GetCount(); f++)
|
||||
{
|
||||
for (wxXmlNode *node = m_Data[f].Doc->GetRoot()->GetChildren();
|
||||
node; node = node->GetNext())
|
||||
if ( node->GetType() == wxXML_ELEMENT_NODE &&
|
||||
(!type || node->GetName() == type) &&
|
||||
node->GetPropVal(wxT("name"), &dummy) &&
|
||||
dummy == name &&
|
||||
wxXmlResourceHandler::CheckPlatform(node))
|
||||
return node;
|
||||
}
|
||||
|
||||
wxLogError(_("XML resource '%s' (type '%s') not found!"),
|
||||
name.c_str(), type.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance)
|
||||
{
|
||||
if (node == NULL) return NULL;
|
||||
|
||||
wxXmlResourceHandler *handler;
|
||||
wxObject *ret;
|
||||
wxNode * ND = m_Handlers.GetFirst();
|
||||
while (ND)
|
||||
{
|
||||
handler = (wxXmlResourceHandler*)ND->GetData();
|
||||
if (handler->CanHandle(node))
|
||||
{
|
||||
ret = handler->CreateResource(node, parent, instance);
|
||||
if (ret) return ret;
|
||||
}
|
||||
ND = ND->GetNext();
|
||||
}
|
||||
|
||||
wxLogError(_("No handler found for XML node '%s'!"), node->GetName().c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
wxXmlResourceHandler::wxXmlResourceHandler()
|
||||
: m_Node(NULL), m_Parent(NULL), m_Instance(NULL),
|
||||
m_ParentAsWindow(NULL), m_InstanceAsWindow(NULL)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance)
|
||||
{
|
||||
if (!CheckPlatform(node)) return NULL;
|
||||
|
||||
wxXmlNode *myNode = m_Node;
|
||||
wxObject *myParent = m_Parent, *myInstance = m_Instance;
|
||||
wxWindow *myParentAW = m_ParentAsWindow, *myInstanceAW = m_InstanceAsWindow;
|
||||
|
||||
m_Node = node;
|
||||
m_Parent = parent;
|
||||
m_Instance = instance;
|
||||
m_ParentAsWindow = wxDynamicCast(m_Parent, wxWindow);
|
||||
m_InstanceAsWindow = wxDynamicCast(m_Instance, wxWindow);
|
||||
|
||||
wxObject *returned = DoCreateResource();
|
||||
|
||||
m_Node = myNode;
|
||||
m_Parent = myParent; m_ParentAsWindow = myParentAW;
|
||||
m_Instance = myInstance; m_InstanceAsWindow = myInstanceAW;
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*static*/ bool wxXmlResourceHandler::CheckPlatform(wxXmlNode *node)
|
||||
{
|
||||
wxString s;
|
||||
if (!node->GetPropVal(_T("platform"), &s)) return TRUE;
|
||||
#ifdef __WXMSW__
|
||||
return s == wxString(_T("win"));
|
||||
#elif defined(__UNIX__)
|
||||
return s == wxString(_T("unix"));
|
||||
#elif defined(__MAC__)
|
||||
return s == wxString(_T("mac"));
|
||||
#elif defined(__OS2__)
|
||||
return s == wxString(_T("os2"));
|
||||
#else
|
||||
wxLogWarning(_("You're running the application on unknown platform, check for platfrom '%s' failed."), s.mb_str());
|
||||
return TRUE; // unknown platform
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void wxXmlResourceHandler::AddStyle(const wxString& name, int value)
|
||||
{
|
||||
m_StyleNames.Add(name);
|
||||
m_StyleValues.Add(value);
|
||||
}
|
||||
|
||||
|
||||
bool wxXmlResourceHandler::HasParam(const wxString& param)
|
||||
{
|
||||
return (GetParamNode(param) != NULL);
|
||||
}
|
||||
|
||||
|
||||
int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults)
|
||||
{
|
||||
wxString s = GetParamValue(param);
|
||||
|
||||
if (!s) return defaults;
|
||||
|
||||
wxStringTokenizer tkn(s, _T("| "), wxTOKEN_STRTOK);
|
||||
int style = 0;
|
||||
int index;
|
||||
wxString fl;
|
||||
while (tkn.HasMoreTokens())
|
||||
{
|
||||
fl = tkn.GetNextToken();
|
||||
index = m_StyleNames.Index(fl);
|
||||
if (index != wxNOT_FOUND)
|
||||
style |= m_StyleValues[index];
|
||||
else
|
||||
wxLogError(_("Unknown style flag ") + fl);
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxXmlResourceHandler::GetText(const wxString& param)
|
||||
{
|
||||
wxString str1 = GetParamValue(param);
|
||||
wxString str2;
|
||||
const wxChar *dt;
|
||||
|
||||
for (dt = str1.c_str(); *dt; dt++)
|
||||
{
|
||||
// Remap $ to &, map $$ to $ (for things like "&File..." --
|
||||
// this is illegal in XML, so we use "$File..."):
|
||||
if (*dt == '$')
|
||||
switch (*(++dt))
|
||||
{
|
||||
case '$' : str2 << '$'; break;
|
||||
default : str2 << '&' << *dt; break;
|
||||
}
|
||||
// Remap \n to CR, \r LF, \t to TAB:
|
||||
else if (*dt == '\\')
|
||||
switch (*(++dt))
|
||||
{
|
||||
case 'n' : str2 << '\n'; break;
|
||||
case 't' : str2 << '\t'; break;
|
||||
case 'r' : str2 << '\r'; break;
|
||||
default : str2 << '\\' << *dt; break;
|
||||
}
|
||||
else str2 << *dt;
|
||||
}
|
||||
return str2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
|
||||
{
|
||||
long value;
|
||||
wxString str1 = GetParamValue(param);
|
||||
|
||||
if (!str1.ToLong(&value))
|
||||
value = defaultv;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
int wxXmlResourceHandler::GetID()
|
||||
{
|
||||
wxString sid = GetName();
|
||||
long num;
|
||||
|
||||
if (sid == _T("-1")) return -1;
|
||||
else if (sid.IsNumber() && sid.ToLong(&num)) return num;
|
||||
#define stdID(id) else if (sid == _T(#id)) return id
|
||||
stdID(wxID_OPEN); stdID(wxID_CLOSE); stdID(wxID_NEW);
|
||||
stdID(wxID_SAVE); stdID(wxID_SAVEAS); stdID(wxID_REVERT);
|
||||
stdID(wxID_EXIT); stdID(wxID_UNDO); stdID(wxID_REDO);
|
||||
stdID(wxID_HELP); stdID(wxID_PRINT); stdID(wxID_PRINT_SETUP);
|
||||
stdID(wxID_PREVIEW); stdID(wxID_ABOUT); stdID(wxID_HELP_CONTENTS);
|
||||
stdID(wxID_HELP_COMMANDS); stdID(wxID_HELP_PROCEDURES);
|
||||
stdID(wxID_CUT); stdID(wxID_COPY); stdID(wxID_PASTE);
|
||||
stdID(wxID_CLEAR); stdID(wxID_FIND); stdID(wxID_DUPLICATE);
|
||||
stdID(wxID_SELECTALL); stdID(wxID_OK); stdID(wxID_CANCEL);
|
||||
stdID(wxID_APPLY); stdID(wxID_YES); stdID(wxID_NO);
|
||||
stdID(wxID_STATIC); stdID(wxID_FORWARD); stdID(wxID_BACKWARD);
|
||||
stdID(wxID_DEFAULT); stdID(wxID_MORE); stdID(wxID_SETUP);
|
||||
stdID(wxID_RESET); stdID(wxID_HELP_CONTEXT);
|
||||
#undef stdID
|
||||
else return XMLID(sid.c_str());
|
||||
}
|
||||
|
||||
|
||||
wxString wxXmlResourceHandler::GetName()
|
||||
{
|
||||
return m_Node->GetPropVal(_T("name"), _T("-1"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv)
|
||||
{
|
||||
wxString v = GetParamValue(param);
|
||||
v.MakeLower();
|
||||
if (!v) return defaultv;
|
||||
else return v == _T("1") || v == _T("t") || v == _T("yes") ||
|
||||
v == _T("on") || v == _T("true");
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxColour wxXmlResourceHandler::GetColour(const wxString& param)
|
||||
{
|
||||
wxString v = GetParamValue(param);
|
||||
unsigned long tmp = 0;
|
||||
|
||||
if (v.Length() != 7 || v[0] != _T('#') ||
|
||||
wxSscanf(v.c_str(), _T("#%lX"), &tmp) != 1)
|
||||
{
|
||||
wxLogError(_("XML resource: Incorrect colour specification '%s' for property '%s'."),
|
||||
v.c_str(), param.c_str());
|
||||
return wxNullColour;
|
||||
}
|
||||
|
||||
return wxColour((tmp & 0xFF0000) >> 16 ,
|
||||
(tmp & 0x00FF00) >> 8,
|
||||
(tmp & 0x0000FF));
|
||||
}
|
||||
|
||||
|
||||
wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param)
|
||||
{
|
||||
wxXmlNode *n = m_Node->GetChildren();
|
||||
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
|
||||
return n;
|
||||
n = n->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node)
|
||||
{
|
||||
wxXmlNode *n = node;
|
||||
if (n == NULL) return wxEmptyString;
|
||||
n = n->GetChildren();
|
||||
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() == wxXML_TEXT_NODE ||
|
||||
n->GetType() == wxXML_CDATA_SECTION_NODE)
|
||||
return n->GetContent();
|
||||
n = n->GetNext();
|
||||
}
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxXmlResourceHandler::GetParamValue(const wxString& param)
|
||||
{
|
||||
return GetNodeContent(GetParamNode(param));
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxSize wxXmlResourceHandler::GetSize(const wxString& param)
|
||||
{
|
||||
wxString s = GetParamValue(param);
|
||||
if (!s) s = _T("-1,-1");
|
||||
bool is_dlg;
|
||||
long sx, sy;
|
||||
|
||||
is_dlg = s[s.Length()-1] == _T('d');
|
||||
if (is_dlg) s.RemoveLast();
|
||||
|
||||
if (!s.BeforeFirst(_T(',')).ToLong(&sx) ||
|
||||
!s.AfterLast(_T(',')).ToLong(&sy))
|
||||
{
|
||||
wxLogError(_("Cannot parse coordinates from '%s'."), s.mb_str());
|
||||
return wxDefaultSize;
|
||||
}
|
||||
|
||||
if (is_dlg)
|
||||
{
|
||||
if (m_InstanceAsWindow)
|
||||
return wxDLG_UNIT(m_InstanceAsWindow, wxSize(sx, sy));
|
||||
else if (m_ParentAsWindow)
|
||||
return wxDLG_UNIT(m_ParentAsWindow, wxSize(sx, sy));
|
||||
else
|
||||
{
|
||||
wxLogError(_("Cannot convert dialog units: dialog unknown."));
|
||||
return wxDefaultSize;
|
||||
}
|
||||
}
|
||||
else return wxSize(sx, sy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxPoint wxXmlResourceHandler::GetPosition(const wxString& param)
|
||||
{
|
||||
wxSize sz = GetSize(param);
|
||||
return wxPoint(sz.x, sz.y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
|
||||
{
|
||||
//FIXME : add font, cursor
|
||||
|
||||
if (HasParam(_T("exstyle")))
|
||||
wnd->SetExtraStyle(GetStyle(_T("exstyle")));
|
||||
if (HasParam(_T("bg")))
|
||||
wnd->SetBackgroundColour(GetColour(_T("bg")));
|
||||
if (HasParam(_T("fg")))
|
||||
wnd->SetForegroundColour(GetColour(_T("fg")));
|
||||
if (GetBool(_T("enabled"), 1) == 0)
|
||||
wnd->Enable(FALSE);
|
||||
if (GetBool(_T("focused"), 0) == 1)
|
||||
wnd->SetFocus();
|
||||
if (GetBool(_T("hidden"), 0) == 1)
|
||||
wnd->Show(FALSE);
|
||||
#if wxUSE_TOOLTIPS
|
||||
if (HasParam(_T("tooltip")))
|
||||
wnd->SetToolTip(GetText(_T("tooltip")));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void wxXmlResourceHandler::CreateChildren(wxObject *parent,
|
||||
bool only_this_handler, wxXmlNode *children_node)
|
||||
{
|
||||
if (children_node == NULL) children_node = GetParamNode(_T("children"));
|
||||
if (children_node == NULL) return;
|
||||
|
||||
wxXmlNode *n = children_node->GetChildren();
|
||||
|
||||
while (n)
|
||||
{
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE)
|
||||
{
|
||||
if (only_this_handler)
|
||||
{
|
||||
if (CanHandle(n))
|
||||
CreateResource(n, parent, NULL);
|
||||
}
|
||||
else
|
||||
m_Resource->CreateResFromNode(n, parent, NULL);
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// --------------- XMLID implementation -----------------------------
|
||||
|
||||
|
||||
#define XMLID_TABLE_SIZE 1024
|
||||
|
||||
struct XMLID_record
|
||||
{
|
||||
int id;
|
||||
const char *key;
|
||||
XMLID_record *next;
|
||||
};
|
||||
|
||||
static XMLID_record *XMLID_Records[XMLID_TABLE_SIZE] = {NULL};
|
||||
static int XMLID_LastID = wxID_HIGHEST;
|
||||
|
||||
/*static*/ int wxXmlResource::GetXMLID(const char *str_id)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
for (const char *c = str_id; *c != '\0'; c++) index += (int)*c;
|
||||
index %= XMLID_TABLE_SIZE;
|
||||
|
||||
XMLID_record *oldrec = NULL;
|
||||
for (XMLID_record *rec = XMLID_Records[index]; rec; rec = rec->next)
|
||||
{
|
||||
if (strcmp(rec->key, str_id) == 0) return rec->id;
|
||||
oldrec = rec;
|
||||
}
|
||||
|
||||
XMLID_record **rec_var = (oldrec == NULL) ?
|
||||
&XMLID_Records[index] : &oldrec->next;
|
||||
*rec_var = new XMLID_record;
|
||||
(*rec_var)->id = ++XMLID_LastID;
|
||||
(*rec_var)->key = str_id;
|
||||
(*rec_var)->next = NULL;
|
||||
|
||||
return (*rec_var)->id;
|
||||
}
|
||||
|
||||
|
||||
static void CleanXMLID_Record(XMLID_record *rec)
|
||||
{
|
||||
if (rec)
|
||||
{
|
||||
CleanXMLID_Record(rec->next);
|
||||
delete rec;
|
||||
}
|
||||
}
|
||||
|
||||
static void CleanXMLID_Records()
|
||||
{
|
||||
for (int i = 0; i < XMLID_TABLE_SIZE; i++)
|
||||
CleanXMLID_Record(XMLID_Records[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// --------------- module and globals -----------------------------
|
||||
|
||||
|
||||
static wxXmlResource gs_XmlResource;
|
||||
|
||||
wxXmlResource *wxTheXmlResource = &gs_XmlResource;
|
||||
|
||||
|
||||
class wxXmlResourceModule: public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxXmlResourceModule)
|
||||
public:
|
||||
wxXmlResourceModule() {}
|
||||
bool OnInit() {return TRUE;}
|
||||
void OnExit()
|
||||
{
|
||||
wxTheXmlResource->ClearHandlers();
|
||||
CleanXMLID_Records();
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule, wxModule)
|
||||
66
contrib/src/xml/xmlrsall.cpp
Normal file
66
contrib/src/xml/xmlrsall.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: xmlrsall.cpp
|
||||
// Purpose: wxXmlResource::InitAllHandlers
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2000/03/05
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -- Already done in xmlres.cpp
|
||||
//#ifdef __GNUG__
|
||||
//#pragma implementation "xmlres.h"
|
||||
//#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xmlres.h"
|
||||
#include "wx/xml/xh_all.h"
|
||||
|
||||
void wxXmlResource::InitAllHandlers()
|
||||
{
|
||||
AddHandler(new wxMenuXmlHandler);
|
||||
AddHandler(new wxMenuBarXmlHandler);
|
||||
|
||||
AddHandler(new wxDialogXmlHandler);
|
||||
AddHandler(new wxPanelXmlHandler);
|
||||
AddHandler(new wxButtonXmlHandler);
|
||||
#if wxUSE_GAUGE
|
||||
AddHandler(new wxGaugeXmlHandler);
|
||||
#endif
|
||||
#if wxUSE_CHECKBOX
|
||||
AddHandler(new wxCheckBoxXmlHandler);
|
||||
#endif
|
||||
#if wxUSE_HTML
|
||||
AddHandler(new wxHtmlWindowXmlHandler);
|
||||
#endif
|
||||
#if wxUSE_SPINBTN
|
||||
AddHandler(new wxSpinButtonXmlHandler);
|
||||
#endif
|
||||
#if wxUSE_SPINCTRL
|
||||
AddHandler(new wxSpinCtrlXmlHandler);
|
||||
#endif
|
||||
AddHandler(new wxStaticTextXmlHandler);
|
||||
AddHandler(new wxStaticBitmapXmlHandler);
|
||||
AddHandler(new wxSliderXmlHandler);
|
||||
#if wxUSE_RADIOBOX
|
||||
AddHandler(new wxRadioBoxXmlHandler);
|
||||
AddHandler(new wxRadioButtonXmlHandler);
|
||||
#endif
|
||||
#if wxUSE_COMBOBOX
|
||||
AddHandler(new wxComboBoxXmlHandler);
|
||||
#endif
|
||||
AddHandler(new wxChoiceXmlHandler);
|
||||
AddHandler(new wxCheckListXmlHandler);
|
||||
AddHandler(new wxSizerXmlHandler);
|
||||
#if wxUSE_NOTEBOOK
|
||||
AddHandler(new wxNotebookXmlHandler);
|
||||
#endif
|
||||
AddHandler(new wxTextCtrlXmlHandler);
|
||||
}
|
||||
Reference in New Issue
Block a user