X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7978fe62dd38661c6af0b0b320fc49d786d98787..1b7274a8c071f0bbe4a19168e9b9b4981c06a8af:/utils/dialoged/src/winprop.cpp diff --git a/utils/dialoged/src/winprop.cpp b/utils/dialoged/src/winprop.cpp index 44923283bb..1d9318bc95 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,31 @@ 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 + { + 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; + + // Close the window, so we can create a new one for the different window + sm_propertyWindow->Destroy(); + sm_propertyWindow = (wxDialogEditorPropertyListFrame *) NULL; + } + } int width = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width; int height = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height; @@ -179,6 +190,13 @@ bool wxPropertyInfo::Edit(wxWindow *WXUNUSED(parent), const wxString& title) view->ShowView(propSheet, propWin->GetPropertyPanel()); propWin->Show(TRUE); + + // Otherwise doesn't show itself +#ifdef __WXMOTIF__ + wxNoOptimize noOptimize; + propWin->SetSize(-1, -1, width, height); +#endif + return TRUE; } @@ -416,7 +434,7 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) } } - if (x != newX) + if (x != pixelX) { m_propertyWindow->Move(pixelX, y); resource->SetSize(newX, resource->GetY(), resource->GetWidth(), resource->GetHeight()); @@ -452,7 +470,7 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) } } - if (y != newY) + if (y != pixelY) { m_propertyWindow->Move(x, pixelY); resource->SetSize(resource->GetX(), newY, resource->GetWidth(), resource->GetHeight()); @@ -488,7 +506,7 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) } } - if (width != newWidth) + if (width != pixelWidth) { m_propertyWindow->SetSize(pixelWidth, height); resource->SetSize(resource->GetX(), resource->GetY(), newWidth, resource->GetHeight()); @@ -524,9 +542,9 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) } } - if (height != newHeight) + if (height != pixelHeight) { - m_propertyWindow->SetSize(width, newHeight); + m_propertyWindow->SetSize(width, pixelHeight); resource->SetSize(resource->GetX(), resource->GetY(), resource->GetWidth(), newHeight); } return TRUE; @@ -668,7 +686,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))) @@ -757,7 +777,7 @@ bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property) { wxFont *newFont = SetFontProperty(name, property, font); if (newFont) - itemWindow->SetLabelFont(* newFont); + itemWindow->SetFont(* newFont); return TRUE; } else if (name == "label") @@ -787,6 +807,7 @@ bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource) wxControl *item = (wxControl *)m_propertyWindow; wxString str(item->GetLabel()); resource->SetTitle(str); + if (item->GetFont().Ok()) resource->SetFont(* wxTheFontList->FindOrCreateFont(item->GetFont().GetPointSize(), item->GetFont().GetFamily(), item->GetFont().GetStyle(), item->GetFont().GetWeight(), @@ -849,12 +870,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 @@ -863,7 +883,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()) @@ -871,7 +891,6 @@ bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *propert } button->SetLabel(* bitmap); - delete[] s; return TRUE; } } @@ -904,7 +923,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) @@ -948,13 +997,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 @@ -963,7 +1011,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()) @@ -971,7 +1019,6 @@ bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *propert } message->SetBitmap(* bitmap); - delete[] s; return TRUE; } } @@ -1039,7 +1086,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") @@ -1058,7 +1105,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 @@ -1154,7 +1201,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 @@ -1318,7 +1365,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") @@ -1339,7 +1386,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; } @@ -1414,7 +1461,7 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) if (name == "numberRowsOrCols") { radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue()); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); return TRUE; } else if (name == "orientation") @@ -1437,7 +1484,7 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(radioBox); resource->SetStyle(windowStyle); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); return TRUE; } else if (name == "values") @@ -1459,7 +1506,7 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) expr = expr->GetNext(); } resource->SetStringValues(stringList); - wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); + m_propertyWindow = wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); return TRUE; } return wxItemPropertyInfo::SetProperty(name, property); @@ -1665,6 +1712,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; } @@ -1754,8 +1802,8 @@ bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name) { wxScrollBar *scrollBar = (wxScrollBar *)m_propertyWindow; - if (name == "value") - return new wxProperty("value", (long)scrollBar->GetValue(), "integer"); + if (name == "thumbPosition") + return new wxProperty("value", (long)scrollBar->GetThumbPosition(), "integer"); else if (name == "orientation") { char *pos = NULL; @@ -1770,24 +1818,20 @@ wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name) } else if (name == "pageSize") { - int viewStart, pageLength, objectLength, viewLength; - scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength); + int pageLength = scrollBar->GetPageSize(); return new wxProperty("pageSize", (long)pageLength, "integer"); } - else if (name == "viewLength") + else if (name == "thumbSize") { - int viewStart, pageLength, objectLength, viewLength; - scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength); + int thumbSize = scrollBar->GetThumbSize(); - return new wxProperty("viewLength", (long)viewLength, "integer"); + return new wxProperty("thumbSize", (long)thumbSize, "integer"); } - else if (name == "objectLength") + else if (name == "range") { - int viewStart, pageLength, objectLength, viewLength; - scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength); - - return new wxProperty("objectLength", (long)objectLength, "integer"); + int range = scrollBar->GetRange(); + return new wxProperty("range", (long)range, "integer"); } else return wxItemPropertyInfo::GetProperty(name); @@ -1796,9 +1840,9 @@ wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name) bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property) { wxScrollBar *scrollBar = (wxScrollBar *)m_propertyWindow; - if (name == "value") + if (name == "thumbPosition") { - scrollBar->SetValue((int)property->GetValue().IntegerValue()); + scrollBar->SetThumbPosition((int)property->GetValue().IntegerValue()); return TRUE; } else if (name == "orientation") @@ -1825,27 +1869,41 @@ 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") { - scrollBar->SetPageSize((int)property->GetValue().IntegerValue()); + int pos = scrollBar->GetThumbPosition(); + int range = scrollBar->GetRange(); + int thumbSize = scrollBar->GetThumbSize(); + scrollBar->SetScrollbar(pos, thumbSize, range, (int)property->GetValue().IntegerValue()); return TRUE; } - else if (name == "viewLength") + else if (name == "thumbSize") { - scrollBar->SetViewLength((int)property->GetValue().IntegerValue()); + int pos = scrollBar->GetThumbPosition(); + int range = scrollBar->GetRange(); + int pageSize = scrollBar->GetPageSize(); + scrollBar->SetScrollbar(pos, (int)property->GetValue().IntegerValue(), range, pageSize); return TRUE; } - else if (name == "objectLength") + else if (name == "range") { - scrollBar->SetObjectLength((int)property->GetValue().IntegerValue()); + int pos = scrollBar->GetThumbPosition(); + int thumbSize = scrollBar->GetThumbSize(); + int pageSize = scrollBar->GetPageSize(); + scrollBar->SetScrollbar(pos, thumbSize, (int)property->GetValue().IntegerValue(), pageSize); return TRUE; } else @@ -1856,10 +1914,10 @@ void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names) { wxItemPropertyInfo::GetPropertyNames(names); names.Add("orientation"); - names.Add("value"); + names.Add("thumbPosition"); + names.Add("thumbSize"); names.Add("pageSize"); - names.Add("viewLength"); - names.Add("objectLength"); + names.Add("range"); // Remove some properties we don't inherit names.Delete("fontPoints"); @@ -1873,14 +1931,15 @@ bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource) { wxScrollBar *sbar = (wxScrollBar *)m_propertyWindow; - resource->SetValue1(sbar->GetValue()); - - int viewStart, pageLength, objectLength, viewLength; - sbar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength); + int thumbPosition = sbar->GetThumbPosition(); + int thumbSize = sbar->GetThumbSize(); + int pageSize = sbar->GetPageSize(); + int range = sbar->GetRange(); - resource->SetValue2(pageLength); - resource->SetValue3(objectLength); - resource->SetValue5(viewLength); + resource->SetValue1(thumbPosition); + resource->SetValue2(thumbSize); + resource->SetValue3(range); + resource->SetValue5(pageSize); return wxItemPropertyInfo::InstantiateResource(resource); } @@ -2017,6 +2076,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") @@ -2096,6 +2156,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; } @@ -2343,7 +2404,6 @@ void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView { wxString symbolName(dialog->GetSymbol()); long id = dialog->GetId(); - dialog->Destroy(); wxString str; str.Printf("%d", id); @@ -2353,6 +2413,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)