📄 custctrl.h
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: custctrl.h
// Purpose: wxCustomControls (v1.0.8)
// Author: Jaakko Salli
// Modified by:
// Created: Oct-24-2004
// RCS-ID: $Id:
// Copyright: (c) Jaakko Salli
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_CUSTCTRL_H__
#define __WX_CUSTCTRL_H__
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface "custctrl.cpp"
#endif
// Doxygen special
#ifndef _WX_WINDOW_H_BASE_
# include "cc_dox_mainpage.h"
#endif
// -----------------------------------------------------------------------
#include "wx/caret.h"
#include "wx/renderer.h"
// -----------------------------------------------------------------------
#if defined(WXMAKINGDLL_CUSTCTRL) || defined(WXMAKINGDLL_PROPGRID)
#define WXDLLIMPEXP_CC WXEXPORT
//#elif defined(WXUSINGDLL)
// #define WXDLLIMPEXP_CC WXIMPORT
#else // not making nor using DLL
#define WXDLLIMPEXP_CC
#endif
// If given in button renderer flags, then popup arrow
// is drawn on it as well.
#define wxCONTROL_POPUP_ARROW wxCONTROL_CHECKED
// -----------------------------------------------------------------------
//
// Here are some platform dependent defines
// (more in custctrl.cpp)
//
#if defined(__WXMSW__)
// tested
#if wxUSE_UXTHEME
# include "wx/msw/uxtheme.h"
#endif
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
#define wxCC_TEXTCTRL_YSPACING 2
#define wxCC_TEXTCTRL_XSPACING 3
#define wxCC_USE_POPUPWIN 1 // 1 if wxPopupWindow can be used.
#elif defined(__WXGTK__)
// tested
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
#define wxCC_TEXTCTRL_YSPACING 2
#define wxCC_TEXTCTRL_XSPACING 3
// Disabled because no proper border support.
#define wxCC_USE_POPUPWIN 0 // 1 if wxPopupWindow can be used.
#elif defined(__WXMAC__)
// *not* tested
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
#define wxCC_TEXTCTRL_YSPACING 2
#define wxCC_TEXTCTRL_XSPACING 3
#define wxCC_USE_POPUPWIN 1 // 1 if wxPopupWindow can be used.
#else
// defaults
#define wxCC_CUSTOM_IMAGE_MARGIN1 2 // before image
#define wxCC_CUSTOM_IMAGE_MARGIN2 7 // after image
#define wxCC_TEXTCTRL_YSPACING 2
#define wxCC_TEXTCTRL_XSPACING 3
#define wxCC_USE_POPUPWIN 0 // 1 if wxPopupWindow can be used.
#endif
// Conform to wxUSE_POPUPWIN
#if !wxUSE_POPUPWIN
# undef wxCC_USE_POPUPWIN
# define wxCC_USE_POPUPWIN 0
#endif
/** If 1, then controls will be moved according to scrolling
(does not work exactly, so 0 is recommended value).
*/
#define wxCC_CORRECT_CONTROL_POSITION 0
#if !wxPG_USE_CUSTOM_CONTROLS
# undef wxCC_CUSTOM_IMAGE_MARGIN1
# undef wxCC_CUSTOM_IMAGE_MARGIN2
#endif
#if wxPG_USE_CUSTOM_CONTROLS
// -----------------------------------------------------------------------
#ifndef SWIG
class WXDLLIMPEXP_CC wxCustomControl;
class WXDLLIMPEXP_CC wxCCustomTextCtrl;
class WXDLLIMPEXP_CC wxCCustomButton;
class WXDLLIMPEXP_CC wxCCustomComboBox;
class WXDLLIMPEXP_CC wxCCustomComboBoxHandler;
class WXDLLIMPEXP_CC wxCustomControlManager;
#endif
// -----------------------------------------------------------------------
/** Each wxCustomControl uses 1+ wxCustomControlHandler.
*/
class WXDLLIMPEXP_CC wxCustomControlHandler
{
public:
inline void SetControl ( wxCustomControl* pctrl )
{
m_control = pctrl;
m_flags = 0;
}
inline wxCustomControl* GetControl() const { return m_control; }
inline bool IsMouseFocused() const;
inline void Move ( int x, int y ) { m_rect.x = x; m_rect.y = y; }
inline void SetSize ( int width, int height ) { m_rect.width = width; m_rect.height = height; }
inline void SetSize ( const wxPoint& pos, const wxSize& sz )
{
m_rect.x = pos.x; m_rect.y = pos.y;
m_rect.width = sz.x; m_rect.height = sz.y;
}
inline const wxRect& GetRect() const { return m_rect; }
inline void ClearFlag( long flag ) { m_flags &= ~(flag); }
inline void SetFlag( long flag ) { m_flags |= flag; }
void Create ( wxCustomControl* pctrl, const wxPoint& pos, const wxSize& sz );
protected:
wxCustomControl* m_control;
wxRect m_rect;
long m_flags; // barely needed
};
// -----------------------------------------------------------------------
class WXDLLIMPEXP_CC wxCustomTextCtrlHandler : public wxCustomControlHandler
{
public:
void Create ( wxCustomControl* pctrl, const wxPoint& pos, const wxSize& sz,
const wxString& value );
void Draw ( wxDC& dc, const wxRect& rect );
bool OnKeyEvent ( wxKeyEvent& event );
bool OnMouseEvent ( wxMouseEvent& event );
int HitTest ( wxCoord x, int* pCol );
bool SetInsertionPoint ( long pos, long first_visible );
bool SetSelection ( long from, long to );
void SetValue ( const wxString& value );
inline int GetPosition () const
{
return m_position;
}
inline const wxString& GetValue() const { return m_text; }
// like DEL key was pressed
void DeleteSelection ();
// wxCC_FL_MODIFIED
protected:
wxString m_text;
//wxString m_textAtPos; // text that begins at position
unsigned int m_position;
unsigned int m_scrollPosition;
int m_selStart;
int m_selEnd;
int m_itemButDown; // dragging centers around this
wxArrayInt m_arrExtents; // cached array of text extents
int UpdateExtentCache ( wxString& tempstr, size_t index );
};
// -----------------------------------------------------------------------
class WXDLLIMPEXP_CC wxCCustomButtonHandler : public wxCustomControlHandler
{
friend class wxCCustomButton;
public:
void Draw ( wxDC& dc, const wxRect& rect );
bool OnMouseEvent ( wxMouseEvent& event );
inline void SetButtonState ( int state ) { m_down = (unsigned char)state; }
protected:
wxString m_label;
unsigned char m_down; // 0 means button is up
};
// -----------------------------------------------------------------------
#if wxCC_USE_POPUPWIN
# include "wx/popupwin.h"
# define wxCustomComboPopupBase wxPopupWindow
#else
# define wxCustomComboPopupBase wxWindow
#endif
class WXDLLIMPEXP_CC wxCustomComboItem
{
public:
wxCustomComboItem();
virtual ~wxCustomComboItem();
protected:
};
// -----------------------------------------------------------------------
class WXDLLIMPEXP_CC wxCustomComboPopup : public wxCustomComboPopupBase
{
friend class wxCustomControlManager;
public:
wxCustomComboPopup ();
virtual ~wxCustomComboPopup();
bool Create ( wxWindow* frame, wxCCustomComboBoxHandler* data,
const wxRect& ctrl_rect, wxCustomControl* ctrl,
const wxSize& size, int sizealign );
/*#if wxCC_USE_POPUPWIN
inline wxScrolledWindow* GetWindow() const { return m_subWindow; };
#else
inline wxScrolledWindow* GetWindow() { return this; };
#endif*/
// kbscroll allows forcing to scroll one item at a time.
virtual void ShowItem ( const wxCustomComboItem& item, bool kbscroll = FALSE ) = 0;
virtual void OnKeyEvent ( wxKeyEvent& event ) = 0;
//virtual void SetSelection ( const wxCustomComboItem& item ) = 0;
void ForcedClose ();
inline wxCustomControl* GetControl () const { return m_control; }
// Event handlers.
void OnMouseEntry( wxMouseEvent& event );
protected:
wxCustomControl* m_control;
wxCustomControlManager* m_manager;
wxCCustomComboBoxHandler* m_chData;
wxArrayPtrVoid m_labels; // holds pointers to labels
int m_wheelSum;
unsigned char m_orientation;
//unsigned char m_entryStatus;
private:
DECLARE_EVENT_TABLE()
};
// -----------------------------------------------------------------------
class WXDLLIMPEXP_CC wxCustomComboListItem : public wxCustomComboItem
{
public:
wxCustomComboListItem();
wxCustomComboListItem( int index ) { m_index = index; }
virtual ~wxCustomComboListItem();
int m_index;
protected:
};
// -----------------------------------------------------------------------
#include "wx/scrolbar.h"
class WXDLLIMPEXP_CC wxComboPopupDefaultList : public wxCustomComboPopup
{
public:
wxComboPopupDefaultList ( wxWindow* frame, wxCCustomComboBoxHandler* data,
const wxRect& rect, wxCustomControl* ctrl );
virtual ~wxComboPopupDefaultList();
virtual void ShowItem ( const wxCustomComboItem& item, bool kbscroll = FALSE );
inline void ShowItem ( int index, bool kbscroll = FALSE )
{
wxCustomComboListItem item(index);
ShowItem (item,kbscroll);
}
//virtual void SetSelection ( const wxCustomComboItem& item );
virtual void OnKeyEvent ( wxKeyEvent& event );
int HitTest ( int y );
inline void DrawItem ( int index )
{
wxCustomComboListItem item(index);
DrawItem(item);
}
void DrawItem ( const wxCustomComboItem& item );
void DrawItem ( wxDC& dc, wxRect& r, unsigned int index );
void OnMouseWheelEvent ( wxMouseEvent& event );
void OnPaint ( wxPaintEvent& event );
void OnMouseDown ( wxMouseEvent& event );
void OnMouseMove ( wxMouseEvent& event );
void OnScrollEvent ( wxScrollEvent& event );
void SetViewStart ( int index, bool adjust_sb );
void RecheckHilighted ( int y );
//void OnMouseUp ( wxMouseEvent& event );
//void SetImagePaintFunction ( wxCustomPaintFunc paintfunc ) { m_paintFunc = paintfunc; }
protected:
int m_hilighted;
int m_itemHeight;
// Scrolling related.
wxScrollBar* m_pScrollBar;
int m_clientWidth;
int m_viewStartY;
int m_viewStartIndex;
int m_sbWidth;
private:
DECLARE_EVENT_TABLE()
};
// -----------------------------------------------------------------------
typedef wxSize (*wxCustomPaintFunc) ( wxDC&, const wxRect&, int, void* );
class WXDLLIMPEXP_CC wxCustomComboPopup;
class WXDLLIMPEXP_CC wxCustomComboItem;
class WXDLLIMPEXP_CC wxComboPopupDefaultList;
class WXDLLIMPEXP_CC wxCCustomComboBoxHandler : public wxCustomControlHandler
{
friend class wxCCustomComboBox;
friend class wxCustomComboPopup;
public:
void Create ( wxCustomControl* pctrl, const wxString& value,
const wxPoint& pos, const wxSize& sz );
inline void SetControl ( wxCustomControl* pctrl )
{
wxCustomControlHandler::SetControl ( pctrl );
m_btData.SetControl ( pctrl );
}
virtual void SetSelection ( const wxCustomComboItem& item ) = 0;
void Draw ( wxDC& dc, const wxRect& rect, bool item_too );
inline wxCustomComboPopup* GetPopupInstance () const
{
return m_listInstance;
}
virtual void OnSelect ( const wxCustomComboItem& item ) = 0;
inline void IntOnSelect ( int index )
{
wxCustomComboListItem item(index);
OnSelect (item);
}
virtual bool OnKeyEvent ( wxKeyEvent& event ) = 0;
virtual wxCustomComboPopup* CreatePopup ( wxWindow* frame,
const wxRect& ctrl_rect, wxCustomControl* ctrl ) = 0;
virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
inline void Move ( int x, int y )
{
m_rect.x = x; m_rect.y = y;
m_btData.Move ( x + m_rect.width - m_buttonWidth, y );
}
inline void SetSize ( int width, int height )
{
m_rect.width = width - m_buttonWidth;
m_rect.height = height;
m_btData.Move ( m_rect.x + width - m_buttonWidth, m_rect.y );
m_btData.SetSize ( m_buttonWidth, height );
}
//inline const wxArrayPtrVoid& GetLabels() const { return m_labels; }
inline wxCustomPaintFunc GetPaintFunc() const { return m_paintfunc; }
inline void* GetPaintFuncCustomData() const { return m_paintfunc_customdata; }
inline const wxSize& GetImageSize() const { return m_imageSize; }
//inline int GetSelection() const { return m_selection; }
inline void SetValue( const wxString& text ) { m_text = text; }
inline const wxString& GetValue() const { return m_text; }
inline wxCCustomButtonHandler* GetButtonData() { return &m_btData; }
virtual ~wxCCustomComboBoxHandler();
protected:
//int m_selection;
int m_buttonWidth;
wxSize m_imageSize; // size of custom image in the list
wxString m_text; // text currently shown
//wxArrayPtrVoid m_labels; // holds pointers to labels
wxCCustomButtonHandler m_btData;
//wxCustomComboItem* m_pItem;
wxCustomComboPopup* m_listInstance;
wxCustomPaintFunc m_paintfunc;
void* m_paintfunc_customdata;
unsigned char m_prevMouseFocus; // used detect in which portion of control mouse is
};
// -----------------------------------------------------------------------
class WXDLLIMPEXP_CC wxCCustomComboBoxDefaultHandler : public wxCCustomComboBoxHandler
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -