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

📄 odcombo.cpp

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    wxComboFrameEventHandler( wxPGComboBox* pCb );
    ~wxComboFrameEventHandler();

    void OnPopup();

    void OnIdle( wxIdleEvent& event );
    void OnMouseEvent( wxMouseEvent& event );
    void OnActivate( wxActivateEvent& event );
    void OnResize( wxSizeEvent& event );
    void OnMove( wxMoveEvent& event );
    void OnMenuEvent( wxMenuEvent& event );
    void OnClose( wxCloseEvent& event );

protected:
    wxWindow*               m_focusStart;
    wxPGComboBox*   m_combo;

private:
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(wxComboFrameEventHandler, wxEvtHandler)
    EVT_IDLE(wxComboFrameEventHandler::OnIdle)
    EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
    EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent)
    EVT_SIZE(wxComboFrameEventHandler::OnResize)
    EVT_MOVE(wxComboFrameEventHandler::OnMove)
    EVT_MENU_HIGHLIGHT(wxID_ANY,wxComboFrameEventHandler::OnMenuEvent)
    EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent)
    EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate)
    EVT_CLOSE(wxComboFrameEventHandler::OnClose)
    //EVT_MOUSEWHEEL(wxComboFrameEventHandler::OnMouseClick)
END_EVENT_TABLE()

wxComboFrameEventHandler::wxComboFrameEventHandler( wxPGComboBox* combo )
    : wxEvtHandler()
{
    m_combo = combo;
}

wxComboFrameEventHandler::~wxComboFrameEventHandler()
{
}

void wxComboFrameEventHandler::OnPopup()
{
    m_focusStart = ::wxWindow::FindFocus();
}

void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event )
{
    wxWindow* win_focused = ::wxWindow::FindFocus();

    wxWindow* popup = m_combo->GetPopupControl();
    wxWindow* winpopup = m_combo->GetPopupWindow();

    if (
         win_focused != m_focusStart &&
         win_focused != popup && 
         win_focused->GetParent() != popup &&
         win_focused != winpopup &&
         win_focused->GetParent() != winpopup &&
         win_focused != m_combo &&
         win_focused != m_combo->GetButton() // GTK (atleast) requires this
        )
    {
        //wxASSERT ( win_focused );
        //wxLogDebug( wxT("FOCUSED: class: %s"), win_focused->GetClassInfo()->GetClassName() );
        m_combo->HidePopup( false );    
    }

    event.Skip();
}

void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event )
{
    m_combo->HidePopup( false );
    event.Skip();
}

void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event )
{
    //if ( event.GetEventType() == wxEVT_MOUSEWHEEL )
    //    wxLogDebug( wxT("wxComboFrameEventHandler::OnMouseClick") );
    //else
    m_combo->HidePopup( false );
    event.Skip();
}

void wxComboFrameEventHandler::OnClose( wxCloseEvent& event )
{
    m_combo->HidePopup( false );
    event.Skip();
}

void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event )
{
    //wxLogDebug( wxT("wxComboFrameEventHandler::OnActivate") );
    m_combo->HidePopup( false );
    event.Skip();
}

void wxComboFrameEventHandler::OnResize( wxSizeEvent& event )
{
    m_combo->HidePopup( false );
    event.Skip();
}

void wxComboFrameEventHandler::OnMove( wxMoveEvent& event )
{
    m_combo->HidePopup( false );
    event.Skip();
}

#endif // wxODC_INSTALL_TOPLEV_HANDLER

// ----------------------------------------------------------------------------
// wxComboPopupWindow is wxPopupWindow customized for
// wxPGComboBox.
// ----------------------------------------------------------------------------

class wxComboPopupWindow : public wxComboPopupWindowBase
{
public:

    wxComboPopupWindow ( wxPGComboBox *parent, int style = wxBORDER_NONE );

#if wxODC_USE_TRANSIENT_POPUP
    virtual bool ProcessLeftDown(wxMouseEvent& event);
#endif

