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

📄 proplist.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        contrib/src/deprecated/proplist.cpp// Purpose:     Property list classes// Author:      Julian Smart// Modified by:// Created:     04/01/98// RCS-ID:      $Id: proplist.cpp,v 1.14 2006/03/28 11:02:19 ABX Exp $// Copyright:   (c) Julian Smart// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------// For compilers that support precompilation, includes "wx/wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__    #pragma hdrstop#endif#include "wx/deprecated/setup.h"#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"#endif#include "wx/sizer.h"#include "wx/module.h"#include "wx/intl.h"#include "wx/artprov.h"#include "wx/colordlg.h"#include "wx/deprecated/proplist.h"#include <ctype.h>#include <stdlib.h>#include <math.h>#include <string.h>#if !WXWIN_COMPATIBILITY_2_4static inline wxChar* copystring(const wxChar* s)    { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }#endif// ----------------------------------------------------------------------------// Property text edit control// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxPropertyTextEdit, wxTextCtrl)wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent,    const wxWindowID id, const wxString& value,    const wxPoint& pos, const wxSize& size,    long style, const wxString& name): wxTextCtrl(parent, id, value, pos, size, style, wxDefaultValidator, name){  m_view = v;}void wxPropertyTextEdit::OnSetFocus(){}void wxPropertyTextEdit::OnKillFocus(){}// ----------------------------------------------------------------------------// Property list view// ----------------------------------------------------------------------------bool wxPropertyListView::sm_dialogCancelled = false;IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView, wxPropertyView)BEGIN_EVENT_TABLE(wxPropertyListView, wxPropertyView)    EVT_BUTTON(wxID_OK,                 wxPropertyListView::OnOk)    EVT_BUTTON(wxID_CANCEL,             wxPropertyListView::OnCancel)    EVT_BUTTON(wxID_HELP,               wxPropertyListView::OnHelp)    EVT_BUTTON(wxID_PROP_CROSS,         wxPropertyListView::OnCross)    EVT_BUTTON(wxID_PROP_CHECK,         wxPropertyListView::OnCheck)    EVT_BUTTON(wxID_PROP_EDIT,          wxPropertyListView::OnEdit)    EVT_TEXT_ENTER(wxID_PROP_TEXT,      wxPropertyListView::OnText)    EVT_LISTBOX(wxID_PROP_SELECT,       wxPropertyListView::OnPropertySelect)    EVT_COMMAND(wxID_PROP_SELECT, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,                                        wxPropertyListView::OnPropertyDoubleClick)    EVT_LISTBOX(wxID_PROP_VALUE_SELECT, wxPropertyListView::OnValueListSelect)END_EVENT_TABLE()wxPropertyListView::wxPropertyListView(wxPanel *propPanel, long flags):wxPropertyView(flags){  m_propertyScrollingList = NULL;  m_valueList = NULL;  m_valueText = NULL;  m_editButton = NULL;  m_confirmButton = NULL;  m_cancelButton = NULL;  m_propertyWindow = propPanel;  m_managedWindow = NULL;  m_windowCloseButton = NULL;  m_windowCancelButton = NULL;  m_windowHelpButton = NULL;  m_detailedEditing = false;}wxPropertyListView::~wxPropertyListView(){}void wxPropertyListView::ShowView(wxPropertySheet *ps, wxPanel *panel){  m_propertySheet = ps;  AssociatePanel(panel);  CreateControls();  UpdatePropertyList();  panel->Layout();}// Update this view of the viewed object, called e.g. by// the object itself.bool wxPropertyListView::OnUpdateView(){  return true;}bool wxPropertyListView::UpdatePropertyList(bool clearEditArea){  if (!m_propertyScrollingList || !m_propertySheet)    return false;  m_propertyScrollingList->Clear();  if (clearEditArea)  {    m_valueList->Clear();    m_valueText->SetValue(wxEmptyString);  }  wxNode *node = m_propertySheet->GetProperties().GetFirst();  // Should sort them... later...  while (node)  {    wxProperty *property = (wxProperty *)node->GetData();    wxString stringValueRepr(property->GetValue().GetStringRepresentation());    wxString paddedString(MakeNameValueString(property->GetName(), stringValueRepr));    m_propertyScrollingList->Append(paddedString.GetData(), (void *)property);    node = node->GetNext();  }  return true;}bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty *property){  if (!m_propertyScrollingList || !m_propertySheet)    return false;#ifdef __WXMSW__  int currentlySelected = m_propertyScrollingList->GetSelection();#endif// #ifdef __WXMSW__  wxString stringValueRepr(property->GetValue().GetStringRepresentation());  wxString paddedString(MakeNameValueString(property->GetName(), stringValueRepr));  int sel = FindListIndexForProperty(property);  if (sel > -1)  {    // Don't update the listbox unnecessarily because it can cause    // ugly flashing.    if (paddedString != m_propertyScrollingList->GetString(sel))      m_propertyScrollingList->SetString(sel, paddedString.GetData());  }//#else//  UpdatePropertyList(false);//#endif  // TODO: why is this necessary?#ifdef __WXMSW__  if (currentlySelected > -1)    m_propertyScrollingList->SetSelection(currentlySelected);#endif  return true;}// Find the wxListBox index corresponding to this propertyint wxPropertyListView::FindListIndexForProperty(wxProperty *property){  int n = m_propertyScrollingList->GetCount();  for (int i = 0; i < n; i++)  {    if (property == (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(i))      return i;  }  return wxNOT_FOUND;}wxString wxPropertyListView::MakeNameValueString(wxString name, wxString value){  wxString theString(name);  int nameWidth = 25;  int padWith = nameWidth - theString.length();  if (padWith < 0)    padWith = 0;  if (GetFlags() & wxPROP_SHOWVALUES)  {    // Want to pad with spaces    theString.Append( wxT(' '), padWith);    theString += value;  }  return theString;}// Select and show string representation in validator the given// property. NULL resets to show no property.bool wxPropertyListView::ShowProperty(wxProperty *property, bool select){  if (m_currentProperty)  {    EndShowingProperty(m_currentProperty);    m_currentProperty = NULL;  }  m_valueList->Clear();  m_valueText->SetValue(wxEmptyString);  if (property)  {    m_currentProperty = property;    BeginShowingProperty(property);  }  if (select)  {    int sel = FindListIndexForProperty(property);    if (sel != wxNOT_FOUND)      m_propertyScrollingList->SetSelection(sel);  }  return true;}// Find appropriate validator and load property into value controlsbool wxPropertyListView::BeginShowingProperty(wxProperty *property){  m_currentValidator = FindPropertyValidator(property);  if (!m_currentValidator)    return false;  if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))    return false;  wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;  listValidator->OnPrepareControls(property, this, m_propertyWindow);  DisplayProperty(property);  return true;}// Find appropriate validator and unload property from value controlsbool wxPropertyListView::EndShowingProperty(wxProperty *property){  if (!m_currentValidator)    return false;  RetrieveProperty(property);  if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))    return false;  wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;  listValidator->OnClearControls(property, this, m_propertyWindow);  if (m_detailedEditing)  {    listValidator->OnClearDetailControls(property, this, m_propertyWindow);    m_detailedEditing = false;  }  return true;}void wxPropertyListView::BeginDetailedEditing(){  if (!m_currentValidator)    return;  if (!m_currentProperty)    return;  if (m_detailedEditing)    return;  if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))    return;  if (!m_currentProperty->IsEnabled())    return;  wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;  if (listValidator->OnPrepareDetailControls(m_currentProperty, this, m_propertyWindow))    m_detailedEditing = true;}void wxPropertyListView::EndDetailedEditing(){  if (!m_currentValidator)    return;  if (!m_currentProperty)    return;  RetrieveProperty(m_currentProperty);  if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))    return;  wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;  if (m_detailedEditing)  {    listValidator->OnClearDetailControls(m_currentProperty, this, m_propertyWindow);    m_detailedEditing = false;  }}bool wxPropertyListView::DisplayProperty(wxProperty *property){  if (!m_currentValidator)    return false;  if (((m_currentValidator->GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == 0) || !property->IsEnabled())    m_valueText->SetEditable(false);  else    m_valueText->SetEditable(true);  if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))    return false;  wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;  listValidator->OnDisplayValue(property, this, m_propertyWindow);  return true;}bool wxPropertyListView::RetrieveProperty(wxProperty *property){  if (!m_currentValidator)    return false;  if (!property->IsEnabled())    return false;  if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))    return false;  wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;  if (listValidator->OnCheckValue(property, this, m_propertyWindow))  {    if (listValidator->OnRetrieveValue(property, this, m_propertyWindow))    {      UpdatePropertyDisplayInList(property);      OnPropertyChanged(property);    }  }  else  {    // Revert to old value    listValidator->OnDisplayValue(property, this, m_propertyWindow);  }  return true;}bool wxPropertyListView::EditProperty(wxProperty *WXUNUSED(property)){  return true;}// Called by the listbox callbackvoid wxPropertyListView::OnPropertySelect(wxCommandEvent& WXUNUSED(event)){  int sel = m_propertyScrollingList->GetSelection();  if (sel != wxNOT_FOUND)  {    wxProperty *newSel = (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(sel);    if (newSel && newSel != m_currentProperty)    {      ShowProperty(newSel, false);    }  }}bool wxPropertyListView::CreateControls(){    wxPanel *panel = (wxPanel *)m_propertyWindow;    wxSize largeButtonSize( 70, 25 );    wxSize smallButtonSize( 23, 23 );    if (m_valueText)        return true;    if (!panel)        return false;    wxFont guiFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);#ifdef __WXMSW__    wxFont *boringFont =        wxTheFontList->FindOrCreateFont(guiFont.GetPointSize(), wxMODERN,                                        wxNORMAL, wxNORMAL, false, _T("Courier New"));#else    wxFont *boringFont = wxTheFontList->FindOrCreateFont(guiFont.GetPointSize(), wxTELETYPE, wxNORMAL, wxNORMAL);#endif    // May need to be changed in future to eliminate clashes with app.    // WHAT WAS THIS FOR?//  panel->SetClientData((char *)this);    wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );    // top row with optional buttons and input line    wxBoxSizer *topsizer = new wxBoxSizer( wxHORIZONTAL );    int buttonborder = 3;    if (m_buttonFlags & wxPROP_BUTTON_CHECK_CROSS)    {        wxBitmap tickBitmap = wxArtProvider::GetBitmap(wxART_TICK_MARK);        wxBitmap crossBitmap = wxArtProvider::GetBitmap(wxART_CROSS_MARK);        if ( tickBitmap.Ok() && crossBitmap.Ok() )        {            m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap, wxDefaultPosition, smallButtonSize );            m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap, wxDefaultPosition, smallButtonSize );        }        else        {            m_confirmButton = new wxButton(panel, wxID_PROP_CHECK, _T(":-)"), wxDefaultPosition, smallButtonSize );

⌨️ 快捷键说明

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