[Wx Widget] wxWidgets-2.8.12 code now compiles, still need to fix up linking
This commit is contained in:
parent
2e5978ae89
commit
5582d83eec
|
@ -145,8 +145,6 @@
|
|||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib,"wxbase28d")
|
||||
#pragma comment(lib,"wxbase28d_net")
|
||||
#pragma comment(lib,"wxbase28d_xml")
|
||||
#if wxUSE_REGEX
|
||||
#pragma comment(lib,"wxregexd")
|
||||
#endif
|
||||
|
@ -167,9 +165,7 @@
|
|||
#if wxUSE_ZLIB
|
||||
#pragma comment(lib,"wxzlibd")
|
||||
#endif
|
||||
#pragma comment(lib,"wxmsw28d_adv")
|
||||
#pragma comment(lib,"wxmsw28d_core")
|
||||
#pragma comment(lib,"wxmsw28d_html")
|
||||
#if wxUSE_GLCANVAS
|
||||
#pragma comment(lib,"wxmsw28d_gl")
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(__WXWINCE__) || defined(__CYGWIN__)
|
||||
#if defined(__WXWINCE__) || defined(__CYGWIN__) || defined(__WXMSW__)
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
//
|
||||
// Recommended setting: 1, it is compiled into a separate library so there
|
||||
// is no overhead if you don't use it
|
||||
#define wxUSE_DEBUGREPORT 1
|
||||
#define wxUSE_DEBUGREPORT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Unicode support
|
||||
|
@ -520,7 +520,7 @@
|
|||
//
|
||||
// Recommended setting: 1 if your compiler supports it, if it doesn't please
|
||||
// contribute us a makefile for src/regex for it
|
||||
#define wxUSE_REGEX 1
|
||||
#define wxUSE_REGEX 0
|
||||
|
||||
// wxSystemOptions class
|
||||
#define wxUSE_SYSTEM_OPTIONS 1
|
||||
|
@ -533,7 +533,7 @@
|
|||
// Default is 1.
|
||||
//
|
||||
// Recommended setting: 1
|
||||
#define wxUSE_MEDIACTRL 1
|
||||
#define wxUSE_MEDIACTRL 0
|
||||
|
||||
// Use GStreamer for Unix (req a lot of dependancies)
|
||||
//
|
||||
|
@ -547,7 +547,7 @@
|
|||
// Default is 1
|
||||
//
|
||||
// Recommended setting: 1 (requires wxUSE_XML)
|
||||
#define wxUSE_XRC 1
|
||||
#define wxUSE_XRC 0
|
||||
|
||||
// XML parsing classes. Note that their API will change in the future, so
|
||||
// using wxXmlDocument and wxXmlNode in your app is not recommended.
|
||||
|
@ -562,7 +562,7 @@
|
|||
// Default is 1
|
||||
//
|
||||
// Recommended setting: 1
|
||||
#define wxUSE_AUI 1
|
||||
#define wxUSE_AUI 0
|
||||
|
||||
|
||||
// Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
|
||||
|
@ -1011,7 +1011,7 @@
|
|||
//
|
||||
// Recommended setting: 1, set to 0 if you want compile a
|
||||
// smaller library.
|
||||
#define wxUSE_RICHTEXT 1
|
||||
#define wxUSE_RICHTEXT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Data transfer
|
||||
|
@ -1170,25 +1170,25 @@
|
|||
#define wxUSE_LIBJPEG 1
|
||||
|
||||
// Set to 1 for TIFF format support (requires libtiff)
|
||||
#define wxUSE_LIBTIFF 1
|
||||
#define wxUSE_LIBTIFF 0
|
||||
|
||||
// Set to 1 for TGA format support (loading only)
|
||||
#define wxUSE_TGA 1
|
||||
#define wxUSE_TGA 0
|
||||
|
||||
// Set to 1 for GIF format support
|
||||
#define wxUSE_GIF 1
|
||||
#define wxUSE_GIF 0
|
||||
|
||||
// Set to 1 for PNM format support
|
||||
#define wxUSE_PNM 1
|
||||
#define wxUSE_PNM 0
|
||||
|
||||
// Set to 1 for PCX format support
|
||||
#define wxUSE_PCX 1
|
||||
#define wxUSE_PCX 0
|
||||
|
||||
// Set to 1 for IFF format support (Amiga format)
|
||||
#define wxUSE_IFF 0
|
||||
|
||||
// Set to 1 for XPM format support
|
||||
#define wxUSE_XPM 1
|
||||
#define wxUSE_XPM 0
|
||||
|
||||
// Set to 1 for MS Icons and Cursors format support
|
||||
#define wxUSE_ICO_CUR 1
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/browserhack28.h
|
||||
// Purpose: Allows GUI library to override base wxLaunchDefaultBrowser.
|
||||
// Author: David Elliott
|
||||
// Modified by:
|
||||
// Created: 2007-08-19
|
||||
// RCS-ID: $Id: browserhack28.h 48184 2007-08-19 19:22:09Z DE $
|
||||
// Copyright: (c) David Elliott
|
||||
// Licence: wxWidgets licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_BROWSERHACK28_H_
|
||||
#define _WX_PRIVATE_BROWSERHACK28_H_
|
||||
|
||||
typedef bool (*wxLaunchDefaultBrowserImpl_t)(const wxString& url, int flags);
|
||||
|
||||
// Function the GUI library can call to provide a better implementation
|
||||
WXDLLIMPEXP_BASE void wxSetLaunchDefaultBrowserImpl(wxLaunchDefaultBrowserImpl_t newImpl);
|
||||
|
||||
#endif //ndef _WX_PRIVATE_BROWSERHACK28_H_
|
|
@ -8,7 +8,6 @@
|
|||
// Copyright: (c) 1998 Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_UTILSH__
|
||||
#define _WX_UTILSH__
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
//
|
||||
// Recommended setting: 1, it is compiled into a separate library so there
|
||||
// is no overhead if you don't use it
|
||||
#define wxUSE_DEBUGREPORT 1
|
||||
#define wxUSE_DEBUGREPORT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Unicode support
|
||||
|
@ -520,7 +520,7 @@
|
|||
//
|
||||
// Recommended setting: 1 if your compiler supports it, if it doesn't please
|
||||
// contribute us a makefile for src/regex for it
|
||||
#define wxUSE_REGEX 1
|
||||
#define wxUSE_REGEX 0
|
||||
|
||||
// wxSystemOptions class
|
||||
#define wxUSE_SYSTEM_OPTIONS 1
|
||||
|
@ -533,7 +533,7 @@
|
|||
// Default is 1.
|
||||
//
|
||||
// Recommended setting: 1
|
||||
#define wxUSE_MEDIACTRL 1
|
||||
#define wxUSE_MEDIACTRL 0
|
||||
|
||||
// Use GStreamer for Unix (req a lot of dependancies)
|
||||
//
|
||||
|
@ -547,7 +547,7 @@
|
|||
// Default is 1
|
||||
//
|
||||
// Recommended setting: 1 (requires wxUSE_XML)
|
||||
#define wxUSE_XRC 1
|
||||
#define wxUSE_XRC 0
|
||||
|
||||
// XML parsing classes. Note that their API will change in the future, so
|
||||
// using wxXmlDocument and wxXmlNode in your app is not recommended.
|
||||
|
@ -562,7 +562,7 @@
|
|||
// Default is 1
|
||||
//
|
||||
// Recommended setting: 1
|
||||
#define wxUSE_AUI 1
|
||||
#define wxUSE_AUI 0
|
||||
|
||||
|
||||
// Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
|
||||
|
@ -1011,7 +1011,7 @@
|
|||
//
|
||||
// Recommended setting: 1, set to 0 if you want compile a
|
||||
// smaller library.
|
||||
#define wxUSE_RICHTEXT 1
|
||||
#define wxUSE_RICHTEXT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Data transfer
|
||||
|
@ -1170,25 +1170,25 @@
|
|||
#define wxUSE_LIBJPEG 1
|
||||
|
||||
// Set to 1 for TIFF format support (requires libtiff)
|
||||
#define wxUSE_LIBTIFF 1
|
||||
#define wxUSE_LIBTIFF 0
|
||||
|
||||
// Set to 1 for TGA format support (loading only)
|
||||
#define wxUSE_TGA 1
|
||||
#define wxUSE_TGA 0
|
||||
|
||||
// Set to 1 for GIF format support
|
||||
#define wxUSE_GIF 1
|
||||
#define wxUSE_GIF 0
|
||||
|
||||
// Set to 1 for PNM format support
|
||||
#define wxUSE_PNM 1
|
||||
#define wxUSE_PNM 0
|
||||
|
||||
// Set to 1 for PCX format support
|
||||
#define wxUSE_PCX 1
|
||||
#define wxUSE_PCX 0
|
||||
|
||||
// Set to 1 for IFF format support (Amiga format)
|
||||
#define wxUSE_IFF 0
|
||||
|
||||
// Set to 1 for XPM format support
|
||||
#define wxUSE_XPM 1
|
||||
#define wxUSE_XPM 0
|
||||
|
||||
// Set to 1 for MS Icons and Cursors format support
|
||||
#define wxUSE_ICO_CUR 1
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
//
|
||||
// Recommended setting: 1, it is compiled into a separate library so there
|
||||
// is no overhead if you don't use it
|
||||
#define wxUSE_DEBUGREPORT 1
|
||||
#define wxUSE_DEBUGREPORT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Unicode support
|
||||
|
@ -520,7 +520,7 @@
|
|||
//
|
||||
// Recommended setting: 1 if your compiler supports it, if it doesn't please
|
||||
// contribute us a makefile for src/regex for it
|
||||
#define wxUSE_REGEX 1
|
||||
#define wxUSE_REGEX 0
|
||||
|
||||
// wxSystemOptions class
|
||||
#define wxUSE_SYSTEM_OPTIONS 1
|
||||
|
@ -533,7 +533,7 @@
|
|||
// Default is 1.
|
||||
//
|
||||
// Recommended setting: 1
|
||||
#define wxUSE_MEDIACTRL 1
|
||||
#define wxUSE_MEDIACTRL 0
|
||||
|
||||
// Use GStreamer for Unix (req a lot of dependancies)
|
||||
//
|
||||
|
@ -547,7 +547,7 @@
|
|||
// Default is 1
|
||||
//
|
||||
// Recommended setting: 1 (requires wxUSE_XML)
|
||||
#define wxUSE_XRC 1
|
||||
#define wxUSE_XRC 0
|
||||
|
||||
// XML parsing classes. Note that their API will change in the future, so
|
||||
// using wxXmlDocument and wxXmlNode in your app is not recommended.
|
||||
|
@ -562,7 +562,7 @@
|
|||
// Default is 1
|
||||
//
|
||||
// Recommended setting: 1
|
||||
#define wxUSE_AUI 1
|
||||
#define wxUSE_AUI 0
|
||||
|
||||
|
||||
// Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
|
||||
|
@ -1011,7 +1011,7 @@
|
|||
//
|
||||
// Recommended setting: 1, set to 0 if you want compile a
|
||||
// smaller library.
|
||||
#define wxUSE_RICHTEXT 1
|
||||
#define wxUSE_RICHTEXT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Data transfer
|
||||
|
@ -1170,25 +1170,25 @@
|
|||
#define wxUSE_LIBJPEG 1
|
||||
|
||||
// Set to 1 for TIFF format support (requires libtiff)
|
||||
#define wxUSE_LIBTIFF 1
|
||||
#define wxUSE_LIBTIFF 0
|
||||
|
||||
// Set to 1 for TGA format support (loading only)
|
||||
#define wxUSE_TGA 1
|
||||
#define wxUSE_TGA 0
|
||||
|
||||
// Set to 1 for GIF format support
|
||||
#define wxUSE_GIF 1
|
||||
#define wxUSE_GIF 0
|
||||
|
||||
// Set to 1 for PNM format support
|
||||
#define wxUSE_PNM 1
|
||||
#define wxUSE_PNM 0
|
||||
|
||||
// Set to 1 for PCX format support
|
||||
#define wxUSE_PCX 1
|
||||
#define wxUSE_PCX 0
|
||||
|
||||
// Set to 1 for IFF format support (Amiga format)
|
||||
#define wxUSE_IFF 0
|
||||
|
||||
// Set to 1 for XPM format support
|
||||
#define wxUSE_XPM 1
|
||||
#define wxUSE_XPM 0
|
||||
|
||||
// Set to 1 for MS Icons and Cursors format support
|
||||
#define wxUSE_ICO_CUR 1
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,354 +1,354 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/artprov.cpp
|
||||
// Purpose: wxArtProvider class
|
||||
// Author: Vaclav Slavik
|
||||
// Modified by:
|
||||
// Created: 18/03/2002
|
||||
// RCS-ID: $Id: artprov.cpp 57701 2008-12-31 23:40:06Z 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
|
||||
|
||||
#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
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#include "wx/msw/wrapwin.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*/ void wxArtProvider::PushBack(wxArtProvider *provider)
|
||||
{
|
||||
Insert(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)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
return wxSize(::GetSystemMetrics(SM_CXSMICON),
|
||||
::GetSystemMetrics(SM_CYSMICON));
|
||||
#else
|
||||
return wxSize(16, 16);
|
||||
#endif // __WXMSW__/!__WXMSW__
|
||||
}
|
||||
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 57701 2008-12-31 23:40:06Z 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
|
||||
|
||||
#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
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#include "wx/msw/wrapwin.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*/ void wxArtProvider::PushBack(wxArtProvider *provider)
|
||||
{
|
||||
Insert(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)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
return wxSize(::GetSystemMetrics(SM_CXSMICON),
|
||||
::GetSystemMetrics(SM_CYSMICON));
|
||||
#else
|
||||
return wxSize(16, 16);
|
||||
#endif // __WXMSW__/!__WXMSW__
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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 65725 2010-10-02 13:05:08Z TIK $
|
||||
// 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") );
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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 65725 2010-10-02 13:05:08Z TIK $
|
||||
// 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") );
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +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
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,206 +1,206 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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 66911 2011-02-16 21:31:33Z JS $
|
||||
// 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 && !m_docManager->Clear(!event.CanVeto()) )
|
||||
{
|
||||
// The user decided not to close finally, abort.
|
||||
event.Veto();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 66911 2011-02-16 21:31:33Z JS $
|
||||
// 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 && !m_docManager->Clear(!event.CanVeto()) )
|
||||
{
|
||||
// The user decided not to close finally, abort.
|
||||
event.Veto();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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__
|
||||
|
|
|
@ -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_
|
||||
|
||||
|
|
|
@ -1,196 +1,196 @@
|
|||
/*****************************************************************************
|
||||
** Name: extended.c
|
||||
** Purpose: IEEE Extended<->Double routines to save floats to file
|
||||
** Maintainer: Ryan Norton
|
||||
** Modified by:
|
||||
** Created: 11/24/04
|
||||
** RCS-ID: $Id: extended.c 36952 2006-01-18 10:25:04Z JS $
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
/* eVC cause warnings in its own headers: stdlib.h and winnt.h */
|
||||
#pragma warning (disable:4115)
|
||||
#pragma warning (disable:4214)
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
#pragma warning (default:4115)
|
||||
#pragma warning (default:4214)
|
||||
#endif
|
||||
|
||||
#if wxUSE_APPLE_IEEE
|
||||
|
||||
#include "wx/math.h"
|
||||
|
||||
/* Copyright (C) 1989-1991 Ken Turkowski. <turk@computer.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Warranty Information
|
||||
* Even though I have reviewed this software, I make no warranty
|
||||
* or representation, either express or implied, with respect to this
|
||||
* software, its quality, accuracy, merchantability, or fitness for a
|
||||
* particular purpose. As a result, this software is provided "as is,"
|
||||
* and you, its user, are assuming the entire risk as to its quality
|
||||
* and accuracy.
|
||||
*
|
||||
* This code may be used and freely distributed as long as it includes
|
||||
* this copyright notice and the above warranty information.
|
||||
*
|
||||
* Machine-independent I/O routines for IEEE floating-point numbers.
|
||||
*
|
||||
* NaN's and infinities are converted to HUGE_VAL or HUGE, which
|
||||
* happens to be infinity on IEEE machines. Unfortunately, it is
|
||||
* impossible to preserve NaN's in a machine-independent way.
|
||||
* Infinities are, however, preserved on IEEE machines.
|
||||
*
|
||||
* These routines have been tested on the following machines:
|
||||
* Apple Macintosh, MPW 3.1 C compiler
|
||||
* Apple Macintosh, THINK C compiler
|
||||
* Silicon Graphics IRIS, MIPS compiler
|
||||
* Cray X/MP and Y/MP
|
||||
* Digital Equipment VAX
|
||||
* Sequent Balance (Multiprocesor 386)
|
||||
* NeXT
|
||||
*
|
||||
*
|
||||
* Implemented by Malcolm Slaney and Ken Turkowski.
|
||||
*
|
||||
* Malcolm Slaney contributions during 1988-1990 include big- and little-
|
||||
* endian file I/O, conversion to and from Motorola's extended 80-bit
|
||||
* floating-point format, and conversions to and from IEEE single-
|
||||
* precision floating-point format.
|
||||
*
|
||||
* In 1991, Ken Turkowski implemented the conversions to and from
|
||||
* IEEE double-precision format, added more precision to the extended
|
||||
* conversions, and accommodated conversions involving +/- infinity,
|
||||
* NaN's, and denormalized numbers.
|
||||
*/
|
||||
|
||||
#ifndef HUGE_VAL
|
||||
# define HUGE_VAL HUGE
|
||||
#endif /*HUGE_VAL*/
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* The following two routines make up for deficiencies in many
|
||||
* compilers to convert properly between unsigned integers and
|
||||
* floating-point. Some compilers which have this bug are the
|
||||
* THINK_C compiler for the Macintosh and the C compiler for the
|
||||
* Silicon Graphics MIPS-based Iris.
|
||||
****************************************************************/
|
||||
|
||||
#ifdef applec /* The Apple C compiler works */
|
||||
# define FloatToUnsigned(f) ((wxUint32)(f))
|
||||
# define UnsignedToFloat(u) ((wxFloat64)(u))
|
||||
#else /*applec*/
|
||||
# define FloatToUnsigned(f) ((wxUint32)(((wxInt32)((f) - 2147483648.0)) + 2147483647L) + 1)
|
||||
# define UnsignedToFloat(u) (((wxFloat64)((wxInt32)((u) - 2147483647L - 1))) + 2147483648.0)
|
||||
#endif /*applec*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* Extended precision IEEE floating-point conversion routines.
|
||||
* Extended is an 80-bit number as defined by Motorola,
|
||||
* with a sign bit, 15 bits of exponent (offset 16383?),
|
||||
* and a 64-bit mantissa, with no hidden bit.
|
||||
****************************************************************/
|
||||
|
||||
wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes)
|
||||
{
|
||||
wxFloat64 f;
|
||||
wxInt32 expon;
|
||||
wxUint32 hiMant, loMant;
|
||||
|
||||
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
|
||||
hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24)
|
||||
| ((wxUint32)(bytes[3] & 0xFF) << 16)
|
||||
| ((wxUint32)(bytes[4] & 0xFF) << 8)
|
||||
| ((wxUint32)(bytes[5] & 0xFF));
|
||||
loMant = ((wxUint32)(bytes[6] & 0xFF) << 24)
|
||||
| ((wxUint32)(bytes[7] & 0xFF) << 16)
|
||||
| ((wxUint32)(bytes[8] & 0xFF) << 8)
|
||||
| ((wxUint32)(bytes[9] & 0xFF));
|
||||
|
||||
if (expon == 0 && hiMant == 0 && loMant == 0) {
|
||||
f = 0;
|
||||
}
|
||||
else {
|
||||
if (expon == 0x7FFF) { /* Infinity or NaN */
|
||||
f = HUGE_VAL;
|
||||
}
|
||||
else {
|
||||
expon -= 16383;
|
||||
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
|
||||
f += ldexp(UnsignedToFloat(loMant), expon-=32);
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes[0] & 0x80)
|
||||
return -f;
|
||||
else
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
||||
void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes)
|
||||
{
|
||||
wxInt32 sign;
|
||||
wxInt32 expon;
|
||||
wxFloat64 fMant, fsMant;
|
||||
wxUint32 hiMant, loMant;
|
||||
|
||||
if (num < 0) {
|
||||
sign = 0x8000;
|
||||
num *= -1;
|
||||
} else {
|
||||
sign = 0;
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
expon = 0; hiMant = 0; loMant = 0;
|
||||
}
|
||||
else {
|
||||
fMant = frexp(num, &expon);
|
||||
if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */
|
||||
expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */
|
||||
}
|
||||
else { /* Finite */
|
||||
expon += 16382;
|
||||
if (expon < 0) { /* denormalized */
|
||||
fMant = ldexp(fMant, expon);
|
||||
expon = 0;
|
||||
}
|
||||
expon |= sign;
|
||||
fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant);
|
||||
fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant);
|
||||
}
|
||||
}
|
||||
|
||||
bytes[0] = expon >> 8;
|
||||
bytes[1] = expon;
|
||||
bytes[2] = hiMant >> 24;
|
||||
bytes[3] = hiMant >> 16;
|
||||
bytes[4] = hiMant >> 8;
|
||||
bytes[5] = hiMant;
|
||||
bytes[6] = loMant >> 24;
|
||||
bytes[7] = loMant >> 16;
|
||||
bytes[8] = loMant >> 8;
|
||||
bytes[9] = loMant;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* wxUSE_APPLE_IEEE */
|
||||
/*****************************************************************************
|
||||
** Name: extended.c
|
||||
** Purpose: IEEE Extended<->Double routines to save floats to file
|
||||
** Maintainer: Ryan Norton
|
||||
** Modified by:
|
||||
** Created: 11/24/04
|
||||
** RCS-ID: $Id: extended.c 36952 2006-01-18 10:25:04Z JS $
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
/* eVC cause warnings in its own headers: stdlib.h and winnt.h */
|
||||
#pragma warning (disable:4115)
|
||||
#pragma warning (disable:4214)
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
#pragma warning (default:4115)
|
||||
#pragma warning (default:4214)
|
||||
#endif
|
||||
|
||||
#if wxUSE_APPLE_IEEE
|
||||
|
||||
#include "wx/math.h"
|
||||
|
||||
/* Copyright (C) 1989-1991 Ken Turkowski. <turk@computer.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Warranty Information
|
||||
* Even though I have reviewed this software, I make no warranty
|
||||
* or representation, either express or implied, with respect to this
|
||||
* software, its quality, accuracy, merchantability, or fitness for a
|
||||
* particular purpose. As a result, this software is provided "as is,"
|
||||
* and you, its user, are assuming the entire risk as to its quality
|
||||
* and accuracy.
|
||||
*
|
||||
* This code may be used and freely distributed as long as it includes
|
||||
* this copyright notice and the above warranty information.
|
||||
*
|
||||
* Machine-independent I/O routines for IEEE floating-point numbers.
|
||||
*
|
||||
* NaN's and infinities are converted to HUGE_VAL or HUGE, which
|
||||
* happens to be infinity on IEEE machines. Unfortunately, it is
|
||||
* impossible to preserve NaN's in a machine-independent way.
|
||||
* Infinities are, however, preserved on IEEE machines.
|
||||
*
|
||||
* These routines have been tested on the following machines:
|
||||
* Apple Macintosh, MPW 3.1 C compiler
|
||||
* Apple Macintosh, THINK C compiler
|
||||
* Silicon Graphics IRIS, MIPS compiler
|
||||
* Cray X/MP and Y/MP
|
||||
* Digital Equipment VAX
|
||||
* Sequent Balance (Multiprocesor 386)
|
||||
* NeXT
|
||||
*
|
||||
*
|
||||
* Implemented by Malcolm Slaney and Ken Turkowski.
|
||||
*
|
||||
* Malcolm Slaney contributions during 1988-1990 include big- and little-
|
||||
* endian file I/O, conversion to and from Motorola's extended 80-bit
|
||||
* floating-point format, and conversions to and from IEEE single-
|
||||
* precision floating-point format.
|
||||
*
|
||||
* In 1991, Ken Turkowski implemented the conversions to and from
|
||||
* IEEE double-precision format, added more precision to the extended
|
||||
* conversions, and accommodated conversions involving +/- infinity,
|
||||
* NaN's, and denormalized numbers.
|
||||
*/
|
||||
|
||||
#ifndef HUGE_VAL
|
||||
# define HUGE_VAL HUGE
|
||||
#endif /*HUGE_VAL*/
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* The following two routines make up for deficiencies in many
|
||||
* compilers to convert properly between unsigned integers and
|
||||
* floating-point. Some compilers which have this bug are the
|
||||
* THINK_C compiler for the Macintosh and the C compiler for the
|
||||
* Silicon Graphics MIPS-based Iris.
|
||||
****************************************************************/
|
||||
|
||||
#ifdef applec /* The Apple C compiler works */
|
||||
# define FloatToUnsigned(f) ((wxUint32)(f))
|
||||
# define UnsignedToFloat(u) ((wxFloat64)(u))
|
||||
#else /*applec*/
|
||||
# define FloatToUnsigned(f) ((wxUint32)(((wxInt32)((f) - 2147483648.0)) + 2147483647L) + 1)
|
||||
# define UnsignedToFloat(u) (((wxFloat64)((wxInt32)((u) - 2147483647L - 1))) + 2147483648.0)
|
||||
#endif /*applec*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* Extended precision IEEE floating-point conversion routines.
|
||||
* Extended is an 80-bit number as defined by Motorola,
|
||||
* with a sign bit, 15 bits of exponent (offset 16383?),
|
||||
* and a 64-bit mantissa, with no hidden bit.
|
||||
****************************************************************/
|
||||
|
||||
wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes)
|
||||
{
|
||||
wxFloat64 f;
|
||||
wxInt32 expon;
|
||||
wxUint32 hiMant, loMant;
|
||||
|
||||
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
|
||||
hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24)
|
||||
| ((wxUint32)(bytes[3] & 0xFF) << 16)
|
||||
| ((wxUint32)(bytes[4] & 0xFF) << 8)
|
||||
| ((wxUint32)(bytes[5] & 0xFF));
|
||||
loMant = ((wxUint32)(bytes[6] & 0xFF) << 24)
|
||||
| ((wxUint32)(bytes[7] & 0xFF) << 16)
|
||||
| ((wxUint32)(bytes[8] & 0xFF) << 8)
|
||||
| ((wxUint32)(bytes[9] & 0xFF));
|
||||
|
||||
if (expon == 0 && hiMant == 0 && loMant == 0) {
|
||||
f = 0;
|
||||
}
|
||||
else {
|
||||
if (expon == 0x7FFF) { /* Infinity or NaN */
|
||||
f = HUGE_VAL;
|
||||
}
|
||||
else {
|
||||
expon -= 16383;
|
||||
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
|
||||
f += ldexp(UnsignedToFloat(loMant), expon-=32);
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes[0] & 0x80)
|
||||
return -f;
|
||||
else
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
||||
void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes)
|
||||
{
|
||||
wxInt32 sign;
|
||||
wxInt32 expon;
|
||||
wxFloat64 fMant, fsMant;
|
||||
wxUint32 hiMant, loMant;
|
||||
|
||||
if (num < 0) {
|
||||
sign = 0x8000;
|
||||
num *= -1;
|
||||
} else {
|
||||
sign = 0;
|
||||
}
|
||||
|
||||
if (num == 0) {
|
||||
expon = 0; hiMant = 0; loMant = 0;
|
||||
}
|
||||
else {
|
||||
fMant = frexp(num, &expon);
|
||||
if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */
|
||||
expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */
|
||||
}
|
||||
else { /* Finite */
|
||||
expon += 16382;
|
||||
if (expon < 0) { /* denormalized */
|
||||
fMant = ldexp(fMant, expon);
|
||||
expon = 0;
|
||||
}
|
||||
expon |= sign;
|
||||
fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant);
|
||||
fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant);
|
||||
}
|
||||
}
|
||||
|
||||
bytes[0] = expon >> 8;
|
||||
bytes[1] = expon;
|
||||
bytes[2] = hiMant >> 24;
|
||||
bytes[3] = hiMant >> 16;
|
||||
bytes[4] = hiMant >> 8;
|
||||
bytes[5] = hiMant;
|
||||
bytes[6] = loMant >> 24;
|
||||
bytes[7] = loMant >> 16;
|
||||
bytes[8] = loMant >> 8;
|
||||
bytes[9] = loMant;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* wxUSE_APPLE_IEEE */
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,256 +1,256 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: ffile.cpp
|
||||
// Purpose: wxFFile encapsulates "FILE *" IO stream
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 14.07.99
|
||||
// RCS-ID: $Id: ffile.cpp 63300 2010-01-28 21:36:09Z MW $
|
||||
// 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
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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 wxHAS_LARGE_FFILES
|
||||
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 63300 2010-01-28 21:36:09Z MW $
|
||||
// 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
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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 wxHAS_LARGE_FFILES
|
||||
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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 66916 2011-02-16 21:48:55Z JS $
|
||||
// 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_FILE_MUST_EXIST) : 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 66916 2011-02-16 21:48:55Z JS $
|
||||
// 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_FILE_MUST_EXIST) : 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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,325 +1,325 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagfill.cpp
|
||||
// Purpose: FloodFill for wxImage
|
||||
// Author: Julian Smart
|
||||
// RCS-ID: $Id: imagfill.cpp 63770 2010-03-28 22:34:12Z 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
|
||||
|
||||
#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"));
|
||||
|
||||
const int x_dev = dc->LogicalToDeviceX(x);
|
||||
const int y_dev = dc->LogicalToDeviceY(y);
|
||||
|
||||
// if start point is outside dc, can't do anything
|
||||
if (!wxRect(0, 0, width, height).Contains(x_dev, y_dev))
|
||||
return false;
|
||||
|
||||
wxBitmap bitmap(width, height);
|
||||
wxMemoryDC memdc(bitmap);
|
||||
// match dc scales
|
||||
double sx, sy;
|
||||
dc->GetUserScale(&sx, &sy);
|
||||
memdc.SetUserScale(sx, sy);
|
||||
dc->GetLogicalScale(&sx, &sy);
|
||||
memdc.SetLogicalScale(sx, sy);
|
||||
|
||||
// get logical size and origin
|
||||
const int w_log = dc->DeviceToLogicalXRel(width);
|
||||
const int h_log = dc->DeviceToLogicalYRel(height);
|
||||
const int x0_log = dc->DeviceToLogicalX(0);
|
||||
const int y0_log = dc->DeviceToLogicalY(0);
|
||||
|
||||
memdc.Blit(0, 0, w_log, h_log, dc, x0_log, y0_log);
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
|
||||
wxImage image = bitmap.ConvertToImage();
|
||||
wxImageFloodFill(&image, x_dev, y_dev, dc->GetBrush(), col, style,
|
||||
dc->GetLogicalFunction());
|
||||
bitmap = wxBitmap(image);
|
||||
memdc.SelectObject(bitmap);
|
||||
dc->Blit(x0_log, y0_log, w_log, h_log, &memdc, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagfill.cpp
|
||||
// Purpose: FloodFill for wxImage
|
||||
// Author: Julian Smart
|
||||
// RCS-ID: $Id: imagfill.cpp 63770 2010-03-28 22:34:12Z 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
|
||||
|
||||
#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"));
|
||||
|
||||
const int x_dev = dc->LogicalToDeviceX(x);
|
||||
const int y_dev = dc->LogicalToDeviceY(y);
|
||||
|
||||
// if start point is outside dc, can't do anything
|
||||
if (!wxRect(0, 0, width, height).Contains(x_dev, y_dev))
|
||||
return false;
|
||||
|
||||
wxBitmap bitmap(width, height);
|
||||
wxMemoryDC memdc(bitmap);
|
||||
// match dc scales
|
||||
double sx, sy;
|
||||
dc->GetUserScale(&sx, &sy);
|
||||
memdc.SetUserScale(sx, sy);
|
||||
dc->GetLogicalScale(&sx, &sy);
|
||||
memdc.SetLogicalScale(sx, sy);
|
||||
|
||||
// get logical size and origin
|
||||
const int w_log = dc->DeviceToLogicalXRel(width);
|
||||
const int h_log = dc->DeviceToLogicalYRel(height);
|
||||
const int x0_log = dc->DeviceToLogicalX(0);
|
||||
const int y0_log = dc->DeviceToLogicalY(0);
|
||||
|
||||
memdc.Blit(0, 0, w_log, h_log, dc, x0_log, y0_log);
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
|
||||
wxImage image = bitmap.ConvertToImage();
|
||||
wxImageFloodFill(&image, x_dev, y_dev, dc->GetBrush(), col, style,
|
||||
dc->GetLogicalFunction());
|
||||
bitmap = wxBitmap(image);
|
||||
memdc.SelectObject(bitmap);
|
||||
dc->Blit(x0_log, y0_log, w_log, h_log, &memdc, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_IMAGE
|
||||
|
|
|
@ -1,105 +1,105 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imaggif.cpp
|
||||
// Purpose: wxGIFHandler
|
||||
// Author: Vaclav Slavik & Guillermo Rodriguez Garcia
|
||||
// RCS-ID: $Id: imaggif.cpp 41819 2006-10-09 17:51:07Z VZ $
|
||||
// Copyright: (c) 1999 Vaclav Slavik & Guillermo Rodriguez Garcia
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE && wxUSE_GIF
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/imaggif.h"
|
||||
#include "wx/gifdecod.h"
|
||||
#include "wx/wfstream.h"
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxGIFHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
|
||||
bool verbose, int index)
|
||||
{
|
||||
wxGIFDecoder *decod;
|
||||
wxGIFErrorCode error;
|
||||
bool ok = true;
|
||||
|
||||
// image->Destroy();
|
||||
decod = new wxGIFDecoder();
|
||||
error = decod->LoadGIF(stream);
|
||||
|
||||
if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case wxGIF_INVFORMAT:
|
||||
wxLogError(_("GIF: error in GIF image format."));
|
||||
break;
|
||||
case wxGIF_MEMERR:
|
||||
wxLogError(_("GIF: not enough memory."));
|
||||
break;
|
||||
default:
|
||||
wxLogError(_("GIF: unknown error!!!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete decod;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((error == wxGIF_TRUNCATED) && verbose)
|
||||
{
|
||||
wxLogError(_("GIF: data stream seems to be truncated."));
|
||||
/* go on; image data is OK */
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ok = decod->ConvertToImage(index != -1 ? (size_t)index : 0, image);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogError(_("GIF: Invalid gif index."));
|
||||
}
|
||||
|
||||
delete decod;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
|
||||
wxOutputStream& WXUNUSED(stream), bool verbose )
|
||||
{
|
||||
if (verbose)
|
||||
wxLogDebug(wxT("GIF: the handler is read-only!!"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxGIFHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
wxGIFDecoder decod;
|
||||
return decod.CanRead(stream);
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_GIF
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imaggif.cpp
|
||||
// Purpose: wxGIFHandler
|
||||
// Author: Vaclav Slavik & Guillermo Rodriguez Garcia
|
||||
// RCS-ID: $Id: imaggif.cpp 41819 2006-10-09 17:51:07Z VZ $
|
||||
// Copyright: (c) 1999 Vaclav Slavik & Guillermo Rodriguez Garcia
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE && wxUSE_GIF
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/imaggif.h"
|
||||
#include "wx/gifdecod.h"
|
||||
#include "wx/wfstream.h"
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxGIFHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
|
||||
bool verbose, int index)
|
||||
{
|
||||
wxGIFDecoder *decod;
|
||||
wxGIFErrorCode error;
|
||||
bool ok = true;
|
||||
|
||||
// image->Destroy();
|
||||
decod = new wxGIFDecoder();
|
||||
error = decod->LoadGIF(stream);
|
||||
|
||||
if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case wxGIF_INVFORMAT:
|
||||
wxLogError(_("GIF: error in GIF image format."));
|
||||
break;
|
||||
case wxGIF_MEMERR:
|
||||
wxLogError(_("GIF: not enough memory."));
|
||||
break;
|
||||
default:
|
||||
wxLogError(_("GIF: unknown error!!!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete decod;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((error == wxGIF_TRUNCATED) && verbose)
|
||||
{
|
||||
wxLogError(_("GIF: data stream seems to be truncated."));
|
||||
/* go on; image data is OK */
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
ok = decod->ConvertToImage(index != -1 ? (size_t)index : 0, image);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogError(_("GIF: Invalid gif index."));
|
||||
}
|
||||
|
||||
delete decod;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
|
||||
wxOutputStream& WXUNUSED(stream), bool verbose )
|
||||
{
|
||||
if (verbose)
|
||||
wxLogDebug(wxT("GIF: the handler is read-only!!"));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxGIFHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
wxGIFDecoder decod;
|
||||
return decod.CanRead(stream);
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_GIF
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,480 +1,480 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagjpeg.cpp
|
||||
// Purpose: wxImage JPEG handler
|
||||
// Author: Vaclav Slavik
|
||||
// RCS-ID: $Id: imagjpeg.cpp 43781 2006-12-03 21:59:47Z MW $
|
||||
// Copyright: (c) Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE && wxUSE_LIBJPEG
|
||||
|
||||
#include "wx/imagjpeg.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
// A hack based on one from tif_jpeg.c to overcome the problem on Windows
|
||||
// of rpcndr.h defining boolean with a different type to the jpeg headers.
|
||||
//
|
||||
// This hack is only necessary for an external jpeg library, the builtin one
|
||||
// usually used on Windows doesn't use the type boolean, so always works.
|
||||
//
|
||||
#ifdef wxHACK_BOOLEAN
|
||||
#define HAVE_BOOLEAN
|
||||
#define boolean wxHACK_BOOLEAN
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#if defined(__WXMSW__)
|
||||
#define XMD_H
|
||||
#endif
|
||||
#include "jpeglib.h"
|
||||
}
|
||||
|
||||
#ifndef HAVE_WXJPEG_BOOLEAN
|
||||
typedef boolean wxjpeg_boolean;
|
||||
#endif
|
||||
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/wfstream.h"
|
||||
|
||||
// For memcpy
|
||||
#include <string.h>
|
||||
// For JPEG library error handling
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifdef __SALFORDC__
|
||||
#undef FAR
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// the standard definition of METHODDEF(type) from jmorecfg.h is "static type"
|
||||
// which means that we can't declare the method functions as extern "C" - the
|
||||
// compiler (rightfully) complains about the multiple storage classes in
|
||||
// declaration
|
||||
//
|
||||
// so we only add extern "C" when using our own, modified, jmorecfg.h - and use
|
||||
// whatever we have in the system headers if this is what we use hoping that it
|
||||
// should be ok (can't do anything else)
|
||||
#ifdef JPEG_METHOD_LINKAGE
|
||||
#define CPP_METHODDEF(type) extern "C" METHODDEF(type)
|
||||
#else // not using our jmorecfg.h header
|
||||
#define CPP_METHODDEF(type) METHODDEF(type)
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxJPEGHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler)
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
//------------- JPEG Data Source Manager
|
||||
|
||||
#define JPEG_IO_BUFFER_SIZE 2048
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_source_mgr pub; /* public fields */
|
||||
|
||||
JOCTET* buffer; /* start of buffer */
|
||||
wxInputStream *stream;
|
||||
} wx_source_mgr;
|
||||
|
||||
typedef wx_source_mgr * wx_src_ptr;
|
||||
|
||||
CPP_METHODDEF(void) wx_init_source ( j_decompress_ptr WXUNUSED(cinfo) )
|
||||
{
|
||||
}
|
||||
|
||||
CPP_METHODDEF(wxjpeg_boolean) wx_fill_input_buffer ( j_decompress_ptr cinfo )
|
||||
{
|
||||
wx_src_ptr src = (wx_src_ptr) cinfo->src;
|
||||
|
||||
src->pub.next_input_byte = src->buffer;
|
||||
src->pub.bytes_in_buffer = src->stream->Read(src->buffer, JPEG_IO_BUFFER_SIZE).LastRead();
|
||||
|
||||
if (src->pub.bytes_in_buffer == 0) // check for end-of-stream
|
||||
{
|
||||
// Insert a fake EOI marker
|
||||
src->buffer[0] = 0xFF;
|
||||
src->buffer[1] = JPEG_EOI;
|
||||
src->pub.bytes_in_buffer = 2;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CPP_METHODDEF(void) wx_skip_input_data ( j_decompress_ptr cinfo, long num_bytes )
|
||||
{
|
||||
if (num_bytes > 0)
|
||||
{
|
||||
wx_src_ptr src = (wx_src_ptr) cinfo->src;
|
||||
|
||||
while (num_bytes > (long)src->pub.bytes_in_buffer)
|
||||
{
|
||||
num_bytes -= (long) src->pub.bytes_in_buffer;
|
||||
src->pub.fill_input_buffer(cinfo);
|
||||
}
|
||||
src->pub.next_input_byte += (size_t) num_bytes;
|
||||
src->pub.bytes_in_buffer -= (size_t) num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
CPP_METHODDEF(void) wx_term_source ( j_decompress_ptr cinfo )
|
||||
{
|
||||
wx_src_ptr src = (wx_src_ptr) cinfo->src;
|
||||
|
||||
if (src->pub.bytes_in_buffer > 0)
|
||||
src->stream->SeekI(-(long)src->pub.bytes_in_buffer, wxFromCurrent);
|
||||
delete[] src->buffer;
|
||||
}
|
||||
|
||||
|
||||
// JPEG error manager:
|
||||
|
||||
struct wx_error_mgr {
|
||||
struct jpeg_error_mgr pub; /* "public" fields */
|
||||
|
||||
jmp_buf setjmp_buffer; /* for return to caller */
|
||||
};
|
||||
|
||||
typedef struct wx_error_mgr * wx_error_ptr;
|
||||
|
||||
/*
|
||||
* Here's the routine that will replace the standard error_exit method:
|
||||
*/
|
||||
|
||||
CPP_METHODDEF(void) wx_error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
/* cinfo->err really points to a wx_error_mgr struct, so coerce pointer */
|
||||
wx_error_ptr myerr = (wx_error_ptr) cinfo->err;
|
||||
|
||||
/* Always display the message. */
|
||||
/* We could postpone this until after returning, if we chose. */
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
|
||||
/* Return control to the setjmp point */
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This will replace the standard output_message method when the user
|
||||
* wants us to be silent (verbose==false). We must have such method instead of
|
||||
* simply using NULL for cinfo->err->output_message because it's called
|
||||
* unconditionally from within libjpeg when there's "garbage input".
|
||||
*/
|
||||
CPP_METHODDEF(void) wx_ignore_message (j_common_ptr WXUNUSED(cinfo))
|
||||
{
|
||||
}
|
||||
|
||||
void wx_jpeg_io_src( j_decompress_ptr cinfo, wxInputStream& infile )
|
||||
{
|
||||
wx_src_ptr src;
|
||||
|
||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(wx_source_mgr));
|
||||
}
|
||||
src = (wx_src_ptr) cinfo->src;
|
||||
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
src->buffer = new JOCTET[JPEG_IO_BUFFER_SIZE];
|
||||
src->pub.next_input_byte = NULL; /* until buffer loaded */
|
||||
src->stream = &infile;
|
||||
|
||||
src->pub.init_source = wx_init_source;
|
||||
src->pub.fill_input_buffer = wx_fill_input_buffer;
|
||||
src->pub.skip_input_data = wx_skip_input_data;
|
||||
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||
src->pub.term_source = wx_term_source;
|
||||
}
|
||||
|
||||
static inline void wx_cmyk_to_rgb(unsigned char* rgb, const unsigned char* cmyk)
|
||||
{
|
||||
register int k = 255 - cmyk[3];
|
||||
register int k2 = cmyk[3];
|
||||
register int c;
|
||||
|
||||
c = k + k2 * (255 - cmyk[0]) / 255;
|
||||
rgb[0] = (unsigned char)((c > 255) ? 0 : (255 - c));
|
||||
|
||||
c = k + k2 * (255 - cmyk[1]) / 255;
|
||||
rgb[1] = (unsigned char)((c > 255) ? 0 : (255 - c));
|
||||
|
||||
c = k + k2 * (255 - cmyk[2]) / 255;
|
||||
rgb[2] = (unsigned char)((c > 255) ? 0 : (255 - c));
|
||||
}
|
||||
|
||||
// temporarily disable the warning C4611 (interaction between '_setjmp' and
|
||||
// C++ object destruction is non-portable) - I don't see any dtors here
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(disable:4611)
|
||||
#endif /* VC++ */
|
||||
|
||||
bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct wx_error_mgr jerr;
|
||||
unsigned char *ptr;
|
||||
|
||||
image->Destroy();
|
||||
cinfo.err = jpeg_std_error( &jerr.pub );
|
||||
jerr.pub.error_exit = wx_error_exit;
|
||||
|
||||
if (!verbose)
|
||||
cinfo.err->output_message = wx_ignore_message;
|
||||
|
||||
/* Establish the setjmp return context for wx_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer)) {
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
if (verbose)
|
||||
wxLogError(_("JPEG: Couldn't load - file is probably corrupted."));
|
||||
(cinfo.src->term_source)(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
if (image->Ok()) image->Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
jpeg_create_decompress( &cinfo );
|
||||
wx_jpeg_io_src( &cinfo, stream );
|
||||
jpeg_read_header( &cinfo, TRUE );
|
||||
|
||||
int bytesPerPixel;
|
||||
if ((cinfo.out_color_space == JCS_CMYK) || (cinfo.out_color_space == JCS_YCCK))
|
||||
{
|
||||
cinfo.out_color_space = JCS_CMYK;
|
||||
bytesPerPixel = 4;
|
||||
}
|
||||
else // all the rest is treated as RGB
|
||||
{
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
bytesPerPixel = 3;
|
||||
}
|
||||
|
||||
jpeg_start_decompress( &cinfo );
|
||||
|
||||
image->Create( cinfo.image_width, cinfo.image_height );
|
||||
if (!image->Ok()) {
|
||||
jpeg_finish_decompress( &cinfo );
|
||||
jpeg_destroy_decompress( &cinfo );
|
||||
return false;
|
||||
}
|
||||
image->SetMask( false );
|
||||
ptr = image->GetData();
|
||||
|
||||
unsigned stride = cinfo.output_width * bytesPerPixel;
|
||||
JSAMPARRAY tempbuf = (*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 );
|
||||
|
||||
while ( cinfo.output_scanline < cinfo.output_height )
|
||||
{
|
||||
jpeg_read_scanlines( &cinfo, tempbuf, 1 );
|
||||
if (cinfo.out_color_space == JCS_RGB)
|
||||
{
|
||||
memcpy( ptr, tempbuf[0], stride );
|
||||
ptr += stride;
|
||||
}
|
||||
else // CMYK
|
||||
{
|
||||
const unsigned char* inptr = (const unsigned char*) tempbuf[0];
|
||||
for (size_t i = 0; i < cinfo.output_width; i++)
|
||||
{
|
||||
wx_cmyk_to_rgb(ptr, inptr);
|
||||
ptr += 3;
|
||||
inptr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_finish_decompress( &cinfo );
|
||||
jpeg_destroy_decompress( &cinfo );
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_destination_mgr pub;
|
||||
|
||||
wxOutputStream *stream;
|
||||
JOCTET * buffer;
|
||||
} wx_destination_mgr;
|
||||
|
||||
typedef wx_destination_mgr * wx_dest_ptr;
|
||||
|
||||
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
|
||||
|
||||
CPP_METHODDEF(void) wx_init_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
wx_dest_ptr dest = (wx_dest_ptr) cinfo->dest;
|
||||
|
||||
/* Allocate the output buffer --- it will be released when done with image */
|
||||
dest->buffer = (JOCTET *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
OUTPUT_BUF_SIZE * sizeof(JOCTET));
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
CPP_METHODDEF(wxjpeg_boolean) wx_empty_output_buffer (j_compress_ptr cinfo)
|
||||
{
|
||||
wx_dest_ptr dest = (wx_dest_ptr) cinfo->dest;
|
||||
|
||||
dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE);
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CPP_METHODDEF(void) wx_term_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
wx_dest_ptr dest = (wx_dest_ptr) cinfo->dest;
|
||||
size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
|
||||
/* Write any data remaining in the buffer */
|
||||
if (datacount > 0)
|
||||
dest->stream->Write(dest->buffer, datacount);
|
||||
}
|
||||
|
||||
GLOBAL(void) wx_jpeg_io_dest (j_compress_ptr cinfo, wxOutputStream& outfile)
|
||||
{
|
||||
wx_dest_ptr dest;
|
||||
|
||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(wx_destination_mgr));
|
||||
}
|
||||
|
||||
dest = (wx_dest_ptr) cinfo->dest;
|
||||
dest->pub.init_destination = wx_init_destination;
|
||||
dest->pub.empty_output_buffer = wx_empty_output_buffer;
|
||||
dest->pub.term_destination = wx_term_destination;
|
||||
dest->stream = &outfile;
|
||||
}
|
||||
|
||||
bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct wx_error_mgr jerr;
|
||||
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
|
||||
JSAMPLE *image_buffer;
|
||||
int stride; /* physical row width in image buffer */
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = wx_error_exit;
|
||||
|
||||
if (!verbose)
|
||||
cinfo.err->output_message = wx_ignore_message;
|
||||
|
||||
/* Establish the setjmp return context for wx_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
if (verbose)
|
||||
wxLogError(_("JPEG: Couldn't save image."));
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
jpeg_create_compress(&cinfo);
|
||||
wx_jpeg_io_dest(&cinfo, stream);
|
||||
|
||||
cinfo.image_width = image->GetWidth();
|
||||
cinfo.image_height = image->GetHeight();
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
|
||||
// TODO: 3rd parameter is force_baseline, what value should this be?
|
||||
// Code says: "If force_baseline is TRUE, the computed quantization table entries
|
||||
// are limited to 1..255 for JPEG baseline compatibility."
|
||||
// 'Quality' is a number between 0 (terrible) and 100 (very good).
|
||||
// The default (in jcparam.c, jpeg_set_defaults) is 75,
|
||||
// and force_baseline is TRUE.
|
||||
if (image->HasOption(wxIMAGE_OPTION_QUALITY))
|
||||
jpeg_set_quality(&cinfo, image->GetOptionInt(wxIMAGE_OPTION_QUALITY), TRUE);
|
||||
|
||||
// set the resolution fields in the output file
|
||||
UINT16 resX,
|
||||
resY;
|
||||
if ( image->HasOption(wxIMAGE_OPTION_RESOLUTIONX) &&
|
||||
image->HasOption(wxIMAGE_OPTION_RESOLUTIONY) )
|
||||
{
|
||||
resX = (UINT16)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX);
|
||||
resY = (UINT16)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY);
|
||||
}
|
||||
else if ( image->HasOption(wxIMAGE_OPTION_RESOLUTION) )
|
||||
{
|
||||
resX =
|
||||
resY = (UINT16)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTION);
|
||||
}
|
||||
else
|
||||
{
|
||||
resX =
|
||||
resY = 0;
|
||||
}
|
||||
|
||||
if ( resX && resY )
|
||||
{
|
||||
cinfo.X_density = resX;
|
||||
cinfo.Y_density = resY;
|
||||
}
|
||||
|
||||
// sets the resolution unit field in the output file
|
||||
// wxIMAGE_RESOLUTION_INCHES for inches
|
||||
// wxIMAGE_RESOLUTION_CM for centimeters
|
||||
if ( image->HasOption(wxIMAGE_OPTION_RESOLUTIONUNIT) )
|
||||
{
|
||||
cinfo.density_unit = (UINT8)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONUNIT);
|
||||
}
|
||||
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
|
||||
stride = cinfo.image_width * 3; /* JSAMPLEs per row in image_buffer */
|
||||
image_buffer = image->GetData();
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
row_pointer[0] = &image_buffer[cinfo.next_scanline * stride];
|
||||
jpeg_write_scanlines( &cinfo, row_pointer, 1 );
|
||||
}
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(default:4611)
|
||||
#endif /* VC++ */
|
||||
|
||||
bool wxJPEGHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
unsigned char hdr[2];
|
||||
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return false;
|
||||
|
||||
return hdr[0] == 0xFF && hdr[1] == 0xD8;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_LIBJPEG
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagjpeg.cpp
|
||||
// Purpose: wxImage JPEG handler
|
||||
// Author: Vaclav Slavik
|
||||
// RCS-ID: $Id: imagjpeg.cpp 43781 2006-12-03 21:59:47Z MW $
|
||||
// Copyright: (c) Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_IMAGE && wxUSE_LIBJPEG
|
||||
|
||||
#include "wx/imagjpeg.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#include "wx/app.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/bitmap.h"
|
||||
#include "wx/module.h"
|
||||
#endif
|
||||
|
||||
// A hack based on one from tif_jpeg.c to overcome the problem on Windows
|
||||
// of rpcndr.h defining boolean with a different type to the jpeg headers.
|
||||
//
|
||||
// This hack is only necessary for an external jpeg library, the builtin one
|
||||
// usually used on Windows doesn't use the type boolean, so always works.
|
||||
//
|
||||
#ifdef wxHACK_BOOLEAN
|
||||
#define HAVE_BOOLEAN
|
||||
#define boolean wxHACK_BOOLEAN
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#if defined(__WXMSW__)
|
||||
#define XMD_H
|
||||
#endif
|
||||
#include "jpeglib.h"
|
||||
}
|
||||
|
||||
#ifndef HAVE_WXJPEG_BOOLEAN
|
||||
typedef boolean wxjpeg_boolean;
|
||||
#endif
|
||||
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/wfstream.h"
|
||||
|
||||
// For memcpy
|
||||
#include <string.h>
|
||||
// For JPEG library error handling
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifdef __SALFORDC__
|
||||
#undef FAR
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// the standard definition of METHODDEF(type) from jmorecfg.h is "static type"
|
||||
// which means that we can't declare the method functions as extern "C" - the
|
||||
// compiler (rightfully) complains about the multiple storage classes in
|
||||
// declaration
|
||||
//
|
||||
// so we only add extern "C" when using our own, modified, jmorecfg.h - and use
|
||||
// whatever we have in the system headers if this is what we use hoping that it
|
||||
// should be ok (can't do anything else)
|
||||
#ifdef JPEG_METHOD_LINKAGE
|
||||
#define CPP_METHODDEF(type) extern "C" METHODDEF(type)
|
||||
#else // not using our jmorecfg.h header
|
||||
#define CPP_METHODDEF(type) METHODDEF(type)
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxJPEGHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxJPEGHandler,wxImageHandler)
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
//------------- JPEG Data Source Manager
|
||||
|
||||
#define JPEG_IO_BUFFER_SIZE 2048
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_source_mgr pub; /* public fields */
|
||||
|
||||
JOCTET* buffer; /* start of buffer */
|
||||
wxInputStream *stream;
|
||||
} wx_source_mgr;
|
||||
|
||||
typedef wx_source_mgr * wx_src_ptr;
|
||||
|
||||
CPP_METHODDEF(void) wx_init_source ( j_decompress_ptr WXUNUSED(cinfo) )
|
||||
{
|
||||
}
|
||||
|
||||
CPP_METHODDEF(wxjpeg_boolean) wx_fill_input_buffer ( j_decompress_ptr cinfo )
|
||||
{
|
||||
wx_src_ptr src = (wx_src_ptr) cinfo->src;
|
||||
|
||||
src->pub.next_input_byte = src->buffer;
|
||||
src->pub.bytes_in_buffer = src->stream->Read(src->buffer, JPEG_IO_BUFFER_SIZE).LastRead();
|
||||
|
||||
if (src->pub.bytes_in_buffer == 0) // check for end-of-stream
|
||||
{
|
||||
// Insert a fake EOI marker
|
||||
src->buffer[0] = 0xFF;
|
||||
src->buffer[1] = JPEG_EOI;
|
||||
src->pub.bytes_in_buffer = 2;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CPP_METHODDEF(void) wx_skip_input_data ( j_decompress_ptr cinfo, long num_bytes )
|
||||
{
|
||||
if (num_bytes > 0)
|
||||
{
|
||||
wx_src_ptr src = (wx_src_ptr) cinfo->src;
|
||||
|
||||
while (num_bytes > (long)src->pub.bytes_in_buffer)
|
||||
{
|
||||
num_bytes -= (long) src->pub.bytes_in_buffer;
|
||||
src->pub.fill_input_buffer(cinfo);
|
||||
}
|
||||
src->pub.next_input_byte += (size_t) num_bytes;
|
||||
src->pub.bytes_in_buffer -= (size_t) num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
CPP_METHODDEF(void) wx_term_source ( j_decompress_ptr cinfo )
|
||||
{
|
||||
wx_src_ptr src = (wx_src_ptr) cinfo->src;
|
||||
|
||||
if (src->pub.bytes_in_buffer > 0)
|
||||
src->stream->SeekI(-(long)src->pub.bytes_in_buffer, wxFromCurrent);
|
||||
delete[] src->buffer;
|
||||
}
|
||||
|
||||
|
||||
// JPEG error manager:
|
||||
|
||||
struct wx_error_mgr {
|
||||
struct jpeg_error_mgr pub; /* "public" fields */
|
||||
|
||||
jmp_buf setjmp_buffer; /* for return to caller */
|
||||
};
|
||||
|
||||
typedef struct wx_error_mgr * wx_error_ptr;
|
||||
|
||||
/*
|
||||
* Here's the routine that will replace the standard error_exit method:
|
||||
*/
|
||||
|
||||
CPP_METHODDEF(void) wx_error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
/* cinfo->err really points to a wx_error_mgr struct, so coerce pointer */
|
||||
wx_error_ptr myerr = (wx_error_ptr) cinfo->err;
|
||||
|
||||
/* Always display the message. */
|
||||
/* We could postpone this until after returning, if we chose. */
|
||||
(*cinfo->err->output_message) (cinfo);
|
||||
|
||||
/* Return control to the setjmp point */
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This will replace the standard output_message method when the user
|
||||
* wants us to be silent (verbose==false). We must have such method instead of
|
||||
* simply using NULL for cinfo->err->output_message because it's called
|
||||
* unconditionally from within libjpeg when there's "garbage input".
|
||||
*/
|
||||
CPP_METHODDEF(void) wx_ignore_message (j_common_ptr WXUNUSED(cinfo))
|
||||
{
|
||||
}
|
||||
|
||||
void wx_jpeg_io_src( j_decompress_ptr cinfo, wxInputStream& infile )
|
||||
{
|
||||
wx_src_ptr src;
|
||||
|
||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(wx_source_mgr));
|
||||
}
|
||||
src = (wx_src_ptr) cinfo->src;
|
||||
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
src->buffer = new JOCTET[JPEG_IO_BUFFER_SIZE];
|
||||
src->pub.next_input_byte = NULL; /* until buffer loaded */
|
||||
src->stream = &infile;
|
||||
|
||||
src->pub.init_source = wx_init_source;
|
||||
src->pub.fill_input_buffer = wx_fill_input_buffer;
|
||||
src->pub.skip_input_data = wx_skip_input_data;
|
||||
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||
src->pub.term_source = wx_term_source;
|
||||
}
|
||||
|
||||
static inline void wx_cmyk_to_rgb(unsigned char* rgb, const unsigned char* cmyk)
|
||||
{
|
||||
register int k = 255 - cmyk[3];
|
||||
register int k2 = cmyk[3];
|
||||
register int c;
|
||||
|
||||
c = k + k2 * (255 - cmyk[0]) / 255;
|
||||
rgb[0] = (unsigned char)((c > 255) ? 0 : (255 - c));
|
||||
|
||||
c = k + k2 * (255 - cmyk[1]) / 255;
|
||||
rgb[1] = (unsigned char)((c > 255) ? 0 : (255 - c));
|
||||
|
||||
c = k + k2 * (255 - cmyk[2]) / 255;
|
||||
rgb[2] = (unsigned char)((c > 255) ? 0 : (255 - c));
|
||||
}
|
||||
|
||||
// temporarily disable the warning C4611 (interaction between '_setjmp' and
|
||||
// C++ object destruction is non-portable) - I don't see any dtors here
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(disable:4611)
|
||||
#endif /* VC++ */
|
||||
|
||||
bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct wx_error_mgr jerr;
|
||||
unsigned char *ptr;
|
||||
|
||||
image->Destroy();
|
||||
cinfo.err = jpeg_std_error( &jerr.pub );
|
||||
jerr.pub.error_exit = wx_error_exit;
|
||||
|
||||
if (!verbose)
|
||||
cinfo.err->output_message = wx_ignore_message;
|
||||
|
||||
/* Establish the setjmp return context for wx_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer)) {
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
if (verbose)
|
||||
wxLogError(_("JPEG: Couldn't load - file is probably corrupted."));
|
||||
(cinfo.src->term_source)(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
if (image->Ok()) image->Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
jpeg_create_decompress( &cinfo );
|
||||
wx_jpeg_io_src( &cinfo, stream );
|
||||
jpeg_read_header( &cinfo, TRUE );
|
||||
|
||||
int bytesPerPixel;
|
||||
if ((cinfo.out_color_space == JCS_CMYK) || (cinfo.out_color_space == JCS_YCCK))
|
||||
{
|
||||
cinfo.out_color_space = JCS_CMYK;
|
||||
bytesPerPixel = 4;
|
||||
}
|
||||
else // all the rest is treated as RGB
|
||||
{
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
bytesPerPixel = 3;
|
||||
}
|
||||
|
||||
jpeg_start_decompress( &cinfo );
|
||||
|
||||
image->Create( cinfo.image_width, cinfo.image_height );
|
||||
if (!image->Ok()) {
|
||||
jpeg_finish_decompress( &cinfo );
|
||||
jpeg_destroy_decompress( &cinfo );
|
||||
return false;
|
||||
}
|
||||
image->SetMask( false );
|
||||
ptr = image->GetData();
|
||||
|
||||
unsigned stride = cinfo.output_width * bytesPerPixel;
|
||||
JSAMPARRAY tempbuf = (*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr) &cinfo, JPOOL_IMAGE, stride, 1 );
|
||||
|
||||
while ( cinfo.output_scanline < cinfo.output_height )
|
||||
{
|
||||
jpeg_read_scanlines( &cinfo, tempbuf, 1 );
|
||||
if (cinfo.out_color_space == JCS_RGB)
|
||||
{
|
||||
memcpy( ptr, tempbuf[0], stride );
|
||||
ptr += stride;
|
||||
}
|
||||
else // CMYK
|
||||
{
|
||||
const unsigned char* inptr = (const unsigned char*) tempbuf[0];
|
||||
for (size_t i = 0; i < cinfo.output_width; i++)
|
||||
{
|
||||
wx_cmyk_to_rgb(ptr, inptr);
|
||||
ptr += 3;
|
||||
inptr += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_finish_decompress( &cinfo );
|
||||
jpeg_destroy_decompress( &cinfo );
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_destination_mgr pub;
|
||||
|
||||
wxOutputStream *stream;
|
||||
JOCTET * buffer;
|
||||
} wx_destination_mgr;
|
||||
|
||||
typedef wx_destination_mgr * wx_dest_ptr;
|
||||
|
||||
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
|
||||
|
||||
CPP_METHODDEF(void) wx_init_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
wx_dest_ptr dest = (wx_dest_ptr) cinfo->dest;
|
||||
|
||||
/* Allocate the output buffer --- it will be released when done with image */
|
||||
dest->buffer = (JOCTET *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
OUTPUT_BUF_SIZE * sizeof(JOCTET));
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
CPP_METHODDEF(wxjpeg_boolean) wx_empty_output_buffer (j_compress_ptr cinfo)
|
||||
{
|
||||
wx_dest_ptr dest = (wx_dest_ptr) cinfo->dest;
|
||||
|
||||
dest->stream->Write(dest->buffer, OUTPUT_BUF_SIZE);
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CPP_METHODDEF(void) wx_term_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
wx_dest_ptr dest = (wx_dest_ptr) cinfo->dest;
|
||||
size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
|
||||
/* Write any data remaining in the buffer */
|
||||
if (datacount > 0)
|
||||
dest->stream->Write(dest->buffer, datacount);
|
||||
}
|
||||
|
||||
GLOBAL(void) wx_jpeg_io_dest (j_compress_ptr cinfo, wxOutputStream& outfile)
|
||||
{
|
||||
wx_dest_ptr dest;
|
||||
|
||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(wx_destination_mgr));
|
||||
}
|
||||
|
||||
dest = (wx_dest_ptr) cinfo->dest;
|
||||
dest->pub.init_destination = wx_init_destination;
|
||||
dest->pub.empty_output_buffer = wx_empty_output_buffer;
|
||||
dest->pub.term_destination = wx_term_destination;
|
||||
dest->stream = &outfile;
|
||||
}
|
||||
|
||||
bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct wx_error_mgr jerr;
|
||||
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
|
||||
JSAMPLE *image_buffer;
|
||||
int stride; /* physical row width in image buffer */
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = wx_error_exit;
|
||||
|
||||
if (!verbose)
|
||||
cinfo.err->output_message = wx_ignore_message;
|
||||
|
||||
/* Establish the setjmp return context for wx_error_exit to use. */
|
||||
if (setjmp(jerr.setjmp_buffer))
|
||||
{
|
||||
/* If we get here, the JPEG code has signaled an error.
|
||||
* We need to clean up the JPEG object, close the input file, and return.
|
||||
*/
|
||||
if (verbose)
|
||||
wxLogError(_("JPEG: Couldn't save image."));
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
jpeg_create_compress(&cinfo);
|
||||
wx_jpeg_io_dest(&cinfo, stream);
|
||||
|
||||
cinfo.image_width = image->GetWidth();
|
||||
cinfo.image_height = image->GetHeight();
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
|
||||
// TODO: 3rd parameter is force_baseline, what value should this be?
|
||||
// Code says: "If force_baseline is TRUE, the computed quantization table entries
|
||||
// are limited to 1..255 for JPEG baseline compatibility."
|
||||
// 'Quality' is a number between 0 (terrible) and 100 (very good).
|
||||
// The default (in jcparam.c, jpeg_set_defaults) is 75,
|
||||
// and force_baseline is TRUE.
|
||||
if (image->HasOption(wxIMAGE_OPTION_QUALITY))
|
||||
jpeg_set_quality(&cinfo, image->GetOptionInt(wxIMAGE_OPTION_QUALITY), TRUE);
|
||||
|
||||
// set the resolution fields in the output file
|
||||
UINT16 resX,
|
||||
resY;
|
||||
if ( image->HasOption(wxIMAGE_OPTION_RESOLUTIONX) &&
|
||||
image->HasOption(wxIMAGE_OPTION_RESOLUTIONY) )
|
||||
{
|
||||
resX = (UINT16)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX);
|
||||
resY = (UINT16)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY);
|
||||
}
|
||||
else if ( image->HasOption(wxIMAGE_OPTION_RESOLUTION) )
|
||||
{
|
||||
resX =
|
||||
resY = (UINT16)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTION);
|
||||
}
|
||||
else
|
||||
{
|
||||
resX =
|
||||
resY = 0;
|
||||
}
|
||||
|
||||
if ( resX && resY )
|
||||
{
|
||||
cinfo.X_density = resX;
|
||||
cinfo.Y_density = resY;
|
||||
}
|
||||
|
||||
// sets the resolution unit field in the output file
|
||||
// wxIMAGE_RESOLUTION_INCHES for inches
|
||||
// wxIMAGE_RESOLUTION_CM for centimeters
|
||||
if ( image->HasOption(wxIMAGE_OPTION_RESOLUTIONUNIT) )
|
||||
{
|
||||
cinfo.density_unit = (UINT8)image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONUNIT);
|
||||
}
|
||||
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
|
||||
stride = cinfo.image_width * 3; /* JSAMPLEs per row in image_buffer */
|
||||
image_buffer = image->GetData();
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
row_pointer[0] = &image_buffer[cinfo.next_scanline * stride];
|
||||
jpeg_write_scanlines( &cinfo, row_pointer, 1 );
|
||||
}
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(default:4611)
|
||||
#endif /* VC++ */
|
||||
|
||||
bool wxJPEGHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
unsigned char hdr[2];
|
||||
|
||||
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
|
||||
return false;
|
||||
|
||||
return hdr[0] == 0xFF && hdr[1] == 0xD8;
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_LIBJPEG
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,201 +1,201 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagpnm.cpp
|
||||
// Purpose: wxImage PNM handler
|
||||
// Author: Sylvain Bougnoux
|
||||
// RCS-ID: $Id: imagpnm.cpp 46311 2007-06-03 22:14:32Z 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 && wxUSE_PNM
|
||||
|
||||
#include "wx/imagpnm.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/txtstrm.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxBMPHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPNMHandler,wxImageHandler)
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
void Skip_Comment(wxInputStream &stream)
|
||||
{
|
||||
wxTextInputStream text_stream(stream);
|
||||
|
||||
if (stream.Peek()==wxT('#'))
|
||||
{
|
||||
text_stream.ReadLine();
|
||||
Skip_Comment(stream);
|
||||
}
|
||||
}
|
||||
|
||||
bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
|
||||
{
|
||||
wxUint32 width, height;
|
||||
wxUint16 maxval;
|
||||
char c(0);
|
||||
|
||||
image->Destroy();
|
||||
|
||||
/*
|
||||
* Read the PNM header
|
||||
*/
|
||||
|
||||
wxBufferedInputStream buf_stream(stream);
|
||||
wxTextInputStream text_stream(buf_stream);
|
||||
|
||||
Skip_Comment(buf_stream);
|
||||
if (buf_stream.GetC()==wxT('P')) c=buf_stream.GetC();
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case wxT('2'): // ASCII Grey
|
||||
case wxT('3'): // ASCII RGB
|
||||
case wxT('5'): // RAW Grey
|
||||
case wxT('6'): break;
|
||||
default:
|
||||
if (verbose) wxLogError(_("PNM: File format is not recognized."));
|
||||
return false;
|
||||
}
|
||||
|
||||
text_stream.ReadLine(); // for the \n
|
||||
Skip_Comment(buf_stream);
|
||||
text_stream >> width >> height ;
|
||||
Skip_Comment(buf_stream);
|
||||
text_stream >> maxval;
|
||||
|
||||
//cout << line << " " << width << " " << height << " " << maxval << endl;
|
||||
image->Create( width, height );
|
||||
unsigned char *ptr = image->GetData();
|
||||
if (!ptr)
|
||||
{
|
||||
if (verbose)
|
||||
wxLogError( _("PNM: Couldn't allocate memory.") );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (c=='2') // Ascii GREY
|
||||
{
|
||||
wxUint32 value, size=width*height;
|
||||
for (wxUint32 i=0; i<size; ++i)
|
||||
{
|
||||
value=text_stream.Read32();
|
||||
if ( maxval != 255 )
|
||||
value = (255 * value)/maxval;
|
||||
*ptr++=(unsigned char)value; // R
|
||||
*ptr++=(unsigned char)value; // G
|
||||
*ptr++=(unsigned char)value; // B
|
||||
if ( !buf_stream )
|
||||
{
|
||||
if (verbose) wxLogError(_("PNM: File seems truncated."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c=='3') // Ascii RBG
|
||||
{
|
||||
wxUint32 value, size=3*width*height;
|
||||
for (wxUint32 i=0; i<size; ++i)
|
||||
{
|
||||
//this is very slow !!!
|
||||
//I wonder how we can make any better ?
|
||||
value=text_stream.Read32();
|
||||
if ( maxval != 255 )
|
||||
value = (255 * value)/maxval;
|
||||
*ptr++=(unsigned char)value;
|
||||
|
||||
if ( !buf_stream )
|
||||
{
|
||||
if (verbose) wxLogError(_("PNM: File seems truncated."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c=='5') // Raw GREY
|
||||
{
|
||||
wxUint32 size=width*height;
|
||||
unsigned char value;
|
||||
for (wxUint32 i=0; i<size; ++i)
|
||||
{
|
||||
buf_stream.Read(&value,1);
|
||||
if ( maxval != 255 )
|
||||
value = (255 * value)/maxval;
|
||||
*ptr++=value; // R
|
||||
*ptr++=value; // G
|
||||
*ptr++=value; // B
|
||||
if ( !buf_stream )
|
||||
{
|
||||
if (verbose) wxLogError(_("PNM: File seems truncated."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( c=='6' ) // Raw RGB
|
||||
{
|
||||
buf_stream.Read(ptr, 3*width*height);
|
||||
if ( maxval != 255 )
|
||||
{
|
||||
for ( unsigned i = 0; i < 3*width*height; i++ )
|
||||
ptr[i] = (255 * ptr[i])/maxval;
|
||||
}
|
||||
}
|
||||
|
||||
image->SetMask( false );
|
||||
|
||||
const wxStreamError err = buf_stream.GetLastError();
|
||||
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
|
||||
}
|
||||
|
||||
bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
|
||||
{
|
||||
wxTextOutputStream text_stream(stream);
|
||||
|
||||
//text_stream << "P6" << endl
|
||||
//<< image->GetWidth() << " " << image->GetHeight() << endl
|
||||
//<< "255" << endl;
|
||||
text_stream << wxT("P6\n") << image->GetWidth() << wxT(" ") << image->GetHeight() << wxT("\n255\n");
|
||||
stream.Write(image->GetData(),3*image->GetWidth()*image->GetHeight());
|
||||
|
||||
return stream.IsOk();
|
||||
}
|
||||
|
||||
bool wxPNMHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
Skip_Comment(stream);
|
||||
|
||||
if ( stream.GetC() == 'P' )
|
||||
{
|
||||
switch ( stream.GetC() )
|
||||
{
|
||||
case '2': // ASCII Grey
|
||||
case '3': // ASCII RGB
|
||||
case '5': // RAW Grey
|
||||
case '6': // RAW RGB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_IMAGE && wxUSE_PNM
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/imagpnm.cpp
|
||||
// Purpose: wxImage PNM handler
|
||||
// Author: Sylvain Bougnoux
|
||||
// RCS-ID: $Id: imagpnm.cpp 46311 2007-06-03 22:14:32Z 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 && wxUSE_PNM
|
||||
|
||||
#include "wx/imagpnm.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/txtstrm.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxBMPHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPNMHandler,wxImageHandler)
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
void Skip_Comment(wxInputStream &stream)
|
||||
{
|
||||
wxTextInputStream text_stream(stream);
|
||||
|
||||
if (stream.Peek()==wxT('#'))
|
||||
{
|
||||
text_stream.ReadLine();
|
||||
Skip_Comment(stream);
|
||||
}
|
||||
}
|
||||
|
||||
bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index) )
|
||||
{
|
||||
wxUint32 width, height;
|
||||
wxUint16 maxval;
|
||||
char c(0);
|
||||
|
||||
image->Destroy();
|
||||
|
||||
/*
|
||||
* Read the PNM header
|
||||
*/
|
||||
|
||||
wxBufferedInputStream buf_stream(stream);
|
||||
wxTextInputStream text_stream(buf_stream);
|
||||
|
||||
Skip_Comment(buf_stream);
|
||||
if (buf_stream.GetC()==wxT('P')) c=buf_stream.GetC();
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case wxT('2'): // ASCII Grey
|
||||
case wxT('3'): // ASCII RGB
|
||||
case wxT('5'): // RAW Grey
|
||||
case wxT('6'): break;
|
||||
default:
|
||||
if (verbose) wxLogError(_("PNM: File format is not recognized."));
|
||||
return false;
|
||||
}
|
||||
|
||||
text_stream.ReadLine(); // for the \n
|
||||
Skip_Comment(buf_stream);
|
||||
text_stream >> width >> height ;
|
||||
Skip_Comment(buf_stream);
|
||||
text_stream >> maxval;
|
||||
|
||||
//cout << line << " " << width << " " << height << " " << maxval << endl;
|
||||
image->Create( width, height );
|
||||
unsigned char *ptr = image->GetData();
|
||||
if (!ptr)
|
||||
{
|
||||
if (verbose)
|
||||
wxLogError( _("PNM: Couldn't allocate memory.") );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (c=='2') // Ascii GREY
|
||||
{
|
||||
wxUint32 value, size=width*height;
|
||||
for (wxUint32 i=0; i<size; ++i)
|
||||
{
|
||||
value=text_stream.Read32();
|
||||
if ( maxval != 255 )
|
||||
value = (255 * value)/maxval;
|
||||
*ptr++=(unsigned char)value; // R
|
||||
*ptr++=(unsigned char)value; // G
|
||||
*ptr++=(unsigned char)value; // B
|
||||
if ( !buf_stream )
|
||||
{
|
||||
if (verbose) wxLogError(_("PNM: File seems truncated."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c=='3') // Ascii RBG
|
||||
{
|
||||
wxUint32 value, size=3*width*height;
|
||||
for (wxUint32 i=0; i<size; ++i)
|
||||
{
|
||||
//this is very slow !!!
|
||||
//I wonder how we can make any better ?
|
||||
value=text_stream.Read32();
|
||||
if ( maxval != 255 )
|
||||
value = (255 * value)/maxval;
|
||||
*ptr++=(unsigned char)value;
|
||||
|
||||
if ( !buf_stream )
|
||||
{
|
||||
if (verbose) wxLogError(_("PNM: File seems truncated."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c=='5') // Raw GREY
|
||||
{
|
||||
wxUint32 size=width*height;
|
||||
unsigned char value;
|
||||
for (wxUint32 i=0; i<size; ++i)
|
||||
{
|
||||
buf_stream.Read(&value,1);
|
||||
if ( maxval != 255 )
|
||||
value = (255 * value)/maxval;
|
||||
*ptr++=value; // R
|
||||
*ptr++=value; // G
|
||||
*ptr++=value; // B
|
||||
if ( !buf_stream )
|
||||
{
|
||||
if (verbose) wxLogError(_("PNM: File seems truncated."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( c=='6' ) // Raw RGB
|
||||
{
|
||||
buf_stream.Read(ptr, 3*width*height);
|
||||
if ( maxval != 255 )
|
||||
{
|
||||
for ( unsigned i = 0; i < 3*width*height; i++ )
|
||||
ptr[i] = (255 * ptr[i])/maxval;
|
||||
}
|
||||
}
|
||||
|
||||
image->SetMask( false );
|
||||
|
||||
const wxStreamError err = buf_stream.GetLastError();
|
||||
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
|
||||
}
|
||||
|
||||
bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) )
|
||||
{
|
||||
wxTextOutputStream text_stream(stream);
|
||||
|
||||
//text_stream << "P6" << endl
|
||||
//<< image->GetWidth() << " " << image->GetHeight() << endl
|
||||
//<< "255" << endl;
|
||||
text_stream << wxT("P6\n") << image->GetWidth() << wxT(" ") << image->GetHeight() << wxT("\n255\n");
|
||||
stream.Write(image->GetData(),3*image->GetWidth()*image->GetHeight());
|
||||
|
||||
return stream.IsOk();
|
||||
}
|
||||
|
||||
bool wxPNMHandler::DoCanRead( wxInputStream& stream )
|
||||
{
|
||||
Skip_Comment(stream);
|
||||
|
||||
if ( stream.GetC() == 'P' )
|
||||
{
|
||||
switch ( stream.GetC() )
|
||||
{
|
||||
case '2': // ASCII Grey
|
||||
case '3': // ASCII RGB
|
||||
case '5': // RAW Grey
|
||||
case '6': // RAW RGB
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // wxUSE_IMAGE && wxUSE_PNM
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue