mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-18 03:51:31 +02:00
set svn:eol-style=native for Externals/**.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1440 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
18ceeda47a
commit
9146b9b261
4494
Externals/Bochs_disasm/PowerPCDisasm.cpp
vendored
4494
Externals/Bochs_disasm/PowerPCDisasm.cpp
vendored
File diff suppressed because it is too large
Load Diff
16
Externals/Bochs_disasm/stdafx.cpp
vendored
16
Externals/Bochs_disasm/stdafx.cpp
vendored
@ -1,8 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// Bochs_disasm.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// Bochs_disasm.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
|
240
Externals/wxWidgets/include/wx/arrimpl.cpp
vendored
240
Externals/wxWidgets/include/wx/arrimpl.cpp
vendored
@ -1,120 +1,120 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/arrimpl.cpp
|
||||
// Purpose: helper file for implementation of dynamic lists
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 16.10.97
|
||||
// RCS-ID: $Id: arrimpl.cpp 34241 2005-05-22 12:10:55Z JS $
|
||||
// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*****************************************************************************
|
||||
* Purpose: implements methods of "template" class declared in *
|
||||
* DECLARE_OBJARRAY macro and which couldn't be implemented inline *
|
||||
* (because they need the full definition of type T in scope) *
|
||||
* *
|
||||
* Usage: 1) #include dynarray.h *
|
||||
* 2) WX_DECLARE_OBJARRAY *
|
||||
* 3) #include arrimpl.cpp *
|
||||
* 4) WX_DEFINE_OBJARRAY *
|
||||
*****************************************************************************/
|
||||
|
||||
// needed to resolve the conflict between global T and macro parameter T
|
||||
|
||||
#define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
|
||||
|
||||
// macro implements remaining (not inline) methods of template list
|
||||
// (it's private to this file)
|
||||
#undef _DEFINE_OBJARRAY
|
||||
#define _DEFINE_OBJARRAY(T, name) \
|
||||
name::~name() \
|
||||
{ \
|
||||
Empty(); \
|
||||
} \
|
||||
\
|
||||
void name::DoCopy(const name& src) \
|
||||
{ \
|
||||
for ( size_t ui = 0; ui < src.size(); ui++ ) \
|
||||
Add(src[ui]); \
|
||||
} \
|
||||
\
|
||||
name& name::operator=(const name& src) \
|
||||
{ \
|
||||
Empty(); \
|
||||
DoCopy(src); \
|
||||
\
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
name::name(const name& src) : wxArrayPtrVoid() \
|
||||
{ \
|
||||
DoCopy(src); \
|
||||
} \
|
||||
\
|
||||
void name::DoEmpty() \
|
||||
{ \
|
||||
for ( size_t ui = 0; ui < size(); ui++ ) \
|
||||
delete (T*)base_array::operator[](ui); \
|
||||
} \
|
||||
\
|
||||
void name::RemoveAt(size_t uiIndex, size_t nRemove) \
|
||||
{ \
|
||||
wxCHECK_RET( uiIndex < size(), _WX_ERROR_REMOVE2(name) ); \
|
||||
\
|
||||
for (size_t i = 0; i < nRemove; i++ ) \
|
||||
delete (T*)base_array::operator[](uiIndex + i); \
|
||||
\
|
||||
base_array::erase(begin() + uiIndex, begin() + uiIndex + nRemove); \
|
||||
} \
|
||||
\
|
||||
void name::Add(const T& item, size_t nInsert) \
|
||||
{ \
|
||||
if (nInsert == 0) \
|
||||
return; \
|
||||
T* pItem = new T(item); \
|
||||
size_t nOldSize = size(); \
|
||||
if ( pItem != NULL ) \
|
||||
base_array::insert(end(), nInsert, pItem); \
|
||||
for (size_t i = 1; i < nInsert; i++) \
|
||||
base_array::operator[](nOldSize + i) = new T(item); \
|
||||
} \
|
||||
\
|
||||
void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
|
||||
{ \
|
||||
if (nInsert == 0) \
|
||||
return; \
|
||||
T* pItem = new T(item); \
|
||||
if ( pItem != NULL ) \
|
||||
base_array::insert(begin() + uiIndex, nInsert, pItem); \
|
||||
for (size_t i = 1; i < nInsert; i++) \
|
||||
base_array::operator[](uiIndex + i) = new T(item); \
|
||||
} \
|
||||
\
|
||||
int name::Index(const T& Item, bool bFromEnd) const \
|
||||
{ \
|
||||
if ( bFromEnd ) { \
|
||||
if ( size() > 0 ) { \
|
||||
size_t ui = size() - 1; \
|
||||
do { \
|
||||
if ( (T*)base_array::operator[](ui) == &Item ) \
|
||||
return wx_static_cast(int, ui); \
|
||||
ui--; \
|
||||
} \
|
||||
while ( ui != 0 ); \
|
||||
} \
|
||||
} \
|
||||
else { \
|
||||
for( size_t ui = 0; ui < size(); ui++ ) { \
|
||||
if( (T*)base_array::operator[](ui) == &Item ) \
|
||||
return wx_static_cast(int, ui); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return wxNOT_FOUND; \
|
||||
}
|
||||
|
||||
// redefine the macro so that now it will generate the class implementation
|
||||
// old value would provoke a compile-time error if this file is not included
|
||||
#undef WX_DEFINE_OBJARRAY
|
||||
#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/arrimpl.cpp
|
||||
// Purpose: helper file for implementation of dynamic lists
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 16.10.97
|
||||
// RCS-ID: $Id: arrimpl.cpp 34241 2005-05-22 12:10:55Z JS $
|
||||
// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*****************************************************************************
|
||||
* Purpose: implements methods of "template" class declared in *
|
||||
* DECLARE_OBJARRAY macro and which couldn't be implemented inline *
|
||||
* (because they need the full definition of type T in scope) *
|
||||
* *
|
||||
* Usage: 1) #include dynarray.h *
|
||||
* 2) WX_DECLARE_OBJARRAY *
|
||||
* 3) #include arrimpl.cpp *
|
||||
* 4) WX_DEFINE_OBJARRAY *
|
||||
*****************************************************************************/
|
||||
|
||||
// needed to resolve the conflict between global T and macro parameter T
|
||||
|
||||
#define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
|
||||
|
||||
// macro implements remaining (not inline) methods of template list
|
||||
// (it's private to this file)
|
||||
#undef _DEFINE_OBJARRAY
|
||||
#define _DEFINE_OBJARRAY(T, name) \
|
||||
name::~name() \
|
||||
{ \
|
||||
Empty(); \
|
||||
} \
|
||||
\
|
||||
void name::DoCopy(const name& src) \
|
||||
{ \
|
||||
for ( size_t ui = 0; ui < src.size(); ui++ ) \
|
||||
Add(src[ui]); \
|
||||
} \
|
||||
\
|
||||
name& name::operator=(const name& src) \
|
||||
{ \
|
||||
Empty(); \
|
||||
DoCopy(src); \
|
||||
\
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
name::name(const name& src) : wxArrayPtrVoid() \
|
||||
{ \
|
||||
DoCopy(src); \
|
||||
} \
|
||||
\
|
||||
void name::DoEmpty() \
|
||||
{ \
|
||||
for ( size_t ui = 0; ui < size(); ui++ ) \
|
||||
delete (T*)base_array::operator[](ui); \
|
||||
} \
|
||||
\
|
||||
void name::RemoveAt(size_t uiIndex, size_t nRemove) \
|
||||
{ \
|
||||
wxCHECK_RET( uiIndex < size(), _WX_ERROR_REMOVE2(name) ); \
|
||||
\
|
||||
for (size_t i = 0; i < nRemove; i++ ) \
|
||||
delete (T*)base_array::operator[](uiIndex + i); \
|
||||
\
|
||||
base_array::erase(begin() + uiIndex, begin() + uiIndex + nRemove); \
|
||||
} \
|
||||
\
|
||||
void name::Add(const T& item, size_t nInsert) \
|
||||
{ \
|
||||
if (nInsert == 0) \
|
||||
return; \
|
||||
T* pItem = new T(item); \
|
||||
size_t nOldSize = size(); \
|
||||
if ( pItem != NULL ) \
|
||||
base_array::insert(end(), nInsert, pItem); \
|
||||
for (size_t i = 1; i < nInsert; i++) \
|
||||
base_array::operator[](nOldSize + i) = new T(item); \
|
||||
} \
|
||||
\
|
||||
void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
|
||||
{ \
|
||||
if (nInsert == 0) \
|
||||
return; \
|
||||
T* pItem = new T(item); \
|
||||
if ( pItem != NULL ) \
|
||||
base_array::insert(begin() + uiIndex, nInsert, pItem); \
|
||||
for (size_t i = 1; i < nInsert; i++) \
|
||||
base_array::operator[](uiIndex + i) = new T(item); \
|
||||
} \
|
||||
\
|
||||
int name::Index(const T& Item, bool bFromEnd) const \
|
||||
{ \
|
||||
if ( bFromEnd ) { \
|
||||
if ( size() > 0 ) { \
|
||||
size_t ui = size() - 1; \
|
||||
do { \
|
||||
if ( (T*)base_array::operator[](ui) == &Item ) \
|
||||
return wx_static_cast(int, ui); \
|
||||
ui--; \
|
||||
} \
|
||||
while ( ui != 0 ); \
|
||||
} \
|
||||
} \
|
||||
else { \
|
||||
for( size_t ui = 0; ui < size(); ui++ ) { \
|
||||
if( (T*)base_array::operator[](ui) == &Item ) \
|
||||
return wx_static_cast(int, ui); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return wxNOT_FOUND; \
|
||||
}
|
||||
|
||||
// redefine the macro so that now it will generate the class implementation
|
||||
// old value would provoke a compile-time error if this file is not included
|
||||
#undef WX_DEFINE_OBJARRAY
|
||||
#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)
|
||||
|
78
Externals/wxWidgets/include/wx/listimpl.cpp
vendored
78
Externals/wxWidgets/include/wx/listimpl.cpp
vendored
@ -1,39 +1,39 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: listimpl.cpp
|
||||
// Purpose: second-part of macro based implementation of template lists
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 16/11/98
|
||||
// RCS-ID: $Id: listimpl.cpp 38893 2006-04-24 17:59:10Z VZ $
|
||||
// Copyright: (c) 1998 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if wxUSE_STL
|
||||
|
||||
#undef WX_DEFINE_LIST
|
||||
#define WX_DEFINE_LIST(name) \
|
||||
void _WX_LIST_HELPER_##name::DeleteFunction( _WX_LIST_ITEM_TYPE_##name X )\
|
||||
{ \
|
||||
delete X; \
|
||||
} \
|
||||
name::BaseListType name::EmptyList;
|
||||
|
||||
#else // !wxUSE_STL
|
||||
|
||||
#define _DEFINE_LIST(T, name) \
|
||||
void wx##name##Node::DeleteData() \
|
||||
{ \
|
||||
delete (T *)GetData(); \
|
||||
}
|
||||
|
||||
// redefine the macro so that now it will generate the class implementation
|
||||
// old value would provoke a compile-time error if this file is not included
|
||||
#undef WX_DEFINE_LIST
|
||||
#define WX_DEFINE_LIST(name) _DEFINE_LIST(_WX_LIST_ITEM_TYPE_##name, name)
|
||||
|
||||
// don't pollute preprocessor's name space
|
||||
//#undef _DEFINE_LIST
|
||||
|
||||
#endif // wxUSE_STL/!wxUSE_STL
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: listimpl.cpp
|
||||
// Purpose: second-part of macro based implementation of template lists
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 16/11/98
|
||||
// RCS-ID: $Id: listimpl.cpp 38893 2006-04-24 17:59:10Z VZ $
|
||||
// Copyright: (c) 1998 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if wxUSE_STL
|
||||
|
||||
#undef WX_DEFINE_LIST
|
||||
#define WX_DEFINE_LIST(name) \
|
||||
void _WX_LIST_HELPER_##name::DeleteFunction( _WX_LIST_ITEM_TYPE_##name X )\
|
||||
{ \
|
||||
delete X; \
|
||||
} \
|
||||
name::BaseListType name::EmptyList;
|
||||
|
||||
#else // !wxUSE_STL
|
||||
|
||||
#define _DEFINE_LIST(T, name) \
|
||||
void wx##name##Node::DeleteData() \
|
||||
{ \
|
||||
delete (T *)GetData(); \
|
||||
}
|
||||
|
||||
// redefine the macro so that now it will generate the class implementation
|
||||
// old value would provoke a compile-time error if this file is not included
|
||||
#undef WX_DEFINE_LIST
|
||||
#define WX_DEFINE_LIST(name) _DEFINE_LIST(_WX_LIST_ITEM_TYPE_##name, name)
|
||||
|
||||
// don't pollute preprocessor's name space
|
||||
//#undef _DEFINE_LIST
|
||||
|
||||
#endif // wxUSE_STL/!wxUSE_STL
|
||||
|
||||
|
660
Externals/wxWidgets/include/wx/thrimpl.cpp
vendored
660
Externals/wxWidgets/include/wx/thrimpl.cpp
vendored
@ -1,330 +1,330 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: include/wx/thrimpl.cpp
|
||||
// Purpose: common part of wxThread Implementations
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 04.06.02 (extracted from src/*/thread.cpp files)
|
||||
// RCS-ID: $Id: thrimpl.cpp 42206 2006-10-21 16:06:11Z VZ $
|
||||
// Copyright: (c) Vadim Zeitlin (2002)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// this file is supposed to be included only by the various thread.cpp
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMutex
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxMutex::wxMutex(wxMutexType mutexType)
|
||||
{
|
||||
m_internal = new wxMutexInternal(mutexType);
|
||||
|
||||
if ( !m_internal->IsOk() )
|
||||
{
|
||||
delete m_internal;
|
||||
m_internal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
bool wxMutex::IsOk() const
|
||||
{
|
||||
return m_internal != NULL;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Lock()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
|
||||
_T("wxMutex::Lock(): not initialized") );
|
||||
|
||||
return m_internal->Lock();
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::TryLock()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
|
||||
_T("wxMutex::TryLock(): not initialized") );
|
||||
|
||||
return m_internal->TryLock();
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Unlock()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
|
||||
_T("wxMutex::Unlock(): not initialized") );
|
||||
|
||||
return m_internal->Unlock();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxConditionInternal
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Win32 and OS/2 don't have explicit support for the POSIX condition
|
||||
// variables and their events/event semaphores have quite different semantics,
|
||||
// so we reimplement the conditions from scratch using the mutexes and
|
||||
// semaphores
|
||||
#if defined(__WXMSW__) || defined(__OS2__) || defined(__EMX__)
|
||||
|
||||
class wxConditionInternal
|
||||
{
|
||||
public:
|
||||
wxConditionInternal(wxMutex& mutex);
|
||||
|
||||
bool IsOk() const { return m_mutex.IsOk() && m_semaphore.IsOk(); }
|
||||
|
||||
wxCondError Wait();
|
||||
wxCondError WaitTimeout(unsigned long milliseconds);
|
||||
|
||||
wxCondError Signal();
|
||||
wxCondError Broadcast();
|
||||
|
||||
private:
|
||||
// the number of threads currently waiting for this condition
|
||||
LONG m_numWaiters;
|
||||
|
||||
// the critical section protecting m_numWaiters
|
||||
wxCriticalSection m_csWaiters;
|
||||
|
||||
wxMutex& m_mutex;
|
||||
wxSemaphore m_semaphore;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxConditionInternal)
|
||||
};
|
||||
|
||||
wxConditionInternal::wxConditionInternal(wxMutex& mutex)
|
||||
: m_mutex(mutex)
|
||||
{
|
||||
// another thread can't access it until we return from ctor, so no need to
|
||||
// protect access to m_numWaiters here
|
||||
m_numWaiters = 0;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::Wait()
|
||||
{
|
||||
// increment the number of waiters
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
m_numWaiters++;
|
||||
}
|
||||
|
||||
m_mutex.Unlock();
|
||||
|
||||
// a potential race condition can occur here
|
||||
//
|
||||
// after a thread increments m_numWaiters, and unlocks the mutex and before
|
||||
// the semaphore.Wait() is called, if another thread can cause a signal to
|
||||
// be generated
|
||||
//
|
||||
// this race condition is handled by using a semaphore and incrementing the
|
||||
// semaphore only if m_numWaiters is greater that zero since the semaphore,
|
||||
// can 'remember' signals the race condition will not occur
|
||||
|
||||
// wait ( if necessary ) and decrement semaphore
|
||||
wxSemaError err = m_semaphore.Wait();
|
||||
m_mutex.Lock();
|
||||
|
||||
if ( err == wxSEMA_NO_ERROR )
|
||||
return wxCOND_NO_ERROR;
|
||||
else if ( err == wxSEMA_TIMEOUT )
|
||||
return wxCOND_TIMEOUT;
|
||||
else
|
||||
return wxCOND_MISC_ERROR;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::WaitTimeout(unsigned long milliseconds)
|
||||
{
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
m_numWaiters++;
|
||||
}
|
||||
|
||||
m_mutex.Unlock();
|
||||
|
||||
// a race condition can occur at this point in the code
|
||||
//
|
||||
// please see the comments in Wait(), for details
|
||||
|
||||
wxSemaError err = m_semaphore.WaitTimeout(milliseconds);
|
||||
|
||||
if ( err == wxSEMA_TIMEOUT )
|
||||
{
|
||||
// another potential race condition exists here it is caused when a
|
||||
// 'waiting' thread times out, and returns from WaitForSingleObject,
|
||||
// but has not yet decremented m_numWaiters
|
||||
//
|
||||
// at this point if another thread calls signal() then the semaphore
|
||||
// will be incremented, but the waiting thread will miss it.
|
||||
//
|
||||
// to handle this particular case, the waiting thread calls
|
||||
// WaitForSingleObject again with a timeout of 0, after locking
|
||||
// m_csWaiters. This call does not block because of the zero
|
||||
// timeout, but will allow the waiting thread to catch the missed
|
||||
// signals.
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
|
||||
wxSemaError err2 = m_semaphore.WaitTimeout(0);
|
||||
|
||||
if ( err2 != wxSEMA_NO_ERROR )
|
||||
{
|
||||
m_numWaiters--;
|
||||
}
|
||||
}
|
||||
|
||||
m_mutex.Lock();
|
||||
|
||||
return err == wxSEMA_NO_ERROR ? wxCOND_NO_ERROR
|
||||
: err == wxSEMA_TIMEOUT ? wxCOND_TIMEOUT
|
||||
: wxCOND_MISC_ERROR;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::Signal()
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
|
||||
if ( m_numWaiters > 0 )
|
||||
{
|
||||
// increment the semaphore by 1
|
||||
if ( m_semaphore.Post() != wxSEMA_NO_ERROR )
|
||||
return wxCOND_MISC_ERROR;
|
||||
|
||||
m_numWaiters--;
|
||||
}
|
||||
|
||||
return wxCOND_NO_ERROR;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::Broadcast()
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
|
||||
while ( m_numWaiters > 0 )
|
||||
{
|
||||
if ( m_semaphore.Post() != wxSEMA_NO_ERROR )
|
||||
return wxCOND_MISC_ERROR;
|
||||
|
||||
m_numWaiters--;
|
||||
}
|
||||
|
||||
return wxCOND_NO_ERROR;
|
||||
}
|
||||
|
||||
#endif // MSW or OS2
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxCondition
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCondition::wxCondition(wxMutex& mutex)
|
||||
{
|
||||
m_internal = new wxConditionInternal(mutex);
|
||||
|
||||
if ( !m_internal->IsOk() )
|
||||
{
|
||||
delete m_internal;
|
||||
m_internal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wxCondition::~wxCondition()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
bool wxCondition::IsOk() const
|
||||
{
|
||||
return m_internal != NULL;
|
||||
}
|
||||
|
||||
wxCondError wxCondition::Wait()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Wait(): not initialized") );
|
||||
|
||||
return m_internal->Wait();
|
||||
}
|
||||
|
||||
wxCondError wxCondition::WaitTimeout(unsigned long milliseconds)
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Wait(): not initialized") );
|
||||
|
||||
return m_internal->WaitTimeout(milliseconds);
|
||||
}
|
||||
|
||||
wxCondError wxCondition::Signal()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Signal(): not initialized") );
|
||||
|
||||
return m_internal->Signal();
|
||||
}
|
||||
|
||||
wxCondError wxCondition::Broadcast()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Broadcast(): not initialized") );
|
||||
|
||||
return m_internal->Broadcast();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxSemaphore
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
wxSemaphore::wxSemaphore(int initialcount, int maxcount)
|
||||
{
|
||||
m_internal = new wxSemaphoreInternal( initialcount, maxcount );
|
||||
if ( !m_internal->IsOk() )
|
||||
{
|
||||
delete m_internal;
|
||||
m_internal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wxSemaphore::~wxSemaphore()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
bool wxSemaphore::IsOk() const
|
||||
{
|
||||
return m_internal != NULL;
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::Wait()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::Wait(): not initialized") );
|
||||
|
||||
return m_internal->Wait();
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::TryWait()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::TryWait(): not initialized") );
|
||||
|
||||
return m_internal->TryWait();
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::WaitTimeout(unsigned long milliseconds)
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::WaitTimeout(): not initialized") );
|
||||
|
||||
return m_internal->WaitTimeout(milliseconds);
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::Post()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::Post(): not initialized") );
|
||||
|
||||
return m_internal->Post();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: include/wx/thrimpl.cpp
|
||||
// Purpose: common part of wxThread Implementations
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 04.06.02 (extracted from src/*/thread.cpp files)
|
||||
// RCS-ID: $Id: thrimpl.cpp 42206 2006-10-21 16:06:11Z VZ $
|
||||
// Copyright: (c) Vadim Zeitlin (2002)
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// this file is supposed to be included only by the various thread.cpp
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMutex
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxMutex::wxMutex(wxMutexType mutexType)
|
||||
{
|
||||
m_internal = new wxMutexInternal(mutexType);
|
||||
|
||||
if ( !m_internal->IsOk() )
|
||||
{
|
||||
delete m_internal;
|
||||
m_internal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wxMutex::~wxMutex()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
bool wxMutex::IsOk() const
|
||||
{
|
||||
return m_internal != NULL;
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Lock()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
|
||||
_T("wxMutex::Lock(): not initialized") );
|
||||
|
||||
return m_internal->Lock();
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::TryLock()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
|
||||
_T("wxMutex::TryLock(): not initialized") );
|
||||
|
||||
return m_internal->TryLock();
|
||||
}
|
||||
|
||||
wxMutexError wxMutex::Unlock()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
|
||||
_T("wxMutex::Unlock(): not initialized") );
|
||||
|
||||
return m_internal->Unlock();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxConditionInternal
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Win32 and OS/2 don't have explicit support for the POSIX condition
|
||||
// variables and their events/event semaphores have quite different semantics,
|
||||
// so we reimplement the conditions from scratch using the mutexes and
|
||||
// semaphores
|
||||
#if defined(__WXMSW__) || defined(__OS2__) || defined(__EMX__)
|
||||
|
||||
class wxConditionInternal
|
||||
{
|
||||
public:
|
||||
wxConditionInternal(wxMutex& mutex);
|
||||
|
||||
bool IsOk() const { return m_mutex.IsOk() && m_semaphore.IsOk(); }
|
||||
|
||||
wxCondError Wait();
|
||||
wxCondError WaitTimeout(unsigned long milliseconds);
|
||||
|
||||
wxCondError Signal();
|
||||
wxCondError Broadcast();
|
||||
|
||||
private:
|
||||
// the number of threads currently waiting for this condition
|
||||
LONG m_numWaiters;
|
||||
|
||||
// the critical section protecting m_numWaiters
|
||||
wxCriticalSection m_csWaiters;
|
||||
|
||||
wxMutex& m_mutex;
|
||||
wxSemaphore m_semaphore;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxConditionInternal)
|
||||
};
|
||||
|
||||
wxConditionInternal::wxConditionInternal(wxMutex& mutex)
|
||||
: m_mutex(mutex)
|
||||
{
|
||||
// another thread can't access it until we return from ctor, so no need to
|
||||
// protect access to m_numWaiters here
|
||||
m_numWaiters = 0;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::Wait()
|
||||
{
|
||||
// increment the number of waiters
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
m_numWaiters++;
|
||||
}
|
||||
|
||||
m_mutex.Unlock();
|
||||
|
||||
// a potential race condition can occur here
|
||||
//
|
||||
// after a thread increments m_numWaiters, and unlocks the mutex and before
|
||||
// the semaphore.Wait() is called, if another thread can cause a signal to
|
||||
// be generated
|
||||
//
|
||||
// this race condition is handled by using a semaphore and incrementing the
|
||||
// semaphore only if m_numWaiters is greater that zero since the semaphore,
|
||||
// can 'remember' signals the race condition will not occur
|
||||
|
||||
// wait ( if necessary ) and decrement semaphore
|
||||
wxSemaError err = m_semaphore.Wait();
|
||||
m_mutex.Lock();
|
||||
|
||||
if ( err == wxSEMA_NO_ERROR )
|
||||
return wxCOND_NO_ERROR;
|
||||
else if ( err == wxSEMA_TIMEOUT )
|
||||
return wxCOND_TIMEOUT;
|
||||
else
|
||||
return wxCOND_MISC_ERROR;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::WaitTimeout(unsigned long milliseconds)
|
||||
{
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
m_numWaiters++;
|
||||
}
|
||||
|
||||
m_mutex.Unlock();
|
||||
|
||||
// a race condition can occur at this point in the code
|
||||
//
|
||||
// please see the comments in Wait(), for details
|
||||
|
||||
wxSemaError err = m_semaphore.WaitTimeout(milliseconds);
|
||||
|
||||
if ( err == wxSEMA_TIMEOUT )
|
||||
{
|
||||
// another potential race condition exists here it is caused when a
|
||||
// 'waiting' thread times out, and returns from WaitForSingleObject,
|
||||
// but has not yet decremented m_numWaiters
|
||||
//
|
||||
// at this point if another thread calls signal() then the semaphore
|
||||
// will be incremented, but the waiting thread will miss it.
|
||||
//
|
||||
// to handle this particular case, the waiting thread calls
|
||||
// WaitForSingleObject again with a timeout of 0, after locking
|
||||
// m_csWaiters. This call does not block because of the zero
|
||||
// timeout, but will allow the waiting thread to catch the missed
|
||||
// signals.
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
|
||||
wxSemaError err2 = m_semaphore.WaitTimeout(0);
|
||||
|
||||
if ( err2 != wxSEMA_NO_ERROR )
|
||||
{
|
||||
m_numWaiters--;
|
||||
}
|
||||
}
|
||||
|
||||
m_mutex.Lock();
|
||||
|
||||
return err == wxSEMA_NO_ERROR ? wxCOND_NO_ERROR
|
||||
: err == wxSEMA_TIMEOUT ? wxCOND_TIMEOUT
|
||||
: wxCOND_MISC_ERROR;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::Signal()
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
|
||||
if ( m_numWaiters > 0 )
|
||||
{
|
||||
// increment the semaphore by 1
|
||||
if ( m_semaphore.Post() != wxSEMA_NO_ERROR )
|
||||
return wxCOND_MISC_ERROR;
|
||||
|
||||
m_numWaiters--;
|
||||
}
|
||||
|
||||
return wxCOND_NO_ERROR;
|
||||
}
|
||||
|
||||
wxCondError wxConditionInternal::Broadcast()
|
||||
{
|
||||
wxCriticalSectionLocker lock(m_csWaiters);
|
||||
|
||||
while ( m_numWaiters > 0 )
|
||||
{
|
||||
if ( m_semaphore.Post() != wxSEMA_NO_ERROR )
|
||||
return wxCOND_MISC_ERROR;
|
||||
|
||||
m_numWaiters--;
|
||||
}
|
||||
|
||||
return wxCOND_NO_ERROR;
|
||||
}
|
||||
|
||||
#endif // MSW or OS2
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxCondition
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCondition::wxCondition(wxMutex& mutex)
|
||||
{
|
||||
m_internal = new wxConditionInternal(mutex);
|
||||
|
||||
if ( !m_internal->IsOk() )
|
||||
{
|
||||
delete m_internal;
|
||||
m_internal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wxCondition::~wxCondition()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
bool wxCondition::IsOk() const
|
||||
{
|
||||
return m_internal != NULL;
|
||||
}
|
||||
|
||||
wxCondError wxCondition::Wait()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Wait(): not initialized") );
|
||||
|
||||
return m_internal->Wait();
|
||||
}
|
||||
|
||||
wxCondError wxCondition::WaitTimeout(unsigned long milliseconds)
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Wait(): not initialized") );
|
||||
|
||||
return m_internal->WaitTimeout(milliseconds);
|
||||
}
|
||||
|
||||
wxCondError wxCondition::Signal()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Signal(): not initialized") );
|
||||
|
||||
return m_internal->Signal();
|
||||
}
|
||||
|
||||
wxCondError wxCondition::Broadcast()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxCOND_INVALID,
|
||||
_T("wxCondition::Broadcast(): not initialized") );
|
||||
|
||||
return m_internal->Broadcast();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxSemaphore
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
wxSemaphore::wxSemaphore(int initialcount, int maxcount)
|
||||
{
|
||||
m_internal = new wxSemaphoreInternal( initialcount, maxcount );
|
||||
if ( !m_internal->IsOk() )
|
||||
{
|
||||
delete m_internal;
|
||||
m_internal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wxSemaphore::~wxSemaphore()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
bool wxSemaphore::IsOk() const
|
||||
{
|
||||
return m_internal != NULL;
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::Wait()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::Wait(): not initialized") );
|
||||
|
||||
return m_internal->Wait();
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::TryWait()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::TryWait(): not initialized") );
|
||||
|
||||
return m_internal->TryWait();
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::WaitTimeout(unsigned long milliseconds)
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::WaitTimeout(): not initialized") );
|
||||
|
||||
return m_internal->WaitTimeout(milliseconds);
|
||||
}
|
||||
|
||||
wxSemaError wxSemaphore::Post()
|
||||
{
|
||||
wxCHECK_MSG( m_internal, wxSEMA_INVALID,
|
||||
_T("wxSemaphore::Post(): not initialized") );
|
||||
|
||||
return m_internal->Post();
|
||||
}
|
||||
|
||||
|
52
Externals/wxWidgets/src/common/accesscmn.cpp
vendored
52
Externals/wxWidgets/src/common/accesscmn.cpp
vendored
@ -1,26 +1,26 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/accesscmn.cpp
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 2003-02-12
|
||||
// RCS-ID: $Id: accesscmn.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
|
||||
#include "wx/access.h"
|
||||
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/accesscmn.cpp
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 2003-02-12
|
||||
// RCS-ID: $Id: accesscmn.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
|
||||
#include "wx/access.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
690
Externals/wxWidgets/src/common/anidecod.cpp
vendored
690
Externals/wxWidgets/src/common/anidecod.cpp
vendored
@ -1,345 +1,345 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/anidecod.cpp
|
||||
// Purpose: wxANIDecoder, ANI reader for wxImage and wxAnimation
|
||||
// Author: Francesco Montorsi
|
||||
// RCS-ID: $Id: anidecod.cpp 43898 2006-12-10 14:18:37Z VZ $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS && wxUSE_ICO_CUR
|
||||
|
||||
#include "wx/anidecod.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/palette.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// static
|
||||
wxCURHandler wxANIDecoder::sm_handler;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxANIFrameInfo
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class wxANIFrameInfo
|
||||
{
|
||||
public:
|
||||
wxANIFrameInfo(unsigned int delay = 0, int idx = -1)
|
||||
{ m_delay=delay; m_imageIndex=idx; }
|
||||
|
||||
unsigned int m_delay;
|
||||
int m_imageIndex;
|
||||
};
|
||||
|
||||
#include "wx/arrimpl.cpp" // this is a magic incantation which must be done!
|
||||
WX_DEFINE_OBJARRAY(wxImageArray)
|
||||
|
||||
#include "wx/arrimpl.cpp" // this is a magic incantation which must be done!
|
||||
WX_DEFINE_OBJARRAY(wxANIFrameInfoArray)
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxANIDecoder
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
wxANIDecoder::wxANIDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
wxANIDecoder::~wxANIDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxANIDecoder::ConvertToImage(unsigned int frame, wxImage *image) const
|
||||
{
|
||||
unsigned int idx = m_info[frame].m_imageIndex;
|
||||
*image = m_images[idx]; // copy
|
||||
return image->IsOk();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Data accessors
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
wxSize wxANIDecoder::GetFrameSize(unsigned int WXUNUSED(frame)) const
|
||||
{
|
||||
// all frames are of the same size...
|
||||
return m_szAnimation;
|
||||
}
|
||||
|
||||
wxPoint wxANIDecoder::GetFramePosition(unsigned int WXUNUSED(frame)) const
|
||||
{
|
||||
// all frames are of the same size...
|
||||
return wxPoint(0,0);
|
||||
}
|
||||
|
||||
wxAnimationDisposal wxANIDecoder::GetDisposalMethod(unsigned int WXUNUSED(frame)) const
|
||||
{
|
||||
// this disposal is implicit for all frames inside an ANI file
|
||||
return wxANIM_TOBACKGROUND;
|
||||
}
|
||||
|
||||
long wxANIDecoder::GetDelay(unsigned int frame) const
|
||||
{
|
||||
return m_info[frame].m_delay;
|
||||
}
|
||||
|
||||
wxColour wxANIDecoder::GetTransparentColour(unsigned int frame) const
|
||||
{
|
||||
unsigned int idx = m_info[frame].m_imageIndex;
|
||||
|
||||
if (!m_images[idx].HasMask())
|
||||
return wxNullColour;
|
||||
|
||||
return wxColour(m_images[idx].GetMaskRed(),
|
||||
m_images[idx].GetMaskGreen(),
|
||||
m_images[idx].GetMaskBlue());
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// ANI reading and decoding
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool wxANIDecoder::CanRead(wxInputStream& stream) const
|
||||
{
|
||||
wxInt32 FCC1, FCC2;
|
||||
wxUint32 datalen ;
|
||||
|
||||
wxInt32 riff32;
|
||||
memcpy( &riff32, "RIFF", 4 );
|
||||
wxInt32 list32;
|
||||
memcpy( &list32, "LIST", 4 );
|
||||
wxInt32 ico32;
|
||||
memcpy( &ico32, "icon", 4 );
|
||||
wxInt32 anih32;
|
||||
memcpy( &anih32, "anih", 4 );
|
||||
|
||||
stream.SeekI(0);
|
||||
if ( !stream.Read(&FCC1, 4) )
|
||||
return false;
|
||||
|
||||
if ( FCC1 != riff32 )
|
||||
return false;
|
||||
|
||||
// we have a riff file:
|
||||
while ( stream.IsOk() )
|
||||
{
|
||||
if ( FCC1 == anih32 )
|
||||
return true; // found the ANIH chunk - this should be an ANI file
|
||||
|
||||
// we always have a data size:
|
||||
stream.Read(&datalen, 4);
|
||||
datalen = wxINT32_SWAP_ON_BE(datalen) ;
|
||||
|
||||
// data should be padded to make even number of bytes
|
||||
if (datalen % 2 == 1) datalen ++ ;
|
||||
|
||||
// now either data or a FCC:
|
||||
if ( (FCC1 == riff32) || (FCC1 == list32) )
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.SeekI(stream.TellI() + datalen);
|
||||
}
|
||||
|
||||
// try to read next data chunk:
|
||||
if ( !stream.Read(&FCC1, 4) )
|
||||
{
|
||||
// reading failed -- either EOF or IO error, bail out anyhow
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// the "anih" RIFF chunk
|
||||
struct wxANIHeader
|
||||
{
|
||||
wxInt32 cbSizeOf; // Num bytes in AniHeader (36 bytes)
|
||||
wxInt32 cFrames; // Number of unique Icons in this cursor
|
||||
wxInt32 cSteps; // Number of Blits before the animation cycles
|
||||
wxInt32 cx; // width of the frames
|
||||
wxInt32 cy; // height of the frames
|
||||
wxInt32 cBitCount; // bit depth
|
||||
wxInt32 cPlanes; // 1
|
||||
wxInt32 JifRate; // Default Jiffies (1/60th of a second) if rate chunk not present.
|
||||
wxInt32 flags; // Animation Flag (see AF_ constants)
|
||||
|
||||
// ANI files are always little endian so we need to swap bytes on big
|
||||
// endian architectures
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
void AdjustEndianness()
|
||||
{
|
||||
// this works because all our fields are wxInt32 and they must be
|
||||
// packed without holes between them (if they're not, they wouldn't map
|
||||
// to the file header!)
|
||||
wxInt32 * const start = (wxInt32 *)this;
|
||||
wxInt32 * const end = start + sizeof(wxANIHeader)/sizeof(wxInt32);
|
||||
for ( wxInt32 *p = start; p != end; p++ )
|
||||
{
|
||||
*p = wxINT32_SWAP_ALWAYS(*p);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void AdjustEndianness() { }
|
||||
#endif
|
||||
};
|
||||
|
||||
bool wxANIDecoder::Load( wxInputStream& stream )
|
||||
{
|
||||
wxInt32 FCC1, FCC2;
|
||||
wxUint32 datalen;
|
||||
unsigned int globaldelay=0;
|
||||
|
||||
wxInt32 riff32;
|
||||
memcpy( &riff32, "RIFF", 4 );
|
||||
wxInt32 list32;
|
||||
memcpy( &list32, "LIST", 4 );
|
||||
wxInt32 ico32;
|
||||
memcpy( &ico32, "icon", 4 );
|
||||
wxInt32 anih32;
|
||||
memcpy( &anih32, "anih", 4 );
|
||||
wxInt32 rate32;
|
||||
memcpy( &rate32, "rate", 4 );
|
||||
wxInt32 seq32;
|
||||
memcpy( &seq32, "seq ", 4 );
|
||||
|
||||
stream.SeekI(0);
|
||||
stream.Read(&FCC1, 4);
|
||||
if ( FCC1 != riff32 )
|
||||
return false;
|
||||
|
||||
m_nFrames = 0;
|
||||
m_szAnimation = wxDefaultSize;
|
||||
|
||||
m_images.Clear();
|
||||
m_info.Clear();
|
||||
|
||||
// we have a riff file:
|
||||
while ( stream.IsOk() )
|
||||
{
|
||||
// we always have a data size:
|
||||
stream.Read(&datalen, 4);
|
||||
datalen = wxINT32_SWAP_ON_BE(datalen);
|
||||
|
||||
//data should be padded to make even number of bytes
|
||||
if (datalen % 2 == 1) datalen++;
|
||||
|
||||
// now either data or a FCC:
|
||||
if ( (FCC1 == riff32) || (FCC1 == list32) )
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
}
|
||||
else if ( FCC1 == anih32 )
|
||||
{
|
||||
if ( datalen != sizeof(wxANIHeader) )
|
||||
return false;
|
||||
|
||||
if (m_nFrames > 0)
|
||||
return false; // already parsed an ani header?
|
||||
|
||||
struct wxANIHeader header;
|
||||
stream.Read(&header, sizeof(wxANIHeader));
|
||||
header.AdjustEndianness();
|
||||
|
||||
// we should have a global frame size
|
||||
m_szAnimation = wxSize(header.cx, header.cy);
|
||||
|
||||
// save interesting info from the header
|
||||
m_nFrames = header.cSteps; // NB: not cFrames!!
|
||||
if ( m_nFrames == 0 )
|
||||
return false;
|
||||
|
||||
globaldelay = header.JifRate * 1000 / 60;
|
||||
|
||||
m_images.Alloc(header.cFrames);
|
||||
m_info.Add(wxANIFrameInfo(), m_nFrames);
|
||||
}
|
||||
else if ( FCC1 == rate32 )
|
||||
{
|
||||
// did we already process the anih32 chunk?
|
||||
if (m_nFrames == 0)
|
||||
return false; // rate chunks should always be placed after anih chunk
|
||||
|
||||
wxASSERT(m_info.GetCount() == m_nFrames);
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
m_info[i].m_delay = wxINT32_SWAP_ON_BE(FCC2) * 1000 / 60;
|
||||
}
|
||||
}
|
||||
else if ( FCC1 == seq32 )
|
||||
{
|
||||
// did we already process the anih32 chunk?
|
||||
if (m_nFrames == 0)
|
||||
return false; // seq chunks should always be placed after anih chunk
|
||||
|
||||
wxASSERT(m_info.GetCount() == m_nFrames);
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
m_info[i].m_imageIndex = wxINT32_SWAP_ON_BE(FCC2);
|
||||
}
|
||||
}
|
||||
else if ( FCC1 == ico32 )
|
||||
{
|
||||
// use DoLoadFile() and not LoadFile()!
|
||||
wxImage image;
|
||||
if (!sm_handler.DoLoadFile(&image, stream, false /* verbose */, -1))
|
||||
return false;
|
||||
|
||||
m_images.Add(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.SeekI(stream.TellI() + datalen);
|
||||
}
|
||||
|
||||
// try to read next data chunk:
|
||||
stream.Read(&FCC1, 4);
|
||||
}
|
||||
|
||||
if (m_nFrames==0)
|
||||
return false;
|
||||
|
||||
if (m_nFrames==m_images.GetCount())
|
||||
{
|
||||
// if no SEQ chunk is available, display the frames in the order
|
||||
// they were loaded
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
if (m_info[i].m_imageIndex == -1)
|
||||
m_info[i].m_imageIndex = i;
|
||||
}
|
||||
|
||||
// if some frame has an invalid delay, use the global delay given in the
|
||||
// ANI header
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
if (m_info[i].m_delay == 0)
|
||||
m_info[i].m_delay = globaldelay;
|
||||
|
||||
// if the header did not contain a valid frame size, try to grab
|
||||
// it from the size of the first frame (all frames are of the same size)
|
||||
if (m_szAnimation.GetWidth() == 0 ||
|
||||
m_szAnimation.GetHeight() == 0)
|
||||
m_szAnimation = wxSize(m_images[0].GetWidth(), m_images[0].GetHeight());
|
||||
|
||||
return m_szAnimation != wxDefaultSize;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_ICO_CUR
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/anidecod.cpp
|
||||
// Purpose: wxANIDecoder, ANI reader for wxImage and wxAnimation
|
||||
// Author: Francesco Montorsi
|
||||
// RCS-ID: $Id: anidecod.cpp 43898 2006-12-10 14:18:37Z VZ $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS && wxUSE_ICO_CUR
|
||||
|
||||
#include "wx/anidecod.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/palette.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// static
|
||||
wxCURHandler wxANIDecoder::sm_handler;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxANIFrameInfo
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class wxANIFrameInfo
|
||||
{
|
||||
public:
|
||||
wxANIFrameInfo(unsigned int delay = 0, int idx = -1)
|
||||
{ m_delay=delay; m_imageIndex=idx; }
|
||||
|
||||
unsigned int m_delay;
|
||||
int m_imageIndex;
|
||||
};
|
||||
|
||||
#include "wx/arrimpl.cpp" // this is a magic incantation which must be done!
|
||||
WX_DEFINE_OBJARRAY(wxImageArray)
|
||||
|
||||
#include "wx/arrimpl.cpp" // this is a magic incantation which must be done!
|
||||
WX_DEFINE_OBJARRAY(wxANIFrameInfoArray)
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxANIDecoder
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
wxANIDecoder::wxANIDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
wxANIDecoder::~wxANIDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxANIDecoder::ConvertToImage(unsigned int frame, wxImage *image) const
|
||||
{
|
||||
unsigned int idx = m_info[frame].m_imageIndex;
|
||||
*image = m_images[idx]; // copy
|
||||
return image->IsOk();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Data accessors
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
wxSize wxANIDecoder::GetFrameSize(unsigned int WXUNUSED(frame)) const
|
||||
{
|
||||
// all frames are of the same size...
|
||||
return m_szAnimation;
|
||||
}
|
||||
|
||||
wxPoint wxANIDecoder::GetFramePosition(unsigned int WXUNUSED(frame)) const
|
||||
{
|
||||
// all frames are of the same size...
|
||||
return wxPoint(0,0);
|
||||
}
|
||||
|
||||
wxAnimationDisposal wxANIDecoder::GetDisposalMethod(unsigned int WXUNUSED(frame)) const
|
||||
{
|
||||
// this disposal is implicit for all frames inside an ANI file
|
||||
return wxANIM_TOBACKGROUND;
|
||||
}
|
||||
|
||||
long wxANIDecoder::GetDelay(unsigned int frame) const
|
||||
{
|
||||
return m_info[frame].m_delay;
|
||||
}
|
||||
|
||||
wxColour wxANIDecoder::GetTransparentColour(unsigned int frame) const
|
||||
{
|
||||
unsigned int idx = m_info[frame].m_imageIndex;
|
||||
|
||||
if (!m_images[idx].HasMask())
|
||||
return wxNullColour;
|
||||
|
||||
return wxColour(m_images[idx].GetMaskRed(),
|
||||
m_images[idx].GetMaskGreen(),
|
||||
m_images[idx].GetMaskBlue());
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// ANI reading and decoding
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool wxANIDecoder::CanRead(wxInputStream& stream) const
|
||||
{
|
||||
wxInt32 FCC1, FCC2;
|
||||
wxUint32 datalen ;
|
||||
|
||||
wxInt32 riff32;
|
||||
memcpy( &riff32, "RIFF", 4 );
|
||||
wxInt32 list32;
|
||||
memcpy( &list32, "LIST", 4 );
|
||||
wxInt32 ico32;
|
||||
memcpy( &ico32, "icon", 4 );
|
||||
wxInt32 anih32;
|
||||
memcpy( &anih32, "anih", 4 );
|
||||
|
||||
stream.SeekI(0);
|
||||
if ( !stream.Read(&FCC1, 4) )
|
||||
return false;
|
||||
|
||||
if ( FCC1 != riff32 )
|
||||
return false;
|
||||
|
||||
// we have a riff file:
|
||||
while ( stream.IsOk() )
|
||||
{
|
||||
if ( FCC1 == anih32 )
|
||||
return true; // found the ANIH chunk - this should be an ANI file
|
||||
|
||||
// we always have a data size:
|
||||
stream.Read(&datalen, 4);
|
||||
datalen = wxINT32_SWAP_ON_BE(datalen) ;
|
||||
|
||||
// data should be padded to make even number of bytes
|
||||
if (datalen % 2 == 1) datalen ++ ;
|
||||
|
||||
// now either data or a FCC:
|
||||
if ( (FCC1 == riff32) || (FCC1 == list32) )
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.SeekI(stream.TellI() + datalen);
|
||||
}
|
||||
|
||||
// try to read next data chunk:
|
||||
if ( !stream.Read(&FCC1, 4) )
|
||||
{
|
||||
// reading failed -- either EOF or IO error, bail out anyhow
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// the "anih" RIFF chunk
|
||||
struct wxANIHeader
|
||||
{
|
||||
wxInt32 cbSizeOf; // Num bytes in AniHeader (36 bytes)
|
||||
wxInt32 cFrames; // Number of unique Icons in this cursor
|
||||
wxInt32 cSteps; // Number of Blits before the animation cycles
|
||||
wxInt32 cx; // width of the frames
|
||||
wxInt32 cy; // height of the frames
|
||||
wxInt32 cBitCount; // bit depth
|
||||
wxInt32 cPlanes; // 1
|
||||
wxInt32 JifRate; // Default Jiffies (1/60th of a second) if rate chunk not present.
|
||||
wxInt32 flags; // Animation Flag (see AF_ constants)
|
||||
|
||||
// ANI files are always little endian so we need to swap bytes on big
|
||||
// endian architectures
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
void AdjustEndianness()
|
||||
{
|
||||
// this works because all our fields are wxInt32 and they must be
|
||||
// packed without holes between them (if they're not, they wouldn't map
|
||||
// to the file header!)
|
||||
wxInt32 * const start = (wxInt32 *)this;
|
||||
wxInt32 * const end = start + sizeof(wxANIHeader)/sizeof(wxInt32);
|
||||
for ( wxInt32 *p = start; p != end; p++ )
|
||||
{
|
||||
*p = wxINT32_SWAP_ALWAYS(*p);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void AdjustEndianness() { }
|
||||
#endif
|
||||
};
|
||||
|
||||
bool wxANIDecoder::Load( wxInputStream& stream )
|
||||
{
|
||||
wxInt32 FCC1, FCC2;
|
||||
wxUint32 datalen;
|
||||
unsigned int globaldelay=0;
|
||||
|
||||
wxInt32 riff32;
|
||||
memcpy( &riff32, "RIFF", 4 );
|
||||
wxInt32 list32;
|
||||
memcpy( &list32, "LIST", 4 );
|
||||
wxInt32 ico32;
|
||||
memcpy( &ico32, "icon", 4 );
|
||||
wxInt32 anih32;
|
||||
memcpy( &anih32, "anih", 4 );
|
||||
wxInt32 rate32;
|
||||
memcpy( &rate32, "rate", 4 );
|
||||
wxInt32 seq32;
|
||||
memcpy( &seq32, "seq ", 4 );
|
||||
|
||||
stream.SeekI(0);
|
||||
stream.Read(&FCC1, 4);
|
||||
if ( FCC1 != riff32 )
|
||||
return false;
|
||||
|
||||
m_nFrames = 0;
|
||||
m_szAnimation = wxDefaultSize;
|
||||
|
||||
m_images.Clear();
|
||||
m_info.Clear();
|
||||
|
||||
// we have a riff file:
|
||||
while ( stream.IsOk() )
|
||||
{
|
||||
// we always have a data size:
|
||||
stream.Read(&datalen, 4);
|
||||
datalen = wxINT32_SWAP_ON_BE(datalen);
|
||||
|
||||
//data should be padded to make even number of bytes
|
||||
if (datalen % 2 == 1) datalen++;
|
||||
|
||||
// now either data or a FCC:
|
||||
if ( (FCC1 == riff32) || (FCC1 == list32) )
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
}
|
||||
else if ( FCC1 == anih32 )
|
||||
{
|
||||
if ( datalen != sizeof(wxANIHeader) )
|
||||
return false;
|
||||
|
||||
if (m_nFrames > 0)
|
||||
return false; // already parsed an ani header?
|
||||
|
||||
struct wxANIHeader header;
|
||||
stream.Read(&header, sizeof(wxANIHeader));
|
||||
header.AdjustEndianness();
|
||||
|
||||
// we should have a global frame size
|
||||
m_szAnimation = wxSize(header.cx, header.cy);
|
||||
|
||||
// save interesting info from the header
|
||||
m_nFrames = header.cSteps; // NB: not cFrames!!
|
||||
if ( m_nFrames == 0 )
|
||||
return false;
|
||||
|
||||
globaldelay = header.JifRate * 1000 / 60;
|
||||
|
||||
m_images.Alloc(header.cFrames);
|
||||
m_info.Add(wxANIFrameInfo(), m_nFrames);
|
||||
}
|
||||
else if ( FCC1 == rate32 )
|
||||
{
|
||||
// did we already process the anih32 chunk?
|
||||
if (m_nFrames == 0)
|
||||
return false; // rate chunks should always be placed after anih chunk
|
||||
|
||||
wxASSERT(m_info.GetCount() == m_nFrames);
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
m_info[i].m_delay = wxINT32_SWAP_ON_BE(FCC2) * 1000 / 60;
|
||||
}
|
||||
}
|
||||
else if ( FCC1 == seq32 )
|
||||
{
|
||||
// did we already process the anih32 chunk?
|
||||
if (m_nFrames == 0)
|
||||
return false; // seq chunks should always be placed after anih chunk
|
||||
|
||||
wxASSERT(m_info.GetCount() == m_nFrames);
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
{
|
||||
stream.Read(&FCC2, 4);
|
||||
m_info[i].m_imageIndex = wxINT32_SWAP_ON_BE(FCC2);
|
||||
}
|
||||
}
|
||||
else if ( FCC1 == ico32 )
|
||||
{
|
||||
// use DoLoadFile() and not LoadFile()!
|
||||
wxImage image;
|
||||
if (!sm_handler.DoLoadFile(&image, stream, false /* verbose */, -1))
|
||||
return false;
|
||||
|
||||
m_images.Add(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.SeekI(stream.TellI() + datalen);
|
||||
}
|
||||
|
||||
// try to read next data chunk:
|
||||
stream.Read(&FCC1, 4);
|
||||
}
|
||||
|
||||
if (m_nFrames==0)
|
||||
return false;
|
||||
|
||||
if (m_nFrames==m_images.GetCount())
|
||||
{
|
||||
// if no SEQ chunk is available, display the frames in the order
|
||||
// they were loaded
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
if (m_info[i].m_imageIndex == -1)
|
||||
m_info[i].m_imageIndex = i;
|
||||
}
|
||||
|
||||
// if some frame has an invalid delay, use the global delay given in the
|
||||
// ANI header
|
||||
for (unsigned int i=0; i<m_nFrames; i++)
|
||||
if (m_info[i].m_delay == 0)
|
||||
m_info[i].m_delay = globaldelay;
|
||||
|
||||
// if the header did not contain a valid frame size, try to grab
|
||||
// it from the size of the first frame (all frames are of the same size)
|
||||
if (m_szAnimation.GetWidth() == 0 ||
|
||||
m_szAnimation.GetHeight() == 0)
|
||||
m_szAnimation = wxSize(m_images[0].GetWidth(), m_images[0].GetHeight());
|
||||
|
||||
return m_szAnimation != wxDefaultSize;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_ICO_CUR
|
||||
|
206
Externals/wxWidgets/src/common/animatecmn.cpp
vendored
206
Externals/wxWidgets/src/common/animatecmn.cpp
vendored
@ -1,103 +1,103 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/animatecmn.cpp
|
||||
// Purpose: wxAnimation and wxAnimationCtrl
|
||||
// Author: Francesco Montorsi
|
||||
// Modified By:
|
||||
// Created: 24/09/2006
|
||||
// Id: $Id: animatecmn.cpp 43494 2006-11-18 17:46:29Z RR $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if wxUSE_ANIMATIONCTRL
|
||||
|
||||
#include "wx/animate.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/brush.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/dcmemory.h"
|
||||
|
||||
const wxChar wxAnimationCtrlNameStr[] = wxT("animationctrl");
|
||||
|
||||
// global object
|
||||
wxAnimation wxNullAnimation;
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxAnimationCtrlBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxAnimationCtrlBase::UpdateStaticImage()
|
||||
{
|
||||
if (!m_bmpStaticReal.IsOk() || !m_bmpStatic.IsOk())
|
||||
return;
|
||||
|
||||
// if given bitmap is not of the right size, recreate m_bmpStaticReal accordingly
|
||||
const wxSize &sz = GetClientSize();
|
||||
if (sz.GetWidth() != m_bmpStaticReal.GetWidth() ||
|
||||
sz.GetHeight() != m_bmpStaticReal.GetHeight())
|
||||
{
|
||||
if (!m_bmpStaticReal.IsOk() ||
|
||||
m_bmpStaticReal.GetWidth() != sz.GetWidth() ||
|
||||
m_bmpStaticReal.GetHeight() != sz.GetHeight())
|
||||
{
|
||||
// need to (re)create m_bmpStaticReal
|
||||
if (!m_bmpStaticReal.Create(sz.GetWidth(), sz.GetHeight(),
|
||||
m_bmpStatic.GetDepth()))
|
||||
{
|
||||
wxLogDebug(wxT("Cannot create the static bitmap"));
|
||||
m_bmpStatic = wxNullBitmap;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bmpStatic.GetWidth() <= sz.GetWidth() &&
|
||||
m_bmpStatic.GetHeight() <= sz.GetHeight())
|
||||
{
|
||||
// clear the background of m_bmpStaticReal
|
||||
wxBrush brush(GetBackgroundColour());
|
||||
wxMemoryDC dc;
|
||||
dc.SelectObject(m_bmpStaticReal);
|
||||
dc.SetBackground(brush);
|
||||
dc.Clear();
|
||||
|
||||
// center the user-provided bitmap in m_bmpStaticReal
|
||||
dc.DrawBitmap(m_bmpStatic,
|
||||
(sz.GetWidth()-m_bmpStatic.GetWidth())/2,
|
||||
(sz.GetHeight()-m_bmpStatic.GetHeight())/2,
|
||||
true /* use mask */ );
|
||||
}
|
||||
else
|
||||
{
|
||||
// the user-provided bitmap is bigger than our control, strech it
|
||||
wxImage temp(m_bmpStatic.ConvertToImage());
|
||||
temp.Rescale(sz.GetWidth(), sz.GetHeight(), wxIMAGE_QUALITY_HIGH);
|
||||
m_bmpStaticReal = wxBitmap(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap &bmp)
|
||||
{
|
||||
m_bmpStatic = bmp;
|
||||
m_bmpStaticReal = bmp;
|
||||
|
||||
// if not playing, update the control now
|
||||
// NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
|
||||
if ( !IsPlaying() )
|
||||
DisplayStaticImage();
|
||||
}
|
||||
|
||||
#endif // wxUSE_ANIMATIONCTRL
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/animatecmn.cpp
|
||||
// Purpose: wxAnimation and wxAnimationCtrl
|
||||
// Author: Francesco Montorsi
|
||||
// Modified By:
|
||||
// Created: 24/09/2006
|
||||
// Id: $Id: animatecmn.cpp 43494 2006-11-18 17:46:29Z RR $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if wxUSE_ANIMATIONCTRL
|
||||
|
||||
#include "wx/animate.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/brush.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/dcmemory.h"
|
||||
|
||||
const wxChar wxAnimationCtrlNameStr[] = wxT("animationctrl");
|
||||
|
||||
// global object
|
||||
wxAnimation wxNullAnimation;
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxAnimationCtrlBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxAnimationCtrlBase::UpdateStaticImage()
|
||||
{
|
||||
if (!m_bmpStaticReal.IsOk() || !m_bmpStatic.IsOk())
|
||||
return;
|
||||
|
||||
// if given bitmap is not of the right size, recreate m_bmpStaticReal accordingly
|
||||
const wxSize &sz = GetClientSize();
|
||||
if (sz.GetWidth() != m_bmpStaticReal.GetWidth() ||
|
||||
sz.GetHeight() != m_bmpStaticReal.GetHeight())
|
||||
{
|
||||
if (!m_bmpStaticReal.IsOk() ||
|
||||
m_bmpStaticReal.GetWidth() != sz.GetWidth() ||
|
||||
m_bmpStaticReal.GetHeight() != sz.GetHeight())
|
||||
{
|
||||
// need to (re)create m_bmpStaticReal
|
||||
if (!m_bmpStaticReal.Create(sz.GetWidth(), sz.GetHeight(),
|
||||
m_bmpStatic.GetDepth()))
|
||||
{
|
||||
wxLogDebug(wxT("Cannot create the static bitmap"));
|
||||
m_bmpStatic = wxNullBitmap;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bmpStatic.GetWidth() <= sz.GetWidth() &&
|
||||
m_bmpStatic.GetHeight() <= sz.GetHeight())
|
||||
{
|
||||
// clear the background of m_bmpStaticReal
|
||||
wxBrush brush(GetBackgroundColour());
|
||||
wxMemoryDC dc;
|
||||
dc.SelectObject(m_bmpStaticReal);
|
||||
dc.SetBackground(brush);
|
||||
dc.Clear();
|
||||
|
||||
// center the user-provided bitmap in m_bmpStaticReal
|
||||
dc.DrawBitmap(m_bmpStatic,
|
||||
(sz.GetWidth()-m_bmpStatic.GetWidth())/2,
|
||||
(sz.GetHeight()-m_bmpStatic.GetHeight())/2,
|
||||
true /* use mask */ );
|
||||
}
|
||||
else
|
||||
{
|
||||
// the user-provided bitmap is bigger than our control, strech it
|
||||
wxImage temp(m_bmpStatic.ConvertToImage());
|
||||
temp.Rescale(sz.GetWidth(), sz.GetHeight(), wxIMAGE_QUALITY_HIGH);
|
||||
m_bmpStaticReal = wxBitmap(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxAnimationCtrlBase::SetInactiveBitmap(const wxBitmap &bmp)
|
||||
{
|
||||
m_bmpStatic = bmp;
|
||||
m_bmpStaticReal = bmp;
|
||||
|
||||
// if not playing, update the control now
|
||||
// NOTE: DisplayStaticImage() will call UpdateStaticImage automatically
|
||||
if ( !IsPlaying() )
|
||||
DisplayStaticImage();
|
||||
}
|
||||
|
||||
#endif // wxUSE_ANIMATIONCTRL
|
||||
|
1692
Externals/wxWidgets/src/common/appbase.cpp
vendored
1692
Externals/wxWidgets/src/common/appbase.cpp
vendored
File diff suppressed because it is too large
Load Diff
1382
Externals/wxWidgets/src/common/appcmn.cpp
vendored
1382
Externals/wxWidgets/src/common/appcmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
82
Externals/wxWidgets/src/common/arcall.cpp
vendored
82
Externals/wxWidgets/src/common/arcall.cpp
vendored
@ -1,41 +1,41 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/arcall.cpp
|
||||
// Purpose: wxArchive link all archive streams
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: arcall.cpp 42508 2006-10-27 09:53:38Z MW $
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_ARCHIVE_STREAMS
|
||||
|
||||
#if wxUSE_ZIPSTREAM
|
||||
#include "wx/zipstrm.h"
|
||||
#endif
|
||||
#if wxUSE_TARSTREAM
|
||||
#include "wx/tarstrm.h"
|
||||
#endif
|
||||
|
||||
// Reference archive classes to ensure they are linked into a statically
|
||||
// linked program that uses Find or GetFirst to look for an archive handler.
|
||||
// It is in its own file so that the user can override this behaviour by
|
||||
// providing their own implementation.
|
||||
|
||||
void wxUseArchiveClasses()
|
||||
{
|
||||
#if wxUSE_ZIPSTREAM
|
||||
wxZipClassFactory();
|
||||
#endif
|
||||
#if wxUSE_TARSTREAM
|
||||
wxTarClassFactory();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_ARCHIVE_STREAMS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/arcall.cpp
|
||||
// Purpose: wxArchive link all archive streams
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: arcall.cpp 42508 2006-10-27 09:53:38Z MW $
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_ARCHIVE_STREAMS
|
||||
|
||||
#if wxUSE_ZIPSTREAM
|
||||
#include "wx/zipstrm.h"
|
||||
#endif
|
||||
#if wxUSE_TARSTREAM
|
||||
#include "wx/tarstrm.h"
|
||||
#endif
|
||||
|
||||
// Reference archive classes to ensure they are linked into a statically
|
||||
// linked program that uses Find or GetFirst to look for an archive handler.
|
||||
// It is in its own file so that the user can override this behaviour by
|
||||
// providing their own implementation.
|
||||
|
||||
void wxUseArchiveClasses()
|
||||
{
|
||||
#if wxUSE_ZIPSTREAM
|
||||
wxZipClassFactory();
|
||||
#endif
|
||||
#if wxUSE_TARSTREAM
|
||||
wxTarClassFactory();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_ARCHIVE_STREAMS
|
||||
|
86
Externals/wxWidgets/src/common/arcfind.cpp
vendored
86
Externals/wxWidgets/src/common/arcfind.cpp
vendored
@ -1,43 +1,43 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/arcfind.cpp
|
||||
// Purpose: Streams for archive formats
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: arcfind.cpp 42508 2006-10-27 09:53:38Z MW $
|
||||
// Copyright: (c) Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_ARCHIVE_STREAMS
|
||||
|
||||
#include "wx/archive.h"
|
||||
|
||||
// These functions are in a separate file so that statically linked apps
|
||||
// that do not call them to search for archive handlers will only link in
|
||||
// the archive classes they use.
|
||||
|
||||
const wxArchiveClassFactory *
|
||||
wxArchiveClassFactory::Find(const wxChar *protocol, wxStreamProtocolType type)
|
||||
{
|
||||
for (const wxArchiveClassFactory *f = GetFirst(); f; f = f->GetNext())
|
||||
if (f->CanHandle(protocol, type))
|
||||
return f;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static
|
||||
const wxArchiveClassFactory *wxArchiveClassFactory::GetFirst()
|
||||
{
|
||||
if (!sm_first)
|
||||
wxUseArchiveClasses();
|
||||
return sm_first;
|
||||
}
|
||||
|
||||
#endif // wxUSE_ARCHIVE_STREAMS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/arcfind.cpp
|
||||
// Purpose: Streams for archive formats
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: arcfind.cpp 42508 2006-10-27 09:53:38Z MW $
|
||||
// Copyright: (c) Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_ARCHIVE_STREAMS
|
||||
|
||||
#include "wx/archive.h"
|
||||
|
||||
// These functions are in a separate file so that statically linked apps
|
||||
// that do not call them to search for archive handlers will only link in
|
||||
// the archive classes they use.
|
||||
|
||||
const wxArchiveClassFactory *
|
||||
wxArchiveClassFactory::Find(const wxChar *protocol, wxStreamProtocolType type)
|
||||
{
|
||||
for (const wxArchiveClassFactory *f = GetFirst(); f; f = f->GetNext())
|
||||
if (f->CanHandle(protocol, type))
|
||||
return f;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static
|
||||
const wxArchiveClassFactory *wxArchiveClassFactory::GetFirst()
|
||||
{
|
||||
if (!sm_first)
|
||||
wxUseArchiveClasses();
|
||||
return sm_first;
|
||||
}
|
||||
|
||||
#endif // wxUSE_ARCHIVE_STREAMS
|
||||
|
196
Externals/wxWidgets/src/common/archive.cpp
vendored
196
Externals/wxWidgets/src/common/archive.cpp
vendored
@ -1,98 +1,98 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/archive.cpp
|
||||
// Purpose: Streams for archive formats
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: archive.cpp 42508 2006-10-27 09:53:38Z MW $
|
||||
// Copyright: (c) Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS
|
||||
|
||||
#include "wx/archive.h"
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxArchiveEntry, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxArchiveClassFactory, wxFilterClassFactoryBase)
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveInputStream
|
||||
|
||||
wxArchiveInputStream::wxArchiveInputStream(wxInputStream& stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterInputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
wxArchiveInputStream::wxArchiveInputStream(wxInputStream *stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterInputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveOutputStream
|
||||
|
||||
wxArchiveOutputStream::wxArchiveOutputStream(wxOutputStream& stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterOutputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
wxArchiveOutputStream::wxArchiveOutputStream(wxOutputStream *stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterOutputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveEntry
|
||||
|
||||
void wxArchiveEntry::SetNotifier(wxArchiveNotifier& notifier)
|
||||
{
|
||||
UnsetNotifier();
|
||||
m_notifier = ¬ifier;
|
||||
m_notifier->OnEntryUpdated(*this);
|
||||
}
|
||||
|
||||
wxArchiveEntry& wxArchiveEntry::operator=(const wxArchiveEntry& WXUNUSED(e))
|
||||
{
|
||||
m_notifier = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveClassFactory
|
||||
|
||||
wxArchiveClassFactory *wxArchiveClassFactory::sm_first = NULL;
|
||||
|
||||
void wxArchiveClassFactory::Remove()
|
||||
{
|
||||
if (m_next != this)
|
||||
{
|
||||
wxArchiveClassFactory **pp = &sm_first;
|
||||
|
||||
while (*pp != this)
|
||||
pp = &(*pp)->m_next;
|
||||
|
||||
*pp = m_next;
|
||||
|
||||
m_next = this;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/archive.cpp
|
||||
// Purpose: Streams for archive formats
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: archive.cpp 42508 2006-10-27 09:53:38Z MW $
|
||||
// Copyright: (c) Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS
|
||||
|
||||
#include "wx/archive.h"
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxArchiveEntry, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxArchiveClassFactory, wxFilterClassFactoryBase)
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveInputStream
|
||||
|
||||
wxArchiveInputStream::wxArchiveInputStream(wxInputStream& stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterInputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
wxArchiveInputStream::wxArchiveInputStream(wxInputStream *stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterInputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveOutputStream
|
||||
|
||||
wxArchiveOutputStream::wxArchiveOutputStream(wxOutputStream& stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterOutputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
wxArchiveOutputStream::wxArchiveOutputStream(wxOutputStream *stream,
|
||||
wxMBConv& conv)
|
||||
: wxFilterOutputStream(stream),
|
||||
m_conv(conv)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveEntry
|
||||
|
||||
void wxArchiveEntry::SetNotifier(wxArchiveNotifier& notifier)
|
||||
{
|
||||
UnsetNotifier();
|
||||
m_notifier = ¬ifier;
|
||||
m_notifier->OnEntryUpdated(*this);
|
||||
}
|
||||
|
||||
wxArchiveEntry& wxArchiveEntry::operator=(const wxArchiveEntry& WXUNUSED(e))
|
||||
{
|
||||
m_notifier = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// wxArchiveClassFactory
|
||||
|
||||
wxArchiveClassFactory *wxArchiveClassFactory::sm_first = NULL;
|
||||
|
||||
void wxArchiveClassFactory::Remove()
|
||||
{
|
||||
if (m_next != this)
|
||||
{
|
||||
wxArchiveClassFactory **pp = &sm_first;
|
||||
|
||||
while (*pp != this)
|
||||
pp = &(*pp)->m_next;
|
||||
|
||||
*pp = m_next;
|
||||
|
||||
m_next = this;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS
|
||||
|
676
Externals/wxWidgets/src/common/artprov.cpp
vendored
676
Externals/wxWidgets/src/common/artprov.cpp
vendored
@ -1,338 +1,338 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/artprov.cpp
|
||||
// Purpose: wxArtProvider class
|
||||
// Author: Vaclav Slavik
|
||||
// Modified by:
|
||||
// Created: 18/03/2002
|
||||
// RCS-ID: $Id: artprov.cpp 41398 2006-09-23 20:16:18Z VZ $
|
||||
// Copyright: (c) Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// headers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/artprov.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/list.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
// ===========================================================================
|
||||
// implementation
|
||||
// ===========================================================================
|
||||
|
||||
#include "wx/listimpl.cpp"
|
||||
WX_DECLARE_LIST(wxArtProvider, wxArtProvidersList);
|
||||
WX_DEFINE_LIST(wxArtProvidersList)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Cache class - stores already requested bitmaps
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash);
|
||||
|
||||
class WXDLLEXPORT wxArtProviderCache
|
||||
{
|
||||
public:
|
||||
bool GetBitmap(const wxString& full_id, wxBitmap* bmp);
|
||||
void PutBitmap(const wxString& full_id, const wxBitmap& bmp)
|
||||
{ m_bitmapsHash[full_id] = bmp; }
|
||||
|
||||
void Clear();
|
||||
|
||||
static wxString ConstructHashID(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& size);
|
||||
|
||||
private:
|
||||
wxArtProviderBitmapsHash m_bitmapsHash;
|
||||
};
|
||||
|
||||
bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp)
|
||||
{
|
||||
wxArtProviderBitmapsHash::iterator entry = m_bitmapsHash.find(full_id);
|
||||
if ( entry == m_bitmapsHash.end() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bmp = entry->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void wxArtProviderCache::Clear()
|
||||
{
|
||||
m_bitmapsHash.clear();
|
||||
}
|
||||
|
||||
/*static*/ wxString wxArtProviderCache::ConstructHashID(
|
||||
const wxArtID& id, const wxArtClient& client,
|
||||
const wxSize& size)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf(wxT("%s-%s-%i-%i"), id.c_str(), client.c_str(), size.x, size.y);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// wxArtProvider class
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxArtProvider, wxObject)
|
||||
|
||||
wxArtProvidersList *wxArtProvider::sm_providers = NULL;
|
||||
wxArtProviderCache *wxArtProvider::sm_cache = NULL;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider ctors/dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxArtProvider::~wxArtProvider()
|
||||
{
|
||||
Remove(this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider operations on provider stack
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/ void wxArtProvider::CommonAddingProvider()
|
||||
{
|
||||
if ( !sm_providers )
|
||||
{
|
||||
sm_providers = new wxArtProvidersList;
|
||||
sm_cache = new wxArtProviderCache;
|
||||
}
|
||||
|
||||
sm_cache->Clear();
|
||||
}
|
||||
|
||||
/*static*/ void wxArtProvider::Push(wxArtProvider *provider)
|
||||
{
|
||||
CommonAddingProvider();
|
||||
sm_providers->Insert(provider);
|
||||
}
|
||||
|
||||
/*static*/ void wxArtProvider::Insert(wxArtProvider *provider)
|
||||
{
|
||||
CommonAddingProvider();
|
||||
sm_providers->Append(provider);
|
||||
}
|
||||
|
||||
/*static*/ bool wxArtProvider::Pop()
|
||||
{
|
||||
wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") );
|
||||
wxCHECK_MSG( !sm_providers->empty(), false, _T("wxArtProviders stack is empty") );
|
||||
|
||||
delete sm_providers->GetFirst()->GetData();
|
||||
sm_cache->Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool wxArtProvider::Remove(wxArtProvider *provider)
|
||||
{
|
||||
wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") );
|
||||
|
||||
if ( sm_providers->DeleteObject(provider) )
|
||||
{
|
||||
sm_cache->Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*static*/ bool wxArtProvider::Delete(wxArtProvider *provider)
|
||||
{
|
||||
// provider will remove itself from the stack in its dtor
|
||||
delete provider;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ void wxArtProvider::CleanUpProviders()
|
||||
{
|
||||
if ( sm_providers )
|
||||
{
|
||||
while ( !sm_providers->empty() )
|
||||
delete *sm_providers->begin();
|
||||
|
||||
delete sm_providers;
|
||||
sm_providers = NULL;
|
||||
|
||||
delete sm_cache;
|
||||
sm_cache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider: retrieving bitmaps/icons
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& size)
|
||||
{
|
||||
// safety-check against writing client,id,size instead of id,client,size:
|
||||
wxASSERT_MSG( client.Last() == _T('C'), _T("invalid 'client' parameter") );
|
||||
|
||||
wxCHECK_MSG( sm_providers, wxNullBitmap, _T("no wxArtProvider exists") );
|
||||
|
||||
wxString hashId = wxArtProviderCache::ConstructHashID(id, client, size);
|
||||
|
||||
wxBitmap bmp;
|
||||
if ( !sm_cache->GetBitmap(hashId, &bmp) )
|
||||
{
|
||||
for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
|
||||
node; node = node->GetNext())
|
||||
{
|
||||
bmp = node->GetData()->CreateBitmap(id, client, size);
|
||||
if ( bmp.Ok() )
|
||||
{
|
||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
||||
if ( size != wxDefaultSize &&
|
||||
(bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) )
|
||||
{
|
||||
wxImage img = bmp.ConvertToImage();
|
||||
img.Rescale(size.x, size.y);
|
||||
bmp = wxBitmap(img);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sm_cache->PutBitmap(hashId, bmp);
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
/*static*/ wxIcon wxArtProvider::GetIcon(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& size)
|
||||
{
|
||||
wxCHECK_MSG( sm_providers, wxNullIcon, _T("no wxArtProvider exists") );
|
||||
|
||||
wxBitmap bmp = GetBitmap(id, client, size);
|
||||
if ( !bmp.Ok() )
|
||||
return wxNullIcon;
|
||||
|
||||
wxIcon icon;
|
||||
icon.CopyFromBitmap(bmp);
|
||||
return icon;
|
||||
}
|
||||
|
||||
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
||||
#include "wx/gtk/private.h"
|
||||
extern GtkIconSize wxArtClientToIconSize(const wxArtClient& client);
|
||||
#endif // defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
||||
|
||||
/*static*/ wxSize wxArtProvider::GetSizeHint(const wxArtClient& client,
|
||||
bool platform_dependent)
|
||||
{
|
||||
if (!platform_dependent)
|
||||
{
|
||||
wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
|
||||
if (node)
|
||||
return node->GetData()->DoGetSizeHint(client);
|
||||
}
|
||||
|
||||
// else return platform dependent size
|
||||
|
||||
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
||||
// Gtk has specific sizes for each client, see artgtk.cpp
|
||||
GtkIconSize gtk_size = wxArtClientToIconSize(client);
|
||||
// no size hints for this client
|
||||
if (gtk_size == GTK_ICON_SIZE_INVALID)
|
||||
return wxDefaultSize;
|
||||
gint width, height;
|
||||
gtk_icon_size_lookup( gtk_size, &width, &height);
|
||||
return wxSize(width, height);
|
||||
#else // !GTK+ 2
|
||||
// NB: These size hints may have to be adjusted per platform
|
||||
if (client == wxART_TOOLBAR)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_MENU)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_FRAME_ICON)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_CMN_DIALOG || client == wxART_MESSAGE_BOX)
|
||||
return wxSize(32, 32);
|
||||
else if (client == wxART_HELP_BROWSER)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_BUTTON)
|
||||
return wxSize(16, 15);
|
||||
else // wxART_OTHER or perhaps a user's client, no specified size
|
||||
return wxDefaultSize;
|
||||
#endif // GTK+ 2/else
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// deprecated wxArtProvider methods
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
/* static */ void wxArtProvider::PushProvider(wxArtProvider *provider)
|
||||
{
|
||||
Push(provider);
|
||||
}
|
||||
|
||||
/* static */ void wxArtProvider::InsertProvider(wxArtProvider *provider)
|
||||
{
|
||||
Insert(provider);
|
||||
}
|
||||
|
||||
/* static */ bool wxArtProvider::PopProvider()
|
||||
{
|
||||
return Pop();
|
||||
}
|
||||
|
||||
/* static */ bool wxArtProvider::RemoveProvider(wxArtProvider *provider)
|
||||
{
|
||||
// RemoveProvider() used to delete the provider being removed so this is
|
||||
// not a typo, we must call Delete() and not Remove() here
|
||||
return Delete(provider);
|
||||
}
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// ============================================================================
|
||||
// wxArtProviderModule
|
||||
// ============================================================================
|
||||
|
||||
class wxArtProviderModule: public wxModule
|
||||
{
|
||||
public:
|
||||
bool OnInit()
|
||||
{
|
||||
wxArtProvider::InitStdProvider();
|
||||
wxArtProvider::InitNativeProvider();
|
||||
return true;
|
||||
}
|
||||
void OnExit()
|
||||
{
|
||||
wxArtProvider::CleanUpProviders();
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxArtProviderModule)
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxArtProviderModule, wxModule)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/artprov.cpp
|
||||
// Purpose: wxArtProvider class
|
||||
// Author: Vaclav Slavik
|
||||
// Modified by:
|
||||
// Created: 18/03/2002
|
||||
// RCS-ID: $Id: artprov.cpp 41398 2006-09-23 20:16:18Z VZ $
|
||||
// Copyright: (c) Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// headers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/artprov.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/list.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
// ===========================================================================
|
||||
// implementation
|
||||
// ===========================================================================
|
||||
|
||||
#include "wx/listimpl.cpp"
|
||||
WX_DECLARE_LIST(wxArtProvider, wxArtProvidersList);
|
||||
WX_DEFINE_LIST(wxArtProvidersList)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Cache class - stores already requested bitmaps
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash);
|
||||
|
||||
class WXDLLEXPORT wxArtProviderCache
|
||||
{
|
||||
public:
|
||||
bool GetBitmap(const wxString& full_id, wxBitmap* bmp);
|
||||
void PutBitmap(const wxString& full_id, const wxBitmap& bmp)
|
||||
{ m_bitmapsHash[full_id] = bmp; }
|
||||
|
||||
void Clear();
|
||||
|
||||
static wxString ConstructHashID(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& size);
|
||||
|
||||
private:
|
||||
wxArtProviderBitmapsHash m_bitmapsHash;
|
||||
};
|
||||
|
||||
bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp)
|
||||
{
|
||||
wxArtProviderBitmapsHash::iterator entry = m_bitmapsHash.find(full_id);
|
||||
if ( entry == m_bitmapsHash.end() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bmp = entry->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void wxArtProviderCache::Clear()
|
||||
{
|
||||
m_bitmapsHash.clear();
|
||||
}
|
||||
|
||||
/*static*/ wxString wxArtProviderCache::ConstructHashID(
|
||||
const wxArtID& id, const wxArtClient& client,
|
||||
const wxSize& size)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf(wxT("%s-%s-%i-%i"), id.c_str(), client.c_str(), size.x, size.y);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// wxArtProvider class
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxArtProvider, wxObject)
|
||||
|
||||
wxArtProvidersList *wxArtProvider::sm_providers = NULL;
|
||||
wxArtProviderCache *wxArtProvider::sm_cache = NULL;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider ctors/dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxArtProvider::~wxArtProvider()
|
||||
{
|
||||
Remove(this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider operations on provider stack
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/ void wxArtProvider::CommonAddingProvider()
|
||||
{
|
||||
if ( !sm_providers )
|
||||
{
|
||||
sm_providers = new wxArtProvidersList;
|
||||
sm_cache = new wxArtProviderCache;
|
||||
}
|
||||
|
||||
sm_cache->Clear();
|
||||
}
|
||||
|
||||
/*static*/ void wxArtProvider::Push(wxArtProvider *provider)
|
||||
{
|
||||
CommonAddingProvider();
|
||||
sm_providers->Insert(provider);
|
||||
}
|
||||
|
||||
/*static*/ void wxArtProvider::Insert(wxArtProvider *provider)
|
||||
{
|
||||
CommonAddingProvider();
|
||||
sm_providers->Append(provider);
|
||||
}
|
||||
|
||||
/*static*/ bool wxArtProvider::Pop()
|
||||
{
|
||||
wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") );
|
||||
wxCHECK_MSG( !sm_providers->empty(), false, _T("wxArtProviders stack is empty") );
|
||||
|
||||
delete sm_providers->GetFirst()->GetData();
|
||||
sm_cache->Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool wxArtProvider::Remove(wxArtProvider *provider)
|
||||
{
|
||||
wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") );
|
||||
|
||||
if ( sm_providers->DeleteObject(provider) )
|
||||
{
|
||||
sm_cache->Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*static*/ bool wxArtProvider::Delete(wxArtProvider *provider)
|
||||
{
|
||||
// provider will remove itself from the stack in its dtor
|
||||
delete provider;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ void wxArtProvider::CleanUpProviders()
|
||||
{
|
||||
if ( sm_providers )
|
||||
{
|
||||
while ( !sm_providers->empty() )
|
||||
delete *sm_providers->begin();
|
||||
|
||||
delete sm_providers;
|
||||
sm_providers = NULL;
|
||||
|
||||
delete sm_cache;
|
||||
sm_cache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider: retrieving bitmaps/icons
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& size)
|
||||
{
|
||||
// safety-check against writing client,id,size instead of id,client,size:
|
||||
wxASSERT_MSG( client.Last() == _T('C'), _T("invalid 'client' parameter") );
|
||||
|
||||
wxCHECK_MSG( sm_providers, wxNullBitmap, _T("no wxArtProvider exists") );
|
||||
|
||||
wxString hashId = wxArtProviderCache::ConstructHashID(id, client, size);
|
||||
|
||||
wxBitmap bmp;
|
||||
if ( !sm_cache->GetBitmap(hashId, &bmp) )
|
||||
{
|
||||
for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
|
||||
node; node = node->GetNext())
|
||||
{
|
||||
bmp = node->GetData()->CreateBitmap(id, client, size);
|
||||
if ( bmp.Ok() )
|
||||
{
|
||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
||||
if ( size != wxDefaultSize &&
|
||||
(bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) )
|
||||
{
|
||||
wxImage img = bmp.ConvertToImage();
|
||||
img.Rescale(size.x, size.y);
|
||||
bmp = wxBitmap(img);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sm_cache->PutBitmap(hashId, bmp);
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
/*static*/ wxIcon wxArtProvider::GetIcon(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& size)
|
||||
{
|
||||
wxCHECK_MSG( sm_providers, wxNullIcon, _T("no wxArtProvider exists") );
|
||||
|
||||
wxBitmap bmp = GetBitmap(id, client, size);
|
||||
if ( !bmp.Ok() )
|
||||
return wxNullIcon;
|
||||
|
||||
wxIcon icon;
|
||||
icon.CopyFromBitmap(bmp);
|
||||
return icon;
|
||||
}
|
||||
|
||||
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
||||
#include "wx/gtk/private.h"
|
||||
extern GtkIconSize wxArtClientToIconSize(const wxArtClient& client);
|
||||
#endif // defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
||||
|
||||
/*static*/ wxSize wxArtProvider::GetSizeHint(const wxArtClient& client,
|
||||
bool platform_dependent)
|
||||
{
|
||||
if (!platform_dependent)
|
||||
{
|
||||
wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
|
||||
if (node)
|
||||
return node->GetData()->DoGetSizeHint(client);
|
||||
}
|
||||
|
||||
// else return platform dependent size
|
||||
|
||||
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
||||
// Gtk has specific sizes for each client, see artgtk.cpp
|
||||
GtkIconSize gtk_size = wxArtClientToIconSize(client);
|
||||
// no size hints for this client
|
||||
if (gtk_size == GTK_ICON_SIZE_INVALID)
|
||||
return wxDefaultSize;
|
||||
gint width, height;
|
||||
gtk_icon_size_lookup( gtk_size, &width, &height);
|
||||
return wxSize(width, height);
|
||||
#else // !GTK+ 2
|
||||
// NB: These size hints may have to be adjusted per platform
|
||||
if (client == wxART_TOOLBAR)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_MENU)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_FRAME_ICON)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_CMN_DIALOG || client == wxART_MESSAGE_BOX)
|
||||
return wxSize(32, 32);
|
||||
else if (client == wxART_HELP_BROWSER)
|
||||
return wxSize(16, 15);
|
||||
else if (client == wxART_BUTTON)
|
||||
return wxSize(16, 15);
|
||||
else // wxART_OTHER or perhaps a user's client, no specified size
|
||||
return wxDefaultSize;
|
||||
#endif // GTK+ 2/else
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// deprecated wxArtProvider methods
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
/* static */ void wxArtProvider::PushProvider(wxArtProvider *provider)
|
||||
{
|
||||
Push(provider);
|
||||
}
|
||||
|
||||
/* static */ void wxArtProvider::InsertProvider(wxArtProvider *provider)
|
||||
{
|
||||
Insert(provider);
|
||||
}
|
||||
|
||||
/* static */ bool wxArtProvider::PopProvider()
|
||||
{
|
||||
return Pop();
|
||||
}
|
||||
|
||||
/* static */ bool wxArtProvider::RemoveProvider(wxArtProvider *provider)
|
||||
{
|
||||
// RemoveProvider() used to delete the provider being removed so this is
|
||||
// not a typo, we must call Delete() and not Remove() here
|
||||
return Delete(provider);
|
||||
}
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// ============================================================================
|
||||
// wxArtProviderModule
|
||||
// ============================================================================
|
||||
|
||||
class wxArtProviderModule: public wxModule
|
||||
{
|
||||
public:
|
||||
bool OnInit()
|
||||
{
|
||||
wxArtProvider::InitStdProvider();
|
||||
wxArtProvider::InitNativeProvider();
|
||||
return true;
|
||||
}
|
||||
void OnExit()
|
||||
{
|
||||
wxArtProvider::CleanUpProviders();
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxArtProviderModule)
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxArtProviderModule, wxModule)
|
||||
|
534
Externals/wxWidgets/src/common/artstd.cpp
vendored
534
Externals/wxWidgets/src/common/artstd.cpp
vendored
@ -1,267 +1,267 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/artstd.cpp
|
||||
// Purpose: stock wxArtProvider instance with default wxWin art
|
||||
// Author: Vaclav Slavik
|
||||
// Modified by:
|
||||
// Created: 18/03/2002
|
||||
// RCS-ID: $Id: artstd.cpp 52561 2008-03-16 00:36:37Z VS $
|
||||
// Copyright: (c) Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// headers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
#include "wx/artprov.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDefaultArtProvider
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDefaultArtProvider : public wxArtProvider
|
||||
{
|
||||
protected:
|
||||
virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
|
||||
const wxSize& size);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Standard macro for getting a resource from XPM file:
|
||||
#define ART(artId, xpmRc) \
|
||||
if ( id == artId ) return wxBitmap(xpmRc##_xpm);
|
||||
|
||||
// There are two ways of getting the standard icon: either via XPMs or via
|
||||
// wxIcon ctor. This depends on the platform:
|
||||
#if defined(__WXUNIVERSAL__)
|
||||
#define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
|
||||
#elif defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||
#define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
|
||||
#else
|
||||
#define CREATE_STD_ICON(iconId, xpmRc) \
|
||||
{ \
|
||||
wxIcon icon(_T(iconId)); \
|
||||
wxBitmap bmp; \
|
||||
bmp.CopyFromIcon(icon); \
|
||||
return bmp; \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Macro used in CreateBitmap to get wxICON_FOO icons:
|
||||
#define ART_MSGBOX(artId, iconId, xpmRc) \
|
||||
if ( id == artId ) \
|
||||
{ \
|
||||
CREATE_STD_ICON(#iconId, xpmRc) \
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider::InitStdProvider
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/ void wxArtProvider::InitStdProvider()
|
||||
{
|
||||
wxArtProvider::Push(new wxDefaultArtProvider);
|
||||
}
|
||||
|
||||
#if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)
|
||||
/*static*/ void wxArtProvider::InitNativeProvider()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// XPMs with the art
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#if defined(__WXGTK__)
|
||||
#include "../../art/gtk/info.xpm"
|
||||
#include "../../art/gtk/error.xpm"
|
||||
#include "../../art/gtk/warning.xpm"
|
||||
#include "../../art/gtk/question.xpm"
|
||||
#elif defined(__WXMOTIF__)
|
||||
#include "../../art/motif/info.xpm"
|
||||
#include "../../art/motif/error.xpm"
|
||||
#include "../../art/motif/warning.xpm"
|
||||
#include "../../art/motif/question.xpm"
|
||||
#endif
|
||||
|
||||
#if wxUSE_HTML
|
||||
#include "../../art/htmsidep.xpm"
|
||||
#include "../../art/htmoptns.xpm"
|
||||
#include "../../art/htmbook.xpm"
|
||||
#include "../../art/htmfoldr.xpm"
|
||||
#include "../../art/htmpage.xpm"
|
||||
#endif // wxUSE_HTML
|
||||
|
||||
#include "../../art/missimg.xpm"
|
||||
#include "../../art/addbookm.xpm"
|
||||
#include "../../art/delbookm.xpm"
|
||||
#include "../../art/back.xpm"
|
||||
#include "../../art/forward.xpm"
|
||||
#include "../../art/up.xpm"
|
||||
#include "../../art/down.xpm"
|
||||
#include "../../art/toparent.xpm"
|
||||
#include "../../art/fileopen.xpm"
|
||||
#include "../../art/print.xpm"
|
||||
#include "../../art/helpicon.xpm"
|
||||
#include "../../art/tipicon.xpm"
|
||||
#include "../../art/home.xpm"
|
||||
#include "../../art/repview.xpm"
|
||||
#include "../../art/listview.xpm"
|
||||
#include "../../art/new_dir.xpm"
|
||||
#include "../../art/harddisk.xpm"
|
||||
#include "../../art/cdrom.xpm"
|
||||
#include "../../art/floppy.xpm"
|
||||
#include "../../art/removable.xpm"
|
||||
#include "../../art/folder.xpm"
|
||||
#include "../../art/folder_open.xpm"
|
||||
#include "../../art/dir_up.xpm"
|
||||
#include "../../art/exefile.xpm"
|
||||
#include "../../art/deffile.xpm"
|
||||
#include "../../art/tick.xpm"
|
||||
#include "../../art/cross.xpm"
|
||||
|
||||
#include "../../art/filesave.xpm"
|
||||
#include "../../art/filesaveas.xpm"
|
||||
#include "../../art/copy.xpm"
|
||||
#include "../../art/cut.xpm"
|
||||
#include "../../art/paste.xpm"
|
||||
#include "../../art/delete.xpm"
|
||||
#include "../../art/new.xpm"
|
||||
#include "../../art/undo.xpm"
|
||||
#include "../../art/redo.xpm"
|
||||
#include "../../art/quit.xpm"
|
||||
#include "../../art/find.xpm"
|
||||
#include "../../art/findrepl.xpm"
|
||||
|
||||
|
||||
|
||||
wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id)
|
||||
{
|
||||
// wxMessageBox icons:
|
||||
ART_MSGBOX(wxART_ERROR, wxICON_ERROR, error)
|
||||
ART_MSGBOX(wxART_INFORMATION, wxICON_INFORMATION, info)
|
||||
ART_MSGBOX(wxART_WARNING, wxICON_WARNING, warning)
|
||||
ART_MSGBOX(wxART_QUESTION, wxICON_QUESTION, question)
|
||||
|
||||
// standard icons:
|
||||
#if wxUSE_HTML
|
||||
ART(wxART_HELP_SIDE_PANEL, htmsidep)
|
||||
ART(wxART_HELP_SETTINGS, htmoptns)
|
||||
ART(wxART_HELP_BOOK, htmbook)
|
||||
ART(wxART_HELP_FOLDER, htmfoldr)
|
||||
ART(wxART_HELP_PAGE, htmpage)
|
||||
#endif // wxUSE_HTML
|
||||
ART(wxART_MISSING_IMAGE, missimg)
|
||||
ART(wxART_ADD_BOOKMARK, addbookm)
|
||||
ART(wxART_DEL_BOOKMARK, delbookm)
|
||||
ART(wxART_GO_BACK, back)
|
||||
ART(wxART_GO_FORWARD, forward)
|
||||
ART(wxART_GO_UP, up)
|
||||
ART(wxART_GO_DOWN, down)
|
||||
ART(wxART_GO_TO_PARENT, toparent)
|
||||
ART(wxART_GO_HOME, home)
|
||||
ART(wxART_FILE_OPEN, fileopen)
|
||||
ART(wxART_PRINT, print)
|
||||
ART(wxART_HELP, helpicon)
|
||||
ART(wxART_TIP, tipicon)
|
||||
ART(wxART_REPORT_VIEW, repview)
|
||||
ART(wxART_LIST_VIEW, listview)
|
||||
ART(wxART_NEW_DIR, new_dir)
|
||||
ART(wxART_HARDDISK, harddisk)
|
||||
ART(wxART_FLOPPY, floppy)
|
||||
ART(wxART_CDROM, cdrom)
|
||||
ART(wxART_REMOVABLE, removable)
|
||||
ART(wxART_FOLDER, folder)
|
||||
ART(wxART_FOLDER_OPEN, folder_open)
|
||||
ART(wxART_GO_DIR_UP, dir_up)
|
||||
ART(wxART_EXECUTABLE_FILE, exefile)
|
||||
ART(wxART_NORMAL_FILE, deffile)
|
||||
ART(wxART_TICK_MARK, tick)
|
||||
ART(wxART_CROSS_MARK, cross)
|
||||
|
||||
ART(wxART_FILE_SAVE, filesave)
|
||||
ART(wxART_FILE_SAVE_AS, filesaveas)
|
||||
ART(wxART_COPY, copy)
|
||||
ART(wxART_CUT, cut)
|
||||
ART(wxART_PASTE, paste)
|
||||
ART(wxART_DELETE, delete)
|
||||
ART(wxART_UNDO, undo)
|
||||
ART(wxART_REDO, redo)
|
||||
ART(wxART_QUIT, quit)
|
||||
ART(wxART_FIND, find)
|
||||
ART(wxART_FIND_AND_REPLACE, findrepl)
|
||||
ART(wxART_NEW, new)
|
||||
|
||||
|
||||
return wxNullBitmap;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CreateBitmap routine
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& reqSize)
|
||||
{
|
||||
wxBitmap bmp = wxDefaultArtProvider_CreateBitmap(id);
|
||||
|
||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
||||
if (bmp.Ok())
|
||||
{
|
||||
// fit into transparent image with desired size hint from the client
|
||||
if (reqSize == wxDefaultSize)
|
||||
{
|
||||
// find out if there is a desired size for this client
|
||||
wxSize bestSize = GetSizeHint(client);
|
||||
if (bestSize != wxDefaultSize)
|
||||
{
|
||||
int bmp_w = bmp.GetWidth();
|
||||
int bmp_h = bmp.GetHeight();
|
||||
|
||||
if ((bmp_h < bestSize.x) && (bmp_w < bestSize.y))
|
||||
{
|
||||
// the caller wants default size, which is larger than
|
||||
// the image we have; to avoid degrading it visually by
|
||||
// scaling it up, paste it into transparent image instead:
|
||||
wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
|
||||
wxImage img = bmp.ConvertToImage();
|
||||
img.Resize(bestSize, offset);
|
||||
bmp = wxBitmap(img);
|
||||
}
|
||||
else // scale (down or mixed, but not up)
|
||||
{
|
||||
wxImage img = bmp.ConvertToImage();
|
||||
bmp = wxBitmap
|
||||
(
|
||||
img.Scale(bestSize.x, bestSize.y,
|
||||
wxIMAGE_QUALITY_HIGH)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
wxUnusedVar(client);
|
||||
wxUnusedVar(reqSize);
|
||||
#endif // wxUSE_IMAGE
|
||||
|
||||
return bmp;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/artstd.cpp
|
||||
// Purpose: stock wxArtProvider instance with default wxWin art
|
||||
// Author: Vaclav Slavik
|
||||
// Modified by:
|
||||
// Created: 18/03/2002
|
||||
// RCS-ID: $Id: artstd.cpp 52561 2008-03-16 00:36:37Z VS $
|
||||
// Copyright: (c) Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// headers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
#include "wx/artprov.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDefaultArtProvider
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDefaultArtProvider : public wxArtProvider
|
||||
{
|
||||
protected:
|
||||
virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
|
||||
const wxSize& size);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Standard macro for getting a resource from XPM file:
|
||||
#define ART(artId, xpmRc) \
|
||||
if ( id == artId ) return wxBitmap(xpmRc##_xpm);
|
||||
|
||||
// There are two ways of getting the standard icon: either via XPMs or via
|
||||
// wxIcon ctor. This depends on the platform:
|
||||
#if defined(__WXUNIVERSAL__)
|
||||
#define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
|
||||
#elif defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||
#define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
|
||||
#else
|
||||
#define CREATE_STD_ICON(iconId, xpmRc) \
|
||||
{ \
|
||||
wxIcon icon(_T(iconId)); \
|
||||
wxBitmap bmp; \
|
||||
bmp.CopyFromIcon(icon); \
|
||||
return bmp; \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Macro used in CreateBitmap to get wxICON_FOO icons:
|
||||
#define ART_MSGBOX(artId, iconId, xpmRc) \
|
||||
if ( id == artId ) \
|
||||
{ \
|
||||
CREATE_STD_ICON(#iconId, xpmRc) \
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxArtProvider::InitStdProvider
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/ void wxArtProvider::InitStdProvider()
|
||||
{
|
||||
wxArtProvider::Push(new wxDefaultArtProvider);
|
||||
}
|
||||
|
||||
#if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)
|
||||
/*static*/ void wxArtProvider::InitNativeProvider()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// XPMs with the art
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#if defined(__WXGTK__)
|
||||
#include "../../art/gtk/info.xpm"
|
||||
#include "../../art/gtk/error.xpm"
|
||||
#include "../../art/gtk/warning.xpm"
|
||||
#include "../../art/gtk/question.xpm"
|
||||
#elif defined(__WXMOTIF__)
|
||||
#include "../../art/motif/info.xpm"
|
||||
#include "../../art/motif/error.xpm"
|
||||
#include "../../art/motif/warning.xpm"
|
||||
#include "../../art/motif/question.xpm"
|
||||
#endif
|
||||
|
||||
#if wxUSE_HTML
|
||||
#include "../../art/htmsidep.xpm"
|
||||
#include "../../art/htmoptns.xpm"
|
||||
#include "../../art/htmbook.xpm"
|
||||
#include "../../art/htmfoldr.xpm"
|
||||
#include "../../art/htmpage.xpm"
|
||||
#endif // wxUSE_HTML
|
||||
|
||||
#include "../../art/missimg.xpm"
|
||||
#include "../../art/addbookm.xpm"
|
||||
#include "../../art/delbookm.xpm"
|
||||
#include "../../art/back.xpm"
|
||||
#include "../../art/forward.xpm"
|
||||
#include "../../art/up.xpm"
|
||||
#include "../../art/down.xpm"
|
||||
#include "../../art/toparent.xpm"
|
||||
#include "../../art/fileopen.xpm"
|
||||
#include "../../art/print.xpm"
|
||||
#include "../../art/helpicon.xpm"
|
||||
#include "../../art/tipicon.xpm"
|
||||
#include "../../art/home.xpm"
|
||||
#include "../../art/repview.xpm"
|
||||
#include "../../art/listview.xpm"
|
||||
#include "../../art/new_dir.xpm"
|
||||
#include "../../art/harddisk.xpm"
|
||||
#include "../../art/cdrom.xpm"
|
||||
#include "../../art/floppy.xpm"
|
||||
#include "../../art/removable.xpm"
|
||||
#include "../../art/folder.xpm"
|
||||
#include "../../art/folder_open.xpm"
|
||||
#include "../../art/dir_up.xpm"
|
||||
#include "../../art/exefile.xpm"
|
||||
#include "../../art/deffile.xpm"
|
||||
#include "../../art/tick.xpm"
|
||||
#include "../../art/cross.xpm"
|
||||
|
||||
#include "../../art/filesave.xpm"
|
||||
#include "../../art/filesaveas.xpm"
|
||||
#include "../../art/copy.xpm"
|
||||
#include "../../art/cut.xpm"
|
||||
#include "../../art/paste.xpm"
|
||||
#include "../../art/delete.xpm"
|
||||
#include "../../art/new.xpm"
|
||||
#include "../../art/undo.xpm"
|
||||
#include "../../art/redo.xpm"
|
||||
#include "../../art/quit.xpm"
|
||||
#include "../../art/find.xpm"
|
||||
#include "../../art/findrepl.xpm"
|
||||
|
||||
|
||||
|
||||
wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id)
|
||||
{
|
||||
// wxMessageBox icons:
|
||||
ART_MSGBOX(wxART_ERROR, wxICON_ERROR, error)
|
||||
ART_MSGBOX(wxART_INFORMATION, wxICON_INFORMATION, info)
|
||||
ART_MSGBOX(wxART_WARNING, wxICON_WARNING, warning)
|
||||
ART_MSGBOX(wxART_QUESTION, wxICON_QUESTION, question)
|
||||
|
||||
// standard icons:
|
||||
#if wxUSE_HTML
|
||||
ART(wxART_HELP_SIDE_PANEL, htmsidep)
|
||||
ART(wxART_HELP_SETTINGS, htmoptns)
|
||||
ART(wxART_HELP_BOOK, htmbook)
|
||||
ART(wxART_HELP_FOLDER, htmfoldr)
|
||||
ART(wxART_HELP_PAGE, htmpage)
|
||||
#endif // wxUSE_HTML
|
||||
ART(wxART_MISSING_IMAGE, missimg)
|
||||
ART(wxART_ADD_BOOKMARK, addbookm)
|
||||
ART(wxART_DEL_BOOKMARK, delbookm)
|
||||
ART(wxART_GO_BACK, back)
|
||||
ART(wxART_GO_FORWARD, forward)
|
||||
ART(wxART_GO_UP, up)
|
||||
ART(wxART_GO_DOWN, down)
|
||||
ART(wxART_GO_TO_PARENT, toparent)
|
||||
ART(wxART_GO_HOME, home)
|
||||
ART(wxART_FILE_OPEN, fileopen)
|
||||
ART(wxART_PRINT, print)
|
||||
ART(wxART_HELP, helpicon)
|
||||
ART(wxART_TIP, tipicon)
|
||||
ART(wxART_REPORT_VIEW, repview)
|
||||
ART(wxART_LIST_VIEW, listview)
|
||||
ART(wxART_NEW_DIR, new_dir)
|
||||
ART(wxART_HARDDISK, harddisk)
|
||||
ART(wxART_FLOPPY, floppy)
|
||||
ART(wxART_CDROM, cdrom)
|
||||
ART(wxART_REMOVABLE, removable)
|
||||
ART(wxART_FOLDER, folder)
|
||||
ART(wxART_FOLDER_OPEN, folder_open)
|
||||
ART(wxART_GO_DIR_UP, dir_up)
|
||||
ART(wxART_EXECUTABLE_FILE, exefile)
|
||||
ART(wxART_NORMAL_FILE, deffile)
|
||||
ART(wxART_TICK_MARK, tick)
|
||||
ART(wxART_CROSS_MARK, cross)
|
||||
|
||||
ART(wxART_FILE_SAVE, filesave)
|
||||
ART(wxART_FILE_SAVE_AS, filesaveas)
|
||||
ART(wxART_COPY, copy)
|
||||
ART(wxART_CUT, cut)
|
||||
ART(wxART_PASTE, paste)
|
||||
ART(wxART_DELETE, delete)
|
||||
ART(wxART_UNDO, undo)
|
||||
ART(wxART_REDO, redo)
|
||||
ART(wxART_QUIT, quit)
|
||||
ART(wxART_FIND, find)
|
||||
ART(wxART_FIND_AND_REPLACE, findrepl)
|
||||
ART(wxART_NEW, new)
|
||||
|
||||
|
||||
return wxNullBitmap;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CreateBitmap routine
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
|
||||
const wxArtClient& client,
|
||||
const wxSize& reqSize)
|
||||
{
|
||||
wxBitmap bmp = wxDefaultArtProvider_CreateBitmap(id);
|
||||
|
||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
||||
if (bmp.Ok())
|
||||
{
|
||||
// fit into transparent image with desired size hint from the client
|
||||
if (reqSize == wxDefaultSize)
|
||||
{
|
||||
// find out if there is a desired size for this client
|
||||
wxSize bestSize = GetSizeHint(client);
|
||||
if (bestSize != wxDefaultSize)
|
||||
{
|
||||
int bmp_w = bmp.GetWidth();
|
||||
int bmp_h = bmp.GetHeight();
|
||||
|
||||
if ((bmp_h < bestSize.x) && (bmp_w < bestSize.y))
|
||||
{
|
||||
// the caller wants default size, which is larger than
|
||||
// the image we have; to avoid degrading it visually by
|
||||
// scaling it up, paste it into transparent image instead:
|
||||
wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
|
||||
wxImage img = bmp.ConvertToImage();
|
||||
img.Resize(bestSize, offset);
|
||||
bmp = wxBitmap(img);
|
||||
}
|
||||
else // scale (down or mixed, but not up)
|
||||
{
|
||||
wxImage img = bmp.ConvertToImage();
|
||||
bmp = wxBitmap
|
||||
(
|
||||
img.Scale(bestSize.x, bestSize.y,
|
||||
wxIMAGE_QUALITY_HIGH)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
wxUnusedVar(client);
|
||||
wxUnusedVar(reqSize);
|
||||
#endif // wxUSE_IMAGE
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
422
Externals/wxWidgets/src/common/bmpbase.cpp
vendored
422
Externals/wxWidgets/src/common/bmpbase.cpp
vendored
@ -1,211 +1,211 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/bmpbase.cpp
|
||||
// Purpose: wxBitmapBase
|
||||
// Author: VaclavSlavik
|
||||
// Created: 2001/04/11
|
||||
// RCS-ID: $Id: bmpbase.cpp 42752 2006-10-30 19:26:48Z VZ $
|
||||
// Copyright: (c) 2001, Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/bitmap.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/colour.h"
|
||||
#include "wx/icon.h"
|
||||
#include "wx/image.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxVariant support
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_BITMAP_BASE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/palette.h"
|
||||
#include "wx/module.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
|
||||
|
||||
wxList wxBitmapBase::sm_handlers;
|
||||
|
||||
void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
|
||||
{
|
||||
sm_handlers.Append(handler);
|
||||
}
|
||||
|
||||
void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
|
||||
{
|
||||
sm_handlers.Insert(handler);
|
||||
}
|
||||
|
||||
bool wxBitmapBase::RemoveHandler(const wxString& name)
|
||||
{
|
||||
wxBitmapHandler *handler = FindHandler(name);
|
||||
if ( handler )
|
||||
{
|
||||
sm_handlers.DeleteObject(handler);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
if ( handler->GetName() == name )
|
||||
return handler;
|
||||
node = node->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
if ( handler->GetExtension() == extension &&
|
||||
(bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
|
||||
return handler;
|
||||
node = node->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
if (handler->GetType() == bitmapType)
|
||||
return handler;
|
||||
node = node->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wxBitmapBase::CleanUpHandlers()
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
wxList::compatibility_iterator next = node->GetNext();
|
||||
delete handler;
|
||||
sm_handlers.Erase(node);
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxBitmapHandlerBase::Create(wxBitmap*, const void*, long, int, int, int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxBitmapHandlerBase::LoadFile(wxBitmap*, const wxString&, long, int, int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxBitmapHandlerBase::SaveFile(const wxBitmap*, const wxString&, int, const wxPalette*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class wxBitmapBaseModule: public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
|
||||
public:
|
||||
wxBitmapBaseModule() {}
|
||||
bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
|
||||
void OnExit() { wxBitmap::CleanUpHandlers(); }
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
|
||||
|
||||
#endif // wxUSE_BITMAP_BASE
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmap common
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
|
||||
|
||||
wxBitmap::wxBitmap(const char* const* bits)
|
||||
{
|
||||
wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
|
||||
|
||||
#if wxUSE_IMAGE && wxUSE_XPM
|
||||
wxImage image(bits);
|
||||
wxCHECK2_MSG(image.Ok(), return, wxT("invalid bitmap data"));
|
||||
|
||||
*this = wxBitmap(image);
|
||||
#else
|
||||
wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
|
||||
#endif // wxUSE_IMAGE && wxUSE_XPM
|
||||
}
|
||||
#endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMaskBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
|
||||
{
|
||||
FreeData();
|
||||
|
||||
return InitFromColour(bitmap, colour);
|
||||
}
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
|
||||
bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
|
||||
{
|
||||
wxPalette *pal = bitmap.GetPalette();
|
||||
|
||||
wxCHECK_MSG( pal, false,
|
||||
wxT("Cannot create mask from palette index of a bitmap without palette") );
|
||||
|
||||
unsigned char r,g,b;
|
||||
pal->GetRGB(paletteIndex, &r, &g, &b);
|
||||
|
||||
return Create(bitmap, wxColour(r, g, b));
|
||||
}
|
||||
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
bool wxMaskBase::Create(const wxBitmap& bitmap)
|
||||
{
|
||||
FreeData();
|
||||
|
||||
return InitFromMonoBitmap(bitmap);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/bmpbase.cpp
|
||||
// Purpose: wxBitmapBase
|
||||
// Author: VaclavSlavik
|
||||
// Created: 2001/04/11
|
||||
// RCS-ID: $Id: bmpbase.cpp 42752 2006-10-30 19:26:48Z VZ $
|
||||
// Copyright: (c) 2001, Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/bitmap.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/colour.h"
|
||||
#include "wx/icon.h"
|
||||
#include "wx/image.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxVariant support
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_BITMAP_BASE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/palette.h"
|
||||
#include "wx/module.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
|
||||
|
||||
wxList wxBitmapBase::sm_handlers;
|
||||
|
||||
void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
|
||||
{
|
||||
sm_handlers.Append(handler);
|
||||
}
|
||||
|
||||
void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
|
||||
{
|
||||
sm_handlers.Insert(handler);
|
||||
}
|
||||
|
||||
bool wxBitmapBase::RemoveHandler(const wxString& name)
|
||||
{
|
||||
wxBitmapHandler *handler = FindHandler(name);
|
||||
if ( handler )
|
||||
{
|
||||
sm_handlers.DeleteObject(handler);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
if ( handler->GetName() == name )
|
||||
return handler;
|
||||
node = node->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
if ( handler->GetExtension() == extension &&
|
||||
(bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
|
||||
return handler;
|
||||
node = node->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
if (handler->GetType() == bitmapType)
|
||||
return handler;
|
||||
node = node->GetNext();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wxBitmapBase::CleanUpHandlers()
|
||||
{
|
||||
wxList::compatibility_iterator node = sm_handlers.GetFirst();
|
||||
while ( node )
|
||||
{
|
||||
wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
|
||||
wxList::compatibility_iterator next = node->GetNext();
|
||||
delete handler;
|
||||
sm_handlers.Erase(node);
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxBitmapHandlerBase::Create(wxBitmap*, const void*, long, int, int, int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxBitmapHandlerBase::LoadFile(wxBitmap*, const wxString&, long, int, int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxBitmapHandlerBase::SaveFile(const wxBitmap*, const wxString&, int, const wxPalette*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class wxBitmapBaseModule: public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
|
||||
public:
|
||||
wxBitmapBaseModule() {}
|
||||
bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
|
||||
void OnExit() { wxBitmap::CleanUpHandlers(); }
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
|
||||
|
||||
#endif // wxUSE_BITMAP_BASE
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmap common
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
|
||||
|
||||
wxBitmap::wxBitmap(const char* const* bits)
|
||||
{
|
||||
wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
|
||||
|
||||
#if wxUSE_IMAGE && wxUSE_XPM
|
||||
wxImage image(bits);
|
||||
wxCHECK2_MSG(image.Ok(), return, wxT("invalid bitmap data"));
|
||||
|
||||
*this = wxBitmap(image);
|
||||
#else
|
||||
wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
|
||||
#endif // wxUSE_IMAGE && wxUSE_XPM
|
||||
}
|
||||
#endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMaskBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
|
||||
{
|
||||
FreeData();
|
||||
|
||||
return InitFromColour(bitmap, colour);
|
||||
}
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
|
||||
bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
|
||||
{
|
||||
wxPalette *pal = bitmap.GetPalette();
|
||||
|
||||
wxCHECK_MSG( pal, false,
|
||||
wxT("Cannot create mask from palette index of a bitmap without palette") );
|
||||
|
||||
unsigned char r,g,b;
|
||||
pal->GetRGB(paletteIndex, &r, &g, &b);
|
||||
|
||||
return Create(bitmap, wxColour(r, g, b));
|
||||
}
|
||||
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
bool wxMaskBase::Create(const wxBitmap& bitmap)
|
||||
{
|
||||
FreeData();
|
||||
|
||||
return InitFromMonoBitmap(bitmap);
|
||||
}
|
||||
|
994
Externals/wxWidgets/src/common/bookctrl.cpp
vendored
994
Externals/wxWidgets/src/common/bookctrl.cpp
vendored
@ -1,497 +1,497 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/bookctrl.cpp
|
||||
// Purpose: wxBookCtrlBase implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 19.08.03
|
||||
// RCS-ID: $Id: bookctrl.cpp 53783 2008-05-27 14:15:14Z SC $
|
||||
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_BOOKCTRL
|
||||
|
||||
#include "wx/imaglist.h"
|
||||
|
||||
#include "wx/bookctrl.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event table
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBookCtrlBase, wxControl)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxBookCtrlBase, wxControl)
|
||||
EVT_SIZE(wxBookCtrlBase::OnSize)
|
||||
#if wxUSE_HELP
|
||||
EVT_HELP(wxID_ANY, wxBookCtrlBase::OnHelp)
|
||||
#endif // wxUSE_HELP
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxBookCtrlBase::Init()
|
||||
{
|
||||
m_bookctrl = NULL;
|
||||
m_imageList = NULL;
|
||||
m_ownsImageList = false;
|
||||
m_fitToCurrentPage = false;
|
||||
|
||||
#if defined(__WXWINCE__)
|
||||
m_internalBorder = 1;
|
||||
#else
|
||||
m_internalBorder = 5;
|
||||
#endif
|
||||
|
||||
m_controlMargin = 0;
|
||||
m_controlSizer = NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
wxBookCtrlBase::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxString& name)
|
||||
{
|
||||
return wxControl::Create
|
||||
(
|
||||
parent,
|
||||
id,
|
||||
pos,
|
||||
size,
|
||||
style,
|
||||
wxDefaultValidator,
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
wxBookCtrlBase::~wxBookCtrlBase()
|
||||
{
|
||||
if ( m_ownsImageList )
|
||||
{
|
||||
// may be NULL, ok
|
||||
delete m_imageList;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// image list
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxBookCtrlBase::SetImageList(wxImageList *imageList)
|
||||
{
|
||||
if ( m_ownsImageList )
|
||||
{
|
||||
// may be NULL, ok
|
||||
delete m_imageList;
|
||||
|
||||
m_ownsImageList = false;
|
||||
}
|
||||
|
||||
m_imageList = imageList;
|
||||
}
|
||||
|
||||
void wxBookCtrlBase::AssignImageList(wxImageList* imageList)
|
||||
{
|
||||
SetImageList(imageList);
|
||||
|
||||
m_ownsImageList = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// geometry
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxBookCtrlBase::DoInvalidateBestSize()
|
||||
{
|
||||
// notice that it is not necessary to invalidate our own best size
|
||||
// explicitly if we have m_bookctrl as it will already invalidate the best
|
||||
// size of its parent when its own size is invalidated and its parent is
|
||||
// this control
|
||||
if ( m_bookctrl )
|
||||
m_bookctrl->InvalidateBestSize();
|
||||
else
|
||||
wxControl::InvalidateBestSize();
|
||||
}
|
||||
|
||||
void wxBookCtrlBase::SetPageSize(const wxSize& size)
|
||||
{
|
||||
SetClientSize(CalcSizeFromPage(size));
|
||||
}
|
||||
|
||||
wxSize wxBookCtrlBase::DoGetBestSize() const
|
||||
{
|
||||
wxSize bestSize;
|
||||
|
||||
// iterate over all pages, get the largest width and height
|
||||
const size_t nCount = m_pages.size();
|
||||
for ( size_t nPage = 0; nPage < nCount; nPage++ )
|
||||
{
|
||||
const wxWindow * const pPage = m_pages[nPage];
|
||||
if( pPage )
|
||||
{
|
||||
wxSize childBestSize(pPage->GetBestSize());
|
||||
|
||||
if ( childBestSize.x > bestSize.x )
|
||||
bestSize.x = childBestSize.x;
|
||||
|
||||
if ( childBestSize.y > bestSize.y )
|
||||
bestSize.y = childBestSize.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_fitToCurrentPage && GetCurrentPage())
|
||||
bestSize = GetCurrentPage()->GetBestSize();
|
||||
|
||||
// convert display area to window area, adding the size necessary for the
|
||||
// tabs
|
||||
wxSize best = CalcSizeFromPage(bestSize);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
wxRect wxBookCtrlBase::GetPageRect() const
|
||||
{
|
||||
const wxSize size = GetControllerSize();
|
||||
|
||||
wxPoint pt;
|
||||
wxRect rectPage(pt, GetClientSize());
|
||||
|
||||
switch ( GetWindowStyle() & wxBK_ALIGN_MASK )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected alignment") );
|
||||
// fall through
|
||||
|
||||
case wxBK_TOP:
|
||||
rectPage.y = size.y + GetInternalBorder();
|
||||
// fall through
|
||||
|
||||
case wxBK_BOTTOM:
|
||||
rectPage.height -= size.y + GetInternalBorder();
|
||||
if (rectPage.height < 0)
|
||||
rectPage.height = 0;
|
||||
break;
|
||||
|
||||
case wxBK_LEFT:
|
||||
rectPage.x = size.x + GetInternalBorder();
|
||||
// fall through
|
||||
|
||||
case wxBK_RIGHT:
|
||||
rectPage.width -= size.x + GetInternalBorder();
|
||||
if (rectPage.width < 0)
|
||||
rectPage.width = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return rectPage;
|
||||
}
|
||||
|
||||
// Lay out controls
|
||||
void wxBookCtrlBase::DoSize()
|
||||
{
|
||||
if ( !m_bookctrl )
|
||||
{
|
||||
// we're not fully created yet or OnSize() should be hidden by derived class
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetSizer())
|
||||
Layout();
|
||||
else
|
||||
{
|
||||
// resize controller and the page area to fit inside our new size
|
||||
const wxSize sizeClient( GetClientSize() ),
|
||||
sizeBorder( m_bookctrl->GetSize() - m_bookctrl->GetClientSize() ),
|
||||
sizeCtrl( GetControllerSize() );
|
||||
|
||||
m_bookctrl->SetClientSize( sizeCtrl.x - sizeBorder.x, sizeCtrl.y - sizeBorder.y );
|
||||
// if this changes the visibility of the scrollbars the best size changes, relayout in this case
|
||||
wxSize sizeCtrl2 = GetControllerSize();
|
||||
if ( sizeCtrl != sizeCtrl2 )
|
||||
{
|
||||
wxSize sizeBorder2 = m_bookctrl->GetSize() - m_bookctrl->GetClientSize();
|
||||
m_bookctrl->SetClientSize( sizeCtrl2.x - sizeBorder2.x, sizeCtrl2.y - sizeBorder2.y );
|
||||
}
|
||||
|
||||
const wxSize sizeNew = m_bookctrl->GetSize();
|
||||
wxPoint posCtrl;
|
||||
switch ( GetWindowStyle() & wxBK_ALIGN_MASK )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected alignment") );
|
||||
// fall through
|
||||
|
||||
case wxBK_TOP:
|
||||
case wxBK_LEFT:
|
||||
// posCtrl is already ok
|
||||
break;
|
||||
|
||||
case wxBK_BOTTOM:
|
||||
posCtrl.y = sizeClient.y - sizeNew.y;
|
||||
break;
|
||||
|
||||
case wxBK_RIGHT:
|
||||
posCtrl.x = sizeClient.x - sizeNew.x;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( m_bookctrl->GetPosition() != posCtrl )
|
||||
m_bookctrl->Move(posCtrl);
|
||||
}
|
||||
|
||||
// resize all pages to fit the new control size
|
||||
const wxRect pageRect = GetPageRect();
|
||||
const unsigned pagesCount = m_pages.Count();
|
||||
for ( unsigned int i = 0; i < pagesCount; ++i )
|
||||
{
|
||||
wxWindow * const page = m_pages[i];
|
||||
if ( !page )
|
||||
{
|
||||
wxASSERT_MSG( AllowNullPage(),
|
||||
_T("Null page in a control that does not allow null pages?") );
|
||||
continue;
|
||||
}
|
||||
|
||||
page->SetSize(pageRect);
|
||||
}
|
||||
}
|
||||
|
||||
void wxBookCtrlBase::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
|
||||
DoSize();
|
||||
}
|
||||
|
||||
wxSize wxBookCtrlBase::GetControllerSize() const
|
||||
{
|
||||
if(!m_bookctrl)
|
||||
return wxSize(0,0);
|
||||
|
||||
const wxSize sizeClient = GetClientSize(),
|
||||
sizeBorder = m_bookctrl->GetSize() - m_bookctrl->GetClientSize(),
|
||||
sizeCtrl = m_bookctrl->GetBestSize() + sizeBorder;
|
||||
|
||||
wxSize size;
|
||||
|
||||
if ( IsVertical() )
|
||||
{
|
||||
size.x = sizeClient.x;
|
||||
size.y = sizeCtrl.y;
|
||||
}
|
||||
else // left/right aligned
|
||||
{
|
||||
size.x = sizeCtrl.x;
|
||||
size.y = sizeClient.y;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// miscellaneous stuff
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_HELP
|
||||
|
||||
void wxBookCtrlBase::OnHelp(wxHelpEvent& event)
|
||||
{
|
||||
// determine where does this even originate from to avoid redirecting it
|
||||
// back to the page which generated it (resulting in an infinite loop)
|
||||
|
||||
// notice that we have to check in the hard(er) way instead of just testing
|
||||
// if the event object == this because the book control can have other
|
||||
// subcontrols inside it (e.g. wxSpinButton in case of a notebook in wxUniv)
|
||||
wxWindow *source = wxStaticCast(event.GetEventObject(), wxWindow);
|
||||
while ( source && source != this && source->GetParent() != this )
|
||||
{
|
||||
source = source->GetParent();
|
||||
}
|
||||
|
||||
if ( source && m_pages.Index(source) == wxNOT_FOUND )
|
||||
{
|
||||
// this event is for the book control itself, redirect it to the
|
||||
// corresponding page
|
||||
wxWindow *page = NULL;
|
||||
|
||||
if ( event.GetOrigin() == wxHelpEvent::Origin_HelpButton )
|
||||
{
|
||||
// show help for the page under the mouse
|
||||
const int pagePos = HitTest(ScreenToClient(event.GetPosition()));
|
||||
|
||||
if ( pagePos != wxNOT_FOUND)
|
||||
{
|
||||
page = GetPage((size_t)pagePos);
|
||||
}
|
||||
}
|
||||
else // event from keyboard or unknown source
|
||||
{
|
||||
// otherwise show the current page help
|
||||
page = GetCurrentPage();
|
||||
}
|
||||
|
||||
if ( page )
|
||||
{
|
||||
// change event object to the page to avoid infinite recursion if
|
||||
// we get this event ourselves if the page doesn't handle it
|
||||
event.SetEventObject(page);
|
||||
|
||||
if ( page->GetEventHandler()->ProcessEvent(event) )
|
||||
{
|
||||
// don't call event.Skip()
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//else: event coming from one of our pages already
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
#endif // wxUSE_HELP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// pages management
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
wxBookCtrlBase::InsertPage(size_t nPage,
|
||||
wxWindow *page,
|
||||
const wxString& WXUNUSED(text),
|
||||
bool WXUNUSED(bSelect),
|
||||
int WXUNUSED(imageId))
|
||||
{
|
||||
wxCHECK_MSG( page || AllowNullPage(), false,
|
||||
_T("NULL page in wxBookCtrlBase::InsertPage()") );
|
||||
wxCHECK_MSG( nPage <= m_pages.size(), false,
|
||||
_T("invalid page index in wxBookCtrlBase::InsertPage()") );
|
||||
|
||||
m_pages.Insert(page, nPage);
|
||||
if ( page )
|
||||
page->SetSize(GetPageRect());
|
||||
|
||||
DoInvalidateBestSize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxBookCtrlBase::DeletePage(size_t nPage)
|
||||
{
|
||||
wxWindow *page = DoRemovePage(nPage);
|
||||
if ( !(page || AllowNullPage()) )
|
||||
return false;
|
||||
|
||||
// delete NULL is harmless
|
||||
delete page;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxWindow *wxBookCtrlBase::DoRemovePage(size_t nPage)
|
||||
{
|
||||
wxCHECK_MSG( nPage < m_pages.size(), NULL,
|
||||
_T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
|
||||
|
||||
wxWindow *pageRemoved = m_pages[nPage];
|
||||
m_pages.RemoveAt(nPage);
|
||||
DoInvalidateBestSize();
|
||||
|
||||
return pageRemoved;
|
||||
}
|
||||
|
||||
int wxBookCtrlBase::GetNextPage(bool forward) const
|
||||
{
|
||||
int nPage;
|
||||
|
||||
int nMax = GetPageCount();
|
||||
if ( nMax-- ) // decrement it to get the last valid index
|
||||
{
|
||||
int nSel = GetSelection();
|
||||
|
||||
// change selection wrapping if it becomes invalid
|
||||
nPage = forward ? nSel == nMax ? 0
|
||||
: nSel + 1
|
||||
: nSel == 0 ? nMax
|
||||
: nSel - 1;
|
||||
}
|
||||
else // notebook is empty, no next page
|
||||
{
|
||||
nPage = wxNOT_FOUND;
|
||||
}
|
||||
|
||||
return nPage;
|
||||
}
|
||||
|
||||
int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
|
||||
{
|
||||
wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
|
||||
wxT("invalid page index in wxBookCtrlBase::DoSetSelection()") );
|
||||
|
||||
const int oldSel = GetSelection();
|
||||
|
||||
if ( n != (size_t)oldSel )
|
||||
{
|
||||
wxBookCtrlBaseEvent *event = CreatePageChangingEvent();
|
||||
bool allowed = false;
|
||||
|
||||
if ( flags & SetSelection_SendEvent )
|
||||
{
|
||||
event->SetSelection(n);
|
||||
event->SetOldSelection(oldSel);
|
||||
event->SetEventObject(this);
|
||||
|
||||
allowed = !GetEventHandler()->ProcessEvent(*event) || event->IsAllowed();
|
||||
}
|
||||
|
||||
if ( !(flags & SetSelection_SendEvent) || allowed)
|
||||
{
|
||||
if ( oldSel != wxNOT_FOUND )
|
||||
m_pages[oldSel]->Hide();
|
||||
|
||||
wxWindow *page = m_pages[n];
|
||||
page->SetSize(GetPageRect());
|
||||
page->Show();
|
||||
|
||||
// change selection now to ignore the selection change event
|
||||
UpdateSelectedPage(n);
|
||||
|
||||
if ( flags & SetSelection_SendEvent )
|
||||
{
|
||||
// program allows the page change
|
||||
MakeChangedEvent(*event);
|
||||
(void)GetEventHandler()->ProcessEvent(*event);
|
||||
}
|
||||
}
|
||||
|
||||
delete event;
|
||||
}
|
||||
|
||||
return oldSel;
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_BOOKCTRL
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/bookctrl.cpp
|
||||
// Purpose: wxBookCtrlBase implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 19.08.03
|
||||
// RCS-ID: $Id: bookctrl.cpp 53783 2008-05-27 14:15:14Z SC $
|
||||
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_BOOKCTRL
|
||||
|
||||
#include "wx/imaglist.h"
|
||||
|
||||
#include "wx/bookctrl.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event table
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxBookCtrlBase, wxControl)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxBookCtrlBase, wxControl)
|
||||
EVT_SIZE(wxBookCtrlBase::OnSize)
|
||||
#if wxUSE_HELP
|
||||
EVT_HELP(wxID_ANY, wxBookCtrlBase::OnHelp)
|
||||
#endif // wxUSE_HELP
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constructors and destructors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxBookCtrlBase::Init()
|
||||
{
|
||||
m_bookctrl = NULL;
|
||||
m_imageList = NULL;
|
||||
m_ownsImageList = false;
|
||||
m_fitToCurrentPage = false;
|
||||
|
||||
#if defined(__WXWINCE__)
|
||||
m_internalBorder = 1;
|
||||
#else
|
||||
m_internalBorder = 5;
|
||||
#endif
|
||||
|
||||
m_controlMargin = 0;
|
||||
m_controlSizer = NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
wxBookCtrlBase::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxString& name)
|
||||
{
|
||||
return wxControl::Create
|
||||
(
|
||||
parent,
|
||||
id,
|
||||
pos,
|
||||
size,
|
||||
style,
|
||||
wxDefaultValidator,
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
wxBookCtrlBase::~wxBookCtrlBase()
|
||||
{
|
||||
if ( m_ownsImageList )
|
||||
{
|
||||
// may be NULL, ok
|
||||
delete m_imageList;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// image list
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxBookCtrlBase::SetImageList(wxImageList *imageList)
|
||||
{
|
||||
if ( m_ownsImageList )
|
||||
{
|
||||
// may be NULL, ok
|
||||
delete m_imageList;
|
||||
|
||||
m_ownsImageList = false;
|
||||
}
|
||||
|
||||
m_imageList = imageList;
|
||||
}
|
||||
|
||||
void wxBookCtrlBase::AssignImageList(wxImageList* imageList)
|
||||
{
|
||||
SetImageList(imageList);
|
||||
|
||||
m_ownsImageList = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// geometry
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxBookCtrlBase::DoInvalidateBestSize()
|
||||
{
|
||||
// notice that it is not necessary to invalidate our own best size
|
||||
// explicitly if we have m_bookctrl as it will already invalidate the best
|
||||
// size of its parent when its own size is invalidated and its parent is
|
||||
// this control
|
||||
if ( m_bookctrl )
|
||||
m_bookctrl->InvalidateBestSize();
|
||||
else
|
||||
wxControl::InvalidateBestSize();
|
||||
}
|
||||
|
||||
void wxBookCtrlBase::SetPageSize(const wxSize& size)
|
||||
{
|
||||
SetClientSize(CalcSizeFromPage(size));
|
||||
}
|
||||
|
||||
wxSize wxBookCtrlBase::DoGetBestSize() const
|
||||
{
|
||||
wxSize bestSize;
|
||||
|
||||
// iterate over all pages, get the largest width and height
|
||||
const size_t nCount = m_pages.size();
|
||||
for ( size_t nPage = 0; nPage < nCount; nPage++ )
|
||||
{
|
||||
const wxWindow * const pPage = m_pages[nPage];
|
||||
if( pPage )
|
||||
{
|
||||
wxSize childBestSize(pPage->GetBestSize());
|
||||
|
||||
if ( childBestSize.x > bestSize.x )
|
||||
bestSize.x = childBestSize.x;
|
||||
|
||||
if ( childBestSize.y > bestSize.y )
|
||||
bestSize.y = childBestSize.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_fitToCurrentPage && GetCurrentPage())
|
||||
bestSize = GetCurrentPage()->GetBestSize();
|
||||
|
||||
// convert display area to window area, adding the size necessary for the
|
||||
// tabs
|
||||
wxSize best = CalcSizeFromPage(bestSize);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
wxRect wxBookCtrlBase::GetPageRect() const
|
||||
{
|
||||
const wxSize size = GetControllerSize();
|
||||
|
||||
wxPoint pt;
|
||||
wxRect rectPage(pt, GetClientSize());
|
||||
|
||||
switch ( GetWindowStyle() & wxBK_ALIGN_MASK )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected alignment") );
|
||||
// fall through
|
||||
|
||||
case wxBK_TOP:
|
||||
rectPage.y = size.y + GetInternalBorder();
|
||||
// fall through
|
||||
|
||||
case wxBK_BOTTOM:
|
||||
rectPage.height -= size.y + GetInternalBorder();
|
||||
if (rectPage.height < 0)
|
||||
rectPage.height = 0;
|
||||
break;
|
||||
|
||||
case wxBK_LEFT:
|
||||
rectPage.x = size.x + GetInternalBorder();
|
||||
// fall through
|
||||
|
||||
case wxBK_RIGHT:
|
||||
rectPage.width -= size.x + GetInternalBorder();
|
||||
if (rectPage.width < 0)
|
||||
rectPage.width = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return rectPage;
|
||||
}
|
||||
|
||||
// Lay out controls
|
||||
void wxBookCtrlBase::DoSize()
|
||||
{
|
||||
if ( !m_bookctrl )
|
||||
{
|
||||
// we're not fully created yet or OnSize() should be hidden by derived class
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetSizer())
|
||||
Layout();
|
||||
else
|
||||
{
|
||||
// resize controller and the page area to fit inside our new size
|
||||
const wxSize sizeClient( GetClientSize() ),
|
||||
sizeBorder( m_bookctrl->GetSize() - m_bookctrl->GetClientSize() ),
|
||||
sizeCtrl( GetControllerSize() );
|
||||
|
||||
m_bookctrl->SetClientSize( sizeCtrl.x - sizeBorder.x, sizeCtrl.y - sizeBorder.y );
|
||||
// if this changes the visibility of the scrollbars the best size changes, relayout in this case
|
||||
wxSize sizeCtrl2 = GetControllerSize();
|
||||
if ( sizeCtrl != sizeCtrl2 )
|
||||
{
|
||||
wxSize sizeBorder2 = m_bookctrl->GetSize() - m_bookctrl->GetClientSize();
|
||||
m_bookctrl->SetClientSize( sizeCtrl2.x - sizeBorder2.x, sizeCtrl2.y - sizeBorder2.y );
|
||||
}
|
||||
|
||||
const wxSize sizeNew = m_bookctrl->GetSize();
|
||||
wxPoint posCtrl;
|
||||
switch ( GetWindowStyle() & wxBK_ALIGN_MASK )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected alignment") );
|
||||
// fall through
|
||||
|
||||
case wxBK_TOP:
|
||||
case wxBK_LEFT:
|
||||
// posCtrl is already ok
|
||||
break;
|
||||
|
||||
case wxBK_BOTTOM:
|
||||
posCtrl.y = sizeClient.y - sizeNew.y;
|
||||
break;
|
||||
|
||||
case wxBK_RIGHT:
|
||||
posCtrl.x = sizeClient.x - sizeNew.x;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( m_bookctrl->GetPosition() != posCtrl )
|
||||
m_bookctrl->Move(posCtrl);
|
||||
}
|
||||
|
||||
// resize all pages to fit the new control size
|
||||
const wxRect pageRect = GetPageRect();
|
||||
const unsigned pagesCount = m_pages.Count();
|
||||
for ( unsigned int i = 0; i < pagesCount; ++i )
|
||||
{
|
||||
wxWindow * const page = m_pages[i];
|
||||
if ( !page )
|
||||
{
|
||||
wxASSERT_MSG( AllowNullPage(),
|
||||
_T("Null page in a control that does not allow null pages?") );
|
||||
continue;
|
||||
}
|
||||
|
||||
page->SetSize(pageRect);
|
||||
}
|
||||
}
|
||||
|
||||
void wxBookCtrlBase::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
|
||||
DoSize();
|
||||
}
|
||||
|
||||
wxSize wxBookCtrlBase::GetControllerSize() const
|
||||
{
|
||||
if(!m_bookctrl)
|
||||
return wxSize(0,0);
|
||||
|
||||
const wxSize sizeClient = GetClientSize(),
|
||||
sizeBorder = m_bookctrl->GetSize() - m_bookctrl->GetClientSize(),
|
||||
sizeCtrl = m_bookctrl->GetBestSize() + sizeBorder;
|
||||
|
||||
wxSize size;
|
||||
|
||||
if ( IsVertical() )
|
||||
{
|
||||
size.x = sizeClient.x;
|
||||
size.y = sizeCtrl.y;
|
||||
}
|
||||
else // left/right aligned
|
||||
{
|
||||
size.x = sizeCtrl.x;
|
||||
size.y = sizeClient.y;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// miscellaneous stuff
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_HELP
|
||||
|
||||
void wxBookCtrlBase::OnHelp(wxHelpEvent& event)
|
||||
{
|
||||
// determine where does this even originate from to avoid redirecting it
|
||||
// back to the page which generated it (resulting in an infinite loop)
|
||||
|
||||
// notice that we have to check in the hard(er) way instead of just testing
|
||||
// if the event object == this because the book control can have other
|
||||
// subcontrols inside it (e.g. wxSpinButton in case of a notebook in wxUniv)
|
||||
wxWindow *source = wxStaticCast(event.GetEventObject(), wxWindow);
|
||||
while ( source && source != this && source->GetParent() != this )
|
||||
{
|
||||
source = source->GetParent();
|
||||
}
|
||||
|
||||
if ( source && m_pages.Index(source) == wxNOT_FOUND )
|
||||
{
|
||||
// this event is for the book control itself, redirect it to the
|
||||
// corresponding page
|
||||
wxWindow *page = NULL;
|
||||
|
||||
if ( event.GetOrigin() == wxHelpEvent::Origin_HelpButton )
|
||||
{
|
||||
// show help for the page under the mouse
|
||||
const int pagePos = HitTest(ScreenToClient(event.GetPosition()));
|
||||
|
||||
if ( pagePos != wxNOT_FOUND)
|
||||
{
|
||||
page = GetPage((size_t)pagePos);
|
||||
}
|
||||
}
|
||||
else // event from keyboard or unknown source
|
||||
{
|
||||
// otherwise show the current page help
|
||||
page = GetCurrentPage();
|
||||
}
|
||||
|
||||
if ( page )
|
||||
{
|
||||
// change event object to the page to avoid infinite recursion if
|
||||
// we get this event ourselves if the page doesn't handle it
|
||||
event.SetEventObject(page);
|
||||
|
||||
if ( page->GetEventHandler()->ProcessEvent(event) )
|
||||
{
|
||||
// don't call event.Skip()
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//else: event coming from one of our pages already
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
#endif // wxUSE_HELP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// pages management
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
wxBookCtrlBase::InsertPage(size_t nPage,
|
||||
wxWindow *page,
|
||||
const wxString& WXUNUSED(text),
|
||||
bool WXUNUSED(bSelect),
|
||||
int WXUNUSED(imageId))
|
||||
{
|
||||
wxCHECK_MSG( page || AllowNullPage(), false,
|
||||
_T("NULL page in wxBookCtrlBase::InsertPage()") );
|
||||
wxCHECK_MSG( nPage <= m_pages.size(), false,
|
||||
_T("invalid page index in wxBookCtrlBase::InsertPage()") );
|
||||
|
||||
m_pages.Insert(page, nPage);
|
||||
if ( page )
|
||||
page->SetSize(GetPageRect());
|
||||
|
||||
DoInvalidateBestSize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxBookCtrlBase::DeletePage(size_t nPage)
|
||||
{
|
||||
wxWindow *page = DoRemovePage(nPage);
|
||||
if ( !(page || AllowNullPage()) )
|
||||
return false;
|
||||
|
||||
// delete NULL is harmless
|
||||
delete page;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxWindow *wxBookCtrlBase::DoRemovePage(size_t nPage)
|
||||
{
|
||||
wxCHECK_MSG( nPage < m_pages.size(), NULL,
|
||||
_T("invalid page index in wxBookCtrlBase::DoRemovePage()") );
|
||||
|
||||
wxWindow *pageRemoved = m_pages[nPage];
|
||||
m_pages.RemoveAt(nPage);
|
||||
DoInvalidateBestSize();
|
||||
|
||||
return pageRemoved;
|
||||
}
|
||||
|
||||
int wxBookCtrlBase::GetNextPage(bool forward) const
|
||||
{
|
||||
int nPage;
|
||||
|
||||
int nMax = GetPageCount();
|
||||
if ( nMax-- ) // decrement it to get the last valid index
|
||||
{
|
||||
int nSel = GetSelection();
|
||||
|
||||
// change selection wrapping if it becomes invalid
|
||||
nPage = forward ? nSel == nMax ? 0
|
||||
: nSel + 1
|
||||
: nSel == 0 ? nMax
|
||||
: nSel - 1;
|
||||
}
|
||||
else // notebook is empty, no next page
|
||||
{
|
||||
nPage = wxNOT_FOUND;
|
||||
}
|
||||
|
||||
return nPage;
|
||||
}
|
||||
|
||||
int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
|
||||
{
|
||||
wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
|
||||
wxT("invalid page index in wxBookCtrlBase::DoSetSelection()") );
|
||||
|
||||
const int oldSel = GetSelection();
|
||||
|
||||
if ( n != (size_t)oldSel )
|
||||
{
|
||||
wxBookCtrlBaseEvent *event = CreatePageChangingEvent();
|
||||
bool allowed = false;
|
||||
|
||||
if ( flags & SetSelection_SendEvent )
|
||||
{
|
||||
event->SetSelection(n);
|
||||
event->SetOldSelection(oldSel);
|
||||
event->SetEventObject(this);
|
||||
|
||||
allowed = !GetEventHandler()->ProcessEvent(*event) || event->IsAllowed();
|
||||
}
|
||||
|
||||
if ( !(flags & SetSelection_SendEvent) || allowed)
|
||||
{
|
||||
if ( oldSel != wxNOT_FOUND )
|
||||
m_pages[oldSel]->Hide();
|
||||
|
||||
wxWindow *page = m_pages[n];
|
||||
page->SetSize(GetPageRect());
|
||||
page->Show();
|
||||
|
||||
// change selection now to ignore the selection change event
|
||||
UpdateSelectedPage(n);
|
||||
|
||||
if ( flags & SetSelection_SendEvent )
|
||||
{
|
||||
// program allows the page change
|
||||
MakeChangedEvent(*event);
|
||||
(void)GetEventHandler()->ProcessEvent(*event);
|
||||
}
|
||||
}
|
||||
|
||||
delete event;
|
||||
}
|
||||
|
||||
return oldSel;
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_BOOKCTRL
|
||||
|
110
Externals/wxWidgets/src/common/choiccmn.cpp
vendored
110
Externals/wxWidgets/src/common/choiccmn.cpp
vendored
@ -1,55 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/choiccmn.cpp
|
||||
// Purpose: common (to all ports) wxChoice functions
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 26.07.99
|
||||
// RCS-ID: $Id: choiccmn.cpp 39470 2006-05-30 07:34:30Z ABX $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CHOICE
|
||||
|
||||
#include "wx/choice.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
const wxChar wxChoiceNameStr[] = wxT("choice");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxChoiceBase::~wxChoiceBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// misc
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxChoiceBase::Command(wxCommandEvent& event)
|
||||
{
|
||||
SetSelection(event.GetInt());
|
||||
(void)ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_CHOICE
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/choiccmn.cpp
|
||||
// Purpose: common (to all ports) wxChoice functions
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 26.07.99
|
||||
// RCS-ID: $Id: choiccmn.cpp 39470 2006-05-30 07:34:30Z ABX $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CHOICE
|
||||
|
||||
#include "wx/choice.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
const wxChar wxChoiceNameStr[] = wxT("choice");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxChoiceBase::~wxChoiceBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// misc
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxChoiceBase::Command(wxCommandEvent& event)
|
||||
{
|
||||
SetSelection(event.GetInt());
|
||||
(void)ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_CHOICE
|
||||
|
126
Externals/wxWidgets/src/common/clipcmn.cpp
vendored
126
Externals/wxWidgets/src/common/clipcmn.cpp
vendored
@ -1,63 +1,63 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/clipcmn.cpp
|
||||
// Purpose: common (to all ports) wxClipboard functions
|
||||
// Author: Robert Roebling
|
||||
// Modified by:
|
||||
// Created: 28.06.99
|
||||
// RCS-ID: $Id: clipcmn.cpp 40943 2006-08-31 19:31:43Z ABX $
|
||||
// Copyright: (c) Robert Roebling
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CLIPBOARD
|
||||
|
||||
#include "wx/clipbrd.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
static wxClipboard *gs_clipboard = NULL;
|
||||
|
||||
/*static*/ wxClipboard *wxClipboardBase::Get()
|
||||
{
|
||||
if ( !gs_clipboard )
|
||||
{
|
||||
gs_clipboard = new wxClipboard;
|
||||
}
|
||||
return gs_clipboard;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxClipboardModule: module responsible for destroying the global clipboard
|
||||
// object
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxClipboardModule : public wxModule
|
||||
{
|
||||
public:
|
||||
bool OnInit() { return true; }
|
||||
void OnExit() { wxDELETE(gs_clipboard); }
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxClipboardModule)
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule, wxModule)
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/clipcmn.cpp
|
||||
// Purpose: common (to all ports) wxClipboard functions
|
||||
// Author: Robert Roebling
|
||||
// Modified by:
|
||||
// Created: 28.06.99
|
||||
// RCS-ID: $Id: clipcmn.cpp 40943 2006-08-31 19:31:43Z ABX $
|
||||
// Copyright: (c) Robert Roebling
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CLIPBOARD
|
||||
|
||||
#include "wx/clipbrd.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
static wxClipboard *gs_clipboard = NULL;
|
||||
|
||||
/*static*/ wxClipboard *wxClipboardBase::Get()
|
||||
{
|
||||
if ( !gs_clipboard )
|
||||
{
|
||||
gs_clipboard = new wxClipboard;
|
||||
}
|
||||
return gs_clipboard;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxClipboardModule: module responsible for destroying the global clipboard
|
||||
// object
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxClipboardModule : public wxModule
|
||||
{
|
||||
public:
|
||||
bool OnInit() { return true; }
|
||||
void OnExit() { wxDELETE(gs_clipboard); }
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxClipboardModule)
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule, wxModule)
|
||||
|
||||
#endif // wxUSE_CLIPBOARD
|
||||
|
166
Externals/wxWidgets/src/common/clntdata.cpp
vendored
166
Externals/wxWidgets/src/common/clntdata.cpp
vendored
@ -1,83 +1,83 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/clntdata.cpp
|
||||
// Purpose: A mixin class for holding a wxClientData or void pointer
|
||||
// Author: Robin Dunn
|
||||
// Modified by:
|
||||
// Created: 9-Oct-2001
|
||||
// RCS-ID: $Id: clntdata.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/clntdata.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxClientDataContainer::wxClientDataContainer()
|
||||
{
|
||||
// no client data (yet)
|
||||
m_clientData = NULL;
|
||||
m_clientDataType = wxClientData_None;
|
||||
}
|
||||
|
||||
wxClientDataContainer::~wxClientDataContainer()
|
||||
{
|
||||
// we only delete object data, not untyped
|
||||
if ( m_clientDataType == wxClientData_Object )
|
||||
delete m_clientObject;
|
||||
}
|
||||
|
||||
void wxClientDataContainer::DoSetClientObject( wxClientData *data )
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Void,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
if ( m_clientObject )
|
||||
delete m_clientObject;
|
||||
|
||||
m_clientObject = data;
|
||||
m_clientDataType = wxClientData_Object;
|
||||
}
|
||||
|
||||
wxClientData *wxClientDataContainer::DoGetClientObject() const
|
||||
{
|
||||
// it's not an error to call GetClientObject() on a window which doesn't
|
||||
// have client data at all - NULL will be returned
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Void,
|
||||
wxT("this window doesn't have object client data") );
|
||||
|
||||
return m_clientObject;
|
||||
}
|
||||
|
||||
void wxClientDataContainer::DoSetClientData( void *data )
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Object,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
m_clientData = data;
|
||||
m_clientDataType = wxClientData_Void;
|
||||
}
|
||||
|
||||
void *wxClientDataContainer::DoGetClientData() const
|
||||
{
|
||||
// it's not an error to call GetClientData() on a window which doesn't have
|
||||
// client data at all - NULL will be returned
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Object,
|
||||
wxT("this window doesn't have void client data") );
|
||||
|
||||
return m_clientData;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/clntdata.cpp
|
||||
// Purpose: A mixin class for holding a wxClientData or void pointer
|
||||
// Author: Robin Dunn
|
||||
// Modified by:
|
||||
// Created: 9-Oct-2001
|
||||
// RCS-ID: $Id: clntdata.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/clntdata.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxClientDataContainer::wxClientDataContainer()
|
||||
{
|
||||
// no client data (yet)
|
||||
m_clientData = NULL;
|
||||
m_clientDataType = wxClientData_None;
|
||||
}
|
||||
|
||||
wxClientDataContainer::~wxClientDataContainer()
|
||||
{
|
||||
// we only delete object data, not untyped
|
||||
if ( m_clientDataType == wxClientData_Object )
|
||||
delete m_clientObject;
|
||||
}
|
||||
|
||||
void wxClientDataContainer::DoSetClientObject( wxClientData *data )
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Void,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
if ( m_clientObject )
|
||||
delete m_clientObject;
|
||||
|
||||
m_clientObject = data;
|
||||
m_clientDataType = wxClientData_Object;
|
||||
}
|
||||
|
||||
wxClientData *wxClientDataContainer::DoGetClientObject() const
|
||||
{
|
||||
// it's not an error to call GetClientObject() on a window which doesn't
|
||||
// have client data at all - NULL will be returned
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Void,
|
||||
wxT("this window doesn't have object client data") );
|
||||
|
||||
return m_clientObject;
|
||||
}
|
||||
|
||||
void wxClientDataContainer::DoSetClientData( void *data )
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Object,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
m_clientData = data;
|
||||
m_clientDataType = wxClientData_Void;
|
||||
}
|
||||
|
||||
void *wxClientDataContainer::DoGetClientData() const
|
||||
{
|
||||
// it's not an error to call GetClientData() on a window which doesn't have
|
||||
// client data at all - NULL will be returned
|
||||
wxASSERT_MSG( m_clientDataType != wxClientData_Object,
|
||||
wxT("this window doesn't have void client data") );
|
||||
|
||||
return m_clientData;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
298
Externals/wxWidgets/src/common/clrpickercmn.cpp
vendored
298
Externals/wxWidgets/src/common/clrpickercmn.cpp
vendored
@ -1,149 +1,149 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/clrpickercmn.cpp
|
||||
// Purpose: wxColourPickerCtrl class implementation
|
||||
// Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
|
||||
// Modified by:
|
||||
// Created: 15/04/2006
|
||||
// RCS-ID: $Id: clrpickercmn.cpp 42219 2006-10-21 19:53:05Z PC $
|
||||
// Copyright: (c) Vadim Zeitlin, Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_COLOURPICKERCTRL
|
||||
|
||||
#include "wx/clrpicker.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
const wxChar wxColourPickerCtrlNameStr[] = wxT("colourpicker");
|
||||
const wxChar wxColourPickerWidgetNameStr[] = wxT("colourpickerwidget");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_COLOURPICKER_CHANGED)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxColourPickerCtrl, wxPickerBase)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxColourPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define M_PICKER ((wxColourPickerWidget*)m_picker)
|
||||
|
||||
bool wxColourPickerCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||
const wxColour &col,
|
||||
const wxPoint &pos, const wxSize &size,
|
||||
long style, const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
if (!wxPickerBase::CreateBase(parent, id, col.GetAsString(), pos, size,
|
||||
style, validator, name))
|
||||
return false;
|
||||
|
||||
// we are not interested to the ID of our picker as we connect
|
||||
// to its "changed" event dynamically...
|
||||
m_picker = new wxColourPickerWidget(this, wxID_ANY, col,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
GetPickerStyle(style));
|
||||
|
||||
// complete sizer creation
|
||||
wxPickerBase::PostCreation();
|
||||
|
||||
m_picker->Connect(wxEVT_COMMAND_COLOURPICKER_CHANGED,
|
||||
wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange),
|
||||
NULL, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxColourPickerCtrl::SetColour(const wxColour &col)
|
||||
{
|
||||
M_PICKER->SetColour(col);
|
||||
UpdateTextCtrlFromPicker();
|
||||
}
|
||||
|
||||
bool wxColourPickerCtrl::SetColour(const wxString &text)
|
||||
{
|
||||
wxColour col(text); // smart wxString->wxColour conversion
|
||||
if ( !col.Ok() )
|
||||
return false;
|
||||
M_PICKER->SetColour(col);
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxColourPickerCtrl::UpdatePickerFromTextCtrl()
|
||||
{
|
||||
wxASSERT(m_text);
|
||||
|
||||
if (m_bIgnoreNextTextCtrlUpdate)
|
||||
{
|
||||
// ignore this update
|
||||
m_bIgnoreNextTextCtrlUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// wxString -> wxColour conversion
|
||||
wxColour col(m_text->GetValue());
|
||||
if ( !col.Ok() )
|
||||
return; // invalid user input
|
||||
|
||||
if (M_PICKER->GetColour() != col)
|
||||
{
|
||||
M_PICKER->SetColour(col);
|
||||
|
||||
// fire an event
|
||||
wxColourPickerEvent event(this, GetId(), col);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxColourPickerCtrl::UpdateTextCtrlFromPicker()
|
||||
{
|
||||
if (!m_text)
|
||||
return; // no textctrl to update
|
||||
|
||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
||||
m_bIgnoreNextTextCtrlUpdate = true;
|
||||
m_text->SetValue(M_PICKER->GetColour().GetAsString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxColourPickerCtrl - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxColourPickerCtrl::OnColourChange(wxColourPickerEvent &ev)
|
||||
{
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
// the wxColourPickerWidget sent us a colour-change notification.
|
||||
// forward this event to our parent
|
||||
wxColourPickerEvent event(this, GetId(), ev.GetColour());
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_COLOURPICKERCTRL
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/clrpickercmn.cpp
|
||||
// Purpose: wxColourPickerCtrl class implementation
|
||||
// Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
|
||||
// Modified by:
|
||||
// Created: 15/04/2006
|
||||
// RCS-ID: $Id: clrpickercmn.cpp 42219 2006-10-21 19:53:05Z PC $
|
||||
// Copyright: (c) Vadim Zeitlin, Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_COLOURPICKERCTRL
|
||||
|
||||
#include "wx/clrpicker.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
const wxChar wxColourPickerCtrlNameStr[] = wxT("colourpicker");
|
||||
const wxChar wxColourPickerWidgetNameStr[] = wxT("colourpickerwidget");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_COLOURPICKER_CHANGED)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxColourPickerCtrl, wxPickerBase)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxColourPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define M_PICKER ((wxColourPickerWidget*)m_picker)
|
||||
|
||||
bool wxColourPickerCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||
const wxColour &col,
|
||||
const wxPoint &pos, const wxSize &size,
|
||||
long style, const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
if (!wxPickerBase::CreateBase(parent, id, col.GetAsString(), pos, size,
|
||||
style, validator, name))
|
||||
return false;
|
||||
|
||||
// we are not interested to the ID of our picker as we connect
|
||||
// to its "changed" event dynamically...
|
||||
m_picker = new wxColourPickerWidget(this, wxID_ANY, col,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
GetPickerStyle(style));
|
||||
|
||||
// complete sizer creation
|
||||
wxPickerBase::PostCreation();
|
||||
|
||||
m_picker->Connect(wxEVT_COMMAND_COLOURPICKER_CHANGED,
|
||||
wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange),
|
||||
NULL, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxColourPickerCtrl::SetColour(const wxColour &col)
|
||||
{
|
||||
M_PICKER->SetColour(col);
|
||||
UpdateTextCtrlFromPicker();
|
||||
}
|
||||
|
||||
bool wxColourPickerCtrl::SetColour(const wxString &text)
|
||||
{
|
||||
wxColour col(text); // smart wxString->wxColour conversion
|
||||
if ( !col.Ok() )
|
||||
return false;
|
||||
M_PICKER->SetColour(col);
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxColourPickerCtrl::UpdatePickerFromTextCtrl()
|
||||
{
|
||||
wxASSERT(m_text);
|
||||
|
||||
if (m_bIgnoreNextTextCtrlUpdate)
|
||||
{
|
||||
// ignore this update
|
||||
m_bIgnoreNextTextCtrlUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// wxString -> wxColour conversion
|
||||
wxColour col(m_text->GetValue());
|
||||
if ( !col.Ok() )
|
||||
return; // invalid user input
|
||||
|
||||
if (M_PICKER->GetColour() != col)
|
||||
{
|
||||
M_PICKER->SetColour(col);
|
||||
|
||||
// fire an event
|
||||
wxColourPickerEvent event(this, GetId(), col);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxColourPickerCtrl::UpdateTextCtrlFromPicker()
|
||||
{
|
||||
if (!m_text)
|
||||
return; // no textctrl to update
|
||||
|
||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
||||
m_bIgnoreNextTextCtrlUpdate = true;
|
||||
m_text->SetValue(M_PICKER->GetColour().GetAsString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxColourPickerCtrl - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxColourPickerCtrl::OnColourChange(wxColourPickerEvent &ev)
|
||||
{
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
// the wxColourPickerWidget sent us a colour-change notification.
|
||||
// forward this event to our parent
|
||||
wxColourPickerEvent event(this, GetId(), ev.GetColour());
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_COLOURPICKERCTRL
|
||||
|
2494
Externals/wxWidgets/src/common/cmdline.cpp
vendored
2494
Externals/wxWidgets/src/common/cmdline.cpp
vendored
File diff suppressed because it is too large
Load Diff
650
Externals/wxWidgets/src/common/cmdproc.cpp
vendored
650
Externals/wxWidgets/src/common/cmdproc.cpp
vendored
@ -1,325 +1,325 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/cmdproc.cpp
|
||||
// Purpose: wxCommand and wxCommandProcessor classes
|
||||
// Author: Julian Smart (extracted from docview.h by VZ)
|
||||
// Modified by:
|
||||
// Created: 05.11.00
|
||||
// RCS-ID: $Id: cmdproc.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/menu.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/cmdproc.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_CLASS(wxCommand, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxCommand
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCommand::wxCommand(bool canUndoIt, const wxString& name)
|
||||
{
|
||||
m_canUndo = canUndoIt;
|
||||
m_commandName = name;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Command processor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCommandProcessor::wxCommandProcessor(int maxCommands)
|
||||
{
|
||||
m_maxNoCommands = maxCommands;
|
||||
#if wxUSE_MENUS
|
||||
m_commandEditMenu = (wxMenu *) NULL;
|
||||
#endif // wxUSE_MENUS
|
||||
m_undoAccelerator = wxT("\tCtrl+Z");
|
||||
m_redoAccelerator = wxT("\tCtrl+Y");
|
||||
|
||||
m_lastSavedCommand =
|
||||
m_currentCommand = wxList::compatibility_iterator();
|
||||
}
|
||||
|
||||
wxCommandProcessor::~wxCommandProcessor()
|
||||
{
|
||||
ClearCommands();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::DoCommand(wxCommand& cmd)
|
||||
{
|
||||
return cmd.Do();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::UndoCommand(wxCommand& cmd)
|
||||
{
|
||||
return cmd.Undo();
|
||||
}
|
||||
|
||||
// Pass a command to the processor. The processor calls Do();
|
||||
// if successful, is appended to the command history unless
|
||||
// storeIt is false.
|
||||
bool wxCommandProcessor::Submit(wxCommand *command, bool storeIt)
|
||||
{
|
||||
wxCHECK_MSG( command, false, _T("no command in wxCommandProcessor::Submit") );
|
||||
|
||||
if ( !DoCommand(*command) )
|
||||
{
|
||||
// the user code expects the command to be deleted anyhow
|
||||
delete command;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( storeIt )
|
||||
Store(command);
|
||||
else
|
||||
delete command;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxCommandProcessor::Store(wxCommand *command)
|
||||
{
|
||||
wxCHECK_RET( command, _T("no command in wxCommandProcessor::Store") );
|
||||
|
||||
if ( (int)m_commands.GetCount() == m_maxNoCommands )
|
||||
{
|
||||
wxList::compatibility_iterator firstNode = m_commands.GetFirst();
|
||||
wxCommand *firstCommand = (wxCommand *)firstNode->GetData();
|
||||
delete firstCommand;
|
||||
m_commands.Erase(firstNode);
|
||||
|
||||
// Make sure m_lastSavedCommand won't point to freed memory
|
||||
if ( m_lastSavedCommand == firstNode )
|
||||
m_lastSavedCommand = wxList::compatibility_iterator();
|
||||
}
|
||||
|
||||
// Correct a bug: we must chop off the current 'branch'
|
||||
// so that we're at the end of the command list.
|
||||
if (!m_currentCommand)
|
||||
ClearCommands();
|
||||
else
|
||||
{
|
||||
wxList::compatibility_iterator node = m_currentCommand->GetNext();
|
||||
while (node)
|
||||
{
|
||||
wxList::compatibility_iterator next = node->GetNext();
|
||||
delete (wxCommand *)node->GetData();
|
||||
m_commands.Erase(node);
|
||||
|
||||
// Make sure m_lastSavedCommand won't point to freed memory
|
||||
if ( m_lastSavedCommand == node )
|
||||
m_lastSavedCommand = wxList::compatibility_iterator();
|
||||
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
m_commands.Append(command);
|
||||
m_currentCommand = m_commands.GetLast();
|
||||
SetMenuStrings();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::Undo()
|
||||
{
|
||||
wxCommand *command = GetCurrentCommand();
|
||||
if ( command && command->CanUndo() )
|
||||
{
|
||||
if ( UndoCommand(*command) )
|
||||
{
|
||||
m_currentCommand = m_currentCommand->GetPrevious();
|
||||
SetMenuStrings();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::Redo()
|
||||
{
|
||||
wxCommand *redoCommand = (wxCommand *) NULL;
|
||||
wxList::compatibility_iterator redoNode
|
||||
#if !wxUSE_STL
|
||||
= NULL // just to avoid warnings
|
||||
#endif // !wxUSE_STL
|
||||
;
|
||||
|
||||
if ( m_currentCommand )
|
||||
{
|
||||
// is there anything to redo?
|
||||
if ( m_currentCommand->GetNext() )
|
||||
{
|
||||
redoCommand = (wxCommand *)m_currentCommand->GetNext()->GetData();
|
||||
redoNode = m_currentCommand->GetNext();
|
||||
}
|
||||
}
|
||||
else // no current command, redo the first one
|
||||
{
|
||||
if (m_commands.GetCount() > 0)
|
||||
{
|
||||
redoCommand = (wxCommand *)m_commands.GetFirst()->GetData();
|
||||
redoNode = m_commands.GetFirst();
|
||||
}
|
||||
}
|
||||
|
||||
if (redoCommand)
|
||||
{
|
||||
bool success = DoCommand(*redoCommand);
|
||||
if (success)
|
||||
{
|
||||
m_currentCommand = redoNode;
|
||||
SetMenuStrings();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::CanUndo() const
|
||||
{
|
||||
wxCommand *command = GetCurrentCommand();
|
||||
|
||||
return command && command->CanUndo();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::CanRedo() const
|
||||
{
|
||||
if (m_currentCommand && !m_currentCommand->GetNext())
|
||||
return false;
|
||||
|
||||
if (m_currentCommand && m_currentCommand->GetNext())
|
||||
return true;
|
||||
|
||||
if (!m_currentCommand && (m_commands.GetCount() > 0))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxCommandProcessor::Initialize()
|
||||
{
|
||||
m_currentCommand = m_commands.GetLast();
|
||||
SetMenuStrings();
|
||||
}
|
||||
|
||||
void wxCommandProcessor::SetMenuStrings()
|
||||
{
|
||||
#if wxUSE_MENUS
|
||||
if (m_commandEditMenu)
|
||||
{
|
||||
wxString undoLabel = GetUndoMenuLabel();
|
||||
wxString redoLabel = GetRedoMenuLabel();
|
||||
|
||||
m_commandEditMenu->SetLabel(wxID_UNDO, undoLabel);
|
||||
m_commandEditMenu->Enable(wxID_UNDO, CanUndo());
|
||||
|
||||
m_commandEditMenu->SetLabel(wxID_REDO, redoLabel);
|
||||
m_commandEditMenu->Enable(wxID_REDO, CanRedo());
|
||||
}
|
||||
#endif // wxUSE_MENUS
|
||||
}
|
||||
|
||||
// Gets the current Undo menu label.
|
||||
wxString wxCommandProcessor::GetUndoMenuLabel() const
|
||||
{
|
||||
wxString buf;
|
||||
if (m_currentCommand)
|
||||
{
|
||||
wxCommand *command = (wxCommand *)m_currentCommand->GetData();
|
||||
wxString commandName(command->GetName());
|
||||
if (commandName.empty()) commandName = _("Unnamed command");
|
||||
bool canUndo = command->CanUndo();
|
||||
if (canUndo)
|
||||
buf = wxString(_("&Undo ")) + commandName + m_undoAccelerator;
|
||||
else
|
||||
buf = wxString(_("Can't &Undo ")) + commandName + m_undoAccelerator;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = _("&Undo") + m_undoAccelerator;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Gets the current Undo menu label.
|
||||
wxString wxCommandProcessor::GetRedoMenuLabel() const
|
||||
{
|
||||
wxString buf;
|
||||
if (m_currentCommand)
|
||||
{
|
||||
// We can redo, if we're not at the end of the history.
|
||||
if (m_currentCommand->GetNext())
|
||||
{
|
||||
wxCommand *redoCommand = (wxCommand *)m_currentCommand->GetNext()->GetData();
|
||||
wxString redoCommandName(redoCommand->GetName());
|
||||
if (redoCommandName.empty()) redoCommandName = _("Unnamed command");
|
||||
buf = wxString(_("&Redo ")) + redoCommandName + m_redoAccelerator;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = _("&Redo") + m_redoAccelerator;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_commands.GetCount() == 0)
|
||||
{
|
||||
buf = _("&Redo") + m_redoAccelerator;
|
||||
}
|
||||
else
|
||||
{
|
||||
// currentCommand is NULL but there are commands: this means that
|
||||
// we've undone to the start of the list, but can redo the first.
|
||||
wxCommand *redoCommand = (wxCommand *)m_commands.GetFirst()->GetData();
|
||||
wxString redoCommandName(redoCommand->GetName());
|
||||
if (redoCommandName.empty()) redoCommandName = _("Unnamed command");
|
||||
buf = wxString(_("&Redo ")) + redoCommandName + m_redoAccelerator;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
void wxCommandProcessor::ClearCommands()
|
||||
{
|
||||
wxList::compatibility_iterator node = m_commands.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
wxCommand *command = (wxCommand *)node->GetData();
|
||||
delete command;
|
||||
m_commands.Erase(node);
|
||||
node = m_commands.GetFirst();
|
||||
}
|
||||
|
||||
m_currentCommand = wxList::compatibility_iterator();
|
||||
m_lastSavedCommand = wxList::compatibility_iterator();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/cmdproc.cpp
|
||||
// Purpose: wxCommand and wxCommandProcessor classes
|
||||
// Author: Julian Smart (extracted from docview.h by VZ)
|
||||
// Modified by:
|
||||
// Created: 05.11.00
|
||||
// RCS-ID: $Id: cmdproc.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/menu.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/cmdproc.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
IMPLEMENT_CLASS(wxCommand, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxCommand
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCommand::wxCommand(bool canUndoIt, const wxString& name)
|
||||
{
|
||||
m_canUndo = canUndoIt;
|
||||
m_commandName = name;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Command processor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxCommandProcessor::wxCommandProcessor(int maxCommands)
|
||||
{
|
||||
m_maxNoCommands = maxCommands;
|
||||
#if wxUSE_MENUS
|
||||
m_commandEditMenu = (wxMenu *) NULL;
|
||||
#endif // wxUSE_MENUS
|
||||
m_undoAccelerator = wxT("\tCtrl+Z");
|
||||
m_redoAccelerator = wxT("\tCtrl+Y");
|
||||
|
||||
m_lastSavedCommand =
|
||||
m_currentCommand = wxList::compatibility_iterator();
|
||||
}
|
||||
|
||||
wxCommandProcessor::~wxCommandProcessor()
|
||||
{
|
||||
ClearCommands();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::DoCommand(wxCommand& cmd)
|
||||
{
|
||||
return cmd.Do();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::UndoCommand(wxCommand& cmd)
|
||||
{
|
||||
return cmd.Undo();
|
||||
}
|
||||
|
||||
// Pass a command to the processor. The processor calls Do();
|
||||
// if successful, is appended to the command history unless
|
||||
// storeIt is false.
|
||||
bool wxCommandProcessor::Submit(wxCommand *command, bool storeIt)
|
||||
{
|
||||
wxCHECK_MSG( command, false, _T("no command in wxCommandProcessor::Submit") );
|
||||
|
||||
if ( !DoCommand(*command) )
|
||||
{
|
||||
// the user code expects the command to be deleted anyhow
|
||||
delete command;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( storeIt )
|
||||
Store(command);
|
||||
else
|
||||
delete command;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxCommandProcessor::Store(wxCommand *command)
|
||||
{
|
||||
wxCHECK_RET( command, _T("no command in wxCommandProcessor::Store") );
|
||||
|
||||
if ( (int)m_commands.GetCount() == m_maxNoCommands )
|
||||
{
|
||||
wxList::compatibility_iterator firstNode = m_commands.GetFirst();
|
||||
wxCommand *firstCommand = (wxCommand *)firstNode->GetData();
|
||||
delete firstCommand;
|
||||
m_commands.Erase(firstNode);
|
||||
|
||||
// Make sure m_lastSavedCommand won't point to freed memory
|
||||
if ( m_lastSavedCommand == firstNode )
|
||||
m_lastSavedCommand = wxList::compatibility_iterator();
|
||||
}
|
||||
|
||||
// Correct a bug: we must chop off the current 'branch'
|
||||
// so that we're at the end of the command list.
|
||||
if (!m_currentCommand)
|
||||
ClearCommands();
|
||||
else
|
||||
{
|
||||
wxList::compatibility_iterator node = m_currentCommand->GetNext();
|
||||
while (node)
|
||||
{
|
||||
wxList::compatibility_iterator next = node->GetNext();
|
||||
delete (wxCommand *)node->GetData();
|
||||
m_commands.Erase(node);
|
||||
|
||||
// Make sure m_lastSavedCommand won't point to freed memory
|
||||
if ( m_lastSavedCommand == node )
|
||||
m_lastSavedCommand = wxList::compatibility_iterator();
|
||||
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
m_commands.Append(command);
|
||||
m_currentCommand = m_commands.GetLast();
|
||||
SetMenuStrings();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::Undo()
|
||||
{
|
||||
wxCommand *command = GetCurrentCommand();
|
||||
if ( command && command->CanUndo() )
|
||||
{
|
||||
if ( UndoCommand(*command) )
|
||||
{
|
||||
m_currentCommand = m_currentCommand->GetPrevious();
|
||||
SetMenuStrings();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::Redo()
|
||||
{
|
||||
wxCommand *redoCommand = (wxCommand *) NULL;
|
||||
wxList::compatibility_iterator redoNode
|
||||
#if !wxUSE_STL
|
||||
= NULL // just to avoid warnings
|
||||
#endif // !wxUSE_STL
|
||||
;
|
||||
|
||||
if ( m_currentCommand )
|
||||
{
|
||||
// is there anything to redo?
|
||||
if ( m_currentCommand->GetNext() )
|
||||
{
|
||||
redoCommand = (wxCommand *)m_currentCommand->GetNext()->GetData();
|
||||
redoNode = m_currentCommand->GetNext();
|
||||
}
|
||||
}
|
||||
else // no current command, redo the first one
|
||||
{
|
||||
if (m_commands.GetCount() > 0)
|
||||
{
|
||||
redoCommand = (wxCommand *)m_commands.GetFirst()->GetData();
|
||||
redoNode = m_commands.GetFirst();
|
||||
}
|
||||
}
|
||||
|
||||
if (redoCommand)
|
||||
{
|
||||
bool success = DoCommand(*redoCommand);
|
||||
if (success)
|
||||
{
|
||||
m_currentCommand = redoNode;
|
||||
SetMenuStrings();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::CanUndo() const
|
||||
{
|
||||
wxCommand *command = GetCurrentCommand();
|
||||
|
||||
return command && command->CanUndo();
|
||||
}
|
||||
|
||||
bool wxCommandProcessor::CanRedo() const
|
||||
{
|
||||
if (m_currentCommand && !m_currentCommand->GetNext())
|
||||
return false;
|
||||
|
||||
if (m_currentCommand && m_currentCommand->GetNext())
|
||||
return true;
|
||||
|
||||
if (!m_currentCommand && (m_commands.GetCount() > 0))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxCommandProcessor::Initialize()
|
||||
{
|
||||
m_currentCommand = m_commands.GetLast();
|
||||
SetMenuStrings();
|
||||
}
|
||||
|
||||
void wxCommandProcessor::SetMenuStrings()
|
||||
{
|
||||
#if wxUSE_MENUS
|
||||
if (m_commandEditMenu)
|
||||
{
|
||||
wxString undoLabel = GetUndoMenuLabel();
|
||||
wxString redoLabel = GetRedoMenuLabel();
|
||||
|
||||
m_commandEditMenu->SetLabel(wxID_UNDO, undoLabel);
|
||||
m_commandEditMenu->Enable(wxID_UNDO, CanUndo());
|
||||
|
||||
m_commandEditMenu->SetLabel(wxID_REDO, redoLabel);
|
||||
m_commandEditMenu->Enable(wxID_REDO, CanRedo());
|
||||
}
|
||||
#endif // wxUSE_MENUS
|
||||
}
|
||||
|
||||
// Gets the current Undo menu label.
|
||||
wxString wxCommandProcessor::GetUndoMenuLabel() const
|
||||
{
|
||||
wxString buf;
|
||||
if (m_currentCommand)
|
||||
{
|
||||
wxCommand *command = (wxCommand *)m_currentCommand->GetData();
|
||||
wxString commandName(command->GetName());
|
||||
if (commandName.empty()) commandName = _("Unnamed command");
|
||||
bool canUndo = command->CanUndo();
|
||||
if (canUndo)
|
||||
buf = wxString(_("&Undo ")) + commandName + m_undoAccelerator;
|
||||
else
|
||||
buf = wxString(_("Can't &Undo ")) + commandName + m_undoAccelerator;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = _("&Undo") + m_undoAccelerator;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Gets the current Undo menu label.
|
||||
wxString wxCommandProcessor::GetRedoMenuLabel() const
|
||||
{
|
||||
wxString buf;
|
||||
if (m_currentCommand)
|
||||
{
|
||||
// We can redo, if we're not at the end of the history.
|
||||
if (m_currentCommand->GetNext())
|
||||
{
|
||||
wxCommand *redoCommand = (wxCommand *)m_currentCommand->GetNext()->GetData();
|
||||
wxString redoCommandName(redoCommand->GetName());
|
||||
if (redoCommandName.empty()) redoCommandName = _("Unnamed command");
|
||||
buf = wxString(_("&Redo ")) + redoCommandName + m_redoAccelerator;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = _("&Redo") + m_redoAccelerator;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_commands.GetCount() == 0)
|
||||
{
|
||||
buf = _("&Redo") + m_redoAccelerator;
|
||||
}
|
||||
else
|
||||
{
|
||||
// currentCommand is NULL but there are commands: this means that
|
||||
// we've undone to the start of the list, but can redo the first.
|
||||
wxCommand *redoCommand = (wxCommand *)m_commands.GetFirst()->GetData();
|
||||
wxString redoCommandName(redoCommand->GetName());
|
||||
if (redoCommandName.empty()) redoCommandName = _("Unnamed command");
|
||||
buf = wxString(_("&Redo ")) + redoCommandName + m_redoAccelerator;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
void wxCommandProcessor::ClearCommands()
|
||||
{
|
||||
wxList::compatibility_iterator node = m_commands.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
wxCommand *command = (wxCommand *)node->GetData();
|
||||
delete command;
|
||||
m_commands.Erase(node);
|
||||
node = m_commands.GetFirst();
|
||||
}
|
||||
|
||||
m_currentCommand = wxList::compatibility_iterator();
|
||||
m_lastSavedCommand = wxList::compatibility_iterator();
|
||||
}
|
||||
|
||||
|
||||
|
1314
Externals/wxWidgets/src/common/cmndata.cpp
vendored
1314
Externals/wxWidgets/src/common/cmndata.cpp
vendored
File diff suppressed because it is too large
Load Diff
252
Externals/wxWidgets/src/common/colourcmn.cpp
vendored
252
Externals/wxWidgets/src/common/colourcmn.cpp
vendored
@ -1,126 +1,126 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/colourcmn.cpp
|
||||
// Purpose: wxColourBase implementation
|
||||
// Author: Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 20/4/2006
|
||||
// RCS-ID: $Id: colourcmn.cpp 41538 2006-09-30 20:45:15Z RR $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/colour.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#endif
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT)
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// wxString <-> wxColour conversions
|
||||
// ============================================================================
|
||||
|
||||
bool wxColourBase::FromString(const wxChar *str)
|
||||
{
|
||||
if ( str == NULL || str[0] == wxT('\0'))
|
||||
return false; // invalid or empty string
|
||||
|
||||
if ( wxStrncmp(str, wxT("RGB"), 3) == 0 ||
|
||||
wxStrncmp(str, wxT("rgb"), 3) == 0 )
|
||||
{
|
||||
// CSS-like RGB specification
|
||||
// according to http://www.w3.org/TR/REC-CSS2/syndata.html#color-units
|
||||
// values outside 0-255 range are allowed but should be clipped
|
||||
int red, green, blue;
|
||||
if (wxSscanf(&str[3], wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
|
||||
return false;
|
||||
|
||||
Set((unsigned char)wxClip(red,0,255),
|
||||
(unsigned char)wxClip(green,0,255),
|
||||
(unsigned char)wxClip(blue,0,255));
|
||||
}
|
||||
else if ( str[0] == wxT('#') && wxStrlen(str) == 7 )
|
||||
{
|
||||
// hexadecimal prefixed with # (HTML syntax)
|
||||
unsigned long tmp;
|
||||
if (wxSscanf(&str[1], wxT("%lx"), &tmp) != 1)
|
||||
return false;
|
||||
|
||||
Set((unsigned char)(tmp >> 16),
|
||||
(unsigned char)(tmp >> 8),
|
||||
(unsigned char)tmp);
|
||||
}
|
||||
else if (wxTheColourDatabase) // a colour name ?
|
||||
{
|
||||
// we can't do
|
||||
// *this = wxTheColourDatabase->Find(str)
|
||||
// because this place can be called from constructor
|
||||
// and 'this' could not be available yet
|
||||
wxColour clr = wxTheColourDatabase->Find(str);
|
||||
if (clr.Ok())
|
||||
Set((unsigned char)clr.Red(),
|
||||
(unsigned char)clr.Green(),
|
||||
(unsigned char)clr.Blue());
|
||||
}
|
||||
|
||||
if (Ok())
|
||||
return true;
|
||||
|
||||
wxLogDebug(wxT("wxColour::Set - couldn't set to colour string '%s'"), str);
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString wxColourBase::GetAsString(long flags) const
|
||||
{
|
||||
wxString colName;
|
||||
|
||||
if (flags & wxC2S_NAME)
|
||||
colName = wxTheColourDatabase->FindName((const wxColour &)(*this)).MakeLower();
|
||||
|
||||
if ( colName.empty() && (flags & wxC2S_CSS_SYNTAX) )
|
||||
{
|
||||
// no name for this colour; return it in CSS syntax
|
||||
colName.Printf(wxT("rgb(%d, %d, %d)"),
|
||||
Red(), Green(), Blue());
|
||||
}
|
||||
else if ( colName.empty() && (flags & wxC2S_HTML_SYNTAX) )
|
||||
{
|
||||
// no name for this colour; return it in HTML syntax
|
||||
colName.Printf(wxT("#%02X%02X%02X"),
|
||||
Red(), Green(), Blue());
|
||||
}
|
||||
|
||||
// this function always returns a non-empty string
|
||||
wxASSERT_MSG(!colName.empty(),
|
||||
wxT("Invalid wxColour -> wxString conversion flags"));
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// static
|
||||
wxColour wxColourBase::CreateByName(const wxString& name)
|
||||
{
|
||||
return wxColour(name);
|
||||
}
|
||||
|
||||
void wxColourBase::InitFromName(const wxString& col)
|
||||
{
|
||||
Set(col);
|
||||
}
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/colourcmn.cpp
|
||||
// Purpose: wxColourBase implementation
|
||||
// Author: Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 20/4/2006
|
||||
// RCS-ID: $Id: colourcmn.cpp 41538 2006-09-30 20:45:15Z RR $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/colour.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#endif
|
||||
|
||||
#if wxUSE_VARIANT
|
||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT)
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// wxString <-> wxColour conversions
|
||||
// ============================================================================
|
||||
|
||||
bool wxColourBase::FromString(const wxChar *str)
|
||||
{
|
||||
if ( str == NULL || str[0] == wxT('\0'))
|
||||
return false; // invalid or empty string
|
||||
|
||||
if ( wxStrncmp(str, wxT("RGB"), 3) == 0 ||
|
||||
wxStrncmp(str, wxT("rgb"), 3) == 0 )
|
||||
{
|
||||
// CSS-like RGB specification
|
||||
// according to http://www.w3.org/TR/REC-CSS2/syndata.html#color-units
|
||||
// values outside 0-255 range are allowed but should be clipped
|
||||
int red, green, blue;
|
||||
if (wxSscanf(&str[3], wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
|
||||
return false;
|
||||
|
||||
Set((unsigned char)wxClip(red,0,255),
|
||||
(unsigned char)wxClip(green,0,255),
|
||||
(unsigned char)wxClip(blue,0,255));
|
||||
}
|
||||
else if ( str[0] == wxT('#') && wxStrlen(str) == 7 )
|
||||
{
|
||||
// hexadecimal prefixed with # (HTML syntax)
|
||||
unsigned long tmp;
|
||||
if (wxSscanf(&str[1], wxT("%lx"), &tmp) != 1)
|
||||
return false;
|
||||
|
||||
Set((unsigned char)(tmp >> 16),
|
||||
(unsigned char)(tmp >> 8),
|
||||
(unsigned char)tmp);
|
||||
}
|
||||
else if (wxTheColourDatabase) // a colour name ?
|
||||
{
|
||||
// we can't do
|
||||
// *this = wxTheColourDatabase->Find(str)
|
||||
// because this place can be called from constructor
|
||||
// and 'this' could not be available yet
|
||||
wxColour clr = wxTheColourDatabase->Find(str);
|
||||
if (clr.Ok())
|
||||
Set((unsigned char)clr.Red(),
|
||||
(unsigned char)clr.Green(),
|
||||
(unsigned char)clr.Blue());
|
||||
}
|
||||
|
||||
if (Ok())
|
||||
return true;
|
||||
|
||||
wxLogDebug(wxT("wxColour::Set - couldn't set to colour string '%s'"), str);
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString wxColourBase::GetAsString(long flags) const
|
||||
{
|
||||
wxString colName;
|
||||
|
||||
if (flags & wxC2S_NAME)
|
||||
colName = wxTheColourDatabase->FindName((const wxColour &)(*this)).MakeLower();
|
||||
|
||||
if ( colName.empty() && (flags & wxC2S_CSS_SYNTAX) )
|
||||
{
|
||||
// no name for this colour; return it in CSS syntax
|
||||
colName.Printf(wxT("rgb(%d, %d, %d)"),
|
||||
Red(), Green(), Blue());
|
||||
}
|
||||
else if ( colName.empty() && (flags & wxC2S_HTML_SYNTAX) )
|
||||
{
|
||||
// no name for this colour; return it in HTML syntax
|
||||
colName.Printf(wxT("#%02X%02X%02X"),
|
||||
Red(), Green(), Blue());
|
||||
}
|
||||
|
||||
// this function always returns a non-empty string
|
||||
wxASSERT_MSG(!colName.empty(),
|
||||
wxT("Invalid wxColour -> wxString conversion flags"));
|
||||
|
||||
return colName;
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// static
|
||||
wxColour wxColourBase::CreateByName(const wxString& name)
|
||||
{
|
||||
return wxColour(name);
|
||||
}
|
||||
|
||||
void wxColourBase::InitFromName(const wxString& col)
|
||||
{
|
||||
Set(col);
|
||||
}
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
4604
Externals/wxWidgets/src/common/combocmn.cpp
vendored
4604
Externals/wxWidgets/src/common/combocmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
980
Externals/wxWidgets/src/common/config.cpp
vendored
980
Externals/wxWidgets/src/common/config.cpp
vendored
@ -1,490 +1,490 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/config.cpp
|
||||
// Purpose: implementation of wxConfigBase class
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 07.04.98
|
||||
// RCS-ID: $Id: config.cpp 50711 2007-12-15 02:57:58Z VZ $
|
||||
// Copyright: (c) 1997 Karsten Ballueder Ballueder@usa.net
|
||||
// Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif //__BORLANDC__
|
||||
|
||||
#ifndef wxUSE_CONFIG_NATIVE
|
||||
#define wxUSE_CONFIG_NATIVE 1
|
||||
#endif
|
||||
|
||||
#include "wx/config.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/arrstr.h"
|
||||
#include "wx/math.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#if wxUSE_CONFIG && ((wxUSE_FILE && wxUSE_TEXTFILE) || wxUSE_CONFIG_NATIVE)
|
||||
|
||||
#include "wx/file.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h> // for INT_MAX
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// global and class static variables
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxConfigBase *wxConfigBase::ms_pConfig = NULL;
|
||||
bool wxConfigBase::ms_bAutoCreate = true;
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Not all args will always be used by derived classes, but including them all
|
||||
// in each class ensures compatibility.
|
||||
wxConfigBase::wxConfigBase(const wxString& appName,
|
||||
const wxString& vendorName,
|
||||
const wxString& WXUNUSED(localFilename),
|
||||
const wxString& WXUNUSED(globalFilename),
|
||||
long style)
|
||||
: m_appName(appName), m_vendorName(vendorName), m_style(style)
|
||||
{
|
||||
m_bExpandEnvVars = true;
|
||||
m_bRecordDefaults = false;
|
||||
}
|
||||
|
||||
wxConfigBase::~wxConfigBase()
|
||||
{
|
||||
// required here for Darwin
|
||||
}
|
||||
|
||||
wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
|
||||
{
|
||||
wxConfigBase *pOld = ms_pConfig;
|
||||
ms_pConfig = pConfig;
|
||||
return pOld;
|
||||
}
|
||||
|
||||
wxConfigBase *wxConfigBase::Create()
|
||||
{
|
||||
if ( ms_bAutoCreate && ms_pConfig == NULL ) {
|
||||
ms_pConfig =
|
||||
#if defined(__WXMSW__) && wxUSE_CONFIG_NATIVE
|
||||
new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
|
||||
#elif defined(__WXPALMOS__) && wxUSE_CONFIG_NATIVE
|
||||
new wxPrefConfig(wxTheApp->GetAppName());
|
||||
#else // either we're under Unix or wish to use files even under Windows
|
||||
new wxFileConfig(wxTheApp->GetAppName());
|
||||
#endif
|
||||
}
|
||||
|
||||
return ms_pConfig;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase reading entries
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// implement both Read() overloads for the given type in terms of DoRead()
|
||||
#define IMPLEMENT_READ_FOR_TYPE(name, type, deftype, extra) \
|
||||
bool wxConfigBase::Read(const wxString& key, type *val) const \
|
||||
{ \
|
||||
wxCHECK_MSG( val, false, _T("wxConfig::Read(): NULL parameter") ); \
|
||||
\
|
||||
if ( !DoRead##name(key, val) ) \
|
||||
return false; \
|
||||
\
|
||||
*val = extra(*val); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
bool wxConfigBase::Read(const wxString& key, \
|
||||
type *val, \
|
||||
deftype defVal) const \
|
||||
{ \
|
||||
wxCHECK_MSG( val, false, _T("wxConfig::Read(): NULL parameter") ); \
|
||||
\
|
||||
bool read = DoRead##name(key, val); \
|
||||
if ( !read ) \
|
||||
{ \
|
||||
if ( IsRecordingDefaults() ) \
|
||||
{ \
|
||||
((wxConfigBase *)this)->DoWrite##name(key, defVal); \
|
||||
} \
|
||||
\
|
||||
*val = defVal; \
|
||||
} \
|
||||
\
|
||||
*val = extra(*val); \
|
||||
\
|
||||
return read; \
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_READ_FOR_TYPE(String, wxString, const wxString&, ExpandEnvVars)
|
||||
IMPLEMENT_READ_FOR_TYPE(Long, long, long, long)
|
||||
IMPLEMENT_READ_FOR_TYPE(Int, int, int, int)
|
||||
IMPLEMENT_READ_FOR_TYPE(Double, double, double, double)
|
||||
IMPLEMENT_READ_FOR_TYPE(Bool, bool, bool, bool)
|
||||
|
||||
#undef IMPLEMENT_READ_FOR_TYPE
|
||||
|
||||
// the DoReadXXX() for the other types have implementation in the base class
|
||||
// but can be overridden in the derived ones
|
||||
bool wxConfigBase::DoReadInt(const wxString& key, int *pi) const
|
||||
{
|
||||
wxCHECK_MSG( pi, false, _T("wxConfig::Read(): NULL parameter") );
|
||||
|
||||
long l;
|
||||
if ( !DoReadLong(key, &l) )
|
||||
return false;
|
||||
|
||||
wxASSERT_MSG( l < INT_MAX, _T("overflow in wxConfig::DoReadInt") );
|
||||
|
||||
*pi = (int)l;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoReadBool(const wxString& key, bool* val) const
|
||||
{
|
||||
wxCHECK_MSG( val, false, _T("wxConfig::Read(): NULL parameter") );
|
||||
|
||||
long l;
|
||||
if ( !DoReadLong(key, &l) )
|
||||
return false;
|
||||
|
||||
wxASSERT_MSG( l == 0 || l == 1, _T("bad bool value in wxConfig::DoReadInt") );
|
||||
|
||||
*val = l != 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoReadDouble(const wxString& key, double* val) const
|
||||
{
|
||||
wxString str;
|
||||
if ( Read(key, &str) )
|
||||
{
|
||||
return str.ToDouble(val);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// string reading helper
|
||||
wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
|
||||
{
|
||||
wxString tmp; // Required for BC++
|
||||
if (IsExpandingEnvVars())
|
||||
tmp = wxExpandEnvVars(str);
|
||||
else
|
||||
tmp = str;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase writing
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxConfigBase::DoWriteDouble(const wxString& key, double val)
|
||||
{
|
||||
return DoWriteString(key, wxString::Format(_T("%g"), val));
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoWriteInt(const wxString& key, int value)
|
||||
{
|
||||
return DoWriteLong(key, (long)value);
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoWriteBool(const wxString& key, bool value)
|
||||
{
|
||||
return DoWriteLong(key, value ? 1l : 0l);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigPathChanger
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
|
||||
const wxString& strEntry)
|
||||
{
|
||||
m_bChanged = false;
|
||||
m_pContainer = (wxConfigBase *)pContainer;
|
||||
|
||||
// the path is everything which precedes the last slash
|
||||
wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR);
|
||||
|
||||
// except in the special case of "/keyname" when there is nothing before "/"
|
||||
if ( strPath.empty() &&
|
||||
((!strEntry.empty()) && strEntry[0] == wxCONFIG_PATH_SEPARATOR) )
|
||||
{
|
||||
strPath = wxCONFIG_PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
if ( !strPath.empty() )
|
||||
{
|
||||
if ( m_pContainer->GetPath() != strPath )
|
||||
{
|
||||
// we do change the path so restore it later
|
||||
m_bChanged = true;
|
||||
|
||||
/* JACS: work around a memory bug that causes an assert
|
||||
when using wxRegConfig, related to reference-counting.
|
||||
Can be reproduced by removing (const wxChar*) below and
|
||||
adding the following code to the config sample OnInit under
|
||||
Windows:
|
||||
|
||||
pConfig->SetPath(wxT("MySettings"));
|
||||
pConfig->SetPath(wxT(".."));
|
||||
int value;
|
||||
pConfig->Read(_T("MainWindowX"), & value);
|
||||
*/
|
||||
m_strOldPath = (const wxChar*) m_pContainer->GetPath();
|
||||
if ( *m_strOldPath.c_str() != wxCONFIG_PATH_SEPARATOR )
|
||||
m_strOldPath += wxCONFIG_PATH_SEPARATOR;
|
||||
m_pContainer->SetPath(strPath);
|
||||
}
|
||||
|
||||
// in any case, use the just the name, not full path
|
||||
m_strName = strEntry.AfterLast(wxCONFIG_PATH_SEPARATOR);
|
||||
}
|
||||
else {
|
||||
// it's a name only, without path - nothing to do
|
||||
m_strName = strEntry;
|
||||
}
|
||||
}
|
||||
|
||||
void wxConfigPathChanger::UpdateIfDeleted()
|
||||
{
|
||||
// we don't have to do anything at all if we didn't change the path
|
||||
if ( !m_bChanged )
|
||||
return;
|
||||
|
||||
// find the deepest still existing parent path of the original path
|
||||
while ( !m_pContainer->HasGroup(m_strOldPath) )
|
||||
{
|
||||
m_strOldPath = m_strOldPath.BeforeLast(wxCONFIG_PATH_SEPARATOR);
|
||||
if ( m_strOldPath.empty() )
|
||||
m_strOldPath = wxCONFIG_PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
wxConfigPathChanger::~wxConfigPathChanger()
|
||||
{
|
||||
// only restore path if it was changed
|
||||
if ( m_bChanged ) {
|
||||
m_pContainer->SetPath(m_strOldPath);
|
||||
}
|
||||
}
|
||||
|
||||
// this is a wxConfig method but it's mainly used with wxConfigPathChanger
|
||||
/* static */
|
||||
wxString wxConfigBase::RemoveTrailingSeparator(const wxString& key)
|
||||
{
|
||||
wxString path(key);
|
||||
|
||||
// don't remove the only separator from a root group path!
|
||||
while ( path.length() > 1 )
|
||||
{
|
||||
if ( *path.rbegin() != wxCONFIG_PATH_SEPARATOR )
|
||||
break;
|
||||
|
||||
path.erase(path.end() - 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif // wxUSE_CONFIG
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// static & global functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// understands both Unix and Windows (but only under Windows) environment
|
||||
// variables expansion: i.e. $var, $(var) and ${var} are always understood
|
||||
// and in addition under Windows %var% is also.
|
||||
|
||||
// don't change the values the enum elements: they must be equal
|
||||
// to the matching [closing] delimiter.
|
||||
enum Bracket
|
||||
{
|
||||
Bracket_None,
|
||||
Bracket_Normal = ')',
|
||||
Bracket_Curly = '}',
|
||||
#ifdef __WXMSW__
|
||||
Bracket_Windows = '%', // yeah, Windows people are a bit strange ;-)
|
||||
#endif
|
||||
Bracket_Max
|
||||
};
|
||||
|
||||
wxString wxExpandEnvVars(const wxString& str)
|
||||
{
|
||||
wxString strResult;
|
||||
strResult.Alloc(str.length());
|
||||
|
||||
size_t m;
|
||||
for ( size_t n = 0; n < str.length(); n++ ) {
|
||||
switch ( str[n] ) {
|
||||
#ifdef __WXMSW__
|
||||
case wxT('%'):
|
||||
#endif //WINDOWS
|
||||
case wxT('$'):
|
||||
{
|
||||
Bracket bracket;
|
||||
#ifdef __WXMSW__
|
||||
if ( str[n] == wxT('%') )
|
||||
bracket = Bracket_Windows;
|
||||
else
|
||||
#endif //WINDOWS
|
||||
if ( n == str.length() - 1 ) {
|
||||
bracket = Bracket_None;
|
||||
}
|
||||
else {
|
||||
switch ( str[n + 1] ) {
|
||||
case wxT('('):
|
||||
bracket = Bracket_Normal;
|
||||
n++; // skip the bracket
|
||||
break;
|
||||
|
||||
case wxT('{'):
|
||||
bracket = Bracket_Curly;
|
||||
n++; // skip the bracket
|
||||
break;
|
||||
|
||||
default:
|
||||
bracket = Bracket_None;
|
||||
}
|
||||
}
|
||||
|
||||
m = n + 1;
|
||||
|
||||
while ( m < str.length() && (wxIsalnum(str[m]) || str[m] == wxT('_')) )
|
||||
m++;
|
||||
|
||||
wxString strVarName(str.c_str() + n + 1, m - n - 1);
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
const wxChar *pszValue = NULL;
|
||||
#else
|
||||
// NB: use wxGetEnv instead of wxGetenv as otherwise variables
|
||||
// set through wxSetEnv may not be read correctly!
|
||||
const wxChar *pszValue = NULL;
|
||||
wxString tmp;
|
||||
if (wxGetEnv(strVarName, &tmp))
|
||||
pszValue = tmp;
|
||||
#endif
|
||||
if ( pszValue != NULL ) {
|
||||
strResult += pszValue;
|
||||
}
|
||||
else {
|
||||
// variable doesn't exist => don't change anything
|
||||
#ifdef __WXMSW__
|
||||
if ( bracket != Bracket_Windows )
|
||||
#endif
|
||||
if ( bracket != Bracket_None )
|
||||
strResult << str[n - 1];
|
||||
strResult << str[n] << strVarName;
|
||||
}
|
||||
|
||||
// check the closing bracket
|
||||
if ( bracket != Bracket_None ) {
|
||||
if ( m == str.length() || str[m] != (wxChar)bracket ) {
|
||||
// under MSW it's common to have '%' characters in the registry
|
||||
// and it's annoying to have warnings about them each time, so
|
||||
// ignroe them silently if they are not used for env vars
|
||||
//
|
||||
// under Unix, OTOH, this warning could be useful for the user to
|
||||
// understand why isn't the variable expanded as intended
|
||||
#ifndef __WXMSW__
|
||||
wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."),
|
||||
(char)bracket, (unsigned int) (m + 1), str.c_str());
|
||||
#endif // __WXMSW__
|
||||
}
|
||||
else {
|
||||
// skip closing bracket unless the variables wasn't expanded
|
||||
if ( pszValue == NULL )
|
||||
strResult << (wxChar)bracket;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
|
||||
n = m - 1; // skip variable name
|
||||
}
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
// backslash can be used to suppress special meaning of % and $
|
||||
if ( n != str.length() - 1 &&
|
||||
(str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) {
|
||||
strResult += str[++n];
|
||||
|
||||
break;
|
||||
}
|
||||
//else: fall through
|
||||
|
||||
default:
|
||||
strResult += str[n];
|
||||
}
|
||||
}
|
||||
|
||||
return strResult;
|
||||
}
|
||||
|
||||
// this function is used to properly interpret '..' in path
|
||||
void wxSplitPath(wxArrayString& aParts, const wxChar *sz)
|
||||
{
|
||||
aParts.clear();
|
||||
|
||||
wxString strCurrent;
|
||||
const wxChar *pc = sz;
|
||||
for ( ;; ) {
|
||||
if ( *pc == wxT('\0') || *pc == wxCONFIG_PATH_SEPARATOR ) {
|
||||
if ( strCurrent == wxT(".") ) {
|
||||
// ignore
|
||||
}
|
||||
else if ( strCurrent == wxT("..") ) {
|
||||
// go up one level
|
||||
if ( aParts.size() == 0 )
|
||||
wxLogWarning(_("'%s' has extra '..', ignored."), sz);
|
||||
else
|
||||
aParts.erase(aParts.end() - 1);
|
||||
|
||||
strCurrent.Empty();
|
||||
}
|
||||
else if ( !strCurrent.empty() ) {
|
||||
aParts.push_back(strCurrent);
|
||||
strCurrent.Empty();
|
||||
}
|
||||
//else:
|
||||
// could log an error here, but we prefer to ignore extra '/'
|
||||
|
||||
if ( *pc == wxT('\0') )
|
||||
break;
|
||||
}
|
||||
else
|
||||
strCurrent += *pc;
|
||||
|
||||
pc++;
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/config.cpp
|
||||
// Purpose: implementation of wxConfigBase class
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 07.04.98
|
||||
// RCS-ID: $Id: config.cpp 50711 2007-12-15 02:57:58Z VZ $
|
||||
// Copyright: (c) 1997 Karsten Ballueder Ballueder@usa.net
|
||||
// Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif //__BORLANDC__
|
||||
|
||||
#ifndef wxUSE_CONFIG_NATIVE
|
||||
#define wxUSE_CONFIG_NATIVE 1
|
||||
#endif
|
||||
|
||||
#include "wx/config.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/arrstr.h"
|
||||
#include "wx/math.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#if wxUSE_CONFIG && ((wxUSE_FILE && wxUSE_TEXTFILE) || wxUSE_CONFIG_NATIVE)
|
||||
|
||||
#include "wx/file.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h> // for INT_MAX
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// global and class static variables
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxConfigBase *wxConfigBase::ms_pConfig = NULL;
|
||||
bool wxConfigBase::ms_bAutoCreate = true;
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Not all args will always be used by derived classes, but including them all
|
||||
// in each class ensures compatibility.
|
||||
wxConfigBase::wxConfigBase(const wxString& appName,
|
||||
const wxString& vendorName,
|
||||
const wxString& WXUNUSED(localFilename),
|
||||
const wxString& WXUNUSED(globalFilename),
|
||||
long style)
|
||||
: m_appName(appName), m_vendorName(vendorName), m_style(style)
|
||||
{
|
||||
m_bExpandEnvVars = true;
|
||||
m_bRecordDefaults = false;
|
||||
}
|
||||
|
||||
wxConfigBase::~wxConfigBase()
|
||||
{
|
||||
// required here for Darwin
|
||||
}
|
||||
|
||||
wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
|
||||
{
|
||||
wxConfigBase *pOld = ms_pConfig;
|
||||
ms_pConfig = pConfig;
|
||||
return pOld;
|
||||
}
|
||||
|
||||
wxConfigBase *wxConfigBase::Create()
|
||||
{
|
||||
if ( ms_bAutoCreate && ms_pConfig == NULL ) {
|
||||
ms_pConfig =
|
||||
#if defined(__WXMSW__) && wxUSE_CONFIG_NATIVE
|
||||
new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
|
||||
#elif defined(__WXPALMOS__) && wxUSE_CONFIG_NATIVE
|
||||
new wxPrefConfig(wxTheApp->GetAppName());
|
||||
#else // either we're under Unix or wish to use files even under Windows
|
||||
new wxFileConfig(wxTheApp->GetAppName());
|
||||
#endif
|
||||
}
|
||||
|
||||
return ms_pConfig;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase reading entries
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// implement both Read() overloads for the given type in terms of DoRead()
|
||||
#define IMPLEMENT_READ_FOR_TYPE(name, type, deftype, extra) \
|
||||
bool wxConfigBase::Read(const wxString& key, type *val) const \
|
||||
{ \
|
||||
wxCHECK_MSG( val, false, _T("wxConfig::Read(): NULL parameter") ); \
|
||||
\
|
||||
if ( !DoRead##name(key, val) ) \
|
||||
return false; \
|
||||
\
|
||||
*val = extra(*val); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
bool wxConfigBase::Read(const wxString& key, \
|
||||
type *val, \
|
||||
deftype defVal) const \
|
||||
{ \
|
||||
wxCHECK_MSG( val, false, _T("wxConfig::Read(): NULL parameter") ); \
|
||||
\
|
||||
bool read = DoRead##name(key, val); \
|
||||
if ( !read ) \
|
||||
{ \
|
||||
if ( IsRecordingDefaults() ) \
|
||||
{ \
|
||||
((wxConfigBase *)this)->DoWrite##name(key, defVal); \
|
||||
} \
|
||||
\
|
||||
*val = defVal; \
|
||||
} \
|
||||
\
|
||||
*val = extra(*val); \
|
||||
\
|
||||
return read; \
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_READ_FOR_TYPE(String, wxString, const wxString&, ExpandEnvVars)
|
||||
IMPLEMENT_READ_FOR_TYPE(Long, long, long, long)
|
||||
IMPLEMENT_READ_FOR_TYPE(Int, int, int, int)
|
||||
IMPLEMENT_READ_FOR_TYPE(Double, double, double, double)
|
||||
IMPLEMENT_READ_FOR_TYPE(Bool, bool, bool, bool)
|
||||
|
||||
#undef IMPLEMENT_READ_FOR_TYPE
|
||||
|
||||
// the DoReadXXX() for the other types have implementation in the base class
|
||||
// but can be overridden in the derived ones
|
||||
bool wxConfigBase::DoReadInt(const wxString& key, int *pi) const
|
||||
{
|
||||
wxCHECK_MSG( pi, false, _T("wxConfig::Read(): NULL parameter") );
|
||||
|
||||
long l;
|
||||
if ( !DoReadLong(key, &l) )
|
||||
return false;
|
||||
|
||||
wxASSERT_MSG( l < INT_MAX, _T("overflow in wxConfig::DoReadInt") );
|
||||
|
||||
*pi = (int)l;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoReadBool(const wxString& key, bool* val) const
|
||||
{
|
||||
wxCHECK_MSG( val, false, _T("wxConfig::Read(): NULL parameter") );
|
||||
|
||||
long l;
|
||||
if ( !DoReadLong(key, &l) )
|
||||
return false;
|
||||
|
||||
wxASSERT_MSG( l == 0 || l == 1, _T("bad bool value in wxConfig::DoReadInt") );
|
||||
|
||||
*val = l != 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoReadDouble(const wxString& key, double* val) const
|
||||
{
|
||||
wxString str;
|
||||
if ( Read(key, &str) )
|
||||
{
|
||||
return str.ToDouble(val);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// string reading helper
|
||||
wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
|
||||
{
|
||||
wxString tmp; // Required for BC++
|
||||
if (IsExpandingEnvVars())
|
||||
tmp = wxExpandEnvVars(str);
|
||||
else
|
||||
tmp = str;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase writing
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxConfigBase::DoWriteDouble(const wxString& key, double val)
|
||||
{
|
||||
return DoWriteString(key, wxString::Format(_T("%g"), val));
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoWriteInt(const wxString& key, int value)
|
||||
{
|
||||
return DoWriteLong(key, (long)value);
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoWriteBool(const wxString& key, bool value)
|
||||
{
|
||||
return DoWriteLong(key, value ? 1l : 0l);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigPathChanger
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer,
|
||||
const wxString& strEntry)
|
||||
{
|
||||
m_bChanged = false;
|
||||
m_pContainer = (wxConfigBase *)pContainer;
|
||||
|
||||
// the path is everything which precedes the last slash
|
||||
wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR);
|
||||
|
||||
// except in the special case of "/keyname" when there is nothing before "/"
|
||||
if ( strPath.empty() &&
|
||||
((!strEntry.empty()) && strEntry[0] == wxCONFIG_PATH_SEPARATOR) )
|
||||
{
|
||||
strPath = wxCONFIG_PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
if ( !strPath.empty() )
|
||||
{
|
||||
if ( m_pContainer->GetPath() != strPath )
|
||||
{
|
||||
// we do change the path so restore it later
|
||||
m_bChanged = true;
|
||||
|
||||
/* JACS: work around a memory bug that causes an assert
|
||||
when using wxRegConfig, related to reference-counting.
|
||||
Can be reproduced by removing (const wxChar*) below and
|
||||
adding the following code to the config sample OnInit under
|
||||
Windows:
|
||||
|
||||
pConfig->SetPath(wxT("MySettings"));
|
||||
pConfig->SetPath(wxT(".."));
|
||||
int value;
|
||||
pConfig->Read(_T("MainWindowX"), & value);
|
||||
*/
|
||||
m_strOldPath = (const wxChar*) m_pContainer->GetPath();
|
||||
if ( *m_strOldPath.c_str() != wxCONFIG_PATH_SEPARATOR )
|
||||
m_strOldPath += wxCONFIG_PATH_SEPARATOR;
|
||||
m_pContainer->SetPath(strPath);
|
||||
}
|
||||
|
||||
// in any case, use the just the name, not full path
|
||||
m_strName = strEntry.AfterLast(wxCONFIG_PATH_SEPARATOR);
|
||||
}
|
||||
else {
|
||||
// it's a name only, without path - nothing to do
|
||||
m_strName = strEntry;
|
||||
}
|
||||
}
|
||||
|
||||
void wxConfigPathChanger::UpdateIfDeleted()
|
||||
{
|
||||
// we don't have to do anything at all if we didn't change the path
|
||||
if ( !m_bChanged )
|
||||
return;
|
||||
|
||||
// find the deepest still existing parent path of the original path
|
||||
while ( !m_pContainer->HasGroup(m_strOldPath) )
|
||||
{
|
||||
m_strOldPath = m_strOldPath.BeforeLast(wxCONFIG_PATH_SEPARATOR);
|
||||
if ( m_strOldPath.empty() )
|
||||
m_strOldPath = wxCONFIG_PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
wxConfigPathChanger::~wxConfigPathChanger()
|
||||
{
|
||||
// only restore path if it was changed
|
||||
if ( m_bChanged ) {
|
||||
m_pContainer->SetPath(m_strOldPath);
|
||||
}
|
||||
}
|
||||
|
||||
// this is a wxConfig method but it's mainly used with wxConfigPathChanger
|
||||
/* static */
|
||||
wxString wxConfigBase::RemoveTrailingSeparator(const wxString& key)
|
||||
{
|
||||
wxString path(key);
|
||||
|
||||
// don't remove the only separator from a root group path!
|
||||
while ( path.length() > 1 )
|
||||
{
|
||||
if ( *path.rbegin() != wxCONFIG_PATH_SEPARATOR )
|
||||
break;
|
||||
|
||||
path.erase(path.end() - 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif // wxUSE_CONFIG
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// static & global functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// understands both Unix and Windows (but only under Windows) environment
|
||||
// variables expansion: i.e. $var, $(var) and ${var} are always understood
|
||||
// and in addition under Windows %var% is also.
|
||||
|
||||
// don't change the values the enum elements: they must be equal
|
||||
// to the matching [closing] delimiter.
|
||||
enum Bracket
|
||||
{
|
||||
Bracket_None,
|
||||
Bracket_Normal = ')',
|
||||
Bracket_Curly = '}',
|
||||
#ifdef __WXMSW__
|
||||
Bracket_Windows = '%', // yeah, Windows people are a bit strange ;-)
|
||||
#endif
|
||||
Bracket_Max
|
||||
};
|
||||
|
||||
wxString wxExpandEnvVars(const wxString& str)
|
||||
{
|
||||
wxString strResult;
|
||||
strResult.Alloc(str.length());
|
||||
|
||||
size_t m;
|
||||
for ( size_t n = 0; n < str.length(); n++ ) {
|
||||
switch ( str[n] ) {
|
||||
#ifdef __WXMSW__
|
||||
case wxT('%'):
|
||||
#endif //WINDOWS
|
||||
case wxT('$'):
|
||||
{
|
||||
Bracket bracket;
|
||||
#ifdef __WXMSW__
|
||||
if ( str[n] == wxT('%') )
|
||||
bracket = Bracket_Windows;
|
||||
else
|
||||
#endif //WINDOWS
|
||||
if ( n == str.length() - 1 ) {
|
||||
bracket = Bracket_None;
|
||||
}
|
||||
else {
|
||||
switch ( str[n + 1] ) {
|
||||
case wxT('('):
|
||||
bracket = Bracket_Normal;
|
||||
n++; // skip the bracket
|
||||
break;
|
||||
|
||||
case wxT('{'):
|
||||
bracket = Bracket_Curly;
|
||||
n++; // skip the bracket
|
||||
break;
|
||||
|
||||
default:
|
||||
bracket = Bracket_None;
|
||||
}
|
||||
}
|
||||
|
||||
m = n + 1;
|
||||
|
||||
while ( m < str.length() && (wxIsalnum(str[m]) || str[m] == wxT('_')) )
|
||||
m++;
|
||||
|
||||
wxString strVarName(str.c_str() + n + 1, m - n - 1);
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
const wxChar *pszValue = NULL;
|
||||
#else
|
||||
// NB: use wxGetEnv instead of wxGetenv as otherwise variables
|
||||
// set through wxSetEnv may not be read correctly!
|
||||
const wxChar *pszValue = NULL;
|
||||
wxString tmp;
|
||||
if (wxGetEnv(strVarName, &tmp))
|
||||
pszValue = tmp;
|
||||
#endif
|
||||
if ( pszValue != NULL ) {
|
||||
strResult += pszValue;
|
||||
}
|
||||
else {
|
||||
// variable doesn't exist => don't change anything
|
||||
#ifdef __WXMSW__
|
||||
if ( bracket != Bracket_Windows )
|
||||
#endif
|
||||
if ( bracket != Bracket_None )
|
||||
strResult << str[n - 1];
|
||||
strResult << str[n] << strVarName;
|
||||
}
|
||||
|
||||
// check the closing bracket
|
||||
if ( bracket != Bracket_None ) {
|
||||
if ( m == str.length() || str[m] != (wxChar)bracket ) {
|
||||
// under MSW it's common to have '%' characters in the registry
|
||||
// and it's annoying to have warnings about them each time, so
|
||||
// ignroe them silently if they are not used for env vars
|
||||
//
|
||||
// under Unix, OTOH, this warning could be useful for the user to
|
||||
// understand why isn't the variable expanded as intended
|
||||
#ifndef __WXMSW__
|
||||
wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."),
|
||||
(char)bracket, (unsigned int) (m + 1), str.c_str());
|
||||
#endif // __WXMSW__
|
||||
}
|
||||
else {
|
||||
// skip closing bracket unless the variables wasn't expanded
|
||||
if ( pszValue == NULL )
|
||||
strResult << (wxChar)bracket;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
|
||||
n = m - 1; // skip variable name
|
||||
}
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
// backslash can be used to suppress special meaning of % and $
|
||||
if ( n != str.length() - 1 &&
|
||||
(str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) {
|
||||
strResult += str[++n];
|
||||
|
||||
break;
|
||||
}
|
||||
//else: fall through
|
||||
|
||||
default:
|
||||
strResult += str[n];
|
||||
}
|
||||
}
|
||||
|
||||
return strResult;
|
||||
}
|
||||
|
||||
// this function is used to properly interpret '..' in path
|
||||
void wxSplitPath(wxArrayString& aParts, const wxChar *sz)
|
||||
{
|
||||
aParts.clear();
|
||||
|
||||
wxString strCurrent;
|
||||
const wxChar *pc = sz;
|
||||
for ( ;; ) {
|
||||
if ( *pc == wxT('\0') || *pc == wxCONFIG_PATH_SEPARATOR ) {
|
||||
if ( strCurrent == wxT(".") ) {
|
||||
// ignore
|
||||
}
|
||||
else if ( strCurrent == wxT("..") ) {
|
||||
// go up one level
|
||||
if ( aParts.size() == 0 )
|
||||
wxLogWarning(_("'%s' has extra '..', ignored."), sz);
|
||||
else
|
||||
aParts.erase(aParts.end() - 1);
|
||||
|
||||
strCurrent.Empty();
|
||||
}
|
||||
else if ( !strCurrent.empty() ) {
|
||||
aParts.push_back(strCurrent);
|
||||
strCurrent.Empty();
|
||||
}
|
||||
//else:
|
||||
// could log an error here, but we prefer to ignore extra '/'
|
||||
|
||||
if ( *pc == wxT('\0') )
|
||||
break;
|
||||
}
|
||||
else
|
||||
strCurrent += *pc;
|
||||
|
||||
pc++;
|
||||
}
|
||||
}
|
||||
|
1356
Externals/wxWidgets/src/common/containr.cpp
vendored
1356
Externals/wxWidgets/src/common/containr.cpp
vendored
File diff suppressed because it is too large
Load Diff
428
Externals/wxWidgets/src/common/convauto.cpp
vendored
428
Externals/wxWidgets/src/common/convauto.cpp
vendored
@ -1,214 +1,214 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/convauto.cpp
|
||||
// Purpose: implementation of wxConvAuto
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2006-04-04
|
||||
// RCS-ID: $Id: convauto.cpp 38570 2006-04-05 14:37:47Z VZ $
|
||||
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_WCHAR_T
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/convauto.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxConvAuto::BOMType wxConvAuto::DetectBOM(const char *src, size_t srcLen)
|
||||
{
|
||||
if ( srcLen < 2 )
|
||||
{
|
||||
// minimal BOM is 2 bytes so bail out immediately and simplify the code
|
||||
// below which wouldn't need to check for length for UTF-16 cases
|
||||
return BOM_None;
|
||||
}
|
||||
|
||||
// examine the buffer for BOM presence
|
||||
//
|
||||
// see http://www.unicode.org/faq/utf_bom.html#BOM
|
||||
switch ( *src++ )
|
||||
{
|
||||
case '\0':
|
||||
// could only be big endian UTF-32 (00 00 FE FF)
|
||||
if ( srcLen >= 4 &&
|
||||
src[0] == '\0' &&
|
||||
src[1] == '\xfe' &&
|
||||
src[2] == '\xff' )
|
||||
{
|
||||
return BOM_UTF32BE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\xfe':
|
||||
// could only be big endian UTF-16 (FE FF)
|
||||
if ( *src++ == '\xff' )
|
||||
{
|
||||
return BOM_UTF16BE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\xff':
|
||||
// could be either little endian UTF-16 or UTF-32, both start
|
||||
// with FF FE
|
||||
if ( *src++ == '\xfe' )
|
||||
{
|
||||
return srcLen >= 4 && src[0] == '\0' && src[1] == '\0'
|
||||
? BOM_UTF32LE
|
||||
: BOM_UTF16LE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\xef':
|
||||
// is this UTF-8 BOM (EF BB BF)?
|
||||
if ( srcLen >= 3 && src[0] == '\xbb' && src[1] == '\xbf' )
|
||||
{
|
||||
return BOM_UTF8;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return BOM_None;
|
||||
}
|
||||
|
||||
void wxConvAuto::InitFromBOM(BOMType bomType)
|
||||
{
|
||||
m_consumedBOM = false;
|
||||
|
||||
switch ( bomType )
|
||||
{
|
||||
case BOM_UTF32BE:
|
||||
m_conv = new wxMBConvUTF32BE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF32LE:
|
||||
m_conv = new wxMBConvUTF32LE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF16BE:
|
||||
m_conv = new wxMBConvUTF16BE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF16LE:
|
||||
m_conv = new wxMBConvUTF16LE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF8:
|
||||
m_conv = &wxConvUTF8;
|
||||
m_ownsConv = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected BOM type") );
|
||||
// fall through: still need to create something
|
||||
|
||||
case BOM_None:
|
||||
InitWithDefault();
|
||||
m_consumedBOM = true; // as there is nothing to consume
|
||||
}
|
||||
}
|
||||
|
||||
void wxConvAuto::SkipBOM(const char **src, size_t *len) const
|
||||
{
|
||||
int ofs;
|
||||
switch ( m_bomType )
|
||||
{
|
||||
case BOM_UTF32BE:
|
||||
case BOM_UTF32LE:
|
||||
ofs = 4;
|
||||
break;
|
||||
|
||||
case BOM_UTF16BE:
|
||||
case BOM_UTF16LE:
|
||||
ofs = 2;
|
||||
break;
|
||||
|
||||
case BOM_UTF8:
|
||||
ofs = 3;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected BOM type") );
|
||||
// fall through: still need to create something
|
||||
|
||||
case BOM_None:
|
||||
ofs = 0;
|
||||
}
|
||||
|
||||
*src += ofs;
|
||||
if ( *len != (size_t)-1 )
|
||||
*len -= ofs;
|
||||
}
|
||||
|
||||
void wxConvAuto::InitFromInput(const char **src, size_t *len)
|
||||
{
|
||||
m_bomType = DetectBOM(*src, *len);
|
||||
InitFromBOM(m_bomType);
|
||||
SkipBOM(src, len);
|
||||
}
|
||||
|
||||
size_t
|
||||
wxConvAuto::ToWChar(wchar_t *dst, size_t dstLen,
|
||||
const char *src, size_t srcLen) const
|
||||
{
|
||||
// we check BOM and create the appropriate conversion the first time we're
|
||||
// called but we also need to ensure that the BOM is skipped not only
|
||||
// during this initial call but also during the first call with non-NULL
|
||||
// dst as typically we're first called with NULL dst to calculate the
|
||||
// needed buffer size
|
||||
wxConvAuto *self = wx_const_cast(wxConvAuto *, this);
|
||||
if ( !m_conv )
|
||||
{
|
||||
self->InitFromInput(&src, &srcLen);
|
||||
if ( dst )
|
||||
self->m_consumedBOM = true;
|
||||
}
|
||||
|
||||
if ( !m_consumedBOM && dst )
|
||||
{
|
||||
self->m_consumedBOM = true;
|
||||
SkipBOM(&src, &srcLen);
|
||||
}
|
||||
|
||||
return m_conv->ToWChar(dst, dstLen, src, srcLen);
|
||||
}
|
||||
|
||||
size_t
|
||||
wxConvAuto::FromWChar(char *dst, size_t dstLen,
|
||||
const wchar_t *src, size_t srcLen) const
|
||||
{
|
||||
if ( !m_conv )
|
||||
{
|
||||
// default to UTF-8 for the multibyte output
|
||||
wx_const_cast(wxConvAuto *, this)->InitWithDefault();
|
||||
}
|
||||
|
||||
return m_conv->FromWChar(dst, dstLen, src, srcLen);
|
||||
}
|
||||
|
||||
#endif // wxUSE_WCHAR_T
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/convauto.cpp
|
||||
// Purpose: implementation of wxConvAuto
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2006-04-04
|
||||
// RCS-ID: $Id: convauto.cpp 38570 2006-04-05 14:37:47Z VZ $
|
||||
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_WCHAR_T
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/convauto.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxConvAuto::BOMType wxConvAuto::DetectBOM(const char *src, size_t srcLen)
|
||||
{
|
||||
if ( srcLen < 2 )
|
||||
{
|
||||
// minimal BOM is 2 bytes so bail out immediately and simplify the code
|
||||
// below which wouldn't need to check for length for UTF-16 cases
|
||||
return BOM_None;
|
||||
}
|
||||
|
||||
// examine the buffer for BOM presence
|
||||
//
|
||||
// see http://www.unicode.org/faq/utf_bom.html#BOM
|
||||
switch ( *src++ )
|
||||
{
|
||||
case '\0':
|
||||
// could only be big endian UTF-32 (00 00 FE FF)
|
||||
if ( srcLen >= 4 &&
|
||||
src[0] == '\0' &&
|
||||
src[1] == '\xfe' &&
|
||||
src[2] == '\xff' )
|
||||
{
|
||||
return BOM_UTF32BE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\xfe':
|
||||
// could only be big endian UTF-16 (FE FF)
|
||||
if ( *src++ == '\xff' )
|
||||
{
|
||||
return BOM_UTF16BE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\xff':
|
||||
// could be either little endian UTF-16 or UTF-32, both start
|
||||
// with FF FE
|
||||
if ( *src++ == '\xfe' )
|
||||
{
|
||||
return srcLen >= 4 && src[0] == '\0' && src[1] == '\0'
|
||||
? BOM_UTF32LE
|
||||
: BOM_UTF16LE;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\xef':
|
||||
// is this UTF-8 BOM (EF BB BF)?
|
||||
if ( srcLen >= 3 && src[0] == '\xbb' && src[1] == '\xbf' )
|
||||
{
|
||||
return BOM_UTF8;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return BOM_None;
|
||||
}
|
||||
|
||||
void wxConvAuto::InitFromBOM(BOMType bomType)
|
||||
{
|
||||
m_consumedBOM = false;
|
||||
|
||||
switch ( bomType )
|
||||
{
|
||||
case BOM_UTF32BE:
|
||||
m_conv = new wxMBConvUTF32BE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF32LE:
|
||||
m_conv = new wxMBConvUTF32LE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF16BE:
|
||||
m_conv = new wxMBConvUTF16BE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF16LE:
|
||||
m_conv = new wxMBConvUTF16LE;
|
||||
m_ownsConv = true;
|
||||
break;
|
||||
|
||||
case BOM_UTF8:
|
||||
m_conv = &wxConvUTF8;
|
||||
m_ownsConv = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected BOM type") );
|
||||
// fall through: still need to create something
|
||||
|
||||
case BOM_None:
|
||||
InitWithDefault();
|
||||
m_consumedBOM = true; // as there is nothing to consume
|
||||
}
|
||||
}
|
||||
|
||||
void wxConvAuto::SkipBOM(const char **src, size_t *len) const
|
||||
{
|
||||
int ofs;
|
||||
switch ( m_bomType )
|
||||
{
|
||||
case BOM_UTF32BE:
|
||||
case BOM_UTF32LE:
|
||||
ofs = 4;
|
||||
break;
|
||||
|
||||
case BOM_UTF16BE:
|
||||
case BOM_UTF16LE:
|
||||
ofs = 2;
|
||||
break;
|
||||
|
||||
case BOM_UTF8:
|
||||
ofs = 3;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unexpected BOM type") );
|
||||
// fall through: still need to create something
|
||||
|
||||
case BOM_None:
|
||||
ofs = 0;
|
||||
}
|
||||
|
||||
*src += ofs;
|
||||
if ( *len != (size_t)-1 )
|
||||
*len -= ofs;
|
||||
}
|
||||
|
||||
void wxConvAuto::InitFromInput(const char **src, size_t *len)
|
||||
{
|
||||
m_bomType = DetectBOM(*src, *len);
|
||||
InitFromBOM(m_bomType);
|
||||
SkipBOM(src, len);
|
||||
}
|
||||
|
||||
size_t
|
||||
wxConvAuto::ToWChar(wchar_t *dst, size_t dstLen,
|
||||
const char *src, size_t srcLen) const
|
||||
{
|
||||
// we check BOM and create the appropriate conversion the first time we're
|
||||
// called but we also need to ensure that the BOM is skipped not only
|
||||
// during this initial call but also during the first call with non-NULL
|
||||
// dst as typically we're first called with NULL dst to calculate the
|
||||
// needed buffer size
|
||||
wxConvAuto *self = wx_const_cast(wxConvAuto *, this);
|
||||
if ( !m_conv )
|
||||
{
|
||||
self->InitFromInput(&src, &srcLen);
|
||||
if ( dst )
|
||||
self->m_consumedBOM = true;
|
||||
}
|
||||
|
||||
if ( !m_consumedBOM && dst )
|
||||
{
|
||||
self->m_consumedBOM = true;
|
||||
SkipBOM(&src, &srcLen);
|
||||
}
|
||||
|
||||
return m_conv->ToWChar(dst, dstLen, src, srcLen);
|
||||
}
|
||||
|
||||
size_t
|
||||
wxConvAuto::FromWChar(char *dst, size_t dstLen,
|
||||
const wchar_t *src, size_t srcLen) const
|
||||
{
|
||||
if ( !m_conv )
|
||||
{
|
||||
// default to UTF-8 for the multibyte output
|
||||
wx_const_cast(wxConvAuto *, this)->InitWithDefault();
|
||||
}
|
||||
|
||||
return m_conv->FromWChar(dst, dstLen, src, srcLen);
|
||||
}
|
||||
|
||||
#endif // wxUSE_WCHAR_T
|
||||
|
||||
|
1024
Externals/wxWidgets/src/common/cshelp.cpp
vendored
1024
Externals/wxWidgets/src/common/cshelp.cpp
vendored
File diff suppressed because it is too large
Load Diff
376
Externals/wxWidgets/src/common/ctrlcmn.cpp
vendored
376
Externals/wxWidgets/src/common/ctrlcmn.cpp
vendored
@ -1,188 +1,188 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/ctrlcmn.cpp
|
||||
// Purpose: wxControl common interface
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 26.07.99
|
||||
// RCS-ID: $Id: ctrlcmn.cpp 40329 2006-07-25 18:40:04Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CONTROLS
|
||||
|
||||
#include "wx/control.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/radiobut.h"
|
||||
#include "wx/statbmp.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/utils.h" // for wxStripMenuCodes()
|
||||
#endif
|
||||
|
||||
const wxChar wxControlNameStr[] = wxT("control");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxControlBase::~wxControlBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
bool wxControlBase::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint &pos,
|
||||
const wxSize &size,
|
||||
long style,
|
||||
const wxValidator& wxVALIDATOR_PARAM(validator),
|
||||
const wxString &name)
|
||||
{
|
||||
bool ret = wxWindow::Create(parent, id, pos, size, style, name);
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
if ( ret )
|
||||
SetValidator(validator);
|
||||
#endif // wxUSE_VALIDATORS
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxControlBase::CreateControl(wxWindowBase *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
// even if it's possible to create controls without parents in some port,
|
||||
// it should surely be discouraged because it doesn't work at all under
|
||||
// Windows
|
||||
wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
|
||||
|
||||
if ( !CreateBase(parent, id, pos, size, style, validator, name) )
|
||||
return false;
|
||||
|
||||
parent->AddChild(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxString wxControlBase::GetLabelText(const wxString& label)
|
||||
{
|
||||
// we don't want strip the TABs here, just the mnemonics
|
||||
return wxStripMenuCodes(label, wxStrip_Mnemonics);
|
||||
}
|
||||
|
||||
void wxControlBase::Command(wxCommandEvent& event)
|
||||
{
|
||||
(void)GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
|
||||
{
|
||||
event.SetEventObject((wxControlBase *)this); // const_cast
|
||||
|
||||
// event.SetId(GetId()); -- this is usuall done in the event ctor
|
||||
|
||||
switch ( m_clientDataType )
|
||||
{
|
||||
case wxClientData_Void:
|
||||
event.SetClientData(GetClientData());
|
||||
break;
|
||||
|
||||
case wxClientData_Object:
|
||||
event.SetClientObject(GetClientObject());
|
||||
break;
|
||||
|
||||
case wxClientData_None:
|
||||
// nothing to do
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxControlBase::SetLabel( const wxString &label )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
wxWindow::SetLabel(label);
|
||||
}
|
||||
|
||||
bool wxControlBase::SetFont(const wxFont& font)
|
||||
{
|
||||
InvalidateBestSize();
|
||||
return wxWindow::SetFont(font);
|
||||
}
|
||||
|
||||
// wxControl-specific processing after processing the update event
|
||||
void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
|
||||
{
|
||||
// call inherited
|
||||
wxWindowBase::DoUpdateWindowUI(event);
|
||||
|
||||
// update label
|
||||
if ( event.GetSetText() )
|
||||
{
|
||||
if ( event.GetText() != GetLabel() )
|
||||
SetLabel(event.GetText());
|
||||
}
|
||||
|
||||
// Unfortunately we don't yet have common base class for
|
||||
// wxRadioButton, so we handle updates of radiobuttons here.
|
||||
// TODO: If once wxRadioButtonBase will exist, move this code there.
|
||||
#if wxUSE_RADIOBTN
|
||||
if ( event.GetSetChecked() )
|
||||
{
|
||||
wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
|
||||
if ( radiobtn )
|
||||
radiobtn->SetValue(event.GetChecked());
|
||||
}
|
||||
#endif // wxUSE_RADIOBTN
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStaticBitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_STATBMP
|
||||
|
||||
wxStaticBitmapBase::~wxStaticBitmapBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
wxSize wxStaticBitmapBase::DoGetBestSize() const
|
||||
{
|
||||
wxSize best;
|
||||
wxBitmap bmp = GetBitmap();
|
||||
if ( bmp.Ok() )
|
||||
best = wxSize(bmp.GetWidth(), bmp.GetHeight());
|
||||
else
|
||||
// this is completely arbitrary
|
||||
best = wxSize(16, 16);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STATBMP
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/ctrlcmn.cpp
|
||||
// Purpose: wxControl common interface
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 26.07.99
|
||||
// RCS-ID: $Id: ctrlcmn.cpp 40329 2006-07-25 18:40:04Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CONTROLS
|
||||
|
||||
#include "wx/control.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/radiobut.h"
|
||||
#include "wx/statbmp.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/utils.h" // for wxStripMenuCodes()
|
||||
#endif
|
||||
|
||||
const wxChar wxControlNameStr[] = wxT("control");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxControlBase::~wxControlBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
bool wxControlBase::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint &pos,
|
||||
const wxSize &size,
|
||||
long style,
|
||||
const wxValidator& wxVALIDATOR_PARAM(validator),
|
||||
const wxString &name)
|
||||
{
|
||||
bool ret = wxWindow::Create(parent, id, pos, size, style, name);
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
if ( ret )
|
||||
SetValidator(validator);
|
||||
#endif // wxUSE_VALIDATORS
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxControlBase::CreateControl(wxWindowBase *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
// even if it's possible to create controls without parents in some port,
|
||||
// it should surely be discouraged because it doesn't work at all under
|
||||
// Windows
|
||||
wxCHECK_MSG( parent, false, wxT("all controls must have parents") );
|
||||
|
||||
if ( !CreateBase(parent, id, pos, size, style, validator, name) )
|
||||
return false;
|
||||
|
||||
parent->AddChild(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxString wxControlBase::GetLabelText(const wxString& label)
|
||||
{
|
||||
// we don't want strip the TABs here, just the mnemonics
|
||||
return wxStripMenuCodes(label, wxStrip_Mnemonics);
|
||||
}
|
||||
|
||||
void wxControlBase::Command(wxCommandEvent& event)
|
||||
{
|
||||
(void)GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
|
||||
{
|
||||
event.SetEventObject((wxControlBase *)this); // const_cast
|
||||
|
||||
// event.SetId(GetId()); -- this is usuall done in the event ctor
|
||||
|
||||
switch ( m_clientDataType )
|
||||
{
|
||||
case wxClientData_Void:
|
||||
event.SetClientData(GetClientData());
|
||||
break;
|
||||
|
||||
case wxClientData_Object:
|
||||
event.SetClientObject(GetClientObject());
|
||||
break;
|
||||
|
||||
case wxClientData_None:
|
||||
// nothing to do
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxControlBase::SetLabel( const wxString &label )
|
||||
{
|
||||
InvalidateBestSize();
|
||||
wxWindow::SetLabel(label);
|
||||
}
|
||||
|
||||
bool wxControlBase::SetFont(const wxFont& font)
|
||||
{
|
||||
InvalidateBestSize();
|
||||
return wxWindow::SetFont(font);
|
||||
}
|
||||
|
||||
// wxControl-specific processing after processing the update event
|
||||
void wxControlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
|
||||
{
|
||||
// call inherited
|
||||
wxWindowBase::DoUpdateWindowUI(event);
|
||||
|
||||
// update label
|
||||
if ( event.GetSetText() )
|
||||
{
|
||||
if ( event.GetText() != GetLabel() )
|
||||
SetLabel(event.GetText());
|
||||
}
|
||||
|
||||
// Unfortunately we don't yet have common base class for
|
||||
// wxRadioButton, so we handle updates of radiobuttons here.
|
||||
// TODO: If once wxRadioButtonBase will exist, move this code there.
|
||||
#if wxUSE_RADIOBTN
|
||||
if ( event.GetSetChecked() )
|
||||
{
|
||||
wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
|
||||
if ( radiobtn )
|
||||
radiobtn->SetValue(event.GetChecked());
|
||||
}
|
||||
#endif // wxUSE_RADIOBTN
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStaticBitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_STATBMP
|
||||
|
||||
wxStaticBitmapBase::~wxStaticBitmapBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
wxSize wxStaticBitmapBase::DoGetBestSize() const
|
||||
{
|
||||
wxSize best;
|
||||
wxBitmap bmp = GetBitmap();
|
||||
if ( bmp.Ok() )
|
||||
best = wxSize(bmp.GetWidth(), bmp.GetHeight());
|
||||
else
|
||||
// this is completely arbitrary
|
||||
best = wxSize(16, 16);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STATBMP
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
|
394
Externals/wxWidgets/src/common/ctrlsub.cpp
vendored
394
Externals/wxWidgets/src/common/ctrlsub.cpp
vendored
@ -1,197 +1,197 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/ctrlsub.cpp
|
||||
// Purpose: wxItemContainer implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 22.10.99
|
||||
// RCS-ID: $Id: ctrlsub.cpp 39077 2006-05-06 19:05:50Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CONTROLS
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/ctrlsub.h"
|
||||
#include "wx/arrstr.h"
|
||||
#endif
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxControlWithItems, wxControl)
|
||||
|
||||
// ============================================================================
|
||||
// wxItemContainerImmutable implementation
|
||||
// ============================================================================
|
||||
|
||||
wxItemContainerImmutable::~wxItemContainerImmutable()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// selection
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxItemContainerImmutable::GetStringSelection() const
|
||||
{
|
||||
wxString s;
|
||||
|
||||
int sel = GetSelection();
|
||||
if ( sel != wxNOT_FOUND )
|
||||
s = GetString((unsigned int)sel);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool wxItemContainerImmutable::SetStringSelection(const wxString& s)
|
||||
{
|
||||
const int sel = FindString(s);
|
||||
if ( sel == wxNOT_FOUND )
|
||||
return false;
|
||||
|
||||
SetSelection(sel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxArrayString wxItemContainerImmutable::GetStrings() const
|
||||
{
|
||||
wxArrayString result;
|
||||
|
||||
const unsigned int count = GetCount();
|
||||
result.Alloc(count);
|
||||
for ( unsigned int n = 0; n < count; n++ )
|
||||
result.Add(GetString(n));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxItemContainer implementation
|
||||
// ============================================================================
|
||||
|
||||
wxItemContainer::~wxItemContainer()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// appending items
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxItemContainer::Append(const wxArrayString& strings)
|
||||
{
|
||||
const size_t count = strings.GetCount();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
{
|
||||
Append(strings[n]);
|
||||
}
|
||||
}
|
||||
|
||||
int wxItemContainer::Insert(const wxString& item, unsigned int pos, void *clientData)
|
||||
{
|
||||
int n = DoInsert(item, pos);
|
||||
if ( n != wxNOT_FOUND )
|
||||
SetClientData(n, clientData);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int wxItemContainer::Insert(const wxString& item, unsigned int pos, wxClientData *clientData)
|
||||
{
|
||||
int n = DoInsert(item, pos);
|
||||
if ( n != wxNOT_FOUND )
|
||||
SetClientObject(n, clientData);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxItemContainer::SetClientObject(unsigned int n, wxClientData *data)
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
// when we call SetClientObject() for the first time, m_clientDataItemsType
|
||||
// is still wxClientData_None and so calling DoGetItemClientObject() would
|
||||
// fail (in addition to being useless) - don't do it
|
||||
if ( m_clientDataItemsType == wxClientData_Object )
|
||||
{
|
||||
wxClientData *clientDataOld = DoGetItemClientObject(n);
|
||||
if ( clientDataOld )
|
||||
delete clientDataOld;
|
||||
}
|
||||
else // m_clientDataItemsType == wxClientData_None
|
||||
{
|
||||
// now we have object client data
|
||||
m_clientDataItemsType = wxClientData_Object;
|
||||
}
|
||||
|
||||
DoSetItemClientObject(n, data);
|
||||
}
|
||||
|
||||
wxClientData *wxItemContainer::GetClientObject(unsigned int n) const
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
|
||||
wxT("this window doesn't have object client data") );
|
||||
|
||||
return DoGetItemClientObject(n);
|
||||
}
|
||||
|
||||
void wxItemContainer::SetClientData(unsigned int n, void *data)
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
DoSetItemClientData(n, data);
|
||||
m_clientDataItemsType = wxClientData_Void;
|
||||
}
|
||||
|
||||
void *wxItemContainer::GetClientData(unsigned int n) const
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
|
||||
wxT("this window doesn't have void client data") );
|
||||
|
||||
return DoGetItemClientData(n);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxControlWithItems implementation
|
||||
// ============================================================================
|
||||
|
||||
void wxControlWithItems::InitCommandEventWithItems(wxCommandEvent& event, int n)
|
||||
{
|
||||
InitCommandEvent(event);
|
||||
|
||||
if ( n != wxNOT_FOUND )
|
||||
{
|
||||
if ( HasClientObjectData() )
|
||||
event.SetClientObject(GetClientObject(n));
|
||||
else if ( HasClientUntypedData() )
|
||||
event.SetClientData(GetClientData(n));
|
||||
}
|
||||
}
|
||||
|
||||
wxControlWithItems::~wxControlWithItems()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/ctrlsub.cpp
|
||||
// Purpose: wxItemContainer implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 22.10.99
|
||||
// RCS-ID: $Id: ctrlsub.cpp 39077 2006-05-06 19:05:50Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_CONTROLS
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/ctrlsub.h"
|
||||
#include "wx/arrstr.h"
|
||||
#endif
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxControlWithItems, wxControl)
|
||||
|
||||
// ============================================================================
|
||||
// wxItemContainerImmutable implementation
|
||||
// ============================================================================
|
||||
|
||||
wxItemContainerImmutable::~wxItemContainerImmutable()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// selection
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxItemContainerImmutable::GetStringSelection() const
|
||||
{
|
||||
wxString s;
|
||||
|
||||
int sel = GetSelection();
|
||||
if ( sel != wxNOT_FOUND )
|
||||
s = GetString((unsigned int)sel);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool wxItemContainerImmutable::SetStringSelection(const wxString& s)
|
||||
{
|
||||
const int sel = FindString(s);
|
||||
if ( sel == wxNOT_FOUND )
|
||||
return false;
|
||||
|
||||
SetSelection(sel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxArrayString wxItemContainerImmutable::GetStrings() const
|
||||
{
|
||||
wxArrayString result;
|
||||
|
||||
const unsigned int count = GetCount();
|
||||
result.Alloc(count);
|
||||
for ( unsigned int n = 0; n < count; n++ )
|
||||
result.Add(GetString(n));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxItemContainer implementation
|
||||
// ============================================================================
|
||||
|
||||
wxItemContainer::~wxItemContainer()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// appending items
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxItemContainer::Append(const wxArrayString& strings)
|
||||
{
|
||||
const size_t count = strings.GetCount();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
{
|
||||
Append(strings[n]);
|
||||
}
|
||||
}
|
||||
|
||||
int wxItemContainer::Insert(const wxString& item, unsigned int pos, void *clientData)
|
||||
{
|
||||
int n = DoInsert(item, pos);
|
||||
if ( n != wxNOT_FOUND )
|
||||
SetClientData(n, clientData);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int wxItemContainer::Insert(const wxString& item, unsigned int pos, wxClientData *clientData)
|
||||
{
|
||||
int n = DoInsert(item, pos);
|
||||
if ( n != wxNOT_FOUND )
|
||||
SetClientObject(n, clientData);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxItemContainer::SetClientObject(unsigned int n, wxClientData *data)
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType != wxClientData_Void,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
// when we call SetClientObject() for the first time, m_clientDataItemsType
|
||||
// is still wxClientData_None and so calling DoGetItemClientObject() would
|
||||
// fail (in addition to being useless) - don't do it
|
||||
if ( m_clientDataItemsType == wxClientData_Object )
|
||||
{
|
||||
wxClientData *clientDataOld = DoGetItemClientObject(n);
|
||||
if ( clientDataOld )
|
||||
delete clientDataOld;
|
||||
}
|
||||
else // m_clientDataItemsType == wxClientData_None
|
||||
{
|
||||
// now we have object client data
|
||||
m_clientDataItemsType = wxClientData_Object;
|
||||
}
|
||||
|
||||
DoSetItemClientObject(n, data);
|
||||
}
|
||||
|
||||
wxClientData *wxItemContainer::GetClientObject(unsigned int n) const
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object,
|
||||
wxT("this window doesn't have object client data") );
|
||||
|
||||
return DoGetItemClientObject(n);
|
||||
}
|
||||
|
||||
void wxItemContainer::SetClientData(unsigned int n, void *data)
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType != wxClientData_Object,
|
||||
wxT("can't have both object and void client data") );
|
||||
|
||||
DoSetItemClientData(n, data);
|
||||
m_clientDataItemsType = wxClientData_Void;
|
||||
}
|
||||
|
||||
void *wxItemContainer::GetClientData(unsigned int n) const
|
||||
{
|
||||
wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
|
||||
wxT("this window doesn't have void client data") );
|
||||
|
||||
return DoGetItemClientData(n);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxControlWithItems implementation
|
||||
// ============================================================================
|
||||
|
||||
void wxControlWithItems::InitCommandEventWithItems(wxCommandEvent& event, int n)
|
||||
{
|
||||
InitCommandEvent(event);
|
||||
|
||||
if ( n != wxNOT_FOUND )
|
||||
{
|
||||
if ( HasClientObjectData() )
|
||||
event.SetClientObject(GetClientObject(n));
|
||||
else if ( HasClientUntypedData() )
|
||||
event.SetClientData(GetClientData(n));
|
||||
}
|
||||
}
|
||||
|
||||
wxControlWithItems::~wxControlWithItems()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
|
166
Externals/wxWidgets/src/common/datacmn.cpp
vendored
166
Externals/wxWidgets/src/common/datacmn.cpp
vendored
@ -1,83 +1,83 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/datacmn.cpp
|
||||
// Purpose: contains definitions of various global wxWidgets variables
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 10.04.03 (from src/*/data.cpp files)
|
||||
// RCS-ID: $Id: datacmn.cpp 43874 2006-12-09 14:52:59Z VZ $
|
||||
// Copyright: (c) 1997-2002 wxWidgets development team
|
||||
// License: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/accel.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// 'Null' objects
|
||||
#if wxUSE_ACCEL
|
||||
wxAcceleratorTable wxNullAcceleratorTable;
|
||||
#endif // wxUSE_ACCEL
|
||||
|
||||
// Default window names
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxButtonNameStr[] = wxT("button");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxCheckBoxNameStr[] = wxT("check");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxComboBoxNameStr[] = wxT("comboBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDialogNameStr[] = wxT("dialog");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFrameNameStr[] = wxT("frame");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticBoxNameStr[] = wxT("groupBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxListBoxNameStr[] = wxT("listBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticLineNameStr[] = wxT("staticLine");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticTextNameStr[] = wxT("staticText");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticBitmapNameStr[] = wxT("staticBitmap");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxNotebookNameStr[] = wxT("notebook");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxPanelNameStr[] = wxT("panel");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxRadioBoxNameStr[] = wxT("radioBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxRadioButtonNameStr[] = wxT("radioButton");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxBitmapRadioButtonNameStr[] = wxT("radioButton");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxScrollBarNameStr[] = wxT("scrollBar");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxSliderNameStr[] = wxT("slider");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStatusLineNameStr[] = wxT("status_line");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxTextCtrlNameStr[] = wxT("text");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxTreeCtrlNameStr[] = wxT("treeCtrl");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxToolBarNameStr[] = wxT("toolbar");
|
||||
|
||||
// Default messages
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxMessageBoxCaptionStr[] = wxT("Message");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorPromptStr[] = wxT("Select a file");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[] = wxT("Select a directory");
|
||||
|
||||
// Other default strings
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorDefaultWildcardStr[] =
|
||||
#if defined(__WXMSW__) || defined(__OS2__)
|
||||
wxT("*.*")
|
||||
#else // Unix/Mac
|
||||
wxT("*")
|
||||
#endif
|
||||
;
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDirDialogNameStr[] = wxT("wxDirCtrl");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDirDialogDefaultFolderStr[] = wxT("/");
|
||||
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFileDialogNameStr[] = wxT("filedlg");
|
||||
#if defined(__WXMSW__) || defined(__OS2__)
|
||||
WXDLLEXPORT_DATA(const wxChar *) wxUserResourceStr = wxT("TEXT");
|
||||
#endif
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/datacmn.cpp
|
||||
// Purpose: contains definitions of various global wxWidgets variables
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 10.04.03 (from src/*/data.cpp files)
|
||||
// RCS-ID: $Id: datacmn.cpp 43874 2006-12-09 14:52:59Z VZ $
|
||||
// Copyright: (c) 1997-2002 wxWidgets development team
|
||||
// License: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/accel.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// 'Null' objects
|
||||
#if wxUSE_ACCEL
|
||||
wxAcceleratorTable wxNullAcceleratorTable;
|
||||
#endif // wxUSE_ACCEL
|
||||
|
||||
// Default window names
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxButtonNameStr[] = wxT("button");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxCheckBoxNameStr[] = wxT("check");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxComboBoxNameStr[] = wxT("comboBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDialogNameStr[] = wxT("dialog");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFrameNameStr[] = wxT("frame");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticBoxNameStr[] = wxT("groupBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxListBoxNameStr[] = wxT("listBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticLineNameStr[] = wxT("staticLine");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticTextNameStr[] = wxT("staticText");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStaticBitmapNameStr[] = wxT("staticBitmap");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxNotebookNameStr[] = wxT("notebook");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxPanelNameStr[] = wxT("panel");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxRadioBoxNameStr[] = wxT("radioBox");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxRadioButtonNameStr[] = wxT("radioButton");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxBitmapRadioButtonNameStr[] = wxT("radioButton");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxScrollBarNameStr[] = wxT("scrollBar");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxSliderNameStr[] = wxT("slider");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxStatusLineNameStr[] = wxT("status_line");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxTextCtrlNameStr[] = wxT("text");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxTreeCtrlNameStr[] = wxT("treeCtrl");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxToolBarNameStr[] = wxT("toolbar");
|
||||
|
||||
// Default messages
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxMessageBoxCaptionStr[] = wxT("Message");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorPromptStr[] = wxT("Select a file");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[] = wxT("Select a directory");
|
||||
|
||||
// Other default strings
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorDefaultWildcardStr[] =
|
||||
#if defined(__WXMSW__) || defined(__OS2__)
|
||||
wxT("*.*")
|
||||
#else // Unix/Mac
|
||||
wxT("*")
|
||||
#endif
|
||||
;
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDirDialogNameStr[] = wxT("wxDirCtrl");
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxDirDialogDefaultFolderStr[] = wxT("/");
|
||||
|
||||
extern WXDLLEXPORT_DATA(const wxChar) wxFileDialogNameStr[] = wxT("filedlg");
|
||||
#if defined(__WXMSW__) || defined(__OS2__)
|
||||
WXDLLEXPORT_DATA(const wxChar *) wxUserResourceStr = wxT("TEXT");
|
||||
#endif
|
||||
|
1822
Externals/wxWidgets/src/common/datavcmn.cpp
vendored
1822
Externals/wxWidgets/src/common/datavcmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
9260
Externals/wxWidgets/src/common/datetime.cpp
vendored
9260
Externals/wxWidgets/src/common/datetime.cpp
vendored
File diff suppressed because it is too large
Load Diff
1490
Externals/wxWidgets/src/common/datstrm.cpp
vendored
1490
Externals/wxWidgets/src/common/datstrm.cpp
vendored
File diff suppressed because it is too large
Load Diff
9048
Externals/wxWidgets/src/common/db.cpp
vendored
9048
Externals/wxWidgets/src/common/db.cpp
vendored
File diff suppressed because it is too large
Load Diff
1454
Externals/wxWidgets/src/common/dbgrid.cpp
vendored
1454
Externals/wxWidgets/src/common/dbgrid.cpp
vendored
File diff suppressed because it is too large
Load Diff
5892
Externals/wxWidgets/src/common/dbtable.cpp
vendored
5892
Externals/wxWidgets/src/common/dbtable.cpp
vendored
File diff suppressed because it is too large
Load Diff
2318
Externals/wxWidgets/src/common/dcbase.cpp
vendored
2318
Externals/wxWidgets/src/common/dcbase.cpp
vendored
File diff suppressed because it is too large
Load Diff
190
Externals/wxWidgets/src/common/dcbufcmn.cpp
vendored
190
Externals/wxWidgets/src/common/dcbufcmn.cpp
vendored
@ -1,95 +1,95 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dcbufcmn.cpp
|
||||
// Purpose: Buffered DC implementation
|
||||
// Author: Ron Lee, Jaakko Salli
|
||||
// Modified by:
|
||||
// Created: Sep-20-2006
|
||||
// RCS-ID: $Id: dcbufcmn.cpp 52152 2008-02-27 18:03:12Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/dcbuffer.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSharedDCBufferManager: helper class maintaining backing store bitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxSharedDCBufferManager : public wxModule
|
||||
{
|
||||
public:
|
||||
wxSharedDCBufferManager() { }
|
||||
|
||||
virtual bool OnInit() { return true; }
|
||||
virtual void OnExit() { wxDELETE(ms_buffer); }
|
||||
|
||||
static wxBitmap* GetBuffer(int w, int h)
|
||||
{
|
||||
if ( !ms_buffer ||
|
||||
w > ms_buffer->GetWidth() ||
|
||||
h > ms_buffer->GetHeight() )
|
||||
{
|
||||
delete ms_buffer;
|
||||
|
||||
// we must always return a valid bitmap but creating a bitmap of
|
||||
// size 0 would fail, so create a 1*1 bitmap in this case
|
||||
if ( !w )
|
||||
w = 1;
|
||||
if ( !h )
|
||||
h = 1;
|
||||
|
||||
ms_buffer = new wxBitmap(w, h);
|
||||
}
|
||||
return ms_buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
static wxBitmap *ms_buffer;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxSharedDCBufferManager)
|
||||
};
|
||||
|
||||
wxBitmap* wxSharedDCBufferManager::ms_buffer = NULL;
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSharedDCBufferManager, wxModule)
|
||||
|
||||
// ============================================================================
|
||||
// wxBufferedDC
|
||||
// ============================================================================
|
||||
|
||||
void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
|
||||
{
|
||||
if ( !m_buffer || !m_buffer->IsOk() )
|
||||
{
|
||||
if ( w == -1 || h == -1 )
|
||||
m_dc->GetSize(&w, &h);
|
||||
|
||||
m_buffer = wxSharedDCBufferManager::GetBuffer(w, h);
|
||||
}
|
||||
|
||||
SelectObject(*m_buffer);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dcbufcmn.cpp
|
||||
// Purpose: Buffered DC implementation
|
||||
// Author: Ron Lee, Jaakko Salli
|
||||
// Modified by:
|
||||
// Created: Sep-20-2006
|
||||
// RCS-ID: $Id: dcbufcmn.cpp 52152 2008-02-27 18:03:12Z VZ $
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/dcbuffer.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSharedDCBufferManager: helper class maintaining backing store bitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxSharedDCBufferManager : public wxModule
|
||||
{
|
||||
public:
|
||||
wxSharedDCBufferManager() { }
|
||||
|
||||
virtual bool OnInit() { return true; }
|
||||
virtual void OnExit() { wxDELETE(ms_buffer); }
|
||||
|
||||
static wxBitmap* GetBuffer(int w, int h)
|
||||
{
|
||||
if ( !ms_buffer ||
|
||||
w > ms_buffer->GetWidth() ||
|
||||
h > ms_buffer->GetHeight() )
|
||||
{
|
||||
delete ms_buffer;
|
||||
|
||||
// we must always return a valid bitmap but creating a bitmap of
|
||||
// size 0 would fail, so create a 1*1 bitmap in this case
|
||||
if ( !w )
|
||||
w = 1;
|
||||
if ( !h )
|
||||
h = 1;
|
||||
|
||||
ms_buffer = new wxBitmap(w, h);
|
||||
}
|
||||
return ms_buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
static wxBitmap *ms_buffer;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxSharedDCBufferManager)
|
||||
};
|
||||
|
||||
wxBitmap* wxSharedDCBufferManager::ms_buffer = NULL;
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSharedDCBufferManager, wxModule)
|
||||
|
||||
// ============================================================================
|
||||
// wxBufferedDC
|
||||
// ============================================================================
|
||||
|
||||
void wxBufferedDC::UseBuffer(wxCoord w, wxCoord h)
|
||||
{
|
||||
if ( !m_buffer || !m_buffer->IsOk() )
|
||||
{
|
||||
if ( w == -1 || h == -1 )
|
||||
m_dc->GetSize(&w, &h);
|
||||
|
||||
m_buffer = wxSharedDCBufferManager::GetBuffer(w, h);
|
||||
}
|
||||
|
||||
SelectObject(*m_buffer);
|
||||
}
|
||||
|
||||
|
2052
Externals/wxWidgets/src/common/dcgraph.cpp
vendored
2052
Externals/wxWidgets/src/common/dcgraph.cpp
vendored
File diff suppressed because it is too large
Load Diff
1396
Externals/wxWidgets/src/common/debugrpt.cpp
vendored
1396
Externals/wxWidgets/src/common/debugrpt.cpp
vendored
File diff suppressed because it is too large
Load Diff
714
Externals/wxWidgets/src/common/dircmn.cpp
vendored
714
Externals/wxWidgets/src/common/dircmn.cpp
vendored
@ -1,357 +1,357 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dircmn.cpp
|
||||
// Purpose: wxDir methods common to all implementations
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 19.05.01
|
||||
// RCS-ID: $Id: dircmn.cpp 40665 2006-08-19 08:45:31Z JS $
|
||||
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/arrstr.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/dir.h"
|
||||
#include "wx/filename.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDirTraverser
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDirTraverseResult
|
||||
wxDirTraverser::OnOpenError(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_IGNORE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::HasFiles() and HasSubDirs()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// dumb generic implementation
|
||||
|
||||
bool wxDir::HasFiles(const wxString& spec)
|
||||
{
|
||||
wxString s;
|
||||
return GetFirst(&s, spec, wxDIR_FILES | wxDIR_HIDDEN);
|
||||
}
|
||||
|
||||
// we have a (much) faster version for Unix
|
||||
#if (defined(__CYGWIN__) && defined(__WINDOWS__)) || !defined(__UNIX_LIKE__) || defined(__WXMAC__) || defined(__EMX__) || defined(__WINE__)
|
||||
|
||||
bool wxDir::HasSubDirs(const wxString& spec)
|
||||
{
|
||||
wxString s;
|
||||
return GetFirst(&s, spec, wxDIR_DIRS | wxDIR_HIDDEN);
|
||||
}
|
||||
|
||||
#endif // !Unix
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::Traverse()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t wxDir::Traverse(wxDirTraverser& sink,
|
||||
const wxString& filespec,
|
||||
int flags) const
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), (size_t)-1,
|
||||
_T("dir must be opened before traversing it") );
|
||||
|
||||
// the total number of files found
|
||||
size_t nFiles = 0;
|
||||
|
||||
// the name of this dir with path delimiter at the end
|
||||
wxString prefix = GetName();
|
||||
prefix += wxFILE_SEP_PATH;
|
||||
|
||||
// first, recurse into subdirs
|
||||
if ( flags & wxDIR_DIRS )
|
||||
{
|
||||
wxString dirname;
|
||||
for ( bool cont = GetFirst(&dirname, wxEmptyString, wxDIR_DIRS | (flags & wxDIR_HIDDEN) );
|
||||
cont;
|
||||
cont = cont && GetNext(&dirname) )
|
||||
{
|
||||
const wxString fulldirname = prefix + dirname;
|
||||
|
||||
switch ( sink.OnDir(fulldirname) )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(_T("unexpected OnDir() return value") );
|
||||
// fall through
|
||||
|
||||
case wxDIR_STOP:
|
||||
cont = false;
|
||||
break;
|
||||
|
||||
case wxDIR_CONTINUE:
|
||||
{
|
||||
wxDir subdir;
|
||||
|
||||
// don't give the error messages for the directories
|
||||
// which we can't open: there can be all sorts of good
|
||||
// reason for this (e.g. insufficient privileges) and
|
||||
// this shouldn't be treated as an error -- instead
|
||||
// let the user code decide what to do
|
||||
bool ok;
|
||||
do
|
||||
{
|
||||
wxLogNull noLog;
|
||||
ok = subdir.Open(fulldirname);
|
||||
if ( !ok )
|
||||
{
|
||||
// ask the user code what to do
|
||||
bool tryagain;
|
||||
switch ( sink.OnOpenError(fulldirname) )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(_T("unexpected OnOpenError() return value") );
|
||||
// fall through
|
||||
|
||||
case wxDIR_STOP:
|
||||
cont = false;
|
||||
// fall through
|
||||
|
||||
case wxDIR_IGNORE:
|
||||
tryagain = false;
|
||||
break;
|
||||
|
||||
case wxDIR_CONTINUE:
|
||||
tryagain = true;
|
||||
}
|
||||
|
||||
if ( !tryagain )
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ( !ok );
|
||||
|
||||
if ( ok )
|
||||
{
|
||||
nFiles += subdir.Traverse(sink, filespec, flags);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case wxDIR_IGNORE:
|
||||
// nothing to do
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now enum our own files
|
||||
if ( flags & wxDIR_FILES )
|
||||
{
|
||||
flags &= ~wxDIR_DIRS;
|
||||
|
||||
wxString filename;
|
||||
bool cont = GetFirst(&filename, filespec, flags);
|
||||
while ( cont )
|
||||
{
|
||||
wxDirTraverseResult res = sink.OnFile(prefix + filename);
|
||||
if ( res == wxDIR_STOP )
|
||||
break;
|
||||
|
||||
wxASSERT_MSG( res == wxDIR_CONTINUE,
|
||||
_T("unexpected OnFile() return value") );
|
||||
|
||||
nFiles++;
|
||||
|
||||
cont = GetNext(&filename);
|
||||
}
|
||||
}
|
||||
|
||||
return nFiles;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::GetAllFiles()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDirTraverserSimple : public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
wxDirTraverserSimple(wxArrayString& files) : m_files(files) { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename)
|
||||
{
|
||||
m_files.push_back(filename);
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
private:
|
||||
wxArrayString& m_files;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxDirTraverserSimple)
|
||||
};
|
||||
|
||||
/* static */
|
||||
size_t wxDir::GetAllFiles(const wxString& dirname,
|
||||
wxArrayString *files,
|
||||
const wxString& filespec,
|
||||
int flags)
|
||||
{
|
||||
wxCHECK_MSG( files, (size_t)-1, _T("NULL pointer in wxDir::GetAllFiles") );
|
||||
|
||||
size_t nFiles = 0;
|
||||
|
||||
wxDir dir(dirname);
|
||||
if ( dir.IsOpened() )
|
||||
{
|
||||
wxDirTraverserSimple traverser(*files);
|
||||
|
||||
nFiles += dir.Traverse(traverser, filespec, flags);
|
||||
}
|
||||
|
||||
return nFiles;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::FindFirst()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDirTraverserFindFirst : public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
wxDirTraverserFindFirst() { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename)
|
||||
{
|
||||
m_file = filename;
|
||||
return wxDIR_STOP;
|
||||
}
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
const wxString& GetFile() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
private:
|
||||
wxString m_file;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxDirTraverserFindFirst)
|
||||
};
|
||||
|
||||
/* static */
|
||||
wxString wxDir::FindFirst(const wxString& dirname,
|
||||
const wxString& filespec,
|
||||
int flags)
|
||||
{
|
||||
wxDir dir(dirname);
|
||||
if ( dir.IsOpened() )
|
||||
{
|
||||
wxDirTraverserFindFirst traverser;
|
||||
|
||||
dir.Traverse(traverser, filespec, flags | wxDIR_FILES);
|
||||
return traverser.GetFile();
|
||||
}
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::GetTotalSize()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDirTraverserSumSize : public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
wxDirTraverserSumSize() { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename)
|
||||
{
|
||||
wxULongLong sz = wxFileName::GetSize(filename);
|
||||
|
||||
// wxFileName::GetSize won't use this class again as
|
||||
// we're passing it a file and not a directory;
|
||||
// thus we are sure to avoid an endless loop
|
||||
if (sz == wxInvalidSize)
|
||||
{
|
||||
// if the GetSize() failed (this can happen because e.g. a
|
||||
// file is locked by another process), we can proceed but
|
||||
// we need to at least warn the user that the resulting
|
||||
// final size could be not reliable (if e.g. the locked
|
||||
// file is very big).
|
||||
m_skippedFiles.Add(filename);
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
m_sz += sz;
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
wxULongLong GetTotalSize() const
|
||||
{ return m_sz; }
|
||||
wxArrayString &FilesSkipped()
|
||||
{ return m_skippedFiles; }
|
||||
|
||||
protected:
|
||||
wxULongLong m_sz;
|
||||
wxArrayString m_skippedFiles;
|
||||
};
|
||||
|
||||
wxULongLong wxDir::GetTotalSize(const wxString &dirname, wxArrayString *filesSkipped)
|
||||
{
|
||||
if (!wxDirExists(dirname))
|
||||
return wxInvalidSize;
|
||||
|
||||
// to get the size of this directory and its contents we need
|
||||
// to recursively walk it...
|
||||
wxDir dir(dirname);
|
||||
if ( !dir.IsOpened() )
|
||||
return wxInvalidSize;
|
||||
|
||||
wxDirTraverserSumSize traverser;
|
||||
if (dir.Traverse(traverser) == (size_t)-1 ||
|
||||
traverser.GetTotalSize() == 0)
|
||||
return wxInvalidSize;
|
||||
|
||||
if (filesSkipped)
|
||||
*filesSkipped = traverser.FilesSkipped();
|
||||
|
||||
return traverser.GetTotalSize();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dircmn.cpp
|
||||
// Purpose: wxDir methods common to all implementations
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 19.05.01
|
||||
// RCS-ID: $Id: dircmn.cpp 40665 2006-08-19 08:45:31Z JS $
|
||||
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/arrstr.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/dir.h"
|
||||
#include "wx/filename.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDirTraverser
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDirTraverseResult
|
||||
wxDirTraverser::OnOpenError(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_IGNORE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::HasFiles() and HasSubDirs()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// dumb generic implementation
|
||||
|
||||
bool wxDir::HasFiles(const wxString& spec)
|
||||
{
|
||||
wxString s;
|
||||
return GetFirst(&s, spec, wxDIR_FILES | wxDIR_HIDDEN);
|
||||
}
|
||||
|
||||
// we have a (much) faster version for Unix
|
||||
#if (defined(__CYGWIN__) && defined(__WINDOWS__)) || !defined(__UNIX_LIKE__) || defined(__WXMAC__) || defined(__EMX__) || defined(__WINE__)
|
||||
|
||||
bool wxDir::HasSubDirs(const wxString& spec)
|
||||
{
|
||||
wxString s;
|
||||
return GetFirst(&s, spec, wxDIR_DIRS | wxDIR_HIDDEN);
|
||||
}
|
||||
|
||||
#endif // !Unix
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::Traverse()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t wxDir::Traverse(wxDirTraverser& sink,
|
||||
const wxString& filespec,
|
||||
int flags) const
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), (size_t)-1,
|
||||
_T("dir must be opened before traversing it") );
|
||||
|
||||
// the total number of files found
|
||||
size_t nFiles = 0;
|
||||
|
||||
// the name of this dir with path delimiter at the end
|
||||
wxString prefix = GetName();
|
||||
prefix += wxFILE_SEP_PATH;
|
||||
|
||||
// first, recurse into subdirs
|
||||
if ( flags & wxDIR_DIRS )
|
||||
{
|
||||
wxString dirname;
|
||||
for ( bool cont = GetFirst(&dirname, wxEmptyString, wxDIR_DIRS | (flags & wxDIR_HIDDEN) );
|
||||
cont;
|
||||
cont = cont && GetNext(&dirname) )
|
||||
{
|
||||
const wxString fulldirname = prefix + dirname;
|
||||
|
||||
switch ( sink.OnDir(fulldirname) )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(_T("unexpected OnDir() return value") );
|
||||
// fall through
|
||||
|
||||
case wxDIR_STOP:
|
||||
cont = false;
|
||||
break;
|
||||
|
||||
case wxDIR_CONTINUE:
|
||||
{
|
||||
wxDir subdir;
|
||||
|
||||
// don't give the error messages for the directories
|
||||
// which we can't open: there can be all sorts of good
|
||||
// reason for this (e.g. insufficient privileges) and
|
||||
// this shouldn't be treated as an error -- instead
|
||||
// let the user code decide what to do
|
||||
bool ok;
|
||||
do
|
||||
{
|
||||
wxLogNull noLog;
|
||||
ok = subdir.Open(fulldirname);
|
||||
if ( !ok )
|
||||
{
|
||||
// ask the user code what to do
|
||||
bool tryagain;
|
||||
switch ( sink.OnOpenError(fulldirname) )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(_T("unexpected OnOpenError() return value") );
|
||||
// fall through
|
||||
|
||||
case wxDIR_STOP:
|
||||
cont = false;
|
||||
// fall through
|
||||
|
||||
case wxDIR_IGNORE:
|
||||
tryagain = false;
|
||||
break;
|
||||
|
||||
case wxDIR_CONTINUE:
|
||||
tryagain = true;
|
||||
}
|
||||
|
||||
if ( !tryagain )
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ( !ok );
|
||||
|
||||
if ( ok )
|
||||
{
|
||||
nFiles += subdir.Traverse(sink, filespec, flags);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case wxDIR_IGNORE:
|
||||
// nothing to do
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now enum our own files
|
||||
if ( flags & wxDIR_FILES )
|
||||
{
|
||||
flags &= ~wxDIR_DIRS;
|
||||
|
||||
wxString filename;
|
||||
bool cont = GetFirst(&filename, filespec, flags);
|
||||
while ( cont )
|
||||
{
|
||||
wxDirTraverseResult res = sink.OnFile(prefix + filename);
|
||||
if ( res == wxDIR_STOP )
|
||||
break;
|
||||
|
||||
wxASSERT_MSG( res == wxDIR_CONTINUE,
|
||||
_T("unexpected OnFile() return value") );
|
||||
|
||||
nFiles++;
|
||||
|
||||
cont = GetNext(&filename);
|
||||
}
|
||||
}
|
||||
|
||||
return nFiles;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::GetAllFiles()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDirTraverserSimple : public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
wxDirTraverserSimple(wxArrayString& files) : m_files(files) { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename)
|
||||
{
|
||||
m_files.push_back(filename);
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
private:
|
||||
wxArrayString& m_files;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxDirTraverserSimple)
|
||||
};
|
||||
|
||||
/* static */
|
||||
size_t wxDir::GetAllFiles(const wxString& dirname,
|
||||
wxArrayString *files,
|
||||
const wxString& filespec,
|
||||
int flags)
|
||||
{
|
||||
wxCHECK_MSG( files, (size_t)-1, _T("NULL pointer in wxDir::GetAllFiles") );
|
||||
|
||||
size_t nFiles = 0;
|
||||
|
||||
wxDir dir(dirname);
|
||||
if ( dir.IsOpened() )
|
||||
{
|
||||
wxDirTraverserSimple traverser(*files);
|
||||
|
||||
nFiles += dir.Traverse(traverser, filespec, flags);
|
||||
}
|
||||
|
||||
return nFiles;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::FindFirst()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDirTraverserFindFirst : public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
wxDirTraverserFindFirst() { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename)
|
||||
{
|
||||
m_file = filename;
|
||||
return wxDIR_STOP;
|
||||
}
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
const wxString& GetFile() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
private:
|
||||
wxString m_file;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxDirTraverserFindFirst)
|
||||
};
|
||||
|
||||
/* static */
|
||||
wxString wxDir::FindFirst(const wxString& dirname,
|
||||
const wxString& filespec,
|
||||
int flags)
|
||||
{
|
||||
wxDir dir(dirname);
|
||||
if ( dir.IsOpened() )
|
||||
{
|
||||
wxDirTraverserFindFirst traverser;
|
||||
|
||||
dir.Traverse(traverser, filespec, flags | wxDIR_FILES);
|
||||
return traverser.GetFile();
|
||||
}
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDir::GetTotalSize()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDirTraverserSumSize : public wxDirTraverser
|
||||
{
|
||||
public:
|
||||
wxDirTraverserSumSize() { }
|
||||
|
||||
virtual wxDirTraverseResult OnFile(const wxString& filename)
|
||||
{
|
||||
wxULongLong sz = wxFileName::GetSize(filename);
|
||||
|
||||
// wxFileName::GetSize won't use this class again as
|
||||
// we're passing it a file and not a directory;
|
||||
// thus we are sure to avoid an endless loop
|
||||
if (sz == wxInvalidSize)
|
||||
{
|
||||
// if the GetSize() failed (this can happen because e.g. a
|
||||
// file is locked by another process), we can proceed but
|
||||
// we need to at least warn the user that the resulting
|
||||
// final size could be not reliable (if e.g. the locked
|
||||
// file is very big).
|
||||
m_skippedFiles.Add(filename);
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
m_sz += sz;
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
|
||||
{
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
wxULongLong GetTotalSize() const
|
||||
{ return m_sz; }
|
||||
wxArrayString &FilesSkipped()
|
||||
{ return m_skippedFiles; }
|
||||
|
||||
protected:
|
||||
wxULongLong m_sz;
|
||||
wxArrayString m_skippedFiles;
|
||||
};
|
||||
|
||||
wxULongLong wxDir::GetTotalSize(const wxString &dirname, wxArrayString *filesSkipped)
|
||||
{
|
||||
if (!wxDirExists(dirname))
|
||||
return wxInvalidSize;
|
||||
|
||||
// to get the size of this directory and its contents we need
|
||||
// to recursively walk it...
|
||||
wxDir dir(dirname);
|
||||
if ( !dir.IsOpened() )
|
||||
return wxInvalidSize;
|
||||
|
||||
wxDirTraverserSumSize traverser;
|
||||
if (dir.Traverse(traverser) == (size_t)-1 ||
|
||||
traverser.GetTotalSize() == 0)
|
||||
return wxInvalidSize;
|
||||
|
||||
if (filesSkipped)
|
||||
*filesSkipped = traverser.FilesSkipped();
|
||||
|
||||
return traverser.GetTotalSize();
|
||||
}
|
||||
|
||||
|
1130
Externals/wxWidgets/src/common/dlgcmn.cpp
vendored
1130
Externals/wxWidgets/src/common/dlgcmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
62
Externals/wxWidgets/src/common/dndcmn.cpp
vendored
62
Externals/wxWidgets/src/common/dndcmn.cpp
vendored
@ -1,31 +1,31 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/dndcmn.cpp
|
||||
// Author: Robert Roebling
|
||||
// Modified by:
|
||||
// Created: 19.10.99
|
||||
// RCS-ID: $Id: dndcmn.cpp 43664 2006-11-26 21:50:51Z JS $
|
||||
// Copyright: (c) wxWidgets Team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/dnd.h"
|
||||
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
|
||||
bool wxIsDragResultOk(wxDragResult res)
|
||||
{
|
||||
return res == wxDragCopy || res == wxDragMove || res == wxDragLink;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/dndcmn.cpp
|
||||
// Author: Robert Roebling
|
||||
// Modified by:
|
||||
// Created: 19.10.99
|
||||
// RCS-ID: $Id: dndcmn.cpp 43664 2006-11-26 21:50:51Z JS $
|
||||
// Copyright: (c) wxWidgets Team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/dnd.h"
|
||||
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
|
||||
bool wxIsDragResultOk(wxDragResult res)
|
||||
{
|
||||
return res == wxDragCopy || res == wxDragMove || res == wxDragLink;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
1034
Externals/wxWidgets/src/common/dobjcmn.cpp
vendored
1034
Externals/wxWidgets/src/common/dobjcmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
408
Externals/wxWidgets/src/common/docmdi.cpp
vendored
408
Externals/wxWidgets/src/common/docmdi.cpp
vendored
@ -1,204 +1,204 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: docmdi.cpp
|
||||
// Purpose: Frame classes for MDI document/view applications
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id: docmdi.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_MDI_ARCHITECTURE
|
||||
|
||||
#include "wx/docmdi.h"
|
||||
|
||||
/*
|
||||
* Docview MDI parent frame
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
|
||||
EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
|
||||
EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
|
||||
EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxDocMDIParentFrame::wxDocMDIParentFrame()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
Init();
|
||||
Create(manager, frame, id, title, pos, size, style, name);
|
||||
}
|
||||
|
||||
bool wxDocMDIParentFrame::Create(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
m_docManager = manager;
|
||||
return wxMDIParentFrame::Create(frame, id, title, pos, size, style, name);
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::Init()
|
||||
{
|
||||
m_docManager = NULL;
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
|
||||
{
|
||||
wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1));
|
||||
if (!f.empty())
|
||||
(void)m_docManager->CreateDocument(f, wxDOC_SILENT);
|
||||
}
|
||||
|
||||
// Extend event processing to search the view's event table
|
||||
bool wxDocMDIParentFrame::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
// Try the document manager, then do default processing
|
||||
if (!m_docManager || !m_docManager->ProcessEvent(event))
|
||||
return wxEvtHandler::ProcessEvent(event);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
if (m_docManager->Clear(!event.CanVeto()))
|
||||
{
|
||||
this->Destroy();
|
||||
}
|
||||
else
|
||||
event.Veto();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default document child frame for MDI children
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
|
||||
EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
|
||||
EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
void wxDocMDIChildFrame::Init()
|
||||
{
|
||||
m_childDocument = (wxDocument*) NULL;
|
||||
m_childView = (wxView*) NULL;
|
||||
}
|
||||
|
||||
wxDocMDIChildFrame::wxDocMDIChildFrame()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
|
||||
const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
Init();
|
||||
Create(doc, view, frame, id, title, pos, size, style, name);
|
||||
}
|
||||
|
||||
bool wxDocMDIChildFrame::Create(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
|
||||
const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
m_childDocument = doc;
|
||||
m_childView = view;
|
||||
if (wxMDIChildFrame::Create(frame, id, title, pos, size, style, name))
|
||||
{
|
||||
if (view)
|
||||
view->SetFrame(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
|
||||
{
|
||||
m_childView = (wxView *) NULL;
|
||||
}
|
||||
|
||||
// Extend event processing to search the view's event table
|
||||
bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
static wxEvent *ActiveEvent = NULL;
|
||||
|
||||
// Break recursion loops
|
||||
if (ActiveEvent == &event)
|
||||
return false;
|
||||
|
||||
ActiveEvent = &event;
|
||||
|
||||
bool ret;
|
||||
if ( !m_childView || ! m_childView->ProcessEvent(event) )
|
||||
{
|
||||
// Only hand up to the parent if it's a menu command
|
||||
if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
|
||||
ret = wxEvtHandler::ProcessEvent(event);
|
||||
else
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
ret = true;
|
||||
|
||||
ActiveEvent = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
|
||||
{
|
||||
wxMDIChildFrame::OnActivate(event);
|
||||
|
||||
if (event.GetActive() && m_childView)
|
||||
m_childView->Activate(event.GetActive());
|
||||
}
|
||||
|
||||
void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
// Close view but don't delete the frame while doing so!
|
||||
// ...since it will be deleted by wxWidgets if we return true.
|
||||
if (m_childView)
|
||||
{
|
||||
bool ans = event.CanVeto()
|
||||
? m_childView->Close(false) // false means don't delete associated window
|
||||
: true; // Must delete.
|
||||
|
||||
if (ans)
|
||||
{
|
||||
m_childView->Activate(false);
|
||||
delete m_childView;
|
||||
m_childView = (wxView *) NULL;
|
||||
m_childDocument = (wxDocument *) NULL;
|
||||
|
||||
this->Destroy();
|
||||
}
|
||||
else
|
||||
event.Veto();
|
||||
}
|
||||
else
|
||||
event.Veto();
|
||||
}
|
||||
|
||||
#endif
|
||||
// wxUSE_DOC_VIEW_ARCHITECTURE
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: docmdi.cpp
|
||||
// Purpose: Frame classes for MDI document/view applications
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id: docmdi.cpp 35650 2005-09-23 12:56:45Z MR $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_MDI_ARCHITECTURE
|
||||
|
||||
#include "wx/docmdi.h"
|
||||
|
||||
/*
|
||||
* Docview MDI parent frame
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
|
||||
EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
|
||||
EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
|
||||
EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxDocMDIParentFrame::wxDocMDIParentFrame()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
Init();
|
||||
Create(manager, frame, id, title, pos, size, style, name);
|
||||
}
|
||||
|
||||
bool wxDocMDIParentFrame::Create(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
m_docManager = manager;
|
||||
return wxMDIParentFrame::Create(frame, id, title, pos, size, style, name);
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::Init()
|
||||
{
|
||||
m_docManager = NULL;
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
|
||||
{
|
||||
wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1));
|
||||
if (!f.empty())
|
||||
(void)m_docManager->CreateDocument(f, wxDOC_SILENT);
|
||||
}
|
||||
|
||||
// Extend event processing to search the view's event table
|
||||
bool wxDocMDIParentFrame::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
// Try the document manager, then do default processing
|
||||
if (!m_docManager || !m_docManager->ProcessEvent(event))
|
||||
return wxEvtHandler::ProcessEvent(event);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
if (m_docManager->Clear(!event.CanVeto()))
|
||||
{
|
||||
this->Destroy();
|
||||
}
|
||||
else
|
||||
event.Veto();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Default document child frame for MDI children
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
|
||||
EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
|
||||
EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
void wxDocMDIChildFrame::Init()
|
||||
{
|
||||
m_childDocument = (wxDocument*) NULL;
|
||||
m_childView = (wxView*) NULL;
|
||||
}
|
||||
|
||||
wxDocMDIChildFrame::wxDocMDIChildFrame()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
|
||||
const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
Init();
|
||||
Create(doc, view, frame, id, title, pos, size, style, name);
|
||||
}
|
||||
|
||||
bool wxDocMDIChildFrame::Create(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
|
||||
const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
{
|
||||
m_childDocument = doc;
|
||||
m_childView = view;
|
||||
if (wxMDIChildFrame::Create(frame, id, title, pos, size, style, name))
|
||||
{
|
||||
if (view)
|
||||
view->SetFrame(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
|
||||
{
|
||||
m_childView = (wxView *) NULL;
|
||||
}
|
||||
|
||||
// Extend event processing to search the view's event table
|
||||
bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
static wxEvent *ActiveEvent = NULL;
|
||||
|
||||
// Break recursion loops
|
||||
if (ActiveEvent == &event)
|
||||
return false;
|
||||
|
||||
ActiveEvent = &event;
|
||||
|
||||
bool ret;
|
||||
if ( !m_childView || ! m_childView->ProcessEvent(event) )
|
||||
{
|
||||
// Only hand up to the parent if it's a menu command
|
||||
if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
|
||||
ret = wxEvtHandler::ProcessEvent(event);
|
||||
else
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
ret = true;
|
||||
|
||||
ActiveEvent = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
|
||||
{
|
||||
wxMDIChildFrame::OnActivate(event);
|
||||
|
||||
if (event.GetActive() && m_childView)
|
||||
m_childView->Activate(event.GetActive());
|
||||
}
|
||||
|
||||
void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
// Close view but don't delete the frame while doing so!
|
||||
// ...since it will be deleted by wxWidgets if we return true.
|
||||
if (m_childView)
|
||||
{
|
||||
bool ans = event.CanVeto()
|
||||
? m_childView->Close(false) // false means don't delete associated window
|
||||
: true; // Must delete.
|
||||
|
||||
if (ans)
|
||||
{
|
||||
m_childView->Activate(false);
|
||||
delete m_childView;
|
||||
m_childView = (wxView *) NULL;
|
||||
m_childDocument = (wxDocument *) NULL;
|
||||
|
||||
this->Destroy();
|
||||
}
|
||||
else
|
||||
event.Veto();
|
||||
}
|
||||
else
|
||||
event.Veto();
|
||||
}
|
||||
|
||||
#endif
|
||||
// wxUSE_DOC_VIEW_ARCHITECTURE
|
||||
|
||||
|
4970
Externals/wxWidgets/src/common/docview.cpp
vendored
4970
Externals/wxWidgets/src/common/docview.cpp
vendored
File diff suppressed because it is too large
Load Diff
538
Externals/wxWidgets/src/common/dpycmn.cpp
vendored
538
Externals/wxWidgets/src/common/dpycmn.cpp
vendored
@ -1,269 +1,269 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dpycmn.cpp
|
||||
// Purpose: wxDisplay and wxDisplayImplSingle implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 01.03.03
|
||||
// RCS-ID: $Id: dpycmn.cpp 41548 2006-10-02 05:38:05Z PC $
|
||||
// Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/window.h"
|
||||
#include "wx/module.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/display.h"
|
||||
#include "wx/display_impl.h"
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
WX_DEFINE_OBJARRAY(wxArrayVideoModes)
|
||||
|
||||
const wxVideoMode wxDefaultVideoMode;
|
||||
|
||||
#endif // wxUSE_DISPLAY
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// globals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// the factory object used by wxDisplay
|
||||
//
|
||||
// created on demand and destroyed by wxDisplayModule
|
||||
static wxDisplayFactory *gs_factory = NULL;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayImplSingle: trivial implementation working for main display only
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
|
||||
{
|
||||
public:
|
||||
wxDisplayImplSingle() : wxDisplayImpl(0) { }
|
||||
|
||||
virtual wxRect GetGeometry() const
|
||||
{
|
||||
wxRect r;
|
||||
wxDisplaySize(&r.width, &r.height);
|
||||
return r;
|
||||
}
|
||||
|
||||
virtual wxRect GetClientArea() const { return wxGetClientDisplayRect(); }
|
||||
|
||||
virtual wxString GetName() const { return wxString(); }
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
// no video modes support for us, provide just the stubs
|
||||
|
||||
virtual wxArrayVideoModes GetModes(const wxVideoMode& WXUNUSED(mode)) const
|
||||
{
|
||||
return wxArrayVideoModes();
|
||||
}
|
||||
|
||||
virtual wxVideoMode GetCurrentMode() const { return wxVideoMode(); }
|
||||
|
||||
virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) { return false; }
|
||||
#endif // wxUSE_DISPLAY
|
||||
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxDisplayImplSingle)
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayModule is used to cleanup gs_factory
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDisplayModule : public wxModule
|
||||
{
|
||||
public:
|
||||
virtual bool OnInit() { return true; }
|
||||
virtual void OnExit()
|
||||
{
|
||||
if ( gs_factory )
|
||||
{
|
||||
delete gs_factory;
|
||||
gs_factory = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxDisplayModule)
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplay implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ctor/dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDisplay::wxDisplay(unsigned n)
|
||||
{
|
||||
wxASSERT_MSG( n < GetCount(),
|
||||
wxT("An invalid index was passed to wxDisplay") );
|
||||
|
||||
m_impl = Factory().CreateDisplay(n);
|
||||
}
|
||||
|
||||
wxDisplay::~wxDisplay()
|
||||
{
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// static functions forwarded to wxDisplayFactory
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/* static */ unsigned wxDisplay::GetCount()
|
||||
{
|
||||
return Factory().GetCount();
|
||||
}
|
||||
|
||||
/* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
|
||||
{
|
||||
return Factory().GetFromPoint(pt);
|
||||
}
|
||||
|
||||
/* static */ int wxDisplay::GetFromWindow(wxWindow *window)
|
||||
{
|
||||
wxCHECK_MSG( window, wxNOT_FOUND, _T("invalid window") );
|
||||
|
||||
return Factory().GetFromWindow(window);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// functions forwarded to wxDisplayImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxRect wxDisplay::GetGeometry() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetGeometry();
|
||||
}
|
||||
|
||||
wxRect wxDisplay::GetClientArea() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetClientArea();
|
||||
}
|
||||
|
||||
wxString wxDisplay::GetName() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetName();
|
||||
}
|
||||
|
||||
bool wxDisplay::IsPrimary() const
|
||||
{
|
||||
return m_impl && m_impl->GetIndex() == 0;
|
||||
}
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
|
||||
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetModes(mode);
|
||||
}
|
||||
|
||||
wxVideoMode wxDisplay::GetCurrentMode() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetCurrentMode();
|
||||
}
|
||||
|
||||
bool wxDisplay::ChangeMode(const wxVideoMode& mode)
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->ChangeMode(mode);
|
||||
}
|
||||
|
||||
#endif // wxUSE_DIRECTDRAW
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// static functions implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// if wxUSE_DISPLAY == 1 this is implemented in port-specific code
|
||||
#if !wxUSE_DISPLAY
|
||||
|
||||
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
|
||||
{
|
||||
return new wxDisplayFactorySingle;
|
||||
}
|
||||
|
||||
#endif // !wxUSE_DISPLAY
|
||||
|
||||
/* static */ wxDisplayFactory& wxDisplay::Factory()
|
||||
{
|
||||
if ( !gs_factory )
|
||||
{
|
||||
gs_factory = CreateFactory();
|
||||
}
|
||||
|
||||
return *gs_factory;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplayFactory implementation
|
||||
// ============================================================================
|
||||
|
||||
int wxDisplayFactory::GetFromWindow(wxWindow *window)
|
||||
{
|
||||
// consider that the window belongs to the display containing its centre
|
||||
const wxRect r(window->GetRect());
|
||||
return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplayFactorySingle implementation
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(unsigned n)
|
||||
{
|
||||
// we recognize the main display only
|
||||
return n != 0 ? NULL : new wxDisplayImplSingle;
|
||||
}
|
||||
|
||||
int wxDisplayFactorySingle::GetFromPoint(const wxPoint& pt)
|
||||
{
|
||||
if ( pt.x >= 0 && pt.y >= 0 )
|
||||
{
|
||||
int w, h;
|
||||
wxDisplaySize(&w, &h);
|
||||
|
||||
if ( pt.x < w && pt.y < h )
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the point is outside of the screen
|
||||
return wxNOT_FOUND;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dpycmn.cpp
|
||||
// Purpose: wxDisplay and wxDisplayImplSingle implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 01.03.03
|
||||
// RCS-ID: $Id: dpycmn.cpp 41548 2006-10-02 05:38:05Z PC $
|
||||
// Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/window.h"
|
||||
#include "wx/module.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/display.h"
|
||||
#include "wx/display_impl.h"
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
WX_DEFINE_OBJARRAY(wxArrayVideoModes)
|
||||
|
||||
const wxVideoMode wxDefaultVideoMode;
|
||||
|
||||
#endif // wxUSE_DISPLAY
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// globals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// the factory object used by wxDisplay
|
||||
//
|
||||
// created on demand and destroyed by wxDisplayModule
|
||||
static wxDisplayFactory *gs_factory = NULL;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayImplSingle: trivial implementation working for main display only
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
|
||||
{
|
||||
public:
|
||||
wxDisplayImplSingle() : wxDisplayImpl(0) { }
|
||||
|
||||
virtual wxRect GetGeometry() const
|
||||
{
|
||||
wxRect r;
|
||||
wxDisplaySize(&r.width, &r.height);
|
||||
return r;
|
||||
}
|
||||
|
||||
virtual wxRect GetClientArea() const { return wxGetClientDisplayRect(); }
|
||||
|
||||
virtual wxString GetName() const { return wxString(); }
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
// no video modes support for us, provide just the stubs
|
||||
|
||||
virtual wxArrayVideoModes GetModes(const wxVideoMode& WXUNUSED(mode)) const
|
||||
{
|
||||
return wxArrayVideoModes();
|
||||
}
|
||||
|
||||
virtual wxVideoMode GetCurrentMode() const { return wxVideoMode(); }
|
||||
|
||||
virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) { return false; }
|
||||
#endif // wxUSE_DISPLAY
|
||||
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxDisplayImplSingle)
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayModule is used to cleanup gs_factory
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDisplayModule : public wxModule
|
||||
{
|
||||
public:
|
||||
virtual bool OnInit() { return true; }
|
||||
virtual void OnExit()
|
||||
{
|
||||
if ( gs_factory )
|
||||
{
|
||||
delete gs_factory;
|
||||
gs_factory = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxDisplayModule)
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplay implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ctor/dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxDisplay::wxDisplay(unsigned n)
|
||||
{
|
||||
wxASSERT_MSG( n < GetCount(),
|
||||
wxT("An invalid index was passed to wxDisplay") );
|
||||
|
||||
m_impl = Factory().CreateDisplay(n);
|
||||
}
|
||||
|
||||
wxDisplay::~wxDisplay()
|
||||
{
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// static functions forwarded to wxDisplayFactory
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/* static */ unsigned wxDisplay::GetCount()
|
||||
{
|
||||
return Factory().GetCount();
|
||||
}
|
||||
|
||||
/* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
|
||||
{
|
||||
return Factory().GetFromPoint(pt);
|
||||
}
|
||||
|
||||
/* static */ int wxDisplay::GetFromWindow(wxWindow *window)
|
||||
{
|
||||
wxCHECK_MSG( window, wxNOT_FOUND, _T("invalid window") );
|
||||
|
||||
return Factory().GetFromWindow(window);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// functions forwarded to wxDisplayImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxRect wxDisplay::GetGeometry() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetGeometry();
|
||||
}
|
||||
|
||||
wxRect wxDisplay::GetClientArea() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetClientArea();
|
||||
}
|
||||
|
||||
wxString wxDisplay::GetName() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetName();
|
||||
}
|
||||
|
||||
bool wxDisplay::IsPrimary() const
|
||||
{
|
||||
return m_impl && m_impl->GetIndex() == 0;
|
||||
}
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
|
||||
wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetModes(mode);
|
||||
}
|
||||
|
||||
wxVideoMode wxDisplay::GetCurrentMode() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->GetCurrentMode();
|
||||
}
|
||||
|
||||
bool wxDisplay::ChangeMode(const wxVideoMode& mode)
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
|
||||
|
||||
return m_impl->ChangeMode(mode);
|
||||
}
|
||||
|
||||
#endif // wxUSE_DIRECTDRAW
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// static functions implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// if wxUSE_DISPLAY == 1 this is implemented in port-specific code
|
||||
#if !wxUSE_DISPLAY
|
||||
|
||||
/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
|
||||
{
|
||||
return new wxDisplayFactorySingle;
|
||||
}
|
||||
|
||||
#endif // !wxUSE_DISPLAY
|
||||
|
||||
/* static */ wxDisplayFactory& wxDisplay::Factory()
|
||||
{
|
||||
if ( !gs_factory )
|
||||
{
|
||||
gs_factory = CreateFactory();
|
||||
}
|
||||
|
||||
return *gs_factory;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplayFactory implementation
|
||||
// ============================================================================
|
||||
|
||||
int wxDisplayFactory::GetFromWindow(wxWindow *window)
|
||||
{
|
||||
// consider that the window belongs to the display containing its centre
|
||||
const wxRect r(window->GetRect());
|
||||
return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxDisplayFactorySingle implementation
|
||||
// ============================================================================
|
||||
|
||||
/* static */
|
||||
wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(unsigned n)
|
||||
{
|
||||
// we recognize the main display only
|
||||
return n != 0 ? NULL : new wxDisplayImplSingle;
|
||||
}
|
||||
|
||||
int wxDisplayFactorySingle::GetFromPoint(const wxPoint& pt)
|
||||
{
|
||||
if ( pt.x >= 0 && pt.y >= 0 )
|
||||
{
|
||||
int w, h;
|
||||
wxDisplaySize(&w, &h);
|
||||
|
||||
if ( pt.x < w && pt.y < h )
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the point is outside of the screen
|
||||
return wxNOT_FOUND;
|
||||
}
|
||||
|
110
Externals/wxWidgets/src/common/dseldlg.cpp
vendored
110
Externals/wxWidgets/src/common/dseldlg.cpp
vendored
@ -1,55 +1,55 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dseldlg.cpp
|
||||
// Purpose: implementation of ::wxDirSelector()
|
||||
// Author: Paul Thiessen
|
||||
// Modified by:
|
||||
// Created: 20.02.01
|
||||
// RCS-ID: $Id: dseldlg.cpp 39613 2006-06-07 11:44:19Z ABX $
|
||||
// Copyright: (c) 2001 wxWidgets team
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DIRDLG
|
||||
|
||||
#include "wx/dirdlg.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxString wxDirSelector(const wxString& message,
|
||||
const wxString& defaultPath,
|
||||
long style,
|
||||
const wxPoint& pos,
|
||||
wxWindow *parent)
|
||||
{
|
||||
wxString path;
|
||||
|
||||
wxDirDialog dirDialog(parent, message, defaultPath, style, pos);
|
||||
if ( dirDialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
path = dirDialog.GetPath();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif // wxUSE_DIRDLG
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dseldlg.cpp
|
||||
// Purpose: implementation of ::wxDirSelector()
|
||||
// Author: Paul Thiessen
|
||||
// Modified by:
|
||||
// Created: 20.02.01
|
||||
// RCS-ID: $Id: dseldlg.cpp 39613 2006-06-07 11:44:19Z ABX $
|
||||
// Copyright: (c) 2001 wxWidgets team
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DIRDLG
|
||||
|
||||
#include "wx/dirdlg.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxString wxDirSelector(const wxString& message,
|
||||
const wxString& defaultPath,
|
||||
long style,
|
||||
const wxPoint& pos,
|
||||
wxWindow *parent)
|
||||
{
|
||||
wxString path;
|
||||
|
||||
wxDirDialog dirDialog(parent, message, defaultPath, style, pos);
|
||||
if ( dirDialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
path = dirDialog.GetPath();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif // wxUSE_DIRDLG
|
||||
|
64
Externals/wxWidgets/src/common/dummy.cpp
vendored
64
Externals/wxWidgets/src/common/dummy.cpp
vendored
@ -1,32 +1,32 @@
|
||||
/*
|
||||
* File: src/common/dummy.cpp
|
||||
* Purpose: See below
|
||||
* Author: Julian Smart
|
||||
* Created: 1993
|
||||
* Updated:
|
||||
* Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
*/
|
||||
|
||||
/* A dummy file to include wx.h. If precompiling wx.h,
|
||||
* always start by compiling this and producing the PCH file.
|
||||
* Then subsequent source files use the PCH file.
|
||||
*
|
||||
* If precompiling wx.h for wxWidgets and derived apps,
|
||||
* link dummy.obj with your program.
|
||||
*
|
||||
* This will produce a big PCH file.
|
||||
*/
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#include "wx/msw/msvcrt.h"
|
||||
#endif
|
||||
|
||||
#ifdef __VISAGECPP__
|
||||
char wxDummyChar = 0;
|
||||
#endif
|
||||
/*
|
||||
* File: src/common/dummy.cpp
|
||||
* Purpose: See below
|
||||
* Author: Julian Smart
|
||||
* Created: 1993
|
||||
* Updated:
|
||||
* Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
*/
|
||||
|
||||
/* A dummy file to include wx.h. If precompiling wx.h,
|
||||
* always start by compiling this and producing the PCH file.
|
||||
* Then subsequent source files use the PCH file.
|
||||
*
|
||||
* If precompiling wx.h for wxWidgets and derived apps,
|
||||
* link dummy.obj with your program.
|
||||
*
|
||||
* This will produce a big PCH file.
|
||||
*/
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#include "wx/msw/msvcrt.h"
|
||||
#endif
|
||||
|
||||
#ifdef __VISAGECPP__
|
||||
char wxDummyChar = 0;
|
||||
#endif
|
||||
|
1054
Externals/wxWidgets/src/common/dynarray.cpp
vendored
1054
Externals/wxWidgets/src/common/dynarray.cpp
vendored
File diff suppressed because it is too large
Load Diff
646
Externals/wxWidgets/src/common/dynlib.cpp
vendored
646
Externals/wxWidgets/src/common/dynlib.cpp
vendored
@ -1,323 +1,323 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dynlib.cpp
|
||||
// Purpose: Dynamic library management
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 20/07/98
|
||||
// RCS-ID: $Id: dynlib.cpp 41807 2006-10-09 15:58:56Z VZ $
|
||||
// Copyright: (c) 1998 Guilhem Lavaux
|
||||
// 2000-2005 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//FIXME: This class isn't really common at all, it should be moved into
|
||||
// platform dependent files (already done for Windows and Unix)
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DYNLIB_CLASS
|
||||
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/utils.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/filename.h" // for SplitPath()
|
||||
#include "wx/platinfo.h"
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
#include "wx/mac/private.h"
|
||||
#endif
|
||||
|
||||
WX_DEFINE_USER_EXPORTED_OBJARRAY(wxDynamicLibraryDetailsArray)
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxDynamicLibrary
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#if defined(__WXPM__) || defined(__EMX__)
|
||||
const wxChar *wxDynamicLibrary::ms_dllext = _T(".dll");
|
||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
const wxChar *wxDynamicLibrary::ms_dllext = wxEmptyString;
|
||||
#endif
|
||||
|
||||
// for MSW/Unix it is defined in platform-specific file
|
||||
#if !(defined(__WXMSW__) || defined(__UNIX__)) || defined(__EMX__)
|
||||
|
||||
wxDllType wxDynamicLibrary::GetProgramHandle()
|
||||
{
|
||||
wxFAIL_MSG( wxT("GetProgramHandle() is not implemented under this platform"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // __WXMSW__ || __UNIX__
|
||||
|
||||
|
||||
bool wxDynamicLibrary::Load(const wxString& libnameOrig, int flags)
|
||||
{
|
||||
wxASSERT_MSG(m_handle == 0, _T("Library already loaded."));
|
||||
|
||||
// add the proper extension for the DLL ourselves unless told not to
|
||||
wxString libname = libnameOrig;
|
||||
if ( !(flags & wxDL_VERBATIM) )
|
||||
{
|
||||
// and also check that the libname doesn't already have it
|
||||
wxString ext;
|
||||
wxFileName::SplitPath(libname, NULL, NULL, &ext);
|
||||
if ( ext.empty() )
|
||||
{
|
||||
libname += GetDllExt();
|
||||
}
|
||||
}
|
||||
|
||||
// different ways to load a shared library
|
||||
//
|
||||
// FIXME: should go to the platform-specific files!
|
||||
#if defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
FSSpec myFSSpec;
|
||||
Ptr myMainAddr;
|
||||
Str255 myErrName;
|
||||
|
||||
wxMacFilename2FSSpec( libname , &myFSSpec );
|
||||
|
||||
if( GetDiskFragment( &myFSSpec,
|
||||
0,
|
||||
kCFragGoesToEOF,
|
||||
"\p",
|
||||
kPrivateCFragCopy,
|
||||
&m_handle,
|
||||
&myMainAddr,
|
||||
myErrName ) != noErr )
|
||||
{
|
||||
wxLogSysError( _("Failed to load shared library '%s' Error '%s'"),
|
||||
libname.c_str(),
|
||||
wxMacMakeStringFromPascal( myErrName ).c_str() );
|
||||
m_handle = 0;
|
||||
}
|
||||
|
||||
#elif defined(__WXPM__) || defined(__EMX__)
|
||||
char err[256] = "";
|
||||
DosLoadModule(err, sizeof(err), (PSZ)libname.c_str(), &m_handle);
|
||||
#else // this should be the only remaining branch eventually
|
||||
m_handle = RawLoad(libname, flags);
|
||||
#endif
|
||||
|
||||
if ( m_handle == 0 )
|
||||
{
|
||||
#ifdef wxHAVE_DYNLIB_ERROR
|
||||
Error();
|
||||
#else
|
||||
wxLogSysError(_("Failed to load shared library '%s'"), libname.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
return IsLoaded();
|
||||
}
|
||||
|
||||
// for MSW and Unix this is implemented in the platform-specific file
|
||||
//
|
||||
// TODO: move the rest to os2/dlpm.cpp and mac/dlmac.cpp!
|
||||
#if (!defined(__WXMSW__) && !defined(__UNIX__)) || defined(__EMX__)
|
||||
|
||||
/* static */
|
||||
void wxDynamicLibrary::Unload(wxDllType handle)
|
||||
{
|
||||
#if defined(__OS2__) || defined(__EMX__)
|
||||
DosFreeModule( handle );
|
||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
CloseConnection( (CFragConnectionID*) &handle );
|
||||
#else
|
||||
#error "runtime shared lib support not implemented"
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // !(__WXMSW__ || __UNIX__)
|
||||
|
||||
void *wxDynamicLibrary::DoGetSymbol(const wxString &name, bool *success) const
|
||||
{
|
||||
wxCHECK_MSG( IsLoaded(), NULL,
|
||||
_T("Can't load symbol from unloaded library") );
|
||||
|
||||
void *symbol = 0;
|
||||
|
||||
wxUnusedVar(symbol);
|
||||
#if defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
Ptr symAddress;
|
||||
CFragSymbolClass symClass;
|
||||
Str255 symName;
|
||||
#if TARGET_CARBON
|
||||
c2pstrcpy( (StringPtr) symName, name.fn_str() );
|
||||
#else
|
||||
strcpy( (char *)symName, name.fn_str() );
|
||||
c2pstr( (char *)symName );
|
||||
#endif
|
||||
if( FindSymbol( m_handle, symName, &symAddress, &symClass ) == noErr )
|
||||
symbol = (void *)symAddress;
|
||||
#elif defined(__WXPM__) || defined(__EMX__)
|
||||
DosQueryProcAddr( m_handle, 1L, (PSZ)name.c_str(), (PFN*)symbol );
|
||||
#else
|
||||
symbol = RawGetSymbol(m_handle, name);
|
||||
#endif
|
||||
|
||||
if ( success )
|
||||
*success = symbol != NULL;
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
void *wxDynamicLibrary::GetSymbol(const wxString& name, bool *success) const
|
||||
{
|
||||
void *symbol = DoGetSymbol(name, success);
|
||||
if ( !symbol )
|
||||
{
|
||||
#ifdef wxHAVE_DYNLIB_ERROR
|
||||
Error();
|
||||
#else
|
||||
wxLogSysError(_("Couldn't find symbol '%s' in a dynamic library"),
|
||||
name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// informational methods
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/
|
||||
wxString
|
||||
wxDynamicLibrary::CanonicalizeName(const wxString& name,
|
||||
wxDynamicLibraryCategory cat)
|
||||
{
|
||||
wxString nameCanonic;
|
||||
|
||||
// under Unix the library names usually start with "lib" prefix, add it
|
||||
#if defined(__UNIX__) && !defined(__EMX__)
|
||||
switch ( cat )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( _T("unknown wxDynamicLibraryCategory value") );
|
||||
// fall through
|
||||
|
||||
case wxDL_MODULE:
|
||||
// don't do anything for modules, their names are arbitrary
|
||||
break;
|
||||
|
||||
case wxDL_LIBRARY:
|
||||
// library names should start with "lib" under Unix
|
||||
nameCanonic = _T("lib");
|
||||
break;
|
||||
}
|
||||
#else // !__UNIX__
|
||||
wxUnusedVar(cat);
|
||||
#endif // __UNIX__/!__UNIX__
|
||||
|
||||
nameCanonic << name << GetDllExt();
|
||||
return nameCanonic;
|
||||
}
|
||||
|
||||
/*static*/
|
||||
wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name,
|
||||
wxPluginCategory cat)
|
||||
{
|
||||
wxString suffix;
|
||||
if ( cat == wxDL_PLUGIN_GUI )
|
||||
{
|
||||
suffix = wxPlatformInfo::Get().GetPortIdShortName();
|
||||
}
|
||||
#if wxUSE_UNICODE
|
||||
suffix << _T('u');
|
||||
#endif
|
||||
#ifdef __WXDEBUG__
|
||||
suffix << _T('d');
|
||||
#endif
|
||||
|
||||
if ( !suffix.empty() )
|
||||
suffix = wxString(_T("_")) + suffix;
|
||||
|
||||
#define WXSTRINGIZE(x) #x
|
||||
#if defined(__UNIX__) && !defined(__EMX__)
|
||||
#if (wxMINOR_VERSION % 2) == 0
|
||||
#define wxDLLVER(x,y,z) "-" WXSTRINGIZE(x) "." WXSTRINGIZE(y)
|
||||
#else
|
||||
#define wxDLLVER(x,y,z) "-" WXSTRINGIZE(x) "." WXSTRINGIZE(y) "." WXSTRINGIZE(z)
|
||||
#endif
|
||||
#else
|
||||
#if (wxMINOR_VERSION % 2) == 0
|
||||
#define wxDLLVER(x,y,z) WXSTRINGIZE(x) WXSTRINGIZE(y)
|
||||
#else
|
||||
#define wxDLLVER(x,y,z) WXSTRINGIZE(x) WXSTRINGIZE(y) WXSTRINGIZE(z)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
suffix << wxString::FromAscii(wxDLLVER(wxMAJOR_VERSION, wxMINOR_VERSION,
|
||||
wxRELEASE_NUMBER));
|
||||
#undef wxDLLVER
|
||||
#undef WXSTRINGIZE
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
// Add compiler identification:
|
||||
#if defined(__GNUG__)
|
||||
suffix << _T("_gcc");
|
||||
#elif defined(__VISUALC__)
|
||||
suffix << _T("_vc");
|
||||
#elif defined(__WATCOMC__)
|
||||
suffix << _T("_wat");
|
||||
#elif defined(__BORLANDC__)
|
||||
suffix << _T("_bcc");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return CanonicalizeName(name + suffix, wxDL_MODULE);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
wxString wxDynamicLibrary::GetPluginsDirectory()
|
||||
{
|
||||
#ifdef __UNIX__
|
||||
wxString format = wxGetInstallPrefix();
|
||||
wxString dir;
|
||||
format << wxFILE_SEP_PATH
|
||||
<< wxT("lib") << wxFILE_SEP_PATH
|
||||
<< wxT("wx") << wxFILE_SEP_PATH
|
||||
#if (wxMINOR_VERSION % 2) == 0
|
||||
<< wxT("%i.%i");
|
||||
dir.Printf(format.c_str(), wxMAJOR_VERSION, wxMINOR_VERSION);
|
||||
#else
|
||||
<< wxT("%i.%i.%i");
|
||||
dir.Printf(format.c_str(),
|
||||
wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER);
|
||||
#endif
|
||||
return dir;
|
||||
|
||||
#else // ! __UNIX__
|
||||
return wxEmptyString;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_DYNLIB_CLASS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dynlib.cpp
|
||||
// Purpose: Dynamic library management
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 20/07/98
|
||||
// RCS-ID: $Id: dynlib.cpp 41807 2006-10-09 15:58:56Z VZ $
|
||||
// Copyright: (c) 1998 Guilhem Lavaux
|
||||
// 2000-2005 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//FIXME: This class isn't really common at all, it should be moved into
|
||||
// platform dependent files (already done for Windows and Unix)
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DYNLIB_CLASS
|
||||
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/utils.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/filename.h" // for SplitPath()
|
||||
#include "wx/platinfo.h"
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
|
||||
#if defined(__WXMAC__)
|
||||
#include "wx/mac/private.h"
|
||||
#endif
|
||||
|
||||
WX_DEFINE_USER_EXPORTED_OBJARRAY(wxDynamicLibraryDetailsArray)
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxDynamicLibrary
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#if defined(__WXPM__) || defined(__EMX__)
|
||||
const wxChar *wxDynamicLibrary::ms_dllext = _T(".dll");
|
||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
const wxChar *wxDynamicLibrary::ms_dllext = wxEmptyString;
|
||||
#endif
|
||||
|
||||
// for MSW/Unix it is defined in platform-specific file
|
||||
#if !(defined(__WXMSW__) || defined(__UNIX__)) || defined(__EMX__)
|
||||
|
||||
wxDllType wxDynamicLibrary::GetProgramHandle()
|
||||
{
|
||||
wxFAIL_MSG( wxT("GetProgramHandle() is not implemented under this platform"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // __WXMSW__ || __UNIX__
|
||||
|
||||
|
||||
bool wxDynamicLibrary::Load(const wxString& libnameOrig, int flags)
|
||||
{
|
||||
wxASSERT_MSG(m_handle == 0, _T("Library already loaded."));
|
||||
|
||||
// add the proper extension for the DLL ourselves unless told not to
|
||||
wxString libname = libnameOrig;
|
||||
if ( !(flags & wxDL_VERBATIM) )
|
||||
{
|
||||
// and also check that the libname doesn't already have it
|
||||
wxString ext;
|
||||
wxFileName::SplitPath(libname, NULL, NULL, &ext);
|
||||
if ( ext.empty() )
|
||||
{
|
||||
libname += GetDllExt();
|
||||
}
|
||||
}
|
||||
|
||||
// different ways to load a shared library
|
||||
//
|
||||
// FIXME: should go to the platform-specific files!
|
||||
#if defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
FSSpec myFSSpec;
|
||||
Ptr myMainAddr;
|
||||
Str255 myErrName;
|
||||
|
||||
wxMacFilename2FSSpec( libname , &myFSSpec );
|
||||
|
||||
if( GetDiskFragment( &myFSSpec,
|
||||
0,
|
||||
kCFragGoesToEOF,
|
||||
"\p",
|
||||
kPrivateCFragCopy,
|
||||
&m_handle,
|
||||
&myMainAddr,
|
||||
myErrName ) != noErr )
|
||||
{
|
||||
wxLogSysError( _("Failed to load shared library '%s' Error '%s'"),
|
||||
libname.c_str(),
|
||||
wxMacMakeStringFromPascal( myErrName ).c_str() );
|
||||
m_handle = 0;
|
||||
}
|
||||
|
||||
#elif defined(__WXPM__) || defined(__EMX__)
|
||||
char err[256] = "";
|
||||
DosLoadModule(err, sizeof(err), (PSZ)libname.c_str(), &m_handle);
|
||||
#else // this should be the only remaining branch eventually
|
||||
m_handle = RawLoad(libname, flags);
|
||||
#endif
|
||||
|
||||
if ( m_handle == 0 )
|
||||
{
|
||||
#ifdef wxHAVE_DYNLIB_ERROR
|
||||
Error();
|
||||
#else
|
||||
wxLogSysError(_("Failed to load shared library '%s'"), libname.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
return IsLoaded();
|
||||
}
|
||||
|
||||
// for MSW and Unix this is implemented in the platform-specific file
|
||||
//
|
||||
// TODO: move the rest to os2/dlpm.cpp and mac/dlmac.cpp!
|
||||
#if (!defined(__WXMSW__) && !defined(__UNIX__)) || defined(__EMX__)
|
||||
|
||||
/* static */
|
||||
void wxDynamicLibrary::Unload(wxDllType handle)
|
||||
{
|
||||
#if defined(__OS2__) || defined(__EMX__)
|
||||
DosFreeModule( handle );
|
||||
#elif defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
CloseConnection( (CFragConnectionID*) &handle );
|
||||
#else
|
||||
#error "runtime shared lib support not implemented"
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // !(__WXMSW__ || __UNIX__)
|
||||
|
||||
void *wxDynamicLibrary::DoGetSymbol(const wxString &name, bool *success) const
|
||||
{
|
||||
wxCHECK_MSG( IsLoaded(), NULL,
|
||||
_T("Can't load symbol from unloaded library") );
|
||||
|
||||
void *symbol = 0;
|
||||
|
||||
wxUnusedVar(symbol);
|
||||
#if defined(__WXMAC__) && !defined(__DARWIN__)
|
||||
Ptr symAddress;
|
||||
CFragSymbolClass symClass;
|
||||
Str255 symName;
|
||||
#if TARGET_CARBON
|
||||
c2pstrcpy( (StringPtr) symName, name.fn_str() );
|
||||
#else
|
||||
strcpy( (char *)symName, name.fn_str() );
|
||||
c2pstr( (char *)symName );
|
||||
#endif
|
||||
if( FindSymbol( m_handle, symName, &symAddress, &symClass ) == noErr )
|
||||
symbol = (void *)symAddress;
|
||||
#elif defined(__WXPM__) || defined(__EMX__)
|
||||
DosQueryProcAddr( m_handle, 1L, (PSZ)name.c_str(), (PFN*)symbol );
|
||||
#else
|
||||
symbol = RawGetSymbol(m_handle, name);
|
||||
#endif
|
||||
|
||||
if ( success )
|
||||
*success = symbol != NULL;
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
void *wxDynamicLibrary::GetSymbol(const wxString& name, bool *success) const
|
||||
{
|
||||
void *symbol = DoGetSymbol(name, success);
|
||||
if ( !symbol )
|
||||
{
|
||||
#ifdef wxHAVE_DYNLIB_ERROR
|
||||
Error();
|
||||
#else
|
||||
wxLogSysError(_("Couldn't find symbol '%s' in a dynamic library"),
|
||||
name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// informational methods
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*static*/
|
||||
wxString
|
||||
wxDynamicLibrary::CanonicalizeName(const wxString& name,
|
||||
wxDynamicLibraryCategory cat)
|
||||
{
|
||||
wxString nameCanonic;
|
||||
|
||||
// under Unix the library names usually start with "lib" prefix, add it
|
||||
#if defined(__UNIX__) && !defined(__EMX__)
|
||||
switch ( cat )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( _T("unknown wxDynamicLibraryCategory value") );
|
||||
// fall through
|
||||
|
||||
case wxDL_MODULE:
|
||||
// don't do anything for modules, their names are arbitrary
|
||||
break;
|
||||
|
||||
case wxDL_LIBRARY:
|
||||
// library names should start with "lib" under Unix
|
||||
nameCanonic = _T("lib");
|
||||
break;
|
||||
}
|
||||
#else // !__UNIX__
|
||||
wxUnusedVar(cat);
|
||||
#endif // __UNIX__/!__UNIX__
|
||||
|
||||
nameCanonic << name << GetDllExt();
|
||||
return nameCanonic;
|
||||
}
|
||||
|
||||
/*static*/
|
||||
wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name,
|
||||
wxPluginCategory cat)
|
||||
{
|
||||
wxString suffix;
|
||||
if ( cat == wxDL_PLUGIN_GUI )
|
||||
{
|
||||
suffix = wxPlatformInfo::Get().GetPortIdShortName();
|
||||
}
|
||||
#if wxUSE_UNICODE
|
||||
suffix << _T('u');
|
||||
#endif
|
||||
#ifdef __WXDEBUG__
|
||||
suffix << _T('d');
|
||||
#endif
|
||||
|
||||
if ( !suffix.empty() )
|
||||
suffix = wxString(_T("_")) + suffix;
|
||||
|
||||
#define WXSTRINGIZE(x) #x
|
||||
#if defined(__UNIX__) && !defined(__EMX__)
|
||||
#if (wxMINOR_VERSION % 2) == 0
|
||||
#define wxDLLVER(x,y,z) "-" WXSTRINGIZE(x) "." WXSTRINGIZE(y)
|
||||
#else
|
||||
#define wxDLLVER(x,y,z) "-" WXSTRINGIZE(x) "." WXSTRINGIZE(y) "." WXSTRINGIZE(z)
|
||||
#endif
|
||||
#else
|
||||
#if (wxMINOR_VERSION % 2) == 0
|
||||
#define wxDLLVER(x,y,z) WXSTRINGIZE(x) WXSTRINGIZE(y)
|
||||
#else
|
||||
#define wxDLLVER(x,y,z) WXSTRINGIZE(x) WXSTRINGIZE(y) WXSTRINGIZE(z)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
suffix << wxString::FromAscii(wxDLLVER(wxMAJOR_VERSION, wxMINOR_VERSION,
|
||||
wxRELEASE_NUMBER));
|
||||
#undef wxDLLVER
|
||||
#undef WXSTRINGIZE
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
// Add compiler identification:
|
||||
#if defined(__GNUG__)
|
||||
suffix << _T("_gcc");
|
||||
#elif defined(__VISUALC__)
|
||||
suffix << _T("_vc");
|
||||
#elif defined(__WATCOMC__)
|
||||
suffix << _T("_wat");
|
||||
#elif defined(__BORLANDC__)
|
||||
suffix << _T("_bcc");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return CanonicalizeName(name + suffix, wxDL_MODULE);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
wxString wxDynamicLibrary::GetPluginsDirectory()
|
||||
{
|
||||
#ifdef __UNIX__
|
||||
wxString format = wxGetInstallPrefix();
|
||||
wxString dir;
|
||||
format << wxFILE_SEP_PATH
|
||||
<< wxT("lib") << wxFILE_SEP_PATH
|
||||
<< wxT("wx") << wxFILE_SEP_PATH
|
||||
#if (wxMINOR_VERSION % 2) == 0
|
||||
<< wxT("%i.%i");
|
||||
dir.Printf(format.c_str(), wxMAJOR_VERSION, wxMINOR_VERSION);
|
||||
#else
|
||||
<< wxT("%i.%i.%i");
|
||||
dir.Printf(format.c_str(),
|
||||
wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER);
|
||||
#endif
|
||||
return dir;
|
||||
|
||||
#else // ! __UNIX__
|
||||
return wxEmptyString;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_DYNLIB_CLASS
|
||||
|
724
Externals/wxWidgets/src/common/dynload.cpp
vendored
724
Externals/wxWidgets/src/common/dynload.cpp
vendored
@ -1,362 +1,362 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dynload.cpp
|
||||
// Purpose: Dynamic loading framework
|
||||
// Author: Ron Lee, David Falkinder, Vadim Zeitlin and a cast of 1000's
|
||||
// (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux)
|
||||
// Modified by:
|
||||
// Created: 03/12/01
|
||||
// RCS-ID: $Id: dynload.cpp 40943 2006-08-31 19:31:43Z ABX $
|
||||
// Copyright: (c) 2001 Ron Lee <ron@debian.org>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DYNAMIC_LOADER
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/private.h"
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/hash.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
#include "wx/strconv.h"
|
||||
|
||||
#include "wx/dynload.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxPluginLibrary
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxDLImports* wxPluginLibrary::ms_classes = NULL;
|
||||
|
||||
class wxPluginLibraryModule : public wxModule
|
||||
{
|
||||
public:
|
||||
wxPluginLibraryModule() { }
|
||||
|
||||
// TODO: create ms_classes on demand, why always preallocate it?
|
||||
virtual bool OnInit()
|
||||
{
|
||||
wxPluginLibrary::ms_classes = new wxDLImports;
|
||||
wxPluginManager::CreateManifest();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnExit()
|
||||
{
|
||||
delete wxPluginLibrary::ms_classes;
|
||||
wxPluginLibrary::ms_classes = NULL;
|
||||
wxPluginManager::ClearManifest();
|
||||
}
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxPluginLibraryModule )
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPluginLibraryModule, wxModule)
|
||||
|
||||
|
||||
wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags)
|
||||
: m_linkcount(1)
|
||||
, m_objcount(0)
|
||||
{
|
||||
m_before = wxClassInfo::sm_first;
|
||||
Load( libname, flags );
|
||||
m_after = wxClassInfo::sm_first;
|
||||
|
||||
if( m_handle != 0 )
|
||||
{
|
||||
UpdateClasses();
|
||||
RegisterModules();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Flag us for deletion
|
||||
--m_linkcount;
|
||||
}
|
||||
}
|
||||
|
||||
wxPluginLibrary::~wxPluginLibrary()
|
||||
{
|
||||
if( m_handle != 0 )
|
||||
{
|
||||
UnregisterModules();
|
||||
RestoreClasses();
|
||||
}
|
||||
}
|
||||
|
||||
wxPluginLibrary *wxPluginLibrary::RefLib()
|
||||
{
|
||||
wxCHECK_MSG( m_linkcount > 0, NULL,
|
||||
_T("Library had been already deleted!") );
|
||||
|
||||
++m_linkcount;
|
||||
return this;
|
||||
}
|
||||
|
||||
bool wxPluginLibrary::UnrefLib()
|
||||
{
|
||||
wxASSERT_MSG( m_objcount == 0,
|
||||
_T("Library unloaded before all objects were destroyed") );
|
||||
|
||||
if ( m_linkcount == 0 || --m_linkcount == 0 )
|
||||
{
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Private methods
|
||||
// ------------------------
|
||||
|
||||
void wxPluginLibrary::UpdateClasses()
|
||||
{
|
||||
for (wxClassInfo *info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
if( info->GetClassName() )
|
||||
{
|
||||
// Hash all the class names into a local table too so
|
||||
// we can quickly find the entry they correspond to.
|
||||
(*ms_classes)[info->GetClassName()] = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxPluginLibrary::RestoreClasses()
|
||||
{
|
||||
// Check if there is a need to restore classes.
|
||||
if (!ms_classes)
|
||||
return;
|
||||
|
||||
for(wxClassInfo *info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
ms_classes->erase(ms_classes->find(info->GetClassName()));
|
||||
}
|
||||
}
|
||||
|
||||
void wxPluginLibrary::RegisterModules()
|
||||
{
|
||||
// Plugin libraries might have wxModules, Register and initialise them if
|
||||
// they do.
|
||||
//
|
||||
// Note that these classes are NOT included in the reference counting since
|
||||
// it's implicit that they will be unloaded if and when the last handle to
|
||||
// the library is. We do have to keep a copy of the module's pointer
|
||||
// though, as there is currently no way to Unregister it without it.
|
||||
|
||||
wxASSERT_MSG( m_linkcount == 1,
|
||||
_T("RegisterModules should only be called for the first load") );
|
||||
|
||||
for ( wxClassInfo *info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
if( info->IsKindOf(CLASSINFO(wxModule)) )
|
||||
{
|
||||
wxModule *m = wxDynamicCast(info->CreateObject(), wxModule);
|
||||
|
||||
wxASSERT_MSG( m, _T("wxDynamicCast of wxModule failed") );
|
||||
|
||||
m_wxmodules.push_back(m);
|
||||
wxModule::RegisterModule(m);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Likewise this is (well was) very similar to InitializeModules()
|
||||
|
||||
for ( wxModuleList::iterator it = m_wxmodules.begin();
|
||||
it != m_wxmodules.end();
|
||||
++it)
|
||||
{
|
||||
if( !(*it)->Init() )
|
||||
{
|
||||
wxLogDebug(_T("wxModule::Init() failed for wxPluginLibrary"));
|
||||
|
||||
// XXX: Watch this, a different hash implementation might break it,
|
||||
// a good hash implementation would let us fix it though.
|
||||
|
||||
// The name of the game is to remove any uninitialised modules and
|
||||
// let the dtor Exit the rest on shutdown, (which we'll initiate
|
||||
// shortly).
|
||||
|
||||
wxModuleList::iterator oldNode = m_wxmodules.end();
|
||||
do {
|
||||
++it;
|
||||
if( oldNode != m_wxmodules.end() )
|
||||
m_wxmodules.erase(oldNode);
|
||||
wxModule::UnregisterModule( *it );
|
||||
oldNode = it;
|
||||
} while( it != m_wxmodules.end() );
|
||||
|
||||
--m_linkcount; // Flag us for deletion
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxPluginLibrary::UnregisterModules()
|
||||
{
|
||||
wxModuleList::iterator it;
|
||||
|
||||
for ( it = m_wxmodules.begin(); it != m_wxmodules.end(); ++it )
|
||||
(*it)->Exit();
|
||||
|
||||
for ( it = m_wxmodules.begin(); it != m_wxmodules.end(); ++it )
|
||||
wxModule::UnregisterModule( *it );
|
||||
|
||||
// NB: content of the list was deleted by UnregisterModule calls above:
|
||||
m_wxmodules.clear();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxPluginManager
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxDLManifest* wxPluginManager::ms_manifest = NULL;
|
||||
|
||||
// ------------------------
|
||||
// Static accessors
|
||||
// ------------------------
|
||||
|
||||
wxPluginLibrary *
|
||||
wxPluginManager::LoadLibrary(const wxString &libname, int flags)
|
||||
{
|
||||
wxString realname(libname);
|
||||
|
||||
if( !(flags & wxDL_VERBATIM) )
|
||||
realname += wxDynamicLibrary::GetDllExt();
|
||||
|
||||
wxPluginLibrary *entry;
|
||||
|
||||
if ( flags & wxDL_NOSHARE )
|
||||
{
|
||||
entry = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = FindByName(realname);
|
||||
}
|
||||
|
||||
if ( entry )
|
||||
{
|
||||
wxLogTrace(_T("dll"),
|
||||
_T("LoadLibrary(%s): already loaded."), realname.c_str());
|
||||
|
||||
entry->RefLib();
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = new wxPluginLibrary( libname, flags );
|
||||
|
||||
if ( entry->IsLoaded() )
|
||||
{
|
||||
(*ms_manifest)[realname] = entry;
|
||||
|
||||
wxLogTrace(_T("dll"),
|
||||
_T("LoadLibrary(%s): loaded ok."), realname.c_str());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogTrace(_T("dll"),
|
||||
_T("LoadLibrary(%s): failed to load."), realname.c_str());
|
||||
|
||||
// we have created entry just above
|
||||
if ( !entry->UnrefLib() )
|
||||
{
|
||||
// ... so UnrefLib() is supposed to delete it
|
||||
wxFAIL_MSG( _T("Currently linked library is not loaded?") );
|
||||
}
|
||||
|
||||
entry = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
bool wxPluginManager::UnloadLibrary(const wxString& libname)
|
||||
{
|
||||
wxString realname = libname;
|
||||
|
||||
wxPluginLibrary *entry = FindByName(realname);
|
||||
|
||||
if ( !entry )
|
||||
{
|
||||
realname += wxDynamicLibrary::GetDllExt();
|
||||
|
||||
entry = FindByName(realname);
|
||||
}
|
||||
|
||||
if ( !entry )
|
||||
{
|
||||
wxLogDebug(_T("Attempt to unload library '%s' which is not loaded."),
|
||||
libname.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
wxLogTrace(_T("dll"), _T("UnloadLibrary(%s)"), realname.c_str());
|
||||
|
||||
if ( !entry->UnrefLib() )
|
||||
{
|
||||
// not really unloaded yet
|
||||
return false;
|
||||
}
|
||||
|
||||
ms_manifest->erase(ms_manifest->find(realname));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Class implementation
|
||||
// ------------------------
|
||||
|
||||
bool wxPluginManager::Load(const wxString &libname, int flags)
|
||||
{
|
||||
m_entry = wxPluginManager::LoadLibrary(libname, flags);
|
||||
|
||||
return IsLoaded();
|
||||
}
|
||||
|
||||
void wxPluginManager::Unload()
|
||||
{
|
||||
wxCHECK_RET( m_entry, _T("unloading an invalid wxPluginManager?") );
|
||||
|
||||
for ( wxDLManifest::iterator i = ms_manifest->begin();
|
||||
i != ms_manifest->end();
|
||||
++i )
|
||||
{
|
||||
if ( i->second == m_entry )
|
||||
{
|
||||
ms_manifest->erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_entry->UnrefLib();
|
||||
|
||||
m_entry = NULL;
|
||||
}
|
||||
|
||||
#endif // wxUSE_DYNAMIC_LOADER
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/dynload.cpp
|
||||
// Purpose: Dynamic loading framework
|
||||
// Author: Ron Lee, David Falkinder, Vadim Zeitlin and a cast of 1000's
|
||||
// (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux)
|
||||
// Modified by:
|
||||
// Created: 03/12/01
|
||||
// RCS-ID: $Id: dynload.cpp 40943 2006-08-31 19:31:43Z ABX $
|
||||
// Copyright: (c) 2001 Ron Lee <ron@debian.org>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_DYNAMIC_LOADER
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/private.h"
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/hash.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
#include "wx/strconv.h"
|
||||
|
||||
#include "wx/dynload.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxPluginLibrary
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxDLImports* wxPluginLibrary::ms_classes = NULL;
|
||||
|
||||
class wxPluginLibraryModule : public wxModule
|
||||
{
|
||||
public:
|
||||
wxPluginLibraryModule() { }
|
||||
|
||||
// TODO: create ms_classes on demand, why always preallocate it?
|
||||
virtual bool OnInit()
|
||||
{
|
||||
wxPluginLibrary::ms_classes = new wxDLImports;
|
||||
wxPluginManager::CreateManifest();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnExit()
|
||||
{
|
||||
delete wxPluginLibrary::ms_classes;
|
||||
wxPluginLibrary::ms_classes = NULL;
|
||||
wxPluginManager::ClearManifest();
|
||||
}
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxPluginLibraryModule )
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPluginLibraryModule, wxModule)
|
||||
|
||||
|
||||
wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags)
|
||||
: m_linkcount(1)
|
||||
, m_objcount(0)
|
||||
{
|
||||
m_before = wxClassInfo::sm_first;
|
||||
Load( libname, flags );
|
||||
m_after = wxClassInfo::sm_first;
|
||||
|
||||
if( m_handle != 0 )
|
||||
{
|
||||
UpdateClasses();
|
||||
RegisterModules();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Flag us for deletion
|
||||
--m_linkcount;
|
||||
}
|
||||
}
|
||||
|
||||
wxPluginLibrary::~wxPluginLibrary()
|
||||
{
|
||||
if( m_handle != 0 )
|
||||
{
|
||||
UnregisterModules();
|
||||
RestoreClasses();
|
||||
}
|
||||
}
|
||||
|
||||
wxPluginLibrary *wxPluginLibrary::RefLib()
|
||||
{
|
||||
wxCHECK_MSG( m_linkcount > 0, NULL,
|
||||
_T("Library had been already deleted!") );
|
||||
|
||||
++m_linkcount;
|
||||
return this;
|
||||
}
|
||||
|
||||
bool wxPluginLibrary::UnrefLib()
|
||||
{
|
||||
wxASSERT_MSG( m_objcount == 0,
|
||||
_T("Library unloaded before all objects were destroyed") );
|
||||
|
||||
if ( m_linkcount == 0 || --m_linkcount == 0 )
|
||||
{
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Private methods
|
||||
// ------------------------
|
||||
|
||||
void wxPluginLibrary::UpdateClasses()
|
||||
{
|
||||
for (wxClassInfo *info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
if( info->GetClassName() )
|
||||
{
|
||||
// Hash all the class names into a local table too so
|
||||
// we can quickly find the entry they correspond to.
|
||||
(*ms_classes)[info->GetClassName()] = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxPluginLibrary::RestoreClasses()
|
||||
{
|
||||
// Check if there is a need to restore classes.
|
||||
if (!ms_classes)
|
||||
return;
|
||||
|
||||
for(wxClassInfo *info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
ms_classes->erase(ms_classes->find(info->GetClassName()));
|
||||
}
|
||||
}
|
||||
|
||||
void wxPluginLibrary::RegisterModules()
|
||||
{
|
||||
// Plugin libraries might have wxModules, Register and initialise them if
|
||||
// they do.
|
||||
//
|
||||
// Note that these classes are NOT included in the reference counting since
|
||||
// it's implicit that they will be unloaded if and when the last handle to
|
||||
// the library is. We do have to keep a copy of the module's pointer
|
||||
// though, as there is currently no way to Unregister it without it.
|
||||
|
||||
wxASSERT_MSG( m_linkcount == 1,
|
||||
_T("RegisterModules should only be called for the first load") );
|
||||
|
||||
for ( wxClassInfo *info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
if( info->IsKindOf(CLASSINFO(wxModule)) )
|
||||
{
|
||||
wxModule *m = wxDynamicCast(info->CreateObject(), wxModule);
|
||||
|
||||
wxASSERT_MSG( m, _T("wxDynamicCast of wxModule failed") );
|
||||
|
||||
m_wxmodules.push_back(m);
|
||||
wxModule::RegisterModule(m);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Likewise this is (well was) very similar to InitializeModules()
|
||||
|
||||
for ( wxModuleList::iterator it = m_wxmodules.begin();
|
||||
it != m_wxmodules.end();
|
||||
++it)
|
||||
{
|
||||
if( !(*it)->Init() )
|
||||
{
|
||||
wxLogDebug(_T("wxModule::Init() failed for wxPluginLibrary"));
|
||||
|
||||
// XXX: Watch this, a different hash implementation might break it,
|
||||
// a good hash implementation would let us fix it though.
|
||||
|
||||
// The name of the game is to remove any uninitialised modules and
|
||||
// let the dtor Exit the rest on shutdown, (which we'll initiate
|
||||
// shortly).
|
||||
|
||||
wxModuleList::iterator oldNode = m_wxmodules.end();
|
||||
do {
|
||||
++it;
|
||||
if( oldNode != m_wxmodules.end() )
|
||||
m_wxmodules.erase(oldNode);
|
||||
wxModule::UnregisterModule( *it );
|
||||
oldNode = it;
|
||||
} while( it != m_wxmodules.end() );
|
||||
|
||||
--m_linkcount; // Flag us for deletion
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxPluginLibrary::UnregisterModules()
|
||||
{
|
||||
wxModuleList::iterator it;
|
||||
|
||||
for ( it = m_wxmodules.begin(); it != m_wxmodules.end(); ++it )
|
||||
(*it)->Exit();
|
||||
|
||||
for ( it = m_wxmodules.begin(); it != m_wxmodules.end(); ++it )
|
||||
wxModule::UnregisterModule( *it );
|
||||
|
||||
// NB: content of the list was deleted by UnregisterModule calls above:
|
||||
m_wxmodules.clear();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxPluginManager
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxDLManifest* wxPluginManager::ms_manifest = NULL;
|
||||
|
||||
// ------------------------
|
||||
// Static accessors
|
||||
// ------------------------
|
||||
|
||||
wxPluginLibrary *
|
||||
wxPluginManager::LoadLibrary(const wxString &libname, int flags)
|
||||
{
|
||||
wxString realname(libname);
|
||||
|
||||
if( !(flags & wxDL_VERBATIM) )
|
||||
realname += wxDynamicLibrary::GetDllExt();
|
||||
|
||||
wxPluginLibrary *entry;
|
||||
|
||||
if ( flags & wxDL_NOSHARE )
|
||||
{
|
||||
entry = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = FindByName(realname);
|
||||
}
|
||||
|
||||
if ( entry )
|
||||
{
|
||||
wxLogTrace(_T("dll"),
|
||||
_T("LoadLibrary(%s): already loaded."), realname.c_str());
|
||||
|
||||
entry->RefLib();
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = new wxPluginLibrary( libname, flags );
|
||||
|
||||
if ( entry->IsLoaded() )
|
||||
{
|
||||
(*ms_manifest)[realname] = entry;
|
||||
|
||||
wxLogTrace(_T("dll"),
|
||||
_T("LoadLibrary(%s): loaded ok."), realname.c_str());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogTrace(_T("dll"),
|
||||
_T("LoadLibrary(%s): failed to load."), realname.c_str());
|
||||
|
||||
// we have created entry just above
|
||||
if ( !entry->UnrefLib() )
|
||||
{
|
||||
// ... so UnrefLib() is supposed to delete it
|
||||
wxFAIL_MSG( _T("Currently linked library is not loaded?") );
|
||||
}
|
||||
|
||||
entry = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
bool wxPluginManager::UnloadLibrary(const wxString& libname)
|
||||
{
|
||||
wxString realname = libname;
|
||||
|
||||
wxPluginLibrary *entry = FindByName(realname);
|
||||
|
||||
if ( !entry )
|
||||
{
|
||||
realname += wxDynamicLibrary::GetDllExt();
|
||||
|
||||
entry = FindByName(realname);
|
||||
}
|
||||
|
||||
if ( !entry )
|
||||
{
|
||||
wxLogDebug(_T("Attempt to unload library '%s' which is not loaded."),
|
||||
libname.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
wxLogTrace(_T("dll"), _T("UnloadLibrary(%s)"), realname.c_str());
|
||||
|
||||
if ( !entry->UnrefLib() )
|
||||
{
|
||||
// not really unloaded yet
|
||||
return false;
|
||||
}
|
||||
|
||||
ms_manifest->erase(ms_manifest->find(realname));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Class implementation
|
||||
// ------------------------
|
||||
|
||||
bool wxPluginManager::Load(const wxString &libname, int flags)
|
||||
{
|
||||
m_entry = wxPluginManager::LoadLibrary(libname, flags);
|
||||
|
||||
return IsLoaded();
|
||||
}
|
||||
|
||||
void wxPluginManager::Unload()
|
||||
{
|
||||
wxCHECK_RET( m_entry, _T("unloading an invalid wxPluginManager?") );
|
||||
|
||||
for ( wxDLManifest::iterator i = ms_manifest->begin();
|
||||
i != ms_manifest->end();
|
||||
++i )
|
||||
{
|
||||
if ( i->second == m_entry )
|
||||
{
|
||||
ms_manifest->erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_entry->UnrefLib();
|
||||
|
||||
m_entry = NULL;
|
||||
}
|
||||
|
||||
#endif // wxUSE_DYNAMIC_LOADER
|
||||
|
248
Externals/wxWidgets/src/common/effects.cpp
vendored
248
Externals/wxWidgets/src/common/effects.cpp
vendored
@ -1,124 +1,124 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/effects.cpp
|
||||
// Purpose: wxEffects implementation
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/4/2000
|
||||
// RCS-ID: $Id: effects.cpp 42755 2006-10-30 19:41:46Z VZ $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/effects.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dcmemory.h"
|
||||
#include "wx/pen.h"
|
||||
#include "wx/settings.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
/*
|
||||
* wxEffects: various 3D effects
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxEffects, wxObject)
|
||||
|
||||
// Assume system colours
|
||||
wxEffects::wxEffects()
|
||||
{
|
||||
m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT) ;
|
||||
m_lightShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT) ;
|
||||
m_faceColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) ;
|
||||
m_mediumShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ;
|
||||
m_darkShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW) ;
|
||||
}
|
||||
|
||||
// Going from lightest to darkest
|
||||
wxEffects::wxEffects(const wxColour& highlightColour, const wxColour& lightShadow,
|
||||
const wxColour& faceColour, const wxColour& mediumShadow, const wxColour& darkShadow)
|
||||
{
|
||||
m_highlightColour = highlightColour;
|
||||
m_lightShadow = lightShadow;
|
||||
m_faceColour = faceColour;
|
||||
m_mediumShadow = mediumShadow;
|
||||
m_darkShadow = darkShadow;
|
||||
}
|
||||
|
||||
// Draw a sunken edge
|
||||
void wxEffects::DrawSunkenEdge(wxDC& dc, const wxRect& rect, int WXUNUSED(borderSize))
|
||||
{
|
||||
wxPen highlightPen(m_highlightColour, 1, wxSOLID);
|
||||
wxPen lightShadowPen(m_lightShadow, 1, wxSOLID);
|
||||
wxPen facePen(m_faceColour, 1, wxSOLID);
|
||||
wxPen mediumShadowPen(m_mediumShadow, 1, wxSOLID);
|
||||
wxPen darkShadowPen(m_darkShadow, 1, wxSOLID);
|
||||
|
||||
//// LEFT AND TOP
|
||||
// Draw a medium shadow pen on left and top, followed by dark shadow line to
|
||||
// right and below of these lines
|
||||
|
||||
dc.SetPen(mediumShadowPen);
|
||||
dc.DrawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y); // Top
|
||||
dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1); // Left
|
||||
|
||||
dc.SetPen(darkShadowPen);
|
||||
dc.DrawLine(rect.x+1, rect.y+1, rect.x+rect.width-2, rect.y+1); // Top
|
||||
dc.DrawLine(rect.x+1, rect.y+1, rect.x+1, rect.y+rect.height-1); // Left
|
||||
|
||||
//// RIGHT AND BOTTOM
|
||||
|
||||
dc.SetPen(highlightPen);
|
||||
dc.DrawLine(rect.x+rect.width-1, rect.y, rect.x+rect.width-1, rect.y+rect.height-1); // Right
|
||||
dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1); // Bottom
|
||||
|
||||
dc.SetPen(lightShadowPen);
|
||||
dc.DrawLine(rect.x+rect.width-2, rect.y+1, rect.x+rect.width-2, rect.y+rect.height-2); // Right
|
||||
dc.DrawLine(rect.x+1, rect.y+rect.height-2, rect.x+rect.width-1, rect.y+rect.height-2); // Bottom
|
||||
|
||||
dc.SetPen(wxNullPen);
|
||||
}
|
||||
|
||||
bool wxEffects::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap)
|
||||
{
|
||||
int w = bitmap.GetWidth();
|
||||
int h = bitmap.GetHeight();
|
||||
|
||||
wxMemoryDC dcMem;
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
static bool hiColour = (wxDisplayDepth() >= 16) ;
|
||||
if (bitmap.GetPalette() && !hiColour)
|
||||
{
|
||||
dc.SetPalette(* bitmap.GetPalette());
|
||||
dcMem.SetPalette(* bitmap.GetPalette());
|
||||
}
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
dcMem.SelectObjectAsSource(bitmap);
|
||||
|
||||
int i, j;
|
||||
for (i = rect.x; i < rect.x + rect.width; i += w)
|
||||
{
|
||||
for (j = rect.y; j < rect.y + rect.height; j+= h)
|
||||
dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
|
||||
}
|
||||
dcMem.SelectObject(wxNullBitmap);
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
if (bitmap.GetPalette() && !hiColour)
|
||||
{
|
||||
dc.SetPalette(wxNullPalette);
|
||||
dcMem.SetPalette(wxNullPalette);
|
||||
}
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
return true;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/effects.cpp
|
||||
// Purpose: wxEffects implementation
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/4/2000
|
||||
// RCS-ID: $Id: effects.cpp 42755 2006-10-30 19:41:46Z VZ $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/effects.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dcmemory.h"
|
||||
#include "wx/pen.h"
|
||||
#include "wx/settings.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
/*
|
||||
* wxEffects: various 3D effects
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxEffects, wxObject)
|
||||
|
||||
// Assume system colours
|
||||
wxEffects::wxEffects()
|
||||
{
|
||||
m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT) ;
|
||||
m_lightShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT) ;
|
||||
m_faceColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) ;
|
||||
m_mediumShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ;
|
||||
m_darkShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW) ;
|
||||
}
|
||||
|
||||
// Going from lightest to darkest
|
||||
wxEffects::wxEffects(const wxColour& highlightColour, const wxColour& lightShadow,
|
||||
const wxColour& faceColour, const wxColour& mediumShadow, const wxColour& darkShadow)
|
||||
{
|
||||
m_highlightColour = highlightColour;
|
||||
m_lightShadow = lightShadow;
|
||||
m_faceColour = faceColour;
|
||||
m_mediumShadow = mediumShadow;
|
||||
m_darkShadow = darkShadow;
|
||||
}
|
||||
|
||||
// Draw a sunken edge
|
||||
void wxEffects::DrawSunkenEdge(wxDC& dc, const wxRect& rect, int WXUNUSED(borderSize))
|
||||
{
|
||||
wxPen highlightPen(m_highlightColour, 1, wxSOLID);
|
||||
wxPen lightShadowPen(m_lightShadow, 1, wxSOLID);
|
||||
wxPen facePen(m_faceColour, 1, wxSOLID);
|
||||
wxPen mediumShadowPen(m_mediumShadow, 1, wxSOLID);
|
||||
wxPen darkShadowPen(m_darkShadow, 1, wxSOLID);
|
||||
|
||||
//// LEFT AND TOP
|
||||
// Draw a medium shadow pen on left and top, followed by dark shadow line to
|
||||
// right and below of these lines
|
||||
|
||||
dc.SetPen(mediumShadowPen);
|
||||
dc.DrawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y); // Top
|
||||
dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1); // Left
|
||||
|
||||
dc.SetPen(darkShadowPen);
|
||||
dc.DrawLine(rect.x+1, rect.y+1, rect.x+rect.width-2, rect.y+1); // Top
|
||||
dc.DrawLine(rect.x+1, rect.y+1, rect.x+1, rect.y+rect.height-1); // Left
|
||||
|
||||
//// RIGHT AND BOTTOM
|
||||
|
||||
dc.SetPen(highlightPen);
|
||||
dc.DrawLine(rect.x+rect.width-1, rect.y, rect.x+rect.width-1, rect.y+rect.height-1); // Right
|
||||
dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1); // Bottom
|
||||
|
||||
dc.SetPen(lightShadowPen);
|
||||
dc.DrawLine(rect.x+rect.width-2, rect.y+1, rect.x+rect.width-2, rect.y+rect.height-2); // Right
|
||||
dc.DrawLine(rect.x+1, rect.y+rect.height-2, rect.x+rect.width-1, rect.y+rect.height-2); // Bottom
|
||||
|
||||
dc.SetPen(wxNullPen);
|
||||
}
|
||||
|
||||
bool wxEffects::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap)
|
||||
{
|
||||
int w = bitmap.GetWidth();
|
||||
int h = bitmap.GetHeight();
|
||||
|
||||
wxMemoryDC dcMem;
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
static bool hiColour = (wxDisplayDepth() >= 16) ;
|
||||
if (bitmap.GetPalette() && !hiColour)
|
||||
{
|
||||
dc.SetPalette(* bitmap.GetPalette());
|
||||
dcMem.SetPalette(* bitmap.GetPalette());
|
||||
}
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
dcMem.SelectObjectAsSource(bitmap);
|
||||
|
||||
int i, j;
|
||||
for (i = rect.x; i < rect.x + rect.width; i += w)
|
||||
{
|
||||
for (j = rect.y; j < rect.y + rect.height; j+= h)
|
||||
dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
|
||||
}
|
||||
dcMem.SelectObject(wxNullBitmap);
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
if (bitmap.GetPalette() && !hiColour)
|
||||
{
|
||||
dc.SetPalette(wxNullPalette);
|
||||
dcMem.SetPalette(wxNullPalette);
|
||||
}
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
return true;
|
||||
}
|
||||
|
6
Externals/wxWidgets/src/common/emptydmy.cpp
vendored
6
Externals/wxWidgets/src/common/emptydmy.cpp
vendored
@ -1,3 +1,3 @@
|
||||
// This file exists so that it can be compiled into an object so the linker
|
||||
// will have something to chew on so that builds don't break when a platform
|
||||
// lacks any objects in a particular multilib.
|
||||
// This file exists so that it can be compiled into an object so the linker
|
||||
// will have something to chew on so that builds don't break when a platform
|
||||
// lacks any objects in a particular multilib.
|
||||
|
1062
Externals/wxWidgets/src/common/encconv.cpp
vendored
1062
Externals/wxWidgets/src/common/encconv.cpp
vendored
File diff suppressed because it is too large
Load Diff
2980
Externals/wxWidgets/src/common/event.cpp
vendored
2980
Externals/wxWidgets/src/common/event.cpp
vendored
File diff suppressed because it is too large
Load Diff
344
Externals/wxWidgets/src/common/evtloopcmn.cpp
vendored
344
Externals/wxWidgets/src/common/evtloopcmn.cpp
vendored
@ -1,172 +1,172 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/evtloopcmn.cpp
|
||||
// Purpose: common wxEventLoop-related stuff
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 2006-01-12
|
||||
// RCS-ID: $Id: evtloopcmn.cpp 45938 2007-05-10 02:07:41Z VZ $
|
||||
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/evtloop.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
// see the comment near the declaration of wxRunningEventLoopCount in
|
||||
// src/msw/thread.cpp for the explanation of this hack
|
||||
#if defined(__WXMSW__) && wxUSE_THREADS
|
||||
|
||||
extern WXDLLIMPEXP_DATA_BASE(int) wxRunningEventLoopCount;
|
||||
struct wxRunningEventLoopCounter
|
||||
{
|
||||
wxRunningEventLoopCounter() { wxRunningEventLoopCount++; }
|
||||
~wxRunningEventLoopCounter() { wxRunningEventLoopCount--; }
|
||||
};
|
||||
|
||||
#endif // __WXMSW__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// globals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
|
||||
|
||||
// wxEventLoopManual is unused in the other ports
|
||||
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__)
|
||||
|
||||
// ============================================================================
|
||||
// wxEventLoopManual implementation
|
||||
// ============================================================================
|
||||
|
||||
wxEventLoopManual::wxEventLoopManual()
|
||||
{
|
||||
m_exitcode = 0;
|
||||
m_shouldExit = false;
|
||||
}
|
||||
|
||||
int wxEventLoopManual::Run()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
||||
|
||||
// ProcessIdle() and Dispatch() below may throw so the code here should
|
||||
// be exception-safe, hence we must use local objects for all actions we
|
||||
// should undo
|
||||
wxEventLoopActivator activate(wx_static_cast(wxEventLoop *, this));
|
||||
|
||||
#if defined(__WXMSW__) && wxUSE_THREADS
|
||||
wxRunningEventLoopCounter evtLoopCounter;
|
||||
#endif // __WXMSW__
|
||||
|
||||
// we must ensure that OnExit() is called even if an exception is thrown
|
||||
// from inside Dispatch() but we must call it from Exit() in normal
|
||||
// situations because it is supposed to be called synchronously,
|
||||
// wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
|
||||
// something similar here)
|
||||
#if wxUSE_EXCEPTIONS
|
||||
for ( ;; )
|
||||
{
|
||||
try
|
||||
{
|
||||
#endif // wxUSE_EXCEPTIONS
|
||||
|
||||
// this is the event loop itself
|
||||
for ( ;; )
|
||||
{
|
||||
// give them the possibility to do whatever they want
|
||||
OnNextIteration();
|
||||
|
||||
// generate and process idle events for as long as we don't
|
||||
// have anything else to do
|
||||
while ( !Pending() && (wxTheApp && wxTheApp->ProcessIdle()) )
|
||||
;
|
||||
|
||||
// if the "should exit" flag is set, the loop should terminate
|
||||
// but not before processing any remaining messages so while
|
||||
// Pending() returns true, do process them
|
||||
if ( m_shouldExit )
|
||||
{
|
||||
while ( Pending() )
|
||||
Dispatch();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// a message came or no more idle processing to do, sit in
|
||||
// Dispatch() waiting for the next message
|
||||
if ( !Dispatch() )
|
||||
{
|
||||
// we got WM_QUIT
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_EXCEPTIONS
|
||||
// exit the outer loop as well
|
||||
break;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
|
||||
{
|
||||
OnExit();
|
||||
break;
|
||||
}
|
||||
//else: continue running the event loop
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
// OnException() throwed, possibly rethrowing the same
|
||||
// exception again: very good, but we still need OnExit() to
|
||||
// be called
|
||||
OnExit();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_EXCEPTIONS
|
||||
|
||||
return m_exitcode;
|
||||
}
|
||||
|
||||
void wxEventLoopManual::Exit(int rc)
|
||||
{
|
||||
wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
|
||||
|
||||
m_exitcode = rc;
|
||||
m_shouldExit = true;
|
||||
|
||||
OnExit();
|
||||
|
||||
// all we have to do to exit from the loop is to (maybe) wake it up so that
|
||||
// it can notice that Exit() had been called
|
||||
//
|
||||
// in particular, do *not* use here calls such as PostQuitMessage() (under
|
||||
// MSW) which terminate the current event loop here because we're not sure
|
||||
// that it is going to be processed by the correct event loop: it would be
|
||||
// possible that another one is started and terminated by mistake if we do
|
||||
// this
|
||||
WakeUp();
|
||||
}
|
||||
|
||||
#endif // __WXMSW__ || __WXMAC__ || __WXDFB__
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/evtloopcmn.cpp
|
||||
// Purpose: common wxEventLoop-related stuff
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 2006-01-12
|
||||
// RCS-ID: $Id: evtloopcmn.cpp 45938 2007-05-10 02:07:41Z VZ $
|
||||
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/evtloop.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
// see the comment near the declaration of wxRunningEventLoopCount in
|
||||
// src/msw/thread.cpp for the explanation of this hack
|
||||
#if defined(__WXMSW__) && wxUSE_THREADS
|
||||
|
||||
extern WXDLLIMPEXP_DATA_BASE(int) wxRunningEventLoopCount;
|
||||
struct wxRunningEventLoopCounter
|
||||
{
|
||||
wxRunningEventLoopCounter() { wxRunningEventLoopCount++; }
|
||||
~wxRunningEventLoopCounter() { wxRunningEventLoopCount--; }
|
||||
};
|
||||
|
||||
#endif // __WXMSW__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// globals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
|
||||
|
||||
// wxEventLoopManual is unused in the other ports
|
||||
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__)
|
||||
|
||||
// ============================================================================
|
||||
// wxEventLoopManual implementation
|
||||
// ============================================================================
|
||||
|
||||
wxEventLoopManual::wxEventLoopManual()
|
||||
{
|
||||
m_exitcode = 0;
|
||||
m_shouldExit = false;
|
||||
}
|
||||
|
||||
int wxEventLoopManual::Run()
|
||||
{
|
||||
// event loops are not recursive, you need to create another loop!
|
||||
wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
|
||||
|
||||
// ProcessIdle() and Dispatch() below may throw so the code here should
|
||||
// be exception-safe, hence we must use local objects for all actions we
|
||||
// should undo
|
||||
wxEventLoopActivator activate(wx_static_cast(wxEventLoop *, this));
|
||||
|
||||
#if defined(__WXMSW__) && wxUSE_THREADS
|
||||
wxRunningEventLoopCounter evtLoopCounter;
|
||||
#endif // __WXMSW__
|
||||
|
||||
// we must ensure that OnExit() is called even if an exception is thrown
|
||||
// from inside Dispatch() but we must call it from Exit() in normal
|
||||
// situations because it is supposed to be called synchronously,
|
||||
// wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
|
||||
// something similar here)
|
||||
#if wxUSE_EXCEPTIONS
|
||||
for ( ;; )
|
||||
{
|
||||
try
|
||||
{
|
||||
#endif // wxUSE_EXCEPTIONS
|
||||
|
||||
// this is the event loop itself
|
||||
for ( ;; )
|
||||
{
|
||||
// give them the possibility to do whatever they want
|
||||
OnNextIteration();
|
||||
|
||||
// generate and process idle events for as long as we don't
|
||||
// have anything else to do
|
||||
while ( !Pending() && (wxTheApp && wxTheApp->ProcessIdle()) )
|
||||
;
|
||||
|
||||
// if the "should exit" flag is set, the loop should terminate
|
||||
// but not before processing any remaining messages so while
|
||||
// Pending() returns true, do process them
|
||||
if ( m_shouldExit )
|
||||
{
|
||||
while ( Pending() )
|
||||
Dispatch();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// a message came or no more idle processing to do, sit in
|
||||
// Dispatch() waiting for the next message
|
||||
if ( !Dispatch() )
|
||||
{
|
||||
// we got WM_QUIT
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_EXCEPTIONS
|
||||
// exit the outer loop as well
|
||||
break;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
|
||||
{
|
||||
OnExit();
|
||||
break;
|
||||
}
|
||||
//else: continue running the event loop
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
// OnException() throwed, possibly rethrowing the same
|
||||
// exception again: very good, but we still need OnExit() to
|
||||
// be called
|
||||
OnExit();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_EXCEPTIONS
|
||||
|
||||
return m_exitcode;
|
||||
}
|
||||
|
||||
void wxEventLoopManual::Exit(int rc)
|
||||
{
|
||||
wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
|
||||
|
||||
m_exitcode = rc;
|
||||
m_shouldExit = true;
|
||||
|
||||
OnExit();
|
||||
|
||||
// all we have to do to exit from the loop is to (maybe) wake it up so that
|
||||
// it can notice that Exit() had been called
|
||||
//
|
||||
// in particular, do *not* use here calls such as PostQuitMessage() (under
|
||||
// MSW) which terminate the current event loop here because we're not sure
|
||||
// that it is going to be processed by the correct event loop: it would be
|
||||
// possible that another one is started and terminated by mistake if we do
|
||||
// this
|
||||
WakeUp();
|
||||
}
|
||||
|
||||
#endif // __WXMSW__ || __WXMAC__ || __WXDFB__
|
||||
|
244
Externals/wxWidgets/src/common/execcmn.cpp
vendored
244
Externals/wxWidgets/src/common/execcmn.cpp
vendored
@ -1,122 +1,122 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/wxexec.cpp
|
||||
// Purpose: defines wxStreamTempInputBuffer which is used by Unix and MSW
|
||||
// implementations of wxExecute; this file is only used by the
|
||||
// library and never by the user code
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 20.08.02
|
||||
// RCS-ID: $Id: execcmn.cpp 35289 2005-08-23 23:12:48Z VZ $
|
||||
// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_WXEXEC_CPP_
|
||||
#define _WX_WXEXEC_CPP_
|
||||
|
||||
// this file should never be compiled directly, just included by other code
|
||||
#ifndef _WX_USED_BY_WXEXECUTE_
|
||||
#error "You should never directly build this file!"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStreamTempInputBuffer
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
wxStreamTempInputBuffer is a hack which we need to solve the problem of
|
||||
executing a child process synchronously with IO redirecting: when we do
|
||||
this, the child writes to a pipe we open to it but when the pipe buffer
|
||||
(which has finite capacity, e.g. commonly just 4Kb) becomes full we have to
|
||||
read data from it because the child blocks in its write() until then and if
|
||||
it blocks we are never going to return from wxExecute() so we dead lock.
|
||||
|
||||
So here is the fix: we now read the output as soon as it appears into a temp
|
||||
buffer (wxStreamTempInputBuffer object) and later just stuff it back into
|
||||
the stream when the process terminates. See supporting code in wxExecute()
|
||||
itself as well.
|
||||
|
||||
Note that this is horribly inefficient for large amounts of output (count
|
||||
the number of times we copy the data around) and so a better API is badly
|
||||
needed! However it's not easy to devise a way to do this keeping backwards
|
||||
compatibility with the existing wxExecute(wxEXEC_SYNC)...
|
||||
*/
|
||||
|
||||
class wxStreamTempInputBuffer
|
||||
{
|
||||
public:
|
||||
wxStreamTempInputBuffer();
|
||||
|
||||
// call to associate a stream with this buffer, otherwise nothing happens
|
||||
// at all
|
||||
void Init(wxPipeInputStream *stream);
|
||||
|
||||
// check for input on our stream and cache it in our buffer if any
|
||||
void Update();
|
||||
|
||||
~wxStreamTempInputBuffer();
|
||||
|
||||
private:
|
||||
// the stream we're buffering, if NULL we don't do anything at all
|
||||
wxPipeInputStream *m_stream;
|
||||
|
||||
// the buffer of size m_size (NULL if m_size == 0)
|
||||
void *m_buffer;
|
||||
|
||||
// the size of the buffer
|
||||
size_t m_size;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxStreamTempInputBuffer)
|
||||
};
|
||||
|
||||
inline wxStreamTempInputBuffer::wxStreamTempInputBuffer()
|
||||
{
|
||||
m_stream = NULL;
|
||||
m_buffer = NULL;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
inline void wxStreamTempInputBuffer::Init(wxPipeInputStream *stream)
|
||||
{
|
||||
m_stream = stream;
|
||||
}
|
||||
|
||||
inline
|
||||
void wxStreamTempInputBuffer::Update()
|
||||
{
|
||||
if ( m_stream && m_stream->CanRead() )
|
||||
{
|
||||
// realloc in blocks of 4Kb: this is the default (and minimal) buffer
|
||||
// size of the Unix pipes so it should be the optimal step
|
||||
//
|
||||
// NB: don't use "static int" in this inline function, some compilers
|
||||
// (e.g. IBM xlC) don't like it
|
||||
enum { incSize = 4096 };
|
||||
|
||||
void *buf = realloc(m_buffer, m_size + incSize);
|
||||
if ( !buf )
|
||||
{
|
||||
// don't read any more, we don't have enough memory to do it
|
||||
m_stream = NULL;
|
||||
}
|
||||
else // got memory for the buffer
|
||||
{
|
||||
m_buffer = buf;
|
||||
m_stream->Read((char *)m_buffer + m_size, incSize);
|
||||
m_size += m_stream->LastRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
wxStreamTempInputBuffer::~wxStreamTempInputBuffer()
|
||||
{
|
||||
if ( m_buffer )
|
||||
{
|
||||
m_stream->Ungetch(m_buffer, m_size);
|
||||
free(m_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _WX_WXEXEC_CPP_
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/wxexec.cpp
|
||||
// Purpose: defines wxStreamTempInputBuffer which is used by Unix and MSW
|
||||
// implementations of wxExecute; this file is only used by the
|
||||
// library and never by the user code
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 20.08.02
|
||||
// RCS-ID: $Id: execcmn.cpp 35289 2005-08-23 23:12:48Z VZ $
|
||||
// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_WXEXEC_CPP_
|
||||
#define _WX_WXEXEC_CPP_
|
||||
|
||||
// this file should never be compiled directly, just included by other code
|
||||
#ifndef _WX_USED_BY_WXEXECUTE_
|
||||
#error "You should never directly build this file!"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStreamTempInputBuffer
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
wxStreamTempInputBuffer is a hack which we need to solve the problem of
|
||||
executing a child process synchronously with IO redirecting: when we do
|
||||
this, the child writes to a pipe we open to it but when the pipe buffer
|
||||
(which has finite capacity, e.g. commonly just 4Kb) becomes full we have to
|
||||
read data from it because the child blocks in its write() until then and if
|
||||
it blocks we are never going to return from wxExecute() so we dead lock.
|
||||
|
||||
So here is the fix: we now read the output as soon as it appears into a temp
|
||||
buffer (wxStreamTempInputBuffer object) and later just stuff it back into
|
||||
the stream when the process terminates. See supporting code in wxExecute()
|
||||
itself as well.
|
||||
|
||||
Note that this is horribly inefficient for large amounts of output (count
|
||||
the number of times we copy the data around) and so a better API is badly
|
||||
needed! However it's not easy to devise a way to do this keeping backwards
|
||||
compatibility with the existing wxExecute(wxEXEC_SYNC)...
|
||||
*/
|
||||
|
||||
class wxStreamTempInputBuffer
|
||||
{
|
||||
public:
|
||||
wxStreamTempInputBuffer();
|
||||
|
||||
// call to associate a stream with this buffer, otherwise nothing happens
|
||||
// at all
|
||||
void Init(wxPipeInputStream *stream);
|
||||
|
||||
// check for input on our stream and cache it in our buffer if any
|
||||
void Update();
|
||||
|
||||
~wxStreamTempInputBuffer();
|
||||
|
||||
private:
|
||||
// the stream we're buffering, if NULL we don't do anything at all
|
||||
wxPipeInputStream *m_stream;
|
||||
|
||||
// the buffer of size m_size (NULL if m_size == 0)
|
||||
void *m_buffer;
|
||||
|
||||
// the size of the buffer
|
||||
size_t m_size;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxStreamTempInputBuffer)
|
||||
};
|
||||
|
||||
inline wxStreamTempInputBuffer::wxStreamTempInputBuffer()
|
||||
{
|
||||
m_stream = NULL;
|
||||
m_buffer = NULL;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
inline void wxStreamTempInputBuffer::Init(wxPipeInputStream *stream)
|
||||
{
|
||||
m_stream = stream;
|
||||
}
|
||||
|
||||
inline
|
||||
void wxStreamTempInputBuffer::Update()
|
||||
{
|
||||
if ( m_stream && m_stream->CanRead() )
|
||||
{
|
||||
// realloc in blocks of 4Kb: this is the default (and minimal) buffer
|
||||
// size of the Unix pipes so it should be the optimal step
|
||||
//
|
||||
// NB: don't use "static int" in this inline function, some compilers
|
||||
// (e.g. IBM xlC) don't like it
|
||||
enum { incSize = 4096 };
|
||||
|
||||
void *buf = realloc(m_buffer, m_size + incSize);
|
||||
if ( !buf )
|
||||
{
|
||||
// don't read any more, we don't have enough memory to do it
|
||||
m_stream = NULL;
|
||||
}
|
||||
else // got memory for the buffer
|
||||
{
|
||||
m_buffer = buf;
|
||||
m_stream->Read((char *)m_buffer + m_size, incSize);
|
||||
m_size += m_stream->LastRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
wxStreamTempInputBuffer::~wxStreamTempInputBuffer()
|
||||
{
|
||||
if ( m_buffer )
|
||||
{
|
||||
m_stream->Ungetch(m_buffer, m_size);
|
||||
free(m_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _WX_WXEXEC_CPP_
|
||||
|
||||
|
204
Externals/wxWidgets/src/common/fddlgcmn.cpp
vendored
204
Externals/wxWidgets/src/common/fddlgcmn.cpp
vendored
@ -1,102 +1,102 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fdrepdlg.cpp
|
||||
// Purpose: common parts of wxFindReplaceDialog implementations
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 01.08.01
|
||||
// RCS-ID:
|
||||
// Copyright: (c) 2001 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FINDREPLDLG
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/fdrepdlg.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWin macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFindDialogEvent, wxCommandEvent)
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_NEXT)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE_ALL)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_CLOSE)
|
||||
|
||||
// ============================================================================
|
||||
// implementations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFindReplaceData
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFindReplaceData::Init()
|
||||
{
|
||||
m_Flags = 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFindReplaceDialogBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFindReplaceDialogBase::~wxFindReplaceDialogBase()
|
||||
{
|
||||
}
|
||||
|
||||
void wxFindReplaceDialogBase::Send(wxFindDialogEvent& event)
|
||||
{
|
||||
// we copy the data to dialog->GetData() as well
|
||||
|
||||
m_FindReplaceData->m_Flags = event.GetFlags();
|
||||
m_FindReplaceData->m_FindWhat = event.GetFindString();
|
||||
if ( HasFlag(wxFR_REPLACEDIALOG) &&
|
||||
(event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE ||
|
||||
event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL) )
|
||||
{
|
||||
m_FindReplaceData->m_ReplaceWith = event.GetReplaceString();
|
||||
}
|
||||
|
||||
// translate wxEVT_COMMAND_FIND_NEXT to wxEVT_COMMAND_FIND if needed
|
||||
if ( event.GetEventType() == wxEVT_COMMAND_FIND_NEXT )
|
||||
{
|
||||
if ( m_FindReplaceData->m_FindWhat != m_lastSearch )
|
||||
{
|
||||
event.SetEventType(wxEVT_COMMAND_FIND);
|
||||
|
||||
m_lastSearch = m_FindReplaceData->m_FindWhat;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !GetEventHandler()->ProcessEvent(event) )
|
||||
{
|
||||
// the event is not propagated upwards to the parent automatically
|
||||
// because the dialog is a top level window, so do it manually as
|
||||
// in 9 cases of 10 the message must be processed by the dialog
|
||||
// owner and not the dialog itself
|
||||
(void)GetParent()->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_FINDREPLDLG
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fdrepdlg.cpp
|
||||
// Purpose: common parts of wxFindReplaceDialog implementations
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 01.08.01
|
||||
// RCS-ID:
|
||||
// Copyright: (c) 2001 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FINDREPLDLG
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/fdrepdlg.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWin macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFindDialogEvent, wxCommandEvent)
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_NEXT)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_REPLACE_ALL)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FIND_CLOSE)
|
||||
|
||||
// ============================================================================
|
||||
// implementations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFindReplaceData
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFindReplaceData::Init()
|
||||
{
|
||||
m_Flags = 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFindReplaceDialogBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFindReplaceDialogBase::~wxFindReplaceDialogBase()
|
||||
{
|
||||
}
|
||||
|
||||
void wxFindReplaceDialogBase::Send(wxFindDialogEvent& event)
|
||||
{
|
||||
// we copy the data to dialog->GetData() as well
|
||||
|
||||
m_FindReplaceData->m_Flags = event.GetFlags();
|
||||
m_FindReplaceData->m_FindWhat = event.GetFindString();
|
||||
if ( HasFlag(wxFR_REPLACEDIALOG) &&
|
||||
(event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE ||
|
||||
event.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL) )
|
||||
{
|
||||
m_FindReplaceData->m_ReplaceWith = event.GetReplaceString();
|
||||
}
|
||||
|
||||
// translate wxEVT_COMMAND_FIND_NEXT to wxEVT_COMMAND_FIND if needed
|
||||
if ( event.GetEventType() == wxEVT_COMMAND_FIND_NEXT )
|
||||
{
|
||||
if ( m_FindReplaceData->m_FindWhat != m_lastSearch )
|
||||
{
|
||||
event.SetEventType(wxEVT_COMMAND_FIND);
|
||||
|
||||
m_lastSearch = m_FindReplaceData->m_FindWhat;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !GetEventHandler()->ProcessEvent(event) )
|
||||
{
|
||||
// the event is not propagated upwards to the parent automatically
|
||||
// because the dialog is a top level window, so do it manually as
|
||||
// in 9 cases of 10 the message must be processed by the dialog
|
||||
// owner and not the dialog itself
|
||||
(void)GetParent()->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_FINDREPLDLG
|
||||
|
||||
|
536
Externals/wxWidgets/src/common/ffile.cpp
vendored
536
Externals/wxWidgets/src/common/ffile.cpp
vendored
@ -1,268 +1,268 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: ffile.cpp
|
||||
// Purpose: wxFFile encapsulates "FILE *" IO stream
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 14.07.99
|
||||
// RCS-ID: $Id: ffile.cpp 38570 2006-04-05 14:37:47Z VZ $
|
||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FFILE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/mslu.h"
|
||||
#endif
|
||||
|
||||
#include "wx/ffile.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// seek and tell with large file support if available
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_FSEEKO
|
||||
# define wxFseek fseeko
|
||||
# define wxFtell ftello
|
||||
#else
|
||||
# define wxFseek fseek
|
||||
# define wxFtell ftell
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// opening the file
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFFile::wxFFile(const wxChar *filename, const wxChar *mode)
|
||||
{
|
||||
Detach();
|
||||
|
||||
(void)Open(filename, mode);
|
||||
}
|
||||
|
||||
bool wxFFile::Open(const wxChar *filename, const wxChar *mode)
|
||||
{
|
||||
wxASSERT_MSG( !m_fp, wxT("should close or detach the old file first") );
|
||||
|
||||
m_fp = wxFopen(filename, mode);
|
||||
|
||||
if ( !m_fp )
|
||||
{
|
||||
wxLogSysError(_("can't open file '%s'"), filename);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_name = filename;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxFFile::Close()
|
||||
{
|
||||
if ( IsOpened() )
|
||||
{
|
||||
if ( fclose(m_fp) != 0 )
|
||||
{
|
||||
wxLogSysError(_("can't close file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Detach();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// read/write
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFFile::ReadAll(wxString *str, const wxMBConv& conv)
|
||||
{
|
||||
wxCHECK_MSG( str, false, wxT("invalid parameter") );
|
||||
wxCHECK_MSG( IsOpened(), false, wxT("can't read from closed file") );
|
||||
wxCHECK_MSG( Length() >= 0, false, wxT("invalid length") );
|
||||
size_t length = wx_truncate_cast(size_t, Length());
|
||||
wxCHECK_MSG( (wxFileOffset)length == Length(), false, wxT("huge file not supported") );
|
||||
|
||||
clearerr(m_fp);
|
||||
|
||||
wxCharBuffer buf(length + 1);
|
||||
|
||||
// note that real length may be less than file length for text files with DOS EOLs
|
||||
// ('\r's get dropped by CRT when reading which means that we have
|
||||
// realLen = fileLen - numOfLinesInTheFile)
|
||||
length = fread(buf.data(), sizeof(char), length, m_fp);
|
||||
|
||||
if ( Error() )
|
||||
{
|
||||
wxLogSysError(_("Read error on file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
buf.data()[length] = 0;
|
||||
*str = wxString(buf, conv);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wxFFile::Read(void *pBuf, size_t nCount)
|
||||
{
|
||||
wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") );
|
||||
wxCHECK_MSG( IsOpened(), 0, wxT("can't read from closed file") );
|
||||
|
||||
size_t nRead = fread(pBuf, 1, nCount, m_fp);
|
||||
if ( (nRead < nCount) && Error() )
|
||||
{
|
||||
wxLogSysError(_("Read error on file '%s'"), m_name.c_str());
|
||||
}
|
||||
|
||||
return nRead;
|
||||
}
|
||||
|
||||
size_t wxFFile::Write(const void *pBuf, size_t nCount)
|
||||
{
|
||||
wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") );
|
||||
wxCHECK_MSG( IsOpened(), 0, wxT("can't write to closed file") );
|
||||
|
||||
size_t nWritten = fwrite(pBuf, 1, nCount, m_fp);
|
||||
if ( nWritten < nCount )
|
||||
{
|
||||
wxLogSysError(_("Write error on file '%s'"), m_name.c_str());
|
||||
}
|
||||
|
||||
return nWritten;
|
||||
}
|
||||
|
||||
bool wxFFile::Flush()
|
||||
{
|
||||
if ( IsOpened() )
|
||||
{
|
||||
// fflush returns non-zero on error
|
||||
//
|
||||
if ( fflush(m_fp) )
|
||||
{
|
||||
wxLogSysError(_("failed to flush the file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// seeking
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFFile::Seek(wxFileOffset ofs, wxSeekMode mode)
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), false, wxT("can't seek on closed file") );
|
||||
|
||||
int origin;
|
||||
switch ( mode )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(wxT("unknown seek mode"));
|
||||
// still fall through
|
||||
|
||||
case wxFromStart:
|
||||
origin = SEEK_SET;
|
||||
break;
|
||||
|
||||
case wxFromCurrent:
|
||||
origin = SEEK_CUR;
|
||||
break;
|
||||
|
||||
case wxFromEnd:
|
||||
origin = SEEK_END;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef HAVE_FSEEKO
|
||||
if ((long)ofs != ofs)
|
||||
{
|
||||
wxLogError(_("Seek error on file '%s' (large files not supported by stdio)"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wxFseek(m_fp, (long)ofs, origin) != 0 )
|
||||
#else
|
||||
if ( wxFseek(m_fp, ofs, origin) != 0 )
|
||||
#endif
|
||||
{
|
||||
wxLogSysError(_("Seek error on file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxFileOffset wxFFile::Tell() const
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), wxInvalidOffset,
|
||||
_T("wxFFile::Tell(): file is closed!") );
|
||||
|
||||
wxFileOffset rc = wxFtell(m_fp);
|
||||
if ( rc == wxInvalidOffset )
|
||||
{
|
||||
wxLogSysError(_("Can't find current position in file '%s'"),
|
||||
m_name.c_str());
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
wxFileOffset wxFFile::Length() const
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), wxInvalidOffset,
|
||||
_T("wxFFile::Length(): file is closed!") );
|
||||
|
||||
wxFFile& self = *(wxFFile *)this; // const_cast
|
||||
|
||||
wxFileOffset posOld = Tell();
|
||||
if ( posOld != wxInvalidOffset )
|
||||
{
|
||||
if ( self.SeekEnd() )
|
||||
{
|
||||
wxFileOffset len = Tell();
|
||||
|
||||
(void)self.Seek(posOld);
|
||||
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
#endif // wxUSE_FFILE
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: ffile.cpp
|
||||
// Purpose: wxFFile encapsulates "FILE *" IO stream
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 14.07.99
|
||||
// RCS-ID: $Id: ffile.cpp 38570 2006-04-05 14:37:47Z VZ $
|
||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FFILE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/mslu.h"
|
||||
#endif
|
||||
|
||||
#include "wx/ffile.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// seek and tell with large file support if available
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef HAVE_FSEEKO
|
||||
# define wxFseek fseeko
|
||||
# define wxFtell ftello
|
||||
#else
|
||||
# define wxFseek fseek
|
||||
# define wxFtell ftell
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// opening the file
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFFile::wxFFile(const wxChar *filename, const wxChar *mode)
|
||||
{
|
||||
Detach();
|
||||
|
||||
(void)Open(filename, mode);
|
||||
}
|
||||
|
||||
bool wxFFile::Open(const wxChar *filename, const wxChar *mode)
|
||||
{
|
||||
wxASSERT_MSG( !m_fp, wxT("should close or detach the old file first") );
|
||||
|
||||
m_fp = wxFopen(filename, mode);
|
||||
|
||||
if ( !m_fp )
|
||||
{
|
||||
wxLogSysError(_("can't open file '%s'"), filename);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_name = filename;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxFFile::Close()
|
||||
{
|
||||
if ( IsOpened() )
|
||||
{
|
||||
if ( fclose(m_fp) != 0 )
|
||||
{
|
||||
wxLogSysError(_("can't close file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Detach();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// read/write
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFFile::ReadAll(wxString *str, const wxMBConv& conv)
|
||||
{
|
||||
wxCHECK_MSG( str, false, wxT("invalid parameter") );
|
||||
wxCHECK_MSG( IsOpened(), false, wxT("can't read from closed file") );
|
||||
wxCHECK_MSG( Length() >= 0, false, wxT("invalid length") );
|
||||
size_t length = wx_truncate_cast(size_t, Length());
|
||||
wxCHECK_MSG( (wxFileOffset)length == Length(), false, wxT("huge file not supported") );
|
||||
|
||||
clearerr(m_fp);
|
||||
|
||||
wxCharBuffer buf(length + 1);
|
||||
|
||||
// note that real length may be less than file length for text files with DOS EOLs
|
||||
// ('\r's get dropped by CRT when reading which means that we have
|
||||
// realLen = fileLen - numOfLinesInTheFile)
|
||||
length = fread(buf.data(), sizeof(char), length, m_fp);
|
||||
|
||||
if ( Error() )
|
||||
{
|
||||
wxLogSysError(_("Read error on file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
buf.data()[length] = 0;
|
||||
*str = wxString(buf, conv);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wxFFile::Read(void *pBuf, size_t nCount)
|
||||
{
|
||||
wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") );
|
||||
wxCHECK_MSG( IsOpened(), 0, wxT("can't read from closed file") );
|
||||
|
||||
size_t nRead = fread(pBuf, 1, nCount, m_fp);
|
||||
if ( (nRead < nCount) && Error() )
|
||||
{
|
||||
wxLogSysError(_("Read error on file '%s'"), m_name.c_str());
|
||||
}
|
||||
|
||||
return nRead;
|
||||
}
|
||||
|
||||
size_t wxFFile::Write(const void *pBuf, size_t nCount)
|
||||
{
|
||||
wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") );
|
||||
wxCHECK_MSG( IsOpened(), 0, wxT("can't write to closed file") );
|
||||
|
||||
size_t nWritten = fwrite(pBuf, 1, nCount, m_fp);
|
||||
if ( nWritten < nCount )
|
||||
{
|
||||
wxLogSysError(_("Write error on file '%s'"), m_name.c_str());
|
||||
}
|
||||
|
||||
return nWritten;
|
||||
}
|
||||
|
||||
bool wxFFile::Flush()
|
||||
{
|
||||
if ( IsOpened() )
|
||||
{
|
||||
// fflush returns non-zero on error
|
||||
//
|
||||
if ( fflush(m_fp) )
|
||||
{
|
||||
wxLogSysError(_("failed to flush the file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// seeking
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFFile::Seek(wxFileOffset ofs, wxSeekMode mode)
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), false, wxT("can't seek on closed file") );
|
||||
|
||||
int origin;
|
||||
switch ( mode )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(wxT("unknown seek mode"));
|
||||
// still fall through
|
||||
|
||||
case wxFromStart:
|
||||
origin = SEEK_SET;
|
||||
break;
|
||||
|
||||
case wxFromCurrent:
|
||||
origin = SEEK_CUR;
|
||||
break;
|
||||
|
||||
case wxFromEnd:
|
||||
origin = SEEK_END;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef HAVE_FSEEKO
|
||||
if ((long)ofs != ofs)
|
||||
{
|
||||
wxLogError(_("Seek error on file '%s' (large files not supported by stdio)"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wxFseek(m_fp, (long)ofs, origin) != 0 )
|
||||
#else
|
||||
if ( wxFseek(m_fp, ofs, origin) != 0 )
|
||||
#endif
|
||||
{
|
||||
wxLogSysError(_("Seek error on file '%s'"), m_name.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxFileOffset wxFFile::Tell() const
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), wxInvalidOffset,
|
||||
_T("wxFFile::Tell(): file is closed!") );
|
||||
|
||||
wxFileOffset rc = wxFtell(m_fp);
|
||||
if ( rc == wxInvalidOffset )
|
||||
{
|
||||
wxLogSysError(_("Can't find current position in file '%s'"),
|
||||
m_name.c_str());
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
wxFileOffset wxFFile::Length() const
|
||||
{
|
||||
wxCHECK_MSG( IsOpened(), wxInvalidOffset,
|
||||
_T("wxFFile::Length(): file is closed!") );
|
||||
|
||||
wxFFile& self = *(wxFFile *)this; // const_cast
|
||||
|
||||
wxFileOffset posOld = Tell();
|
||||
if ( posOld != wxInvalidOffset )
|
||||
{
|
||||
if ( self.SeekEnd() )
|
||||
{
|
||||
wxFileOffset len = Tell();
|
||||
|
||||
(void)self.Seek(posOld);
|
||||
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
#endif // wxUSE_FFILE
|
||||
|
1118
Externals/wxWidgets/src/common/file.cpp
vendored
1118
Externals/wxWidgets/src/common/file.cpp
vendored
File diff suppressed because it is too large
Load Diff
676
Externals/wxWidgets/src/common/fileback.cpp
vendored
676
Externals/wxWidgets/src/common/fileback.cpp
vendored
@ -1,338 +1,338 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fileback.cpp
|
||||
// Purpose: Back an input stream with memory or a file
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: fileback.cpp 42651 2006-10-29 20:06:45Z MW $
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM
|
||||
|
||||
#include "wx/private/fileback.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/utils.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/private/filename.h"
|
||||
|
||||
// Prefer wxFFile unless wxFile has large file support but wxFFile does not.
|
||||
//
|
||||
#if wxUSE_FFILE && (defined wxHAS_LARGE_FFILES || !defined wxHAS_LARGE_FILES)
|
||||
typedef wxFFile wxBFFile;
|
||||
static const bool wxBadSeek = false;
|
||||
#else
|
||||
typedef wxFile wxBFFile;
|
||||
static const wxFileOffset wxBadSeek = wxInvalidOffset;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Backing file implementation
|
||||
|
||||
class wxBackingFileImpl
|
||||
{
|
||||
public:
|
||||
wxBackingFileImpl(wxInputStream *stream,
|
||||
size_t bufsize,
|
||||
const wxString& prefix);
|
||||
~wxBackingFileImpl();
|
||||
|
||||
void Release() { if (--m_refcount == 0) delete this; }
|
||||
wxBackingFileImpl *AddRef() { m_refcount++; return this; }
|
||||
|
||||
wxStreamError ReadAt(wxFileOffset pos, void *buffer, size_t *size);
|
||||
wxFileOffset GetLength() const;
|
||||
|
||||
private:
|
||||
int m_refcount;
|
||||
|
||||
wxInputStream *m_stream;
|
||||
wxStreamError m_parenterror;
|
||||
|
||||
char *m_buf;
|
||||
size_t m_bufsize;
|
||||
size_t m_buflen;
|
||||
|
||||
wxString m_prefix;
|
||||
wxString m_filename;
|
||||
wxBFFile m_file;
|
||||
wxFileOffset m_filelen;
|
||||
};
|
||||
|
||||
wxBackingFileImpl::wxBackingFileImpl(wxInputStream *stream,
|
||||
size_t bufsize,
|
||||
const wxString& prefix)
|
||||
: m_refcount(1),
|
||||
m_stream(stream),
|
||||
m_parenterror(wxSTREAM_NO_ERROR),
|
||||
m_buf(NULL),
|
||||
m_bufsize(bufsize),
|
||||
m_buflen(0),
|
||||
m_prefix(prefix),
|
||||
m_filelen(0)
|
||||
{
|
||||
wxFileOffset len = m_stream->GetLength();
|
||||
|
||||
if (len >= 0 && len + size_t(1) < m_bufsize)
|
||||
m_bufsize = size_t(len + 1);
|
||||
|
||||
if (m_bufsize)
|
||||
m_buf = new char[m_bufsize];
|
||||
}
|
||||
|
||||
wxBackingFileImpl::~wxBackingFileImpl()
|
||||
{
|
||||
delete m_stream;
|
||||
delete [] m_buf;
|
||||
|
||||
if (!m_filename.empty())
|
||||
wxRemoveFile(m_filename);
|
||||
}
|
||||
|
||||
wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
|
||||
void *buffer,
|
||||
size_t *size)
|
||||
{
|
||||
size_t reqestedSize = *size;
|
||||
*size = 0;
|
||||
|
||||
// size1 is the number of bytes it will read directly from the backing
|
||||
// file. size2 is any remaining bytes not yet backed, these are returned
|
||||
// from the buffer or read from the parent stream.
|
||||
size_t size1, size2;
|
||||
|
||||
if (pos + reqestedSize <= m_filelen + size_t(0)) {
|
||||
size1 = reqestedSize;
|
||||
size2 = 0;
|
||||
} else if (pos < m_filelen) {
|
||||
size1 = size_t(m_filelen - pos);
|
||||
size2 = reqestedSize - size1;
|
||||
} else {
|
||||
size1 = 0;
|
||||
size2 = reqestedSize;
|
||||
}
|
||||
|
||||
if (pos < 0)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
// read the backing file
|
||||
if (size1) {
|
||||
if (m_file.Seek(pos) == wxBadSeek)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
ssize_t n = m_file.Read(buffer, size1);
|
||||
if (n > 0) {
|
||||
*size = n;
|
||||
pos += n;
|
||||
}
|
||||
|
||||
if (*size < size1)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
}
|
||||
|
||||
// read from the buffer or parent stream
|
||||
if (size2)
|
||||
{
|
||||
while (*size < reqestedSize)
|
||||
{
|
||||
// if pos is further ahead than the parent has been read so far,
|
||||
// then read forward in the parent stream
|
||||
while (pos - m_filelen + size_t(0) >= m_buflen)
|
||||
{
|
||||
// if the parent is small enough, don't use a backing file
|
||||
// just the buffer memory
|
||||
if (!m_stream && m_filelen == 0)
|
||||
return m_parenterror;
|
||||
|
||||
// before refilling the buffer write out the current buffer
|
||||
// to the backing file if there is anything in it
|
||||
if (m_buflen)
|
||||
{
|
||||
if (!m_file.IsOpened())
|
||||
if (!wxCreateTempFile(m_prefix, &m_file, &m_filename))
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
if (m_file.Seek(m_filelen) == wxBadSeek)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
size_t count = m_file.Write(m_buf, m_buflen);
|
||||
m_filelen += count;
|
||||
|
||||
if (count < m_buflen) {
|
||||
delete m_stream;
|
||||
m_stream = NULL;
|
||||
if (count > 0) {
|
||||
delete[] m_buf;
|
||||
m_buf = NULL;
|
||||
m_buflen = 0;
|
||||
}
|
||||
m_parenterror = wxSTREAM_READ_ERROR;
|
||||
return m_parenterror;
|
||||
}
|
||||
|
||||
m_buflen = 0;
|
||||
|
||||
if (!m_stream) {
|
||||
delete[] m_buf;
|
||||
m_buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_stream)
|
||||
return m_parenterror;
|
||||
|
||||
// refill buffer
|
||||
m_buflen = m_stream->Read(m_buf, m_bufsize).LastRead();
|
||||
|
||||
if (m_buflen < m_bufsize) {
|
||||
m_parenterror = m_stream->GetLastError();
|
||||
if (m_parenterror == wxSTREAM_NO_ERROR)
|
||||
m_parenterror = wxSTREAM_EOF;
|
||||
delete m_stream;
|
||||
m_stream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// copy to the user's buffer
|
||||
size_t start = size_t(pos - m_filelen);
|
||||
size_t len = wxMin(m_buflen - start, reqestedSize - *size);
|
||||
|
||||
memcpy((char*)buffer + *size, m_buf + start, len);
|
||||
*size += len;
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
|
||||
return wxSTREAM_NO_ERROR;
|
||||
}
|
||||
|
||||
wxFileOffset wxBackingFileImpl::GetLength() const
|
||||
{
|
||||
if (m_parenterror != wxSTREAM_EOF) {
|
||||
wxLogNull nolog;
|
||||
return m_stream->GetLength();
|
||||
}
|
||||
return m_filelen + m_buflen;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Backing File, the handle part
|
||||
|
||||
wxBackingFile::wxBackingFile(wxInputStream *stream,
|
||||
size_t bufsize,
|
||||
const wxString& prefix)
|
||||
: m_impl(new wxBackingFileImpl(stream, bufsize, prefix))
|
||||
{
|
||||
}
|
||||
|
||||
wxBackingFile::wxBackingFile(const wxBackingFile& backer)
|
||||
: m_impl(backer.m_impl ? backer.m_impl->AddRef() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
wxBackingFile& wxBackingFile::operator=(const wxBackingFile& backer)
|
||||
{
|
||||
if (backer.m_impl != m_impl) {
|
||||
if (m_impl)
|
||||
m_impl->Release();
|
||||
|
||||
m_impl = backer.m_impl;
|
||||
|
||||
if (m_impl)
|
||||
m_impl->AddRef();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxBackingFile::~wxBackingFile()
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->Release();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Input stream
|
||||
|
||||
wxBackedInputStream::wxBackedInputStream(const wxBackingFile& backer)
|
||||
: m_backer(backer),
|
||||
m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::GetLength() const
|
||||
{
|
||||
return m_backer.m_impl->GetLength();
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::FindLength() const
|
||||
{
|
||||
wxFileOffset len = GetLength();
|
||||
|
||||
if (len == wxInvalidOffset && IsOk()) {
|
||||
// read a byte at 7ff...ffe
|
||||
wxFileOffset pos = 1;
|
||||
pos <<= sizeof(pos) * 8 - 1;
|
||||
pos = ~pos - 1;
|
||||
char ch;
|
||||
size_t size = 1;
|
||||
m_backer.m_impl->ReadAt(pos, &ch, &size);
|
||||
len = GetLength();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
|
||||
{
|
||||
if (!IsOk())
|
||||
return 0;
|
||||
|
||||
m_lasterror = m_backer.m_impl->ReadAt(m_pos, buffer, &size);
|
||||
m_pos += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case wxFromCurrent:
|
||||
{
|
||||
m_pos += pos;
|
||||
break;
|
||||
}
|
||||
case wxFromEnd:
|
||||
{
|
||||
wxFileOffset len = GetLength();
|
||||
if (len == wxInvalidOffset)
|
||||
return wxInvalidOffset;
|
||||
m_pos = len + pos;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_pos = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::OnSysTell() const
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILESYSTEM
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fileback.cpp
|
||||
// Purpose: Back an input stream with memory or a file
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: fileback.cpp 42651 2006-10-29 20:06:45Z MW $
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM
|
||||
|
||||
#include "wx/private/fileback.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/utils.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/private/filename.h"
|
||||
|
||||
// Prefer wxFFile unless wxFile has large file support but wxFFile does not.
|
||||
//
|
||||
#if wxUSE_FFILE && (defined wxHAS_LARGE_FFILES || !defined wxHAS_LARGE_FILES)
|
||||
typedef wxFFile wxBFFile;
|
||||
static const bool wxBadSeek = false;
|
||||
#else
|
||||
typedef wxFile wxBFFile;
|
||||
static const wxFileOffset wxBadSeek = wxInvalidOffset;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Backing file implementation
|
||||
|
||||
class wxBackingFileImpl
|
||||
{
|
||||
public:
|
||||
wxBackingFileImpl(wxInputStream *stream,
|
||||
size_t bufsize,
|
||||
const wxString& prefix);
|
||||
~wxBackingFileImpl();
|
||||
|
||||
void Release() { if (--m_refcount == 0) delete this; }
|
||||
wxBackingFileImpl *AddRef() { m_refcount++; return this; }
|
||||
|
||||
wxStreamError ReadAt(wxFileOffset pos, void *buffer, size_t *size);
|
||||
wxFileOffset GetLength() const;
|
||||
|
||||
private:
|
||||
int m_refcount;
|
||||
|
||||
wxInputStream *m_stream;
|
||||
wxStreamError m_parenterror;
|
||||
|
||||
char *m_buf;
|
||||
size_t m_bufsize;
|
||||
size_t m_buflen;
|
||||
|
||||
wxString m_prefix;
|
||||
wxString m_filename;
|
||||
wxBFFile m_file;
|
||||
wxFileOffset m_filelen;
|
||||
};
|
||||
|
||||
wxBackingFileImpl::wxBackingFileImpl(wxInputStream *stream,
|
||||
size_t bufsize,
|
||||
const wxString& prefix)
|
||||
: m_refcount(1),
|
||||
m_stream(stream),
|
||||
m_parenterror(wxSTREAM_NO_ERROR),
|
||||
m_buf(NULL),
|
||||
m_bufsize(bufsize),
|
||||
m_buflen(0),
|
||||
m_prefix(prefix),
|
||||
m_filelen(0)
|
||||
{
|
||||
wxFileOffset len = m_stream->GetLength();
|
||||
|
||||
if (len >= 0 && len + size_t(1) < m_bufsize)
|
||||
m_bufsize = size_t(len + 1);
|
||||
|
||||
if (m_bufsize)
|
||||
m_buf = new char[m_bufsize];
|
||||
}
|
||||
|
||||
wxBackingFileImpl::~wxBackingFileImpl()
|
||||
{
|
||||
delete m_stream;
|
||||
delete [] m_buf;
|
||||
|
||||
if (!m_filename.empty())
|
||||
wxRemoveFile(m_filename);
|
||||
}
|
||||
|
||||
wxStreamError wxBackingFileImpl::ReadAt(wxFileOffset pos,
|
||||
void *buffer,
|
||||
size_t *size)
|
||||
{
|
||||
size_t reqestedSize = *size;
|
||||
*size = 0;
|
||||
|
||||
// size1 is the number of bytes it will read directly from the backing
|
||||
// file. size2 is any remaining bytes not yet backed, these are returned
|
||||
// from the buffer or read from the parent stream.
|
||||
size_t size1, size2;
|
||||
|
||||
if (pos + reqestedSize <= m_filelen + size_t(0)) {
|
||||
size1 = reqestedSize;
|
||||
size2 = 0;
|
||||
} else if (pos < m_filelen) {
|
||||
size1 = size_t(m_filelen - pos);
|
||||
size2 = reqestedSize - size1;
|
||||
} else {
|
||||
size1 = 0;
|
||||
size2 = reqestedSize;
|
||||
}
|
||||
|
||||
if (pos < 0)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
// read the backing file
|
||||
if (size1) {
|
||||
if (m_file.Seek(pos) == wxBadSeek)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
ssize_t n = m_file.Read(buffer, size1);
|
||||
if (n > 0) {
|
||||
*size = n;
|
||||
pos += n;
|
||||
}
|
||||
|
||||
if (*size < size1)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
}
|
||||
|
||||
// read from the buffer or parent stream
|
||||
if (size2)
|
||||
{
|
||||
while (*size < reqestedSize)
|
||||
{
|
||||
// if pos is further ahead than the parent has been read so far,
|
||||
// then read forward in the parent stream
|
||||
while (pos - m_filelen + size_t(0) >= m_buflen)
|
||||
{
|
||||
// if the parent is small enough, don't use a backing file
|
||||
// just the buffer memory
|
||||
if (!m_stream && m_filelen == 0)
|
||||
return m_parenterror;
|
||||
|
||||
// before refilling the buffer write out the current buffer
|
||||
// to the backing file if there is anything in it
|
||||
if (m_buflen)
|
||||
{
|
||||
if (!m_file.IsOpened())
|
||||
if (!wxCreateTempFile(m_prefix, &m_file, &m_filename))
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
if (m_file.Seek(m_filelen) == wxBadSeek)
|
||||
return wxSTREAM_READ_ERROR;
|
||||
|
||||
size_t count = m_file.Write(m_buf, m_buflen);
|
||||
m_filelen += count;
|
||||
|
||||
if (count < m_buflen) {
|
||||
delete m_stream;
|
||||
m_stream = NULL;
|
||||
if (count > 0) {
|
||||
delete[] m_buf;
|
||||
m_buf = NULL;
|
||||
m_buflen = 0;
|
||||
}
|
||||
m_parenterror = wxSTREAM_READ_ERROR;
|
||||
return m_parenterror;
|
||||
}
|
||||
|
||||
m_buflen = 0;
|
||||
|
||||
if (!m_stream) {
|
||||
delete[] m_buf;
|
||||
m_buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_stream)
|
||||
return m_parenterror;
|
||||
|
||||
// refill buffer
|
||||
m_buflen = m_stream->Read(m_buf, m_bufsize).LastRead();
|
||||
|
||||
if (m_buflen < m_bufsize) {
|
||||
m_parenterror = m_stream->GetLastError();
|
||||
if (m_parenterror == wxSTREAM_NO_ERROR)
|
||||
m_parenterror = wxSTREAM_EOF;
|
||||
delete m_stream;
|
||||
m_stream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// copy to the user's buffer
|
||||
size_t start = size_t(pos - m_filelen);
|
||||
size_t len = wxMin(m_buflen - start, reqestedSize - *size);
|
||||
|
||||
memcpy((char*)buffer + *size, m_buf + start, len);
|
||||
*size += len;
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
|
||||
return wxSTREAM_NO_ERROR;
|
||||
}
|
||||
|
||||
wxFileOffset wxBackingFileImpl::GetLength() const
|
||||
{
|
||||
if (m_parenterror != wxSTREAM_EOF) {
|
||||
wxLogNull nolog;
|
||||
return m_stream->GetLength();
|
||||
}
|
||||
return m_filelen + m_buflen;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Backing File, the handle part
|
||||
|
||||
wxBackingFile::wxBackingFile(wxInputStream *stream,
|
||||
size_t bufsize,
|
||||
const wxString& prefix)
|
||||
: m_impl(new wxBackingFileImpl(stream, bufsize, prefix))
|
||||
{
|
||||
}
|
||||
|
||||
wxBackingFile::wxBackingFile(const wxBackingFile& backer)
|
||||
: m_impl(backer.m_impl ? backer.m_impl->AddRef() : NULL)
|
||||
{
|
||||
}
|
||||
|
||||
wxBackingFile& wxBackingFile::operator=(const wxBackingFile& backer)
|
||||
{
|
||||
if (backer.m_impl != m_impl) {
|
||||
if (m_impl)
|
||||
m_impl->Release();
|
||||
|
||||
m_impl = backer.m_impl;
|
||||
|
||||
if (m_impl)
|
||||
m_impl->AddRef();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxBackingFile::~wxBackingFile()
|
||||
{
|
||||
if (m_impl)
|
||||
m_impl->Release();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Input stream
|
||||
|
||||
wxBackedInputStream::wxBackedInputStream(const wxBackingFile& backer)
|
||||
: m_backer(backer),
|
||||
m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::GetLength() const
|
||||
{
|
||||
return m_backer.m_impl->GetLength();
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::FindLength() const
|
||||
{
|
||||
wxFileOffset len = GetLength();
|
||||
|
||||
if (len == wxInvalidOffset && IsOk()) {
|
||||
// read a byte at 7ff...ffe
|
||||
wxFileOffset pos = 1;
|
||||
pos <<= sizeof(pos) * 8 - 1;
|
||||
pos = ~pos - 1;
|
||||
char ch;
|
||||
size_t size = 1;
|
||||
m_backer.m_impl->ReadAt(pos, &ch, &size);
|
||||
len = GetLength();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t wxBackedInputStream::OnSysRead(void *buffer, size_t size)
|
||||
{
|
||||
if (!IsOk())
|
||||
return 0;
|
||||
|
||||
m_lasterror = m_backer.m_impl->ReadAt(m_pos, buffer, &size);
|
||||
m_pos += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case wxFromCurrent:
|
||||
{
|
||||
m_pos += pos;
|
||||
break;
|
||||
}
|
||||
case wxFromEnd:
|
||||
{
|
||||
wxFileOffset len = GetLength();
|
||||
if (len == wxInvalidOffset)
|
||||
return wxInvalidOffset;
|
||||
m_pos = len + pos;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
m_pos = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
wxFileOffset wxBackedInputStream::OnSysTell() const
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILESYSTEM
|
||||
|
4262
Externals/wxWidgets/src/common/fileconf.cpp
vendored
4262
Externals/wxWidgets/src/common/fileconf.cpp
vendored
File diff suppressed because it is too large
Load Diff
4216
Externals/wxWidgets/src/common/filefn.cpp
vendored
4216
Externals/wxWidgets/src/common/filefn.cpp
vendored
File diff suppressed because it is too large
Load Diff
5074
Externals/wxWidgets/src/common/filename.cpp
vendored
5074
Externals/wxWidgets/src/common/filename.cpp
vendored
File diff suppressed because it is too large
Load Diff
448
Externals/wxWidgets/src/common/filepickercmn.cpp
vendored
448
Externals/wxWidgets/src/common/filepickercmn.cpp
vendored
@ -1,224 +1,224 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/filepickercmn.cpp
|
||||
// Purpose: wxFilePickerCtrl class implementation
|
||||
// Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
|
||||
// Modified by:
|
||||
// Created: 15/04/2006
|
||||
// RCS-ID: $Id: filepickercmn.cpp 42219 2006-10-21 19:53:05Z PC $
|
||||
// Copyright: (c) Vadim Zeitlin, Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
|
||||
|
||||
#include "wx/filepicker.h"
|
||||
#include "wx/filename.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
const wxChar wxFilePickerCtrlNameStr[] = wxT("filepicker");
|
||||
const wxChar wxFilePickerWidgetNameStr[] = wxT("filepickerwidget");
|
||||
const wxChar wxDirPickerCtrlNameStr[] = wxT("dirpicker");
|
||||
const wxChar wxDirPickerWidgetNameStr[] = wxT("dirpickerwidget");
|
||||
const wxChar wxFilePickerWidgetLabel[] = wxT("Browse");
|
||||
const wxChar wxDirPickerWidgetLabel[] = wxT("Browse");
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent, wxCommandEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDirPickerCtrlBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileDirPickerCtrlBase::CreateBase(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString &path,
|
||||
const wxString &message,
|
||||
const wxString &wildcard,
|
||||
const wxPoint &pos,
|
||||
const wxSize &size,
|
||||
long style,
|
||||
const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
wxASSERT_MSG(path.empty() || CheckPath(path), wxT("Invalid initial path!"));
|
||||
|
||||
if (!wxPickerBase::CreateBase(parent, id, path, pos, size,
|
||||
style, validator, name))
|
||||
return false;
|
||||
|
||||
if (!HasFlag(wxFLP_OPEN) && !HasFlag(wxFLP_SAVE))
|
||||
m_windowStyle |= wxFLP_OPEN; // wxFD_OPEN is the default
|
||||
|
||||
// check that the styles are not contradictory
|
||||
wxASSERT_MSG( !(HasFlag(wxFLP_SAVE) && HasFlag(wxFLP_OPEN)),
|
||||
_T("can't specify both wxFLP_SAVE and wxFLP_OPEN at once") );
|
||||
|
||||
wxASSERT_MSG( !HasFlag(wxFLP_SAVE) || !HasFlag(wxFLP_FILE_MUST_EXIST),
|
||||
_T("wxFLP_FILE_MUST_EXIST can't be used with wxFLP_SAVE" ) );
|
||||
|
||||
wxASSERT_MSG( !HasFlag(wxFLP_OPEN) || !HasFlag(wxFLP_OVERWRITE_PROMPT),
|
||||
_T("wxFLP_OVERWRITE_PROMPT can't be used with wxFLP_OPEN") );
|
||||
|
||||
// create a wxFilePickerWidget or a wxDirPickerWidget...
|
||||
m_pickerIface = CreatePicker(this, path, message, wildcard);
|
||||
if ( !m_pickerIface )
|
||||
return false;
|
||||
m_picker = m_pickerIface->AsControl();
|
||||
|
||||
// complete sizer creation
|
||||
wxPickerBase::PostCreation();
|
||||
|
||||
m_picker->Connect(GetEventType(),
|
||||
wxFileDirPickerEventHandler(wxFileDirPickerCtrlBase::OnFileDirChange),
|
||||
NULL, this);
|
||||
|
||||
// default's wxPickerBase textctrl limit is too small for this control:
|
||||
// make it bigger
|
||||
if (m_text) m_text->SetMaxLength(512);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxString wxFileDirPickerCtrlBase::GetPath() const
|
||||
{
|
||||
return m_pickerIface->GetPath();
|
||||
}
|
||||
|
||||
void wxFileDirPickerCtrlBase::SetPath(const wxString &path)
|
||||
{
|
||||
m_pickerIface->SetPath(path);
|
||||
UpdateTextCtrlFromPicker();
|
||||
}
|
||||
|
||||
void wxFileDirPickerCtrlBase::UpdatePickerFromTextCtrl()
|
||||
{
|
||||
wxASSERT(m_text);
|
||||
|
||||
if (m_bIgnoreNextTextCtrlUpdate)
|
||||
{
|
||||
// ignore this update
|
||||
m_bIgnoreNextTextCtrlUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// remove the eventually present path-separator from the end of the textctrl
|
||||
// string otherwise we would generate a wxFileDirPickerEvent when changing
|
||||
// from e.g. /home/user to /home/user/ and we want to avoid it !
|
||||
wxString newpath(GetTextCtrlValue());
|
||||
if (!CheckPath(newpath))
|
||||
return; // invalid user input
|
||||
|
||||
if (m_pickerIface->GetPath() != newpath)
|
||||
{
|
||||
m_pickerIface->SetPath(newpath);
|
||||
|
||||
// update current working directory, if necessary
|
||||
// NOTE: the path separator is required because if newpath is "C:"
|
||||
// then no change would happen
|
||||
if (IsCwdToUpdate())
|
||||
wxSetWorkingDirectory(newpath);
|
||||
|
||||
// fire an event
|
||||
wxFileDirPickerEvent event(GetEventType(), this, GetId(), newpath);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxFileDirPickerCtrlBase::UpdateTextCtrlFromPicker()
|
||||
{
|
||||
if (!m_text)
|
||||
return; // no textctrl to update
|
||||
|
||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
||||
m_bIgnoreNextTextCtrlUpdate = true;
|
||||
m_text->SetValue(m_pickerIface->GetPath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDirPickerCtrlBase - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFileDirPickerCtrlBase::OnFileDirChange(wxFileDirPickerEvent &ev)
|
||||
{
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
// the wxFilePickerWidget sent us a colour-change notification.
|
||||
// forward this event to our parent
|
||||
wxFileDirPickerEvent event(GetEventType(), this, GetId(), ev.GetPath());
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDirPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_FILEPICKERCTRL
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFilePickerCtrl, wxPickerBase)
|
||||
|
||||
bool wxFilePickerCtrl::CheckPath(const wxString& path) const
|
||||
{
|
||||
// if wxFLP_SAVE was given or wxFLP_FILE_MUST_EXIST has NOT been given we
|
||||
// must accept any path
|
||||
return HasFlag(wxFLP_SAVE) ||
|
||||
!HasFlag(wxFLP_FILE_MUST_EXIST) ||
|
||||
wxFileName::FileExists(path);
|
||||
}
|
||||
|
||||
wxString wxFilePickerCtrl::GetTextCtrlValue() const
|
||||
{
|
||||
// filter it through wxFileName to remove any spurious path separator
|
||||
return wxFileName(m_text->GetValue()).GetFullPath();
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILEPICKERCTRL
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDirPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_DIRPICKERCTRL
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDirPickerCtrl, wxPickerBase)
|
||||
|
||||
bool wxDirPickerCtrl::CheckPath(const wxString& path) const
|
||||
{
|
||||
// if wxDIRP_DIR_MUST_EXIST has NOT been given we must accept any path
|
||||
return !HasFlag(wxDIRP_DIR_MUST_EXIST) || wxFileName::DirExists(path);
|
||||
}
|
||||
|
||||
wxString wxDirPickerCtrl::GetTextCtrlValue() const
|
||||
{
|
||||
// filter it through wxFileName to remove any spurious path separator
|
||||
return wxFileName::DirName(m_text->GetValue()).GetPath();
|
||||
}
|
||||
|
||||
#endif // wxUSE_DIRPICKERCTRL
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/filepickercmn.cpp
|
||||
// Purpose: wxFilePickerCtrl class implementation
|
||||
// Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
|
||||
// Modified by:
|
||||
// Created: 15/04/2006
|
||||
// RCS-ID: $Id: filepickercmn.cpp 42219 2006-10-21 19:53:05Z PC $
|
||||
// Copyright: (c) Vadim Zeitlin, Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
|
||||
|
||||
#include "wx/filepicker.h"
|
||||
#include "wx/filename.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
const wxChar wxFilePickerCtrlNameStr[] = wxT("filepicker");
|
||||
const wxChar wxFilePickerWidgetNameStr[] = wxT("filepickerwidget");
|
||||
const wxChar wxDirPickerCtrlNameStr[] = wxT("dirpicker");
|
||||
const wxChar wxDirPickerWidgetNameStr[] = wxT("dirpickerwidget");
|
||||
const wxChar wxFilePickerWidgetLabel[] = wxT("Browse");
|
||||
const wxChar wxDirPickerWidgetLabel[] = wxT("Browse");
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED)
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent, wxCommandEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDirPickerCtrlBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileDirPickerCtrlBase::CreateBase(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString &path,
|
||||
const wxString &message,
|
||||
const wxString &wildcard,
|
||||
const wxPoint &pos,
|
||||
const wxSize &size,
|
||||
long style,
|
||||
const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
wxASSERT_MSG(path.empty() || CheckPath(path), wxT("Invalid initial path!"));
|
||||
|
||||
if (!wxPickerBase::CreateBase(parent, id, path, pos, size,
|
||||
style, validator, name))
|
||||
return false;
|
||||
|
||||
if (!HasFlag(wxFLP_OPEN) && !HasFlag(wxFLP_SAVE))
|
||||
m_windowStyle |= wxFLP_OPEN; // wxFD_OPEN is the default
|
||||
|
||||
// check that the styles are not contradictory
|
||||
wxASSERT_MSG( !(HasFlag(wxFLP_SAVE) && HasFlag(wxFLP_OPEN)),
|
||||
_T("can't specify both wxFLP_SAVE and wxFLP_OPEN at once") );
|
||||
|
||||
wxASSERT_MSG( !HasFlag(wxFLP_SAVE) || !HasFlag(wxFLP_FILE_MUST_EXIST),
|
||||
_T("wxFLP_FILE_MUST_EXIST can't be used with wxFLP_SAVE" ) );
|
||||
|
||||
wxASSERT_MSG( !HasFlag(wxFLP_OPEN) || !HasFlag(wxFLP_OVERWRITE_PROMPT),
|
||||
_T("wxFLP_OVERWRITE_PROMPT can't be used with wxFLP_OPEN") );
|
||||
|
||||
// create a wxFilePickerWidget or a wxDirPickerWidget...
|
||||
m_pickerIface = CreatePicker(this, path, message, wildcard);
|
||||
if ( !m_pickerIface )
|
||||
return false;
|
||||
m_picker = m_pickerIface->AsControl();
|
||||
|
||||
// complete sizer creation
|
||||
wxPickerBase::PostCreation();
|
||||
|
||||
m_picker->Connect(GetEventType(),
|
||||
wxFileDirPickerEventHandler(wxFileDirPickerCtrlBase::OnFileDirChange),
|
||||
NULL, this);
|
||||
|
||||
// default's wxPickerBase textctrl limit is too small for this control:
|
||||
// make it bigger
|
||||
if (m_text) m_text->SetMaxLength(512);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxString wxFileDirPickerCtrlBase::GetPath() const
|
||||
{
|
||||
return m_pickerIface->GetPath();
|
||||
}
|
||||
|
||||
void wxFileDirPickerCtrlBase::SetPath(const wxString &path)
|
||||
{
|
||||
m_pickerIface->SetPath(path);
|
||||
UpdateTextCtrlFromPicker();
|
||||
}
|
||||
|
||||
void wxFileDirPickerCtrlBase::UpdatePickerFromTextCtrl()
|
||||
{
|
||||
wxASSERT(m_text);
|
||||
|
||||
if (m_bIgnoreNextTextCtrlUpdate)
|
||||
{
|
||||
// ignore this update
|
||||
m_bIgnoreNextTextCtrlUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// remove the eventually present path-separator from the end of the textctrl
|
||||
// string otherwise we would generate a wxFileDirPickerEvent when changing
|
||||
// from e.g. /home/user to /home/user/ and we want to avoid it !
|
||||
wxString newpath(GetTextCtrlValue());
|
||||
if (!CheckPath(newpath))
|
||||
return; // invalid user input
|
||||
|
||||
if (m_pickerIface->GetPath() != newpath)
|
||||
{
|
||||
m_pickerIface->SetPath(newpath);
|
||||
|
||||
// update current working directory, if necessary
|
||||
// NOTE: the path separator is required because if newpath is "C:"
|
||||
// then no change would happen
|
||||
if (IsCwdToUpdate())
|
||||
wxSetWorkingDirectory(newpath);
|
||||
|
||||
// fire an event
|
||||
wxFileDirPickerEvent event(GetEventType(), this, GetId(), newpath);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxFileDirPickerCtrlBase::UpdateTextCtrlFromPicker()
|
||||
{
|
||||
if (!m_text)
|
||||
return; // no textctrl to update
|
||||
|
||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
||||
m_bIgnoreNextTextCtrlUpdate = true;
|
||||
m_text->SetValue(m_pickerIface->GetPath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDirPickerCtrlBase - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFileDirPickerCtrlBase::OnFileDirChange(wxFileDirPickerEvent &ev)
|
||||
{
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
// the wxFilePickerWidget sent us a colour-change notification.
|
||||
// forward this event to our parent
|
||||
wxFileDirPickerEvent event(GetEventType(), this, GetId(), ev.GetPath());
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDirPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_FILEPICKERCTRL
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFilePickerCtrl, wxPickerBase)
|
||||
|
||||
bool wxFilePickerCtrl::CheckPath(const wxString& path) const
|
||||
{
|
||||
// if wxFLP_SAVE was given or wxFLP_FILE_MUST_EXIST has NOT been given we
|
||||
// must accept any path
|
||||
return HasFlag(wxFLP_SAVE) ||
|
||||
!HasFlag(wxFLP_FILE_MUST_EXIST) ||
|
||||
wxFileName::FileExists(path);
|
||||
}
|
||||
|
||||
wxString wxFilePickerCtrl::GetTextCtrlValue() const
|
||||
{
|
||||
// filter it through wxFileName to remove any spurious path separator
|
||||
return wxFileName(m_text->GetValue()).GetFullPath();
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILEPICKERCTRL
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDirPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_DIRPICKERCTRL
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxDirPickerCtrl, wxPickerBase)
|
||||
|
||||
bool wxDirPickerCtrl::CheckPath(const wxString& path) const
|
||||
{
|
||||
// if wxDIRP_DIR_MUST_EXIST has NOT been given we must accept any path
|
||||
return !HasFlag(wxDIRP_DIR_MUST_EXIST) || wxFileName::DirExists(path);
|
||||
}
|
||||
|
||||
wxString wxDirPickerCtrl::GetTextCtrlValue() const
|
||||
{
|
||||
// filter it through wxFileName to remove any spurious path separator
|
||||
return wxFileName::DirName(m_text->GetValue()).GetPath();
|
||||
}
|
||||
|
||||
#endif // wxUSE_DIRPICKERCTRL
|
||||
|
1368
Externals/wxWidgets/src/common/filesys.cpp
vendored
1368
Externals/wxWidgets/src/common/filesys.cpp
vendored
File diff suppressed because it is too large
Load Diff
72
Externals/wxWidgets/src/common/filtall.cpp
vendored
72
Externals/wxWidgets/src/common/filtall.cpp
vendored
@ -1,36 +1,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/filtall.cpp
|
||||
// Purpose: Link all filter streams
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: filtall.cpp 42412 2006-10-25 20:41:12Z MW $
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
#if wxUSE_ZLIB
|
||||
#include "wx/zstream.h"
|
||||
#endif
|
||||
|
||||
// Reference filter classes to ensure they are linked into a statically
|
||||
// linked program that uses Find or GetFirst to look for an filter handler.
|
||||
// It is in its own file so that the user can override this behaviour by
|
||||
// providing their own implementation.
|
||||
|
||||
void wxUseFilterClasses()
|
||||
{
|
||||
#if wxUSE_ZLIB
|
||||
wxZlibClassFactory();
|
||||
wxGzipClassFactory();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/filtall.cpp
|
||||
// Purpose: Link all filter streams
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: filtall.cpp 42412 2006-10-25 20:41:12Z MW $
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
#if wxUSE_ZLIB
|
||||
#include "wx/zstream.h"
|
||||
#endif
|
||||
|
||||
// Reference filter classes to ensure they are linked into a statically
|
||||
// linked program that uses Find or GetFirst to look for an filter handler.
|
||||
// It is in its own file so that the user can override this behaviour by
|
||||
// providing their own implementation.
|
||||
|
||||
void wxUseFilterClasses()
|
||||
{
|
||||
#if wxUSE_ZLIB
|
||||
wxZlibClassFactory();
|
||||
wxGzipClassFactory();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
86
Externals/wxWidgets/src/common/filtfind.cpp
vendored
86
Externals/wxWidgets/src/common/filtfind.cpp
vendored
@ -1,43 +1,43 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/filtfind.cpp
|
||||
// Purpose: Streams for filter formats
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: filtfind.cpp 42412 2006-10-25 20:41:12Z MW $
|
||||
// Copyright: (c) Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
#include "wx/stream.h"
|
||||
|
||||
// These functions are in a separate file so that statically linked apps
|
||||
// that do not call them to search for filter handlers will only link in
|
||||
// the filter classes they use.
|
||||
|
||||
const wxFilterClassFactory *
|
||||
wxFilterClassFactory::Find(const wxChar *protocol, wxStreamProtocolType type)
|
||||
{
|
||||
for (const wxFilterClassFactory *f = GetFirst(); f; f = f->GetNext())
|
||||
if (f->CanHandle(protocol, type))
|
||||
return f;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static
|
||||
const wxFilterClassFactory *wxFilterClassFactory::GetFirst()
|
||||
{
|
||||
if (!sm_first)
|
||||
wxUseFilterClasses();
|
||||
return sm_first;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/filtfind.cpp
|
||||
// Purpose: Streams for filter formats
|
||||
// Author: Mike Wetherell
|
||||
// RCS-ID: $Id: filtfind.cpp 42412 2006-10-25 20:41:12Z MW $
|
||||
// Copyright: (c) Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
#include "wx/stream.h"
|
||||
|
||||
// These functions are in a separate file so that statically linked apps
|
||||
// that do not call them to search for filter handlers will only link in
|
||||
// the filter classes they use.
|
||||
|
||||
const wxFilterClassFactory *
|
||||
wxFilterClassFactory::Find(const wxChar *protocol, wxStreamProtocolType type)
|
||||
{
|
||||
for (const wxFilterClassFactory *f = GetFirst(); f; f = f->GetNext())
|
||||
if (f->CanHandle(protocol, type))
|
||||
return f;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static
|
||||
const wxFilterClassFactory *wxFilterClassFactory::GetFirst()
|
||||
{
|
||||
if (!sm_first)
|
||||
wxUseFilterClasses();
|
||||
return sm_first;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
696
Externals/wxWidgets/src/common/fldlgcmn.cpp
vendored
696
Externals/wxWidgets/src/common/fldlgcmn.cpp
vendored
@ -1,348 +1,348 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fldlgcmn.cpp
|
||||
// Purpose: wxFileDialog common functions
|
||||
// Author: John Labenski
|
||||
// Modified by:
|
||||
// Created: 14.06.03 (extracted from src/*/filedlg.cpp)
|
||||
// RCS-ID: $Id: fldlgcmn.cpp 47482 2007-07-15 14:12:08Z VS $
|
||||
// Copyright: (c) Robert Roebling
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if wxUSE_FILEDLG
|
||||
|
||||
#include "wx/filedlg.h"
|
||||
#include "wx/dirdlg.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/window.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileDialogBase
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDialogBase, wxDialog)
|
||||
|
||||
void wxFileDialogBase::Init()
|
||||
{
|
||||
m_filterIndex =
|
||||
m_windowStyle = 0;
|
||||
}
|
||||
|
||||
bool wxFileDialogBase::Create(wxWindow *parent,
|
||||
const wxString& message,
|
||||
const wxString& defaultDir,
|
||||
const wxString& defaultFile,
|
||||
const wxString& wildCard,
|
||||
long style,
|
||||
const wxPoint& WXUNUSED(pos),
|
||||
const wxSize& WXUNUSED(sz),
|
||||
const wxString& WXUNUSED(name))
|
||||
{
|
||||
m_message = message;
|
||||
m_dir = defaultDir;
|
||||
m_fileName = defaultFile;
|
||||
m_wildCard = wildCard;
|
||||
|
||||
m_parent = parent;
|
||||
m_windowStyle = style;
|
||||
m_filterIndex = 0;
|
||||
|
||||
if (!HasFdFlag(wxFD_OPEN) && !HasFdFlag(wxFD_SAVE))
|
||||
m_windowStyle |= wxFD_OPEN; // wxFD_OPEN is the default
|
||||
|
||||
// check that the styles are not contradictory
|
||||
wxASSERT_MSG( !(HasFdFlag(wxFD_SAVE) && HasFdFlag(wxFD_OPEN)),
|
||||
_T("can't specify both wxFD_SAVE and wxFD_OPEN at once") );
|
||||
|
||||
wxASSERT_MSG( !HasFdFlag(wxFD_SAVE) ||
|
||||
(!HasFdFlag(wxFD_MULTIPLE) && !HasFdFlag(wxFD_FILE_MUST_EXIST)),
|
||||
_T("wxFD_MULTIPLE or wxFD_FILE_MUST_EXIST can't be used with wxFD_SAVE" ) );
|
||||
|
||||
wxASSERT_MSG( !HasFdFlag(wxFD_OPEN) || !HasFdFlag(wxFD_OVERWRITE_PROMPT),
|
||||
_T("wxFD_OVERWRITE_PROMPT can't be used with wxFD_OPEN") );
|
||||
|
||||
if ( wildCard.empty() || wildCard == wxFileSelectorDefaultWildcardStr )
|
||||
{
|
||||
m_wildCard = wxString::Format(_("All files (%s)|%s"),
|
||||
wxFileSelectorDefaultWildcardStr,
|
||||
wxFileSelectorDefaultWildcardStr);
|
||||
}
|
||||
else // have wild card
|
||||
{
|
||||
// convert m_wildCard from "*.bar" to "bar files (*.bar)|*.bar"
|
||||
if ( m_wildCard.Find(wxT('|')) == wxNOT_FOUND )
|
||||
{
|
||||
wxString::size_type nDot = m_wildCard.find(_T("*."));
|
||||
if ( nDot != wxString::npos )
|
||||
nDot++;
|
||||
else
|
||||
nDot = 0;
|
||||
|
||||
m_wildCard = wxString::Format
|
||||
(
|
||||
_("%s files (%s)|%s"),
|
||||
wildCard.c_str() + nDot,
|
||||
wildCard.c_str(),
|
||||
wildCard.c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_4
|
||||
// Parses the filterStr, returning the number of filters.
|
||||
// Returns 0 if none or if there's a problem.
|
||||
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
|
||||
int wxFileDialogBase::ParseWildcard(const wxString& filterStr,
|
||||
wxArrayString& descriptions,
|
||||
wxArrayString& filters)
|
||||
{
|
||||
return ::wxParseCommonDialogsFilter(filterStr, descriptions, filters);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_4
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
long wxFileDialogBase::GetStyle() const
|
||||
{
|
||||
return GetWindowStyle();
|
||||
}
|
||||
|
||||
void wxFileDialogBase::SetStyle(long style)
|
||||
{
|
||||
SetWindowStyle(style);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
|
||||
wxString wxFileDialogBase::AppendExtension(const wxString &filePath,
|
||||
const wxString &extensionList)
|
||||
{
|
||||
// strip off path, to avoid problems with "path.bar/foo"
|
||||
wxString fileName = filePath.AfterLast(wxFILE_SEP_PATH);
|
||||
|
||||
// if fileName is of form "foo.bar" it's ok, return it
|
||||
int idx_dot = fileName.Find(wxT('.'), true);
|
||||
if ((idx_dot != wxNOT_FOUND) && (idx_dot < (int)fileName.length() - 1))
|
||||
return filePath;
|
||||
|
||||
// get the first extension from extensionList, or all of it
|
||||
wxString ext = extensionList.BeforeFirst(wxT(';'));
|
||||
|
||||
// if ext == "foo" or "foo." there's no extension
|
||||
int idx_ext_dot = ext.Find(wxT('.'), true);
|
||||
if ((idx_ext_dot == wxNOT_FOUND) || (idx_ext_dot == (int)ext.length() - 1))
|
||||
return filePath;
|
||||
else
|
||||
ext = ext.AfterLast(wxT('.'));
|
||||
|
||||
// if ext == "*" or "bar*" or "b?r" or " " then its not valid
|
||||
if ((ext.Find(wxT('*')) != wxNOT_FOUND) ||
|
||||
(ext.Find(wxT('?')) != wxNOT_FOUND) ||
|
||||
(ext.Strip(wxString::both).empty()))
|
||||
return filePath;
|
||||
|
||||
// if fileName doesn't have a '.' then add one
|
||||
if (filePath.Last() != wxT('.'))
|
||||
ext = wxT(".") + ext;
|
||||
|
||||
return filePath + ext;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileDialog convenience functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
wxString wxFileSelector(const wxChar *title,
|
||||
const wxChar *defaultDir,
|
||||
const wxChar *defaultFileName,
|
||||
const wxChar *defaultExtension,
|
||||
const wxChar *filter,
|
||||
int flags,
|
||||
wxWindow *parent,
|
||||
int x, int y)
|
||||
{
|
||||
// The defaultExtension, if non-NULL, is
|
||||
// appended to the filename if the user fails to type an extension. The new
|
||||
// implementation (taken from wxFileSelectorEx) appends the extension
|
||||
// automatically, by looking at the filter specification. In fact this
|
||||
// should be better than the native Microsoft implementation because
|
||||
// Windows only allows *one* default extension, whereas here we do the
|
||||
// right thing depending on the filter the user has chosen.
|
||||
|
||||
// If there's a default extension specified but no filter, we create a
|
||||
// suitable filter.
|
||||
|
||||
wxString filter2;
|
||||
if ( !wxIsEmpty(defaultExtension) && wxIsEmpty(filter) )
|
||||
filter2 = wxString(wxT("*.")) + defaultExtension;
|
||||
else if ( !wxIsEmpty(filter) )
|
||||
filter2 = filter;
|
||||
|
||||
wxString defaultDirString;
|
||||
if (!wxIsEmpty(defaultDir))
|
||||
defaultDirString = defaultDir;
|
||||
|
||||
wxString defaultFilenameString;
|
||||
if (!wxIsEmpty(defaultFileName))
|
||||
defaultFilenameString = defaultFileName;
|
||||
|
||||
wxFileDialog fileDialog(parent, title, defaultDirString,
|
||||
defaultFilenameString, filter2,
|
||||
flags, wxPoint(x, y));
|
||||
|
||||
// if filter is of form "All files (*)|*|..." set correct filter index
|
||||
if((wxStrlen(defaultExtension) != 0) && (filter2.Find(wxT('|')) != wxNOT_FOUND))
|
||||
{
|
||||
int filterIndex = 0;
|
||||
|
||||
wxArrayString descriptions, filters;
|
||||
// don't care about errors, handled already by wxFileDialog
|
||||
(void)wxParseCommonDialogsFilter(filter2, descriptions, filters);
|
||||
for (size_t n=0; n<filters.GetCount(); n++)
|
||||
{
|
||||
if (filters[n].Contains(defaultExtension))
|
||||
{
|
||||
filterIndex = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filterIndex > 0)
|
||||
fileDialog.SetFilterIndex(filterIndex);
|
||||
}
|
||||
|
||||
wxString filename;
|
||||
if ( fileDialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
filename = fileDialog.GetPath();
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileSelectorEx
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
wxString wxFileSelectorEx(const wxChar *title,
|
||||
const wxChar *defaultDir,
|
||||
const wxChar *defaultFileName,
|
||||
int* defaultFilterIndex,
|
||||
const wxChar *filter,
|
||||
int flags,
|
||||
wxWindow* parent,
|
||||
int x,
|
||||
int y)
|
||||
|
||||
{
|
||||
wxFileDialog fileDialog(parent,
|
||||
!wxIsEmpty(title) ? title : wxEmptyString,
|
||||
!wxIsEmpty(defaultDir) ? defaultDir : wxEmptyString,
|
||||
!wxIsEmpty(defaultFileName) ? defaultFileName : wxEmptyString,
|
||||
!wxIsEmpty(filter) ? filter : wxEmptyString,
|
||||
flags, wxPoint(x, y));
|
||||
|
||||
wxString filename;
|
||||
if ( fileDialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
if ( defaultFilterIndex )
|
||||
*defaultFilterIndex = fileDialog.GetFilterIndex();
|
||||
|
||||
filename = fileDialog.GetPath();
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxDefaultFileSelector - Generic load/save dialog (for internal use only)
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
static wxString wxDefaultFileSelector(bool load,
|
||||
const wxChar *what,
|
||||
const wxChar *extension,
|
||||
const wxChar *default_name,
|
||||
wxWindow *parent)
|
||||
{
|
||||
wxString prompt;
|
||||
wxString str;
|
||||
if (load)
|
||||
str = _("Load %s file");
|
||||
else
|
||||
str = _("Save %s file");
|
||||
prompt.Printf(str, what);
|
||||
|
||||
wxString wild;
|
||||
const wxChar *ext = extension;
|
||||
if ( !wxIsEmpty(ext) )
|
||||
{
|
||||
if ( *ext == wxT('.') )
|
||||
ext++;
|
||||
|
||||
wild.Printf(wxT("*.%s"), ext);
|
||||
}
|
||||
else // no extension specified
|
||||
{
|
||||
wild = wxFileSelectorDefaultWildcardStr;
|
||||
}
|
||||
|
||||
return wxFileSelector(prompt, NULL, default_name, ext, wild,
|
||||
load ? wxFD_OPEN : wxFD_SAVE, parent);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxLoadFileSelector
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what,
|
||||
const wxChar *extension,
|
||||
const wxChar *default_name,
|
||||
wxWindow *parent)
|
||||
{
|
||||
return wxDefaultFileSelector(true, what, extension, default_name, parent);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxSaveFileSelector
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what,
|
||||
const wxChar *extension,
|
||||
const wxChar *default_name,
|
||||
wxWindow *parent)
|
||||
{
|
||||
return wxDefaultFileSelector(false, what, extension, default_name, parent);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxDirDialogBase
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
long wxDirDialogBase::GetStyle() const
|
||||
{
|
||||
return GetWindowStyle();
|
||||
}
|
||||
|
||||
void wxDirDialogBase::SetStyle(long style)
|
||||
{
|
||||
SetWindowStyle(style);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
|
||||
#endif // wxUSE_FILEDLG
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fldlgcmn.cpp
|
||||
// Purpose: wxFileDialog common functions
|
||||
// Author: John Labenski
|
||||
// Modified by:
|
||||
// Created: 14.06.03 (extracted from src/*/filedlg.cpp)
|
||||
// RCS-ID: $Id: fldlgcmn.cpp 47482 2007-07-15 14:12:08Z VS $
|
||||
// Copyright: (c) Robert Roebling
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if wxUSE_FILEDLG
|
||||
|
||||
#include "wx/filedlg.h"
|
||||
#include "wx/dirdlg.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/window.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileDialogBase
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDialogBase, wxDialog)
|
||||
|
||||
void wxFileDialogBase::Init()
|
||||
{
|
||||
m_filterIndex =
|
||||
m_windowStyle = 0;
|
||||
}
|
||||
|
||||
bool wxFileDialogBase::Create(wxWindow *parent,
|
||||
const wxString& message,
|
||||
const wxString& defaultDir,
|
||||
const wxString& defaultFile,
|
||||
const wxString& wildCard,
|
||||
long style,
|
||||
const wxPoint& WXUNUSED(pos),
|
||||
const wxSize& WXUNUSED(sz),
|
||||
const wxString& WXUNUSED(name))
|
||||
{
|
||||
m_message = message;
|
||||
m_dir = defaultDir;
|
||||
m_fileName = defaultFile;
|
||||
m_wildCard = wildCard;
|
||||
|
||||
m_parent = parent;
|
||||
m_windowStyle = style;
|
||||
m_filterIndex = 0;
|
||||
|
||||
if (!HasFdFlag(wxFD_OPEN) && !HasFdFlag(wxFD_SAVE))
|
||||
m_windowStyle |= wxFD_OPEN; // wxFD_OPEN is the default
|
||||
|
||||
// check that the styles are not contradictory
|
||||
wxASSERT_MSG( !(HasFdFlag(wxFD_SAVE) && HasFdFlag(wxFD_OPEN)),
|
||||
_T("can't specify both wxFD_SAVE and wxFD_OPEN at once") );
|
||||
|
||||
wxASSERT_MSG( !HasFdFlag(wxFD_SAVE) ||
|
||||
(!HasFdFlag(wxFD_MULTIPLE) && !HasFdFlag(wxFD_FILE_MUST_EXIST)),
|
||||
_T("wxFD_MULTIPLE or wxFD_FILE_MUST_EXIST can't be used with wxFD_SAVE" ) );
|
||||
|
||||
wxASSERT_MSG( !HasFdFlag(wxFD_OPEN) || !HasFdFlag(wxFD_OVERWRITE_PROMPT),
|
||||
_T("wxFD_OVERWRITE_PROMPT can't be used with wxFD_OPEN") );
|
||||
|
||||
if ( wildCard.empty() || wildCard == wxFileSelectorDefaultWildcardStr )
|
||||
{
|
||||
m_wildCard = wxString::Format(_("All files (%s)|%s"),
|
||||
wxFileSelectorDefaultWildcardStr,
|
||||
wxFileSelectorDefaultWildcardStr);
|
||||
}
|
||||
else // have wild card
|
||||
{
|
||||
// convert m_wildCard from "*.bar" to "bar files (*.bar)|*.bar"
|
||||
if ( m_wildCard.Find(wxT('|')) == wxNOT_FOUND )
|
||||
{
|
||||
wxString::size_type nDot = m_wildCard.find(_T("*."));
|
||||
if ( nDot != wxString::npos )
|
||||
nDot++;
|
||||
else
|
||||
nDot = 0;
|
||||
|
||||
m_wildCard = wxString::Format
|
||||
(
|
||||
_("%s files (%s)|%s"),
|
||||
wildCard.c_str() + nDot,
|
||||
wildCard.c_str(),
|
||||
wildCard.c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_4
|
||||
// Parses the filterStr, returning the number of filters.
|
||||
// Returns 0 if none or if there's a problem.
|
||||
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
|
||||
int wxFileDialogBase::ParseWildcard(const wxString& filterStr,
|
||||
wxArrayString& descriptions,
|
||||
wxArrayString& filters)
|
||||
{
|
||||
return ::wxParseCommonDialogsFilter(filterStr, descriptions, filters);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_4
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
long wxFileDialogBase::GetStyle() const
|
||||
{
|
||||
return GetWindowStyle();
|
||||
}
|
||||
|
||||
void wxFileDialogBase::SetStyle(long style)
|
||||
{
|
||||
SetWindowStyle(style);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
|
||||
wxString wxFileDialogBase::AppendExtension(const wxString &filePath,
|
||||
const wxString &extensionList)
|
||||
{
|
||||
// strip off path, to avoid problems with "path.bar/foo"
|
||||
wxString fileName = filePath.AfterLast(wxFILE_SEP_PATH);
|
||||
|
||||
// if fileName is of form "foo.bar" it's ok, return it
|
||||
int idx_dot = fileName.Find(wxT('.'), true);
|
||||
if ((idx_dot != wxNOT_FOUND) && (idx_dot < (int)fileName.length() - 1))
|
||||
return filePath;
|
||||
|
||||
// get the first extension from extensionList, or all of it
|
||||
wxString ext = extensionList.BeforeFirst(wxT(';'));
|
||||
|
||||
// if ext == "foo" or "foo." there's no extension
|
||||
int idx_ext_dot = ext.Find(wxT('.'), true);
|
||||
if ((idx_ext_dot == wxNOT_FOUND) || (idx_ext_dot == (int)ext.length() - 1))
|
||||
return filePath;
|
||||
else
|
||||
ext = ext.AfterLast(wxT('.'));
|
||||
|
||||
// if ext == "*" or "bar*" or "b?r" or " " then its not valid
|
||||
if ((ext.Find(wxT('*')) != wxNOT_FOUND) ||
|
||||
(ext.Find(wxT('?')) != wxNOT_FOUND) ||
|
||||
(ext.Strip(wxString::both).empty()))
|
||||
return filePath;
|
||||
|
||||
// if fileName doesn't have a '.' then add one
|
||||
if (filePath.Last() != wxT('.'))
|
||||
ext = wxT(".") + ext;
|
||||
|
||||
return filePath + ext;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileDialog convenience functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
wxString wxFileSelector(const wxChar *title,
|
||||
const wxChar *defaultDir,
|
||||
const wxChar *defaultFileName,
|
||||
const wxChar *defaultExtension,
|
||||
const wxChar *filter,
|
||||
int flags,
|
||||
wxWindow *parent,
|
||||
int x, int y)
|
||||
{
|
||||
// The defaultExtension, if non-NULL, is
|
||||
// appended to the filename if the user fails to type an extension. The new
|
||||
// implementation (taken from wxFileSelectorEx) appends the extension
|
||||
// automatically, by looking at the filter specification. In fact this
|
||||
// should be better than the native Microsoft implementation because
|
||||
// Windows only allows *one* default extension, whereas here we do the
|
||||
// right thing depending on the filter the user has chosen.
|
||||
|
||||
// If there's a default extension specified but no filter, we create a
|
||||
// suitable filter.
|
||||
|
||||
wxString filter2;
|
||||
if ( !wxIsEmpty(defaultExtension) && wxIsEmpty(filter) )
|
||||
filter2 = wxString(wxT("*.")) + defaultExtension;
|
||||
else if ( !wxIsEmpty(filter) )
|
||||
filter2 = filter;
|
||||
|
||||
wxString defaultDirString;
|
||||
if (!wxIsEmpty(defaultDir))
|
||||
defaultDirString = defaultDir;
|
||||
|
||||
wxString defaultFilenameString;
|
||||
if (!wxIsEmpty(defaultFileName))
|
||||
defaultFilenameString = defaultFileName;
|
||||
|
||||
wxFileDialog fileDialog(parent, title, defaultDirString,
|
||||
defaultFilenameString, filter2,
|
||||
flags, wxPoint(x, y));
|
||||
|
||||
// if filter is of form "All files (*)|*|..." set correct filter index
|
||||
if((wxStrlen(defaultExtension) != 0) && (filter2.Find(wxT('|')) != wxNOT_FOUND))
|
||||
{
|
||||
int filterIndex = 0;
|
||||
|
||||
wxArrayString descriptions, filters;
|
||||
// don't care about errors, handled already by wxFileDialog
|
||||
(void)wxParseCommonDialogsFilter(filter2, descriptions, filters);
|
||||
for (size_t n=0; n<filters.GetCount(); n++)
|
||||
{
|
||||
if (filters[n].Contains(defaultExtension))
|
||||
{
|
||||
filterIndex = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filterIndex > 0)
|
||||
fileDialog.SetFilterIndex(filterIndex);
|
||||
}
|
||||
|
||||
wxString filename;
|
||||
if ( fileDialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
filename = fileDialog.GetPath();
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFileSelectorEx
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
wxString wxFileSelectorEx(const wxChar *title,
|
||||
const wxChar *defaultDir,
|
||||
const wxChar *defaultFileName,
|
||||
int* defaultFilterIndex,
|
||||
const wxChar *filter,
|
||||
int flags,
|
||||
wxWindow* parent,
|
||||
int x,
|
||||
int y)
|
||||
|
||||
{
|
||||
wxFileDialog fileDialog(parent,
|
||||
!wxIsEmpty(title) ? title : wxEmptyString,
|
||||
!wxIsEmpty(defaultDir) ? defaultDir : wxEmptyString,
|
||||
!wxIsEmpty(defaultFileName) ? defaultFileName : wxEmptyString,
|
||||
!wxIsEmpty(filter) ? filter : wxEmptyString,
|
||||
flags, wxPoint(x, y));
|
||||
|
||||
wxString filename;
|
||||
if ( fileDialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
if ( defaultFilterIndex )
|
||||
*defaultFilterIndex = fileDialog.GetFilterIndex();
|
||||
|
||||
filename = fileDialog.GetPath();
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxDefaultFileSelector - Generic load/save dialog (for internal use only)
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
static wxString wxDefaultFileSelector(bool load,
|
||||
const wxChar *what,
|
||||
const wxChar *extension,
|
||||
const wxChar *default_name,
|
||||
wxWindow *parent)
|
||||
{
|
||||
wxString prompt;
|
||||
wxString str;
|
||||
if (load)
|
||||
str = _("Load %s file");
|
||||
else
|
||||
str = _("Save %s file");
|
||||
prompt.Printf(str, what);
|
||||
|
||||
wxString wild;
|
||||
const wxChar *ext = extension;
|
||||
if ( !wxIsEmpty(ext) )
|
||||
{
|
||||
if ( *ext == wxT('.') )
|
||||
ext++;
|
||||
|
||||
wild.Printf(wxT("*.%s"), ext);
|
||||
}
|
||||
else // no extension specified
|
||||
{
|
||||
wild = wxFileSelectorDefaultWildcardStr;
|
||||
}
|
||||
|
||||
return wxFileSelector(prompt, NULL, default_name, ext, wild,
|
||||
load ? wxFD_OPEN : wxFD_SAVE, parent);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxLoadFileSelector
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what,
|
||||
const wxChar *extension,
|
||||
const wxChar *default_name,
|
||||
wxWindow *parent)
|
||||
{
|
||||
return wxDefaultFileSelector(true, what, extension, default_name, parent);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxSaveFileSelector
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what,
|
||||
const wxChar *extension,
|
||||
const wxChar *default_name,
|
||||
wxWindow *parent)
|
||||
{
|
||||
return wxDefaultFileSelector(false, what, extension, default_name, parent);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxDirDialogBase
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
long wxDirDialogBase::GetStyle() const
|
||||
{
|
||||
return GetWindowStyle();
|
||||
}
|
||||
|
||||
void wxDirDialogBase::SetStyle(long style)
|
||||
{
|
||||
SetWindowStyle(style);
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
|
||||
#endif // wxUSE_FILEDLG
|
||||
|
1474
Externals/wxWidgets/src/common/fmapbase.cpp
vendored
1474
Externals/wxWidgets/src/common/fmapbase.cpp
vendored
File diff suppressed because it is too large
Load Diff
1568
Externals/wxWidgets/src/common/fontcmn.cpp
vendored
1568
Externals/wxWidgets/src/common/fontcmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
262
Externals/wxWidgets/src/common/fontenumcmn.cpp
vendored
262
Externals/wxWidgets/src/common/fontenumcmn.cpp
vendored
@ -1,131 +1,131 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fontenumcmn.cpp
|
||||
// Purpose: wxFontEnumerator class
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 7/5/2006
|
||||
// RCS-ID: $Id: fontenumcmn.cpp 43727 2006-12-01 10:14:28Z VS $
|
||||
// Copyright: (c) 1999-2003 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/fontenum.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// A simple wxFontEnumerator which doesn't perform any filtering and
|
||||
// just returns all facenames and encodings found in the system
|
||||
class WXDLLEXPORT wxSimpleFontEnumerator : public wxFontEnumerator
|
||||
{
|
||||
public:
|
||||
wxSimpleFontEnumerator() { }
|
||||
|
||||
// called by EnumerateFacenames
|
||||
virtual bool OnFacename(const wxString& facename)
|
||||
{
|
||||
m_arrFacenames.Add(facename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// called by EnumerateEncodings
|
||||
virtual bool OnFontEncoding(const wxString& WXUNUSED(facename),
|
||||
const wxString& encoding)
|
||||
{
|
||||
m_arrEncodings.Add(encoding);
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
wxArrayString m_arrFacenames, m_arrEncodings;
|
||||
};
|
||||
|
||||
|
||||
/* static */
|
||||
wxArrayString wxFontEnumerator::GetFacenames(wxFontEncoding encoding, bool fixedWidthOnly)
|
||||
{
|
||||
wxSimpleFontEnumerator temp;
|
||||
temp.EnumerateFacenames(encoding, fixedWidthOnly);
|
||||
return temp.m_arrFacenames;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxArrayString wxFontEnumerator::GetEncodings(const wxString& facename)
|
||||
{
|
||||
wxSimpleFontEnumerator temp;
|
||||
temp.EnumerateEncodings(facename);
|
||||
return temp.m_arrEncodings;
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool wxFontEnumerator::IsValidFacename(const wxString &facename)
|
||||
{
|
||||
// we cache the result of wxFontEnumerator::GetFacenames supposing that
|
||||
// the array of face names won't change in the session of this program
|
||||
static wxArrayString s_arr = wxFontEnumerator::GetFacenames();
|
||||
|
||||
#ifdef __WXMSW__
|
||||
// Quoting the MSDN:
|
||||
// "MS Shell Dlg is a mapping mechanism that enables
|
||||
// U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
|
||||
// support locales that have characters that are not contained in code
|
||||
// page 1252. It is not a font but a face name for a nonexistent font."
|
||||
// Thus we need to consider "Ms Shell Dlg" and "Ms Shell Dlg 2" as valid
|
||||
// font face names even if they are enumerated by wxFontEnumerator
|
||||
if (facename.IsSameAs(wxT("Ms Shell Dlg"), false) ||
|
||||
facename.IsSameAs(wxT("Ms Shell Dlg 2"), false))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
// is given font face name a valid one ?
|
||||
if (s_arr.Index(facename, false) == wxNOT_FOUND)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef wxHAS_UTF8_FONTS
|
||||
bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString& facename)
|
||||
{
|
||||
// name of UTF-8 encoding: no need to use wxFontMapper for it as it's
|
||||
// unlikely to change
|
||||
const wxString utf8(_T("UTF-8"));
|
||||
|
||||
// all fonts are in UTF-8 only if this code is used
|
||||
if ( !facename.empty() )
|
||||
{
|
||||
OnFontEncoding(facename, utf8);
|
||||
return true;
|
||||
}
|
||||
|
||||
// so enumerating all facenames supporting this encoding is the same as
|
||||
// enumerating all facenames
|
||||
const wxArrayString facenames(GetFacenames(wxFONTENCODING_UTF8));
|
||||
const size_t count = facenames.size();
|
||||
if ( !count )
|
||||
return false;
|
||||
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
{
|
||||
OnFontEncoding(facenames[n], utf8);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // wxHAS_UTF8_FONTS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fontenumcmn.cpp
|
||||
// Purpose: wxFontEnumerator class
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 7/5/2006
|
||||
// RCS-ID: $Id: fontenumcmn.cpp 43727 2006-12-01 10:14:28Z VS $
|
||||
// Copyright: (c) 1999-2003 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/fontenum.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// A simple wxFontEnumerator which doesn't perform any filtering and
|
||||
// just returns all facenames and encodings found in the system
|
||||
class WXDLLEXPORT wxSimpleFontEnumerator : public wxFontEnumerator
|
||||
{
|
||||
public:
|
||||
wxSimpleFontEnumerator() { }
|
||||
|
||||
// called by EnumerateFacenames
|
||||
virtual bool OnFacename(const wxString& facename)
|
||||
{
|
||||
m_arrFacenames.Add(facename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// called by EnumerateEncodings
|
||||
virtual bool OnFontEncoding(const wxString& WXUNUSED(facename),
|
||||
const wxString& encoding)
|
||||
{
|
||||
m_arrEncodings.Add(encoding);
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
wxArrayString m_arrFacenames, m_arrEncodings;
|
||||
};
|
||||
|
||||
|
||||
/* static */
|
||||
wxArrayString wxFontEnumerator::GetFacenames(wxFontEncoding encoding, bool fixedWidthOnly)
|
||||
{
|
||||
wxSimpleFontEnumerator temp;
|
||||
temp.EnumerateFacenames(encoding, fixedWidthOnly);
|
||||
return temp.m_arrFacenames;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxArrayString wxFontEnumerator::GetEncodings(const wxString& facename)
|
||||
{
|
||||
wxSimpleFontEnumerator temp;
|
||||
temp.EnumerateEncodings(facename);
|
||||
return temp.m_arrEncodings;
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool wxFontEnumerator::IsValidFacename(const wxString &facename)
|
||||
{
|
||||
// we cache the result of wxFontEnumerator::GetFacenames supposing that
|
||||
// the array of face names won't change in the session of this program
|
||||
static wxArrayString s_arr = wxFontEnumerator::GetFacenames();
|
||||
|
||||
#ifdef __WXMSW__
|
||||
// Quoting the MSDN:
|
||||
// "MS Shell Dlg is a mapping mechanism that enables
|
||||
// U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
|
||||
// support locales that have characters that are not contained in code
|
||||
// page 1252. It is not a font but a face name for a nonexistent font."
|
||||
// Thus we need to consider "Ms Shell Dlg" and "Ms Shell Dlg 2" as valid
|
||||
// font face names even if they are enumerated by wxFontEnumerator
|
||||
if (facename.IsSameAs(wxT("Ms Shell Dlg"), false) ||
|
||||
facename.IsSameAs(wxT("Ms Shell Dlg 2"), false))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
// is given font face name a valid one ?
|
||||
if (s_arr.Index(facename, false) == wxNOT_FOUND)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef wxHAS_UTF8_FONTS
|
||||
bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString& facename)
|
||||
{
|
||||
// name of UTF-8 encoding: no need to use wxFontMapper for it as it's
|
||||
// unlikely to change
|
||||
const wxString utf8(_T("UTF-8"));
|
||||
|
||||
// all fonts are in UTF-8 only if this code is used
|
||||
if ( !facename.empty() )
|
||||
{
|
||||
OnFontEncoding(facename, utf8);
|
||||
return true;
|
||||
}
|
||||
|
||||
// so enumerating all facenames supporting this encoding is the same as
|
||||
// enumerating all facenames
|
||||
const wxArrayString facenames(GetFacenames(wxFONTENCODING_UTF8));
|
||||
const size_t count = facenames.size();
|
||||
if ( !count )
|
||||
return false;
|
||||
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
{
|
||||
OnFontEncoding(facenames[n], utf8);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // wxHAS_UTF8_FONTS
|
||||
|
1038
Externals/wxWidgets/src/common/fontmap.cpp
vendored
1038
Externals/wxWidgets/src/common/fontmap.cpp
vendored
File diff suppressed because it is too large
Load Diff
690
Externals/wxWidgets/src/common/fontmgrcmn.cpp
vendored
690
Externals/wxWidgets/src/common/fontmgrcmn.cpp
vendored
@ -1,345 +1,345 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fontmgrcmn.cpp
|
||||
// Purpose: font management for ports that don't have their own
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2006-11-18
|
||||
// RCS-ID: $Id: fontmgrcmn.cpp 43550 2006-11-20 20:45:57Z VS $
|
||||
// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
|
||||
// (c) 2006 REA Elektronik GmbH
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/private/fontmgr.h"
|
||||
|
||||
#include "wx/listimpl.cpp"
|
||||
#include "wx/hashmap.h"
|
||||
|
||||
WX_DECLARE_LIST(wxFontInstance, wxFontInstanceList);
|
||||
WX_DEFINE_LIST(wxFontInstanceList)
|
||||
WX_DEFINE_LIST(wxFontBundleList)
|
||||
WX_DECLARE_HASH_MAP(wxString, wxFontBundle*,
|
||||
wxStringHash, wxStringEqual,
|
||||
wxFontBundleHash);
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontFaceBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontFaceBase::wxFontFaceBase()
|
||||
: m_refCnt(0)
|
||||
{
|
||||
m_instances = new wxFontInstanceList;
|
||||
m_instances->DeleteContents(true);
|
||||
}
|
||||
|
||||
wxFontFaceBase::~wxFontFaceBase()
|
||||
{
|
||||
delete m_instances;
|
||||
}
|
||||
|
||||
void wxFontFaceBase::Acquire()
|
||||
{
|
||||
m_refCnt++;
|
||||
}
|
||||
|
||||
void wxFontFaceBase::Release()
|
||||
{
|
||||
if ( --m_refCnt == 0 )
|
||||
{
|
||||
m_instances->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
wxFontInstance *wxFontFaceBase::GetFontInstance(float ptSize, bool aa)
|
||||
{
|
||||
wxASSERT_MSG( m_refCnt > 0, _T("font library not loaded!") );
|
||||
|
||||
wxFontInstance *i;
|
||||
wxFontInstanceList::Node *node;
|
||||
|
||||
for ( node = m_instances->GetFirst(); node; node = node->GetNext() )
|
||||
{
|
||||
i = node->GetData();
|
||||
if ( i->GetPointSize() == ptSize && i->IsAntiAliased() == aa )
|
||||
return i;
|
||||
}
|
||||
|
||||
i = CreateFontInstance(ptSize, aa);
|
||||
m_instances->Append(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontBundleBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontBundleBase::wxFontBundleBase()
|
||||
{
|
||||
for (int i = 0; i < FaceType_Max; i++)
|
||||
m_faces[i] = NULL;
|
||||
}
|
||||
|
||||
wxFontBundleBase::~wxFontBundleBase()
|
||||
{
|
||||
for (int i = 0; i < FaceType_Max; i++)
|
||||
delete m_faces[i];
|
||||
}
|
||||
|
||||
wxFontFace *wxFontBundleBase::GetFace(FaceType type) const
|
||||
{
|
||||
wxFontFace *f = m_faces[type];
|
||||
|
||||
wxCHECK_MSG( f, NULL, _T("no such face in font bundle") );
|
||||
|
||||
f->Acquire();
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
wxFontFace *
|
||||
wxFontBundleBase::GetFaceForFont(const wxFontMgrFontRefData& font) const
|
||||
{
|
||||
wxASSERT_MSG( font.GetFaceName().empty() || font.GetFaceName() == GetName(),
|
||||
_T("calling GetFaceForFont for incompatible font") );
|
||||
|
||||
int type = FaceType_Regular;
|
||||
|
||||
if ( font.GetWeight() == wxBOLD )
|
||||
type |= FaceType_Bold;
|
||||
|
||||
// FIXME -- this should read "if ( font->GetStyle() == wxITALIC )",
|
||||
// but since MGL neither DFB supports slant, we try to display it with
|
||||
// italic face (better than nothing...)
|
||||
if ( font.GetStyle() == wxITALIC || font.GetStyle() == wxSLANT )
|
||||
{
|
||||
if ( HasFace((FaceType)(type | FaceType_Italic)) )
|
||||
type |= FaceType_Italic;
|
||||
}
|
||||
|
||||
if ( !HasFace((FaceType)type) )
|
||||
{
|
||||
for (int i = 0; i < FaceType_Max; i++)
|
||||
{
|
||||
if ( HasFace((FaceType)i) )
|
||||
return GetFace((FaceType)i);
|
||||
}
|
||||
|
||||
wxFAIL_MSG( _T("no face") );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return GetFace((FaceType)type);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontsManagerBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontsManager *wxFontsManagerBase::ms_instance = NULL;
|
||||
|
||||
wxFontsManagerBase::wxFontsManagerBase()
|
||||
{
|
||||
m_hash = new wxFontBundleHash();
|
||||
m_list = new wxFontBundleList;
|
||||
m_list->DeleteContents(true);
|
||||
}
|
||||
|
||||
wxFontsManagerBase::~wxFontsManagerBase()
|
||||
{
|
||||
delete m_hash;
|
||||
delete m_list;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxFontsManager *wxFontsManagerBase::Get()
|
||||
{
|
||||
if ( !ms_instance )
|
||||
ms_instance = new wxFontsManager();
|
||||
return ms_instance;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void wxFontsManagerBase::CleanUp()
|
||||
{
|
||||
wxDELETE(ms_instance);
|
||||
}
|
||||
|
||||
wxFontBundle *wxFontsManagerBase::GetBundle(const wxString& name) const
|
||||
{
|
||||
return (*m_hash)[name.Lower()];
|
||||
}
|
||||
|
||||
wxFontBundle *
|
||||
wxFontsManagerBase::GetBundleForFont(const wxFontMgrFontRefData& font) const
|
||||
{
|
||||
wxFontBundle *bundle = NULL;
|
||||
|
||||
wxString facename = font.GetFaceName();
|
||||
if ( !facename.empty() )
|
||||
bundle = GetBundle(facename);
|
||||
|
||||
if ( !bundle )
|
||||
{
|
||||
facename = GetDefaultFacename((wxFontFamily)font.GetFamily());
|
||||
if ( !facename.empty() )
|
||||
bundle = GetBundle(facename);
|
||||
}
|
||||
|
||||
if ( !bundle )
|
||||
{
|
||||
if ( m_list->GetFirst() )
|
||||
bundle = m_list->GetFirst()->GetData();
|
||||
else
|
||||
wxFAIL_MSG(wxT("Fatal error, no fonts available!"));
|
||||
}
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
void wxFontsManagerBase::AddBundle(wxFontBundle *bundle)
|
||||
{
|
||||
(*m_hash)[bundle->GetName().Lower()] = bundle;
|
||||
m_list->Append(bundle);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontMgrFontRefData
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontMgrFontRefData::wxFontMgrFontRefData(int size,
|
||||
int family,
|
||||
int style,
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
if ( family == wxDEFAULT )
|
||||
family = wxSWISS;
|
||||
if ( style == wxDEFAULT )
|
||||
style = wxNORMAL;
|
||||
if ( weight == wxDEFAULT )
|
||||
weight = wxNORMAL;
|
||||
if ( size == wxDEFAULT )
|
||||
size = 12;
|
||||
|
||||
m_info.family = (wxFontFamily)family;
|
||||
m_info.faceName = faceName;
|
||||
m_info.style = (wxFontStyle)style;
|
||||
m_info.weight = (wxFontWeight)weight;
|
||||
m_info.pointSize = size;
|
||||
m_info.underlined = underlined;
|
||||
m_info.encoding = encoding;
|
||||
|
||||
m_noAA = false;
|
||||
|
||||
m_fontFace = NULL;
|
||||
m_fontBundle = NULL;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
wxFontMgrFontRefData::wxFontMgrFontRefData(const wxFontMgrFontRefData& data)
|
||||
{
|
||||
m_info = data.m_info;
|
||||
m_noAA = data.m_noAA;
|
||||
|
||||
m_fontFace = data.m_fontFace;
|
||||
m_fontBundle = data.m_fontBundle;
|
||||
m_fontValid = data.m_fontValid;
|
||||
if ( m_fontFace )
|
||||
m_fontFace->Acquire();
|
||||
}
|
||||
|
||||
wxFontMgrFontRefData::~wxFontMgrFontRefData()
|
||||
{
|
||||
if ( m_fontFace )
|
||||
m_fontFace->Release();
|
||||
}
|
||||
|
||||
wxFontBundle *wxFontMgrFontRefData::GetFontBundle() const
|
||||
{
|
||||
wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont();
|
||||
return m_fontBundle;
|
||||
}
|
||||
|
||||
wxFontInstance *
|
||||
wxFontMgrFontRefData::GetFontInstance(float scale, bool antialiased) const
|
||||
{
|
||||
wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont();
|
||||
return m_fontFace->GetFontInstance(m_info.pointSize * scale,
|
||||
antialiased && !m_noAA);
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetPointSize(int pointSize)
|
||||
{
|
||||
m_info.pointSize = pointSize;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetFamily(int family)
|
||||
{
|
||||
m_info.family = (wxFontFamily)family;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetStyle(int style)
|
||||
{
|
||||
m_info.style = (wxFontStyle)style;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetWeight(int weight)
|
||||
{
|
||||
m_info.weight = (wxFontWeight)weight;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetFaceName(const wxString& faceName)
|
||||
{
|
||||
m_info.faceName = faceName;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetUnderlined(bool underlined)
|
||||
{
|
||||
m_info.underlined = underlined;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetEncoding(wxFontEncoding encoding)
|
||||
{
|
||||
m_info.encoding = encoding;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetNoAntiAliasing(bool no)
|
||||
{
|
||||
m_noAA = no;
|
||||
}
|
||||
|
||||
|
||||
void wxFontMgrFontRefData::EnsureValidFont()
|
||||
{
|
||||
if ( !m_fontValid )
|
||||
{
|
||||
wxFontFace *old = m_fontFace;
|
||||
|
||||
m_fontBundle = wxFontsManager::Get()->GetBundleForFont(*this);
|
||||
m_fontFace = m_fontBundle->GetFaceForFont(*this);
|
||||
|
||||
if ( old )
|
||||
old->Release();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fontmgrcmn.cpp
|
||||
// Purpose: font management for ports that don't have their own
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2006-11-18
|
||||
// RCS-ID: $Id: fontmgrcmn.cpp 43550 2006-11-20 20:45:57Z VS $
|
||||
// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
|
||||
// (c) 2006 REA Elektronik GmbH
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/private/fontmgr.h"
|
||||
|
||||
#include "wx/listimpl.cpp"
|
||||
#include "wx/hashmap.h"
|
||||
|
||||
WX_DECLARE_LIST(wxFontInstance, wxFontInstanceList);
|
||||
WX_DEFINE_LIST(wxFontInstanceList)
|
||||
WX_DEFINE_LIST(wxFontBundleList)
|
||||
WX_DECLARE_HASH_MAP(wxString, wxFontBundle*,
|
||||
wxStringHash, wxStringEqual,
|
||||
wxFontBundleHash);
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontFaceBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontFaceBase::wxFontFaceBase()
|
||||
: m_refCnt(0)
|
||||
{
|
||||
m_instances = new wxFontInstanceList;
|
||||
m_instances->DeleteContents(true);
|
||||
}
|
||||
|
||||
wxFontFaceBase::~wxFontFaceBase()
|
||||
{
|
||||
delete m_instances;
|
||||
}
|
||||
|
||||
void wxFontFaceBase::Acquire()
|
||||
{
|
||||
m_refCnt++;
|
||||
}
|
||||
|
||||
void wxFontFaceBase::Release()
|
||||
{
|
||||
if ( --m_refCnt == 0 )
|
||||
{
|
||||
m_instances->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
wxFontInstance *wxFontFaceBase::GetFontInstance(float ptSize, bool aa)
|
||||
{
|
||||
wxASSERT_MSG( m_refCnt > 0, _T("font library not loaded!") );
|
||||
|
||||
wxFontInstance *i;
|
||||
wxFontInstanceList::Node *node;
|
||||
|
||||
for ( node = m_instances->GetFirst(); node; node = node->GetNext() )
|
||||
{
|
||||
i = node->GetData();
|
||||
if ( i->GetPointSize() == ptSize && i->IsAntiAliased() == aa )
|
||||
return i;
|
||||
}
|
||||
|
||||
i = CreateFontInstance(ptSize, aa);
|
||||
m_instances->Append(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontBundleBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontBundleBase::wxFontBundleBase()
|
||||
{
|
||||
for (int i = 0; i < FaceType_Max; i++)
|
||||
m_faces[i] = NULL;
|
||||
}
|
||||
|
||||
wxFontBundleBase::~wxFontBundleBase()
|
||||
{
|
||||
for (int i = 0; i < FaceType_Max; i++)
|
||||
delete m_faces[i];
|
||||
}
|
||||
|
||||
wxFontFace *wxFontBundleBase::GetFace(FaceType type) const
|
||||
{
|
||||
wxFontFace *f = m_faces[type];
|
||||
|
||||
wxCHECK_MSG( f, NULL, _T("no such face in font bundle") );
|
||||
|
||||
f->Acquire();
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
wxFontFace *
|
||||
wxFontBundleBase::GetFaceForFont(const wxFontMgrFontRefData& font) const
|
||||
{
|
||||
wxASSERT_MSG( font.GetFaceName().empty() || font.GetFaceName() == GetName(),
|
||||
_T("calling GetFaceForFont for incompatible font") );
|
||||
|
||||
int type = FaceType_Regular;
|
||||
|
||||
if ( font.GetWeight() == wxBOLD )
|
||||
type |= FaceType_Bold;
|
||||
|
||||
// FIXME -- this should read "if ( font->GetStyle() == wxITALIC )",
|
||||
// but since MGL neither DFB supports slant, we try to display it with
|
||||
// italic face (better than nothing...)
|
||||
if ( font.GetStyle() == wxITALIC || font.GetStyle() == wxSLANT )
|
||||
{
|
||||
if ( HasFace((FaceType)(type | FaceType_Italic)) )
|
||||
type |= FaceType_Italic;
|
||||
}
|
||||
|
||||
if ( !HasFace((FaceType)type) )
|
||||
{
|
||||
for (int i = 0; i < FaceType_Max; i++)
|
||||
{
|
||||
if ( HasFace((FaceType)i) )
|
||||
return GetFace((FaceType)i);
|
||||
}
|
||||
|
||||
wxFAIL_MSG( _T("no face") );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return GetFace((FaceType)type);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontsManagerBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontsManager *wxFontsManagerBase::ms_instance = NULL;
|
||||
|
||||
wxFontsManagerBase::wxFontsManagerBase()
|
||||
{
|
||||
m_hash = new wxFontBundleHash();
|
||||
m_list = new wxFontBundleList;
|
||||
m_list->DeleteContents(true);
|
||||
}
|
||||
|
||||
wxFontsManagerBase::~wxFontsManagerBase()
|
||||
{
|
||||
delete m_hash;
|
||||
delete m_list;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxFontsManager *wxFontsManagerBase::Get()
|
||||
{
|
||||
if ( !ms_instance )
|
||||
ms_instance = new wxFontsManager();
|
||||
return ms_instance;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void wxFontsManagerBase::CleanUp()
|
||||
{
|
||||
wxDELETE(ms_instance);
|
||||
}
|
||||
|
||||
wxFontBundle *wxFontsManagerBase::GetBundle(const wxString& name) const
|
||||
{
|
||||
return (*m_hash)[name.Lower()];
|
||||
}
|
||||
|
||||
wxFontBundle *
|
||||
wxFontsManagerBase::GetBundleForFont(const wxFontMgrFontRefData& font) const
|
||||
{
|
||||
wxFontBundle *bundle = NULL;
|
||||
|
||||
wxString facename = font.GetFaceName();
|
||||
if ( !facename.empty() )
|
||||
bundle = GetBundle(facename);
|
||||
|
||||
if ( !bundle )
|
||||
{
|
||||
facename = GetDefaultFacename((wxFontFamily)font.GetFamily());
|
||||
if ( !facename.empty() )
|
||||
bundle = GetBundle(facename);
|
||||
}
|
||||
|
||||
if ( !bundle )
|
||||
{
|
||||
if ( m_list->GetFirst() )
|
||||
bundle = m_list->GetFirst()->GetData();
|
||||
else
|
||||
wxFAIL_MSG(wxT("Fatal error, no fonts available!"));
|
||||
}
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
void wxFontsManagerBase::AddBundle(wxFontBundle *bundle)
|
||||
{
|
||||
(*m_hash)[bundle->GetName().Lower()] = bundle;
|
||||
m_list->Append(bundle);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontMgrFontRefData
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontMgrFontRefData::wxFontMgrFontRefData(int size,
|
||||
int family,
|
||||
int style,
|
||||
int weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
if ( family == wxDEFAULT )
|
||||
family = wxSWISS;
|
||||
if ( style == wxDEFAULT )
|
||||
style = wxNORMAL;
|
||||
if ( weight == wxDEFAULT )
|
||||
weight = wxNORMAL;
|
||||
if ( size == wxDEFAULT )
|
||||
size = 12;
|
||||
|
||||
m_info.family = (wxFontFamily)family;
|
||||
m_info.faceName = faceName;
|
||||
m_info.style = (wxFontStyle)style;
|
||||
m_info.weight = (wxFontWeight)weight;
|
||||
m_info.pointSize = size;
|
||||
m_info.underlined = underlined;
|
||||
m_info.encoding = encoding;
|
||||
|
||||
m_noAA = false;
|
||||
|
||||
m_fontFace = NULL;
|
||||
m_fontBundle = NULL;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
wxFontMgrFontRefData::wxFontMgrFontRefData(const wxFontMgrFontRefData& data)
|
||||
{
|
||||
m_info = data.m_info;
|
||||
m_noAA = data.m_noAA;
|
||||
|
||||
m_fontFace = data.m_fontFace;
|
||||
m_fontBundle = data.m_fontBundle;
|
||||
m_fontValid = data.m_fontValid;
|
||||
if ( m_fontFace )
|
||||
m_fontFace->Acquire();
|
||||
}
|
||||
|
||||
wxFontMgrFontRefData::~wxFontMgrFontRefData()
|
||||
{
|
||||
if ( m_fontFace )
|
||||
m_fontFace->Release();
|
||||
}
|
||||
|
||||
wxFontBundle *wxFontMgrFontRefData::GetFontBundle() const
|
||||
{
|
||||
wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont();
|
||||
return m_fontBundle;
|
||||
}
|
||||
|
||||
wxFontInstance *
|
||||
wxFontMgrFontRefData::GetFontInstance(float scale, bool antialiased) const
|
||||
{
|
||||
wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont();
|
||||
return m_fontFace->GetFontInstance(m_info.pointSize * scale,
|
||||
antialiased && !m_noAA);
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetPointSize(int pointSize)
|
||||
{
|
||||
m_info.pointSize = pointSize;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetFamily(int family)
|
||||
{
|
||||
m_info.family = (wxFontFamily)family;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetStyle(int style)
|
||||
{
|
||||
m_info.style = (wxFontStyle)style;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetWeight(int weight)
|
||||
{
|
||||
m_info.weight = (wxFontWeight)weight;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetFaceName(const wxString& faceName)
|
||||
{
|
||||
m_info.faceName = faceName;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetUnderlined(bool underlined)
|
||||
{
|
||||
m_info.underlined = underlined;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetEncoding(wxFontEncoding encoding)
|
||||
{
|
||||
m_info.encoding = encoding;
|
||||
m_fontValid = false;
|
||||
}
|
||||
|
||||
void wxFontMgrFontRefData::SetNoAntiAliasing(bool no)
|
||||
{
|
||||
m_noAA = no;
|
||||
}
|
||||
|
||||
|
||||
void wxFontMgrFontRefData::EnsureValidFont()
|
||||
{
|
||||
if ( !m_fontValid )
|
||||
{
|
||||
wxFontFace *old = m_fontFace;
|
||||
|
||||
m_fontBundle = wxFontsManager::Get()->GetBundleForFont(*this);
|
||||
m_fontFace = m_fontBundle->GetFaceForFont(*this);
|
||||
|
||||
if ( old )
|
||||
old->Release();
|
||||
}
|
||||
}
|
||||
|
362
Externals/wxWidgets/src/common/fontpickercmn.cpp
vendored
362
Externals/wxWidgets/src/common/fontpickercmn.cpp
vendored
@ -1,181 +1,181 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fontpickercmn.cpp
|
||||
// Purpose: wxFontPickerCtrl class implementation
|
||||
// Author: Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 15/04/2006
|
||||
// RCS-ID: $Id: fontpickercmn.cpp 42999 2006-11-03 21:54:13Z VZ $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FONTPICKERCTRL
|
||||
|
||||
#include "wx/fontpicker.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
#include "wx/fontenum.h"
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
const wxChar wxFontPickerCtrlNameStr[] = wxT("fontpicker");
|
||||
const wxChar wxFontPickerWidgetNameStr[] = wxT("fontpickerwidget");
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FONTPICKER_CHANGED)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontPickerCtrl, wxPickerBase)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontPickerEvent, wxCommandEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define M_PICKER ((wxFontPickerWidget*)m_picker)
|
||||
|
||||
bool wxFontPickerCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||
const wxFont &initial,
|
||||
const wxPoint &pos, const wxSize &size,
|
||||
long style, const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
if (!wxPickerBase::CreateBase(parent, id,
|
||||
Font2String(initial.IsOk() ? initial
|
||||
: *wxNORMAL_FONT),
|
||||
pos, size, style, validator, name))
|
||||
return false;
|
||||
|
||||
// the picker of a wxFontPickerCtrl is a wxFontPickerWidget
|
||||
m_picker = new wxFontPickerWidget(this, wxID_ANY, initial,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
GetPickerStyle(style));
|
||||
// complete sizer creation
|
||||
wxPickerBase::PostCreation();
|
||||
|
||||
m_picker->Connect(wxEVT_COMMAND_FONTPICKER_CHANGED,
|
||||
wxFontPickerEventHandler(wxFontPickerCtrl::OnFontChange),
|
||||
NULL, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxString wxFontPickerCtrl::Font2String(const wxFont &f)
|
||||
{
|
||||
wxString ret = f.GetNativeFontInfoUserDesc();
|
||||
#ifdef __WXMSW__
|
||||
// on wxMSW the encoding of the font is appended at the end of the string;
|
||||
// since encoding is not very user-friendly we remove it.
|
||||
wxFontEncoding enc = f.GetEncoding();
|
||||
if ( enc != wxFONTENCODING_DEFAULT && enc != wxFONTENCODING_SYSTEM )
|
||||
ret = ret.BeforeLast(wxT(' '));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
wxFont wxFontPickerCtrl::String2Font(const wxString &s)
|
||||
{
|
||||
wxString str(s);
|
||||
wxFont ret;
|
||||
double n;
|
||||
|
||||
// put a limit on the maximum point size which the user can enter
|
||||
// NOTE: we suppose the last word of given string is the pointsize
|
||||
wxString size = str.AfterLast(wxT(' '));
|
||||
if (size.ToDouble(&n))
|
||||
{
|
||||
if (n < 1)
|
||||
str = str.Left(str.length() - size.length()) + wxT("1");
|
||||
else if (n >= m_nMaxPointSize)
|
||||
str = str.Left(str.length() - size.length()) +
|
||||
wxString::Format(wxT("%d"), m_nMaxPointSize);
|
||||
}
|
||||
|
||||
if (!ret.SetNativeFontInfoUserDesc(str))
|
||||
return wxNullFont;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wxFontPickerCtrl::SetSelectedFont(const wxFont &f)
|
||||
{
|
||||
M_PICKER->SetSelectedFont(f);
|
||||
UpdateTextCtrlFromPicker();
|
||||
}
|
||||
|
||||
void wxFontPickerCtrl::UpdatePickerFromTextCtrl()
|
||||
{
|
||||
wxASSERT(m_text);
|
||||
|
||||
if (m_bIgnoreNextTextCtrlUpdate)
|
||||
{
|
||||
// ignore this update
|
||||
m_bIgnoreNextTextCtrlUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// NB: we don't use the wxFont::wxFont(const wxString &) constructor
|
||||
// since that constructor expects the native font description
|
||||
// string returned by wxFont::GetNativeFontInfoDesc() and not
|
||||
// the user-friendly one returned by wxFont::GetNativeFontInfoUserDesc()
|
||||
wxFont f = String2Font(m_text->GetValue());
|
||||
if (!f.Ok())
|
||||
return; // invalid user input
|
||||
|
||||
if (M_PICKER->GetSelectedFont() != f)
|
||||
{
|
||||
M_PICKER->SetSelectedFont(f);
|
||||
|
||||
// fire an event
|
||||
wxFontPickerEvent event(this, GetId(), f);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxFontPickerCtrl::UpdateTextCtrlFromPicker()
|
||||
{
|
||||
if (!m_text)
|
||||
return; // no textctrl to update
|
||||
|
||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
||||
m_bIgnoreNextTextCtrlUpdate = true;
|
||||
m_text->SetValue(Font2String(M_PICKER->GetSelectedFont()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontPickerCtrl - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFontPickerCtrl::OnFontChange(wxFontPickerEvent &ev)
|
||||
{
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
// the wxFontPickerWidget sent us a colour-change notification.
|
||||
// forward this event to our parent
|
||||
wxFontPickerEvent event(this, GetId(), ev.GetFont());
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_FONTPICKERCTRL
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fontpickercmn.cpp
|
||||
// Purpose: wxFontPickerCtrl class implementation
|
||||
// Author: Francesco Montorsi
|
||||
// Modified by:
|
||||
// Created: 15/04/2006
|
||||
// RCS-ID: $Id: fontpickercmn.cpp 42999 2006-11-03 21:54:13Z VZ $
|
||||
// Copyright: (c) Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FONTPICKERCTRL
|
||||
|
||||
#include "wx/fontpicker.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
#include "wx/fontenum.h"
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
const wxChar wxFontPickerCtrlNameStr[] = wxT("fontpicker");
|
||||
const wxChar wxFontPickerWidgetNameStr[] = wxT("fontpickerwidget");
|
||||
|
||||
DEFINE_EVENT_TYPE(wxEVT_COMMAND_FONTPICKER_CHANGED)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontPickerCtrl, wxPickerBase)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontPickerEvent, wxCommandEvent)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontPickerCtrl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define M_PICKER ((wxFontPickerWidget*)m_picker)
|
||||
|
||||
bool wxFontPickerCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||
const wxFont &initial,
|
||||
const wxPoint &pos, const wxSize &size,
|
||||
long style, const wxValidator& validator,
|
||||
const wxString &name )
|
||||
{
|
||||
if (!wxPickerBase::CreateBase(parent, id,
|
||||
Font2String(initial.IsOk() ? initial
|
||||
: *wxNORMAL_FONT),
|
||||
pos, size, style, validator, name))
|
||||
return false;
|
||||
|
||||
// the picker of a wxFontPickerCtrl is a wxFontPickerWidget
|
||||
m_picker = new wxFontPickerWidget(this, wxID_ANY, initial,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
GetPickerStyle(style));
|
||||
// complete sizer creation
|
||||
wxPickerBase::PostCreation();
|
||||
|
||||
m_picker->Connect(wxEVT_COMMAND_FONTPICKER_CHANGED,
|
||||
wxFontPickerEventHandler(wxFontPickerCtrl::OnFontChange),
|
||||
NULL, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxString wxFontPickerCtrl::Font2String(const wxFont &f)
|
||||
{
|
||||
wxString ret = f.GetNativeFontInfoUserDesc();
|
||||
#ifdef __WXMSW__
|
||||
// on wxMSW the encoding of the font is appended at the end of the string;
|
||||
// since encoding is not very user-friendly we remove it.
|
||||
wxFontEncoding enc = f.GetEncoding();
|
||||
if ( enc != wxFONTENCODING_DEFAULT && enc != wxFONTENCODING_SYSTEM )
|
||||
ret = ret.BeforeLast(wxT(' '));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
wxFont wxFontPickerCtrl::String2Font(const wxString &s)
|
||||
{
|
||||
wxString str(s);
|
||||
wxFont ret;
|
||||
double n;
|
||||
|
||||
// put a limit on the maximum point size which the user can enter
|
||||
// NOTE: we suppose the last word of given string is the pointsize
|
||||
wxString size = str.AfterLast(wxT(' '));
|
||||
if (size.ToDouble(&n))
|
||||
{
|
||||
if (n < 1)
|
||||
str = str.Left(str.length() - size.length()) + wxT("1");
|
||||
else if (n >= m_nMaxPointSize)
|
||||
str = str.Left(str.length() - size.length()) +
|
||||
wxString::Format(wxT("%d"), m_nMaxPointSize);
|
||||
}
|
||||
|
||||
if (!ret.SetNativeFontInfoUserDesc(str))
|
||||
return wxNullFont;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wxFontPickerCtrl::SetSelectedFont(const wxFont &f)
|
||||
{
|
||||
M_PICKER->SetSelectedFont(f);
|
||||
UpdateTextCtrlFromPicker();
|
||||
}
|
||||
|
||||
void wxFontPickerCtrl::UpdatePickerFromTextCtrl()
|
||||
{
|
||||
wxASSERT(m_text);
|
||||
|
||||
if (m_bIgnoreNextTextCtrlUpdate)
|
||||
{
|
||||
// ignore this update
|
||||
m_bIgnoreNextTextCtrlUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// NB: we don't use the wxFont::wxFont(const wxString &) constructor
|
||||
// since that constructor expects the native font description
|
||||
// string returned by wxFont::GetNativeFontInfoDesc() and not
|
||||
// the user-friendly one returned by wxFont::GetNativeFontInfoUserDesc()
|
||||
wxFont f = String2Font(m_text->GetValue());
|
||||
if (!f.Ok())
|
||||
return; // invalid user input
|
||||
|
||||
if (M_PICKER->GetSelectedFont() != f)
|
||||
{
|
||||
M_PICKER->SetSelectedFont(f);
|
||||
|
||||
// fire an event
|
||||
wxFontPickerEvent event(this, GetId(), f);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxFontPickerCtrl::UpdateTextCtrlFromPicker()
|
||||
{
|
||||
if (!m_text)
|
||||
return; // no textctrl to update
|
||||
|
||||
// NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED
|
||||
// which will trigger a unneeded UpdateFromTextCtrl(); thus before using
|
||||
// SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag...
|
||||
m_bIgnoreNextTextCtrlUpdate = true;
|
||||
m_text->SetValue(Font2String(M_PICKER->GetSelectedFont()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontPickerCtrl - event handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFontPickerCtrl::OnFontChange(wxFontPickerEvent &ev)
|
||||
{
|
||||
UpdateTextCtrlFromPicker();
|
||||
|
||||
// the wxFontPickerWidget sent us a colour-change notification.
|
||||
// forward this event to our parent
|
||||
wxFontPickerEvent event(this, GetId(), ev.GetFont());
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
#endif // wxUSE_FONTPICKERCTRL
|
||||
|
1180
Externals/wxWidgets/src/common/framecmn.cpp
vendored
1180
Externals/wxWidgets/src/common/framecmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
1066
Externals/wxWidgets/src/common/fs_arc.cpp
vendored
1066
Externals/wxWidgets/src/common/fs_arc.cpp
vendored
File diff suppressed because it is too large
Load Diff
184
Externals/wxWidgets/src/common/fs_filter.cpp
vendored
184
Externals/wxWidgets/src/common/fs_filter.cpp
vendored
@ -1,92 +1,92 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fs_filter.cpp
|
||||
// Purpose: wxFilter file system handler
|
||||
// Author: Mike Wetherell
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// CVS-ID: $Id: fs_filter.cpp 42514 2006-10-27 10:47:13Z MW $
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM
|
||||
|
||||
#include "wx/fs_filter.h"
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/ptr_scpd.h"
|
||||
|
||||
wxDEFINE_SCOPED_PTR_TYPE(wxFSFile)
|
||||
wxDEFINE_SCOPED_PTR_TYPE(wxInputStream)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFilterFSHandler
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
bool wxFilterFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
return wxFilterClassFactory::Find(GetProtocol(location)) != NULL;
|
||||
}
|
||||
|
||||
wxFSFile* wxFilterFSHandler::OpenFile(
|
||||
wxFileSystem& fs,
|
||||
const wxString& location)
|
||||
{
|
||||
wxString right = GetRightLocation(location);
|
||||
if (!right.empty())
|
||||
return NULL;
|
||||
|
||||
wxString protocol = GetProtocol(location);
|
||||
const wxFilterClassFactory *factory = wxFilterClassFactory::Find(protocol);
|
||||
if (!factory)
|
||||
return NULL;
|
||||
|
||||
wxString left = GetLeftLocation(location);
|
||||
wxFSFilePtr leftFile(fs.OpenFile(left));
|
||||
if (!leftFile.get())
|
||||
return NULL;
|
||||
|
||||
wxInputStreamPtr leftStream(leftFile->DetachStream());
|
||||
if (!leftStream.get() || !leftStream->IsOk())
|
||||
return NULL;
|
||||
|
||||
wxInputStreamPtr stream(factory->NewStream(leftStream.release()));
|
||||
|
||||
// The way compressed streams are supposed to be served is e.g.:
|
||||
// Content-type: application/postscript
|
||||
// Content-encoding: gzip
|
||||
// So the mime type should be just the mime type of the lhs. However check
|
||||
// whether the mime type is that of this compression format (e.g.
|
||||
// application/gzip). If so pop any extension and try GetMimeTypeFromExt,
|
||||
// e.g. if it were '.ps.gz' pop the '.gz' and try looking up '.ps'
|
||||
wxString mime = leftFile->GetMimeType();
|
||||
if (factory->CanHandle(mime, wxSTREAM_MIMETYPE))
|
||||
mime = GetMimeTypeFromExt(factory->PopExtension(left));
|
||||
|
||||
return new wxFSFile(stream.release(),
|
||||
left + wxT("#") + protocol + wxT(":") + right,
|
||||
mime,
|
||||
GetAnchor(location)
|
||||
#if wxUSE_DATETIME
|
||||
, leftFile->GetModificationTime()
|
||||
#endif // wxUSE_DATETIME
|
||||
);
|
||||
}
|
||||
|
||||
wxString wxFilterFSHandler::FindFirst(const wxString& WXUNUSED(spec), int WXUNUSED(flags))
|
||||
{
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
wxString wxFilterFSHandler::FindNext()
|
||||
{
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
#endif //wxUSE_FILESYSTEM
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fs_filter.cpp
|
||||
// Purpose: wxFilter file system handler
|
||||
// Author: Mike Wetherell
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// CVS-ID: $Id: fs_filter.cpp 42514 2006-10-27 10:47:13Z MW $
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM
|
||||
|
||||
#include "wx/fs_filter.h"
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/ptr_scpd.h"
|
||||
|
||||
wxDEFINE_SCOPED_PTR_TYPE(wxFSFile)
|
||||
wxDEFINE_SCOPED_PTR_TYPE(wxInputStream)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFilterFSHandler
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
bool wxFilterFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
return wxFilterClassFactory::Find(GetProtocol(location)) != NULL;
|
||||
}
|
||||
|
||||
wxFSFile* wxFilterFSHandler::OpenFile(
|
||||
wxFileSystem& fs,
|
||||
const wxString& location)
|
||||
{
|
||||
wxString right = GetRightLocation(location);
|
||||
if (!right.empty())
|
||||
return NULL;
|
||||
|
||||
wxString protocol = GetProtocol(location);
|
||||
const wxFilterClassFactory *factory = wxFilterClassFactory::Find(protocol);
|
||||
if (!factory)
|
||||
return NULL;
|
||||
|
||||
wxString left = GetLeftLocation(location);
|
||||
wxFSFilePtr leftFile(fs.OpenFile(left));
|
||||
if (!leftFile.get())
|
||||
return NULL;
|
||||
|
||||
wxInputStreamPtr leftStream(leftFile->DetachStream());
|
||||
if (!leftStream.get() || !leftStream->IsOk())
|
||||
return NULL;
|
||||
|
||||
wxInputStreamPtr stream(factory->NewStream(leftStream.release()));
|
||||
|
||||
// The way compressed streams are supposed to be served is e.g.:
|
||||
// Content-type: application/postscript
|
||||
// Content-encoding: gzip
|
||||
// So the mime type should be just the mime type of the lhs. However check
|
||||
// whether the mime type is that of this compression format (e.g.
|
||||
// application/gzip). If so pop any extension and try GetMimeTypeFromExt,
|
||||
// e.g. if it were '.ps.gz' pop the '.gz' and try looking up '.ps'
|
||||
wxString mime = leftFile->GetMimeType();
|
||||
if (factory->CanHandle(mime, wxSTREAM_MIMETYPE))
|
||||
mime = GetMimeTypeFromExt(factory->PopExtension(left));
|
||||
|
||||
return new wxFSFile(stream.release(),
|
||||
left + wxT("#") + protocol + wxT(":") + right,
|
||||
mime,
|
||||
GetAnchor(location)
|
||||
#if wxUSE_DATETIME
|
||||
, leftFile->GetModificationTime()
|
||||
#endif // wxUSE_DATETIME
|
||||
);
|
||||
}
|
||||
|
||||
wxString wxFilterFSHandler::FindFirst(const wxString& WXUNUSED(spec), int WXUNUSED(flags))
|
||||
{
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
wxString wxFilterFSHandler::FindNext()
|
||||
{
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
#endif //wxUSE_FILESYSTEM
|
||||
|
334
Externals/wxWidgets/src/common/fs_inet.cpp
vendored
334
Externals/wxWidgets/src/common/fs_inet.cpp
vendored
@ -1,167 +1,167 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fs_inet.cpp
|
||||
// Purpose: HTTP and FTP file system
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// RCS-ID: $Id: fs_inet.cpp 41033 2006-09-06 13:49:42Z RR $
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if !wxUSE_SOCKETS
|
||||
#undef wxUSE_FS_INET
|
||||
#define wxUSE_FS_INET 0
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM && wxUSE_FS_INET
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/url.h"
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/fs_inet.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Helper classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This stream deletes the file when destroyed
|
||||
class wxTemporaryFileInputStream : public wxFileInputStream
|
||||
{
|
||||
public:
|
||||
wxTemporaryFileInputStream(const wxString& filename) :
|
||||
wxFileInputStream(filename), m_filename(filename) {}
|
||||
|
||||
virtual ~wxTemporaryFileInputStream()
|
||||
{
|
||||
// NB: copied from wxFileInputStream dtor, we need to do it before
|
||||
// wxRemoveFile
|
||||
if (m_file_destroy)
|
||||
{
|
||||
delete m_file;
|
||||
m_file_destroy = false;
|
||||
}
|
||||
wxRemoveFile(m_filename);
|
||||
}
|
||||
|
||||
protected:
|
||||
wxString m_filename;
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxInternetFSHandler
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static wxString StripProtocolAnchor(const wxString& location)
|
||||
{
|
||||
wxString myloc(location.BeforeLast(wxT('#')));
|
||||
if (myloc.empty()) myloc = location.AfterFirst(wxT(':'));
|
||||
else myloc = myloc.AfterFirst(wxT(':'));
|
||||
|
||||
// fix malformed url:
|
||||
if (!myloc.Left(2).IsSameAs(wxT("//")))
|
||||
{
|
||||
if (myloc.GetChar(0) != wxT('/')) myloc = wxT("//") + myloc;
|
||||
else myloc = wxT("/") + myloc;
|
||||
}
|
||||
if (myloc.Mid(2).Find(wxT('/')) == wxNOT_FOUND) myloc << wxT('/');
|
||||
|
||||
return myloc;
|
||||
}
|
||||
|
||||
|
||||
bool wxInternetFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
#if wxUSE_URL
|
||||
wxString p = GetProtocol(location);
|
||||
if ((p == wxT("http")) || (p == wxT("ftp")))
|
||||
{
|
||||
wxURL url(p + wxT(":") + StripProtocolAnchor(location));
|
||||
return (url.GetError() == wxURL_NOERR);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
|
||||
const wxString& location)
|
||||
{
|
||||
#if !wxUSE_URL
|
||||
return NULL;
|
||||
#else
|
||||
wxString right =
|
||||
GetProtocol(location) + wxT(":") + StripProtocolAnchor(location);
|
||||
|
||||
wxURL url(right);
|
||||
if (url.GetError() == wxURL_NOERR)
|
||||
{
|
||||
wxInputStream *s = url.GetInputStream();
|
||||
wxString content = url.GetProtocol().GetContentType();
|
||||
if (content == wxEmptyString) content = GetMimeTypeFromExt(location);
|
||||
if (s)
|
||||
{
|
||||
wxString tmpfile =
|
||||
wxFileName::CreateTempFileName(wxT("wxhtml"));
|
||||
|
||||
{ // now copy streams content to temporary file:
|
||||
wxFileOutputStream sout(tmpfile);
|
||||
s->Read(sout);
|
||||
}
|
||||
delete s;
|
||||
|
||||
return new wxFSFile(new wxTemporaryFileInputStream(tmpfile),
|
||||
right,
|
||||
content,
|
||||
GetAnchor(location)
|
||||
#if wxUSE_DATETIME
|
||||
, wxDateTime::Now()
|
||||
#endif // wxUSE_DATETIME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (wxFSFile*) NULL; // incorrect URL
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
class wxFileSystemInternetModule : public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxFileSystemInternetModule)
|
||||
|
||||
public:
|
||||
wxFileSystemInternetModule() :
|
||||
wxModule(),
|
||||
m_handler(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool OnInit()
|
||||
{
|
||||
m_handler = new wxInternetFSHandler;
|
||||
wxFileSystem::AddHandler(m_handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnExit()
|
||||
{
|
||||
delete wxFileSystem::RemoveHandler(m_handler);
|
||||
}
|
||||
|
||||
private:
|
||||
wxFileSystemHandler* m_handler;
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileSystemInternetModule, wxModule)
|
||||
|
||||
#endif // wxUSE_FILESYSTEM && wxUSE_FS_INET
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fs_inet.cpp
|
||||
// Purpose: HTTP and FTP file system
|
||||
// Author: Vaclav Slavik
|
||||
// Copyright: (c) 1999 Vaclav Slavik
|
||||
// RCS-ID: $Id: fs_inet.cpp 41033 2006-09-06 13:49:42Z RR $
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if !wxUSE_SOCKETS
|
||||
#undef wxUSE_FS_INET
|
||||
#define wxUSE_FS_INET 0
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM && wxUSE_FS_INET
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/url.h"
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/fs_inet.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Helper classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This stream deletes the file when destroyed
|
||||
class wxTemporaryFileInputStream : public wxFileInputStream
|
||||
{
|
||||
public:
|
||||
wxTemporaryFileInputStream(const wxString& filename) :
|
||||
wxFileInputStream(filename), m_filename(filename) {}
|
||||
|
||||
virtual ~wxTemporaryFileInputStream()
|
||||
{
|
||||
// NB: copied from wxFileInputStream dtor, we need to do it before
|
||||
// wxRemoveFile
|
||||
if (m_file_destroy)
|
||||
{
|
||||
delete m_file;
|
||||
m_file_destroy = false;
|
||||
}
|
||||
wxRemoveFile(m_filename);
|
||||
}
|
||||
|
||||
protected:
|
||||
wxString m_filename;
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxInternetFSHandler
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static wxString StripProtocolAnchor(const wxString& location)
|
||||
{
|
||||
wxString myloc(location.BeforeLast(wxT('#')));
|
||||
if (myloc.empty()) myloc = location.AfterFirst(wxT(':'));
|
||||
else myloc = myloc.AfterFirst(wxT(':'));
|
||||
|
||||
// fix malformed url:
|
||||
if (!myloc.Left(2).IsSameAs(wxT("//")))
|
||||
{
|
||||
if (myloc.GetChar(0) != wxT('/')) myloc = wxT("//") + myloc;
|
||||
else myloc = wxT("/") + myloc;
|
||||
}
|
||||
if (myloc.Mid(2).Find(wxT('/')) == wxNOT_FOUND) myloc << wxT('/');
|
||||
|
||||
return myloc;
|
||||
}
|
||||
|
||||
|
||||
bool wxInternetFSHandler::CanOpen(const wxString& location)
|
||||
{
|
||||
#if wxUSE_URL
|
||||
wxString p = GetProtocol(location);
|
||||
if ((p == wxT("http")) || (p == wxT("ftp")))
|
||||
{
|
||||
wxURL url(p + wxT(":") + StripProtocolAnchor(location));
|
||||
return (url.GetError() == wxURL_NOERR);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
wxFSFile* wxInternetFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
|
||||
const wxString& location)
|
||||
{
|
||||
#if !wxUSE_URL
|
||||
return NULL;
|
||||
#else
|
||||
wxString right =
|
||||
GetProtocol(location) + wxT(":") + StripProtocolAnchor(location);
|
||||
|
||||
wxURL url(right);
|
||||
if (url.GetError() == wxURL_NOERR)
|
||||
{
|
||||
wxInputStream *s = url.GetInputStream();
|
||||
wxString content = url.GetProtocol().GetContentType();
|
||||
if (content == wxEmptyString) content = GetMimeTypeFromExt(location);
|
||||
if (s)
|
||||
{
|
||||
wxString tmpfile =
|
||||
wxFileName::CreateTempFileName(wxT("wxhtml"));
|
||||
|
||||
{ // now copy streams content to temporary file:
|
||||
wxFileOutputStream sout(tmpfile);
|
||||
s->Read(sout);
|
||||
}
|
||||
delete s;
|
||||
|
||||
return new wxFSFile(new wxTemporaryFileInputStream(tmpfile),
|
||||
right,
|
||||
content,
|
||||
GetAnchor(location)
|
||||
#if wxUSE_DATETIME
|
||||
, wxDateTime::Now()
|
||||
#endif // wxUSE_DATETIME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (wxFSFile*) NULL; // incorrect URL
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
class wxFileSystemInternetModule : public wxModule
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxFileSystemInternetModule)
|
||||
|
||||
public:
|
||||
wxFileSystemInternetModule() :
|
||||
wxModule(),
|
||||
m_handler(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool OnInit()
|
||||
{
|
||||
m_handler = new wxInternetFSHandler;
|
||||
wxFileSystem::AddHandler(m_handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnExit()
|
||||
{
|
||||
delete wxFileSystem::RemoveHandler(m_handler);
|
||||
}
|
||||
|
||||
private:
|
||||
wxFileSystemHandler* m_handler;
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFileSystemInternetModule, wxModule)
|
||||
|
||||
#endif // wxUSE_FILESYSTEM && wxUSE_FS_INET
|
||||
|
576
Externals/wxWidgets/src/common/fs_mem.cpp
vendored
576
Externals/wxWidgets/src/common/fs_mem.cpp
vendored
@ -1,288 +1,288 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fs_mem.cpp
|
||||
// Purpose: in-memory file system
|
||||
// Author: Vaclav Slavik
|
||||
// RCS-ID: $Id: fs_mem.cpp 46522 2007-06-18 18:37:40Z VS $
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM && wxUSE_STREAMS
|
||||
|
||||
#include "wx/fs_mem.h"
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/hash.h"
|
||||
#if wxUSE_GUI
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/image.h"
|
||||
#endif // wxUSE_GUI
|
||||
#endif
|
||||
|
||||
#include "wx/mstream.h"
|
||||
|
||||
class MemFSHashObj : public wxObject
|
||||
{
|
||||
public:
|
||||
|
||||
MemFSHashObj(const void *data, size_t len, const wxString& mime)
|
||||
{
|
||||
m_Data = new char[len];
|
||||
memcpy(m_Data, data, len);
|
||||
m_Len = len;
|
||||
m_MimeType = mime;
|
||||
InitTime();
|
||||
}
|
||||
|
||||
MemFSHashObj(const wxMemoryOutputStream& stream, const wxString& mime)
|
||||
{
|
||||
m_Len = stream.GetSize();
|
||||
m_Data = new char[m_Len];
|
||||
stream.CopyTo(m_Data, m_Len);
|
||||
m_MimeType = mime;
|
||||
InitTime();
|
||||
}
|
||||
|
||||
virtual ~MemFSHashObj()
|
||||
{
|
||||
delete[] m_Data;
|
||||
}
|
||||
|
||||
char *m_Data;
|
||||
size_t m_Len;
|
||||
wxString m_MimeType;
|
||||
#if wxUSE_DATETIME
|
||||
wxDateTime m_Time;
|
||||
#endif // wxUSE_DATETIME
|
||||
|
||||
DECLARE_NO_COPY_CLASS(MemFSHashObj)
|
||||
|
||||
private:
|
||||
void InitTime()
|
||||
{
|
||||
#if wxUSE_DATETIME
|
||||
m_Time = wxDateTime::Now();
|
||||
#endif // wxUSE_DATETIME
|
||||
}
|
||||
};
|
||||
|
||||
#if wxUSE_BASE
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxMemoryFSHandler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxHashTable *wxMemoryFSHandlerBase::m_Hash = NULL;
|
||||
|
||||
|
||||
wxMemoryFSHandlerBase::wxMemoryFSHandlerBase() : wxFileSystemHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxMemoryFSHandlerBase::~wxMemoryFSHandlerBase()
|
||||
{
|
||||
// as only one copy of FS handler is supposed to exist, we may silently
|
||||
// delete static data here. (There is no way how to remove FS handler from
|
||||
// wxFileSystem other than releasing _all_ handlers.)
|
||||
|
||||
if (m_Hash)
|
||||
{
|
||||
WX_CLEAR_HASH_TABLE(*m_Hash);
|
||||
delete m_Hash;
|
||||
m_Hash = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxMemoryFSHandlerBase::CanOpen(const wxString& location)
|
||||
{
|
||||
wxString p = GetProtocol(location);
|
||||
return (p == wxT("memory"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wxFSFile* wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
|
||||
{
|
||||
if (m_Hash)
|
||||
{
|
||||
MemFSHashObj *obj = (MemFSHashObj*) m_Hash -> Get(GetRightLocation(location));
|
||||
if (obj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString mime = obj->m_MimeType;
|
||||
if ( mime.empty() )
|
||||
mime = GetMimeTypeFromExt(location);
|
||||
return new wxFSFile
|
||||
(
|
||||
new wxMemoryInputStream(obj -> m_Data, obj -> m_Len),
|
||||
location,
|
||||
mime,
|
||||
GetAnchor(location)
|
||||
#if wxUSE_DATETIME
|
||||
, obj -> m_Time
|
||||
#endif // wxUSE_DATETIME
|
||||
);
|
||||
}
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxMemoryFSHandlerBase::FindFirst(const wxString& WXUNUSED(spec),
|
||||
int WXUNUSED(flags))
|
||||
{
|
||||
wxFAIL_MSG(wxT("wxMemoryFSHandlerBase::FindFirst not implemented"));
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxMemoryFSHandlerBase::FindNext()
|
||||
{
|
||||
wxFAIL_MSG(wxT("wxMemoryFSHandlerBase::FindNext not implemented"));
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
bool wxMemoryFSHandlerBase::CheckHash(const wxString& filename)
|
||||
{
|
||||
if (m_Hash == NULL)
|
||||
{
|
||||
m_Hash = new wxHashTable(wxKEY_STRING);
|
||||
}
|
||||
|
||||
if (m_Hash -> Get(filename) != NULL)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(_("Memory VFS already contains file '%s'!"), filename.c_str());
|
||||
wxLogError(s);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename,
|
||||
const wxString& textdata,
|
||||
const wxString& mimetype)
|
||||
{
|
||||
AddFileWithMimeType(filename,
|
||||
(const void*) textdata.mb_str(), textdata.length(),
|
||||
mimetype);
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename,
|
||||
const void *binarydata, size_t size,
|
||||
const wxString& mimetype)
|
||||
{
|
||||
if (!CheckHash(filename)) return;
|
||||
m_Hash -> Put(filename, new MemFSHashObj(binarydata, size, mimetype));
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFile(const wxString& filename,
|
||||
const wxString& textdata)
|
||||
{
|
||||
AddFileWithMimeType(filename, textdata, wxEmptyString);
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFile(const wxString& filename,
|
||||
const void *binarydata, size_t size)
|
||||
{
|
||||
AddFileWithMimeType(filename, binarydata, size, wxEmptyString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*static*/ void wxMemoryFSHandlerBase::RemoveFile(const wxString& filename)
|
||||
{
|
||||
if (m_Hash == NULL ||
|
||||
m_Hash -> Get(filename) == NULL)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(_("Trying to remove file '%s' from memory VFS, but it is not loaded!"), filename.c_str());
|
||||
wxLogError(s);
|
||||
}
|
||||
|
||||
else
|
||||
delete m_Hash -> Delete(filename);
|
||||
}
|
||||
|
||||
#endif // wxUSE_BASE
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
||||
#if wxUSE_IMAGE
|
||||
/*static*/ void
|
||||
wxMemoryFSHandler::AddFile(const wxString& filename,
|
||||
const wxImage& image,
|
||||
long type)
|
||||
{
|
||||
if (!CheckHash(filename)) return;
|
||||
|
||||
wxMemoryOutputStream mems;
|
||||
if (image.Ok() && image.SaveFile(mems, (int)type))
|
||||
{
|
||||
m_Hash->Put
|
||||
(
|
||||
filename,
|
||||
new MemFSHashObj
|
||||
(
|
||||
mems,
|
||||
wxImage::FindHandler(type)->GetMimeType()
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(_("Failed to store image '%s' to memory VFS!"), filename.c_str());
|
||||
wxPrintf(wxT("'%s'\n"), s.c_str());
|
||||
wxLogError(s);
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
wxMemoryFSHandler::AddFile(const wxString& filename,
|
||||
const wxBitmap& bitmap,
|
||||
long type)
|
||||
{
|
||||
#if !defined(__WXMSW__) || wxUSE_WXDIB
|
||||
wxImage img = bitmap.ConvertToImage();
|
||||
AddFile(filename, img, type);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
|
||||
#endif // wxUSE_GUI
|
||||
|
||||
|
||||
#endif // wxUSE_FILESYSTEM && wxUSE_FS_ZIP
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/fs_mem.cpp
|
||||
// Purpose: in-memory file system
|
||||
// Author: Vaclav Slavik
|
||||
// RCS-ID: $Id: fs_mem.cpp 46522 2007-06-18 18:37:40Z VS $
|
||||
// Copyright: (c) 2000 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_FILESYSTEM && wxUSE_STREAMS
|
||||
|
||||
#include "wx/fs_mem.h"
|
||||
|
||||
#ifndef WXPRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/hash.h"
|
||||
#if wxUSE_GUI
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/image.h"
|
||||
#endif // wxUSE_GUI
|
||||
#endif
|
||||
|
||||
#include "wx/mstream.h"
|
||||
|
||||
class MemFSHashObj : public wxObject
|
||||
{
|
||||
public:
|
||||
|
||||
MemFSHashObj(const void *data, size_t len, const wxString& mime)
|
||||
{
|
||||
m_Data = new char[len];
|
||||
memcpy(m_Data, data, len);
|
||||
m_Len = len;
|
||||
m_MimeType = mime;
|
||||
InitTime();
|
||||
}
|
||||
|
||||
MemFSHashObj(const wxMemoryOutputStream& stream, const wxString& mime)
|
||||
{
|
||||
m_Len = stream.GetSize();
|
||||
m_Data = new char[m_Len];
|
||||
stream.CopyTo(m_Data, m_Len);
|
||||
m_MimeType = mime;
|
||||
InitTime();
|
||||
}
|
||||
|
||||
virtual ~MemFSHashObj()
|
||||
{
|
||||
delete[] m_Data;
|
||||
}
|
||||
|
||||
char *m_Data;
|
||||
size_t m_Len;
|
||||
wxString m_MimeType;
|
||||
#if wxUSE_DATETIME
|
||||
wxDateTime m_Time;
|
||||
#endif // wxUSE_DATETIME
|
||||
|
||||
DECLARE_NO_COPY_CLASS(MemFSHashObj)
|
||||
|
||||
private:
|
||||
void InitTime()
|
||||
{
|
||||
#if wxUSE_DATETIME
|
||||
m_Time = wxDateTime::Now();
|
||||
#endif // wxUSE_DATETIME
|
||||
}
|
||||
};
|
||||
|
||||
#if wxUSE_BASE
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// wxMemoryFSHandler
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxHashTable *wxMemoryFSHandlerBase::m_Hash = NULL;
|
||||
|
||||
|
||||
wxMemoryFSHandlerBase::wxMemoryFSHandlerBase() : wxFileSystemHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxMemoryFSHandlerBase::~wxMemoryFSHandlerBase()
|
||||
{
|
||||
// as only one copy of FS handler is supposed to exist, we may silently
|
||||
// delete static data here. (There is no way how to remove FS handler from
|
||||
// wxFileSystem other than releasing _all_ handlers.)
|
||||
|
||||
if (m_Hash)
|
||||
{
|
||||
WX_CLEAR_HASH_TABLE(*m_Hash);
|
||||
delete m_Hash;
|
||||
m_Hash = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool wxMemoryFSHandlerBase::CanOpen(const wxString& location)
|
||||
{
|
||||
wxString p = GetProtocol(location);
|
||||
return (p == wxT("memory"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
wxFSFile* wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
|
||||
{
|
||||
if (m_Hash)
|
||||
{
|
||||
MemFSHashObj *obj = (MemFSHashObj*) m_Hash -> Get(GetRightLocation(location));
|
||||
if (obj == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString mime = obj->m_MimeType;
|
||||
if ( mime.empty() )
|
||||
mime = GetMimeTypeFromExt(location);
|
||||
return new wxFSFile
|
||||
(
|
||||
new wxMemoryInputStream(obj -> m_Data, obj -> m_Len),
|
||||
location,
|
||||
mime,
|
||||
GetAnchor(location)
|
||||
#if wxUSE_DATETIME
|
||||
, obj -> m_Time
|
||||
#endif // wxUSE_DATETIME
|
||||
);
|
||||
}
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxMemoryFSHandlerBase::FindFirst(const wxString& WXUNUSED(spec),
|
||||
int WXUNUSED(flags))
|
||||
{
|
||||
wxFAIL_MSG(wxT("wxMemoryFSHandlerBase::FindFirst not implemented"));
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wxString wxMemoryFSHandlerBase::FindNext()
|
||||
{
|
||||
wxFAIL_MSG(wxT("wxMemoryFSHandlerBase::FindNext not implemented"));
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
bool wxMemoryFSHandlerBase::CheckHash(const wxString& filename)
|
||||
{
|
||||
if (m_Hash == NULL)
|
||||
{
|
||||
m_Hash = new wxHashTable(wxKEY_STRING);
|
||||
}
|
||||
|
||||
if (m_Hash -> Get(filename) != NULL)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(_("Memory VFS already contains file '%s'!"), filename.c_str());
|
||||
wxLogError(s);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename,
|
||||
const wxString& textdata,
|
||||
const wxString& mimetype)
|
||||
{
|
||||
AddFileWithMimeType(filename,
|
||||
(const void*) textdata.mb_str(), textdata.length(),
|
||||
mimetype);
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename,
|
||||
const void *binarydata, size_t size,
|
||||
const wxString& mimetype)
|
||||
{
|
||||
if (!CheckHash(filename)) return;
|
||||
m_Hash -> Put(filename, new MemFSHashObj(binarydata, size, mimetype));
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFile(const wxString& filename,
|
||||
const wxString& textdata)
|
||||
{
|
||||
AddFileWithMimeType(filename, textdata, wxEmptyString);
|
||||
}
|
||||
|
||||
|
||||
/*static*/
|
||||
void wxMemoryFSHandlerBase::AddFile(const wxString& filename,
|
||||
const void *binarydata, size_t size)
|
||||
{
|
||||
AddFileWithMimeType(filename, binarydata, size, wxEmptyString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*static*/ void wxMemoryFSHandlerBase::RemoveFile(const wxString& filename)
|
||||
{
|
||||
if (m_Hash == NULL ||
|
||||
m_Hash -> Get(filename) == NULL)
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(_("Trying to remove file '%s' from memory VFS, but it is not loaded!"), filename.c_str());
|
||||
wxLogError(s);
|
||||
}
|
||||
|
||||
else
|
||||
delete m_Hash -> Delete(filename);
|
||||
}
|
||||
|
||||
#endif // wxUSE_BASE
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
||||
#if wxUSE_IMAGE
|
||||
/*static*/ void
|
||||
wxMemoryFSHandler::AddFile(const wxString& filename,
|
||||
const wxImage& image,
|
||||
long type)
|
||||
{
|
||||
if (!CheckHash(filename)) return;
|
||||
|
||||
wxMemoryOutputStream mems;
|
||||
if (image.Ok() && image.SaveFile(mems, (int)type))
|
||||
{
|
||||
m_Hash->Put
|
||||
(
|
||||
filename,
|
||||
new MemFSHashObj
|
||||
(
|
||||
mems,
|
||||
wxImage::FindHandler(type)->GetMimeType()
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxString s;
|
||||
s.Printf(_("Failed to store image '%s' to memory VFS!"), filename.c_str());
|
||||
wxPrintf(wxT("'%s'\n"), s.c_str());
|
||||
wxLogError(s);
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
wxMemoryFSHandler::AddFile(const wxString& filename,
|
||||
const wxBitmap& bitmap,
|
||||
long type)
|
||||
{
|
||||
#if !defined(__WXMSW__) || wxUSE_WXDIB
|
||||
wxImage img = bitmap.ConvertToImage();
|
||||
AddFile(filename, img, type);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
|
||||
#endif // wxUSE_GUI
|
||||
|
||||
|
||||
#endif // wxUSE_FILESYSTEM && wxUSE_FS_ZIP
|
||||
|
2016
Externals/wxWidgets/src/common/ftp.cpp
vendored
2016
Externals/wxWidgets/src/common/ftp.cpp
vendored
File diff suppressed because it is too large
Load Diff
312
Externals/wxWidgets/src/common/gaugecmn.cpp
vendored
312
Externals/wxWidgets/src/common/gaugecmn.cpp
vendored
@ -1,156 +1,156 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/gaugecmn.cpp
|
||||
// Purpose: wxGaugeBase: common to all ports methods of wxGauge
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 20.02.01
|
||||
// RCS-ID: $Id: gaugecmn.cpp 41089 2006-09-09 13:36:54Z RR $
|
||||
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#if wxUSE_GAUGE
|
||||
|
||||
#include "wx/gauge.h"
|
||||
|
||||
const wxChar wxGaugeNameStr[] = wxT("gauge");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxGaugeBase::~wxGaugeBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge creation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxGaugeBase::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
int range,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
|
||||
return false;
|
||||
|
||||
SetName(name);
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
SetValidator(validator);
|
||||
#endif // wxUSE_VALIDATORS
|
||||
|
||||
SetRange(range);
|
||||
SetValue(0);
|
||||
#if wxGAUGE_EMULATE_INDETERMINATE_MODE
|
||||
m_nDirection = wxRIGHT;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge determinate mode range/position
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxGaugeBase::SetRange(int range)
|
||||
{
|
||||
m_rangeMax = range;
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetRange() const
|
||||
{
|
||||
return m_rangeMax;
|
||||
}
|
||||
|
||||
void wxGaugeBase::SetValue(int pos)
|
||||
{
|
||||
m_gaugePos = pos;
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetValue() const
|
||||
{
|
||||
return m_gaugePos;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge indeterminate mode
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxGaugeBase::Pulse()
|
||||
{
|
||||
#if wxGAUGE_EMULATE_INDETERMINATE_MODE
|
||||
// simulate indeterminate mode
|
||||
int curr = GetValue(), max = GetRange();
|
||||
|
||||
if (m_nDirection == wxRIGHT)
|
||||
{
|
||||
if (curr < max)
|
||||
SetValue(curr + 1);
|
||||
else
|
||||
{
|
||||
SetValue(max - 1);
|
||||
m_nDirection = wxLEFT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curr > 0)
|
||||
SetValue(curr - 1);
|
||||
else
|
||||
{
|
||||
SetValue(1);
|
||||
m_nDirection = wxRIGHT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge appearance params
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxGaugeBase::SetShadowWidth(int WXUNUSED(w))
|
||||
{
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetShadowWidth() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void wxGaugeBase::SetBezelFace(int WXUNUSED(w))
|
||||
{
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetBezelFace() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // wxUSE_GAUGE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/gaugecmn.cpp
|
||||
// Purpose: wxGaugeBase: common to all ports methods of wxGauge
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 20.02.01
|
||||
// RCS-ID: $Id: gaugecmn.cpp 41089 2006-09-09 13:36:54Z RR $
|
||||
// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||
// License: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#if wxUSE_GAUGE
|
||||
|
||||
#include "wx/gauge.h"
|
||||
|
||||
const wxChar wxGaugeNameStr[] = wxT("gauge");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
wxGaugeBase::~wxGaugeBase()
|
||||
{
|
||||
// this destructor is required for Darwin
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge creation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxGaugeBase::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
int range,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxValidator& validator,
|
||||
const wxString& name)
|
||||
{
|
||||
if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
|
||||
return false;
|
||||
|
||||
SetName(name);
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
SetValidator(validator);
|
||||
#endif // wxUSE_VALIDATORS
|
||||
|
||||
SetRange(range);
|
||||
SetValue(0);
|
||||
#if wxGAUGE_EMULATE_INDETERMINATE_MODE
|
||||
m_nDirection = wxRIGHT;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge determinate mode range/position
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxGaugeBase::SetRange(int range)
|
||||
{
|
||||
m_rangeMax = range;
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetRange() const
|
||||
{
|
||||
return m_rangeMax;
|
||||
}
|
||||
|
||||
void wxGaugeBase::SetValue(int pos)
|
||||
{
|
||||
m_gaugePos = pos;
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetValue() const
|
||||
{
|
||||
return m_gaugePos;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge indeterminate mode
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxGaugeBase::Pulse()
|
||||
{
|
||||
#if wxGAUGE_EMULATE_INDETERMINATE_MODE
|
||||
// simulate indeterminate mode
|
||||
int curr = GetValue(), max = GetRange();
|
||||
|
||||
if (m_nDirection == wxRIGHT)
|
||||
{
|
||||
if (curr < max)
|
||||
SetValue(curr + 1);
|
||||
else
|
||||
{
|
||||
SetValue(max - 1);
|
||||
m_nDirection = wxLEFT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curr > 0)
|
||||
SetValue(curr - 1);
|
||||
else
|
||||
{
|
||||
SetValue(1);
|
||||
m_nDirection = wxRIGHT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGauge appearance params
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxGaugeBase::SetShadowWidth(int WXUNUSED(w))
|
||||
{
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetShadowWidth() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void wxGaugeBase::SetBezelFace(int WXUNUSED(w))
|
||||
{
|
||||
}
|
||||
|
||||
int wxGaugeBase::GetBezelFace() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // wxUSE_GAUGE
|
||||
|
1568
Externals/wxWidgets/src/common/gbsizer.cpp
vendored
1568
Externals/wxWidgets/src/common/gbsizer.cpp
vendored
File diff suppressed because it is too large
Load Diff
1742
Externals/wxWidgets/src/common/gdicmn.cpp
vendored
1742
Externals/wxWidgets/src/common/gdicmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
728
Externals/wxWidgets/src/common/geometry.cpp
vendored
728
Externals/wxWidgets/src/common/geometry.cpp
vendored
@ -1,364 +1,364 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/geometry.cpp
|
||||
// Purpose: Common Geometry Classes
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 08/05/99
|
||||
// RCS-ID:
|
||||
// Copyright: (c) 1999 Stefan Csomor
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_GEOMETRY
|
||||
|
||||
#include "wx/geometry.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "wx/datstrm.h"
|
||||
|
||||
//
|
||||
// wxPoint2D
|
||||
//
|
||||
|
||||
//
|
||||
// wxRect2D
|
||||
//
|
||||
|
||||
// wxDouble version
|
||||
|
||||
// for the following calculations always remember
|
||||
// that the right and bottom edges are not part of a rect
|
||||
|
||||
bool wxRect2DDouble::Intersects( const wxRect2DDouble &rect ) const
|
||||
{
|
||||
wxDouble left,right,bottom,top;
|
||||
left = wxMax ( m_x , rect.m_x );
|
||||
right = wxMin ( m_x+m_width, rect.m_x + rect.m_width );
|
||||
top = wxMax ( m_y , rect.m_y );
|
||||
bottom = wxMin ( m_y+m_height, rect.m_y + rect.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxRect2DDouble::Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest )
|
||||
{
|
||||
wxDouble left,right,bottom,top;
|
||||
left = wxMax ( src1.m_x , src2.m_x );
|
||||
right = wxMin ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMax ( src1.m_y , src2.m_y );
|
||||
bottom = wxMin ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest->m_width = dest->m_height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DDouble::Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest )
|
||||
{
|
||||
wxDouble left,right,bottom,top;
|
||||
|
||||
left = wxMin ( src1.m_x , src2.m_x );
|
||||
right = wxMax ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMin ( src1.m_y , src2.m_y );
|
||||
bottom = wxMax ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
|
||||
void wxRect2DDouble::Union( const wxPoint2DDouble &pt )
|
||||
{
|
||||
wxDouble x = pt.m_x;
|
||||
wxDouble y = pt.m_y;
|
||||
|
||||
if ( x < m_x )
|
||||
{
|
||||
SetLeft( x );
|
||||
}
|
||||
else if ( x < m_x + m_width )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetRight( x );
|
||||
}
|
||||
|
||||
if ( y < m_y )
|
||||
{
|
||||
SetTop( y );
|
||||
}
|
||||
else if ( y < m_y + m_height )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetBottom( y );
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DDouble::ConstrainTo( const wxRect2DDouble &rect )
|
||||
{
|
||||
if ( GetLeft() < rect.GetLeft() )
|
||||
SetLeft( rect.GetLeft() );
|
||||
|
||||
if ( GetRight() > rect.GetRight() )
|
||||
SetRight( rect.GetRight() );
|
||||
|
||||
if ( GetBottom() > rect.GetBottom() )
|
||||
SetBottom( rect.GetBottom() );
|
||||
|
||||
if ( GetTop() < rect.GetTop() )
|
||||
SetTop( rect.GetTop() );
|
||||
}
|
||||
|
||||
wxRect2DDouble& wxRect2DDouble::operator=( const wxRect2DDouble &r )
|
||||
{
|
||||
m_x = r.m_x;
|
||||
m_y = r.m_y;
|
||||
m_width = r.m_width;
|
||||
m_height = r.m_height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// integer version
|
||||
|
||||
// for the following calculations always remember
|
||||
// that the right and bottom edges are not part of a rect
|
||||
|
||||
// wxPoint2D
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
void wxPoint2DInt::WriteTo( wxDataOutputStream &stream ) const
|
||||
{
|
||||
stream.Write32( m_x );
|
||||
stream.Write32( m_y );
|
||||
}
|
||||
|
||||
void wxPoint2DInt::ReadFrom( wxDataInputStream &stream )
|
||||
{
|
||||
m_x = stream.Read32();
|
||||
m_y = stream.Read32();
|
||||
}
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
wxDouble wxPoint2DInt::GetVectorAngle() const
|
||||
{
|
||||
if ( m_x == 0 )
|
||||
{
|
||||
if ( m_y >= 0 )
|
||||
return 90;
|
||||
else
|
||||
return 270;
|
||||
}
|
||||
if ( m_y == 0 )
|
||||
{
|
||||
if ( m_x >= 0 )
|
||||
return 0;
|
||||
else
|
||||
return 180;
|
||||
}
|
||||
|
||||
// casts needed for MIPSpro compiler under SGI
|
||||
wxDouble deg = atan2( (double)m_y , (double)m_x ) * 180 / M_PI;
|
||||
if ( deg < 0 )
|
||||
{
|
||||
deg += 360;
|
||||
}
|
||||
return deg;
|
||||
}
|
||||
|
||||
|
||||
void wxPoint2DInt::SetVectorAngle( wxDouble degrees )
|
||||
{
|
||||
wxDouble length = GetVectorLength();
|
||||
m_x = (int)(length * cos( degrees / 180 * M_PI ));
|
||||
m_y = (int)(length * sin( degrees / 180 * M_PI ));
|
||||
}
|
||||
|
||||
wxDouble wxPoint2DDouble::GetVectorAngle() const
|
||||
{
|
||||
if ( wxIsNullDouble(m_x) )
|
||||
{
|
||||
if ( m_y >= 0 )
|
||||
return 90;
|
||||
else
|
||||
return 270;
|
||||
}
|
||||
if ( wxIsNullDouble(m_y) )
|
||||
{
|
||||
if ( m_x >= 0 )
|
||||
return 0;
|
||||
else
|
||||
return 180;
|
||||
}
|
||||
wxDouble deg = atan2( m_y , m_x ) * 180 / M_PI;
|
||||
if ( deg < 0 )
|
||||
{
|
||||
deg += 360;
|
||||
}
|
||||
return deg;
|
||||
}
|
||||
|
||||
void wxPoint2DDouble::SetVectorAngle( wxDouble degrees )
|
||||
{
|
||||
wxDouble length = GetVectorLength();
|
||||
m_x = length * cos( degrees / 180 * M_PI );
|
||||
m_y = length * sin( degrees / 180 * M_PI );
|
||||
}
|
||||
|
||||
// wxRect2D
|
||||
|
||||
bool wxRect2DInt::Intersects( const wxRect2DInt &rect ) const
|
||||
{
|
||||
wxInt32 left,right,bottom,top;
|
||||
left = wxMax ( m_x , rect.m_x );
|
||||
right = wxMin ( m_x+m_width, rect.m_x + rect.m_width );
|
||||
top = wxMax ( m_y , rect.m_y );
|
||||
bottom = wxMin ( m_y+m_height, rect.m_y + rect.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxRect2DInt::Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest )
|
||||
{
|
||||
wxInt32 left,right,bottom,top;
|
||||
left = wxMax ( src1.m_x , src2.m_x );
|
||||
right = wxMin ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMax ( src1.m_y , src2.m_y );
|
||||
bottom = wxMin ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest->m_width = dest->m_height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DInt::Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest )
|
||||
{
|
||||
wxInt32 left,right,bottom,top;
|
||||
|
||||
left = wxMin ( src1.m_x , src2.m_x );
|
||||
right = wxMax ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMin ( src1.m_y , src2.m_y );
|
||||
bottom = wxMax ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
|
||||
void wxRect2DInt::Union( const wxPoint2DInt &pt )
|
||||
{
|
||||
wxInt32 x = pt.m_x;
|
||||
wxInt32 y = pt.m_y;
|
||||
|
||||
if ( x < m_x )
|
||||
{
|
||||
SetLeft( x );
|
||||
}
|
||||
else if ( x < m_x + m_width )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetRight( x );
|
||||
}
|
||||
|
||||
if ( y < m_y )
|
||||
{
|
||||
SetTop( y );
|
||||
}
|
||||
else if ( y < m_y + m_height )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetBottom( y );
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DInt::ConstrainTo( const wxRect2DInt &rect )
|
||||
{
|
||||
if ( GetLeft() < rect.GetLeft() )
|
||||
SetLeft( rect.GetLeft() );
|
||||
|
||||
if ( GetRight() > rect.GetRight() )
|
||||
SetRight( rect.GetRight() );
|
||||
|
||||
if ( GetBottom() > rect.GetBottom() )
|
||||
SetBottom( rect.GetBottom() );
|
||||
|
||||
if ( GetTop() < rect.GetTop() )
|
||||
SetTop( rect.GetTop() );
|
||||
}
|
||||
|
||||
wxRect2DInt& wxRect2DInt::operator=( const wxRect2DInt &r )
|
||||
{
|
||||
m_x = r.m_x;
|
||||
m_y = r.m_y;
|
||||
m_width = r.m_width;
|
||||
m_height = r.m_height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
void wxRect2DInt::WriteTo( wxDataOutputStream &stream ) const
|
||||
{
|
||||
stream.Write32( m_x );
|
||||
stream.Write32( m_y );
|
||||
stream.Write32( m_width );
|
||||
stream.Write32( m_height );
|
||||
}
|
||||
|
||||
void wxRect2DInt::ReadFrom( wxDataInputStream &stream )
|
||||
{
|
||||
m_x = stream.Read32();
|
||||
m_y = stream.Read32();
|
||||
m_width = stream.Read32();
|
||||
m_height = stream.Read32();
|
||||
}
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_GEOMETRY
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/geometry.cpp
|
||||
// Purpose: Common Geometry Classes
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 08/05/99
|
||||
// RCS-ID:
|
||||
// Copyright: (c) 1999 Stefan Csomor
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_GEOMETRY
|
||||
|
||||
#include "wx/geometry.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "wx/datstrm.h"
|
||||
|
||||
//
|
||||
// wxPoint2D
|
||||
//
|
||||
|
||||
//
|
||||
// wxRect2D
|
||||
//
|
||||
|
||||
// wxDouble version
|
||||
|
||||
// for the following calculations always remember
|
||||
// that the right and bottom edges are not part of a rect
|
||||
|
||||
bool wxRect2DDouble::Intersects( const wxRect2DDouble &rect ) const
|
||||
{
|
||||
wxDouble left,right,bottom,top;
|
||||
left = wxMax ( m_x , rect.m_x );
|
||||
right = wxMin ( m_x+m_width, rect.m_x + rect.m_width );
|
||||
top = wxMax ( m_y , rect.m_y );
|
||||
bottom = wxMin ( m_y+m_height, rect.m_y + rect.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxRect2DDouble::Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest )
|
||||
{
|
||||
wxDouble left,right,bottom,top;
|
||||
left = wxMax ( src1.m_x , src2.m_x );
|
||||
right = wxMin ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMax ( src1.m_y , src2.m_y );
|
||||
bottom = wxMin ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest->m_width = dest->m_height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DDouble::Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest )
|
||||
{
|
||||
wxDouble left,right,bottom,top;
|
||||
|
||||
left = wxMin ( src1.m_x , src2.m_x );
|
||||
right = wxMax ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMin ( src1.m_y , src2.m_y );
|
||||
bottom = wxMax ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
|
||||
void wxRect2DDouble::Union( const wxPoint2DDouble &pt )
|
||||
{
|
||||
wxDouble x = pt.m_x;
|
||||
wxDouble y = pt.m_y;
|
||||
|
||||
if ( x < m_x )
|
||||
{
|
||||
SetLeft( x );
|
||||
}
|
||||
else if ( x < m_x + m_width )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetRight( x );
|
||||
}
|
||||
|
||||
if ( y < m_y )
|
||||
{
|
||||
SetTop( y );
|
||||
}
|
||||
else if ( y < m_y + m_height )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetBottom( y );
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DDouble::ConstrainTo( const wxRect2DDouble &rect )
|
||||
{
|
||||
if ( GetLeft() < rect.GetLeft() )
|
||||
SetLeft( rect.GetLeft() );
|
||||
|
||||
if ( GetRight() > rect.GetRight() )
|
||||
SetRight( rect.GetRight() );
|
||||
|
||||
if ( GetBottom() > rect.GetBottom() )
|
||||
SetBottom( rect.GetBottom() );
|
||||
|
||||
if ( GetTop() < rect.GetTop() )
|
||||
SetTop( rect.GetTop() );
|
||||
}
|
||||
|
||||
wxRect2DDouble& wxRect2DDouble::operator=( const wxRect2DDouble &r )
|
||||
{
|
||||
m_x = r.m_x;
|
||||
m_y = r.m_y;
|
||||
m_width = r.m_width;
|
||||
m_height = r.m_height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// integer version
|
||||
|
||||
// for the following calculations always remember
|
||||
// that the right and bottom edges are not part of a rect
|
||||
|
||||
// wxPoint2D
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
void wxPoint2DInt::WriteTo( wxDataOutputStream &stream ) const
|
||||
{
|
||||
stream.Write32( m_x );
|
||||
stream.Write32( m_y );
|
||||
}
|
||||
|
||||
void wxPoint2DInt::ReadFrom( wxDataInputStream &stream )
|
||||
{
|
||||
m_x = stream.Read32();
|
||||
m_y = stream.Read32();
|
||||
}
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
wxDouble wxPoint2DInt::GetVectorAngle() const
|
||||
{
|
||||
if ( m_x == 0 )
|
||||
{
|
||||
if ( m_y >= 0 )
|
||||
return 90;
|
||||
else
|
||||
return 270;
|
||||
}
|
||||
if ( m_y == 0 )
|
||||
{
|
||||
if ( m_x >= 0 )
|
||||
return 0;
|
||||
else
|
||||
return 180;
|
||||
}
|
||||
|
||||
// casts needed for MIPSpro compiler under SGI
|
||||
wxDouble deg = atan2( (double)m_y , (double)m_x ) * 180 / M_PI;
|
||||
if ( deg < 0 )
|
||||
{
|
||||
deg += 360;
|
||||
}
|
||||
return deg;
|
||||
}
|
||||
|
||||
|
||||
void wxPoint2DInt::SetVectorAngle( wxDouble degrees )
|
||||
{
|
||||
wxDouble length = GetVectorLength();
|
||||
m_x = (int)(length * cos( degrees / 180 * M_PI ));
|
||||
m_y = (int)(length * sin( degrees / 180 * M_PI ));
|
||||
}
|
||||
|
||||
wxDouble wxPoint2DDouble::GetVectorAngle() const
|
||||
{
|
||||
if ( wxIsNullDouble(m_x) )
|
||||
{
|
||||
if ( m_y >= 0 )
|
||||
return 90;
|
||||
else
|
||||
return 270;
|
||||
}
|
||||
if ( wxIsNullDouble(m_y) )
|
||||
{
|
||||
if ( m_x >= 0 )
|
||||
return 0;
|
||||
else
|
||||
return 180;
|
||||
}
|
||||
wxDouble deg = atan2( m_y , m_x ) * 180 / M_PI;
|
||||
if ( deg < 0 )
|
||||
{
|
||||
deg += 360;
|
||||
}
|
||||
return deg;
|
||||
}
|
||||
|
||||
void wxPoint2DDouble::SetVectorAngle( wxDouble degrees )
|
||||
{
|
||||
wxDouble length = GetVectorLength();
|
||||
m_x = length * cos( degrees / 180 * M_PI );
|
||||
m_y = length * sin( degrees / 180 * M_PI );
|
||||
}
|
||||
|
||||
// wxRect2D
|
||||
|
||||
bool wxRect2DInt::Intersects( const wxRect2DInt &rect ) const
|
||||
{
|
||||
wxInt32 left,right,bottom,top;
|
||||
left = wxMax ( m_x , rect.m_x );
|
||||
right = wxMin ( m_x+m_width, rect.m_x + rect.m_width );
|
||||
top = wxMax ( m_y , rect.m_y );
|
||||
bottom = wxMin ( m_y+m_height, rect.m_y + rect.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxRect2DInt::Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest )
|
||||
{
|
||||
wxInt32 left,right,bottom,top;
|
||||
left = wxMax ( src1.m_x , src2.m_x );
|
||||
right = wxMin ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMax ( src1.m_y , src2.m_y );
|
||||
bottom = wxMin ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
if ( left < right && top < bottom )
|
||||
{
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest->m_width = dest->m_height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DInt::Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest )
|
||||
{
|
||||
wxInt32 left,right,bottom,top;
|
||||
|
||||
left = wxMin ( src1.m_x , src2.m_x );
|
||||
right = wxMax ( src1.m_x+src1.m_width, src2.m_x + src2.m_width );
|
||||
top = wxMin ( src1.m_y , src2.m_y );
|
||||
bottom = wxMax ( src1.m_y+src1.m_height, src2.m_y + src2.m_height );
|
||||
|
||||
dest->m_x = left;
|
||||
dest->m_y = top;
|
||||
dest->m_width = right - left;
|
||||
dest->m_height = bottom - top;
|
||||
}
|
||||
|
||||
void wxRect2DInt::Union( const wxPoint2DInt &pt )
|
||||
{
|
||||
wxInt32 x = pt.m_x;
|
||||
wxInt32 y = pt.m_y;
|
||||
|
||||
if ( x < m_x )
|
||||
{
|
||||
SetLeft( x );
|
||||
}
|
||||
else if ( x < m_x + m_width )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetRight( x );
|
||||
}
|
||||
|
||||
if ( y < m_y )
|
||||
{
|
||||
SetTop( y );
|
||||
}
|
||||
else if ( y < m_y + m_height )
|
||||
{
|
||||
// contained
|
||||
}
|
||||
else
|
||||
{
|
||||
SetBottom( y );
|
||||
}
|
||||
}
|
||||
|
||||
void wxRect2DInt::ConstrainTo( const wxRect2DInt &rect )
|
||||
{
|
||||
if ( GetLeft() < rect.GetLeft() )
|
||||
SetLeft( rect.GetLeft() );
|
||||
|
||||
if ( GetRight() > rect.GetRight() )
|
||||
SetRight( rect.GetRight() );
|
||||
|
||||
if ( GetBottom() > rect.GetBottom() )
|
||||
SetBottom( rect.GetBottom() );
|
||||
|
||||
if ( GetTop() < rect.GetTop() )
|
||||
SetTop( rect.GetTop() );
|
||||
}
|
||||
|
||||
wxRect2DInt& wxRect2DInt::operator=( const wxRect2DInt &r )
|
||||
{
|
||||
m_x = r.m_x;
|
||||
m_y = r.m_y;
|
||||
m_width = r.m_width;
|
||||
m_height = r.m_height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
void wxRect2DInt::WriteTo( wxDataOutputStream &stream ) const
|
||||
{
|
||||
stream.Write32( m_x );
|
||||
stream.Write32( m_y );
|
||||
stream.Write32( m_width );
|
||||
stream.Write32( m_height );
|
||||
}
|
||||
|
||||
void wxRect2DInt::ReadFrom( wxDataInputStream &stream )
|
||||
{
|
||||
m_x = stream.Read32();
|
||||
m_y = stream.Read32();
|
||||
m_width = stream.Read32();
|
||||
m_height = stream.Read32();
|
||||
}
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_GEOMETRY
|
||||
|
1812
Externals/wxWidgets/src/common/gifdecod.cpp
vendored
1812
Externals/wxWidgets/src/common/gifdecod.cpp
vendored
File diff suppressed because it is too large
Load Diff
1538
Externals/wxWidgets/src/common/graphcmn.cpp
vendored
1538
Externals/wxWidgets/src/common/graphcmn.cpp
vendored
File diff suppressed because it is too large
Load Diff
2154
Externals/wxWidgets/src/common/hash.cpp
vendored
2154
Externals/wxWidgets/src/common/hash.cpp
vendored
File diff suppressed because it is too large
Load Diff
304
Externals/wxWidgets/src/common/hashmap.cpp
vendored
304
Externals/wxWidgets/src/common/hashmap.cpp
vendored
@ -1,152 +1,152 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/hashmap.cpp
|
||||
// Purpose: wxHashMap implementation
|
||||
// Author: Mattia Barbon
|
||||
// Modified by:
|
||||
// Created: 29/01/2002
|
||||
// RCS-ID: $Id: hashmap.cpp 39802 2006-06-20 10:24:07Z ABX $
|
||||
// Copyright: (c) Mattia Barbon
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
|
||||
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
|
||||
/* from requirements by Colin Plumb. */
|
||||
/* (http://burtleburtle.net/bob/hash/doobs.html) */
|
||||
/* adapted from Perl sources ( hv.h ) */
|
||||
unsigned long wxStringHash::wxCharStringHash( const wxChar* k )
|
||||
{
|
||||
unsigned long hash = 0;
|
||||
|
||||
while( *k )
|
||||
{
|
||||
hash += *k++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
|
||||
return hash + (hash << 15);
|
||||
}
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
unsigned long wxStringHash::charStringHash( const char* k )
|
||||
{
|
||||
unsigned long hash = 0;
|
||||
|
||||
while( *k )
|
||||
{
|
||||
hash += *k++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
|
||||
return hash + (hash << 15);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
|
||||
|
||||
/* from SGI STL */
|
||||
const unsigned long _wxHashTableBase2::ms_primes[prime_count] =
|
||||
{
|
||||
7ul, 13ul, 29ul,
|
||||
53ul, 97ul, 193ul, 389ul, 769ul,
|
||||
1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
|
||||
49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
|
||||
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
|
||||
50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
|
||||
1610612741ul, 3221225473ul, 4294967291ul
|
||||
};
|
||||
|
||||
unsigned long _wxHashTableBase2::GetNextPrime( unsigned long n )
|
||||
{
|
||||
const unsigned long* ptr = &ms_primes[0];
|
||||
for( size_t i = 0; i < prime_count; ++i, ++ptr )
|
||||
{
|
||||
if( n < *ptr )
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
/* someone might try to alloc a 2^32-element hash table */
|
||||
wxFAIL_MSG( _T("hash table too big?") );
|
||||
|
||||
/* quiet warning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long _wxHashTableBase2::GetPreviousPrime( unsigned long n )
|
||||
{
|
||||
const unsigned long* ptr = &ms_primes[prime_count - 1];
|
||||
|
||||
for( size_t i = 0; i < prime_count; ++i, --ptr )
|
||||
{
|
||||
if( n > *ptr )
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
/* quiet warning */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _wxHashTableBase2::DeleteNodes( size_t buckets,
|
||||
_wxHashTable_NodeBase** table,
|
||||
NodeDtor dtor )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for( i = 0; i < buckets; ++i )
|
||||
{
|
||||
_wxHashTable_NodeBase* node = table[i];
|
||||
_wxHashTable_NodeBase* tmp;
|
||||
|
||||
while( node )
|
||||
{
|
||||
tmp = node->m_nxt;
|
||||
dtor( node );
|
||||
node = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
memset( table, 0, buckets * sizeof(void*) );
|
||||
}
|
||||
|
||||
void _wxHashTableBase2::CopyHashTable( _wxHashTable_NodeBase** srcTable,
|
||||
size_t srcBuckets,
|
||||
_wxHashTableBase2* dst,
|
||||
_wxHashTable_NodeBase** dstTable,
|
||||
BucketFromNode func, ProcessNode proc )
|
||||
{
|
||||
for( size_t i = 0; i < srcBuckets; ++i )
|
||||
{
|
||||
_wxHashTable_NodeBase* nextnode;
|
||||
|
||||
for( _wxHashTable_NodeBase* node = srcTable[i]; node; node = nextnode )
|
||||
{
|
||||
size_t bucket = func( dst, node );
|
||||
|
||||
nextnode = node->m_nxt;
|
||||
_wxHashTable_NodeBase* newnode = proc( node );
|
||||
newnode->m_nxt = dstTable[bucket];
|
||||
dstTable[bucket] = newnode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_wxHashTable_NodeBase* _wxHashTableBase2::DummyProcessNode(_wxHashTable_NodeBase* node)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
#endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/hashmap.cpp
|
||||
// Purpose: wxHashMap implementation
|
||||
// Author: Mattia Barbon
|
||||
// Modified by:
|
||||
// Created: 29/01/2002
|
||||
// RCS-ID: $Id: hashmap.cpp 39802 2006-06-20 10:24:07Z ABX $
|
||||
// Copyright: (c) Mattia Barbon
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
|
||||
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
|
||||
/* from requirements by Colin Plumb. */
|
||||
/* (http://burtleburtle.net/bob/hash/doobs.html) */
|
||||
/* adapted from Perl sources ( hv.h ) */
|
||||
unsigned long wxStringHash::wxCharStringHash( const wxChar* k )
|
||||
{
|
||||
unsigned long hash = 0;
|
||||
|
||||
while( *k )
|
||||
{
|
||||
hash += *k++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
|
||||
return hash + (hash << 15);
|
||||
}
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
unsigned long wxStringHash::charStringHash( const char* k )
|
||||
{
|
||||
unsigned long hash = 0;
|
||||
|
||||
while( *k )
|
||||
{
|
||||
hash += *k++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
|
||||
return hash + (hash << 15);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
|
||||
|
||||
/* from SGI STL */
|
||||
const unsigned long _wxHashTableBase2::ms_primes[prime_count] =
|
||||
{
|
||||
7ul, 13ul, 29ul,
|
||||
53ul, 97ul, 193ul, 389ul, 769ul,
|
||||
1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
|
||||
49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
|
||||
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
|
||||
50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
|
||||
1610612741ul, 3221225473ul, 4294967291ul
|
||||
};
|
||||
|
||||
unsigned long _wxHashTableBase2::GetNextPrime( unsigned long n )
|
||||
{
|
||||
const unsigned long* ptr = &ms_primes[0];
|
||||
for( size_t i = 0; i < prime_count; ++i, ++ptr )
|
||||
{
|
||||
if( n < *ptr )
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
/* someone might try to alloc a 2^32-element hash table */
|
||||
wxFAIL_MSG( _T("hash table too big?") );
|
||||
|
||||
/* quiet warning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long _wxHashTableBase2::GetPreviousPrime( unsigned long n )
|
||||
{
|
||||
const unsigned long* ptr = &ms_primes[prime_count - 1];
|
||||
|
||||
for( size_t i = 0; i < prime_count; ++i, --ptr )
|
||||
{
|
||||
if( n > *ptr )
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
/* quiet warning */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _wxHashTableBase2::DeleteNodes( size_t buckets,
|
||||
_wxHashTable_NodeBase** table,
|
||||
NodeDtor dtor )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for( i = 0; i < buckets; ++i )
|
||||
{
|
||||
_wxHashTable_NodeBase* node = table[i];
|
||||
_wxHashTable_NodeBase* tmp;
|
||||
|
||||
while( node )
|
||||
{
|
||||
tmp = node->m_nxt;
|
||||
dtor( node );
|
||||
node = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
memset( table, 0, buckets * sizeof(void*) );
|
||||
}
|
||||
|
||||
void _wxHashTableBase2::CopyHashTable( _wxHashTable_NodeBase** srcTable,
|
||||
size_t srcBuckets,
|
||||
_wxHashTableBase2* dst,
|
||||
_wxHashTable_NodeBase** dstTable,
|
||||
BucketFromNode func, ProcessNode proc )
|
||||
{
|
||||
for( size_t i = 0; i < srcBuckets; ++i )
|
||||
{
|
||||
_wxHashTable_NodeBase* nextnode;
|
||||
|
||||
for( _wxHashTable_NodeBase* node = srcTable[i]; node; node = nextnode )
|
||||
{
|
||||
size_t bucket = func( dst, node );
|
||||
|
||||
nextnode = node->m_nxt;
|
||||
_wxHashTable_NodeBase* newnode = proc( node );
|
||||
newnode->m_nxt = dstTable[bucket];
|
||||
dstTable[bucket] = newnode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_wxHashTable_NodeBase* _wxHashTableBase2::DummyProcessNode(_wxHashTable_NodeBase* node)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
#endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)
|
||||
|
56
Externals/wxWidgets/src/common/helpbase.cpp
vendored
56
Externals/wxWidgets/src/common/helpbase.cpp
vendored
@ -1,28 +1,28 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/helpbase.cpp
|
||||
// Purpose: Help system base classes
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id: helpbase.cpp 38787 2006-04-18 07:24:35Z ABX $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_HELP
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/helpbase.h"
|
||||
|
||||
IMPLEMENT_CLASS(wxHelpControllerBase, wxObject)
|
||||
|
||||
#endif // wxUSE_HELP
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/helpbase.cpp
|
||||
// Purpose: Help system base classes
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id: helpbase.cpp 38787 2006-04-18 07:24:35Z ABX $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_HELP
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/helpbase.h"
|
||||
|
||||
IMPLEMENT_CLASS(wxHelpControllerBase, wxObject)
|
||||
|
||||
#endif // wxUSE_HELP
|
||||
|
844
Externals/wxWidgets/src/common/http.cpp
vendored
844
Externals/wxWidgets/src/common/http.cpp
vendored
@ -1,422 +1,422 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/http.cpp
|
||||
// Purpose: HTTP protocol
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by: Simo Virokannas (authentication, Dec 2005)
|
||||
// Created: August 1997
|
||||
// RCS-ID: $Id: http.cpp 44660 2007-03-07 23:07:17Z VZ $
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_PROTOCOL_HTTP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/app.h"
|
||||
#endif
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/socket.h"
|
||||
#include "wx/protocol/protocol.h"
|
||||
#include "wx/url.h"
|
||||
#include "wx/protocol/http.h"
|
||||
#include "wx/sckstrm.h"
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHTTP, wxProtocol)
|
||||
IMPLEMENT_PROTOCOL(wxHTTP, wxT("http"), wxT("80"), true)
|
||||
|
||||
wxHTTP::wxHTTP()
|
||||
: wxProtocol()
|
||||
{
|
||||
m_addr = NULL;
|
||||
m_read = false;
|
||||
m_proxy_mode = false;
|
||||
m_post_buf = wxEmptyString;
|
||||
m_http_response = 0;
|
||||
|
||||
SetNotify(wxSOCKET_LOST_FLAG);
|
||||
}
|
||||
|
||||
wxHTTP::~wxHTTP()
|
||||
{
|
||||
ClearHeaders();
|
||||
|
||||
delete m_addr;
|
||||
}
|
||||
|
||||
void wxHTTP::ClearHeaders()
|
||||
{
|
||||
m_headers.clear();
|
||||
}
|
||||
|
||||
wxString wxHTTP::GetContentType()
|
||||
{
|
||||
return GetHeader(wxT("Content-Type"));
|
||||
}
|
||||
|
||||
void wxHTTP::SetProxyMode(bool on)
|
||||
{
|
||||
m_proxy_mode = on;
|
||||
}
|
||||
|
||||
wxHTTP::wxHeaderIterator wxHTTP::FindHeader(const wxString& header)
|
||||
{
|
||||
wxHeaderIterator it = m_headers.begin();
|
||||
for ( wxHeaderIterator en = m_headers.end(); it != en; ++it )
|
||||
{
|
||||
if ( wxStricmp(it->first, header) == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
wxHTTP::wxHeaderConstIterator wxHTTP::FindHeader(const wxString& header) const
|
||||
{
|
||||
wxHeaderConstIterator it = m_headers.begin();
|
||||
for ( wxHeaderConstIterator en = m_headers.end(); it != en; ++it )
|
||||
{
|
||||
if ( wxStricmp(it->first, header) == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
void wxHTTP::SetHeader(const wxString& header, const wxString& h_data)
|
||||
{
|
||||
if (m_read) {
|
||||
ClearHeaders();
|
||||
m_read = false;
|
||||
}
|
||||
|
||||
wxHeaderIterator it = FindHeader(header);
|
||||
if (it != m_headers.end())
|
||||
it->second = h_data;
|
||||
else
|
||||
m_headers[header] = h_data;
|
||||
}
|
||||
|
||||
wxString wxHTTP::GetHeader(const wxString& header) const
|
||||
{
|
||||
wxHeaderConstIterator it = FindHeader(header);
|
||||
|
||||
return it == m_headers.end() ? wxGetEmptyString() : it->second;
|
||||
}
|
||||
|
||||
wxString wxHTTP::GenerateAuthString(const wxString& user, const wxString& pass) const
|
||||
{
|
||||
static const char *base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
wxString buf;
|
||||
wxString toencode;
|
||||
|
||||
buf.Printf(wxT("Basic "));
|
||||
|
||||
toencode.Printf(wxT("%s:%s"),user.c_str(),pass.c_str());
|
||||
|
||||
size_t len = toencode.length();
|
||||
const wxChar *from = toencode.c_str();
|
||||
while (len >= 3) { // encode full blocks first
|
||||
buf << wxString::Format(wxT("%c%c"), base64[(from[0] >> 2) & 0x3f], base64[((from[0] << 4) & 0x30) | ((from[1] >> 4) & 0xf)]);
|
||||
buf << wxString::Format(wxT("%c%c"), base64[((from[1] << 2) & 0x3c) | ((from[2] >> 6) & 0x3)], base64[from[2] & 0x3f]);
|
||||
from += 3;
|
||||
len -= 3;
|
||||
}
|
||||
if (len > 0) { // pad the remaining characters
|
||||
buf << wxString::Format(wxT("%c"), base64[(from[0] >> 2) & 0x3f]);
|
||||
if (len == 1) {
|
||||
buf << wxString::Format(wxT("%c="), base64[(from[0] << 4) & 0x30]);
|
||||
} else {
|
||||
buf << wxString::Format(wxT("%c%c"), base64[((from[0] << 4) & 0x30) | ((from[1] >> 4) & 0xf)], base64[(from[1] << 2) & 0x3c]);
|
||||
}
|
||||
buf << wxString::Format(wxT("="));
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void wxHTTP::SetPostBuffer(const wxString& post_buf)
|
||||
{
|
||||
m_post_buf = post_buf;
|
||||
}
|
||||
|
||||
void wxHTTP::SendHeaders()
|
||||
{
|
||||
typedef wxStringToStringHashMap::iterator iterator;
|
||||
wxString buf;
|
||||
|
||||
for (iterator it = m_headers.begin(), en = m_headers.end(); it != en; ++it )
|
||||
{
|
||||
buf.Printf(wxT("%s: %s\r\n"), it->first.c_str(), it->second.c_str());
|
||||
|
||||
const wxWX2MBbuf cbuf = buf.mb_str();
|
||||
Write(cbuf, strlen(cbuf));
|
||||
}
|
||||
}
|
||||
|
||||
bool wxHTTP::ParseHeaders()
|
||||
{
|
||||
wxString line;
|
||||
wxStringTokenizer tokenzr;
|
||||
|
||||
ClearHeaders();
|
||||
m_read = true;
|
||||
|
||||
for ( ;; )
|
||||
{
|
||||
m_perr = ReadLine(this, line);
|
||||
if (m_perr != wxPROTO_NOERR)
|
||||
return false;
|
||||
|
||||
if (line.length() == 0)
|
||||
break;
|
||||
|
||||
wxString left_str = line.BeforeFirst(':');
|
||||
m_headers[left_str] = line.AfterFirst(':').Strip(wxString::both);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxHTTP::Connect(const wxString& host, unsigned short port)
|
||||
{
|
||||
wxIPV4address *addr;
|
||||
|
||||
if (m_addr) {
|
||||
delete m_addr;
|
||||
m_addr = NULL;
|
||||
Close();
|
||||
}
|
||||
|
||||
m_addr = addr = new wxIPV4address();
|
||||
|
||||
if (!addr->Hostname(host)) {
|
||||
delete m_addr;
|
||||
m_addr = NULL;
|
||||
m_perr = wxPROTO_NETERR;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( port )
|
||||
addr->Service(port);
|
||||
else if (!addr->Service(wxT("http")))
|
||||
addr->Service(80);
|
||||
|
||||
SetHeader(wxT("Host"), host);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait))
|
||||
{
|
||||
if (m_addr) {
|
||||
delete m_addr;
|
||||
Close();
|
||||
}
|
||||
|
||||
m_addr = addr.Clone();
|
||||
|
||||
wxIPV4address *ipv4addr = wxDynamicCast(&addr, wxIPV4address);
|
||||
if (ipv4addr)
|
||||
SetHeader(wxT("Host"), ipv4addr->OrigHostname());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
|
||||
{
|
||||
const wxChar *request;
|
||||
|
||||
switch (req)
|
||||
{
|
||||
case wxHTTP_GET:
|
||||
request = wxT("GET");
|
||||
break;
|
||||
|
||||
case wxHTTP_POST:
|
||||
request = wxT("POST");
|
||||
if ( GetHeader( wxT("Content-Length") ).IsNull() )
|
||||
SetHeader( wxT("Content-Length"), wxString::Format( wxT("%lu"), (unsigned long)m_post_buf.Len() ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
m_http_response = 0;
|
||||
|
||||
// If there is no User-Agent defined, define it.
|
||||
if (GetHeader(wxT("User-Agent")).IsNull())
|
||||
SetHeader(wxT("User-Agent"), wxT("wxWidgets 2.x"));
|
||||
|
||||
// Send authentication information
|
||||
if (!m_username.empty() || !m_password.empty()) {
|
||||
SetHeader(wxT("Authorization"), GenerateAuthString(m_username, m_password));
|
||||
}
|
||||
|
||||
SaveState();
|
||||
|
||||
// we may use non blocking sockets only if we can dispatch events from them
|
||||
SetFlags( wxIsMainThread() && wxApp::IsMainLoopRunning() ? wxSOCKET_NONE
|
||||
: wxSOCKET_BLOCK );
|
||||
Notify(false);
|
||||
|
||||
wxString buf;
|
||||
buf.Printf(wxT("%s %s HTTP/1.0\r\n"), request, path.c_str());
|
||||
const wxWX2MBbuf pathbuf = wxConvLocal.cWX2MB(buf);
|
||||
Write(pathbuf, strlen(wxMBSTRINGCAST pathbuf));
|
||||
SendHeaders();
|
||||
Write("\r\n", 2);
|
||||
|
||||
if ( req == wxHTTP_POST ) {
|
||||
Write(m_post_buf.mbc_str(), m_post_buf.Len());
|
||||
m_post_buf = wxEmptyString;
|
||||
}
|
||||
|
||||
wxString tmp_str;
|
||||
m_perr = ReadLine(this, tmp_str);
|
||||
if (m_perr != wxPROTO_NOERR) {
|
||||
RestoreState();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tmp_str.Contains(wxT("HTTP/"))) {
|
||||
// TODO: support HTTP v0.9 which can have no header.
|
||||
// FIXME: tmp_str is not put back in the in-queue of the socket.
|
||||
SetHeader(wxT("Content-Length"), wxT("-1"));
|
||||
SetHeader(wxT("Content-Type"), wxT("none/none"));
|
||||
RestoreState();
|
||||
return true;
|
||||
}
|
||||
|
||||
wxStringTokenizer token(tmp_str,wxT(' '));
|
||||
wxString tmp_str2;
|
||||
bool ret_value;
|
||||
|
||||
token.NextToken();
|
||||
tmp_str2 = token.NextToken();
|
||||
|
||||
m_http_response = wxAtoi(tmp_str2);
|
||||
|
||||
switch (tmp_str2[0u])
|
||||
{
|
||||
case wxT('1'):
|
||||
/* INFORMATION / SUCCESS */
|
||||
break;
|
||||
|
||||
case wxT('2'):
|
||||
/* SUCCESS */
|
||||
break;
|
||||
|
||||
case wxT('3'):
|
||||
/* REDIRECTION */
|
||||
break;
|
||||
|
||||
default:
|
||||
m_perr = wxPROTO_NOFILE;
|
||||
RestoreState();
|
||||
return false;
|
||||
}
|
||||
|
||||
ret_value = ParseHeaders();
|
||||
RestoreState();
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
class wxHTTPStream : public wxSocketInputStream
|
||||
{
|
||||
public:
|
||||
wxHTTP *m_http;
|
||||
size_t m_httpsize;
|
||||
unsigned long m_read_bytes;
|
||||
|
||||
wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
|
||||
size_t GetSize() const { return m_httpsize; }
|
||||
virtual ~wxHTTPStream(void) { m_http->Abort(); }
|
||||
|
||||
protected:
|
||||
size_t OnSysRead(void *buffer, size_t bufsize);
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxHTTPStream)
|
||||
};
|
||||
|
||||
size_t wxHTTPStream::OnSysRead(void *buffer, size_t bufsize)
|
||||
{
|
||||
if (m_httpsize > 0 && m_read_bytes >= m_httpsize)
|
||||
{
|
||||
m_lasterror = wxSTREAM_EOF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ret = wxSocketInputStream::OnSysRead(buffer, bufsize);
|
||||
m_read_bytes += ret;
|
||||
|
||||
if (m_httpsize==(size_t)-1 && m_lasterror == wxSTREAM_READ_ERROR )
|
||||
{
|
||||
// if m_httpsize is (size_t) -1 this means read until connection closed
|
||||
// which is equivalent to getting a READ_ERROR, for clients however this
|
||||
// must be translated into EOF, as it is the expected way of signalling
|
||||
// end end of the content
|
||||
m_lasterror = wxSTREAM_EOF ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxHTTP::Abort(void)
|
||||
{
|
||||
return wxSocketClient::Close();
|
||||
}
|
||||
|
||||
wxInputStream *wxHTTP::GetInputStream(const wxString& path)
|
||||
{
|
||||
wxHTTPStream *inp_stream;
|
||||
|
||||
wxString new_path;
|
||||
|
||||
m_perr = wxPROTO_CONNERR;
|
||||
if (!m_addr)
|
||||
return NULL;
|
||||
|
||||
// We set m_connected back to false so wxSocketBase will know what to do.
|
||||
#ifdef __WXMAC__
|
||||
wxSocketClient::Connect(*m_addr , false );
|
||||
wxSocketClient::WaitOnConnect(10);
|
||||
|
||||
if (!wxSocketClient::IsConnected())
|
||||
return NULL;
|
||||
#else
|
||||
if (!wxProtocol::Connect(*m_addr))
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
if (!BuildRequest(path, m_post_buf.empty() ? wxHTTP_GET : wxHTTP_POST))
|
||||
return NULL;
|
||||
|
||||
inp_stream = new wxHTTPStream(this);
|
||||
|
||||
if (!GetHeader(wxT("Content-Length")).empty())
|
||||
inp_stream->m_httpsize = wxAtoi(WXSTRINGCAST GetHeader(wxT("Content-Length")));
|
||||
else
|
||||
inp_stream->m_httpsize = (size_t)-1;
|
||||
|
||||
inp_stream->m_read_bytes = 0;
|
||||
|
||||
Notify(false);
|
||||
SetFlags(wxSOCKET_BLOCK | wxSOCKET_WAITALL);
|
||||
|
||||
return inp_stream;
|
||||
}
|
||||
|
||||
#endif // wxUSE_PROTOCOL_HTTP
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/http.cpp
|
||||
// Purpose: HTTP protocol
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by: Simo Virokannas (authentication, Dec 2005)
|
||||
// Created: August 1997
|
||||
// RCS-ID: $Id: http.cpp 44660 2007-03-07 23:07:17Z VZ $
|
||||
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_PROTOCOL_HTTP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
#include "wx/app.h"
|
||||
#endif
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/socket.h"
|
||||
#include "wx/protocol/protocol.h"
|
||||
#include "wx/url.h"
|
||||
#include "wx/protocol/http.h"
|
||||
#include "wx/sckstrm.h"
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxHTTP, wxProtocol)
|
||||
IMPLEMENT_PROTOCOL(wxHTTP, wxT("http"), wxT("80"), true)
|
||||
|
||||
wxHTTP::wxHTTP()
|
||||
: wxProtocol()
|
||||
{
|
||||
m_addr = NULL;
|
||||
m_read = false;
|
||||
m_proxy_mode = false;
|
||||
m_post_buf = wxEmptyString;
|
||||
m_http_response = 0;
|
||||
|
||||
SetNotify(wxSOCKET_LOST_FLAG);
|
||||
}
|
||||
|
||||
wxHTTP::~wxHTTP()
|
||||
{
|
||||
ClearHeaders();
|
||||
|
||||
delete m_addr;
|
||||
}
|
||||
|
||||
void wxHTTP::ClearHeaders()
|
||||
{
|
||||
m_headers.clear();
|
||||
}
|
||||
|
||||
wxString wxHTTP::GetContentType()
|
||||
{
|
||||
return GetHeader(wxT("Content-Type"));
|
||||
}
|
||||
|
||||
void wxHTTP::SetProxyMode(bool on)
|
||||
{
|
||||
m_proxy_mode = on;
|
||||
}
|
||||
|
||||
wxHTTP::wxHeaderIterator wxHTTP::FindHeader(const wxString& header)
|
||||
{
|
||||
wxHeaderIterator it = m_headers.begin();
|
||||
for ( wxHeaderIterator en = m_headers.end(); it != en; ++it )
|
||||
{
|
||||
if ( wxStricmp(it->first, header) == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
wxHTTP::wxHeaderConstIterator wxHTTP::FindHeader(const wxString& header) const
|
||||
{
|
||||
wxHeaderConstIterator it = m_headers.begin();
|
||||
for ( wxHeaderConstIterator en = m_headers.end(); it != en; ++it )
|
||||
{
|
||||
if ( wxStricmp(it->first, header) == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
void wxHTTP::SetHeader(const wxString& header, const wxString& h_data)
|
||||
{
|
||||
if (m_read) {
|
||||
ClearHeaders();
|
||||
m_read = false;
|
||||
}
|
||||
|
||||
wxHeaderIterator it = FindHeader(header);
|
||||
if (it != m_headers.end())
|
||||
it->second = h_data;
|
||||
else
|
||||
m_headers[header] = h_data;
|
||||
}
|
||||
|
||||
wxString wxHTTP::GetHeader(const wxString& header) const
|
||||
{
|
||||
wxHeaderConstIterator it = FindHeader(header);
|
||||
|
||||
return it == m_headers.end() ? wxGetEmptyString() : it->second;
|
||||
}
|
||||
|
||||
wxString wxHTTP::GenerateAuthString(const wxString& user, const wxString& pass) const
|
||||
{
|
||||
static const char *base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
wxString buf;
|
||||
wxString toencode;
|
||||
|
||||
buf.Printf(wxT("Basic "));
|
||||
|
||||
toencode.Printf(wxT("%s:%s"),user.c_str(),pass.c_str());
|
||||
|
||||
size_t len = toencode.length();
|
||||
const wxChar *from = toencode.c_str();
|
||||
while (len >= 3) { // encode full blocks first
|
||||
buf << wxString::Format(wxT("%c%c"), base64[(from[0] >> 2) & 0x3f], base64[((from[0] << 4) & 0x30) | ((from[1] >> 4) & 0xf)]);
|
||||
buf << wxString::Format(wxT("%c%c"), base64[((from[1] << 2) & 0x3c) | ((from[2] >> 6) & 0x3)], base64[from[2] & 0x3f]);
|
||||
from += 3;
|
||||
len -= 3;
|
||||
}
|
||||
if (len > 0) { // pad the remaining characters
|
||||
buf << wxString::Format(wxT("%c"), base64[(from[0] >> 2) & 0x3f]);
|
||||
if (len == 1) {
|
||||
buf << wxString::Format(wxT("%c="), base64[(from[0] << 4) & 0x30]);
|
||||
} else {
|
||||
buf << wxString::Format(wxT("%c%c"), base64[((from[0] << 4) & 0x30) | ((from[1] >> 4) & 0xf)], base64[(from[1] << 2) & 0x3c]);
|
||||
}
|
||||
buf << wxString::Format(wxT("="));
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void wxHTTP::SetPostBuffer(const wxString& post_buf)
|
||||
{
|
||||
m_post_buf = post_buf;
|
||||
}
|
||||
|
||||
void wxHTTP::SendHeaders()
|
||||
{
|
||||
typedef wxStringToStringHashMap::iterator iterator;
|
||||
wxString buf;
|
||||
|
||||
for (iterator it = m_headers.begin(), en = m_headers.end(); it != en; ++it )
|
||||
{
|
||||
buf.Printf(wxT("%s: %s\r\n"), it->first.c_str(), it->second.c_str());
|
||||
|
||||
const wxWX2MBbuf cbuf = buf.mb_str();
|
||||
Write(cbuf, strlen(cbuf));
|
||||
}
|
||||
}
|
||||
|
||||
bool wxHTTP::ParseHeaders()
|
||||
{
|
||||
wxString line;
|
||||
wxStringTokenizer tokenzr;
|
||||
|
||||
ClearHeaders();
|
||||
m_read = true;
|
||||
|
||||
for ( ;; )
|
||||
{
|
||||
m_perr = ReadLine(this, line);
|
||||
if (m_perr != wxPROTO_NOERR)
|
||||
return false;
|
||||
|
||||
if (line.length() == 0)
|
||||
break;
|
||||
|
||||
wxString left_str = line.BeforeFirst(':');
|
||||
m_headers[left_str] = line.AfterFirst(':').Strip(wxString::both);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxHTTP::Connect(const wxString& host, unsigned short port)
|
||||
{
|
||||
wxIPV4address *addr;
|
||||
|
||||
if (m_addr) {
|
||||
delete m_addr;
|
||||
m_addr = NULL;
|
||||
Close();
|
||||
}
|
||||
|
||||
m_addr = addr = new wxIPV4address();
|
||||
|
||||
if (!addr->Hostname(host)) {
|
||||
delete m_addr;
|
||||
m_addr = NULL;
|
||||
m_perr = wxPROTO_NETERR;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( port )
|
||||
addr->Service(port);
|
||||
else if (!addr->Service(wxT("http")))
|
||||
addr->Service(80);
|
||||
|
||||
SetHeader(wxT("Host"), host);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait))
|
||||
{
|
||||
if (m_addr) {
|
||||
delete m_addr;
|
||||
Close();
|
||||
}
|
||||
|
||||
m_addr = addr.Clone();
|
||||
|
||||
wxIPV4address *ipv4addr = wxDynamicCast(&addr, wxIPV4address);
|
||||
if (ipv4addr)
|
||||
SetHeader(wxT("Host"), ipv4addr->OrigHostname());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
|
||||
{
|
||||
const wxChar *request;
|
||||
|
||||
switch (req)
|
||||
{
|
||||
case wxHTTP_GET:
|
||||
request = wxT("GET");
|
||||
break;
|
||||
|
||||
case wxHTTP_POST:
|
||||
request = wxT("POST");
|
||||
if ( GetHeader( wxT("Content-Length") ).IsNull() )
|
||||
SetHeader( wxT("Content-Length"), wxString::Format( wxT("%lu"), (unsigned long)m_post_buf.Len() ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
m_http_response = 0;
|
||||
|
||||
// If there is no User-Agent defined, define it.
|
||||
if (GetHeader(wxT("User-Agent")).IsNull())
|
||||
SetHeader(wxT("User-Agent"), wxT("wxWidgets 2.x"));
|
||||
|
||||
// Send authentication information
|
||||
if (!m_username.empty() || !m_password.empty()) {
|
||||
SetHeader(wxT("Authorization"), GenerateAuthString(m_username, m_password));
|
||||
}
|
||||
|
||||
SaveState();
|
||||
|
||||
// we may use non blocking sockets only if we can dispatch events from them
|
||||
SetFlags( wxIsMainThread() && wxApp::IsMainLoopRunning() ? wxSOCKET_NONE
|
||||
: wxSOCKET_BLOCK );
|
||||
Notify(false);
|
||||
|
||||
wxString buf;
|
||||
buf.Printf(wxT("%s %s HTTP/1.0\r\n"), request, path.c_str());
|
||||
const wxWX2MBbuf pathbuf = wxConvLocal.cWX2MB(buf);
|
||||
Write(pathbuf, strlen(wxMBSTRINGCAST pathbuf));
|
||||
SendHeaders();
|
||||
Write("\r\n", 2);
|
||||
|
||||
if ( req == wxHTTP_POST ) {
|
||||
Write(m_post_buf.mbc_str(), m_post_buf.Len());
|
||||
m_post_buf = wxEmptyString;
|
||||
}
|
||||
|
||||
wxString tmp_str;
|
||||
m_perr = ReadLine(this, tmp_str);
|
||||
if (m_perr != wxPROTO_NOERR) {
|
||||
RestoreState();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tmp_str.Contains(wxT("HTTP/"))) {
|
||||
// TODO: support HTTP v0.9 which can have no header.
|
||||
// FIXME: tmp_str is not put back in the in-queue of the socket.
|
||||
SetHeader(wxT("Content-Length"), wxT("-1"));
|
||||
SetHeader(wxT("Content-Type"), wxT("none/none"));
|
||||
RestoreState();
|
||||
return true;
|
||||
}
|
||||
|
||||
wxStringTokenizer token(tmp_str,wxT(' '));
|
||||
wxString tmp_str2;
|
||||
bool ret_value;
|
||||
|
||||
token.NextToken();
|
||||
tmp_str2 = token.NextToken();
|
||||
|
||||
m_http_response = wxAtoi(tmp_str2);
|
||||
|
||||
switch (tmp_str2[0u])
|
||||
{
|
||||
case wxT('1'):
|
||||
/* INFORMATION / SUCCESS */
|
||||
break;
|
||||
|
||||
case wxT('2'):
|
||||
/* SUCCESS */
|
||||
break;
|
||||
|
||||
case wxT('3'):
|
||||
/* REDIRECTION */
|
||||
break;
|
||||
|
||||
default:
|
||||
m_perr = wxPROTO_NOFILE;
|
||||
RestoreState();
|
||||
return false;
|
||||
}
|
||||
|
||||
ret_value = ParseHeaders();
|
||||
RestoreState();
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
class wxHTTPStream : public wxSocketInputStream
|
||||
{
|
||||
public:
|
||||
wxHTTP *m_http;
|
||||
size_t m_httpsize;
|
||||
unsigned long m_read_bytes;
|
||||
|
||||
wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
|
||||
size_t GetSize() const { return m_httpsize; }
|
||||
virtual ~wxHTTPStream(void) { m_http->Abort(); }
|
||||
|
||||
protected:
|
||||
size_t OnSysRead(void *buffer, size_t bufsize);
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxHTTPStream)
|
||||
};
|
||||
|
||||
size_t wxHTTPStream::OnSysRead(void *buffer, size_t bufsize)
|
||||
{
|
||||
if (m_httpsize > 0 && m_read_bytes >= m_httpsize)
|
||||
{
|
||||
m_lasterror = wxSTREAM_EOF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ret = wxSocketInputStream::OnSysRead(buffer, bufsize);
|
||||
m_read_bytes += ret;
|
||||
|
||||
if (m_httpsize==(size_t)-1 && m_lasterror == wxSTREAM_READ_ERROR )
|
||||
{
|
||||
// if m_httpsize is (size_t) -1 this means read until connection closed
|
||||
// which is equivalent to getting a READ_ERROR, for clients however this
|
||||
// must be translated into EOF, as it is the expected way of signalling
|
||||
// end end of the content
|
||||
m_lasterror = wxSTREAM_EOF ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxHTTP::Abort(void)
|
||||
{
|
||||
return wxSocketClient::Close();
|
||||
}
|
||||
|
||||
wxInputStream *wxHTTP::GetInputStream(const wxString& path)
|
||||
{
|
||||
wxHTTPStream *inp_stream;
|
||||
|
||||
wxString new_path;
|
||||
|
||||
m_perr = wxPROTO_CONNERR;
|
||||
if (!m_addr)
|
||||
return NULL;
|
||||
|
||||
// We set m_connected back to false so wxSocketBase will know what to do.
|
||||
#ifdef __WXMAC__
|
||||
wxSocketClient::Connect(*m_addr , false );
|
||||
wxSocketClient::WaitOnConnect(10);
|
||||
|
||||
if (!wxSocketClient::IsConnected())
|
||||
return NULL;
|
||||
#else
|
||||
if (!wxProtocol::Connect(*m_addr))
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
if (!BuildRequest(path, m_post_buf.empty() ? wxHTTP_GET : wxHTTP_POST))
|
||||
return NULL;
|
||||
|
||||
inp_stream = new wxHTTPStream(this);
|
||||
|
||||
if (!GetHeader(wxT("Content-Length")).empty())
|
||||
inp_stream->m_httpsize = wxAtoi(WXSTRINGCAST GetHeader(wxT("Content-Length")));
|
||||
else
|
||||
inp_stream->m_httpsize = (size_t)-1;
|
||||
|
||||
inp_stream->m_read_bytes = 0;
|
||||
|
||||
Notify(false);
|
||||
SetFlags(wxSOCKET_BLOCK | wxSOCKET_WAITALL);
|
||||
|
||||
return inp_stream;
|
||||
}
|
||||
|
||||
#endif // wxUSE_PROTOCOL_HTTP
|
||||
|
284
Externals/wxWidgets/src/common/iconbndl.cpp
vendored
284
Externals/wxWidgets/src/common/iconbndl.cpp
vendored
@ -1,142 +1,142 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/iconbndl.cpp
|
||||
// Purpose: wxIconBundle
|
||||
// Author: Mattia Barbon
|
||||
// Created: 23.03.2002
|
||||
// RCS-ID: $Id: iconbndl.cpp 40654 2006-08-17 16:08:13Z VS $
|
||||
// Copyright: (c) Mattia barbon
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/iconbndl.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/settings.h"
|
||||
#include "wx/icon.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
|
||||
WX_DEFINE_OBJARRAY(wxIconArray)
|
||||
|
||||
const wxIconBundle& wxIconBundle::operator =( const wxIconBundle& ic )
|
||||
{
|
||||
if( this == &ic ) return *this;
|
||||
|
||||
size_t i, max = ic.m_icons.GetCount();
|
||||
|
||||
DeleteIcons();
|
||||
for( i = 0; i < max; ++i )
|
||||
m_icons.Add( ic.m_icons[i] );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wxIconBundle::DeleteIcons()
|
||||
{
|
||||
m_icons.Empty();
|
||||
}
|
||||
|
||||
#if wxUSE_IMAGE
|
||||
void wxIconBundle::AddIcon( const wxString& file, long type )
|
||||
#else
|
||||
void wxIconBundle::AddIcon( const wxString& WXUNUSED(file), long WXUNUSED(type) )
|
||||
#endif
|
||||
{
|
||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
||||
size_t count = wxImage::GetImageCount( file, type );
|
||||
size_t i;
|
||||
wxImage image;
|
||||
|
||||
for( i = 0; i < count; ++i )
|
||||
{
|
||||
if( !image.LoadFile( file, type, i ) )
|
||||
{
|
||||
wxLogError( _("Failed to load image %d from file '%s'."),
|
||||
i, file.c_str() );
|
||||
continue;
|
||||
}
|
||||
|
||||
wxIcon* tmp = new wxIcon();
|
||||
tmp->CopyFromBitmap( wxBitmap( image ) );
|
||||
AddIcon( *tmp );
|
||||
delete tmp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const wxIcon& wxIconBundle::GetIcon( const wxSize& size ) const
|
||||
{
|
||||
// temp. variable needed to fix Borland C++ 5.5.1 problem
|
||||
// with passing a return value through two functions
|
||||
wxIcon *tmp;
|
||||
|
||||
size_t max = m_icons.GetCount();
|
||||
|
||||
// if we have one or no icon, we can return now without doing more work:
|
||||
if ( max <= 1 )
|
||||
{
|
||||
if ( max == 1 ) // fix for broken BCC
|
||||
tmp = &m_icons[0];
|
||||
else // max == 0
|
||||
tmp = &wxNullIcon;
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
// there are more icons, find the best match:
|
||||
wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
|
||||
sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
|
||||
|
||||
wxIcon *sysIcon = 0;
|
||||
|
||||
for( size_t i = 0; i < max; i++ )
|
||||
{
|
||||
if( !m_icons[i].Ok() )
|
||||
continue;
|
||||
wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight();
|
||||
// requested size
|
||||
if( sx == size.x && sy == size.y )
|
||||
{
|
||||
tmp = &m_icons[i]; // fix for broken BCC
|
||||
return *tmp;
|
||||
}
|
||||
// keep track if there is a system-size icon
|
||||
if( sx == sysX && sy == sysY )
|
||||
sysIcon = &m_icons[i];
|
||||
}
|
||||
|
||||
// return the system-sized icon if we've got one
|
||||
if( sysIcon ) return *sysIcon;
|
||||
// we certainly have at least one icon thanks to the <=1 check above
|
||||
tmp = &m_icons[0];
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
void wxIconBundle::AddIcon( const wxIcon& icon )
|
||||
{
|
||||
size_t i, max = m_icons.GetCount();
|
||||
|
||||
for( i = 0; i < max; ++i )
|
||||
{
|
||||
wxIcon& tmp = m_icons[i];
|
||||
if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() &&
|
||||
tmp.GetHeight() == icon.GetHeight() )
|
||||
{
|
||||
tmp = icon;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_icons.Add( icon );
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/iconbndl.cpp
|
||||
// Purpose: wxIconBundle
|
||||
// Author: Mattia Barbon
|
||||
// Created: 23.03.2002
|
||||
// RCS-ID: $Id: iconbndl.cpp 40654 2006-08-17 16:08:13Z VS $
|
||||
// Copyright: (c) Mattia barbon
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/iconbndl.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/settings.h"
|
||||
#include "wx/icon.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
|
||||
WX_DEFINE_OBJARRAY(wxIconArray)
|
||||
|
||||
const wxIconBundle& wxIconBundle::operator =( const wxIconBundle& ic )
|
||||
{
|
||||
if( this == &ic ) return *this;
|
||||
|
||||
size_t i, max = ic.m_icons.GetCount();
|
||||
|
||||
DeleteIcons();
|
||||
for( i = 0; i < max; ++i )
|
||||
m_icons.Add( ic.m_icons[i] );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wxIconBundle::DeleteIcons()
|
||||
{
|
||||
m_icons.Empty();
|
||||
}
|
||||
|
||||
#if wxUSE_IMAGE
|
||||
void wxIconBundle::AddIcon( const wxString& file, long type )
|
||||
#else
|
||||
void wxIconBundle::AddIcon( const wxString& WXUNUSED(file), long WXUNUSED(type) )
|
||||
#endif
|
||||
{
|
||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
||||
size_t count = wxImage::GetImageCount( file, type );
|
||||
size_t i;
|
||||
wxImage image;
|
||||
|
||||
for( i = 0; i < count; ++i )
|
||||
{
|
||||
if( !image.LoadFile( file, type, i ) )
|
||||
{
|
||||
wxLogError( _("Failed to load image %d from file '%s'."),
|
||||
i, file.c_str() );
|
||||
continue;
|
||||
}
|
||||
|
||||
wxIcon* tmp = new wxIcon();
|
||||
tmp->CopyFromBitmap( wxBitmap( image ) );
|
||||
AddIcon( *tmp );
|
||||
delete tmp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const wxIcon& wxIconBundle::GetIcon( const wxSize& size ) const
|
||||
{
|
||||
// temp. variable needed to fix Borland C++ 5.5.1 problem
|
||||
// with passing a return value through two functions
|
||||
wxIcon *tmp;
|
||||
|
||||
size_t max = m_icons.GetCount();
|
||||
|
||||
// if we have one or no icon, we can return now without doing more work:
|
||||
if ( max <= 1 )
|
||||
{
|
||||
if ( max == 1 ) // fix for broken BCC
|
||||
tmp = &m_icons[0];
|
||||
else // max == 0
|
||||
tmp = &wxNullIcon;
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
// there are more icons, find the best match:
|
||||
wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
|
||||
sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
|
||||
|
||||
wxIcon *sysIcon = 0;
|
||||
|
||||
for( size_t i = 0; i < max; i++ )
|
||||
{
|
||||
if( !m_icons[i].Ok() )
|
||||
continue;
|
||||
wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight();
|
||||
// requested size
|
||||
if( sx == size.x && sy == size.y )
|
||||
{
|
||||
tmp = &m_icons[i]; // fix for broken BCC
|
||||
return *tmp;
|
||||
}
|
||||
// keep track if there is a system-size icon
|
||||
if( sx == sysX && sy == sysY )
|
||||
sysIcon = &m_icons[i];
|
||||
}
|
||||
|
||||
// return the system-sized icon if we've got one
|
||||
if( sysIcon ) return *sysIcon;
|
||||
// we certainly have at least one icon thanks to the <=1 check above
|
||||
tmp = &m_icons[0];
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
void wxIconBundle::AddIcon( const wxIcon& icon )
|
||||
{
|
||||
size_t i, max = m_icons.GetCount();
|
||||
|
||||
for( i = 0; i < max; ++i )
|
||||
{
|
||||
wxIcon& tmp = m_icons[i];
|
||||
if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() &&
|
||||
tmp.GetHeight() == icon.GetHeight() )
|
||||
{
|
||||
tmp = icon;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_icons.Add( icon );
|
||||
}
|
||||
|
128
Externals/wxWidgets/src/common/imagall.cpp
vendored
128
Externals/wxWidgets/src/common/imagall.cpp
vendored
@ -1,64 +1,64 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagall.cpp
|
||||
// Purpose: wxImage access all handler
|
||||
// Author: Sylvain Bougnoux
|
||||
// RCS-ID: $Id: imagall.cpp 42644 2006-10-29 18:58:25Z VZ $
|
||||
// Copyright: (c) Sylvain Bougnoux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This function allows dynamic access to all image handlers compile within
|
||||
// the library. This function should be in a separate file as some compilers
|
||||
// link against the whole object file as long as just one of is function is called!
|
||||
|
||||
void wxInitAllImageHandlers()
|
||||
{
|
||||
#if wxUSE_LIBPNG
|
||||
wxImage::AddHandler( new wxPNGHandler );
|
||||
#endif
|
||||
#if wxUSE_LIBJPEG
|
||||
wxImage::AddHandler( new wxJPEGHandler );
|
||||
#endif
|
||||
#if wxUSE_LIBTIFF
|
||||
wxImage::AddHandler( new wxTIFFHandler );
|
||||
#endif
|
||||
#if wxUSE_GIF
|
||||
wxImage::AddHandler( new wxGIFHandler );
|
||||
#endif
|
||||
#if wxUSE_PNM
|
||||
wxImage::AddHandler( new wxPNMHandler );
|
||||
#endif
|
||||
#if wxUSE_PCX
|
||||
wxImage::AddHandler( new wxPCXHandler );
|
||||
#endif
|
||||
#if wxUSE_IFF
|
||||
wxImage::AddHandler( new wxIFFHandler );
|
||||
#endif
|
||||
#if wxUSE_ICO_CUR
|
||||
wxImage::AddHandler( new wxICOHandler );
|
||||
wxImage::AddHandler( new wxCURHandler );
|
||||
wxImage::AddHandler( new wxANIHandler );
|
||||
#endif
|
||||
#if wxUSE_TGA
|
||||
wxImage::AddHandler( new wxTGAHandler );
|
||||
#endif
|
||||
#if wxUSE_XPM
|
||||
wxImage::AddHandler( new wxXPMHandler );
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagall.cpp
|
||||
// Purpose: wxImage access all handler
|
||||
// Author: Sylvain Bougnoux
|
||||
// RCS-ID: $Id: imagall.cpp 42644 2006-10-29 18:58:25Z VZ $
|
||||
// Copyright: (c) Sylvain Bougnoux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This function allows dynamic access to all image handlers compile within
|
||||
// the library. This function should be in a separate file as some compilers
|
||||
// link against the whole object file as long as just one of is function is called!
|
||||
|
||||
void wxInitAllImageHandlers()
|
||||
{
|
||||
#if wxUSE_LIBPNG
|
||||
wxImage::AddHandler( new wxPNGHandler );
|
||||
#endif
|
||||
#if wxUSE_LIBJPEG
|
||||
wxImage::AddHandler( new wxJPEGHandler );
|
||||
#endif
|
||||
#if wxUSE_LIBTIFF
|
||||
wxImage::AddHandler( new wxTIFFHandler );
|
||||
#endif
|
||||
#if wxUSE_GIF
|
||||
wxImage::AddHandler( new wxGIFHandler );
|
||||
#endif
|
||||
#if wxUSE_PNM
|
||||
wxImage::AddHandler( new wxPNMHandler );
|
||||
#endif
|
||||
#if wxUSE_PCX
|
||||
wxImage::AddHandler( new wxPCXHandler );
|
||||
#endif
|
||||
#if wxUSE_IFF
|
||||
wxImage::AddHandler( new wxIFFHandler );
|
||||
#endif
|
||||
#if wxUSE_ICO_CUR
|
||||
wxImage::AddHandler( new wxICOHandler );
|
||||
wxImage::AddHandler( new wxCURHandler );
|
||||
wxImage::AddHandler( new wxANIHandler );
|
||||
#endif
|
||||
#if wxUSE_TGA
|
||||
wxImage::AddHandler( new wxTGAHandler );
|
||||
#endif
|
||||
#if wxUSE_XPM
|
||||
wxImage::AddHandler( new wxXPMHandler );
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
|
2712
Externals/wxWidgets/src/common/imagbmp.cpp
vendored
2712
Externals/wxWidgets/src/common/imagbmp.cpp
vendored
File diff suppressed because it is too large
Load Diff
6256
Externals/wxWidgets/src/common/image.cpp
vendored
6256
Externals/wxWidgets/src/common/image.cpp
vendored
File diff suppressed because it is too large
Load Diff
616
Externals/wxWidgets/src/common/imagfill.cpp
vendored
616
Externals/wxWidgets/src/common/imagfill.cpp
vendored
@ -1,308 +1,308 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagfill.cpp
|
||||
// Purpose: FloodFill for wxImage
|
||||
// Author: Julian Smart
|
||||
// RCS-ID: $Id: imagfill.cpp 39957 2006-07-03 19:02:54Z ABX $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE && !defined(__WXMSW__)
|
||||
// we have no use for this code in wxMSW...
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/brush.h"
|
||||
#include "wx/dc.h"
|
||||
#include "wx/dcmemory.h"
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
// DoFloodFill
|
||||
// Fills with the colour extracted from fillBrush, starting at x,y until either
|
||||
// a color different from the start pixel is reached (wxFLOOD_SURFACE)
|
||||
// or fill color is reached (wxFLOOD_BORDER)
|
||||
|
||||
static bool LINKAGEMODE MatchPixel(wxImage *img, int x, int y, int w, int h, const wxColour& c)
|
||||
{
|
||||
if ((x<0)||(x>=w)||(y<0)||(y>=h)) return false;
|
||||
|
||||
unsigned char r = img->GetRed(x,y);
|
||||
unsigned char g = img->GetGreen(x,y);
|
||||
unsigned char b = img->GetBlue(x,y);
|
||||
return c.Red() == r && c.Green() == g && c.Blue() == b ;
|
||||
}
|
||||
|
||||
static bool LINKAGEMODE MatchBoundaryPixel(wxImage *img, int x, int y, int w, int h, const wxColour & fill, const wxColour& bound)
|
||||
{
|
||||
if ((x<0)||(x>=w)||(y<0)||(y>=h)) return true;
|
||||
|
||||
unsigned char r = img->GetRed(x,y);
|
||||
unsigned char g = img->GetGreen(x,y);
|
||||
unsigned char b = img->GetBlue(x,y);
|
||||
if ( fill.Red() == r && fill.Green() == g && fill.Blue() == b )
|
||||
return true;
|
||||
if ( bound.Red() == r && bound.Green() == g && bound.Blue() == b )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void LINKAGEMODE
|
||||
wxImageFloodFill(wxImage *image,
|
||||
wxCoord x, wxCoord y, const wxBrush & fillBrush,
|
||||
const wxColour& testColour, int style,
|
||||
int WXUNUSED(LogicalFunction))
|
||||
{
|
||||
/* A diamond flood-fill using a circular queue system.
|
||||
Each pixel surrounding the current pixel is added to
|
||||
the queue if it meets the criteria, then is retrieved in
|
||||
its turn. Code originally based on http://www.drawit.co.nz/Developers.htm,
|
||||
with explicit permission to use this for wxWidgets granted by Andrew Empson
|
||||
(no copyright claimed)
|
||||
*/
|
||||
|
||||
int width = image->GetWidth();
|
||||
int height = image->GetHeight();
|
||||
|
||||
//Draw using a pen made from the current brush colour
|
||||
//Potentially allows us to use patterned flood fills in future code
|
||||
wxColour fillColour = fillBrush.GetColour();
|
||||
unsigned char r = fillColour.Red();
|
||||
unsigned char g = fillColour.Green();
|
||||
unsigned char b = fillColour.Blue();
|
||||
|
||||
//initial test :
|
||||
if (style == wxFLOOD_SURFACE)
|
||||
{
|
||||
//if wxFLOOD_SURFACE, if fill colour is same as required, we don't do anything
|
||||
if ( image->GetRed(x,y) != r
|
||||
|| image->GetGreen(x,y) != g
|
||||
|| image->GetBlue (x,y) != b )
|
||||
{
|
||||
//prepare memory for queue
|
||||
//queue save, start, read
|
||||
size_t *qs, *qst, *qr;
|
||||
|
||||
//queue size (physical)
|
||||
long qSz= height * width * 2;
|
||||
qst = new size_t [qSz];
|
||||
|
||||
//temporary x and y locations
|
||||
int xt, yt;
|
||||
|
||||
for (int i=0; i < qSz; i++)
|
||||
qst[i] = 0;
|
||||
|
||||
// start queue
|
||||
qs=qr=qst;
|
||||
*qs=xt=x;
|
||||
qs++;
|
||||
*qs=yt=y;
|
||||
qs++;
|
||||
|
||||
image->SetRGB(xt,yt,r,g,b);
|
||||
|
||||
//Main queue loop
|
||||
while(qr!=qs)
|
||||
{
|
||||
//Add new members to queue
|
||||
//Above current pixel
|
||||
if(MatchPixel(image,xt,yt-1,width,height,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt-1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt-1,r,g,b);
|
||||
|
||||
//Loop back to beginning of queue
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Below current pixel
|
||||
if(MatchPixel(image,xt,yt+1,width,height,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt+1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt+1,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Left of current pixel
|
||||
if(MatchPixel(image,xt-1,yt,width,height,testColour))
|
||||
{
|
||||
*qs=xt-1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt-1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Right of current pixel
|
||||
if(MatchPixel(image,xt+1,yt,width,height,testColour))
|
||||
{
|
||||
*qs=xt+1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt+1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Retrieve current queue member
|
||||
qr+=2;
|
||||
|
||||
//Loop back to the beginning
|
||||
if(qr>=(qst+qSz)) qr=qst;
|
||||
xt=*qr;
|
||||
yt=*(qr+1);
|
||||
|
||||
//Go Back to beginning of loop
|
||||
}
|
||||
|
||||
delete[] qst;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//style is wxFLOOD_BORDER
|
||||
// fill up to testColor border - if already testColour don't do anything
|
||||
if ( image->GetRed(x,y) != testColour.Red()
|
||||
|| image->GetGreen(x,y) != testColour.Green()
|
||||
|| image->GetBlue(x,y) != testColour.Blue() )
|
||||
{
|
||||
//prepare memory for queue
|
||||
//queue save, start, read
|
||||
size_t *qs, *qst, *qr;
|
||||
|
||||
//queue size (physical)
|
||||
long qSz= height * width * 2;
|
||||
qst = new size_t [qSz];
|
||||
|
||||
//temporary x and y locations
|
||||
int xt, yt;
|
||||
|
||||
for (int i=0; i < qSz; i++)
|
||||
qst[i] = 0;
|
||||
|
||||
// start queue
|
||||
qs=qr=qst;
|
||||
*qs=xt=x;
|
||||
qs++;
|
||||
*qs=yt=y;
|
||||
qs++;
|
||||
|
||||
image->SetRGB(xt,yt,r,g,b);
|
||||
|
||||
//Main queue loop
|
||||
while (qr!=qs)
|
||||
{
|
||||
//Add new members to queue
|
||||
//Above current pixel
|
||||
if(!MatchBoundaryPixel(image,xt,yt-1,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt-1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt-1,r,g,b);
|
||||
|
||||
//Loop back to beginning of queue
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Below current pixel
|
||||
if(!MatchBoundaryPixel(image,xt,yt+1,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt+1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt+1,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Left of current pixel
|
||||
if(!MatchBoundaryPixel(image,xt-1,yt,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt-1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt-1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Right of current pixel
|
||||
if(!MatchBoundaryPixel(image,xt+1,yt,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt+1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt+1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Retrieve current queue member
|
||||
qr+=2;
|
||||
|
||||
//Loop back to the beginning
|
||||
if(qr>=(qst+qSz)) qr=qst;
|
||||
xt=*qr;
|
||||
yt=*(qr+1);
|
||||
|
||||
//Go Back to beginning of loop
|
||||
}
|
||||
|
||||
delete[] qst;
|
||||
}
|
||||
}
|
||||
//all done,
|
||||
}
|
||||
|
||||
|
||||
bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
|
||||
const wxColour& col, int style)
|
||||
{
|
||||
if (dc->GetBrush().GetStyle() == wxTRANSPARENT)
|
||||
return true;
|
||||
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
dc->GetSize(&width, &height);
|
||||
|
||||
//it would be nice to fail if we don't get a sensible size...
|
||||
wxCHECK_MSG(width >= 1 && height >= 1, false,
|
||||
wxT("In FloodFill, dc.GetSize routine failed, method not supported by this DC"));
|
||||
|
||||
//this is much faster than doing the individual pixels
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bitmap(width, height);
|
||||
memdc.SelectObject(bitmap);
|
||||
memdc.Blit(0, 0, width, height, dc, 0, 0);
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
|
||||
wxImage image = bitmap.ConvertToImage();
|
||||
wxImageFloodFill(&image, x,y, dc->GetBrush(), col, style,
|
||||
dc->GetLogicalFunction());
|
||||
bitmap = wxBitmap(image);
|
||||
memdc.SelectObject(bitmap);
|
||||
dc->Blit(0, 0, width, height, &memdc, 0, 0);
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagfill.cpp
|
||||
// Purpose: FloodFill for wxImage
|
||||
// Author: Julian Smart
|
||||
// RCS-ID: $Id: imagfill.cpp 39957 2006-07-03 19:02:54Z ABX $
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE && !defined(__WXMSW__)
|
||||
// we have no use for this code in wxMSW...
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/brush.h"
|
||||
#include "wx/dc.h"
|
||||
#include "wx/dcmemory.h"
|
||||
#include "wx/image.h"
|
||||
#endif
|
||||
|
||||
// DoFloodFill
|
||||
// Fills with the colour extracted from fillBrush, starting at x,y until either
|
||||
// a color different from the start pixel is reached (wxFLOOD_SURFACE)
|
||||
// or fill color is reached (wxFLOOD_BORDER)
|
||||
|
||||
static bool LINKAGEMODE MatchPixel(wxImage *img, int x, int y, int w, int h, const wxColour& c)
|
||||
{
|
||||
if ((x<0)||(x>=w)||(y<0)||(y>=h)) return false;
|
||||
|
||||
unsigned char r = img->GetRed(x,y);
|
||||
unsigned char g = img->GetGreen(x,y);
|
||||
unsigned char b = img->GetBlue(x,y);
|
||||
return c.Red() == r && c.Green() == g && c.Blue() == b ;
|
||||
}
|
||||
|
||||
static bool LINKAGEMODE MatchBoundaryPixel(wxImage *img, int x, int y, int w, int h, const wxColour & fill, const wxColour& bound)
|
||||
{
|
||||
if ((x<0)||(x>=w)||(y<0)||(y>=h)) return true;
|
||||
|
||||
unsigned char r = img->GetRed(x,y);
|
||||
unsigned char g = img->GetGreen(x,y);
|
||||
unsigned char b = img->GetBlue(x,y);
|
||||
if ( fill.Red() == r && fill.Green() == g && fill.Blue() == b )
|
||||
return true;
|
||||
if ( bound.Red() == r && bound.Green() == g && bound.Blue() == b )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void LINKAGEMODE
|
||||
wxImageFloodFill(wxImage *image,
|
||||
wxCoord x, wxCoord y, const wxBrush & fillBrush,
|
||||
const wxColour& testColour, int style,
|
||||
int WXUNUSED(LogicalFunction))
|
||||
{
|
||||
/* A diamond flood-fill using a circular queue system.
|
||||
Each pixel surrounding the current pixel is added to
|
||||
the queue if it meets the criteria, then is retrieved in
|
||||
its turn. Code originally based on http://www.drawit.co.nz/Developers.htm,
|
||||
with explicit permission to use this for wxWidgets granted by Andrew Empson
|
||||
(no copyright claimed)
|
||||
*/
|
||||
|
||||
int width = image->GetWidth();
|
||||
int height = image->GetHeight();
|
||||
|
||||
//Draw using a pen made from the current brush colour
|
||||
//Potentially allows us to use patterned flood fills in future code
|
||||
wxColour fillColour = fillBrush.GetColour();
|
||||
unsigned char r = fillColour.Red();
|
||||
unsigned char g = fillColour.Green();
|
||||
unsigned char b = fillColour.Blue();
|
||||
|
||||
//initial test :
|
||||
if (style == wxFLOOD_SURFACE)
|
||||
{
|
||||
//if wxFLOOD_SURFACE, if fill colour is same as required, we don't do anything
|
||||
if ( image->GetRed(x,y) != r
|
||||
|| image->GetGreen(x,y) != g
|
||||
|| image->GetBlue (x,y) != b )
|
||||
{
|
||||
//prepare memory for queue
|
||||
//queue save, start, read
|
||||
size_t *qs, *qst, *qr;
|
||||
|
||||
//queue size (physical)
|
||||
long qSz= height * width * 2;
|
||||
qst = new size_t [qSz];
|
||||
|
||||
//temporary x and y locations
|
||||
int xt, yt;
|
||||
|
||||
for (int i=0; i < qSz; i++)
|
||||
qst[i] = 0;
|
||||
|
||||
// start queue
|
||||
qs=qr=qst;
|
||||
*qs=xt=x;
|
||||
qs++;
|
||||
*qs=yt=y;
|
||||
qs++;
|
||||
|
||||
image->SetRGB(xt,yt,r,g,b);
|
||||
|
||||
//Main queue loop
|
||||
while(qr!=qs)
|
||||
{
|
||||
//Add new members to queue
|
||||
//Above current pixel
|
||||
if(MatchPixel(image,xt,yt-1,width,height,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt-1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt-1,r,g,b);
|
||||
|
||||
//Loop back to beginning of queue
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Below current pixel
|
||||
if(MatchPixel(image,xt,yt+1,width,height,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt+1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt+1,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Left of current pixel
|
||||
if(MatchPixel(image,xt-1,yt,width,height,testColour))
|
||||
{
|
||||
*qs=xt-1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt-1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Right of current pixel
|
||||
if(MatchPixel(image,xt+1,yt,width,height,testColour))
|
||||
{
|
||||
*qs=xt+1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt+1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Retrieve current queue member
|
||||
qr+=2;
|
||||
|
||||
//Loop back to the beginning
|
||||
if(qr>=(qst+qSz)) qr=qst;
|
||||
xt=*qr;
|
||||
yt=*(qr+1);
|
||||
|
||||
//Go Back to beginning of loop
|
||||
}
|
||||
|
||||
delete[] qst;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//style is wxFLOOD_BORDER
|
||||
// fill up to testColor border - if already testColour don't do anything
|
||||
if ( image->GetRed(x,y) != testColour.Red()
|
||||
|| image->GetGreen(x,y) != testColour.Green()
|
||||
|| image->GetBlue(x,y) != testColour.Blue() )
|
||||
{
|
||||
//prepare memory for queue
|
||||
//queue save, start, read
|
||||
size_t *qs, *qst, *qr;
|
||||
|
||||
//queue size (physical)
|
||||
long qSz= height * width * 2;
|
||||
qst = new size_t [qSz];
|
||||
|
||||
//temporary x and y locations
|
||||
int xt, yt;
|
||||
|
||||
for (int i=0; i < qSz; i++)
|
||||
qst[i] = 0;
|
||||
|
||||
// start queue
|
||||
qs=qr=qst;
|
||||
*qs=xt=x;
|
||||
qs++;
|
||||
*qs=yt=y;
|
||||
qs++;
|
||||
|
||||
image->SetRGB(xt,yt,r,g,b);
|
||||
|
||||
//Main queue loop
|
||||
while (qr!=qs)
|
||||
{
|
||||
//Add new members to queue
|
||||
//Above current pixel
|
||||
if(!MatchBoundaryPixel(image,xt,yt-1,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt-1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt-1,r,g,b);
|
||||
|
||||
//Loop back to beginning of queue
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Below current pixel
|
||||
if(!MatchBoundaryPixel(image,xt,yt+1,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt;
|
||||
qs++;
|
||||
*qs=yt+1;
|
||||
qs++;
|
||||
image->SetRGB(xt,yt+1,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Left of current pixel
|
||||
if(!MatchBoundaryPixel(image,xt-1,yt,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt-1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt-1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Right of current pixel
|
||||
if(!MatchBoundaryPixel(image,xt+1,yt,width,height,fillColour,testColour))
|
||||
{
|
||||
*qs=xt+1;
|
||||
qs++;
|
||||
*qs=yt;
|
||||
qs++;
|
||||
image->SetRGB(xt+1,yt,r,g,b);
|
||||
if(qs>=(qst+qSz)) qs=qst;
|
||||
}
|
||||
|
||||
//Retrieve current queue member
|
||||
qr+=2;
|
||||
|
||||
//Loop back to the beginning
|
||||
if(qr>=(qst+qSz)) qr=qst;
|
||||
xt=*qr;
|
||||
yt=*(qr+1);
|
||||
|
||||
//Go Back to beginning of loop
|
||||
}
|
||||
|
||||
delete[] qst;
|
||||
}
|
||||
}
|
||||
//all done,
|
||||
}
|
||||
|
||||
|
||||
bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
|
||||
const wxColour& col, int style)
|
||||
{
|
||||
if (dc->GetBrush().GetStyle() == wxTRANSPARENT)
|
||||
return true;
|
||||
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
dc->GetSize(&width, &height);
|
||||
|
||||
//it would be nice to fail if we don't get a sensible size...
|
||||
wxCHECK_MSG(width >= 1 && height >= 1, false,
|
||||
wxT("In FloodFill, dc.GetSize routine failed, method not supported by this DC"));
|
||||
|
||||
//this is much faster than doing the individual pixels
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bitmap(width, height);
|
||||
memdc.SelectObject(bitmap);
|
||||
memdc.Blit(0, 0, width, height, dc, 0, 0);
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
|
||||
wxImage image = bitmap.ConvertToImage();
|
||||
wxImageFloodFill(&image, x,y, dc->GetBrush(), col, style,
|
||||
dc->GetLogicalFunction());
|
||||
bitmap = wxBitmap(image);
|
||||
memdc.SelectObject(bitmap);
|
||||
dc->Blit(0, 0, width, height, &memdc, 0, 0);
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user