    void OnMouseEvent( wxMouseEvent& event );
#if !wxUSE_POPUPWIN
    void OnActivate( wxActivateEvent& event );
#endif

protected:

#if wxODC_USE_TRANSIENT_POPUP 
    virtual void OnDismiss();
#endif

private:
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(wxComboPopupWindow, wxComboPopupWindowBase)
    EVT_MOUSE_EVENTS(wxComboPopupWindow::OnMouseEvent)
#if !wxUSE_POPUPWIN
    EVT_ACTIVATE(wxComboPopupWindow::OnActivate)
#endif
END_EVENT_TABLE()

void wxComboPopupWindow::OnMouseEvent ( wxMouseEvent& event )
{
    //wxLogDebug(wxT("wxComboPopupWindow::OnMouseEvent(%i)"),(int)event.GetEventType());
    event.Skip();
}

#if !wxUSE_POPUPWIN
void wxComboPopupWindow::OnActivate( wxActivateEvent& event )
{
    if ( !event.GetActive() )
    {
        // Tell combo control that we are dismissed.
        wxPGComboBox* combo = (wxPGComboBox*) GetParent();
        wxASSERT ( combo );
        wxASSERT ( combo->IsKindOf(CLASSINFO(wxPGComboBox)) );

        combo->HidePopup( false );
        
        if ( ::wxFindWindowAtPoint(::wxGetMousePosition()) == (wxWindow*) combo->m_btn )
            combo->PreventNextButtonPopup();

        /*else
            combo->m_isPopupShown = false;*/

        event.Skip();
    }
}
#endif

wxComboPopupWindow::wxComboPopupWindow (wxPGComboBox *parent,
                                        int style)
#if wxUSE_POPUPWIN
                                       : wxComboPopupWindowBase(parent,style)
#else
                                       : wxComboPopupWindowBase(parent,
                                                                wxID_ANY,
                                                                wxEmptyString,
                                                                wxPoint(-21,-21),
                                                                wxSize(20,20),
                                                                style)
#endif
{
}

#if wxODC_USE_TRANSIENT_POPUP
bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent& event )
{
    //wxLogDebug(wxT("wxComboPopupWindow::ProcessLeftDown(%i,%i)"),event.m_x,event.m_y);
    //return false;
    return wxComboPopupWindowBase::ProcessLeftDown(event);
}
#endif

#if wxODC_USE_TRANSIENT_POPUP 
void wxComboPopupWindow::OnDismiss()
{
    // Tell combo control that we are dismissed.
    wxPGComboBox* combo = (wxPGComboBox*) GetParent();
    wxASSERT ( combo->IsKindOf(CLASSINFO(wxPGComboBox)) );

    //wxLogDebug(wxT("wxComboPopupWindow::OnDismiss()"));

    if ( !(::wxFindWindowAtPoint(::wxGetMousePosition()) == (wxWindow*) combo->m_btn) )
        combo->m_isPopupShown = 0;
    else
        combo->OnPopupDismiss();

}
#endif

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

BEGIN_EVENT_TABLE(wxComboPopupInterface, wxEvtHandler)
#if !wxODC_USE_TRANSIENT_POPUP
    EVT_MOUSE_EVENTS(wxComboPopupInterface::OnMouseEvent)
    //EVT_KILL_FOCUS(wxComboPopupInterface::OnFocusChange)
#endif
END_EVENT_TABLE()

wxComboPopupInterface::wxComboPopupInterface()
{
    m_callback = (wxComboPaintCallback) NULL;
}

wxComboPopupInterface::~wxComboPopupInterface()
{
    wxWindow* popup = m_combo->GetPopupControl();
    if ( popup )
        popup->RemoveEventHandler(this);
}

bool wxComboPopupInterface::Init( wxPGComboBox* combo )
{
    m_combo = combo;

    return true; // default is to generate popup immediately
}

bool wxComboPopupInterface::IsHighlighted ( int ) const
{
    return false;
}

const int* wxComboPopupInterface::GetIntPtr() const
{
    return (const int*) NULL;
}

void wxComboPopupInterface::Clear()
{
}

void wxComboPopupInterface::Delete( int WXUNUSED(item) )
{
}

int wxComboPopupInterface::FindString(const wxString&) const
{
    return wxNOT_FOUND;
}

int wxComboPopupInterface::GetCount() const
{
    return 0;
}

wxString wxComboPopupInterface::GetString( int ) const
{
    return wxEmptyString;
}

void wxComboPopupInterface::Insert( const wxString& WXUNUSED(item),
                                    int WXUNUSED(pos) )
{
}

void wxComboPopupInterface::SetSelection ( int WXUNUSED(item) )
{
}

void wxComboPopupInterface::SetString( int, const wxString& )
{
}

void wxComboPopupInterface::SetValueFromString ( const wxString& WXUNUSED(value) )
{
}

#if !wxODC_USE_TRANSIENT_POPUP
void wxComboPopupInterface::OnMouseEvent ( wxMouseEvent& event )
{
    //if ( m_handledWnd)
    //wxLogDebug(wxT("wxComboPopupInterface::OnMouseEvent(%i)"),(int)event.GetEventType());
    event.Skip();
}

