⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 custctrl.h

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 H
📖 第 1 页 / 共 3 页
字号:
public:
    void Create ( wxCustomControl* pctrl, const wxString& value,
        const wxPoint& pos, const wxSize& sz,
        int n, const wxChar* choices[] );

    int Append( const wxString& str );

    virtual void SetSelection ( const wxCustomComboItem& item );
    virtual void OnSelect ( const wxCustomComboItem& item );
    virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );
    virtual bool OnKeyEvent ( wxKeyEvent& event );
    virtual wxCustomComboPopup* CreatePopup ( wxWindow* frame,
        const wxRect& ctrl_rect, wxCustomControl* ctrl );

    inline const wxArrayPtrVoid& GetLabels() const { return m_labels; }
    inline wxArrayPtrVoid& GetWritableLabels() { return m_labels; }
    inline int GetSelection() const { return m_selection; }

    virtual ~wxCCustomComboBoxDefaultHandler();

protected:

    int                     m_selection;

    wxArrayPtrVoid          m_labels; // Holds pointers to labels.

    wxArrayString           m_extraStrings; // Place extra appended strings here.

};

/** wxCustomControlManager's flags
*/

/** m_parent is wxScrolledWindow or derivative. */
#define wxCCM_FL_SCROLLEDWIN        0x0001

/** Notify for the event poller. */
#define wxCCM_FL_EVENTREADY         0x0002

/** If there is internal-to-control dragging going on. */
#define wxCCM_FL_DRAGGING           0x0004

/** When mouse cursor is actually inside mouse-focused control. */
#define wxCCM_FL_MOUSE_INSIDE       0x0008

/** Set by OnParentScrollEvent handler. */
#define wxCCM_FL_VIEWSTARTCHANGED   0x0010

/** Helper caret info. */
#define wxCCM_FL_CARETVISIBLE       0x0020

// -----------------------------------------------------------------------

/** \class wxCustomControls
    \ingroup classes
    \brief Static functions for drawing custom controls.
*/
class WXDLLIMPEXP_CC wxCustomControlManager
{
    friend class wxCustomControl;
    friend class wxCustomTextCtrlHandler;
    friend class wxCCustomTextCtrl;
    friend class wxCCustomButtonHandler;
    friend class wxCCustomButton;
    friend class wxCCustomComboBoxHandler;
    friend class wxCCustomComboBox;
public:
    
    wxCustomControlManager();
    wxCustomControlManager( wxWindow* parent );
    ~wxCustomControlManager();

    void AddChild ( wxCustomControl* child );

    void AddChildData ( wxCustomControlHandler* pdata );

    void AddEvent ( wxCustomControl* child, int eventtype );

    void ClosePopup ();

    void Create ( wxWindow* parent );

    /** When xxData needs to redraw the control in question, use this
        to create the necessary device context. Then DestroyDC must be
        used to delete it.
    */
    wxDC& CreateDC ( wxPoint* palignpt );

    /** Creates frame etc. for a popup.
    */
    wxWindow* CreatePopupParent() { return m_parent; }

    /** Black text on white background, centered vertically in the rect etc.
        state 0 = no background clearing, 1 = clear bg, 3 = selected, clearbg.
    */
    void CtrlWriteText ( wxDC& dc, const wxChar* text,
        const wxRect& rect, wxCustomControl* ctrl, int state );

    /** See CreateDC.*/
    void DestroyDC ( wxDC& dc );

    wxCustomControlHandler* FindDataByPosition ( int x, int y );
    wxCustomControl* FindWindowByPosition ( int x, int y );

    inline void ForceMouseLeave ( wxMouseEvent& event )
    {
        DoMouseLeave ( event, NULL, TRUE );
    }

    inline wxEvent& GetEvent ()
    {
        m_flags &= ~(wxCCM_FL_EVENTREADY);
        return *(&m_event);
    }

    inline wxPoint GetCaretPosition () const
    {
        wxPoint p = m_pCaret->GetPosition();
        //TranslatePositionToLogical ( &p.x, &p.y );
        return p;
    }

