📄 manager.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// 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/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/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..",
"................",
"................",
"................"
};
/*
// Categoric Mode Icon
static char* gs_xpm_catmode[] = {
"12 12 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............"
};
// Alphabetic Mode Icon
static char* gs_xpm_noncatmode[] = {
"12 12 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.........."
};
// Default Page Icon.
static char* gs_xpm_defpage[] = {
"12 12 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.."
};*/
// -----------------------------------------------------------------------
/** \class wxPropertyGridPageData
\ingroup classes
\brief
Simple holder of propertygrid page information.
*/
/*
class wxPropertyGridPageData
{
public:
wxPropertyGridPageData() { }
~wxPropertyGridPageData() { }
wxString m_label;
wxPropertyGridState GetStatePtr();
int m_id;
};
*/
#define GetPageState(page) ((wxPropertyGridPage*)m_arrPages.Item(page))->GetStatePtr()
// -----------------------------------------------------------------------
// wxPropertyGridPage
// -----------------------------------------------------------------------
IMPLEMENT_CLASS(wxPropertyGridPage, wxEvtHandler)
BEGIN_EVENT_TABLE(wxPropertyGridPage, wxEvtHandler)
END_EVENT_TABLE()
wxPropertyGridPage::wxPropertyGridPage()
: wxEvtHandler(), wxPropertyContainerMethods(), wxPropertyGridState()
{
m_isDefault = false;
m_pState = this; // wxPropertyContainerMethods to point to State
}
wxPropertyGridPage::~wxPropertyGridPage()
{
}
void wxPropertyGridPage::RefreshProperty( wxPGProperty* p )
{
m_manager->RefreshProperty(p);
}
/*
bool wxPropertyGridPage::ProcessEvent( wxEvent& event )
{
// By default, redirect unhandled events to the manager's parent
if ( !wxEvtHandler::ProcessEvent(event) )
{
if ( IsHandlingAllEvents() )
return false;
m_manager->GetParent()->GetEventHandler()->AddPendingEvent(event);
return true;
}
return true;
}*/
wxPGId wxPropertyGridPage::Insert( wxPGId id, int index, wxPGProperty* property )
{
return m_manager->Insert(id,index,property);
}
wxPGId wxPropertyGridPage::Insert( wxPGPropNameStr name, int index, wxPGProperty* property )
{
return m_manager->Insert(name,index,property);
}
// -----------------------------------------------------------------------
// wxPropertyGridManager
// -----------------------------------------------------------------------
// 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()
{
//m_pPropGrid = (wxPropertyGrid*) NULL;
m_pPropGrid = CreatePropertyGrid();
#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_emptyPage = (wxPropertyGridPage*) NULL;
m_targetPage = 0;
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
// NB: But just prepare - you still need to call Add/InsertPage
// to actually add properties on it.
wxPropertyGridPage* pd = new wxPropertyGridPage();
pd->m_isDefault = true;
wxPropertyGridState* state = pd->GetStatePtr();
state->m_pPropGrid = m_pPropGrid;
m_arrPages.Add( (void*)pd );
m_pPropGrid->m_pState = state;
m_targetState = state;
wxWindowID baseId = GetId();
wxWindowID useId = baseId;
if ( baseId < 0 )
baseId = wxPG_MAN_ALTERNATE_BASE_ID;
#ifdef __WXMAC__
// Smaller controls on Mac
SetWindowVariant(wxWINDOW_VARIANT_SMALL);
#endif
// Create propertygrid.
m_pPropGrid->Create(this,baseId,wxPoint(0,0),csz,
(m_windowStyle&wxPG_MAN_PASS_FLAGS_MASK)
|wxPG_MAN_PROPGRID_FORCED_FLAGS);
m_pPropGrid->m_eventObject = this;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -