X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/386af6a2fa349e16f9b8abd32e3fedf13f021686..5dcf05ae082a2da39102dec13ab3ad4c483221c8:/src/common/resource.cpp diff --git a/src/common/resource.cpp b/src/common/resource.cpp index 0c2cc28936..f31d3ae392 100644 --- a/src/common/resource.cpp +++ b/src/common/resource.cpp @@ -20,6 +20,12 @@ #pragma hdrstop #endif +#if wxUSE_WX_RESOURCES + +#ifdef _MSC_VER + #pragma warning(disable:4706) // assignment within conditional expression +#endif // VC++ + #ifndef WX_PRECOMP #include "wx/defs.h" #include "wx/setup.h" @@ -59,8 +65,6 @@ #include "wx/log.h" -#if wxUSE_WX_RESOURCES - #include #include #include @@ -144,7 +148,7 @@ wxItemResource::~wxItemResource() /* * Resource table */ - + wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING) { } @@ -153,7 +157,7 @@ wxResourceTable::~wxResourceTable() { ClearTable(); } - + wxItemResource *wxResourceTable::FindResource(const wxString& name) const { wxItemResource *item = (wxItemResource *)Get((char *)(const char *)name); @@ -192,7 +196,7 @@ bool wxResourceTable::DeleteResource(const wxString& name) break; } } - + delete item; return TRUE; } @@ -375,10 +379,15 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c { control = new wxScrollBar(parent, id, pos, size, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); +/* ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1()); ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2()); ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3()); ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5()); +*/ + ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(), + (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),FALSE); + } #endif else if (itemType == wxString("wxSlider")) @@ -579,7 +588,7 @@ wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, long windowStyle = wxDEFAULT_DIALOG_STYLE; if (isPanel) windowStyle = 0; - + int x = 0; int y = 0; int width = -1; int height = -1; int isModal = 0; wxExpr *labelFontExpr = (wxExpr *) NULL; @@ -623,7 +632,7 @@ wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, dialogItem->SetName(name); dialogItem->SetTitle(title); dialogItem->SetSize(x, y, width, height); - + if (backColourHex != "") { int r = 0; @@ -1024,7 +1033,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr) controlItem->SetValue4(str); count ++; - + wxExpr *valueList = (wxExpr *) NULL; // Check for default value list if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList)) @@ -1097,7 +1106,7 @@ wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr) return controlItem; } -// Forward declaration +// Forward declaration wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr); /* @@ -1107,7 +1116,7 @@ wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr); wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr) { wxItemResource *item = new wxItemResource; - + wxExpr *labelExpr = expr->Nth(0); wxExpr *idExpr = expr->Nth(1); wxExpr *helpExpr = expr->Nth(2); @@ -1161,7 +1170,7 @@ wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr wxExpr *subMenuExpr = expr->GetFirst(); while (subMenuExpr && (subMenuExpr->Type() != PrologList)) subMenuExpr = subMenuExpr->GetNext(); - + while (subMenuExpr) { wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr); @@ -1199,7 +1208,7 @@ wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr) expr->GetAttributeValue("menu", &listExpr); if (!listExpr) return (wxItemResource *) NULL; - + wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); if (!menuResource) @@ -1210,7 +1219,7 @@ wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr) { menuResource->SetName(name); } - + return menuResource; } @@ -1224,7 +1233,7 @@ wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr) wxItemResource *resource = new wxItemResource; resource->SetType("wxMenu"); // resource->SetType(wxTYPE_MENU); - + wxExpr *element = listExpr->GetFirst(); while (element) { @@ -1238,7 +1247,7 @@ wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr) { resource->SetName(name); } - + return resource; } @@ -1292,7 +1301,7 @@ wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxEx } else bitmapSpec->SetValue1(0); - + if (platformExpr && platformExpr->StringValue()) { wxString plat(platformExpr->StringValue()); @@ -1317,14 +1326,14 @@ wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxEx if (yresExpr) yres = (int)yresExpr->IntegerValue(); bitmapSpec->SetSize(0, 0, xres, yres); - + bitmapItem->GetChildren().Append(bitmapSpec); } } } bitmapExpr = bitmapExpr->GetNext(); } - + return bitmapItem; } @@ -1353,7 +1362,7 @@ wxFont wxResourceInterpretFontSpec(wxExpr *expr) int weight = wxNORMAL; int underline = 0; wxString faceName(""); - + wxExpr *pointExpr = expr->Nth(0); wxExpr *familyExpr = expr->Nth(1); wxExpr *styleExpr = expr->Nth(2); @@ -1509,7 +1518,7 @@ bool wxGetResourceToken(FILE *fd) wxReallocateResourceBuffer(); wxResourceBuffer[wxResourceBufferCount] = (char)ch; wxResourceBufferCount ++; - + ch = getc(fd); } wxResourceBuffer[wxResourceBufferCount] = 0; @@ -1524,12 +1533,12 @@ bool wxGetResourceToken(FILE *fd) static char *name = "...."; with possible comments. */ - + bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + // static or #define if (!wxGetResourceToken(fd)) { @@ -1557,7 +1566,7 @@ bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResour } delete[] name; delete[] value; - + return TRUE; } else if (strcmp(wxResourceBuffer, "#include") == 0) @@ -1600,7 +1609,7 @@ bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResour wxLogWarning(_("Expected 'char' whilst parsing resource.")); return FALSE; } - + // *name if (!wxGetResourceToken(fd)) { @@ -1616,7 +1625,7 @@ bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResour } char nameBuf[100]; strncpy(nameBuf, wxResourceBuffer+1, 99); - + // = if (!wxGetResourceToken(fd)) { @@ -1657,7 +1666,7 @@ bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResour /* * Parses string window style into integer window style */ - + /* * Style flag parsing, e.g. * "wxSYSTEM_MENU | wxBORDER" -> integer @@ -1713,13 +1722,13 @@ static wxResourceBitListStruct wxResourceBitListTable[] = { "wxLB_SORT", wxLB_SORT }, { "wxLB_OWNERDRAW", wxLB_OWNERDRAW }, { "wxLB_HSCROLL", wxLB_HSCROLL }, - + /* wxComboxBox */ { "wxCB_SIMPLE", wxCB_SIMPLE }, { "wxCB_DROPDOWN", wxCB_DROPDOWN }, { "wxCB_READONLY", wxCB_READONLY }, { "wxCB_SORT", wxCB_SORT }, - + /* wxGauge */ { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR }, { "wxGA_HORIZONTAL", wxGA_HORIZONTAL }, @@ -1806,7 +1815,7 @@ static wxResourceBitListStruct wxResourceBitListTable[] = { "wxALIGN_CENTRE", wxALIGN_CENTRE}, { "wxALIGN_RIGHT", wxALIGN_RIGHT}, { "wxCOLOURED", wxCOLOURED}, - + /* wxToolBar */ { "wxTB_3DBUTTONS", wxTB_3DBUTTONS}, { "wxTB_HORIZONTAL", wxTB_HORIZONTAL}, @@ -1830,7 +1839,8 @@ static wxResourceBitListStruct wxResourceBitListTable[] = { "wxMINIMIZE_BOX", wxMINIMIZE_BOX}, { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX}, { "wxRESIZE_BOX", wxRESIZE_BOX}, - { "wxDEFAULT_FRAME", wxDEFAULT_FRAME}, + { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE}, + { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE}, { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE}, { "wxBORDER", wxBORDER}, { "wxRETAINED", wxRETAINED}, @@ -1980,12 +1990,12 @@ long wxParseWindowStyle(const wxString& bitListString) * Load a bitmap from a wxWindows resource, choosing an optimum * depth and appropriate type. */ - + wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + wxItemResource *item = table->FindResource(resource); if (item) { @@ -1998,7 +2008,7 @@ wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table long thisNoColours = (long)pow(2.0, (double)thisDepth); wxItemResource *optResource = (wxItemResource *) NULL; - + // Try to find optimum bitmap for this platform/colour depth wxNode *node = item->GetChildren().First(); while (node) @@ -2092,7 +2102,7 @@ wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table { wxLogWarning(_("Failed to find XBM resource %s.\n" "Forgot to use wxResourceLoadBitmapData?"), (const char*) name); - return (wxBitmap *) NULL; + return wxNullBitmap; } return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ; #else @@ -2108,7 +2118,7 @@ wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table { wxLogWarning(_("Failed to find XPM resource %s.\n" "Forgot to use wxResourceLoadBitmapData?"), (const char*) name); - return (wxBitmap *) NULL; + return wxNullBitmap; } return wxBitmap(item->GetValue1()); #else @@ -2135,12 +2145,12 @@ wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table * Load an icon from a wxWindows resource, choosing an optimum * depth and appropriate type. */ - + wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + wxItemResource *item = table->FindResource(resource); if (item) { @@ -2153,7 +2163,7 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) long thisNoColours = (long)pow(2.0, (double)thisDepth); wxItemResource *optResource = (wxItemResource *) NULL; - + // Try to find optimum icon for this platform/colour depth wxNode *node = item->GetChildren().First(); while (node) @@ -2247,9 +2257,9 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) { wxLogWarning(_("Failed to find XBM resource %s.\n" "Forgot to use wxResourceLoadIconData?"), (const char*) name); - return (wxIcon *) NULL; + return wxNullIcon; } - return wxIcon((char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); + return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); #else wxLogWarning(_("No XBM facility available!")); #endif @@ -2291,7 +2301,7 @@ wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) else { wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource); - return (wxIcon *) NULL; + return wxNullIcon; } } @@ -2323,7 +2333,7 @@ wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *ta { if (!table) table = wxDefaultResourceTable; - + wxItemResource *menuResource = table->FindResource(resource); if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu")) { @@ -2347,7 +2357,7 @@ wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + wxItemResource *menuResource = table->FindResource(resource); if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu")) // if (menuResource && (menuResource->GetType() == wxTYPE_MENU)) @@ -2360,7 +2370,7 @@ bool wxResourceParseData(const wxString& resource, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + return table->ParseResourceData(resource); } @@ -2368,7 +2378,7 @@ bool wxResourceParseFile(const wxString& filename, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + return table->ParseResourceFile(filename); } @@ -2377,7 +2387,7 @@ bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, { if (!table) table = wxDefaultResourceTable; - + return table->RegisterResourceBitmapData(name, bits, width, height); } @@ -2405,7 +2415,7 @@ bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *t { if (!table) table = wxDefaultResourceTable; - + table->identifiers.Put(name, (wxObject *)value); return TRUE; } @@ -2414,7 +2424,7 @@ int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + return (int)table->identifiers.Get(name); } @@ -2426,7 +2436,7 @@ bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + FILE *fd = fopen(f, "r"); if (!fd) { @@ -2480,7 +2490,7 @@ bool wxEatWhiteSpaceString(char *s) int ch = getc_string(s); if (ch == EOF) return TRUE; - + if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9)) { ungetc_string(); @@ -2575,7 +2585,7 @@ bool wxGetResourceTokenString(char *s) wxReallocateResourceBuffer(); wxResourceBuffer[wxResourceBufferCount] = (char)ch; wxResourceBufferCount ++; - + ch = getc_string(s); } wxResourceBuffer[wxResourceBufferCount] = 0; @@ -2590,12 +2600,12 @@ bool wxGetResourceTokenString(char *s) static char *name = "...."; with possible comments. */ - + bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + // static or #define if (!wxGetResourceTokenString(s)) { @@ -2623,7 +2633,7 @@ bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxR } delete[] name; delete[] value; - + return TRUE; } /* @@ -2670,7 +2680,7 @@ bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxR wxLogWarning(_("Expected 'char' whilst parsing resource.")); return FALSE; } - + // *name if (!wxGetResourceTokenString(s)) { @@ -2686,7 +2696,7 @@ bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxR } char nameBuf[100]; strncpy(nameBuf, wxResourceBuffer+1, 99); - + // = if (!wxGetResourceTokenString(s)) { @@ -2728,11 +2738,11 @@ bool wxResourceParseString(char *s, wxResourceTable *table) { if (!table) table = wxDefaultResourceTable; - + if (!s) return FALSE; - - // Turn backslashes into spaces + + // Turn backslashes into spaces if (s) { int len = strlen(s); @@ -2764,7 +2774,7 @@ bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, { if (!table) table = wxDefaultResourceTable; - + wxItemResource *resource = table->FindResource((const char *)resourceName); // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX)) if (!resource || !resource->GetType() || @@ -2817,7 +2827,7 @@ bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, } // Should have some kind of font at this point - if (!GetFont()->Ok()) + if (!GetFont().Ok()) SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); if (!GetBackgroundColour().Ok()) SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); @@ -2838,7 +2848,7 @@ bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, while (node) { wxItemResource *childResource = (wxItemResource *)node->Data(); - + (void) CreateItem(childResource, resource, table); node = node->Next(); @@ -2853,4 +2863,8 @@ wxControl *wxWindow::CreateItem(const wxItemResource *resource, const wxItemReso return table->CreateItem((wxWindow *)this, resource, parentResource); } +#ifdef _MSC_VER + #pragma warning(default:4706) // assignment within conditional expression +#endif // VC++ + #endif // wxUSE_WX_RESOURCES