X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03f68f123bc79f23ff77821cfe80bfa76b0e68c4..d47631c8f54fdd78c51de318d4128461a841cf57:/utils/dialoged/src/winprop.cpp diff --git a/utils/dialoged/src/winprop.cpp b/utils/dialoged/src/winprop.cpp index 602c87a763..7eabff4260 100644 --- a/utils/dialoged/src/winprop.cpp +++ b/utils/dialoged/src/winprop.cpp @@ -49,8 +49,9 @@ void wxResourcePropertyListView::OnPropertyChanged(wxProperty *property) // IF the property value was modified. if (property->GetValue().GetModified()) { - propertyInfo->SetProperty(property->GetName(), property); + m_propertyInfo->SetProperty(property->GetName(), property); property->GetValue().SetModified(FALSE); + wxResourceManager::GetCurrentResourceManager()->Modify(TRUE); } } @@ -74,6 +75,7 @@ wxWindow *wxPropertyInfo::sm_propertyWindow; * wxDialogEditorPropertyListDialog */ + /* wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name): @@ -89,6 +91,23 @@ wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog() delete m_propInfo; wxPropertyInfo::sm_propertyWindow = NULL; } +*/ + +wxDialogEditorPropertyListFrame::wxDialogEditorPropertyListFrame(wxPropertyListView *v, wxFrame *parent, const wxString& title, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name): + wxPropertyListFrame(v, parent, title, pos, size, style, name) +{ + m_propSheet = NULL; + m_propInfo = NULL; +} + +wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame() +{ + delete m_propSheet; + delete m_propInfo; + wxPropertyInfo::sm_propertyWindow = NULL; +} /* * wxPropertyInfo @@ -96,10 +115,13 @@ wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog() // Edit the information represented by this object, whatever that // might be. -bool wxPropertyInfo::Edit(wxWindow *parent, const wxString& title) +bool wxPropertyInfo::Edit(wxWindow *WXUNUSED(parent), const wxString& title) { if (sm_propertyWindow) - return FALSE; + { + sm_propertyWindow->Raise(); + return TRUE; + } int width = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width; int height = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height; @@ -127,32 +149,32 @@ bool wxPropertyInfo::Edit(wxWindow *parent, const wxString& title) propSheet->SetAllModified(FALSE); wxResourcePropertyListView *view = new wxResourcePropertyListView(this, NULL, -#ifdef __XVIEW__ wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | -#endif wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES); - wxDialogEditorPropertyListDialog *propDialog = new wxDialogEditorPropertyListDialog(view, + wxDialogEditorPropertyListFrame *propWin = new wxDialogEditorPropertyListFrame(view, wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title, wxPoint(x, y), - wxSize(width, height), wxDEFAULT_DIALOG_STYLE); - sm_propertyWindow = propDialog; + wxSize(width, height), wxDEFAULT_FRAME_STYLE); + sm_propertyWindow = propWin; + + propWin->m_registry.RegisterValidator(wxString("real"), new wxRealListValidator); + propWin->m_registry.RegisterValidator(wxString("string"), new wxStringListValidator); + propWin->m_registry.RegisterValidator(wxString("integer"), new wxIntegerListValidator); + propWin->m_registry.RegisterValidator(wxString("bool"), new wxBoolListValidator); + propWin->m_registry.RegisterValidator(wxString("filename"), new wxFilenameListValidator); + propWin->m_registry.RegisterValidator(wxString("stringlist"), new wxListOfStringsListValidator); + propWin->m_registry.RegisterValidator(wxString("window_id"), new wxResourceSymbolValidator); - propDialog->m_registry.RegisterValidator((wxString)"real", new wxRealListValidator); - propDialog->m_registry.RegisterValidator((wxString)"string", new wxStringListValidator); - propDialog->m_registry.RegisterValidator((wxString)"integer", new wxIntegerListValidator); - propDialog->m_registry.RegisterValidator((wxString)"bool", new wxBoolListValidator); - propDialog->m_registry.RegisterValidator((wxString)"filename", new wxFilenameListValidator); - propDialog->m_registry.RegisterValidator((wxString)"stringlist", new wxListOfStringsListValidator); - propDialog->m_registry.RegisterValidator((wxString)"window_id", new wxResourceSymbolValidator); + propWin->m_propInfo = this; + propWin->m_propSheet = propSheet; - propDialog->m_propInfo = this; - propDialog->m_propSheet = propSheet; +// view->m_propertyWindow = propWin; + view->AddRegistry(&(propWin->m_registry)); -// view->propertyWindow = propDialog; - view->AddRegistry(&(propDialog->m_registry)); - view->ShowView(propSheet, propDialog); + propWin->Initialize(); + view->ShowView(propSheet, propWin->GetPropertyPanel()); - propDialog->Show(TRUE); + propWin->Show(TRUE); return TRUE; } @@ -162,8 +184,8 @@ bool wxPropertyInfo::Edit(wxWindow *parent, const wxString& title) wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow *win, wxItemResource *res) { - propertyWindow = win; - propertyResource = res; + m_propertyWindow = win; + m_propertyResource = res; } wxWindowPropertyInfo::~wxWindowPropertyInfo(void) @@ -258,42 +280,68 @@ wxFont *wxWindowPropertyInfo::SetFontProperty(wxString& name, wxProperty *proper wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name) { - wxFont *font = propertyWindow->GetFont(); + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + + wxFont *font = m_propertyWindow->GetFont(); if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined") return GetFontProperty(name, font); else if (name == "name") - return new wxProperty("name", propertyWindow->GetName(), "string"); + return new wxProperty("name", m_propertyWindow->GetName(), "string"); else if (name == "title") - return new wxProperty("title", propertyWindow->GetTitle(), "string"); + return new wxProperty("title", m_propertyWindow->GetTitle(), "string"); else if (name == "x") { - int x, y; - propertyWindow->GetPosition(&x, &y); - return new wxProperty("x", (long)x, "integer"); + return new wxProperty("x", (long)resource->GetX(), "integer"); } else if (name == "y") { - int x, y; - propertyWindow->GetPosition(&x, &y); - return new wxProperty("y", (long)y, "integer"); + return new wxProperty("y", (long)resource->GetY(), "integer"); } else if (name == "width") { - int width, height; - propertyWindow->GetSize(&width, &height); - return new wxProperty("width", (long)width, "integer"); + return new wxProperty("width", (long)resource->GetWidth(), "integer"); } else if (name == "height") { - int width, height; - propertyWindow->GetSize(&width, &height); - return new wxProperty("height", (long)height, "integer"); + return new wxProperty("width", (long)resource->GetHeight(), "integer"); } else if (name == "id") { - wxString symbolName("TODO"); - return new wxProperty("id", symbolName, "window_id"); + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource) + { + int id = resource->GetId(); + wxString idStr; + idStr.Printf("%d", id); + wxString symbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id); + symbolName += "="; + symbolName += idStr; + // symbolName is now e.g. "ID_PANEL21=105" + return new wxProperty("id", symbolName, "window_id"); + } + else + return NULL; + } + else if (name == "border") + { + wxString border(""); + if (m_propertyWindow->GetWindowStyleFlag() & wxSIMPLE_BORDER) + border = "wxSIMPLE_BORDER"; + else if (m_propertyWindow->GetWindowStyleFlag() & wxRAISED_BORDER) + border = "wxRAISED_BORDER"; + else if (m_propertyWindow->GetWindowStyleFlag() & wxSUNKEN_BORDER) + border = "wxSUNKEN_BORDER"; + else if (m_propertyWindow->GetWindowStyleFlag() & wxDOUBLE_BORDER) + border = "wxDOUBLE_BORDER"; + else if (m_propertyWindow->GetWindowStyleFlag() & wxSTATIC_BORDER) + border = "wxSTATIC_BORDER"; + else + border = "wxNO_BORDER"; + + return new wxProperty("border", border, "string", + new wxStringListValidator(new wxStringList("wxSIMPLE_BORDER", "wxRAISED_BORDER", + "wxSUNKEN_BORDER", "wxDOUBLE_BORDER", "wxSTATIC_BORDER", "wxNO_BORDER", NULL))); } else return NULL; @@ -301,30 +349,30 @@ wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name) bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxFont *font = propertyWindow->GetFont(); + wxFont *font = m_propertyWindow->GetFont(); if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" )) { wxFont *newFont = SetFontProperty(name, property, font); if (newFont) - propertyWindow->SetFont(newFont); + m_propertyWindow->SetFont(newFont); return TRUE; } else if (name == "name") { // Remove old name from resource table, if it's there. - wxItemResource *oldResource = (wxItemResource *)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(propertyWindow->GetName()); + wxItemResource *oldResource = (wxItemResource *)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(m_propertyWindow->GetName()); if (oldResource) { // It's a top-level resource - propertyWindow->SetName(property->GetValue().StringValue()); + m_propertyWindow->SetName(property->GetValue().StringValue()); oldResource->SetName(property->GetValue().StringValue()); - wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(propertyWindow->GetName(), oldResource); + wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(m_propertyWindow->GetName(), oldResource); } else { // It's a child of something; just set the name of the resource and the window. - propertyWindow->SetName(property->GetValue().StringValue()); - propertyResource->SetName(property->GetValue().StringValue()); + m_propertyWindow->SetName(property->GetValue().StringValue()); + m_propertyResource->SetName(property->GetValue().StringValue()); } // Refresh the resource manager list, because the name changed. wxResourceManager::GetCurrentResourceManager()->UpdateResourceList(); @@ -332,64 +380,240 @@ bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property) } else if (name == "title") { - propertyWindow->SetTitle(property->GetValue().StringValue()); + m_propertyWindow->SetTitle(property->GetValue().StringValue()); return TRUE; } else if (name == "x") { int x, y; - propertyWindow->GetPosition(&x, &y); + m_propertyWindow->GetPosition(&x, &y); int newX = (int)property->GetValue().IntegerValue(); + + // We need to convert to pixels if this is not a dialog or panel, but + // the parent resource specifies dialog units. + if (m_propertyWindow->GetParent() && m_propertyWindow->IsKindOf(CLASSINFO(wxControl))) + { + wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow->GetParent()); + if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxPoint pt = m_propertyWindow->GetParent()->ConvertDialogToPixels(wxPoint(newX, y)); + newX = pt.x; + } + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) + { + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxPoint pt = m_propertyWindow->ConvertDialogToPixels(wxPoint(newX, y)); + newX = pt.x; + } + } + if (x != newX) - propertyWindow->Move(newX, y); + m_propertyWindow->Move(newX, y); return TRUE; } else if (name == "y") { int x, y; - propertyWindow->GetPosition(&x, &y); + m_propertyWindow->GetPosition(&x, &y); int newY = (int)property->GetValue().IntegerValue(); + + // We need to convert to pixels if this is not a dialog or panel, but + // the parent resource specifies dialog units. + if (m_propertyWindow->GetParent() && m_propertyWindow->IsKindOf(CLASSINFO(wxControl))) + { + wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow->GetParent()); + if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxPoint pt = m_propertyWindow->GetParent()->ConvertDialogToPixels(wxPoint(x, newY)); + newY = pt.y; + } + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) + { + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxPoint pt = m_propertyWindow->ConvertDialogToPixels(wxPoint(x, newY)); + newY = pt.y; + } + } + if (y != newY) - propertyWindow->Move(x, newY); + m_propertyWindow->Move(x, newY); return TRUE; } else if (name == "width") { int width, height; - propertyWindow->GetSize(&width, &height); + m_propertyWindow->GetSize(&width, &height); int newWidth = (int)property->GetValue().IntegerValue(); + + // We need to convert to pixels if this is not a dialog or panel, but + // the parent resource specifies dialog units. + if (m_propertyWindow->GetParent() && m_propertyWindow->IsKindOf(CLASSINFO(wxControl))) + { + wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow->GetParent()); + if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxSize sz = m_propertyWindow->GetParent()->ConvertDialogToPixels(wxSize(newWidth, height)); + newWidth = sz.x; + } + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) + { + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxSize sz = m_propertyWindow->ConvertDialogToPixels(wxSize(newWidth, height)); + newWidth = sz.x; + } + } + if (width != newWidth) { - propertyWindow->SetSize(newWidth, height); -/* - if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog))) - { - propertyWindow->GetParent()->SetClientSize(newWidth, height); - } -*/ + m_propertyWindow->SetSize(newWidth, height); } return TRUE; } else if (name == "height") { int width, height; - propertyWindow->GetSize(&width, &height); + m_propertyWindow->GetSize(&width, &height); int newHeight = (int)property->GetValue().IntegerValue(); + + // We need to convert to pixels if this is not a dialog or panel, but + // the parent resource specifies dialog units. + if (m_propertyWindow->GetParent() && m_propertyWindow->IsKindOf(CLASSINFO(wxControl))) + { + wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow->GetParent()); + if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxSize sz = m_propertyWindow->GetParent()->ConvertDialogToPixels(wxSize(width, newHeight)); + newHeight = sz.y; + } + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) + { + wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxSize sz = m_propertyWindow->ConvertDialogToPixels(wxSize(width, newHeight)); + newHeight = sz.y; + } + } + if (height != newHeight) { - propertyWindow->SetSize(width, newHeight); -/* - if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog))) - { - propertyWindow->GetParent()->SetClientSize(width, newHeight); - } -*/ + m_propertyWindow->SetSize(width, newHeight); } return TRUE; } else if (name == "id") { - // TODO + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + if (resource) + { + wxString value = property->GetValue().StringValue(); + + wxString strName = value.Before('='); + wxString strId = value.After('='); + int id = atoi(strId); + + wxString oldSymbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource->GetId()); + int oldSymbolId = resource->GetId(); + + if (strName != "") + { + // If we change the id for an existing symbol, we need to: + // 1) Check if there are any other resources currently using the original id. + // If so, will need to change their id to the new id. + // 2) Remove the old symbol, add the new symbol. + // In this check, we don't have to do this, but we need to do it in SetProperty. + + if (strName == oldSymbolName && id != oldSymbolId) + { + wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) ); + + // It's OK to change just the id. But we'll need to change all matching ids in all resources, + // because ids are unique and changing one resource's id must change all identical ones. + wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId, id); + + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName); + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id); + } + + // If we change the name but not the id, we'll just need to remove and + // re-add the symbol/id pair. + if (strName != oldSymbolName && id == oldSymbolId) + { + wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) ); + + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName); + + if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName)) + { + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id); + } + } + + // What if we're changing both the name and the id? + // - if there's no symbol of that name, just remove the old, add the new (in SetProperty) + // - if there is a symbol of that name, if id matches, do nothing. If not, veto. + + if (strName != oldSymbolName && id != oldSymbolId) + { + // Remove old symbol if it's not being used + if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource, oldSymbolId) && + !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) + { + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName); + } + + if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName)) + { + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id); + } + } + resource->SetId(id); + } + + return TRUE; + } + else + return FALSE; + } + else if (name == "border") + { + long borderStyle = wxNO_BORDER; + wxString val = property->GetValue().StringValue(); + + if (val == "wxSIMPLE_BORDER") + borderStyle = wxSIMPLE_BORDER; + else if (val == "wxRAISED_BORDER") + borderStyle = wxRAISED_BORDER; + else if (val == "wxSUNKEN_BORDER") + borderStyle = wxSUNKEN_BORDER; + else if (val == "wxDOUBLE_BORDER") + borderStyle = wxDOUBLE_BORDER; + else if (val == "wxSTATIC_BORDER") + borderStyle = wxSTATIC_BORDER; + else + borderStyle = wxNO_BORDER; + + SetWindowStyle(m_propertyWindow, wxSIMPLE_BORDER, FALSE); + SetWindowStyle(m_propertyWindow, wxRAISED_BORDER, FALSE); + SetWindowStyle(m_propertyWindow, wxSUNKEN_BORDER, FALSE); + SetWindowStyle(m_propertyWindow, wxDOUBLE_BORDER, FALSE); + SetWindowStyle(m_propertyWindow, wxSTATIC_BORDER, FALSE); + SetWindowStyle(m_propertyWindow, wxNO_BORDER, FALSE); + + SetWindowStyle(m_propertyWindow, borderStyle, TRUE); + + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); return TRUE; } else @@ -404,7 +628,8 @@ void wxWindowPropertyInfo::GetPropertyNames(wxStringList& names) names.Add("y"); names.Add("width"); names.Add("height"); - if (!propertyWindow->IsKindOf(CLASSINFO(wxControl))) + names.Add("border"); + if (!m_propertyWindow->IsKindOf(CLASSINFO(wxControl))) { names.Add("fontPoints"); names.Add("fontFamily"); @@ -417,19 +642,73 @@ void wxWindowPropertyInfo::GetPropertyNames(wxStringList& names) // Fill in the wxItemResource members to mirror the current window settings bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource) { - resource->SetType(propertyWindow->GetClassInfo()->GetClassName()); - -// resource->SetStyle(propertyWindow->GetWindowStyleFlag()); - wxString str(propertyWindow->GetName()); - resource->SetName(WXSTRINGCAST str); +// resource->SetType(m_propertyWindow->GetClassInfo()->GetClassName()); + +// resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); + wxString str(m_propertyWindow->GetName()); + resource->SetName(str); + +#if 0 int x, y, w, h; - propertyWindow->GetSize(&w, &h); - propertyWindow->GetPosition(&x, &y); + if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) + m_propertyWindow->GetClientSize(&w, &h); + else + m_propertyWindow->GetSize(&w, &h); + + m_propertyWindow->GetPosition(&x, &y); + + // We need to convert to dialog units if this is not a dialog or panel, but + // the parent resource specifies dialog units. + if (m_propertyWindow->GetParent() && m_propertyWindow->IsKindOf(CLASSINFO(wxControl))) + { + 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; + } + } + else if (m_propertyWindow->IsKindOf(CLASSINFO(wxPanel))) + { + if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) + { + wxPoint pt = m_propertyWindow->ConvertPixelsToDialog(wxPoint(x, y)); + x = pt.x; y = pt.y; + wxSize sz = m_propertyWindow->ConvertPixelsToDialog(wxSize(w, h)); + w = sz.x; h = sz.y; + } + } + resource->SetSize(x, y, w, h); +#endif + return TRUE; } +// Set the window style +void wxWindowPropertyInfo::SetWindowStyle(wxWindow* win, long style, bool set) +{ + if (style == 0) + return; + + if ((win->GetWindowStyleFlag() & style) == style) + { + if (!set) + { + win->SetWindowStyleFlag(win->GetWindowStyleFlag() - style); + } + } + else + { + if (set) + { + win->SetWindowStyleFlag(win->GetWindowStyleFlag() | style); + } + } +} /* * Controls @@ -437,21 +716,21 @@ bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxItemPropertyInfo::GetProperty(wxString& name) { - wxControl *itemWindow = (wxControl *)propertyWindow; + wxControl *itemWindow = (wxControl *)m_propertyWindow; wxFont *font = itemWindow->GetFont(); if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined") return GetFontProperty(name, font); else if (name == "label" && itemWindow->GetLabel()) - return new wxProperty("label", propertyWindow->GetLabel(), "string"); + return new wxProperty("label", m_propertyWindow->GetLabel(), "string"); else return wxWindowPropertyInfo::GetProperty(name); } bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxControl *itemWindow = (wxControl *)propertyWindow; + wxControl *itemWindow = (wxControl *)m_propertyWindow; wxFont *font = itemWindow->GetFont(); if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" )) @@ -485,9 +764,9 @@ bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource) { wxWindowPropertyInfo::InstantiateResource(resource); - wxControl *item = (wxControl *)propertyWindow; + wxControl *item = (wxControl *)m_propertyWindow; wxString str(item->GetLabel()); - resource->SetTitle(WXSTRINGCAST str); + resource->SetTitle(str); if (item->GetFont() && item->GetFont()->Ok()) resource->SetFont(wxTheFontList->FindOrCreateFont(item->GetFont()->GetPointSize(), item->GetFont()->GetFamily(), item->GetFont()->GetStyle(), item->GetFont()->GetWeight(), @@ -501,20 +780,18 @@ bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxButtonPropertyInfo::GetProperty(wxString& name) { - wxButton *button = (wxButton *)propertyWindow; return wxItemPropertyInfo::GetProperty(name); } bool wxButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxButton *button = (wxButton *)propertyWindow; return wxItemPropertyInfo::SetProperty(name, property); } void wxButtonPropertyInfo::GetPropertyNames(wxStringList& names) { - names.Add("label"); wxItemPropertyInfo::GetPropertyNames(names); + names.Add("label"); } bool wxButtonPropertyInfo::InstantiateResource(wxItemResource *resource) @@ -528,7 +805,7 @@ bool wxButtonPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxBitmapButtonPropertyInfo::GetProperty(wxString& name) { - wxBitmapButton *button = (wxBitmapButton *)propertyWindow; + wxBitmapButton *button = (wxBitmapButton *)m_propertyWindow; if (name == "label") { wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button); @@ -536,9 +813,7 @@ wxProperty *wxBitmapButtonPropertyInfo::GetProperty(wxString& name) if (resource) { - char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource); - if (filename) - str = filename; + str = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource); } return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp")); } @@ -548,7 +823,7 @@ wxProperty *wxBitmapButtonPropertyInfo::GetProperty(wxString& name) bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxBitmapButton *button = (wxBitmapButton *)propertyWindow; + wxBitmapButton *button = (wxBitmapButton *)m_propertyWindow; if (name == "label") { char *s = property->GetValue().StringValue(); @@ -568,11 +843,11 @@ bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *propert if (resource) { wxString oldResource(resource->GetValue4()); - char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s); + wxString resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s); resource->SetValue4(resName); if (!oldResource.IsNull()) - wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource); + wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource); } button->SetLabel(bitmap); @@ -603,20 +878,18 @@ bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxStaticTextPropertyInfo::GetProperty(wxString& name) { - wxStaticText *message = (wxStaticText *)propertyWindow; return wxItemPropertyInfo::GetProperty(name); } bool wxStaticTextPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxStaticText *message = (wxStaticText *)propertyWindow; return wxItemPropertyInfo::SetProperty(name, property); } void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList& names) { - names.Add("label"); wxItemPropertyInfo::GetPropertyNames(names); + names.Add("label"); } bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource *resource) @@ -630,7 +903,7 @@ bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxStaticBitmapPropertyInfo::GetProperty(wxString& name) { - wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow; + wxStaticBitmap *message = (wxStaticBitmap *)m_propertyWindow; if (name == "label") { wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message); @@ -638,9 +911,7 @@ wxProperty *wxStaticBitmapPropertyInfo::GetProperty(wxString& name) if (resource) { - char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource); - if (filename) - str = filename; + str = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource); } return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp")); } @@ -650,7 +921,7 @@ wxProperty *wxStaticBitmapPropertyInfo::GetProperty(wxString& name) bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow; + wxStaticBitmap *message = (wxStaticBitmap *)m_propertyWindow; if (name == "label") { char *s = property->GetValue().StringValue(); @@ -671,11 +942,11 @@ bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *propert if (resource) { wxString oldResource(resource->GetValue4()); - char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s); + wxString resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s); resource->SetValue4(resName); if (!oldResource.IsNull()) - wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource); + wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource); } message->SetBitmap(bitmap); @@ -691,8 +962,8 @@ bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *propert void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList& names) { - names.Add("label"); wxItemPropertyInfo::GetPropertyNames(names); + names.Add("label"); } bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource *resource) @@ -706,7 +977,7 @@ bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxTextPropertyInfo::GetProperty(wxString& name) { - wxTextCtrl *text = (wxTextCtrl *)propertyWindow; + wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; if (name == "value") return new wxProperty("value", text->GetValue(), "string"); else if (name == "password") @@ -725,7 +996,7 @@ wxProperty *wxTextPropertyInfo::GetProperty(wxString& name) bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxTextCtrl *text = (wxTextCtrl *)propertyWindow; + wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; if (name == "value") { text->SetValue(property->GetValue().StringValue()); @@ -775,17 +1046,17 @@ bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxTextPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("value"); names.Add("readonly"); names.Add("password"); - wxItemPropertyInfo::GetPropertyNames(names); } bool wxTextPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxTextCtrl *text = (wxTextCtrl *)propertyWindow; + wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; wxString str(text->GetValue()); - resource->SetValue4(WXSTRINGCAST str); + resource->SetValue4(str); return wxItemPropertyInfo::InstantiateResource(resource); } @@ -796,7 +1067,7 @@ bool wxTextPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name) { - wxListBox *listBox = (wxListBox *)propertyWindow; + wxListBox *listBox = (wxListBox *)m_propertyWindow; if (name == "values") { wxStringList *stringList = new wxStringList; @@ -808,7 +1079,6 @@ wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name) } else if (name == "multiple") { - char *pos = NULL; wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox); if (!resource) return NULL; @@ -838,7 +1108,7 @@ wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name) bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxListBox *listBox = (wxListBox *)propertyWindow; + wxListBox *listBox = (wxListBox *)m_propertyWindow; if (name == "values") { listBox->Clear(); @@ -874,14 +1144,14 @@ bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxListBoxPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("values"); names.Add("multiple"); - wxItemPropertyInfo::GetPropertyNames(names); } bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxListBox *lbox = (wxListBox *)propertyWindow; + wxListBox *lbox = (wxListBox *)m_propertyWindow; // This will be set for the wxItemResource on reading or in SetProperty // resource->SetValue1(lbox->GetSelectionMode()); int i; @@ -889,10 +1159,10 @@ bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource) resource->SetStringValues(NULL); else { - wxStringList *slist = new wxStringList; + wxStringList slist; for (i = 0; i < lbox->Number(); i++) - slist->Add(lbox->GetString(i)); + slist.Add(lbox->GetString(i)); resource->SetStringValues(slist); } @@ -905,10 +1175,10 @@ bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxChoicePropertyInfo::GetProperty(wxString& name) { - wxChoice *choice = (wxChoice *)propertyWindow; + wxChoice *choice = (wxChoice *)m_propertyWindow; if (name == "values") { - wxStringList *stringList = new wxStringList; + wxStringList* stringList = new wxStringList; int i; for (i = 0; i < choice->Number(); i++) stringList->Add(choice->GetString(i)); @@ -921,7 +1191,7 @@ wxProperty *wxChoicePropertyInfo::GetProperty(wxString& name) bool wxChoicePropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxChoice *choice = (wxChoice *)propertyWindow; + wxChoice *choice = (wxChoice *)m_propertyWindow; if (name == "values") { choice->Clear(); @@ -943,22 +1213,141 @@ bool wxChoicePropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxChoicePropertyInfo::GetPropertyNames(wxStringList& names) { - names.Add("values"); wxItemPropertyInfo::GetPropertyNames(names); + names.Add("values"); } bool wxChoicePropertyInfo::InstantiateResource(wxItemResource *resource) { - wxChoice *choice = (wxChoice *)propertyWindow; + wxChoice *choice = (wxChoice *)m_propertyWindow; int i; if (choice->Number() == 0) resource->SetStringValues(NULL); else { - wxStringList *slist = new wxStringList; + wxStringList slist; + + for (i = 0; i < choice->Number(); i++) + slist.Add(choice->GetString(i)); + + resource->SetStringValues(slist); + } + return wxItemPropertyInfo::InstantiateResource(resource); +} + +/* + * Choice item + */ + +wxProperty *wxComboBoxPropertyInfo::GetProperty(wxString& name) +{ + wxComboBox *choice = (wxComboBox *)m_propertyWindow; + if (name == "values") + { + wxStringList *stringList = new wxStringList; + int i; + for (i = 0; i < choice->Number(); i++) + stringList->Add(choice->GetString(i)); + + return new wxProperty(name, stringList, "stringlist"); + } + else if (name == "sort") + { + bool sort = ((m_propertyWindow->GetWindowStyleFlag() & wxCB_SORT) == wxCB_SORT); + return new wxProperty(name, sort, "bool"); + } + else if (name == "style") + { + wxString styleStr("dropdown"); + if (m_propertyWindow->GetWindowStyleFlag() & wxCB_SIMPLE) + styleStr = "simple"; + else if (m_propertyWindow->GetWindowStyleFlag() & wxCB_READONLY) + styleStr = "readonly"; + else + styleStr = "dropdown"; + + return new wxProperty(name, styleStr, "string", + new wxStringListValidator(new wxStringList("simple", "dropdown", "readonly", + NULL))); + } + else + return wxItemPropertyInfo::GetProperty(name); +} + +bool wxComboBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) +{ + wxComboBox *choice = (wxComboBox *)m_propertyWindow; + if (name == "values") + { + choice->Clear(); + wxPropertyValue *expr = property->GetValue().GetFirst(); + while (expr) + { + char *s = expr->StringValue(); + if (s) + choice->Append(s); + expr = expr->GetNext(); + } + if (choice->Number() > 0) + choice->SetSelection(0); + return TRUE; + } + else if (name == "sort") + { + SetWindowStyle(m_propertyWindow, wxCB_SORT, property->GetValue().BoolValue()); + + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); + + wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow, this); + return TRUE; + } + else if (name == "style") + { + SetWindowStyle(m_propertyWindow, wxCB_SIMPLE, FALSE); + SetWindowStyle(m_propertyWindow, wxCB_DROPDOWN, FALSE); + SetWindowStyle(m_propertyWindow, wxCB_READONLY, FALSE); + + wxString styleStr(property->GetValue().StringValue()); + if (styleStr == "simple") + SetWindowStyle(m_propertyWindow, wxCB_SIMPLE, TRUE); + else if (styleStr == "dropdown") + SetWindowStyle(m_propertyWindow, wxCB_DROPDOWN, TRUE); + else if (styleStr == "readonly") + SetWindowStyle(m_propertyWindow, wxCB_READONLY, TRUE); + + // Necesary? + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + resource->SetStyle(m_propertyWindow->GetWindowStyleFlag()); + + wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow, this); + + return TRUE; + } + else + return wxItemPropertyInfo::SetProperty(name, property); +} + +void wxComboBoxPropertyInfo::GetPropertyNames(wxStringList& names) +{ + wxItemPropertyInfo::GetPropertyNames(names); + names.Add("values"); + names.Add("style"); + names.Add("sort"); +} + +bool wxComboBoxPropertyInfo::InstantiateResource(wxItemResource *resource) +{ + wxComboBox *choice = (wxComboBox *)m_propertyWindow; + int i; + if (choice->Number() == 0) + resource->SetStringValues(NULL); + else + { + wxStringList slist; for (i = 0; i < choice->Number(); i++) - slist->Add(choice->GetString(i)); + slist.Add(choice->GetString(i)); resource->SetStringValues(slist); } @@ -971,21 +1360,21 @@ bool wxChoicePropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxRadioBoxPropertyInfo::GetProperty(wxString& name) { - wxRadioBox *radioBox = (wxRadioBox *)propertyWindow; + wxRadioBox *radioBox = (wxRadioBox *)m_propertyWindow; if (name == "numberRowsOrCols") { return new wxProperty("numberRowsOrCols", (long)radioBox->GetNumberOfRowsOrCols(), "integer"); } if (name == "orientation") { - char *pos = NULL; - if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL) - pos = "wxHORIZONTAL"; + wxString orient; + if (m_propertyWindow->GetWindowStyleFlag() & wxRA_HORIZONTAL) + orient = "wxRA_HORIZONTAL"; else - pos = "wxVERTICAL"; + orient = "wxRA_VERTICAL"; - return new wxProperty("orientation", pos, "string", - new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL", + return new wxProperty("orientation", orient, "string", + new wxStringListValidator(new wxStringList("wxRA_HORIZONTAL", "wxRA_VERTICAL", NULL))); } else if (name == "values") @@ -1002,7 +1391,7 @@ wxProperty *wxRadioBoxPropertyInfo::GetProperty(wxString& name) bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxRadioBox *radioBox = (wxRadioBox *)propertyWindow; + wxRadioBox *radioBox = (wxRadioBox *)m_propertyWindow; if (name == "numberRowsOrCols") { radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue()); @@ -1013,19 +1402,21 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) { long windowStyle = radioBox->GetWindowStyleFlag(); wxString val(property->GetValue().StringValue()); - if (val == "wxHORIZONTAL") + if (val == "wxRA_HORIZONTAL") { - if (windowStyle & wxVERTICAL) - windowStyle -= wxVERTICAL; - windowStyle |= wxHORIZONTAL; + if (windowStyle & wxRA_VERTICAL) + windowStyle -= wxRA_VERTICAL; + windowStyle |= wxRA_HORIZONTAL; } else { - if (windowStyle & wxHORIZONTAL) - windowStyle -= wxHORIZONTAL; - windowStyle |= wxVERTICAL; + if (windowStyle & wxRA_HORIZONTAL) + windowStyle -= wxRA_HORIZONTAL; + windowStyle |= wxRA_VERTICAL; } radioBox->SetWindowStyleFlag(windowStyle); + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(radioBox); + resource->SetStyle(windowStyle); wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); return TRUE; @@ -1035,26 +1426,20 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) // Set property into *resource*, not wxRadioBox, and then recreate // the wxRadioBox. This is because we can't dynamically set the strings // of a wxRadioBox. - wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow); + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); if (!resource) return FALSE; - wxStringList *stringList = resource->GetStringValues(); - if (!stringList) - { - stringList = new wxStringList; - resource->SetStringValues(stringList); - } - stringList->Clear(); - + wxStringList stringList; wxPropertyValue *expr = property->GetValue().GetFirst(); while (expr) { char *s = expr->StringValue(); if (s) - stringList->Add(s); + stringList.Add(s); expr = expr->GetNext(); } + resource->SetStringValues(stringList); wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this); return TRUE; } @@ -1063,16 +1448,16 @@ bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("label"); names.Add("values"); names.Add("orientation"); names.Add("numberRowsOrCols"); - wxItemPropertyInfo::GetPropertyNames(names); } bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxRadioBox *rbox = (wxRadioBox *)propertyWindow; + wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow; // Take strings from resource instead /* int i; @@ -1098,7 +1483,6 @@ bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxGroupBoxPropertyInfo::GetProperty(wxString& name) { - wxStaticBox *groupBox = (wxStaticBox *)propertyWindow; return wxItemPropertyInfo::GetProperty(name); } @@ -1109,13 +1493,12 @@ bool wxGroupBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList& names) { - names.Add("label"); wxItemPropertyInfo::GetPropertyNames(names); + names.Add("label"); } bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxStaticBox *gbox = (wxStaticBox *)propertyWindow; return wxItemPropertyInfo::InstantiateResource(resource); } @@ -1125,7 +1508,7 @@ bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxCheckBoxPropertyInfo::GetProperty(wxString& name) { - wxCheckBox *checkBox = (wxCheckBox *)propertyWindow; + wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow; if (name == "value") return new wxProperty("value", checkBox->GetValue(), "bool"); else @@ -1134,7 +1517,7 @@ wxProperty *wxCheckBoxPropertyInfo::GetProperty(wxString& name) bool wxCheckBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxCheckBox *checkBox = (wxCheckBox *)propertyWindow; + wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow; if (name == "value") { checkBox->SetValue((bool)property->GetValue().BoolValue()); @@ -1146,14 +1529,14 @@ bool wxCheckBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("label"); names.Add("value"); - wxItemPropertyInfo::GetPropertyNames(names); } bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxCheckBox *cbox = (wxCheckBox *)propertyWindow; + wxCheckBox *cbox = (wxCheckBox *)m_propertyWindow; resource->SetValue1(cbox->GetValue()); return wxItemPropertyInfo::InstantiateResource(resource); } @@ -1164,7 +1547,7 @@ bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxRadioButtonPropertyInfo::GetProperty(wxString& name) { - wxRadioButton *checkBox = (wxRadioButton *)propertyWindow; + wxRadioButton *checkBox = (wxRadioButton *)m_propertyWindow; if (name == "value") return new wxProperty("value", checkBox->GetValue(), "bool"); else @@ -1173,7 +1556,7 @@ wxProperty *wxRadioButtonPropertyInfo::GetProperty(wxString& name) bool wxRadioButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxRadioButton *checkBox = (wxRadioButton *)propertyWindow; + wxRadioButton *checkBox = (wxRadioButton *)m_propertyWindow; if (name == "value") { checkBox->SetValue((bool)property->GetValue().BoolValue()); @@ -1185,14 +1568,14 @@ bool wxRadioButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("label"); names.Add("value"); - wxItemPropertyInfo::GetPropertyNames(names); } bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxRadioButton *cbox = (wxRadioButton *)propertyWindow; + wxRadioButton *cbox = (wxRadioButton *)m_propertyWindow; resource->SetValue1(cbox->GetValue()); return wxItemPropertyInfo::InstantiateResource(resource); } @@ -1203,13 +1586,13 @@ bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxSliderPropertyInfo::GetProperty(wxString& name) { - wxSlider *slider = (wxSlider *)propertyWindow; + wxSlider *slider = (wxSlider *)m_propertyWindow; if (name == "value") return new wxProperty("value", (long)slider->GetValue(), "integer"); else if (name == "orientation") { char *pos = NULL; - if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL) + if (m_propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL) pos = "wxHORIZONTAL"; else pos = "wxVERTICAL"; @@ -1218,17 +1601,17 @@ wxProperty *wxSliderPropertyInfo::GetProperty(wxString& name) new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL", NULL))); } - else if (name == "min_value") - return new wxProperty("min_value", (long)slider->GetMin(), "integer"); - else if (name == "max_value") - return new wxProperty("max_value", (long)slider->GetMax(), "integer"); + else if (name == "minValue") + return new wxProperty("minValue", (long)slider->GetMin(), "integer"); + else if (name == "maxValue") + return new wxProperty("maxValue", (long)slider->GetMax(), "integer"); else return wxItemPropertyInfo::GetProperty(name); } bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxSlider *slider = (wxSlider *)propertyWindow; + wxSlider *slider = (wxSlider *)m_propertyWindow; if (name == "value") { slider->SetValue((int)property->GetValue().IntegerValue()); @@ -1266,12 +1649,12 @@ bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property) return TRUE; } - else if (name == "min_value") + else if (name == "minValue") { slider->SetRange((int)property->GetValue().IntegerValue(), slider->GetMax()); return TRUE; } - else if (name == "max_value") + else if (name == "maxValue") { slider->SetRange(slider->GetMin(), (int)property->GetValue().IntegerValue()); return TRUE; @@ -1282,16 +1665,16 @@ bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxSliderPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("value"); names.Add("orientation"); - names.Add("min_value"); - names.Add("max_value"); - wxItemPropertyInfo::GetPropertyNames(names); + names.Add("minValue"); + names.Add("maxValue"); } bool wxSliderPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxSlider *slider = (wxSlider *)propertyWindow; + wxSlider *slider = (wxSlider *)m_propertyWindow; resource->SetValue1(slider->GetValue()); resource->SetValue2(slider->GetMin()); resource->SetValue3(slider->GetMax()); @@ -1304,24 +1687,24 @@ bool wxSliderPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxGaugePropertyInfo::GetProperty(wxString& name) { - wxGauge *gauge = (wxGauge *)propertyWindow; + wxGauge *gauge = (wxGauge *)m_propertyWindow; if (name == "value") return new wxProperty("value", (long)gauge->GetValue(), "integer"); - else if (name == "max_value") - return new wxProperty("max_value", (long)gauge->GetRange(), "integer"); + else if (name == "maxValue") + return new wxProperty("maxValue", (long)gauge->GetRange(), "integer"); else return wxItemPropertyInfo::GetProperty(name); } bool wxGaugePropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxGauge *gauge = (wxGauge *)propertyWindow; + wxGauge *gauge = (wxGauge *)m_propertyWindow; if (name == "value") { gauge->SetValue((int)property->GetValue().IntegerValue()); return TRUE; } - else if (name == "max_value") + else if (name == "maxValue") { gauge->SetRange((int)property->GetValue().IntegerValue()); return TRUE; @@ -1332,14 +1715,14 @@ bool wxGaugePropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxGaugePropertyInfo::GetPropertyNames(wxStringList& names) { - names.Add("value"); - names.Add("max_value"); wxItemPropertyInfo::GetPropertyNames(names); + names.Add("value"); + names.Add("maxValue"); } bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource) { - wxGauge *gauge = (wxGauge *)propertyWindow; + wxGauge *gauge = (wxGauge *)m_propertyWindow; resource->SetValue1(gauge->GetValue()); resource->SetValue2(gauge->GetRange()); return wxItemPropertyInfo::InstantiateResource(resource); @@ -1351,13 +1734,13 @@ bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name) { - wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow; + wxScrollBar *scrollBar = (wxScrollBar *)m_propertyWindow; if (name == "value") return new wxProperty("value", (long)scrollBar->GetValue(), "integer"); else if (name == "orientation") { char *pos = NULL; - if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL) + if (m_propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL) pos = "wxHORIZONTAL"; else pos = "wxVERTICAL"; @@ -1393,7 +1776,7 @@ wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name) bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow; + wxScrollBar *scrollBar = (wxScrollBar *)m_propertyWindow; if (name == "value") { scrollBar->SetValue((int)property->GetValue().IntegerValue()); @@ -1452,12 +1835,12 @@ bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names) { + wxItemPropertyInfo::GetPropertyNames(names); names.Add("orientation"); names.Add("value"); names.Add("pageSize"); names.Add("viewLength"); names.Add("objectLength"); - wxItemPropertyInfo::GetPropertyNames(names); // Remove some properties we don't inherit names.Delete("fontPoints"); @@ -1469,8 +1852,8 @@ void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names) bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxScrollBar *sbar = (wxScrollBar *)propertyWindow; - + wxScrollBar *sbar = (wxScrollBar *)m_propertyWindow; + resource->SetValue1(sbar->GetValue()); int viewStart, pageLength, objectLength, viewLength; @@ -1489,7 +1872,7 @@ bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxPanelPropertyInfo::GetProperty(wxString& name) { - wxPanel *panelWindow = (wxPanel *)propertyWindow; + wxPanel *panelWindow = (wxPanel *)m_propertyWindow; wxFont *labelFont = panelWindow->GetLabelFont(); wxFont *buttonFont = panelWindow->GetButtonFont(); @@ -1527,13 +1910,40 @@ wxProperty *wxPanelPropertyInfo::GetProperty(wxString& name) else return new wxProperty(name, "Could not get title", "string"); } + else if (name == "caption") + { + return new wxProperty(name, ((panelWindow->GetWindowStyleFlag() & wxCAPTION) == wxCAPTION), + "bool"); + } + else if (name == "systemMenu") + { + return new wxProperty(name, ((panelWindow->GetWindowStyleFlag() & wxSYSTEM_MENU) == wxSYSTEM_MENU), + "bool"); + } + else if (name == "thickFrame") + { + return new wxProperty(name, ((panelWindow->GetWindowStyleFlag() & wxTHICK_FRAME) == wxTHICK_FRAME), + "bool"); + } + else if (name == "useSystemDefaults") + { + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + return new wxProperty(name, ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) == wxRESOURCE_USE_DEFAULTS), + "bool"); + } + else if (name == "useDialogUnits") + { + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + return new wxProperty(name, ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == wxRESOURCE_DIALOG_UNITS), + "bool"); + } else return wxWindowPropertyInfo::GetProperty(name); } bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxPanel *panelWindow = (wxPanel *)propertyWindow; + wxPanel *panelWindow = (wxPanel *)m_propertyWindow; wxFont *labelFont = panelWindow->GetLabelFont(); wxFont *buttonFont = panelWindow->GetButtonFont(); @@ -1554,7 +1964,6 @@ bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property) else if (name == "no3D") { bool userColours = property->GetValue().BoolValue(); - long flag = panelWindow->GetWindowStyleFlag(); if (userColours) { @@ -1595,6 +2004,75 @@ bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property) else return FALSE; } + else if (name == "caption") + { + SetWindowStyle(panelWindow, wxCAPTION, property->GetValue().BoolValue()); + + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + resource->SetStyle(panelWindow->GetWindowStyleFlag()); + return TRUE; + } + else if (name == "thickFrame") + { + SetWindowStyle(panelWindow, wxTHICK_FRAME, property->GetValue().BoolValue()); + + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + resource->SetStyle(panelWindow->GetWindowStyleFlag()); + return TRUE; + } + else if (name == "systemMenu") + { + SetWindowStyle(panelWindow, wxSYSTEM_MENU, property->GetValue().BoolValue()); + + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + resource->SetStyle(panelWindow->GetWindowStyleFlag()); + return TRUE; + } + else if (name == "useSystemDefaults") + { + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + bool useDefaults = property->GetValue().BoolValue(); + long style = resource->GetResourceStyle(); + if (useDefaults) + { + if ((style & wxRESOURCE_USE_DEFAULTS) == 0) + style |= wxRESOURCE_USE_DEFAULTS; + } + else + { + if ((style & wxRESOURCE_USE_DEFAULTS) != 0) + style -= wxRESOURCE_USE_DEFAULTS; + } + resource->SetResourceStyle(style); + panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this); + return TRUE; + } + else if (name == "useDialogUnits") + { + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow); + bool useDialogUnits = property->GetValue().BoolValue(); + long style = resource->GetResourceStyle(); + if (useDialogUnits) + { + if ((style & wxRESOURCE_DIALOG_UNITS) == 0) + { + style |= wxRESOURCE_DIALOG_UNITS; + ConvertDialogUnits(TRUE); // Convert all resources + } + } + else + { + if ((style & wxRESOURCE_DIALOG_UNITS) != 0) + { + style -= wxRESOURCE_DIALOG_UNITS; + ConvertDialogUnits(FALSE); // Convert all resources + } + } + resource->SetResourceStyle(style); + panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this); + // TODO: need to regenerate the width and height properties else they'll be inconsistent. + return TRUE; + } else return wxWindowPropertyInfo::SetProperty(name, property); } @@ -1606,21 +2084,68 @@ void wxPanelPropertyInfo::GetPropertyNames(wxStringList& names) names.Add("title"); names.Add("no3D"); names.Add("backgroundColour"); + names.Add("caption"); + names.Add("systemMenu"); + names.Add("thickFrame"); + names.Add("useSystemDefaults"); + names.Add("useDialogUnits"); } bool wxPanelPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxPanel *panel = (wxPanel *)propertyWindow; - if (panel->GetFont()) + wxPanel *panel = (wxPanel *)m_propertyWindow; + if (panel->GetFont() && panel->GetFont()->Ok()) resource->SetFont(wxTheFontList->FindOrCreateFont(panel->GetFont()->GetPointSize(), panel->GetFont()->GetFamily(), panel->GetFont()->GetStyle(), panel->GetFont()->GetWeight(), panel->GetFont()->GetUnderlined(), panel->GetFont()->GetFaceName())); - resource->SetBackgroundColour(new wxColour(panel->GetBackgroundColour())); + resource->SetBackgroundColour(wxColour(panel->GetBackgroundColour())); return wxWindowPropertyInfo::InstantiateResource(resource); } +// Convert this dialog, and its children, to or from dialog units +void wxPanelPropertyInfo::ConvertDialogUnits(bool toDialogUnits) +{ + wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow); + + wxPoint pt; + wxSize sz; + if (toDialogUnits) + { + sz = m_propertyWindow->ConvertPixelsToDialog(wxSize(resource->GetWidth(), resource->GetHeight())); + pt = m_propertyWindow->ConvertPixelsToDialog(wxPoint(resource->GetX(), resource->GetY())); + } + else + { + sz = m_propertyWindow->ConvertDialogToPixels(wxSize(resource->GetWidth(), resource->GetHeight())); + pt = m_propertyWindow->ConvertDialogToPixels(wxPoint(resource->GetX(), resource->GetY())); + } + resource->SetSize(pt.x, pt.y, sz.x, sz.y); + + wxNode* node = m_propertyWindow->GetChildren()->First(); + while (node) + { + wxWindow* child = (wxWindow*) node->Data(); + if (child->IsKindOf(CLASSINFO(wxControl))) + { + resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(child); + if (toDialogUnits) + { + sz = m_propertyWindow->ConvertPixelsToDialog(wxSize(resource->GetWidth(), resource->GetHeight())); + pt = m_propertyWindow->ConvertPixelsToDialog(wxPoint(resource->GetX(), resource->GetY())); + } + else + { + sz = m_propertyWindow->ConvertDialogToPixels(wxSize(resource->GetWidth(), resource->GetHeight())); + pt = m_propertyWindow->ConvertDialogToPixels(wxPoint(resource->GetX(), resource->GetY())); + } + resource->SetSize(pt.x, pt.y, sz.x, sz.y); + } + node = node->Next(); + } +} + #if 0 /* * Dialog boxes @@ -1628,7 +2153,7 @@ bool wxPanelPropertyInfo::InstantiateResource(wxItemResource *resource) wxProperty *wxDialogPropertyInfo::GetProperty(wxString& name) { - wxDialog *dialogWindow = (wxDialog *)propertyWindow; + wxDialog *dialogWindow = (wxDialog *)m_propertyWindow; if (name == "modal") { wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow); @@ -1644,7 +2169,7 @@ wxProperty *wxDialogPropertyInfo::GetProperty(wxString& name) bool wxDialogPropertyInfo::SetProperty(wxString& name, wxProperty *property) { - wxDialog *dialogWindow = (wxDialog *)propertyWindow; + wxDialog *dialogWindow = (wxDialog *)m_propertyWindow; if (name == "modal") { @@ -1661,17 +2186,16 @@ bool wxDialogPropertyInfo::SetProperty(wxString& name, wxProperty *property) void wxDialogPropertyInfo::GetPropertyNames(wxStringList& names) { + wxPanelPropertyInfo::GetPropertyNames(names); names.Add("title"); names.Add("modal"); - - wxPanelPropertyInfo::GetPropertyNames(names); } bool wxDialogPropertyInfo::InstantiateResource(wxItemResource *resource) { - wxDialog *dialog = (wxDialog *)propertyWindow; + wxDialog *dialog = (wxDialog *)m_propertyWindow; wxString str(dialog->GetTitle()); - resource->SetTitle(WXSTRINGCAST str); + resource->SetTitle(str); return wxPanelPropertyInfo::InstantiateResource(resource); } @@ -1719,7 +2243,7 @@ wxResourceSymbolValidator::~wxResourceSymbolValidator(void) { } -bool wxResourceSymbolValidator::OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +bool wxResourceSymbolValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow)) { return TRUE; } @@ -1727,7 +2251,7 @@ bool wxResourceSymbolValidator::OnCheckValue(wxProperty *property, wxPropertyLis // Called when TICK is pressed or focus is lost or view wants to update // the property list. // Does the transferance from the property editing area to the property itself -bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) { if (!view->GetValueText()) return FALSE; @@ -1739,7 +2263,7 @@ bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty *property, wxProperty // Called when TICK is pressed or focus is lost or view wants to update // the property list. // Does the transferance from the property editing area to the property itself -bool wxResourceSymbolValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +bool wxResourceSymbolValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) { if (!view->GetValueText()) return FALSE; @@ -1758,7 +2282,7 @@ bool wxResourceSymbolValidator::OnDoubleClick(wxProperty *property, wxPropertyLi return TRUE; } -bool wxResourceSymbolValidator::OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow) +bool wxResourceSymbolValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow)) { if (view->GetConfirmButton()) view->GetConfirmButton()->Enable(TRUE); @@ -1778,48 +2302,37 @@ void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView wxResourceSymbolDialog* dialog = new wxResourceSymbolDialog(parentWindow, -1, "Edit Symbol"); - dialog->SetSymbol(property->GetValue().StringValue()); + // Split name/id pair e.g. "IDC_TEXT=123" + wxString value(property->GetValue().StringValue()); + + wxString strName = value.Before('='); + wxString strId = value.After('='); - // TODO: split name/id pair e.g. "IDC_TEXT=123" or get from symbol table - which? - dialog->SetId(1234); + dialog->SetSymbol(strName); + dialog->SetId(atoi(strId)); dialog->Init(); - if (dialog->ShowModal()) + if (dialog->ShowModal() == wxID_OK) { wxString symbolName(dialog->GetSymbol()); long id = dialog->GetId(); dialog->Destroy(); - // TODO: set id somewhere - property->GetValue() = wxString(symbolName); - - view->DisplayProperty(property); - view->UpdatePropertyDisplayInList(property); - view->OnPropertyChanged(property); - } + wxString str; + str.Printf("%d", id); + property->GetValue() = symbolName + wxString("=") + str; -#if 0 - char *s = wxFileSelector( - filenameMessage.GetData(), - wxPathOnly(property->GetValue().StringValue()), - wxFileNameFromPath(property->GetValue().StringValue()), - NULL, - filenameWildCard.GetData(), - 0, - parentWindow); - if (s) - { - property->GetValue() = wxString(s); view->DisplayProperty(property); view->UpdatePropertyDisplayInList(property); view->OnPropertyChanged(property); } -#endif } BEGIN_EVENT_TABLE(wxResourceSymbolDialog, wxDialog) EVT_BUTTON(wxID_OK, wxResourceSymbolDialog::OnOK) + EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnComboBoxSelect) + EVT_TEXT(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnSymbolNameUpdate) END_EVENT_TABLE() wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos, @@ -1834,7 +2347,7 @@ wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowI x += 80; m_nameCtrl = new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX, "", - wxPoint(x, y), wxSize(200, -1), 0, NULL, wxCB_DROPDOWN); + wxPoint(x, y), wxSize(200, -1), 0, NULL, wxCB_DROPDOWN|wxCB_SORT); y += 30; x = 5; @@ -1848,10 +2361,10 @@ wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowI y += 30; x = 5; - (void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(90, -1)); + (void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(80, -1)); - x += 120; - (void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(90, -1)); + x += 100; + (void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(80, -1)); Fit(); Centre(); @@ -1864,6 +2377,8 @@ void wxResourceSymbolDialog::Init() m_nameCtrl->SetValue(m_symbolName); m_idCtrl->SetValue(defaultId); + + wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl); } void wxResourceSymbolDialog::OnOK(wxCommandEvent& event) @@ -1876,6 +2391,124 @@ void wxResourceSymbolDialog::OnOK(wxCommandEvent& event) bool wxResourceSymbolDialog::CheckValues() { + wxString nameStr(m_nameCtrl->GetValue()); + wxString idStr(m_idCtrl->GetValue()); + int id = atoi(idStr); + + if (id <= 0 ) + { + wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this); + return FALSE; + } + if (nameStr == "") + { + wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this); + return FALSE; + } + if (nameStr.Contains(" ")) + { + wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this); + return FALSE; + } + if (nameStr.Contains("=")) + { + wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this); + return FALSE; + } + if (nameStr.IsNumber()) + { + wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this); + return FALSE; + } + // TODO: other checks on the name syntax. + + if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr)) + { + // If we change the id for an existing symbol, we need to: + // 1) Check if there are any other resources currently using the original id. + // If so, will need to change their id to the new id, in SetProperty. + // 2) Remove the old symbol, add the new symbol. + // In this check, we don't have to do this, but we need to do it in SetProperty. + + if (nameStr == GetSymbol() && id != GetId()) + { + // It's OK to change the id. But we'll need to change all matching ids in all resources, + // in SetProperty. + } + + // If we change the name but not the id... we'll just need to remove and + // re-add the symbol/id pair, in SetProperty. + if (nameStr != GetSymbol() && id == GetId()) + { + } + + // What if we're changing both the name and the id? + // - if there's no symbol of that name, just remove the old, add the new (in SetProperty) + // - if there is a symbol of that name, if id matches, do nothing. If not, veto. + + if (nameStr != GetSymbol() && id != GetId()) + { + if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr, id)) + { + wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.", + "Dialog Editor", wxOK|wxICON_EXCLAMATION, this); + return FALSE; + } + } + + } + + SetSymbol(nameStr); + SetId(id); + return TRUE; } +void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent& WXUNUSED(event)) +{ + wxString str(m_nameCtrl->GetStringSelection()); + if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str)) + { + int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str); + wxString str2; + str2.Printf("%d", id); + m_idCtrl->SetValue(str2); + m_idCtrl->Enable(FALSE); + } + else + { + if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str)) + { + int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str); + wxString str2; + str2.Printf("%d", id); + m_idCtrl->SetValue(str2); + } + m_idCtrl->Enable(TRUE); + } +} + +void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent& WXUNUSED(event)) +{ + wxString str(m_nameCtrl->GetValue()); + if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str)) + { + int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str); + wxString str2; + str2.Printf("%d", id); + m_idCtrl->SetValue(str2); + m_idCtrl->Enable(FALSE); + } + else + { + if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str)) + { + int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str); + wxString str2; + str2.Printf("%d", id); + m_idCtrl->SetValue(str2); + } + m_idCtrl->Enable(TRUE); + } +} +