From 4a3bdee6a979146c426cd058e9bfe6b58135b124 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 30 Mar 2003 19:47:55 +0000 Subject: [PATCH] New location for some deprecated files git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/deprecated/expr.h | 68 + contrib/include/wx/deprecated/prop.h | 348 +++ contrib/include/wx/deprecated/propform.h | 338 +++ contrib/include/wx/deprecated/proplist.h | 597 ++++ contrib/include/wx/deprecated/resource.h | 209 ++ contrib/include/wx/deprecated/setup.h | 37 + contrib/include/wx/deprecated/treelay.h | 155 + contrib/include/wx/deprecated/wxexpr.h | 285 ++ contrib/src/deprecated/Makefile.in | 26 + contrib/src/deprecated/doslex.c | 1276 +++++++++ contrib/src/deprecated/dosyacc.c | 540 ++++ contrib/src/deprecated/lex_yy.c | 1276 +++++++++ contrib/src/deprecated/lexer.l | 192 ++ contrib/src/deprecated/makefile.b32 | 17 + contrib/src/deprecated/makefile.g95 | 16 + contrib/src/deprecated/makefile.vc | 38 + contrib/src/deprecated/parser.y | 184 ++ contrib/src/deprecated/prop.cpp | 1164 ++++++++ contrib/src/deprecated/propform.cpp | 763 +++++ contrib/src/deprecated/proplist.cpp | 1838 ++++++++++++ contrib/src/deprecated/resource.cpp | 3265 ++++++++++++++++++++++ contrib/src/deprecated/treelay.cpp | 473 ++++ contrib/src/deprecated/wxexpr.cpp | 1280 +++++++++ contrib/src/deprecated/y_tab.c | 538 ++++ 24 files changed, 14923 insertions(+) create mode 100644 contrib/include/wx/deprecated/expr.h create mode 100644 contrib/include/wx/deprecated/prop.h create mode 100644 contrib/include/wx/deprecated/propform.h create mode 100644 contrib/include/wx/deprecated/proplist.h create mode 100644 contrib/include/wx/deprecated/resource.h create mode 100644 contrib/include/wx/deprecated/setup.h create mode 100644 contrib/include/wx/deprecated/treelay.h create mode 100644 contrib/include/wx/deprecated/wxexpr.h create mode 100644 contrib/src/deprecated/Makefile.in create mode 100644 contrib/src/deprecated/doslex.c create mode 100644 contrib/src/deprecated/dosyacc.c create mode 100644 contrib/src/deprecated/lex_yy.c create mode 100644 contrib/src/deprecated/lexer.l create mode 100644 contrib/src/deprecated/makefile.b32 create mode 100644 contrib/src/deprecated/makefile.g95 create mode 100644 contrib/src/deprecated/makefile.vc create mode 100644 contrib/src/deprecated/parser.y create mode 100644 contrib/src/deprecated/prop.cpp create mode 100644 contrib/src/deprecated/propform.cpp create mode 100644 contrib/src/deprecated/proplist.cpp create mode 100644 contrib/src/deprecated/resource.cpp create mode 100644 contrib/src/deprecated/treelay.cpp create mode 100644 contrib/src/deprecated/wxexpr.cpp create mode 100644 contrib/src/deprecated/y_tab.c diff --git a/contrib/include/wx/deprecated/expr.h b/contrib/include/wx/deprecated/expr.h new file mode 100644 index 0000000000..90c233795f --- /dev/null +++ b/contrib/include/wx/deprecated/expr.h @@ -0,0 +1,68 @@ +/* ////////////////////////////////////////////////////////////////////////// +// Name: expr.h +// Purpose: C helper defines and functions for wxExpr class +// Author: Julian Smart +// Modified by: +// Created: 01/02/97 +// RCS-ID: $Id$ +// Copyright: (c) +// Licence: wxWindows licence +////////////////////////////////////////////////////////////////////////// */ + +#ifndef _WX_EXPRH__ +#define _WX_EXPRH__ + +#include +#if defined(__VISAGECPP__) && __IBMCPP__ >= 400 +# undef __BSEXCPT__ +#endif +#include + +#ifdef ____HPUX__ +#define alloca malloc +#endif + + +#ifdef __cplusplus +extern "C" { +char *proio_cons(char *, char *); +char * wxmake_integer(char *); +char * wxmake_word(char *); +char * wxmake_string(char *); +char * wxmake_real(char *, char *); +char * wxmake_exp(char *, char *); +char * wxmake_exp2(char *, char *, char*); +void add_expr(char *); +void process_command(char *); +void syntax_error(char *); +} +#else +#if defined(__BORLANDC__) || defined(__VISAGECPP__) +char *proio_cons(char *, char *); +char * wxmake_integer(char *); +char * wxmake_word(char *); +char * wxmake_string(char *); +char * wxmake_real(char *, char *); +char * wxmake_exp(char *, char *); +char * wxmake_exp2(char *, char *, char*); +void add_expr(char *); +void process_command(char *); +void syntax_error(char *); +int lex_input(void); +#else +char *proio_cons(); +char * wxmake_integer(); +char * wxmake_word(); +char * wxmake_string(); +char * wxmake_real(); +char * wxmake_exp(); +char * wxmake_exp2(); + +void add_expr(); +void process_command(); +void syntax_error(); +#endif +#endif + +#endif + /* _WX_EXPRH__ */ diff --git a/contrib/include/wx/deprecated/prop.h b/contrib/include/wx/deprecated/prop.h new file mode 100644 index 0000000000..8882220e2f --- /dev/null +++ b/contrib/include/wx/deprecated/prop.h @@ -0,0 +1,348 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: prop.h +// Purpose: Property sheet classes +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_PROP_H_ +#define _WX_PROP_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "prop.h" +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROPSHEET + +#include "wx/defs.h" +#include "wx/string.h" +#include "wx/hash.h" +#include "wx/dialog.h" +#include "wx/frame.h" +#include "wx/button.h" +#include "wx/listbox.h" +#include "wx/textctrl.h" +#include "wx/gdicmn.h" +#include "wx/layout.h" +#include "wx/sizer.h" + +class wxWindow; +class wxProperty; +class wxPropertyValue; +class wxPropertySheet; +class wxPropertyView; +class wxPropertyValidator; +class wxPropertyValidatorRegistry; + +#define wxPROPERTY_VERSION 2.0 + +// A storable sheet of values +class WXDLLEXPORT wxPropertySheet: public wxObject +{ +public: + wxPropertySheet(const wxString& name = wxT("")); + ~wxPropertySheet(); + + // Set the name of the sheet + inline virtual void SetName(const wxString& name) { m_name=name; } + inline virtual wxString GetName() const { return m_name; } + + // Does this sheet contain a property with this name + virtual bool HasProperty(const wxString& name) const; + + // Set property name to value + virtual bool SetProperty(const wxString& name, const wxPropertyValue& value); + + // Remove property from sheet by name, deleting it + virtual void RemoveProperty(const wxString& name); + + // Get the name of the sheet + // Add a property + virtual void AddProperty(wxProperty *property); + + // Get property by name + virtual wxProperty *GetProperty(const wxString& name) const; + + // Clear all properties + virtual void Clear(); + + virtual void UpdateAllViews(wxPropertyView *thisView = NULL); + inline virtual wxList& GetProperties() const { return (wxList&) m_properties; } + + // Sets/clears the modified flag for each property value + virtual void SetAllModified(bool flag = TRUE); + +protected: + wxObject* m_viewedObject; + wxList m_properties; + wxPropertyView* m_propertyView; + wxString m_name; + +private: + DECLARE_DYNAMIC_CLASS(wxPropertySheet) +}; + + +// Base class for property sheet views. There are currently two directly derived +// classes: wxPropertyListView, and wxPropertyFormView. +class WXDLLEXPORT wxPropertyView: public wxEvtHandler +{ +public: + wxPropertyView(long flags = 0); + ~wxPropertyView(); + + // Associates and shows the view + virtual void ShowView(wxPropertySheet *WXUNUSED(propertySheet), wxWindow *WXUNUSED(panel)) {} + + // Update this view of the viewed object, called e.g. by + // the object itself. + virtual bool OnUpdateView() {return FALSE;}; + + // Override this to do something as soon as the property changed, + // if the view and validators support it. + virtual void OnPropertyChanged(wxProperty *WXUNUSED(property)) {} + + virtual void AddRegistry(wxPropertyValidatorRegistry *registry); + inline virtual wxList& GetRegistryList() const + { return (wxList&) m_validatorRegistryList; } + + virtual wxPropertyValidator *FindPropertyValidator(wxProperty *property); + inline virtual void SetPropertySheet(wxPropertySheet *sheet) { m_propertySheet = sheet; } + inline virtual wxPropertySheet *GetPropertySheet() const { return m_propertySheet; } + + inline virtual bool OnClose() { return FALSE; } + inline long GetFlags(void) { return m_buttonFlags; } + +protected: + long m_buttonFlags; + wxPropertySheet* m_propertySheet; + wxProperty* m_currentProperty; + wxList m_validatorRegistryList; + wxPropertyValidator* m_currentValidator; + +private: + DECLARE_DYNAMIC_CLASS(wxPropertyView) +}; + + +class WXDLLEXPORT wxPropertyValidator: public wxEvtHandler +{ +public: + wxPropertyValidator(long flags = 0); + ~wxPropertyValidator(); + + inline long GetFlags() const { return m_validatorFlags; } + inline void SetValidatorProperty(wxProperty *prop) { m_validatorProperty = prop; } + inline wxProperty *GetValidatorProperty(void) const { return m_validatorProperty; } + + virtual bool StringToFloat (wxChar *s, float *number); + virtual bool StringToDouble (wxChar *s, double *number); + virtual bool StringToInt (wxChar *s, int *number); + virtual bool StringToLong (wxChar *s, long *number); + virtual wxChar *FloatToString (float number); + virtual wxChar *DoubleToString (double number); + virtual wxChar *IntToString (int number); + virtual wxChar *LongToString (long number); + +protected: + long m_validatorFlags; + wxProperty* m_validatorProperty; + +private: + DECLARE_DYNAMIC_CLASS(wxPropertyValidator) +}; + + +// extern wxPropertyValidator *wxDefaultPropertyValidator; + +class WXDLLEXPORT wxPropertyValidatorRegistry: public wxHashTable +{ +public: + wxPropertyValidatorRegistry(); + ~wxPropertyValidatorRegistry(); + + virtual void RegisterValidator(const wxString& roleName, wxPropertyValidator *validator); + virtual wxPropertyValidator *GetValidator(const wxString& roleName); + void ClearRegistry(); + +private: + DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry) +}; + +/* + * Property value class + */ + +typedef enum { + wxPropertyValueNull, + wxPropertyValueInteger, + wxPropertyValueReal, + wxPropertyValuebool, + wxPropertyValueString, + wxPropertyValueList, + wxPropertyValueIntegerPtr, + wxPropertyValueRealPtr, + wxPropertyValueboolPtr, + wxPropertyValueStringPtr +} wxPropertyValueType; + +class WXDLLEXPORT wxPropertyValue: public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxPropertyValue) + + wxPropertyValue(void); // Unknown type + wxPropertyValue(const wxPropertyValue& copyFrom); // Copy constructor + wxPropertyValue(const wxChar *val); + wxPropertyValue(const wxString& val); + wxPropertyValue(long val); + wxPropertyValue(bool val); + wxPropertyValue(float val); + wxPropertyValue(double the_real); + wxPropertyValue(wxList *val); + wxPropertyValue(wxStringList *val); + // Pointer versions + wxPropertyValue(wxChar **val); + wxPropertyValue(long *val); + wxPropertyValue(bool *val); + wxPropertyValue(float *val); + + ~wxPropertyValue(void); + + virtual inline wxPropertyValueType Type(void) const { return m_type; } + virtual inline void SetType(wxPropertyValueType typ) { m_type = typ; } + virtual long IntegerValue(void) const; + virtual float RealValue(void) const; + virtual bool BoolValue(void) const; + virtual wxChar *StringValue(void) const; + virtual long *IntegerValuePtr(void) const; + virtual float *RealValuePtr(void) const; + virtual bool *BoolValuePtr(void) const; + virtual wxChar **StringValuePtr(void) const; + + // Get nth arg of clause (starting from 1) + virtual wxPropertyValue *Arg(wxPropertyValueType type, int arg) const; + + // Return nth argument of a list expression (starting from zero) + virtual wxPropertyValue *Nth(int arg) const; + // Returns the number of elements in a list expression + virtual int Number(void) const; + + virtual wxPropertyValue *NewCopy(void) const; + virtual void Copy(wxPropertyValue& copyFrom); + + virtual void WritePropertyClause(wxString &stream); // Write this expression as a top-level clause + virtual void WritePropertyType(wxString &stream); // Write as any other subexpression + + // Append an expression to a list + virtual void Append(wxPropertyValue *expr); + // Insert at beginning of list + virtual void Insert(wxPropertyValue *expr); + + // Get first expr in list + virtual inline wxPropertyValue *GetFirst(void) const + { return ((m_type == wxPropertyValueList) ? m_value.first : (wxPropertyValue*)NULL); } + + // Get next expr if this is a node in a list + virtual inline wxPropertyValue *GetNext(void) const + { return m_next; } + + // Get last expr in list + virtual inline wxPropertyValue *GetLast(void) const + { return ((m_type == wxPropertyValueList) ? m_last : (wxPropertyValue*)NULL); } + + // Delete this node from the list + virtual void Delete(wxPropertyValue *node); + + // Clear list + virtual void ClearList(void); + + virtual inline void SetClientData(wxObject *data) { m_clientData = data; } + virtual inline wxObject *GetClientData(void) { return m_clientData; } + + virtual wxString GetStringRepresentation(void); + + inline void SetModified(bool flag = TRUE) { m_modifiedFlag = flag; } + inline bool GetModified(void) { return m_modifiedFlag; } + + // Operators + void operator=(const wxPropertyValue& val); +// void operator=(const char *val); + void operator=(const wxString& val); + void operator=(const long val); + void operator=(const bool val); + void operator=(const float val); + void operator=(const wxChar **val); + void operator=(const long *val); + void operator=(const bool *val); + void operator=(const float *val); + + public: + wxObject* m_clientData; + wxPropertyValueType m_type; + bool m_modifiedFlag; + + union { + long integer; // Also doubles as bool + wxChar *string; + float real; + long *integerPtr; + bool *boolPtr; + wxChar **stringPtr; + float *realPtr; + wxPropertyValue *first; // If is a list expr, points to the first node + } m_value; + + wxPropertyValue* m_next; // If this is a node in a list, points to the next node + wxPropertyValue* m_last; // If is a list expr, points to the last node + +}; + +/* + * Property class: contains a name and a value. + */ + +class WXDLLEXPORT wxProperty: public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxProperty) + protected: + bool m_enabled; + public: + wxPropertyValue m_value; + wxString m_name; + wxString m_propertyRole; + wxPropertyValidator* m_propertyValidator; + wxWindow* m_propertyWindow; // Usually a panel item, if anything + + wxProperty(void); + wxProperty(wxProperty& copyFrom); + wxProperty(wxString name, wxString role, wxPropertyValidator *ed = NULL); + wxProperty(wxString name, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed = NULL); + ~wxProperty(void); + + virtual wxPropertyValue& GetValue(void) const; + virtual wxPropertyValidator *GetValidator(void) const; + virtual wxString& GetName(void) const; + virtual wxString& GetRole(void) const; + virtual void SetValue(const wxPropertyValue& val); + virtual void SetValidator(wxPropertyValidator *v); + virtual void SetName(wxString& nm); + virtual void SetRole(wxString& role); + void operator=(const wxPropertyValue& val); + virtual inline void SetWindow(wxWindow *win) { m_propertyWindow = win; } + virtual inline wxWindow *GetWindow(void) const { return m_propertyWindow; } + + inline void Enable(bool en) { m_enabled = en; } + inline bool IsEnabled(void) const { return m_enabled; } +}; + +#endif + // wxUSE_PROPSHEET + +#endif + // _WX_PROP_H_ diff --git a/contrib/include/wx/deprecated/propform.h b/contrib/include/wx/deprecated/propform.h new file mode 100644 index 0000000000..dabcc80eb0 --- /dev/null +++ b/contrib/include/wx/deprecated/propform.h @@ -0,0 +1,338 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: propform.h +// Purpose: Property form classes +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_PROPFORM_H_ +#define _WX_PROPFORM_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "propform.h" +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROPSHEET + +#include "wx/deprecated/prop.h" +#include "wx/panel.h" + +class WXDLLEXPORT wxPropertyFormView; + +//// +//// Property form classes: for using an existing dialog or panel +//// + +#define wxID_PROP_REVERT 3100 +#define wxID_PROP_UPDATE 3101 + +// Mediates between a physical panel and the property sheet +class WXDLLEXPORT wxPropertyFormView: public wxPropertyView +{ + DECLARE_DYNAMIC_CLASS(wxPropertyFormView) + public: + wxPropertyFormView(wxWindow *propPanel = NULL, long flags = 0); + ~wxPropertyFormView(void); + + // Associates and shows the view + virtual void ShowView(wxPropertySheet *propertySheet, wxWindow *panel); + + // Update this view of the viewed object, called e.g. by + // the object itself. + virtual bool OnUpdateView(void); + + // Transfer values from property sheet to dialog + virtual bool TransferToDialog(void); + + // Transfer values from dialog to property sheet + virtual bool TransferToPropertySheet(void); + + // Check that all the values are valid + virtual bool Check(void); + + // Give each property in the sheet a panel item, by matching + // the name of the property to the name of the panel item. + // The user doesn't always want to call this; sometimes, it + // will have been done explicitly (e.g., no matching names). + virtual bool AssociateNames(void); + + void OnOk(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + void OnHelp(wxCommandEvent& event); + void OnUpdate(wxCommandEvent& event); + void OnRevert(wxCommandEvent& event); + + virtual bool OnClose(); + virtual void OnDoubleClick(wxControl *item); + + // TODO: does OnCommand still get called...??? No, + // make ProcessEvent do it. + virtual void OnCommand(wxWindow& win, wxCommandEvent& event); + + // Extend event processing to process OnCommand + virtual bool ProcessEvent(wxEvent& event); + + inline virtual void AssociatePanel(wxWindow *win) { m_propertyWindow = win; } + inline virtual wxWindow *GetPanel(void) const { return m_propertyWindow; } + + inline virtual void SetManagedWindow(wxWindow *win) { m_managedWindow = win; } + inline virtual wxWindow *GetManagedWindow(void) const { return m_managedWindow; } + + inline virtual wxButton *GetWindowCloseButton() const { return m_windowCloseButton; } + inline virtual wxButton *GetWindowCancelButton() const { return m_windowCancelButton; } + inline virtual wxButton *GetHelpButton() const { return m_windowHelpButton; } + +public: + static bool sm_dialogCancelled; + + protected: + bool m_detailedEditing; // E.g. using listbox for choices + + wxWindow* m_propertyWindow; // Panel that the controls will appear on + wxWindow* m_managedWindow; // Frame or dialog + + wxButton* m_windowCloseButton; // Or OK + wxButton* m_windowCancelButton; + wxButton* m_windowHelpButton; + +DECLARE_EVENT_TABLE() + +}; + +/* + * The type of validator used for forms (wxForm style but using an existing panel + * or dialog box). + * Classes derived from this know how to map from whatever widget they + * find themselves paired with, to the wxProperty and vice versa. + * Should the widget pointer be stored with the validator, or + * the wxProperty? If with the property, we don't have to supply + * a validator for every property. Otherwise, there ALWAYS needs + * to be a validator. On the other hand, not storing a wxWindow pointer + * in the wxProperty is more elegant. Perhaps. + * I think on balance, should put wxWindow pointer into wxProperty. + * After all, wxProperty will often be used to represent the data + * assocated with a window. It's that kinda thing. + */ + +class WXDLLEXPORT wxPropertyFormValidator: public wxPropertyValidator +{ + DECLARE_DYNAMIC_CLASS(wxPropertyFormValidator) + protected: + public: + wxPropertyFormValidator(long flags = 0): wxPropertyValidator(flags) { } + ~wxPropertyFormValidator(void) {} + + // Called to check value is OK (e.g. when OK is pressed) + // Return FALSE if value didn't check out; signal to restore old value. + virtual bool OnCheckValue( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) { return TRUE; } + + // Does the transferance from the property editing area to the property itself. + // Called by the view, e.g. when closing the window. + virtual bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) = 0; + + // Called by the view to transfer the property to the window. + virtual bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) = 0; + + virtual void OnDoubleClick( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) { } + virtual void OnSetFocus( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) { } + virtual void OnKillFocus( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) { } + virtual void OnCommand( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow), wxCommandEvent& WXUNUSED(event) ) {} +private: +// Virtual function hiding suppression +#if WXWIN_COMPATIBILITY_2 + virtual void OnCommand(wxWindow& win, + wxCommandEvent& event) + { wxEvtHandler::OnCommand(win, event); } +#endif +}; + +/* + * Some default validators + */ + +class WXDLLEXPORT wxRealFormValidator: public wxPropertyFormValidator +{ + DECLARE_DYNAMIC_CLASS(wxRealFormValidator) + public: + // 0.0, 0.0 means no range + wxRealFormValidator(float min = 0.0, float max = 0.0, long flags = 0):wxPropertyFormValidator(flags) + { + m_realMin = min; m_realMax = max; + } + ~wxRealFormValidator(void) {} + + bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + // Called by the view to transfer the property to the window. + bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + + protected: + float m_realMin; + float m_realMax; +}; + +class WXDLLEXPORT wxIntegerFormValidator: public wxPropertyFormValidator +{ + DECLARE_DYNAMIC_CLASS(wxIntegerFormValidator) + public: + // 0, 0 means no range + wxIntegerFormValidator(long min = 0, long max = 0, long flags = 0):wxPropertyFormValidator(flags) + { + m_integerMin = min; m_integerMax = max; + } + ~wxIntegerFormValidator(void) {} + + bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + + protected: + long m_integerMin; + long m_integerMax; +}; + +class WXDLLEXPORT wxBoolFormValidator: public wxPropertyFormValidator +{ + DECLARE_DYNAMIC_CLASS(wxBoolFormValidator) + protected: + public: + wxBoolFormValidator(long flags = 0):wxPropertyFormValidator(flags) + { + } + ~wxBoolFormValidator(void) {} + + bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); +}; + +class WXDLLEXPORT wxStringFormValidator: public wxPropertyFormValidator +{ + DECLARE_DYNAMIC_CLASS(wxStringFormValidator) + public: + wxStringFormValidator(wxStringList *list = NULL, long flags = 0); + + ~wxStringFormValidator(void) + { + if (m_strings) + delete m_strings; + } + + bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); + + protected: + wxStringList* m_strings; +}; + +/* + * A default dialog box class to use. + */ + +class WXDLLEXPORT wxPropertyFormDialog: public wxDialog +{ +public: + wxPropertyFormDialog(wxPropertyFormView *v = NULL, + wxWindow *parent = NULL, + const wxString& title = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_DIALOG_STYLE, + const wxString& name = _T("dialogBox")); + + void OnCloseWindow(wxCloseEvent& event); + void OnDefaultAction(wxControl *item); + void OnCommand(wxWindow& win, wxCommandEvent& event); + + // Extend event processing to search the view's event table + virtual bool ProcessEvent(wxEvent& event); + +private: + wxPropertyFormView* m_view; + + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxPropertyFormDialog) +}; + +/* + * A default panel class to use. + */ + +class WXDLLEXPORT wxPropertyFormPanel: public wxPanel +{ +public: + wxPropertyFormPanel(wxPropertyFormView *v = NULL, + wxWindow *parent = NULL, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = _T("panel")) + : wxPanel(parent, -1, pos, size, style, name) + { + m_view = v; + } + void OnDefaultAction(wxControl *item); + void OnCommand(wxWindow& win, wxCommandEvent& event); + + // Extend event processing to search the view's event table + virtual bool ProcessEvent(wxEvent& event); + void SetView(wxPropertyFormView* view) { m_view = view; } + wxPropertyFormView* GetView() const { return m_view; } + +private: + wxPropertyFormView* m_view; + + DECLARE_CLASS(wxPropertyFormPanel) +}; + +/* + * A default frame class to use. + */ + +class WXDLLEXPORT wxPropertyFormFrame: public wxFrame +{ +public: + wxPropertyFormFrame(wxPropertyFormView *v = NULL, + wxFrame *parent = NULL, + const wxString& title = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = _T("frame")) + : wxFrame(parent, -1, title, pos, size, style, name) + { + m_view = v; + m_propertyPanel = NULL; + } + void OnCloseWindow(wxCloseEvent& event); + + // Must call this to create panel and associate view + virtual bool Initialize(void); + virtual wxPanel *OnCreatePanel(wxFrame *parent, wxPropertyFormView *v); + inline virtual wxPanel *GetPropertyPanel(void) const { return m_propertyPanel; } + +private: + wxPropertyFormView* m_view; + wxPanel* m_propertyPanel; + + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxPropertyFormFrame) +}; + +#endif + // wxUSE_PROPSHEET + +#endif + // _WX_PROPFORM_H_ diff --git a/contrib/include/wx/deprecated/proplist.h b/contrib/include/wx/deprecated/proplist.h new file mode 100644 index 0000000000..02c874e532 --- /dev/null +++ b/contrib/include/wx/deprecated/proplist.h @@ -0,0 +1,597 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: proplist.h +// Purpose: Property list classes +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + + /* + + TO DO: + + (1) Optional popup-help for each item, and an optional Help button + for dialog. + + (2) Align Ok, Cancel, Help buttons properly. + + (3) Consider retrieving the rectangle on the panel that can be + drawn into (where the value listbox is) and giving an example + of editing graphically. May be too fancy. + + (4) Deriveable types for wxPropertyValue => may need to reorganise + wxPropertyValue to use inheritance rather than present all-types-in-one + scheme. + + (5) Optional popup panel for value list, perhaps. + + (6) Floating point checking routine still crashes with Floating + point error for zany input. + + (7) Property sheet with choice (or listbox) to select alternative + sheets... multiple views per panel, only one active. For this + we really need a wxChoice that can be dynamically set: XView + may be a problem; Motif? + + (8) More example validators, e.g. colour selector. + */ + +#ifndef _WX_PROPLIST_H_ +#define _WX_PROPLIST_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "proplist.h" +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROPSHEET + +#include "wx/deprecated/prop.h" +#include "wx/panel.h" + +#define wxPROP_BUTTON_CLOSE 1 +#define wxPROP_BUTTON_OK 2 +#define wxPROP_BUTTON_CANCEL 4 +#define wxPROP_BUTTON_CHECK_CROSS 8 +#define wxPROP_BUTTON_HELP 16 +#define wxPROP_DYNAMIC_VALUE_FIELD 32 +#define wxPROP_PULLDOWN 64 +#define wxPROP_SHOWVALUES 128 + +// Show OK/Cancel buttons on X-based systems where window management is +// more awkward +#if defined(__WXMOTIF__) || defined(__WXGTK__) +#define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN +#else +#define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES +#endif + +#define wxID_PROP_CROSS 3000 +#define wxID_PROP_CHECK 3001 +#define wxID_PROP_EDIT 3002 +#define wxID_PROP_TEXT 3003 +#define wxID_PROP_SELECT 3004 +#define wxID_PROP_VALUE_SELECT 3005 + +// Mediates between a physical panel and the property sheet +class WXDLLEXPORT wxPropertyListView: public wxPropertyView +{ +public: + wxPropertyListView(wxPanel *propPanel = NULL, long flags = wxPROP_BUTTON_DEFAULT); + ~wxPropertyListView(void); + + // Associates and shows the view + virtual void ShowView(wxPropertySheet *propertySheet, wxPanel *panel); + + // Update this view of the viewed object, called e.g. by + // the object itself. + virtual bool OnUpdateView(void); + + wxString MakeNameValueString(wxString name, wxString value); + + // Update a single line in the list of properties + virtual bool UpdatePropertyDisplayInList(wxProperty *property); + + // Update the whole list + virtual bool UpdatePropertyList(bool clearEditArea = TRUE); + + // Find the wxListBox index corresponding to this property + virtual int FindListIndexForProperty(wxProperty *property); + + // Select and show string representation in editor the given + // property. NULL resets to show no property. + virtual bool ShowProperty(wxProperty *property, bool select = TRUE); + virtual bool EditProperty(wxProperty *property); + + // Update the display from the property + virtual bool DisplayProperty(wxProperty *property); + // Update the property from the display + virtual bool RetrieveProperty(wxProperty *property); + + // Find appropriate validator and load property into value controls + virtual bool BeginShowingProperty(wxProperty *property); + // Find appropriate validator and unload property from value controls + virtual bool EndShowingProperty(wxProperty *property); + + // Begin detailed editing (e.g. using value listbox) + virtual void BeginDetailedEditing(void); + + // End detailed editing (e.g. using value listbox) + virtual void EndDetailedEditing(void); + + // Called by the property listbox + void OnPropertySelect(wxCommandEvent& event); + + // Called by the value listbox + void OnValueListSelect(wxCommandEvent& event); + + virtual bool CreateControls(void); + virtual void ShowTextControl(bool show); + virtual void ShowListBoxControl(bool show); + virtual void EnableCheck(bool show); + virtual void EnableCross(bool show); + + void OnOk(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + void OnHelp(wxCommandEvent& event); + void OnPropertyDoubleClick(wxCommandEvent& event); +// virtual void OnDoubleClick(void); + + void OnCheck(wxCommandEvent& event); + void OnCross(wxCommandEvent& event); + void OnEdit(wxCommandEvent& event); + void OnText(wxCommandEvent& event); + + inline virtual wxListBox *GetPropertyScrollingList() const { return m_propertyScrollingList; } + inline virtual wxListBox *GetValueList() const { return m_valueList; } + inline virtual wxTextCtrl *GetValueText() const { return m_valueText; } + inline virtual wxButton *GetConfirmButton() const { return m_confirmButton; } + inline virtual wxButton *GetCancelButton() const { return m_cancelButton; } + inline virtual wxButton *GetEditButton() const { return m_editButton; } + inline virtual bool GetDetailedEditing(void) const { return m_detailedEditing; } + + inline virtual void AssociatePanel(wxPanel *win) { m_propertyWindow = win; } + inline virtual wxPanel *GetPanel(void) const { return m_propertyWindow; } + + inline virtual void SetManagedWindow(wxWindow *win) { m_managedWindow = win; } + inline virtual wxWindow *GetManagedWindow(void) const { return m_managedWindow; } + + inline virtual wxButton *GetWindowCloseButton() const { return m_windowCloseButton; } + inline virtual wxButton *GetWindowCancelButton() const { return m_windowCancelButton; } + inline virtual wxButton *GetHelpButton() const { return m_windowHelpButton; } + + bool OnClose(void); + +public: + static bool sm_dialogCancelled; + + protected: + wxListBox* m_propertyScrollingList; + wxListBox* m_valueList; // Should really be a combobox, but we don't have one. + wxTextCtrl* m_valueText; + wxButton* m_confirmButton; // A tick, as in VB + wxButton* m_cancelButton; // A cross, as in VB + wxButton* m_editButton; // Invokes the custom validator, if any + wxSizer* m_middleSizer; + + bool m_detailedEditing; // E.g. using listbox for choices + + wxPanel* m_propertyWindow; // Panel that the controls will appear on + wxWindow* m_managedWindow; // Frame or dialog + + wxButton* m_windowCloseButton; // Or OK + wxButton* m_windowCancelButton; + wxButton* m_windowHelpButton; + +private: + DECLARE_DYNAMIC_CLASS(wxPropertyListView) + DECLARE_EVENT_TABLE() + + virtual void ShowView(wxPropertySheet *propertySheet, wxWindow *window) + { wxPropertyView::ShowView(propertySheet, window); }; +}; + +class WXDLLEXPORT wxPropertyTextEdit: public wxTextCtrl +{ +public: + wxPropertyTextEdit(wxPropertyListView *v = NULL, + wxWindow *parent = NULL, + const wxWindowID id = -1, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxT("text")); + + void OnSetFocus(); + void OnKillFocus(); + + wxPropertyListView* m_view; + +private: + DECLARE_CLASS(wxPropertyTextEdit) +}; + +#define wxPROP_ALLOW_TEXT_EDITING 1 + +/* + * The type of validator used for property lists (Visual Basic style) + */ + +class WXDLLEXPORT wxPropertyListValidator: public wxPropertyValidator +{ +public: + wxPropertyListValidator(long flags = wxPROP_ALLOW_TEXT_EDITING): wxPropertyValidator(flags) { } + ~wxPropertyListValidator() {} + + // Called when the property is selected or deselected: typically displays the value + // in the edit control (having chosen a suitable control to display: (non)editable text or listbox) + virtual bool OnSelect(bool select, wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the property is double clicked. Extra functionality can be provided, such as + // cycling through possible values. + inline virtual bool OnDoubleClick( + wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) ) + { return TRUE; } + + // Called when the value listbox is selected. Default behaviour is to copy + // string to text control, and retrieve the value into the property. + virtual bool OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the property value is edited using standard text control + inline virtual bool OnPrepareControls( + wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) ) + { return TRUE; } + + virtual bool OnClearControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the property is edited in detail + inline virtual bool OnPrepareDetailControls( + wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) ) + { return TRUE; } + + // Called if focus lost, IF we're in a modeless property editing situation. + inline virtual bool OnClearDetailControls( + wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) ) + { return TRUE; } + + // Called when the edit (...) button is pressed. The default implementation + // calls view->BeginDetailedEditing; the filename validator (for example) overrides + // this function to show the file selector. + virtual void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + inline virtual bool OnCheckValue( + wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) ) + { return TRUE; } + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transferance from the property editing area to the property itself + virtual bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + virtual bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +private: + DECLARE_DYNAMIC_CLASS(wxPropertyListValidator) +}; + +/* + * A default dialog box class to use. + */ + +class WXDLLEXPORT wxPropertyListDialog: public wxDialog +{ +public: + wxPropertyListDialog(wxPropertyListView *v = NULL, + wxWindow *parent = NULL, + const wxString& title = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_DIALOG_STYLE, + const wxString& name = wxT("dialogBox")); + + void OnCloseWindow(wxCloseEvent& event); + void OnDefaultAction(wxControl *item); + void OnCancel(wxCommandEvent& event); + + // Extend event processing to search the view's event table + virtual bool ProcessEvent(wxEvent& event); + +private: + wxPropertyListView* m_view; + +private: + DECLARE_CLASS(wxPropertyListDialog) + DECLARE_EVENT_TABLE() +}; + +/* + * A default panel class to use. + */ + +class WXDLLEXPORT wxPropertyListPanel: public wxPanel +{ +public: + wxPropertyListPanel(wxPropertyListView *v = NULL, + wxWindow *parent = NULL, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxT("panel")) + : wxPanel(parent, -1, pos, size, style, name) + { + m_view = v; + } + ~wxPropertyListPanel(); + void OnDefaultAction(wxControl *item); + + inline void SetView(wxPropertyListView* v) { m_view = v; } + inline wxPropertyListView* GetView() const { return m_view; } + + // Extend event processing to search the view's event table + virtual bool ProcessEvent(wxEvent& event); + + // Call Layout() + void OnSize(wxSizeEvent& event); + +private: + wxPropertyListView* m_view; + +private: + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxPropertyListPanel) +}; + +/* + * A default frame class to use. + */ + +class WXDLLEXPORT wxPropertyListFrame: public wxFrame +{ +public: + wxPropertyListFrame(wxPropertyListView *v = NULL, + wxFrame *parent = NULL, + const wxString& title = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = _T("frame")) + : wxFrame(parent, -1, title, pos, size, style, name) + { + m_view = v; + m_propertyPanel = NULL; + } + void OnCloseWindow(wxCloseEvent& event); + + // Must call this to create panel and associate view + virtual bool Initialize(void); + virtual wxPropertyListPanel *OnCreatePanel(wxFrame *parent, wxPropertyListView *v); + inline virtual wxPropertyListPanel *GetPropertyPanel(void) const { return m_propertyPanel; } + inline wxPropertyListView* GetView() const { return m_view; } + +private: + wxPropertyListView* m_view; + wxPropertyListPanel* m_propertyPanel; + +private: + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxPropertyListFrame) +}; + +/* + * Some default validators + */ + +class WXDLLEXPORT wxRealListValidator: public wxPropertyListValidator +{ +public: + // 0.0, 0.0 means no range + wxRealListValidator(float min = 0.0, float max = 0.0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags) + { m_realMin = min; m_realMax = max; } + ~wxRealListValidator() {} + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transfer from the property editing area to the property itself + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +protected: + float m_realMin; + float m_realMax; + +private: + DECLARE_DYNAMIC_CLASS(wxRealListValidator) +}; + +class WXDLLEXPORT wxIntegerListValidator: public wxPropertyListValidator +{ +public: + // 0, 0 means no range + wxIntegerListValidator(long min = 0, long max = 0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags) + { + m_integerMin = min; m_integerMax = max; + } + ~wxIntegerListValidator() {} + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transfer from the property editing area to the property itself + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +protected: + long m_integerMin; + long m_integerMax; + +private: + DECLARE_DYNAMIC_CLASS(wxIntegerListValidator) +}; + +class WXDLLEXPORT wxBoolListValidator: public wxPropertyListValidator +{ +public: + wxBoolListValidator(long flags = 0):wxPropertyListValidator(flags) {} + ~wxBoolListValidator() {} + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnClearDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transfer from the property editing area to the property itself + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the property is double clicked. Extra functionality can be provided, + // cycling through possible values. + virtual bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +private: + DECLARE_DYNAMIC_CLASS(wxBoolListValidator) +}; + +class WXDLLEXPORT wxStringListValidator: public wxPropertyListValidator +{ +public: + wxStringListValidator(wxStringList *list = NULL, long flags = 0); + + ~wxStringListValidator() + { + if (m_strings) + delete m_strings; + } + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnClearDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transfer from the property editing area to the property itself + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the property is double clicked. Extra functionality can be provided, + // cycling through possible values. + bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +protected: + wxStringList* m_strings; + +private: + DECLARE_DYNAMIC_CLASS(wxStringListValidator) +}; + +class WXDLLEXPORT wxFilenameListValidator: public wxPropertyListValidator +{ +public: + wxFilenameListValidator(wxString message = wxT("Select a file"), wxString wildcard = wxALL_FILES_PATTERN, long flags = 0); + ~wxFilenameListValidator(); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transferance from the property editing area to the property itself + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the edit (...) button is pressed. + void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +protected: + wxString m_filenameWildCard; + wxString m_filenameMessage; + +private: + DECLARE_DYNAMIC_CLASS(wxFilenameListValidator) +}; + +class WXDLLEXPORT wxColourListValidator: public wxPropertyListValidator +{ +public: + wxColourListValidator(long flags = 0); + ~wxColourListValidator(); + + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the edit (...) button is pressed. + void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +private: + DECLARE_DYNAMIC_CLASS(wxColourListValidator) +}; + +class WXDLLEXPORT wxListOfStringsListValidator: public wxPropertyListValidator +{ +public: + wxListOfStringsListValidator(long flags = 0); + ~wxListOfStringsListValidator() {} + + bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost. + // Return FALSE if value didn't check out; signal to restore old value. + bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when TICK is pressed or focus is lost or view wants to update + // the property list. + // Does the transfer from the property editing area to the property itself + bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + // Called when the property is double clicked. + bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + + bool EditStringList(wxWindow *parent, wxStringList *stringList, const wxChar *title = wxT("String List Editor")); + + // Called when the edit (...) button is pressed. + void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow); + +private: + DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator) +}; + +#endif + // wxUSE_PROPSHEET + +#endif + // _WX_PROPLIST_H_ diff --git a/contrib/include/wx/deprecated/resource.h b/contrib/include/wx/deprecated/resource.h new file mode 100644 index 0000000000..d9823a377b --- /dev/null +++ b/contrib/include/wx/deprecated/resource.h @@ -0,0 +1,209 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: resource.h +// Purpose: Resource processing +// Author: Julian Smart +// Modified by: +// Created: 01/02/97 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_RESOURCEH__ +#define _WX_RESOURCEH__ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "resource.h" +#endif + +#include "wx/setup.h" +#include "wx/deprecated/setup.h" + +#if wxUSE_WX_RESOURCES + +#include "wx/bitmap.h" +#include + +// A few further types not in wx_types.h +#define wxRESOURCE_TYPE_SEPARATOR 1000 +#define wxRESOURCE_TYPE_XBM_DATA 1001 +#define wxRESOURCE_TYPE_XPM_DATA 1002 + +#define RESOURCE_PLATFORM_WINDOWS 1 +#define RESOURCE_PLATFORM_X 2 +#define RESOURCE_PLATFORM_MAC 3 +#define RESOURCE_PLATFORM_ANY 4 + +// Extended styles: for resource usage only + +// Use dialog units instead of pixels +#define wxRESOURCE_DIALOG_UNITS 0x0001 +// Use default system colour and font +#define wxRESOURCE_USE_DEFAULTS 0x0002 +// Old-style vertical label +#define wxRESOURCE_VERTICAL_LABEL 0x0004 +// Old-style horizontal label +#define wxRESOURCE_HORIZONTAL_LABEL 0x0008 + +// Macros to help use dialog units +#define wxDLG_POINT(x, y, parent, useDlgUnits) (useDlgUnits ? parent->ConvertDialogToPixel(wxPoint(x, y)) : wxPoint(x, y)) +#define wxDLG_SIZE(x, y, parent, useDlgUnits) (useDlgUnits ? parent->ConvertDialogToPixel(wxSize(x, y)) : wxSize(x, y)) + +#ifdef FindResource +#undef FindResource +#endif + +class WXDLLEXPORT wxInputStream; + +/* + * Internal format for control/panel item + */ + +class WXDLLEXPORT wxItemResource: public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxItemResource) + + public: + + wxItemResource(); + ~wxItemResource(); + + inline void SetType(const wxString& type) { m_itemType = type; } + inline void SetStyle(long styl) { m_windowStyle = styl; } + inline void SetId(int id) { m_windowId = id; } + inline void SetBitmap(const wxBitmap& bm) { m_bitmap = bm; } + inline wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; } + inline void SetFont(const wxFont& font) { m_windowFont = font; } + inline wxFont& GetFont() const { return (wxFont&) m_windowFont; } + inline void SetSize(int xx, int yy, int ww, int hh) + { m_x = xx; m_y = yy; m_width = ww; m_height = hh; } + inline void SetTitle(const wxString& title) { m_title = title; } + inline void SetName(const wxString& name) { m_name = name; } + inline void SetValue1(long v) { m_value1 = v; } + inline void SetValue2(long v) { m_value2 = v; } + inline void SetValue3(long v) { m_value3 = v; } + inline void SetValue5(long v) { m_value5 = v; } + inline void SetValue4(const wxString& v) { m_value4 = v; } + inline void SetStringValues(const wxStringList& svalues) { m_stringValues = svalues; } + + inline const wxString& GetType() const { return m_itemType; } + inline int GetX() const { return m_x; } + inline int GetY() const { return m_y; } + inline int GetWidth() const { return m_width; } + inline int GetHeight() const { return m_height; } + + inline const wxString& GetTitle() const { return m_title; } + inline const wxString& GetName() const { return m_name; } + inline long GetStyle() const { return m_windowStyle; } + inline int GetId() const { return m_windowId; } + + inline wxInt32 GetValue1() const { return m_value1; } + inline wxInt32 GetValue2() const { return m_value2; } + inline wxInt32 GetValue3() const { return m_value3; } + inline wxInt32 GetValue5() const { return m_value5; } + inline wxString GetValue4() const { return m_value4; } + inline wxList& GetChildren() const { return (wxList&) m_children; } + inline wxStringList& GetStringValues() const { return (wxStringList&) m_stringValues; } + + inline void SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; } + inline void SetLabelColour(const wxColour& col) { m_labelColour = col; } + inline void SetButtonColour(const wxColour& col) { m_buttonColour = col; } + + inline wxColour& GetBackgroundColour() const { return (wxColour&) m_backgroundColour; } + inline wxColour& GetLabelColour() const { return (wxColour&) m_labelColour; } + inline wxColour& GetButtonColour() const { return (wxColour&) m_buttonColour; } + + inline void SetResourceStyle(long style) { m_exStyle = style; } + inline wxInt32 GetResourceStyle() const { return m_exStyle; } + + protected: + wxList m_children; + wxString m_itemType; + int m_x, m_y, m_width, m_height; + wxString m_title; + wxString m_name; + long m_windowStyle; + long m_value1, m_value2, m_value3, m_value5; + wxString m_value4; + int m_windowId; + wxStringList m_stringValues; // Optional string values + wxBitmap m_bitmap; + wxColour m_backgroundColour; + wxColour m_labelColour; + wxColour m_buttonColour; + wxFont m_windowFont; + long m_exStyle; // Extended, resource-specific styles +}; + +/* + * Resource table (normally only one of these) + */ + +class WXDLLEXPORT wxResourceTable: public wxHashTable +{ + DECLARE_DYNAMIC_CLASS(wxResourceTable) + + protected: + + public: + wxHashTable identifiers; + + wxResourceTable(); + ~wxResourceTable(); + + virtual wxItemResource *FindResource(const wxString& name) const; + virtual void AddResource(wxItemResource *item); + virtual bool DeleteResource(const wxString& name); + + virtual bool ParseResourceFile(const wxString& filename); + virtual bool ParseResourceFile(wxInputStream *is); + virtual bool ParseResourceData(const wxString& data); + virtual bool SaveResource(const wxString& filename); + + // Register XBM/XPM data + virtual bool RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height); + virtual bool RegisterResourceBitmapData(const wxString& name, char **data); + + virtual wxControl *CreateItem(wxWindow *panel, const wxItemResource* childResource, const wxItemResource* parentResource) const; + + virtual void ClearTable(); +}; + +WXDLLEXPORT extern void wxInitializeResourceSystem(); +WXDLLEXPORT extern void wxCleanUpResourceSystem(); + +WXDLLEXPORT_DATA(extern wxResourceTable*) wxDefaultResourceTable; +WXDLLEXPORT extern long wxParseWindowStyle(const wxString& style); + +class WXDLLEXPORT wxMenuBar; +class WXDLLEXPORT wxMenu; +class WXDLLEXPORT wxBitmap; +class WXDLLEXPORT wxIcon; +WXDLLEXPORT extern wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern wxMenuBar* wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL, wxMenuBar *menuBar = (wxMenuBar *) NULL); +WXDLLEXPORT extern wxMenu* wxResourceCreateMenu(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseData(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseData(const char* resource, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseFile(const wxString& filename, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseString(char* s, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseString(const wxString& s, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern void wxResourceClear(wxResourceTable *table = (wxResourceTable *) NULL); +// Register XBM/XPM data +WXDLLEXPORT extern bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table = (wxResourceTable *) NULL); +#define wxResourceRegisterIconData wxResourceRegisterBitmapData + +/* + * Resource identifer code: #define storage + */ + +WXDLLEXPORT extern bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table = (wxResourceTable *) NULL); + +#if defined(__WXPM__) +#include "wx/os2/wxrsc.h" +#endif +#endif +#endif + // _WX_RESOURCEH__ diff --git a/contrib/include/wx/deprecated/setup.h b/contrib/include/wx/deprecated/setup.h new file mode 100644 index 0000000000..5196376f80 --- /dev/null +++ b/contrib/include/wx/deprecated/setup.h @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/deprecated/setup.h +// Purpose: Configuration for deprecated features of the library +// Author: Julian Smart +// Modified by: +// Created: 2003-03-30 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_DEPRECATED_SETUP_H_ +#define _WX_DEPRECATED_SETUP_H_ + +// wxUSE_TIMEDATE enables compilation of the old wxDate and wxTime classes (not +// the same as wxDateTime!). These classes are obsolete and shouldn't be used +// in new code +// +// Default is 0 +// +// Recommended setting: 0 unless you have legacy code which uses these classes +#define wxUSE_TIMEDATE 0 + +// wxProperty[Value/Form/List] classes, used by Dialog Editor +#define wxUSE_PROPSHEET 1 + +// wxTreeLayout class +#define wxUSE_TREELAYOUT 1 + +// use wxExpr (a.k.a. PrologIO) +#define wxUSE_PROLOGIO 1 + +// Use .wxr resource mechanism (requires PrologIO library) +#define wxUSE_WX_RESOURCES 1 + +#endif + // _WX_DEPRECATED_SETUP_H_ diff --git a/contrib/include/wx/deprecated/treelay.h b/contrib/include/wx/deprecated/treelay.h new file mode 100644 index 0000000000..a87818356e --- /dev/null +++ b/contrib/include/wx/deprecated/treelay.h @@ -0,0 +1,155 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: treelay.h +// Purpose: wxTreeLayout class +// Author: Julian Smart +// Modified by: +// Created: 7/4/98 +// RCS-ID: $Id$ +// Copyright: (c) 1998 Julian Smart +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_TREELAY_H_ +#define _WX_TREELAY_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "wxtree.h" +#endif + +#ifndef WX_PRECOMP +#include "wx/object.h" +class wxList; +class wxDC; +class wxMouseEvent; +#endif + +#include "wx/deprecated/setup.h" +#include "wx/string.h" + +#if wxUSE_TREELAYOUT + +class WXDLLEXPORT wxTreeLayout: public wxObject +{ +public: + wxTreeLayout(); + virtual ~wxTreeLayout() { } + + // Redefine these + virtual void GetChildren(long id, wxList& list) = 0; + virtual long GetNextNode(long id) = 0; + virtual long GetNodeParent(long id) = 0; + virtual long GetNodeX(long id) = 0; + virtual long GetNodeY(long id) = 0; + virtual void SetNodeX(long id, long x) = 0; + virtual void SetNodeY(long id, long y) = 0; + virtual void ActivateNode(long id, bool active) = 0; + virtual bool NodeActive(long id) = 0; + + // Optional redefinition + void Initialize(void); + inline virtual void SetNodeName(long WXUNUSED(id), const wxString& WXUNUSED(name)) {} + inline virtual wxString GetNodeName(long WXUNUSED(id)) { return wxString(wxT("")); } + virtual void GetNodeSize(long id, long *x, long *y, wxDC& dc); + virtual void Draw(wxDC& dc); + virtual void DrawNodes(wxDC& dc); + virtual void DrawBranches(wxDC& dc); + virtual void DrawNode(long id, wxDC& dc); + virtual void DrawBranch(long from, long to, wxDC& dc); + + // Don't redefine + virtual void DoLayout(wxDC& dc, long topNode = -1); + + // Accessors -- don't redefine + inline void SetTopNode(long id) { m_parentNode = id; } + inline long GetTopNode(void) const { return m_parentNode; } + inline void SetSpacing(long x, long y) { m_xSpacing = x; m_ySpacing = y; } + inline long GetXSpacing(void) const { return m_xSpacing; } + inline long GetYSpacing(void) const { return m_ySpacing; } + inline void SetMargins(long x, long y) { m_leftMargin = x; m_topMargin = y; } + inline long GetTopMargin(void) const { return m_topMargin; } + inline long GetLeftMargin(void) const { return m_leftMargin; } + + inline bool GetOrientation(void) const { return m_orientation; } + inline void SetOrientation(bool orient) { m_orientation = orient; } + +private: + void CalcLayout(long node_id, int level, wxDC& dc); + +protected: + long m_parentNode; + long m_lastY; + long m_lastX; + long m_xSpacing; + long m_ySpacing; + long m_topMargin; + long m_leftMargin; + bool m_orientation; // TRUE for top-to-bottom, FALSE for left-to-right + +private: + DECLARE_ABSTRACT_CLASS(wxTreeLayout) +}; + +class WXDLLEXPORT wxStoredNode +{ +public: + wxString m_name; + long m_x, m_y; + long m_parentId; + bool m_active; + long m_clientData; +}; + +/* + * A version of wxTreeLayout with storage for nodes + */ + +class WXDLLEXPORT wxTreeLayoutStored: public wxTreeLayout +{ +public: + wxTreeLayoutStored(int noNodes = 200); + virtual ~wxTreeLayoutStored(void); + void Initialize(int n); + + wxString HitTest(wxMouseEvent& event, wxDC& dc); + wxStoredNode* GetNode(long id) const; + inline int GetNumNodes() const { return m_maxNodes; }; + inline int GetNodeCount() const { return m_num; }; + + virtual void GetChildren(long id, wxList& list); + virtual long GetNextNode(long id); + virtual long GetNodeParent(long id); + virtual long GetNodeX(long id); + virtual long GetNodeY(long id); + virtual void SetNodeX(long id, long x); + virtual void SetNodeY(long id, long y); + virtual void SetNodeName(long id, const wxString& name); + virtual wxString GetNodeName(long id); + virtual void ActivateNode(long id, bool active); + virtual bool NodeActive(long id); + virtual void SetClientData(long id, long clientData); + virtual long GetClientData(long id) const; + + virtual long AddChild(const wxString& name, const wxString& parent = wxT("")); + virtual long AddChild(const wxString& name, long parent); + virtual long NameToId(const wxString& name); + + // Data members +private: + wxStoredNode* m_nodes; + int m_num; + int m_maxNodes; + +private: + DECLARE_DYNAMIC_CLASS(wxTreeLayoutStored) + DECLARE_NO_COPY_CLASS(wxTreeLayoutStored) +}; + +// For backward compatibility +#define wxStoredTree wxTreeLayoutStored + +#endif + // wxUSE_TREELAYOUT + +#endif + // _WX_TREELAY_H_ + diff --git a/contrib/include/wx/deprecated/wxexpr.h b/contrib/include/wx/deprecated/wxexpr.h new file mode 100644 index 0000000000..623314a8bc --- /dev/null +++ b/contrib/include/wx/deprecated/wxexpr.h @@ -0,0 +1,285 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxexpr.h +// Purpose: Prolog-like file I/O, used by resource system. +// Author: Julian Smart +// Modified by: +// Created: 01/02/97 +// RCS-ID: $Id$ +// Copyright: (c) +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_WXEXPRH__ +#define _WX_WXEXPRH__ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "wxexpr.h" +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROLOGIO + +#include "wx/defs.h" +#include "wx/string.h" + +#include "wx/list.h" +#include "wx/hash.h" + +#include "wx/deprecated/expr.h" + +#include + +// Compatibility +#define PrologExpr wxExpr +#define PrologDatabase wxExprDatabase +#define proioErrorHandler wxExprErrorHandler +#define PROIO_ERROR_GENERAL 1 +#define PROIO_ERROR_SYNTAX 2 +#define PrologNull wxExprNull +#define PrologInteger wxExprInteger +#define PrologReal wxExprReal +#define PrologWord wxExprWord +#define PrologString wxExprString +#define PrologList wxExprList +#define PrologType wxExprType + +// Error types +#define WXEXPR_ERROR_GENERAL 1 +#define WXEXPR_ERROR_SYNTAX 2 + +// Error handler function definition. If app returns TRUE, +// carry on processing. +typedef bool (*wxExprErrorHandler) (int errorType, char *msg); + +WXDLLEXPORT_DATA(extern wxExprErrorHandler) currentwxExprErrorHandler; + + +typedef enum { + wxExprNull, + wxExprInteger, + wxExprReal, + wxExprWord, + wxExprString, + wxExprList +} wxExprType; + +class WXDLLEXPORT wxExprDatabase; + +class WXDLLEXPORT wxExpr +{ + public: + wxObject *client_data; + wxExprType type; + union { + long integer; + wxChar *word; + wxChar *string; + double real; + wxExpr *first; // If is a list expr, points to the first node + } value; + + wxExpr *next; // If this is a node in a list, points to the next node + wxExpr *last; // If is a list expr, points to the last node + + wxExpr(wxExprType the_type, wxChar *word_or_string, bool allocate); + wxExpr(const wxString& functor); // Assume this is a new clause - pass functor + wxExpr(wxExprType the_type, const wxString& word_or_string = wxT("")); + wxExpr(long the_integer); + wxExpr(double the_real); + wxExpr(wxList *the_list); + ~wxExpr(void); + + inline wxExprType Type(void) const { return type; } + inline long IntegerValue(void) const + { + if (type == wxExprInteger) + return value.integer; + else if (type == wxExprReal) + return (long)value.real; + else return 0; + } + + inline double RealValue(void) const { + if (type == wxExprReal) + return value.real; + else if (type == wxExprInteger) + return (double)value.integer; + else return (double)0.0; + } + + inline wxString WordValue(void) const { + if (type == wxExprWord) + return value.word; + else if (type == wxExprString) + return wxString(value.string); + else return wxString(wxT("")); + } + + inline wxString StringValue(void) const { + if (type == wxExprString) + return wxString(value.string); + else if (type == wxExprWord) + return wxString(value.word); + else return wxString(wxT("")); + } + + // Get nth arg of clause (starting from 1) + wxExpr *Arg(wxExprType type, int arg) const; + + // Return nth argument of a list expression (starting from zero) + wxExpr *Nth(int arg) const; + + // Returns the number of elements in a list expression + int Number(void) const; + + // Make a clone + wxExpr *Copy(void) const; + + wxExpr *GetAttributeValueNode(const wxString& word) const; // Use only for a clause or list + wxExpr *AttributeValue(const wxString& word) const; // Use only for a clause + wxString Functor(void) const; // Only for a clause + bool IsFunctor(const wxString& s) const; // Only for a clause + void WriteClause(FILE* stream); // Write this expression as a top-level clause + void WriteExpr(FILE* stream); // Write as any other subexpression + + // Append an expression to a list + void Append(wxExpr *expr); + // Insert at beginning of list + void Insert(wxExpr *expr); + + // Get first expr in list + inline wxExpr *GetFirst(void) const { return ((type == wxExprList) ? value.first : (wxExpr*)NULL); } + + // Get next expr if this is a node in a list + inline wxExpr *GetNext(void) const { return next; } + + // Get last expr in list + inline wxExpr *GetLast(void) const { return ((type == wxExprList) ? last : (wxExpr*)NULL); } + + // This should really be called SetAttributeValue since any existing + // attribute-value is deleted first. + void AddAttributeValue(const wxString& attribute, long value); + void AddAttributeValue(const wxString& attribute, double value); + void AddAttributeValueWord(const wxString& attribute, const wxString& value); + void AddAttributeValueString(const wxString& attribute, const wxString& value); + void AddAttributeValue(const wxString& attribute, wxList *value); + void AddAttributeValue(const wxString& attribute, wxExpr *value); + void AddAttributeValueStringList(const wxString& attribute, wxList *string_list); + + void DeleteAttributeValue(const wxString& attribute); + + bool GetAttributeValue(const wxString& att, int& var) const; + bool GetAttributeValue(const wxString& att, long& var) const; + bool GetAttributeValue(const wxString& att, float& var) const; + bool GetAttributeValue(const wxString& att, double& var) const; + bool GetAttributeValue(const wxString& att, wxString& var) const; // Word OR string -> string + bool GetAttributeValue(const wxString& att, wxExpr **var) const; + + // Compatibility with old PrologIO + inline void AssignAttributeValue(wxChar *att, int *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, long *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, float *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, double *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, wxExpr **var) const { GetAttributeValue(att, var); } + void AssignAttributeValue(wxChar *att, wxChar **var) const ; // Word OR string -> string + + // Add string items to list if the list attribute exists + bool GetAttributeValueStringList(const wxString& att, wxList *var) const; + + // Associate other data with this expression, e.g. when reading in a + // number of linked items - store C++ object pointer with the expression + // so we can index into the wxExpr database and fish out the pointer. + inline void SetClientData(wxObject *data) { client_data = data; } + inline wxObject *GetClientData(void) const { return client_data; } + + DECLARE_NO_COPY_CLASS(wxExpr) +}; + +class WXDLLEXPORT wxExprDatabase: public wxList +{ +private: + wxNode *position; // Where we are in a search + wxHashTable *hash_table; + wxString attribute_to_hash; + +public: + int noErrors; + + wxExprDatabase(wxExprErrorHandler handler = 0); + + // Use hashing on both the functor, and the attribute of + // specified type (wxExprString or wxExprInteger) and name. + // So to find node 45 + // (i.e. match the clause node(id=45, ...)) + // it usually requires 1 look-up: the keys for functor and attribute + // are added together. + // Obviously if the attribute was missing in a clause, it would + // fail to be found by this method, but could be retrieved by a + // linear search using BeginFind and FindClauseByFunctor, + // or just searching through the list as per usual. + + wxExprDatabase(wxExprType type, const wxString& attribute, int size = 500, + wxExprErrorHandler handler = 0); + + ~wxExprDatabase(void); + + void BeginFind(void) ; // Initialise a search + wxExpr *FindClause(long id) ; // Find a term based on an integer id attribute + // e.g. node(id=23, type=rectangle, ....). + + // Find on basis of attribute/value pairs, e.g. type=rectangle + // This doesn't use hashing; it's a linear search. + wxExpr *FindClause(const wxString& word, const wxString& value); + wxExpr *FindClause(const wxString& word, long value); + wxExpr *FindClause(const wxString& word, double value); + wxExpr *FindClauseByFunctor(const wxString& functor); + + wxExpr *HashFind(const wxString& functor, const wxString& value) const; + wxExpr *HashFind(const wxString& functor, long value) const; + + void Append(wxExpr *expr); // Does cleverer things if hashing is on + void ClearDatabase(void); + inline int GetErrorCount() const { return noErrors; } + bool Read(const wxString& filename); + bool ReadFromString(const wxString& buffer); + bool Write(const wxString& fileName); + bool Write(FILE* stream); + + // Compatibility + inline bool ReadProlog(wxChar *filename) { return Read(wxString(filename)); } + inline bool ReadPrologFromString(char *buffer) + { + return ReadFromString(wxString(buffer, wxConvLibc)); + } + inline void WriteProlog(FILE* stream) { Write(stream); } + +private: + DECLARE_DYNAMIC_CLASS(wxExprDatabase) + DECLARE_NO_COPY_CLASS(wxExprDatabase) +}; + +// Function call-style interface - some more convenience wrappers/unwrappers + +// Make a call +WXDLLEXPORT wxExpr* wxExprMakeCall(const wxString& functor ...); + +#define wxExprMakeInteger(x) (new wxExpr((long)x)) +#define wxExprMakeReal(x) (new wxExpr((double)x)) +#define wxExprMakeString(x) (new wxExpr(wxExprString, x)) +#define wxExprMakeWord(x) (new wxExpr(wxExprWord, x)) +#define wxExprMake(x) (new wxExpr(x)) + +// Checks functor +WXDLLEXPORT bool wxExprIsFunctor(wxExpr *expr, const wxString& functor); + +// Temporary variable for communicating between wxexpr.cpp and YACC/LEX +WXDLLEXPORT_DATA(extern wxExprDatabase*) thewxExprDatabase; + +// YACC/LEX can leave memory lying around... +extern "C" WXDLLEXPORT int wxExprCleanUp(); + +#endif // wxUSE_PROLOGIO + +#endif // _WX_WXEXPRH__ + diff --git a/contrib/src/deprecated/Makefile.in b/contrib/src/deprecated/Makefile.in new file mode 100644 index 0000000000..67d852f58e --- /dev/null +++ b/contrib/src/deprecated/Makefile.in @@ -0,0 +1,26 @@ +# $Id$ + +top_srcdir = @top_srcdir@/.. +top_builddir = ../../.. +libsrc_dir = contrib/src/deprecated + +TARGET_LIBNAME=lib@WX_LIBRARY_BASENAME@_deprecated-@WX_RELEASE@ + +LIBVERSION_CURRENT=@WX_CURRENT@ +LIBVERSION_REVISION=@WX_REVISION@ +LIBVERSION_AGE=@WX_AGE@ + + +HEADER_PATH=$(top_srcdir)/contrib/include/wx +HEADER_SUBDIR=deprecated + +HEADERS=prop.h propform.h proplist.h resource.h treelay.h wxexpr.h treelay.h + +OBJECTS=prop.o propform.o proplist.o wxexpr.o y_tab.o treelay.cpp +DEPFILES=$(OBJECTS:.o=.d) + +APPEXTRADEFS=-I$(top_srcdir)/contrib/include + +include $(top_builddir)/src/makelib.env + +-include $(DEPFILES) diff --git a/contrib/src/deprecated/doslex.c b/contrib/src/deprecated/doslex.c new file mode 100644 index 0000000000..dfe6d82721 --- /dev/null +++ b/contrib/src/deprecated/doslex.c @@ -0,0 +1,1276 @@ +/* A lexical scanner generated by flex */ + +/* scanner skeleton version: + * $Header$ + Last change: JS 13 Jul 97 6:17 pm + */ + +#define FLEX_SCANNER + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include + +#ifdef __SALFORDC__ +#include +#include +#else +#include +#endif + +#ifdef __VISAGECPP__ +#include +#endif + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + +/* use prototypes in function declarations */ +#define YY_USE_PROTOS + +/* the "const" storage-class-modifier is valid */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#ifdef __STDC__ + +#ifdef __GNUC__ +#include +#else +#include +#endif /* __GNUC__ */ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + + +#ifdef __TURBOC__ +#define YY_USE_CONST +#endif + + +#ifndef YY_USE_CONST +#define const +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +/* we can't get here if it's an ANSI C compiler, or a C++ compiler, + * so it's got to be a K&R compiler, and therefore there's no standard + * place from which to include these definitions + */ +/* +char *malloc(); +int free(); +*/ + +#endif + + +/* amount of stuff to slurp up with each read */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* returned upon end-of-file */ +#define YY_END_TOK 0 + +/* copy whatever the last rule matched to the standard output */ + +/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */ +/* this used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite() + */ +#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout ) + +/* gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#define YY_NULL 0 + +/* no semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#define yyterminate() return ( YY_NULL ) + +/* report a fatal error */ + +/* The funky do-while is used to turn this macro definition into + * a single C statement (which needs a semi-colon terminator). + * This avoids problems with code like: + * + * if ( something_happens ) + * YY_FATAL_ERROR( "oops, the something happened" ); + * else + * everything_okay(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the YY_FATAL_ERROR() call. + */ + +#if !defined(__VISAGECPP__) +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( 0 ) +#else +/* suppress expression always false warning */ +int os2var = 0; +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( os2var == 0 ) +#endif + +/* default yywrap function - always treat EOF as an EOF */ +int yywrap(void) { return 1; } + + +/* enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN + */ +#define BEGIN yy_start = 1 + 2 * + +/* action number for EOF rule of a given start state */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* special action meaning "start processing a new file" */ +#if !defined(__VISAGECPP__) +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( 0 ) +#else +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( os2var == 0 ) +#endif + +/* default declaration of generated scanner - a define so the user can + * easily add parameters + */ +#define YY_DECL int yylex YY_PROTO(( void )) + +/* code executed at the end of each rule */ +#define YY_BREAK break; + +#define YY_END_OF_BUFFER_CHAR 0 + +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */ +#endif + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +#define YY_CHAR unsigned char +# line 1 "lexer.l" +#define INITIAL 0 +# line 9 "lexer.l" +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include + +/* +++steve162e: added, otherwise, PROIO_input will be undefined (at least under LINUX) + please check, if this is also TRUE under other UNIXes. + */ + +#if defined(FLEX_SCANNER) && defined(_LINUX) +#define PROIO_input my_input +#endif +/* ---steve162e */ + +#include "wx/deprecated/expr.h" +#ifdef wx_x +extern char *malloc(); +#endif +#define Return(x) return x; + +#if defined(VMS) && ( __VMS_VER < 70000000 ) +#define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s)); +#endif + +static size_t lex_buffer_length = 0; +static const char *lex_buffer = NULL; +static size_t lex_string_ptr = 0; +static int lex_read_from_string = 0; + +static int my_input(void); +static int my_unput(char); + +#ifdef FLEX_SCANNER +#undef YY_INPUT +# define YY_INPUT(buf,result,max_size) \ + if (lex_read_from_string) \ + { int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \ + else \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#else +# ifndef unput +# undef unput +# endif +# define unput(_c) my_unput(_c) +#endif + +# line 58 "lexer.l" + +/* done after the current pattern has been matched and before the + * corresponding action - sets up yytext + */ +#define YY_DO_BEFORE_ACTION \ + yytext = yy_bp; \ + yyleng = yy_cp - yy_bp; \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* return all but the first 'n' matched characters back to the input stream */ +#if !defined(__VISAGECPP__) +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#else +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( os2var == 0 ) +#endif + +#undef unput +#define unput(c) yyunput( c, yytext ) + + +struct yy_buffer_state + { + FILE *yy_input_file; + + YY_CHAR *yy_ch_buf; /* input buffer */ + YY_CHAR *yy_buf_pos; /* current position in input buffer */ + + /* size of input buffer in bytes, not including room for EOB characters*/ + int yy_buf_size; + + /* number of characters read into yy_ch_buf, not including EOB characters */ + int yy_n_chars; + + int yy_eof_status; /* whether we've seen an EOF on this buffer */ +#define EOF_NOT_SEEN 0 + /* "pending" happens when the EOF has been seen but there's still + * some text process + */ +#define EOF_PENDING 1 +#define EOF_DONE 2 + }; + +static YY_BUFFER_STATE yy_current_buffer; + +/* we provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state" + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed */ +static YY_CHAR yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + + +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +#ifndef YY_USER_INIT +#define YY_USER_INIT +#endif + +extern YY_CHAR *yytext; +extern int yyleng; +extern FILE *yyin, *yyout; + +YY_CHAR *yytext; +int yyleng; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +#define YY_END_OF_BUFFER 18 +typedef int yy_state_type; +static const short int yy_accept[34] = + { 0, + 0, 0, 18, 16, 13, 14, 16, 16, 6, 7, + 16, 8, 12, 16, 1, 11, 3, 9, 10, 2, + 0, 5, 0, 0, 0, 4, 1, 15, 3, 5, + 0, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 9, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 17, 18, 1, 15, 1, 15, 15, 15, 15, + + 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 1, 20, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[21] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 1, 2, 1, 3, 1, 2, 1 + } ; + +static const short int yy_base[37] = + { 0, + 0, 0, 48, 55, 55, 55, 17, 42, 55, 55, + 19, 55, 55, 23, 17, 55, 0, 55, 55, 0, + 18, 55, 19, 23, 21, 55, 12, 55, 0, 24, + 25, 29, 55, 49, 52, 22 + } ; + +static const short int yy_def[37] = + { 0, + 33, 1, 33, 33, 33, 33, 34, 35, 33, 33, + 33, 33, 33, 33, 33, 33, 36, 33, 33, 36, + 34, 33, 34, 34, 35, 33, 33, 33, 36, 34, + 34, 34, 0, 33, 33, 33 + } ; + +static const short int yy_nxt[76] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 4, 11, 12, + 13, 14, 15, 16, 17, 18, 4, 19, 20, 4, + 22, 22, 30, 29, 27, 26, 22, 22, 30, 27, + 28, 27, 30, 23, 23, 23, 24, 24, 24, 31, + 23, 32, 24, 24, 24, 23, 26, 33, 24, 21, + 21, 21, 25, 25, 3, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static const short int yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 21, 23, 36, 27, 25, 24, 30, 31, 15, + 14, 11, 32, 7, 21, 23, 7, 21, 23, 24, + 30, 31, 24, 30, 31, 32, 8, 3, 32, 34, + 34, 34, 35, 35, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static yy_state_type yy_last_accepting_state; +static YY_CHAR *yy_last_accepting_cpos; + +/* the intent behind this definition is that it'll catch + * any uses of REJECT which flex missed + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 + +/* these variables are all declared out here so that section 3 code can + * manipulate them + */ +/* points to current character in buffer */ +static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr )); +void yyrestart YY_PROTO(( FILE *input_file )); +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); + +#define yy_new_buffer yy_create_buffer + +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif + +YY_DECL + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp, *yy_bp; + register int yy_act; + + + + + if ( yy_init ) + { + YY_USER_INIT; + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( yy_current_buffer ) + yy_init_buffer( yy_current_buffer, yyin ); + else + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + + yy_init = 0; + } + +#if !defined(__VISAGECPP__) + while ( 1 ) /* loops until end-of-file is reached */ +#else + os2var = 1; + if (os2var == 0) return 0; + while ( os2var == 1 ) /* loops until end-of-file is reached */ +#endif + { + yy_cp = yy_c_buf_p; + + /* support of yytext */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of the + * current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[*yy_cp]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 33 ); + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + YY_USER_ACTION; + +do_action: /* this label is used only to access EOF actions */ + + + switch ( yy_act ) + { + case 0: /* must backtrack */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +# line 60 "lexer.l" +{yylval.s = strdup((const char*) yytext); Return(INTEGER);} + YY_BREAK +case 2: +# line 62 "lexer.l" +Return(EXP); + YY_BREAK +case 3: +# line 64 "lexer.l" +{yylval.s = strdup((const char*) yytext); Return(WORD);} + YY_BREAK +case 4: +# line 66 "lexer.l" +{int len = strlen((const char*) yytext); + yytext[len-1] = 0; + yylval.s = strdup((const char*) (yytext+1)); + Return(WORD);} + YY_BREAK +case 5: +# line 71 "lexer.l" +{yylval.s = strdup((const char*) yytext); Return(STRING);} + YY_BREAK +case 6: +# line 73 "lexer.l" +Return(OPEN); + YY_BREAK +case 7: +# line 75 "lexer.l" +Return(CLOSE); + YY_BREAK +case 8: +# line 77 "lexer.l" +Return(COMMA); + YY_BREAK +case 9: +# line 79 "lexer.l" +Return(OPEN_SQUARE); + YY_BREAK +case 10: +# line 81 "lexer.l" +Return(CLOSE_SQUARE); + YY_BREAK +case 11: +# line 83 "lexer.l" +Return(EQUALS); + YY_BREAK +case 12: +# line 85 "lexer.l" +Return(PERIOD); + YY_BREAK +case 13: +# line 87 "lexer.l" +; + YY_BREAK +case 14: +# line 89 "lexer.l" +; + YY_BREAK +case 15: +# line 91 "lexer.l" +{ loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + YY_BREAK +case 16: +# line 106 "lexer.l" +Return(ERROR); + YY_BREAK +case 17: +# line 108 "lexer.l" +ECHO; + YY_BREAK +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* amount of text matched not including the EOB char */ + int yy_amount_of_matched_text = yy_cp - yytext - 1; + + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + + /* note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the end- + * of-buffer state). Contrast this with the test in yyinput(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + { + yy_state_type yy_next_state; + + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* okay, we're now positioned to make the + * NUL transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we + * don't want to build jamming into it because + * then it will run more slowly) + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* consume the NUL */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* note: because we've taken care in + * yy_get_next_buffer() to have set up yytext, + * we can now set up yy_c_buf_p so that if some + * total hoser (like flex itself) wants + * to call the scanner after we return the + * YY_NULL, it'll still work - another YY_NULL + * will get returned. + */ + yy_c_buf_p = yytext + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF((yy_start - 1) / 2); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: +#ifdef FLEX_DEBUG + printf( "action # %d\n", yy_act ); +#endif + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } + } +#if defined(__VISAGECPP__) +/* VA complains about proc maybe not returning a value so return one */ +return 0; +#endif + } + + +/* yy_get_next_buffer - try to read in a new buffer + * + * synopsis + * int yy_get_next_buffer(); + * + * returns a code representing an action + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + + { + register YY_CHAR *dest = yy_current_buffer->yy_ch_buf; + register YY_CHAR *source = yytext - 1; /* copy prev. char, too */ + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + /* try to read more data */ + + /* first move last chars to start of buffer */ + number_to_move = yy_c_buf_p - yytext; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; + + else + { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + else if ( num_to_read <= 0 ) + YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); + + /* read in more data */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == 1 ) + { + ret_val = EOB_ACT_END_OF_FILE; + yy_current_buffer->yy_eof_status = EOF_DONE; + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_eof_status = EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + /* yytext begins at the second character in yy_ch_buf; the first + * character is the one which preceded it before reading in the latest + * buffer; it needs to be kept around in case it's a newline, so + * yy_get_previous_state() will have with '^' rules active + */ + + yytext = &yy_current_buffer->yy_ch_buf[1]; + + return ( ret_val ); + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached + * + * synopsis + * yy_state_type yy_get_previous_state(); + */ + +static yy_state_type yy_get_previous_state() + + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return ( yy_current_state ); + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +register yy_state_type yy_current_state; +#endif + + { + register int yy_is_jam; + register YY_CHAR *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 33); + + return ( yy_is_jam ? 0 : yy_current_state ); + } + + +#ifdef YY_USE_PROTOS +static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp ) +#else +static void yyunput( c, yy_bp ) +YY_CHAR c; +register YY_CHAR *yy_bp; +#endif + + { + register YY_CHAR *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */ + register YY_CHAR *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register YY_CHAR *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += dest - source; + yy_bp += dest - source; + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) + yy_cp[-2] = '\n'; + + *--yy_cp = c; + + /* note: the formal parameter *must* be called "yy_bp" for this + * macro to now work correctly + */ + YY_DO_BEFORE_ACTION; /* set up yytext again */ + } + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + + { + int c; + YY_CHAR *yy_cp = yy_c_buf_p; + + *yy_cp = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + yytext = yy_c_buf_p; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + { + yy_c_buf_p = yytext + YY_MORE_ADJ; + return ( EOF ); + } + + YY_NEW_FILE; + +#ifdef __cplusplus + return ( yyinput() ); +#else + return ( input() ); +#endif + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + YY_MORE_ADJ; + break; + + case EOB_ACT_LAST_MATCH: +#ifdef __cplusplus + YY_FATAL_ERROR( "unexpected last match in yyinput()" ); +#else + YY_FATAL_ERROR( "unexpected last match in input()" ); +#endif + } + } + } + + c = *yy_c_buf_p; + yy_hold_char = *++yy_c_buf_p; + + return ( c ); + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + + { + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* flush out information for old buffer */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); + + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) ); + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + yy_init_buffer( b, file ); + + return ( b ); + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + free( (char *) b->yy_ch_buf ); + free( (char *) b ); + } + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + { + b->yy_input_file = file; + + /* we put in the '\n' and start reading from [1] so that an + * initial match-at-newline will be true. + */ + + b->yy_ch_buf[0] = '\n'; + b->yy_n_chars = 1; + + /* we always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[1]; + + b->yy_eof_status = EOF_NOT_SEEN; + } +# line 108 "lexer.l" + + + +#ifdef FLEX_SCANNER +static int lex_input() { + return input(); +} +#else /* BSD/AT&T lex */ +#ifndef input +# error "Sorry, but need either flex or AT&T lex" +#endif +static int lex_input() { + return input(); +} +/* # undef unput +# define unput(_c) my_unput(_c) +*/ + +# undef input +# define input() my_input() +static int my_unput(char c) +{ + if (lex_read_from_string) { + /* Make sure we have something */ + if (lex_string_ptr) { + if (c == '\n') yylineno--; + lex_string_ptr--; + } + } else { + yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar; +/* unput(c); Causes infinite recursion! */ + } + return c; +} + +#endif + +/* Public */ +void LexFromFile(FILE *fd) +{ + lex_read_from_string = 0; + yyin = fd; + /* Don't know why this is necessary, but otherwise + * lex only works _once_! + */ +#ifdef FLEX_SCANNER + yy_init = 1; +#endif +} + +void LexFromString(char *buffer) +{ + lex_read_from_string = 1; + lex_buffer = buffer; + lex_buffer_length = strlen((const char*) buffer); + lex_string_ptr = 0; + /* Don't know why this is necessary, but otherwise + * lex only works _once_! + */ +#ifdef FLEX_SCANNER + yy_init = 1; +#endif +} + +static int my_input( void ) +{ + if (lex_read_from_string) { + if (lex_string_ptr == lex_buffer_length) + return 0; + else { + char c = lex_buffer[lex_string_ptr++]; +#ifndef FLEX_SCANNER + if (c == '\n') yylineno++; +#endif + return c; + } + } else { + return lex_input(); + } +} + +void wxExprCleanUp() +{ + if (yy_current_buffer) + yy_delete_buffer(yy_current_buffer); +} diff --git a/contrib/src/deprecated/dosyacc.c b/contrib/src/deprecated/dosyacc.c new file mode 100644 index 0000000000..aa79d52bd8 --- /dev/null +++ b/contrib/src/deprecated/dosyacc.c @@ -0,0 +1,540 @@ +/* include platform.h first to get __WIN32__ definition */ +#include "wx/platform.h" +#if defined(__WIN32__) || defined(__GNUWIN32__) +/* all Win32 compilers can handle C++ comments, and C++ comments + is the only C++ in setup.h */ +#include "wx/setup.h" +#endif + +#if !defined(wxUSE_PROLOGIO) || wxUSE_PROLOGIO + +#ifndef lint +static char yysccsid[] = "@(#)yaccpar 1.7 (Berkeley) 09/09/90"; +#endif +#define YYBYACC 1 +#line 2 "parser.y" +#include "string.h" +#if defined(_MSC_VER) || defined(__VISAGECPP__) +#include +#endif +#include "wx/deprecated/expr.h" + +#ifndef __EXTERN_C__ +#define __EXTERN_C__ 1 +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +extern "C" { +#endif +#endif +int yylex(void); +int yylook(void); +int yywrap(void); +int yyback(int *, int); + +/* You may need to put /DLEX_SCANNER in your makefile + * if you're using LEX! + */ +#ifdef LEX_SCANNER +/* int yyoutput(int); */ +void yyoutput(int); +#else +void yyoutput(int); +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +} +#endif +#endif +#line 36 "parser.y" +typedef union { + char *s; +/* struct pexpr *expr; */ +} YYSTYPE; +#line 44 "y_tab.c" +#define INTEGER 1 +#define WORD 2 +#define STRING 3 +#define PERIOD 13 +#define OPEN 4 +#define CLOSE 5 +#define COMMA 6 +#define NEWLINE 7 +#define ERROR 8 +#define OPEN_SQUARE 9 +#define CLOSE_SQUARE 10 +#define EQUALS 11 +#define EXP 14 +#define YYERRCODE 256 +short yylhs[] = { -1, + 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, + 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, +}; +short yylen[] = { 2, + 0, 2, 2, 2, 2, 4, 2, 3, 0, 1, + 3, 3, 1, 1, 1, 1, 3, 3, 5, 1, +}; +short yydefred[] = { 1, + 0, 0, 0, 0, 2, 0, 5, 3, 0, 0, + 0, 15, 7, 20, 0, 0, 13, 4, 0, 0, + 0, 0, 8, 0, 6, 0, 18, 0, 12, 11, + 0, 19, +}; +short yydgoto[] = { 1, + 5, 14, 15, 16, 17, +}; +short yysindex[] = { 0, + -2, 9, 2, 1, 0, 10, 0, 0, 11, -5, + 17, 0, 0, 0, 14, -1, 0, 0, 33, 38, + 41, 16, 0, 11, 0, 29, 0, 40, 0, 0, + 44, 0, +}; +short yyrindex[] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 42, 21, + 24, 0, 0, 0, 0, 30, 0, 0, 0, 0, + 0, 0, 0, 31, 0, 27, 0, 24, 0, 0, + 0, 0, +}; +short yygindex[] = { 0, + 0, 45, -8, 0, 26, +}; +#define YYTABLESIZE 254 +short yytable[] = { 3, + 19, 10, 11, 12, 24, 9, 4, 20, 21, 4, + 13, 10, 11, 12, 8, 30, 10, 28, 12, 4, + 9, 7, 18, 23, 4, 16, 16, 22, 14, 14, + 16, 17, 17, 14, 10, 9, 17, 25, 26, 10, + 9, 27, 31, 9, 32, 6, 9, 29, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, +}; +short yycheck[] = { 2, + 9, 1, 2, 3, 6, 4, 9, 13, 14, 9, + 10, 1, 2, 3, 13, 24, 1, 2, 3, 9, + 4, 13, 13, 10, 9, 5, 6, 11, 5, 6, + 10, 5, 6, 10, 5, 5, 10, 5, 1, 10, + 10, 1, 14, 4, 1, 1, 5, 22, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 256, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 14 +#if YYDEBUG +char *yyname[] = { +"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE", +"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP", +}; +char *yyrule[] = { +"$accept : commands", +"commands :", +"commands : commands command", +"command : WORD PERIOD", +"command : expr PERIOD", +"command : error PERIOD", +"expr : WORD OPEN arglist CLOSE", +"expr : OPEN_SQUARE CLOSE_SQUARE", +"expr : OPEN_SQUARE arglist CLOSE_SQUARE", +"arglist :", +"arglist : arg", +"arglist : arg COMMA arglist", +"arg : WORD EQUALS arg1", +"arg : arg1", +"arg1 : WORD", +"arg1 : STRING", +"arg1 : INTEGER", +"arg1 : INTEGER PERIOD INTEGER", +"arg1 : INTEGER EXP INTEGER", +"arg1 : INTEGER PERIOD INTEGER EXP INTEGER", +"arg1 : expr", +}; +#endif +#define yyclearin (yychar=(-1)) +#define yyerrok (yyerrflag=0) +#ifdef YYSTACKSIZE +#ifndef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#endif +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 600 +#define YYMAXDEPTH 600 +#endif +#endif +int yydebug; +int yynerrs; +int yyerrflag; +int yychar; +short *yyssp; +YYSTYPE *yyvsp; +YYSTYPE yyval; +YYSTYPE yylval; +short yyss[YYSTACKSIZE]; +YYSTYPE yyvs[YYSTACKSIZE]; +#define yystacksize YYSTACKSIZE +#line 118 "parser.y" + +#ifdef IDE_INVOKED +#include "../common/doslex.c" +#else +#include "../common/lex_yy.c" +#endif + +/* +void yyerror(s) +char *s; +{ + syntax_error(s); +} +*/ + +/* Ansi prototype. If this doesn't work for you... uncomment + the above instead. + */ + +void yyerror(char *s) +{ + syntax_error(s); +} + +/* + * Unfortunately, my DOS version of FLEX + * requires yywrap to be #def'ed, whereas + * the UNIX flex expects a proper function. + */ + +/* Not sure if __SC__ is the appropriate thing + * to test + */ + +#ifndef __SC__ +#ifdef USE_DEFINE +#ifndef yywrap +#define yywrap() 1 +#endif +#else +# if !(defined(__VISAGECPP__) && __IBMC__ >= 400) +/* VA 4.0 thinks this is multiply defined (in lex_yy.c) */ + int yywrap() { return 1; } +# endif +#endif +#endif +#line 247 "y_tab.c" +#define YYABORT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab +int +PROIO_yyparse() +{ + register int yym, yyn, yystate; +#if YYDEBUG + register char *yys; + extern char *getenv(); + + yys = getenv("YYDEBUG"); + if (yys) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = (-1); + + yyssp = yyss; + yyvsp = yyvs; + *yyssp = yystate = 0; + +yyloop: + yyn = yydefred[yystate]; + if (yyn != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("yydebug: state %d, reading %d (%s)\n", yystate, + yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("yydebug: state %d, shifting to state %d\n", + yystate, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + yychar = (-1); + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; +#ifdef lint + goto yynewerror; +#endif +yynewerror: + yyerror("syntax error"); +#ifdef lint + goto yyerrlab; +#endif +yyerrlab: + ++yynerrs; +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("yydebug: state %d, error recovery shifting\ + to state %d\n", *yyssp, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("yydebug: error recovery discarding state %d\n", + *yyssp); +#endif + if (yyssp <= yyss) goto yyabort; + --yyssp; + --yyvsp; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("yydebug: state %d, error recovery discards token %d (%s)\n", + yystate, yychar, yys); + } +#endif + yychar = (-1); + goto yyloop; + } +yyreduce: +#if YYDEBUG + if (yydebug) + printf("yydebug: state %d, reducing by rule %d (%s)\n", + yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + yyval = yyvsp[1-yym]; + switch (yyn) + { +case 3: +#line 68 "parser.y" +{process_command(proio_cons(wxmake_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);} +break; +case 4: +#line 70 "parser.y" +{process_command(yyvsp[-1].s);} +break; +case 5: +#line 72 "parser.y" +{syntax_error("Unrecognized command.");} +break; +case 6: +#line 76 "parser.y" +{yyval.s = proio_cons(wxmake_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);} +break; +case 7: +#line 78 "parser.y" +{yyval.s = proio_cons(NULL, NULL);} +break; +case 8: +#line 80 "parser.y" +{yyval.s = yyvsp[-1].s; } +break; +case 9: +#line 84 "parser.y" +{yyval.s = NULL;} +break; +case 10: +#line 86 "parser.y" +{yyval.s = proio_cons(yyvsp[0].s, NULL);} +break; +case 11: +#line 89 "parser.y" +{yyval.s = proio_cons(yyvsp[-2].s, yyvsp[0].s);} +break; +case 12: +#line 93 "parser.y" +{yyval.s = proio_cons(wxmake_word("="), proio_cons(wxmake_word(yyvsp[-2].s), proio_cons(yyvsp[0].s, NULL))); + free(yyvsp[-2].s); } +break; +case 13: +#line 96 "parser.y" +{yyval.s = yyvsp[0].s; } +break; +case 14: +#line 99 "parser.y" +{yyval.s = wxmake_word(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 15: +#line 101 "parser.y" +{yyval.s = wxmake_string(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 16: +#line 103 "parser.y" +{yyval.s = wxmake_integer(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 17: +#line 105 "parser.y" +{yyval.s = wxmake_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); } +break; +case 18: +#line 107 "parser.y" +{yyval.s = wxmake_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); } +break; +case 19: +#line 110 "parser.y" +{yyval.s = wxmake_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s); + free(yyvsp[0].s); } +break; +case 20: +#line 114 "parser.y" +{yyval.s = yyvsp[0].s;} +break; +#line 461 "y_tab.c" + } + yyssp -= yym; + yystate = *yyssp; + yyvsp -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("yydebug: after reduction, shifting from state 0 to\ + state %d\n", YYFINAL); +#endif + yystate = YYFINAL; + *++yyssp = YYFINAL; + *++yyvsp = yyval; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("yydebug: state %d, reading %d (%s)\n", + YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("yydebug: after reduction, shifting from state %d \ +to state %d\n", *yyssp, yystate); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate; + *++yyvsp = yyval; + goto yyloop; +yyoverflow: + yyerror("yacc stack overflow"); +yyabort: + return (1); +yyaccept: + return (0); +} + +#endif /* wxUSE_PROLOGIO */ diff --git a/contrib/src/deprecated/lex_yy.c b/contrib/src/deprecated/lex_yy.c new file mode 100644 index 0000000000..dfe6d82721 --- /dev/null +++ b/contrib/src/deprecated/lex_yy.c @@ -0,0 +1,1276 @@ +/* A lexical scanner generated by flex */ + +/* scanner skeleton version: + * $Header$ + Last change: JS 13 Jul 97 6:17 pm + */ + +#define FLEX_SCANNER + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include + +#ifdef __SALFORDC__ +#include +#include +#else +#include +#endif + +#ifdef __VISAGECPP__ +#include +#endif + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + +/* use prototypes in function declarations */ +#define YY_USE_PROTOS + +/* the "const" storage-class-modifier is valid */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#ifdef __STDC__ + +#ifdef __GNUC__ +#include +#else +#include +#endif /* __GNUC__ */ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + + +#ifdef __TURBOC__ +#define YY_USE_CONST +#endif + + +#ifndef YY_USE_CONST +#define const +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +/* we can't get here if it's an ANSI C compiler, or a C++ compiler, + * so it's got to be a K&R compiler, and therefore there's no standard + * place from which to include these definitions + */ +/* +char *malloc(); +int free(); +*/ + +#endif + + +/* amount of stuff to slurp up with each read */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* returned upon end-of-file */ +#define YY_END_TOK 0 + +/* copy whatever the last rule matched to the standard output */ + +/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */ +/* this used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite() + */ +#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout ) + +/* gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#define YY_INPUT(buf,result,max_size) \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#define YY_NULL 0 + +/* no semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#define yyterminate() return ( YY_NULL ) + +/* report a fatal error */ + +/* The funky do-while is used to turn this macro definition into + * a single C statement (which needs a semi-colon terminator). + * This avoids problems with code like: + * + * if ( something_happens ) + * YY_FATAL_ERROR( "oops, the something happened" ); + * else + * everything_okay(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the YY_FATAL_ERROR() call. + */ + +#if !defined(__VISAGECPP__) +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( 0 ) +#else +/* suppress expression always false warning */ +int os2var = 0; +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + (void) fputs( msg, stderr ); \ + (void) putc( '\n', stderr ); \ + exit( 1 ); \ + } \ + while ( os2var == 0 ) +#endif + +/* default yywrap function - always treat EOF as an EOF */ +int yywrap(void) { return 1; } + + +/* enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN + */ +#define BEGIN yy_start = 1 + 2 * + +/* action number for EOF rule of a given start state */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* special action meaning "start processing a new file" */ +#if !defined(__VISAGECPP__) +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( 0 ) +#else +#define YY_NEW_FILE \ + do \ + { \ + yy_init_buffer( yy_current_buffer, yyin ); \ + yy_load_buffer_state(); \ + } \ + while ( os2var == 0 ) +#endif + +/* default declaration of generated scanner - a define so the user can + * easily add parameters + */ +#define YY_DECL int yylex YY_PROTO(( void )) + +/* code executed at the end of each rule */ +#define YY_BREAK break; + +#define YY_END_OF_BUFFER_CHAR 0 + +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */ +#endif + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +#define YY_CHAR unsigned char +# line 1 "lexer.l" +#define INITIAL 0 +# line 9 "lexer.l" +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include + +/* +++steve162e: added, otherwise, PROIO_input will be undefined (at least under LINUX) + please check, if this is also TRUE under other UNIXes. + */ + +#if defined(FLEX_SCANNER) && defined(_LINUX) +#define PROIO_input my_input +#endif +/* ---steve162e */ + +#include "wx/deprecated/expr.h" +#ifdef wx_x +extern char *malloc(); +#endif +#define Return(x) return x; + +#if defined(VMS) && ( __VMS_VER < 70000000 ) +#define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s)); +#endif + +static size_t lex_buffer_length = 0; +static const char *lex_buffer = NULL; +static size_t lex_string_ptr = 0; +static int lex_read_from_string = 0; + +static int my_input(void); +static int my_unput(char); + +#ifdef FLEX_SCANNER +#undef YY_INPUT +# define YY_INPUT(buf,result,max_size) \ + if (lex_read_from_string) \ + { int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \ + else \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#else +# ifndef unput +# undef unput +# endif +# define unput(_c) my_unput(_c) +#endif + +# line 58 "lexer.l" + +/* done after the current pattern has been matched and before the + * corresponding action - sets up yytext + */ +#define YY_DO_BEFORE_ACTION \ + yytext = yy_bp; \ + yyleng = yy_cp - yy_bp; \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* return all but the first 'n' matched characters back to the input stream */ +#if !defined(__VISAGECPP__) +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#else +#define yyless(n) \ + do \ + { \ + /* undo effects of setting up yytext */ \ + *yy_cp = yy_hold_char; \ + yy_c_buf_p = yy_cp = yy_bp + n; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( os2var == 0 ) +#endif + +#undef unput +#define unput(c) yyunput( c, yytext ) + + +struct yy_buffer_state + { + FILE *yy_input_file; + + YY_CHAR *yy_ch_buf; /* input buffer */ + YY_CHAR *yy_buf_pos; /* current position in input buffer */ + + /* size of input buffer in bytes, not including room for EOB characters*/ + int yy_buf_size; + + /* number of characters read into yy_ch_buf, not including EOB characters */ + int yy_n_chars; + + int yy_eof_status; /* whether we've seen an EOF on this buffer */ +#define EOF_NOT_SEEN 0 + /* "pending" happens when the EOF has been seen but there's still + * some text process + */ +#define EOF_PENDING 1 +#define EOF_DONE 2 + }; + +static YY_BUFFER_STATE yy_current_buffer; + +/* we provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state" + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed */ +static YY_CHAR yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + + +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +#ifndef YY_USER_INIT +#define YY_USER_INIT +#endif + +extern YY_CHAR *yytext; +extern int yyleng; +extern FILE *yyin, *yyout; + +YY_CHAR *yytext; +int yyleng; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +#define YY_END_OF_BUFFER 18 +typedef int yy_state_type; +static const short int yy_accept[34] = + { 0, + 0, 0, 18, 16, 13, 14, 16, 16, 6, 7, + 16, 8, 12, 16, 1, 11, 3, 9, 10, 2, + 0, 5, 0, 0, 0, 4, 1, 15, 3, 5, + 0, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 9, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 17, 18, 1, 15, 1, 15, 15, 15, 15, + + 19, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 1, 20, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[21] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 1, 2, 1, 3, 1, 2, 1 + } ; + +static const short int yy_base[37] = + { 0, + 0, 0, 48, 55, 55, 55, 17, 42, 55, 55, + 19, 55, 55, 23, 17, 55, 0, 55, 55, 0, + 18, 55, 19, 23, 21, 55, 12, 55, 0, 24, + 25, 29, 55, 49, 52, 22 + } ; + +static const short int yy_def[37] = + { 0, + 33, 1, 33, 33, 33, 33, 34, 35, 33, 33, + 33, 33, 33, 33, 33, 33, 36, 33, 33, 36, + 34, 33, 34, 34, 35, 33, 33, 33, 36, 34, + 34, 34, 0, 33, 33, 33 + } ; + +static const short int yy_nxt[76] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 4, 11, 12, + 13, 14, 15, 16, 17, 18, 4, 19, 20, 4, + 22, 22, 30, 29, 27, 26, 22, 22, 30, 27, + 28, 27, 30, 23, 23, 23, 24, 24, 24, 31, + 23, 32, 24, 24, 24, 23, 26, 33, 24, 21, + 21, 21, 25, 25, 3, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static const short int yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 21, 23, 36, 27, 25, 24, 30, 31, 15, + 14, 11, 32, 7, 21, 23, 7, 21, 23, 24, + 30, 31, 24, 30, 31, 32, 8, 3, 32, 34, + 34, 34, 35, 35, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; + +static yy_state_type yy_last_accepting_state; +static YY_CHAR *yy_last_accepting_cpos; + +/* the intent behind this definition is that it'll catch + * any uses of REJECT which flex missed + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 + +/* these variables are all declared out here so that section 3 code can + * manipulate them + */ +/* points to current character in buffer */ +static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr )); +void yyrestart YY_PROTO(( FILE *input_file )); +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); + +#define yy_new_buffer yy_create_buffer + +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif + +YY_DECL + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp, *yy_bp; + register int yy_act; + + + + + if ( yy_init ) + { + YY_USER_INIT; + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( yy_current_buffer ) + yy_init_buffer( yy_current_buffer, yyin ); + else + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + + yy_init = 0; + } + +#if !defined(__VISAGECPP__) + while ( 1 ) /* loops until end-of-file is reached */ +#else + os2var = 1; + if (os2var == 0) return 0; + while ( os2var == 1 ) /* loops until end-of-file is reached */ +#endif + { + yy_cp = yy_c_buf_p; + + /* support of yytext */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of the + * current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[*yy_cp]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 33 ); + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + YY_USER_ACTION; + +do_action: /* this label is used only to access EOF actions */ + + + switch ( yy_act ) + { + case 0: /* must backtrack */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +# line 60 "lexer.l" +{yylval.s = strdup((const char*) yytext); Return(INTEGER);} + YY_BREAK +case 2: +# line 62 "lexer.l" +Return(EXP); + YY_BREAK +case 3: +# line 64 "lexer.l" +{yylval.s = strdup((const char*) yytext); Return(WORD);} + YY_BREAK +case 4: +# line 66 "lexer.l" +{int len = strlen((const char*) yytext); + yytext[len-1] = 0; + yylval.s = strdup((const char*) (yytext+1)); + Return(WORD);} + YY_BREAK +case 5: +# line 71 "lexer.l" +{yylval.s = strdup((const char*) yytext); Return(STRING);} + YY_BREAK +case 6: +# line 73 "lexer.l" +Return(OPEN); + YY_BREAK +case 7: +# line 75 "lexer.l" +Return(CLOSE); + YY_BREAK +case 8: +# line 77 "lexer.l" +Return(COMMA); + YY_BREAK +case 9: +# line 79 "lexer.l" +Return(OPEN_SQUARE); + YY_BREAK +case 10: +# line 81 "lexer.l" +Return(CLOSE_SQUARE); + YY_BREAK +case 11: +# line 83 "lexer.l" +Return(EQUALS); + YY_BREAK +case 12: +# line 85 "lexer.l" +Return(PERIOD); + YY_BREAK +case 13: +# line 87 "lexer.l" +; + YY_BREAK +case 14: +# line 89 "lexer.l" +; + YY_BREAK +case 15: +# line 91 "lexer.l" +{ loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + YY_BREAK +case 16: +# line 106 "lexer.l" +Return(ERROR); + YY_BREAK +case 17: +# line 108 "lexer.l" +ECHO; + YY_BREAK +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* amount of text matched not including the EOB char */ + int yy_amount_of_matched_text = yy_cp - yytext - 1; + + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + + /* note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the end- + * of-buffer state). Contrast this with the test in yyinput(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + { + yy_state_type yy_next_state; + + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* okay, we're now positioned to make the + * NUL transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we + * don't want to build jamming into it because + * then it will run more slowly) + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* consume the NUL */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* note: because we've taken care in + * yy_get_next_buffer() to have set up yytext, + * we can now set up yy_c_buf_p so that if some + * total hoser (like flex itself) wants + * to call the scanner after we return the + * YY_NULL, it'll still work - another YY_NULL + * will get returned. + */ + yy_c_buf_p = yytext + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF((yy_start - 1) / 2); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: +#ifdef FLEX_DEBUG + printf( "action # %d\n", yy_act ); +#endif + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } + } +#if defined(__VISAGECPP__) +/* VA complains about proc maybe not returning a value so return one */ +return 0; +#endif + } + + +/* yy_get_next_buffer - try to read in a new buffer + * + * synopsis + * int yy_get_next_buffer(); + * + * returns a code representing an action + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + + { + register YY_CHAR *dest = yy_current_buffer->yy_ch_buf; + register YY_CHAR *source = yytext - 1; /* copy prev. char, too */ + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + /* try to read more data */ + + /* first move last chars to start of buffer */ + number_to_move = yy_c_buf_p - yytext; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_n_chars = 0; + + else + { + int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1; + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + else if ( num_to_read <= 0 ) + YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); + + /* read in more data */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == 1 ) + { + ret_val = EOB_ACT_END_OF_FILE; + yy_current_buffer->yy_eof_status = EOF_DONE; + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_eof_status = EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + /* yytext begins at the second character in yy_ch_buf; the first + * character is the one which preceded it before reading in the latest + * buffer; it needs to be kept around in case it's a newline, so + * yy_get_previous_state() will have with '^' rules active + */ + + yytext = &yy_current_buffer->yy_ch_buf[1]; + + return ( ret_val ); + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached + * + * synopsis + * yy_state_type yy_get_previous_state(); + */ + +static yy_state_type yy_get_previous_state() + + { + register yy_state_type yy_current_state; + register YY_CHAR *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return ( yy_current_state ); + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +register yy_state_type yy_current_state; +#endif + + { + register int yy_is_jam; + register YY_CHAR *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = yy_def[yy_current_state]; + if ( yy_current_state >= 34 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 33); + + return ( yy_is_jam ? 0 : yy_current_state ); + } + + +#ifdef YY_USE_PROTOS +static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp ) +#else +static void yyunput( c, yy_bp ) +YY_CHAR c; +register YY_CHAR *yy_bp; +#endif + + { + register YY_CHAR *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */ + register YY_CHAR *dest = + &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2]; + register YY_CHAR *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += dest - source; + yy_bp += dest - source; + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) + yy_cp[-2] = '\n'; + + *--yy_cp = c; + + /* note: the formal parameter *must* be called "yy_bp" for this + * macro to now work correctly + */ + YY_DO_BEFORE_ACTION; /* set up yytext again */ + } + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + + { + int c; + YY_CHAR *yy_cp = yy_c_buf_p; + + *yy_cp = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* this was really a NUL */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + yytext = yy_c_buf_p; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + { + yy_c_buf_p = yytext + YY_MORE_ADJ; + return ( EOF ); + } + + YY_NEW_FILE; + +#ifdef __cplusplus + return ( yyinput() ); +#else + return ( input() ); +#endif + } + break; + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext + YY_MORE_ADJ; + break; + + case EOB_ACT_LAST_MATCH: +#ifdef __cplusplus + YY_FATAL_ERROR( "unexpected last match in yyinput()" ); +#else + YY_FATAL_ERROR( "unexpected last match in input()" ); +#endif + } + } + } + + c = *yy_c_buf_p; + yy_hold_char = *++yy_c_buf_p; + + return ( c ); + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + + { + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* flush out information for old buffer */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); + + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) ); + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + yy_init_buffer( b, file ); + + return ( b ); + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + free( (char *) b->yy_ch_buf ); + free( (char *) b ); + } + + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + { + b->yy_input_file = file; + + /* we put in the '\n' and start reading from [1] so that an + * initial match-at-newline will be true. + */ + + b->yy_ch_buf[0] = '\n'; + b->yy_n_chars = 1; + + /* we always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[1]; + + b->yy_eof_status = EOF_NOT_SEEN; + } +# line 108 "lexer.l" + + + +#ifdef FLEX_SCANNER +static int lex_input() { + return input(); +} +#else /* BSD/AT&T lex */ +#ifndef input +# error "Sorry, but need either flex or AT&T lex" +#endif +static int lex_input() { + return input(); +} +/* # undef unput +# define unput(_c) my_unput(_c) +*/ + +# undef input +# define input() my_input() +static int my_unput(char c) +{ + if (lex_read_from_string) { + /* Make sure we have something */ + if (lex_string_ptr) { + if (c == '\n') yylineno--; + lex_string_ptr--; + } + } else { + yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar; +/* unput(c); Causes infinite recursion! */ + } + return c; +} + +#endif + +/* Public */ +void LexFromFile(FILE *fd) +{ + lex_read_from_string = 0; + yyin = fd; + /* Don't know why this is necessary, but otherwise + * lex only works _once_! + */ +#ifdef FLEX_SCANNER + yy_init = 1; +#endif +} + +void LexFromString(char *buffer) +{ + lex_read_from_string = 1; + lex_buffer = buffer; + lex_buffer_length = strlen((const char*) buffer); + lex_string_ptr = 0; + /* Don't know why this is necessary, but otherwise + * lex only works _once_! + */ +#ifdef FLEX_SCANNER + yy_init = 1; +#endif +} + +static int my_input( void ) +{ + if (lex_read_from_string) { + if (lex_string_ptr == lex_buffer_length) + return 0; + else { + char c = lex_buffer[lex_string_ptr++]; +#ifndef FLEX_SCANNER + if (c == '\n') yylineno++; +#endif + return c; + } + } else { + return lex_input(); + } +} + +void wxExprCleanUp() +{ + if (yy_current_buffer) + yy_delete_buffer(yy_current_buffer); +} diff --git a/contrib/src/deprecated/lexer.l b/contrib/src/deprecated/lexer.l new file mode 100644 index 0000000000..0b6da15c98 --- /dev/null +++ b/contrib/src/deprecated/lexer.l @@ -0,0 +1,192 @@ +SIGN [+-] +DIGIT [0-9] +ALPHA [a-zA-Z_] +ALPHADIGIT [a-zA-Z_0-9] +STRINGCHAR [^"\\] +WORDCHAR [^'\\] + +%{ +/* + * File: lexer.l + * Description: Lexical analyser for PROLOGIO; can be used with + * either lex and flex. + */ +#include +#include + +/* +++steve162e: added, otherwise, PROIO_input will be undefined (at least under LINUX) + please check, if this is also TRUE under other UNIXes. + */ + +#if defined(FLEX_SCANNER) && defined(_LINUX) +#define PROIO_input my_input +#endif +/* ---steve162e */ + +#include "wx/deprecated/expr.h" + +#define Return(x) return x; + +#if defined(VMS) && !defined(strdup) +#define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s)); +#endif + +static size_t lex_buffer_length = 0; +static const char *lex_buffer = NULL; +static size_t lex_string_ptr = 0; +static int lex_read_from_string = 0; + +static int my_input(void); + +#ifdef FLEX_SCANNER +# undef YY_INPUT +# define YY_INPUT(buf,result,max_size) \ + if (lex_read_from_string) \ + { int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \ + else \ + if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "read() in flex scanner failed" ); +#else +# undef unput +# define unput(_c) my_unput(_c) + static int my_unput(char); +#endif + +%} + +%% + +{SIGN}?{DIGIT}+ {yylval.s = strdup(yytext); Return(INTEGER);} + +"e" Return(EXP); + +{ALPHA}{ALPHADIGIT}* {yylval.s = strdup(yytext); Return(WORD);} + +"'"{WORDCHAR}*"'" {int len = strlen(yytext); + yytext[len-1] = 0; + yylval.s = strdup(yytext+1); + Return(WORD);} + +\"({STRINGCHAR}|\\\"|\|\\\\|\\)*\" {yylval.s = strdup(yytext); Return(STRING);} + +"(" Return(OPEN); + +")" Return(CLOSE); + +"," Return(COMMA); + +"[" Return(OPEN_SQUARE); + +"]" Return(CLOSE_SQUARE); + +"=" Return(EQUALS); + +"." Return(PERIOD); + +[ \t] ; + +\n ; + +"/*" { loop: +#ifdef __cplusplus + while (yyinput() != '*'); + switch (yyinput()) +#else + while (input() != '*'); + switch (input()) +#endif + { + case '/': break; + case '*': unput('*'); + default: goto loop; + } + } + +. Return(ERROR); + +%% + + +#ifdef FLEX_SCANNER +static int lex_input() { + return input(); +} +#else /* BSD/AT&T lex */ +#ifndef input +# error "Sorry, but need either flex or AT&T lex" +#endif +static int lex_input() { + return input(); +} + +# undef input +# define input() my_input() +static int my_unput(char c) +{ + if (lex_read_from_string != 0) { + /* Make sure we have something */ + if (lex_string_ptr) { + if (c == '\n') yylineno--; + lex_string_ptr--; + } + } else { + yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar; +/* unput(c); Causes infinite recursion! */ + } + return c; +} + +#endif + +/* Public */ +void LexFromFile(FILE *fd) +{ + lex_read_from_string = 0; + yyin = fd; + /* Don't know why this is necessary, but otherwise + * lex only works _once_! + */ +#ifdef FLEX_SCANNER + yyrestart(fd); + yy_init = 1; +#endif +} + +void LexFromString(char *buffer) +{ + lex_read_from_string = 1; + lex_buffer = buffer; + lex_buffer_length = strlen(buffer); + lex_string_ptr = 0; + /* Don't know why this is necessary, but otherwise + * lex only works _once_! + */ +#ifdef FLEX_SCANNER + yy_init = 1; +#endif +} + +static int my_input( void ) +{ + if (lex_read_from_string) { + if (lex_string_ptr == lex_buffer_length) + return 0; + else { + char c = lex_buffer[lex_string_ptr++]; +#ifndef FLEX_SCANNER + if (c == '\n') yylineno++; +#endif + return c; + } + } else { + return lex_input(); + } +} + +void wxExprCleanUp() +{ +#ifdef FLEX_SCANNER + if (yy_current_buffer) + yy_delete_buffer(yy_current_buffer); +#endif +} diff --git a/contrib/src/deprecated/makefile.b32 b/contrib/src/deprecated/makefile.b32 new file mode 100644 index 0000000000..b45c3ab60a --- /dev/null +++ b/contrib/src/deprecated/makefile.b32 @@ -0,0 +1,17 @@ +# +# File: makefile.b32 +# Author: Julian Smart +# Created: 1999 +# Updated: +# Copyright: +# +# Makefile : Builds Deprecated library for 32-bit BC++ + +WXDIR = $(WXWIN) + +LIBTARGET=$(WXDIR)\lib\wxdeprecated.lib + +OBJECTS = prop.obj propform.obj proplist.obj y_tab.obj resource.obj treelay.obj + +!include $(WXDIR)\src\makelib.b32 + diff --git a/contrib/src/deprecated/makefile.g95 b/contrib/src/deprecated/makefile.g95 new file mode 100644 index 0000000000..31a23ee0bf --- /dev/null +++ b/contrib/src/deprecated/makefile.g95 @@ -0,0 +1,16 @@ +# +# File: makefile.g95 +# Author: Julian Smart +# Created: 1999 +# Updated: +# Copyright: (c) Julian Smart, 1999 +# +# Makefile for wxWindows Deprecated Features library (Cygwin/Mingw32). + +WXDIR = ../../.. + +LIBTARGET=$(WXDIR)/lib/libwxdeprecated.a +OBJECTS = prop.o propform.o proplist.o y_tab.o resource.o treelay.o + +include $(WXDIR)/src/makelib.g95 + diff --git a/contrib/src/deprecated/makefile.vc b/contrib/src/deprecated/makefile.vc new file mode 100644 index 0000000000..9b18d5efa9 --- /dev/null +++ b/contrib/src/deprecated/makefile.vc @@ -0,0 +1,38 @@ + +# File: makefile.vc +# Author: Julian Smart +# Created: 1993 +# Updated: +# Copyright: +# +# "%W% %G%" +# +# Makefile : Builds Deprecated Features classes library (MS VC++). +# Use FINAL=1 argument to nmake to build final version with no debugging +# info + +# Set WXDIR for your system +WXDIR = $(WXWIN) +THISDIR = $(WXDIR)\contrib\src\deprecated + +!if "$(RM)" == "" +RM= erase +!endif + +NOPCH=1 + +# Unfortunately we need this _before_ we include makelib.vc +!if "$(FINAL)" == "1" +D=Release +!else +D=Debug +LIBEXT=d +!endif + +LIBTARGET=$(WXDIR)\lib\wxdeprecated$(LIBEXT).lib +EXTRATARGETS=$(D) + +OBJECTS=$(D)\prop.obj $(D)\propform.obj $(D)\proplist.obj $(D)\y_tab.obj $(D)\resource.obj $(D)\treelay.obj + +!include $(WXDIR)\src\makelib.vc + diff --git a/contrib/src/deprecated/parser.y b/contrib/src/deprecated/parser.y new file mode 100644 index 0000000000..cad1dc60d1 --- /dev/null +++ b/contrib/src/deprecated/parser.y @@ -0,0 +1,184 @@ +/* Version: $Id$ */ + %{ +#include "wx/setup.h" +#include +#ifdef _MSC_VER +#include +#endif +#if defined(__GNUWIN32__) && !defined(__TWIN32__) +#include +#endif + +#include "wx/deprecated/expr.h" + +#ifndef __EXTERN_C__ +#define __EXTERN_C__ 1 +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +extern "C" { +#endif +#endif +int yylex(void); +int yylook(void); +int yywrap(void); +int yyback(int *, int); +void yyerror(char *); + +/* You may need to put /DLEX_SCANNER in your makefile + * if you're using LEX! + */ +void yyoutput(int); + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +} +#endif +#endif +%} + +%union { + char *s; +/* struct pexpr *expr; */ +} + + +%start commands + +%token INTEGER 1 +%token WORD 2 +%token STRING 3 +%token PERIOD 13 +%token OPEN 4 +%token CLOSE 5 +%token COMMA 6 +%token NEWLINE 7 +%token ERROR 8 +%token OPEN_SQUARE 9 +%token CLOSE_SQUARE 10 +%token EQUALS 11 +%token EXP 14 + +/* %type command expr arglist arg arg1 */ +%type command expr arglist arg arg1 + +%% + +commands : /* empty */ + | commands command + ; + +command : WORD PERIOD + {process_command(proio_cons(wxmake_word($1), NULL)); free($1);} + | expr PERIOD + {process_command($1);} + | error PERIOD + {syntax_error("Unrecognized command.");} + ; + +expr : WORD OPEN arglist CLOSE + {$$ = proio_cons(wxmake_word($1), $3); free($1);} + | OPEN_SQUARE arglist CLOSE_SQUARE + {$$ = $2; } + ; + +arglist : + {$$ = proio_cons(NULL, NULL);} + | arg + {$$ = proio_cons($1, NULL);} + | + arg COMMA arglist + {$$ = proio_cons($1, $3);} + ; + +arg : WORD EQUALS arg1 + {$$ = proio_cons(wxmake_word("="), proio_cons(wxmake_word($1), proio_cons($3, NULL))); + free($1); } + | arg1 + {$$ = $1; } + ; + +arg1 : WORD + {$$ = wxmake_word($1); free($1);} + | STRING + {$$ = wxmake_string($1); free($1);} + | INTEGER + {$$ = wxmake_integer($1); free($1);} + | INTEGER PERIOD INTEGER + {$$ = wxmake_real($1, $3); free($1); free($3); } + | INTEGER EXP INTEGER + {$$ = wxmake_exp($1, $3); free($1); free($3); } + | + INTEGER PERIOD INTEGER EXP INTEGER + {$$ = wxmake_exp2($1, $3, $5); free($1); free($3); + free($5); } + + | expr + {$$ = $1;} + ; + +%% + +/* We include lexer.c if we are building for gtk, wine or motif + * and also whenever we are using configure (marked by __WX_SETUP_H__) for, + * for example, cross compilation. */ +#if (defined(__WXGTK__) || defined(__WXWINE__) || defined(__WXMOTIF__)) || defined(__WX_SETUP_H__) && !defined(NO_CONFIGURE) +#include "lexer.c" +#elif defined(__WXMAC__) && defined(__APPLE__) +#include "lexer.c" +#elif defined(__MWERKS__) +#include "../common/cwlex_yy.c" +#else +#include "../common/lex_yy.c" +#endif + +/* +void yyerror(s) +char *s; +{ + syntax_error(s); +} +*/ + +/* Ansi prototype. If this doesn't work for you... uncomment + the above instead. + */ + +void yyerror(char *s) +{ + syntax_error(s); +} + +/* + * Unfortunately, my DOS version of FLEX + * requires yywrap to be #def'ed, whereas + * the UNIX flex expects a proper function. + */ + +/* At least on alphaev6-dec-osf4.0e yywrap() must be #define'd. + * RL: ... but on Debian/Alpha(linux) it must not, so hopefully + * testing for __OSF__ here is what we really want. + */ +#ifdef __OSF__ +#ifndef yywrap +#define yywrap() 1 +#endif +#else +/* HH: Added test for __WX_SETUP_H__ for gnuwin builds + * using configure */ +#if !defined(__SC__) && !defined(__GNUWIN32__) +#ifdef USE_DEFINE +#ifndef yywrap +#define yywrap() 1 +#endif +#elif !defined(__ultrix) +int yywrap() { return 1; } +#elif defined(__VMS__) +int yywrap() { return 1; } +#endif +#elif defined(__WX_SETUP_H__) +int yywrap() { return 1; } +#endif +#endif + diff --git a/contrib/src/deprecated/prop.cpp b/contrib/src/deprecated/prop.cpp new file mode 100644 index 0000000000..75bfa145b2 --- /dev/null +++ b/contrib/src/deprecated/prop.cpp @@ -0,0 +1,1164 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: prop.cpp +// Purpose: Propert sheet classes implementation +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "prop.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROPSHEET + +#ifndef WX_PRECOMP +#endif + +#include "wx/debug.h" +#include "wx/deprecated/prop.h" + +#include +#include +#include +#include + + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyValue, wxObject) + +wxPropertyValue::wxPropertyValue(void) +{ + m_type = wxPropertyValueNull; + m_next = NULL; + m_last = NULL; + m_value.first = NULL; + m_clientData = NULL; + m_modifiedFlag = FALSE; +} + +wxPropertyValue::wxPropertyValue(const wxPropertyValue& copyFrom) + : wxObject() +{ + m_value.string = (wxChar*) NULL; + m_modifiedFlag = FALSE; + Copy((wxPropertyValue& )copyFrom); +} + +wxPropertyValue::wxPropertyValue(const wxChar *val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueString; + + m_value.string = copystring(val); + m_clientData = NULL; + m_next = NULL; + m_last = NULL; +} + +wxPropertyValue::wxPropertyValue(const wxString& val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueString; + + m_value.string = copystring((const wxChar *)val); + m_clientData = NULL; + m_next = NULL; + m_last = NULL; +} + +wxPropertyValue::wxPropertyValue(long the_integer) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueInteger; + m_value.integer = the_integer; + m_clientData = NULL; + m_next = NULL; +} + +wxPropertyValue::wxPropertyValue(bool val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValuebool; + m_value.integer = val; + m_clientData = NULL; + m_next = NULL; +} + +wxPropertyValue::wxPropertyValue(float the_real) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueReal; + m_value.real = the_real; + m_clientData = NULL; + m_next = NULL; +} + +wxPropertyValue::wxPropertyValue(double the_real) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueReal; + m_value.real = (float)the_real; + m_clientData = NULL; + m_next = NULL; +} + +// Pointer versions: we have a pointer to the real C++ value. +wxPropertyValue::wxPropertyValue(wxChar **val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueStringPtr; + + m_value.stringPtr = val; + m_clientData = NULL; + m_next = NULL; + m_last = NULL; +} + +wxPropertyValue::wxPropertyValue(long *val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueIntegerPtr; + m_value.integerPtr = val; + m_clientData = NULL; + m_next = NULL; +} + +wxPropertyValue::wxPropertyValue(bool *val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueboolPtr; + m_value.boolPtr = val; + m_clientData = NULL; + m_next = NULL; +} + +wxPropertyValue::wxPropertyValue(float *val) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueRealPtr; + m_value.realPtr = val; + m_clientData = NULL; + m_next = NULL; +} + +wxPropertyValue::wxPropertyValue(wxList *the_list) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueList; + m_clientData = NULL; + m_last = NULL; + m_value.first = NULL; + + wxNode *node = the_list->GetFirst(); + while (node) + { + wxPropertyValue *expr = (wxPropertyValue *)node->GetData(); + Append(expr); + node = node->GetNext(); + } + + delete the_list; +} + +wxPropertyValue::wxPropertyValue(wxStringList *the_list) +{ + m_modifiedFlag = FALSE; + m_type = wxPropertyValueList; + m_clientData = NULL; + m_last = NULL; + m_value.first = NULL; + + wxStringList::Node *node = the_list->GetFirst(); + while (node) + { + wxChar *s = node->GetData(); + Append(new wxPropertyValue(s)); + node = node->GetNext(); + } + delete the_list; +} + +wxPropertyValue::~wxPropertyValue(void) +{ + switch (m_type) + { + case wxPropertyValueInteger: + case wxPropertyValuebool: + case wxPropertyValueReal: + { + break; + } + case wxPropertyValueString: + { + delete[] m_value.string; + break; + } + case wxPropertyValueList: + { + wxPropertyValue *expr = m_value.first; + while (expr) + { + wxPropertyValue *expr1 = expr->m_next; + + delete expr; + expr = expr1; + } + break; + } + default: + case wxPropertyValueNull: break; + } +} + +void wxPropertyValue::Append(wxPropertyValue *expr) +{ + m_modifiedFlag = TRUE; + if (!m_value.first) + m_value.first = expr; + + if (m_last) + m_last->m_next = expr; + m_last = expr; +} + +void wxPropertyValue::Insert(wxPropertyValue *expr) +{ + m_modifiedFlag = TRUE; + expr->m_next = m_value.first; + m_value.first = expr; + + if (!m_last) + m_last = expr; +} + +// Delete from list +void wxPropertyValue::Delete(wxPropertyValue *node) +{ + wxPropertyValue *expr = GetFirst(); + + wxPropertyValue *previous = NULL; + while (expr && (expr != node)) + { + previous = expr; + expr = expr->GetNext(); + } + + if (expr) + { + if (previous) + previous->m_next = expr->m_next; + + // If node was the first in the list, + // make the list point to the NEXT one. + if (GetFirst() == expr) + { + m_value.first = expr->m_next; + } + + // If node was the last in the list, + // make the list 'last' pointer point to the PREVIOUS one. + if (GetLast() == expr) + { + if (previous) + m_last = previous; + else + m_last = NULL; + } + m_modifiedFlag = TRUE; + delete expr; + } + +} + +void wxPropertyValue::ClearList(void) +{ + wxPropertyValue *val = GetFirst(); + if (val) + m_modifiedFlag = TRUE; + + while (val) + { + wxPropertyValue *next = val->GetNext(); + delete val; + val = next; + } + m_value.first = NULL; + m_last = NULL; +} + +wxPropertyValue *wxPropertyValue::NewCopy(void) const +{ + switch (m_type) + { + case wxPropertyValueInteger: + return new wxPropertyValue(m_value.integer); + case wxPropertyValuebool: + return new wxPropertyValue((bool) (m_value.integer != 0)); + case wxPropertyValueReal: + return new wxPropertyValue(m_value.real); + case wxPropertyValueString: + return new wxPropertyValue(m_value.string); + case wxPropertyValueList: + { + wxPropertyValue *expr = m_value.first; + wxPropertyValue *new_list = new wxPropertyValue; + new_list->SetType(wxPropertyValueList); + while (expr) + { + wxPropertyValue *expr2 = expr->NewCopy(); + new_list->Append(expr2); + expr = expr->m_next; + } + return new_list; + } + case wxPropertyValueIntegerPtr: + return new wxPropertyValue(m_value.integerPtr); + case wxPropertyValueRealPtr: + return new wxPropertyValue(m_value.realPtr); + case wxPropertyValueboolPtr: + return new wxPropertyValue(m_value.boolPtr); + case wxPropertyValueStringPtr: + return new wxPropertyValue(m_value.stringPtr); + + case wxPropertyValueNull: + wxFAIL_MSG( wxT("Should never get here!\n" ) ); + break; + } + return NULL; +} + +void wxPropertyValue::Copy(wxPropertyValue& copyFrom) +{ + if (m_type == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } + m_type = copyFrom.Type(); + + switch (m_type) + { + case wxPropertyValueInteger: + (*this) = copyFrom.IntegerValue(); + return ; + + case wxPropertyValueReal: + (*this) = copyFrom.RealValue(); + return ; + + case wxPropertyValueString: + (*this) = wxString(copyFrom.StringValue()); + return ; + + case wxPropertyValuebool: + (*this) = copyFrom.BoolValue(); + return ; + + // Pointers + case wxPropertyValueboolPtr: + (*this) = copyFrom.BoolValuePtr(); + return ; + case wxPropertyValueRealPtr: + (*this) = copyFrom.RealValuePtr(); + return ; + case wxPropertyValueIntegerPtr: + (*this) = copyFrom.IntegerValuePtr(); + return ; + case wxPropertyValueStringPtr: + { + wxChar** s = copyFrom.StringValuePtr(); + +#if 0 + // what is this? are you trying to assign a bool or a string? VA can't figure it out.. +#if defined(__VISAGECPP__) || defined( __VISUALC__ ) + (*this) = s; +#else + (*this) = s != 0; +#endif +#endif // if 0 + + (*this) = (bool)(s != 0); + + return ; + } + + case wxPropertyValueList: + { + m_value.first = NULL; + m_next = NULL; + m_last = NULL; + wxPropertyValue *expr = copyFrom.m_value.first; + while (expr) + { + wxPropertyValue *expr2 = expr->NewCopy(); + Append(expr2); + expr = expr->m_next; + } + return; + } + case wxPropertyValueNull: + wxFAIL_MSG( wxT("Should never get here!\n" ) ); + break; + } +} + +// Return nth argument of a clause (starting from 1) +wxPropertyValue *wxPropertyValue::Arg(wxPropertyValueType type, int arg) const +{ + wxPropertyValue *expr = m_value.first; + for (int i = 1; i < arg; i++) + if (expr) + expr = expr->m_next; + + if (expr && (expr->m_type == type)) + return expr; + else + return NULL; +} + +// Return nth argument of a list expression (starting from zero) +wxPropertyValue *wxPropertyValue::Nth(int arg) const +{ + if (m_type != wxPropertyValueList) + return NULL; + + wxPropertyValue *expr = m_value.first; + for (int i = 0; i < arg; i++) + if (expr) + expr = expr->m_next; + else return NULL; + + if (expr) + return expr; + else + return NULL; +} + + // Returns the number of elements in a list expression +int wxPropertyValue::Number(void) const +{ + if (m_type != wxPropertyValueList) + return 0; + + int i = 0; + wxPropertyValue *expr = m_value.first; + while (expr) + { + expr = expr->m_next; + i ++; + } + return i; +} + +void wxPropertyValue::WritePropertyClause(wxString& stream) // Write this expression as a top-level clause +{ + if (m_type != wxPropertyValueList) + return; + + wxPropertyValue *node = m_value.first; + if (node) + { + node->WritePropertyType(stream); + stream.Append( wxT("(") ); + node = node->m_next; + bool first = TRUE; + while (node) + { + if (!first) + stream.Append( wxT(" ") ); + node->WritePropertyType(stream); + node = node->m_next; + if (node) + stream.Append( wxT(",\n" ) ); + first = FALSE; + } + stream.Append( wxT(").\n\n") ); + } +} + +void wxPropertyValue::WritePropertyType(wxString& stream) // Write as any other subexpression +{ + wxString tmp; + switch (m_type) + { + case wxPropertyValueInteger: + { + tmp.Printf( wxT("%ld"), m_value.integer ); + stream.Append( tmp ); + break; + } + case wxPropertyValueIntegerPtr: + { + tmp.Printf( wxT("%ld"), *m_value.integerPtr ); + stream.Append( tmp ); + break; + } + case wxPropertyValuebool: + { + if (m_value.integer) + stream.Append( wxT("True") ); + else + stream.Append( wxT("False") ); + break; + } + case wxPropertyValueboolPtr: + { + if (*m_value.integerPtr) + stream.Append( wxT("True") ); + else + stream.Append( wxT("False") ); + break; + } + case wxPropertyValueReal: + { + double d = m_value.real; + tmp.Printf( wxT("%.6g"), d ); + stream.Append( tmp ); + break; + } + case wxPropertyValueRealPtr: + { + double d = *m_value.realPtr; + tmp.Printf( wxT("%.6g"), d ); + stream.Append( tmp ); + break; + } + case wxPropertyValueString: + { + stream.Append( m_value.string ); + break; + } + case wxPropertyValueStringPtr: + { + wxFAIL_MSG( wxT("wxPropertyValue::WritePropertyType( wxPropertyValueStringPtr ) not implemented") ); + /* + int i; + int len = strlen(*(m_value.stringPtr)); + for (i = 0; i < len; i++) + { + char ch = *(m_value.stringPtr)[i]; + + } + */ + break; + } + case wxPropertyValueList: + { + if (!m_value.first) + stream.Append( wxT("[]") ); + else + { + wxPropertyValue *expr = m_value.first; + + stream.Append( wxT("[") ); + while (expr) + { + expr->WritePropertyType(stream); + expr = expr->m_next; + if (expr) + stream.Append( wxT(", ") ); + } + stream.Append( wxT("]") ); + } + break; + } + case wxPropertyValueNull: break; + } +} + +wxString wxPropertyValue::GetStringRepresentation(void) +{ + wxString str; + WritePropertyType(str); + return str; +} + +void wxPropertyValue::operator=(const wxPropertyValue& val) +{ + m_modifiedFlag = TRUE; + Copy((wxPropertyValue&)val); +} + +// void wxPropertyValue::operator=(const char *val) +void wxPropertyValue::operator=(const wxString& val1) +{ + const wxChar *val = (const wxChar *)val1; + + m_modifiedFlag = TRUE; + + wxPropertyValueType oldType = m_type; + if (oldType == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } + + if (m_type == wxPropertyValueNull) + m_type = wxPropertyValueString; + + if (m_type == wxPropertyValueString) + { + if (val) + m_value.string = copystring(val); + else + m_value.string = NULL; + } + else if (m_type == wxPropertyValueStringPtr) + { + wxFAIL_MSG( wxT("Shouldn't try to assign a wxString reference to a char* pointer.") ); + if (val) + *m_value.stringPtr = copystring(val); + else + *m_value.stringPtr = NULL; + } + + m_clientData = NULL; + m_next = NULL; + m_last = NULL; + +} + +void wxPropertyValue::operator=(const long val) +{ + wxPropertyValueType oldType = m_type; + if (oldType == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } + + m_modifiedFlag = TRUE; + if (m_type == wxPropertyValueNull) + m_type = wxPropertyValueInteger; + + if (m_type == wxPropertyValueInteger) + m_value.integer = val; + else if (m_type == wxPropertyValueIntegerPtr) + *m_value.integerPtr = val; + else if (m_type == wxPropertyValueReal) + m_value.real = (float)val; + else if (m_type == wxPropertyValueRealPtr) + *m_value.realPtr = (float)val; + + m_clientData = NULL; + m_next = NULL; +} + +void wxPropertyValue::operator=(const bool val) +{ + wxPropertyValueType oldType = m_type; + if (oldType == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } + + m_modifiedFlag = TRUE; + if (m_type == wxPropertyValueNull) + m_type = wxPropertyValuebool; + + if (m_type == wxPropertyValuebool) + m_value.integer = (long)val; + else if (m_type == wxPropertyValueboolPtr) + *m_value.boolPtr = val; + + m_clientData = NULL; + m_next = NULL; +} + +void wxPropertyValue::operator=(const float val) +{ + wxPropertyValueType oldType = m_type; + if (oldType == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } + + m_modifiedFlag = TRUE; + if (m_type == wxPropertyValueNull) + m_type = wxPropertyValueReal; + + if (m_type == wxPropertyValueInteger) + m_value.integer = (long)val; + else if (m_type == wxPropertyValueIntegerPtr) + *m_value.integerPtr = (long)val; + else if (m_type == wxPropertyValueReal) + m_value.real = val; + else if (m_type == wxPropertyValueRealPtr) + *m_value.realPtr = val; + + m_clientData = NULL; + m_next = NULL; +} + +void wxPropertyValue::operator=(const wxChar **val) +{ + wxPropertyValueType oldType = m_type; + if (oldType == wxPropertyValueString) + { + delete[] m_value.string ; + m_value.string = NULL; + } + + m_modifiedFlag = TRUE; + m_type = wxPropertyValueStringPtr; + + if (val) + m_value.stringPtr = (wxChar **)val; + else + m_value.stringPtr = NULL; + m_clientData = NULL; + m_next = NULL; + m_last = NULL; + +} + +void wxPropertyValue::operator=(const long *val) +{ + m_modifiedFlag = TRUE; + m_type = wxPropertyValueIntegerPtr; + m_value.integerPtr = (long *)val; + m_clientData = NULL; + m_next = NULL; +} + +void wxPropertyValue::operator=(const bool *val) +{ + m_modifiedFlag = TRUE; + m_type = wxPropertyValueboolPtr; + m_value.boolPtr = (bool *)val; + m_clientData = NULL; + m_next = NULL; +} + +void wxPropertyValue::operator=(const float *val) +{ + m_modifiedFlag = TRUE; + m_type = wxPropertyValueRealPtr; + m_value.realPtr = (float *)val; + m_clientData = NULL; + m_next = NULL; +} + +long wxPropertyValue::IntegerValue(void) const + { + if (m_type == wxPropertyValueInteger) + return m_value.integer; + else if (m_type == wxPropertyValueReal) + return (long)m_value.real; + else if (m_type == wxPropertyValueIntegerPtr) + return *m_value.integerPtr; + else if (m_type == wxPropertyValueRealPtr) + return (long)(*m_value.realPtr); + else return 0; + } + +long *wxPropertyValue::IntegerValuePtr(void) const +{ + return m_value.integerPtr; +} + +float wxPropertyValue::RealValue(void) const { + if (m_type == wxPropertyValueReal) + return m_value.real; + else if (m_type == wxPropertyValueRealPtr) + return *m_value.realPtr; + else if (m_type == wxPropertyValueInteger) + return (float)m_value.integer; + else if (m_type == wxPropertyValueIntegerPtr) + return (float)*(m_value.integerPtr); + else return 0.0; + } + +float *wxPropertyValue::RealValuePtr(void) const +{ + return m_value.realPtr; +} + +bool wxPropertyValue::BoolValue(void) const { + if (m_type == wxPropertyValueReal) + return (m_value.real != 0.0); + if (m_type == wxPropertyValueRealPtr) + return (*(m_value.realPtr) != 0.0); + else if (m_type == wxPropertyValueInteger) + return (m_value.integer != 0); + else if (m_type == wxPropertyValueIntegerPtr) + return (*(m_value.integerPtr) != 0); + else if (m_type == wxPropertyValuebool) + return (m_value.integer != 0); + else if (m_type == wxPropertyValueboolPtr) + return (*(m_value.boolPtr) != 0); + else return FALSE; + } + +bool *wxPropertyValue::BoolValuePtr(void) const +{ + return m_value.boolPtr; +} + +wxChar *wxPropertyValue::StringValue(void) const { + if (m_type == wxPropertyValueString) + return m_value.string; + else if (m_type == wxPropertyValueStringPtr) + return *(m_value.stringPtr); + else return NULL; + } + +wxChar **wxPropertyValue::StringValuePtr(void) const +{ + return m_value.stringPtr; +} + +/* + * A property (name plus value) + */ + +IMPLEMENT_DYNAMIC_CLASS(wxProperty, wxObject) + +wxProperty::wxProperty(void) +{ + m_propertyRole = wxEmptyString; + m_propertyValidator = NULL; + m_propertyWindow = NULL; + m_enabled = TRUE; +} + +wxProperty::wxProperty(wxProperty& copyFrom) + : wxObject() +{ + m_value = copyFrom.GetValue(); + m_name = copyFrom.GetName(); + m_propertyRole = copyFrom.GetRole(); + m_propertyValidator = copyFrom.GetValidator(); + m_enabled = copyFrom.IsEnabled(); + m_propertyWindow = NULL; +} + +wxProperty::wxProperty(wxString nm, wxString role, wxPropertyValidator *ed):m_name(nm), m_propertyRole(role) +{ + m_propertyValidator = ed; + m_propertyWindow = NULL; + m_enabled = TRUE; +} + +wxProperty::wxProperty(wxString nm, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed): + m_value(val), m_name(nm), m_propertyRole(role) +{ + m_propertyValidator = ed; + m_propertyWindow = NULL; + m_enabled = TRUE; +} + +wxProperty::~wxProperty(void) +{ + if (m_propertyValidator) + delete m_propertyValidator; +} + +wxPropertyValue& wxProperty::GetValue(void) const +{ + return (wxPropertyValue&) m_value; +} + +wxPropertyValidator *wxProperty::GetValidator(void) const +{ + return m_propertyValidator; +} + +wxString& wxProperty::GetName(void) const +{ + return (wxString&) m_name; +} + +wxString& wxProperty::GetRole(void) const +{ + return (wxString&) m_propertyRole; +} + +void wxProperty::SetValue(const wxPropertyValue& val) +{ + m_value = val; +} + +void wxProperty::SetValidator(wxPropertyValidator *ed) +{ + m_propertyValidator = ed; +} + +void wxProperty::SetRole(wxString& role) +{ + m_propertyRole = role; +} + +void wxProperty::SetName(wxString& nm) +{ + m_name = nm; +} + +void wxProperty::operator=(const wxPropertyValue& val) +{ + m_value = val; +} + +/* + * Base property view class + */ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler) + +wxPropertyView::wxPropertyView(long flags) +{ + m_buttonFlags = flags; + m_propertySheet = NULL; + m_currentValidator = NULL; + m_currentProperty = NULL; +} + +wxPropertyView::~wxPropertyView(void) +{ +} + +void wxPropertyView::AddRegistry(wxPropertyValidatorRegistry *registry) +{ + m_validatorRegistryList.Append(registry); +} + +wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property) +{ + if (property->GetValidator()) + return property->GetValidator(); + + wxNode *node = m_validatorRegistryList.GetFirst(); + while (node) + { + wxPropertyValidatorRegistry *registry = (wxPropertyValidatorRegistry *)node->GetData(); + wxPropertyValidator *validator = registry->GetValidator(property->GetRole()); + if (validator) + return validator; + node = node->GetNext(); + } + return NULL; +/* + if (!wxDefaultPropertyValidator) + wxDefaultPropertyValidator = new wxPropertyListValidator; + return wxDefaultPropertyValidator; +*/ +} + +/* + * Property sheet + */ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertySheet, wxObject) + +wxPropertySheet::wxPropertySheet(const wxString& name) +:m_properties(wxKEY_STRING),m_name(name) +{ +} + +wxPropertySheet::~wxPropertySheet(void) +{ + Clear(); +} + +void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) ) +{ +} + +// Add a property +void wxPropertySheet::AddProperty(wxProperty *property) +{ + m_properties.Append((const wxChar*) property->GetName(), property); +} + +// Get property by name +wxProperty *wxPropertySheet::GetProperty(const wxString& name) const +{ + wxNode *node = m_properties.Find((const wxChar*) name); + if (!node) + return NULL; + else + return (wxProperty *)node->GetData(); +} + +bool wxPropertySheet::SetProperty(const wxString& name, const wxPropertyValue& value) +{ + wxProperty* prop = GetProperty(name); + if(prop){ + prop->SetValue(value); + return TRUE; + }else{ + return FALSE; + } +} + +void wxPropertySheet::RemoveProperty(const wxString& name) +{ + wxNode *node = m_properties.Find(name); + if(node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + delete prop; + m_properties.DeleteNode(node); + } +} + +bool wxPropertySheet::HasProperty(const wxString& name) const +{ + return (GetProperty(name)?TRUE:FALSE); +} + +// Clear all properties +void wxPropertySheet::Clear(void) +{ + wxNode *node = m_properties.GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + wxNode *next = node->GetNext(); + delete prop; + delete node; + node = next; + } +} + +// Sets/clears the modified flag for each property value +void wxPropertySheet::SetAllModified(bool flag) +{ + wxNode *node = m_properties.GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + prop->GetValue().SetModified(flag); + node = node->GetNext(); + } +} + +/* + * Property validator registry + * + */ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyValidatorRegistry, wxHashTable) + +wxPropertyValidatorRegistry::wxPropertyValidatorRegistry(void):wxHashTable(wxKEY_STRING) +{ +} + +wxPropertyValidatorRegistry::~wxPropertyValidatorRegistry(void) +{ + ClearRegistry(); +} + +void wxPropertyValidatorRegistry::RegisterValidator(const wxString& typeName, wxPropertyValidator *validator) +{ + Put((const wxChar*) typeName, validator); +} + +wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(const wxString& typeName) +{ + return (wxPropertyValidator *)Get((const wxChar*) typeName); +} + +void wxPropertyValidatorRegistry::ClearRegistry(void) +{ + BeginFind(); + wxNode *node; + while ((node = Next()) != NULL) + { + delete (wxPropertyValidator *)node->GetData(); + } +} + + /* + * Property validator + */ + + +IMPLEMENT_ABSTRACT_CLASS(wxPropertyValidator, wxEvtHandler) + +wxPropertyValidator::wxPropertyValidator(long flags) +{ + m_validatorFlags = flags; + m_validatorProperty = NULL; +} + +wxPropertyValidator::~wxPropertyValidator(void) +{} + +bool wxPropertyValidator::StringToFloat (wxChar *s, float *number) { + double num; + bool ok = StringToDouble (s, &num); + *number = (float) num; + return ok; +} + +bool wxPropertyValidator::StringToDouble (wxChar *s, double *number) { + bool ok = TRUE; + wxChar *value_ptr; + *number = wxStrtod (s, &value_ptr); + if (value_ptr) { + int len = wxStrlen (value_ptr); + for (int i = 0; i < len; i++) { + ok = (wxIsspace (value_ptr[i]) != 0); + if (!ok) return FALSE; + } + } + return ok; +} + +bool wxPropertyValidator::StringToInt (wxChar *s, int *number) { + long num; + bool ok = StringToLong (s, &num); + *number = (int) num; + return ok; +} + +bool wxPropertyValidator::StringToLong (wxChar *s, long *number) { + bool ok = TRUE; + wxChar *value_ptr; + *number = wxStrtol (s, &value_ptr, 10); + if (value_ptr) { + int len = wxStrlen (value_ptr); + for (int i = 0; i < len; i++) { + ok = (wxIsspace (value_ptr[i]) != 0); + if (!ok) return FALSE; + } + } + return ok; +} + +wxChar *wxPropertyValidator::FloatToString (float number) { + static wxChar buf[20]; + wxSnprintf (buf, 20, wxT("%.6g"), number); + return buf; +} + +wxChar *wxPropertyValidator::DoubleToString (double number) { + static wxChar buf[20]; + wxSnprintf (buf, 20, wxT("%.6g"), number); + return buf; +} + +wxChar *wxPropertyValidator::IntToString (int number) { + return ::IntToString (number); +} + +wxChar *wxPropertyValidator::LongToString (long number) { + return ::LongToString (number); + } + +#endif // wxUSE_PROPSHEET diff --git a/contrib/src/deprecated/propform.cpp b/contrib/src/deprecated/propform.cpp new file mode 100644 index 0000000000..6490cca3c8 --- /dev/null +++ b/contrib/src/deprecated/propform.cpp @@ -0,0 +1,763 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: propform.cpp +// Purpose: Property form classes +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "propform.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROPSHEET + +#ifndef WX_PRECOMP + #include "wx/choice.h" + #include "wx/checkbox.h" + #include "wx/slider.h" + #include "wx/msgdlg.h" +#endif + +#include "wx/deprecated/propform.h" + +#include +#include +#include +#include + + +/* +* Property view +*/ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormView, wxPropertyView) + +BEGIN_EVENT_TABLE(wxPropertyFormView, wxPropertyView) +EVT_BUTTON(wxID_OK, wxPropertyFormView::OnOk) +EVT_BUTTON(wxID_CANCEL, wxPropertyFormView::OnCancel) +EVT_BUTTON(wxID_HELP, wxPropertyFormView::OnHelp) +EVT_BUTTON(wxID_PROP_REVERT, wxPropertyFormView::OnRevert) +EVT_BUTTON(wxID_PROP_UPDATE, wxPropertyFormView::OnUpdate) +END_EVENT_TABLE() + +bool wxPropertyFormView::sm_dialogCancelled = FALSE; + +wxPropertyFormView::wxPropertyFormView(wxWindow *propPanel, long flags):wxPropertyView(flags) +{ + m_propertyWindow = propPanel; + m_managedWindow = NULL; + + m_windowCloseButton = NULL; + m_windowCancelButton = NULL; + m_windowHelpButton = NULL; + + m_detailedEditing = FALSE; +} + +wxPropertyFormView::~wxPropertyFormView(void) +{ +} + +void wxPropertyFormView::ShowView(wxPropertySheet *ps, wxWindow *panel) +{ + m_propertySheet = ps; + + AssociatePanel(panel); + // CreateControls(); + // UpdatePropertyList(); +} + +// Update this view of the viewed object, called e.g. by +// the object itself. +bool wxPropertyFormView::OnUpdateView(void) +{ + return TRUE; +} + +bool wxPropertyFormView::Check(void) +{ + if (!m_propertySheet) + return FALSE; + + wxNode *node = m_propertySheet->GetProperties().GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + wxPropertyValidator *validator = FindPropertyValidator(prop); + if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) + { + wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; + if (!formValidator->OnCheckValue(prop, this, m_propertyWindow)) + return FALSE; + } + node = node->GetNext(); + } + return TRUE; +} + +bool wxPropertyFormView::TransferToPropertySheet(void) +{ + if (!m_propertySheet) + return FALSE; + + wxNode *node = m_propertySheet->GetProperties().GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + wxPropertyValidator *validator = FindPropertyValidator(prop); + if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) + { + wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; + formValidator->OnRetrieveValue(prop, this, m_propertyWindow); + } + node = node->GetNext(); + } + return TRUE; +} + +bool wxPropertyFormView::TransferToDialog(void) +{ + if (!m_propertySheet) + return FALSE; + + wxNode *node = m_propertySheet->GetProperties().GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + wxPropertyValidator *validator = FindPropertyValidator(prop); + if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) + { + wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; + formValidator->OnDisplayValue(prop, this, m_propertyWindow); + } + node = node->GetNext(); + } + return TRUE; +} + +bool wxPropertyFormView::AssociateNames(void) +{ + if (!m_propertySheet || !m_propertyWindow) + return FALSE; + + wxWindowList::Node *node = m_propertyWindow->GetChildren().GetFirst(); + while (node) + { + wxWindow *win = node->GetData(); + if ( win->GetName() != wxEmptyString ) + { + wxProperty *prop = m_propertySheet->GetProperty(win->GetName()); + if (prop) + prop->SetWindow(win); + } + node = node->GetNext(); + } + return TRUE; +} + + +bool wxPropertyFormView::OnClose(void) +{ + if (m_propertyWindow->IsKindOf(CLASSINFO(wxPropertyFormPanel))) + { + ((wxPropertyFormPanel*)m_propertyWindow)->SetView(NULL); + } + delete this; + return TRUE; +} + +void wxPropertyFormView::OnOk(wxCommandEvent& WXUNUSED(event)) +{ + // Retrieve the value if any + if (!Check()) + return; + + sm_dialogCancelled = FALSE; + TransferToPropertySheet(); + + m_managedWindow->Close(TRUE); +} + +void wxPropertyFormView::OnCancel(wxCommandEvent& WXUNUSED(event)) +{ + sm_dialogCancelled = TRUE; + + m_managedWindow->Close(TRUE); +} + +void wxPropertyFormView::OnHelp(wxCommandEvent& WXUNUSED(event)) +{ +} + +void wxPropertyFormView::OnUpdate(wxCommandEvent& WXUNUSED(event)) +{ + if (Check()) + TransferToPropertySheet(); +} + +void wxPropertyFormView::OnRevert(wxCommandEvent& WXUNUSED(event)) +{ + TransferToDialog(); +} + +void wxPropertyFormView::OnCommand(wxWindow& win, wxCommandEvent& event) +{ + if (!m_propertySheet) + return; + + if (win.GetName() == wxT("")) + return; + + if (wxStrcmp(win.GetName(), wxT("ok")) == 0) + OnOk(event); + else if (wxStrcmp(win.GetName(), wxT("cancel")) == 0) + OnCancel(event); + else if (wxStrcmp(win.GetName(), wxT("help")) == 0) + OnHelp(event); + else if (wxStrcmp(win.GetName(), wxT("update")) == 0) + OnUpdate(event); + else if (wxStrcmp(win.GetName(), wxT("revert")) == 0) + OnRevert(event); + else + { + // Find a validator to route the command to. + wxNode *node = m_propertySheet->GetProperties().GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + if (prop->GetWindow() && (prop->GetWindow() == &win)) + { + wxPropertyValidator *validator = FindPropertyValidator(prop); + if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) + { + wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; + formValidator->OnCommand(prop, this, m_propertyWindow, event); + return; + } + } + node = node->GetNext(); + } + } +} + +// Extend event processing to call OnCommand +bool wxPropertyFormView::ProcessEvent(wxEvent& event) +{ + if (wxEvtHandler::ProcessEvent(event)) + return TRUE; + else if (event.IsCommandEvent() && !event.IsKindOf(CLASSINFO(wxUpdateUIEvent)) && event.GetEventObject()) + { + OnCommand(* ((wxWindow*) event.GetEventObject()), (wxCommandEvent&) event); + return TRUE; + } + else + return FALSE; +} + +void wxPropertyFormView::OnDoubleClick(wxControl *item) +{ + if (!m_propertySheet) + return; + + // Find a validator to route the command to. + wxNode *node = m_propertySheet->GetProperties().GetFirst(); + while (node) + { + wxProperty *prop = (wxProperty *)node->GetData(); + if (prop->GetWindow() && ((wxControl *)prop->GetWindow() == item)) + { + wxPropertyValidator *validator = FindPropertyValidator(prop); + if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) + { + wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; + formValidator->OnDoubleClick(prop, this, m_propertyWindow); + return; + } + } + node = node->GetNext(); + } +} + +/* +* Property form dialog box +*/ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormDialog, wxDialog) + +BEGIN_EVENT_TABLE(wxPropertyFormDialog, wxDialog) +EVT_CLOSE(wxPropertyFormDialog::OnCloseWindow) +END_EVENT_TABLE() + +wxPropertyFormDialog::wxPropertyFormDialog(wxPropertyFormView *v, wxWindow *parent, const wxString& title, + const wxPoint& pos, const wxSize& size, long style, const wxString& name): +wxDialog(parent, -1, title, pos, size, style, name) +{ + m_view = v; + m_view->AssociatePanel(this); + m_view->SetManagedWindow(this); + // SetAutoLayout(TRUE); +} + +void wxPropertyFormDialog::OnCloseWindow(wxCloseEvent& event) +{ + if (m_view) + { + m_view->OnClose(); + m_view = NULL; + this->Destroy(); + } + else + event.Veto(); +} + +void wxPropertyFormDialog::OnDefaultAction(wxControl *item) +{ + m_view->OnDoubleClick(item); +} + +void wxPropertyFormDialog::OnCommand(wxWindow& win, wxCommandEvent& event) +{ + if ( m_view ) + m_view->OnCommand(win, event); +} + +// Extend event processing to search the view's event table +bool wxPropertyFormDialog::ProcessEvent(wxEvent& event) +{ + if ( !m_view || ! m_view->ProcessEvent(event) ) + return wxEvtHandler::ProcessEvent(event); + else + return TRUE; +} + + +/* +* Property form panel +*/ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormPanel, wxPanel) + +void wxPropertyFormPanel::OnDefaultAction(wxControl *item) +{ + m_view->OnDoubleClick(item); +} + +void wxPropertyFormPanel::OnCommand(wxWindow& win, wxCommandEvent& event) +{ + m_view->OnCommand(win, event); +} + +// Extend event processing to search the view's event table +bool wxPropertyFormPanel::ProcessEvent(wxEvent& event) +{ + if ( !m_view || ! m_view->ProcessEvent(event) ) + return wxEvtHandler::ProcessEvent(event); + else + return TRUE; +} + +/* +* Property frame +*/ + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormFrame, wxFrame) + +BEGIN_EVENT_TABLE(wxPropertyFormFrame, wxFrame) +EVT_CLOSE(wxPropertyFormFrame::OnCloseWindow) +END_EVENT_TABLE() + +void wxPropertyFormFrame::OnCloseWindow(wxCloseEvent& event) +{ + if (m_view && m_view->OnClose()) + this->Destroy(); + else + event.Veto(); +} + +wxPanel *wxPropertyFormFrame::OnCreatePanel(wxFrame *parent, wxPropertyFormView *v) +{ + return new wxPropertyFormPanel(v, parent); +} + +bool wxPropertyFormFrame::Initialize(void) +{ + m_propertyPanel = OnCreatePanel(this, m_view); + if (m_propertyPanel) + { + m_view->AssociatePanel(m_propertyPanel); + m_view->SetManagedWindow(this); + return TRUE; + } + else + return FALSE; +} + +/* +* Property form specific validator +*/ + +IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator, wxPropertyValidator) + + +/* +* Default validators +*/ + +IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator, wxPropertyFormValidator) + +/// +/// Real number form validator +/// +bool wxRealFormValidator::OnCheckValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *parentWindow) +{ + if (m_realMin == 0.0 && m_realMax == 0.0) + return TRUE; + + // The item used for viewing the real number: should be a text item. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + return FALSE; + + wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); + + float val = 0.0; + if (!StringToFloat(WXSTRINGCAST value, &val)) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value %s is not a valid real number!"), (const wxChar *)value); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + + if (val < m_realMin || val > m_realMax) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin, m_realMax); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + return TRUE; +} + +bool wxRealFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) +{ + // The item used for viewing the real number: should be a text item. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + return FALSE; + + wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); + + if (value.Length() == 0) + return FALSE; + + float f = (float)wxAtof((const wxChar *)value); + property->GetValue() = f; + return TRUE; +} + +bool wxRealFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) +{ + // The item used for viewing the real number: should be a text item. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + return FALSE; + + wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow; + textItem->SetValue(FloatToString(property->GetValue().RealValue())); + return TRUE; +} + +/// +/// Integer validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator, wxPropertyFormValidator) + +bool wxIntegerFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *parentWindow) +{ + if (m_integerMin == 0.0 && m_integerMax == 0.0) + return TRUE; + + // The item used for viewing the real number: should be a text item or a slider + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow) + return FALSE; + + long val = 0; + + if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + { + wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); + + if (!StringToLong(WXSTRINGCAST value, &val)) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value %s is not a valid integer!"), (const wxChar *)value); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider))) + { + val = (long)((wxSlider *)m_propertyWindow)->GetValue(); + } + else + return FALSE; + + if (val < m_integerMin || val > m_integerMax) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + return TRUE; +} + +bool wxIntegerFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow)) +{ + // The item used for viewing the real number: should be a text item or a slider + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow) + return FALSE; + + if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + { + wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); + + if (value.Length() == 0) + return FALSE; + + long i = wxAtol((const wxChar *)value); + property->GetValue() = i; + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider))) + { + property->GetValue() = (long)((wxSlider *)m_propertyWindow)->GetValue(); + } + else + return FALSE; + + return TRUE; +} + +bool wxIntegerFormValidator::OnDisplayValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow)) +{ + // The item used for viewing the real number: should be a text item or a slider + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow) + return FALSE; + + if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + { + wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow; + textItem->SetValue(LongToString(property->GetValue().IntegerValue())); + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider))) + { + ((wxSlider *)m_propertyWindow)->SetValue((int)property->GetValue().IntegerValue()); + } + else + return FALSE; + return TRUE; +} + +/// +/// Boolean validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator, wxPropertyFormValidator) + +bool wxBoolFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow)) +{ + // The item used for viewing the boolean: should be a checkbox + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox))) + return FALSE; + + return TRUE; +} + +bool wxBoolFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) +{ + // The item used for viewing the boolean: should be a checkbox. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox))) + return FALSE; + + wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow; + + property->GetValue() = (bool)checkBox->GetValue(); + return TRUE; +} + +bool wxBoolFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow)) +{ + // The item used for viewing the boolean: should be a checkbox. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox))) + return FALSE; + + wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow; + checkBox->SetValue((bool)property->GetValue().BoolValue()); + return TRUE; +} + +/// +/// String validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator, wxPropertyFormValidator) + +wxStringFormValidator::wxStringFormValidator(wxStringList *list, long flags): +wxPropertyFormValidator(flags) +{ + m_strings = list; +} + +bool wxStringFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *parentWindow ) +{ + if (!m_strings) + return TRUE; + + // The item used for viewing the string: should be a text item, choice item or listbox. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow) + return FALSE; + if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + { + wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; + if (!m_strings->Member(text->GetValue())) + { + wxString str( wxT("Value ") ); + str += text->GetValue(); + str += wxT(" is not valid."); + wxMessageBox(str, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + } + else + { + // Any other item constrains the string value, + // so we don't have to check it. + } + return TRUE; +} + +bool wxStringFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) +{ + // The item used for viewing the string: should be a text item, choice item or listbox. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow) + return FALSE; + if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + { + wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; + property->GetValue() = text->GetValue(); + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox))) + { + wxListBox *lbox = (wxListBox *)m_propertyWindow; + if (lbox->GetSelection() > -1) + property->GetValue() = lbox->GetStringSelection(); + } + /* + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox))) + { + wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow; + int n = 0; + if ((n = rbox->GetSelection()) > -1) + property->GetValue() = rbox->GetString(n); + } + */ + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice))) + { + wxChoice *choice = (wxChoice *)m_propertyWindow; + if (choice->GetSelection() > -1) + property->GetValue() = choice->GetStringSelection(); + } + else + return FALSE; + return TRUE; +} + +bool wxStringFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), + wxWindow *WXUNUSED(parentWindow) ) +{ + // The item used for viewing the string: should be a text item, choice item or listbox. + wxWindow *m_propertyWindow = property->GetWindow(); + if (!m_propertyWindow) + return FALSE; + if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) + { + wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; + text->SetValue(property->GetValue().StringValue()); + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox))) + { + wxListBox *lbox = (wxListBox *)m_propertyWindow; + if (lbox->GetCount() == 0 && m_strings) + { + // Try to initialize the listbox from 'strings' + wxStringList::Node *node = m_strings->GetFirst(); + while (node) + { + wxChar *s = node->GetData(); + lbox->Append(s); + node = node->GetNext(); + } + } + lbox->SetStringSelection(property->GetValue().StringValue()); + } + /* + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox))) + { + wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow; + rbox->SetStringSelection(property->GetValue().StringValue()); + } + */ + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice))) + { + wxChoice *choice = (wxChoice *)m_propertyWindow; + if (choice->GetCount() == 0 && m_strings) + { + // Try to initialize the choice item from 'strings' + // XView doesn't allow this kind of thing. + wxStringList::Node *node = m_strings->GetFirst(); + while (node) + { + wxChar *s = node->GetData(); + choice->Append(s); + node = node->GetNext(); + } + } + choice->SetStringSelection(property->GetValue().StringValue()); + } + else + return FALSE; + return TRUE; +} + +#endif // wxUSE_PROPSHEET diff --git a/contrib/src/deprecated/proplist.cpp b/contrib/src/deprecated/proplist.cpp new file mode 100644 index 0000000000..e8d5ae0fde --- /dev/null +++ b/contrib/src/deprecated/proplist.cpp @@ -0,0 +1,1838 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: proplist.cpp +// Purpose: Property list classes +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "proplist.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROPSHEET + +#ifndef WX_PRECOMP + #include "wx/window.h" + #include "wx/font.h" + #include "wx/button.h" + #include "wx/bmpbuttn.h" + #include "wx/textctrl.h" + #include "wx/listbox.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" + #include "wx/filedlg.h" +#endif + +#include "wx/sizer.h" +#include "wx/module.h" +#include "wx/intl.h" +#include "wx/artprov.h" + +#include "wx/colordlg.h" +#include "wx/deprecated/proplist.h" + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Property text edit control +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit, wxTextCtrl) + +wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent, + const wxWindowID id, const wxString& value, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name): + wxTextCtrl(parent, id, value, pos, size, style, wxDefaultValidator, name) +{ + m_view = v; +} + +void wxPropertyTextEdit::OnSetFocus() +{ +} + +void wxPropertyTextEdit::OnKillFocus() +{ +} + +// ---------------------------------------------------------------------------- +// Property list view +// ---------------------------------------------------------------------------- + +bool wxPropertyListView::sm_dialogCancelled = FALSE; + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView, wxPropertyView) + +BEGIN_EVENT_TABLE(wxPropertyListView, wxPropertyView) + EVT_BUTTON(wxID_OK, wxPropertyListView::OnOk) + EVT_BUTTON(wxID_CANCEL, wxPropertyListView::OnCancel) + EVT_BUTTON(wxID_HELP, wxPropertyListView::OnHelp) + EVT_BUTTON(wxID_PROP_CROSS, wxPropertyListView::OnCross) + EVT_BUTTON(wxID_PROP_CHECK, wxPropertyListView::OnCheck) + EVT_BUTTON(wxID_PROP_EDIT, wxPropertyListView::OnEdit) + EVT_TEXT_ENTER(wxID_PROP_TEXT, wxPropertyListView::OnText) + EVT_LISTBOX(wxID_PROP_SELECT, wxPropertyListView::OnPropertySelect) + EVT_COMMAND(wxID_PROP_SELECT, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, + wxPropertyListView::OnPropertyDoubleClick) + EVT_LISTBOX(wxID_PROP_VALUE_SELECT, wxPropertyListView::OnValueListSelect) +END_EVENT_TABLE() + +wxPropertyListView::wxPropertyListView(wxPanel *propPanel, long flags):wxPropertyView(flags) +{ + m_propertyScrollingList = NULL; + m_valueList = NULL; + m_valueText = NULL; + m_editButton = NULL; + m_confirmButton = NULL; + m_cancelButton = NULL; + m_propertyWindow = propPanel; + m_managedWindow = NULL; + + m_windowCloseButton = NULL; + m_windowCancelButton = NULL; + m_windowHelpButton = NULL; + + m_detailedEditing = FALSE; +} + +wxPropertyListView::~wxPropertyListView() +{ +} + +void wxPropertyListView::ShowView(wxPropertySheet *ps, wxPanel *panel) +{ + m_propertySheet = ps; + + AssociatePanel(panel); + CreateControls(); + + UpdatePropertyList(); + panel->Layout(); +} + +// Update this view of the viewed object, called e.g. by +// the object itself. +bool wxPropertyListView::OnUpdateView() +{ + return TRUE; +} + +bool wxPropertyListView::UpdatePropertyList(bool clearEditArea) +{ + if (!m_propertyScrollingList || !m_propertySheet) + return FALSE; + + m_propertyScrollingList->Clear(); + if (clearEditArea) + { + m_valueList->Clear(); + m_valueText->SetValue( wxT("") ); + } + wxNode *node = m_propertySheet->GetProperties().GetFirst(); + + // Should sort them... later... + while (node) + { + wxProperty *property = (wxProperty *)node->GetData(); + wxString stringValueRepr(property->GetValue().GetStringRepresentation()); + wxString paddedString(MakeNameValueString(property->GetName(), stringValueRepr)); + m_propertyScrollingList->Append(paddedString.GetData(), (void *)property); + node = node->GetNext(); + } + return TRUE; +} + +bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty *property) +{ + if (!m_propertyScrollingList || !m_propertySheet) + return FALSE; + +#ifdef __WXMSW__ + int currentlySelected = m_propertyScrollingList->GetSelection(); +#endif +// #ifdef __WXMSW__ + wxString stringValueRepr(property->GetValue().GetStringRepresentation()); + wxString paddedString(MakeNameValueString(property->GetName(), stringValueRepr)); + int sel = FindListIndexForProperty(property); + + if (sel > -1) + { + // Don't update the listbox unnecessarily because it can cause + // ugly flashing. + + if (paddedString != m_propertyScrollingList->GetString(sel)) + m_propertyScrollingList->SetString(sel, paddedString.GetData()); + } +//#else +// UpdatePropertyList(FALSE); +//#endif + + // TODO: why is this necessary? +#ifdef __WXMSW__ + if (currentlySelected > -1) + m_propertyScrollingList->SetSelection(currentlySelected); +#endif + + return TRUE; +} + +// Find the wxListBox index corresponding to this property +int wxPropertyListView::FindListIndexForProperty(wxProperty *property) +{ + int n = m_propertyScrollingList->GetCount(); + for (int i = 0; i < n; i++) + { + if (property == (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(i)) + return i; + } + return -1; +} + +wxString wxPropertyListView::MakeNameValueString(wxString name, wxString value) +{ + wxString theString(name); + + int nameWidth = 25; + int padWith = nameWidth - theString.Length(); + if (padWith < 0) + padWith = 0; + + if (GetFlags() & wxPROP_SHOWVALUES) + { + // Want to pad with spaces + theString.Append( wxT(' '), padWith); + theString += value; + } + + return theString; +} + +// Select and show string representation in validator the given +// property. NULL resets to show no property. +bool wxPropertyListView::ShowProperty(wxProperty *property, bool select) +{ + if (m_currentProperty) + { + EndShowingProperty(m_currentProperty); + m_currentProperty = NULL; + } + + m_valueList->Clear(); + m_valueText->SetValue( wxT("") ); + + if (property) + { + m_currentProperty = property; + BeginShowingProperty(property); + } + if (select) + { + int sel = FindListIndexForProperty(property); + if (sel > -1) + m_propertyScrollingList->SetSelection(sel); + } + return TRUE; +} + +// Find appropriate validator and load property into value controls +bool wxPropertyListView::BeginShowingProperty(wxProperty *property) +{ + m_currentValidator = FindPropertyValidator(property); + if (!m_currentValidator) + return FALSE; + + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return FALSE; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + listValidator->OnPrepareControls(property, this, m_propertyWindow); + DisplayProperty(property); + return TRUE; +} + +// Find appropriate validator and unload property from value controls +bool wxPropertyListView::EndShowingProperty(wxProperty *property) +{ + if (!m_currentValidator) + return FALSE; + + RetrieveProperty(property); + + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return FALSE; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + listValidator->OnClearControls(property, this, m_propertyWindow); + if (m_detailedEditing) + { + listValidator->OnClearDetailControls(property, this, m_propertyWindow); + m_detailedEditing = FALSE; + } + return TRUE; +} + +void wxPropertyListView::BeginDetailedEditing() +{ + if (!m_currentValidator) + return; + if (!m_currentProperty) + return; + if (m_detailedEditing) + return; + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return; + if (!m_currentProperty->IsEnabled()) + return; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + if (listValidator->OnPrepareDetailControls(m_currentProperty, this, m_propertyWindow)) + m_detailedEditing = TRUE; +} + +void wxPropertyListView::EndDetailedEditing() +{ + if (!m_currentValidator) + return; + if (!m_currentProperty) + return; + + RetrieveProperty(m_currentProperty); + + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + if (m_detailedEditing) + { + listValidator->OnClearDetailControls(m_currentProperty, this, m_propertyWindow); + m_detailedEditing = FALSE; + } +} + +bool wxPropertyListView::DisplayProperty(wxProperty *property) +{ + if (!m_currentValidator) + return FALSE; + + if (((m_currentValidator->GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == 0) || !property->IsEnabled()) + m_valueText->SetEditable(FALSE); + else + m_valueText->SetEditable(TRUE); + + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return FALSE; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + listValidator->OnDisplayValue(property, this, m_propertyWindow); + return TRUE; +} + +bool wxPropertyListView::RetrieveProperty(wxProperty *property) +{ + if (!m_currentValidator) + return FALSE; + if (!property->IsEnabled()) + return FALSE; + + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return FALSE; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + if (listValidator->OnCheckValue(property, this, m_propertyWindow)) + { + if (listValidator->OnRetrieveValue(property, this, m_propertyWindow)) + { + UpdatePropertyDisplayInList(property); + OnPropertyChanged(property); + } + } + else + { + // Revert to old value + listValidator->OnDisplayValue(property, this, m_propertyWindow); + } + return TRUE; +} + + +bool wxPropertyListView::EditProperty(wxProperty *WXUNUSED(property)) +{ + return TRUE; +} + +// Called by the listbox callback +void wxPropertyListView::OnPropertySelect(wxCommandEvent& WXUNUSED(event)) +{ + int sel = m_propertyScrollingList->GetSelection(); + if (sel > -1) + { + wxProperty *newSel = (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(sel); + if (newSel && newSel != m_currentProperty) + { + ShowProperty(newSel, FALSE); + } + } +} + +bool wxPropertyListView::CreateControls() +{ + wxPanel *panel = (wxPanel *)m_propertyWindow; + + wxSize largeButtonSize( 70, 25 ); + wxSize smallButtonSize( 23, 23 ); + + if (m_valueText) + return TRUE; + + if (!panel) + return FALSE; + + wxFont guiFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); + +#ifdef __WXMSW__ + wxFont *boringFont = + wxTheFontList->FindOrCreateFont(guiFont.GetPointSize(), wxMODERN, + wxNORMAL, wxNORMAL, FALSE, _T("Courier New")); +#else + wxFont *boringFont = wxTheFontList->FindOrCreateFont(guiFont.GetPointSize(), wxTELETYPE, wxNORMAL, wxNORMAL); +#endif + + // May need to be changed in future to eliminate clashes with app. + // WHAT WAS THIS FOR? +// panel->SetClientData((char *)this); + + wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); + + // top row with optional buttons and input line + + wxBoxSizer *topsizer = new wxBoxSizer( wxHORIZONTAL ); + int buttonborder = 3; + + if (m_buttonFlags & wxPROP_BUTTON_CHECK_CROSS) + { + wxBitmap tickBitmap = wxArtProvider::GetBitmap(wxART_TICK_MARK); + wxBitmap crossBitmap = wxArtProvider::GetBitmap(wxART_CROSS_MARK); + + if ( tickBitmap.Ok() && crossBitmap.Ok() ) + { + m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap, wxPoint(-1, -1), smallButtonSize ); + m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap, wxPoint(-1, -1), smallButtonSize ); + } + else + { + m_confirmButton = new wxButton(panel, wxID_PROP_CHECK, _T(":-)"), wxPoint(-1, -1), smallButtonSize ); + m_cancelButton = new wxButton(panel, wxID_PROP_CROSS, _T("X"), wxPoint(-1, -1), smallButtonSize ); + } + + topsizer->Add( m_confirmButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); + topsizer->Add( m_cancelButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); + } + + m_valueText = new wxPropertyTextEdit(this, panel, wxID_PROP_TEXT, _T(""), + wxPoint(-1, -1), wxSize(-1, smallButtonSize.y), wxPROCESS_ENTER); + m_valueText->Enable(FALSE); + topsizer->Add( m_valueText, 1, wxALL | wxEXPAND, buttonborder ); + + if (m_buttonFlags & wxPROP_PULLDOWN) + { + m_editButton = new wxButton(panel, wxID_PROP_EDIT, _T("..."), wxPoint(-1, -1), smallButtonSize); + m_editButton->Enable(FALSE); + topsizer->Add( m_editButton, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); + } + + mainsizer->Add( topsizer, 0, wxEXPAND ); + + // middle section with two list boxes + + m_middleSizer = new wxBoxSizer( wxVERTICAL ); + + m_valueList = new wxListBox(panel, wxID_PROP_VALUE_SELECT, wxPoint(-1, -1), wxSize(-1, 60)); + m_valueList->Show(FALSE); + + m_propertyScrollingList = new wxListBox(panel, wxID_PROP_SELECT, wxPoint(-1, -1), wxSize(100, 100)); + m_propertyScrollingList->SetFont(* boringFont); + m_middleSizer->Add( m_propertyScrollingList, 1, wxALL|wxEXPAND, buttonborder ); + + mainsizer->Add( m_middleSizer, 1, wxEXPAND ); + + // bottom row with buttons + + if ((m_buttonFlags & wxPROP_BUTTON_OK) || + (m_buttonFlags & wxPROP_BUTTON_CLOSE) || + (m_buttonFlags & wxPROP_BUTTON_CANCEL) || + (m_buttonFlags & wxPROP_BUTTON_HELP)) + { + wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); + buttonborder = 5; + + if (m_buttonFlags & wxPROP_BUTTON_OK) + { + m_windowCloseButton = new wxButton(panel, wxID_OK, _("OK"), wxPoint(-1, -1), largeButtonSize ); + m_windowCloseButton->SetDefault(); + m_windowCloseButton->SetFocus(); + bottomsizer->Add( m_windowCloseButton, 0, wxALL, buttonborder ); + } + else if (m_buttonFlags & wxPROP_BUTTON_CLOSE) + { + m_windowCloseButton = new wxButton(panel, wxID_OK, _("Close"), wxPoint(-1, -1), largeButtonSize ); + bottomsizer->Add( m_windowCloseButton, 0, wxALL, buttonborder ); + } + if (m_buttonFlags & wxPROP_BUTTON_CANCEL) + { + m_windowCancelButton = new wxButton(panel, wxID_CANCEL, _("Cancel"), wxPoint(-1, -1), largeButtonSize ); + bottomsizer->Add( m_windowCancelButton, 0, wxALL, buttonborder ); + } + if (m_buttonFlags & wxPROP_BUTTON_HELP) + { + m_windowHelpButton = new wxButton(panel, wxID_HELP, _("Help"), wxPoint(-1, -1), largeButtonSize ); + bottomsizer->Add( m_windowHelpButton, 0, wxALL, buttonborder ); + } + + mainsizer->Add( bottomsizer, 0, wxALIGN_RIGHT | wxEXPAND ); + } + + panel->SetSizer( mainsizer ); + + return TRUE; +} + +void wxPropertyListView::ShowTextControl(bool show) +{ + if (m_valueText) + m_valueText->Show(show); +} + +void wxPropertyListView::ShowListBoxControl(bool show) +{ + if (!m_valueList) return; + + m_valueList->Show(show); + + if (m_buttonFlags & wxPROP_DYNAMIC_VALUE_FIELD) + { + if (show) + m_middleSizer->Prepend( m_valueList, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 3 ); + else + m_middleSizer->Remove( 0 ); + + m_propertyWindow->Layout(); + } +} + +void wxPropertyListView::EnableCheck(bool show) +{ + if (m_confirmButton) + m_confirmButton->Enable(show); +} + +void wxPropertyListView::EnableCross(bool show) +{ + if (m_cancelButton) + m_cancelButton->Enable(show); +} + +bool wxPropertyListView::OnClose() +{ + // Retrieve the value if any + wxCommandEvent event; + OnCheck(event); + + delete this; + return TRUE; +} + +void wxPropertyListView::OnValueListSelect(wxCommandEvent& WXUNUSED(event)) +{ + if (m_currentProperty && m_currentValidator) + { + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + listValidator->OnValueListSelect(m_currentProperty, this, m_propertyWindow); + } +} + +void wxPropertyListView::OnOk(wxCommandEvent& event) +{ + // Retrieve the value if any + OnCheck(event); + + m_managedWindow->Close(TRUE); + sm_dialogCancelled = FALSE; +} + +void wxPropertyListView::OnCancel(wxCommandEvent& WXUNUSED(event)) +{ +// SetReturnCode(wxID_CANCEL); + m_managedWindow->Close(TRUE); + sm_dialogCancelled = TRUE; +} + +void wxPropertyListView::OnHelp(wxCommandEvent& WXUNUSED(event)) +{ +} + +void wxPropertyListView::OnCheck(wxCommandEvent& WXUNUSED(event)) +{ + if (m_currentProperty) + { + RetrieveProperty(m_currentProperty); + } +} + +void wxPropertyListView::OnCross(wxCommandEvent& WXUNUSED(event)) +{ + if (m_currentProperty && m_currentValidator) + { + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + // Revert to old value + listValidator->OnDisplayValue(m_currentProperty, this, m_propertyWindow); + } +} + +void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent& WXUNUSED(event)) +{ + if (m_currentProperty && m_currentValidator) + { + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + // Revert to old value + listValidator->OnDoubleClick(m_currentProperty, this, m_propertyWindow); + } +} + +void wxPropertyListView::OnEdit(wxCommandEvent& WXUNUSED(event)) +{ + if (m_currentProperty && m_currentValidator) + { + if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator))) + return; + + wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator; + + listValidator->OnEdit(m_currentProperty, this, m_propertyWindow); + } +} + +void wxPropertyListView::OnText(wxCommandEvent& event) +{ + if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) + { + OnCheck(event); + } +} + +// ---------------------------------------------------------------------------- +// Property dialog box +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog, wxDialog) + +BEGIN_EVENT_TABLE(wxPropertyListDialog, wxDialog) + EVT_BUTTON(wxID_CANCEL, wxPropertyListDialog::OnCancel) + EVT_CLOSE(wxPropertyListDialog::OnCloseWindow) +END_EVENT_TABLE() + +wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView *v, wxWindow *parent, + const wxString& title, const wxPoint& pos, + const wxSize& size, long style, const wxString& name): + wxDialog(parent, -1, title, pos, size, style, name) +{ + m_view = v; + m_view->AssociatePanel( ((wxPanel*)this) ); + m_view->SetManagedWindow(this); + SetAutoLayout(TRUE); +} + +void wxPropertyListDialog::OnCloseWindow(wxCloseEvent& event) +{ + if (m_view) + { + SetReturnCode(wxID_CANCEL); + m_view->OnClose(); + m_view = NULL; + this->Destroy(); + } + else + { + event.Veto(); + } +} + +void wxPropertyListDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) +{ + SetReturnCode(wxID_CANCEL); + this->Close(); +} + +void wxPropertyListDialog::OnDefaultAction(wxControl *WXUNUSED(item)) +{ +/* + if (item == m_view->GetPropertyScrollingList()) + view->OnDoubleClick(); +*/ +} + +// Extend event processing to search the view's event table +bool wxPropertyListDialog::ProcessEvent(wxEvent& event) +{ + if ( !m_view || ! m_view->ProcessEvent(event) ) + return wxEvtHandler::ProcessEvent(event); + else + return TRUE; +} + +// ---------------------------------------------------------------------------- +// Property panel +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel, wxPanel) + +BEGIN_EVENT_TABLE(wxPropertyListPanel, wxPanel) + EVT_SIZE(wxPropertyListPanel::OnSize) +END_EVENT_TABLE() + +wxPropertyListPanel::~wxPropertyListPanel() +{ +} + +void wxPropertyListPanel::OnDefaultAction(wxControl *WXUNUSED(item)) +{ +/* + if (item == view->GetPropertyScrollingList()) + view->OnDoubleClick(); +*/ +} + +// Extend event processing to search the view's event table +bool wxPropertyListPanel::ProcessEvent(wxEvent& event) +{ + if ( !m_view || ! m_view->ProcessEvent(event) ) + return wxEvtHandler::ProcessEvent(event); + else + return TRUE; +} + +void wxPropertyListPanel::OnSize(wxSizeEvent& WXUNUSED(event)) +{ + Layout(); +} + +// ---------------------------------------------------------------------------- +// Property frame +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame, wxFrame) + +BEGIN_EVENT_TABLE(wxPropertyListFrame, wxFrame) + EVT_CLOSE(wxPropertyListFrame::OnCloseWindow) +END_EVENT_TABLE() + +void wxPropertyListFrame::OnCloseWindow(wxCloseEvent& event) +{ + if (m_view) + { + if (m_propertyPanel) + m_propertyPanel->SetView(NULL); + m_view->OnClose(); + m_view = NULL; + this->Destroy(); + } + else + { + event.Veto(); + } +} + +wxPropertyListPanel *wxPropertyListFrame::OnCreatePanel(wxFrame *parent, wxPropertyListView *v) +{ + return new wxPropertyListPanel(v, parent); +} + +bool wxPropertyListFrame::Initialize() +{ + m_propertyPanel = OnCreatePanel(this, m_view); + if (m_propertyPanel) + { + m_view->AssociatePanel(m_propertyPanel); + m_view->SetManagedWindow(this); + m_propertyPanel->SetAutoLayout(TRUE); + return TRUE; + } + else + return FALSE; +} + +// ---------------------------------------------------------------------------- +// Property list specific validator +// ---------------------------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator, wxPropertyValidator) + +bool wxPropertyListValidator::OnSelect(bool select, wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +{ +// view->GetValueText()->Show(TRUE); + if (select) + OnDisplayValue(property, view, parentWindow); + + return TRUE; +} + +bool wxPropertyListValidator::OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + wxString s(view->GetValueList()->GetStringSelection()); + if (s != wxT("")) + { + view->GetValueText()->SetValue(s); + view->RetrieveProperty(property); + } + return TRUE; +} + +bool wxPropertyListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ +// view->GetValueText()->Show(TRUE); + wxString str(property->GetValue().GetStringRepresentation()); + + view->GetValueText()->SetValue(str); + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxPropertyListValidator::OnRetrieveValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + return FALSE; +} + +void wxPropertyListValidator::OnEdit(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetDetailedEditing()) + view->EndDetailedEditing(); + else + view->BeginDetailedEditing(); +} + +bool wxPropertyListValidator::OnClearControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(FALSE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(FALSE); + if (view->GetEditButton()) + view->GetEditButton()->Enable(FALSE); + return TRUE; +} + +// ---------------------------------------------------------------------------- +// Default validators +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator, wxPropertyListValidator) + +/// +/// Real number validator +/// +bool wxRealListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow) +{ + if (m_realMin == 0.0 && m_realMax == 0.0) + return TRUE; + + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + + float val = 0.0; + if (!StringToFloat(WXSTRINGCAST value, &val)) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value %s is not a valid real number!"), value.GetData()); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + + if (val < m_realMin || val > m_realMax) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin, m_realMax); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxRealListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + + if (wxStrlen(view->GetValueText()->GetValue()) == 0) + return FALSE; + + wxString value(view->GetValueText()->GetValue()); + float f = (float)wxAtof(value.GetData()); + property->GetValue() = f; + return TRUE; +} + +bool wxRealListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(TRUE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(TRUE); + if (view->GetEditButton()) + view->GetEditButton()->Enable(FALSE); + if (view->GetValueText()) + view->GetValueText()->Enable(TRUE); + return TRUE; +} + +/// +/// Integer validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator, wxPropertyListValidator) + +bool wxIntegerListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow) +{ + if (m_integerMin == 0 && m_integerMax == 0) + return TRUE; + + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + + long val = 0; + if (!StringToLong(WXSTRINGCAST value, &val)) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value %s is not a valid integer!"), value.GetData()); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + if (val < m_integerMin || val > m_integerMax) + { + wxChar buf[200]; + wxSprintf(buf, wxT("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxIntegerListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + + if (wxStrlen(view->GetValueText()->GetValue()) == 0) + return FALSE; + + wxString value(view->GetValueText()->GetValue()); + long val = (long)wxAtoi(value.GetData()); + property->GetValue() = (long)val; + return TRUE; +} + +bool wxIntegerListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(TRUE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(TRUE); + if (view->GetEditButton()) + view->GetEditButton()->Enable(FALSE); + if (view->GetValueText()) + view->GetValueText()->Enable(TRUE); + return TRUE; +} + +/// +/// boolean validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator, wxPropertyListValidator) + +bool wxBoolListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow) +{ + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + if (value != wxT("True") && value != wxT("False")) + { + wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxBoolListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + + if (wxStrlen(view->GetValueText()->GetValue()) == 0) + return FALSE; + + wxString value(view->GetValueText()->GetValue()); + bool boolValue = FALSE; + if (value == wxT("True")) + boolValue = TRUE; + else + boolValue = FALSE; + property->GetValue() = (bool)boolValue; + return TRUE; +} + +bool wxBoolListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString str(property->GetValue().GetStringRepresentation()); + + view->GetValueText()->SetValue(str); + + if (view->GetValueList()->IsShown()) + { + view->GetValueList()->SetStringSelection(str); + } + return TRUE; +} + +bool wxBoolListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(FALSE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(FALSE); + if (view->GetEditButton()) + view->GetEditButton()->Enable(TRUE); + if (view->GetValueText()) + view->GetValueText()->Enable(FALSE); + return TRUE; +} + +bool wxBoolListValidator::OnPrepareDetailControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetValueList()) + { + view->ShowListBoxControl(TRUE); + view->GetValueList()->Enable(TRUE); + + view->GetValueList()->Append(wxT("True")); + view->GetValueList()->Append(wxT("False")); + wxChar *currentString = copystring(view->GetValueText()->GetValue()); + view->GetValueList()->SetStringSelection(currentString); + delete[] currentString; + } + return TRUE; +} + +bool wxBoolListValidator::OnClearDetailControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetValueList()) + { + view->GetValueList()->Clear(); + view->ShowListBoxControl(FALSE); + view->GetValueList()->Enable(FALSE); + } + return TRUE; +} + +// Called when the property is double clicked. Extra functionality can be provided, +// cycling through possible values. +bool wxBoolListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + if (property->GetValue().BoolValue()) + property->GetValue() = (bool)FALSE; + else + property->GetValue() = (bool)TRUE; + view->DisplayProperty(property); + view->UpdatePropertyDisplayInList(property); + view->OnPropertyChanged(property); + return TRUE; +} + +/// +/// String validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator, wxPropertyListValidator) + +wxStringListValidator::wxStringListValidator(wxStringList *list, long flags): + wxPropertyListValidator(flags) +{ + m_strings = list; + // If no constraint, we just allow the string to be edited. + if (!m_strings && ((m_validatorFlags & wxPROP_ALLOW_TEXT_EDITING) == 0)) + m_validatorFlags |= wxPROP_ALLOW_TEXT_EDITING; +} + +bool wxStringListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow) +{ + if (!m_strings) + return TRUE; + + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + + if (!m_strings->Member(value.GetData())) + { + wxString str( wxT("Value ") ); + str += value.GetData(); + str += wxT(" is not valid."); + wxMessageBox( str.GetData(), wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + return FALSE; + } + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxStringListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + property->GetValue() = value ; + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxStringListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString str(property->GetValue().GetStringRepresentation()); + view->GetValueText()->SetValue(str); + if (m_strings && view->GetValueList() && view->GetValueList()->IsShown() && view->GetValueList()->GetCount() > 0) + { + view->GetValueList()->SetStringSelection(str); + } + return TRUE; +} + +bool wxStringListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + // Unconstrained + if (!m_strings) + { + if (view->GetEditButton()) + view->GetEditButton()->Enable(FALSE); + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(TRUE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(TRUE); + if (view->GetValueText()) + view->GetValueText()->Enable(TRUE); + return TRUE; + } + + // Constrained + if (view->GetValueText()) + view->GetValueText()->Enable(FALSE); + + if (view->GetEditButton()) + view->GetEditButton()->Enable(TRUE); + + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(FALSE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(FALSE); + return TRUE; +} + +bool wxStringListValidator::OnPrepareDetailControls( wxProperty *property, + wxPropertyListView *view, + wxWindow *WXUNUSED(parentWindow) ) +{ + if (view->GetValueList()) + { + view->ShowListBoxControl(TRUE); + view->GetValueList()->Enable(TRUE); + wxStringList::Node *node = m_strings->GetFirst(); + while (node) + { + wxChar *s = node->GetData(); + view->GetValueList()->Append(s); + node = node->GetNext(); + } + wxChar *currentString = property->GetValue().StringValue(); + view->GetValueList()->SetStringSelection(currentString); + } + return TRUE; +} + +bool wxStringListValidator::OnClearDetailControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!m_strings) + { + return TRUE; + } + + if (view->GetValueList()) + { + view->GetValueList()->Clear(); + view->ShowListBoxControl(FALSE); + view->GetValueList()->Enable(FALSE); + } + return TRUE; +} + +// Called when the property is double clicked. Extra functionality can be provided, +// cycling through possible values. +bool wxStringListValidator::OnDoubleClick( wxProperty *property, + wxPropertyListView *view, + wxWindow *WXUNUSED(parentWindow) ) +{ + if (!view->GetValueText()) + return FALSE; + if (!m_strings) + return FALSE; + + wxStringList::Node *node = m_strings->GetFirst(); + wxChar *currentString = property->GetValue().StringValue(); + while (node) + { + wxChar *s = node->GetData(); + if (wxStrcmp(s, currentString) == 0) + { + wxChar *nextString = NULL; + if (node->GetNext()) + nextString = node->GetNext()->GetData(); + else + nextString = m_strings->GetFirst()->GetData(); + property->GetValue() = wxString(nextString); + view->DisplayProperty(property); + view->UpdatePropertyDisplayInList(property); + view->OnPropertyChanged(property); + return TRUE; + } + else node = node->GetNext(); + } + return TRUE; +} + +/// +/// Filename validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator, wxPropertyListValidator) + +wxFilenameListValidator::wxFilenameListValidator(wxString message , wxString wildcard, long flags): + wxPropertyListValidator(flags), m_filenameWildCard(wildcard), m_filenameMessage(message) +{ +} + +wxFilenameListValidator::~wxFilenameListValidator() +{ +} + +bool wxFilenameListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow)) +{ + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxFilenameListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + property->GetValue() = value ; + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxFilenameListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString str(property->GetValue().GetStringRepresentation()); + view->GetValueText()->SetValue(str); + return TRUE; +} + +// Called when the property is double clicked. Extra functionality can be provided, +// cycling through possible values. +bool wxFilenameListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +{ + if (!view->GetValueText()) + return FALSE; + OnEdit(property, view, parentWindow); + return TRUE; +} + +bool wxFilenameListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(TRUE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(TRUE); + if (view->GetEditButton()) + view->GetEditButton()->Enable(TRUE); + if (view->GetValueText()) + view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING); + return TRUE; +} + +void wxFilenameListValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +{ + if (!view->GetValueText()) + return; + + wxString s = wxFileSelector( + m_filenameMessage.GetData(), + wxPathOnly(property->GetValue().StringValue()), + wxFileNameFromPath(property->GetValue().StringValue()), + NULL, + m_filenameWildCard.GetData(), + 0, + parentWindow); + if (s != wxT("")) + { + property->GetValue() = s; + view->DisplayProperty(property); + view->UpdatePropertyDisplayInList(property); + view->OnPropertyChanged(property); + } +} + +/// +/// Colour validator +/// +IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator, wxPropertyListValidator) + +wxColourListValidator::wxColourListValidator(long flags): + wxPropertyListValidator(flags) +{ +} + +wxColourListValidator::~wxColourListValidator() +{ +} + +bool wxColourListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow)) +{ + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxColourListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString value(view->GetValueText()->GetValue()); + + property->GetValue() = value ; + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself +bool wxColourListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString str(property->GetValue().GetStringRepresentation()); + view->GetValueText()->SetValue(str); + return TRUE; +} + +// Called when the property is double clicked. Extra functionality can be provided, +// cycling through possible values. +bool wxColourListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +{ + if (!view->GetValueText()) + return FALSE; + OnEdit(property, view, parentWindow); + return TRUE; +} + +bool wxColourListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(TRUE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(TRUE); + if (view->GetEditButton()) + view->GetEditButton()->Enable(TRUE); + if (view->GetValueText()) + view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING); + return TRUE; +} + +void wxColourListValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +{ + if (!view->GetValueText()) + return; + + wxChar *s = property->GetValue().StringValue(); + int r = 0; + int g = 0; + int b = 0; + if (s) + { + r = wxHexToDec(s); + g = wxHexToDec(s+2); + b = wxHexToDec(s+4); + } + + wxColour col(r,g,b); + + wxColourData data; + data.SetChooseFull(TRUE); + data.SetColour(col); + + for (int i = 0; i < 16; i++) + { + wxColour colour(i*16, i*16, i*16); + data.SetCustomColour(i, colour); + } + + wxColourDialog dialog(parentWindow, &data); + if (dialog.ShowModal() != wxID_CANCEL) + { + wxColourData retData = dialog.GetColourData(); + col = retData.GetColour(); + + wxChar buf[7]; + wxDecToHex(col.Red(), buf); + wxDecToHex(col.Green(), buf+2); + wxDecToHex(col.Blue(), buf+4); + + property->GetValue() = wxString(buf); + view->DisplayProperty(property); + view->UpdatePropertyDisplayInList(property); + view->OnPropertyChanged(property); + } +} + +/// +/// List of strings validator. For this we need more user interface than +/// we get with a property list; so create a new dialog for editing the list. +/// +IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator, wxPropertyListValidator) + +wxListOfStringsListValidator::wxListOfStringsListValidator(long flags): + wxPropertyListValidator(flags) +{ +} + +bool wxListOfStringsListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow)) +{ + // No constraints for an arbitrary, user-editable list of strings. + return TRUE; +} + +// Called when TICK is pressed or focus is lost or view wants to update +// the property list. +// Does the transferance from the property editing area to the property itself. +// In this case, the user cannot directly edit the string list. +bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow)) +{ + return TRUE; +} + +bool wxListOfStringsListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (!view->GetValueText()) + return FALSE; + wxString str(property->GetValue().GetStringRepresentation()); + view->GetValueText()->SetValue(str); + return TRUE; +} + +bool wxListOfStringsListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) +{ + if (view->GetEditButton()) + view->GetEditButton()->Enable(TRUE); + if (view->GetValueText()) + view->GetValueText()->Enable(FALSE); + + if (view->GetConfirmButton()) + view->GetConfirmButton()->Enable(FALSE); + if (view->GetCancelButton()) + view->GetCancelButton()->Enable(FALSE); + return TRUE; +} + +// Called when the property is double clicked. Extra functionality can be provided, +// cycling through possible values. +bool wxListOfStringsListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +{ + OnEdit(property, view, parentWindow); + return TRUE; +} + +void wxListOfStringsListValidator::OnEdit( wxProperty *property, + wxPropertyListView *view, + wxWindow *parentWindow ) +{ + // Convert property value to a list of strings for editing + wxStringList *stringList = new wxStringList; + + wxPropertyValue *expr = property->GetValue().GetFirst(); + while (expr) + { + wxChar *s = expr->StringValue(); + if (s) + stringList->Add(s); + expr = expr->GetNext(); + } + + wxString title(wxT("Editing ")); + title += property->GetName(); + + if (EditStringList(parentWindow, stringList, title.GetData())) + { + wxPropertyValue& oldValue = property->GetValue(); + oldValue.ClearList(); + wxStringList::Node *node = stringList->GetFirst(); + while (node) + { + wxChar *s = node->GetData(); + oldValue.Append(new wxPropertyValue(s)); + + node = node->GetNext(); + } + + view->DisplayProperty(property); + view->UpdatePropertyDisplayInList(property); + view->OnPropertyChanged(property); + } + delete stringList; +} + +class wxPropertyStringListEditorDialog: public wxDialog +{ + public: + wxPropertyStringListEditorDialog(wxWindow *parent, const wxString& title, + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + long windowStyle = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxT("stringEditorDialogBox")): + wxDialog(parent, -1, title, pos, size, windowStyle, name) + { + m_stringList = NULL; + m_stringText = NULL; + m_listBox = NULL; + sm_dialogCancelled = FALSE; + m_currentSelection = -1; + } + ~wxPropertyStringListEditorDialog(void) {} + void OnCloseWindow(wxCloseEvent& event); + void SaveCurrentSelection(void); + void ShowCurrentSelection(void); + + void OnOK(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + void OnAdd(wxCommandEvent& event); + void OnDelete(wxCommandEvent& event); + void OnStrings(wxCommandEvent& event); + void OnText(wxCommandEvent& event); + +public: + wxStringList* m_stringList; + wxListBox* m_listBox; + wxTextCtrl* m_stringText; + static bool sm_dialogCancelled; + int m_currentSelection; +DECLARE_EVENT_TABLE() +}; + +#define wxID_PROP_SL_ADD 3000 +#define wxID_PROP_SL_DELETE 3001 +#define wxID_PROP_SL_STRINGS 3002 +#define wxID_PROP_SL_TEXT 3003 + +BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog, wxDialog) + EVT_BUTTON(wxID_OK, wxPropertyStringListEditorDialog::OnOK) + EVT_BUTTON(wxID_CANCEL, wxPropertyStringListEditorDialog::OnCancel) + EVT_BUTTON(wxID_PROP_SL_ADD, wxPropertyStringListEditorDialog::OnAdd) + EVT_BUTTON(wxID_PROP_SL_DELETE, wxPropertyStringListEditorDialog::OnDelete) + EVT_LISTBOX(wxID_PROP_SL_STRINGS, wxPropertyStringListEditorDialog::OnStrings) + EVT_TEXT_ENTER(wxID_PROP_SL_TEXT, wxPropertyStringListEditorDialog::OnText) + EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow) +END_EVENT_TABLE() + +class wxPropertyStringListEditorText: public wxTextCtrl +{ + public: + wxPropertyStringListEditorText(wxWindow *parent, wxWindowID id, const wxString& val, + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + long windowStyle = 0, const wxString& name = wxT("text")): + wxTextCtrl(parent, id, val, pos, size, windowStyle, wxDefaultValidator, name) + { + } + void OnKillFocus() + { + wxPropertyStringListEditorDialog *dialog = (wxPropertyStringListEditorDialog *)GetParent(); + dialog->SaveCurrentSelection(); + } +}; + +bool wxPropertyStringListEditorDialog::sm_dialogCancelled = FALSE; + +// Edit the string list. +bool wxListOfStringsListValidator::EditStringList(wxWindow *parent, wxStringList *stringList, const wxChar *title) +{ + int largeButtonWidth = 60; + int largeButtonHeight = 25; + + wxBeginBusyCursor(); + wxPropertyStringListEditorDialog *dialog = new wxPropertyStringListEditorDialog(parent, + title, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL); + + dialog->m_stringList = stringList; + + dialog->m_listBox = new wxListBox(dialog, wxID_PROP_SL_STRINGS, + wxPoint(-1, -1), wxSize(-1, -1), 0, NULL, wxLB_SINGLE); + + dialog->m_stringText = new wxPropertyStringListEditorText(dialog, + wxID_PROP_SL_TEXT, wxT(""), wxPoint(5, 240), + wxSize(300, -1), wxPROCESS_ENTER); + dialog->m_stringText->Enable(FALSE); + + wxButton *addButton = new wxButton(dialog, wxID_PROP_SL_ADD, wxT("Add"), wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight)); + wxButton *deleteButton = new wxButton(dialog, wxID_PROP_SL_DELETE, wxT("Delete"), wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight)); + wxButton *cancelButton = new wxButton(dialog, wxID_CANCEL, wxT("Cancel"), wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight)); + wxButton *okButton = new wxButton(dialog, wxID_OK, wxT("OK"), wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight)); + +#ifndef __WXGTK__ + okButton->SetDefault(); +#endif + + wxLayoutConstraints *c = new wxLayoutConstraints; + + c->top.SameAs (dialog, wxTop, 2); + c->left.SameAs (dialog, wxLeft, 2); + c->right.SameAs (dialog, wxRight, 2); + c->bottom.SameAs (dialog->m_stringText, wxTop, 2); + dialog->m_listBox->SetConstraints(c); + + c = new wxLayoutConstraints; + c->left.SameAs (dialog, wxLeft, 2); + c->right.SameAs (dialog, wxRight, 2); + c->bottom.SameAs (addButton, wxTop, 2); + c->height.AsIs(); + dialog->m_stringText->SetConstraints(c); + + c = new wxLayoutConstraints; + c->bottom.SameAs (dialog, wxBottom, 2); + c->left.SameAs (dialog, wxLeft, 2); + c->width.AsIs(); + c->height.AsIs(); + addButton->SetConstraints(c); + + c = new wxLayoutConstraints; + c->bottom.SameAs (dialog, wxBottom, 2); + c->left.SameAs (addButton, wxRight, 2); + c->width.AsIs(); + c->height.AsIs(); + deleteButton->SetConstraints(c); + + c = new wxLayoutConstraints; + c->bottom.SameAs (dialog, wxBottom, 2); + c->right.SameAs (dialog, wxRight, 2); + c->width.AsIs(); + c->height.AsIs(); + cancelButton->SetConstraints(c); + + c = new wxLayoutConstraints; + c->bottom.SameAs (dialog, wxBottom, 2); + c->right.SameAs (cancelButton, wxLeft, 2); + c->width.AsIs(); + c->height.AsIs(); + okButton->SetConstraints(c); + + wxStringList::Node *node = stringList->GetFirst(); + while (node) + { + wxChar *str = node->GetData(); + // Save node as client data for each listbox item + dialog->m_listBox->Append(str, (wxChar *)node); + node = node->GetNext(); + } + + dialog->SetClientSize(310, 305); + dialog->Layout(); + + dialog->Centre(wxBOTH); + wxEndBusyCursor(); + if (dialog->ShowModal() == wxID_CANCEL) + return FALSE; + else + return TRUE; +} + +/* + * String list editor callbacks + * + */ + +void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent& WXUNUSED(event)) +{ + int sel = m_listBox->GetSelection(); + if (sel > -1) + { + m_currentSelection = sel; + + ShowCurrentSelection(); + } +} + +void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent& WXUNUSED(event)) +{ + int sel = m_listBox->GetSelection(); + if (sel == -1) + return; + + wxNode *node = (wxNode *)m_listBox->wxListBox::GetClientData(sel); + if (!node) + return; + + m_listBox->Delete(sel); + delete[] (wxChar *)node->GetData(); + delete node; + m_currentSelection = -1; + m_stringText->SetValue(_T("")); +} + +void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent& WXUNUSED(event)) +{ + SaveCurrentSelection(); + + wxString initialText; + wxNode *node = m_stringList->Add(initialText); + m_listBox->Append(initialText, (void *)node); + m_currentSelection = m_stringList->GetCount() - 1; + m_listBox->SetSelection(m_currentSelection); + ShowCurrentSelection(); + m_stringText->SetFocus(); +} + +void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent& WXUNUSED(event)) +{ + SaveCurrentSelection(); + EndModal(wxID_OK); + // Close(TRUE); + this->Destroy(); +} + +void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) +{ + sm_dialogCancelled = TRUE; + EndModal(wxID_CANCEL); +// Close(TRUE); + this->Destroy(); +} + +void wxPropertyStringListEditorDialog::OnText(wxCommandEvent& event) +{ + if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) + { + SaveCurrentSelection(); + } +} + +void +wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) +{ + SaveCurrentSelection(); + + Destroy(); +} + +void wxPropertyStringListEditorDialog::SaveCurrentSelection() +{ + if (m_currentSelection == -1) + return; + + wxNode *node = (wxNode *)m_listBox->wxListBox::GetClientData(m_currentSelection); + if (!node) + return; + + wxString txt(m_stringText->GetValue()); + if (node->GetData()) + delete[] (wxChar *)node->GetData(); + node->SetData((wxObject *)wxStrdup(txt)); + + m_listBox->SetString(m_currentSelection, (wxChar *)node->GetData()); +} + +void wxPropertyStringListEditorDialog::ShowCurrentSelection() +{ + if (m_currentSelection == -1) + { + m_stringText->SetValue(wxT("")); + return; + } + wxNode *node = (wxNode *)m_listBox->wxListBox::GetClientData(m_currentSelection); + wxChar *txt = (wxChar *)node->GetData(); + m_stringText->SetValue(txt); + m_stringText->Enable(TRUE); +} + + +#endif // wxUSE_PROPSHEET diff --git a/contrib/src/deprecated/resource.cpp b/contrib/src/deprecated/resource.cpp new file mode 100644 index 0000000000..f1c718063a --- /dev/null +++ b/contrib/src/deprecated/resource.cpp @@ -0,0 +1,3265 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: resource.cpp +// Purpose: Resource system +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "resource.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_WX_RESOURCES + +#ifdef __VISUALC__ +#pragma warning(disable:4706) // assignment within conditional expression +#endif // VC++ + +#ifndef WX_PRECOMP +#include "wx/defs.h" +#include "wx/setup.h" +#include "wx/list.h" +#include "wx/hash.h" +#include "wx/gdicmn.h" +#include "wx/utils.h" +#include "wx/types.h" +#include "wx/menu.h" +#include "wx/stattext.h" +#include "wx/button.h" +#include "wx/bmpbuttn.h" +#include "wx/radiobox.h" +#include "wx/listbox.h" +#include "wx/choice.h" +#include "wx/checkbox.h" +#include "wx/settings.h" +#include "wx/slider.h" +#include "wx/icon.h" +#include "wx/statbox.h" +#include "wx/statbmp.h" +#include "wx/gauge.h" +#include "wx/textctrl.h" +#include "wx/msgdlg.h" +#include "wx/intl.h" +#endif + +#include "wx/treebase.h" +#include "wx/listctrl.h" + +#if wxUSE_RADIOBTN +#include "wx/radiobut.h" +#endif + +#if wxUSE_SCROLLBAR +#include "wx/scrolbar.h" +#endif + +#if wxUSE_COMBOBOX +#include "wx/combobox.h" +#endif + +#include "wx/validate.h" + +#include "wx/log.h" + +#include +#include +#include +#include + +#include "wx/string.h" +#include "wx/settings.h" +#include "wx/stream.h" + +#include "wx/deprecated/resource.h" +#include "wx/deprecated/wxexpr.h" + +// Forward (private) declarations +bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db); +wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE); +wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr); +// Interpret list expression +wxFont wxResourceInterpretFontSpec(wxExpr *expr); + +bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL); +bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) ; +bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL); + +wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL; + +char *wxResourceBuffer = (char *) NULL; +long wxResourceBufferSize = 0; +long wxResourceBufferCount = 0; +int wxResourceStringPtr = 0; + +void wxInitializeResourceSystem() +{ + wxDefaultResourceTable = new wxResourceTable; +} + +void wxCleanUpResourceSystem() +{ + delete wxDefaultResourceTable; + if (wxResourceBuffer) + delete[] wxResourceBuffer; +} + +#if 0 +void wxLogWarning(char *msg) +{ + wxMessageBox(msg, _("Warning"), wxOK); +} +#endif + +IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable) + +wxItemResource::wxItemResource() +{ + m_itemType = wxT(""); + m_title = wxT(""); + m_name = wxT(""); + m_windowStyle = 0; + m_x = m_y = m_width = m_height = 0; + m_value1 = m_value2 = m_value3 = m_value5 = 0; + m_value4 = wxT(""); + m_windowId = 0; + m_exStyle = 0; +} + +wxItemResource::~wxItemResource() +{ + wxNode *node = m_children.First(); + while (node) + { + wxItemResource *item = (wxItemResource *)node->Data(); + delete item; + delete node; + node = m_children.First(); + } +} + +/* +* Resource table +*/ + +wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING) +{ +} + +wxResourceTable::~wxResourceTable() +{ + ClearTable(); +} + +wxItemResource *wxResourceTable::FindResource(const wxString& name) const +{ + wxItemResource *item = (wxItemResource *)Get(WXSTRINGCAST name); + return item; +} + +void wxResourceTable::AddResource(wxItemResource *item) +{ + wxString name = item->GetName(); + if (name == wxT("")) + name = item->GetTitle(); + if (name == wxT("")) + name = wxT("no name"); + + // Delete existing resource, if any. + Delete(name); + + Put(name, item); +} + +bool wxResourceTable::DeleteResource(const wxString& name) +{ + wxItemResource *item = (wxItemResource *)Delete(WXSTRINGCAST name); + if (item) + { + // See if any resource has this as its child; if so, delete from + // parent's child list. + BeginFind(); + wxNode *node = (wxNode *) NULL; + node = Next(); + while (node != NULL) + { + wxItemResource *parent = (wxItemResource *)node->Data(); + if (parent->GetChildren().Member(item)) + { + parent->GetChildren().DeleteObject(item); + break; + } + node = Next(); + } + + delete item; + return TRUE; + } + else + return FALSE; +} + +bool wxResourceTable::ParseResourceFile( wxInputStream *is ) +{ + wxExprDatabase db; + int len = is->GetSize() ; + + bool eof = FALSE; + while ( is->TellI() + 10 < len) // it's a hack because the streams dont support EOF + { + wxResourceReadOneResource(is, db, &eof, this) ; + } + return wxResourceInterpretResources(*this, db); +} + +bool wxResourceTable::ParseResourceFile(const wxString& filename) +{ + wxExprDatabase db; + + FILE *fd = wxFopen(filename, wxT("r")); + if (!fd) + return FALSE; + bool eof = FALSE; + while (wxResourceReadOneResource(fd, db, &eof, this) && !eof) + { + // Loop + } + fclose(fd); + return wxResourceInterpretResources(*this, db); +} + +bool wxResourceTable::ParseResourceData(const wxString& data) +{ + wxExprDatabase db; + if (!db.ReadFromString(data)) + { + wxLogWarning(_("Ill-formed resource file syntax.")); + return FALSE; + } + + return wxResourceInterpretResources(*this, db); +} + +bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height) +{ + // Register pre-loaded bitmap data + wxItemResource *item = new wxItemResource; + // item->SetType(wxRESOURCE_TYPE_XBM_DATA); + item->SetType(wxT("wxXBMData")); + item->SetName(name); + item->SetValue1((long)bits); + item->SetValue2((long)width); + item->SetValue3((long)height); + AddResource(item); + return TRUE; +} + +bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char **data) +{ + // Register pre-loaded bitmap data + wxItemResource *item = new wxItemResource; + // item->SetType(wxRESOURCE_TYPE_XPM_DATA); + item->SetType(wxT("wxXPMData")); + item->SetName(name); + item->SetValue1((long)data); + AddResource(item); + return TRUE; +} + +bool wxResourceTable::SaveResource(const wxString& WXUNUSED(filename)) +{ + return FALSE; +} + +void wxResourceTable::ClearTable() +{ + BeginFind(); + wxNode *node = Next(); + while (node) + { + wxNode *next = Next(); + wxItemResource *item = (wxItemResource *)node->Data(); + delete item; + delete node; + node = next; + } +} + +wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* childResource, const wxItemResource* parentResource) const +{ + int id = childResource->GetId(); + if ( id == 0 ) + id = -1; + + bool dlgUnits = ((parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0); + + wxControl *control = (wxControl *) NULL; + wxString itemType(childResource->GetType()); + + wxPoint pos; + wxSize size; + if (dlgUnits) + { + pos = parent->ConvertDialogToPixels(wxPoint(childResource->GetX(), childResource->GetY())); + size = parent->ConvertDialogToPixels(wxSize(childResource->GetWidth(), childResource->GetHeight())); + } + else + { + pos = wxPoint(childResource->GetX(), childResource->GetY()); + size = wxSize(childResource->GetWidth(), childResource->GetHeight()); + } + + if (itemType == wxString(wxT("wxButton")) || itemType == wxString(wxT("wxBitmapButton"))) + { + if (childResource->GetValue4() != wxT("")) + { + // Bitmap button + wxBitmap bitmap = childResource->GetBitmap(); + if (!bitmap.Ok()) + { + bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); + ((wxItemResource*) childResource)->SetBitmap(bitmap); + } + if (!bitmap.Ok()) +#if defined(__WXPM__) + // + // OS/2 uses integer id's to access resources, not file name strings + // + bitmap.LoadFile(wxCROSS_BITMAP, wxBITMAP_TYPE_BMP_RESOURCE); +#else + bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); +#endif + control = new wxBitmapButton(parent, id, bitmap, pos, size, + childResource->GetStyle() | wxBU_AUTODRAW, wxDefaultValidator, childResource->GetName()); + } + else + // Normal, text button + control = new wxButton(parent, id, childResource->GetTitle(), pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + } + else if (itemType == wxString(wxT("wxMessage")) || itemType == wxString(wxT("wxStaticText")) || + itemType == wxString(wxT("wxStaticBitmap"))) + { + if (childResource->GetValue4() != wxT("") || itemType == wxString(wxT("wxStaticBitmap")) ) + { + // Bitmap message + wxBitmap bitmap = childResource->GetBitmap(); + if (!bitmap.Ok()) + { + bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); + ((wxItemResource*) childResource)->SetBitmap(bitmap); + } +#if wxUSE_BITMAP_MESSAGE +#ifdef __WXMSW__ + // Use a default bitmap + if (!bitmap.Ok()) + bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); +#endif + + if (bitmap.Ok()) + control = new wxStaticBitmap(parent, id, bitmap, pos, size, + childResource->GetStyle(), childResource->GetName()); +#endif + } + else + { + control = new wxStaticText(parent, id, childResource->GetTitle(), pos, size, + childResource->GetStyle(), childResource->GetName()); + } + } + else if (itemType == wxString(wxT("wxText")) || itemType == wxString(wxT("wxTextCtrl")) || itemType == wxString(wxT("wxMultiText"))) + { + control = new wxTextCtrl(parent, id, childResource->GetValue4(), pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + } + else if (itemType == wxString(wxT("wxCheckBox"))) + { + control = new wxCheckBox(parent, id, childResource->GetTitle(), pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + + ((wxCheckBox *)control)->SetValue((childResource->GetValue1() != 0)); + } +#if wxUSE_GAUGE + else if (itemType == wxString(wxT("wxGauge"))) + { + control = new wxGauge(parent, id, (int)childResource->GetValue2(), pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + + ((wxGauge *)control)->SetValue((int)childResource->GetValue1()); + } +#endif +#if wxUSE_RADIOBTN + else if (itemType == wxString(wxT("wxRadioButton"))) + { + control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(), + pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + } +#endif +#if wxUSE_SCROLLBAR + else if (itemType == wxString(wxT("wxScrollBar"))) + { + control = new wxScrollBar(parent, id, pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + /* + ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1()); + ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2()); + ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3()); + ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5()); + */ + ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(), + (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),FALSE); + + } +#endif + else if (itemType == wxString(wxT("wxSlider"))) + { + control = new wxSlider(parent, id, (int)childResource->GetValue1(), + (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size, + childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + } + else if (itemType == wxString(wxT("wxGroupBox")) || itemType == wxString(wxT("wxStaticBox"))) + { + control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size, + childResource->GetStyle(), childResource->GetName()); + } + else if (itemType == wxString(wxT("wxListBox"))) + { + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; + int noStrings = 0; + if (stringList.Number() > 0) + { + noStrings = stringList.Number(); + strings = new wxString[noStrings]; + wxNode *node = stringList.First(); + int i = 0; + while (node) + { + strings[i] = (wxChar *)node->Data(); + i ++; + node = node->Next(); + } + } + control = new wxListBox(parent, id, pos, size, + noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + + if (strings) + delete[] strings; + } + else if (itemType == wxString(wxT("wxChoice"))) + { + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; + int noStrings = 0; + if (stringList.Number() > 0) + { + noStrings = stringList.Number(); + strings = new wxString[noStrings]; + wxNode *node = stringList.First(); + int i = 0; + while (node) + { + strings[i] = (wxChar *)node->Data(); + i ++; + node = node->Next(); + } + } + control = new wxChoice(parent, id, pos, size, + noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + + if (strings) + delete[] strings; + } +#if wxUSE_COMBOBOX + else if (itemType == wxString(wxT("wxComboBox"))) + { + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; + int noStrings = 0; + if (stringList.Number() > 0) + { + noStrings = stringList.Number(); + strings = new wxString[noStrings]; + wxNode *node = stringList.First(); + int i = 0; + while (node) + { + strings[i] = (wxChar *)node->Data(); + i ++; + node = node->Next(); + } + } + control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size, + noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); + + if (strings) + delete[] strings; + } +#endif + else if (itemType == wxString(wxT("wxRadioBox"))) + { + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; + int noStrings = 0; + if (stringList.Number() > 0) + { + noStrings = stringList.Number(); + strings = new wxString[noStrings]; + wxNode *node = stringList.First(); + int i = 0; + while (node) + { + strings[i] = (wxChar *)node->Data(); + i ++; + node = node->Next(); + } + } + control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size, + noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator, + childResource->GetName()); + + if (strings) + delete[] strings; + } + + if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) + { + // Don't set font; will be inherited from parent. + } + else + { + if (control && childResource->GetFont().Ok()) + { + control->SetFont(childResource->GetFont()); + +#ifdef __WXMSW__ + // Force the layout algorithm since the size changes the layout + if (control->IsKindOf(CLASSINFO(wxRadioBox))) + { + control->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT); + } +#endif + } + } + return control; +} + +/* +* Interpret database as a series of resources +*/ + +bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db) +{ + wxNode *node = db.First(); + while (node) + { + wxExpr *clause = (wxExpr *)node->Data(); + wxString functor(clause->Functor()); + + wxItemResource *item = (wxItemResource *) NULL; + if (functor == wxT("dialog")) + item = wxResourceInterpretDialog(table, clause); + else if (functor == wxT("panel")) + item = wxResourceInterpretDialog(table, clause, TRUE); + else if (functor == wxT("menubar")) + item = wxResourceInterpretMenuBar(table, clause); + else if (functor == wxT("menu")) + item = wxResourceInterpretMenu(table, clause); + else if (functor == wxT("string")) + item = wxResourceInterpretString(table, clause); + else if (functor == wxT("bitmap")) + item = wxResourceInterpretBitmap(table, clause); + else if (functor == wxT("icon")) + item = wxResourceInterpretIcon(table, clause); + + if (item) + { + // Remove any existing resource of same name + if (item->GetName() != wxT("")) + table.DeleteResource(item->GetName()); + table.AddResource(item); + } + node = node->Next(); + } + return TRUE; +} + +static const wxChar *g_ValidControlClasses[] = +{ + wxT("wxButton"), + wxT("wxBitmapButton"), + wxT("wxMessage"), + wxT("wxStaticText"), + wxT("wxStaticBitmap"), + wxT("wxText"), + wxT("wxTextCtrl"), + wxT("wxMultiText"), + wxT("wxListBox"), + wxT("wxRadioBox"), + wxT("wxRadioButton"), + wxT("wxCheckBox"), + wxT("wxBitmapCheckBox"), + wxT("wxGroupBox"), + wxT("wxStaticBox"), + wxT("wxSlider"), + wxT("wxGauge"), + wxT("wxScrollBar"), + wxT("wxChoice"), + wxT("wxComboBox") +}; + +static bool wxIsValidControlClass(const wxString& c) +{ + for ( size_t i = 0; i < WXSIZEOF(g_ValidControlClasses); i++ ) + { + if ( c == g_ValidControlClasses[i] ) + return TRUE; + } + return FALSE; +} + +wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel) +{ + wxItemResource *dialogItem = new wxItemResource; + if (isPanel) + dialogItem->SetType(wxT("wxPanel")); + else + dialogItem->SetType(wxT("wxDialog")); + wxString style = wxT(""); + wxString title = wxT(""); + wxString name = wxT(""); + wxString backColourHex = wxT(""); + wxString labelColourHex = wxT(""); + wxString buttonColourHex = wxT(""); + + long windowStyle = wxDEFAULT_DIALOG_STYLE; + if (isPanel) + windowStyle = 0; + + int x = 0; int y = 0; int width = -1; int height = -1; + int isModal = 0; + wxExpr *labelFontExpr = (wxExpr *) NULL; + wxExpr *buttonFontExpr = (wxExpr *) NULL; + wxExpr *fontExpr = (wxExpr *) NULL; + expr->GetAttributeValue(wxT("style"), style); + expr->GetAttributeValue(wxT("name"), name); + expr->GetAttributeValue(wxT("title"), title); + expr->GetAttributeValue(wxT("x"), x); + expr->GetAttributeValue(wxT("y"), y); + expr->GetAttributeValue(wxT("width"), width); + expr->GetAttributeValue(wxT("height"), height); + expr->GetAttributeValue(wxT("modal"), isModal); + expr->GetAttributeValue(wxT("label_font"), &labelFontExpr); + expr->GetAttributeValue(wxT("button_font"), &buttonFontExpr); + expr->GetAttributeValue(wxT("font"), &fontExpr); + expr->GetAttributeValue(wxT("background_colour"), backColourHex); + expr->GetAttributeValue(wxT("label_colour"), labelColourHex); + expr->GetAttributeValue(wxT("button_colour"), buttonColourHex); + + int useDialogUnits = 0; + expr->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits); + if (useDialogUnits != 0) + dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS); + + int useDefaults = 0; + expr->GetAttributeValue(wxT("use_system_defaults"), useDefaults); + if (useDefaults != 0) + dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS); + + int id = 0; + expr->GetAttributeValue(wxT("id"), id); + dialogItem->SetId(id); + + if (style != wxT("")) + { + windowStyle = wxParseWindowStyle(style); + } + dialogItem->SetStyle(windowStyle); + dialogItem->SetValue1(isModal); + if (windowStyle & wxDIALOG_MODAL) // Uses style in wxWin 2 + dialogItem->SetValue1(TRUE); + + dialogItem->SetName(name); + dialogItem->SetTitle(title); + dialogItem->SetSize(x, y, width, height); + + // Check for wxWin 1.68-style specifications + if (style.Find(wxT("VERTICAL_LABEL")) != -1) + dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); + else if (style.Find(wxT("HORIZONTAL_LABEL")) != -1) + dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); + + if (backColourHex != wxT("")) + { + int r = 0; + int g = 0; + int b = 0; + r = wxHexToDec(backColourHex.Mid(0, 2)); + g = wxHexToDec(backColourHex.Mid(2, 2)); + b = wxHexToDec(backColourHex.Mid(4, 2)); + dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); + } + if (labelColourHex != wxT("")) + { + int r = 0; + int g = 0; + int b = 0; + r = wxHexToDec(labelColourHex.Mid(0, 2)); + g = wxHexToDec(labelColourHex.Mid(2, 2)); + b = wxHexToDec(labelColourHex.Mid(4, 2)); + dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); + } + if (buttonColourHex != wxT("")) + { + int r = 0; + int g = 0; + int b = 0; + r = wxHexToDec(buttonColourHex.Mid(0, 2)); + g = wxHexToDec(buttonColourHex.Mid(2, 2)); + b = wxHexToDec(buttonColourHex.Mid(4, 2)); + dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); + } + + if (fontExpr) + dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr)); + else if (buttonFontExpr) + dialogItem->SetFont(wxResourceInterpretFontSpec(buttonFontExpr)); + else if (labelFontExpr) + dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr)); + + // Now parse all controls + wxExpr *controlExpr = expr->GetFirst(); + while (controlExpr) + { + if (controlExpr->Number() == 3) + { + wxString controlKeyword(controlExpr->Nth(1)->StringValue()); + if (controlKeyword != wxT("") && controlKeyword == wxT("control")) + { + // The value part: always a list. + wxExpr *listExpr = controlExpr->Nth(2); + if (listExpr->Type() == PrologList) + { + wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr); + if (controlItem) + { + dialogItem->GetChildren().Append(controlItem); + } + } + } + } + controlExpr = controlExpr->GetNext(); + } + return dialogItem; +} + +wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr) +{ + wxItemResource *controlItem = new wxItemResource; + + // First, find the standard features of a control definition: + // [optional integer/string id], control name, title, style, name, x, y, width, height + + wxString controlType; + wxString style; + wxString title; + wxString name; + int id = 0; + long windowStyle = 0; + int x = 0; int y = 0; int width = -1; int height = -1; + int count = 0; + + wxExpr *expr1 = expr->Nth(0); + + if ( expr1->Type() == PrologString || expr1->Type() == PrologWord ) + { + if ( wxIsValidControlClass(expr1->StringValue()) ) + { + count = 1; + controlType = expr1->StringValue(); + } + else + { + wxString str(expr1->StringValue()); + id = wxResourceGetIdentifier(str, &table); + if (id == 0) + { + wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"), + (const wxChar*) expr1->StringValue()); + delete controlItem; + return (wxItemResource *) NULL; + } + else + { + // Success - we have an id, so the 2nd element must be the control class. + controlType = expr->Nth(1)->StringValue(); + count = 2; + } + } + } + else if (expr1->Type() == PrologInteger) + { + id = (int)expr1->IntegerValue(); + // Success - we have an id, so the 2nd element must be the control class. + controlType = expr->Nth(1)->StringValue(); + count = 2; + } + + expr1 = expr->Nth(count); + count ++; + if ( expr1 ) + title = expr1->StringValue(); + + expr1 = expr->Nth(count); + count ++; + if (expr1) + { + style = expr1->StringValue(); + windowStyle = wxParseWindowStyle(style); + } + + expr1 = expr->Nth(count); + count ++; + if (expr1) + name = expr1->StringValue(); + + expr1 = expr->Nth(count); + count ++; + if (expr1) + x = (int)expr1->IntegerValue(); + + expr1 = expr->Nth(count); + count ++; + if (expr1) + y = (int)expr1->IntegerValue(); + + expr1 = expr->Nth(count); + count ++; + if (expr1) + width = (int)expr1->IntegerValue(); + + expr1 = expr->Nth(count); + count ++; + if (expr1) + height = (int)expr1->IntegerValue(); + + controlItem->SetStyle(windowStyle); + controlItem->SetName(name); + controlItem->SetTitle(title); + controlItem->SetSize(x, y, width, height); + controlItem->SetType(controlType); + controlItem->SetId(id); + + // Check for wxWin 1.68-style specifications + if (style.Find(wxT("VERTICAL_LABEL")) != -1) + controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); + else if (style.Find(wxT("HORIZONTAL_LABEL")) != -1) + controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); + + if (controlType == wxT("wxButton")) + { + // Check for bitmap resource name (in case loading old-style resource file) + if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) + { + wxString str(expr->Nth(count)->StringValue()); + count ++; + + if (str != wxT("")) + { + controlItem->SetValue4(str); + controlItem->SetType(wxT("wxBitmapButton")); + } + } + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + else if (controlType == wxT("wxBitmapButton")) + { + // Check for bitmap resource name + if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) + { + wxString str(expr->Nth(count)->StringValue()); + controlItem->SetValue4(str); + count ++; + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + else if (controlType == wxT("wxCheckBox")) + { + // Check for default value + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue1(expr->Nth(count)->IntegerValue()); + count ++; + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } +#if wxUSE_RADIOBTN + else if (controlType == wxT("wxRadioButton")) + { + // Check for default value + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue1(expr->Nth(count)->IntegerValue()); + count ++; + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } +#endif + else if (controlType == wxT("wxText") || controlType == wxT("wxTextCtrl") || controlType == wxT("wxMultiText")) + { + // Check for default value + if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) + { + wxString str(expr->Nth(count)->StringValue()); + controlItem->SetValue4(str); + count ++; + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); + // Skip past the obsolete label font spec if there are two consecutive specs + if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) + count ++; + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } + else if (controlType == wxT("wxMessage") || controlType == wxT("wxStaticText")) + { + // Check for bitmap resource name (in case it's an old-style .wxr file) + if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) + { + wxString str(expr->Nth(count)->StringValue()); + controlItem->SetValue4(str); + count ++; + controlItem->SetType(wxT("wxStaticText")); + } + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + else if (controlType == wxT("wxStaticBitmap")) + { + // Check for bitmap resource name + if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) + { + wxString str(expr->Nth(count)->StringValue()); + controlItem->SetValue4(str); + count ++; + } + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + else if (controlType == wxT("wxGroupBox") || controlType == wxT("wxStaticBox")) + { + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + else if (controlType == wxT("wxGauge")) + { + // Check for default value + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue1(expr->Nth(count)->IntegerValue()); + count ++; + + // Check for range + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue2(expr->Nth(count)->IntegerValue()); + count ++; + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // Skip past the obsolete label font spec if there are two consecutive specs + if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) + count ++; + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } + } + else if (controlType == wxT("wxSlider")) + { + // Check for default value + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue1(expr->Nth(count)->IntegerValue()); + count ++; + + // Check for min + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue2(expr->Nth(count)->IntegerValue()); + count ++; + + // Check for max + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue3(expr->Nth(count)->IntegerValue()); + count ++; + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); + // do nothing + count ++; + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } + } + } + else if (controlType == wxT("wxScrollBar")) + { + // DEFAULT VALUE + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue1(expr->Nth(count)->IntegerValue()); + count ++; + + // PAGE LENGTH + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue2(expr->Nth(count)->IntegerValue()); + count ++; + + // OBJECT LENGTH + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue3(expr->Nth(count)->IntegerValue()); + count ++; + + // VIEW LENGTH + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + controlItem->SetValue5(expr->Nth(count)->IntegerValue()); + } + } + } + } + else if (controlType == wxT("wxListBox")) + { + wxExpr *valueList = (wxExpr *) NULL; + + if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) + { + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); + while (stringExpr) + { + stringList.Add(stringExpr->StringValue()); + stringExpr = stringExpr->GetNext(); + } + controlItem->SetStringValues(stringList); + count ++; + // This is now obsolete: it's in the window style. + // Check for wxSINGLE/wxMULTIPLE + wxExpr *mult = (wxExpr *) NULL; + /* + controlItem->SetValue1(wxLB_SINGLE); + */ + if (((mult = expr->Nth(count)) != 0) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord))) + { + /* + wxString m(mult->StringValue()); + if (m == "wxLB_MULTIPLE") + controlItem->SetValue1(wxLB_MULTIPLE); + else if (m == "wxLB_EXTENDED") + controlItem->SetValue1(wxLB_EXTENDED); + */ + // Ignore the value + count ++; + } + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // Skip past the obsolete label font spec if there are two consecutive specs + if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) + count ++; + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } + else if (controlType == wxT("wxChoice")) + { + wxExpr *valueList = (wxExpr *) NULL; + // Check for default value list + if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) + { + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); + while (stringExpr) + { + stringList.Add(stringExpr->StringValue()); + stringExpr = stringExpr->GetNext(); + } + controlItem->SetStringValues(stringList); + + count ++; + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // Skip past the obsolete label font spec if there are two consecutive specs + if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) + count ++; + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } +#if wxUSE_COMBOBOX + else if (controlType == wxT("wxComboBox")) + { + wxExpr *textValue = expr->Nth(count); + if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord)) + { + wxString str(textValue->StringValue()); + controlItem->SetValue4(str); + + count ++; + + wxExpr *valueList = (wxExpr *) NULL; + // Check for default value list + if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) + { + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); + while (stringExpr) + { + stringList.Add(stringExpr->StringValue()); + stringExpr = stringExpr->GetNext(); + } + controlItem->SetStringValues(stringList); + + count ++; + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // Skip past the obsolete label font spec if there are two consecutive specs + if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) + count ++; + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } + } +#endif +#if 1 + else if (controlType == wxT("wxRadioBox")) + { + wxExpr *valueList = (wxExpr *) NULL; + // Check for default value list + if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) + { + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); + while (stringExpr) + { + stringList.Add(stringExpr->StringValue()); + stringExpr = stringExpr->GetNext(); + } + controlItem->SetStringValues(stringList); + count ++; + + // majorDim (number of rows or cols) + if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) + { + controlItem->SetValue1(expr->Nth(count)->IntegerValue()); + count ++; + } + else + controlItem->SetValue1(0); + + if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) + { + // Skip past the obsolete label font spec if there are two consecutive specs + if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) + count ++; + controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); + } + } + } +#endif + else + { + delete controlItem; + return (wxItemResource *) NULL; + } + return controlItem; +} + +// Forward declaration +wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr); + +/* +* Interpet a menu item +*/ + +wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr) +{ + wxItemResource *item = new wxItemResource; + + wxExpr *labelExpr = expr->Nth(0); + wxExpr *idExpr = expr->Nth(1); + wxExpr *helpExpr = expr->Nth(2); + wxExpr *checkableExpr = expr->Nth(3); + + // Further keywords/attributes to follow sometime... + if (expr->Number() == 0) + { + // item->SetType(wxRESOURCE_TYPE_SEPARATOR); + item->SetType(wxT("wxMenuSeparator")); + return item; + } + else + { + // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter. + item->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter. + if (labelExpr) + { + wxString str(labelExpr->StringValue()); + item->SetTitle(str); + } + if (idExpr) + { + int id = 0; + // If a string or word, must look up in identifier table. + if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord)) + { + wxString str(idExpr->StringValue()); + id = wxResourceGetIdentifier(str, &table); + if (id == 0) + { + wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"), + (const wxChar*) idExpr->StringValue()); + } + } + else if (idExpr->Type() == PrologInteger) + id = (int)idExpr->IntegerValue(); + item->SetValue1(id); + } + if (helpExpr) + { + wxString str(helpExpr->StringValue()); + item->SetValue4(str); + } + if (checkableExpr) + item->SetValue2(checkableExpr->IntegerValue()); + + // Find the first expression that's a list, for submenu + wxExpr *subMenuExpr = expr->GetFirst(); + while (subMenuExpr && (subMenuExpr->Type() != PrologList)) + subMenuExpr = subMenuExpr->GetNext(); + + while (subMenuExpr) + { + wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr); + item->GetChildren().Append(child); + subMenuExpr = subMenuExpr->GetNext(); + } + } + return item; +} + +/* +* Interpret a nested list as a menu +*/ +/* +wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr) +{ +wxItemResource *menu = new wxItemResource; +// menu->SetType(wxTYPE_MENU); +menu->SetType("wxMenu"); +wxExpr *element = expr->GetFirst(); +while (element) +{ +wxItemResource *item = wxResourceInterpretMenuItem(table, element); +if (item) +menu->GetChildren().Append(item); +element = element->GetNext(); +} +return menu; +} +*/ + +wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr) +{ + wxExpr *listExpr = (wxExpr *) NULL; + expr->GetAttributeValue(wxT("menu"), &listExpr); + if (!listExpr) + return (wxItemResource *) NULL; + + wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); + + if (!menuResource) + return (wxItemResource *) NULL; + + wxString name; + if (expr->GetAttributeValue(wxT("name"), name)) + { + menuResource->SetName(name); + } + + return menuResource; +} + +wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr) +{ + wxExpr *listExpr = (wxExpr *) NULL; + expr->GetAttributeValue(wxT("menu"), &listExpr); + if (!listExpr) + return (wxItemResource *) NULL; + + wxItemResource *resource = new wxItemResource; + resource->SetType(wxT("wxMenu")); + // resource->SetType(wxTYPE_MENU); + + wxExpr *element = listExpr->GetFirst(); + while (element) + { + wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); + resource->GetChildren().Append(menuResource); + element = element->GetNext(); + } + + wxString name; + if (expr->GetAttributeValue(wxT("name"), name)) + { + resource->SetName(name); + } + + return resource; +} + +wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr)) +{ + return (wxItemResource *) NULL; +} + +wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr) +{ + wxItemResource *bitmapItem = new wxItemResource; + // bitmapItem->SetType(wxTYPE_BITMAP); + bitmapItem->SetType(wxT("wxBitmap")); + wxString name; + if (expr->GetAttributeValue(wxT("name"), name)) + { + bitmapItem->SetName(name); + } + // Now parse all bitmap specifications + wxExpr *bitmapExpr = expr->GetFirst(); + while (bitmapExpr) + { + if (bitmapExpr->Number() == 3) + { + wxString bitmapKeyword(bitmapExpr->Nth(1)->StringValue()); + if (bitmapKeyword == wxT("bitmap") || bitmapKeyword == wxT("icon")) + { + // The value part: always a list. + wxExpr *listExpr = bitmapExpr->Nth(2); + if (listExpr->Type() == PrologList) + { + wxItemResource *bitmapSpec = new wxItemResource; + // bitmapSpec->SetType(wxTYPE_BITMAP); + bitmapSpec->SetType(wxT("wxBitmap")); + + // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution] + // where everything after 'filename' is optional. + wxExpr *nameExpr = listExpr->Nth(0); + wxExpr *typeExpr = listExpr->Nth(1); + wxExpr *platformExpr = listExpr->Nth(2); + wxExpr *coloursExpr = listExpr->Nth(3); + wxExpr *xresExpr = listExpr->Nth(4); + wxExpr *yresExpr = listExpr->Nth(5); + if (nameExpr && nameExpr->StringValue() != wxT("")) + { + bitmapSpec->SetName(nameExpr->StringValue()); + } + if (typeExpr && typeExpr->StringValue() != wxT("")) + { + bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue())); + } + else + bitmapSpec->SetValue1(0); + + if (platformExpr && platformExpr->StringValue() != wxT("")) + { + wxString plat(platformExpr->StringValue()); + if (plat == wxT("windows") || plat == wxT("WINDOWS")) + bitmapSpec->SetValue2(RESOURCE_PLATFORM_WINDOWS); + else if (plat == wxT("x") || plat == wxT("X")) + bitmapSpec->SetValue2(RESOURCE_PLATFORM_X); + else if (plat == wxT("mac") || plat == wxT("MAC")) + bitmapSpec->SetValue2(RESOURCE_PLATFORM_MAC); + else + bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY); + } + else + bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY); + + if (coloursExpr) + bitmapSpec->SetValue3(coloursExpr->IntegerValue()); + int xres = 0; + int yres = 0; + if (xresExpr) + xres = (int)xresExpr->IntegerValue(); + if (yresExpr) + yres = (int)yresExpr->IntegerValue(); + bitmapSpec->SetSize(0, 0, xres, yres); + + bitmapItem->GetChildren().Append(bitmapSpec); + } + } + } + bitmapExpr = bitmapExpr->GetNext(); + } + + return bitmapItem; +} + +wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr) +{ + wxItemResource *item = wxResourceInterpretBitmap(table, expr); + if (item) + { + // item->SetType(wxTYPE_ICON); + item->SetType(wxT("wxIcon")); + return item; + } + else + return (wxItemResource *) NULL; +} + +// Interpret list expression as a font +wxFont wxResourceInterpretFontSpec(wxExpr *expr) +{ + if (expr->Type() != PrologList) + return wxNullFont; + + int point = 10; + int family = wxSWISS; + int style = wxNORMAL; + int weight = wxNORMAL; + int underline = 0; + wxString faceName(wxT("")); + + wxExpr *pointExpr = expr->Nth(0); + wxExpr *familyExpr = expr->Nth(1); + wxExpr *styleExpr = expr->Nth(2); + wxExpr *weightExpr = expr->Nth(3); + wxExpr *underlineExpr = expr->Nth(4); + wxExpr *faceNameExpr = expr->Nth(5); + if (pointExpr) + point = (int)pointExpr->IntegerValue(); + + wxString str; + if (familyExpr) + { + str = familyExpr->StringValue(); + family = (int)wxParseWindowStyle(str); + } + if (styleExpr) + { + str = styleExpr->StringValue(); + style = (int)wxParseWindowStyle(str); + } + if (weightExpr) + { + str = weightExpr->StringValue(); + weight = (int)wxParseWindowStyle(str); + } + if (underlineExpr) + underline = (int)underlineExpr->IntegerValue(); + if (faceNameExpr) + faceName = faceNameExpr->StringValue(); + + return *wxTheFontList->FindOrCreateFont(point, family, style, weight, + (underline != 0), faceName); +} + +// Separate file for the remainder of this, for BC++/Win16 + +#if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__)) +/* +* (Re)allocate buffer for reading in from resource file +*/ + +bool wxReallocateResourceBuffer() +{ + if (!wxResourceBuffer) + { + wxResourceBufferSize = 1000; + wxResourceBuffer = new char[wxResourceBufferSize]; + return TRUE; + } + if (wxResourceBuffer) + { + long newSize = wxResourceBufferSize + 1000; + char *tmp = new char[(int)newSize]; + strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount); + delete[] wxResourceBuffer; + wxResourceBuffer = tmp; + wxResourceBufferSize = newSize; + } + return TRUE; +} + +static bool wxEatWhiteSpace(FILE *fd) +{ + int ch = 0; + + while ((ch = getc(fd)) != EOF) + { + switch (ch) + { + case ' ': + case 0x0a: + case 0x0d: + case 0x09: + break; + case '/': + { + int prev_ch = ch; + ch = getc(fd); + if (ch == EOF) + { + ungetc(prev_ch, fd); + return TRUE; + } + + if (ch == '*') + { + // Eat C comment + prev_ch = 0; + while ((ch = getc(fd)) != EOF) + { + if (ch == '/' && prev_ch == '*') + break; + prev_ch = ch; + } + } + else if (ch == '/') + { + // Eat C++ comment + static char buffer[255]; + fgets(buffer, 255, fd); + } + else + { + ungetc(prev_ch, fd); + ungetc(ch, fd); + return TRUE; + } + } + break; + default: + ungetc(ch, fd); + return TRUE; + + } + } + return FALSE; +} +static bool wxEatWhiteSpace(wxInputStream *is) +{ + int ch = is->GetC() ; + if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9)) + { + is->Ungetch(ch); + return TRUE; + } + + // Eat whitespace + while (ch == ' ' || ch == 10 || ch == 13 || ch == 9) + ch = is->GetC(); + // Check for comment + if (ch == '/') + { + ch = is->GetC(); + if (ch == '*') + { + bool finished = FALSE; + while (!finished) + { + ch = is->GetC(); + if (ch == EOF) + return FALSE; + if (ch == '*') + { + int newCh = is->GetC(); + if (newCh == '/') + finished = TRUE; + else + { + is->Ungetch(ch); + } + } + } + } + else // False alarm + return FALSE; + } + else + is->Ungetch(ch); + return wxEatWhiteSpace(is); +} + +bool wxGetResourceToken(FILE *fd) +{ + if (!wxResourceBuffer) + wxReallocateResourceBuffer(); + wxResourceBuffer[0] = 0; + wxEatWhiteSpace(fd); + + int ch = getc(fd); + if (ch == '"') + { + // Get string + wxResourceBufferCount = 0; + ch = getc(fd); + while (ch != '"') + { + int actualCh = ch; + if (ch == EOF) + { + wxResourceBuffer[wxResourceBufferCount] = 0; + return FALSE; + } + // Escaped characters + else if (ch == '\\') + { + int newCh = getc(fd); + if (newCh == '"') + actualCh = '"'; + else if (newCh == 10) + actualCh = 10; + else + { + ungetc(newCh, fd); + } + } + + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; + wxResourceBufferCount ++; + ch = getc(fd); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + } + else + { + wxResourceBufferCount = 0; + // Any other token + while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) + { + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)ch; + wxResourceBufferCount ++; + + ch = getc(fd); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + if (ch == EOF) + return FALSE; + } + return TRUE; +} + +bool wxGetResourceToken(wxInputStream *is) +{ + if (!wxResourceBuffer) + wxReallocateResourceBuffer(); + wxResourceBuffer[0] = 0; + wxEatWhiteSpace(is); + + int ch = is->GetC() ; + if (ch == '"') + { + // Get string + wxResourceBufferCount = 0; + ch = is->GetC(); + while (ch != '"') + { + int actualCh = ch; + if (ch == EOF) + { + wxResourceBuffer[wxResourceBufferCount] = 0; + return FALSE; + } + // Escaped characters + else if (ch == '\\') + { + int newCh = is->GetC(); + if (newCh == '"') + actualCh = '"'; + else if (newCh == 10) + actualCh = 10; + else if (newCh == 13) // mac + actualCh = 10; + else + { + is->Ungetch(newCh); + } + } + + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; + wxResourceBufferCount ++; + ch = is->GetC(); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + } + else + { + wxResourceBufferCount = 0; + // Any other token + while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) + { + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)ch; + wxResourceBufferCount ++; + + ch = is->GetC(); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + if (ch == EOF) + return FALSE; + } + return TRUE; +} + +/* +* Files are in form: +static char *name = "...."; +with possible comments. +*/ + +bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + // static or #define + if (!wxGetResourceToken(fd)) + { + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "#define") == 0) + { + wxGetResourceToken(fd); + wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + wxGetResourceToken(fd); + wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + if (wxIsdigit(value[0])) + { + int val = (int)wxAtol(value); + wxResourceAddIdentifier(name, val, table); + } + else + { + wxLogWarning(_("#define %s must be an integer."), name); + delete[] name; + delete[] value; + return FALSE; + } + delete[] name; + delete[] value; + + return TRUE; + } + else if (strcmp(wxResourceBuffer, "#include") == 0) + { + wxGetResourceToken(fd); + wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + wxChar *actualName = name; + if (name[0] == wxT('"')) + actualName = name + 1; + int len = wxStrlen(name); + if ((len > 0) && (name[len-1] == wxT('"'))) + name[len-1] = 0; + if (!wxResourceParseIncludeFile(actualName, table)) + { + wxLogWarning(_("Could not find resource include file %s."), actualName); + } + delete[] name; + return TRUE; + } + else if (strcmp(wxResourceBuffer, "static") != 0) + { + wxChar buf[300]; + wxStrcpy(buf, _("Found ")); + wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); + wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); + wxLogWarning(buf); + return FALSE; + } + + // char + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "char") != 0) + { + wxLogWarning(_("Expected 'char' whilst parsing resource.")); + return FALSE; + } + + // *name + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (wxResourceBuffer[0] != '*') + { + wxLogWarning(_("Expected '*' whilst parsing resource.")); + return FALSE; + } + wxChar nameBuf[100]; + wxMB2WX(nameBuf, wxResourceBuffer+1, 99); + nameBuf[99] = 0; + + // = + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "=") != 0) + { + wxLogWarning(_("Expected '=' whilst parsing resource.")); + return FALSE; + } + + // String + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + else + { + if (!db.ReadPrologFromString(wxResourceBuffer)) + { + wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); + return FALSE; + } + } + // Semicolon + if (!wxGetResourceToken(fd)) + { + *eof = TRUE; + } + return TRUE; +} + +bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + // static or #define + if (!wxGetResourceToken(fd)) + { + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "#define") == 0) + { + wxGetResourceToken(fd); + wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); + wxGetResourceToken(fd); + wxChar *value = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); + if (wxIsalpha(value[0])) + { + int val = (int)wxAtol(value); + wxResourceAddIdentifier(name, val, table); + } + else + { + wxLogWarning(_("#define %s must be an integer."), name); + delete[] name; + delete[] value; + return FALSE; + } + delete[] name; + delete[] value; + + return TRUE; + } + else if (strcmp(wxResourceBuffer, "#include") == 0) + { + wxGetResourceToken(fd); + wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); + wxChar *actualName = name; + if (name[0] == wxT('"')) + actualName = name + 1; + int len = wxStrlen(name); + if ((len > 0) && (name[len-1] == wxT('"'))) + name[len-1] = 0; + if (!wxResourceParseIncludeFile(actualName, table)) + { + wxLogWarning(_("Could not find resource include file %s."), actualName); + } + delete[] name; + return TRUE; + } + else if (strcmp(wxResourceBuffer, "static") != 0) + { + wxChar buf[300]; + wxStrcpy(buf, _("Found ")); + wxStrncat(buf, wxConvLibc.cMB2WX(wxResourceBuffer), 30); + wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); + wxLogWarning(buf); + return FALSE; + } + + // char + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "char") != 0) + { + wxLogWarning(_("Expected 'char' whilst parsing resource.")); + return FALSE; + } + + // *name + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (wxResourceBuffer[0] != '*') + { + wxLogWarning(_("Expected '*' whilst parsing resource.")); + return FALSE; + } + char nameBuf[100]; + strncpy(nameBuf, wxResourceBuffer+1, 99); + + // = + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "=") != 0) + { + wxLogWarning(_("Expected '=' whilst parsing resource.")); + return FALSE; + } + + // String + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + else + { + if (!db.ReadPrologFromString(wxResourceBuffer)) + { + wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); + return FALSE; + } + } + // Semicolon + if (!wxGetResourceToken(fd)) + { + *eof = TRUE; + } + return TRUE; +} + +/* +* Parses string window style into integer window style +*/ + +/* +* Style flag parsing, e.g. +* "wxSYSTEM_MENU | wxBORDER" -> integer +*/ + +wxChar* wxResourceParseWord(wxChar*s, int *i) +{ + if (!s) + return (wxChar*) NULL; + + static wxChar buf[150]; + int len = wxStrlen(s); + int j = 0; + int ii = *i; + while ((ii < len) && (wxIsalpha(s[ii]) || (s[ii] == wxT('_')))) + { + buf[j] = s[ii]; + j ++; + ii ++; + } + buf[j] = 0; + + // Eat whitespace and conjunction characters + while ((ii < len) && + ((s[ii] == wxT(' ')) || (s[ii] == wxT('|')) || (s[ii] == wxT(',')))) + { + ii ++; + } + *i = ii; + if (j == 0) + return (wxChar*) NULL; + else + return buf; +} + +struct wxResourceBitListStruct +{ + const wxChar *word; + long bits; +}; + +static wxResourceBitListStruct wxResourceBitListTable[] = +{ + /* wxListBox */ + { wxT("wxSINGLE"), wxLB_SINGLE }, + { wxT("wxMULTIPLE"), wxLB_MULTIPLE }, + { wxT("wxEXTENDED"), wxLB_EXTENDED }, + { wxT("wxLB_SINGLE"), wxLB_SINGLE }, + { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE }, + { wxT("wxLB_EXTENDED"), wxLB_EXTENDED }, + { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB }, + { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB }, + { wxT("wxLB_SORT"), wxLB_SORT }, + { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW }, + { wxT("wxLB_HSCROLL"), wxLB_HSCROLL }, + + /* wxComboxBox */ + { wxT("wxCB_SIMPLE"), wxCB_SIMPLE }, + { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN }, + { wxT("wxCB_READONLY"), wxCB_READONLY }, + { wxT("wxCB_SORT"), wxCB_SORT }, + + /* wxGauge */ + { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR }, + { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL }, + { wxT("wxGA_VERTICAL"), wxGA_VERTICAL }, + + /* wxTextCtrl */ + { wxT("wxPASSWORD"), wxPASSWORD}, + { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER}, + { wxT("wxTE_PASSWORD"), wxTE_PASSWORD}, + { wxT("wxTE_READONLY"), wxTE_READONLY}, + { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER}, + { wxT("wxTE_MULTILINE"), wxTE_MULTILINE}, + { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL}, + + /* wxRadioBox/wxRadioButton */ + { wxT("wxRB_GROUP"), wxRB_GROUP }, + { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS }, + { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS }, + { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL }, + { wxT("wxRA_VERTICAL"), wxRA_VERTICAL }, + + /* wxSlider */ + { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL }, + { wxT("wxSL_VERTICAL"), wxSL_VERTICAL }, + { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS }, + { wxT("wxSL_LABELS"), wxSL_LABELS }, + { wxT("wxSL_LEFT"), wxSL_LEFT }, + { wxT("wxSL_TOP"), wxSL_TOP }, + { wxT("wxSL_RIGHT"), wxSL_RIGHT }, + { wxT("wxSL_BOTTOM"), wxSL_BOTTOM }, + { wxT("wxSL_BOTH"), wxSL_BOTH }, + { wxT("wxSL_SELRANGE"), wxSL_SELRANGE }, + + /* wxScrollBar */ + { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL }, + { wxT("wxSB_VERTICAL"), wxSB_VERTICAL }, + + /* wxButton */ + { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW }, + { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW }, + + /* wxTreeCtrl */ + { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS }, + { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS }, + { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT }, + + /* wxListCtrl */ + { wxT("wxLC_ICON"), wxLC_ICON }, + { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON }, + { wxT("wxLC_LIST"), wxLC_LIST }, + { wxT("wxLC_REPORT"), wxLC_REPORT }, + { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP }, + { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT }, + { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE }, + { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT }, + { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS }, + { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER }, + { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER }, + { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL }, + { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING }, + { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING }, + + /* wxSpinButton */ + { wxT("wxSP_VERTICAL"), wxSP_VERTICAL}, + { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL}, + { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS}, + { wxT("wxSP_WRAP"), wxSP_WRAP}, + + /* wxSplitterWnd */ + { wxT("wxSP_NOBORDER"), wxSP_NOBORDER}, + { wxT("wxSP_3D"), wxSP_3D}, + { wxT("wxSP_BORDER"), wxSP_BORDER}, + + /* wxTabCtrl */ + { wxT("wxTC_MULTILINE"), wxTC_MULTILINE}, + { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY}, + { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH}, + { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW}, + + /* wxStatusBar95 */ + { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP}, + + /* wxControl */ + { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH}, + { wxT("wxALIGN_LEFT"), wxALIGN_LEFT}, + { wxT("wxALIGN_CENTER"), wxALIGN_CENTER}, + { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE}, + { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT}, + { wxT("wxCOLOURED"), wxCOLOURED}, + + /* wxToolBar */ + { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS}, + { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL}, + { wxT("wxTB_VERTICAL"), wxTB_VERTICAL}, + { wxT("wxTB_FLAT"), wxTB_FLAT}, + + /* wxDialog */ + { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL }, + + /* Generic */ + { wxT("wxVSCROLL"), wxVSCROLL }, + { wxT("wxHSCROLL"), wxHSCROLL }, + { wxT("wxCAPTION"), wxCAPTION }, + { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP}, + { wxT("wxICONIZE"), wxICONIZE}, + { wxT("wxMINIMIZE"), wxICONIZE}, + { wxT("wxMAXIMIZE"), wxMAXIMIZE}, + { wxT("wxSDI"), 0}, + { wxT("wxMDI_PARENT"), 0}, + { wxT("wxMDI_CHILD"), 0}, + { wxT("wxTHICK_FRAME"), wxTHICK_FRAME}, + { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER}, + { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU}, + { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX}, + { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX}, + { wxT("wxRESIZE_BOX"), wxRESIZE_BOX}, + { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE}, + { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE}, + { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE}, + { wxT("wxBORDER"), wxBORDER}, + { wxT("wxRETAINED"), wxRETAINED}, + { wxT("wxNATIVE_IMPL"), 0}, + { wxT("wxEXTENDED_IMPL"), 0}, + { wxT("wxBACKINGSTORE"), wxBACKINGSTORE}, + // { wxT("wxFLAT"), wxFLAT}, + // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE}, + { wxT("wxFIXED_LENGTH"), 0}, + { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER}, + { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER}, + { wxT("wxRAISED_BORDER"), wxRAISED_BORDER}, + { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER}, + { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER}, + { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW}, + { wxT("wxNO_BORDER"), wxNO_BORDER}, + { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN}, + { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS}, + { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only + + { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ}, + { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT}, + + // Text font families + { wxT("wxDEFAULT"), wxDEFAULT}, + { wxT("wxDECORATIVE"), wxDECORATIVE}, + { wxT("wxROMAN"), wxROMAN}, + { wxT("wxSCRIPT"), wxSCRIPT}, + { wxT("wxSWISS"), wxSWISS}, + { wxT("wxMODERN"), wxMODERN}, + { wxT("wxTELETYPE"), wxTELETYPE}, + { wxT("wxVARIABLE"), wxVARIABLE}, + { wxT("wxFIXED"), wxFIXED}, + { wxT("wxNORMAL"), wxNORMAL}, + { wxT("wxLIGHT"), wxLIGHT}, + { wxT("wxBOLD"), wxBOLD}, + { wxT("wxITALIC"), wxITALIC}, + { wxT("wxSLANT"), wxSLANT}, + { wxT("wxSOLID"), wxSOLID}, + { wxT("wxDOT"), wxDOT}, + { wxT("wxLONG_DASH"), wxLONG_DASH}, + { wxT("wxSHORT_DASH"), wxSHORT_DASH}, + { wxT("wxDOT_DASH"), wxDOT_DASH}, + { wxT("wxUSER_DASH"), wxUSER_DASH}, + { wxT("wxTRANSPARENT"), wxTRANSPARENT}, + { wxT("wxSTIPPLE"), wxSTIPPLE}, + { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH}, + { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH}, + { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH}, + { wxT("wxCROSS_HATCH"), wxCROSS_HATCH}, + { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH}, + { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH}, + { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL}, + { wxT("wxJOIN_MITER"), wxJOIN_MITER}, + { wxT("wxJOIN_ROUND"), wxJOIN_ROUND}, + { wxT("wxCAP_ROUND"), wxCAP_ROUND}, + { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING}, + { wxT("wxCAP_BUTT"), wxCAP_BUTT}, + + // Logical ops + { wxT("wxCLEAR"), wxCLEAR}, + { wxT("wxXOR"), wxXOR}, + { wxT("wxINVERT"), wxINVERT}, + { wxT("wxOR_REVERSE"), wxOR_REVERSE}, + { wxT("wxAND_REVERSE"), wxAND_REVERSE}, + { wxT("wxCOPY"), wxCOPY}, + { wxT("wxAND"), wxAND}, + { wxT("wxAND_INVERT"), wxAND_INVERT}, + { wxT("wxNO_OP"), wxNO_OP}, + { wxT("wxNOR"), wxNOR}, + { wxT("wxEQUIV"), wxEQUIV}, + { wxT("wxSRC_INVERT"), wxSRC_INVERT}, + { wxT("wxOR_INVERT"), wxOR_INVERT}, + { wxT("wxNAND"), wxNAND}, + { wxT("wxOR"), wxOR}, + { wxT("wxSET"), wxSET}, + + { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE}, + { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER}, + { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE}, + { wxT("wxWINDING_RULE"), wxWINDING_RULE}, + { wxT("wxHORIZONTAL"), wxHORIZONTAL}, + { wxT("wxVERTICAL"), wxVERTICAL}, + { wxT("wxBOTH"), wxBOTH}, + { wxT("wxCENTER_FRAME"), wxCENTER_FRAME}, + { wxT("wxOK"), wxOK}, + { wxT("wxYES_NO"), wxYES_NO}, + { wxT("wxCANCEL"), wxCANCEL}, + { wxT("wxYES"), wxYES}, + { wxT("wxNO"), wxNO}, + { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION}, + { wxT("wxICON_HAND"), wxICON_HAND}, + { wxT("wxICON_QUESTION"), wxICON_QUESTION}, + { wxT("wxICON_INFORMATION"), wxICON_INFORMATION}, + { wxT("wxICON_STOP"), wxICON_STOP}, + { wxT("wxICON_ASTERISK"), wxICON_ASTERISK}, + { wxT("wxICON_MASK"), wxICON_MASK}, + { wxT("wxCENTRE"), wxCENTRE}, + { wxT("wxCENTER"), wxCENTRE}, + { wxT("wxUSER_COLOURS"), wxUSER_COLOURS}, + { wxT("wxVERTICAL_LABEL"), 0}, + { wxT("wxHORIZONTAL_LABEL"), 0}, + + // Bitmap types (not strictly styles) + { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM}, + { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM}, + { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP}, + { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE}, + { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE}, + { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF}, + { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF}, + { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO}, + { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE}, + { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR}, + { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE}, + { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA}, + { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA}, + { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY} +}; + +static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct)); + +long wxParseWindowStyle(const wxString& bitListString) +{ + int i = 0; + wxChar *word; + long bitList = 0; + word = wxResourceParseWord(WXSTRINGCAST bitListString, &i); + while (word != NULL) + { + bool found = FALSE; + int j; + for (j = 0; j < wxResourceBitListCount; j++) + if (wxStrcmp(wxResourceBitListTable[j].word, word) == 0) + { + bitList |= wxResourceBitListTable[j].bits; + found = TRUE; + break; + } + if (!found) + { + wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word); + return 0; + } + word = wxResourceParseWord(WXSTRINGCAST bitListString, &i); + } + return bitList; +} + +/* +* Load a bitmap from a wxWindows resource, choosing an optimum +* depth and appropriate type. +*/ + +wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + wxItemResource *item = table->FindResource(resource); + if (item) + { + if ((item->GetType() == wxT("")) || (item->GetType() != wxT("wxBitmap"))) + { + wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar*) resource); + return wxNullBitmap; + } + int thisDepth = wxDisplayDepth(); + long thisNoColours = (long)pow(2.0, (double)thisDepth); + + wxItemResource *optResource = (wxItemResource *) NULL; + + // Try to find optimum bitmap for this platform/colour depth + wxNode *node = item->GetChildren().First(); + while (node) + { + wxItemResource *child = (wxItemResource *)node->Data(); + int platform = (int)child->GetValue2(); + int noColours = (int)child->GetValue3(); + /* + char *name = child->GetName(); + int bitmapType = (int)child->GetValue1(); + int xRes = child->GetWidth(); + int yRes = child->GetHeight(); + */ + + switch (platform) + { + case RESOURCE_PLATFORM_ANY: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours. + // If noColours is zero (unspecified), then assume this + // is the right one. + if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#ifdef __WXMSW__ + case RESOURCE_PLATFORM_WINDOWS: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours + if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#endif +#ifdef __WXGTK__ + case RESOURCE_PLATFORM_X: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours + if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#endif +#ifdef wx_max + case RESOURCE_PLATFORM_MAC: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours + if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#endif + default: + break; + } + node = node->Next(); + } + // If no matching resource, fail. + if (!optResource) + return wxNullBitmap; + + wxString name = optResource->GetName(); + int bitmapType = (int)optResource->GetValue1(); + switch (bitmapType) + { + case wxBITMAP_TYPE_XBM_DATA: + { +#ifdef __WXGTK__ + wxItemResource *item = table->FindResource(name); + if (!item) + { + wxLogWarning(_("Failed to find XBM resource %s.\n" + "Forgot to use wxResourceLoadBitmapData?"), (const wxChar*) name); + return wxNullBitmap; + } + return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ; +#else + wxLogWarning(_("No XBM facility available!")); + break; +#endif + } + case wxBITMAP_TYPE_XPM_DATA: + { + wxItemResource *item = table->FindResource(name); + if (!item) + { + wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar*) name); + return wxNullBitmap; + } + return wxBitmap((char **)item->GetValue1()); + } + default: + { +#if defined(__WXPM__) + return wxNullBitmap; +#else + return wxBitmap(name, (wxBitmapType)bitmapType); +#endif + } + } +#ifndef __WXGTK__ + return wxNullBitmap; +#endif + } + else + { + wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar*) resource); + return wxNullBitmap; + } +} + +/* +* Load an icon from a wxWindows resource, choosing an optimum +* depth and appropriate type. +*/ + +wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + wxItemResource *item = table->FindResource(resource); + if (item) + { + if ((item->GetType() == wxT("")) || wxStrcmp(item->GetType(), wxT("wxIcon")) != 0) + { + wxLogWarning(_("%s not an icon resource specification."), (const wxChar*) resource); + return wxNullIcon; + } + int thisDepth = wxDisplayDepth(); + long thisNoColours = (long)pow(2.0, (double)thisDepth); + + wxItemResource *optResource = (wxItemResource *) NULL; + + // Try to find optimum icon for this platform/colour depth + wxNode *node = item->GetChildren().First(); + while (node) + { + wxItemResource *child = (wxItemResource *)node->Data(); + int platform = (int)child->GetValue2(); + int noColours = (int)child->GetValue3(); + /* + char *name = child->GetName(); + int bitmapType = (int)child->GetValue1(); + int xRes = child->GetWidth(); + int yRes = child->GetHeight(); + */ + + switch (platform) + { + case RESOURCE_PLATFORM_ANY: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours. + // If noColours is zero (unspecified), then assume this + // is the right one. + if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#ifdef __WXMSW__ + case RESOURCE_PLATFORM_WINDOWS: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours + if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#endif +#ifdef __WXGTK__ + case RESOURCE_PLATFORM_X: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours + if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#endif +#ifdef wx_max + case RESOURCE_PLATFORM_MAC: + { + if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) + optResource = child; + else + { + // Maximise the number of colours + if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) + optResource = child; + } + break; + } +#endif + default: + break; + } + node = node->Next(); + } + // If no matching resource, fail. + if (!optResource) + return wxNullIcon; + + wxString name = optResource->GetName(); + int bitmapType = (int)optResource->GetValue1(); + switch (bitmapType) + { + case wxBITMAP_TYPE_XBM_DATA: + { +#ifdef __WXGTK__ + wxItemResource *item = table->FindResource(name); + if (!item) + { + wxLogWarning(_("Failed to find XBM resource %s.\n" + "Forgot to use wxResourceLoadIconData?"), (const wxChar*) name); + return wxNullIcon; + } + return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); +#else + wxLogWarning(_("No XBM facility available!")); + break; +#endif + } + case wxBITMAP_TYPE_XPM_DATA: + { + // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS *** + /* + wxItemResource *item = table->FindResource(name); + if (!item) + { + char buf[400]; + sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name); + wxLogWarning(buf); + return NULL; + } + return wxIcon((char **)item->GetValue1()); + */ + wxLogWarning(_("No XPM icon facility available!")); + break; + } + default: + { +#if defined( __WXGTK__ ) || defined( __WXMOTIF__ ) + wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); + break; +#else + return wxIcon(name, bitmapType); +#endif + } + } + return wxNullIcon; + } + else + { + wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); + return wxNullIcon; + } +} + +#if wxUSE_MENUS + +wxMenu *wxResourceCreateMenu(wxItemResource *item) +{ + wxMenu *menu = new wxMenu; + wxNode *node = item->GetChildren().First(); + while (node) + { + wxItemResource *child = (wxItemResource *)node->Data(); + if ((child->GetType() != wxT("")) && (child->GetType() == wxT("wxMenuSeparator"))) + menu->AppendSeparator(); + else if (child->GetChildren().Number() > 0) + { + wxMenu *subMenu = wxResourceCreateMenu(child); + if (subMenu) + menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4()); + } + else + { + menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0)); + } + node = node->Next(); + } + return menu; +} + +wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar) +{ + if (!table) + table = wxDefaultResourceTable; + + wxItemResource *menuResource = table->FindResource(resource); + if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu"))) + { + if (!menuBar) + menuBar = new wxMenuBar; + wxNode *node = menuResource->GetChildren().First(); + while (node) + { + wxItemResource *child = (wxItemResource *)node->Data(); + wxMenu *menu = wxResourceCreateMenu(child); + if (menu) + menuBar->Append(menu, child->GetTitle()); + node = node->Next(); + } + return menuBar; + } + return (wxMenuBar *) NULL; +} + +wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + wxItemResource *menuResource = table->FindResource(resource); + if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu"))) + // if (menuResource && (menuResource->GetType() == wxTYPE_MENU)) + return wxResourceCreateMenu(menuResource); + return (wxMenu *) NULL; +} + +#endif // wxUSE_MENUS + +// Global equivalents (so don't have to refer to default table explicitly) +bool wxResourceParseData(const wxString& resource, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + return table->ParseResourceData(resource); +} + +bool wxResourceParseData(const char* resource, wxResourceTable *table) +{ + wxString str(resource, wxConvLibc); + if (!table) + table = wxDefaultResourceTable; + + return table->ParseResourceData(str); +} + +bool wxResourceParseFile(const wxString& filename, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + return table->ParseResourceFile(filename); +} + +// Register XBM/XPM data +bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + return table->RegisterResourceBitmapData(name, bits, width, height); +} + +bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + return table->RegisterResourceBitmapData(name, data); +} + +void wxResourceClear(wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + table->ClearTable(); +} + +/* +* Identifiers +*/ + +bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + table->identifiers.Put(name, (wxObject *)(long)value); + return TRUE; +} + +int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + return (int)(long)table->identifiers.Get(name); +} + +/* +* Parse #include file for #defines (only) +*/ + +bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + FILE *fd = wxFopen(f, wxT("r")); + if (!fd) + { + return FALSE; + } + while (wxGetResourceToken(fd)) + { + if (strcmp(wxResourceBuffer, "#define") == 0) + { + wxGetResourceToken(fd); + wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + wxGetResourceToken(fd); + wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + if (wxIsdigit(value[0])) + { + int val = (int)wxAtol(value); + wxResourceAddIdentifier(name, val, table); + } + delete[] name; + delete[] value; + } + } + fclose(fd); + return TRUE; +} + +/* +* Reading strings as if they were .wxr files +*/ + +static int getc_string(char *s) +{ + int ch = s[wxResourceStringPtr]; + if (ch == 0) + return EOF; + else + { + wxResourceStringPtr ++; + return ch; + } +} + +static int ungetc_string() +{ + wxResourceStringPtr --; + return 0; +} + +bool wxEatWhiteSpaceString(char *s) +{ + int ch = 0; + + while ((ch = getc_string(s)) != EOF) + { + switch (ch) + { + case ' ': + case 0x0a: + case 0x0d: + case 0x09: + break; + case '/': + { + int prev_ch = ch; + ch = getc_string(s); + if (ch == EOF) + { + ungetc_string(); + return TRUE; + } + + if (ch == '*') + { + // Eat C comment + prev_ch = 0; + while ((ch = getc_string(s)) != EOF) + { + if (ch == '/' && prev_ch == '*') + break; + prev_ch = ch; + } + } + else + { + ungetc_string(); + ungetc_string(); + return TRUE; + } + } + break; + default: + ungetc_string(); + return TRUE; + + } + } + return FALSE; +} + +bool wxGetResourceTokenString(char *s) +{ + if (!wxResourceBuffer) + wxReallocateResourceBuffer(); + wxResourceBuffer[0] = 0; + wxEatWhiteSpaceString(s); + + int ch = getc_string(s); + if (ch == '"') + { + // Get string + wxResourceBufferCount = 0; + ch = getc_string(s); + while (ch != '"') + { + int actualCh = ch; + if (ch == EOF) + { + wxResourceBuffer[wxResourceBufferCount] = 0; + return FALSE; + } + // Escaped characters + else if (ch == '\\') + { + int newCh = getc_string(s); + if (newCh == '"') + actualCh = '"'; + else if (newCh == 10) + actualCh = 10; + else + { + ungetc_string(); + } + } + + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; + wxResourceBufferCount ++; + ch = getc_string(s); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + } + else + { + wxResourceBufferCount = 0; + // Any other token + while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) + { + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)ch; + wxResourceBufferCount ++; + + ch = getc_string(s); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + if (ch == EOF) + return FALSE; + } + return TRUE; +} + +/* +* Files are in form: +static char *name = "...."; +with possible comments. +*/ + +bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + // static or #define + if (!wxGetResourceTokenString(s)) + { + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "#define") == 0) + { + wxGetResourceTokenString(s); + wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + wxGetResourceTokenString(s); + wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); + if (wxIsdigit(value[0])) + { + int val = (int)wxAtol(value); + wxResourceAddIdentifier(name, val, table); + } + else + { + wxLogWarning(_("#define %s must be an integer."), name); + delete[] name; + delete[] value; + return FALSE; + } + delete[] name; + delete[] value; + + return TRUE; + } + /* + else if (strcmp(wxResourceBuffer, "#include") == 0) + { + wxGetResourceTokenString(s); + char *name = copystring(wxResourceBuffer); + char *actualName = name; + if (name[0] == '"') + actualName = name + 1; + int len = strlen(name); + if ((len > 0) && (name[len-1] == '"')) + name[len-1] = 0; + if (!wxResourceParseIncludeFile(actualName, table)) + { + char buf[400]; + sprintf(buf, _("Could not find resource include file %s."), actualName); + wxLogWarning(buf); + } + delete[] name; + return TRUE; + } + */ + else if (strcmp(wxResourceBuffer, "static") != 0) + { + wxChar buf[300]; + wxStrcpy(buf, _("Found ")); + wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); + wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); + wxLogWarning(buf); + return FALSE; + } + + // char + if (!wxGetResourceTokenString(s)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "char") != 0) + { + wxLogWarning(_("Expected 'char' whilst parsing resource.")); + return FALSE; + } + + // *name + if (!wxGetResourceTokenString(s)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (wxResourceBuffer[0] != '*') + { + wxLogWarning(_("Expected '*' whilst parsing resource.")); + return FALSE; + } + wxChar nameBuf[100]; + wxMB2WX(nameBuf, wxResourceBuffer+1, 99); + nameBuf[99] = 0; + + // = + if (!wxGetResourceTokenString(s)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "=") != 0) + { + wxLogWarning(_("Expected '=' whilst parsing resource.")); + return FALSE; + } + + // String + if (!wxGetResourceTokenString(s)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + else + { + if (!db.ReadPrologFromString(wxResourceBuffer)) + { + wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); + return FALSE; + } + } + // Semicolon + if (!wxGetResourceTokenString(s)) + { + *eof = TRUE; + } + return TRUE; +} + +bool wxResourceParseString(const wxString& s, wxResourceTable *table) +{ +#if wxUSE_UNICODE + return wxResourceParseString( (char*)s.mb_str().data() ); +#else + return wxResourceParseString( (char*)s.c_str() ); +#endif +} + +bool wxResourceParseString(char *s, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + if (!s) + return FALSE; + + // Turn backslashes into spaces + if (s) + { + int len = strlen(s); + int i; + for (i = 0; i < len; i++) + if (s[i] == 92 && s[i+1] == 13) + { + s[i] = ' '; + s[i+1] = ' '; + } + } + + wxExprDatabase db; + wxResourceStringPtr = 0; + + bool eof = FALSE; + while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof) + { + // Loop + } + return wxResourceInterpretResources(*table, db); +} + +/* +* resource loading facility +*/ + +bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + wxItemResource *resource = table->FindResource((const wxChar *)resourceName); + // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX)) + if (!resource || (resource->GetType() == wxT("")) || + ! ((resource->GetType() == wxT("wxDialog")) || (resource->GetType() == wxT("wxPanel")))) + return FALSE; + + wxString title(resource->GetTitle()); + long theWindowStyle = resource->GetStyle(); + bool isModal = (resource->GetValue1() != 0) ; + int x = resource->GetX(); + int y = resource->GetY(); + int width = resource->GetWidth(); + int height = resource->GetHeight(); + wxString name = resource->GetName(); + + // this is used for loading wxWizard pages from WXR + if ( parent != this ) + { + if (IsKindOf(CLASSINFO(wxDialog))) + { + wxDialog *dialogBox = (wxDialog *)this; + long modalStyle = isModal ? wxDIALOG_MODAL : 0; + if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name)) + return FALSE; + + // Only reset the client size if we know we're not going to do it again below. + if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0) + dialogBox->SetClientSize(width, height); + } + else if (IsKindOf(CLASSINFO(wxPanel))) + { + wxPanel* panel = (wxPanel *)this; + if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle | wxTAB_TRAVERSAL, name)) + return FALSE; + } + else + { + if (!((wxWindow *)this)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) + return FALSE; + } + } + + if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) + { + // No need to do this since it's done in wxPanel or wxDialog constructor. + // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); + } + else + { + if (resource->GetFont().Ok()) + SetFont(resource->GetFont()); + if (resource->GetBackgroundColour().Ok()) + SetBackgroundColour(resource->GetBackgroundColour()); + } + + // Should have some kind of font at this point + if (!GetFont().Ok()) + SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); + if (!GetBackgroundColour().Ok()) + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); + + // Only when we've created the window and set the font can we set the correct size, + // if based on dialog units. + if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) + { + wxSize sz = ConvertDialogToPixels(wxSize(width, height)); + SetClientSize(sz.x, sz.y); + + wxPoint pt = ConvertDialogToPixels(wxPoint(x, y)); + Move(pt.x, pt.y); + } + + // Now create children + wxNode *node = resource->GetChildren().First(); + while (node) + { + wxItemResource *childResource = (wxItemResource *)node->Data(); + + (void) CreateItem(childResource, resource, table); + + node = node->Next(); + } + return TRUE; +} + +wxControl *wxWindowBase::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + return table->CreateItem((wxWindow *)this, resource, parentResource); +} + +#ifdef __VISUALC__ +#pragma warning(default:4706) // assignment within conditional expression +#endif // VC++ + +#endif +// BC++/Win16 + +#endif // wxUSE_WX_RESOURCES diff --git a/contrib/src/deprecated/treelay.cpp b/contrib/src/deprecated/treelay.cpp new file mode 100644 index 0000000000..f9cac7c4e0 --- /dev/null +++ b/contrib/src/deprecated/treelay.cpp @@ -0,0 +1,473 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: treelay.h +// Purpose: wxTreeLayout class +// Author: Julian Smart +// Modified by: +// Created: 7/4/98 +// RCS-ID: $Id$ +// Copyright: (c) 1998 Julian Smart +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "wxtree.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/dc.h" +#include "wx/event.h" +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_TREELAYOUT + +#include "wx/deprecated/treelay.h" + +/* + * Abstract tree + * + */ + +IMPLEMENT_ABSTRACT_CLASS(wxTreeLayout, wxObject) + +wxTreeLayout::wxTreeLayout() +{ + m_xSpacing = 16; + m_ySpacing = 20; + m_topMargin = 5; + m_leftMargin = 5; + m_orientation = FALSE; + m_parentNode = 0; +} + +void wxTreeLayout::DoLayout(wxDC& dc, long topId) +{ + if (topId != -1) + SetTopNode(topId); + + long actualTopId = GetTopNode(); + long id = actualTopId; + while (id != -1) + { + SetNodeX(id, 0); + SetNodeY(id, 0); + ActivateNode(id, FALSE); + id = GetNextNode(id); + } + m_lastY = m_topMargin; + m_lastX = m_leftMargin; + CalcLayout(actualTopId, 0, dc); +} + +void wxTreeLayout::Draw(wxDC& dc) +{ + dc.Clear(); + DrawBranches(dc); + DrawNodes(dc); +} + +void wxTreeLayout::DrawNodes(wxDC& dc) +{ + long id = GetTopNode(); + while (id != -1) + { + if (NodeActive(id)) + DrawNode(id, dc); + id = GetNextNode(id); + } +} + +void wxTreeLayout::DrawBranches(wxDC& dc) +{ + long id = GetTopNode(); + while (id != -1) + { + if (GetNodeParent(id) > -1) + { + long parent = GetNodeParent(id); + if (NodeActive(parent)) + DrawBranch(parent, id, dc); + } + id = GetNextNode(id); + } +} + +void wxTreeLayout::DrawNode(long id, wxDC& dc) +{ + wxChar buf[80]; + wxString name(GetNodeName(id)); + if (name != wxT("")) + wxSprintf(buf, wxT("%s"), (const wxChar*) name); + else + wxSprintf(buf, wxT("")); + + long x = 80; + long y = 20; + dc.GetTextExtent(buf, &x, &y); + dc.DrawText(buf, GetNodeX(id), (long)(GetNodeY(id) - (y/2.0))); +} + +void wxTreeLayout::DrawBranch(long from, long to, wxDC& dc) +{ + long w, h; + GetNodeSize(from, &w, &h, dc); + dc.DrawLine(GetNodeX(from)+w, GetNodeY(from), + GetNodeX(to), GetNodeY(to)); +} + +void wxTreeLayout::Initialize(void) +{ +} + +void wxTreeLayout::GetNodeSize(long id, long *x, long *y, wxDC& dc) +{ + wxString name(GetNodeName(id)); + if (name != wxT("")) + dc.GetTextExtent(name, x, y); + else + { + *x = 70; *y = 20; + } +} + +void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc) +{ + wxList children; + GetChildren(nodeId, children); + int n = children.GetCount(); + + if (m_orientation == FALSE) + { + // Left to right + // X Calculations + if (level == 0) + SetNodeX(nodeId, m_leftMargin); + else + { + long x = 0; + long y = 0; + long parentId = GetNodeParent(nodeId); + if (parentId != -1) + GetNodeSize(parentId, &x, &y, dc); + SetNodeX(nodeId, (long)(GetNodeX(parentId) + m_xSpacing + x)); + } + + wxNode *node = children.GetFirst(); + while (node) + { + CalcLayout((long)node->GetData(), level+1, dc); + node = node->GetNext(); + } + + // Y Calculations + long averageY; + ActivateNode(nodeId, TRUE); + + if (n > 0) + { + averageY = 0; + node = children.GetFirst(); + while (node) + { + averageY += GetNodeY((long)node->GetData()); + node = node->GetNext(); + } + averageY = averageY / n; + SetNodeY(nodeId, averageY); + } + else + { + SetNodeY(nodeId, m_lastY); + long x, y; + GetNodeSize(nodeId, &x, &y, dc); + + m_lastY = m_lastY + y + m_ySpacing; + } + } + else + { + // Top to bottom + + // Y Calculations + if (level == 0) + SetNodeY(nodeId, m_topMargin); + else + { + long x = 0; + long y = 0; + long parentId = GetNodeParent(nodeId); + if (parentId != -1) + GetNodeSize(parentId, &x, &y, dc); + SetNodeY(nodeId, (long)(GetNodeY(parentId) + m_ySpacing + y)); + } + + wxNode *node = children.GetFirst(); + while (node) + { + CalcLayout((long)node->GetData(), level+1, dc); + node = node->GetNext(); + } + + // X Calculations + long averageX; + ActivateNode(nodeId, TRUE); + + if (n > 0) + { + averageX = 0; + node = children.GetFirst(); + while (node) + { + averageX += GetNodeX((long)node->GetData()); + node = node->GetNext(); + } + averageX = averageX / n; + SetNodeX(nodeId, averageX); + } + else + { + SetNodeX(nodeId, m_lastX); + long x, y; + GetNodeSize(nodeId, &x, &y, dc); + + m_lastX = m_lastX + x + m_xSpacing; + } + } +} + +/* + * Tree with storage + * + */ + +IMPLEMENT_DYNAMIC_CLASS(wxTreeLayoutStored, wxTreeLayout) + +wxTreeLayoutStored::wxTreeLayoutStored(int n):wxTreeLayout() +{ + m_nodes = NULL; + m_maxNodes = 0; + Initialize(n); +} + +wxTreeLayoutStored::~wxTreeLayoutStored(void) +{ + if (m_nodes) + delete[] m_nodes; +} + +void wxTreeLayoutStored::Initialize(int n) +{ + m_maxNodes = n; + wxTreeLayout::Initialize(); + if (m_nodes) delete[] m_nodes; + m_nodes = new wxStoredNode[m_maxNodes]; + int i; + for (i = 0; i < n; i++) + { + m_nodes[i].m_name = wxT(""); + m_nodes[i].m_active = FALSE; + m_nodes[i].m_parentId = -1; + m_nodes[i].m_x = 0; + m_nodes[i].m_y = 0; + } + m_num = 0; +} + +long wxTreeLayoutStored::AddChild(const wxString& name, const wxString& parent) +{ + if (m_num < (m_maxNodes -1 )) + { + long i = -1; + if (parent != wxT("")) + i = NameToId(parent); + else m_parentNode = m_num; + + m_nodes[m_num].m_parentId = i; + m_nodes[m_num].m_name = name; + m_nodes[m_num].m_x = m_nodes[m_num].m_y = 0; + m_nodes[m_num].m_clientData = 0; + m_num ++; + + return (m_num - 1); + } + else + return -1; +} + +long wxTreeLayoutStored::AddChild(const wxString& name, long parent) +{ + if (m_num < (m_maxNodes -1 ) && parent < m_num) + { + long i = -1; + if (parent != -1) + { + i = parent; + } + else + { + m_parentNode = m_num; + } + + m_nodes[m_num].m_parentId = i; + m_nodes[m_num].m_name = name; + m_nodes[m_num].m_x = m_nodes[m_num].m_y = 0; + m_nodes[m_num].m_clientData = 0; + m_num ++; + + return (m_num - 1); + } + else + return -1; +} + +long wxTreeLayoutStored::NameToId(const wxString& name) +{ + long i; + for (i = 0; i < m_num; i++) + if (name == m_nodes[i].m_name) + return i; + return -1; +} + +void wxTreeLayoutStored::GetChildren(long id, wxList& list) +{ + long currentId = GetTopNode(); + while (currentId != -1) + { + if (id == GetNodeParent(currentId)) + list.Append((wxObject *)currentId); + currentId = GetNextNode(currentId); + } +} + +wxStoredNode* wxTreeLayoutStored::GetNode(long idx) const +{ + wxASSERT(idx < m_num); + + return &m_nodes[idx]; +}; + +long wxTreeLayoutStored::GetNodeX(long id) +{ + wxASSERT(id < m_num); + + return (long)m_nodes[id].m_x; +} + +long wxTreeLayoutStored::GetNodeY(long id) +{ + wxASSERT(id < m_num); + + return (long)m_nodes[id].m_y; +} + +void wxTreeLayoutStored::SetNodeX(long id, long x) +{ + wxASSERT(id < m_num); + + m_nodes[id].m_x = (int)x; +} + +void wxTreeLayoutStored::SetNodeY(long id, long y) +{ + wxASSERT(id < m_num); + + m_nodes[id].m_y = (int)y; +} + +void wxTreeLayoutStored::SetNodeName(long id, const wxString& name) +{ + wxASSERT(id < m_num); + + m_nodes[id].m_name = name; +} + +wxString wxTreeLayoutStored::GetNodeName(long id) +{ + wxASSERT(id < m_num); + + return m_nodes[id].m_name; +} + +long wxTreeLayoutStored::GetNodeParent(long id) +{ + if (id != -1) + { + wxASSERT(id < m_num); + + return m_nodes[id].m_parentId; + } + else + return -1; +} + +long wxTreeLayoutStored::GetNextNode(long id) +{ + wxASSERT(id < m_num); + + if ((id != -1) && (id < (m_num - 1))) + return id + 1; + else + return -1; +} + +void wxTreeLayoutStored::SetClientData(long id, long clientData) +{ + wxASSERT(id < m_num); + + m_nodes[id].m_clientData = clientData; +} + +long wxTreeLayoutStored::GetClientData(long id) const +{ + wxASSERT(id < m_num); + + return m_nodes[id].m_clientData; +} + +void wxTreeLayoutStored::ActivateNode(long id, bool active) +{ + wxASSERT(id < m_num); + + m_nodes[id].m_active = active; +} + +bool wxTreeLayoutStored::NodeActive(long id) +{ + wxASSERT(id < m_num); + + return m_nodes[id].m_active; +} + +wxString wxTreeLayoutStored::HitTest(wxMouseEvent& event, wxDC& dc) +{ + wxPoint pt = event.GetPosition(); + wxCoord x = pt.x; + wxCoord y = pt.y; + + int i; + for (i = 0; i < m_maxNodes; i++) + { + long width, height; + dc.GetTextExtent(m_nodes[i].m_name, &width, &height); + + if ( (x >= (m_nodes[i].m_x-10)) && (x < (m_nodes[i].m_x + width+10)) && + (y >= m_nodes[i].m_y-10) && (y < (m_nodes[i].m_y + height+10)) ) + { + return m_nodes[i].m_name; + } + } + + return wxString( wxT("") ); +} + +#endif + // wxUSE_TREELAYOUT diff --git a/contrib/src/deprecated/wxexpr.cpp b/contrib/src/deprecated/wxexpr.cpp new file mode 100644 index 0000000000..bc2d40f850 --- /dev/null +++ b/contrib/src/deprecated/wxexpr.cpp @@ -0,0 +1,1280 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wxexpr.cpp +// Purpose: wxExpr +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "wxexpr.h" +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include "wx/deprecated/setup.h" + +#if wxUSE_PROLOGIO + +#include +#include +#include + +#include "wx/utils.h" +#include "wx/deprecated/expr.h" +#include "wx/deprecated/wxexpr.h" + +extern "C" void add_expr(char *); +extern "C" void LexFromFile(FILE *fd); +extern "C" void LexFromString(char *buf); + + + +/* Rename all YACC/LEX stuff or we'll conflict with other + * applications + */ + +#define yyback PROIO_yyback +#define yylook PROIO_yylook +#define yywrap PROIO_yywrap +#define yyoutput PROIO_yyoutput +#define yylex PROIO_yylex +#define yyerror PROIO_yyerror +#define yyleng PROIO_yyleng +#define yytext PROIO_yytext +#define yymorfg PROIO_yymorfg +#define yylineno PROIO_yylineno +#define yytchar PROIO_yytchar +#define yyin PROIO_yyin +#define yyout PROIO_yyout +#define yysvf PROIO_yysvf +#define yyestate PROIO_yyestate +#define yysvec PROIO_yysvec +#define yybgin PROIO_yybgin +#define yyprevious PROIO_yyprevious +#define yylhs PROIO_yylhs +#define yylen PROIO_yylen +#define yydefred PROIO_yydefred +#define yydgoto PROIO_yydgoto +#define yysindex PROIO_yysindex +#define yyrindex PROIO_yyrindex +#define yygindex PROIO_yygindex +#define yytable PROIO_yytable +#define yycheck PROIO_yycheck +#define yyname PROIO_yyname +#define yyrule PROIO_yyrule +#define yydebug PROIO_yydebug +#define yynerrs PROIO_yynerrs +#define yyerrflag PROIO_yyerrflag +#define yychar PROIO_yychar +#define yyvsp PROIO_yyvsp +#define yyssp PROIO_yyssp +#define yyval PROIO_yyval +#define yylval PROIO_yylval +#define yyss PROIO_yyss +#define yyvs PROIO_yyvs +#define yyparse PROIO_yyparse + +/* +++steve162e: more defines necessary */ +#define yy_init_buffer PROIO_yy_init_buffer +#define yy_create_buffer PROIO_yy_create_buffer +#define yy_load_buffer_state PROIO_yy_load_buffer_state +#define yyrestart PROIO_yyrestart +#define yy_switch_to_buffer PROIO_yy_switch_to_buffer +#define yy_delete_buffer PROIO_yy_delete_buffer +/* ---steve162e */ + +/* WG 1/96: still more for flex 2.5 */ +#define yy_scan_buffer PROIO_scan_buffer +#define yy_scan_string PROIO_scan_string +#define yy_scan_bytes PROIO_scan_bytes +#define yy_flex_debug PROIO_flex_debug +#define yy_flush_buffer PROIO_flush_buffer +#if !defined(__VISAGECPP__) +/* multiply defined??? */ +#define yyleng PROIO_yyleng +#define yytext PROIO_yytext +#endif + +extern "C" WXDLLEXPORT_DATA(FILE*) yyin; +extern "C" WXDLLEXPORT int yyparse(void); + + +wxExprDatabase *thewxExprDatabase = NULL; +wxExprErrorHandler currentwxExprErrorHandler; + +wxExpr::wxExpr(const wxString& functor) +{ + type = wxExprList; + next = NULL; + last = NULL; + value.first = NULL; + + wxExpr *pfunctor = new wxExpr(wxExprWord, functor); + Append(pfunctor); + client_data = NULL; +} + +wxExpr::wxExpr(wxExprType the_type, const wxString& word_or_string) +{ + type = the_type; + + switch (the_type) + { + case wxExprWord: + value.word = copystring((const wxChar *)word_or_string); + break; + case wxExprString: + value.string = copystring((const wxChar *)word_or_string); + break; + case wxExprList: + last = NULL; + value.first = NULL; + break; + case wxExprReal: + case wxExprInteger: + case wxExprNull: + break; + } + client_data = NULL; + next = NULL; +} + +wxExpr::wxExpr(wxExprType the_type, wxChar *word_or_string, bool allocate) +{ + type = the_type; + + switch (the_type) + { + case wxExprWord: + value.word = allocate ? copystring(word_or_string) : word_or_string; + break; + case wxExprString: + value.string = allocate ? copystring(word_or_string) : word_or_string; + break; + case wxExprList: + last = NULL; + value.first = NULL; + break; + case wxExprReal: + case wxExprInteger: + case wxExprNull: + break; + } + client_data = NULL; + next = NULL; +} + +wxExpr::wxExpr(long the_integer) +{ + type = wxExprInteger; + value.integer = the_integer; + client_data = NULL; + next = NULL; +} + +wxExpr::wxExpr(double the_real) +{ + type = wxExprReal; + value.real = the_real; + client_data = NULL; + next = NULL; +} + +wxExpr::wxExpr(wxList *the_list) +{ + type = wxExprList; + client_data = NULL; + last = NULL; + value.first = NULL; + + wxExpr *listExpr = new wxExpr(wxExprList); + + wxNode *node = the_list->GetFirst(); + while (node) + { + wxExpr *expr = (wxExpr *)node->GetData(); + listExpr->Append(expr); + node = node->GetNext(); + } + Append(listExpr); + + delete the_list; +} + +wxExpr::~wxExpr(void) +{ + switch (type) + { + case wxExprInteger: + case wxExprReal: + { + break; + } + case wxExprString: + { + delete[] value.string; + break; + } + case wxExprWord: + { + delete[] value.word; + break; + } + case wxExprList: + { + wxExpr *expr = value.first; + while (expr) + { + wxExpr *expr1 = expr->next; + + delete expr; + expr = expr1; + } + break; + } + case wxExprNull: break; + } +} + +void wxExpr::Append(wxExpr *expr) +{ + if (!value.first) + value.first = expr; + + if (last) + last->next = expr; + last = expr; +} + +void wxExpr::Insert(wxExpr *expr) +{ + expr->next = value.first; + value.first = expr; + + if (!last) + last = expr; +} + +wxExpr *wxExpr::Copy(void) const +{ + // This seems to get round an optimizer bug when + // using Watcom C++ 10a in WIN32 compilation mode. + // If these lines not present, the type seems to be + // interpreted wrongly as an integer. + // I don't want to turn optimization off since it's needed + // for reading in files quickly. +#if defined(__WATCOMC__) + char buf[2]; + sprintf(buf, ""); +#endif + + switch (type) + { + case wxExprInteger: + return new wxExpr(value.integer); + case wxExprReal: + return new wxExpr(value.real); + case wxExprString: + return new wxExpr(wxExprString, wxString(value.string)); + case wxExprWord: + return new wxExpr(wxExprWord, wxString(value.word)); + case wxExprList: + { + wxExpr *expr = value.first; + wxExpr *new_list = new wxExpr(wxExprList); + while (expr) + { + wxExpr *expr2 = expr->Copy(); + new_list->Append(expr2); + expr = expr->next; + } + return new_list; + } + case wxExprNull: + break; + } + return NULL; +} + + +// Get the wxExpr (containing (= wxExpr Value) form) for the given word +// or string, assuming that we have Attribute=Value, ... +wxExpr *wxExpr::GetAttributeValueNode(const wxString& word) const // Use only for a clause or list +{ + if (type != wxExprList) + return NULL; + + wxExpr *expr = value.first; + while (expr) + { + if (expr->type == wxExprList) + { + wxExpr *firstNode = expr->value.first; + if ((firstNode->type == wxExprWord) && (firstNode->value.word[0] == '=')) + { + wxExpr *secondNode = firstNode->next; + if ((secondNode->type == wxExprWord) && + (wxStrcmp((const wxChar *)word, secondNode->value.word) == 0)) + { + return expr; + } + } + } + expr = expr->next; + } + return NULL; +} + +// Get the value (in wxExpr form) for the given word or string, assuming +// that we have Attribute=Value, ... +wxExpr *wxExpr::AttributeValue(const wxString& word) const // Use only for a clause or list +{ + if (type != wxExprList) + return NULL; + + wxExpr *attExpr = GetAttributeValueNode(word); + if (attExpr && attExpr->value.first && attExpr->value.first->next) + return attExpr->value.first->next->next; + else return NULL; +} + +wxString wxExpr::Functor(void) const // Use only for a clause +{ + if ((type != wxExprList) || !value.first) + return wxString(wxT("")); + + if (value.first->type == wxExprWord) + return wxString(value.first->value.word); + else + return wxString(wxT("")); +} + +bool wxExpr::IsFunctor(const wxString& f) const // Use only for a clause +{ + if ((type != wxExprList) || !value.first) + return FALSE; + + return (value.first->type == wxExprWord && + (wxStrcmp((const wxChar *)f, value.first->value.word) == 0)); +} + +// Return nth argument of a clause (starting from 1) +wxExpr *wxExpr::Arg(wxExprType theType, int arg) const +{ + wxExpr *expr = value.first; + int i; + for (i = 1; i < arg; i++) + if (expr) + expr = expr->next; + + if (expr && (expr->type == theType)) + return expr; + else + return NULL; +} + +// Return nth argument of a list expression (starting from zero) +wxExpr *wxExpr::Nth(int arg) const +{ + if (type != wxExprList) + return NULL; + + wxExpr *expr = value.first; + int i; + for (i = 0; i < arg; i++) + if (expr) + expr = expr->next; + else return NULL; + + if (expr) + return expr; + else + return NULL; +} + + // Returns the number of elements in a list expression +int wxExpr::Number(void) const +{ + if (type != wxExprList) + return 0; + + int i = 0; + wxExpr *expr = value.first; + while (expr) + { + expr = expr->next; + i ++; + } + return i; +} + +void wxExpr::DeleteAttributeValue(const wxString& attribute) +{ + if (type != wxExprList) + return; + + wxExpr *expr = value.first; + wxExpr *lastExpr = this; + while (expr) + { + if (expr->type == wxExprList) + { + wxExpr *firstNode = expr->value.first; + if ((firstNode->type == wxExprWord) && (firstNode->value.word[0] == '=')) + { + wxExpr *secondNode = firstNode->next; + if ((secondNode->type == wxExprWord) && + (wxStrcmp((const wxChar *)attribute, secondNode->value.word) == 0)) + { + wxExpr *nextExpr = expr->next; + delete expr; + + lastExpr->next = nextExpr; + + if (last == expr) + last = lastExpr; + + return; + } + } + } + lastExpr = expr; + expr = expr->next; + } + return; +} + +void wxExpr::AddAttributeValue(const wxString& attribute, wxExpr *val) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + // Warning - existing code may assume that any existing value + // is deleted first. For efficiency, we leave this to the application. +// DeleteAttributeValue(attribute); + + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr = new wxExpr(wxExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(val); + + Append(listExpr); +} + +void wxExpr::AddAttributeValue(const wxString& attribute, long val) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + // Warning - existing code may assume that any existing value + // is deleted first. For efficiency, we leave this to the application. +// DeleteAttributeValue(attribute); + + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pval = new wxExpr(val); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr = new wxExpr(wxExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void wxExpr::AddAttributeValue(const wxString& attribute, double val) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + +// DeleteAttributeValue(attribute); + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pval = new wxExpr(val); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr = new wxExpr(wxExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void wxExpr::AddAttributeValueString(const wxString& attribute, const wxString& val) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + +// DeleteAttributeValue(attribute); + + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pval = new wxExpr(wxExprString, val); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr = new wxExpr(wxExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void wxExpr::AddAttributeValueWord(const wxString& attribute, const wxString& val) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + +// DeleteAttributeValue(attribute); + + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pval = new wxExpr(wxExprWord, val); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr = new wxExpr(wxExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void wxExpr::AddAttributeValue(const wxString& attribute, wxList *val) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + if (!val) + return; + +// DeleteAttributeValue(attribute); + + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pval = new wxExpr(val); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr = new wxExpr(wxExprList); + + listExpr->Append(pequals); + listExpr->Append(patt); + listExpr->Append(pval); + + Append(listExpr); +} + +void wxExpr::AddAttributeValueStringList(const wxString& attribute, wxList *string_list) +{ + if (type != wxExprList) + { +// cout << "Error! tried to add an attribute-value pair to a nonlist wxExpr expression\n"; + return; + } + if (!string_list) + return; + +// DeleteAttributeValue(attribute); + + // First make a list of wxExpr strings + wxExpr *listExpr = new wxExpr(wxExprList); + wxNode *node = string_list->GetFirst(); + while (node) + { + wxChar *string = (wxChar*)node->GetData(); + wxExpr *expr = new wxExpr(wxExprString, wxString(string)); + listExpr->Append(expr); + node = node->GetNext(); + } + + // Now make an (=, Att, Value) triple + wxExpr *patt = new wxExpr(wxExprWord, attribute); + wxExpr *pequals = new wxExpr(wxExprWord, wxT("=")); + + wxExpr *listExpr2 = new wxExpr(wxExprList); + + listExpr2->Append(pequals); + listExpr2->Append(patt); + listExpr2->Append(listExpr); + + Append(listExpr2); +} + +bool wxExpr::GetAttributeValue(const wxString& att, int& var) const +{ + wxExpr *expr = AttributeValue(att); + + if (expr && (expr->Type() == wxExprInteger || expr->Type() == wxExprReal)) + { + var = (int)(expr->IntegerValue()); + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValue(const wxString& att, long& var) const +{ + wxExpr *expr = AttributeValue(att); + + if (expr && (expr->Type() == wxExprInteger || expr->Type() == wxExprReal)) + { + var = expr->IntegerValue(); + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValue(const wxString& att, float& var) const +{ + wxExpr *expr = AttributeValue(att); + if (expr && (expr->Type() == wxExprInteger || expr->Type() == wxExprReal)) + { + var = (float) expr->RealValue(); + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValue(const wxString& att, double& var) const +{ + wxExpr *expr = AttributeValue(att); + if (expr && (expr->Type() == wxExprInteger || expr->Type() == wxExprReal)) + { + var = expr->RealValue(); + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValue(const wxString& att, wxString& var) const // Word OR string -> string +{ + wxExpr *expr = AttributeValue(att); + if (expr && expr->Type() == wxExprWord) + { + var = expr->WordValue(); + return TRUE; + } + else if (expr && expr->Type() == wxExprString) + { + var = expr->StringValue(); + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValue(const wxString& att, wxExpr **var) const +{ + wxExpr *expr = AttributeValue(att); + if (expr) + { + *var = expr; + return TRUE; + } + else + return FALSE; +} + +bool wxExpr::GetAttributeValueStringList(const wxString& att, wxList *var) const +{ + wxExpr *expr = AttributeValue(att); + if (expr && expr->Type() == wxExprList) + { + wxExpr *string_expr = expr->value.first; + while (string_expr) + { + if (string_expr->Type() == wxExprString) + var->Append((wxObject *)copystring(string_expr->StringValue())); + + string_expr = string_expr->next; + } + return TRUE; + } + else + return FALSE; +} + +// Compatibility +void wxExpr::AssignAttributeValue(wxChar *att, wxChar **var) const +{ + wxString str; + if (GetAttributeValue(att, str)) + { + if (*var) + delete[] *var; + *var = copystring((const wxChar *) str); + } +} + +void wxExpr::WriteClause(FILE* stream) // Write this expression as a top-level clause +{ + if (type != wxExprList) + return; + + wxExpr *node = value.first; + if (node) + { + node->WriteExpr(stream); + fprintf( stream, "(" ); + node = node->next; + bool first = TRUE; + while (node) + { + if (!first) + fprintf( stream, " " ); + node->WriteExpr(stream); + node = node->next; + if (node) + fprintf( stream, ",\n" ); + first = FALSE; + } + fprintf( stream, ").\n\n" ); + } +} + +void wxExpr::WriteExpr(FILE* stream) // Write as any other subexpression +{ + // This seems to get round an optimizer bug when + // using Watcom C++ 10a in WIN32 compilation mode. + // If these lines not present, the type seems to be + // interpreted wrongly as an integer. + // I don't want to turn optimization off since it's needed + // for reading in files quickly. +#if defined(__WATCOMC__) + char buf[2]; + sprintf(buf, ""); +#endif + + switch (type) + { + case wxExprInteger: + { + fprintf( stream, "%ld", value.integer ); + break; + } + case wxExprReal: + { + double f = value.real; + fprintf( stream, "%.6g", f); + break; + } + case wxExprString: + { + fprintf( stream, "\"" ); + size_t i; + const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.string); + size_t len = strlen(val); + for (i = 0; i < len; i++) + { + char ch = val[i]; + if (ch == '"' || ch == '\\') + fprintf( stream, "\\" ); + char tmp[2]; + tmp[0] = ch; + tmp[1] = 0; + fprintf( stream, tmp ); + } + fprintf( stream, "\"" ); + break; + } + case wxExprWord: + { + bool quote_it = FALSE; + const wxWX2MBbuf val = wxConvLibc.cWX2MB(value.word); + size_t len = strlen(val); + if ((len == 0) || (len > 0 && (val[(size_t) 0] > 64 && val[(size_t) 0] < 91))) + quote_it = TRUE; + else + { + size_t i; + for (i = 0; i < len; i++) + if ((!isalpha(val[i])) && (!isdigit(val[i])) && + (val[i] != '_')) + { quote_it = TRUE; i = len; } + } + + if (quote_it) + fprintf( stream ,"'" ); + + fprintf( stream, val ); + + if (quote_it) + fprintf( stream, "'" ); + + break; + } + case wxExprList: + { + if (!value.first) + fprintf( stream, "[]" ); + else + { + wxExpr *expr = value.first; + + if ((expr->Type() == wxExprWord) && (wxStrcmp(expr->WordValue(), wxT("=")) == 0)) + { + wxExpr *arg1 = expr->next; + wxExpr *arg2 = arg1->next; + arg1->WriteExpr(stream); + fprintf( stream, " = " ); + arg2->WriteExpr(stream); + } + else + { + fprintf( stream, "[" ); + while (expr) + { + expr->WriteExpr(stream); + expr = expr->next; + if (expr) + fprintf( stream, ", " ); + } + fprintf( stream, "]" ); + } + } + break; + } + case wxExprNull: break; + } +} + +/* + * wxExpr 'database' (list of expressions) + */ + +IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList) + +wxExprDatabase::wxExprDatabase(wxExprErrorHandler handler) +{ + position = NULL; + hash_table = NULL; + currentwxExprErrorHandler = handler; + noErrors = 0; +} + +wxExprDatabase::wxExprDatabase(wxExprType type, const wxString& attribute, int size, + wxExprErrorHandler handler) +{ + position = NULL; + attribute_to_hash = attribute; + if (type == wxExprString) + hash_table = new wxHashTable(wxKEY_STRING, size); + else if (type == wxExprInteger) + hash_table = new wxHashTable(wxKEY_INTEGER, size); + else hash_table = NULL; + + currentwxExprErrorHandler = handler; + noErrors = 0; +} + +wxExprDatabase::~wxExprDatabase(void) +{ + ClearDatabase(); + if (hash_table) + delete hash_table; +} + +void wxExprDatabase::BeginFind(void) // Initialise a search +{ + position = GetFirst(); +} + +wxExpr *wxExprDatabase::FindClause(long id) // Find a term based on an integer id attribute + // e.g. node(id=23, type=rectangle, ....). +{ + wxExpr *found = NULL; + while (position && !found) + { + wxExpr *term = (wxExpr *)position->GetData(); + + if (term->Type() == wxExprList) + { + wxExpr *value = term->AttributeValue(wxT("id")); + if (value->Type() == wxExprInteger && value->IntegerValue() == id) + found = term; + } + position = position->GetNext(); + } + return found; +} + +// Find on basis of attribute/value pairs, e.g. type=rectangle +wxExpr *wxExprDatabase::FindClause(const wxString& word, const wxString& val) +{ + wxExpr *found = NULL; + while (position && !found) + { + wxExpr *term = (wxExpr *)position->GetData(); + + if (term->Type() == wxExprList) + { + wxExpr *value = term->AttributeValue(word); + if ((value->Type() == wxExprWord && value->WordValue() == val) || + (value->Type() == wxExprString && value->StringValue() == val)) + found = term; + } + position = position->GetNext(); + } + return found; +} + +wxExpr *wxExprDatabase::FindClause(const wxString& word, long val) +{ + wxExpr *found = NULL; + while (position && !found) + { + wxExpr *term = (wxExpr *)position->GetData(); + + if (term->Type() == wxExprList) + { + wxExpr *value = term->AttributeValue(word); + if ((value->Type() == wxExprInteger) && (value->IntegerValue() == val)) + found = term; + } + position = position->GetNext(); + } + return found; +} + +wxExpr *wxExprDatabase::FindClause(const wxString& word, double val) +{ + wxExpr *found = NULL; + while (position && !found) + { + wxExpr *term = (wxExpr *)position->GetData(); + + if (term->Type() == wxExprList) + { + wxExpr *value = term->AttributeValue(word); + if ((value->Type() == wxExprReal) && (value->RealValue() == val)) + found = term; + } + position = position->GetNext(); + } + return found; +} + +wxExpr *wxExprDatabase::FindClauseByFunctor(const wxString& functor) +{ + wxExpr *found = NULL; + while (position && !found) + { + wxExpr *term = (wxExpr *)position->GetData(); + + if (term->Type() == wxExprList) + { + if (term->Functor() == functor) + found = term; + } + position = position->GetNext(); + } + return found; +} + +// If hashing is on, must store in hash table too +void wxExprDatabase::Append(wxExpr *clause) +{ + wxList::Append((wxObject *)clause); + if (hash_table) + { + wxString functor(clause->Functor()); + wxExpr *expr = clause->AttributeValue(attribute_to_hash); + if (expr) + { + long functor_key = hash_table->MakeKey(WXSTRINGCAST functor); + long value_key = 0; + if (expr && expr->Type() == wxExprString) + { + value_key = hash_table->MakeKey(WXSTRINGCAST expr->StringValue()); + hash_table->Put(functor_key + value_key, WXSTRINGCAST expr->StringValue(), (wxObject *)clause); + } + else if (expr && expr->Type() == wxExprInteger) + { + value_key = expr->IntegerValue(); + hash_table->Put(functor_key + value_key, expr->IntegerValue(), (wxObject *)clause); + } + + } + } +} + +wxExpr *wxExprDatabase::HashFind(const wxString& functor, long value) const +{ + long key = hash_table->MakeKey(WXSTRINGCAST functor) + value; + + // The key alone isn't guaranteed to be unique: + // must supply value too. Let's assume the value of the + // id is going to be reasonably unique. + return (wxExpr *)hash_table->Get(key, value); +} + +wxExpr *wxExprDatabase::HashFind(const wxString& functor, const wxString& value) const +{ + long key = hash_table->MakeKey(WXSTRINGCAST functor) + hash_table->MakeKey(WXSTRINGCAST value); + return (wxExpr *)hash_table->Get(key, WXSTRINGCAST value); +} + +void wxExprDatabase::ClearDatabase(void) +{ + noErrors = 0; + wxNode *node = GetFirst(); + while (node) + { + wxExpr *expr = (wxExpr *)node->GetData(); + delete expr; + delete node; + node = GetFirst(); + } + + if (hash_table) + hash_table->Clear(); +} + +bool wxExprDatabase::Read(const wxString& filename) +{ + noErrors = 0; + + FILE *f = wxFopen(filename, _T("r")); + if (f) + { + thewxExprDatabase = this; + + LexFromFile(f); + yyparse(); + fclose(f); + + wxExprCleanUp(); + return (noErrors == 0); + } + else + { + return FALSE; + } +} + +bool wxExprDatabase::ReadFromString(const wxString& buffer) +{ + noErrors = 0; + thewxExprDatabase = this; + + const wxWX2MBbuf buf = buffer.mb_str(); + LexFromString(wxMBSTRINGCAST buf); + yyparse(); + wxExprCleanUp(); + return (noErrors == 0); +} + +bool wxExprDatabase::Write(const wxString& fileName) +{ + FILE *stream = wxFopen( fileName, _T("w+")); + + if (!stream) + return FALSE; + + bool success = Write(stream); + fclose(stream); + return success; +} + +bool wxExprDatabase::Write(FILE *stream) +{ + noErrors = 0; + wxNode *node = GetFirst(); + while (node) + { + wxExpr *expr = (wxExpr *)node->GetData(); + expr->WriteClause(stream); + node = node->GetNext(); + } + return (noErrors == 0); +} + +void add_expr(wxExpr * expr) +{ + thewxExprDatabase->Append(expr); +} + +// Checks functor +bool wxExprIsFunctor(wxExpr *expr, const wxString& functor) +{ + if (expr && (expr->Type() == wxExprList)) + { + wxExpr *first_expr = expr->value.first; + + if (first_expr && (first_expr->Type() == wxExprWord) && + (first_expr->WordValue() == functor)) + return TRUE; + else + return FALSE; + } + else + return FALSE; +} + +/* + * Called from parser + * + */ + +char *wxmake_integer(char *str) +{ + wxExpr *x = new wxExpr(atol(str)); + + return (char *)x; +} + +char *wxmake_real(char *str1, char *str2) +{ + char buf[50]; + + sprintf(buf, "%s.%s", str1, str2); + double f = (double)atof(buf); + wxExpr *x = new wxExpr(f); + + return (char *)x; +} + +// extern "C" double exp10(double); + +char *wxmake_exp(char *str1, char *str2) +{ + double mantissa = (double)atoi(str1); + double exponent = (double)atoi(str2); + + double d = mantissa * pow(10.0, exponent); + + wxExpr *x = new wxExpr(d); + + return (char *)x; +} + +char *wxmake_exp2(char *str1, char *str2, char *str3) +{ + char buf[50]; + + sprintf(buf, "%s.%s", str1, str2); + double mantissa = (double)atof(buf); + double exponent = (double)atoi(str3); + + double d = mantissa * pow(10.0, exponent); + + wxExpr *x = new wxExpr(d); + + return (char *)x; +} + +char *wxmake_word(char *str) +{ + wxExpr *x = new wxExpr(wxExprWord, wxString(str, wxConvLibc).c_str()); + return (char *)x; +} + +char *wxmake_string(char *str) +{ + wxChar *s, *t; + size_t len, i; + const wxMB2WXbuf sbuf = wxConvLibc.cMB2WX(str); + +// str++; /* skip leading quote */ + len = wxStrlen(sbuf) - 1; /* ignore trailing quote */ + + s = new wxChar[len + 1]; + + t = s; + for(i=1; iInsert(car); + return (char *)cdr; +} + +void process_command(char * cexpr) +{ + wxExpr *expr = (wxExpr *)cexpr; + add_expr(expr); +} + +void syntax_error(char *WXUNUSED(s)) +{ + if (currentwxExprErrorHandler) + (void)(*(currentwxExprErrorHandler))(WXEXPR_ERROR_SYNTAX, (char *)"syntax error"); + if (thewxExprDatabase) thewxExprDatabase->noErrors += 1; +} + +#if 0 +#ifdef _WINDLL +// char *__cdecl strdup(const char *s) +WXDLLEXPORT char *strdup(const char *s) +{ + int len = strlen(s); + char *new_s = (char *)malloc(sizeof(char)*(len+1)); + strcpy(new_s, s); + return new_s; +} +#endif +#endif + +#endif + // wxUSE_PROLOGIO diff --git a/contrib/src/deprecated/y_tab.c b/contrib/src/deprecated/y_tab.c new file mode 100644 index 0000000000..5b34eceaf2 --- /dev/null +++ b/contrib/src/deprecated/y_tab.c @@ -0,0 +1,538 @@ +#if defined(__WIN32__) || defined(__GNUWIN32__) +/* all Win32 compilers can handle C++ comments, and C++ comments + is the only C++ in setup.h */ +#include "wx/setup.h" +#endif + +#if !defined(wxUSE_PROLOGIO) || wxUSE_PROLOGIO + +#ifndef lint +static char yysccsid[] = "@(#)yaccpar 1.7 (Berkeley) 09/09/90"; +#endif +#define YYBYACC 1 +#line 2 "parser.y" +#include "string.h" +#if defined(_MSC_VER) || defined(__VISAGECPP__) +#include +#endif +#include "wx/deprecated/expr.h" + +#ifndef __EXTERN_C__ +#define __EXTERN_C__ 1 +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +extern "C" { +#endif +#endif +int yylex(void); +int yylook(void); +int yywrap(void); +int yyback(int *, int); + +/* You may need to put /DLEX_SCANNER in your makefile + * if you're using LEX! + */ +#ifdef LEX_SCANNER +/* int yyoutput(int); */ +void yyoutput(int); +#else +void yyoutput(int); +#endif + +#if defined(__cplusplus) || defined(__STDC__) +#if defined(__cplusplus) && defined(__EXTERN_C__) +} +#endif +#endif +#line 36 "parser.y" +typedef union { + char *s; +/* struct pexpr *expr; */ +} YYSTYPE; +#line 44 "y_tab.c" +#define INTEGER 1 +#define WORD 2 +#define STRING 3 +#define PERIOD 13 +#define OPEN 4 +#define CLOSE 5 +#define COMMA 6 +#define NEWLINE 7 +#define ERROR 8 +#define OPEN_SQUARE 9 +#define CLOSE_SQUARE 10 +#define EQUALS 11 +#define EXP 14 +#define YYERRCODE 256 +short yylhs[] = { -1, + 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, + 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, +}; +short yylen[] = { 2, + 0, 2, 2, 2, 2, 4, 2, 3, 0, 1, + 3, 3, 1, 1, 1, 1, 3, 3, 5, 1, +}; +short yydefred[] = { 1, + 0, 0, 0, 0, 2, 0, 5, 3, 0, 0, + 0, 15, 7, 20, 0, 0, 13, 4, 0, 0, + 0, 0, 8, 0, 6, 0, 18, 0, 12, 11, + 0, 19, +}; +short yydgoto[] = { 1, + 5, 14, 15, 16, 17, +}; +short yysindex[] = { 0, + -2, 9, 2, 1, 0, 10, 0, 0, 11, -5, + 17, 0, 0, 0, 14, -1, 0, 0, 33, 38, + 41, 16, 0, 11, 0, 29, 0, 40, 0, 0, + 44, 0, +}; +short yyrindex[] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 42, 21, + 24, 0, 0, 0, 0, 30, 0, 0, 0, 0, + 0, 0, 0, 31, 0, 27, 0, 24, 0, 0, + 0, 0, +}; +short yygindex[] = { 0, + 0, 45, -8, 0, 26, +}; +#define YYTABLESIZE 254 +short yytable[] = { 3, + 19, 10, 11, 12, 24, 9, 4, 20, 21, 4, + 13, 10, 11, 12, 8, 30, 10, 28, 12, 4, + 9, 7, 18, 23, 4, 16, 16, 22, 14, 14, + 16, 17, 17, 14, 10, 9, 17, 25, 26, 10, + 9, 27, 31, 9, 32, 6, 9, 29, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, +}; +short yycheck[] = { 2, + 9, 1, 2, 3, 6, 4, 9, 13, 14, 9, + 10, 1, 2, 3, 13, 24, 1, 2, 3, 9, + 4, 13, 13, 10, 9, 5, 6, 11, 5, 6, + 10, 5, 6, 10, 5, 5, 10, 5, 1, 10, + 10, 1, 14, 4, 1, 1, 5, 22, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 256, +}; +#define YYFINAL 1 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 14 +#if YYDEBUG +char *yyname[] = { +"end-of-file","INTEGER","WORD","STRING","OPEN","CLOSE","COMMA","NEWLINE", +"ERROR","OPEN_SQUARE","CLOSE_SQUARE","EQUALS",0,"PERIOD","EXP", +}; +char *yyrule[] = { +"$accept : commands", +"commands :", +"commands : commands command", +"command : WORD PERIOD", +"command : expr PERIOD", +"command : error PERIOD", +"expr : WORD OPEN arglist CLOSE", +"expr : OPEN_SQUARE CLOSE_SQUARE", +"expr : OPEN_SQUARE arglist CLOSE_SQUARE", +"arglist :", +"arglist : arg", +"arglist : arg COMMA arglist", +"arg : WORD EQUALS arg1", +"arg : arg1", +"arg1 : WORD", +"arg1 : STRING", +"arg1 : INTEGER", +"arg1 : INTEGER PERIOD INTEGER", +"arg1 : INTEGER EXP INTEGER", +"arg1 : INTEGER PERIOD INTEGER EXP INTEGER", +"arg1 : expr", +}; +#endif +#define yyclearin (yychar=(-1)) +#define yyerrok (yyerrflag=0) +#ifdef YYSTACKSIZE +#ifndef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#endif +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 600 +#define YYMAXDEPTH 600 +#endif +#endif +int yydebug; +int yynerrs; +int yyerrflag; +int yychar; +short *yyssp; +YYSTYPE *yyvsp; +YYSTYPE yyval; +YYSTYPE yylval; +short yyss[YYSTACKSIZE]; +YYSTYPE yyvs[YYSTACKSIZE]; +#define yystacksize YYSTACKSIZE +#line 118 "parser.y" + +#ifdef IDE_INVOKED +#include "../common/doslex.c" +#else +#include "../common/lex_yy.c" +#endif + +/* +void yyerror(s) +char *s; +{ + syntax_error(s); +} +*/ + +/* Ansi prototype. If this doesn't work for you... uncomment + the above instead. + */ + +void yyerror(char *s) +{ + syntax_error(s); +} + +/* + * Unfortunately, my DOS version of FLEX + * requires yywrap to be #def'ed, whereas + * the UNIX flex expects a proper function. + */ + +/* Not sure if __SC__ is the appropriate thing + * to test + */ + +#ifndef __SC__ +#ifdef USE_DEFINE +#ifndef yywrap +#define yywrap() 1 +#endif +#else +# if !(defined(__VISAGECPP__) && __IBMC__ >= 400) +/* VA 4.0 thinks this is multiply defined (in lex_yy.c) */ + int yywrap() { return 1; } +# endif +#endif +#endif +#line 247 "y_tab.c" +#define YYABORT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab +int +PROIO_yyparse() +{ + register int yym, yyn, yystate; +#if YYDEBUG + register char *yys; + extern char *getenv(); + + yys = getenv("YYDEBUG"); + if (yys) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + + yynerrs = 0; + yyerrflag = 0; + yychar = (-1); + + yyssp = yyss; + yyvsp = yyvs; + *yyssp = yystate = 0; + +yyloop: + yyn = yydefred[yystate]; + if (yyn != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("yydebug: state %d, reading %d (%s)\n", yystate, + yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("yydebug: state %d, shifting to state %d\n", + yystate, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + yychar = (-1); + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; +#ifdef lint + goto yynewerror; +#endif +yynewerror: + yyerror("syntax error"); +#ifdef lint + goto yyerrlab; +#endif +yyerrlab: + ++yynerrs; +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("yydebug: state %d, error recovery shifting\ + to state %d\n", *yyssp, yytable[yyn]); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("yydebug: error recovery discarding state %d\n", + *yyssp); +#endif + if (yyssp <= yyss) goto yyabort; + --yyssp; + --yyvsp; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("yydebug: state %d, error recovery discards token %d (%s)\n", + yystate, yychar, yys); + } +#endif + yychar = (-1); + goto yyloop; + } +yyreduce: +#if YYDEBUG + if (yydebug) + printf("yydebug: state %d, reducing by rule %d (%s)\n", + yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + yyval = yyvsp[1-yym]; + switch (yyn) + { +case 3: +#line 68 "parser.y" +{process_command(proio_cons(wxmake_word(yyvsp[-1].s), NULL)); free(yyvsp[-1].s);} +break; +case 4: +#line 70 "parser.y" +{process_command(yyvsp[-1].s);} +break; +case 5: +#line 72 "parser.y" +{syntax_error("Unrecognized command.");} +break; +case 6: +#line 76 "parser.y" +{yyval.s = proio_cons(wxmake_word(yyvsp[-3].s), yyvsp[-1].s); free(yyvsp[-3].s);} +break; +case 7: +#line 78 "parser.y" +{yyval.s = proio_cons(NULL, NULL);} +break; +case 8: +#line 80 "parser.y" +{yyval.s = yyvsp[-1].s; } +break; +case 9: +#line 84 "parser.y" +{yyval.s = NULL;} +break; +case 10: +#line 86 "parser.y" +{yyval.s = proio_cons(yyvsp[0].s, NULL);} +break; +case 11: +#line 89 "parser.y" +{yyval.s = proio_cons(yyvsp[-2].s, yyvsp[0].s);} +break; +case 12: +#line 93 "parser.y" +{yyval.s = proio_cons(wxmake_word("="), proio_cons(wxmake_word(yyvsp[-2].s), proio_cons(yyvsp[0].s, NULL))); + free(yyvsp[-2].s); } +break; +case 13: +#line 96 "parser.y" +{yyval.s = yyvsp[0].s; } +break; +case 14: +#line 99 "parser.y" +{yyval.s = wxmake_word(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 15: +#line 101 "parser.y" +{yyval.s = wxmake_string(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 16: +#line 103 "parser.y" +{yyval.s = wxmake_integer(yyvsp[0].s); free(yyvsp[0].s);} +break; +case 17: +#line 105 "parser.y" +{yyval.s = wxmake_real(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); } +break; +case 18: +#line 107 "parser.y" +{yyval.s = wxmake_exp(yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-2].s); free(yyvsp[0].s); } +break; +case 19: +#line 110 "parser.y" +{yyval.s = wxmake_exp2(yyvsp[-4].s, yyvsp[-2].s, yyvsp[0].s); free(yyvsp[-4].s); free(yyvsp[-2].s); + free(yyvsp[0].s); } +break; +case 20: +#line 114 "parser.y" +{yyval.s = yyvsp[0].s;} +break; +#line 461 "y_tab.c" + } + yyssp -= yym; + yystate = *yyssp; + yyvsp -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("yydebug: after reduction, shifting from state 0 to\ + state %d\n", YYFINAL); +#endif + yystate = YYFINAL; + *++yyssp = YYFINAL; + *++yyvsp = yyval; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("yydebug: state %d, reading %d (%s)\n", + YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("yydebug: after reduction, shifting from state %d \ +to state %d\n", *yyssp, yystate); +#endif + if (yyssp >= yyss + yystacksize - 1) + { + goto yyoverflow; + } + *++yyssp = yystate; + *++yyvsp = yyval; + goto yyloop; +yyoverflow: + yyerror("yacc stack overflow"); +yyabort: + return (1); +yyaccept: + return (0); +} + +#endif /* wxUSE_PROLOGIO */ -- 2.45.2