X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9c331ded69073da6d9b2cec4a12eb09e63347892..7cf98a658a11f0ea3fb723ea686a77b8adb39718:/src/common/resource.cpp?ds=sidebyside diff --git a/src/common/resource.cpp b/src/common/resource.cpp index ab9cceda58..ecc8121d7d 100644 --- a/src/common/resource.cpp +++ b/src/common/resource.cpp @@ -31,24 +31,27 @@ #include "wx/menu.h" #include "wx/stattext.h" #include "wx/button.h" +#include "wx/bmpbuttn.h" #include "wx/radiobox.h" #include "wx/listbox.h" #include "wx/choice.h" #include "wx/checkbox.h" +#include "wx/settings.h" #include "wx/slider.h" #include "wx/statbox.h" -#if USE_GAUGE +#if wxUSE_GAUGE #include "wx/gauge.h" #endif #include "wx/textctrl.h" -#include "wx/msgbxdlg.h" +#include "wx/msgdlg.h" +#include "wx/intl.h" #endif -#if USE_SCROLLBAR +#if wxUSE_SCROLLBAR #include "wx/scrolbar.h" #endif -#if USE_COMBOBOX +#if wxUSE_COMBOBOX #include "wx/combobox.h" #endif @@ -56,7 +59,7 @@ #include "wx/log.h" -#if USE_WX_RESOURCES +#if wxUSE_WX_RESOURCES #include #include @@ -67,36 +70,40 @@ #include "wx/string.h" #include "wx/wxexpr.h" +#include "wx/settings.h" + // Forward (private) declarations -bool wxResourceInterpretResources(wxResourceTable& table, PrologDatabase& db); -wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, PrologExpr *expr, bool isPanel = FALSE); -wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *expr); -wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, PrologExpr *expr); -wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, PrologExpr *expr); -wxItemResource *wxResourceInterpretString(wxResourceTable& table, PrologExpr *expr); -wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, PrologExpr *expr); -wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, PrologExpr *expr); +bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db); +wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE); +wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr); +wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr); // Interpret list expression -wxFont *wxResourceInterpretFontSpec(PrologExpr *expr); +wxFont wxResourceInterpretFontSpec(wxExpr *expr); -bool wxResourceReadOneResource(FILE *fd, PrologDatabase& db, bool *eof, wxResourceTable *table = NULL); -bool wxResourceParseIncludeFile(char *f, wxResourceTable *table = NULL); +bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL); +bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL); -wxResourceTable *wxDefaultResourceTable = NULL; +wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL; -static char *wxResourceBuffer = NULL; +static char *wxResourceBuffer = (char *) NULL; static long wxResourceBufferSize = 0; static long wxResourceBufferCount = 0; static int wxResourceStringPtr = 0; -void wxInitializeResourceSystem(void) +void wxInitializeResourceSystem() { wxDefaultResourceTable = new wxResourceTable; } -void wxCleanUpResourceSystem(void) +void wxCleanUpResourceSystem() { delete wxDefaultResourceTable; + if (wxResourceBuffer) + delete[] wxResourceBuffer; } void wxLogWarning(char *msg) @@ -109,115 +116,40 @@ IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable) #endif -wxItemResource::wxItemResource(void) +wxItemResource::wxItemResource() { - itemType = NULL; - title = NULL; - name = NULL; - windowStyle = 0; - x = y = width = height = 0; - value1 = value2 = value3 = value5 = 0; - value4 = NULL; - stringValues = NULL; - bitmap = NULL; - backgroundColour = labelColour = buttonColour = NULL; - windowFont = NULL; + m_itemType = ""; + m_title = ""; + m_name = ""; + m_windowStyle = 0; + m_x = m_y = m_width = m_height = 0; + m_value1 = m_value2 = m_value3 = m_value5 = 0; + m_value4 = ""; m_windowId = 0; + m_exStyle = 0; } -wxItemResource::~wxItemResource(void) +wxItemResource::~wxItemResource() { - if (itemType) delete[] itemType; - if (title) delete[] title; - if (name) delete[] name; - if (value4) delete[] value4; - if (stringValues) - delete stringValues; - if (bitmap) - delete bitmap; - if (backgroundColour) - delete backgroundColour; - if (labelColour) - delete labelColour; - if (buttonColour) - delete buttonColour; - wxNode *node = children.First(); + wxNode *node = m_children.First(); while (node) { wxItemResource *item = (wxItemResource *)node->Data(); delete item; delete node; - node = children.First(); + node = m_children.First(); } } -void wxItemResource::SetTitle(char *t) -{ - if (t == title) - return; - - if (title) delete[] title; - if (t) - title = copystring(t); - else - title = NULL; -} - -void wxItemResource::SetType(char *t) -{ - if (itemType == t) - return; - - if (itemType) delete[] itemType; - if (t) - itemType = copystring(t); - else - itemType = NULL; -} - -void wxItemResource::SetName(char *n) -{ - if (n == name) - return; - - if (name) delete[] name; - if (n) - name = copystring(n); - else - name = NULL; -} - -void wxItemResource::SetStringValues(wxStringList *svalues) -{ - if (stringValues) - delete stringValues; - if (svalues) - stringValues = svalues; - else - stringValues = NULL; -} - -void wxItemResource::SetValue4(char *v) -{ - if (value4 == v) - return; - - if (value4) delete[] value4; - if (v) - value4 = copystring(v); - else - value4 = NULL; -} - /* * Resource table */ -wxResourceTable::wxResourceTable(void):wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING) +wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING) { } -wxResourceTable::~wxResourceTable(void) +wxResourceTable::~wxResourceTable() { ClearTable(); } @@ -230,10 +162,10 @@ wxItemResource *wxResourceTable::FindResource(const wxString& name) const void wxResourceTable::AddResource(wxItemResource *item) { - char *name = item->GetName(); - if (!name) + wxString name = item->GetName(); + if (name == "") name = item->GetTitle(); - if (!name) + if (name == "") name = "no name"; // Delete existing resource, if any. @@ -250,7 +182,7 @@ bool wxResourceTable::DeleteResource(const wxString& name) // See if any resource has this as its child; if so, delete from // parent's child list. BeginFind(); - wxNode *node = NULL; + wxNode *node = (wxNode *) NULL; while ((node = Next())) { wxItemResource *parent = (wxItemResource *)node->Data(); @@ -268,11 +200,11 @@ bool wxResourceTable::DeleteResource(const wxString& name) return FALSE; } -bool wxResourceTable::ParseResourceFile(char *filename) +bool wxResourceTable::ParseResourceFile(const wxString& filename) { - PrologDatabase db; + wxExprDatabase db; - FILE *fd = fopen(filename, "r"); + FILE *fd = fopen((const char*) filename, "r"); if (!fd) return FALSE; bool eof = FALSE; @@ -284,10 +216,10 @@ bool wxResourceTable::ParseResourceFile(char *filename) return wxResourceInterpretResources(*this, db); } -bool wxResourceTable::ParseResourceData(char *data) +bool wxResourceTable::ParseResourceData(const wxString& data) { - PrologDatabase db; - if (!db.ReadPrologFromString(data)) + wxExprDatabase db; + if (!db.ReadFromString(data)) { wxLogWarning(_("Ill-formed resource file syntax.")); return FALSE; @@ -296,7 +228,7 @@ bool wxResourceTable::ParseResourceData(char *data) return wxResourceInterpretResources(*this, db); } -bool wxResourceTable::RegisterResourceBitmapData(char *name, char bits[], int width, int height) +bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height) { // Register pre-loaded bitmap data wxItemResource *item = new wxItemResource; @@ -310,7 +242,7 @@ bool wxResourceTable::RegisterResourceBitmapData(char *name, char bits[], int wi return TRUE; } -bool wxResourceTable::RegisterResourceBitmapData(char *name, char **data) +bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char **data) { // Register pre-loaded bitmap data wxItemResource *item = new wxItemResource; @@ -322,12 +254,12 @@ bool wxResourceTable::RegisterResourceBitmapData(char *name, char **data) return TRUE; } -bool wxResourceTable::SaveResource(char *WXUNUSED(filename)) +bool wxResourceTable::SaveResource(const wxString& WXUNUSED(filename)) { return FALSE; } -void wxResourceTable::ClearTable(void) +void wxResourceTable::ClearTable() { BeginFind(); wxNode *node = Next(); @@ -341,108 +273,107 @@ void wxResourceTable::ClearTable(void) } } -wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childResource) const +wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* childResource, const wxItemResource* parentResource) const { int id = childResource->GetId(); if ( id == 0 ) id = -1; - wxControl *control = NULL; + bool dlgUnits = ((parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0); + + wxControl *control = (wxControl *) NULL; wxString itemType(childResource->GetType()); + + wxPoint pos; + wxSize size; + if (dlgUnits) + { + pos = parent->ConvertDialogToPixels(wxPoint(childResource->GetX(), childResource->GetY())); + size = parent->ConvertDialogToPixels(wxSize(childResource->GetWidth(), childResource->GetHeight())); + } + else + { + pos = wxPoint(childResource->GetX(), childResource->GetY()); + size = wxSize(childResource->GetWidth(), childResource->GetHeight()); + } + if (itemType == wxString("wxButton") || itemType == wxString("wxBitmapButton")) { - if (childResource->GetValue4()) + if (childResource->GetValue4() != "") { // Bitmap button - wxBitmap *bitmap = childResource->GetBitmap(); - if (!bitmap) + wxBitmap bitmap = childResource->GetBitmap(); + if (!bitmap.Ok()) { bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); - childResource->SetBitmap(bitmap); + ((wxItemResource*) childResource)->SetBitmap(bitmap); } - if (bitmap) - control = new wxBitmapButton(parent, id, *bitmap, - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + if (bitmap.Ok()) + control = new wxBitmapButton(parent, id, bitmap, pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); } else // Normal, text button - control = new wxButton(parent, id, childResource->GetTitle(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxButton(parent, id, childResource->GetTitle(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); } else if (itemType == wxString("wxMessage") || itemType == wxString("wxStaticText") || itemType == wxString("wxStaticBitmap")) { - if (childResource->GetValue4()) + if (childResource->GetValue4() != "") { // Bitmap message - wxBitmap *bitmap = childResource->GetBitmap(); - if (!bitmap) + wxBitmap bitmap = childResource->GetBitmap(); + if (!bitmap.Ok()) { bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); - childResource->SetBitmap(bitmap); + ((wxItemResource*) childResource)->SetBitmap(bitmap); } -#if USE_BITMAP_MESSAGE - if (bitmap) - control = new wxStaticBitmap(parent, id, *bitmap, - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), +#if wxUSE_BITMAP_MESSAGE + if (bitmap.Ok()) + control = new wxStaticBitmap(parent, id, bitmap, pos, size, childResource->GetStyle(), childResource->GetName()); #endif } else { - control = new wxStaticText(parent, id, childResource->GetTitle(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxStaticText(parent, id, childResource->GetTitle(), pos, size, childResource->GetStyle(), childResource->GetName()); } } else if (itemType == wxString("wxText") || itemType == wxString("wxTextCtrl") || itemType == wxString("wxMultiText")) { - control = new wxTextCtrl(parent, id, childResource->GetValue4(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxTextCtrl(parent, id, childResource->GetValue4(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); } else if (itemType == wxString("wxCheckBox")) { - control = new wxCheckBox(parent, id, childResource->GetTitle(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxCheckBox(parent, id, childResource->GetTitle(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); ((wxCheckBox *)control)->SetValue((childResource->GetValue1() != 0)); } -#if USE_GAUGE +#if wxUSE_GAUGE else if (itemType == wxString("wxGauge")) { - control = new wxGauge(parent, id, (int)childResource->GetValue2(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxGauge(parent, id, (int)childResource->GetValue2(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); ((wxGauge *)control)->SetValue((int)childResource->GetValue1()); } #endif -#if USE_RADIOBUTTON +#if wxUSE_RADIOBUTTON else if (itemType == wxString("wxRadioButton")) { control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); } #endif -#if USE_SCROLLBAR +#if wxUSE_SCROLLBAR else if (itemType == wxString("wxScrollBar")) { - control = new wxScrollBar(parent, id, - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxScrollBar(parent, id, pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1()); ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2()); @@ -453,28 +384,24 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe else if (itemType == wxString("wxSlider")) { control = new wxSlider(parent, id, (int)childResource->GetValue1(), - (int)childResource->GetValue2(), (int)childResource->GetValue3(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); } else if (itemType == wxString("wxGroupBox") || itemType == wxString("wxStaticBox")) { - control = new wxStaticBox(parent, id, childResource->GetTitle(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size, childResource->GetStyle(), childResource->GetName()); } else if (itemType == wxString("wxListBox")) { - wxStringList *stringList = childResource->GetStringValues(); - wxString *strings = NULL; + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList && (stringList->Number() > 0)) + if (stringList.Number() > 0) { - noStrings = stringList->Number(); + noStrings = stringList.Number(); strings = new wxString[noStrings]; - wxNode *node = stringList->First(); + wxNode *node = stringList.First(); int i = 0; while (node) { @@ -483,9 +410,7 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe node = node->Next(); } } - control = new wxListBox(parent, id, - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxListBox(parent, id, pos, size, noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) @@ -493,14 +418,14 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe } else if (itemType == wxString("wxChoice")) { - wxStringList *stringList = childResource->GetStringValues(); - wxString *strings = NULL; + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList && (stringList->Number() > 0)) + if (stringList.Number() > 0) { - noStrings = stringList->Number(); + noStrings = stringList.Number(); strings = new wxString[noStrings]; - wxNode *node = stringList->First(); + wxNode *node = stringList.First(); int i = 0; while (node) { @@ -509,25 +434,23 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe node = node->Next(); } } - control = new wxChoice(parent, id, - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxChoice(parent, id, pos, size, noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) delete[] strings; } -#if USE_COMBOBOX +#if wxUSE_COMBOBOX else if (itemType == wxString("wxComboBox")) { - wxStringList *stringList = childResource->GetStringValues(); - wxString *strings = NULL; + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList && (stringList->Number() > 0)) + if (stringList.Number() > 0) { - noStrings = stringList->Number(); + noStrings = stringList.Number(); strings = new wxString[noStrings]; - wxNode *node = stringList->First(); + wxNode *node = stringList.First(); int i = 0; while (node) { @@ -536,9 +459,7 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe node = node->Next(); } } - control = new wxComboBox(parent, id, childResource->GetValue4(), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size, noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); if (strings) @@ -547,14 +468,14 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe #endif else if (itemType == wxString("wxRadioBox")) { - wxStringList *stringList = childResource->GetStringValues(); - wxString *strings = NULL; + wxStringList& stringList = childResource->GetStringValues(); + wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList && (stringList->Number() > 0)) + if (stringList.Number() > 0) { - noStrings = stringList->Number(); + noStrings = stringList.Number(); strings = new wxString[noStrings]; - wxNode *node = stringList->First(); + wxNode *node = stringList.First(); int i = 0; while (node) { @@ -563,9 +484,7 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe node = node->Next(); } } - control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), - wxPoint(childResource->GetX(), childResource->GetY()), - wxSize(childResource->GetWidth(), childResource->GetHeight()), + control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size, noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); @@ -573,8 +492,15 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe delete[] strings; } - if (control && childResource->GetFont()) - control->SetFont(*childResource->GetFont()); + if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) + { + // Don't set font; will be inherited from parent. + } + else + { + if (control && childResource->GetFont().Ok()) + control->SetFont(childResource->GetFont()); + } return control; } @@ -582,15 +508,15 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, wxItemResource *childRe * Interpret database as a series of resources */ -bool wxResourceInterpretResources(wxResourceTable& table, PrologDatabase& db) +bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db) { wxNode *node = db.First(); while (node) { - PrologExpr *clause = (PrologExpr *)node->Data(); + wxExpr *clause = (wxExpr *)node->Data(); wxString functor(clause->Functor()); - wxItemResource *item = NULL; + wxItemResource *item = (wxItemResource *) NULL; if (functor == "dialog") item = wxResourceInterpretDialog(table, clause); else if (functor == "panel") @@ -609,7 +535,7 @@ bool wxResourceInterpretResources(wxResourceTable& table, PrologDatabase& db) if (item) { // Remove any existing resource of same name - if (item->GetName()) + if (item->GetName() != "") table.DeleteResource(item->GetName()); table.AddResource(item); } @@ -636,19 +562,19 @@ static bool wxIsValidControlClass(const wxString& c) return FALSE; } -wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, PrologExpr *expr, bool isPanel) +wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel) { wxItemResource *dialogItem = new wxItemResource; if (isPanel) dialogItem->SetType("wxPanel"); else dialogItem->SetType("wxDialog"); - char *style = NULL; - char *title = NULL; - char *name = NULL; - char *backColourHex = NULL; - char *labelColourHex = NULL; - char *buttonColourHex = NULL; + wxString style = ""; + wxString title = ""; + wxString name = ""; + wxString backColourHex = ""; + wxString labelColourHex = ""; + wxString buttonColourHex = ""; long windowStyle = wxDEFAULT_DIALOG_STYLE; if (isPanel) @@ -656,81 +582,79 @@ wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, PrologExpr *ex int x = 0; int y = 0; int width = -1; int height = -1; int isModal = 0; - PrologExpr *labelFontExpr = NULL; - PrologExpr *buttonFontExpr = NULL; - PrologExpr *fontExpr = NULL; - expr->AssignAttributeValue("style", &style); - expr->AssignAttributeValue("name", &name); - expr->AssignAttributeValue("title", &title); - expr->AssignAttributeValue("x", &x); - expr->AssignAttributeValue("y", &y); - expr->AssignAttributeValue("width", &width); - expr->AssignAttributeValue("height", &height); - expr->AssignAttributeValue("modal", &isModal); - expr->AssignAttributeValue("label_font", &labelFontExpr); - expr->AssignAttributeValue("button_font", &buttonFontExpr); - expr->AssignAttributeValue("font", &fontExpr); - expr->AssignAttributeValue("background_colour", &backColourHex); - expr->AssignAttributeValue("label_colour", &labelColourHex); - expr->AssignAttributeValue("button_colour", &buttonColourHex); + wxExpr *labelFontExpr = (wxExpr *) NULL; + wxExpr *buttonFontExpr = (wxExpr *) NULL; + wxExpr *fontExpr = (wxExpr *) NULL; + expr->GetAttributeValue("style", style); + expr->GetAttributeValue("name", name); + expr->GetAttributeValue("title", title); + expr->GetAttributeValue("x", x); + expr->GetAttributeValue("y", y); + expr->GetAttributeValue("width", width); + expr->GetAttributeValue("height", height); + expr->GetAttributeValue("modal", isModal); + expr->GetAttributeValue("label_font", &labelFontExpr); + expr->GetAttributeValue("button_font", &buttonFontExpr); + expr->GetAttributeValue("font", &fontExpr); + expr->GetAttributeValue("background_colour", backColourHex); + expr->GetAttributeValue("label_colour", labelColourHex); + expr->GetAttributeValue("button_colour", buttonColourHex); + + int useDialogUnits = 0; + expr->GetAttributeValue("use_dialog_units", useDialogUnits); + if (useDialogUnits != 0) + dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS); + + int useDefaults = 0; + expr->GetAttributeValue("use_system_defaults", useDefaults); + if (useDefaults != 0) + dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS); long id = 0; expr->GetAttributeValue("id", id); dialogItem->SetId(id); - if (style) + if (style != "") { windowStyle = wxParseWindowStyle(style); } dialogItem->SetStyle(windowStyle); dialogItem->SetValue1(isModal); - if (name) - dialogItem->SetName(name); - if (title) - dialogItem->SetTitle(title); + dialogItem->SetName(name); + dialogItem->SetTitle(title); dialogItem->SetSize(x, y, width, height); - if (backColourHex) + if (backColourHex != "") { int r = 0; int g = 0; int b = 0; - r = wxHexToDec(backColourHex); - g = wxHexToDec(backColourHex+2); - b = wxHexToDec(backColourHex+4); - dialogItem->SetBackgroundColour(new wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); - delete[] backColourHex; + r = wxHexToDec(backColourHex.Mid(0, 2)); + g = wxHexToDec(backColourHex.Mid(2, 2)); + b = wxHexToDec(backColourHex.Mid(4, 2)); + dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); } - if (labelColourHex) + if (labelColourHex != "") { int r = 0; int g = 0; int b = 0; - r = wxHexToDec(labelColourHex); - g = wxHexToDec(labelColourHex+2); - b = wxHexToDec(labelColourHex+4); - dialogItem->SetLabelColour(new wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); - delete[] labelColourHex; + r = wxHexToDec(labelColourHex.Mid(0, 2)); + g = wxHexToDec(labelColourHex.Mid(2, 2)); + b = wxHexToDec(labelColourHex.Mid(4, 2)); + dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); } - if (buttonColourHex) + if (buttonColourHex != "") { int r = 0; int g = 0; int b = 0; - r = wxHexToDec(buttonColourHex); - g = wxHexToDec(buttonColourHex+2); - b = wxHexToDec(buttonColourHex+4); - dialogItem->SetButtonColour(new wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); - delete[] buttonColourHex; + r = wxHexToDec(buttonColourHex.Mid(0, 2)); + g = wxHexToDec(buttonColourHex.Mid(2, 2)); + b = wxHexToDec(buttonColourHex.Mid(4, 2)); + dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); } - if (name) - delete[] name; - if (title) - delete[] title; - if (style) - delete[] style; - if (fontExpr) dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr)); else if (buttonFontExpr) @@ -739,7 +663,7 @@ wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, PrologExpr *ex dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr)); // Now parse all controls - PrologExpr *controlExpr = expr->GetFirst(); + wxExpr *controlExpr = expr->GetFirst(); while (controlExpr) { if (controlExpr->Number() == 3) @@ -748,7 +672,7 @@ wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, PrologExpr *ex if (controlKeyword != "" && controlKeyword == "control") { // The value part: always a list. - PrologExpr *listExpr = controlExpr->Nth(2); + wxExpr *listExpr = controlExpr->Nth(2); if (listExpr->Type() == PrologList) { wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr); @@ -764,7 +688,7 @@ wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, PrologExpr *ex return dialogItem; } -wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *expr) +wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr) { wxItemResource *controlItem = new wxItemResource; @@ -780,7 +704,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e int x = 0; int y = 0; int width = -1; int height = -1; int count = 0; - PrologExpr *expr1 = expr->Nth(0); + wxExpr *expr1 = expr->Nth(0); if ( expr1->Type() == PrologString || expr1->Type() == PrologWord ) { @@ -792,7 +716,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e else { wxString str(expr1->StringValue()); - id = wxResourceGetIdentifier(WXSTRINGCAST str, &table); + id = wxResourceGetIdentifier(str, &table); if (id == 0) { wxLogWarning(_("Could not resolve control class or id '%s'. " @@ -800,7 +724,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e "(see manual for caveats)"), (const char*) expr1->StringValue()); delete controlItem; - return NULL; + return (wxItemResource *) NULL; } else { @@ -828,7 +752,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e if (expr1) { style = expr1->StringValue(); - windowStyle = wxParseWindowStyle(WXSTRINGCAST style); + windowStyle = wxParseWindowStyle(style); } expr1 = expr->Nth(count); @@ -857,10 +781,10 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e height = (int)expr1->IntegerValue(); controlItem->SetStyle(windowStyle); - controlItem->SetName(WXSTRINGCAST name); - controlItem->SetTitle(WXSTRINGCAST title); + controlItem->SetName(name); + controlItem->SetTitle(title); controlItem->SetSize(x, y, width, height); - controlItem->SetType(WXSTRINGCAST controlType); + controlItem->SetType(controlType); controlItem->SetId(id); if (controlType == "wxButton") @@ -869,7 +793,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) { wxString str(expr->Nth(count)->StringValue()); - controlItem->SetValue4(WXSTRINGCAST str); + controlItem->SetValue4(str); count ++; if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); @@ -886,7 +810,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); } } -#if USE_RADIOBUTTON +#if wxUSE_RADIOBUTTON else if (controlType == "wxRadioButton") { // Check for default value @@ -899,13 +823,13 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e } } #endif - else if (controlType == "wxText" || controlType == "wxTextCtrl") + else if (controlType == "wxText" || controlType == "wxTextCtrl" || controlType == "wxMultiText") { // Check for default value if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) { wxString str(expr->Nth(count)->StringValue()); - controlItem->SetValue4(WXSTRINGCAST str); + controlItem->SetValue4(str); count ++; if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) @@ -924,7 +848,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) { wxString str(expr->Nth(count)->StringValue()); - controlItem->SetValue4(WXSTRINGCAST str); + controlItem->SetValue4(str); count ++; if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); @@ -1023,22 +947,22 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e } else if (controlType == "wxListBox") { - PrologExpr *valueList = NULL; + wxExpr *valueList = (wxExpr *) NULL; if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList)) { - wxStringList *stringList = new wxStringList; - PrologExpr *stringExpr = valueList->GetFirst(); + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); while (stringExpr) { - stringList->Add(stringExpr->StringValue()); + stringList.Add(stringExpr->StringValue()); stringExpr = stringExpr->GetNext(); } controlItem->SetStringValues(stringList); count ++; // Check for wxSINGLE/wxMULTIPLE - PrologExpr *mult = NULL; + wxExpr *mult = (wxExpr *) NULL; controlItem->SetValue1(wxLB_SINGLE); if ((mult = expr->Nth(count)) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord))) { @@ -1060,15 +984,15 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e } else if (controlType == "wxChoice") { - PrologExpr *valueList = NULL; + wxExpr *valueList = (wxExpr *) NULL; // Check for default value list if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList)) { - wxStringList *stringList = new wxStringList; - PrologExpr *stringExpr = valueList->GetFirst(); + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); while (stringExpr) { - stringList->Add(stringExpr->StringValue()); + stringList.Add(stringExpr->StringValue()); stringExpr = stringExpr->GetNext(); } controlItem->SetStringValues(stringList); @@ -1085,26 +1009,26 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e } } } -#if USE_COMBOBOX +#if wxUSE_COMBOBOX else if (controlType == "wxComboBox") { - PrologExpr *textValue = expr->Nth(count); + wxExpr *textValue = expr->Nth(count); if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord)) { wxString str(textValue->StringValue()); - controlItem->SetValue4(WXSTRINGCAST str); + controlItem->SetValue4(str); count ++; - PrologExpr *valueList = NULL; + wxExpr *valueList = (wxExpr *) NULL; // Check for default value list if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList)) { - wxStringList *stringList = new wxStringList; - PrologExpr *stringExpr = valueList->GetFirst(); + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); while (stringExpr) { - stringList->Add(stringExpr->StringValue()); + stringList.Add(stringExpr->StringValue()); stringExpr = stringExpr->GetNext(); } controlItem->SetStringValues(stringList); @@ -1123,18 +1047,18 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e } } #endif -#if 0 +#if 1 else if (controlType == "wxRadioBox") { - PrologExpr *valueList = NULL; + wxExpr *valueList = (wxExpr *) NULL; // Check for default value list if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList)) { - wxStringList *stringList = new wxStringList; - PrologExpr *stringExpr = valueList->GetFirst(); + wxStringList stringList; + wxExpr *stringExpr = valueList->GetFirst(); while (stringExpr) { - stringList->Add(stringExpr->StringValue()); + stringList.Add(stringExpr->StringValue()); stringExpr = stringExpr->GetNext(); } controlItem->SetStringValues(stringList); @@ -1163,26 +1087,26 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, PrologExpr *e else { delete controlItem; - return NULL; + return (wxItemResource *) NULL; } return controlItem; } // Forward declaration -wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr); +wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr); /* * Interpet a menu item */ -wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, PrologExpr *expr) +wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr) { wxItemResource *item = new wxItemResource; - PrologExpr *labelExpr = expr->Nth(0); - PrologExpr *idExpr = expr->Nth(1); - PrologExpr *helpExpr = expr->Nth(2); - PrologExpr *checkableExpr = expr->Nth(3); + wxExpr *labelExpr = expr->Nth(0); + wxExpr *idExpr = expr->Nth(1); + wxExpr *helpExpr = expr->Nth(2); + wxExpr *checkableExpr = expr->Nth(3); // Further keywords/attributes to follow sometime... if (expr->Number() == 0) @@ -1198,7 +1122,7 @@ wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, PrologExpr * if (labelExpr) { wxString str(labelExpr->StringValue()); - item->SetTitle(WXSTRINGCAST str); + item->SetTitle(str); } if (idExpr) { @@ -1207,7 +1131,7 @@ wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, PrologExpr * if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord)) { wxString str(idExpr->StringValue()); - id = wxResourceGetIdentifier(WXSTRINGCAST str, &table); + id = wxResourceGetIdentifier(str, &table); if (id == 0) { wxLogWarning(_("Could not resolve menu id '%s'. " @@ -1223,13 +1147,13 @@ wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, PrologExpr * if (helpExpr) { wxString str(helpExpr->StringValue()); - item->SetValue4(WXSTRINGCAST str); + item->SetValue4(str); } if (checkableExpr) item->SetValue2(checkableExpr->IntegerValue()); // Find the first expression that's a list, for submenu - PrologExpr *subMenuExpr = expr->GetFirst(); + wxExpr *subMenuExpr = expr->GetFirst(); while (subMenuExpr && (subMenuExpr->Type() != PrologList)) subMenuExpr = subMenuExpr->GetNext(); @@ -1247,12 +1171,12 @@ wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, PrologExpr * * Interpret a nested list as a menu */ /* -wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr) +wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr) { wxItemResource *menu = new wxItemResource; // menu->SetType(wxTYPE_MENU); menu->SetType("wxMenu"); - PrologExpr *element = expr->GetFirst(); + wxExpr *element = expr->GetFirst(); while (element) { wxItemResource *item = wxResourceInterpretMenuItem(table, element); @@ -1264,41 +1188,39 @@ wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *exp } */ -wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, PrologExpr *expr) +wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr) { - PrologExpr *listExpr = NULL; - expr->AssignAttributeValue("menu", &listExpr); + wxExpr *listExpr = (wxExpr *) NULL; + expr->GetAttributeValue("menu", &listExpr); if (!listExpr) - return NULL; + return (wxItemResource *) NULL; wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); if (!menuResource) - return NULL; - - char *name = NULL; - expr->AssignAttributeValue("name", &name); - if (name) + return (wxItemResource *) NULL; + + wxString name; + if (expr->GetAttributeValue("name", name)) { menuResource->SetName(name); - delete[] name; } return menuResource; } -wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, PrologExpr *expr) +wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr) { - PrologExpr *listExpr = NULL; - expr->AssignAttributeValue("menu", &listExpr); + wxExpr *listExpr = (wxExpr *) NULL; + expr->GetAttributeValue("menu", &listExpr); if (!listExpr) - return NULL; + return (wxItemResource *) NULL; wxItemResource *resource = new wxItemResource; resource->SetType("wxMenu"); // resource->SetType(wxTYPE_MENU); - PrologExpr *element = listExpr->GetFirst(); + wxExpr *element = listExpr->GetFirst(); while (element) { wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); @@ -1306,36 +1228,32 @@ wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, PrologExpr *e element = element->GetNext(); } - char *name = NULL; - expr->AssignAttributeValue("name", &name); - if (name) + wxString name; + if (expr->GetAttributeValue("name", name)) { resource->SetName(name); - delete[] name; } return resource; } -wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), PrologExpr *WXUNUSED(expr)) +wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr)) { - return NULL; + return (wxItemResource *) NULL; } -wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), PrologExpr *expr) +wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr) { wxItemResource *bitmapItem = new wxItemResource; // bitmapItem->SetType(wxTYPE_BITMAP); bitmapItem->SetType("wxBitmap"); - char *name = NULL; - expr->AssignAttributeValue("name", &name); - if (name) + wxString name; + if (expr->GetAttributeValue("name", name)) { bitmapItem->SetName(name); - delete[] name; } // Now parse all bitmap specifications - PrologExpr *bitmapExpr = expr->GetFirst(); + wxExpr *bitmapExpr = expr->GetFirst(); while (bitmapExpr) { if (bitmapExpr->Number() == 3) @@ -1344,7 +1262,7 @@ wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), Prol if (bitmapKeyword == "bitmap" || bitmapKeyword == "icon") { // The value part: always a list. - PrologExpr *listExpr = bitmapExpr->Nth(2); + wxExpr *listExpr = bitmapExpr->Nth(2); if (listExpr->Type() == PrologList) { wxItemResource *bitmapSpec = new wxItemResource; @@ -1353,21 +1271,19 @@ wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), Prol // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution] // where everything after 'filename' is optional. - PrologExpr *nameExpr = listExpr->Nth(0); - PrologExpr *typeExpr = listExpr->Nth(1); - PrologExpr *platformExpr = listExpr->Nth(2); - PrologExpr *coloursExpr = listExpr->Nth(3); - PrologExpr *xresExpr = listExpr->Nth(4); - PrologExpr *yresExpr = listExpr->Nth(5); + wxExpr *nameExpr = listExpr->Nth(0); + wxExpr *typeExpr = listExpr->Nth(1); + wxExpr *platformExpr = listExpr->Nth(2); + wxExpr *coloursExpr = listExpr->Nth(3); + wxExpr *xresExpr = listExpr->Nth(4); + wxExpr *yresExpr = listExpr->Nth(5); if (nameExpr && nameExpr->StringValue()) { - wxString str(nameExpr->StringValue()); - bitmapSpec->SetName(WXSTRINGCAST str); + bitmapSpec->SetName(nameExpr->StringValue()); } if (typeExpr && typeExpr->StringValue()) { - wxString str(typeExpr->StringValue()); - bitmapSpec->SetValue1(wxParseWindowStyle(WXSTRINGCAST str)); + bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue())); } else bitmapSpec->SetValue1(0); @@ -1407,7 +1323,7 @@ wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), Prol return bitmapItem; } -wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, PrologExpr *expr) +wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr) { wxItemResource *item = wxResourceInterpretBitmap(table, expr); if (item) @@ -1417,14 +1333,14 @@ wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, PrologExpr *expr return item; } else - return NULL; + return (wxItemResource *) NULL; } // Interpret list expression as a font -wxFont *wxResourceInterpretFontSpec(PrologExpr *expr) +wxFont wxResourceInterpretFontSpec(wxExpr *expr) { if (expr->Type() != PrologList) - return NULL; + return wxNullFont; int point = 10; int family = wxSWISS; @@ -1433,12 +1349,12 @@ wxFont *wxResourceInterpretFontSpec(PrologExpr *expr) int underline = 0; wxString faceName(""); - PrologExpr *pointExpr = expr->Nth(0); - PrologExpr *familyExpr = expr->Nth(1); - PrologExpr *styleExpr = expr->Nth(2); - PrologExpr *weightExpr = expr->Nth(3); - PrologExpr *underlineExpr = expr->Nth(4); - PrologExpr *faceNameExpr = expr->Nth(5); + wxExpr *pointExpr = expr->Nth(0); + wxExpr *familyExpr = expr->Nth(1); + wxExpr *styleExpr = expr->Nth(2); + wxExpr *weightExpr = expr->Nth(3); + wxExpr *underlineExpr = expr->Nth(4); + wxExpr *faceNameExpr = expr->Nth(5); if (pointExpr) point = (int)pointExpr->IntegerValue(); @@ -1446,27 +1362,24 @@ wxFont *wxResourceInterpretFontSpec(PrologExpr *expr) if (familyExpr) { str = familyExpr->StringValue(); - family = (int)wxParseWindowStyle(WXSTRINGCAST str); + family = (int)wxParseWindowStyle(str); } if (styleExpr) { str = styleExpr->StringValue(); - style = (int)wxParseWindowStyle(WXSTRINGCAST str); + style = (int)wxParseWindowStyle(str); } if (weightExpr) { str = weightExpr->StringValue(); - weight = (int)wxParseWindowStyle(WXSTRINGCAST str); + weight = (int)wxParseWindowStyle(str); } if (underlineExpr) underline = (int)underlineExpr->IntegerValue(); if (faceNameExpr) faceName = faceNameExpr->StringValue(); - char *faceName1 = NULL; - if (faceName != "") - faceName1 = WXSTRINGCAST faceName; - wxFont *font = wxTheFontList->FindOrCreateFont(point, family, style, weight, (underline != 0), faceName1); + wxFont font(point, family, style, weight, (underline != 0), faceName); return font; } @@ -1474,7 +1387,7 @@ wxFont *wxResourceInterpretFontSpec(PrologExpr *expr) * (Re)allocate buffer for reading in from resource file */ -bool wxReallocateResourceBuffer(void) +bool wxReallocateResourceBuffer() { if (!wxResourceBuffer) { @@ -1607,7 +1520,7 @@ bool wxGetResourceToken(FILE *fd) with possible comments. */ -bool wxResourceReadOneResource(FILE *fd, PrologDatabase& db, bool *eof, wxResourceTable *table) +bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -1745,10 +1658,10 @@ bool wxResourceReadOneResource(FILE *fd, PrologDatabase& db, bool *eof, wxResour * "wxSYSTEM_MENU | wxBORDER" -> integer */ -char *wxResourceParseWord(char *s, int *i) +char* wxResourceParseWord(char*s, int *i) { if (!s) - return NULL; + return (char*) NULL; static char buf[150]; int len = strlen(s); @@ -1770,7 +1683,7 @@ char *wxResourceParseWord(char *s, int *i) } *i = ii; if (j == 0) - return NULL; + return (char*) NULL; else return buf; } @@ -2033,12 +1946,12 @@ static wxResourceBitListStruct wxResourceBitListTable[] = static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct)); -long wxParseWindowStyle(char *bitListString) +long wxParseWindowStyle(const wxString& bitListString) { int i = 0; char *word; long bitList = 0; - while ((word = wxResourceParseWord(bitListString, &i))) + while ((word = wxResourceParseWord((char*) (const char*) bitListString, &i))) { bool found = FALSE; int j; @@ -2063,7 +1976,7 @@ long wxParseWindowStyle(char *bitListString) * depth and appropriate type. */ -wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) +wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2073,13 +1986,13 @@ wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) { if (!item->GetType() || strcmp(item->GetType(), "wxBitmap") != 0) { - wxLogWarning(_("%s not a bitmap resource specification."), resource); - return NULL; + wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource); + return wxNullBitmap; } int thisDepth = wxDisplayDepth(); long thisNoColours = (long)pow(2.0, (double)thisDepth); - wxItemResource *optResource = NULL; + wxItemResource *optResource = (wxItemResource *) NULL; // Try to find optimum bitmap for this platform/colour depth wxNode *node = item->GetChildren().First(); @@ -2125,7 +2038,7 @@ wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) break; } #endif -#ifdef __X__ +#ifdef __WXGTK__ case RESOURCE_PLATFORM_X: { if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) @@ -2160,24 +2073,23 @@ wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) } // If no matching resource, fail. if (!optResource) - return NULL; + return wxNullBitmap; - char *name = optResource->GetName(); + wxString name = optResource->GetName(); int bitmapType = (int)optResource->GetValue1(); - wxBitmap *bitmap = NULL; switch (bitmapType) { case wxBITMAP_TYPE_XBM_DATA: { -#ifdef __X__ +#ifdef __WXGTK__ wxItemResource *item = table->FindResource(name); if (!item) { wxLogWarning(_("Failed to find XBM resource %s.\n" - "Forgot to use wxResourceLoadBitmapData?"), name); - return NULL; + "Forgot to use wxResourceLoadBitmapData?"), (const char*) name); + return (wxBitmap *) NULL; } - bitmap = new wxBitmap((char *)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); + return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ; #else wxLogWarning(_("No XBM facility available!")); #endif @@ -2185,15 +2097,15 @@ wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) } case wxBITMAP_TYPE_XPM_DATA: { -#if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW) +#if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW) wxItemResource *item = table->FindResource(name); if (!item) { wxLogWarning(_("Failed to find XPM resource %s.\n" - "Forgot to use wxResourceLoadBitmapData?"), name); - return NULL; + "Forgot to use wxResourceLoadBitmapData?"), (const char*) name); + return (wxBitmap *) NULL; } - bitmap = new wxBitmap(item->GetValue1()); + return wxBitmap(item->GetValue1()); #else wxLogWarning(_("No XPM facility available!")); #endif @@ -2201,27 +2113,16 @@ wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) } default: { - bitmap = new wxBitmap(name, bitmapType); + return wxBitmap(name, bitmapType); break; } } - if (!bitmap) - return NULL; - - if (bitmap->Ok()) - { - return bitmap; - } - else - { - delete bitmap; - return NULL; - } + return wxNullBitmap; } else { - wxLogWarning(_("Bitmap resource specification %s not found."), resource); - return NULL; + wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource); + return wxNullBitmap; } } @@ -2230,23 +2131,23 @@ wxBitmap *wxResourceCreateBitmap(char *resource, wxResourceTable *table) * depth and appropriate type. */ -wxIcon *wxResourceCreateIcon(char *resource, wxResourceTable *table) +wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) { if (!table) - table = wxDefaultResourceTable; + table = wxDefaultResourceTable; wxItemResource *item = table->FindResource(resource); if (item) { - if (!item->GetType() || strcmp(item->GetType(), "wxIcon") != 0) + if ((item->GetType() == "") || strcmp(item->GetType(), "wxIcon") != 0) { - wxLogWarning(_("%s not an icon resource specification."), resource); - return NULL; + wxLogWarning(_("%s not an icon resource specification."), (const char*) resource); + return wxNullIcon; } int thisDepth = wxDisplayDepth(); long thisNoColours = (long)pow(2.0, (double)thisDepth); - wxItemResource *optResource = NULL; + wxItemResource *optResource = (wxItemResource *) NULL; // Try to find optimum icon for this platform/colour depth wxNode *node = item->GetChildren().First(); @@ -2292,7 +2193,7 @@ wxIcon *wxResourceCreateIcon(char *resource, wxResourceTable *table) break; } #endif -#ifdef __X__ +#ifdef __WXGTK__ case RESOURCE_PLATFORM_X: { if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) @@ -2327,24 +2228,23 @@ wxIcon *wxResourceCreateIcon(char *resource, wxResourceTable *table) } // If no matching resource, fail. if (!optResource) - return NULL; + return wxNullIcon; - char *name = optResource->GetName(); + wxString name = optResource->GetName(); int bitmapType = (int)optResource->GetValue1(); - wxIcon *icon = NULL; switch (bitmapType) { case wxBITMAP_TYPE_XBM_DATA: { -#ifdef __X__ +#ifdef __WXGTK__ wxItemResource *item = table->FindResource(name); if (!item) { wxLogWarning(_("Failed to find XBM resource %s.\n" - "Forgot to use wxResourceLoadIconData?"), name); - return NULL; + "Forgot to use wxResourceLoadIconData?"), (const char*) name); + return (wxIcon *) NULL; } - icon = new wxIcon((char *)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); + return wxIcon((char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); #else wxLogWarning(_("No XBM facility available!")); #endif @@ -2354,7 +2254,7 @@ wxIcon *wxResourceCreateIcon(char *resource, wxResourceTable *table) { // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS *** /* -#if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW) +#if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW) wxItemResource *item = table->FindResource(name); if (!item) { @@ -2363,7 +2263,7 @@ wxIcon *wxResourceCreateIcon(char *resource, wxResourceTable *table) wxLogWarning(buf); return NULL; } - icon = new wxIcon((char **)item->GetValue1()); + return wxIcon((char **)item->GetValue1()); #else wxLogWarning(_("No XPM facility available!")); #endif @@ -2373,27 +2273,20 @@ wxIcon *wxResourceCreateIcon(char *resource, wxResourceTable *table) } default: { - icon = new wxIcon(name, bitmapType); +#ifdef __WXGTK__ + wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource); +#else + return wxIcon(name, bitmapType); +#endif break; } } - if (!icon) - return NULL; - - if (icon->Ok()) - { - return icon; - } - else - { - delete icon; - return NULL; - } + return wxNullIcon; } else { - wxLogWarning(_("Icon resource specification %s not found."), resource); - return NULL; + wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource); + return (wxIcon *) NULL; } } @@ -2404,7 +2297,7 @@ wxMenu *wxResourceCreateMenu(wxItemResource *item) while (node) { wxItemResource *child = (wxItemResource *)node->Data(); - if (child->GetType() && strcmp(child->GetType(), "wxMenuSeparator") == 0) + if ((child->GetType() != "") && (child->GetType() == "wxMenuSeparator")) menu->AppendSeparator(); else if (child->GetChildren().Number() > 0) { @@ -2421,13 +2314,13 @@ wxMenu *wxResourceCreateMenu(wxItemResource *item) return menu; } -wxMenuBar *wxResourceCreateMenuBar(char *resource, wxResourceTable *table, wxMenuBar *menuBar) +wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar) { if (!table) table = wxDefaultResourceTable; wxItemResource *menuResource = table->FindResource(resource); - if (menuResource && menuResource->GetType() && strcmp(menuResource->GetType(), "wxMenu") == 0) + if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu")) { if (!menuBar) menuBar = new wxMenuBar; @@ -2442,23 +2335,23 @@ wxMenuBar *wxResourceCreateMenuBar(char *resource, wxResourceTable *table, wxMen } return menuBar; } - return NULL; + return (wxMenuBar *) NULL; } -wxMenu *wxResourceCreateMenu(char *resource, wxResourceTable *table) +wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; wxItemResource *menuResource = table->FindResource(resource); - if (menuResource && menuResource->GetType() && strcmp(menuResource->GetType(), "wxMenu") == 0) + if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu")) // if (menuResource && (menuResource->GetType() == wxTYPE_MENU)) return wxResourceCreateMenu(menuResource); - return NULL; + return (wxMenu *) NULL; } // Global equivalents (so don't have to refer to default table explicitly) -bool wxResourceParseData(char *resource, wxResourceTable *table) +bool wxResourceParseData(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2466,7 +2359,7 @@ bool wxResourceParseData(char *resource, wxResourceTable *table) return table->ParseResourceData(resource); } -bool wxResourceParseFile(char *filename, wxResourceTable *table) +bool wxResourceParseFile(const wxString& filename, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2475,7 +2368,7 @@ bool wxResourceParseFile(char *filename, wxResourceTable *table) } // Register XBM/XPM data -bool wxResourceRegisterBitmapData(char *name, char bits[], int width, int height, wxResourceTable *table) +bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2483,7 +2376,7 @@ bool wxResourceRegisterBitmapData(char *name, char bits[], int width, int height return table->RegisterResourceBitmapData(name, bits, width, height); } -bool wxResourceRegisterBitmapData(char *name, char **data, wxResourceTable *table) +bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2503,7 +2396,7 @@ void wxResourceClear(wxResourceTable *table) * Identifiers */ -bool wxResourceAddIdentifier(char *name, int value, wxResourceTable *table) +bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2512,7 +2405,7 @@ bool wxResourceAddIdentifier(char *name, int value, wxResourceTable *table) return TRUE; } -int wxResourceGetIdentifier(char *name, wxResourceTable *table) +int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2524,7 +2417,7 @@ int wxResourceGetIdentifier(char *name, wxResourceTable *table) * Parse #include file for #defines (only) */ -bool wxResourceParseIncludeFile(char *f, wxResourceTable *table) +bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2571,7 +2464,7 @@ static int getc_string(char *s) } } -static int ungetc_string(void) +static int ungetc_string() { wxResourceStringPtr --; return 0; @@ -2693,7 +2586,7 @@ bool wxGetResourceTokenString(char *s) with possible comments. */ -bool wxResourceReadOneResourceString(char *s, PrologDatabase& db, bool *eof, wxResourceTable *table) +bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -2847,7 +2740,7 @@ bool wxResourceParseString(char *s, wxResourceTable *table) } } - PrologDatabase db; + wxExprDatabase db; wxResourceStringPtr = 0; bool eof = FALSE; @@ -2873,61 +2766,86 @@ bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, ! ((strcmp(resource->GetType(), "wxDialog") == 0) || (strcmp(resource->GetType(), "wxPanel") == 0))) return FALSE; - char *title = resource->GetTitle(); + wxString title(resource->GetTitle()); long theWindowStyle = resource->GetStyle(); bool isModal = (resource->GetValue1() != 0); int x = resource->GetX(); int y = resource->GetY(); int width = resource->GetWidth(); int height = resource->GetHeight(); - char *name = resource->GetName(); - - wxFont *theFont = resource->GetFont(); + wxString name = resource->GetName(); if (IsKindOf(CLASSINFO(wxDialog))) { wxDialog *dialogBox = (wxDialog *)this; - long modalStyle = isModal ? wxDIALOG_MODAL : 0; + long modalStyle = isModal ? wxDIALOG_MODAL : 0; if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name)) return FALSE; - dialogBox->SetClientSize(width, height); + + // Only reset the client size if we know we're not going to do it again below. + if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0) + dialogBox->SetClientSize(width, height); + } + else if (IsKindOf(CLASSINFO(wxPanel))) + { + wxPanel* panel = (wxPanel *)this; + if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) + return FALSE; } else { - if (!((wxWindow *)this)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) + if (!this->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) return FALSE; } - if (theFont) - SetFont(*theFont); + if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) + { + // No need to do this since it's done in wxPanel or wxDialog constructor. + // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); + } + else + { + if (resource->GetFont().Ok()) + SetFont(resource->GetFont()); + if (resource->GetBackgroundColour().Ok()) + SetBackgroundColour(resource->GetBackgroundColour()); + } - if (resource->GetBackgroundColour()) - SetBackgroundColour(*resource->GetBackgroundColour()); + // Should have some kind of font at this point + if (!GetFont()->Ok()) + SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); + if (!GetBackgroundColour().Ok()) + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); + + // Only when we've created the window and set the font can we set the correct size, + // if based on dialog units. + if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) + { + wxSize sz = ConvertDialogToPixels(wxSize(width, height)); + SetClientSize(sz.x, sz.y); + + wxPoint pt = ConvertDialogToPixels(wxPoint(x, y)); + Move(pt.x, pt.y); + } - // TODO - if (resource->GetLabelColour()) - SetForegroundColour(*resource->GetLabelColour()); - else if (resource->GetButtonColour()) - SetForegroundColour(*resource->GetButtonColour()); - // Now create children wxNode *node = resource->GetChildren().First(); while (node) { wxItemResource *childResource = (wxItemResource *)node->Data(); - (void) CreateItem(childResource, table); + (void) CreateItem(childResource, resource, table); node = node->Next(); } return TRUE; } -wxControl *wxWindow::CreateItem(const wxItemResource *resource, const wxResourceTable *table) +wxControl *wxWindow::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - return table->CreateItem((wxWindow *)this, (wxItemResource *)resource); + return table->CreateItem((wxWindow *)this, resource, parentResource); } -#endif // USE_WX_RESOURCES +#endif // wxUSE_WX_RESOURCES