* wxThread: new functions: wxThread::Pause/Resume, wxThread::GetThreadFromID

* Updates and new objects in utils/serialize
* wxLayout*_Serialize are friends of wxLayout* (so I can access to the
internal fields)
* wxMenu (GTK):  SetTitle/GetTitle (basic implementation)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@592 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux 1998-08-18 17:22:15 +00:00
parent c86f1403c3
commit c2dd8380ba
21 changed files with 569 additions and 37 deletions

View File

@ -127,6 +127,9 @@ public:
wxMenu( const wxString& title = wxEmptyString, const wxFunction func = NULL );
// operations
// title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// menu creation
void AppendSeparator();
void Append(int id, const wxString &item,

View File

@ -127,6 +127,9 @@ public:
wxMenu( const wxString& title = wxEmptyString, const wxFunction func = NULL );
// operations
// title
void SetTitle(const wxString& label);
const wxString GetTitle() const;
// menu creation
void AppendSeparator();
void Append(int id, const wxString &item,

View File

@ -48,6 +48,9 @@ class WXDLLEXPORT wxIndividualLayoutConstraint: public wxObject
DECLARE_DYNAMIC_CLASS(wxIndividualLayoutConstraint)
protected:
// To be allowed to modify the internal variables
friend class wxIndividualLayoutConstraint_Serialize;
// 'This' window is the parent or sibling of otherWin
wxWindow *otherWin;

View File

@ -9,8 +9,8 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_THREADH__
#define _WX_THREADH__
#ifndef __THREADH__
#define __THREADH__
#ifdef __GNUG__
#pragma interface "thread.h"
@ -30,7 +30,8 @@ typedef enum {
THREAD_NO_ERROR=0, // No error
THREAD_NO_RESOURCE, // No resource left to create a new thread
THREAD_RUNNING, // The thread is already running
THREAD_NOT_RUNNING // The thread isn't running
THREAD_NOT_RUNNING, // The thread isn't running
THREAD_MISC_ERROR // Some other error
} wxThreadError;
// defines the interval of priority.
@ -40,7 +41,7 @@ typedef enum {
// ---------------------------------------------------------------------------
// Mutex handler
class wxMutexInternal;
class WXDLLEXPORT wxMutexInternal;
class WXDLLEXPORT wxMutex {
public:
// constructor & destructor
@ -100,6 +101,12 @@ public:
// Destroys the thread immediately if the defer flag isn't true.
wxThreadError Destroy();
// Pause a running thread
wxThreadError Pause();
// Resume a paused thread
wxThreadError Resume();
// Switches on the defer flag.
void DeferDestroy(bool on);
@ -117,11 +124,16 @@ public:
// Returns true if the thread is alive.
bool IsAlive() const;
// Returns true if the thread is running (not paused, not killed).
bool IsRunning() const;
// Returns true if the thread is the main thread (aka the GUI thread).
static bool IsMain();
// Called when thread exits.
virtual void OnExit();
// Returns the wxThread object which corresponds to the ID.
static wxThread *GetThreadFromID(unsigned long id);
protected:
// In case, the DIFFER flag is true, enables another thread to kill this one.
void TestDestroy();

View File

@ -243,6 +243,17 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
}
}
void wxMenu::SetTitle( const wxString& title )
{
// Waiting for something better.
m_title = title;
}
const wxString wxMenu::GetTitle() const
{
return m_title;
}
void wxMenu::AppendSeparator()
{
wxMenuItem *mitem = new wxMenuItem();

View File

@ -89,7 +89,17 @@ wxThreadError wxThread::Create()
wxThreadError wxThread::Destroy()
{
return THREAD_RUNNING;
return THREAD_NOT_RUNNING;
}
wxThreadError wxThread::Pause()
{
return THREAD_NOT_RUNNING;
}
wxThreadError wxThread::Resume()
{
return THREAD_NOT_RUNNING;
}
void wxThread::DeferDestroy( bool WXUNUSED(on) )
@ -115,6 +125,11 @@ bool wxThread::IsMain()
return TRUE;
}
bool wxThread::IsRunning() const
{
return FALSE;
}
bool wxThread::IsAlive() const
{
return FALSE;

View File

@ -23,6 +23,8 @@
enum thread_state {
STATE_IDLE = 0,
STATE_RUNNING,
STATE_PAUSING,
STATE_PAUSED,
STATE_CANCELED,
STATE_EXITED
};
@ -32,6 +34,9 @@ enum thread_state {
/////////////////////////////////////////////////////////////////////////////
static pthread_t p_mainid;
static wxMutex p_list_mutex;
static wxList p_threads_list;
wxMutex wxMainMutex; // controls access to all GUI functions
/////////////////////////////////////////////////////////////////////////////
@ -157,14 +162,29 @@ public:
pthread_t thread_id;
int state;
int prio;
int defer_destroy;
int id;
};
void *wxThreadInternal::PthreadStart(void *ptr)
{
wxThread *thread = (wxThread *)ptr;
// Add the current thread to the list
p_list_mutex.Lock();
thread->p_internal->id = p_threads_list.Number();
p_threads_list.Append((wxObject *)thread);
p_list_mutex.Unlock();
// Call the main entry
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
void* status = thread->Entry();
// Delete the current thread from the list
p_list_mutex.Lock();
delete node_thread;
p_list_mutex.Unlock();
thread->Exit(status);
return NULL;
@ -200,6 +220,7 @@ wxThreadError wxThread::Create()
return THREAD_NO_RESOURCE;
}
pthread_attr_destroy(&a);
return THREAD_NO_ERROR;
}
@ -237,6 +258,27 @@ wxThreadError wxThread::Destroy()
if (res == 0)
p_internal->state = STATE_CANCELED;
}
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
if (p_internal->state != STATE_RUNNING)
return THREAD_NOT_RUNNING;
if (!p_internal->defer_destroy)
return THREAD_MISC_ERROR;
p_internal->state = STATE_PAUSING;
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
if (p_internal->state == STATE_PAUSING || p_internal->state == STATE_PAUSED)
p_internal->state = STATE_RUNNING;
return THREAD_NO_ERROR;
}
@ -255,6 +297,11 @@ void *wxThread::Join()
pthread_join(p_internal->thread_id, &status);
if (do_unlock)
wxMainMutex.Lock();
p_list_mutex.Lock();
delete p_threads_list.Nth(p_internal->id);
p_list_mutex.Unlock();
p_internal->state = STATE_IDLE;
}
return status;
@ -262,7 +309,16 @@ void *wxThread::Join()
unsigned long wxThread::GetID() const
{
return (unsigned long)p_internal->thread_id;
return p_internal->id;
}
wxThread *wxThread::GetThreadFromID(unsigned long id)
{
wxNode *node = p_threads_list.Nth(id);
if (!node)
return NULL;
return (wxThread *)node->Data();
}
void wxThread::Exit(void *status)
@ -276,6 +332,13 @@ void wxThread::Exit(void *status)
void wxThread::TestDestroy()
{
if (p_internal->state == STATE_PAUSING) {
p_internal->state = STATE_PAUSED;
while (p_internal->state == STATE_PAUSED) {
pthread_testcancel();
usleep(1);
}
}
pthread_testcancel();
}
@ -284,6 +347,18 @@ bool wxThread::IsMain()
return (bool)pthread_equal(pthread_self(), p_mainid);
}
bool wxThread::IsRunning() const
{
return (p_internal->state == STATE_RUNNING);
}
bool wxThread::IsAlive() const
{
return (p_internal->state == STATE_RUNNING) ||
(p_internal->state == STATE_PAUSING) ||
(p_internal->state == STATE_PAUSED);
}
wxThread::wxThread()
{
p_internal = new wxThreadInternal();
@ -299,6 +374,7 @@ wxThread::~wxThread()
// The default callback just joins the thread and throws away the result.
void wxThread::OnExit()
{
Join();
}
// Automatic initialization
@ -308,6 +384,7 @@ public:
virtual bool OnInit() {
wxThreadGuiInit();
p_mainid = pthread_self();
p_threads_list = wxList(wxKEY_INTEGER);
wxMainMutex.Lock();
return TRUE;

View File

@ -141,10 +141,22 @@ wxThreadError wxThread::Create()
return THREAD_NO_ERROR;
}
void wxThread::Destroy()
wxThreadError wxThread::Destroy()
{
if (p_internal->state == STATE_RUNNING)
p_internal->state = STATE_CANCELED;
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
return THREAD_NO_ERROR;
}
void *wxThread::Join()
@ -188,11 +200,21 @@ int wxThread::GetPriority() const
return 0;
}
bool wxThreadIsMain()
bool wxThread::IsMain()
{
return (int)getpid() == main_id;
}
bool wxThread::IsAlive() const
{
return (p_internal->state == STATE_RUNNING);
}
bool wxThread::IsRunning() const
{
return (p_internal->state == STATE_RUNNING);
}
wxThread::wxThread()
{
p_internal = new wxThreadPrivate();

View File

@ -243,6 +243,17 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func )
}
}
void wxMenu::SetTitle( const wxString& title )
{
// Waiting for something better.
m_title = title;
}
const wxString wxMenu::GetTitle() const
{
return m_title;
}
void wxMenu::AppendSeparator()
{
wxMenuItem *mitem = new wxMenuItem();

View File

@ -89,7 +89,17 @@ wxThreadError wxThread::Create()
wxThreadError wxThread::Destroy()
{
return THREAD_RUNNING;
return THREAD_NOT_RUNNING;
}
wxThreadError wxThread::Pause()
{
return THREAD_NOT_RUNNING;
}
wxThreadError wxThread::Resume()
{
return THREAD_NOT_RUNNING;
}
void wxThread::DeferDestroy( bool WXUNUSED(on) )
@ -115,6 +125,11 @@ bool wxThread::IsMain()
return TRUE;
}
bool wxThread::IsRunning() const
{
return FALSE;
}
bool wxThread::IsAlive() const
{
return FALSE;

View File

@ -23,6 +23,8 @@
enum thread_state {
STATE_IDLE = 0,
STATE_RUNNING,
STATE_PAUSING,
STATE_PAUSED,
STATE_CANCELED,
STATE_EXITED
};
@ -32,6 +34,9 @@ enum thread_state {
/////////////////////////////////////////////////////////////////////////////
static pthread_t p_mainid;
static wxMutex p_list_mutex;
static wxList p_threads_list;
wxMutex wxMainMutex; // controls access to all GUI functions
/////////////////////////////////////////////////////////////////////////////
@ -157,14 +162,29 @@ public:
pthread_t thread_id;
int state;
int prio;
int defer_destroy;
int id;
};
void *wxThreadInternal::PthreadStart(void *ptr)
{
wxThread *thread = (wxThread *)ptr;
// Add the current thread to the list
p_list_mutex.Lock();
thread->p_internal->id = p_threads_list.Number();
p_threads_list.Append((wxObject *)thread);
p_list_mutex.Unlock();
// Call the main entry
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
void* status = thread->Entry();
// Delete the current thread from the list
p_list_mutex.Lock();
delete node_thread;
p_list_mutex.Unlock();
thread->Exit(status);
return NULL;
@ -200,6 +220,7 @@ wxThreadError wxThread::Create()
return THREAD_NO_RESOURCE;
}
pthread_attr_destroy(&a);
return THREAD_NO_ERROR;
}
@ -237,6 +258,27 @@ wxThreadError wxThread::Destroy()
if (res == 0)
p_internal->state = STATE_CANCELED;
}
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
if (p_internal->state != STATE_RUNNING)
return THREAD_NOT_RUNNING;
if (!p_internal->defer_destroy)
return THREAD_MISC_ERROR;
p_internal->state = STATE_PAUSING;
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
if (p_internal->state == STATE_PAUSING || p_internal->state == STATE_PAUSED)
p_internal->state = STATE_RUNNING;
return THREAD_NO_ERROR;
}
@ -255,6 +297,11 @@ void *wxThread::Join()
pthread_join(p_internal->thread_id, &status);
if (do_unlock)
wxMainMutex.Lock();
p_list_mutex.Lock();
delete p_threads_list.Nth(p_internal->id);
p_list_mutex.Unlock();
p_internal->state = STATE_IDLE;
}
return status;
@ -262,7 +309,16 @@ void *wxThread::Join()
unsigned long wxThread::GetID() const
{
return (unsigned long)p_internal->thread_id;
return p_internal->id;
}
wxThread *wxThread::GetThreadFromID(unsigned long id)
{
wxNode *node = p_threads_list.Nth(id);
if (!node)
return NULL;
return (wxThread *)node->Data();
}
void wxThread::Exit(void *status)
@ -276,6 +332,13 @@ void wxThread::Exit(void *status)
void wxThread::TestDestroy()
{
if (p_internal->state == STATE_PAUSING) {
p_internal->state = STATE_PAUSED;
while (p_internal->state == STATE_PAUSED) {
pthread_testcancel();
usleep(1);
}
}
pthread_testcancel();
}
@ -284,6 +347,18 @@ bool wxThread::IsMain()
return (bool)pthread_equal(pthread_self(), p_mainid);
}
bool wxThread::IsRunning() const
{
return (p_internal->state == STATE_RUNNING);
}
bool wxThread::IsAlive() const
{
return (p_internal->state == STATE_RUNNING) ||
(p_internal->state == STATE_PAUSING) ||
(p_internal->state == STATE_PAUSED);
}
wxThread::wxThread()
{
p_internal = new wxThreadInternal();
@ -299,6 +374,7 @@ wxThread::~wxThread()
// The default callback just joins the thread and throws away the result.
void wxThread::OnExit()
{
Join();
}
// Automatic initialization
@ -308,6 +384,7 @@ public:
virtual bool OnInit() {
wxThreadGuiInit();
p_mainid = pthread_self();
p_threads_list = wxList(wxKEY_INTEGER);
wxMainMutex.Lock();
return TRUE;

View File

@ -141,10 +141,22 @@ wxThreadError wxThread::Create()
return THREAD_NO_ERROR;
}
void wxThread::Destroy()
wxThreadError wxThread::Destroy()
{
if (p_internal->state == STATE_RUNNING)
p_internal->state = STATE_CANCELED;
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
return THREAD_NO_ERROR;
}
void *wxThread::Join()
@ -188,11 +200,21 @@ int wxThread::GetPriority() const
return 0;
}
bool wxThreadIsMain()
bool wxThread::IsMain()
{
return (int)getpid() == main_id;
}
bool wxThread::IsAlive() const
{
return (p_internal->state == STATE_RUNNING);
}
bool wxThread::IsRunning() const
{
return (p_internal->state == STATE_RUNNING);
}
wxThread::wxThread()
{
p_internal = new wxThreadPrivate();

View File

@ -89,7 +89,17 @@ wxThreadError wxThread::Create()
wxThreadError wxThread::Destroy()
{
return THREAD_RUNNING;
return THREAD_NOT_RUNNING;
}
wxThreadError wxThread::Pause()
{
return THREAD_NOT_RUNNING;
}
wxThreadError wxThread::Resume()
{
return THREAD_NOT_RUNNING;
}
void wxThread::DeferDestroy( bool WXUNUSED(on) )
@ -110,11 +120,21 @@ unsigned long wxThread::GetID() const
return 0;
}
wxThread *wxThread::GetThreadFromID(unsigned long WXUNUSED(id)) const
{
return NULL;
}
bool wxThread::IsMain()
{
return TRUE;
}
bool wxThread::IsRunning() const
{
return FALSE;
}
bool wxThread::IsAlive() const
{
return FALSE;

View File

@ -23,6 +23,8 @@
enum thread_state {
STATE_IDLE = 0,
STATE_RUNNING,
STATE_PAUSING,
STATE_PAUSED,
STATE_CANCELED,
STATE_EXITED
};
@ -32,6 +34,9 @@ enum thread_state {
/////////////////////////////////////////////////////////////////////////////
static pthread_t p_mainid;
static wxMutex p_list_mutex;
static wxList p_threads_list;
wxMutex wxMainMutex; // controls access to all GUI functions
/////////////////////////////////////////////////////////////////////////////
@ -157,14 +162,29 @@ public:
pthread_t thread_id;
int state;
int prio;
int defer_destroy;
int id;
};
void *wxThreadInternal::PthreadStart(void *ptr)
{
wxThread *thread = (wxThread *)ptr;
// Add the current thread to the list
p_list_mutex.Lock();
thread->p_internal->id = p_threads_list.Number();
p_threads_list.Append((wxObject *)thread);
p_list_mutex.Unlock();
// Call the main entry
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
void* status = thread->Entry();
// Delete the current thread from the list
p_list_mutex.Lock();
delete node_thread;
p_list_mutex.Unlock();
thread->Exit(status);
return NULL;
@ -200,6 +220,7 @@ wxThreadError wxThread::Create()
return THREAD_NO_RESOURCE;
}
pthread_attr_destroy(&a);
return THREAD_NO_ERROR;
}
@ -237,6 +258,27 @@ wxThreadError wxThread::Destroy()
if (res == 0)
p_internal->state = STATE_CANCELED;
}
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
if (p_internal->state != STATE_RUNNING)
return THREAD_NOT_RUNNING;
if (!p_internal->defer_destroy)
return THREAD_MISC_ERROR;
p_internal->state = STATE_PAUSING;
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
if (p_internal->state == STATE_PAUSING || p_internal->state == STATE_PAUSED)
p_internal->state = STATE_RUNNING;
return THREAD_NO_ERROR;
}
@ -255,6 +297,11 @@ void *wxThread::Join()
pthread_join(p_internal->thread_id, &status);
if (do_unlock)
wxMainMutex.Lock();
p_list_mutex.Lock();
delete p_threads_list.Nth(p_internal->id);
p_list_mutex.Unlock();
p_internal->state = STATE_IDLE;
}
return status;
@ -262,7 +309,16 @@ void *wxThread::Join()
unsigned long wxThread::GetID() const
{
return (unsigned long)p_internal->thread_id;
return p_internal->id;
}
wxThread *wxThread::GetThreadFromID(unsigned long id)
{
wxNode *node = p_threads_list.Nth(id);
if (!node)
return NULL;
return (wxThread *)node->Data();
}
void wxThread::Exit(void *status)
@ -276,6 +332,13 @@ void wxThread::Exit(void *status)
void wxThread::TestDestroy()
{
if (p_internal->state == STATE_PAUSING) {
p_internal->state = STATE_PAUSED;
while (p_internal->state == STATE_PAUSED) {
pthread_testcancel();
usleep(1);
}
}
pthread_testcancel();
}
@ -284,6 +347,18 @@ bool wxThread::IsMain()
return (bool)pthread_equal(pthread_self(), p_mainid);
}
bool wxThread::IsRunning() const
{
return (p_internal->state == STATE_RUNNING);
}
bool wxThread::IsAlive() const
{
return (p_internal->state == STATE_RUNNING) ||
(p_internal->state == STATE_PAUSING) ||
(p_internal->state == STATE_PAUSED);
}
wxThread::wxThread()
{
p_internal = new wxThreadInternal();
@ -299,6 +374,7 @@ wxThread::~wxThread()
// The default callback just joins the thread and throws away the result.
void wxThread::OnExit()
{
Join();
}
// Automatic initialization
@ -308,6 +384,7 @@ public:
virtual bool OnInit() {
wxThreadGuiInit();
p_mainid = pthread_self();
p_threads_list = wxList(wxKEY_INTEGER);
wxMainMutex.Lock();
return TRUE;

View File

@ -141,10 +141,22 @@ wxThreadError wxThread::Create()
return THREAD_NO_ERROR;
}
void wxThread::Destroy()
wxThreadError wxThread::Destroy()
{
if (p_internal->state == STATE_RUNNING)
p_internal->state = STATE_CANCELED;
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
return THREAD_NO_ERROR;
}
void *wxThread::Join()
@ -188,11 +200,21 @@ int wxThread::GetPriority() const
return 0;
}
bool wxThreadIsMain()
bool wxThread::IsMain()
{
return (int)getpid() == main_id;
}
bool wxThread::IsAlive() const
{
return (p_internal->state == STATE_RUNNING);
}
bool wxThread::IsRunning() const
{
return (p_internal->state == STATE_RUNNING);
}
wxThread::wxThread()
{
p_internal = new wxThreadPrivate();

View File

@ -143,6 +143,18 @@ wxThreadError wxThread::Destroy()
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Pause()
{
// TODO
return THREAD_NO_ERROR;
}
wxThreadError wxThread::Resume()
{
// TODO
return THREAD_NO_ERROR;
}
void wxThread::Exit(void *status)
{
// TODO
@ -181,6 +193,24 @@ unsigned long wxThread::GetID() const
return 0;
}
wxThread *wxThread::GetThreadFromID(unsigned long id)
{
// TODO
return NULL;
}
bool wxThread::IsAlive() const
{
// TODO
return FALSE;
}
bool wxThread::IsRunning() const
{
// TODO
return FALSE;
}
bool wxThread::IsMain()
{
// TODO

View File

@ -25,6 +25,7 @@
#include <wx/radiobox.h>
#include <wx/stattext.h>
#include <wx/combobox.h>
#include <wx/imaglist.h>
#include <wx/objstrm.h>
#include <wx/datstrm.h>
#include <wx/serbase.h>
@ -57,7 +58,7 @@ void WXSERIAL(wxButton)::LoadObject(wxObjectInputStream& s)
printf("label = %s\n", WXSTRINGCAST m_label);
button->Create(m_parent, m_id, m_label, wxPoint(m_x, m_y), wxSize(m_w, m_h),
m_style, m_name);
m_style, *m_validator, m_name);
}
void WXSERIAL(wxCheckBox)::StoreObject(wxObjectOutputStream& s)
@ -79,7 +80,7 @@ void WXSERIAL(wxCheckBox)::LoadObject(wxObjectInputStream& s)
wxCheckBox *chkbox = (wxCheckBox *)Object();
chkbox->Create(m_parent, m_id, m_label, wxPoint(m_x, m_y), wxSize(m_w, m_h),
m_style, m_name);
m_style, *m_validator, m_name);
chkbox->SetValue(data_s.Read8());
}
@ -118,7 +119,7 @@ void WXSERIAL(wxSlider)::LoadObject(wxObjectInputStream& s)
value = data_s.Read32();
slider->Create(m_parent, m_id, value, min, max, wxPoint(m_x, m_y),
wxSize(m_w, m_h), m_style, m_name);
wxSize(m_w, m_h), m_style, *m_validator, m_name);
slider->SetTickFreq( 0, data_s.Read32() );
slider->SetPageSize( data_s.Read32() );
@ -155,7 +156,7 @@ void WXSERIAL(wxGauge)::LoadObject(wxObjectInputStream& s)
range = data_s.Read32();
gauge->Create(m_parent, m_id, range, wxPoint(m_x, m_y), wxSize(m_w, m_h),
m_style, m_name);
m_style, *m_validator, m_name);
gauge->SetShadowWidth( data_s.Read8() );
gauge->SetBezelFace( data_s.Read8() );
@ -187,7 +188,7 @@ void WXSERIAL(wxChoice)::LoadObject(wxObjectInputStream& s)
int i,num = data_s.Read32();
choice->Create(m_parent, m_id, wxPoint(m_x, m_y), wxSize(m_w, m_h), 0, NULL,
m_style, m_name);
m_style, *m_validator, m_name);
for (i=0;i<num;i++)
choice->Append( data_s.ReadString() );
@ -224,26 +225,33 @@ void WXSERIAL(wxListBox)::LoadObject(wxObjectInputStream& s)
void WXSERIAL(wxNotebook)::StoreObject(wxObjectOutputStream& s)
{
wxNotebook *notebook = (wxNotebook *)Object();
wxImageList *imaglist = notebook->GetImageList();
int i, pcount = notebook->GetPageCount();
WXSERIAL(wxControl)::StoreObject(s);
if (s.FirstStage()) {
// Don't know how to retrieve images from wxImageList (copy to a DC ?)
s.AddChild(imaglist);
WXSERIAL(wxControl)::StoreObject(s);
return;
}
wxDataOutputStream data_s(s);
data_s.Write8( pcount );
WXSERIAL(wxControl)::StoreObject(s);
for (i=0;i<pcount;i++)
data_s.WriteString( notebook->GetPageText(i) );
}
void WXSERIAL(wxNotebook)::LoadObject(wxObjectInputStream& s)
{
wxNotebook *notebook = (wxNotebook *)Object();
int i, pcount;
wxImageList *imaglist;
imaglist = (wxImageList *)s.GetChild(0);
s.RemoveChildren(1);
WXSERIAL(wxControl)::LoadObject(s);
@ -293,7 +301,7 @@ void WXSERIAL(wxRadioBox)::LoadObject(wxObjectInputStream& s)
items[i] = data_s.ReadString();
box->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), wxSize(m_w, m_h),
n_items, items, 0, m_style, m_name);
n_items, items, 0, m_style, *m_validator, m_name);
}
void WXSERIAL(wxComboBox)::StoreObject(wxObjectOutputStream& s)
@ -326,7 +334,7 @@ void WXSERIAL(wxComboBox)::LoadObject(wxObjectInputStream& s)
int i, num, selection;
box->Create(m_parent, m_id, wxEmptyString, wxPoint(m_x, m_y), wxSize(m_w, m_h),
0, NULL, m_style, m_name);
0, NULL, m_style, *m_validator, m_name);
num = data_s.Read8();
selection = data_s.Read8();

View File

@ -20,6 +20,7 @@
#include <wx/pen.h>
#include <wx/brush.h>
#include <wx/serbase.h>
#include <wx/imaglist.h>
#include "sergdi.h"
IMPLEMENT_SERIAL_CLASS(wxBitmap, wxObject)
@ -28,6 +29,7 @@ IMPLEMENT_SERIAL_CLASS(wxColour, wxGDIObject)
IMPLEMENT_SERIAL_CLASS(wxFont, wxGDIObject)
IMPLEMENT_SERIAL_CLASS(wxPen, wxGDIObject)
IMPLEMENT_SERIAL_CLASS(wxBrush, wxGDIObject)
IMPLEMENT_SERIAL_CLASS(wxImageList, wxObject)
IMPLEMENT_ALIAS_SERIAL_CLASS(wxPenList, wxList)
IMPLEMENT_ALIAS_SERIAL_CLASS(wxBrushList, wxList)
@ -200,3 +202,29 @@ void WXSERIAL(wxFont)::LoadObject(wxObjectInputStream& s)
*font = wxFont(psize, face_name, family, style, weight, underlined);
}
void WXSERIAL(wxImageList)::StoreObject(wxObjectOutputStream& s)
{
wxImageList *list = (wxImageList *)Object();
int i;
if (s.FirstStage()) {
for (i=0;i<list->GetImageCount();i++)
s.AddChild(list->GetBitmap(i));
}
wxDataOutputStream data_s(s);
data_s.Write32(list->GetImageCount());
}
void WXSERIAL(wxImageList)::LoadObject(wxObjectInputStream& s)
{
int i, count;
wxImageList *list = (wxImageList *)Object();
wxDataInputStream data_s(s);
count = data_s.Read32();
for (i=0;i<count;i++)
list->Add(*((wxBitmap *)s.GetChild(i)));
}