/*void wxComboPopupInterface::OnFocusChange ( wxFocusEvent& event )
{
    m_combo->HidePopup();
    event.Skip();
}*/

#endif

// ----------------------------------------------------------------------------
// wxVListBoxComboPopup is a wxVListBox customized to act as a popup control
// ----------------------------------------------------------------------------

class wxVListBoxComboInterface;

class wxVListBoxComboPopup : public wxVListBox
{
public:

    // ctor and dtor
    wxVListBoxComboPopup(wxWindow* parent, wxVListBoxComboInterface* iface,
        wxComboPaintCallback callback, int style = 0);
    virtual ~wxVListBoxComboPopup();

    inline int GetItemAtPosition( const wxPoint& pos ) { return HitTest(pos); }

    inline wxCoord GetTotalHeight() const { return EstimateTotalHeight(); }

    inline wxCoord GetLineHeight(int line) const { return OnGetLineHeight(line); }

protected:

    // wxVListBox implementation
    virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
    virtual wxCoord OnMeasureItem(size_t n) const;
    void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;

    void SendSelectedEvent();

    // filter mouse move events happening outside the list box
    // move selection with cursor
    void OnMouseMove(wxMouseEvent& event);
    void OnKey(wxKeyEvent& event);
    void OnLeftClick(wxMouseEvent& event);

    wxVListBoxComboInterface*   m_iface;

    wxComboPaintCallback        m_callback;

private:

    // has the mouse been released on this control?
    bool m_clicked;

    DECLARE_EVENT_TABLE()
};

// ----------------------------------------------------------------------------
// wxVListBoxComboInterface is the "default" wxOwnerDrawComboBox combo
// interface. It uses wxVListBoxComboPopup as the popup control.
// ----------------------------------------------------------------------------

class wxVListBoxComboInterface : public wxComboPopupInterface
{
    friend class wxVListBoxComboPopup;
public:

    wxVListBoxComboInterface ( wxComboPaintCallback callback );
    virtual ~wxVListBoxComboInterface ();

    bool Init( wxPGComboBox* combo );

    virtual void Insert( const wxString& item, int pos );
    virtual void Clear();
    virtual void Delete( int item );
    virtual int FindString(const wxString& s) const;
    virtual int GetCount() const;
    virtual wxString GetString( int item ) const;
    virtual wxString GetValueAsString() const;
    virtual void SetSelection ( int item );
    virtual void SetString( int item, const wxString& str );
    virtual void SetValueFromString ( const wxString& value );

    virtual wxWindow* GeneratePopup( wxWindow* parent, int minWidth,
                                     int maxHeight, int prefHeight );

    virtual bool IsHighlighted ( int item ) const;

    virtual const int* GetIntPtr () const;

    void Populate ( int n, const wxString choices[] );

protected:

    // Event handlers.
    void OnMouseMove ( wxMouseEvent& event );
    void OnKey (wxKeyEvent& event);
    void OnSelect (wxCommandEvent& event);

    void CheckWidth( int pos, const wxString& item );

    wxVListBoxComboPopup*   m_popup;

    wxArrayString           m_strings;

    wxFont                  m_font;

    int                     m_value;

    int                     m_widestWidth; // width of widest item thus far

    int                     m_avgCharWidth;

    int                     m_baseImageWidth; // how much per item drawn in addition to text

private:
    DECLARE_EVENT_TABLE()
};

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

BEGIN_EVENT_TABLE(wxVListBoxComboPopup, wxVListBox)
    EVT_MOTION(wxVListBoxComboPopup::OnMouseMove)
    EVT_KEY_DOWN(wxVListBoxComboPopup::OnKey)
    EVT_LEFT_UP(wxVListBoxComboPopup::OnLeftClick)
END_EVENT_TABLE()

wxVListBoxComboPopup::wxVListBoxComboPopup(wxWindow *parent,
                                           wxVListBoxComboInterface* iface,
                                           wxComboPaintCallback callback,
                                           int style)
              : wxVListBox(parent, wxID_ANY,
                          wxDefaultPosition, wxDefaultSize,
                          wxBORDER_SIMPLE | wxLB_INT_HEIGHT | style )
{
    m_iface = iface;
    m_callback = callback;

    wxASSERT ( GetParent()->GetParent() );
    SetFont( GetParent()->GetParent()->GetFont() );

}

wxVListBoxComboPopup::~wxVListBoxComboPopup()
{
}

void wxVListBoxComboPopup::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const

⌨️ 快捷键说明

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