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

📄 manager.cpp

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////
// Name:        manager.cpp
// Purpose:     wxPropertyGridManager
// Author:      Jaakko Salli
// Modified by:
// Created:     Jan-14-2005
// RCS-ID:      $Id:
// Copyright:   (c) Jaakko Salli
// Licence:     wxWindows license
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
    #pragma implementation "manager.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/defs.h"
    #include "wx/object.h"
    #include "wx/hash.h"
    #include "wx/string.h"
    #include "wx/log.h"
    #include "wx/event.h"
    #include "wx/window.h"
    #include "wx/panel.h"
    #include "wx/dc.h"
    #include "wx/dcclient.h"
    //#include "wx/dcmemory.h"
    #include "wx/button.h"
    #include "wx/pen.h"
    #include "wx/brush.h"
    #include "wx/cursor.h"
    #include "wx/dialog.h"
    #include "wx/settings.h"
    #include "wx/msgdlg.h"
    #include "wx/choice.h"
    #include "wx/stattext.h"
    #include "wx/textctrl.h"
    #include "wx/scrolwin.h"
    #include "wx/dirdlg.h"
    //#include "wx/listbox.h"
    #include "wx/combobox.h"
    #include "wx/layout.h"
    #include "wx/sizer.h"
    #include "wx/textdlg.h"
    #include "wx/filedlg.h"
    #include "wx/statusbr.h"
    #include "wx/toolbar.h"
    #include "wx/intl.h"
#endif

// This define is necessary to prevent macro clearing
#define __wxPG_SOURCE_FILE__

#include <wx/propgrid/propgrid.h>

#include <wx/propgrid/manager.h>


#define wxPG_MAN_ALTERNATE_BASE_ID          11249 // Needed for wxID_ANY madnesss


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

// For wxMSW cursor consistency, we must do mouse capturing even
// when using custom controls

# define BEGIN_MOUSE_CAPTURE \
    if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) \
    { \
        CaptureMouse(); \
        m_iFlags |= wxPG_FL_MOUSE_CAPTURED; \
    }

# define END_MOUSE_CAPTURE \
    if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) \
    { \
        ReleaseMouse(); \
        m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); \
    }

// -----------------------------------------------------------------------
// wxPropertyGridManager
// -----------------------------------------------------------------------

const wxChar *wxPropertyGridManagerNameStr = wxT("wxPropertyGridManager");

/* Categoric Mode Icon */
static char* gs_xpm_catmode[] = {
"16 16 5 1",
". c none",
"B c black",
"D c #868686",
"L c #CACACA",
"W c #FFFFFF",
".DDD............",
".DLD.BBBBBB.....",
".DDD............",
".....DDDDD.DDD..",
"................",
".....DDDDD.DDD..",
"................",
".....DDDDD.DDD..",
"................",
".....DDDDD.DDD..",
"................",
".DDD............",
".DLD.BBBBBB.....",
".DDD............",
".....DDDDD.DDD..",
"................"
};

/* Alphabetic Mode Icon */
static char* gs_xpm_noncatmode[] = {
"16 16 5 1",
". c none",
"B c black",
"D c #868686",
"L c #000080",
"W c #FFFFFF",
"..DBD...DDD.DDD.",
".DB.BD..........",
".BBBBB..DDD.DDD.",
".B...B..........",
"...L....DDD.DDD.",
"...L............",
".L.L.L..DDD.DDD.",
"..LLL...........",
"...L....DDD.DDD.",
"................",
".BBBBB..DDD.DDD.",
"....BD..........",
"...BD...DDD.DDD.",
"..BD............",
".BBBBB..DDD.DDD.",
"................"
};

/* Default Page Icon. */
static char* gs_xpm_defpage[] = {
"16 16 5 1",
". c none",
"B c black",
"D c #868686",
"L c #000080",
"W c #FFFFFF",
"................",
"................",
"..BBBBBBBBBBBB..",
"..B..........B..",
"..B.BB.LLLLL.B..",
"..B..........B..",
"..B.BB.LLLLL.B..",
"..B..........B..",
"..B.BB.LLLLL.B..",
"..B..........B..",
"..B.BB.LLLLL.B..",
"..B..........B..",
"..BBBBBBBBBBBB..",
"................",
"................",
"................"
};

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

/** \class wxPropertyGridPageData
    \ingroup classes
    \brief
    Simple holder of propertygrid page information.
*/
class wxPropertyGridPageData
{
public:

    wxPropertyGridPageData() { }
    ~wxPropertyGridPageData() { }

    wxString                m_label;
    wxPropertyGridState     m_state;
    int                     m_id;
};

#define GetPageState(page) (&((wxPropertyGridPageData*)m_arrPages.Item(page))->m_state)

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

// Final default splitter y is client height minus this.
#define wxPGMAN_DEFAULT_NEGATIVE_SPLITTER_Y         100

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

IMPLEMENT_CLASS(wxPropertyGridManager, wxPanel)

#define ID_ADVTOOLBAR_OFFSET        1
#define ID_ADVHELPCAPTION_OFFSET    2
#define ID_ADVHELPCONTENT_OFFSET    3
#define ID_ADVBUTTON_OFFSET         4
#define ID_ADVTBITEMSBASE_OFFSET    5   // Must be last.

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

BEGIN_EVENT_TABLE(wxPropertyGridManager, wxPanel)
  EVT_MOTION(wxPropertyGridManager::OnMouseMove)
  EVT_SIZE(wxPropertyGridManager::OnResize)
  EVT_PAINT(wxPropertyGridManager::OnPaint)
  EVT_LEFT_DOWN(wxPropertyGridManager::OnMouseClick)
  EVT_LEFT_UP(wxPropertyGridManager::OnMouseUp)
  EVT_LEAVE_WINDOW(wxPropertyGridManager::OnMouseEntry)
  //EVT_ENTER_WINDOW(wxPropertyGridManager::OnMouseEntry)
END_EVENT_TABLE()

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

wxPropertyGridManager::wxPropertyGridManager()
    : wxPanel()
{
    Init1();
}

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

wxPropertyGridManager::wxPropertyGridManager (wxWindow *parent, wxWindowID id,
                const wxPoint& pos,
                const wxSize& size,
                long style,
                const wxChar* name )
    : wxPanel()
{
    Init1();
    Create(parent,id,pos,size,style,name);
}

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

bool wxPropertyGridManager::Create ( wxWindow *parent, wxWindowID id ,
                const wxPoint& pos,
                const wxSize& size,
                long style,
                const wxChar* name )
{

    bool res = wxPanel::Create ( parent, id, pos, size, (style&0xFFFF0000)|wxWANTS_CHARS, name );
    Init2(style);

    return res;
}

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

//
// Initialize values to defaults
//
void wxPropertyGridManager::Init1()
{

#if wxUSE_TOOLBAR
    m_pToolbar = (wxToolBar*) NULL;
#endif
    m_pTxtHelpCaption = (wxStaticText*) NULL;
    m_pTxtHelpContent = (wxStaticText*) NULL;
    m_pButCompactor = (wxButton*) NULL;

    m_targetState = (wxPropertyGridState*) NULL;

    m_selPage = -1;

    m_width = m_height = 0;

    m_splitterHeight = 5;

    m_splitterY = -1; // -1 causes default to be set.

    m_nextDescBoxSize = -1;

    m_extraHeight = 0;
    m_dragStatus = 0;
    m_onSplitter = 0;
    m_iFlags = 0;

}

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

// These flags are always used in wxPropertyGrid integrated in xPropertyGridManager.
#define wxPG_MAN_PROPGRID_FORCED_FLAGS (wxSIMPLE_BORDER| \
                                        wxNO_FULL_REPAINT_ON_RESIZE| \
                                        wxCLIP_CHILDREN)

// Which flags can be passed to underlying wxPropertyGrid.
#define wxPG_MAN_PASS_FLAGS_MASK       (0xFFF0|wxTAB_TRAVERSAL)

//
// Initialize after parent etc. set
//
void wxPropertyGridManager::Init2 ( int style )
{

    if ( m_iFlags & wxPG_FL_INITIALIZED )
        return;

    m_windowStyle |= (style&0x0000FFFF);

    wxSize csz = GetClientSize();

    m_cursorSizeNS = wxCursor(wxCURSOR_SIZENS);

    // Prepare the first page
    wxPropertyGridPageData* pd = new wxPropertyGridPageData();
    pd->m_state.m_pPropGrid = &m_propGrid;
    m_arrPages.Add( (void*)pd );
    m_propGrid.m_pState = &pd->m_state;
    m_targetState = &pd->m_state;

    wxWindowID baseId = GetId();
    wxWindowID useId = baseId;
    if ( baseId < 0 )
        baseId = wxPG_MAN_ALTERNATE_BASE_ID;

    // Create propertygrid.
    m_propGrid.Create(this,baseId,wxPoint(0,0),csz,
        (m_windowStyle&wxPG_MAN_PASS_FLAGS_MASK)
        |wxPG_MAN_PROPGRID_FORCED_FLAGS
      );

    m_propGrid.SetId(useId);

    m_propGrid.m_iFlags |= wxPG_FL_IN_MANAGER;

    m_pState = m_propGrid.m_pState;

    //m_propGrid.SetCursor ( *wxSTANDARD_CURSOR );
    //m_propGrid.SetCursor ( wxPG_DEFAULT_CURSOR );
    m_propGrid.SetExtraStyle(wxPG_EX_INIT_NOCAT);

    m_nextTbInd = baseId+ID_ADVTBITEMSBASE_OFFSET + 2;

    // Connect to property grid onselect event.
    Connect(useId,
            wxEVT_PG_SELECTED,
            (wxObjectEventFunction) (wxEventFunction) (wxPropertyGridEventFunction)
            &wxPropertyGridManager::OnPropertyGridSelect );

    // Connect to compactor button event.
    Connect(baseId+ID_ADVBUTTON_OFFSET,
            wxEVT_COMMAND_BUTTON_CLICKED,
            (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
            &wxPropertyGridManager::OnCompactorClick );

    // Connect to toolbar button events.
    Connect(baseId+ID_ADVTBITEMSBASE_OFFSET,baseId+ID_ADVTBITEMSBASE_OFFSET+50,
            wxEVT_COMMAND_TOOL_CLICKED,
            (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
            &wxPropertyGridManager::OnToolbarClick );

    /*
    // Connect to wxPropertyGrid mouse entry.
    Connect(baseId,
            wxEVT_ENTER_WINDOW,
            (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction)
            &wxPropertyGridManager::OnMouseEntry );

    // Connect to button mouse entry.
    Connect(baseId+ID_ADVBUTTON_OFFSET,
            wxEVT_ENTER_WINDOW,
            (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction)
            &wxPropertyGridManager::OnMouseEntry );
    */

#if !wxUSE_TOOLBAR && defined(__WXDEBUG__)
    if ( m_windowStyle & wxPG_TOOLBAR )
        wxLogDebug(wxT("WARNING: wxPropertyGridManager ignores style %s with this library build."),wxT("wxPG_TOOLBAR"));
#endif

    // Optional initial controls.
    m_width = -12345;
    //RecreateControls();

    m_iFlags |= wxPG_FL_INITIALIZED;

}

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

wxPropertyGridManager::~wxPropertyGridManager()
{
    END_MOUSE_CAPTURE

#if wxUSE_TOOLBAR
    /*if ( m_pBmpCatMode ) delete m_pBmpCatMode;
    if ( m_pBmpNonCatMode ) delete m_pBmpNonCatMode;*/
#endif

    size_t i;
    for ( i=0; i<m_arrPages.GetCount(); i++ )
    {
        // Do not delete selected, since its pointers etc. are copied
        // to propgrid, which automatically deletes it.
        //if ( i != (size_t)m_selPage )
        delete (wxPropertyGridPageData*)m_arrPages.Item(i);
    }

}

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

void wxPropertyGridManager::SetId( wxWindowID winid )
{
    wxWindow::SetId(winid);

    // TODO: Reconnect propgrid event handler(s).

    m_propGrid.SetId(winid);
}

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

wxSize wxPropertyGridManager::DoGetBestSize() const
{
    /*
    //wxSize sz = m_propGrid.DoGetBestSize();
    wxSize sz(60,m_propGrid.m_lineHeight);
    wxLogDebug(wxT("m_extraHeight: %i"),m_extraHeight);
    sz.y += m_extraHeight;
    wxLogDebug(wxT("sz.y: %i"),sz.y);
    //CacheBestSize(sz);
    return sz;
    */
    return wxSize(60,150);
}

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

bool wxPropertyGridManager::SetFont ( const wxFont& font )
{
    bool res = wxWindow::SetFont(font);
    m_propGrid.SetFont(font);
    // TODO: Need to do caption recacalculations for other pages as well.
    return res;
}

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

void wxPropertyGridManager::SetExtraStyle ( long exStyle )
{
    wxWindow::SetExtraStyle ( exStyle );
    m_propGrid.SetExtraStyle ( exStyle & 0xFFFFF000 );
#if wxUSE_TOOLBAR
    if ( (exStyle & wxPG_EX_NO_FLAT_TOOLBAR) && m_pToolbar )
        RecreateControls();
#endif
}

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

void wxPropertyGridManager::Freeze()
{
    m_propGrid.Freeze();
    wxWindow::Freeze();
}

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

void wxPropertyGridManager::Thaw()
{
    wxWindow::Thaw();
    m_propGrid.Thaw();
}

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

void wxPropertyGridManager::SetWindowStyleFlag ( long style )
{
    wxWindow::SetWindowStyleFlag( style );
    m_propGrid.SetWindowStyleFlag( (m_propGrid.GetWindowStyleFlag()&~(wxPG_MAN_PASS_FLAGS_MASK)) |
                                   (style&wxPG_MAN_PASS_FLAGS_MASK) );
}

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

// Actually shows given page.
void wxPropertyGridManager::SelectPage ( int index )
{
    wxASSERT ( m_selPage >= 0 );

    wxCHECK_RET( index >= 0 && index < (int)m_arrPages.GetCount(),
        wxT("invalid page index") );

    if ( m_selPage == index )
        return;

    wxPropertyGridPageData* pd_next = (wxPropertyGridPageData*)m_arrPages.Item(index);

    m_iFlags |= wxPG_FL_DESC_REFRESH_REQUIRED;

    m_propGrid.SwitchState ( &pd_next->m_state );

    m_targetState = &pd_next->m_state;
    m_pState = m_propGrid.m_pState;

⌨️ 快捷键说明

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