    inline long GetFlags () const { return m_flags; }

    inline wxWindow* GetPopup () const { return m_openPopup; }

    inline wxCustomControl* GetFocused () const { return m_ctrlKbFocus; }
    inline wxCustomControlHandler* GetMouseFocusedData () const { return m_dataMouseFocus; }

    inline wxWindow* GetWindow () const { return m_parent; }

    inline const wxColour& GetWindowColour () const { return *(&m_colBackground); }
    inline const wxColour& GetWindowTextColour () const { return *(&m_colText); }
    inline const wxColour& GetSelectionColour () const { return *(&m_colSelection); }
    inline const wxColour& GetSelectionTextColour () const { return *(&m_colSelectionText); }
    inline const wxColour& GetButtonColour () const { return *(&m_colButton); }
    inline const wxColour& GetButtonTextColour () const { return *(&m_colButtonText); }

    inline wxString& GetTempString() { return *(&m_tempStr1); }

    inline bool HasEvent () const { return (m_flags & wxCCM_FL_EVENTREADY)?TRUE:FALSE; }

    inline bool HasKbFocus () const { return (m_ctrlKbFocus!=NULL)?TRUE:FALSE; }

    inline bool HasMouseFocus () const { return (m_ctrlMouseFocus!=NULL)?TRUE:FALSE; }

    inline bool IsDragging () const { return (m_flags & wxCCM_FL_DRAGGING)?TRUE:FALSE; }

    void MoveCaret ( const wxRect& ctrl_rect, int x, int y );
    //void MoveCaretRelative ( int x, int y );
    void RepositionCaret ();

    /** Must be called when parent's focus changes. state = TRUE if focused.
    */
    void OnParentFocusChange ( bool state );

    /** Must be called when parent wxScrolledWindow gets scrolling event.
    */
    void OnParentScrollWinEvent ( wxScrollWinEvent &event );

    void OnParentScrollChange ();

    bool ProcessKeyboardEvent ( wxKeyEvent& event );

    /** Relays mouse event to appropriate managed custom control. If processes
        (i.e. returns TRUE),  event's coordinates have been converted to control's
        local space.
        \returns
        Returns TRUE if event was inside some ctrl (some events may actually be processed even in this case).
    */
    bool ProcessMouseEvent ( wxMouseEvent& event );

    void RemoveChild ( wxCustomControl* child );

    void RemoveFocus ( wxCustomControl* child );

    inline void ShowCaret ()
    {
        if ( m_pCaret && !(m_flags & wxCCM_FL_CARETVISIBLE) )
        {
            m_pCaret->Show ( TRUE );
            m_flags |= wxCCM_FL_CARETVISIBLE;
            //wxLogDebug ( wxT("ShowCaret( visible_after=%i )"), (int)m_pCaret->IsVisible() );
        }
    }

    inline void ShowCaretBalanced ()
    {
        m_pCaret->Show ( TRUE );
    }

    inline void HideCaretBalanced ()
    {
        m_pCaret->Show ( FALSE );
    }

    inline void HideCaret ()
    {
        if ( m_pCaret && ( m_flags & wxCCM_FL_CARETVISIBLE ) )
        {
            m_pCaret->Show ( FALSE );
            m_flags &= ~(wxCCM_FL_CARETVISIBLE);
            //wxLogDebug ( wxT("HideCaret( visible_after=%i )"), (int)m_pCaret->IsVisible() );
        }
    }

    inline bool IsCaretVisible () const
    {
        //if ( m_pCaret )
            return m_pCaret->IsVisible();
        //return FALSE;
    }

    void SetDoubleBuffer ( wxBitmap* buffer ) { m_bmpDoubleBuffer = buffer; }

    void SetFocus ( wxCustomControl* child );

    void SetFont ( const wxFont& font ) { m_font = font; }

    void SetPopup ( wxCustomComboPopup* popup );

    inline void StartDragging () { m_flags |= wxCCM_FL_DRAGGING; }
    
    inline void StopDragging () { m_flags &= ~(wxCCM_FL_DRAGGING); }