View File

@ -25,6 +25,7 @@ DECLARE_SERIAL_CLASS(wxColour, wxGDIObject)
DECLARE_SERIAL_CLASS(wxFont, wxGDIObject)
DECLARE_SERIAL_CLASS(wxPen, wxGDIObject)
DECLARE_SERIAL_CLASS(wxBrush, wxGDIObject)
DECLARE_SERIAL_CLASS(wxImageList, wxObject)
//DECLARE_SERIAL_CLASS(wxSize, wxObject)
//DECLARE_SERIAL_CLASS(wxRealPoint, wxObject)

View File

@ -22,19 +22,26 @@
#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/menu.h>
#include <wx/dialog.h>
#include <wx/serbase.h>
#include <wx/statusbr.h>
#include <wx/mdi.h>
#include "serwnd.h"
IMPLEMENT_SERIAL_CLASS(wxWindow, wxObject)
IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint, wxObject)
IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints, wxObject)
IMPLEMENT_ALIAS_SERIAL_CLASS(wxValidator, wxObject)
IMPLEMENT_SERIAL_CLASS(wxFrame, wxWindow)
IMPLEMENT_SERIAL_CLASS(wxPanel, wxWindow)
//IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow)
IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow)
IMPLEMENT_SERIAL_CLASS(wxMenuBar, wxWindow)
IMPLEMENT_SERIAL_CLASS(wxMenuItem, wxObject)
IMPLEMENT_SERIAL_CLASS(wxMenu, wxObject)
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxWindow)::StoreObject(wxObjectOutputStream& s)
{
wxWindow *win_object = (wxWindow *)Object();
@ -42,8 +49,13 @@ void WXSERIAL(wxWindow)::StoreObject(wxObjectOutputStream& s)
if (s.FirstStage()) {
s.AddChild(win_object->GetConstraints());
// s.AddChild(&(win_object->GetDefaultBackgroundColour()));
// s.AddChild(&(win_object->GetDefaultForegroundColour()));
s.AddChild(win_object->GetValidator());
// BAD HACK, but I don't have access to the internal variable of wxWindow.
m_bg_colour = win_object->GetDefaultBackgroundColour();
m_fg_colour = win_object->GetDefaultForegroundColour();
s.AddChild(&m_bg_colour);
s.AddChild(&m_fg_colour);
s.AddChild(win_object->GetFont());
while (node) {
s.AddChild(node->Data());
@ -95,15 +107,16 @@ void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s)
/* I assume we will never create raw wxWindow object */
// This will be done by wxLayoutConstraints, as we need an initialized object.
// win_object->SetConstraints((wxLayoutConstraints *)s.GetChild(0));
// win_object->SetDefaultBackgroundColour(*((wxColour *)s.GetChild(1)));
// win_object->SetDefaultForegroundColour(*((wxColour *)s.GetChild(2)));
win_object->SetFont(*((wxFont *)s.GetChild(1)));
m_validator = (wxValidator *)s.GetChild(1);
win_object->SetDefaultBackgroundColour(*((wxColour *)s.GetChild(2)));
win_object->SetDefaultForegroundColour(*((wxColour *)s.GetChild(3)));
win_object->SetFont(*((wxFont *)s.GetChild(4)));
return;
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxIndividualLayoutConstraint)::StoreObject
(wxObjectOutputStream& s)
{
@ -141,6 +154,8 @@ void WXSERIAL(wxIndividualLayoutConstraint)::
lay_object->otherEdge = (wxEdge)data_s.Read8();
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxLayoutConstraints)::StoreObject(wxObjectOutputStream& s)
{
wxLayoutConstraints *lay_object = (wxLayoutConstraints *)Object();
@ -188,6 +203,8 @@ void WXSERIAL(wxLayoutConstraints)::LoadObject(wxObjectInputStream& s)
((wxWindow *)s.GetParent())->SetConstraints(lay_object);
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxFrame)::StoreObject(wxObjectOutputStream& s)
{
wxFrame *frame = (wxFrame *)Object();
@ -222,12 +239,15 @@ void WXSERIAL(wxFrame)::LoadObject(wxObjectInputStream& s)
wxDataInputStream data_s(s);
frame->SetMenuBar(mbar);
frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), wxSize(m_w, m_h),
m_style, m_name);
if (frame->GetClassInfo() == CLASSINFO(wxFrame))
frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y),
wxSize(m_w, m_h), m_style, m_name);
frame->CreateStatusBar(data_s.Read8());
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxMenuBar)::StoreObject(wxObjectOutputStream& s)
{
wxMenuBar *mbar = (wxMenuBar *)Object();
@ -263,6 +283,8 @@ void WXSERIAL(wxMenuBar)::LoadObject(wxObjectInputStream& s)
// WXSERIAL(wxWindow)::LoadObject(s);
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxMenu)::StoreObject(wxObjectOutputStream& s)
{
wxMenu *menu = (wxMenu *)Object();
@ -293,6 +315,8 @@ void WXSERIAL(wxMenu)::LoadObject(wxObjectInputStream& s)
}
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxMenuItem)::StoreObject(wxObjectOutputStream& s)
{
wxMenuItem *item = (wxMenuItem *)Object();
@ -324,6 +348,8 @@ void WXSERIAL(wxMenuItem)::LoadObject(wxObjectInputStream& s)
item->SetSubMenu( (wxMenu *)s.GetChild(0) );
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxPanel)::StoreObject(wxObjectOutputStream& s)
{
WXSERIAL(wxWindow)::StoreObject(s);
@ -336,3 +362,48 @@ void WXSERIAL(wxPanel)::LoadObject(wxObjectInputStream& s)
((wxPanel *)Object())->Create(m_parent, m_id, wxPoint(m_x, m_y),
wxSize(m_w, m_h), m_style, m_name);
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxDialog)::StoreObject(wxObjectOutputStream& s)
{
WXSERIAL(wxWindow)::StoreObject(s);
}
void WXSERIAL(wxDialog)::LoadObject(wxObjectInputStream& s)
{
WXSERIAL(wxWindow)::LoadObject(s);
((wxDialog *)Object())->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y),
wxSize(m_w, m_h), m_style, m_name);
}
/////////////////////////////////////////////////////////////////////////////
void WXSERIAL(wxMDIParentFrame)::StoreObject(wxObjectOutputStream& s)
{
wxMDIParentFrame *frame = (wxMDIParentFrame *)Object();
if (s.FirstStage()) {
s.AddChild(frame->GetClientWindow());
WXSERIAL(wxMDIParentFrame)::StoreObject(s);
return;
}
WXSERIAL(wxMDIParentFrame)::StoreObject(s);
}
void WXSERIAL(wxMDIParentFrame)::LoadObject(wxObjectInputStream& s)
{
wxMDIParentFrame *frame = (wxMDIParentFrame *)Object();
wxMDIClientWindow *client;
client = (wxMDIClientWindow *) s.GetChild(0);
s.RemoveChildren(1);
frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y),
wxSize(m_w, m_h), m_style, m_name);
// client->CreateClient(this, style_client);
WXSERIAL(wxFrame)::LoadObject(s);
}

View File

@ -35,16 +35,20 @@ class WXSERIAL(wxWindow) : public WXSERIAL(wxObject)
wxWindowID m_id;
wxString m_name, m_title, m_label;
wxWindow *m_parent;
wxValidator *m_validator;
wxColour m_bg_colour, m_fg_colour;
long m_style;
};
DECLARE_SERIAL_CLASS(wxIndividualLayoutConstraint, wxObject)
DECLARE_SERIAL_CLASS(wxLayoutConstraints, wxObject)
DECLARE_ALIAS_SERIAL_CLASS(wxValidator, wxObject)
DECLARE_SERIAL_CLASS(wxFrame, wxWindow)
DECLARE_SERIAL_CLASS(wxPanel, wxWindow)
//DECLARE_SERIAL_CLASS(wxDialog, wxWindow)
DECLARE_SERIAL_CLASS(wxDialog, wxWindow)
DECLARE_SERIAL_CLASS(wxMenuBar, wxWindow)
DECLARE_SERIAL_CLASS(wxMenuItem, wxObject)
DECLARE_SERIAL_CLASS(wxMenu, wxObject)
DECLARE_SERIAL_CLASS(wxMDIParentFrame, wxFrame)
#endif