#pragma hdrstop
#endif
+#if wxUSE_WX_RESOURCES
+
+#ifdef __VISUALC__
+ #pragma warning(disable:4706) // assignment within conditional expression
+#endif // VC++
+
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/setup.h"
#include "wx/button.h"
#include "wx/bmpbuttn.h"
#include "wx/radiobox.h"
+#include "wx/radiobut.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"
+#include "wx/statbmp.h"
#if wxUSE_GAUGE
#include "wx/gauge.h"
#endif
#include "wx/intl.h"
#endif
+#if wxUSE_RADIOBUTTON
+#include "wx/radiobut.h"
+#endif
+
#if wxUSE_SCROLLBAR
#include "wx/scrolbar.h"
#endif
#include "wx/log.h"
-#if wxUSE_WX_RESOURCES
-
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL;
-static char *wxResourceBuffer = (char *) NULL;
-static long wxResourceBufferSize = 0;
-static long wxResourceBufferCount = 0;
-static int wxResourceStringPtr = 0;
+char *wxResourceBuffer = (char *) NULL;
+long wxResourceBufferSize = 0;
+long wxResourceBufferCount = 0;
+int wxResourceStringPtr = 0;
void wxInitializeResourceSystem()
{
/*
* Resource table
*/
-
+
wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING)
{
}
{
ClearTable();
}
-
+
wxItemResource *wxResourceTable::FindResource(const wxString& name) const
{
wxItemResource *item = (wxItemResource *)Get((char *)(const char *)name);
break;
}
}
-
+
delete item;
return TRUE;
}
{
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"))
return TRUE;
}
-static char *g_ValidControlClasses[] = { "wxButton", "wxBitmapButton", "wxMessage",
- "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
- "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
- "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
- "wxChoice", "wxComboBox" } ;
-static int g_ValidControlClassesCount = sizeof(g_ValidControlClasses) / sizeof(char *) ;
+static const char *g_ValidControlClasses[] =
+{
+ "wxButton",
+ "wxBitmapButton",
+ "wxMessage",
+ "wxStaticText",
+ "wxStaticBitmap",
+ "wxText",
+ "wxTextCtrl",
+ "wxMultiText",
+ "wxListBox",
+ "wxRadioBox",
+ "wxRadioButton",
+ "wxCheckBox",
+ "wxBitmapCheckBox",
+ "wxGroupBox",
+ "wxStaticBox",
+ "wxSlider",
+ "wxGauge",
+ "wxScrollBar",
+ "wxChoice",
+ "wxComboBox"
+};
static bool wxIsValidControlClass(const wxString& c)
{
- int i;
- for ( i = 0; i < g_ValidControlClassesCount; i++)
+ for ( size_t i = 0; i < WXSIZEOF(g_ValidControlClasses); i++ )
{
if ( c == g_ValidControlClasses[i] )
return TRUE;
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;
dialogItem->SetName(name);
dialogItem->SetTitle(title);
dialogItem->SetSize(x, y, width, height);
-
+
if (backColourHex != "")
{
int r = 0;
controlItem->SetId(id);
if (controlType == "wxButton")
+ {
+ // Check for bitmap resource name (in case loading old-style resource file)
+ if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
+ {
+ wxString str(expr->Nth(count)->StringValue());
+ count ++;
+
+ if (str != "")
+ {
+ controlItem->SetValue4(str);
+ controlItem->SetType("wxBitmapButton");
+ }
+ }
+ if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
+ controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
+ }
+ else if (controlType == "wxBitmapButton")
{
// Check for bitmap resource name
if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
}
}
else if (controlType == "wxMessage" || controlType == "wxStaticText")
+ {
+ // Check for bitmap resource name (in case it's an old-style .wxr file)
+ if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
+ {
+ wxString str(expr->Nth(count)->StringValue());
+ controlItem->SetValue4(str);
+ count ++;
+ controlItem->SetType("wxStaticText");
+ }
+ if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
+ controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
+ }
+ else if (controlType == "wxStaticBitmap")
{
// Check for bitmap resource name
if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
wxString str(expr->Nth(count)->StringValue());
controlItem->SetValue4(str);
count ++;
- if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
- controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
}
+ if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
+ controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
}
else if (controlType == "wxGroupBox" || controlType == "wxStaticBox")
{
controlItem->SetValue4(str);
count ++;
-
+
wxExpr *valueList = (wxExpr *) NULL;
// Check for default value list
if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList))
return controlItem;
}
-// Forward declaration
+// Forward declaration
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);
wxExpr *subMenuExpr = expr->GetFirst();
while (subMenuExpr && (subMenuExpr->Type() != PrologList))
subMenuExpr = subMenuExpr->GetNext();
-
+
while (subMenuExpr)
{
wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr);
expr->GetAttributeValue("menu", &listExpr);
if (!listExpr)
return (wxItemResource *) NULL;
-
+
wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
if (!menuResource)
{
menuResource->SetName(name);
}
-
+
return menuResource;
}
wxItemResource *resource = new wxItemResource;
resource->SetType("wxMenu");
// resource->SetType(wxTYPE_MENU);
-
+
wxExpr *element = listExpr->GetFirst();
while (element)
{
{
resource->SetName(name);
}
-
+
return resource;
}
wxExpr *coloursExpr = listExpr->Nth(3);
wxExpr *xresExpr = listExpr->Nth(4);
wxExpr *yresExpr = listExpr->Nth(5);
- if (nameExpr && nameExpr->StringValue())
+ if (nameExpr && nameExpr->StringValue() != "")
{
bitmapSpec->SetName(nameExpr->StringValue());
}
- if (typeExpr && typeExpr->StringValue())
+ if (typeExpr && typeExpr->StringValue() != "")
{
bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue()));
}
else
bitmapSpec->SetValue1(0);
-
- if (platformExpr && platformExpr->StringValue())
+
+ if (platformExpr && platformExpr->StringValue() != "")
{
wxString plat(platformExpr->StringValue());
if (plat == "windows" || plat == "WINDOWS")
if (yresExpr)
yres = (int)yresExpr->IntegerValue();
bitmapSpec->SetSize(0, 0, xres, yres);
-
+
bitmapItem->GetChildren().Append(bitmapSpec);
}
}
}
bitmapExpr = bitmapExpr->GetNext();
}
-
+
return bitmapItem;
}
int weight = wxNORMAL;
int underline = 0;
wxString faceName("");
-
+
wxExpr *pointExpr = expr->Nth(0);
wxExpr *familyExpr = expr->Nth(1);
wxExpr *styleExpr = expr->Nth(2);
return font;
}
+// 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
*/
wxReallocateResourceBuffer();
wxResourceBuffer[wxResourceBufferCount] = (char)ch;
wxResourceBufferCount ++;
-
+
ch = getc(fd);
}
wxResourceBuffer[wxResourceBufferCount] = 0;
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))
{
}
delete[] name;
delete[] value;
-
+
return TRUE;
}
else if (strcmp(wxResourceBuffer, "#include") == 0)
wxLogWarning(_("Expected 'char' whilst parsing resource."));
return FALSE;
}
-
+
// *name
if (!wxGetResourceToken(fd))
{
}
char nameBuf[100];
strncpy(nameBuf, wxResourceBuffer+1, 99);
-
+
// =
if (!wxGetResourceToken(fd))
{
/*
* Parses string window style into integer window style
*/
-
+
/*
* Style flag parsing, e.g.
* "wxSYSTEM_MENU | wxBORDER" -> integer
{ "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 },
/* wxRadioBox/wxRadioButton */
{ "wxRB_GROUP", wxRB_GROUP },
+ { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS },
+ { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS },
{ "wxRA_HORIZONTAL", wxRA_HORIZONTAL },
{ "wxRA_VERTICAL", wxRA_VERTICAL },
{ "wxALIGN_CENTRE", wxALIGN_CENTRE},
{ "wxALIGN_RIGHT", wxALIGN_RIGHT},
{ "wxCOLOURED", wxCOLOURED},
-
+
/* wxToolBar */
{ "wxTB_3DBUTTONS", wxTB_3DBUTTONS},
{ "wxTB_HORIZONTAL", wxTB_HORIZONTAL},
{ "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},
* 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)
{
- if (!item->GetType() || strcmp(item->GetType(), "wxBitmap") != 0)
+ if ((item->GetType() == "") || (item->GetType() != "wxBitmap"))
{
wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource);
return wxNullBitmap;
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)
{
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
{
wxLogWarning(_("Failed to find XPM resource %s.\n"
"Forgot to use wxResourceLoadBitmapData?"), (const char*) name);
- return (wxBitmap *) NULL;
+ return wxNullBitmap;
}
- return wxBitmap(item->GetValue1());
+ return wxBitmap((char **)item->GetValue1());
#else
wxLogWarning(_("No XPM facility available!"));
#endif
* 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)
{
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)
{
wxLogWarning(_("Failed to find XBM resource %s.\n"
"Forgot to use wxResourceLoadIconData?"), (const char*) name);
- return (wxIcon *) NULL;
+ return wxNullIcon;
}
return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3());
#else
else
{
wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
- return (wxIcon *) NULL;
+ return wxNullIcon;
}
}
{
if (!table)
table = wxDefaultResourceTable;
-
+
wxItemResource *menuResource = table->FindResource(resource);
if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
{
{
if (!table)
table = wxDefaultResourceTable;
-
+
wxItemResource *menuResource = table->FindResource(resource);
if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
// if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
{
if (!table)
table = wxDefaultResourceTable;
-
+
return table->ParseResourceData(resource);
}
{
if (!table)
table = wxDefaultResourceTable;
-
+
return table->ParseResourceFile(filename);
}
{
if (!table)
table = wxDefaultResourceTable;
-
+
return table->RegisterResourceBitmapData(name, bits, width, height);
}
{
if (!table)
table = wxDefaultResourceTable;
-
+
table->identifiers.Put(name, (wxObject *)value);
return TRUE;
}
{
if (!table)
table = wxDefaultResourceTable;
-
+
return (int)table->identifiers.Get(name);
}
{
if (!table)
table = wxDefaultResourceTable;
-
+
FILE *fd = fopen(f, "r");
if (!fd)
{
int ch = getc_string(s);
if (ch == EOF)
return TRUE;
-
+
if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
{
ungetc_string();
wxReallocateResourceBuffer();
wxResourceBuffer[wxResourceBufferCount] = (char)ch;
wxResourceBufferCount ++;
-
+
ch = getc_string(s);
}
wxResourceBuffer[wxResourceBufferCount] = 0;
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))
{
}
delete[] name;
delete[] value;
-
+
return TRUE;
}
/*
wxLogWarning(_("Expected 'char' whilst parsing resource."));
return FALSE;
}
-
+
// *name
if (!wxGetResourceTokenString(s))
{
}
char nameBuf[100];
strncpy(nameBuf, wxResourceBuffer+1, 99);
-
+
// =
if (!wxGetResourceTokenString(s))
{
{
if (!table)
table = wxDefaultResourceTable;
-
+
if (!s)
return FALSE;
-
- // Turn backslashes into spaces
+
+ // Turn backslashes into spaces
if (s)
{
int len = strlen(s);
{
if (!table)
table = wxDefaultResourceTable;
-
+
wxItemResource *resource = table->FindResource((const char *)resourceName);
// if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
- if (!resource || !resource->GetType() ||
- ! ((strcmp(resource->GetType(), "wxDialog") == 0) || (strcmp(resource->GetType(), "wxPanel") == 0)))
+ if (!resource || (resource->GetType() == "") ||
+ ! ((resource->GetType() == "wxDialog") || (resource->GetType() == "wxPanel")))
return FALSE;
wxString title(resource->GetTitle());
}
// 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));
while (node)
{
wxItemResource *childResource = (wxItemResource *)node->Data();
-
+
(void) CreateItem(childResource, resource, table);
node = node->Next();
return table->CreateItem((wxWindow *)this, resource, parentResource);
}
+#ifdef __VISUALC__
+ #pragma warning(default:4706) // assignment within conditional expression
+#endif // VC++
+
+#endif
+ // BC++/Win16
+
#endif // wxUSE_WX_RESOURCES