    /** Translates coordinate translation necessary for scrolled window.
    */
    void TranslatePositionToPhysical ( int* x, int* y ) const;
    void TranslatePositionToLogical ( int* x, int* y ) const;

protected:

    // returns index to first data of a control
    int GetControlsFirstData ( wxCustomControl* ctrl );

protected:


    wxWindow*               m_parent;

    wxBitmap*               m_bmpDoubleBuffer; // never owns; just borrows parent's, if available;

    //wxArrayPtrVoid          m_controls;

    wxArrayPtrVoid          m_handlers; // one control may comprise of more than one controldata

    wxCustomControl*    m_ctrlMouseFocus; // which control has mouse focus
    wxCustomControlHandler*    m_dataMouseFocus; // which controldata has mouse focus
    wxCustomControl*    m_ctrlKbFocus; // which control has keyboard focus

    wxCaret*                m_pCaret;

    wxPoint                 m_caretRelativePos; // caret x inside m_ctrlKbFocus

    wxColour                m_colBackground;
    wxColour                m_colText;
    wxColour                m_colSelection;
    wxColour                m_colSelectionText;
    wxColour                m_colButton;
    wxColour                m_colButtonText;

    wxFont                  m_font;

    wxCursor                m_cursorIBeam;

    wxString                m_tempStr1;

    long                    m_flags;

    wxCommandEvent          m_event;

#if wxCC_CORRECT_CONTROL_POSITION
    wxSize                  m_prevViewStart; // for wxScrolledWindow scroll management
#endif

    wxWindow*               m_openPopup;

    void DoMouseLeave ( wxMouseEvent& event, wxCustomControlHandler* newdata, bool force );

};

// -----------------------------------------------------------------------

#define wxCC_FL_KBFOCUS         0x0001

#define wxCC_FL_MOUSEFOCUS      0x0002 // When mouse is over the control and it is not dragging for another control

#define wxCC_FL_NEEDSCARET      0x0004

#define wxCC_FL_DRAWN           0x0008 // Set by drawing function

#define wxCC_FL_MODIFIED        0x0010 // May be needed internally by various controls/datas

#define wxCC_FL_REMOVED         0x0020 // Manager's RemoveChild already called on this.

#define wxCC_EXTRA_FLAG(N)      (1<<(16+N))

// -----------------------------------------------------------------------

void wxRendererNative_DrawButton (wxWindow* win, wxDC& dc, const wxRect& rect, int flags = wxUP );

// -----------------------------------------------------------------------

class WXDLLIMPEXP_CC wxCustomControl : public wxObject
{
	DECLARE_DYNAMIC_CLASS(wxCustomControl)

    friend class wxCustomControlManager;
    friend class wxCustomTextCtrlHandler;
    friend class wxCCustomButtonHandler;
    friend class wxCCustomComboBoxHandler;
public:

    wxCustomControl();
    wxCustomControl ( wxCustomControlManager* manager, wxWindowID id,
        const wxPoint& pos, const wxSize& size, long style = 0 );
    virtual ~wxCustomControl();

    virtual void DoMove ( int x, int y );

    inline const wxColour& GetBackgroundColour() const { return *(&m_manager->m_colBackground);}

    inline wxFont& GetFont () const { return *m_pFont; }
    inline int GetFontHeight () const { return m_fontHeight; }

    inline wxWindowID GetId () const { return m_id; }

    inline wxCustomControlManager* GetManager () const { return m_manager; }

    inline wxWindow* GetParent () const { return m_manager->m_parent; }
    
    inline wxPoint GetPosition () const { return wxPoint(m_rect.x,m_rect.y); }
    
    inline wxRect GetRect () const { return m_rect; }
    
    inline wxSize GetSize () const { return wxSize(m_rect.width,m_rect.height); }

    inline int GetX () const { return m_rect.x; }
    
    inline long GetWindowStyle () const { return m_windowStyle; }

    inline void Move ( const wxPoint& pos ) { DoMove (pos.x,pos.y); }

    inline void Move ( wxCoord x, wxCoord y ) { DoMove (x,y); }

