* Fixes and new features in wxObject*Stream
* Fixes: wxChoice (GTK), wxCheckBox (GTK) * Fixes: wxStream * wxObject calls wx*Serialize::LoadObject/StoreObject in StoreObject/LoadObject * Added support for dynamic library (Linux only, Windows will follow) * Added serbase.h (Serialization base defines and base object) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@436 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
95
include/wx/dynlib.h
Normal file
95
include/wx/dynlib.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#ifndef __DYNLIB_H__
|
||||
#define __DYNLIB_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <wx/string.h>
|
||||
#include <wx/list.h>
|
||||
#include <wx/dynarray.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Some more info on a class
|
||||
|
||||
typedef struct {
|
||||
wxClassInfo *class_info;
|
||||
wxString path;
|
||||
} wxClassLibInfo;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Useful arrays
|
||||
|
||||
WX_DEFINE_ARRAY(wxClassInfo *, wxArrayClassInfo);
|
||||
WX_DEFINE_ARRAY(wxClassLibInfo *, wxArrayClassLibInfo);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxClassLibrary
|
||||
|
||||
class wxClassLibrary {
|
||||
protected:
|
||||
wxArrayClassLibInfo m_list;
|
||||
public:
|
||||
wxClassLibrary(void);
|
||||
~wxClassLibrary(void);
|
||||
|
||||
// Dynamic (un)register a (new) class in the database
|
||||
void RegisterClass(wxClassInfo *class_info, const wxString& path);
|
||||
void UnregisterClass(wxClassInfo *class_info);
|
||||
|
||||
// Fetch all infos whose name matches the string (wildcards allowed)
|
||||
bool FetchInfos(const wxString& path, wxArrayClassLibInfo& infos);
|
||||
|
||||
// Create all objects whose name matches the string (wildcards allowed)
|
||||
bool CreateObjects(const wxString& path, wxArrayClassInfo& objs);
|
||||
|
||||
// Create one object using the EXACT name
|
||||
wxObject *CreateObject(const wxString& path);
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxLibrary
|
||||
|
||||
class wxLibrary: public wxObject {
|
||||
protected:
|
||||
wxClassLibrary *m_liblist;
|
||||
void *m_handle;
|
||||
public:
|
||||
wxLibrary(void *handle);
|
||||
~wxLibrary(void);
|
||||
|
||||
// Get a symbol from the dynamic library
|
||||
void *GetSymbol(const wxString& symbname);
|
||||
|
||||
// Create the object whose classname is "name"
|
||||
wxObject *CreateObject(const wxString& name);
|
||||
|
||||
wxClassLibrary *ClassLib() const;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxLibraries
|
||||
|
||||
class wxLibraries {
|
||||
protected:
|
||||
wxList m_loaded;
|
||||
public:
|
||||
wxLibraries(void);
|
||||
~wxLibraries(void);
|
||||
|
||||
wxLibrary *LoadLibrary(const wxString& name);
|
||||
wxObject *CreateObject(const wxString& name);
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global variables
|
||||
|
||||
extern wxLibraries wxTheLibraries;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Interesting defines
|
||||
|
||||
#define WXDLL_ENTRY_FUNCTION() extern "C" wxClassLibrary *GetClassList()
|
||||
#define WXDLL_EXIT_FUNCTION(param) extern "C" void FreeClassList(wxClassLibrary *param)
|
||||
|
||||
#endif
|
@@ -179,8 +179,8 @@ class WXDLLEXPORT wxObject
|
||||
#endif
|
||||
|
||||
#ifdef USE_STORABLE_CLASSES
|
||||
virtual void StoreObject( wxObjectOutputStream &WXUNUSED(stream) ) {};
|
||||
virtual void LoadObject( wxObjectInputStream &WXUNUSED(stream) ) {};
|
||||
virtual void StoreObject( wxObjectOutputStream &stream );
|
||||
virtual void LoadObject( wxObjectInputStream &stream );
|
||||
#endif
|
||||
|
||||
// make a 'clone' of the object
|
||||
|
@@ -23,9 +23,9 @@
|
||||
class wxObjectStreamInfo : public wxObject {
|
||||
public:
|
||||
wxString object_name;
|
||||
int n_children;
|
||||
int n_children, children_removed;
|
||||
wxList children;
|
||||
wxObject *parent;
|
||||
wxObjectStreamInfo *parent;
|
||||
wxObject *object;
|
||||
};
|
||||
|
||||
@@ -56,7 +56,9 @@ class wxObjectInputStream : public wxFilterInputStream {
|
||||
wxObjectInputStream(wxInputStream& s);
|
||||
|
||||
wxObject *GetChild(int no) const;
|
||||
wxObject *GetParent() const { return m_current_info->parent; }
|
||||
int NumberOfChildren() const { return m_current_info->n_children; }
|
||||
void RemoveChildren(int nb);
|
||||
wxObject *GetParent() const;
|
||||
wxObject *LoadObject();
|
||||
|
||||
wxObject *SolveName(const wxString& objName) const;
|
||||
|
57
include/wx/serbase.h
Normal file
57
include/wx/serbase.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: serbase.h
|
||||
// Purpose: Serialization plug-ins
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: July 1998
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __WX_SERBASEH_H__
|
||||
#define __WX_SERBASEH_H__
|
||||
|
||||
#include <wx/dynlib.h>
|
||||
|
||||
#define WXSERIAL(classname) classname##_Serialize
|
||||
|
||||
class wxObject_Serialize : public wxObject {
|
||||
DECLARE_DYNAMIC_CLASS(wxObject_Serialize)
|
||||
public:
|
||||
wxObject_Serialize() {}
|
||||
virtual ~wxObject_Serialize() {}
|
||||
|
||||
void SetObject(wxObject *obj) { m_object = obj; }
|
||||
wxObject *Object() { return m_object; }
|
||||
|
||||
protected:
|
||||
wxObject *m_object;
|
||||
};
|
||||
|
||||
|
||||
#define DECLARE_SERIAL_CLASS(classname, parent) \
|
||||
class WXSERIAL(classname) : public WXSERIAL(parent) { \
|
||||
DECLARE_DYNAMIC_CLASS(classname##_Serialize) \
|
||||
public: \
|
||||
WXSERIAL(classname)() { } \
|
||||
virtual ~WXSERIAL(classname)() { } \
|
||||
\
|
||||
virtual void StoreObject(wxObjectOutputStream& stream); \
|
||||
virtual void LoadObject(wxObjectInputStream& stream); \
|
||||
};
|
||||
|
||||
#define DECLARE_ALIAS_SERIAL_CLASS(classname, parent) \
|
||||
class WXSERIAL(classname) : public WXSERIAL(parent) { \
|
||||
DECLARE_DYNAMIC_CLASS(classname##_Serialize) \
|
||||
public: \
|
||||
WXSERIAL(classname)() { } \
|
||||
virtual ~WXSERIAL(classname)() { } \
|
||||
};
|
||||
|
||||
#define IMPLEMENT_SERIAL_CLASS(classname, parent) \
|
||||
IMPLEMENT_DYNAMIC_CLASS(classname##_Serialize, parent##_Serialize)
|
||||
|
||||
#define IMPLEMENT_ALIAS_SERIAL_CLASS(classname, parent) \
|
||||
IMPLEMENT_DYNAMIC_CLASS(classname##_Serialize, parent##_Serialize)
|
||||
|
||||
#endif
|
@@ -78,8 +78,8 @@ class WXDLLEXPORT wxInputStream {
|
||||
wxInputStream& Read(wxOutputStream& stream_out);
|
||||
|
||||
// Position functions
|
||||
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
off_t TellI() const;
|
||||
virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
virtual off_t TellI() const;
|
||||
|
||||
// State functions
|
||||
bool Eof() const { return m_eof; }
|
||||
@@ -174,6 +174,7 @@ class WXDLLEXPORT wxFilterInputStream: public wxInputStream {
|
||||
|
||||
virtual bool Eof() const { return m_parent_i_stream->Eof(); }
|
||||
virtual size_t LastRead() const { return m_parent_i_stream->LastRead(); }
|
||||
virtual off_t TellI() const { return m_parent_i_stream->TellI(); }
|
||||
|
||||
protected:
|
||||
virtual size_t DoRead(void *buffer, size_t size);
|
||||
@@ -191,9 +192,9 @@ class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
|
||||
|
||||
virtual bool Bad() const { return m_parent_o_stream->Bad(); }
|
||||
virtual size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
|
||||
virtual off_t TellO() const { return m_parent_o_stream->TellO(); }
|
||||
|
||||
protected:
|
||||
|
||||
// The forward is implicitely done by wxStreamBuffer.
|
||||
|
||||
virtual size_t DoWrite(const void *buffer, size_t size);
|
||||
|
637
install/gtk/configure
vendored
637
install/gtk/configure
vendored
File diff suppressed because it is too large
Load Diff
@@ -502,15 +502,13 @@ dnl ##########################
|
||||
dnl ##### Threads #####
|
||||
USE_THREADS=1
|
||||
THREADS_LINK=""
|
||||
UNIX_THREAD=""
|
||||
UNIX_THREAD="gtk/threadno.cpp"
|
||||
|
||||
AC_ARG_WITH(threads,
|
||||
[ --without-threads Force disabling threads ],
|
||||
[USE_THREADS="$withval"])
|
||||
|
||||
if test "$USE_THREADS" = "1"; then
|
||||
UNIX_THREAD="gtk/threadno.cpp"
|
||||
|
||||
dnl For glibc 2 users who have the old libc 5 too
|
||||
|
||||
AC_CHECK_LIB(pthread-0.7, pthread_create, [
|
||||
@@ -529,9 +527,12 @@ if test "$USE_THREADS" = "1"; then
|
||||
THREADS_LINK="-lpthreads"
|
||||
AC_DEFINE(USE_THREADS)
|
||||
])
|
||||
AC_CHECK_HEADER(sys/prctl.h, [
|
||||
UNIX_THREAD="gtk/threadsgi.cpp"
|
||||
AC_DEFINE(USE_THREADS)
|
||||
dnl Two levels
|
||||
AC_CHECK_FUNC(sproc, [
|
||||
AC_CHECK_HEADER(sys/prctl.h, [
|
||||
UNIX_THREAD="gtk/threadsgi.cpp"
|
||||
AC_DEFINE(USE_THREADS)
|
||||
])
|
||||
])
|
||||
fi
|
||||
|
||||
@@ -695,7 +696,6 @@ DEFAULT_USE_MEM_TRACING=0
|
||||
DEFAULT_USE_ZLIB=1
|
||||
DEFAULT_USE_GDK_IMLIB=1
|
||||
DEFAULT_USE_LIBPNG=1
|
||||
DEFAULT_USE_ODBC=1
|
||||
|
||||
DEFAULT_USE_APPLE_IEEE=1
|
||||
DEFAULT_USE_STORABLE_CLASSES=1
|
||||
@@ -777,10 +777,6 @@ AC_OVERRIDES(libpng,libpng,
|
||||
**--with-libpng use libpng (PNG image format),
|
||||
USE_LIBPNG)
|
||||
|
||||
AC_OVERRIDES(odbc,odbc,
|
||||
**--with-odbc use iODBC,
|
||||
USE_ODBC)
|
||||
|
||||
AC_OVERRIDES(opengl,opengl,
|
||||
**--with-opengl use opengl (OpenGL or Mesa),
|
||||
USE_OPENGL)
|
||||
@@ -926,11 +922,6 @@ if test "$USE_LIBPNG" = 1 ; then
|
||||
LIBPNG="LIBPNG"
|
||||
fi
|
||||
|
||||
ODBC=NONE
|
||||
if test "$USE_ODBC" = 1 ; then
|
||||
ODBC="ODBC"
|
||||
fi
|
||||
|
||||
APPLE_IEEE=NONE
|
||||
if test "$USE_APPLE_IEEE" = 1 ; then
|
||||
APPLE_IEEE="APPLE_IEEE"
|
||||
@@ -951,7 +942,7 @@ fi
|
||||
|
||||
WXDEBUG=
|
||||
if test "$USE_DEBUG_INFO" = 1 ; then
|
||||
WXDEBUG="-g -O0"
|
||||
WXDEBUG="-g"
|
||||
fi
|
||||
AC_SUBST(WXDEBUG)
|
||||
|
||||
@@ -963,7 +954,7 @@ fi
|
||||
|
||||
if test "$USE_MEM_TRACING" = 1 ; then
|
||||
AC_DEFINE_UNQUOTED(USE_MEMORY_TRACING,$USE_MEM_TRACING)
|
||||
dnl AC_DEFINE_UNQUOTED(USE_GLOBAL_MEMORY_OPERATORS,$USE_MEM_TRACING)
|
||||
AC_DEFINE_UNQUOTED(USE_GLOBAL_MEMORY_OPERATORS,$USE_MEM_TRACING)
|
||||
fi
|
||||
|
||||
PROFILE=
|
||||
@@ -1201,14 +1192,6 @@ AC_SUBST(GUI_TK_LINK)
|
||||
AC_SUBST(TOOLKIT)
|
||||
AC_SUBST(TOOLKIT_DEF)
|
||||
|
||||
dnl ----------------------------------------------------------------
|
||||
dnl select dynamic loader (used by iODBC to load drivers)
|
||||
dnl ----------------------------------------------------------------
|
||||
|
||||
DL_LIBRARY=-ldl
|
||||
|
||||
AC_SUBST(DL_LIBRARY)
|
||||
|
||||
dnl ----------------------------------------------------------------
|
||||
dnl search for opengl
|
||||
dnl ----------------------------------------------------------------
|
||||
@@ -1364,15 +1347,11 @@ dnl AC_SUBST(LIBPNG_LIBRARY)
|
||||
dnl AC_SUBST(LIBPNG_LINK)
|
||||
|
||||
dnl ----------------------------------------------------------------
|
||||
dnl search for iODBC
|
||||
dnl search for Python
|
||||
dnl ----------------------------------------------------------------
|
||||
dnl
|
||||
if test "$USE_ODBC" = 1; then
|
||||
AC_DEFINE_UNQUOTED(USE_ODBC,$USE_ODBC)
|
||||
fi
|
||||
|
||||
dnl ----------------------------------------------------------------
|
||||
dnl search for Python
|
||||
dnl search for ODBC
|
||||
dnl ----------------------------------------------------------------
|
||||
|
||||
dnl ----------------------------------------------------------------
|
||||
|
@@ -130,6 +130,8 @@ LIB_CPP_SRC=\
|
||||
generic/tabg.cpp \
|
||||
generic/textdlgg.cpp \
|
||||
generic/treectrl.cpp
|
||||
|
||||
# common/dynlib.cpp Disabled until I write support for DLL on all platforms
|
||||
|
||||
LIB_C_SRC=\
|
||||
common/extended.c \
|
||||
|
228
src/common/dynlib.cpp
Normal file
228
src/common/dynlib.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dynlib.cpp
|
||||
// Purpose: Dynamic library management
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 20/07/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dynlib.h"
|
||||
#endif
|
||||
|
||||
#include <wx/dynlib.h>
|
||||
#include <wx/filefn.h>
|
||||
#include <wx/list.h>
|
||||
#include <wx/string.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// System dependent include
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#ifdef linux
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global variables
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxLibraries wxTheLibraries;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxLibrary (one instance per dynamic library
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxLibrary::wxLibrary(void *handle)
|
||||
{
|
||||
typedef wxClassLibrary *(*t_get_list)(void);
|
||||
t_get_list get_list;
|
||||
|
||||
m_handle = handle;
|
||||
|
||||
get_list = (t_get_list)GetSymbol("GetClassList");
|
||||
m_liblist = (*get_list)();
|
||||
}
|
||||
|
||||
wxLibrary::~wxLibrary()
|
||||
{
|
||||
if (m_handle) {
|
||||
typedef void (*t_free_list)(wxClassLibrary *);
|
||||
t_free_list free_list;
|
||||
|
||||
free_list = (t_free_list) GetSymbol("FreeClassList");
|
||||
if (free_list != NULL)
|
||||
free_list(m_liblist);
|
||||
else
|
||||
delete m_liblist;
|
||||
|
||||
dlclose(m_handle);
|
||||
}
|
||||
}
|
||||
|
||||
wxObject *wxLibrary::CreateObject(const wxString& name)
|
||||
{
|
||||
return m_liblist->CreateObject(name);
|
||||
}
|
||||
|
||||
void *wxLibrary::GetSymbol(const wxString& symbname)
|
||||
{
|
||||
#ifdef linux
|
||||
return dlsym(m_handle, symbname.GetData());
|
||||
#endif
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxLibraries (only one instance should normally exist)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxLibraries::wxLibraries()
|
||||
{
|
||||
}
|
||||
|
||||
wxLibraries::~wxLibraries()
|
||||
{
|
||||
wxNode *node = m_loaded.First();
|
||||
|
||||
while (node) {
|
||||
wxLibrary *lib = (wxLibrary *)node->Data();
|
||||
delete lib;
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
wxLibrary *wxLibraries::LoadLibrary(const wxString& name)
|
||||
{
|
||||
wxString lib_name = name;
|
||||
wxNode *node;
|
||||
wxLibrary *lib;
|
||||
|
||||
if ( (node = m_loaded.Find(name.GetData())) )
|
||||
return ((wxLibrary *)node->Data());
|
||||
|
||||
#ifdef linux
|
||||
lib_name.Prepend("./lib");
|
||||
lib_name += ".so";
|
||||
|
||||
printf("lib_name = %s\n", WXSTRINGCAST lib_name);
|
||||
|
||||
void *handle = dlopen(lib_name.GetData(), RTLD_LAZY);
|
||||
|
||||
printf("handle = %x\n", handle);
|
||||
lib = new wxLibrary(handle);
|
||||
|
||||
#endif
|
||||
#ifdef __WINDOWS__
|
||||
lib_name += ".dll";
|
||||
|
||||
#endif
|
||||
|
||||
m_loaded.Append(name.GetData(), lib);
|
||||
return lib;
|
||||
}
|
||||
|
||||
wxObject *wxLibraries::CreateObject(const wxString& path)
|
||||
{
|
||||
wxNode *node = m_loaded.First();
|
||||
wxObject *obj;
|
||||
|
||||
while (node) {
|
||||
obj = ((wxLibrary *)node->Data())->CreateObject(path);
|
||||
if (obj)
|
||||
return obj;
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxClassLibrary (this class is used to access the internal class)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxClassLibrary::wxClassLibrary(void)
|
||||
{
|
||||
}
|
||||
|
||||
wxClassLibrary::~wxClassLibrary(void)
|
||||
{
|
||||
uint i;
|
||||
|
||||
for (i=0;i<m_list.Count();i++)
|
||||
delete (m_list[i]);
|
||||
}
|
||||
|
||||
void wxClassLibrary::RegisterClass(wxClassInfo *class_info,
|
||||
const wxString& path)
|
||||
{
|
||||
wxClassLibInfo *info = new wxClassLibInfo;
|
||||
|
||||
info->class_info = class_info;
|
||||
info->path = path;
|
||||
m_list.Add(info);
|
||||
}
|
||||
|
||||
void wxClassLibrary::UnregisterClass(wxClassInfo *class_info)
|
||||
{
|
||||
uint i = 0;
|
||||
|
||||
while (i < m_list.Count()) {
|
||||
if (m_list[i]->class_info == class_info) {
|
||||
delete (m_list[i]);
|
||||
m_list.Remove(i);
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxClassLibrary::CreateObjects(const wxString& path,
|
||||
wxArrayClassInfo& objs)
|
||||
{
|
||||
wxClassLibInfo *info;
|
||||
uint i = 0;
|
||||
|
||||
while (i < m_list.Count()) {
|
||||
info = m_list[i];
|
||||
if (wxMatchWild(path, info->path))
|
||||
objs.Add(info->class_info);
|
||||
i++;
|
||||
}
|
||||
return (i > 0);
|
||||
}
|
||||
|
||||
bool wxClassLibrary::FetchInfos(const wxString& path,
|
||||
wxArrayClassLibInfo& infos)
|
||||
{
|
||||
wxClassLibInfo *info;
|
||||
uint i = 0;
|
||||
|
||||
while (i < m_list.Count()) {
|
||||
info = m_list[i];
|
||||
if (wxMatchWild(path, info->path)) {
|
||||
wxClassLibInfo *inf = new wxClassLibInfo;
|
||||
*inf = *info;
|
||||
infos.Add(inf);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (i > 0);
|
||||
}
|
||||
|
||||
wxObject *wxClassLibrary::CreateObject(const wxString& path)
|
||||
{
|
||||
wxClassLibInfo *info;
|
||||
uint i = 0;
|
||||
|
||||
while (i < m_list.Count()) {
|
||||
info = m_list[i];
|
||||
if (wxMatchWild(path, info->path))
|
||||
return info->class_info->CreateObject();
|
||||
i++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
@@ -23,8 +23,6 @@
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#define BUF_TEMP_SIZE 10000
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileInputStream
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -46,7 +44,10 @@ char wxFileInputStream::Peek()
|
||||
|
||||
size_t wxFileInputStream::DoRead(void *buffer, size_t size)
|
||||
{
|
||||
return wxFile::Read(buffer, size);
|
||||
size_t ret = wxFile::Read(buffer, size);
|
||||
m_eof = wxFile::Eof();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
|
||||
|
@@ -221,12 +221,57 @@ wxObject *wxCreateDynamicObject(char *name)
|
||||
|
||||
#ifdef USE_STORABLE_CLASSES
|
||||
|
||||
#include "wx/serbase.h"
|
||||
#include "wx/dynlib.h"
|
||||
#include "wx/msgdlg.h"
|
||||
|
||||
wxObject* wxCreateStoredObject( wxInputStream &stream )
|
||||
{
|
||||
wxObjectInputStream obj_s(stream);
|
||||
return obj_s.LoadObject();
|
||||
};
|
||||
|
||||
void wxObject::StoreObject( wxObjectOutputStream& stream )
|
||||
{
|
||||
wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
|
||||
wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
|
||||
WXSERIAL(wxObject) *serial =
|
||||
(WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
|
||||
|
||||
if (!serial) {
|
||||
wxString message;
|
||||
|
||||
message.Printf("Can't find the serialization object (%s) for the object %s",
|
||||
WXSTRINGCAST obj_name, WXSTRINGCAST GetClassInfo()->GetClassName());
|
||||
wxMessageBox(message, "Alert !");
|
||||
return;
|
||||
}
|
||||
|
||||
serial->SetObject(this);
|
||||
serial->StoreObject(stream);
|
||||
}
|
||||
|
||||
void wxObject::LoadObject( wxObjectInputStream& stream )
|
||||
{
|
||||
wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
|
||||
wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
|
||||
WXSERIAL(wxObject) *serial =
|
||||
(WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
|
||||
|
||||
if (!serial) {
|
||||
wxString message;
|
||||
|
||||
message.Printf("Can't find the serialization object (%s) for the object %s",
|
||||
WXSTRINGCAST obj_name,
|
||||
WXSTRINGCAST GetClassInfo()->GetClassName());
|
||||
wxMessageBox(message, "Alert !");
|
||||
return;
|
||||
}
|
||||
|
||||
serial->SetObject(this);
|
||||
serial->LoadObject(stream);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#define WXOBJ_BEGIN "OBEGIN"
|
||||
#define WXOBJ_BEG_LEN 6
|
||||
|
||||
#define TAG_EMPTY_OBJECT "NULL"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxObjectOutputStream
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -42,8 +44,15 @@ void wxObjectOutputStream::WriteObjectDef(wxObjectStreamInfo& info)
|
||||
wxDataOutputStream data_s(*this);
|
||||
|
||||
Write(WXOBJ_BEGIN, WXOBJ_BEG_LEN);
|
||||
data_s.WriteString(info.object->GetClassInfo()->GetClassName());
|
||||
|
||||
if (info.object) {
|
||||
data_s.WriteString(info.object->GetClassInfo()->GetClassName());
|
||||
} else {
|
||||
data_s.WriteString(TAG_EMPTY_OBJECT);
|
||||
}
|
||||
|
||||
data_s.WriteString(GetObjectName(info.object));
|
||||
|
||||
// I assume an object will not have millions of children
|
||||
data_s.Write8(info.children.Number());
|
||||
}
|
||||
@@ -58,7 +67,7 @@ void wxObjectOutputStream::AddChild(wxObject *obj)
|
||||
info = new wxObjectStreamInfo;
|
||||
info->n_children = 0;
|
||||
info->object = obj;
|
||||
info->parent = m_current_info->object; // Not useful here.
|
||||
info->parent = m_current_info; // Not useful here.
|
||||
m_current_info->n_children++;
|
||||
m_current_info->children.Append(info);
|
||||
}
|
||||
@@ -69,7 +78,8 @@ void wxObjectOutputStream::ProcessObjectDef(wxObjectStreamInfo *info)
|
||||
|
||||
m_current_info = info;
|
||||
// First stage: get children of obj
|
||||
info->object->StoreObject(*this);
|
||||
if (info->object)
|
||||
info->object->StoreObject(*this);
|
||||
|
||||
// Prepare and write the sub-entry about the child obj.
|
||||
WriteObjectDef(*info);
|
||||
@@ -88,7 +98,8 @@ void wxObjectOutputStream::ProcessObjectData(wxObjectStreamInfo *info)
|
||||
|
||||
m_current_info = info;
|
||||
|
||||
info->object->StoreObject(*this);
|
||||
if (info->object)
|
||||
info->object->StoreObject(*this);
|
||||
|
||||
while (node) {
|
||||
ProcessObjectData((wxObjectStreamInfo *)node->Data());
|
||||
@@ -145,24 +156,54 @@ wxObject *wxObjectInputStream::SolveName(const wxString& name) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxObject *wxObjectInputStream::GetParent() const
|
||||
{
|
||||
if (!m_current_info->parent)
|
||||
return NULL;
|
||||
|
||||
return m_current_info->parent->object;
|
||||
}
|
||||
|
||||
wxObject *wxObjectInputStream::GetChild(int no) const
|
||||
{
|
||||
return m_current_info->children.Nth(no);
|
||||
wxNode *node = m_current_info->children.Nth(m_current_info->children_removed+no);
|
||||
wxObjectStreamInfo *info;
|
||||
|
||||
if (!node)
|
||||
return NULL;
|
||||
|
||||
info = (wxObjectStreamInfo *)node->Data();
|
||||
|
||||
return info->object;
|
||||
}
|
||||
|
||||
void wxObjectInputStream::RemoveChildren(int nb)
|
||||
{
|
||||
m_current_info->children_removed += nb;
|
||||
}
|
||||
|
||||
bool wxObjectInputStream::ReadObjectDef(wxObjectStreamInfo *info)
|
||||
{
|
||||
wxDataInputStream data_s(*this);
|
||||
char sig[WXOBJ_BEG_LEN+1];
|
||||
wxString class_name;
|
||||
|
||||
Read(sig, WXOBJ_BEG_LEN);
|
||||
sig[WXOBJ_BEG_LEN] = 0;
|
||||
if (wxString(sig) != WXOBJ_BEGIN)
|
||||
return FALSE;
|
||||
info->object = wxCreateDynamicObject( WXSTRINGCAST data_s.ReadString());
|
||||
|
||||
class_name = data_s.ReadString();
|
||||
printf("class_name = %s\n", WXSTRINGCAST class_name);
|
||||
if (class_name == TAG_EMPTY_OBJECT)
|
||||
info->object = NULL;
|
||||
else
|
||||
info->object = wxCreateDynamicObject( WXSTRINGCAST class_name);
|
||||
info->object_name = data_s.ReadString();
|
||||
printf("object_name = %s\n", WXSTRINGCAST info->object_name);
|
||||
info->n_children = data_s.Read8();
|
||||
info->children = wxList();
|
||||
info->children_removed = 0;
|
||||
printf("n_children = %d\n", info->n_children);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -198,10 +239,10 @@ void wxObjectInputStream::ProcessObjectData(wxObjectStreamInfo *info)
|
||||
|
||||
m_current_info = info;
|
||||
|
||||
info->object->LoadObject(*this);
|
||||
if (info->object)
|
||||
info->object->LoadObject(*this);
|
||||
while (node) {
|
||||
c_info = (wxObjectStreamInfo *)node->Data();
|
||||
c_info->object->LoadObject(*this);
|
||||
ProcessObjectData((wxObjectStreamInfo *)node->Data());
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
@@ -202,12 +202,14 @@ wxInputStream::wxInputStream()
|
||||
{
|
||||
m_i_destroybuf = TRUE;
|
||||
m_i_streambuf = new wxStreamBuffer(*this);
|
||||
m_eof = FALSE;
|
||||
}
|
||||
|
||||
wxInputStream::wxInputStream(wxStreamBuffer *buffer)
|
||||
{
|
||||
m_i_destroybuf = FALSE;
|
||||
m_i_streambuf = buffer;
|
||||
m_eof = FALSE;
|
||||
}
|
||||
|
||||
wxInputStream::~wxInputStream()
|
||||
|
@@ -59,6 +59,8 @@ bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label
|
||||
|
||||
PreCreation( parent, id, pos, size, style, name );
|
||||
|
||||
SetLabel( label );
|
||||
|
||||
m_widget = gtk_check_button_new_with_label( label );
|
||||
|
||||
wxSize newSize = size;
|
||||
|
@@ -179,9 +179,9 @@ wxString wxChoice::GetStringSelection(void) const
|
||||
|
||||
int wxChoice::Number(void) const
|
||||
{
|
||||
GtkMenu *menu = GTK_MENU( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
|
||||
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
|
||||
int count = 0;
|
||||
GList *child = menu->children;
|
||||
GList *child = menu_shell->children;
|
||||
while (child)
|
||||
{
|
||||
count++;
|
||||
|
@@ -59,6 +59,8 @@ bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label
|
||||
|
||||
PreCreation( parent, id, pos, size, style, name );
|
||||
|
||||
SetLabel( label );
|
||||
|
||||
m_widget = gtk_check_button_new_with_label( label );
|
||||
|
||||
wxSize newSize = size;
|
||||
|
@@ -179,9 +179,9 @@ wxString wxChoice::GetStringSelection(void) const
|
||||
|
||||
int wxChoice::Number(void) const
|
||||
{
|
||||
GtkMenu *menu = GTK_MENU( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
|
||||
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
|
||||
int count = 0;
|
||||
GList *child = menu->children;
|
||||
GList *child = menu_shell->children;
|
||||
while (child)
|
||||
{
|
||||
count++;
|
||||
|
Reference in New Issue
Block a user