X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/15d5ab675769cc0cbbeb634f18fca9b5f304eaeb..8a693e6e0460b6b3c32e4b6f114a3ab7b7cd24ea:/utils/dialoged/src/winprop.cpp?ds=inline diff --git a/utils/dialoged/src/winprop.cpp b/utils/dialoged/src/winprop.cpp index 5985d0adc7..dde79ec61c 100644 --- a/utils/dialoged/src/winprop.cpp +++ b/utils/dialoged/src/winprop.cpp @@ -29,16 +29,6 @@ #include #include -#if wxUSE_IOSTREAMH -#if defined(__WXMSW__) && !defined(__GNUWIN32__) -#include -#else -#include -#endif -#else -#include -#endif - #ifdef __WXMSW__ #include #endif @@ -110,7 +100,8 @@ wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame() { delete m_propSheet; delete m_propInfo; - wxPropertyInfo::sm_propertyWindow = NULL; + if (wxPropertyInfo::sm_propertyWindow == this) + wxPropertyInfo::sm_propertyWindow = NULL; } /* @@ -121,11 +112,20 @@ wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame() // might be. bool wxPropertyInfo::Edit(wxWindow *WXUNUSED(parent), const wxString& title) { - if (sm_propertyWindow) - { + if (sm_propertyWindow) + { + wxWindowPropertyInfo* thisProp = (wxWindowPropertyInfo*) this; + wxWindowPropertyInfo* oldProp = (wxWindowPropertyInfo*) (((wxDialogEditorPropertyListFrame *) sm_propertyWindow)->GetInfo()); + if (oldProp->GetWindow() == thisProp->GetWindow()) + { sm_propertyWindow->Raise(); return TRUE; - } + } + else + { + CloseWindow(); // Close the window so we can open a new one + } + } int width = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width; int height = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height; @@ -153,7 +153,7 @@ bool wxPropertyInfo::Edit(wxWindow *WXUNUSED(parent), const wxString& title) propSheet->SetAllModified(FALSE); wxResourcePropertyListView *view = new wxResourcePropertyListView(this, NULL, - wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | + wxPROP_BUTTON_OK | // wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES); wxDialogEditorPropertyListFrame *propWin = new wxDialogEditorPropertyListFrame(view, @@ -189,6 +189,24 @@ bool wxPropertyInfo::Edit(wxWindow *WXUNUSED(parent), const wxString& title) return TRUE; } +void wxPropertyInfo::CloseWindow() +{ + if (sm_propertyWindow) + { + int w, h, x, y; + sm_propertyWindow->GetSize(& w, & h); + sm_propertyWindow->GetPosition(& x, & y); + + wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width = w; + wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height = h; + wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x = x; + wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y = y; + + sm_propertyWindow->Destroy(); + sm_propertyWindow = (wxDialogEditorPropertyListFrame *) NULL; + } +} + /* * wxWindowPropertyInfo */ @@ -365,7 +383,15 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) { wxFont *newFont = SetFontProperty(name, property, font); if (newFont) + { m_propertyWindow->SetFont(* newFont); + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource) + { + resource->SetFont(* newFont); + } + } + return TRUE; } else if (name == "name") @@ -675,7 +701,9 @@ bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource) wxString str(m_propertyWindow->GetName()); resource->SetName(str); -#if 0 +#if 0 // Why did we comment this out? Possibly because of rounding errors + // that will build up as the conversion is repeatedly done. + // so only do the conversion when a resize happens. int x, y, w, h; if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) @@ -758,6 +786,7 @@ wxProperty *wxItemPropertyInfo::GetProperty(wxString& name) bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property) { wxControl *itemWindow = (wxControl *)m_propertyWindow; +#if 0 wxFont *font = & itemWindow->GetFont(); if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" )) @@ -767,7 +796,9 @@ bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property) itemWindow->SetFont(* newFont); return TRUE; } - else if (name == "label") + else +#endif + if (name == "label") { itemWindow->SetLabel(property->GetValue().StringValue()); return TRUE; @@ -857,12 +888,11 @@ bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *propert char *s = property->GetValue().StringValue(); if (s && wxFileExists(s)) { - s = copystring(s); - wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP); + wxString str(s); + wxBitmap *bitmap = new wxBitmap(str, wxBITMAP_TYPE_BMP); if (!bitmap->Ok()) { delete bitmap; - delete[] s; return FALSE; } else @@ -871,7 +901,7 @@ bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *propert if (resource) { wxString oldResource(resource->GetValue4()); - wxString resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s); + wxString resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(str); resource->SetValue4(resName); if (!oldResource.IsNull()) @@ -879,7 +909,6 @@ bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *propert } button->SetLabel(* bitmap); - delete[] s; return TRUE; } } @@ -912,7 +941,37 @@ wxProperty *wxStaticTextPropertyInfo::GetProperty(wxString& name) bool wxStaticTextPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - return wxItemPropertyInfo::SetProperty(name, property); + wxStaticText* itemWindow = (wxStaticText*) m_propertyWindow; + if (name == "label") + { + // Because setting a wxStaticText control's label may change the + // size, we must get the size and instantiate the resource immediately. + itemWindow->SetLabel(property->GetValue().StringValue()); + int w, h; + + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(itemWindow); + + m_propertyWindow->GetSize(&w, &h); + // m_propertyWindow->GetPosition(&x, &y); + + // We need to convert to dialog units if + // the parent resource specifies dialog units. + if (m_propertyWindow->GetParent()) + { + wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow->GetParent()); + if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + // wxPoint pt = m_propertyWindow->GetParent()->ConvertPixelsToDialog(wxPoint(x, y)); + // x = pt.x; y = pt.y; + wxSize sz = m_propertyWindow->GetParent()->ConvertPixelsToDialog(wxSize(w, h)); + w = sz.x; h = sz.y; + } + } + resource->SetSize(resource->GetX(), resource->GetY(), w, h); + return TRUE; + } + else + return wxItemPropertyInfo::SetProperty(name, property); } void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList& names) @@ -956,13 +1015,12 @@ bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *propert char *s = property->GetValue().StringValue(); if (s && wxFileExists(s)) { - s = copystring(s); + wxString str(s); - wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP); + wxBitmap *bitmap = new wxBitmap(str, wxBITMAP_TYPE_BMP); if (!bitmap->Ok()) { delete bitmap; - delete[] s; return FALSE; } else @@ -971,7 +1029,7 @@ bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *propert if (resource) { wxString oldResource(resource->GetValue4()); - wxString resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s); + wxString resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(str); resource->SetValue4(resName); if (!oldResource.IsNull()) @@ -979,7 +1037,6 @@ bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *propert } message->SetBitmap(* bitmap); - delete[] s; return TRUE; } } @@ -1047,7 +1104,7 @@ bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text); resource->SetStyle(flag); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this); return TRUE; } else if (name == "readonly") @@ -1066,7 +1123,7 @@ bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text); resource->SetStyle(flag); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this); return TRUE; } else @@ -1162,7 +1219,7 @@ bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox); if (resource) resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox, this); return TRUE; } else @@ -1326,7 +1383,7 @@ bool wxComboBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow, this); return TRUE; } else if (name == "style") @@ -1347,7 +1404,7 @@ bool wxComboBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow, this); return TRUE; } @@ -1421,8 +1478,10 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxRadioBox *radioBox = (wxRadioBox *)m_propertyWindow; if (name == "numberRowsOrCols") { + wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(radioBox); + radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue()); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); return TRUE; } else if (name == "orientation") @@ -1441,11 +1500,14 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) windowStyle -= wxRA_SPECIFY_COLS; windowStyle |= wxRA_SPECIFY_ROWS; } + wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(radioBox); + radioBox->SetWindowStyleFlag(windowStyle); wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(radioBox); resource->SetStyle(windowStyle); + resource->SetSize(resource->GetX(), resource->GetY(), -1, -1); // Let it calculate it's own size - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this, FALSE); return TRUE; } else if (name == "values") @@ -1467,9 +1529,32 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) expr = expr->GetNext(); } resource->SetStringValues(stringList); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); + resource->SetSize(resource->GetX(), resource->GetY(), -1, -1); // Let it calculate it's own size + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this, FALSE); return TRUE; } + else if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ) + { + wxFont *font = & m_propertyWindow->GetFont(); + if (!font) + return FALSE; + wxFont *newFont = SetFontProperty(name, property, font); + if (newFont) + { + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource) + { + resource->SetFont(* newFont); + } + + wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(radioBox); + + radioBox->SetFont(* newFont); + radioBox->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); + return TRUE; + } + } + return wxItemPropertyInfo::SetProperty(name, property); } @@ -1673,6 +1758,7 @@ bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property) slider = (wxSlider *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider, this); slider->SetSize(-1, -1, h, w); + m_propertyWindow = slider; return TRUE; } @@ -1829,12 +1915,17 @@ bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property) scrollBar->SetWindowStyleFlag(windowStyle); // If the window style has changed, we swap the width and height parameters. - int w, h; - scrollBar->GetSize(&w, &h); - +// int w, h; +// scrollBar->GetSize(&w, &h); + wxItemResource *item = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(scrollBar); + if ( item ) { + item->SetSize(item->GetX(), item->GetY(), item->GetHeight(), item->GetWidth()); + item->SetStyle(windowStyle); + } /* IF */ + scrollBar = (wxScrollBar *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar, this); - scrollBar->SetSize(-1, -1, h, w); - + m_propertyWindow = scrollBar; + return TRUE; } else if (name == "pageSize") @@ -2031,6 +2122,7 @@ bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxColour col(r,g,b); panelWindow->SetBackgroundColour(col); panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this); + m_propertyWindow = panelWindow; return TRUE; } else if (name == "title") @@ -2110,6 +2202,7 @@ bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property) } resource->SetResourceStyle(style); panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this); + m_propertyWindow = panelWindow; // TODO: need to regenerate the width and height properties else they'll be inconsistent. return TRUE; } @@ -2357,7 +2450,6 @@ void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView { wxString symbolName(dialog->GetSymbol()); long id = dialog->GetId(); - dialog->Destroy(); wxString str; str.Printf("%d", id); @@ -2367,6 +2459,8 @@ void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView view->UpdatePropertyDisplayInList(property); view->OnPropertyChanged(property); } + // Moved from the 'if' branch on suggestion of Roman Pavlov + dialog->Destroy(); } BEGIN_EVENT_TABLE(wxResourceSymbolDialog, wxDialog)