    /** Called on keyboard focus.
    */
    virtual void OnFocus ( bool focused );

    /** Returns TRUE if processed.
    */
    virtual bool OnKeyEvent ( wxKeyEvent& event );

    /** entry is TRUE if mouse enters, FALSE if leaves.
    */
    virtual bool OnMouseFocus ( bool entry );

    virtual bool OnMouseEvent ( wxMouseEvent& event, wxCustomControlHandler* pdata );

    /** Draw control on parent. If dc is NULL, creates one. */
    void DrawPDC ( wxDC* dc = NULL );

    inline void Draw () { DrawPDC ( NULL ); }

    void Draw ( wxDC& dc );

    /** Draw control on dc. align is control position adjustment on dc (incase
        of a double-buffer, for example).
    */
    void Draw ( wxDC& dc, const wxPoint* align );

    /**
    Draws control in to the dc.
    \remarks
    - On both entry and exit, nothing can be assumed of current Pen or Brush.
    - May set clipping region to the control rectangle. If so, calls
      DestroyClippingRegion before exiting.
    */
    virtual void DoDraw ( wxDC& dc, const wxRect& rect );

    virtual void DoSetSize ( int width, int height );

    wxCommandEvent& GetEvent () const { return *(&m_manager->m_event); }

    inline bool HasFocus () const { return (m_manager->m_ctrlKbFocus == this )?TRUE:FALSE; }

    inline void Refresh ( bool = FALSE, const wxRect* = (const wxRect*) NULL ) { Draw(); }

    inline void RemoveFocus ()
    {
        m_manager->RemoveFocus ( this );
    }

    inline void ResetFont () { m_pFont = &m_manager->m_font; }

    inline void SetFocus ()
    {
        m_manager->SetFocus ( this );
    }

    inline void SetFocusFromKbd ()
    {
        m_manager->SetFocus ( this );
    }

    /** Sets font for the control.
        \remarks
        Does not copy the font for itself, just pointer to it.
    */
    virtual void SetFont ( wxFont& font, wxDC* pdc = NULL );

    inline void SetSize ( int x, int y, int width, int height )
    {
        DoMove ( x, y );
        DoSetSize ( width, height );
    }

    inline void SetSize ( const wxRect& rect )
    {
        DoMove ( rect.x, rect.y );
        DoSetSize ( rect.width, rect.height );
    }

    inline void SetSize ( int width, int height )
    { 
        DoSetSize ( width, height );
    }

    inline void SetSize ( const wxSize& size )
    {
        DoSetSize ( size.x, size.y );
    }

    inline void Show() { }

protected:
    wxCustomControlManager  *m_manager;
    wxFont                  *m_pFont;
    wxRect                  m_rect;
    //wxSize                  m_imageSize; // Size of image in front of the control
    wxWindowID              m_id;
    long                    m_windowStyle;
    wxUint32                m_flags;
    int                     m_fontHeight;
    int                     m_xSplit; // splitting the control into two parts (wxCCustomComboBox needs)
    unsigned char           m_curPart; // which part of the control is focused? (only if m_xSplit)
};

// -----------------------------------------------------------------------

inline bool wxCustomControlHandler::IsMouseFocused() const
{
    return m_control->GetManager()->GetMouseFocusedData() == this;
}

// -----------------------------------------------------------------------

class WXDLLIMPEXP_CC wxCCustomTextCtrl : public wxCustomControl
{
	DECLARE_DYNAMIC_CLASS(wxCCustomTextCtrl)

public:

    wxCCustomTextCtrl () : wxCustomControl() { }

    wxCCustomTextCtrl ( wxCustomControlManager* manager, wxWindowID id, const wxString& value = wxEmptyString,
        const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
        long style = 0 );

    virtual ~wxCCustomTextCtrl();

    inline wxString GetValue() const { return m_data.GetValue(); }

    inline void SetSelection(long from, long to)
    {
        if ( m_data.SetSelection(from,to) )
            Draw ();
    }

    void SetValue ( const wxString& value );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -