📄 advprops.cpp
字号:
//wxEnumPropertyClass::DoSetValue ( (void*)&value, NULL );
}
wxCursorPropertyClass::~wxCursorPropertyClass ()
{
}
wxSize wxCursorPropertyClass::GetImageSize() const
{
#if wxPG_CAN_DRAW_CURSOR
return wxSize(wxPG_CURSOR_IMAGE_WIDTH,wxPG_CURSOR_IMAGE_WIDTH);
#else
return wxSize(0,0);
#endif
}
#if wxPG_CAN_DRAW_CURSOR
void wxCursorPropertyClass::OnCustomPaint ( wxDC& dc,
const wxRect& rect, wxPGPaintData& paintdata )
{
// Background brush
dc.SetBrush ( wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNFACE ) );
if ( paintdata.m_choiceItem >= 0 )
{
dc.DrawRectangle ( rect );
int cursorindex = gs_cp_es_syscursors_values[paintdata.m_choiceItem];
/*
if ( cursorindex == wxPG_CURSOR_FROM_FILE )
{
wxFAIL_MSG(wxT("not implemented"));
}
else if ( cursorindex == wxPG_CURSOR_FROM_RESOURCE )
{
wxFAIL_MSG(wxT("not implemented"));
}
else
*/
{
if ( cursorindex == wxCURSOR_NONE )
cursorindex = wxCURSOR_ARROW;
wxCursor cursor( cursorindex );
#ifdef __WXMSW__
::DrawIconEx( (HDC)dc.GetHDC(),
rect.x,
rect.y,
(HICON)cursor.GetHandle(),
0,
0,
0,
NULL,
DI_COMPAT | DI_DEFAULTSIZE | DI_NORMAL
);
#endif
}
}
}
#else
void wxCursorPropertyClass::OnCustomPaint ( wxDC&, const wxRect&, wxPGPaintData& ) { }
#endif
// -----------------------------------------------------------------------
// wxImageFileProperty
// -----------------------------------------------------------------------
#if wxUSE_IMAGE
const wxString& wxPGGetDefaultImageWildcard ()
{
// Form the wildcard, if not done yet
if ( !wxPGGlobalVars->m_pDefaultImageWildcard.length() )
{
wxString str;
// TODO: This section may require locking (using global).
wxList& handlers = wxImage::GetHandlers();
wxList::iterator node;
// Let's iterate over the image handler list.
//for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
for ( node = handlers.begin(); node != handlers.end(); node++ )
{
wxImageHandler *handler = (wxImageHandler*)*node;
wxString ext_lo = handler->GetExtension();
wxString ext_up = ext_lo.Upper();
str.append ( ext_up );
str.append ( wxT(" files (*.") );
str.append ( ext_up );
str.append ( wxT(")|*.") );
str.append ( ext_lo );
str.append ( wxT("|") );
}
str.append ( wxT("All files (*.*)|*.*") );
wxPGGlobalVars->m_pDefaultImageWildcard = str;
}
return wxPGGlobalVars->m_pDefaultImageWildcard;
}
WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxImageFileProperty,const wxString&)
wxImageFilePropertyClass::wxImageFilePropertyClass ( const wxString& label, const wxString& name,
const wxString& value )
: wxFilePropertyClass(label,name,value)
{
m_wildcard = wxPGGetDefaultImageWildcard();
m_pImage = (wxImage*) NULL;
m_pBitmap = (wxBitmap*) NULL;
}
wxImageFilePropertyClass::~wxImageFilePropertyClass ()
{
if ( m_pBitmap )
delete m_pBitmap;
if ( m_pImage )
delete m_pImage;
}
void wxImageFilePropertyClass::DoSetValue ( wxPGVariant value )
{
wxFilePropertyClass::DoSetValue(value);
// Delete old image
if ( m_pImage )
{
delete m_pImage;
m_pImage = NULL;
}
if ( m_pBitmap )
{
delete m_pBitmap;
m_pBitmap = NULL;
}
// Create the image thumbnail
if ( m_filename.FileExists() )
{
m_pImage = new wxImage ( m_filename.GetFullPath() );
}
}
wxSize wxImageFilePropertyClass::GetImageSize() const
{
return wxSize(-1,-1);
}
void wxImageFilePropertyClass::OnCustomPaint ( wxDC& dc,
const wxRect& rect, wxPGPaintData& )
{
if ( m_pBitmap || (m_pImage && m_pImage->Ok() ) )
{
// Draw the thumbnail
// Create the bitmap here because required size is not known in DoSetValue().
if ( !m_pBitmap )
{
m_pImage->Rescale ( rect.width, rect.height );
m_pBitmap = new wxBitmap ( *m_pImage );
delete m_pImage;
m_pImage = NULL;
}
dc.DrawBitmap ( *m_pBitmap, rect.x, rect.y, FALSE );
}
else
{
// No file - just draw a white box
dc.SetBrush ( *wxWHITE_BRUSH );
dc.DrawRectangle ( rect );
}
}
#endif // wxUSE_IMAGE
// -----------------------------------------------------------------------
// wxMultiChoiceProperty
// -----------------------------------------------------------------------
#if wxUSE_CHOICEDLG
#include <wx/choicdlg.h>
wxPGProperty* wxPG_CONSTFUNC(wxMultiChoiceProperty)( const wxString& label, const wxString& name,
wxArrayString& strings, const wxArrayInt& value )
{
return new wxPG_PROPCLASS(wxMultiChoiceProperty)(label,name,strings,value);
}
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxArrayInt,
const wxArrayInt&,TextCtrlAndButton)
wxMultiChoicePropertyClass::wxMultiChoicePropertyClass ( const wxString& label,
const wxString& name,
wxArrayString& strings,
const wxArrayInt& value )
: wxPGProperty(label,name)
{
wxPG_INIT_REQUIRED_TYPE(wxArrayInt)
m_constants = wxPropertyGrid::AddConstantsArray(strings,
// This is good (value is
// not supposed to go here)
*((const wxArrayInt*)NULL),
true);
DoSetValue( (void*)&value );
}
wxMultiChoicePropertyClass::wxMultiChoicePropertyClass ( const wxString& label,
const wxString& name,
const wxArrayInt& WXUNUSED(value) )
: wxPGProperty(label,name)
{
m_constants = &wxPGGlobalVars->m_emptyConstants;
}
wxMultiChoicePropertyClass::~wxMultiChoicePropertyClass ()
{
wxPGUnRefChoices(m_constants);
}
void wxMultiChoicePropertyClass::DoSetValue ( wxPGVariant value )
{
wxArrayInt* pObj = (wxArrayInt*)wxPGVariantToVoidPtr(value);
if ( pObj )
{
m_value_wxArrayInt = *pObj;
GenerateValueAsString();
wxPG_SetVariantValueVoidPtr();
}
}
wxPGVariant wxMultiChoicePropertyClass::DoGetValue () const
{
return wxPGVariant((void*)&m_value_wxArrayInt);
}
wxString wxMultiChoicePropertyClass::GetValueAsString ( int ) const
{
return m_display;
}
void wxMultiChoicePropertyClass::GenerateValueAsString ()
{
// Allow zero-length strings list
if ( !m_constants->GetCount() )
{
m_display = wxEmptyString;
return;
}
wxString& tempstr = m_display;
unsigned int i;
unsigned int itemcount = m_value_wxArrayInt.GetCount();
tempstr.Empty();
if ( itemcount )
tempstr.append ( wxT("\"") );
for ( i = 0; i < itemcount; i++ )
{
int ind = m_value_wxArrayInt.Item(i);
wxASSERT ( ind >= 0 && ind < (int)m_constants->GetCount() );
tempstr.append ( m_constants->GetLabel(ind) );
tempstr.append ( wxT("\"") );
if ( i < (itemcount-1) )
tempstr.append ( wxT(" \"") );
}
}
bool wxMultiChoicePropertyClass::OnEvent ( wxPropertyGrid* propgrid, wxPGCtrlClass* primary,
wxEvent& event )
{
//if ( wxPGTextCtrlPropertyClass::OnEvent ( propgrid, primary, event ) )
// return TRUE;
if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
{
// Update the value
PrepareValueForDialogEditing(propgrid);
// launch editor dialog
wxMultiChoiceDialog dlg(propgrid,
_("Make a selection:"),
m_label,
m_constants->GetCount(),
&m_constants->GetLabels()[0],
wxCHOICEDLG_STYLE);
dlg.Move ( propgrid->GetGoodEditorDialogPosition (this,dlg.GetSize()) );
dlg.SetSelections(m_value_wxArrayInt);
if ( dlg.ShowModal() == wxID_OK /*&& dlg.IsModified()*/ )
{
wxArrayInt arrint = dlg.GetSelections();
DoSetValue ( (void*)&arrint );
UpdateControl ( primary );
return TRUE;
}
}
return FALSE;
}
int wxMultiChoicePropertyClass::GetChoiceInfo ( wxPGChoiceInfo* choiceinfo )
{
if ( choiceinfo )
{
choiceinfo->m_itemCount = m_constants->GetCount();
choiceinfo->m_constants = &m_constants;
}
return -1;
}
bool wxMultiChoicePropertyClass::SetValueFromString ( const wxString& text, int )
{
m_value_wxArrayInt.Empty();
wxArrayString& strings = m_constants->GetLabels();
WX_PG_TOKENIZER2_BEGIN(text,wxT('"'))
int ind = strings.Index( token );
if ( ind != wxNOT_FOUND )
m_value_wxArrayInt.Add ( ind );
WX_PG_TOKENIZER2_END()
GenerateValueAsString();
return TRUE;
}
#endif // wxUSE_CHOICEDLG
// -----------------------------------------------------------------------
// wxPropertyContainerMethods
// -----------------------------------------------------------------------
void wxPropertyContainerMethods::InitAllTypeHandlers ()
{
wxPG_INIT_REQUIRED_TYPE(wxColour)
wxPG_INIT_REQUIRED_TYPE(wxFont)
wxPG_INIT_REQUIRED_TYPE(wxArrayInt)
wxPG_INIT_REQUIRED_TYPE(wxColourPropertyValue)
}
// -----------------------------------------------------------------------
void wxPropertyContainerMethods::RegisterAdvancedPropertyClasses()
{
wxPGRegisterPropertyClass(wxMultiChoiceProperty);
wxPGRegisterPropertyClass(wxImageFileProperty);
wxPGRegisterPropertyClass(wxColourProperty);
wxPGRegisterPropertyClass(wxFontProperty);
wxPGRegisterPropertyClass(wxSystemColourProperty);
wxPGRegisterPropertyClass(wxCursorProperty);
}
// -----------------------------------------------------------------------
#endif // wxPG_INCLUDE_ADVPROPS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -