📄 props.cpp
字号:
return true;
}
dlg->Destroy();
return false;
}
bool wxLongStringPropertyClass::SetValueFromString( const wxString& text, int )
{
if ( m_value != text )
{
DoSetValue ( text );
return true;
}
return false;
}
// -----------------------------------------------------------------------
// wxArrayEditorDialog
// -----------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxArrayEditorDialog, wxDialog)
EVT_IDLE(wxArrayEditorDialog::OnIdle)
EVT_LISTBOX(24, wxArrayEditorDialog::OnListBoxClick)
EVT_TEXT_ENTER(21, wxArrayEditorDialog::OnAddClick)
EVT_BUTTON(22, wxArrayEditorDialog::OnAddClick)
EVT_BUTTON(23, wxArrayEditorDialog::OnDeleteClick)
EVT_BUTTON(25, wxArrayEditorDialog::OnUpClick)
EVT_BUTTON(26, wxArrayEditorDialog::OnDownClick)
EVT_BUTTON(27, wxArrayEditorDialog::OnUpdateClick)
//EVT_BUTTON(28, wxArrayEditorDialog::OnCustomEditClick)
END_EVENT_TABLE()
IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog, wxDialog)
#include <wx/statline.h>
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnIdle(wxIdleEvent& event)
{
//
// Do control focus detection here.
//
wxWindow* focused = FindFocus();
// This strange focus thing is a workaround for wxGTK wxListBox focus
// reporting bug.
if ( m_curFocus == 0 && focused != m_edValue &&
focused != m_butAdd && focused != m_butUpdate &&
m_lbStrings->GetSelection() >= 0 )
{
//wxLogDebug(wxT("Focused: %s"),focused?focused->GetClassInfo()->GetClassName():wxT("NULL"));
// ListBox was just focused.
m_butAdd->Enable(false);
m_butUpdate->Enable(false);
m_butRemove->Enable(true);
m_butUp->Enable(true);
m_butDown->Enable(true);
m_curFocus = 1;
}
else if ( (m_curFocus == 1 && focused == m_edValue) /*|| m_curFocus == 2*/ )
{
//wxLogDebug(wxT("Focused: %s"),focused?focused->GetClassInfo()->GetClassName():wxT("NULL"));
// TextCtrl was just focused.
m_butAdd->Enable(true);
bool upd_enable = false;
if ( m_lbStrings->GetCount() && m_lbStrings->GetSelection() >= 0 )
upd_enable = true;
m_butUpdate->Enable(upd_enable);
m_butRemove->Enable(false);
m_butUp->Enable(false);
m_butDown->Enable(false);
m_curFocus = 0;
}
event.Skip();
}
// -----------------------------------------------------------------------
wxArrayEditorDialog::wxArrayEditorDialog()
: wxDialog()
{
Init();
}
// -----------------------------------------------------------------------
void wxArrayEditorDialog::Init()
{
m_custBtText = (const wxChar*) NULL;
//m_pCallingClass = (wxArrayStringPropertyClass*) NULL;
}
// -----------------------------------------------------------------------
wxArrayEditorDialog::wxArrayEditorDialog( wxWindow *parent,
const wxString& message,
const wxString& caption,
long style,
const wxPoint& pos,
const wxSize& sz )
: wxDialog()
{
Init();
Create(parent,message,caption,style,pos,sz);
}
// -----------------------------------------------------------------------
bool wxArrayEditorDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& caption,
long style,
const wxPoint& pos,
const wxSize& sz )
{
bool res = wxDialog::Create(parent,1,caption,pos,sz,style);
SetFont(parent->GetFont()); // To allow entering chars of the same set as the propGrid
#if !wxPG_SMALL_SCREEN
const int spacing = 4;
#else
const int spacing = 3;
#endif
m_modified = false;
m_curFocus = 1;
const int but_sz_flags =
wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL; //wxBOTTOM|wxLEFT|wxRIGHT;
wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL );
// Message
if ( message.length() )
topsizer->Add( new wxStaticText(this,-1,message),
0, wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxALL, spacing );
// String editor
wxBoxSizer* rowsizer = new wxBoxSizer( wxHORIZONTAL );
m_edValue = new wxTextCtrl(this,21,wxEmptyString,
wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
wxValidator* validator = GetTextCtrlValidator();
if ( validator )
{
m_edValue->SetValidator( *validator );
delete validator;
}
rowsizer->Add( m_edValue,
1, wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxALL, spacing );
// Add button
m_butAdd = new wxButton(this,22,_("Add"));
rowsizer->Add( m_butAdd,
0, wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, spacing );
topsizer->Add( rowsizer, 0, wxEXPAND, spacing );
// Separator line
topsizer->Add( new wxStaticLine(this,-1),
0, wxEXPAND|wxBOTTOM|wxLEFT|wxRIGHT, spacing );
rowsizer = new wxBoxSizer( wxHORIZONTAL );
// list box
m_lbStrings = new wxListBox(this, 24, wxDefaultPosition, wxDefaultSize);
unsigned int i;
for ( i=0; i<ArrayGetCount(); i++ )
m_lbStrings->Append( ArrayGet(i) );
rowsizer->Add( m_lbStrings, 1, wxEXPAND|wxRIGHT, spacing );
// Manipulator buttons
wxBoxSizer* colsizer = new wxBoxSizer( wxVERTICAL );
m_butCustom = (wxButton*) NULL;
if ( m_custBtText )
{
m_butCustom = new wxButton(this,28,::wxGetTranslation(m_custBtText));
colsizer->Add( m_butCustom,
0, wxALIGN_CENTER|wxTOP/*wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT*/,
spacing );
}
m_butUpdate = new wxButton(this,27,_("Update"));
colsizer->Add( m_butUpdate,
0, wxALIGN_CENTER|wxTOP, spacing );
m_butRemove = new wxButton(this,23,_("Remove"));
colsizer->Add( m_butRemove,
0, wxALIGN_CENTER|wxTOP, spacing );
m_butUp = new wxButton(this,25,_("Up"));
colsizer->Add( m_butUp,
0, wxALIGN_CENTER|wxTOP, spacing );
m_butDown = new wxButton(this,26,_("Down"));
colsizer->Add( m_butDown,
0, wxALIGN_CENTER|wxTOP, spacing );
rowsizer->Add( colsizer, 0, 0, spacing );
topsizer->Add( rowsizer, 1, wxLEFT|wxRIGHT|wxEXPAND, spacing );
// Separator line
topsizer->Add( new wxStaticLine(this,-1),
0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, spacing );
// buttons
rowsizer = new wxBoxSizer( wxHORIZONTAL );
/*
const int but_sz_flags =
wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT;
*/
rowsizer->Add( new wxButton(this,wxID_OK,_("Ok")),
0, but_sz_flags, spacing );
rowsizer->Add( new wxButton(this,wxID_CANCEL,_("Cancel")),
0, but_sz_flags, spacing );
topsizer->Add( rowsizer, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL, 0 );
m_edValue->SetFocus();
SetSizer( topsizer );
topsizer->SetSizeHints( this );
#if !wxPG_SMALL_SCREEN
if ( sz.x == wxDefaultSize.x &&
sz.y == wxDefaultSize.y )
SetSize( wxSize(275,360) );
else
SetSize(sz);
#endif
return res;
}
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnAddClick(wxCommandEvent& )
{
wxString text = m_edValue->GetValue();
if ( text.length() )
{
if ( ArrayInsert( text, -1 ) )
{
m_lbStrings->Append( text );
m_modified = true;
m_edValue->Clear();
}
}
}
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnDeleteClick(wxCommandEvent& )
{
int index = m_lbStrings->GetSelection();
if ( index >= 0 )
{
ArrayRemoveAt( index );
m_lbStrings->Delete ( index );
m_modified = true;
}
}
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnUpClick(wxCommandEvent& )
{
int index = m_lbStrings->GetSelection();
if ( index > 0 )
{
ArraySwap(index-1,index);
/*wxString old_str = m_array[index-1];
wxString new_str = m_array[index];
m_array[index-1] = new_str;
m_array[index] = old_str;*/
m_lbStrings->SetString ( index-1, ArrayGet(index-1) );
m_lbStrings->SetString ( index, ArrayGet(index) );
m_lbStrings->SetSelection ( index-1 );
m_modified = true;
}
}
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnDownClick(wxCommandEvent& )
{
int index = m_lbStrings->GetSelection();
int lastStringIndex = ((int) m_lbStrings->GetCount()) - 1;
if ( index >= 0 && index < lastStringIndex )
{
ArraySwap(index,index+1);
/*wxString old_str = m_array[index+1];
wxString new_str = m_array[index];
m_array[index+1] = new_str;
m_array[index] = old_str;*/
m_lbStrings->SetString ( index+1, ArrayGet(index+1) );
m_lbStrings->SetString ( index, ArrayGet(index) );
m_lbStrings->SetSelection ( index+1 );
m_modified = true;
}
}
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnUpdateClick(wxCommandEvent& )
{
int index = m_lbStrings->GetSelection();
if ( index >= 0 )
{
wxString str = m_edValue->GetValue();
if ( ArraySet(index,str) )
{
m_lbStrings->SetString ( index, str );
//m_array[index] = str;
m_modified = true;
}
}
}
// -----------------------------------------------------------------------
/*void wxArrayEditorDialog::OnCustomEditClick(wxCommandEvent& )
{
wxASSERT ( m_pCallingClass );
wxString str = m_edValue->GetValue();
if ( m_pCallingClass->OnCustomStringEdit(m_parent,str) )
{
//m_edValue->SetValue ( str );
if ( ArrayInsert(-1,str) )
{
m_lbStrings->Append ( str );
m_modified = true;
}
}
}*/
// -----------------------------------------------------------------------
void wxArrayEditorDialog::OnListBoxClick(wxCommandEvent& )
{
int index = m_lbStrings->GetSelection();
if ( index >= 0 )
{
m_edValue->SetValue( m_lbStrings->GetString(index) );
}
}
// -----------------------------------------------------------------------
// wxArrayStringEditorDialog
// -----------------------------------------------------------------------
class wxArrayStringEditorDialog : public wxArrayEditorDialog
{
public:
wxArrayStringEditorDialog();
void Init();
virtual void SetDialogValue( const wxVariant& value )
{
m_array = value.GetArrayString();
}
virtual wxVariant GetDialogValue() const
{
return m_array;
}
inline void SetCustomButton( const wxChar* custBtText, wxArrayStringPropertyClass* pcc )
{
m_custBtText = custBtText;
m_pCallingClass = pcc;
}
void OnCustomEditClick(wxCommandEvent& event);
protected:
wxArrayString m_array;
wxArrayStringPropertyClass* m_pCallingClass;
virtual wxString ArrayGet( size_t index );
virtual size_t ArrayGetCount();
virtual bool ArrayInsert( const wxString& str, int index );
virtual bool ArraySet( size_t index, const wxString& str );
virtual void ArrayRemoveAt( int index );
virtual void ArraySwap( size_t first, size_t second );
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayStringEditorDialog)
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxArrayStringEditorDialog, wxArrayEditorDialog)
EVT_BUTTON(28, wxArrayStringEditorDialog::OnCustomEditClick)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxArrayStringEditorDialog, wxArrayEditorDialog)
// -----------------------------------------------------------------------
wxString wxArrayStringEditorDialog::ArrayGet( size_t index )
{
return m_array[index];
}
size_t wxArrayStringEditorDialog::ArrayGetCount()
{
return m_array.GetCount();
}
bool wxArrayStringEditorDialog::ArrayInsert( const wxString& str, int index )
{
if (index<0)
m_array.Add(str);
else
m_array.Insert(str,index);
return true;
}
bool wxArrayStringEditorDialog::ArraySet( size_t index, const wxString& str )
{
m_array[index] = str;
return true;
}
void wxArrayStringEditorDialog::ArrayRemoveAt( int index )
{
m_array.RemoveAt(index);
}
void wxArrayStringEditorDialog::ArraySwap( size_t first, size_t second )
{
wxString old_str = m_array[first];
wxString new_str = m_array[second];
m_array[first] = new_str;
m_array[second] = old_str;
}
wxArrayStringEditorDialog::wxArrayStringEditorDialog()
: wxArrayEditorDialog()
{
Init();
}
void wxArrayStringEditorDialog::Init()
{
m_pCallingClass = (wxArrayStringPropertyClass*) NULL;
}
void wxArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent& )
{
wxASSERT( m_pCallingClass );
wxString str = m_edValue->GetValue();
if ( m_pCallingClass->OnCustomStringEdit(m_parent,str) )
{
//m_edValue->SetValue ( str );
m_lbStrings->Append ( str );
m_array.Add ( str );
m_modified = true;
}
}
// -----------------------------------------------------------------------
// wxArrayStringPropert
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -