X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4a3bdee6a979146c426cd058e9bfe6b58135b124..d1a6e2b7a103d761fbc15e0e9c1c20ab53a849d9:/contrib/src/deprecated/resource.cpp?ds=inline diff --git a/contrib/src/deprecated/resource.cpp b/contrib/src/deprecated/resource.cpp index f1c718063a..3d0188a9ec 100644 --- a/contrib/src/deprecated/resource.cpp +++ b/contrib/src/deprecated/resource.cpp @@ -70,9 +70,12 @@ #include "wx/combobox.h" #endif -#include "wx/validate.h" +#include "wx/splitter.h" +#include "wx/toolbar.h" +#include "wx/validate.h" #include "wx/log.h" +#include "wx/module.h" #include #include @@ -86,6 +89,11 @@ #include "wx/deprecated/resource.h" #include "wx/deprecated/wxexpr.h" +#if !WXWIN_COMPATIBILITY_2_4 +static inline wxChar* copystring(const wxChar* s) + { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } +#endif + // Forward (private) declarations bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db); wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE); @@ -111,7 +119,8 @@ int wxResourceStringPtr = 0; void wxInitializeResourceSystem() { - wxDefaultResourceTable = new wxResourceTable; + if (!wxDefaultResourceTable) + wxDefaultResourceTable = new wxResourceTable; } void wxCleanUpResourceSystem() @@ -121,12 +130,21 @@ void wxCleanUpResourceSystem() delete[] wxResourceBuffer; } -#if 0 -void wxLogWarning(char *msg) +// Module to ensure the resource system data gets initialized +// and cleaned up. + +class wxResourceModule: public wxModule { - wxMessageBox(msg, _("Warning"), wxOK); -} -#endif +public: + wxResourceModule() : wxModule() {} + virtual bool OnInit() { wxInitializeResourceSystem(); return TRUE; } + virtual void OnExit() { wxCleanUpResourceSystem(); } + + DECLARE_DYNAMIC_CLASS(wxResourceModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxResourceModule, wxModule) + IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable) @@ -146,13 +164,13 @@ wxItemResource::wxItemResource() wxItemResource::~wxItemResource() { - wxNode *node = m_children.First(); + wxNode *node = m_children.GetFirst(); while (node) { - wxItemResource *item = (wxItemResource *)node->Data(); + wxItemResource *item = (wxItemResource *)node->GetData(); delete item; delete node; - node = m_children.First(); + node = m_children.GetFirst(); } } @@ -197,11 +215,10 @@ 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 = (wxNode *) NULL; - node = Next(); + wxNode *node = Next(); while (node != NULL) { - wxItemResource *parent = (wxItemResource *)node->Data(); + wxItemResource *parent = (wxItemResource *)node->GetData(); if (parent->GetChildren().Member(item)) { parent->GetChildren().DeleteObject(item); @@ -296,7 +313,7 @@ void wxResourceTable::ClearTable() while (node) { wxNode *next = Next(); - wxItemResource *item = (wxItemResource *)node->Data(); + wxItemResource *item = (wxItemResource *)node->GetData(); delete item; delete node; node = next; @@ -446,17 +463,17 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList.Number() > 0) + if (stringList.GetCount() > 0) { - noStrings = stringList.Number(); + noStrings = stringList.GetCount(); strings = new wxString[noStrings]; - wxNode *node = stringList.First(); + wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { - strings[i] = (wxChar *)node->Data(); + strings[i] = (wxChar *)node->GetData(); i ++; - node = node->Next(); + node = node->GetNext(); } } control = new wxListBox(parent, id, pos, size, @@ -470,17 +487,17 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList.Number() > 0) + if (stringList.GetCount() > 0) { - noStrings = stringList.Number(); + noStrings = stringList.GetCount(); strings = new wxString[noStrings]; - wxNode *node = stringList.First(); + wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { - strings[i] = (wxChar *)node->Data(); + strings[i] = (wxChar *)node->GetData(); i ++; - node = node->Next(); + node = node->GetNext(); } } control = new wxChoice(parent, id, pos, size, @@ -495,17 +512,17 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList.Number() > 0) + if (stringList.GetCount() > 0) { - noStrings = stringList.Number(); + noStrings = stringList.GetCount(); strings = new wxString[noStrings]; - wxNode *node = stringList.First(); + wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { - strings[i] = (wxChar *)node->Data(); + strings[i] = (wxChar *)node->GetData(); i ++; - node = node->Next(); + node = node->GetNext(); } } control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size, @@ -520,17 +537,17 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c wxStringList& stringList = childResource->GetStringValues(); wxString *strings = (wxString *) NULL; int noStrings = 0; - if (stringList.Number() > 0) + if (stringList.GetCount() > 0) { - noStrings = stringList.Number(); + noStrings = stringList.GetCount(); strings = new wxString[noStrings]; - wxNode *node = stringList.First(); + wxStringListNode *node = stringList.GetFirst(); int i = 0; while (node) { - strings[i] = (wxChar *)node->Data(); + strings[i] = (wxChar *)node->GetData(); i ++; - node = node->Next(); + node = node->GetNext(); } } control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size, @@ -569,10 +586,10 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db) { - wxNode *node = db.First(); + wxNode *node = db.GetFirst(); while (node) { - wxExpr *clause = (wxExpr *)node->Data(); + wxExpr *clause = (wxExpr *)node->GetData(); wxString functor(clause->Functor()); wxItemResource *item = (wxItemResource *) NULL; @@ -598,7 +615,7 @@ bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db) table.DeleteResource(item->GetName()); table.AddResource(item); } - node = node->Next(); + node = node->GetNext(); } return TRUE; } @@ -1499,9 +1516,6 @@ wxFont wxResourceInterpretFontSpec(wxExpr *expr) (underline != 0), faceName); } -// Separate file for the remainder of this, for BC++/Win16 - -#if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__)) /* * (Re)allocate buffer for reading in from resource file */ @@ -1528,7 +1542,7 @@ bool wxReallocateResourceBuffer() static bool wxEatWhiteSpace(FILE *fd) { - int ch = 0; + int ch; while ((ch = getc(fd)) != EOF) { @@ -2376,10 +2390,10 @@ wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table wxItemResource *optResource = (wxItemResource *) NULL; // Try to find optimum bitmap for this platform/colour depth - wxNode *node = item->GetChildren().First(); + wxNode *node = item->GetChildren().GetFirst(); while (node) { - wxItemResource *child = (wxItemResource *)node->Data(); + wxItemResource *child = (wxItemResource *)node->GetData(); int platform = (int)child->GetValue2(); int noColours = (int)child->GetValue3(); /* @@ -2450,7 +2464,7 @@ wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table default: break; } - node = node->Next(); + node = node->GetNext(); } // If no matching resource, fail. if (!optResource) @@ -2530,10 +2544,10 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) wxItemResource *optResource = (wxItemResource *) NULL; // Try to find optimum icon for this platform/colour depth - wxNode *node = item->GetChildren().First(); + wxNode *node = item->GetChildren().GetFirst(); while (node) { - wxItemResource *child = (wxItemResource *)node->Data(); + wxItemResource *child = (wxItemResource *)node->GetData(); int platform = (int)child->GetValue2(); int noColours = (int)child->GetValue3(); /* @@ -2604,7 +2618,7 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) default: break; } - node = node->Next(); + node = node->GetNext(); } // If no matching resource, fail. if (!optResource) @@ -2653,7 +2667,7 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); break; #else - return wxIcon(name, bitmapType); + return wxIcon(name, (wxBitmapType) bitmapType); #endif } } @@ -2671,13 +2685,13 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) wxMenu *wxResourceCreateMenu(wxItemResource *item) { wxMenu *menu = new wxMenu; - wxNode *node = item->GetChildren().First(); + wxNode *node = item->GetChildren().GetFirst(); while (node) { - wxItemResource *child = (wxItemResource *)node->Data(); + wxItemResource *child = (wxItemResource *)node->GetData(); if ((child->GetType() != wxT("")) && (child->GetType() == wxT("wxMenuSeparator"))) menu->AppendSeparator(); - else if (child->GetChildren().Number() > 0) + else if (child->GetChildren().GetCount() > 0) { wxMenu *subMenu = wxResourceCreateMenu(child); if (subMenu) @@ -2687,7 +2701,7 @@ wxMenu *wxResourceCreateMenu(wxItemResource *item) { menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0)); } - node = node->Next(); + node = node->GetNext(); } return menu; } @@ -2702,14 +2716,14 @@ wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *ta { if (!menuBar) menuBar = new wxMenuBar; - wxNode *node = menuResource->GetChildren().First(); + wxNode *node = menuResource->GetChildren().GetFirst(); while (node) { - wxItemResource *child = (wxItemResource *)node->Data(); + wxItemResource *child = (wxItemResource *)node->GetData(); wxMenu *menu = wxResourceCreateMenu(child); if (menu) menuBar->Append(menu, child->GetTitle()); - node = node->Next(); + node = node->GetNext(); } return menuBar; } @@ -2861,7 +2875,7 @@ static int ungetc_string() bool wxEatWhiteSpaceString(char *s) { - int ch = 0; + int ch; while ((ch = getc_string(s)) != EOF) { @@ -2874,7 +2888,6 @@ bool wxEatWhiteSpaceString(char *s) break; case '/': { - int prev_ch = ch; ch = getc_string(s); if (ch == EOF) { @@ -2885,7 +2898,7 @@ bool wxEatWhiteSpaceString(char *s) if (ch == '*') { // Eat C comment - prev_ch = 0; + int prev_ch = 0; while ((ch = getc_string(s)) != EOF) { if (ch == '/' && prev_ch == '*') @@ -3113,7 +3126,7 @@ bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxR return TRUE; } -bool wxResourceParseString(const wxString& s, wxResourceTable *table) +bool wxResourceParseString(const wxString& s, wxResourceTable *WXUNUSED(table)) { #if wxUSE_UNICODE return wxResourceParseString( (char*)s.mb_str().data() ); @@ -3158,7 +3171,7 @@ bool wxResourceParseString(char *s, wxResourceTable *table) * resource loading facility */ -bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table) +bool wxLoadFromResource(wxWindow* thisWindow, wxWindow *parent, const wxString& resourceName, const wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; @@ -3179,11 +3192,11 @@ bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceNa wxString name = resource->GetName(); // this is used for loading wxWizard pages from WXR - if ( parent != this ) + if ( parent != thisWindow ) { - if (IsKindOf(CLASSINFO(wxDialog))) + if (thisWindow->IsKindOf(CLASSINFO(wxDialog))) { - wxDialog *dialogBox = (wxDialog *)this; + wxDialog *dialogBox = (wxDialog *)thisWindow; long modalStyle = isModal ? wxDIALOG_MODAL : 0; if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name)) return FALSE; @@ -3192,15 +3205,15 @@ bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceNa if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0) dialogBox->SetClientSize(width, height); } - else if (IsKindOf(CLASSINFO(wxPanel))) + else if (thisWindow->IsKindOf(CLASSINFO(wxPanel))) { - wxPanel* panel = (wxPanel *)this; + wxPanel* panel = (wxPanel *)thisWindow; if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle | wxTAB_TRAVERSAL, name)) return FALSE; } else { - if (!((wxWindow *)this)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) + if (!((wxWindow *)thisWindow)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) return FALSE; } } @@ -3213,53 +3226,51 @@ bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceNa else { if (resource->GetFont().Ok()) - SetFont(resource->GetFont()); + thisWindow->SetFont(resource->GetFont()); if (resource->GetBackgroundColour().Ok()) - SetBackgroundColour(resource->GetBackgroundColour()); + thisWindow->SetBackgroundColour(resource->GetBackgroundColour()); } // Should have some kind of font at this point - if (!GetFont().Ok()) - SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - if (!GetBackgroundColour().Ok()) - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); + if (!thisWindow->GetFont().Ok()) + thisWindow->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); + if (!thisWindow->GetBackgroundColour().Ok()) + thisWindow->SetBackgroundColour(wxSystemSettings::GetColour(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); + wxSize sz = thisWindow->ConvertDialogToPixels(wxSize(width, height)); + thisWindow->SetClientSize(sz.x, sz.y); - wxPoint pt = ConvertDialogToPixels(wxPoint(x, y)); - Move(pt.x, pt.y); + wxPoint pt = thisWindow->ConvertDialogToPixels(wxPoint(x, y)); + thisWindow->Move(pt.x, pt.y); } // Now create children - wxNode *node = resource->GetChildren().First(); + wxNode *node = resource->GetChildren().GetFirst(); while (node) { - wxItemResource *childResource = (wxItemResource *)node->Data(); + wxItemResource *childResource = (wxItemResource *)node->GetData(); - (void) CreateItem(childResource, resource, table); + (void) wxCreateItem(thisWindow, childResource, resource, table); - node = node->Next(); + node = node->GetNext(); } return TRUE; } -wxControl *wxWindowBase::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table) +wxControl *wxCreateItem(wxWindow* thisWindow, const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - return table->CreateItem((wxWindow *)this, resource, parentResource); + return table->CreateItem(thisWindow, resource, parentResource); } #ifdef __VISUALC__ #pragma warning(default:4706) // assignment within conditional expression #endif // VC++ -#endif -// BC++/Win16 - #endif // wxUSE_WX_RESOURCES +