Add wx headers and ext
This commit is contained in:
parent
6390dcef6a
commit
66d3c7b811
1531 changed files with 295895 additions and 0 deletions
156
wxheaders/wx/private/addremovectrl.h
Normal file
156
wxheaders/wx/private/addremovectrl.h
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/addremovectrl.h
|
||||
// Purpose: wxAddRemoveImpl helper class declaration
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2015-02-04
|
||||
// Copyright: (c) 2015 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_ADDREMOVECTRL_H_
|
||||
#define _WX_PRIVATE_ADDREMOVECTRL_H_
|
||||
|
||||
#include "wx/button.h"
|
||||
#include "wx/sizer.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxAddRemoveImplBase: implementation-only part of wxAddRemoveCtrl, base part
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxAddRemoveImplBase
|
||||
{
|
||||
public:
|
||||
// Base class ctor just initializes the associated adaptor, the derived
|
||||
// class is supposed to create the buttons and layout everything.
|
||||
//
|
||||
// Takes ownership of the adaptor pointer.
|
||||
explicit wxAddRemoveImplBase(wxAddRemoveAdaptor* adaptor,
|
||||
wxAddRemoveCtrl* WXUNUSED(parent),
|
||||
wxWindow* ctrlItems)
|
||||
: m_adaptor(adaptor)
|
||||
{
|
||||
ctrlItems->Bind(wxEVT_CHAR, &wxAddRemoveImplBase::OnChar, this);
|
||||
}
|
||||
|
||||
// wxOSX implementation needs to override this as it doesn't use sizers,
|
||||
// for the others it is not necessary.
|
||||
virtual wxSize GetBestClientSize() const { return wxDefaultSize; }
|
||||
|
||||
virtual void SetButtonsToolTips(const wxString& addtip,
|
||||
const wxString& removetip) = 0;
|
||||
|
||||
virtual ~wxAddRemoveImplBase()
|
||||
{
|
||||
delete m_adaptor;
|
||||
}
|
||||
|
||||
// Event handlers which must be connected to the appropriate sources by the
|
||||
// derived classes.
|
||||
|
||||
void OnUpdateUIAdd(wxUpdateUIEvent& event)
|
||||
{
|
||||
event.Enable( m_adaptor->CanAdd() );
|
||||
}
|
||||
|
||||
void OnUpdateUIRemove(wxUpdateUIEvent& event)
|
||||
{
|
||||
event.Enable( m_adaptor->CanRemove() );
|
||||
}
|
||||
|
||||
void OnAdd(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_adaptor->OnAdd();
|
||||
}
|
||||
|
||||
void OnRemove(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_adaptor->OnRemove();
|
||||
}
|
||||
|
||||
private:
|
||||
// This event handler is connected by this class itself and doesn't need to
|
||||
// be accessible to the derived classes.
|
||||
|
||||
void OnChar(wxKeyEvent& event)
|
||||
{
|
||||
switch ( event.GetKeyCode() )
|
||||
{
|
||||
case '+':
|
||||
case WXK_INSERT:
|
||||
case WXK_NUMPAD_INSERT:
|
||||
if ( m_adaptor->CanAdd() )
|
||||
m_adaptor->OnAdd();
|
||||
return;
|
||||
|
||||
case '-':
|
||||
case WXK_DELETE:
|
||||
case WXK_NUMPAD_DELETE:
|
||||
if ( m_adaptor->CanRemove() )
|
||||
m_adaptor->OnRemove();
|
||||
return;
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
wxAddRemoveAdaptor* const m_adaptor;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxAddRemoveImplBase);
|
||||
};
|
||||
|
||||
// GTK+ uses a wxToolBar-based implementation and so doesn't need this class.
|
||||
#ifndef __WXGTK__
|
||||
|
||||
// Base class for the ports using actual wxButtons for the "+"/"-" buttons.
|
||||
class wxAddRemoveImplWithButtons : public wxAddRemoveImplBase
|
||||
{
|
||||
public:
|
||||
explicit wxAddRemoveImplWithButtons(wxAddRemoveAdaptor* adaptor,
|
||||
wxAddRemoveCtrl* parent,
|
||||
wxWindow* ctrlItems)
|
||||
: wxAddRemoveImplBase(adaptor, parent, ctrlItems)
|
||||
{
|
||||
m_btnAdd =
|
||||
m_btnRemove = NULL;
|
||||
}
|
||||
|
||||
virtual void SetButtonsToolTips(const wxString& addtip,
|
||||
const wxString& removetip) wxOVERRIDE
|
||||
{
|
||||
m_btnAdd->SetToolTip(addtip);
|
||||
m_btnRemove->SetToolTip(removetip);
|
||||
}
|
||||
|
||||
protected:
|
||||
// Must be called by the derived class ctor after creating the buttons to
|
||||
// set up the event handlers.
|
||||
void SetUpEvents()
|
||||
{
|
||||
m_btnAdd->Bind(wxEVT_UPDATE_UI,
|
||||
&wxAddRemoveImplBase::OnUpdateUIAdd, this);
|
||||
m_btnRemove->Bind(wxEVT_UPDATE_UI,
|
||||
&wxAddRemoveImplBase::OnUpdateUIRemove, this);
|
||||
|
||||
m_btnAdd->Bind(wxEVT_BUTTON, &wxAddRemoveImplBase::OnAdd, this);
|
||||
m_btnRemove->Bind(wxEVT_BUTTON, &wxAddRemoveImplBase::OnRemove, this);
|
||||
}
|
||||
|
||||
wxButton *m_btnAdd,
|
||||
*m_btnRemove;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxAddRemoveImplWithButtons);
|
||||
};
|
||||
|
||||
#endif // !wxGTK
|
||||
|
||||
#ifdef __WXOSX__
|
||||
#include "wx/osx/private/addremovectrl.h"
|
||||
#elif defined(__WXGTK20__)
|
||||
#include "wx/gtk/private/addremovectrl.h"
|
||||
#elif defined(__WXGTK__)
|
||||
#include "wx/gtk1/private/addremovectrl.h"
|
||||
#else
|
||||
#include "wx/generic/private/addremovectrl.h"
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_ADDREMOVECTRL_H_
|
||||
44
wxheaders/wx/private/animate.h
Normal file
44
wxheaders/wx/private/animate.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/animate.h
|
||||
// Purpose: wxAnimationImpl declaration
|
||||
// Author: Robin Dunn, Vadim Zeitlin
|
||||
// Created: 2020-04-06
|
||||
// Copyright: (c) 2020 wxWidgets development team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_ANIMATEH__
|
||||
#define _WX_PRIVATE_ANIMATEH__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxAnimationImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_CORE wxAnimationImpl : public wxRefCounter
|
||||
{
|
||||
public:
|
||||
wxAnimationImpl() {}
|
||||
virtual ~wxAnimationImpl() {}
|
||||
|
||||
virtual bool IsOk() const = 0;
|
||||
virtual bool IsCompatibleWith(wxClassInfo* ci) const = 0;
|
||||
|
||||
// can be -1
|
||||
virtual int GetDelay(unsigned int frame) const = 0;
|
||||
|
||||
virtual unsigned int GetFrameCount() const = 0;
|
||||
virtual wxImage GetFrame(unsigned int frame) const = 0;
|
||||
virtual wxSize GetSize() const = 0;
|
||||
|
||||
virtual bool LoadFile(const wxString& name,
|
||||
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
|
||||
virtual bool Load(wxInputStream& stream,
|
||||
wxAnimationType type = wxANIMATION_TYPE_ANY) = 0;
|
||||
|
||||
// This function creates the default implementation for this platform:
|
||||
// currently it's wxAnimationGTKImpl under wxGTK and wxAnimationGenericImpl
|
||||
// under all the other platforms.
|
||||
static wxAnimationImpl *CreateDefault();
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_ANIMATEH__
|
||||
34
wxheaders/wx/private/bmpbndl.h
Normal file
34
wxheaders/wx/private/bmpbndl.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/bmpbndl.h
|
||||
// Purpose: wxBitmapBundleImpl declaration.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2021-09-22
|
||||
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_BMPBNDL_H_
|
||||
#define _WX_PRIVATE_BMPBNDL_H_
|
||||
|
||||
#include "wx/bmpbndl.h"
|
||||
|
||||
#ifdef __WXOSX__
|
||||
|
||||
// this methods are wx-private, may change in the future
|
||||
|
||||
WXImage WXDLLIMPEXP_CORE wxOSXGetImageFromBundle(const wxBitmapBundle& bundle);
|
||||
wxBitmapBundle WXDLLIMPEXP_CORE wxOSXMakeBundleFromImage(WXImage image);
|
||||
WXImage WXDLLIMPEXP_CORE wxOSXImageFromBitmap(const wxBitmap& bmp);
|
||||
#if wxOSX_USE_COCOA
|
||||
void WXDLLIMPEXP_CORE wxOSXAddBitmapToImage(WXImage image, const wxBitmap& bmp);
|
||||
#endif
|
||||
|
||||
// for hiding the storage of the NSImage with wxBitmapBundleImpls from public API
|
||||
|
||||
WXImage WXDLLIMPEXP_CORE wxOSXGetImageFromBundleImpl(const wxBitmapBundleImpl* impl);
|
||||
void WXDLLIMPEXP_CORE wxOSXSetImageForBundleImpl(const wxBitmapBundleImpl* impl, WXImage image);
|
||||
void WXDLLIMPEXP_CORE wxOSXBundleImplDestroyed(const wxBitmapBundleImpl* impl);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_BMPBNDL_H_
|
||||
214
wxheaders/wx/private/display.h
Normal file
214
wxheaders/wx/private/display.h
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/display.h
|
||||
// Purpose: wxDisplayImpl class declaration
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2006-03-15
|
||||
// Copyright: (c) 2002-2006 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_DISPLAY_H_
|
||||
#define _WX_PRIVATE_DISPLAY_H_
|
||||
|
||||
#include "wx/display.h"
|
||||
#include "wx/gdicmn.h" // for wxRect
|
||||
#include "wx/vector.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayFactory: allows to create wxDisplay objects
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDisplayFactory
|
||||
{
|
||||
public:
|
||||
wxDisplayFactory() { }
|
||||
virtual ~wxDisplayFactory() { ClearImpls(); }
|
||||
|
||||
// Create the display if necessary using CreateDisplay(), otherwise just
|
||||
// get it from cache.
|
||||
wxDisplayImpl* GetDisplay(unsigned n)
|
||||
{
|
||||
// Normally, m_impls should be cleared if the number of displays in the
|
||||
// system changes because InvalidateCache() must be called. However in
|
||||
// some ports (e.g. Mac right now, see #18318), cache invalidation never
|
||||
// happens, so we can end up with m_impls size being out of sync with
|
||||
// the actual number of monitors. Compensate for this here by checking
|
||||
// if the index is invalid and invalidating the cache at least in this
|
||||
// case.
|
||||
//
|
||||
// Note that this is still incorrect because we continue using outdated
|
||||
// information if the first monitor is disconnected, for example. The
|
||||
// only real solution is to ensure that InvalidateCache() is called,
|
||||
// but for now this at least avoids crashes when a new display is
|
||||
// connected.
|
||||
if ( n >= m_impls.size() )
|
||||
{
|
||||
// This strange two-step resize is done to clear all the existing
|
||||
// elements: they may not be valid any longer if the number of
|
||||
// displays has changed.
|
||||
m_impls.resize(0);
|
||||
m_impls.resize(GetCount());
|
||||
}
|
||||
else if ( m_impls[n] )
|
||||
{
|
||||
// Just return the existing display if we have it.
|
||||
return m_impls[n];
|
||||
}
|
||||
|
||||
m_impls[n] = CreateDisplay(n);
|
||||
return m_impls[n];
|
||||
}
|
||||
|
||||
// Return the primary display object, creating it if necessary.
|
||||
wxDisplayImpl* GetPrimaryDisplay();
|
||||
|
||||
// get the total number of displays
|
||||
virtual unsigned GetCount() = 0;
|
||||
|
||||
// return the display for the given point or wxNOT_FOUND
|
||||
virtual int GetFromPoint(const wxPoint& pt) = 0;
|
||||
|
||||
// return the display for the given window or wxNOT_FOUND
|
||||
//
|
||||
// the window pointer must not be NULL (i.e. caller should check it)
|
||||
virtual int GetFromWindow(const wxWindow *window);
|
||||
|
||||
// Trigger recreation of wxDisplayImpl when they're needed the next time.
|
||||
virtual void InvalidateCache() { ClearImpls(); }
|
||||
|
||||
protected:
|
||||
// create a new display object
|
||||
//
|
||||
// it can return a NULL pointer if the display creation failed
|
||||
virtual wxDisplayImpl *CreateDisplay(unsigned n) = 0;
|
||||
|
||||
private:
|
||||
// Delete all the elements of m_impls vector and clear it.
|
||||
void ClearImpls();
|
||||
|
||||
// On-demand populated vector of wxDisplayImpl objects.
|
||||
wxVector<wxDisplayImpl*> m_impls;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxDisplayFactory);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayImpl: base class for all wxDisplay implementations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxDisplayImpl
|
||||
{
|
||||
public:
|
||||
// virtual dtor for this base class
|
||||
virtual ~wxDisplayImpl() { }
|
||||
|
||||
|
||||
// return the full area of this display
|
||||
virtual wxRect GetGeometry() const = 0;
|
||||
|
||||
// return the area of the display available for normal windows
|
||||
virtual wxRect GetClientArea() const { return GetGeometry(); }
|
||||
|
||||
// return the depth or 0 if unknown
|
||||
virtual int GetDepth() const = 0;
|
||||
|
||||
// return the scale factor used to convert logical pixels to physical ones
|
||||
virtual double GetScaleFactor() const { return 1.0; }
|
||||
|
||||
// return the resolution of the display, by default uses GetScaleFactor(),
|
||||
// but can be also overridden directly, as is done in wxMSW
|
||||
virtual wxSize GetPPI() const { return wxDisplay::GetStdPPI()*GetScaleFactor(); }
|
||||
|
||||
// return the name (may be empty)
|
||||
virtual wxString GetName() const { return wxString(); }
|
||||
|
||||
// return the index of this display
|
||||
unsigned GetIndex() const { return m_index; }
|
||||
|
||||
// return true if this is the primary monitor (usually one with index 0)
|
||||
virtual bool IsPrimary() const { return GetIndex() == 0; }
|
||||
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
// implements wxDisplay::GetModes()
|
||||
virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const = 0;
|
||||
|
||||
// get current video mode
|
||||
virtual wxVideoMode GetCurrentMode() const = 0;
|
||||
|
||||
// change current mode, return true if succeeded, false otherwise
|
||||
virtual bool ChangeMode(const wxVideoMode& mode) = 0;
|
||||
#endif // wxUSE_DISPLAY
|
||||
|
||||
protected:
|
||||
// create the object providing access to the display with the given index
|
||||
wxDisplayImpl(unsigned n) : m_index(n) { }
|
||||
|
||||
|
||||
// the index of this display (0 is always the primary one)
|
||||
const unsigned m_index;
|
||||
|
||||
|
||||
friend class wxDisplayFactory;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxDisplayImpl);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayImplSingle: the simplest possible impl for the main display only
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Note that this is still an ABC and GetGeometry() and GetClientArea() methods
|
||||
// must be implemented in the derived classes.
|
||||
|
||||
class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
|
||||
{
|
||||
public:
|
||||
wxDisplayImplSingle() : wxDisplayImpl(0) { }
|
||||
|
||||
#if wxUSE_DISPLAY
|
||||
// no video modes support for us, provide just the stubs
|
||||
virtual wxArrayVideoModes
|
||||
GetModes(const wxVideoMode& WXUNUSED(mode)) const wxOVERRIDE
|
||||
{
|
||||
return wxArrayVideoModes();
|
||||
}
|
||||
|
||||
virtual wxVideoMode GetCurrentMode() const wxOVERRIDE
|
||||
{
|
||||
return wxVideoMode();
|
||||
}
|
||||
|
||||
virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) wxOVERRIDE
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // wxUSE_DISPLAY
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxDisplayImplSingle);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDisplayFactorySingle
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This is the simplest implementation of wxDisplayFactory using single/main
|
||||
// display only. It is used when wxUSE_DISPLAY == 0 because getting the size of
|
||||
// the main display is always needed.
|
||||
//
|
||||
// Note that this is still an ABC and derived classes must implement
|
||||
// CreateSingleDisplay().
|
||||
|
||||
class wxDisplayFactorySingle : public wxDisplayFactory
|
||||
{
|
||||
public:
|
||||
virtual unsigned GetCount() wxOVERRIDE { return 1; }
|
||||
virtual int GetFromPoint(const wxPoint& pt) wxOVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual wxDisplayImpl *CreateDisplay(unsigned n) wxOVERRIDE;
|
||||
|
||||
virtual wxDisplayImpl *CreateSingleDisplay() = 0;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_DISPLAY_H_
|
||||
29
wxheaders/wx/private/eventloopsourcesmanager.h
Normal file
29
wxheaders/wx/private/eventloopsourcesmanager.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/eventloopsourcesmanager.h
|
||||
// Purpose: declares wxEventLoopSourcesManagerBase class
|
||||
// Author: Rob Bresalier
|
||||
// Created: 2013-06-19
|
||||
// Copyright: (c) 2013 Rob Bresalier
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_EVENTLOOPSOURCESMANAGER_H_
|
||||
#define _WX_PRIVATE_EVENTLOOPSOURCESMANAGER_H_
|
||||
|
||||
// For pulling in the value of wxUSE_EVENTLOOP_SOURCE
|
||||
#include "wx/evtloop.h"
|
||||
|
||||
#if wxUSE_EVENTLOOP_SOURCE
|
||||
|
||||
class WXDLLIMPEXP_BASE wxEventLoopSourcesManagerBase
|
||||
{
|
||||
public:
|
||||
virtual wxEventLoopSource*
|
||||
AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags) = 0;
|
||||
|
||||
virtual ~wxEventLoopSourcesManagerBase() { }
|
||||
};
|
||||
|
||||
#endif // wxUSE_EVENTLOOP_SOURCE
|
||||
|
||||
#endif // _WX_PRIVATE_EVENTLOOPSOURCESMANAGER_H_
|
||||
84
wxheaders/wx/private/extfield.h
Normal file
84
wxheaders/wx/private/extfield.h
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/extfield.h
|
||||
// Purpose: Declare wxExternalField helper
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2017-11-21
|
||||
// Copyright: (c) 2017 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_EXTFIELD_H_
|
||||
#define _WX_PRIVATE_EXTFIELD_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxExternalField: store object data outside of it
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This class allows to store some data without consuming space for the objects
|
||||
// that don't need it and can be useful for avoiding to add rarely used fields
|
||||
// to the classes that are used by many objects, e.g. wxWindow.
|
||||
//
|
||||
// Note that using this class costs in speed and convenience of access to the
|
||||
// field, which requires a hash lookup instead of accessing it directly. It
|
||||
// also only currently works for heap-allocated fields as it's probably never
|
||||
// worth using it for fields of simple types.
|
||||
//
|
||||
// Template parameter Object is the class that "contains" the field, Field is
|
||||
// the type of the field itself and FieldMap is the hash map, defined
|
||||
// separately using WX_DECLARE_HASH_MAP(), with Object* as the key and Field*
|
||||
// as the value type.
|
||||
template <typename Object, typename Field, typename FieldMap>
|
||||
class wxExternalField
|
||||
{
|
||||
public:
|
||||
typedef Object ObjectType;
|
||||
typedef Field FieldType;
|
||||
typedef FieldMap MapType;
|
||||
|
||||
// Store the field object to be used for the given object, replacing the
|
||||
// existing one, if any.
|
||||
//
|
||||
// This method takes ownership of the field pointer which will be destroyed
|
||||
// by EraseForObject().
|
||||
static void StoreForObject(ObjectType* obj, FieldType* field)
|
||||
{
|
||||
const typename MapType::iterator it = ms_map.find(obj);
|
||||
if ( it != ms_map.end() )
|
||||
{
|
||||
delete it->second;
|
||||
it->second = field;
|
||||
}
|
||||
else
|
||||
{
|
||||
ms_map.insert(typename MapType::value_type(obj, field));
|
||||
}
|
||||
}
|
||||
|
||||
// Find the object for the corresponding window.
|
||||
static FieldType* FromObject(ObjectType* obj)
|
||||
{
|
||||
const typename MapType::const_iterator it = ms_map.find(obj);
|
||||
return it == ms_map.end() ? NULL : it->second;
|
||||
}
|
||||
|
||||
// Erase the object used for the corresponding window, return true if there
|
||||
// was one or false otherwise.
|
||||
static bool EraseForObject(ObjectType* obj)
|
||||
{
|
||||
const typename MapType::iterator it = ms_map.find(obj);
|
||||
if ( it == ms_map.end() )
|
||||
return false;
|
||||
|
||||
delete it->second;
|
||||
ms_map.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
static FieldMap ms_map;
|
||||
};
|
||||
|
||||
template <typename O, typename F, typename M>
|
||||
M wxExternalField<O, F, M>::ms_map;
|
||||
|
||||
#endif // _WX_PRIVATE_EXTFIELD_H_
|
||||
53
wxheaders/wx/private/fd.h
Normal file
53
wxheaders/wx/private/fd.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fd.h
|
||||
// Purpose: private stuff for working with file descriptors
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2008-11-23 (moved from wx/unix/private.h)
|
||||
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FD_H_
|
||||
#define _WX_PRIVATE_FD_H_
|
||||
|
||||
// standard Linux headers produce many warnings when used with icc so define
|
||||
// our own replacements for FD_XXX macros
|
||||
#if defined(__INTELC__) && defined(__LINUX__)
|
||||
inline void wxFD_ZERO(fd_set *fds)
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:593)
|
||||
FD_ZERO(fds);
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
inline void wxFD_SET(int fd, fd_set *fds)
|
||||
{
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable:1469)
|
||||
FD_SET(fd, fds);
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
inline bool wxFD_ISSET(int fd, fd_set *fds)
|
||||
{
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable:1469)
|
||||
return FD_ISSET(fd, fds);
|
||||
#pragma warning(pop)
|
||||
}
|
||||
inline void wxFD_CLR(int fd, fd_set *fds)
|
||||
{
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable:1469)
|
||||
FD_CLR(fd, fds);
|
||||
#pragma warning(pop)
|
||||
}
|
||||
#else // !__INTELC__
|
||||
#define wxFD_ZERO(fds) FD_ZERO(fds)
|
||||
#define wxFD_SET(fd, fds) FD_SET(fd, fds)
|
||||
#define wxFD_ISSET(fd, fds) FD_ISSET(fd, fds)
|
||||
#define wxFD_CLR(fd, fds) FD_CLR(fd, fds)
|
||||
#endif // __INTELC__/!__INTELC__
|
||||
|
||||
#endif // _WX_PRIVATE_FD_H_
|
||||
118
wxheaders/wx/private/fdiodispatcher.h
Normal file
118
wxheaders/wx/private/fdiodispatcher.h
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fdiodispatcher.h
|
||||
// Purpose: classes for dispatching IO notifications for file descriptors
|
||||
// Authors: Lukasz Michalski
|
||||
// Created: December 2006
|
||||
// Copyright: (c) Lukasz Michalski
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FDIODISPATCHER_H_
|
||||
#define _WX_PRIVATE_FDIODISPATCHER_H_
|
||||
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/private/fdiohandler.h"
|
||||
|
||||
// those flags describes sets where descriptor should be added
|
||||
enum wxFDIODispatcherEntryFlags
|
||||
{
|
||||
wxFDIO_INPUT = 1,
|
||||
wxFDIO_OUTPUT = 2,
|
||||
wxFDIO_EXCEPTION = 4,
|
||||
wxFDIO_ALL = wxFDIO_INPUT | wxFDIO_OUTPUT | wxFDIO_EXCEPTION
|
||||
};
|
||||
|
||||
// base class for wxSelectDispatcher and wxEpollDispatcher
|
||||
class WXDLLIMPEXP_BASE wxFDIODispatcher
|
||||
{
|
||||
public:
|
||||
enum { TIMEOUT_INFINITE = -1 };
|
||||
|
||||
// return the global dispatcher to be used for IO events, can be NULL only
|
||||
// if wxSelectDispatcher wasn't compiled into the library at all as
|
||||
// creating it never fails
|
||||
//
|
||||
// don't delete the returned pointer
|
||||
static wxFDIODispatcher *Get();
|
||||
|
||||
// if we have any registered handlers, check for any pending events to them
|
||||
// and dispatch them -- this is used from wxX11 and wxDFB event loops
|
||||
// implementation
|
||||
static void DispatchPending();
|
||||
|
||||
// register handler for the given descriptor with the dispatcher, return
|
||||
// true on success or false on error
|
||||
virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags) = 0;
|
||||
|
||||
// modify descriptor flags or handler, return true on success
|
||||
virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0;
|
||||
|
||||
// unregister descriptor previously registered with RegisterFD()
|
||||
virtual bool UnregisterFD(int fd) = 0;
|
||||
|
||||
// check if any events are currently available without dispatching them
|
||||
virtual bool HasPending() const = 0;
|
||||
|
||||
// wait for an event for at most timeout milliseconds and process it;
|
||||
// return the number of events processed (possibly 0 if timeout expired) or
|
||||
// -1 if an error occurred
|
||||
virtual int Dispatch(int timeout = TIMEOUT_INFINITE) = 0;
|
||||
|
||||
virtual ~wxFDIODispatcher() { }
|
||||
};
|
||||
|
||||
//entry for wxFDIOHandlerMap
|
||||
struct wxFDIOHandlerEntry
|
||||
{
|
||||
wxFDIOHandlerEntry()
|
||||
{
|
||||
}
|
||||
|
||||
wxFDIOHandlerEntry(wxFDIOHandler *handler_, int flags_)
|
||||
: handler(handler_),
|
||||
flags(flags_)
|
||||
{
|
||||
}
|
||||
|
||||
wxFDIOHandler *handler;
|
||||
int flags;
|
||||
};
|
||||
|
||||
// this hash is used to map file descriptors to their handlers
|
||||
WX_DECLARE_HASH_MAP(
|
||||
int,
|
||||
wxFDIOHandlerEntry,
|
||||
wxIntegerHash,
|
||||
wxIntegerEqual,
|
||||
wxFDIOHandlerMap
|
||||
);
|
||||
|
||||
// FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if
|
||||
// this map isn't maintained elsewhere already as it is usually needed anyhow
|
||||
//
|
||||
// notice that all functions for FD management have implementation
|
||||
// in the base class and should be called from the derived classes
|
||||
class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher
|
||||
{
|
||||
public:
|
||||
// find the handler for the given fd, return NULL if none
|
||||
wxFDIOHandler *FindHandler(int fd) const;
|
||||
|
||||
// register handler for the given descriptor with the dispatcher, return
|
||||
// true on success or false on error
|
||||
virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags) wxOVERRIDE;
|
||||
|
||||
// modify descriptor flags or handler, return true on success
|
||||
virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) wxOVERRIDE;
|
||||
|
||||
// unregister descriptor previously registered with RegisterFD()
|
||||
virtual bool UnregisterFD(int fd) wxOVERRIDE;
|
||||
|
||||
virtual ~wxMappedFDIODispatcher() { }
|
||||
|
||||
protected:
|
||||
// the fd -> handler map containing all the registered handlers
|
||||
wxFDIOHandlerMap m_handlers;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_FDIODISPATCHER_H_
|
||||
38
wxheaders/wx/private/fdioeventloopsourcehandler.h
Normal file
38
wxheaders/wx/private/fdioeventloopsourcehandler.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fdioeventloopsourcehandler.h
|
||||
// Purpose: declares wxFDIOEventLoopSourceHandler class
|
||||
// Author: Rob Bresalier, Vadim Zeitlin
|
||||
// Created: 2013-06-13 (extracted from src/unix/evtloopunix.cpp)
|
||||
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// (c) 2013 Rob Bresalier
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FDIO_EVENT_LOOP_SOURCE_HANDLER_H
|
||||
#define _WX_PRIVATE_FDIO_EVENT_LOOP_SOURCE_HANDLER_H
|
||||
|
||||
#include "wx/evtloopsrc.h"
|
||||
|
||||
// This class is a temporary bridge between event loop sources and
|
||||
// FDIODispatcher. It is going to be removed soon, when all subject interfaces
|
||||
// are modified
|
||||
class wxFDIOEventLoopSourceHandler : public wxFDIOHandler
|
||||
{
|
||||
public:
|
||||
explicit wxFDIOEventLoopSourceHandler(wxEventLoopSourceHandler* handler)
|
||||
: m_handler(handler)
|
||||
{
|
||||
}
|
||||
|
||||
// Just forward to the real handler.
|
||||
virtual void OnReadWaiting() wxOVERRIDE { m_handler->OnReadWaiting(); }
|
||||
virtual void OnWriteWaiting() wxOVERRIDE { m_handler->OnWriteWaiting(); }
|
||||
virtual void OnExceptionWaiting() wxOVERRIDE { m_handler->OnExceptionWaiting(); }
|
||||
|
||||
protected:
|
||||
wxEventLoopSourceHandler* const m_handler;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxFDIOEventLoopSourceHandler);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_FDIO_EVENT_LOOP_SOURCE_HANDLER_H
|
||||
53
wxheaders/wx/private/fdiohandler.h
Normal file
53
wxheaders/wx/private/fdiohandler.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fdiohandler.h
|
||||
// Purpose: declares wxFDIOHandler class
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2009-08-17
|
||||
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FDIOHANDLER_H_
|
||||
#define _WX_PRIVATE_FDIOHANDLER_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFDIOHandler: interface used to process events on file descriptors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxFDIOHandler
|
||||
{
|
||||
public:
|
||||
wxFDIOHandler() { m_regmask = 0; }
|
||||
|
||||
// called when descriptor is available for non-blocking read
|
||||
virtual void OnReadWaiting() = 0;
|
||||
|
||||
// called when descriptor is available for non-blocking write
|
||||
virtual void OnWriteWaiting() = 0;
|
||||
|
||||
// called when there is exception on descriptor
|
||||
virtual void OnExceptionWaiting() = 0;
|
||||
|
||||
// called to check if the handler is still valid, only used by
|
||||
// wxSocketImplUnix currently
|
||||
virtual bool IsOk() const { return true; }
|
||||
|
||||
|
||||
// get/set the mask of events for which we're currently registered for:
|
||||
// it's a combination of wxFDIO_{INPUT,OUTPUT,EXCEPTION}
|
||||
int GetRegisteredEvents() const { return m_regmask; }
|
||||
void SetRegisteredEvent(int flag) { m_regmask |= flag; }
|
||||
void ClearRegisteredEvent(int flag) { m_regmask &= ~flag; }
|
||||
|
||||
|
||||
// virtual dtor for the base class
|
||||
virtual ~wxFDIOHandler() { }
|
||||
|
||||
private:
|
||||
int m_regmask;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxFDIOHandler);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_FDIOHANDLER_H_
|
||||
|
||||
42
wxheaders/wx/private/fdiomanager.h
Normal file
42
wxheaders/wx/private/fdiomanager.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fdiomanager.h
|
||||
// Purpose: declaration of wxFDIOManager
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2009-08-17
|
||||
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FDIOMANAGER_H_
|
||||
#define _WX_PRIVATE_FDIOMANAGER_H_
|
||||
|
||||
#include "wx/private/fdiohandler.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFDIOManager: register or unregister wxFDIOHandlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// currently only used in wxGTK and wxMotif, see wx/unix/apptrait.h
|
||||
|
||||
class wxFDIOManager
|
||||
{
|
||||
public:
|
||||
// identifies either input or output direction
|
||||
//
|
||||
// NB: the values of this enum shouldn't change
|
||||
enum Direction
|
||||
{
|
||||
INPUT,
|
||||
OUTPUT
|
||||
};
|
||||
|
||||
// start or stop monitoring the events on the given file descriptor
|
||||
virtual int AddInput(wxFDIOHandler *handler, int fd, Direction d) = 0;
|
||||
virtual void RemoveInput(wxFDIOHandler *handler, int fd, Direction d) = 0;
|
||||
|
||||
// empty but virtual dtor for the base class
|
||||
virtual ~wxFDIOManager() { }
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_FDIOMANAGER_H_
|
||||
|
||||
82
wxheaders/wx/private/fileback.h
Normal file
82
wxheaders/wx/private/fileback.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fileback.h
|
||||
// Purpose: Back an input stream with memory or a file
|
||||
// Author: Mike Wetherell
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_FILEBACK_H__
|
||||
#define _WX_FILEBACK_H__
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if wxUSE_FILESYSTEM
|
||||
|
||||
#include "wx/stream.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Backs an input stream with memory or a file to make it seekable.
|
||||
//
|
||||
// One or more wxBackedInputStreams can be used to read it's data. The data is
|
||||
// reference counted, so stays alive until the last wxBackingFile or
|
||||
// wxBackedInputStream using it is destroyed.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_BASE wxBackingFile
|
||||
{
|
||||
public:
|
||||
enum { DefaultBufSize = 16384 };
|
||||
|
||||
// Takes ownership of stream. If the stream is smaller than bufsize, the
|
||||
// backing file is never created and the backing is done with memory.
|
||||
wxBackingFile(wxInputStream *stream,
|
||||
size_t bufsize = DefaultBufSize,
|
||||
const wxString& prefix = wxT("wxbf"));
|
||||
|
||||
wxBackingFile() : m_impl(NULL) { }
|
||||
~wxBackingFile();
|
||||
|
||||
wxBackingFile(const wxBackingFile& backer);
|
||||
wxBackingFile& operator=(const wxBackingFile& backer);
|
||||
|
||||
operator bool() const { return m_impl != NULL; }
|
||||
|
||||
private:
|
||||
class wxBackingFileImpl *m_impl;
|
||||
friend class wxBackedInputStream;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// An input stream to read from a wxBackingFile.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_BASE wxBackedInputStream : public wxInputStream
|
||||
{
|
||||
public:
|
||||
wxBackedInputStream(const wxBackingFile& backer);
|
||||
|
||||
// If the length of the backer's parent stream is unknown then GetLength()
|
||||
// returns wxInvalidOffset until the parent has been read to the end.
|
||||
wxFileOffset GetLength() const wxOVERRIDE;
|
||||
|
||||
// Returns the length, reading the parent stream to the end if necessary.
|
||||
wxFileOffset FindLength() const;
|
||||
|
||||
bool IsSeekable() const wxOVERRIDE { return true; }
|
||||
|
||||
protected:
|
||||
size_t OnSysRead(void *buffer, size_t size) wxOVERRIDE;
|
||||
wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) wxOVERRIDE;
|
||||
wxFileOffset OnSysTell() const wxOVERRIDE;
|
||||
|
||||
private:
|
||||
wxBackingFile m_backer;
|
||||
wxFileOffset m_pos;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxBackedInputStream);
|
||||
};
|
||||
|
||||
#endif // wxUSE_FILESYSTEM
|
||||
|
||||
#endif // _WX_FILEBACK_H__
|
||||
85
wxheaders/wx/private/filedlgcustomize.h
Normal file
85
wxheaders/wx/private/filedlgcustomize.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/filedlgcustomize.h
|
||||
// Purpose: Private helpers used for wxFileDialog customization
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2022-05-26
|
||||
// Copyright: (c) 2022 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FILEDLGCUSTOMIZE_H_
|
||||
#define _WX_PRIVATE_FILEDLGCUSTOMIZE_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDialogCustomControlImpl: interface for all custom controls
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxFileDialogCustomControlImpl
|
||||
{
|
||||
public:
|
||||
virtual void Show(bool show) = 0;
|
||||
virtual void Enable(bool enable) = 0;
|
||||
|
||||
virtual bool DoBind(wxEvtHandler* handler);
|
||||
|
||||
virtual ~wxFileDialogCustomControlImpl();
|
||||
};
|
||||
|
||||
// This class is defined for symmetry with the other ones, but there are no
|
||||
// button-specific methods so far.
|
||||
class wxFileDialogButtonImpl : public wxFileDialogCustomControlImpl
|
||||
{
|
||||
};
|
||||
|
||||
class wxFileDialogCheckBoxImpl : public wxFileDialogCustomControlImpl
|
||||
{
|
||||
public:
|
||||
virtual bool GetValue() = 0;
|
||||
virtual void SetValue(bool value) = 0;
|
||||
};
|
||||
|
||||
class wxFileDialogRadioButtonImpl : public wxFileDialogCustomControlImpl
|
||||
{
|
||||
public:
|
||||
virtual bool GetValue() = 0;
|
||||
virtual void SetValue(bool value) = 0;
|
||||
};
|
||||
|
||||
class wxFileDialogChoiceImpl : public wxFileDialogCustomControlImpl
|
||||
{
|
||||
public:
|
||||
virtual int GetSelection() = 0;
|
||||
virtual void SetSelection(int n) = 0;
|
||||
};
|
||||
|
||||
class wxFileDialogTextCtrlImpl : public wxFileDialogCustomControlImpl
|
||||
{
|
||||
public:
|
||||
virtual wxString GetValue() = 0;
|
||||
virtual void SetValue(const wxString& value) = 0;
|
||||
};
|
||||
|
||||
class wxFileDialogStaticTextImpl : public wxFileDialogCustomControlImpl
|
||||
{
|
||||
public:
|
||||
virtual void SetLabelText(const wxString& text) = 0;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDialogCustomizeImpl: interface for actual customizers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxFileDialogCustomizeImpl
|
||||
{
|
||||
public:
|
||||
virtual wxFileDialogButtonImpl* AddButton(const wxString& label) = 0;
|
||||
virtual wxFileDialogCheckBoxImpl* AddCheckBox(const wxString& label) = 0;
|
||||
virtual wxFileDialogRadioButtonImpl* AddRadioButton(const wxString& label) = 0;
|
||||
virtual wxFileDialogChoiceImpl* AddChoice(size_t n, const wxString* strings) = 0;
|
||||
virtual wxFileDialogTextCtrlImpl* AddTextCtrl(const wxString& label) = 0;
|
||||
virtual wxFileDialogStaticTextImpl* AddStaticText(const wxString& label) = 0;
|
||||
|
||||
virtual ~wxFileDialogCustomizeImpl();
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_FILEDLGCUSTOMIZE_H_
|
||||
55
wxheaders/wx/private/filename.h
Normal file
55
wxheaders/wx/private/filename.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/filename.h
|
||||
// Purpose: Internal declarations for src/common/filename.cpp
|
||||
// Author: Mike Wetherell
|
||||
// Modified by:
|
||||
// Created: 2006-10-22
|
||||
// Copyright: (c) 2006 Mike Wetherell
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FILENAME_H_
|
||||
#define _WX_PRIVATE_FILENAME_H_
|
||||
|
||||
#include "wx/file.h"
|
||||
#include "wx/ffile.h"
|
||||
|
||||
// Self deleting temp files aren't supported on all platforms. Therefore
|
||||
// rather than let these be in the API, they can be used internally to
|
||||
// implement classes (e.g. wxTempFileStream), that will do the clean up when
|
||||
// the OS doesn't support it.
|
||||
|
||||
// Same usage as wxFileName::CreateTempFileName() with the extra parameter
|
||||
// deleteOnClose. *deleteOnClose true on entry requests a file created with a
|
||||
// delete on close flag, on exit the value of *deleteOnClose indicates whether
|
||||
// available.
|
||||
|
||||
#if wxUSE_FILE
|
||||
wxString wxCreateTempFileName(const wxString& prefix,
|
||||
wxFile *fileTemp,
|
||||
bool *deleteOnClose = NULL);
|
||||
#endif
|
||||
|
||||
#if wxUSE_FFILE
|
||||
wxString wxCreateTempFileName(const wxString& prefix,
|
||||
wxFFile *fileTemp,
|
||||
bool *deleteOnClose = NULL);
|
||||
#endif
|
||||
|
||||
// Returns an open temp file, if possible either an unlinked open file or one
|
||||
// that will delete on close. Only returns the filename if neither was
|
||||
// possible, so that the caller can delete the file when done.
|
||||
|
||||
#if wxUSE_FILE
|
||||
bool wxCreateTempFile(const wxString& prefix,
|
||||
wxFile *fileTemp,
|
||||
wxString *name);
|
||||
#endif
|
||||
|
||||
#if wxUSE_FFILE
|
||||
bool wxCreateTempFile(const wxString& prefix,
|
||||
wxFFile *fileTemp,
|
||||
wxString *name);
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_FILENAME_H_
|
||||
116
wxheaders/wx/private/flagscheck.h
Normal file
116
wxheaders/wx/private/flagscheck.h
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/flagscheck.h
|
||||
// Purpose: helpers for checking that (bit)flags don't overlap
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2008-02-21
|
||||
// Copyright: (c) 2008 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FLAGSCHECK_H_
|
||||
#define _WX_PRIVATE_FLAGSCHECK_H_
|
||||
|
||||
#include "wx/debug.h"
|
||||
|
||||
// IBM xlC 8 can't parse the template syntax
|
||||
#if !defined(__IBMCPP__)
|
||||
|
||||
#include "wx/meta/if.h"
|
||||
|
||||
namespace wxPrivate
|
||||
{
|
||||
|
||||
// These templates are used to implement wxADD_FLAG macro below.
|
||||
//
|
||||
// The idea is that we want to trigger *compilation* error if the flags
|
||||
// overlap, not just runtime assert failure. We can't implement the check
|
||||
// using just a simple logical operation, we need checks equivalent to this
|
||||
// code:
|
||||
//
|
||||
// mask = wxFLAG_1;
|
||||
// assert( (mask & wxFLAG_2) == 0 ); // no overlap
|
||||
// mask |= wxFLAG_3;
|
||||
// assert( (mask & wxFLAG_3) == 0 ); // no overlap
|
||||
// mask |= wxFLAG_3;
|
||||
// ...
|
||||
//
|
||||
// This can be done at compilation time by using templates metaprogramming
|
||||
// technique that makes the compiler carry on the computation.
|
||||
//
|
||||
// NB: If any of this doesn't compile with your compiler and would be too
|
||||
// hard to make work, it's probably best to disable this code and replace
|
||||
// the macros below with empty stubs, this isn't anything critical.
|
||||
|
||||
template<int val> struct FlagsHaveConflictingValues
|
||||
{
|
||||
// no value here - triggers compilation error
|
||||
};
|
||||
|
||||
template<int val> struct FlagValue
|
||||
{
|
||||
enum { value = val };
|
||||
};
|
||||
|
||||
// This template adds its template parameter integer 'add' to another integer
|
||||
// 'all' and produces their OR-combination (all | add). The result is "stored"
|
||||
// as constant SafelyAddToMask<>::value. Combination of many flags is achieved
|
||||
// by chaining parameter lists: the 'add' parameter is value member of
|
||||
// another (different) SafelyAddToMask<> instantiation.
|
||||
template<int all, int add> struct SafelyAddToMask
|
||||
{
|
||||
// This typedefs ensures that no flags in the list conflict. If there's
|
||||
// any overlap between the already constructed part of the mask ('all')
|
||||
// and the value being added to it ('add'), the test that is wxIf<>'s
|
||||
// first parameter will be non-zero and so Added value will be
|
||||
// FlagsHaveConflictingValues<add>. The next statement will try to use
|
||||
// AddedValue::value, but there's no such thing in
|
||||
// FlagsHaveConflictingValues<> and so compilation will fail.
|
||||
typedef typename wxIf<(all & add) == 0,
|
||||
FlagValue<add>,
|
||||
FlagsHaveConflictingValues<add> >::value
|
||||
AddedValue;
|
||||
|
||||
enum { value = all | AddedValue::value };
|
||||
};
|
||||
|
||||
} // wxPrivate namespace
|
||||
|
||||
|
||||
|
||||
// This macro is used to ensure that no two flags that can be combined in
|
||||
// the same integer value have overlapping bits. This is sometimes not entirely
|
||||
// trivial to ensure, for example in wxWindow styles or flags for wxSizerItem
|
||||
// that span several enums, some of them used for multiple purposes.
|
||||
//
|
||||
// By constructing allowed flags mask using wxADD_FLAG macro and then using
|
||||
// this mask to check flags passed as arguments, you can ensure that
|
||||
//
|
||||
// a) if any of the allowed flags overlap, you will get compilation error
|
||||
// b) if invalid flag is used, there will be an assert at runtime
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// static const int SIZER_FLAGS_MASK =
|
||||
// wxADD_FLAG(wxCENTRE,
|
||||
// wxADD_FLAG(wxHORIZONTAL,
|
||||
// wxADD_FLAG(wxVERTICAL,
|
||||
// ...
|
||||
// 0))...);
|
||||
//
|
||||
// And wherever flags are used:
|
||||
//
|
||||
// wxASSERT_VALID_FLAG( m_flag, SIZER_FLAGS_MASK );
|
||||
|
||||
#define wxADD_FLAG(f, others) \
|
||||
::wxPrivate::SafelyAddToMask<f, others>::value
|
||||
|
||||
#else
|
||||
#define wxADD_FLAG(f, others) (f | others)
|
||||
#endif
|
||||
|
||||
// Checks if flags value 'f' is within the mask of allowed values
|
||||
#define wxASSERT_VALID_FLAGS(f, mask) \
|
||||
wxASSERT_MSG( (f & mask) == f, \
|
||||
"invalid flag: not within " #mask )
|
||||
|
||||
#endif // _WX_PRIVATE_FLAGSCHECK_H_
|
||||
247
wxheaders/wx/private/fontmgr.h
Normal file
247
wxheaders/wx/private/fontmgr.h
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fontmgr.h
|
||||
// Purpose: font management for ports that don't have their own
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2006-11-18
|
||||
// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
|
||||
// (c) 2006 REA Elektronik GmbH
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_FONTMGR_H_
|
||||
#define _WX_PRIVATE_FONTMGR_H_
|
||||
|
||||
#include "wx/list.h"
|
||||
#include "wx/fontutil.h"
|
||||
|
||||
class wxFontsManager;
|
||||
class wxFontInstance;
|
||||
class wxFontInstanceList;
|
||||
class wxFontFace;
|
||||
class wxFontBundle;
|
||||
class wxFontBundleHash;
|
||||
class wxFontMgrFontRefData;
|
||||
|
||||
WX_DECLARE_LIST(wxFontBundle, wxFontBundleList);
|
||||
|
||||
/**
|
||||
This class represents single font face with set parameters (point size,
|
||||
antialiasing).
|
||||
*/
|
||||
class wxFontInstanceBase
|
||||
{
|
||||
protected:
|
||||
wxFontInstanceBase(float ptSize, bool aa) : m_ptSize(ptSize), m_aa(aa) {}
|
||||
virtual ~wxFontInstanceBase() {}
|
||||
|
||||
public:
|
||||
float GetPointSize() const { return m_ptSize; }
|
||||
bool IsAntiAliased() const { return m_aa; }
|
||||
|
||||
protected:
|
||||
float m_ptSize;
|
||||
bool m_aa;
|
||||
};
|
||||
|
||||
|
||||
/// This class represents loaded font face (bundle+weight+italics).
|
||||
class wxFontFaceBase
|
||||
{
|
||||
protected:
|
||||
/// Ctor. Creates object with reference count = 0, Acquire() must be
|
||||
/// called after the object is created.
|
||||
wxFontFaceBase();
|
||||
virtual ~wxFontFaceBase();
|
||||
|
||||
public:
|
||||
/// Increases reference count of the face
|
||||
virtual void Acquire();
|
||||
|
||||
/**
|
||||
Decreases reference count of the face. Call this when you no longer
|
||||
use the object returned by wxFontBundle. Note that this doesn't destroy
|
||||
the object, but only optionally shuts it down, so it's possible to
|
||||
call Acquire() and Release() more than once.
|
||||
*/
|
||||
virtual void Release();
|
||||
|
||||
/**
|
||||
Returns instance of the font at given size.
|
||||
|
||||
@param ptSize point size of the font to create; note that this is
|
||||
a float and not integer, it should be wxFont's point
|
||||
size multiplied by wxDC's scale factor
|
||||
@param aa should the font be antialiased?
|
||||
*/
|
||||
virtual wxFontInstance *GetFontInstance(float ptSize, bool aa);
|
||||
|
||||
protected:
|
||||
/// Called to create a new instance of the font by GetFontInstance() if
|
||||
/// it wasn't found it cache.
|
||||
virtual wxFontInstance *CreateFontInstance(float ptSize, bool aa) = 0;
|
||||
|
||||
protected:
|
||||
unsigned m_refCnt;
|
||||
wxFontInstanceList *m_instances;
|
||||
};
|
||||
|
||||
/**
|
||||
This class represents font bundle. Font bundle is set of faces that have
|
||||
the same name, but differ in weight and italics.
|
||||
*/
|
||||
class wxFontBundleBase
|
||||
{
|
||||
public:
|
||||
wxFontBundleBase();
|
||||
virtual ~wxFontBundleBase();
|
||||
|
||||
/// Returns name of the bundle
|
||||
virtual wxString GetName() const = 0;
|
||||
|
||||
/// Returns true if the font is fixed-width
|
||||
virtual bool IsFixed() const = 0;
|
||||
|
||||
/// Type of faces in the bundle
|
||||
enum FaceType
|
||||
{
|
||||
// NB: values of these constants are set so that it's possible to
|
||||
// make OR-combinations of them and still get valid enum element
|
||||
FaceType_Regular = 0,
|
||||
FaceType_Italic = 1,
|
||||
FaceType_Bold = 2,
|
||||
FaceType_BoldItalic = FaceType_Italic | FaceType_Bold,
|
||||
|
||||
FaceType_Max
|
||||
};
|
||||
|
||||
/// Returns true if the given face is available
|
||||
bool HasFace(FaceType type) const { return m_faces[type] != NULL; }
|
||||
|
||||
/**
|
||||
Returns font face object that can be used to render font of given type.
|
||||
|
||||
Note that this method can only be called if HasFace(type) returns true.
|
||||
|
||||
Acquire() was called on the returned object, you must call Release()
|
||||
when you stop using it.
|
||||
*/
|
||||
wxFontFace *GetFace(FaceType type) const;
|
||||
|
||||
/**
|
||||
Returns font face object that can be used to render given font.
|
||||
|
||||
Acquire() was called on the returned object, you must call Release()
|
||||
when you stop using it.
|
||||
*/
|
||||
wxFontFace *GetFaceForFont(const wxFontMgrFontRefData& font) const;
|
||||
|
||||
protected:
|
||||
wxFontFace *m_faces[FaceType_Max];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Base class for wxFontsManager class, which manages the list of all
|
||||
available fonts and their loaded instances.
|
||||
*/
|
||||
class wxFontsManagerBase
|
||||
{
|
||||
protected:
|
||||
wxFontsManagerBase();
|
||||
virtual ~wxFontsManagerBase();
|
||||
|
||||
public:
|
||||
/// Returns the font manager singleton, creating it if it doesn't exist
|
||||
static wxFontsManager *Get();
|
||||
|
||||
/// Called by wxApp to shut down the manager
|
||||
static void CleanUp();
|
||||
|
||||
/// Returns list of all available font bundles
|
||||
const wxFontBundleList& GetBundles() const { return *m_list; }
|
||||
|
||||
/**
|
||||
Returns object representing font bundle with the given name.
|
||||
|
||||
The returned object is owned by wxFontsManager, you must not delete it.
|
||||
*/
|
||||
wxFontBundle *GetBundle(const wxString& name) const;
|
||||
|
||||
/**
|
||||
Returns object representing font bundle that can be used to render
|
||||
given font.
|
||||
|
||||
The returned object is owned by wxFontsManager, you must not delete it.
|
||||
*/
|
||||
wxFontBundle *GetBundleForFont(const wxFontMgrFontRefData& font) const;
|
||||
|
||||
/// This method must be called by derived
|
||||
void AddBundle(wxFontBundle *bundle);
|
||||
|
||||
/// Returns default facename for given wxFont family
|
||||
virtual wxString GetDefaultFacename(wxFontFamily family) const = 0;
|
||||
|
||||
private:
|
||||
wxFontBundleHash *m_hash;
|
||||
wxFontBundleList *m_list;
|
||||
|
||||
protected:
|
||||
static wxFontsManager *ms_instance;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if defined(__WXDFB__)
|
||||
#include "wx/dfb/private/fontmgr.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/// wxFontMgrFontRefData implementation using wxFontsManager classes
|
||||
class wxFontMgrFontRefData : public wxGDIRefData
|
||||
{
|
||||
public:
|
||||
wxFontMgrFontRefData(int size = wxDEFAULT,
|
||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
||||
int weight = wxFONTWEIGHT_NORMAL,
|
||||
bool underlined = false,
|
||||
const wxString& faceName = wxEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
wxFontMgrFontRefData(const wxFontMgrFontRefData& data);
|
||||
~wxFontMgrFontRefData();
|
||||
|
||||
wxFontBundle *GetFontBundle() const;
|
||||
wxFontInstance *GetFontInstance(float scale, bool antialiased) const;
|
||||
|
||||
bool IsFixedWidth() const { return GetFontBundle()->IsFixed(); }
|
||||
|
||||
const wxNativeFontInfo *GetNativeFontInfo() const { return &m_info; }
|
||||
|
||||
double GetFractionalPointSize() const { return m_info.pointSize; }
|
||||
wxString GetFaceName() const { return m_info.faceName; }
|
||||
wxFontFamily GetFamily() const { return m_info.family; }
|
||||
wxFontStyle GetStyle() const { return m_info.style; }
|
||||
int GetNumericWeight() const { return m_info.weight; }
|
||||
bool GetUnderlined() const { return m_info.underlined; }
|
||||
wxFontEncoding GetEncoding() const { return m_info.encoding; }
|
||||
|
||||
void SetFractionalPointSize(double pointSize);
|
||||
void SetFamily(wxFontFamily family);
|
||||
void SetStyle(wxFontStyle style);
|
||||
void SetNumericWeight(int weight);
|
||||
void SetFaceName(const wxString& faceName);
|
||||
void SetUnderlined(bool underlined);
|
||||
void SetEncoding(wxFontEncoding encoding);
|
||||
|
||||
private:
|
||||
void EnsureValidFont();
|
||||
|
||||
wxNativeFontInfo m_info;
|
||||
|
||||
wxFontFace *m_fontFace;
|
||||
wxFontBundle *m_fontBundle;
|
||||
bool m_fontValid;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_FONTMGR_H_
|
||||
115
wxheaders/wx/private/fswatcher.h
Normal file
115
wxheaders/wx/private/fswatcher.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/fswatcher.h
|
||||
// Purpose: File system watcher impl classes
|
||||
// Author: Bartosz Bekier
|
||||
// Created: 2009-05-26
|
||||
// Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef WX_PRIVATE_FSWATCHER_H_
|
||||
#define WX_PRIVATE_FSWATCHER_H_
|
||||
|
||||
#include "wx/sharedptr.h"
|
||||
|
||||
#ifdef wxHAS_INOTIFY
|
||||
class wxFSWatchEntryUnix;
|
||||
#define wxFSWatchEntry wxFSWatchEntryUnix
|
||||
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
|
||||
#include "wx/unix/private/fswatcher_inotify.h"
|
||||
#elif defined(wxHAS_KQUEUE)
|
||||
class wxFSWatchEntryKq;
|
||||
#define wxFSWatchEntry wxFSWatchEntryKq
|
||||
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
|
||||
#include "wx/unix/private/fswatcher_kqueue.h"
|
||||
#elif defined(__WINDOWS__)
|
||||
class wxFSWatchEntryMSW;
|
||||
#define wxFSWatchEntry wxFSWatchEntryMSW
|
||||
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
|
||||
#include "wx/msw/private/fswatcher.h"
|
||||
#else
|
||||
#define wxFSWatchEntry wxFSWatchEntryPolling
|
||||
#endif
|
||||
|
||||
class wxFSWatcherImpl
|
||||
{
|
||||
public:
|
||||
wxFSWatcherImpl(wxFileSystemWatcherBase* watcher) :
|
||||
m_watcher(watcher)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~wxFSWatcherImpl()
|
||||
{
|
||||
(void) RemoveAll();
|
||||
}
|
||||
|
||||
virtual bool Init() = 0;
|
||||
|
||||
virtual bool Add(const wxFSWatchInfo& winfo)
|
||||
{
|
||||
if ( m_watches.find(winfo.GetPath()) != m_watches.end() )
|
||||
{
|
||||
wxLogTrace(wxTRACE_FSWATCHER,
|
||||
"Path '%s' is already watched", winfo.GetPath());
|
||||
// This can happen if a dir is watched, then a parent tree added
|
||||
return true;
|
||||
}
|
||||
|
||||
// construct watch entry
|
||||
wxSharedPtr<wxFSWatchEntry> watch(new wxFSWatchEntry(winfo));
|
||||
|
||||
if (!DoAdd(watch))
|
||||
return false;
|
||||
|
||||
// add watch to our map (always succeeds, checked above)
|
||||
wxFSWatchEntries::value_type val(watch->GetPath(), watch);
|
||||
return m_watches.insert(val).second;
|
||||
}
|
||||
|
||||
virtual bool Remove(const wxFSWatchInfo& winfo)
|
||||
{
|
||||
wxFSWatchEntries::iterator it = m_watches.find(winfo.GetPath());
|
||||
if ( it == m_watches.end() )
|
||||
{
|
||||
wxLogTrace(wxTRACE_FSWATCHER,
|
||||
"Path '%s' is not watched", winfo.GetPath());
|
||||
// This can happen if a dir is watched, then a parent tree added
|
||||
return true;
|
||||
}
|
||||
wxSharedPtr<wxFSWatchEntry> watch = it->second;
|
||||
m_watches.erase(it);
|
||||
return DoRemove(watch);
|
||||
}
|
||||
|
||||
virtual bool RemoveAll()
|
||||
{
|
||||
bool ret = true;
|
||||
for ( wxFSWatchEntries::iterator it = m_watches.begin();
|
||||
it != m_watches.end();
|
||||
++it )
|
||||
{
|
||||
if ( !DoRemove(it->second) )
|
||||
ret = false;
|
||||
}
|
||||
m_watches.clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Check whether any filespec matches the file's ext (if present)
|
||||
bool MatchesFilespec(const wxFileName& fn, const wxString& filespec) const
|
||||
{
|
||||
return filespec.empty() || wxMatchWild(filespec, fn.GetFullName());
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool DoAdd(wxSharedPtr<wxFSWatchEntry> watch) = 0;
|
||||
|
||||
virtual bool DoRemove(wxSharedPtr<wxFSWatchEntry> watch) = 0;
|
||||
|
||||
wxFSWatchEntries m_watches;
|
||||
wxFileSystemWatcherBase* m_watcher;
|
||||
};
|
||||
|
||||
|
||||
#endif /* WX_PRIVATE_FSWATCHER_H_ */
|
||||
25
wxheaders/wx/private/glibc.h
Normal file
25
wxheaders/wx/private/glibc.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/glibc.h
|
||||
// Purpose: glibc-specific private wx header
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2022-06-23
|
||||
// Copyright: (c) 2022 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_GLIBC_H_
|
||||
#define _WX_PRIVATE_GLIBC_H_
|
||||
|
||||
// Ensure that a header include __GLIBC__ is defined.
|
||||
#include <string.h>
|
||||
|
||||
// Macro for testing glibc version similar to wxCHECK_GCC_VERSION().
|
||||
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
|
||||
#define wxCHECK_GLIBC_VERSION( major, minor ) \
|
||||
( ( __GLIBC__ > (major) ) \
|
||||
|| ( __GLIBC__ == (major) && __GLIBC_MINOR__ >= (minor) ) )
|
||||
#else
|
||||
#define wxCHECK_GLIBC_VERSION( major, minor ) 0
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_GLIBC_H_
|
||||
168
wxheaders/wx/private/graphics.h
Normal file
168
wxheaders/wx/private/graphics.h
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/graphics.h
|
||||
// Purpose: private graphics context header
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created:
|
||||
// Copyright: (c) Stefan Csomor
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_GRAPHICS_PRIVATE_H_
|
||||
#define _WX_GRAPHICS_PRIVATE_H_
|
||||
|
||||
#if wxUSE_GRAPHICS_CONTEXT
|
||||
|
||||
#include "wx/graphics.h"
|
||||
|
||||
class WXDLLIMPEXP_CORE wxGraphicsObjectRefData : public wxObjectRefData
|
||||
{
|
||||
public :
|
||||
wxGraphicsObjectRefData( wxGraphicsRenderer* renderer );
|
||||
wxGraphicsObjectRefData( const wxGraphicsObjectRefData* data );
|
||||
wxGraphicsRenderer* GetRenderer() const ;
|
||||
virtual wxGraphicsObjectRefData* Clone() const ;
|
||||
|
||||
protected :
|
||||
wxGraphicsRenderer* m_renderer;
|
||||
} ;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxGraphicsBitmapData : public wxGraphicsObjectRefData
|
||||
{
|
||||
public :
|
||||
wxGraphicsBitmapData( wxGraphicsRenderer* renderer) :
|
||||
wxGraphicsObjectRefData(renderer) {}
|
||||
|
||||
virtual ~wxGraphicsBitmapData() {}
|
||||
|
||||
// returns the native representation
|
||||
virtual void * GetNativeBitmap() const = 0;
|
||||
} ;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxGraphicsMatrixData : public wxGraphicsObjectRefData
|
||||
{
|
||||
public :
|
||||
wxGraphicsMatrixData( wxGraphicsRenderer* renderer) :
|
||||
wxGraphicsObjectRefData(renderer) {}
|
||||
|
||||
virtual ~wxGraphicsMatrixData() {}
|
||||
|
||||
// concatenates the matrix
|
||||
virtual void Concat( const wxGraphicsMatrixData *t ) = 0;
|
||||
|
||||
// sets the matrix to the respective values
|
||||
virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
|
||||
wxDouble tx=0.0, wxDouble ty=0.0) = 0;
|
||||
|
||||
// gets the component values of the matrix
|
||||
virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
|
||||
wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const = 0;
|
||||
|
||||
// makes this the inverse matrix
|
||||
virtual void Invert() = 0;
|
||||
|
||||
// returns true if the elements of the transformation matrix are equal ?
|
||||
virtual bool IsEqual( const wxGraphicsMatrixData* t) const = 0;
|
||||
|
||||
// return true if this is the identity matrix
|
||||
virtual bool IsIdentity() const = 0;
|
||||
|
||||
//
|
||||
// transformation
|
||||
//
|
||||
|
||||
// add the translation to this matrix
|
||||
virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
|
||||
|
||||
// add the scale to this matrix
|
||||
virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
|
||||
|
||||
// add the rotation to this matrix (radians)
|
||||
virtual void Rotate( wxDouble angle ) = 0;
|
||||
|
||||
//
|
||||
// apply the transforms
|
||||
//
|
||||
|
||||
// applies that matrix to the point
|
||||
virtual void TransformPoint( wxDouble *x, wxDouble *y ) const = 0;
|
||||
|
||||
// applies the matrix except for translations
|
||||
virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const =0;
|
||||
|
||||
// returns the native representation
|
||||
virtual void * GetNativeMatrix() const = 0;
|
||||
} ;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxGraphicsPathData : public wxGraphicsObjectRefData
|
||||
{
|
||||
public :
|
||||
wxGraphicsPathData(wxGraphicsRenderer* renderer) : wxGraphicsObjectRefData(renderer) {}
|
||||
virtual ~wxGraphicsPathData() {}
|
||||
|
||||
//
|
||||
// These are the path primitives from which everything else can be constructed
|
||||
//
|
||||
|
||||
// begins a new subpath at (x,y)
|
||||
virtual void MoveToPoint( wxDouble x, wxDouble y ) = 0;
|
||||
|
||||
// adds a straight line from the current point to (x,y)
|
||||
virtual void AddLineToPoint( wxDouble x, wxDouble y ) = 0;
|
||||
|
||||
// adds a cubic Bezier curve from the current point, using two control points and an end point
|
||||
virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) = 0;
|
||||
|
||||
// adds another path
|
||||
virtual void AddPath( const wxGraphicsPathData* path ) =0;
|
||||
|
||||
// closes the current sub-path
|
||||
virtual void CloseSubpath() = 0;
|
||||
|
||||
// gets the last point of the current path, (0,0) if not yet set
|
||||
virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const = 0;
|
||||
|
||||
// adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
|
||||
virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) = 0;
|
||||
|
||||
//
|
||||
// These are convenience functions which - if not available natively will be assembled
|
||||
// using the primitives from above
|
||||
//
|
||||
|
||||
// adds a quadratic Bezier curve from the current point, using a control point and an end point
|
||||
virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
|
||||
|
||||
// appends a rectangle as a new closed subpath
|
||||
virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
|
||||
|
||||
// appends an ellipsis as a new closed subpath fitting the passed rectangle
|
||||
virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
|
||||
|
||||
// appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
|
||||
virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
|
||||
|
||||
// appends an ellipse
|
||||
virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
|
||||
|
||||
// appends a rounded rectangle
|
||||
virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
|
||||
|
||||
// returns the native path
|
||||
virtual void * GetNativePath() const = 0;
|
||||
|
||||
// give the native path returned by GetNativePath() back (there might be some deallocations necessary)
|
||||
virtual void UnGetNativePath(void *p) const= 0;
|
||||
|
||||
// transforms each point of this path by the matrix
|
||||
virtual void Transform( const wxGraphicsMatrixData* matrix ) =0;
|
||||
|
||||
// gets the bounding box enclosing all points (possibly including control points)
|
||||
virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const=0;
|
||||
|
||||
virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxODDEVEN_RULE) const=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _WX_GRAPHICS_PRIVATE_H_
|
||||
91
wxheaders/wx/private/icondir.h
Normal file
91
wxheaders/wx/private/icondir.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/icondir.h
|
||||
// Purpose: Declarations of structs used for loading MS icons
|
||||
// Author: wxWidgets team
|
||||
// Created: 2017-05-19
|
||||
// Copyright: (c) 2017 wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_ICONDIR_H_
|
||||
#define _WX_PRIVATE_ICONDIR_H_
|
||||
|
||||
#include "wx/defs.h" // wxUint* declarations
|
||||
|
||||
|
||||
// Structs declared here are used for loading group icons from
|
||||
// .ICO files or MS Windows resources.
|
||||
// Icon entry and directory structs for .ICO files and
|
||||
// MS Windows resources are very similar but not identical.
|
||||
|
||||
#if wxUSE_ICO_CUR
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
// icon entry in .ICO files
|
||||
struct ICONDIRENTRY
|
||||
{
|
||||
wxUint8 bWidth; // Width of the image
|
||||
wxUint8 bHeight; // Height of the image (times 2)
|
||||
wxUint8 bColorCount; // Number of colors in image (0 if >=8bpp)
|
||||
wxUint8 bReserved; // Reserved
|
||||
|
||||
// these two are different in icons and cursors:
|
||||
// icon or cursor
|
||||
wxUint16 wPlanes; // Color Planes or XHotSpot
|
||||
wxUint16 wBitCount; // Bits per pixel or YHotSpot
|
||||
|
||||
wxUint32 dwBytesInRes; // how many bytes in this resource?
|
||||
wxUint32 dwImageOffset; // where in the file is this image
|
||||
};
|
||||
|
||||
// icon directory in .ICO files
|
||||
struct ICONDIR
|
||||
{
|
||||
wxUint16 idReserved; // Reserved
|
||||
wxUint16 idType; // resource type (1 for icons, 2 for cursors)
|
||||
wxUint16 idCount; // how many images?
|
||||
};
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(2)
|
||||
|
||||
// icon entry in MS Windows resources
|
||||
struct GRPICONDIRENTRY
|
||||
{
|
||||
wxUint8 bWidth; // Width of the image
|
||||
wxUint8 bHeight; // Height of the image (times 2)
|
||||
wxUint8 bColorCount; // Number of colors in image (0 if >=8bpp)
|
||||
wxUint8 bReserved; // Reserved
|
||||
|
||||
// these two are different in icons and cursors:
|
||||
// icon or cursor
|
||||
wxUint16 wPlanes; // Color Planes or XHotSpot
|
||||
wxUint16 wBitCount; // Bits per pixel or YHotSpot
|
||||
|
||||
wxUint32 dwBytesInRes; // how many bytes in this resource?
|
||||
|
||||
wxUint16 nID; // actual icon resource ID
|
||||
};
|
||||
|
||||
// icon directory in MS Windows resources
|
||||
struct GRPICONDIR
|
||||
{
|
||||
wxUint16 idReserved; // Reserved
|
||||
wxUint16 idType; // resource type (1 for icons, 2 for cursors)
|
||||
wxUint16 idCount; // how many images?
|
||||
GRPICONDIRENTRY idEntries[1]; // The entries for each image
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif // __WINDOWS__
|
||||
|
||||
#endif // wxUSE_ICO_CUR
|
||||
|
||||
#endif // _WX_PRIVATE_ICONDIR_H_
|
||||
88
wxheaders/wx/private/json.h
Normal file
88
wxheaders/wx/private/json.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/json.h
|
||||
// Purpose: Helper functions to handle JSON data
|
||||
// Author: Tobias Taschner
|
||||
// Created: 2020-01-17
|
||||
// Copyright: (c) 2020 wxWidgets development team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_JSON_H_
|
||||
#define _WX_PRIVATE_JSON_H_
|
||||
|
||||
namespace wxJSON
|
||||
{
|
||||
|
||||
// Decode a string literal including escape sequences
|
||||
// Returns false if the input string is not a valid JSON string
|
||||
bool DecodeString(const wxString& in, wxString* out)
|
||||
{
|
||||
const wxWCharBuffer buf = in.wc_str();
|
||||
const wchar_t* ch = buf.data();
|
||||
// String has to chart with a quote
|
||||
if (*(ch++) != '"')
|
||||
return false;
|
||||
out->clear();
|
||||
out->reserve(buf.length());
|
||||
const wchar_t* end = buf.data() + buf.length() - 1;
|
||||
for (; ch < end; ++ch)
|
||||
{
|
||||
if (*ch == '\\')
|
||||
{
|
||||
switch (*(++ch))
|
||||
{
|
||||
case 'b':
|
||||
out->append('\b');
|
||||
break;
|
||||
case 'n':
|
||||
out->append('\n');
|
||||
break;
|
||||
case 'r':
|
||||
out->append('\r');
|
||||
break;
|
||||
case 't':
|
||||
out->append('\t');
|
||||
break;
|
||||
case 'f':
|
||||
out->append('\f');
|
||||
break;
|
||||
case '/':
|
||||
out->append('/');
|
||||
break;
|
||||
case '"':
|
||||
out->append('"');
|
||||
break;
|
||||
case '\\':
|
||||
out->append('\\');
|
||||
break;
|
||||
case 'u':
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
// In this case, we handle surrogates without doing anything special was wchar_t strings use UTF-17 encoding.
|
||||
if (wxIsxdigit(ch[1]) && wxIsxdigit(ch[2]) &&
|
||||
wxIsxdigit(ch[3]) && wxIsxdigit(ch[4]))
|
||||
{
|
||||
wchar_t uchar = wxHexToDec(wxString(&ch[3], 2)) |
|
||||
wxHexToDec(wxString(&ch[1], 2)) >> 8;
|
||||
out->append(uchar);
|
||||
ch += 4;
|
||||
}
|
||||
#else
|
||||
#error Implement correct surrogate handling.
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
out->append(*ch);
|
||||
}
|
||||
|
||||
// String has to end with a quote
|
||||
return (*ch) == '"';
|
||||
}
|
||||
|
||||
} // namespace JSON
|
||||
|
||||
#endif // _WX_PRIVATE_JSON_H_
|
||||
208
wxheaders/wx/private/jsscriptwrapper.h
Normal file
208
wxheaders/wx/private/jsscriptwrapper.h
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/jsscriptwrapper.h
|
||||
// Purpose: JS Script Wrapper for wxWebView
|
||||
// Author: Jose Lorenzo
|
||||
// Created: 2017-08-12
|
||||
// Copyright: (c) 2017 Jose Lorenzo <josee.loren@gmail.com>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_JSSCRIPTWRAPPER_H_
|
||||
#define _WX_PRIVATE_JSSCRIPTWRAPPER_H_
|
||||
|
||||
#include "wx/regex.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Helper for wxWebView::RunScript()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This class provides GetWrappedCode(), GetOutputCode() and GetCleanUpCode()
|
||||
// functions that should be executed in the backend-appropriate way by each
|
||||
// wxWebView implementation in order to actually execute the user-provided
|
||||
// JavaScript code, retrieve its result (if it executed successfully) and
|
||||
// perform the cleanup at the end.
|
||||
class wxJSScriptWrapper
|
||||
{
|
||||
public:
|
||||
enum OutputType
|
||||
{
|
||||
JS_OUTPUT_STRING, // All return types are converted to a string
|
||||
JS_OUTPUT_WEBKIT, // Some return types will be processed
|
||||
JS_OUTPUT_IE, // Most return types will be processed
|
||||
JS_OUTPUT_RAW // The return types is returned as is
|
||||
};
|
||||
|
||||
wxJSScriptWrapper(const wxString& js, OutputType outputType)
|
||||
: m_escapedCode(js), m_outputType(outputType)
|
||||
{
|
||||
// Adds one escape level.
|
||||
const char *charsNeededToBeEscaped = "\\\"\n\r\v\t\b\f";
|
||||
for (
|
||||
size_t pos = m_escapedCode.find_first_of(charsNeededToBeEscaped, 0);
|
||||
pos != wxString::npos;
|
||||
pos = m_escapedCode.find_first_of(charsNeededToBeEscaped, pos)
|
||||
) {
|
||||
switch (m_escapedCode[pos].GetValue())
|
||||
{
|
||||
case 0x0A: // '\n'
|
||||
m_escapedCode[pos] = 'n';
|
||||
break;
|
||||
case 0x0D: // '\r'
|
||||
m_escapedCode[pos] = 'r';
|
||||
break;
|
||||
case 0x0B: // '\v'
|
||||
m_escapedCode[pos] = 'v';
|
||||
break;
|
||||
case 0x09: // '\t'
|
||||
m_escapedCode[pos] = 't';
|
||||
break;
|
||||
case 0x08: // '\b'
|
||||
m_escapedCode[pos] = 'b';
|
||||
break;
|
||||
case 0x0C: // '\f'
|
||||
m_escapedCode[pos] = 'f';
|
||||
break;
|
||||
}
|
||||
m_escapedCode.insert(pos, '\\');
|
||||
pos += 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the code to execute, its returned value will be either the value,
|
||||
// if it executed successfully, or the exception message prefixed with
|
||||
// "__wxexc:" if an error occurred.
|
||||
//
|
||||
// Either use SetOutput() to specify the script result or access it directly
|
||||
// Using GetOutputRef()
|
||||
//
|
||||
// Execute ExtractOutput() later to get the real output after successful
|
||||
// execution of this code or the proper error message.
|
||||
wxString GetWrappedCode() const
|
||||
{
|
||||
wxString code = wxString::Format(
|
||||
wxASCII_STR("(function () { try { var res = eval(\"%s\"); "),
|
||||
m_escapedCode);
|
||||
|
||||
switch (m_outputType)
|
||||
{
|
||||
case JS_OUTPUT_STRING:
|
||||
code += wxASCII_STR(
|
||||
"if (typeof res == 'object') return JSON.stringify(res);"
|
||||
"else if (typeof res == 'undefined') return 'undefined';"
|
||||
"else return String(res);"
|
||||
);
|
||||
break;
|
||||
case JS_OUTPUT_WEBKIT:
|
||||
code += wxASCII_STR(
|
||||
"if (typeof res == 'object') return JSON.stringify(res);"
|
||||
"else if (typeof res == 'undefined') return 'undefined';"
|
||||
"else return res;"
|
||||
);
|
||||
break;
|
||||
case JS_OUTPUT_IE:
|
||||
code += wxASCII_STR(
|
||||
"try {"
|
||||
"return (res == null || typeof res != 'object') ? String(res)"
|
||||
": JSON.stringify(res);"
|
||||
"}"
|
||||
"catch (e) {"
|
||||
"try {"
|
||||
"function __wx$stringifyJSON(obj) {"
|
||||
"if (!(obj instanceof Object))"
|
||||
"return typeof obj === \"string\""
|
||||
"? \'\"\' + obj + \'\"\'"
|
||||
": \'\' + obj;"
|
||||
"else if (obj instanceof Array) {"
|
||||
"if (obj[0] === undefined)"
|
||||
"return \'[]\';"
|
||||
"else {"
|
||||
"var arr = [];"
|
||||
"for (var i = 0; i < obj.length; i++)"
|
||||
"arr.push(__wx$stringifyJSON(obj[i]));"
|
||||
"return \'[\' + arr + \']\';"
|
||||
"}"
|
||||
"}"
|
||||
"else if (typeof obj === \"object\") {"
|
||||
"if (obj instanceof Date) {"
|
||||
"if (!Date.prototype.toISOString) {"
|
||||
"(function() {"
|
||||
"function pad(number) {"
|
||||
"return number < 10"
|
||||
"? '0' + number"
|
||||
": number;"
|
||||
"}"
|
||||
"Date.prototype.toISOString = function() {"
|
||||
"return this.getUTCFullYear() +"
|
||||
"'-' + pad(this.getUTCMonth() + 1) +"
|
||||
"'-' + pad(this.getUTCDate()) +"
|
||||
"'T' + pad(this.getUTCHours()) +"
|
||||
"':' + pad(this.getUTCMinutes()) +"
|
||||
"':' + pad(this.getUTCSeconds()) +"
|
||||
"'.' + (this.getUTCMilliseconds() / 1000)"
|
||||
".toFixed(3).slice(2, 5) + 'Z\"';"
|
||||
"};"
|
||||
"}());"
|
||||
"}"
|
||||
"return '\"' + obj.toISOString(); + '\"'"
|
||||
"}"
|
||||
"var objElements = [];"
|
||||
"for (var key in obj)"
|
||||
"{"
|
||||
"if (typeof obj[key] === \"function\")"
|
||||
"return \'{}\';"
|
||||
"else {"
|
||||
"objElements.push(\'\"\'"
|
||||
"+ key + \'\":\' +"
|
||||
"__wx$stringifyJSON(obj[key]));"
|
||||
"}"
|
||||
"}"
|
||||
"return \'{\' + objElements + \'}\';"
|
||||
"}"
|
||||
"}"
|
||||
"return __wx$stringifyJSON(res);"
|
||||
"}"
|
||||
"catch (e) { return \"__wxexc:\" + e.name + \": \" + e.message; }"
|
||||
"}");
|
||||
break;
|
||||
case JS_OUTPUT_RAW:
|
||||
code += wxASCII_STR("return res;");
|
||||
break;
|
||||
}
|
||||
|
||||
code +=
|
||||
wxASCII_STR("} catch (e) { return \"__wxexc:\" + e.name + \": \" + e.message; }"
|
||||
"})()");
|
||||
return code;
|
||||
}
|
||||
|
||||
// Extract the output value
|
||||
//
|
||||
// Returns true if executed successfully
|
||||
// string of the result will be put into output
|
||||
// Returns false when an exception occurred
|
||||
// string will be the exception message
|
||||
static bool ExtractOutput(const wxString& result, wxString* output)
|
||||
{
|
||||
if (output)
|
||||
*output = result;
|
||||
|
||||
if (result.starts_with(wxASCII_STR("__wxexc:")))
|
||||
{
|
||||
if (output)
|
||||
output->Remove(0, 8);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
wxString m_escapedCode;
|
||||
OutputType m_outputType;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxJSScriptWrapper);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_JSSCRIPTWRAPPER_H_
|
||||
43
wxheaders/wx/private/launchbrowser.h
Normal file
43
wxheaders/wx/private/launchbrowser.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/launchbrowser.h
|
||||
// Purpose: Helpers for wxLaunchDefaultBrowser() implementation.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2016-02-07
|
||||
// Copyright: (c) 2016 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_LAUNCHBROWSER_H_
|
||||
#define _WX_PRIVATE_LAUNCHBROWSER_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxLaunchBrowserParams: passed to wxDoLaunchDefaultBrowser()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
struct wxLaunchBrowserParams
|
||||
{
|
||||
explicit wxLaunchBrowserParams(int f) : flags(f) { }
|
||||
|
||||
// Return either the URL or the file depending on our scheme.
|
||||
const wxString& GetPathOrURL() const
|
||||
{
|
||||
return scheme == wxS("file") ? path : url;
|
||||
}
|
||||
|
||||
|
||||
// The URL is always specified and is the real URL, always with the scheme
|
||||
// part, which can be "file://".
|
||||
wxString url;
|
||||
|
||||
// The path is a local path which is only non-empty if the URL uses the
|
||||
// "file://" scheme.
|
||||
wxString path;
|
||||
|
||||
// The scheme of the URL, e.g. "file" or "http".
|
||||
wxString scheme;
|
||||
|
||||
// The flags passed to wxLaunchDefaultBrowser().
|
||||
int flags;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_LAUNCHBROWSER_H_
|
||||
49
wxheaders/wx/private/localeset.h
Normal file
49
wxheaders/wx/private/localeset.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/localeset.h
|
||||
// Purpose: Define helper wxLocaleSetter class.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2021-08-03 (extracted from tests/testprec.h)
|
||||
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_LOCALESET_H_
|
||||
#define _WX_PRIVATE_LOCALESET_H_
|
||||
|
||||
#include "wx/crt.h" // wxStrdupA()
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
// Helper class setting the locale to the given one for its lifetime.
|
||||
class wxLocaleSetter
|
||||
{
|
||||
public:
|
||||
wxLocaleSetter(const char *loc)
|
||||
: m_locOld(wxStrdupA(setlocale(LC_ALL, NULL)))
|
||||
{
|
||||
setlocale(LC_ALL, loc);
|
||||
}
|
||||
|
||||
~wxLocaleSetter()
|
||||
{
|
||||
setlocale(LC_ALL, m_locOld);
|
||||
free(m_locOld);
|
||||
}
|
||||
|
||||
private:
|
||||
char * const m_locOld;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxLocaleSetter);
|
||||
};
|
||||
|
||||
// An even simpler helper for setting the locale to "C" one during its lifetime.
|
||||
class wxCLocaleSetter : private wxLocaleSetter
|
||||
{
|
||||
public:
|
||||
wxCLocaleSetter() : wxLocaleSetter("C") { }
|
||||
|
||||
private:
|
||||
wxDECLARE_NO_COPY_CLASS(wxCLocaleSetter);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_LOCALESET_H_
|
||||
176
wxheaders/wx/private/markupparser.h
Normal file
176
wxheaders/wx/private/markupparser.h
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/markupparser.h
|
||||
// Purpose: Classes for parsing simple markup.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-02-16
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_MARKUPPARSER_H_
|
||||
#define _WX_PRIVATE_MARKUPPARSER_H_
|
||||
|
||||
#include "wx/string.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMarkupSpanAttributes: information about attributes for a markup span.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
struct wxMarkupSpanAttributes
|
||||
{
|
||||
enum OptionalBool
|
||||
{
|
||||
Unspecified = -1,
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
|
||||
wxMarkupSpanAttributes()
|
||||
{
|
||||
m_sizeKind = Size_Unspecified;
|
||||
|
||||
m_isBold =
|
||||
m_isItalic =
|
||||
m_isUnderlined =
|
||||
m_isStrikethrough = Unspecified;
|
||||
}
|
||||
|
||||
// If a string is empty, it means that the corresponding attribute is not
|
||||
// set.
|
||||
wxString m_fgCol,
|
||||
m_bgCol,
|
||||
m_fontFace;
|
||||
|
||||
// There are many ways of specifying the size. First of all, the size may
|
||||
// be relative in which case m_fontSize is either -1 or +1 meaning that
|
||||
// it's one step smaller or larger than the current font. Second, it may be
|
||||
// absolute in which case m_fontSize contains either the size in 1024th of
|
||||
// a point (Pango convention) or its values are in [-3, 3] interval and map
|
||||
// to [xx-small, xx-large] CSS-like font size specification. And finally it
|
||||
// may be not specified at all, of course, in which case the value of
|
||||
// m_fontSize doesn't matter and it shouldn't be used.
|
||||
enum
|
||||
{
|
||||
Size_Unspecified,
|
||||
Size_Relative,
|
||||
Size_Symbolic,
|
||||
Size_PointParts
|
||||
} m_sizeKind;
|
||||
int m_fontSize;
|
||||
|
||||
// If the value is Unspecified, the attribute wasn't given.
|
||||
OptionalBool m_isBold,
|
||||
m_isItalic,
|
||||
m_isUnderlined,
|
||||
m_isStrikethrough;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMarkupParserOutput: gathers the results of parsing markup.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// A class deriving directly from this one needs to implement all the pure
|
||||
// virtual functions below but as the handling of all simple tags (bold, italic
|
||||
// &c) is often very similar, it is usually more convenient to inherit from
|
||||
// wxMarkupParserFontOutput defined in wx/private/markupparserfont.h instead.
|
||||
class wxMarkupParserOutput
|
||||
{
|
||||
public:
|
||||
wxMarkupParserOutput() { }
|
||||
virtual ~wxMarkupParserOutput() { }
|
||||
|
||||
// Virtual functions called by wxMarkupParser while parsing the markup.
|
||||
|
||||
// Called for a run of normal text.
|
||||
virtual void OnText(const wxString& text) = 0;
|
||||
|
||||
// These functions correspond to the simple tags without parameters.
|
||||
virtual void OnBoldStart() = 0;
|
||||
virtual void OnBoldEnd() = 0;
|
||||
|
||||
virtual void OnItalicStart() = 0;
|
||||
virtual void OnItalicEnd() = 0;
|
||||
|
||||
virtual void OnUnderlinedStart() = 0;
|
||||
virtual void OnUnderlinedEnd() = 0;
|
||||
|
||||
virtual void OnStrikethroughStart() = 0;
|
||||
virtual void OnStrikethroughEnd() = 0;
|
||||
|
||||
virtual void OnBigStart() = 0;
|
||||
virtual void OnBigEnd() = 0;
|
||||
|
||||
virtual void OnSmallStart() = 0;
|
||||
virtual void OnSmallEnd() = 0;
|
||||
|
||||
virtual void OnTeletypeStart() = 0;
|
||||
virtual void OnTeletypeEnd() = 0;
|
||||
|
||||
// The generic span start and end functions.
|
||||
virtual void OnSpanStart(const wxMarkupSpanAttributes& attrs) = 0;
|
||||
virtual void OnSpanEnd(const wxMarkupSpanAttributes& attrs) = 0;
|
||||
|
||||
private:
|
||||
wxDECLARE_NO_COPY_CLASS(wxMarkupParserOutput);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMarkupParser: parses the given markup text into wxMarkupParserOutput.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_CORE wxMarkupParser
|
||||
{
|
||||
public:
|
||||
// Initialize the parser with the object that will receive parsing results.
|
||||
// This object lifetime must be greater than ours.
|
||||
explicit wxMarkupParser(wxMarkupParserOutput& output)
|
||||
: m_output(output)
|
||||
{
|
||||
}
|
||||
|
||||
// Parse the entire string and call wxMarkupParserOutput methods.
|
||||
//
|
||||
// Return true if the string was successfully parsed or false if it failed
|
||||
// (presumably because of syntax errors in the markup).
|
||||
bool Parse(const wxString& text);
|
||||
|
||||
// Quote a normal string, not meant to be interpreted as markup, so that it
|
||||
// produces the same string when parsed as markup. This means, for example,
|
||||
// replacing '<' in the input string with "<" to prevent them from being
|
||||
// interpreted as tag opening characters.
|
||||
static wxString Quote(const wxString& text);
|
||||
|
||||
// Strip markup from a string, i.e. simply remove all tags and replace
|
||||
// XML entities with their values (or with "&&" in case of "&" to
|
||||
// prevent it from being interpreted as mnemonic marker).
|
||||
static wxString Strip(const wxString& text);
|
||||
|
||||
private:
|
||||
// Simple struct combining the name of a tag and its attributes.
|
||||
struct TagAndAttrs
|
||||
{
|
||||
TagAndAttrs(const wxString& name_) : name(name_) { }
|
||||
|
||||
wxString name;
|
||||
wxMarkupSpanAttributes attrs;
|
||||
};
|
||||
|
||||
// Call the wxMarkupParserOutput method corresponding to the given tag.
|
||||
//
|
||||
// Return false if the tag doesn't match any of the known ones.
|
||||
bool OutputTag(const TagAndAttrs& tagAndAttrs, bool start);
|
||||
|
||||
// Parse the attributes and fill the provided TagAndAttrs object with the
|
||||
// information about them. Does nothing if attrs string is empty.
|
||||
//
|
||||
// Returns empty string on success of a [fragment of an] error message if
|
||||
// we failed to parse the attributes.
|
||||
wxString ParseAttrs(wxString attrs, TagAndAttrs& tagAndAttrs);
|
||||
|
||||
|
||||
wxMarkupParserOutput& m_output;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxMarkupParser);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_MARKUPPARSER_H_
|
||||
256
wxheaders/wx/private/markupparserattr.h
Normal file
256
wxheaders/wx/private/markupparserattr.h
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/markupparserattr.h
|
||||
// Purpose: Classes mapping markup attributes to wxFont/wxColour.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-02-18
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_MARKUPPARSERATTR_H_
|
||||
#define _WX_PRIVATE_MARKUPPARSERATTR_H_
|
||||
|
||||
#include "wx/private/markupparser.h"
|
||||
|
||||
#include "wx/stack.h"
|
||||
|
||||
#include "wx/colour.h"
|
||||
#include "wx/font.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMarkupParserAttrOutput: simplified wxFont-using version of the above.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This class assumes that wxFont and wxColour are used to perform all the
|
||||
// markup tags and implements the base class virtual functions in terms of
|
||||
// OnAttr{Start,End}() only.
|
||||
//
|
||||
// Notice that you still must implement OnText() inherited from the base class
|
||||
// when deriving from this one.
|
||||
class wxMarkupParserAttrOutput : public wxMarkupParserOutput
|
||||
{
|
||||
public:
|
||||
// A container of font and colours with inheritance support. It holds two
|
||||
// sets of attributes:
|
||||
// 1. The currently specified ones from parsed tags that contain
|
||||
// information on what should change in the output; some of them
|
||||
// may be invalid if only the others are affected by a change.
|
||||
// 2. The _effective_ attributes that are always valid and accumulate
|
||||
// all past changes as the markup is being parser; these are used
|
||||
// to restore state when unwinding nested attributes.
|
||||
struct Attr
|
||||
{
|
||||
Attr(const Attr *attrInEffect,
|
||||
const wxFont& font_,
|
||||
const wxColour& foreground_ = wxColour(),
|
||||
const wxColour& background_ = wxColour())
|
||||
: font(font_), foreground(foreground_), background(background_)
|
||||
{
|
||||
if (attrInEffect)
|
||||
{
|
||||
effectiveFont = font.IsOk() ? font : attrInEffect->effectiveFont;
|
||||
effectiveForeground = foreground_.IsOk() ? foreground_ : attrInEffect->effectiveForeground;
|
||||
effectiveBackground = background.IsOk() ? background : attrInEffect->effectiveBackground;
|
||||
}
|
||||
else
|
||||
{
|
||||
effectiveFont = font;
|
||||
effectiveForeground = foreground;
|
||||
effectiveBackground = background;
|
||||
}
|
||||
}
|
||||
|
||||
wxFont font;
|
||||
wxColour foreground,
|
||||
background;
|
||||
wxFont effectiveFont;
|
||||
wxColour effectiveForeground,
|
||||
effectiveBackground;
|
||||
};
|
||||
|
||||
|
||||
// This object must be initialized with the font and colours to use
|
||||
// initially, i.e. the ones used before any tags in the string.
|
||||
wxMarkupParserAttrOutput(const wxFont& font,
|
||||
const wxColour& foreground,
|
||||
const wxColour& background)
|
||||
{
|
||||
m_attrs.push(Attr(NULL, font, foreground, background));
|
||||
}
|
||||
|
||||
// Indicates the change of the font and/or colours used. Any of the
|
||||
// fields of the argument may be invalid indicating that the corresponding
|
||||
// attribute didn't actually change.
|
||||
virtual void OnAttrStart(const Attr& attr) = 0;
|
||||
|
||||
// Indicates the end of the region affected by the given attributes
|
||||
// (the same ones that were passed to the matching OnAttrStart(), use
|
||||
// GetAttr() to get the ones that will be used from now on).
|
||||
virtual void OnAttrEnd(const Attr& attr) = 0;
|
||||
|
||||
|
||||
// Implement all pure virtual methods inherited from the base class in
|
||||
// terms of our own ones.
|
||||
virtual void OnBoldStart() wxOVERRIDE { DoChangeFont(&wxFont::Bold); }
|
||||
virtual void OnBoldEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnItalicStart() wxOVERRIDE { DoChangeFont(&wxFont::Italic); }
|
||||
virtual void OnItalicEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnUnderlinedStart() wxOVERRIDE { DoChangeFont(&wxFont::Underlined); }
|
||||
virtual void OnUnderlinedEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnStrikethroughStart() wxOVERRIDE { DoChangeFont(&wxFont::Strikethrough); }
|
||||
virtual void OnStrikethroughEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnBigStart() wxOVERRIDE { DoChangeFont(&wxFont::Larger); }
|
||||
virtual void OnBigEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnSmallStart() wxOVERRIDE { DoChangeFont(&wxFont::Smaller); }
|
||||
virtual void OnSmallEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnTeletypeStart() wxOVERRIDE
|
||||
{
|
||||
wxFont font(GetFont());
|
||||
font.SetFamily(wxFONTFAMILY_TELETYPE);
|
||||
DoSetFont(font);
|
||||
}
|
||||
virtual void OnTeletypeEnd() wxOVERRIDE { DoEndAttr(); }
|
||||
|
||||
virtual void OnSpanStart(const wxMarkupSpanAttributes& spanAttr) wxOVERRIDE
|
||||
{
|
||||
wxFont font(GetFont());
|
||||
if ( !spanAttr.m_fontFace.empty() )
|
||||
font.SetFaceName(spanAttr.m_fontFace);
|
||||
|
||||
FontModifier<wxFontWeight>()(spanAttr.m_isBold,
|
||||
font, &wxFont::SetWeight,
|
||||
wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_BOLD);
|
||||
|
||||
FontModifier<wxFontStyle>()(spanAttr.m_isItalic,
|
||||
font, &wxFont::SetStyle,
|
||||
wxFONTSTYLE_NORMAL, wxFONTSTYLE_ITALIC);
|
||||
|
||||
FontModifier<bool>()(spanAttr.m_isUnderlined,
|
||||
font, &wxFont::SetUnderlined,
|
||||
false, true);
|
||||
|
||||
FontModifier<bool>()(spanAttr.m_isStrikethrough,
|
||||
font, &wxFont::SetStrikethrough,
|
||||
false, true);
|
||||
|
||||
switch ( spanAttr.m_sizeKind )
|
||||
{
|
||||
case wxMarkupSpanAttributes::Size_Unspecified:
|
||||
break;
|
||||
|
||||
case wxMarkupSpanAttributes::Size_Relative:
|
||||
if ( spanAttr.m_fontSize > 0 )
|
||||
font.MakeLarger();
|
||||
else
|
||||
font.MakeSmaller();
|
||||
break;
|
||||
|
||||
case wxMarkupSpanAttributes::Size_Symbolic:
|
||||
// The values of font size intentionally coincide with the
|
||||
// values of wxFontSymbolicSize enum elements so simply cast
|
||||
// one to the other.
|
||||
font.SetSymbolicSize(
|
||||
static_cast<wxFontSymbolicSize>(spanAttr.m_fontSize)
|
||||
);
|
||||
break;
|
||||
|
||||
case wxMarkupSpanAttributes::Size_PointParts:
|
||||
font.SetFractionalPointSize(spanAttr.m_fontSize/1024.);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
const Attr attr(&m_attrs.top(), font, spanAttr.m_fgCol, spanAttr.m_bgCol);
|
||||
OnAttrStart(attr);
|
||||
|
||||
m_attrs.push(attr);
|
||||
}
|
||||
|
||||
virtual void OnSpanEnd(const wxMarkupSpanAttributes& WXUNUSED(spanAttr)) wxOVERRIDE
|
||||
{
|
||||
DoEndAttr();
|
||||
}
|
||||
|
||||
protected:
|
||||
// Get the current attributes, i.e. the ones that should be used for
|
||||
// rendering (or measuring or whatever) the text at the current position in
|
||||
// the string.
|
||||
//
|
||||
// It may be called from OnAttrStart() to get the old attributes used
|
||||
// before and from OnAttrEnd() to get the new attributes that will be used
|
||||
// from now on but is mostly meant to be used from overridden OnText()
|
||||
// implementations.
|
||||
const Attr& GetAttr() const { return m_attrs.top(); }
|
||||
|
||||
// A shortcut for accessing the font of the current attribute.
|
||||
const wxFont& GetFont() const { return GetAttr().font; }
|
||||
|
||||
private:
|
||||
// Change only the font to the given one. Call OnAttrStart() to notify
|
||||
// about the change and update the attributes stack.
|
||||
void DoSetFont(const wxFont& font)
|
||||
{
|
||||
const Attr attr(&m_attrs.top(), font);
|
||||
|
||||
OnAttrStart(attr);
|
||||
|
||||
m_attrs.push(attr);
|
||||
}
|
||||
|
||||
// Apply the given function to the font currently on top of the font stack,
|
||||
// push the new font on the stack and call OnAttrStart() with it.
|
||||
void DoChangeFont(wxFont (wxFont::*func)() const)
|
||||
{
|
||||
DoSetFont((GetFont().*func)());
|
||||
}
|
||||
|
||||
void DoEndAttr()
|
||||
{
|
||||
const Attr attr(m_attrs.top());
|
||||
m_attrs.pop();
|
||||
|
||||
OnAttrEnd(attr);
|
||||
}
|
||||
|
||||
// A helper class used to apply the given function to a wxFont object
|
||||
// depending on the value of an OptionalBool.
|
||||
template <typename T>
|
||||
struct FontModifier
|
||||
{
|
||||
FontModifier() { }
|
||||
|
||||
void operator()(wxMarkupSpanAttributes::OptionalBool isIt,
|
||||
wxFont& font,
|
||||
void (wxFont::*func)(T),
|
||||
T noValue,
|
||||
T yesValue)
|
||||
{
|
||||
switch ( isIt )
|
||||
{
|
||||
case wxMarkupSpanAttributes::Unspecified:
|
||||
break;
|
||||
|
||||
case wxMarkupSpanAttributes::No:
|
||||
(font.*func)(noValue);
|
||||
break;
|
||||
|
||||
case wxMarkupSpanAttributes::Yes:
|
||||
(font.*func)(yesValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
wxStack<Attr> m_attrs;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxMarkupParserAttrOutput);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_MARKUPPARSERATTR_H_
|
||||
216
wxheaders/wx/private/menuradio.h
Normal file
216
wxheaders/wx/private/menuradio.h
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/menuradio.h
|
||||
// Purpose: wxMenuRadioItemsData implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified: Artur Wieczorek: added UpdateOnInsertNonRadio()
|
||||
// Created: 2017-08-12
|
||||
// Copyright: (c) 2011 Vadim Zeitlin et al
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef WX_PRIVATE_MENURADIO_H_
|
||||
#define WX_PRIVATE_MENURADIO_H_
|
||||
|
||||
#include "wx/vector.h"
|
||||
|
||||
// Contains the data about the radio items groups in the given menu.
|
||||
class wxMenuRadioItemsData
|
||||
{
|
||||
public:
|
||||
wxMenuRadioItemsData() { }
|
||||
|
||||
// Default copy ctor, assignment operator and dtor are all ok.
|
||||
|
||||
// Find the start and end of the group containing the given position or
|
||||
// return false if it's not inside any range.
|
||||
bool GetGroupRange(int pos, int *start, int *end) const
|
||||
{
|
||||
// We use a simple linear search here because there are not that many
|
||||
// items in a menu and hence even fewer radio items ranges anyhow, so
|
||||
// normally there is no need to do anything fancy (like keeping the
|
||||
// array sorted and using binary search).
|
||||
for ( Ranges::const_iterator it = m_ranges.begin();
|
||||
it != m_ranges.end();
|
||||
++it )
|
||||
{
|
||||
const Range& r = *it;
|
||||
|
||||
if ( r.start <= pos && pos <= r.end )
|
||||
{
|
||||
if ( start )
|
||||
*start = r.start;
|
||||
if ( end )
|
||||
*end = r.end;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Take into account the new radio item about to be added at the given
|
||||
// position. The are two cases to handle:
|
||||
// - If item precedes the range, the range indices have to be updated.
|
||||
// - If item falls inside the range, this range is extended to include
|
||||
// the item.
|
||||
// Returns true if this item starts a new radio group, false if it extends
|
||||
// an existing one.
|
||||
bool UpdateOnInsertRadio(int pos)
|
||||
{
|
||||
bool inExistingGroup = false;
|
||||
|
||||
for ( Ranges::iterator it = m_ranges.begin();
|
||||
it != m_ranges.end();
|
||||
++it )
|
||||
{
|
||||
Range& r = *it;
|
||||
|
||||
if ( pos < r.start )
|
||||
{
|
||||
// Item is inserted before this range, update its indices.
|
||||
r.start++;
|
||||
r.end++;
|
||||
}
|
||||
else if ( pos <= r.end + 1 )
|
||||
{
|
||||
wxASSERT_MSG(!inExistingGroup,
|
||||
wxS("Item already inserted inside another range"));
|
||||
// Item is inserted in the middle of this range or immediately
|
||||
// after it in which case it extends this range so make it span
|
||||
// one more item in any case.
|
||||
r.end++;
|
||||
|
||||
inExistingGroup = true;
|
||||
}
|
||||
//else: Item is inserted after this range, nothing to do for it.
|
||||
}
|
||||
|
||||
if ( inExistingGroup )
|
||||
return false;
|
||||
|
||||
// Make a new range for the group this item will belong to.
|
||||
Range r;
|
||||
r.start = pos;
|
||||
r.end = pos;
|
||||
m_ranges.push_back(r);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Take into account the new non-radio item about to be added at the given
|
||||
// position. The are two cases to handle:
|
||||
// - If item precedes the range, the range indices have to be updated.
|
||||
// - If item falls inside the range, this range has to be split into
|
||||
// two new ranges.
|
||||
// Returns true if existing group has been split into two subgroups.
|
||||
bool UpdateOnInsertNonRadio(int pos)
|
||||
{
|
||||
bool wasSplit = false;
|
||||
Range newRange;
|
||||
|
||||
for ( Ranges::iterator it = m_ranges.begin();
|
||||
it != m_ranges.end();
|
||||
++it )
|
||||
{
|
||||
Range& r = *it;
|
||||
|
||||
if ( pos <= r.start )
|
||||
{
|
||||
// Item is inserted before this range or just at its start,
|
||||
// update its indices.
|
||||
r.start++;
|
||||
r.end++;
|
||||
}
|
||||
else if ( pos <= r.end )
|
||||
{
|
||||
wxASSERT_MSG(!wasSplit,
|
||||
wxS("Item already inserted inside another range"));
|
||||
// Item is inserted inside this range in which case
|
||||
// it breaks the range into two parts: one ending before
|
||||
// the item and one started after it.
|
||||
|
||||
// The new range after the item has to be stored and added to the list
|
||||
// after finishing the iteration through the ranges.
|
||||
newRange.start = pos + 1; // start after the item
|
||||
newRange.end = r.end + 1; // inherits current end "moved up" by one item
|
||||
wasSplit = true;
|
||||
// Current range ends just before the item position.
|
||||
r.end = pos - 1;
|
||||
}
|
||||
//else: Item is inserted after this range, nothing to do for it.
|
||||
}
|
||||
|
||||
if ( !wasSplit )
|
||||
return false;
|
||||
|
||||
// Add a split range to the list.
|
||||
m_ranges.push_back(newRange);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update the ranges of the existing radio groups after removing the menu
|
||||
// item at the given position.
|
||||
//
|
||||
// The item being removed can be the item of any kind, not only the radio
|
||||
// button belonging to the radio group, and this function checks for it
|
||||
// and, as a side effect, returns true if this item was found inside an
|
||||
// existing radio group.
|
||||
bool UpdateOnRemoveItem(int pos)
|
||||
{
|
||||
bool inExistingGroup = false;
|
||||
|
||||
// Pointer to (necessarily unique) empty group which could be left
|
||||
// after removing the last radio button from it.
|
||||
Ranges::iterator itEmptyGroup = m_ranges.end();
|
||||
|
||||
for ( Ranges::iterator it = m_ranges.begin();
|
||||
it != m_ranges.end();
|
||||
++it )
|
||||
{
|
||||
Range& r = *it;
|
||||
|
||||
if ( pos < r.start )
|
||||
{
|
||||
// Removed item was positioned before this range, update its
|
||||
// indices.
|
||||
r.start--;
|
||||
r.end--;
|
||||
}
|
||||
else if ( pos <= r.end )
|
||||
{
|
||||
// Removed item belongs to this radio group (it is a radio
|
||||
// button), update index of its end.
|
||||
r.end--;
|
||||
|
||||
// Check if empty group left after removal.
|
||||
// If so, it will be deleted later on.
|
||||
if ( r.end < r.start )
|
||||
itEmptyGroup = it;
|
||||
|
||||
inExistingGroup = true;
|
||||
}
|
||||
//else: Removed item was after this range, nothing to do for it.
|
||||
}
|
||||
|
||||
// Remove empty group from the list.
|
||||
if ( itEmptyGroup != m_ranges.end() )
|
||||
m_ranges.erase(itEmptyGroup);
|
||||
|
||||
return inExistingGroup;
|
||||
}
|
||||
|
||||
private:
|
||||
// Contains the inclusive positions of the range start and end.
|
||||
struct Range
|
||||
{
|
||||
int start;
|
||||
int end;
|
||||
};
|
||||
|
||||
typedef wxVector<Range> Ranges;
|
||||
Ranges m_ranges;
|
||||
};
|
||||
|
||||
#endif // WX_PRIVATE_MENURADIO_H_
|
||||
76
wxheaders/wx/private/notifmsg.h
Normal file
76
wxheaders/wx/private/notifmsg.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/notifmsg.h
|
||||
// Purpose: wxNotificationMessage declarations
|
||||
// Author: Tobias Taschner
|
||||
// Created: 2015-08-04
|
||||
// Copyright: (c) 2015 wxWidgets development team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_NOTIFMSG_H_
|
||||
#define _WX_PRIVATE_NOTIFMSG_H_
|
||||
|
||||
class wxNotificationMessageImpl
|
||||
{
|
||||
public:
|
||||
wxNotificationMessageImpl(wxNotificationMessageBase* notification):
|
||||
m_notification(notification),
|
||||
m_active(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual ~wxNotificationMessageImpl() { }
|
||||
|
||||
virtual bool Show(int timeout) = 0;
|
||||
|
||||
virtual bool Close() = 0;
|
||||
|
||||
virtual void SetTitle(const wxString& title) = 0;
|
||||
|
||||
virtual void SetMessage(const wxString& message) = 0;
|
||||
|
||||
virtual void SetParent(wxWindow *parent) = 0;
|
||||
|
||||
virtual void SetFlags(int flags) = 0;
|
||||
|
||||
virtual void SetIcon(const wxIcon& icon) = 0;
|
||||
|
||||
virtual bool AddAction(wxWindowID actionid, const wxString &label) = 0;
|
||||
|
||||
virtual void Detach()
|
||||
{
|
||||
if (m_active)
|
||||
m_notification = NULL;
|
||||
else
|
||||
delete this;
|
||||
}
|
||||
|
||||
bool ProcessNotificationEvent(wxEvent& event)
|
||||
{
|
||||
if (m_notification)
|
||||
return m_notification->ProcessEvent(event);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
wxNotificationMessageBase* GetNotification() const
|
||||
{
|
||||
return m_notification;
|
||||
}
|
||||
|
||||
protected:
|
||||
wxNotificationMessageBase* m_notification;
|
||||
bool m_active;
|
||||
|
||||
void SetActive(bool active)
|
||||
{
|
||||
m_active = active;
|
||||
|
||||
// Delete the implementation if the notification is detached
|
||||
if (!m_notification && !active)
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_NOTIFMSG_H_
|
||||
40
wxheaders/wx/private/overlay.h
Normal file
40
wxheaders/wx/private/overlay.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/overlay.h
|
||||
// Purpose: wxOverlayImpl declaration
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 2006-10-20
|
||||
// Copyright: (c) wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_OVERLAY_H_
|
||||
#define _WX_PRIVATE_OVERLAY_H_
|
||||
|
||||
#include "wx/overlay.h"
|
||||
|
||||
#if defined(__WXDFB__)
|
||||
#define wxHAS_NATIVE_OVERLAY 1
|
||||
#elif defined(__WXOSX__) && wxOSX_USE_COCOA
|
||||
#define wxHAS_NATIVE_OVERLAY 1
|
||||
#elif defined(__WXGTK3__)
|
||||
#define wxHAS_NATIVE_OVERLAY 1
|
||||
#define wxHAS_GENERIC_OVERLAY 1
|
||||
#else
|
||||
#define wxHAS_GENERIC_OVERLAY 1
|
||||
#endif
|
||||
|
||||
class wxOverlay::Impl
|
||||
{
|
||||
public:
|
||||
virtual ~Impl();
|
||||
virtual bool IsNative() const;
|
||||
virtual bool IsOk() = 0;
|
||||
virtual void Init(wxDC* dc, int x, int y, int width, int height) = 0;
|
||||
virtual void BeginDrawing(wxDC* dc) = 0;
|
||||
virtual void EndDrawing(wxDC* dc) = 0;
|
||||
virtual void Clear(wxDC* dc) = 0;
|
||||
virtual void Reset() = 0;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_OVERLAY_H_
|
||||
29
wxheaders/wx/private/pipestream.h
Normal file
29
wxheaders/wx/private/pipestream.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/pipestream.h
|
||||
// Purpose: Declares wxPipeInputStream and wxPipeOutputStream.
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by: Rob Bresalier
|
||||
// Created: 2013-04-27
|
||||
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// (c) 2013 Rob Bresalier
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_PIPESTREAM_H_
|
||||
#define _WX_PRIVATE_PIPESTREAM_H_
|
||||
|
||||
#include "wx/platform.h"
|
||||
|
||||
// wxPipeInputStream is a platform-dependent input stream class (i.e. deriving,
|
||||
// possible indirectly, from wxInputStream) for reading from a pipe, i.e. a
|
||||
// pipe FD under Unix or a pipe HANDLE under MSW. It provides a single extra
|
||||
// IsOpened() method.
|
||||
//
|
||||
// wxPipeOutputStream is similar but has no additional methods at all.
|
||||
#if defined(__UNIX__) && !defined(__WINDOWS__)
|
||||
#include "wx/unix/private/pipestream.h"
|
||||
#elif defined(__WINDOWS__)
|
||||
#include "wx/msw/private/pipestream.h"
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_PIPESTREAM_H_
|
||||
40
wxheaders/wx/private/preferences.h
Normal file
40
wxheaders/wx/private/preferences.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/preferences.h
|
||||
// Purpose: wxPreferencesEditorImpl declaration.
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2013-02-19
|
||||
// Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_PREFERENCES_H_
|
||||
#define _WX_PRIVATE_PREFERENCES_H_
|
||||
|
||||
#include "wx/preferences.h"
|
||||
|
||||
#if wxUSE_TOOLBAR && defined(__WXOSX_COCOA__) && wxOSX_USE_NATIVE_TOOLBAR
|
||||
#define wxHAS_PREF_EDITOR_NATIVE
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxPreferencesEditorImpl: defines wxPreferencesEditor implementation.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxPreferencesEditorImpl
|
||||
{
|
||||
public:
|
||||
// This is implemented in a platform-specific way.
|
||||
static wxPreferencesEditorImpl* Create(const wxString& title);
|
||||
|
||||
// These methods simply mirror the public wxPreferencesEditor ones.
|
||||
virtual void AddPage(wxPreferencesPage* page) = 0;
|
||||
virtual void Show(wxWindow* parent) = 0;
|
||||
virtual void Dismiss() = 0;
|
||||
|
||||
virtual ~wxPreferencesEditorImpl() {}
|
||||
|
||||
protected:
|
||||
wxPreferencesEditorImpl() {}
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_PREFERENCES_H_
|
||||
42
wxheaders/wx/private/refcountermt.h
Normal file
42
wxheaders/wx/private/refcountermt.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/refcountermt.h
|
||||
// Purpose: wxRefCounterMT class: MT-safe version of wxRefCounter
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2021-01-11
|
||||
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_REFCOUNTERMT_H_
|
||||
#define _WX_PRIVATE_REFCOUNTERMT_H_
|
||||
|
||||
#include "wx/atomic.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Version of wxRefCounter with MT-safe count
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxRefCounterMT
|
||||
{
|
||||
public:
|
||||
wxRefCounterMT() { m_count = 1; }
|
||||
|
||||
void IncRef() { wxAtomicInc(m_count); }
|
||||
void DecRef()
|
||||
{
|
||||
if ( wxAtomicDec(m_count) == 0 )
|
||||
delete this;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~wxRefCounterMT() { }
|
||||
|
||||
private:
|
||||
// Ref count is atomic to allow IncRef() and DecRef() to be concurrently
|
||||
// called from different threads.
|
||||
wxAtomicInt m_count;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxRefCounterMT);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_REFCOUNTERMT_H_
|
||||
146
wxheaders/wx/private/rescale.h
Normal file
146
wxheaders/wx/private/rescale.h
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/rescale.h
|
||||
// Purpose: Helpers for rescaling coordinates
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2021-07-13
|
||||
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_RESCALE_H_
|
||||
#define _WX_PRIVATE_RESCALE_H_
|
||||
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/math.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
// Required in order to use wxMulDivInt32().
|
||||
#include "wx/msw/wrapwin.h"
|
||||
#endif
|
||||
|
||||
// wxRescaleCoord is used to scale the components of the given wxSize by the
|
||||
// ratio between 2 scales, with rounding. It doesn't scale the components
|
||||
// if they're set to -1 (wxDefaultCoord), as this value is special in wxSize.
|
||||
//
|
||||
// The way it's used is special because we want to ensure there is no confusion
|
||||
// between the scale being converted from and the scale being converted to, so
|
||||
// instead of just using a single function, we use an intermediate object,
|
||||
// which is not supposed to be used directly, but is only returned by From() in
|
||||
// order to allow calling To() on it.
|
||||
//
|
||||
// Another complication is that we want this to work for both wxSize and
|
||||
// wxPoint, as well as for just plain coordinate values, so wxRescaleCoord() is
|
||||
// an overloaded function and the helper classes are templates, with their
|
||||
// template parameter being either wxSize, wxPoint or int.
|
||||
|
||||
namespace wxPrivate
|
||||
{
|
||||
|
||||
template <typename T> class wxRescaleCoordWithValue;
|
||||
|
||||
template <typename T>
|
||||
class wxRescaleCoordWithFrom
|
||||
{
|
||||
public:
|
||||
T To(wxSize newScale) const
|
||||
{
|
||||
T value(m_value);
|
||||
|
||||
if ( value.x != wxDefaultCoord )
|
||||
value.x = wxMulDivInt32(value.x, newScale.x, m_oldScale.x);
|
||||
|
||||
if ( value.y != wxDefaultCoord )
|
||||
value.y = wxMulDivInt32(value.y, newScale.y, m_oldScale.y);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
T To(int newScaleX, int newScaleY) const
|
||||
{
|
||||
return To(wxSize(newScaleX, newScaleY));
|
||||
}
|
||||
|
||||
private:
|
||||
wxRescaleCoordWithFrom(T value, wxSize oldScale)
|
||||
: m_value(value), m_oldScale(oldScale)
|
||||
{
|
||||
}
|
||||
|
||||
const T m_value;
|
||||
const wxSize m_oldScale;
|
||||
|
||||
// Only it can create objects of this class.
|
||||
friend class wxRescaleCoordWithValue<T>;
|
||||
};
|
||||
|
||||
// Specialization for just a single value.
|
||||
template <>
|
||||
class wxRescaleCoordWithFrom<int>
|
||||
{
|
||||
public:
|
||||
int To(wxSize newScale) const
|
||||
{
|
||||
return m_value == wxDefaultCoord
|
||||
? wxDefaultCoord
|
||||
: wxMulDivInt32(m_value, newScale.x, m_oldScale.x);
|
||||
}
|
||||
|
||||
private:
|
||||
wxRescaleCoordWithFrom(int value, wxSize oldScale)
|
||||
: m_value(value), m_oldScale(oldScale)
|
||||
{
|
||||
}
|
||||
|
||||
const int m_value;
|
||||
const wxSize m_oldScale;
|
||||
|
||||
// Only it can create objects of this class.
|
||||
friend class wxRescaleCoordWithValue<int>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class wxRescaleCoordWithValue
|
||||
{
|
||||
public:
|
||||
explicit wxRescaleCoordWithValue(T value)
|
||||
: m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
wxRescaleCoordWithFrom<T> From(wxSize oldScale)
|
||||
{
|
||||
return wxRescaleCoordWithFrom<T>(m_value, oldScale);
|
||||
}
|
||||
|
||||
wxRescaleCoordWithFrom<T> From(int oldScaleX, int oldScaleY)
|
||||
{
|
||||
return From(wxSize(oldScaleX, oldScaleY));
|
||||
}
|
||||
|
||||
private:
|
||||
const T m_value;
|
||||
};
|
||||
|
||||
} // namespace wxPrivate
|
||||
|
||||
inline wxPrivate::wxRescaleCoordWithValue<int> wxRescaleCoord(int coord)
|
||||
{
|
||||
return wxPrivate::wxRescaleCoordWithValue<int>(coord);
|
||||
}
|
||||
|
||||
inline wxPrivate::wxRescaleCoordWithValue<wxSize> wxRescaleCoord(wxSize sz)
|
||||
{
|
||||
return wxPrivate::wxRescaleCoordWithValue<wxSize>(sz);
|
||||
}
|
||||
|
||||
inline wxPrivate::wxRescaleCoordWithValue<wxSize> wxRescaleCoord(int x, int y)
|
||||
{
|
||||
return wxPrivate::wxRescaleCoordWithValue<wxSize>(wxSize(x, y));
|
||||
}
|
||||
|
||||
inline wxPrivate::wxRescaleCoordWithValue<wxPoint> wxRescaleCoord(wxPoint pt)
|
||||
{
|
||||
return wxPrivate::wxRescaleCoordWithValue<wxPoint>(pt);
|
||||
}
|
||||
|
||||
#endif // _WX_PRIVATE_RESCALE_H_
|
||||
44
wxheaders/wx/private/richtooltip.h
Normal file
44
wxheaders/wx/private/richtooltip.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/richtooltip.h
|
||||
// Purpose: wxRichToolTipImpl declaration.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-10-18
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_RICHTOOLTIP_H_
|
||||
#define _WX_PRIVATE_RICHTOOLTIP_H_
|
||||
|
||||
#include "wx/richtooltip.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxRichToolTipImpl: defines wxRichToolTip implementation.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxRichToolTipImpl
|
||||
{
|
||||
public:
|
||||
// This is implemented in a platform-specific way.
|
||||
static wxRichToolTipImpl* Create(const wxString& title,
|
||||
const wxString& message);
|
||||
|
||||
// These methods simply mirror the public wxRichToolTip ones.
|
||||
virtual void SetBackgroundColour(const wxColour& col,
|
||||
const wxColour& colEnd) = 0;
|
||||
virtual void SetCustomIcon(const wxBitmapBundle& icon) = 0;
|
||||
virtual void SetStandardIcon(int icon) = 0;
|
||||
virtual void SetTimeout(unsigned milliseconds,
|
||||
unsigned millisecondsShowdelay = 0) = 0;
|
||||
virtual void SetTipKind(wxTipKind tipKind) = 0;
|
||||
virtual void SetTitleFont(const wxFont& font) = 0;
|
||||
|
||||
virtual void ShowFor(wxWindow* win, const wxRect* rect = NULL) = 0;
|
||||
|
||||
virtual ~wxRichToolTipImpl() { }
|
||||
|
||||
protected:
|
||||
wxRichToolTipImpl() { }
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_RICHTOOLTIP_H_
|
||||
316
wxheaders/wx/private/sckaddr.h
Normal file
316
wxheaders/wx/private/sckaddr.h
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/sckaddr.h
|
||||
// Purpose: wxSockAddressImpl
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2008-12-28
|
||||
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_SOCKADDR_H_
|
||||
#define _WX_PRIVATE_SOCKADDR_H_
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/wrapwin.h"
|
||||
|
||||
#if wxUSE_IPV6
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#elif defined(__VMS__)
|
||||
#include <socket.h>
|
||||
|
||||
struct sockaddr_un
|
||||
{
|
||||
u_char sun_len; /* sockaddr len including null */
|
||||
u_char sun_family; /* AF_UNIX */
|
||||
char sun_path[108]; /* path name (gag) */
|
||||
};
|
||||
#include <in.h>
|
||||
#else // generic Unix
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
#endif // platform
|
||||
|
||||
#include <stdlib.h> // for calloc()
|
||||
|
||||
// this is a wrapper for sockaddr_storage if it's available or just sockaddr
|
||||
// otherwise
|
||||
union wxSockAddressStorage
|
||||
{
|
||||
#if wxUSE_IPV6
|
||||
sockaddr_storage addr_storage;
|
||||
#endif
|
||||
sockaddr addr;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helpers for wxSockAddressImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// helper class mapping sockaddr_xxx types to corresponding AF_XXX values
|
||||
template <class T> struct AddressFamily;
|
||||
|
||||
template <> struct AddressFamily<sockaddr_in> { enum { value = AF_INET }; };
|
||||
|
||||
#if wxUSE_IPV6
|
||||
template <> struct AddressFamily<sockaddr_in6> { enum { value = AF_INET6 }; };
|
||||
#endif // wxUSE_IPV6
|
||||
|
||||
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
template <> struct AddressFamily<sockaddr_un> { enum { value = AF_UNIX }; };
|
||||
#endif // wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSockAddressImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Represents a socket endpoint, e.g. an (address, port) pair for PF_INET
|
||||
// sockets. It can be initialized from an existing sockaddr struct and also
|
||||
// provides access to sockaddr stored internally so that it can be easily used
|
||||
// with e.g. connect(2).
|
||||
//
|
||||
// This class also performs (synchronous, hence potentially long) name lookups
|
||||
// if necessary, i.e. if the host name strings don't contain addresses in
|
||||
// numerical form (quad dotted for IPv4 or standard hexadecimal for IPv6).
|
||||
// Notice that internally the potentially Unicode host names are encoded as
|
||||
// UTF-8 before being passed to the lookup function but the host names should
|
||||
// really be ASCII anyhow.
|
||||
class wxSockAddressImpl
|
||||
{
|
||||
public:
|
||||
// as this is passed to socket() it should be a PF_XXX and not AF_XXX (even
|
||||
// though they're the same in practice)
|
||||
enum Family
|
||||
{
|
||||
FAMILY_INET = PF_INET,
|
||||
#if wxUSE_IPV6
|
||||
FAMILY_INET6 = PF_INET6,
|
||||
#endif
|
||||
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
FAMILY_UNIX = PF_UNIX,
|
||||
#endif
|
||||
FAMILY_UNSPEC = PF_UNSPEC
|
||||
};
|
||||
|
||||
// default ctor creates uninitialized object, use one of CreateXXX() below
|
||||
wxSockAddressImpl()
|
||||
{
|
||||
InitUnspec();
|
||||
}
|
||||
|
||||
// ctor from an existing sockaddr
|
||||
wxSockAddressImpl(const sockaddr& addr, int len)
|
||||
{
|
||||
switch ( addr.sa_family )
|
||||
{
|
||||
case PF_INET:
|
||||
#if wxUSE_IPV6
|
||||
case PF_INET6:
|
||||
#endif
|
||||
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
case PF_UNIX:
|
||||
#endif
|
||||
m_family = static_cast<Family>(addr.sa_family);
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( "unsupported socket address family" );
|
||||
InitUnspec();
|
||||
return;
|
||||
}
|
||||
|
||||
InitFromSockaddr(addr, len);
|
||||
}
|
||||
|
||||
// copy ctor and assignment operators
|
||||
wxSockAddressImpl(const wxSockAddressImpl& other)
|
||||
{
|
||||
InitFromOther(other);
|
||||
}
|
||||
|
||||
wxSockAddressImpl& operator=(const wxSockAddressImpl& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
free(m_addr);
|
||||
InitFromOther(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// dtor frees the memory used by m_addr
|
||||
~wxSockAddressImpl()
|
||||
{
|
||||
free(m_addr);
|
||||
}
|
||||
|
||||
|
||||
// reset the address to the initial uninitialized state
|
||||
void Clear()
|
||||
{
|
||||
free(m_addr);
|
||||
|
||||
InitUnspec();
|
||||
}
|
||||
|
||||
// initialize the address to be of specific address family, it must be
|
||||
// currently uninitialized (you may call Clear() to achieve this)
|
||||
void CreateINET();
|
||||
void CreateINET6();
|
||||
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
void CreateUnix();
|
||||
#endif // wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
void Create(Family family)
|
||||
{
|
||||
switch ( family )
|
||||
{
|
||||
case FAMILY_INET:
|
||||
CreateINET();
|
||||
break;
|
||||
|
||||
#if wxUSE_IPV6
|
||||
case FAMILY_INET6:
|
||||
CreateINET6();
|
||||
break;
|
||||
#endif // wxUSE_IPV6
|
||||
|
||||
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
case FAMILY_UNIX:
|
||||
CreateUnix();
|
||||
break;
|
||||
#endif // wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( "unsupported socket address family" );
|
||||
}
|
||||
}
|
||||
|
||||
// simple accessors
|
||||
Family GetFamily() const { return m_family; }
|
||||
bool Is(Family family) const { return m_family == family; }
|
||||
bool IsOk() const { return m_family != FAMILY_UNSPEC; }
|
||||
const sockaddr *GetAddr() const { return m_addr; }
|
||||
sockaddr *GetWritableAddr() { return m_addr; }
|
||||
int GetLen() const { return m_len; }
|
||||
|
||||
// accessors for INET or INET6 address families
|
||||
#if wxUSE_IPV6
|
||||
#define CALL_IPV4_OR_6(func, args) \
|
||||
Is(FAMILY_INET6) ? func##6(args) : func##4(args)
|
||||
#define CALL_IPV4_OR_6_VOID(func) \
|
||||
Is(FAMILY_INET6) ? func##6() : func##4()
|
||||
#else
|
||||
#define CALL_IPV4_OR_6(func, args) func##4(args)
|
||||
#define CALL_IPV4_OR_6_VOID(func) func##4()
|
||||
#endif // IPv6 support on/off
|
||||
|
||||
wxString GetHostName() const;
|
||||
bool SetHostName(const wxString& name)
|
||||
{
|
||||
return CALL_IPV4_OR_6(SetHostName, (name));
|
||||
}
|
||||
|
||||
wxUint16 GetPort() const { return CALL_IPV4_OR_6_VOID(GetPort); }
|
||||
bool SetPort(wxUint16 port) { return CALL_IPV4_OR_6(SetPort, (port)); }
|
||||
bool SetPortName(const wxString& name, const char *protocol);
|
||||
|
||||
bool SetToAnyAddress() { return CALL_IPV4_OR_6_VOID(SetToAnyAddress); }
|
||||
|
||||
#undef CALL_IPV4_OR_6
|
||||
|
||||
// accessors for INET addresses only
|
||||
bool GetHostAddress(wxUint32 *address) const;
|
||||
bool SetHostAddress(wxUint32 address);
|
||||
|
||||
bool SetToBroadcastAddress() { return SetHostAddress(INADDR_BROADCAST); }
|
||||
|
||||
// accessors for INET6 addresses only
|
||||
#if wxUSE_IPV6
|
||||
bool GetHostAddress(in6_addr *address) const;
|
||||
bool SetHostAddress(const in6_addr& address);
|
||||
#endif // wxUSE_IPV6
|
||||
|
||||
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
// methods valid for Unix address family addresses only
|
||||
bool SetPath(const wxString& path);
|
||||
wxString GetPath() const;
|
||||
#endif // wxHAS_UNIX_DOMAIN_SOCKETS
|
||||
|
||||
private:
|
||||
void DoAlloc(int len)
|
||||
{
|
||||
m_addr = static_cast<sockaddr *>(calloc(1, len));
|
||||
m_len = len;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *Alloc()
|
||||
{
|
||||
DoAlloc(sizeof(T));
|
||||
|
||||
return reinterpret_cast<T *>(m_addr);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *Get() const
|
||||
{
|
||||
wxCHECK_MSG( static_cast<int>(m_family) == AddressFamily<T>::value,
|
||||
NULL,
|
||||
"socket address family mismatch" );
|
||||
|
||||
return reinterpret_cast<T *>(m_addr);
|
||||
}
|
||||
|
||||
void InitUnspec()
|
||||
{
|
||||
m_family = FAMILY_UNSPEC;
|
||||
m_addr = NULL;
|
||||
m_len = 0;
|
||||
}
|
||||
|
||||
void InitFromSockaddr(const sockaddr& addr, int len)
|
||||
{
|
||||
DoAlloc(len);
|
||||
memcpy(m_addr, &addr, len);
|
||||
}
|
||||
|
||||
void InitFromOther(const wxSockAddressImpl& other)
|
||||
{
|
||||
m_family = other.m_family;
|
||||
|
||||
if ( other.m_addr )
|
||||
{
|
||||
InitFromSockaddr(*other.m_addr, other.m_len);
|
||||
}
|
||||
else // no address to copy
|
||||
{
|
||||
m_addr = NULL;
|
||||
m_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// IPv4/6 implementations of public functions
|
||||
bool SetHostName4(const wxString& name);
|
||||
|
||||
bool SetPort4(wxUint16 port);
|
||||
wxUint16 GetPort4() const;
|
||||
|
||||
bool SetToAnyAddress4() { return SetHostAddress(INADDR_ANY); }
|
||||
|
||||
#if wxUSE_IPV6
|
||||
bool SetHostName6(const wxString& name);
|
||||
|
||||
bool SetPort6(wxUint16 port);
|
||||
wxUint16 GetPort6() const;
|
||||
|
||||
bool SetToAnyAddress6();
|
||||
#endif // wxUSE_IPV6
|
||||
|
||||
Family m_family;
|
||||
sockaddr *m_addr;
|
||||
int m_len;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_SOCKADDR_H_
|
||||
95
wxheaders/wx/private/secretstore.h
Normal file
95
wxheaders/wx/private/secretstore.h
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/secretstore.h
|
||||
// Purpose: Classes used in wxSecretStore implementation only.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2016-05-27
|
||||
// Copyright: (c) 2016 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_SECRETSTORE_H_
|
||||
#define _WX_PRIVATE_SECRETSTORE_H_
|
||||
|
||||
#include "wx/object.h" // wxRefCounter
|
||||
|
||||
// Both of the implementation classes here are ref-counted so that the
|
||||
// corresponding public objects could be copied cheaply and, in the case of
|
||||
// wxSecretValue, also to avoid having the secret in more than one place in
|
||||
// memory at a time.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Class holding wxSecretValue data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// This is a common base class for our own and libsecret-based implementations.
|
||||
class wxSecretValueImpl : public wxRefCounter
|
||||
{
|
||||
public:
|
||||
wxSecretValueImpl()
|
||||
{
|
||||
}
|
||||
|
||||
virtual size_t GetSize() const = 0;
|
||||
virtual const void *GetData() const = 0;
|
||||
};
|
||||
|
||||
// Trivial common implementation of wxSecretValueImpl used under MSW and OS X.
|
||||
#if defined(__WINDOWS__) || defined(__DARWIN__)
|
||||
|
||||
class wxSecretValueGenericImpl : public wxSecretValueImpl
|
||||
{
|
||||
public:
|
||||
wxSecretValueGenericImpl(size_t size, const void *data)
|
||||
: m_size(size),
|
||||
m_data(new char[size])
|
||||
{
|
||||
memcpy(m_data, data, size);
|
||||
}
|
||||
|
||||
virtual ~wxSecretValueGenericImpl()
|
||||
{
|
||||
if ( m_data )
|
||||
{
|
||||
wxSecretValue::Wipe(m_size, m_data);
|
||||
delete [] m_data;
|
||||
}
|
||||
}
|
||||
|
||||
virtual size_t GetSize() const wxOVERRIDE { return m_size; }
|
||||
virtual const void *GetData() const wxOVERRIDE { return m_data; }
|
||||
|
||||
private:
|
||||
const size_t m_size;
|
||||
char* const m_data;
|
||||
};
|
||||
|
||||
#endif // MSW or OSX
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Base class for wxSecretStore implementations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// All its methods are similar to the methods of the public class except that
|
||||
// they work with the implementation rather than public objects and they all
|
||||
// take an extra "wxString&" output parameter which is filled with the low
|
||||
// level error message in case of an error. This message will be logged by
|
||||
// wxSecretStore itself, wxSecretStoreImpl methods shouldn't do any logging on
|
||||
// their own.
|
||||
class wxSecretStoreImpl : public wxRefCounter
|
||||
{
|
||||
public:
|
||||
virtual bool IsOk(wxString* WXUNUSED(errmsg)) const { return true; }
|
||||
|
||||
virtual bool Save(const wxString& service,
|
||||
const wxString& username,
|
||||
const wxSecretValueImpl& password,
|
||||
wxString& errmsg) = 0;
|
||||
virtual bool Load(const wxString& service,
|
||||
wxString* username,
|
||||
wxSecretValueImpl** password,
|
||||
wxString& errmsg) const = 0;
|
||||
virtual bool Delete(const wxString& service,
|
||||
wxString& errmsg) = 0;
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_SECRETSTORE_H_
|
||||
125
wxheaders/wx/private/selectdispatcher.h
Normal file
125
wxheaders/wx/private/selectdispatcher.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/selectdispatcher.h
|
||||
// Purpose: wxSelectDispatcher class
|
||||
// Authors: Lukasz Michalski and Vadim Zeitlin
|
||||
// Created: December 2006
|
||||
// Copyright: (c) Lukasz Michalski
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_SELECTDISPATCHER_H_
|
||||
#define _WX_PRIVATE_SELECTDISPATCHER_H_
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if wxUSE_SELECT_DISPATCHER
|
||||
|
||||
#if defined(HAVE_SYS_SELECT_H)
|
||||
#include <sys/time.h>
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "wx/thread.h"
|
||||
#include "wx/private/fdiodispatcher.h"
|
||||
|
||||
// helper class storing all the select() fd sets
|
||||
class WXDLLIMPEXP_BASE wxSelectSets
|
||||
{
|
||||
public:
|
||||
// ctor zeroes out all fd_sets
|
||||
wxSelectSets();
|
||||
|
||||
// default copy ctor, assignment operator and dtor are ok
|
||||
|
||||
|
||||
// return true if fd appears in any of the sets
|
||||
bool HasFD(int fd) const;
|
||||
|
||||
// add or remove FD to our sets depending on whether flags contains
|
||||
// wxFDIO_INPUT/OUTPUT/EXCEPTION bits
|
||||
bool SetFD(int fd, int flags);
|
||||
|
||||
// same as SetFD() except it unsets the bits set in the flags for the given
|
||||
// fd
|
||||
bool ClearFD(int fd)
|
||||
{
|
||||
return SetFD(fd, 0);
|
||||
}
|
||||
|
||||
|
||||
// call select() with our sets: the other parameters are the same as for
|
||||
// select() itself
|
||||
int Select(int nfds, struct timeval *tv);
|
||||
|
||||
// call the handler methods corresponding to the sets having this fd if it
|
||||
// is present in any set and return true if it is
|
||||
bool Handle(int fd, wxFDIOHandler& handler) const;
|
||||
|
||||
private:
|
||||
typedef void (wxFDIOHandler::*Callback)();
|
||||
|
||||
// the FD sets indices
|
||||
enum
|
||||
{
|
||||
Read,
|
||||
Write,
|
||||
Except,
|
||||
Max
|
||||
};
|
||||
|
||||
// the sets used with select()
|
||||
fd_set m_fds[Max];
|
||||
|
||||
// the wxFDIO_XXX flags, functions and names (used for debug messages only)
|
||||
// corresponding to the FD sets above
|
||||
static int ms_flags[Max];
|
||||
static const char *ms_names[Max];
|
||||
static Callback ms_handlers[Max];
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_BASE wxSelectDispatcher : public wxMappedFDIODispatcher
|
||||
{
|
||||
public:
|
||||
// default ctor
|
||||
wxSelectDispatcher() { m_maxFD = -1; }
|
||||
|
||||
// implement pure virtual methods of the base class
|
||||
virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL) wxOVERRIDE;
|
||||
virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL) wxOVERRIDE;
|
||||
virtual bool UnregisterFD(int fd) wxOVERRIDE;
|
||||
virtual bool HasPending() const wxOVERRIDE;
|
||||
virtual int Dispatch(int timeout = TIMEOUT_INFINITE) wxOVERRIDE;
|
||||
|
||||
private:
|
||||
// common part of RegisterFD() and ModifyFD()
|
||||
bool DoUpdateFDAndHandler(int fd, wxFDIOHandler *handler, int flags);
|
||||
|
||||
// call the handlers for the fds present in the given sets, return the
|
||||
// number of handlers we called
|
||||
int ProcessSets(const wxSelectSets& sets);
|
||||
|
||||
// helper of ProcessSets(): call the handler if its fd is in the set
|
||||
void DoProcessFD(int fd, const fd_set& fds, wxFDIOHandler *handler,
|
||||
const char *name);
|
||||
|
||||
// common part of HasPending() and Dispatch(): calls select() with the
|
||||
// specified timeout
|
||||
int DoSelect(wxSelectSets& sets, int timeout) const;
|
||||
|
||||
|
||||
#if wxUSE_THREADS
|
||||
wxCriticalSection m_cs;
|
||||
#endif // wxUSE_THREADS
|
||||
|
||||
// the select sets containing all the registered fds
|
||||
wxSelectSets m_sets;
|
||||
|
||||
// the highest registered fd value or -1 if none
|
||||
int m_maxFD;
|
||||
};
|
||||
|
||||
#endif // wxUSE_SELECT_DISPATCHER
|
||||
|
||||
#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_
|
||||
383
wxheaders/wx/private/socket.h
Normal file
383
wxheaders/wx/private/socket.h
Normal file
|
|
@ -0,0 +1,383 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/socket.h
|
||||
// Purpose: wxSocketImpl and related declarations
|
||||
// Authors: Guilhem Lavaux, Vadim Zeitlin
|
||||
// Created: April 1997
|
||||
// Copyright: (c) 1997 Guilhem Lavaux
|
||||
// (c) 2008 Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
Brief overview of different socket classes:
|
||||
|
||||
- wxSocketBase is the public class representing a socket ("Base" here
|
||||
refers to the fact that wxSocketClient and wxSocketServer are derived
|
||||
from it and predates the convention of using "Base" for common base
|
||||
classes for platform-specific classes in wxWidgets) with implementation
|
||||
common to all platforms and forwarding methods whose implementation
|
||||
differs between platforms to wxSocketImpl which it contains.
|
||||
|
||||
- wxSocketImpl is actually just an abstract base class having only code
|
||||
common to all platforms, the concrete implementation classes derive from
|
||||
it and are created by wxSocketImpl::Create().
|
||||
|
||||
- Some socket operations have different implementations in console-mode and
|
||||
GUI applications. wxSocketManager class exists to abstract this in such
|
||||
way that console applications (using wxBase) don't depend on wxNet. An
|
||||
object of this class is made available via wxApp and GUI applications set
|
||||
up a different kind of global socket manager from console ones.
|
||||
|
||||
TODO: it looks like wxSocketManager could be eliminated by providing
|
||||
methods for registering/unregistering sockets directly in
|
||||
wxEventLoop.
|
||||
*/
|
||||
|
||||
#ifndef _WX_PRIVATE_SOCKET_H_
|
||||
#define _WX_PRIVATE_SOCKET_H_
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include "wx/socket.h"
|
||||
#include "wx/private/sckaddr.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
Including sys/types.h under Cygwin results in the warnings about "fd_set
|
||||
having been defined in sys/types.h" when winsock.h is included later and
|
||||
doesn't seem to be necessary anyhow. It's not needed under Mac either.
|
||||
*/
|
||||
#if !defined(__WXMAC__) && !defined(__WXMSW__)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
// include the header defining timeval: under Windows this struct is used only
|
||||
// with sockets so we need to include winsock.h which we do via windows.h
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/wrapwin.h"
|
||||
#else
|
||||
#include <sys/time.h> // for timeval
|
||||
#endif
|
||||
|
||||
// 64 bit Cygwin can't use the standard struct timeval because it has long
|
||||
// fields, which are supposed to be 32 bits in Win64 API, but long is 64 bits
|
||||
// in 64 bit Cygwin, so we need to use its special __ms_timeval instead.
|
||||
#if defined(__CYGWIN__) && defined(__LP64__) && defined(__WINDOWS__)
|
||||
typedef __ms_timeval wxTimeVal_t;
|
||||
#else
|
||||
typedef timeval wxTimeVal_t;
|
||||
#endif
|
||||
|
||||
// these definitions are for MSW when we don't use configure, otherwise these
|
||||
// symbols are defined by configure
|
||||
#ifndef WX_SOCKLEN_T
|
||||
#define WX_SOCKLEN_T int
|
||||
#endif
|
||||
|
||||
#ifndef SOCKOPTLEN_T
|
||||
#define SOCKOPTLEN_T int
|
||||
#endif
|
||||
|
||||
// define some symbols which winsock.h defines but traditional BSD headers
|
||||
// don't
|
||||
#ifndef INVALID_SOCKET
|
||||
#define INVALID_SOCKET (-1)
|
||||
#endif
|
||||
|
||||
#ifndef SOCKET_ERROR
|
||||
#define SOCKET_ERROR (-1)
|
||||
#endif
|
||||
|
||||
typedef int wxSocketEventFlags;
|
||||
|
||||
class wxSocketImpl;
|
||||
|
||||
/*
|
||||
Class providing hooks abstracting the differences between console and GUI
|
||||
applications for socket code.
|
||||
|
||||
We also have different implementations of this class for different platforms
|
||||
allowing us to keep more things in the common code but the main reason for
|
||||
its existence is that we want the same socket code work differently
|
||||
depending on whether it's used from a console or a GUI program. This is
|
||||
achieved by implementing the virtual methods of this class differently in
|
||||
the objects returned by wxConsoleAppTraits::GetSocketManager() and the same
|
||||
method in wxGUIAppTraits.
|
||||
*/
|
||||
class wxSocketManager
|
||||
{
|
||||
public:
|
||||
// set the manager to use, we don't take ownership of it
|
||||
//
|
||||
// this should be called before creating the first wxSocket object,
|
||||
// otherwise the manager returned by wxAppTraits::GetSocketManager() will
|
||||
// be used
|
||||
static void Set(wxSocketManager *manager);
|
||||
|
||||
// return the manager to use
|
||||
//
|
||||
// this initializes the manager at first use
|
||||
static wxSocketManager *Get()
|
||||
{
|
||||
if ( !ms_manager )
|
||||
Init();
|
||||
|
||||
return ms_manager;
|
||||
}
|
||||
|
||||
// called before the first wxSocket is created and should do the
|
||||
// initializations needed in order to use the network
|
||||
//
|
||||
// return true if initialized successfully; if this returns false sockets
|
||||
// can't be used at all
|
||||
virtual bool OnInit() = 0;
|
||||
|
||||
// undo the initializations of OnInit()
|
||||
virtual void OnExit() = 0;
|
||||
|
||||
|
||||
// create the socket implementation object matching this manager
|
||||
virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket) = 0;
|
||||
|
||||
// these functions enable or disable monitoring of the given socket for the
|
||||
// specified events inside the currently running event loop (but notice
|
||||
// that both BSD and Winsock implementations actually use socket->m_server
|
||||
// value to determine what exactly should be monitored so it needs to be
|
||||
// set before calling these functions)
|
||||
//
|
||||
// the default event value is used just for the convenience of wxMSW
|
||||
// implementation which doesn't use this parameter anyhow, it doesn't make
|
||||
// sense to pass wxSOCKET_LOST for the Unix implementation which does use
|
||||
// this parameter
|
||||
virtual void Install_Callback(wxSocketImpl *socket,
|
||||
wxSocketNotify event = wxSOCKET_LOST) = 0;
|
||||
virtual void Uninstall_Callback(wxSocketImpl *socket,
|
||||
wxSocketNotify event = wxSOCKET_LOST) = 0;
|
||||
|
||||
virtual ~wxSocketManager() { }
|
||||
|
||||
private:
|
||||
// get the manager to use if we don't have it yet
|
||||
static void Init();
|
||||
|
||||
static wxSocketManager *ms_manager;
|
||||
};
|
||||
|
||||
/*
|
||||
Base class for all socket implementations providing functionality common to
|
||||
BSD and Winsock sockets.
|
||||
|
||||
Objects of this class are not created directly but only via the factory
|
||||
function wxSocketManager::CreateSocket().
|
||||
*/
|
||||
class wxSocketImpl
|
||||
{
|
||||
public:
|
||||
virtual ~wxSocketImpl();
|
||||
|
||||
// set various socket properties: all of those can only be called before
|
||||
// creating the socket
|
||||
void SetTimeout(unsigned long millisec);
|
||||
void SetReusable() { m_reusable = true; }
|
||||
void SetBroadcast() { m_broadcast = true; }
|
||||
void DontDoBind() { m_dobind = false; }
|
||||
void SetInitialSocketBuffers(int recv, int send)
|
||||
{
|
||||
m_initialRecvBufferSize = recv;
|
||||
m_initialSendBufferSize = send;
|
||||
}
|
||||
|
||||
wxSocketError SetLocal(const wxSockAddressImpl& address);
|
||||
wxSocketError SetPeer(const wxSockAddressImpl& address);
|
||||
|
||||
// accessors
|
||||
// ---------
|
||||
|
||||
bool IsServer() const { return m_server; }
|
||||
|
||||
const wxSockAddressImpl& GetLocal(); // non const as may update m_local
|
||||
const wxSockAddressImpl& GetPeer() const { return m_peer; }
|
||||
|
||||
wxSocketError GetError() const { return m_error; }
|
||||
bool IsOk() const { return m_error == wxSOCKET_NOERROR; }
|
||||
|
||||
// get the error code corresponding to the last operation
|
||||
virtual wxSocketError GetLastError() const = 0;
|
||||
|
||||
|
||||
// creating/closing the socket
|
||||
// --------------------------
|
||||
|
||||
// notice that SetLocal() must be called before creating the socket using
|
||||
// any of the functions below
|
||||
//
|
||||
// all of Create() functions return wxSOCKET_NOERROR if the operation
|
||||
// completed successfully or one of:
|
||||
// wxSOCKET_INVSOCK - the socket is in use.
|
||||
// wxSOCKET_INVADDR - the local (server) or peer (client) address has not
|
||||
// been set.
|
||||
// wxSOCKET_IOERR - any other error.
|
||||
|
||||
// create a socket listening on the local address specified by SetLocal()
|
||||
// (notice that DontDoBind() is ignored by this function)
|
||||
wxSocketError CreateServer();
|
||||
|
||||
// create a socket connected to the peer address specified by SetPeer()
|
||||
// (notice that DontDoBind() is ignored by this function)
|
||||
//
|
||||
// this function may return wxSOCKET_WOULDBLOCK in addition to the return
|
||||
// values listed above if wait is false
|
||||
wxSocketError CreateClient(bool wait);
|
||||
|
||||
// create (and bind unless DontDoBind() had been called) an UDP socket
|
||||
// associated with the given local address
|
||||
wxSocketError CreateUDP();
|
||||
|
||||
// may be called whether the socket was created or not, calls DoClose() if
|
||||
// it was indeed created
|
||||
void Close();
|
||||
|
||||
// shuts down the writing end of the socket and closes it, this is a more
|
||||
// graceful way to close
|
||||
//
|
||||
// does nothing if the socket wasn't created
|
||||
void Shutdown();
|
||||
|
||||
|
||||
// IO operations
|
||||
// -------------
|
||||
|
||||
// basic IO, work for both TCP and UDP sockets
|
||||
//
|
||||
// return the number of bytes read/written (possibly 0) or -1 on error
|
||||
int Read(void *buffer, int size);
|
||||
int Write(const void *buffer, int size);
|
||||
|
||||
// basically a wrapper for select(): returns the condition of the socket,
|
||||
// blocking for not longer than timeout if it is specified (otherwise just
|
||||
// poll without blocking at all)
|
||||
//
|
||||
// flags defines what kind of conditions we're interested in, the return
|
||||
// value is composed of a (possibly empty) subset of the bits set in flags
|
||||
wxSocketEventFlags Select(wxSocketEventFlags flags,
|
||||
wxTimeVal_t *timeout = NULL);
|
||||
|
||||
// convenient wrapper calling Select() with our default timeout
|
||||
wxSocketEventFlags SelectWithTimeout(wxSocketEventFlags flags)
|
||||
{
|
||||
return Select(flags, &m_timeout);
|
||||
}
|
||||
|
||||
// just a wrapper for accept(): it is called to create a new wxSocketImpl
|
||||
// corresponding to a new server connection represented by the given
|
||||
// wxSocketBase, returns NULL on error (including immediately if there are
|
||||
// no pending connections as our sockets are non-blocking)
|
||||
wxSocketImpl *Accept(wxSocketBase& wxsocket);
|
||||
|
||||
|
||||
// notifications
|
||||
// -------------
|
||||
|
||||
// Update the socket depending on the presence or absence of wxSOCKET_BLOCK
|
||||
// in GetSocketFlags(): if it's present, make the socket blocking and
|
||||
// ensure that we don't get any asynchronous event for it, otherwise put
|
||||
// it into non-blocking mode and enable monitoring it in the event loop.
|
||||
virtual void UpdateBlockingState() = 0;
|
||||
|
||||
// notify m_wxsocket about the given socket event by calling its (inaptly
|
||||
// named) OnRequest() method
|
||||
void NotifyOnStateChange(wxSocketNotify event);
|
||||
|
||||
// called after reading/writing the data from/to the socket and should
|
||||
// enable back the wxSOCKET_INPUT/OUTPUT_FLAG notifications if they were
|
||||
// turned off when this data was first detected
|
||||
virtual void ReenableEvents(wxSocketEventFlags flags) = 0;
|
||||
|
||||
// TODO: make these fields protected and provide accessors for those of
|
||||
// them that wxSocketBase really needs
|
||||
//protected:
|
||||
wxSOCKET_T m_fd;
|
||||
|
||||
int m_initialRecvBufferSize;
|
||||
int m_initialSendBufferSize;
|
||||
|
||||
wxSockAddressImpl m_local,
|
||||
m_peer;
|
||||
wxSocketError m_error;
|
||||
|
||||
bool m_stream;
|
||||
bool m_establishing;
|
||||
bool m_reusable;
|
||||
bool m_broadcast;
|
||||
bool m_dobind;
|
||||
|
||||
wxTimeVal_t m_timeout;
|
||||
|
||||
protected:
|
||||
wxSocketImpl(wxSocketBase& wxsocket);
|
||||
|
||||
// get the associated socket flags
|
||||
wxSocketFlags GetSocketFlags() const { return m_wxsocket->GetFlags(); }
|
||||
|
||||
// true if we're a listening stream socket
|
||||
bool m_server;
|
||||
|
||||
private:
|
||||
// called by Close() if we have a valid m_fd
|
||||
virtual void DoClose() = 0;
|
||||
|
||||
// check that the socket wasn't created yet and that the given address
|
||||
// (either m_local or m_peer depending on the socket kind) is valid and
|
||||
// set m_error and return false if this is not the case
|
||||
bool PreCreateCheck(const wxSockAddressImpl& addr);
|
||||
|
||||
// set the given socket option: this just wraps setsockopt(SOL_SOCKET)
|
||||
int SetSocketOption(int optname, int optval)
|
||||
{
|
||||
// although modern Unix systems use "const void *" for the 4th
|
||||
// parameter here, old systems and Winsock still use "const char *"
|
||||
return setsockopt(m_fd, SOL_SOCKET, optname,
|
||||
reinterpret_cast<const char *>(&optval),
|
||||
sizeof(optval));
|
||||
}
|
||||
|
||||
// set the given socket option to true value: this is an even simpler
|
||||
// wrapper for setsockopt(SOL_SOCKET) for boolean options
|
||||
int EnableSocketOption(int optname)
|
||||
{
|
||||
return SetSocketOption(optname, 1);
|
||||
}
|
||||
|
||||
// apply the options to the (just created) socket and register it with the
|
||||
// event loop by calling UpdateBlockingState()
|
||||
void PostCreation();
|
||||
|
||||
// update local address after binding/connecting
|
||||
wxSocketError UpdateLocalAddress();
|
||||
|
||||
// functions used to implement Read/Write()
|
||||
int RecvStream(void *buffer, int size);
|
||||
int RecvDgram(void *buffer, int size);
|
||||
int SendStream(const void *buffer, int size);
|
||||
int SendDgram(const void *buffer, int size);
|
||||
|
||||
|
||||
// set in ctor and never changed except that it's reset to NULL when the
|
||||
// socket is shut down
|
||||
wxSocketBase *m_wxsocket;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxSocketImpl);
|
||||
};
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
#include "wx/msw/private/sockmsw.h"
|
||||
#else
|
||||
#include "wx/unix/private/sockunix.h"
|
||||
#endif
|
||||
|
||||
#endif /* wxUSE_SOCKETS */
|
||||
|
||||
#endif /* _WX_PRIVATE_SOCKET_H_ */
|
||||
41
wxheaders/wx/private/spinctrl.h
Normal file
41
wxheaders/wx/private/spinctrl.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/spinctrl.h
|
||||
// Purpose: Private functions used in wxSpinCtrl implementation.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2019-11-13
|
||||
// Copyright: (c) 2019 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_SPINCTRL_H_
|
||||
#define _WX_PRIVATE_SPINCTRL_H_
|
||||
|
||||
namespace wxSpinCtrlImpl
|
||||
{
|
||||
|
||||
// This is an internal helper function currently used by all ports: return the
|
||||
// string containing hexadecimal representation of the given number.
|
||||
extern wxString FormatAsHex(long val, long maxVal);
|
||||
|
||||
// Another helper returning the maximum length of a string representing a value
|
||||
// valid in the given control.
|
||||
extern int GetMaxValueLength(int minVal, int maxVal, int base);
|
||||
|
||||
// The helper function to determine the best size for the given control.
|
||||
// We can't implement this function in the wxSpinCtrlBase because MSW implementation
|
||||
// of wxSpinCtrl is derived from wxSpinButton but uses the same algorithm.
|
||||
extern wxSize GetBestSize(const wxControl* spin, int minVal, int maxVal, int base);
|
||||
|
||||
// Helper function to check if given combination of range and base is valid.
|
||||
extern bool IsBaseCompatibleWithRange(int minVal, int maxVal, int base);
|
||||
|
||||
// Maximum number of digits returned by DetermineDigits().
|
||||
const unsigned SPINCTRLDBL_MAX_DIGITS = 20;
|
||||
|
||||
// Return the number of digits required to show the numbers using the
|
||||
// specified increment without loss of precision.
|
||||
extern unsigned DetermineDigits(double inc);
|
||||
|
||||
} // namespace wxSpinCtrlImpl
|
||||
|
||||
#endif // _WX_PRIVATE_SPINCTRL_H_
|
||||
134
wxheaders/wx/private/streamtempinput.h
Normal file
134
wxheaders/wx/private/streamtempinput.h
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/streamtempinput.h
|
||||
// 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: Rob Bresalier
|
||||
// Created: 2013-05-04
|
||||
// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_STREAMTEMPINPUT_H
|
||||
#define _WX_PRIVATE_STREAMTEMPINPUT_H
|
||||
|
||||
#include "wx/private/pipestream.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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()
|
||||
{
|
||||
m_stream = NULL;
|
||||
m_buffer = NULL;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
// call to associate a stream with this buffer, otherwise nothing happens
|
||||
// at all
|
||||
void Init(wxPipeInputStream *stream)
|
||||
{
|
||||
wxASSERT_MSG( !m_stream, wxS("Can only initialize once") );
|
||||
|
||||
m_stream = stream;
|
||||
}
|
||||
|
||||
// check for input on our stream and cache it in our buffer if any
|
||||
//
|
||||
// return true if anything was done
|
||||
bool Update()
|
||||
{
|
||||
if ( !m_stream || !m_stream->CanRead() )
|
||||
return false;
|
||||
|
||||
// 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 )
|
||||
return false;
|
||||
|
||||
m_buffer = buf;
|
||||
m_stream->Read((char *)m_buffer + m_size, incSize);
|
||||
m_size += m_stream->LastRead();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// check if can continue reading from the stream, this is used to disable
|
||||
// the callback once we can't read anything more
|
||||
bool Eof() const
|
||||
{
|
||||
// If we have no stream, always return true as we can't read any more.
|
||||
return !m_stream || m_stream->Eof();
|
||||
}
|
||||
|
||||
// read everything remaining until the EOF, this should only be called once
|
||||
// the child process terminates and we know that no more data is coming
|
||||
bool ReadAll()
|
||||
{
|
||||
while ( !Eof() )
|
||||
{
|
||||
if ( !Update() )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// dtor puts the data buffered during this object lifetime into the
|
||||
// associated stream
|
||||
~wxStreamTempInputBuffer()
|
||||
{
|
||||
if ( m_buffer )
|
||||
{
|
||||
m_stream->Ungetch(m_buffer, m_size);
|
||||
free(m_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
const void *GetBuffer() const { return m_buffer; }
|
||||
|
||||
size_t GetSize() const { return m_size; }
|
||||
|
||||
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;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxStreamTempInputBuffer);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_STREAMTEMPINPUT_H
|
||||
176
wxheaders/wx/private/textmeasure.h
Normal file
176
wxheaders/wx/private/textmeasure.h
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/textmeasure.h
|
||||
// Purpose: declaration of wxTextMeasure class
|
||||
// Author: Manuel Martin
|
||||
// Created: 2012-10-05
|
||||
// Copyright: (c) 1997-2012 wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_TEXTMEASURE_H_
|
||||
#define _WX_PRIVATE_TEXTMEASURE_H_
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxDC;
|
||||
class WXDLLIMPEXP_FWD_CORE wxFont;
|
||||
class WXDLLIMPEXP_FWD_CORE wxWindow;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTextMeasure: class used to measure text extent.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxTextMeasureBase
|
||||
{
|
||||
public:
|
||||
// The first ctor argument must be non-NULL, i.e. each object of this class
|
||||
// is associated with either a valid wxDC or a valid wxWindow. The font can
|
||||
// be NULL to use the current DC/window font or can be specified explicitly.
|
||||
wxTextMeasureBase(const wxDC *dc, const wxFont *theFont);
|
||||
wxTextMeasureBase(const wxWindow *win, const wxFont *theFont);
|
||||
|
||||
// Even though this class is not supposed to be used polymorphically, give
|
||||
// it a virtual dtor to avoid compiler warnings.
|
||||
virtual ~wxTextMeasureBase() { }
|
||||
|
||||
|
||||
// Return the extent of a single line string.
|
||||
void GetTextExtent(const wxString& string,
|
||||
wxCoord *width,
|
||||
wxCoord *height,
|
||||
wxCoord *descent = NULL,
|
||||
wxCoord *externalLeading = NULL);
|
||||
|
||||
// The same for a multiline (with '\n') string.
|
||||
void GetMultiLineTextExtent(const wxString& text,
|
||||
wxCoord *width,
|
||||
wxCoord *height,
|
||||
wxCoord *heightOneLine = NULL);
|
||||
|
||||
// Find the dimensions of the largest string.
|
||||
wxSize GetLargestStringExtent(size_t n, const wxString* strings);
|
||||
wxSize GetLargestStringExtent(const wxArrayString& strings)
|
||||
{
|
||||
return GetLargestStringExtent(strings.size(), &strings[0]);
|
||||
}
|
||||
|
||||
// Fill the array with the widths for each "0..N" substrings for N from 1
|
||||
// to text.length().
|
||||
//
|
||||
// The scaleX argument is the horizontal scale used by wxDC and is only
|
||||
// used in the generic implementation.
|
||||
bool GetPartialTextExtents(const wxString& text,
|
||||
wxArrayInt& widths,
|
||||
double scaleX);
|
||||
|
||||
|
||||
// This is another method which is only used by MeasuringGuard.
|
||||
bool IsUsingDCImpl() const { return m_useDCImpl; }
|
||||
|
||||
protected:
|
||||
// RAII wrapper for the two methods above.
|
||||
class MeasuringGuard
|
||||
{
|
||||
public:
|
||||
MeasuringGuard(wxTextMeasureBase& tm) : m_tm(tm)
|
||||
{
|
||||
// BeginMeasuring() should only be called if we have a native DC,
|
||||
// so don't call it if we delegate to a DC of unknown type.
|
||||
if ( !m_tm.IsUsingDCImpl() )
|
||||
m_tm.BeginMeasuring();
|
||||
}
|
||||
|
||||
~MeasuringGuard()
|
||||
{
|
||||
if ( !m_tm.IsUsingDCImpl() )
|
||||
m_tm.EndMeasuring();
|
||||
}
|
||||
|
||||
private:
|
||||
wxTextMeasureBase& m_tm;
|
||||
};
|
||||
|
||||
|
||||
// These functions are called by our public methods before and after each
|
||||
// call to DoGetTextExtent(). Derived classes may override them to prepare
|
||||
// for -- possibly several -- subsequent calls to DoGetTextExtent().
|
||||
//
|
||||
// As these calls must be always paired, they're never called directly but
|
||||
// only by our friend MeasuringGuard class.
|
||||
virtual void BeginMeasuring() { }
|
||||
virtual void EndMeasuring() { }
|
||||
|
||||
|
||||
// The main function of this class, to be implemented in platform-specific
|
||||
// way used by all our public methods.
|
||||
//
|
||||
// The width and height pointers here are never NULL and the input string
|
||||
// is not empty.
|
||||
virtual void DoGetTextExtent(const wxString& string,
|
||||
wxCoord *width,
|
||||
wxCoord *height,
|
||||
wxCoord *descent = NULL,
|
||||
wxCoord *externalLeading = NULL) = 0;
|
||||
|
||||
// The real implementation of GetPartialTextExtents().
|
||||
//
|
||||
// On input, widths array contains text.length() zero elements and the text
|
||||
// is guaranteed to be non-empty.
|
||||
virtual bool DoGetPartialTextExtents(const wxString& text,
|
||||
wxArrayInt& widths,
|
||||
double scaleX) = 0;
|
||||
|
||||
// Call either DoGetTextExtent() or wxDC::GetTextExtent() depending on the
|
||||
// value of m_useDCImpl.
|
||||
//
|
||||
// This must be always used instead of calling DoGetTextExtent() directly!
|
||||
void CallGetTextExtent(const wxString& string,
|
||||
wxCoord *width,
|
||||
wxCoord *height,
|
||||
wxCoord *descent = NULL,
|
||||
wxCoord *externalLeading = NULL);
|
||||
|
||||
// Get line height: used when the line is empty because CallGetTextExtent()
|
||||
// would just return (0, 0) in this case.
|
||||
int GetEmptyLineHeight();
|
||||
|
||||
// Return a valid font: if one was given to us in the ctor, use this one,
|
||||
// otherwise use the current font of the associated wxDC or wxWindow.
|
||||
wxFont GetFont() const;
|
||||
|
||||
|
||||
// Exactly one of m_dc and m_win is non-NULL for any given object of this
|
||||
// class.
|
||||
const wxDC* const m_dc;
|
||||
const wxWindow* const m_win;
|
||||
|
||||
// If this is true, simply forward to wxDC::GetTextExtent() from our
|
||||
// CallGetTextExtent() instead of calling our own DoGetTextExtent().
|
||||
//
|
||||
// We need this because our DoGetTextExtent() typically only works with
|
||||
// native DCs, i.e. those having an HDC under Windows or using Pango under
|
||||
// GTK+. However wxTextMeasure object can be constructed for any wxDC, not
|
||||
// necessarily a native one and in this case we must call back into the DC
|
||||
// implementation of text measuring itself.
|
||||
bool m_useDCImpl;
|
||||
|
||||
// This one can be NULL or not.
|
||||
const wxFont* const m_font;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxTextMeasureBase);
|
||||
};
|
||||
|
||||
// Include the platform dependent class declaration, if any.
|
||||
#if defined(__WXGTK20__)
|
||||
#include "wx/gtk/private/textmeasure.h"
|
||||
#elif defined(__WXMSW__)
|
||||
#include "wx/msw/private/textmeasure.h"
|
||||
#else // no platform-specific implementation of wxTextMeasure yet
|
||||
#include "wx/generic/private/textmeasure.h"
|
||||
|
||||
#define wxUSE_GENERIC_TEXTMEASURE 1
|
||||
#endif
|
||||
|
||||
#ifndef wxUSE_GENERIC_TEXTMEASURE
|
||||
#define wxUSE_GENERIC_TEXTMEASURE 0
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_TEXTMEASURE_H_
|
||||
69
wxheaders/wx/private/threadinfo.h
Normal file
69
wxheaders/wx/private/threadinfo.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/threadinfo.h
|
||||
// Purpose: declaration of wxThreadSpecificInfo: thread-specific information
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2009-07-13
|
||||
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_THREADINFO_H_
|
||||
#define _WX_PRIVATE_THREADINFO_H_
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_BASE wxLog;
|
||||
|
||||
#if wxUSE_INTL
|
||||
#include "wx/hashset.h"
|
||||
WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual,
|
||||
wxLocaleUntranslatedStrings);
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxThreadSpecificInfo: contains all thread-specific information used by wx
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Group all thread-specific information we use (e.g. the active wxLog target)
|
||||
// a in this class to avoid consuming more TLS slots than necessary as there is
|
||||
// only a limited number of them.
|
||||
class wxThreadSpecificInfo
|
||||
{
|
||||
public:
|
||||
// Return this thread's instance.
|
||||
static wxThreadSpecificInfo& Get();
|
||||
|
||||
// the thread-specific logger or NULL if the thread is using the global one
|
||||
// (this is not used for the main thread which always uses the global
|
||||
// logger)
|
||||
wxLog *logger;
|
||||
|
||||
// true if logging is currently disabled for this thread (this is also not
|
||||
// used for the main thread which uses wxLog::ms_doLog)
|
||||
//
|
||||
// NB: we use a counter-intuitive "disabled" flag instead of "enabled" one
|
||||
// because the default, for 0-initialized struct, should be to enable
|
||||
// logging
|
||||
bool loggingDisabled;
|
||||
|
||||
#if wxUSE_INTL
|
||||
// Storage for wxTranslations::GetUntranslatedString()
|
||||
wxLocaleUntranslatedStrings untranslatedStrings;
|
||||
#endif
|
||||
|
||||
#if wxUSE_THREADS
|
||||
// Cleans up storage for the current thread. Should be called when a thread
|
||||
// is being destroyed. If it's not called, the only bad thing that happens
|
||||
// is that the memory is deallocated later, on process termination.
|
||||
static void ThreadCleanUp();
|
||||
#endif
|
||||
|
||||
private:
|
||||
wxThreadSpecificInfo() : logger(NULL), loggingDisabled(false) {}
|
||||
};
|
||||
|
||||
#define wxThreadInfo wxThreadSpecificInfo::Get()
|
||||
|
||||
#endif // _WX_PRIVATE_THREADINFO_H_
|
||||
|
||||
72
wxheaders/wx/private/timer.h
Normal file
72
wxheaders/wx/private/timer.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/timer.h
|
||||
// Purpose: Base class for wxTimer implementations
|
||||
// Author: Lukasz Michalski <lmichalski@sf.net>
|
||||
// Created: 31.10.2006
|
||||
// Copyright: (c) 2006-2007 wxWidgets dev team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_TIMERIMPL_H_BASE_
|
||||
#define _WX_TIMERIMPL_H_BASE_
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/event.h"
|
||||
#include "wx/timer.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTimerImpl: abstract base class for wxTimer implementations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_BASE wxTimerImpl
|
||||
{
|
||||
public:
|
||||
// default ctor, SetOwner() must be called after it (wxTimer does it)
|
||||
wxTimerImpl(wxTimer *owner);
|
||||
|
||||
// this must be called initially but may be also called later
|
||||
void SetOwner(wxEvtHandler *owner, int timerid);
|
||||
|
||||
// empty but virtual base class dtor, the caller is responsible for
|
||||
// stopping the timer before it's destroyed (it can't be done from here as
|
||||
// it's too late)
|
||||
virtual ~wxTimerImpl() { }
|
||||
|
||||
|
||||
// start the timer. When overriding call base version first.
|
||||
virtual bool Start(int milliseconds = -1, bool oneShot = false);
|
||||
|
||||
// stop the timer, only called if the timer is really running (unlike
|
||||
// wxTimer::Stop())
|
||||
virtual void Stop() = 0;
|
||||
|
||||
// return true if the timer is running
|
||||
virtual bool IsRunning() const = 0;
|
||||
|
||||
// this should be called by the port-specific code when the timer expires
|
||||
virtual void Notify() { m_timer->Notify(); }
|
||||
|
||||
// the default implementation of wxTimer::Notify(): generate a wxEVT_TIMER
|
||||
void SendEvent();
|
||||
|
||||
|
||||
// accessors for wxTimer:
|
||||
wxEvtHandler *GetOwner() const { return m_owner; }
|
||||
int GetId() const { return m_idTimer; }
|
||||
int GetInterval() const { return m_milli; }
|
||||
bool IsOneShot() const { return m_oneShot; }
|
||||
|
||||
protected:
|
||||
wxTimer *m_timer;
|
||||
|
||||
wxEvtHandler *m_owner;
|
||||
|
||||
int m_idTimer; // id passed to wxTimerEvent
|
||||
int m_milli; // the timer interval
|
||||
bool m_oneShot; // true if one shot
|
||||
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxTimerImpl);
|
||||
};
|
||||
|
||||
#endif // _WX_TIMERIMPL_H_BASE_
|
||||
184
wxheaders/wx/private/tlwgeom.h
Normal file
184
wxheaders/wx/private/tlwgeom.h
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/tlwgeom.h
|
||||
// Purpose: Declaration of platform-specific and private wxTLWGeometry.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2018-04-29
|
||||
// Copyright: (c) 2018 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_TLWGEOM_H_
|
||||
#define _WX_PRIVATE_TLWGEOM_H_
|
||||
|
||||
#include "wx/display.h"
|
||||
#include "wx/toplevel.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTLWGeometryBase: abstract base class for platform-specific classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// wxTLWGeometry contains full information about the window geometry, which may
|
||||
// include things other than the obvious ones like its current position and
|
||||
// size (e.g. under MSW it also stores the position of the maximized window,
|
||||
// under GTK the size of non-client decorations etc). It is private to wx and
|
||||
// is only used indirectly, via wxTopLevelWindow::SaveGeometry() and
|
||||
// RestoreToGeometry() methods, in the public API.
|
||||
|
||||
class wxTLWGeometryBase
|
||||
{
|
||||
public:
|
||||
typedef wxTopLevelWindow::GeometrySerializer Serializer;
|
||||
|
||||
wxTLWGeometryBase() {}
|
||||
virtual ~wxTLWGeometryBase() {}
|
||||
|
||||
// Initialize from the given window.
|
||||
virtual bool GetFrom(const wxTopLevelWindow* tlw) = 0;
|
||||
|
||||
// Resize the window to use this geometry.
|
||||
virtual bool ApplyTo(wxTopLevelWindow* tlw) = 0;
|
||||
|
||||
// Serialize or deserialize the object by using the provided object for
|
||||
// writing/reading the values of the different fields of this object.
|
||||
virtual bool Save(const Serializer& ser) const = 0;
|
||||
virtual bool Restore(Serializer& ser) = 0;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTLWGeometryGeneric: simplest possible generic implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// names for various persistent options
|
||||
#define wxPERSIST_TLW_X "x"
|
||||
#define wxPERSIST_TLW_Y "y"
|
||||
#define wxPERSIST_TLW_W "w"
|
||||
#define wxPERSIST_TLW_H "h"
|
||||
|
||||
#define wxPERSIST_TLW_MAXIMIZED "Maximized"
|
||||
#define wxPERSIST_TLW_ICONIZED "Iconized"
|
||||
|
||||
// MSW has its own native implementation and doesn't use this class.
|
||||
#ifndef __WXMSW__
|
||||
|
||||
class wxTLWGeometryGeneric : public wxTLWGeometryBase
|
||||
{
|
||||
public:
|
||||
wxTLWGeometryGeneric()
|
||||
{
|
||||
m_hasPos =
|
||||
m_hasSize =
|
||||
m_iconized =
|
||||
m_maximized = false;
|
||||
}
|
||||
|
||||
virtual bool Save(const Serializer& ser) const wxOVERRIDE
|
||||
{
|
||||
if ( !ser.SaveField(wxPERSIST_TLW_X, m_rectScreen.x) ||
|
||||
!ser.SaveField(wxPERSIST_TLW_Y, m_rectScreen.y) )
|
||||
return false;
|
||||
|
||||
if ( !ser.SaveField(wxPERSIST_TLW_W, m_rectScreen.width) ||
|
||||
!ser.SaveField(wxPERSIST_TLW_H, m_rectScreen.height) )
|
||||
return false;
|
||||
|
||||
if ( !ser.SaveField(wxPERSIST_TLW_MAXIMIZED, m_maximized) )
|
||||
return false;
|
||||
|
||||
if ( !ser.SaveField(wxPERSIST_TLW_ICONIZED, m_iconized) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool Restore(Serializer& ser) wxOVERRIDE
|
||||
{
|
||||
m_hasPos = ser.RestoreField(wxPERSIST_TLW_X, &m_rectScreen.x) &&
|
||||
ser.RestoreField(wxPERSIST_TLW_Y, &m_rectScreen.y);
|
||||
|
||||
m_hasSize = ser.RestoreField(wxPERSIST_TLW_W, &m_rectScreen.width) &&
|
||||
ser.RestoreField(wxPERSIST_TLW_H, &m_rectScreen.height);
|
||||
|
||||
int tmp;
|
||||
if ( ser.RestoreField(wxPERSIST_TLW_MAXIMIZED, &tmp) )
|
||||
m_maximized = tmp != 0;
|
||||
|
||||
if ( ser.RestoreField(wxPERSIST_TLW_ICONIZED, &tmp) )
|
||||
m_iconized = tmp != 0;
|
||||
|
||||
// If we restored at least something, return true.
|
||||
return m_hasPos || m_hasSize || m_maximized || m_iconized;
|
||||
}
|
||||
|
||||
virtual bool GetFrom(const wxTopLevelWindow* tlw) wxOVERRIDE
|
||||
{
|
||||
m_rectScreen = tlw->GetScreenRect();
|
||||
m_hasPos =
|
||||
m_hasSize = true;
|
||||
m_iconized = tlw->IsIconized();
|
||||
m_maximized = tlw->IsMaximized();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool ApplyTo(wxTopLevelWindow* tlw) wxOVERRIDE
|
||||
{
|
||||
if ( m_hasPos )
|
||||
{
|
||||
// to avoid making the window completely invisible if it had been
|
||||
// shown on a monitor which was disconnected since the last run
|
||||
// (this is pretty common for notebook with external displays)
|
||||
//
|
||||
// NB: we should allow window position to be (slightly) off screen,
|
||||
// it's not uncommon to position the window so that its upper
|
||||
// left corner has slightly negative coordinate
|
||||
if ( wxDisplay::GetFromPoint(m_rectScreen.GetTopLeft()) != wxNOT_FOUND ||
|
||||
(m_hasSize &&
|
||||
wxDisplay::GetFromPoint(m_rectScreen.GetBottomRight()) != wxNOT_FOUND) )
|
||||
{
|
||||
tlw->Move(m_rectScreen.GetTopLeft(), wxSIZE_ALLOW_MINUS_ONE);
|
||||
}
|
||||
//else: should we try to adjust position/size somehow?
|
||||
}
|
||||
|
||||
if ( m_hasSize )
|
||||
{
|
||||
// a previous version of the program could have saved the window
|
||||
// size which used to be big enough, but which is not big enough
|
||||
// any more for the new version, so check that the size we restore
|
||||
// doesn't cut off parts of the window
|
||||
wxSize size = m_rectScreen.GetSize();
|
||||
size.IncTo(tlw->GetBestSize());
|
||||
tlw->SetSize(size);
|
||||
}
|
||||
|
||||
// note that the window can be both maximized and iconized
|
||||
if ( m_maximized )
|
||||
tlw->Maximize();
|
||||
|
||||
if ( m_iconized )
|
||||
tlw->Iconize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
wxRect m_rectScreen;
|
||||
bool m_hasPos;
|
||||
bool m_hasSize;
|
||||
bool m_iconized;
|
||||
bool m_maximized;
|
||||
};
|
||||
|
||||
#endif // !__WXMSW__
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
#include "wx/gtk/private/tlwgeom.h"
|
||||
#elif defined(__WXMSW__)
|
||||
#include "wx/msw/private/tlwgeom.h"
|
||||
#else
|
||||
class wxTLWGeometry : public wxTLWGeometryGeneric
|
||||
{
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // _WX_PRIVATE_TLWGEOM_H_
|
||||
44
wxheaders/wx/private/uiaction.h
Normal file
44
wxheaders/wx/private/uiaction.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/uiaction.h
|
||||
// Purpose: wxUIActionSimulatorImpl declaration
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2016-05-21
|
||||
// Copyright: (c) 2016 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_UIACTION_H_
|
||||
#define _WX_PRIVATE_UIACTION_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Platform-specific implementation of wxUIActionSimulator
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxUIActionSimulatorImpl
|
||||
{
|
||||
public:
|
||||
wxUIActionSimulatorImpl() { }
|
||||
virtual ~wxUIActionSimulatorImpl() { }
|
||||
|
||||
// Low level mouse methods which must be implemented in the derived class.
|
||||
virtual bool MouseMove(long x, long y) = 0;
|
||||
virtual bool MouseDown(int button = wxMOUSE_BTN_LEFT) = 0;
|
||||
virtual bool MouseUp(int button = wxMOUSE_BTN_LEFT) = 0;
|
||||
|
||||
// Higher level mouse methods which have default implementation in the base
|
||||
// class but can be overridden if necessary.
|
||||
virtual bool MouseClick(int button = wxMOUSE_BTN_LEFT);
|
||||
virtual bool MouseDblClick(int button = wxMOUSE_BTN_LEFT);
|
||||
virtual bool MouseDragDrop(long x1, long y1, long x2, long y2,
|
||||
int button = wxMOUSE_BTN_LEFT);
|
||||
|
||||
// The low-level port-specific function which really generates the key
|
||||
// presses. It should generate exactly one key event with the given
|
||||
// parameters.
|
||||
virtual bool DoKey(int keycode, int modifiers, bool isDown) = 0;
|
||||
|
||||
private:
|
||||
wxDECLARE_NO_COPY_CLASS(wxUIActionSimulatorImpl);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_UIACTION_H_
|
||||
90
wxheaders/wx/private/uilocale.h
Normal file
90
wxheaders/wx/private/uilocale.h
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/uilocale.h
|
||||
// Purpose: wxUILocaleImpl class declaration
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2021-08-01
|
||||
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_UILOCALE_H_
|
||||
#define _WX_PRIVATE_UILOCALE_H_
|
||||
|
||||
#include "wx/localedefs.h"
|
||||
#include "wx/object.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/vector.h"
|
||||
|
||||
typedef wxVector<wxLanguageInfo> wxLanguageInfos;
|
||||
|
||||
// Return the vector of all languages known to wx.
|
||||
const wxLanguageInfos& wxGetLanguageInfos();
|
||||
|
||||
// Function returning hard-coded values for the "C" locale.
|
||||
wxString wxGetStdCLocaleInfo(wxLocaleInfo index, wxLocaleCategory cat);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxUILocaleImpl provides the implementation of public wxUILocale functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxUILocaleImpl : public wxRefCounter
|
||||
{
|
||||
public:
|
||||
// This function is implemented in platform-specific code and returns the
|
||||
// object used by default, i.e. if wxUILocale::UseDefault() is not called.
|
||||
// This object corresponds to the traditional "C" locale.
|
||||
//
|
||||
// It should never return NULL.
|
||||
static wxUILocaleImpl* CreateStdC();
|
||||
|
||||
// Similarly, this one returns the object corresponding to the default user
|
||||
// locale settings which is used if wxUILocale::UseDefault() was called.
|
||||
//
|
||||
// It may return NULL in case of failure.
|
||||
static wxUILocaleImpl* CreateUserDefault();
|
||||
|
||||
// Create locale object for the given locale.
|
||||
//
|
||||
// It may return NULL in case of failure.
|
||||
static wxUILocaleImpl* CreateForLocale(const wxLocaleIdent& locId);
|
||||
|
||||
// This function exists only for wxLocale compatibility and creates the
|
||||
// locale corresponding to the given language. It shouldn't be used
|
||||
// anywhere else.
|
||||
//
|
||||
// It is implemented in terms of CreateForLocale() for non-MSW platforms,
|
||||
// but under MSW it is different for compatibility reasons.
|
||||
//
|
||||
// The language passed to this function is a valid language, i.e. neither
|
||||
// wxLANGUAGE_UNKNOWN nor wxLANGUAGE_DEFAULT.
|
||||
//
|
||||
// It may return NULL in case of failure, but never does so for English
|
||||
// languages because wxLocale(wxLANGUAGE_ENGLISH) is always supposed to
|
||||
// work, so it just falls back on CreateStdC() if it fails to create it.
|
||||
static wxUILocaleImpl* CreateForLanguage(const wxLanguageInfo& info);
|
||||
|
||||
// This function retrieves a list of preferred UI languages.
|
||||
// The list is in the order of preference, if it has more than one entry.
|
||||
// The entries contain platform-dependent identifiers.
|
||||
static wxVector<wxString> GetPreferredUILanguages();
|
||||
|
||||
// Use this locale in the UI.
|
||||
//
|
||||
// This is not implemented for all platforms, notably not for Mac where the
|
||||
// UI locale is determined at application startup, but we can't do anything
|
||||
// about it anyhow, so we don't even bother returning an error code from it.
|
||||
virtual void Use() = 0;
|
||||
|
||||
// Functions corresponding to wxUILocale ones.
|
||||
virtual wxString GetName() const = 0;
|
||||
virtual wxLocaleIdent GetLocaleId() const = 0;
|
||||
virtual wxString GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const = 0;
|
||||
virtual wxString GetLocalizedName(wxLocaleName name, wxLocaleForm form) const = 0;
|
||||
virtual wxLayoutDirection GetLayoutDirection() const = 0;
|
||||
virtual int CompareStrings(const wxString& lhs, const wxString& rhs,
|
||||
int flags) const = 0;
|
||||
|
||||
virtual ~wxUILocaleImpl() { }
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_UILOCALE_H_
|
||||
16
wxheaders/wx/private/unicode.h
Normal file
16
wxheaders/wx/private/unicode.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/unicode.h
|
||||
// Purpose: Unicode private declsrations
|
||||
// Author: Pavel Tyunin
|
||||
// Created: 2020-10-06
|
||||
// Copyright: (c) 2020 Pavel Tyunin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_UNICODEH__
|
||||
#define _WX_PRIVATE_UNICODEH__
|
||||
|
||||
// this table gives the length of the UTF-8 encoding from its first character:
|
||||
extern const unsigned char tableUtf8Lengths[256];
|
||||
|
||||
#endif // _WX_PRIVATE_UNICODEH__
|
||||
268
wxheaders/wx/private/webrequest.h
Normal file
268
wxheaders/wx/private/webrequest.h
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/webrequest.h
|
||||
// Purpose: wxWebRequest implementation classes
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2020-12-26
|
||||
// Copyright: (c) 2020 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_WEBREQUEST_H_
|
||||
#define _WX_PRIVATE_WEBREQUEST_H_
|
||||
|
||||
#include "wx/ffile.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/scopedptr.h"
|
||||
|
||||
#include "wx/private/refcountermt.h"
|
||||
|
||||
WX_DECLARE_STRING_HASH_MAP(wxString, wxWebRequestHeaderMap);
|
||||
|
||||
// Default buffer size when a fixed-size buffer must be used.
|
||||
const int wxWEBREQUEST_BUFFER_SIZE = 64 * 1024;
|
||||
|
||||
// Trace mask used for the messages in wxWebRequest code.
|
||||
#define wxTRACE_WEBREQUEST "webrequest"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWebAuthChallengeImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxWebAuthChallengeImpl : public wxRefCounterMT
|
||||
{
|
||||
public:
|
||||
virtual ~wxWebAuthChallengeImpl() { }
|
||||
|
||||
wxWebAuthChallenge::Source GetSource() const { return m_source; }
|
||||
|
||||
virtual void SetCredentials(const wxWebCredentials& cred) = 0;
|
||||
|
||||
protected:
|
||||
explicit wxWebAuthChallengeImpl(wxWebAuthChallenge::Source source)
|
||||
: m_source(source) { }
|
||||
|
||||
private:
|
||||
const wxWebAuthChallenge::Source m_source;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebAuthChallengeImpl);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWebRequestImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxWebRequestImpl : public wxRefCounterMT
|
||||
{
|
||||
public:
|
||||
virtual ~wxWebRequestImpl() { }
|
||||
|
||||
void SetHeader(const wxString& name, const wxString& value)
|
||||
{ m_headers[name] = value; }
|
||||
|
||||
void SetMethod(const wxString& method) { m_method = method; }
|
||||
|
||||
void SetData(const wxString& text, const wxString& contentType, const wxMBConv& conv = wxConvUTF8);
|
||||
|
||||
bool SetData(wxScopedPtr<wxInputStream>& dataStream, const wxString& contentType, wxFileOffset dataSize = wxInvalidOffset);
|
||||
|
||||
void SetStorage(wxWebRequest::Storage storage) { m_storage = storage; }
|
||||
|
||||
wxWebRequest::Storage GetStorage() const { return m_storage; }
|
||||
|
||||
// Precondition for this method checked by caller: current state is idle.
|
||||
virtual void Start() = 0;
|
||||
|
||||
// Precondition for this method checked by caller: not idle and not already
|
||||
// cancelled.
|
||||
void Cancel();
|
||||
|
||||
virtual wxWebResponseImplPtr GetResponse() const = 0;
|
||||
|
||||
virtual wxWebAuthChallengeImplPtr GetAuthChallenge() const = 0;
|
||||
|
||||
int GetId() const { return m_id; }
|
||||
|
||||
wxWebSession& GetSession() const { return m_session; }
|
||||
|
||||
wxWebRequest::State GetState() const { return m_state; }
|
||||
|
||||
virtual wxFileOffset GetBytesSent() const = 0;
|
||||
|
||||
virtual wxFileOffset GetBytesExpectedToSend() const = 0;
|
||||
|
||||
virtual wxFileOffset GetBytesReceived() const;
|
||||
|
||||
virtual wxFileOffset GetBytesExpectedToReceive() const;
|
||||
|
||||
virtual wxWebRequestHandle GetNativeHandle() const = 0;
|
||||
|
||||
void DisablePeerVerify(bool disable) { m_peerVerifyDisabled = disable; }
|
||||
|
||||
bool IsPeerVerifyDisabled() const { return m_peerVerifyDisabled; }
|
||||
|
||||
void SetState(wxWebRequest::State state, const wxString& failMsg = wxString());
|
||||
|
||||
void ReportDataReceived(size_t sizeReceived);
|
||||
|
||||
wxEvtHandler* GetHandler() const { return m_handler; }
|
||||
|
||||
// Called to notify about the state change in the main thread by SetState()
|
||||
// (which can itself be called from a different one).
|
||||
//
|
||||
// It also releases a reference added when switching to the active state by
|
||||
// SetState() when leaving it.
|
||||
//
|
||||
// TODO-C++11: make private when we don't need StateEventProcessor any more.
|
||||
void ProcessStateEvent(wxWebRequest::State state, const wxString& failMsg);
|
||||
|
||||
protected:
|
||||
wxString m_method;
|
||||
wxWebRequest::Storage m_storage;
|
||||
wxWebRequestHeaderMap m_headers;
|
||||
wxFileOffset m_dataSize;
|
||||
wxScopedPtr<wxInputStream> m_dataStream;
|
||||
bool m_peerVerifyDisabled;
|
||||
|
||||
wxWebRequestImpl(wxWebSession& session,
|
||||
wxWebSessionImpl& sessionImpl,
|
||||
wxEvtHandler* handler,
|
||||
int id);
|
||||
|
||||
bool WasCancelled() const { return m_cancelled; }
|
||||
|
||||
// Call SetState() with either State_Failed or State_Completed appropriate
|
||||
// for the response status.
|
||||
void SetFinalStateFromStatus();
|
||||
|
||||
private:
|
||||
// Called from public Cancel() at most once per object.
|
||||
virtual void DoCancel() = 0;
|
||||
|
||||
wxWebSession& m_session;
|
||||
wxEvtHandler* const m_handler;
|
||||
const int m_id;
|
||||
wxWebRequest::State m_state;
|
||||
wxFileOffset m_bytesReceived;
|
||||
wxCharBuffer m_dataText;
|
||||
|
||||
// Initially false, set to true after the first call to Cancel().
|
||||
bool m_cancelled;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebRequestImpl);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWebResponseImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxWebResponseImpl : public wxRefCounterMT
|
||||
{
|
||||
public:
|
||||
virtual ~wxWebResponseImpl();
|
||||
|
||||
virtual wxFileOffset GetContentLength() const = 0;
|
||||
|
||||
virtual wxString GetURL() const = 0;
|
||||
|
||||
virtual wxString GetHeader(const wxString& name) const = 0;
|
||||
|
||||
virtual wxString GetMimeType() const;
|
||||
|
||||
virtual int GetStatus() const = 0;
|
||||
|
||||
virtual wxString GetStatusText() const = 0;
|
||||
|
||||
virtual wxInputStream* GetStream() const;
|
||||
|
||||
virtual wxString GetSuggestedFileName() const;
|
||||
|
||||
wxString AsString() const;
|
||||
|
||||
virtual wxString GetDataFile() const;
|
||||
|
||||
protected:
|
||||
wxWebRequestImpl& m_request;
|
||||
size_t m_readSize;
|
||||
|
||||
explicit wxWebResponseImpl(wxWebRequestImpl& request);
|
||||
|
||||
// Called from derived class ctor to finish initialization which can't be
|
||||
// performed in ctor itself as it needs to use pure virtual method.
|
||||
void Init();
|
||||
|
||||
void* GetDataBuffer(size_t sizeNeeded);
|
||||
|
||||
void ReportDataReceived(size_t sizeReceived);
|
||||
|
||||
// This function can optionally be called to preallocate the read buffer,
|
||||
// if the total amount of data to be downloaded is known in advance.
|
||||
void PreAllocBuffer(size_t sizeNeeded);
|
||||
|
||||
private:
|
||||
// Called by wxWebRequestImpl only.
|
||||
friend class wxWebRequestImpl;
|
||||
void Finalize();
|
||||
|
||||
wxMemoryBuffer m_readBuffer;
|
||||
mutable wxFFile m_file;
|
||||
mutable wxScopedPtr<wxInputStream> m_stream;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebResponseImpl);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWebSessionFactory
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxWebSessionFactory
|
||||
{
|
||||
public:
|
||||
virtual wxWebSessionImpl* Create() = 0;
|
||||
|
||||
virtual bool Initialize() { return true; }
|
||||
|
||||
virtual ~wxWebSessionFactory() { }
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWebSessionImpl
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxWebSessionImpl : public wxRefCounterMT
|
||||
{
|
||||
public:
|
||||
virtual ~wxWebSessionImpl() { }
|
||||
|
||||
virtual wxWebRequestImplPtr
|
||||
CreateRequest(wxWebSession& session,
|
||||
wxEvtHandler* handler,
|
||||
const wxString& url,
|
||||
int id) = 0;
|
||||
|
||||
virtual wxVersionInfo GetLibraryVersionInfo() = 0;
|
||||
|
||||
void AddCommonHeader(const wxString& name, const wxString& value)
|
||||
{ m_headers[name] = value; }
|
||||
|
||||
void SetTempDir(const wxString& dir) { m_tempDir = dir; }
|
||||
|
||||
wxString GetTempDir() const;
|
||||
|
||||
const wxWebRequestHeaderMap& GetHeaders() const { return m_headers; }
|
||||
|
||||
virtual wxWebSessionHandle GetNativeHandle() const = 0;
|
||||
|
||||
protected:
|
||||
wxWebSessionImpl();
|
||||
|
||||
private:
|
||||
// Make it a friend to allow accessing our m_headers.
|
||||
friend class wxWebRequest;
|
||||
|
||||
wxWebRequestHeaderMap m_headers;
|
||||
wxString m_tempDir;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebSessionImpl);
|
||||
};
|
||||
|
||||
#endif // _WX_PRIVATE_WEBREQUEST_H_
|
||||
202
wxheaders/wx/private/webrequest_curl.h
Normal file
202
wxheaders/wx/private/webrequest_curl.h
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/webrequest_curl.h
|
||||
// Purpose: wxWebRequest implementation using libcurl
|
||||
// Author: Tobias Taschner
|
||||
// Created: 2018-10-25
|
||||
// Copyright: (c) 2018 wxWidgets development team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_WEBREQUEST_CURL_H
|
||||
#define _WX_WEBREQUEST_CURL_H
|
||||
|
||||
#if wxUSE_WEBREQUEST_CURL
|
||||
|
||||
#include "wx/private/webrequest.h"
|
||||
|
||||
#include "wx/thread.h"
|
||||
#include "wx/vector.h"
|
||||
#include "wx/timer.h"
|
||||
#include "wx/hashmap.h"
|
||||
|
||||
#include "curl/curl.h"
|
||||
|
||||
class wxWebRequestCURL;
|
||||
class wxWebResponseCURL;
|
||||
class wxWebSessionCURL;
|
||||
class SocketPoller;
|
||||
|
||||
class wxWebAuthChallengeCURL : public wxWebAuthChallengeImpl
|
||||
{
|
||||
public:
|
||||
wxWebAuthChallengeCURL(wxWebAuthChallenge::Source source,
|
||||
wxWebRequestCURL& request);
|
||||
|
||||
void SetCredentials(const wxWebCredentials& cred) wxOVERRIDE;
|
||||
|
||||
private:
|
||||
wxWebRequestCURL& m_request;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebAuthChallengeCURL);
|
||||
};
|
||||
|
||||
class wxWebRequestCURL : public wxWebRequestImpl
|
||||
{
|
||||
public:
|
||||
wxWebRequestCURL(wxWebSession& session,
|
||||
wxWebSessionCURL& sessionImpl,
|
||||
wxEvtHandler* handler,
|
||||
const wxString& url,
|
||||
int id);
|
||||
|
||||
~wxWebRequestCURL();
|
||||
|
||||
void Start() wxOVERRIDE;
|
||||
|
||||
wxWebResponseImplPtr GetResponse() const wxOVERRIDE
|
||||
{ return m_response; }
|
||||
|
||||
wxWebAuthChallengeImplPtr GetAuthChallenge() const wxOVERRIDE
|
||||
{ return m_authChallenge; }
|
||||
|
||||
wxFileOffset GetBytesSent() const wxOVERRIDE;
|
||||
|
||||
wxFileOffset GetBytesExpectedToSend() const wxOVERRIDE;
|
||||
|
||||
CURL* GetHandle() const { return m_handle; }
|
||||
|
||||
wxWebRequestHandle GetNativeHandle() const wxOVERRIDE
|
||||
{
|
||||
return (wxWebRequestHandle)GetHandle();
|
||||
}
|
||||
|
||||
bool StartRequest();
|
||||
|
||||
void HandleCompletion();
|
||||
|
||||
wxString GetError() const;
|
||||
|
||||
// Method called from libcurl callback
|
||||
size_t CURLOnRead(char* buffer, size_t size);
|
||||
|
||||
private:
|
||||
void DoCancel() wxOVERRIDE;
|
||||
|
||||
wxWebSessionCURL& m_sessionImpl;
|
||||
|
||||
CURL* m_handle;
|
||||
char m_errorBuffer[CURL_ERROR_SIZE];
|
||||
struct curl_slist *m_headerList;
|
||||
wxObjectDataPtr<wxWebResponseCURL> m_response;
|
||||
wxObjectDataPtr<wxWebAuthChallengeCURL> m_authChallenge;
|
||||
wxFileOffset m_bytesSent;
|
||||
|
||||
void DestroyHeaderList();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebRequestCURL);
|
||||
};
|
||||
|
||||
class wxWebResponseCURL : public wxWebResponseImpl
|
||||
{
|
||||
public:
|
||||
explicit wxWebResponseCURL(wxWebRequestCURL& request);
|
||||
|
||||
wxFileOffset GetContentLength() const wxOVERRIDE;
|
||||
|
||||
wxString GetURL() const wxOVERRIDE;
|
||||
|
||||
wxString GetHeader(const wxString& name) const wxOVERRIDE;
|
||||
|
||||
int GetStatus() const wxOVERRIDE;
|
||||
|
||||
wxString GetStatusText() const wxOVERRIDE { return m_statusText; }
|
||||
|
||||
|
||||
// Methods called from libcurl callbacks
|
||||
size_t CURLOnWrite(void *buffer, size_t size);
|
||||
size_t CURLOnHeader(const char* buffer, size_t size);
|
||||
int CURLOnProgress(curl_off_t);
|
||||
|
||||
private:
|
||||
wxWebRequestHeaderMap m_headers;
|
||||
wxString m_statusText;
|
||||
wxFileOffset m_knownDownloadSize;
|
||||
|
||||
CURL* GetHandle() const
|
||||
{ return static_cast<wxWebRequestCURL&>(m_request).GetHandle(); }
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebResponseCURL);
|
||||
};
|
||||
|
||||
class wxWebSessionCURL : public wxWebSessionImpl, public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
wxWebSessionCURL();
|
||||
|
||||
~wxWebSessionCURL();
|
||||
|
||||
wxWebRequestImplPtr
|
||||
CreateRequest(wxWebSession& session,
|
||||
wxEvtHandler* handler,
|
||||
const wxString& url,
|
||||
int id = wxID_ANY) wxOVERRIDE;
|
||||
|
||||
wxVersionInfo GetLibraryVersionInfo() wxOVERRIDE;
|
||||
|
||||
wxWebSessionHandle GetNativeHandle() const wxOVERRIDE
|
||||
{
|
||||
return (wxWebSessionHandle)m_handle;
|
||||
}
|
||||
|
||||
bool StartRequest(wxWebRequestCURL& request);
|
||||
|
||||
void CancelRequest(wxWebRequestCURL* request);
|
||||
|
||||
void RequestHasTerminated(wxWebRequestCURL* request);
|
||||
|
||||
static bool CurlRuntimeAtLeastVersion(unsigned int, unsigned int,
|
||||
unsigned int);
|
||||
|
||||
private:
|
||||
static int TimerCallback(CURLM*, long, void*);
|
||||
static int SocketCallback(CURL*, curl_socket_t, int, void*, void*);
|
||||
|
||||
void ProcessTimerCallback(long);
|
||||
void TimeoutNotification(wxTimerEvent&);
|
||||
void ProcessTimeoutNotification();
|
||||
void ProcessSocketCallback(CURL*, curl_socket_t, int);
|
||||
void ProcessSocketPollerResult(wxThreadEvent&);
|
||||
void CheckForCompletedTransfers();
|
||||
void FailRequest(CURL*, const wxString&);
|
||||
void StopActiveTransfer(CURL*);
|
||||
void RemoveActiveSocket(CURL*);
|
||||
|
||||
WX_DECLARE_HASH_MAP(CURL*, wxWebRequestCURL*, wxPointerHash, \
|
||||
wxPointerEqual, TransferSet);
|
||||
|
||||
WX_DECLARE_HASH_MAP(CURL*, curl_socket_t, wxPointerHash, \
|
||||
wxPointerEqual, CurlSocketMap);
|
||||
|
||||
TransferSet m_activeTransfers;
|
||||
CurlSocketMap m_activeSockets;
|
||||
|
||||
SocketPoller* m_socketPoller;
|
||||
wxTimer m_timeoutTimer;
|
||||
CURLM* m_handle;
|
||||
|
||||
static int ms_activeSessions;
|
||||
static unsigned int ms_runtimeVersion;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxWebSessionCURL);
|
||||
};
|
||||
|
||||
class wxWebSessionFactoryCURL : public wxWebSessionFactory
|
||||
{
|
||||
public:
|
||||
wxWebSessionImpl* Create() wxOVERRIDE
|
||||
{ return new wxWebSessionCURL(); }
|
||||
};
|
||||
|
||||
#endif // wxUSE_WEBREQUEST_CURL
|
||||
|
||||
#endif
|
||||
100
wxheaders/wx/private/window.h
Normal file
100
wxheaders/wx/private/window.h
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/window.h
|
||||
// Purpose: misc wxWindow helpers
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2010-01-21
|
||||
// Copyright: (c) 2010 Vaclav Slavik
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_WINDOW_H_
|
||||
#define _WX_PRIVATE_WINDOW_H_
|
||||
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
namespace wxPrivate
|
||||
{
|
||||
|
||||
// Windows' computes dialog units using average character width over upper-
|
||||
// and lower-case ASCII alphabet and not using the average character width
|
||||
// metadata stored in the font; see
|
||||
// http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
|
||||
//
|
||||
// This helper function computes font dimensions in the same way. It works with
|
||||
// either wxDC or wxWindow argument.
|
||||
template<typename T>
|
||||
inline wxSize GetAverageASCIILetterSize(const T& of_what)
|
||||
{
|
||||
const wxStringCharType *TEXT_TO_MEASURE =
|
||||
wxS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
wxSize s = of_what.GetTextExtent(TEXT_TO_MEASURE);
|
||||
s.x = (s.x / 26 + 1) / 2;
|
||||
return s;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
inline bool SupportsPerMonitorDPI()
|
||||
{
|
||||
static bool s_checkDPI =
|
||||
#if defined(__WXMSW__) && wxUSE_DYNLIB_CLASS
|
||||
// Only check the DPI when GetDpiForWindow is available because the old
|
||||
// method (GetDeviceCaps) is a lot slower (about 1500 times).
|
||||
// And when GetDpiForWindow is not available (for example older Windows
|
||||
// versions), per-monitor DPI (V2) is also not available.
|
||||
wxLoadedDLL("user32.dll").HasSymbol("GetDpiForWindow");
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
return s_checkDPI;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class DpiDependentValue
|
||||
{
|
||||
public:
|
||||
// Explicit initialization is needed if T is a primitive type.
|
||||
DpiDependentValue()
|
||||
: m_value(), m_dpi()
|
||||
{ }
|
||||
|
||||
bool HasChanged(const wxWindowBase* win)
|
||||
{
|
||||
if ( win && SupportsPerMonitorDPI() )
|
||||
{
|
||||
const wxSize dpi = win->GetDPI();
|
||||
if ( dpi != m_dpi )
|
||||
{
|
||||
m_dpi = dpi;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that we return true the first time we're called,
|
||||
// assuming that the value will always be set to a non-default value.
|
||||
return m_value == T();
|
||||
}
|
||||
|
||||
void SetAtNewDPI(const T& value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
T& Get()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_value;
|
||||
wxSize m_dpi;
|
||||
};
|
||||
|
||||
} // namespace wxPrivate
|
||||
|
||||
#endif // _WX_PRIVATE_WINDOW_H_
|
||||
968
wxheaders/wx/private/wxprintf.h
Normal file
968
wxheaders/wx/private/wxprintf.h
Normal file
|
|
@ -0,0 +1,968 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/private/wxprintf.h
|
||||
// Purpose: wxWidgets wxPrintf() implementation
|
||||
// Author: Ove Kaven
|
||||
// Modified by: Ron Lee, Francesco Montorsi
|
||||
// Created: 09/04/99
|
||||
// Copyright: (c) wxWidgets copyright
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_PRIVATE_WXPRINTF_H_
|
||||
#define _WX_PRIVATE_WXPRINTF_H_
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// headers and macros
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "wx/crt.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/utils.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
// prefer snprintf over sprintf
|
||||
#if defined(__VISUALC__)
|
||||
#define system_sprintf(buff, max, flags, data) \
|
||||
::_snprintf(buff, max, flags, data)
|
||||
#elif defined(HAVE_SNPRINTF)
|
||||
#define system_sprintf(buff, max, flags, data) \
|
||||
::snprintf(buff, max, flags, data)
|
||||
#else // NB: at least sprintf() should always be available
|
||||
// since 'max' is not used in this case, wxVsnprintf() should always
|
||||
// ensure that 'buff' is big enough for all common needs
|
||||
// (see wxMAX_SVNPRINTF_FLAGBUFFER_LEN and wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN)
|
||||
#define system_sprintf(buff, max, flags, data) \
|
||||
::sprintf(buff, flags, data)
|
||||
|
||||
#define SYSTEM_SPRINTF_IS_UNSAFE
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// printf format string parsing
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// some limits of our implementation
|
||||
#define wxMAX_SVNPRINTF_ARGUMENTS 64
|
||||
#define wxMAX_SVNPRINTF_FLAGBUFFER_LEN 32
|
||||
#define wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN 512
|
||||
|
||||
|
||||
// the conversion specifiers accepted by wxCRT_VsnprintfW
|
||||
enum wxPrintfArgType
|
||||
{
|
||||
wxPAT_INVALID = -1,
|
||||
|
||||
wxPAT_INT, // %d, %i, %o, %u, %x, %X
|
||||
wxPAT_LONGINT, // %ld, etc
|
||||
#ifdef wxLongLong_t
|
||||
wxPAT_LONGLONGINT, // %Ld, etc
|
||||
#endif
|
||||
wxPAT_SIZET, // %zd, etc
|
||||
|
||||
wxPAT_DOUBLE, // %e, %E, %f, %g, %G
|
||||
wxPAT_LONGDOUBLE, // %le, etc
|
||||
|
||||
wxPAT_POINTER, // %p
|
||||
|
||||
wxPAT_CHAR, // %hc (in ANSI mode: %c, too)
|
||||
wxPAT_WCHAR, // %lc (in Unicode mode: %c, too)
|
||||
|
||||
wxPAT_PCHAR, // %s (related to a char *)
|
||||
wxPAT_PWCHAR, // %s (related to a wchar_t *)
|
||||
|
||||
wxPAT_NINT, // %n
|
||||
wxPAT_NSHORTINT, // %hn
|
||||
wxPAT_NLONGINT, // %ln
|
||||
|
||||
wxPAT_STAR // '*' used for width or precision
|
||||
};
|
||||
|
||||
// an argument passed to wxCRT_VsnprintfW
|
||||
union wxPrintfArg
|
||||
{
|
||||
int pad_int; // %d, %i, %o, %u, %x, %X
|
||||
long int pad_longint; // %ld, etc
|
||||
#ifdef wxLongLong_t
|
||||
wxLongLong_t pad_longlongint; // %Ld, etc
|
||||
#endif
|
||||
size_t pad_sizet; // %zd, etc
|
||||
|
||||
double pad_double; // %e, %E, %f, %g, %G
|
||||
long double pad_longdouble; // %le, etc
|
||||
|
||||
void *pad_pointer; // %p
|
||||
|
||||
char pad_char; // %hc (in ANSI mode: %c, too)
|
||||
wchar_t pad_wchar; // %lc (in Unicode mode: %c, too)
|
||||
|
||||
void *pad_str; // %s
|
||||
|
||||
int *pad_nint; // %n
|
||||
short int *pad_nshortint; // %hn
|
||||
long int *pad_nlongint; // %ln
|
||||
};
|
||||
|
||||
// helper for converting string into either char* or wchar_t* depending
|
||||
// on the type of wxPrintfConvSpec<T> instantiation:
|
||||
template<typename CharType> struct wxPrintfStringHelper {};
|
||||
|
||||
template<> struct wxPrintfStringHelper<char>
|
||||
{
|
||||
typedef const wxWX2MBbuf ConvertedType;
|
||||
static ConvertedType Convert(const wxString& s) { return s.mb_str(); }
|
||||
};
|
||||
|
||||
template<> struct wxPrintfStringHelper<wchar_t>
|
||||
{
|
||||
typedef const wxWX2WCbuf ConvertedType;
|
||||
static ConvertedType Convert(const wxString& s) { return s.wc_str(); }
|
||||
};
|
||||
|
||||
|
||||
// Contains parsed data relative to a conversion specifier given to
|
||||
// wxCRT_VsnprintfW and parsed from the format string
|
||||
// NOTE: in C++ there is almost no difference between struct & classes thus
|
||||
// there is no performance gain by using a struct here...
|
||||
template<typename CharType>
|
||||
class wxPrintfConvSpec
|
||||
{
|
||||
public:
|
||||
|
||||
// the position of the argument relative to this conversion specifier
|
||||
size_t m_pos;
|
||||
|
||||
// the type of this conversion specifier
|
||||
wxPrintfArgType m_type;
|
||||
|
||||
// the minimum and maximum width
|
||||
// when one of this var is set to -1 it means: use the following argument
|
||||
// in the stack as minimum/maximum width for this conversion specifier
|
||||
int m_nMinWidth, m_nMaxWidth;
|
||||
|
||||
// does the argument need to the be aligned to left ?
|
||||
bool m_bAlignLeft;
|
||||
|
||||
// pointer to the '%' of this conversion specifier in the format string
|
||||
// NOTE: this points somewhere in the string given to the Parse() function -
|
||||
// it's task of the caller ensure that memory is still valid !
|
||||
const CharType *m_pArgPos;
|
||||
|
||||
// pointer to the last character of this conversion specifier in the
|
||||
// format string
|
||||
// NOTE: this points somewhere in the string given to the Parse() function -
|
||||
// it's task of the caller ensure that memory is still valid !
|
||||
const CharType *m_pArgEnd;
|
||||
|
||||
// a little buffer where formatting flags like #+\.hlqLz are stored by Parse()
|
||||
// for use in Process()
|
||||
char m_szFlags[wxMAX_SVNPRINTF_FLAGBUFFER_LEN];
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// we don't declare this as a constructor otherwise it would be called
|
||||
// automatically and we don't want this: to be optimized, wxCRT_VsnprintfW
|
||||
// calls this function only on really-used instances of this class.
|
||||
void Init();
|
||||
|
||||
// Parses the first conversion specifier in the given string, which must
|
||||
// begin with a '%'. Returns false if the first '%' does not introduce a
|
||||
// (valid) conversion specifier and thus should be ignored.
|
||||
bool Parse(const CharType *format);
|
||||
|
||||
// Process this conversion specifier and puts the result in the given
|
||||
// buffer. Returns the number of characters written in 'buf' or -1 if
|
||||
// there's not enough space.
|
||||
int Process(CharType *buf, size_t lenMax, wxPrintfArg *p, size_t written);
|
||||
|
||||
// Loads the argument of this conversion specifier from given va_list.
|
||||
bool LoadArg(wxPrintfArg *p, va_list &argptr);
|
||||
|
||||
private:
|
||||
// A helper function of LoadArg() which is used to handle the '*' flag
|
||||
void ReplaceAsteriskWith(int w);
|
||||
};
|
||||
|
||||
template<typename CharType>
|
||||
void wxPrintfConvSpec<CharType>::Init()
|
||||
{
|
||||
m_nMinWidth = 0;
|
||||
m_nMaxWidth = INT_MAX;
|
||||
m_pos = 0;
|
||||
m_bAlignLeft = false;
|
||||
m_pArgPos = m_pArgEnd = NULL;
|
||||
m_type = wxPAT_INVALID;
|
||||
|
||||
memset(m_szFlags, 0, sizeof(m_szFlags));
|
||||
// this character will never be removed from m_szFlags array and
|
||||
// is important when calling sprintf() in wxPrintfConvSpec::Process() !
|
||||
m_szFlags[0] = '%';
|
||||
}
|
||||
|
||||
template<typename CharType>
|
||||
bool wxPrintfConvSpec<CharType>::Parse(const CharType *format)
|
||||
{
|
||||
bool done = false;
|
||||
|
||||
// temporary parse data
|
||||
size_t flagofs = 1;
|
||||
bool in_prec, // true if we found the dot in some previous iteration
|
||||
prec_dot; // true if the dot has been already added to m_szFlags
|
||||
int ilen = 0;
|
||||
|
||||
m_bAlignLeft = in_prec = prec_dot = false;
|
||||
m_pArgPos = m_pArgEnd = format;
|
||||
do
|
||||
{
|
||||
#define CHECK_PREC \
|
||||
if (in_prec && !prec_dot) \
|
||||
{ \
|
||||
m_szFlags[flagofs++] = '.'; \
|
||||
prec_dot = true; \
|
||||
}
|
||||
|
||||
// what follows '%'?
|
||||
const CharType ch = *(++m_pArgEnd);
|
||||
switch ( ch )
|
||||
{
|
||||
case wxT('\0'):
|
||||
return false; // not really an argument
|
||||
|
||||
case wxT('%'):
|
||||
return false; // not really an argument
|
||||
|
||||
case wxT('#'):
|
||||
case wxT('0'):
|
||||
case wxT(' '):
|
||||
case wxT('+'):
|
||||
case wxT('\''):
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
|
||||
case wxT('-'):
|
||||
CHECK_PREC
|
||||
m_bAlignLeft = true;
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
|
||||
case wxT('.'):
|
||||
// don't use CHECK_PREC here to avoid warning about the value
|
||||
// assigned to prec_dot inside it being never used (because
|
||||
// overwritten just below)
|
||||
if (in_prec && !prec_dot)
|
||||
m_szFlags[flagofs++] = '.';
|
||||
in_prec = true;
|
||||
prec_dot = false;
|
||||
m_nMaxWidth = 0;
|
||||
// dot will be auto-added to m_szFlags if non-negative
|
||||
// number follows
|
||||
break;
|
||||
|
||||
case wxT('h'):
|
||||
ilen = -1;
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
|
||||
case wxT('l'):
|
||||
// NB: it's safe to use flagofs-1 as flagofs always start from 1
|
||||
if (m_szFlags[flagofs-1] == 'l') // 'll' modifier is the same as 'L' or 'q'
|
||||
ilen = 2;
|
||||
else
|
||||
ilen = 1;
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
|
||||
case wxT('q'):
|
||||
case wxT('L'):
|
||||
ilen = 2;
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
#ifdef __WINDOWS__
|
||||
// under Windows we support the special '%I64' notation as longlong
|
||||
// integer conversion specifier for MSVC compatibility
|
||||
// (it behaves exactly as '%lli' or '%Li' or '%qi')
|
||||
case wxT('I'):
|
||||
if (*(m_pArgEnd+1) == wxT('6') &&
|
||||
*(m_pArgEnd+2) == wxT('4'))
|
||||
{
|
||||
m_pArgEnd++;
|
||||
m_pArgEnd++;
|
||||
|
||||
ilen = 2;
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
m_szFlags[flagofs++] = '6';
|
||||
m_szFlags[flagofs++] = '4';
|
||||
break;
|
||||
}
|
||||
// else: fall-through, 'I' is MSVC equivalent of C99 'z'
|
||||
wxFALLTHROUGH;
|
||||
#endif // __WINDOWS__
|
||||
|
||||
case wxT('z'):
|
||||
case wxT('Z'):
|
||||
// 'z' is C99 standard for size_t and ptrdiff_t, 'Z' was used
|
||||
// for this purpose in libc5 and by wx <= 2.8
|
||||
ilen = 3;
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
|
||||
case wxT('*'):
|
||||
if (in_prec)
|
||||
{
|
||||
CHECK_PREC
|
||||
|
||||
// tell Process() to use the next argument
|
||||
// in the stack as maxwidth...
|
||||
m_nMaxWidth = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// tell Process() to use the next argument
|
||||
// in the stack as minwidth...
|
||||
m_nMinWidth = -1;
|
||||
}
|
||||
|
||||
// save the * in our formatting buffer...
|
||||
// will be replaced later by Process()
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
break;
|
||||
|
||||
case wxT('1'): case wxT('2'): case wxT('3'):
|
||||
case wxT('4'): case wxT('5'): case wxT('6'):
|
||||
case wxT('7'): case wxT('8'): case wxT('9'):
|
||||
{
|
||||
int len = 0;
|
||||
CHECK_PREC
|
||||
while ( (*m_pArgEnd >= CharType('0')) &&
|
||||
(*m_pArgEnd <= CharType('9')) )
|
||||
{
|
||||
m_szFlags[flagofs++] = char(*m_pArgEnd);
|
||||
len = len*10 + (*m_pArgEnd - wxT('0'));
|
||||
m_pArgEnd++;
|
||||
}
|
||||
|
||||
if (in_prec)
|
||||
m_nMaxWidth = len;
|
||||
else
|
||||
m_nMinWidth = len;
|
||||
|
||||
m_pArgEnd--; // the main loop pre-increments n again
|
||||
}
|
||||
break;
|
||||
|
||||
case wxT('$'): // a positional parameter (e.g. %2$s) ?
|
||||
{
|
||||
if (m_nMinWidth <= 0)
|
||||
break; // ignore this formatting flag as no
|
||||
// numbers are preceding it
|
||||
|
||||
// remove from m_szFlags all digits previously added
|
||||
do {
|
||||
flagofs--;
|
||||
} while (m_szFlags[flagofs] >= '1' &&
|
||||
m_szFlags[flagofs] <= '9');
|
||||
|
||||
// re-adjust the offset making it point to the
|
||||
// next free char of m_szFlags
|
||||
flagofs++;
|
||||
|
||||
m_pos = m_nMinWidth;
|
||||
m_nMinWidth = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case wxT('d'):
|
||||
case wxT('i'):
|
||||
case wxT('o'):
|
||||
case wxT('u'):
|
||||
case wxT('x'):
|
||||
case wxT('X'):
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
if (ilen == 0)
|
||||
m_type = wxPAT_INT;
|
||||
else if (ilen == -1)
|
||||
// NB: 'short int' value passed through '...'
|
||||
// is promoted to 'int', so we have to get
|
||||
// an int from stack even if we need a short
|
||||
m_type = wxPAT_INT;
|
||||
else if (ilen == 1)
|
||||
m_type = wxPAT_LONGINT;
|
||||
else if (ilen == 2)
|
||||
#ifdef wxLongLong_t
|
||||
m_type = wxPAT_LONGLONGINT;
|
||||
#else // !wxLongLong_t
|
||||
m_type = wxPAT_LONGINT;
|
||||
#endif // wxLongLong_t/!wxLongLong_t
|
||||
else if (ilen == 3)
|
||||
m_type = wxPAT_SIZET;
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case wxT('e'):
|
||||
case wxT('E'):
|
||||
case wxT('f'):
|
||||
case wxT('g'):
|
||||
case wxT('G'):
|
||||
CHECK_PREC
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
if (ilen == 2)
|
||||
m_type = wxPAT_LONGDOUBLE;
|
||||
else
|
||||
m_type = wxPAT_DOUBLE;
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case wxT('p'):
|
||||
m_type = wxPAT_POINTER;
|
||||
m_szFlags[flagofs++] = char(ch);
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case wxT('c'):
|
||||
#if wxUSE_UNICODE
|
||||
if (ilen == -1)
|
||||
{
|
||||
// %hc == ANSI character
|
||||
m_type = wxPAT_CHAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// %lc == %c == Unicode character
|
||||
m_type = wxPAT_WCHAR;
|
||||
}
|
||||
#else
|
||||
if (ilen == 1)
|
||||
{
|
||||
// %lc == Unicode character
|
||||
m_type = wxPAT_WCHAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// %hc == %c == ANSI character
|
||||
m_type = wxPAT_CHAR;
|
||||
}
|
||||
#endif
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case wxT('s'):
|
||||
#if wxUSE_UNICODE
|
||||
if (ilen == -1)
|
||||
{
|
||||
// wx extension: we'll let %hs mean non-Unicode strings
|
||||
m_type = wxPAT_PCHAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// %ls == %s == Unicode string
|
||||
m_type = wxPAT_PWCHAR;
|
||||
}
|
||||
#else
|
||||
if (ilen == 1)
|
||||
{
|
||||
// %ls == Unicode string
|
||||
m_type = wxPAT_PWCHAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// %s == %hs == ANSI string
|
||||
m_type = wxPAT_PCHAR;
|
||||
}
|
||||
#endif
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case wxT('n'):
|
||||
if (ilen == 0)
|
||||
m_type = wxPAT_NINT;
|
||||
else if (ilen == -1)
|
||||
m_type = wxPAT_NSHORTINT;
|
||||
else if (ilen >= 1)
|
||||
m_type = wxPAT_NLONGINT;
|
||||
done = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
// bad format, don't consider this an argument;
|
||||
// leave it unchanged
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flagofs == wxMAX_SVNPRINTF_FLAGBUFFER_LEN)
|
||||
{
|
||||
wxLogDebug(wxT("Too many flags specified for a single conversion specifier!"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
|
||||
return true; // parsing was successful
|
||||
}
|
||||
|
||||
template<typename CharType>
|
||||
void wxPrintfConvSpec<CharType>::ReplaceAsteriskWith(int width)
|
||||
{
|
||||
char temp[wxMAX_SVNPRINTF_FLAGBUFFER_LEN];
|
||||
|
||||
// find the first * in our flag buffer
|
||||
char *pwidth = strchr(m_szFlags, '*');
|
||||
wxCHECK_RET(pwidth, wxT("field width must be specified"));
|
||||
|
||||
// save what follows the * (the +1 is to skip the asterisk itself!)
|
||||
strcpy(temp, pwidth+1);
|
||||
if (width < 0)
|
||||
{
|
||||
pwidth[0] = wxT('-');
|
||||
pwidth++;
|
||||
}
|
||||
|
||||
// replace * with the actual integer given as width
|
||||
#ifndef SYSTEM_SPRINTF_IS_UNSAFE
|
||||
int maxlen = (m_szFlags + wxMAX_SVNPRINTF_FLAGBUFFER_LEN - pwidth) /
|
||||
sizeof(*m_szFlags);
|
||||
#endif
|
||||
int offset = system_sprintf(pwidth, maxlen, "%d", abs(width));
|
||||
|
||||
// restore after the expanded * what was following it
|
||||
strcpy(pwidth+offset, temp);
|
||||
}
|
||||
|
||||
template<typename CharType>
|
||||
bool wxPrintfConvSpec<CharType>::LoadArg(wxPrintfArg *p, va_list &argptr)
|
||||
{
|
||||
// did the '*' width/precision specifier was used ?
|
||||
if (m_nMaxWidth == -1)
|
||||
{
|
||||
// take the maxwidth specifier from the stack
|
||||
m_nMaxWidth = va_arg(argptr, int);
|
||||
if (m_nMaxWidth < 0)
|
||||
m_nMaxWidth = 0;
|
||||
else
|
||||
ReplaceAsteriskWith(m_nMaxWidth);
|
||||
}
|
||||
|
||||
if (m_nMinWidth == -1)
|
||||
{
|
||||
// take the minwidth specifier from the stack
|
||||
m_nMinWidth = va_arg(argptr, int);
|
||||
|
||||
ReplaceAsteriskWith(m_nMinWidth);
|
||||
if (m_nMinWidth < 0)
|
||||
{
|
||||
m_bAlignLeft = !m_bAlignLeft;
|
||||
m_nMinWidth = -m_nMinWidth;
|
||||
}
|
||||
}
|
||||
|
||||
switch (m_type) {
|
||||
case wxPAT_INT:
|
||||
p->pad_int = va_arg(argptr, int);
|
||||
break;
|
||||
case wxPAT_LONGINT:
|
||||
p->pad_longint = va_arg(argptr, long int);
|
||||
break;
|
||||
#ifdef wxLongLong_t
|
||||
case wxPAT_LONGLONGINT:
|
||||
p->pad_longlongint = va_arg(argptr, wxLongLong_t);
|
||||
break;
|
||||
#endif // wxLongLong_t
|
||||
case wxPAT_SIZET:
|
||||
p->pad_sizet = va_arg(argptr, size_t);
|
||||
break;
|
||||
case wxPAT_DOUBLE:
|
||||
p->pad_double = va_arg(argptr, double);
|
||||
break;
|
||||
case wxPAT_LONGDOUBLE:
|
||||
p->pad_longdouble = va_arg(argptr, long double);
|
||||
break;
|
||||
case wxPAT_POINTER:
|
||||
p->pad_pointer = va_arg(argptr, void *);
|
||||
break;
|
||||
|
||||
case wxPAT_CHAR:
|
||||
p->pad_char = (char)va_arg(argptr, int); // char is promoted to int when passed through '...'
|
||||
break;
|
||||
case wxPAT_WCHAR:
|
||||
p->pad_wchar = (wchar_t)va_arg(argptr, int); // char is promoted to int when passed through '...'
|
||||
break;
|
||||
|
||||
case wxPAT_PCHAR:
|
||||
case wxPAT_PWCHAR:
|
||||
p->pad_str = va_arg(argptr, void *);
|
||||
break;
|
||||
|
||||
case wxPAT_NINT:
|
||||
p->pad_nint = va_arg(argptr, int *);
|
||||
break;
|
||||
case wxPAT_NSHORTINT:
|
||||
p->pad_nshortint = va_arg(argptr, short int *);
|
||||
break;
|
||||
case wxPAT_NLONGINT:
|
||||
p->pad_nlongint = va_arg(argptr, long int *);
|
||||
break;
|
||||
|
||||
case wxPAT_STAR:
|
||||
// this will be handled as part of the next argument
|
||||
return true;
|
||||
|
||||
case wxPAT_INVALID:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true; // loading was successful
|
||||
}
|
||||
|
||||
template<typename CharType>
|
||||
int wxPrintfConvSpec<CharType>::Process(CharType *buf, size_t lenMax, wxPrintfArg *p, size_t written)
|
||||
{
|
||||
// buffer to avoid dynamic memory allocation each time for small strings;
|
||||
// note that this buffer is used only to hold results of number formatting,
|
||||
// %s directly writes user's string in buf, without using szScratch
|
||||
char szScratch[wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN];
|
||||
size_t lenScratch = 0, lenCur = 0;
|
||||
|
||||
#define APPEND_CH(ch) \
|
||||
{ \
|
||||
if ( lenCur == lenMax ) \
|
||||
return -1; \
|
||||
\
|
||||
buf[lenCur++] = ch; \
|
||||
}
|
||||
|
||||
switch ( m_type )
|
||||
{
|
||||
case wxPAT_INT:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_int);
|
||||
break;
|
||||
|
||||
case wxPAT_LONGINT:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_longint);
|
||||
break;
|
||||
|
||||
#ifdef wxLongLong_t
|
||||
case wxPAT_LONGLONGINT:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_longlongint);
|
||||
break;
|
||||
#endif // SIZEOF_LONG_LONG
|
||||
|
||||
case wxPAT_SIZET:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_sizet);
|
||||
break;
|
||||
|
||||
case wxPAT_LONGDOUBLE:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_longdouble);
|
||||
break;
|
||||
|
||||
case wxPAT_DOUBLE:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_double);
|
||||
break;
|
||||
|
||||
case wxPAT_POINTER:
|
||||
lenScratch = system_sprintf(szScratch, wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN, m_szFlags, p->pad_pointer);
|
||||
break;
|
||||
|
||||
case wxPAT_CHAR:
|
||||
case wxPAT_WCHAR:
|
||||
{
|
||||
wxUniChar ch;
|
||||
if (m_type == wxPAT_CHAR)
|
||||
ch = p->pad_char;
|
||||
else // m_type == wxPAT_WCHAR
|
||||
ch = p->pad_wchar;
|
||||
|
||||
CharType val = ch;
|
||||
|
||||
size_t i;
|
||||
|
||||
if (!m_bAlignLeft)
|
||||
for (i = 1; i < (size_t)m_nMinWidth; i++)
|
||||
APPEND_CH(wxT(' '));
|
||||
|
||||
APPEND_CH(val);
|
||||
|
||||
if (m_bAlignLeft)
|
||||
for (i = 1; i < (size_t)m_nMinWidth; i++)
|
||||
APPEND_CH(wxT(' '));
|
||||
}
|
||||
break;
|
||||
|
||||
case wxPAT_PCHAR:
|
||||
case wxPAT_PWCHAR:
|
||||
{
|
||||
wxString s;
|
||||
if ( !p->pad_str )
|
||||
{
|
||||
if ( m_nMaxWidth >= 6 )
|
||||
s = wxT("(null)");
|
||||
}
|
||||
else if (m_type == wxPAT_PCHAR)
|
||||
s.assign(static_cast<const char *>(p->pad_str));
|
||||
else // m_type == wxPAT_PWCHAR
|
||||
s.assign(static_cast<const wchar_t *>(p->pad_str));
|
||||
|
||||
typename wxPrintfStringHelper<CharType>::ConvertedType strbuf(
|
||||
wxPrintfStringHelper<CharType>::Convert(s));
|
||||
|
||||
// at this point we are sure that m_nMaxWidth is positive or
|
||||
// null (see top of wxPrintfConvSpec::LoadArg)
|
||||
int len = wxMin((unsigned int)m_nMaxWidth, wxStrlen(strbuf));
|
||||
|
||||
int i;
|
||||
|
||||
if (!m_bAlignLeft)
|
||||
{
|
||||
for (i = len; i < m_nMinWidth; i++)
|
||||
APPEND_CH(wxT(' '));
|
||||
}
|
||||
|
||||
len = wxMin((unsigned int)len, lenMax-lenCur);
|
||||
wxStrncpy(buf+lenCur, strbuf, len);
|
||||
lenCur += len;
|
||||
|
||||
if (m_bAlignLeft)
|
||||
{
|
||||
for (i = len; i < m_nMinWidth; i++)
|
||||
APPEND_CH(wxT(' '));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case wxPAT_NINT:
|
||||
*p->pad_nint = written;
|
||||
break;
|
||||
|
||||
case wxPAT_NSHORTINT:
|
||||
*p->pad_nshortint = (short int)written;
|
||||
break;
|
||||
|
||||
case wxPAT_NLONGINT:
|
||||
*p->pad_nlongint = written;
|
||||
break;
|
||||
|
||||
case wxPAT_INVALID:
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if we used system's sprintf() then we now need to append the s_szScratch
|
||||
// buffer to the given one...
|
||||
switch (m_type)
|
||||
{
|
||||
case wxPAT_INT:
|
||||
case wxPAT_LONGINT:
|
||||
#ifdef wxLongLong_t
|
||||
case wxPAT_LONGLONGINT:
|
||||
#endif
|
||||
case wxPAT_SIZET:
|
||||
case wxPAT_LONGDOUBLE:
|
||||
case wxPAT_DOUBLE:
|
||||
case wxPAT_POINTER:
|
||||
wxASSERT(lenScratch < wxMAX_SVNPRINTF_SCRATCHBUFFER_LEN);
|
||||
// NB: 1) we can compare lenMax (for CharType*, i.e. possibly
|
||||
// wchar_t*) with lenScratch (char*) because this code is
|
||||
// formatting integers and that will have the same length
|
||||
// even in UTF-8 (the only case when char* length may be
|
||||
// more than wchar_t* length of the same string)
|
||||
// 2) wxStrncpy converts the 2nd argument to 1st argument's
|
||||
// type transparently if their types differ, so this code
|
||||
// works for both instantiations
|
||||
if (lenMax < lenScratch)
|
||||
{
|
||||
// fill output buffer and then return -1
|
||||
wxStrncpy(buf, szScratch, lenMax);
|
||||
return -1;
|
||||
}
|
||||
wxStrncpy(buf, szScratch, lenScratch);
|
||||
lenCur += lenScratch;
|
||||
break;
|
||||
|
||||
default:
|
||||
break; // all other cases were completed previously
|
||||
}
|
||||
|
||||
return lenCur;
|
||||
}
|
||||
|
||||
|
||||
// helper that parses format string
|
||||
template<typename CharType>
|
||||
struct wxPrintfConvSpecParser
|
||||
{
|
||||
typedef wxPrintfConvSpec<CharType> ConvSpec;
|
||||
|
||||
wxPrintfConvSpecParser(const CharType *fmt)
|
||||
{
|
||||
nspecs =
|
||||
nargs = 0;
|
||||
posarg_present =
|
||||
nonposarg_present = false;
|
||||
|
||||
memset(pspec, 0, sizeof(pspec));
|
||||
|
||||
// parse the format string
|
||||
for ( const CharType *toparse = fmt; *toparse != wxT('\0'); toparse++ )
|
||||
{
|
||||
// skip everything except format specifications
|
||||
if ( *toparse != '%' )
|
||||
continue;
|
||||
|
||||
// also skip escaped percent signs
|
||||
if ( toparse[1] == '%' )
|
||||
{
|
||||
toparse++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ConvSpec *spec = &specs[nspecs];
|
||||
spec->Init();
|
||||
|
||||
// attempt to parse this format specification
|
||||
if ( !spec->Parse(toparse) )
|
||||
continue;
|
||||
|
||||
// advance to the end of this specifier
|
||||
toparse = spec->m_pArgEnd;
|
||||
|
||||
// special handling for specifications including asterisks: we need
|
||||
// to reserve an extra slot (or two if asterisks were used for both
|
||||
// width and precision) in specs array in this case
|
||||
if ( const char *f = strchr(spec->m_szFlags, '*') )
|
||||
{
|
||||
unsigned numAsterisks = 1;
|
||||
if ( strchr(++f, '*') )
|
||||
numAsterisks++;
|
||||
|
||||
for ( unsigned n = 0; n < numAsterisks; n++ )
|
||||
{
|
||||
if ( ++nspecs == wxMAX_SVNPRINTF_ARGUMENTS )
|
||||
break;
|
||||
|
||||
// TODO: we need to support specifiers of the form "%2$*1$s"
|
||||
// (this is the same as "%*s") as if any positional arguments
|
||||
// are used all asterisks must be positional as well but this
|
||||
// requires a lot of changes in this code (basically we'd need
|
||||
// to rewrite Parse() to return "*" and conversion itself as
|
||||
// separate entries)
|
||||
if ( posarg_present )
|
||||
{
|
||||
wxFAIL_MSG
|
||||
(
|
||||
wxString::Format
|
||||
(wxASCII_STR(
|
||||
"Format string \"%s\" uses both positional "
|
||||
"parameters and '*' but this is not currently "
|
||||
"supported by this implementation, sorry."),
|
||||
fmt
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
specs[nspecs] = *spec;
|
||||
|
||||
// make an entry for '*' and point to it from pspec
|
||||
spec->Init();
|
||||
spec->m_type = wxPAT_STAR;
|
||||
pspec[nargs++] = spec;
|
||||
|
||||
spec = &specs[nspecs];
|
||||
}
|
||||
|
||||
// If we hit the maximal number of arguments inside the inner
|
||||
// loop, break out of the outer one as well.
|
||||
if ( nspecs == wxMAX_SVNPRINTF_ARGUMENTS )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// check if this is a positional or normal argument
|
||||
if ( spec->m_pos > 0 )
|
||||
{
|
||||
// the positional arguments start from number 1 so we need
|
||||
// to adjust the index
|
||||
spec->m_pos--;
|
||||
|
||||
// We could be reusing an already existing argument, only
|
||||
// increment their number if it's really a new one.
|
||||
if ( spec->m_pos >= nargs )
|
||||
{
|
||||
nargs = spec->m_pos + 1;
|
||||
}
|
||||
else if ( pspec[spec->m_pos] ) // Had we seen it before?
|
||||
{
|
||||
// Check that the type specified this time is compatible
|
||||
// with the previously-specified type.
|
||||
wxASSERT_MSG
|
||||
(
|
||||
pspec[spec->m_pos]->m_type == spec->m_type,
|
||||
"Positional parameter specified multiple times "
|
||||
"with incompatible types."
|
||||
);
|
||||
}
|
||||
|
||||
posarg_present = true;
|
||||
}
|
||||
else // not a positional argument...
|
||||
{
|
||||
spec->m_pos = nargs++;
|
||||
nonposarg_present = true;
|
||||
}
|
||||
|
||||
// this conversion specifier is tied to the pos-th argument...
|
||||
pspec[spec->m_pos] = spec;
|
||||
|
||||
if ( ++nspecs == wxMAX_SVNPRINTF_ARGUMENTS )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// warn if we lost any arguments (the program probably will crash
|
||||
// anyhow because of stack corruption...)
|
||||
if ( nspecs == wxMAX_SVNPRINTF_ARGUMENTS )
|
||||
{
|
||||
wxFAIL_MSG
|
||||
(
|
||||
wxString::Format
|
||||
(wxASCII_STR(
|
||||
"wxVsnprintf() currently supports only %d arguments, "
|
||||
"but format string \"%s\" defines more of them.\n"
|
||||
"You need to change wxMAX_SVNPRINTF_ARGUMENTS and "
|
||||
"recompile if more are really needed."),
|
||||
fmt, wxMAX_SVNPRINTF_ARGUMENTS
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// total number of valid elements in specs
|
||||
unsigned nspecs;
|
||||
|
||||
// total number of arguments, also number of valid elements in pspec, and
|
||||
// always less than or (usually) equal to nspecs
|
||||
unsigned nargs;
|
||||
|
||||
// all format specifications in this format string in order of their
|
||||
// appearance (which may be different from arguments order)
|
||||
ConvSpec specs[wxMAX_SVNPRINTF_ARGUMENTS];
|
||||
|
||||
// pointer to specs array element for the N-th argument
|
||||
ConvSpec *pspec[wxMAX_SVNPRINTF_ARGUMENTS];
|
||||
|
||||
// true if any positional/non-positional parameters are used
|
||||
bool posarg_present,
|
||||
nonposarg_present;
|
||||
};
|
||||
|
||||
#undef APPEND_CH
|
||||
#undef CHECK_PREC
|
||||
|
||||
#endif // _WX_PRIVATE_WXPRINTF_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue