X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/feeb8165970889f393d4a1bf2dae2a1505fd5e4c..1a0d517ea4dbcef61ba9b0868318f686e97618bb:/src/generic/proplist.cpp diff --git a/src/generic/proplist.cpp b/src/generic/proplist.cpp index 30c31e44a6..55722a5c10 100644 --- a/src/generic/proplist.cpp +++ b/src/generic/proplist.cpp @@ -9,27 +9,37 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "proplist.h" + #pragma implementation "proplist.h" #endif // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif +#if wxUSE_PROPSHEET + #ifndef WX_PRECOMP -#include "wx/window.h" -#include "wx/font.h" -#include "wx/button.h" -#include "wx/bmpbuttn.h" -#include "wx/textctrl.h" -#include "wx/listbox.h" -#include "wx/settings.h" -#include "wx/msgdlg.h" -#include "wx/filedlg.h" + #include "wx/window.h" + #include "wx/font.h" + #include "wx/button.h" + #include "wx/bmpbuttn.h" + #include "wx/textctrl.h" + #include "wx/listbox.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" + #include "wx/filedlg.h" #endif #include "wx/sizer.h" @@ -44,25 +54,27 @@ #include #include +// ---------------------------------------------------------------------------- +// XPMs +// ---------------------------------------------------------------------------- + #ifndef __WXMSW__ -#include "wx/generic/cross.xpm" -#include "wx/generic/tick.xpm" + #include "wx/generic/cross.xpm" + #include "wx/generic/tick.xpm" #endif +// ---------------------------------------------------------------------------- +// accessor functions for the bitmaps (may return NULL, check for it!) +// ---------------------------------------------------------------------------- -/* - * global data, urgh. - */ +static wxBitmap *GetTickBitmap(); +static wxBitmap *GetCrossBitmap(); -static wxBitmap* gs_tickBitmap = (wxBitmap*) NULL; -static wxBitmap* gs_crossBitmap = (wxBitmap*) NULL; +// ---------------------------------------------------------------------------- +// Property text edit control +// ---------------------------------------------------------------------------- - -/* - * Property text edit control - */ - -IMPLEMENT_CLASS(wxPropertyTextEdit, wxTextCtrl) +IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit, wxTextCtrl) wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent, const wxWindowID id, const wxString& value, @@ -73,17 +85,17 @@ wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent, m_view = v; } -void wxPropertyTextEdit::OnSetFocus(void) +void wxPropertyTextEdit::OnSetFocus() { } -void wxPropertyTextEdit::OnKillFocus(void) +void wxPropertyTextEdit::OnKillFocus() { } -/* - * Property list view - */ +// ---------------------------------------------------------------------------- +// Property list view +// ---------------------------------------------------------------------------- bool wxPropertyListView::sm_dialogCancelled = FALSE; @@ -121,7 +133,7 @@ wxPropertyListView::wxPropertyListView(wxPanel *propPanel, long flags):wxPropert m_detailedEditing = FALSE; } -wxPropertyListView::~wxPropertyListView(void) +wxPropertyListView::~wxPropertyListView() { } @@ -138,7 +150,7 @@ void wxPropertyListView::ShowView(wxPropertySheet *ps, wxPanel *panel) // Update this view of the viewed object, called e.g. by // the object itself. -bool wxPropertyListView::OnUpdateView(void) +bool wxPropertyListView::OnUpdateView() { return TRUE; } @@ -205,7 +217,7 @@ bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty *property) // Find the wxListBox index corresponding to this property int wxPropertyListView::FindListIndexForProperty(wxProperty *property) { - int n = m_propertyScrollingList->Number(); + int n = m_propertyScrollingList->GetCount(); for (int i = 0; i < n; i++) { if (property == (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(i)) @@ -299,7 +311,7 @@ bool wxPropertyListView::EndShowingProperty(wxProperty *property) return TRUE; } -void wxPropertyListView::BeginDetailedEditing(void) +void wxPropertyListView::BeginDetailedEditing() { if (!m_currentValidator) return; @@ -318,7 +330,7 @@ void wxPropertyListView::BeginDetailedEditing(void) m_detailedEditing = TRUE; } -void wxPropertyListView::EndDetailedEditing(void) +void wxPropertyListView::EndDetailedEditing() { if (!m_currentValidator) return; @@ -410,7 +422,7 @@ bool wxPropertyListView::CreateControls() { wxPanel *panel = (wxPanel *)m_propertyWindow; - wxSize largeButtonSize( 60, 25 ); + wxSize largeButtonSize( 70, 25 ); wxSize smallButtonSize( 23, 23 ); if (m_valueText) @@ -441,19 +453,22 @@ bool wxPropertyListView::CreateControls() if (m_buttonFlags & wxPROP_BUTTON_CHECK_CROSS) { - if (gs_tickBitmap && gs_crossBitmap) + wxBitmap *tickBitmap = GetTickBitmap(); + wxBitmap *crossBitmap = GetCrossBitmap(); + + if ( tickBitmap && crossBitmap ) { - m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, *gs_tickBitmap, wxPoint(-1, -1), smallButtonSize ); - m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, *gs_crossBitmap, wxPoint(-1, -1), smallButtonSize ); + m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, *tickBitmap, wxPoint(-1, -1), smallButtonSize ); + m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, *crossBitmap, wxPoint(-1, -1), smallButtonSize ); } else { m_confirmButton = new wxButton(panel, wxID_PROP_CHECK, ":-)", wxPoint(-1, -1), smallButtonSize ); - m_cancelButton = new wxButton(panel, wxID_PROP_CROSS, "X", wxPoint(-1, -1), smallButtonSize ); + m_cancelButton = new wxButton(panel, wxID_PROP_CROSS, "X", wxPoint(-1, -1), smallButtonSize ); } - - topsizer->Add( m_confirmButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); - topsizer->Add( m_cancelButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); + + topsizer->Add( m_confirmButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); + topsizer->Add( m_cancelButton, 0, wxLEFT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); } m_valueText = new wxPropertyTextEdit(this, panel, wxID_PROP_TEXT, "", @@ -465,7 +480,7 @@ bool wxPropertyListView::CreateControls() { m_editButton = new wxButton(panel, wxID_PROP_EDIT, "...", wxPoint(-1, -1), smallButtonSize); m_editButton->Enable(FALSE); - topsizer->Add( m_editButton, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); + topsizer->Add( m_editButton, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, buttonborder ); } mainsizer->Add( topsizer, 0, wxEXPAND ); @@ -487,8 +502,8 @@ bool wxPropertyListView::CreateControls() if ((m_buttonFlags & wxPROP_BUTTON_OK) || (m_buttonFlags & wxPROP_BUTTON_CLOSE) || - (m_buttonFlags & wxPROP_BUTTON_CANCEL) || - (m_buttonFlags & wxPROP_BUTTON_HELP)) + (m_buttonFlags & wxPROP_BUTTON_CANCEL) || + (m_buttonFlags & wxPROP_BUTTON_HELP)) { wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); buttonborder = 5; @@ -498,7 +513,7 @@ bool wxPropertyListView::CreateControls() m_windowCloseButton = new wxButton(panel, wxID_OK, _("OK"), wxPoint(-1, -1), largeButtonSize ); m_windowCloseButton->SetDefault(); m_windowCloseButton->SetFocus(); - bottomsizer->Add( m_windowCloseButton, 0, wxLEFT|wxTOP|wxBOTTOM, buttonborder ); + bottomsizer->Add( m_windowCloseButton, 0, wxALL, buttonborder ); } else if (m_buttonFlags & wxPROP_BUTTON_CLOSE) { @@ -515,8 +530,8 @@ bool wxPropertyListView::CreateControls() m_windowHelpButton = new wxButton(panel, wxID_HELP, _("Help"), wxPoint(-1, -1), largeButtonSize ); bottomsizer->Add( m_windowHelpButton, 0, wxALL, buttonborder ); } - - mainsizer->Add( bottomsizer, 1, wxALIGN_RIGHT | wxEXPAND ); + + mainsizer->Add( bottomsizer, 0, wxALIGN_RIGHT | wxEXPAND ); } panel->SetSizer( mainsizer ); @@ -539,9 +554,9 @@ void wxPropertyListView::ShowListBoxControl(bool show) if (m_buttonFlags & wxPROP_DYNAMIC_VALUE_FIELD) { if (show) - m_middleSizer->Prepend( m_valueList, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 3 ); - else - m_middleSizer->Remove( 0 ); + m_middleSizer->Prepend( m_valueList, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 3 ); + else + m_middleSizer->Remove( 0 ); m_propertyWindow->Layout(); } @@ -559,7 +574,7 @@ void wxPropertyListView::EnableCross(bool show) m_cancelButton->Enable(show); } -bool wxPropertyListView::OnClose(void) +bool wxPropertyListView::OnClose() { // Retrieve the value if any wxCommandEvent event; @@ -658,11 +673,11 @@ void wxPropertyListView::OnText(wxCommandEvent& event) } } -/* - * Property dialog box - */ +// ---------------------------------------------------------------------------- +// Property dialog box +// ---------------------------------------------------------------------------- -IMPLEMENT_CLASS(wxPropertyListDialog, wxDialog) +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListDialog, wxDialog) BEGIN_EVENT_TABLE(wxPropertyListDialog, wxDialog) EVT_BUTTON(wxID_CANCEL, wxPropertyListDialog::OnCancel) @@ -718,11 +733,11 @@ bool wxPropertyListDialog::ProcessEvent(wxEvent& event) return TRUE; } -/* - * Property panel - */ +// ---------------------------------------------------------------------------- +// Property panel +// ---------------------------------------------------------------------------- -IMPLEMENT_CLASS(wxPropertyListPanel, wxPanel) +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListPanel, wxPanel) BEGIN_EVENT_TABLE(wxPropertyListPanel, wxPanel) EVT_SIZE(wxPropertyListPanel::OnSize) @@ -754,11 +769,11 @@ void wxPropertyListPanel::OnSize(wxSizeEvent& WXUNUSED(event)) Layout(); } -/* - * Property frame - */ +// ---------------------------------------------------------------------------- +// Property frame +// ---------------------------------------------------------------------------- -IMPLEMENT_CLASS(wxPropertyListFrame, wxFrame) +IMPLEMENT_DYNAMIC_CLASS(wxPropertyListFrame, wxFrame) BEGIN_EVENT_TABLE(wxPropertyListFrame, wxFrame) EVT_CLOSE(wxPropertyListFrame::OnCloseWindow) @@ -785,7 +800,7 @@ wxPropertyListPanel *wxPropertyListFrame::OnCreatePanel(wxFrame *parent, wxPrope return new wxPropertyListPanel(v, parent); } -bool wxPropertyListFrame::Initialize(void) +bool wxPropertyListFrame::Initialize() { m_propertyPanel = OnCreatePanel(this, m_view); if (m_propertyPanel) @@ -799,9 +814,9 @@ bool wxPropertyListFrame::Initialize(void) return FALSE; } - /* - * Property list specific validator - */ +// ---------------------------------------------------------------------------- +// Property list specific validator +// ---------------------------------------------------------------------------- IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator, wxPropertyValidator) @@ -817,7 +832,7 @@ bool wxPropertyListValidator::OnSelect(bool select, wxProperty *property, wxProp bool wxPropertyListValidator::OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) { wxString s(view->GetValueList()->GetStringSelection()); - if (s != _T("")) + if (s != wxT("")) { view->GetValueText()->SetValue(s); view->RetrieveProperty(property); @@ -863,9 +878,9 @@ bool wxPropertyListValidator::OnClearControls(wxProperty *WXUNUSED(property), wx return TRUE; } -/* - * Default validators - */ +// ---------------------------------------------------------------------------- +// Default validators +// ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator, wxPropertyListValidator) @@ -885,8 +900,8 @@ bool wxRealListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropert if (!StringToFloat(WXSTRINGCAST value, &val)) { wxChar buf[200]; - wxSprintf(buf, _T("Value %s is not a valid real number!"), value.GetData()); - wxMessageBox(buf, _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + wxSprintf(buf, wxT("Value %s is not a valid real number!"), value.GetData()); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); return FALSE; } @@ -948,15 +963,15 @@ bool wxIntegerListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxProp if (!StringToLong(WXSTRINGCAST value, &val)) { wxChar buf[200]; - wxSprintf(buf, _T("Value %s is not a valid integer!"), value.GetData()); - wxMessageBox(buf, _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + wxSprintf(buf, wxT("Value %s is not a valid integer!"), value.GetData()); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); return FALSE; } if (val < m_integerMin || val > m_integerMax) { wxChar buf[200]; - wxSprintf(buf, _T("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax); - wxMessageBox(buf, _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + wxSprintf(buf, wxT("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax); + wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); return FALSE; } return TRUE; @@ -1002,9 +1017,9 @@ bool wxBoolListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropert if (!view->GetValueText()) return FALSE; wxString value(view->GetValueText()->GetValue()); - if (value != _T("True") && value != _T("False")) + if (value != wxT("True") && value != wxT("False")) { - wxMessageBox(_T("Value must be True or False!"), _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); + wxMessageBox(wxT("Value must be True or False!"), wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); return FALSE; } return TRUE; @@ -1023,7 +1038,7 @@ bool wxBoolListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListVi wxString value(view->GetValueText()->GetValue()); bool boolValue = FALSE; - if (value == _T("True")) + if (value == wxT("True")) boolValue = TRUE; else boolValue = FALSE; @@ -1066,8 +1081,8 @@ bool wxBoolListValidator::OnPrepareDetailControls(wxProperty *WXUNUSED(property) view->ShowListBoxControl(TRUE); view->GetValueList()->Enable(TRUE); - view->GetValueList()->Append(_T("True")); - view->GetValueList()->Append(_T("False")); + view->GetValueList()->Append(wxT("True")); + view->GetValueList()->Append(wxT("False")); wxChar *currentString = copystring(view->GetValueText()->GetValue()); view->GetValueList()->SetStringSelection(currentString); delete[] currentString; @@ -1157,7 +1172,7 @@ bool wxStringListValidator::OnDisplayValue(wxProperty *property, wxPropertyListV return FALSE; wxString str(property->GetValue().GetStringRepresentation()); view->GetValueText()->SetValue(str); - if (m_strings && view->GetValueList() && view->GetValueList()->IsShown() && view->GetValueList()->Number() > 0) + if (m_strings && view->GetValueList() && view->GetValueList()->IsShown() && view->GetValueList()->GetCount() > 0) { view->GetValueList()->SetStringSelection(str); } @@ -1271,7 +1286,7 @@ wxFilenameListValidator::wxFilenameListValidator(wxString message , wxString wil { } -wxFilenameListValidator::~wxFilenameListValidator(void) +wxFilenameListValidator::~wxFilenameListValidator() { } @@ -1340,7 +1355,7 @@ void wxFilenameListValidator::OnEdit(wxProperty *property, wxPropertyListView *v m_filenameWildCard.GetData(), 0, parentWindow); - if (s != _T("")) + if (s != wxT("")) { property->GetValue() = s; view->DisplayProperty(property); @@ -1359,7 +1374,7 @@ wxColourListValidator::wxColourListValidator(long flags): { } -wxColourListValidator::~wxColourListValidator(void) +wxColourListValidator::~wxColourListValidator() { } @@ -1533,7 +1548,7 @@ void wxListOfStringsListValidator::OnEdit(wxProperty *property, wxPropertyListVi expr = expr->GetNext(); } - wxString title(_T("Editing ")); + wxString title(wxT("Editing ")); title += property->GetName(); if (EditStringList(parentWindow, stringList, title.GetData())) @@ -1615,7 +1630,7 @@ class wxPropertyStringListEditorText: public wxTextCtrl wxTextCtrl(parent, id, val, pos, size, windowStyle, wxDefaultValidator, name) { } - void OnKillFocus(void) + void OnKillFocus() { wxPropertyStringListEditorDialog *dialog = (wxPropertyStringListEditorDialog *)GetParent(); dialog->SaveCurrentSelection(); @@ -1753,7 +1768,7 @@ void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent& WXUNUSED(event)) { SaveCurrentSelection(); - wxChar *initialText = _T(""); + wxChar *initialText = wxT(""); wxNode *node = m_stringList->Add(initialText); m_listBox->Append(initialText, (void *)node); m_currentSelection = m_stringList->Number() - 1; @@ -1786,13 +1801,15 @@ void wxPropertyStringListEditorDialog::OnText(wxCommandEvent& event) } } -void wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent& event) +void +wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { SaveCurrentSelection(); - this->Destroy(); + + Destroy(); } -void wxPropertyStringListEditorDialog::SaveCurrentSelection(void) +void wxPropertyStringListEditorDialog::SaveCurrentSelection() { if (m_currentSelection == -1) return; @@ -1809,7 +1826,7 @@ void wxPropertyStringListEditorDialog::SaveCurrentSelection(void) m_listBox->SetString(m_currentSelection, (char *)node->Data()); } -void wxPropertyStringListEditorDialog::ShowCurrentSelection(void) +void wxPropertyStringListEditorDialog::ShowCurrentSelection() { if (m_currentSelection == -1) { @@ -1822,47 +1839,47 @@ void wxPropertyStringListEditorDialog::ShowCurrentSelection(void) m_stringText->Enable(TRUE); } -//----------------------------------------------------------------------------- -// wxPropertyModule -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// global functions +// ---------------------------------------------------------------------------- -class wxPropertyModule: public wxModule +// FIXME MT-UNSAFE +static wxBitmap *GetTickBitmap() { - DECLARE_DYNAMIC_CLASS(wxPropertyModule) - -public: - wxPropertyModule() {} - bool OnInit(); - void OnExit(); -}; - -IMPLEMENT_DYNAMIC_CLASS(wxPropertyModule,wxModule) + static wxBitmap* s_tickBitmap = (wxBitmap *) NULL; + static bool s_loaded = FALSE; -bool wxPropertyModule::OnInit() -{ -#if defined(__WXMSW__) || defined(__WXOS2__) - gs_tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE); - gs_crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE); -#else - gs_tickBitmap = new wxBitmap( tick_xpm ); - gs_crossBitmap = new wxBitmap( cross_xpm ); -#endif - if (!gs_tickBitmap || !gs_crossBitmap || !gs_tickBitmap->Ok() || !gs_crossBitmap->Ok()) + if ( !s_loaded ) { - if (gs_tickBitmap) delete gs_tickBitmap; - if (gs_crossBitmap) delete gs_crossBitmap; - gs_tickBitmap = (wxBitmap*) NULL; - gs_crossBitmap = (wxBitmap*) NULL; + s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + + #if defined(__WXMSW__) || defined(__WXPM__) + s_tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE); + #else + s_tickBitmap = new wxBitmap( tick_xpm ); + #endif } - return TRUE; + return s_tickBitmap; } -void wxPropertyModule::OnExit() +static wxBitmap *GetCrossBitmap() { - if (gs_tickBitmap) - delete gs_tickBitmap; - if (gs_crossBitmap) - delete gs_crossBitmap; + static wxBitmap* s_crossBitmap = (wxBitmap *) NULL; + static bool s_loaded = FALSE; + + if ( !s_loaded ) + { + s_loaded = TRUE; // set it to TRUE anyhow, we won't try again + + #if defined(__WXMSW__) || defined(__WXPM__) + s_crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE); + #else // XPMs + s_crossBitmap = new wxBitmap( cross_xpm ); + #endif // BMPs/XPMs + } + + return s_crossBitmap; } +#endif // wxUSE_PROPSHEET