1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     Resource system 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart and Markus Holzem 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "resource.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  28 #include "wx/gdicmn.h" 
  32 #include "wx/stattext.h" 
  33 #include "wx/button.h" 
  34 #include "wx/radiobox.h" 
  35 #include "wx/listbox.h" 
  36 #include "wx/choice.h" 
  37 #include "wx/checkbox.h" 
  38 #include "wx/slider.h" 
  39 #include "wx/statbox.h" 
  43 #include "wx/textctrl.h" 
  44 #include "wx/msgbxdlg.h" 
  48 #include "wx/scrolbar.h" 
  52 #include "wx/combobox.h" 
  55 #include "wx/validate.h" 
  64 #include "wx/resource.h" 
  65 #include "wx/string.h" 
  66 #include "wx/wxexpr.h" 
  68 // Forward (private) declarations 
  69 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
); 
  70 wxItemResource 
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr 
*expr
, bool isPanel 
= FALSE
); 
  71 wxItemResource 
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr 
*expr
); 
  72 wxItemResource 
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr 
*expr
); 
  73 wxItemResource 
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr 
*expr
); 
  74 wxItemResource 
*wxResourceInterpretString(wxResourceTable
& table
, PrologExpr 
*expr
); 
  75 wxItemResource 
*wxResourceInterpretBitmap(wxResourceTable
& table
, PrologExpr 
*expr
); 
  76 wxItemResource 
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr 
*expr
); 
  77 // Interpret list expression 
  78 wxFont 
*wxResourceInterpretFontSpec(PrologExpr 
*expr
); 
  80 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable 
*table 
= NULL
); 
  81 bool wxResourceParseIncludeFile(char *f
, wxResourceTable 
*table 
= NULL
); 
  83 wxResourceTable 
*wxDefaultResourceTable 
= NULL
; 
  85 static char *wxResourceBuffer 
= NULL
; 
  86 static long wxResourceBufferSize 
= 0; 
  87 static long wxResourceBufferCount 
= 0; 
  88 static int wxResourceStringPtr 
= 0; 
  90 void wxInitializeResourceSystem(void) 
  92     wxDefaultResourceTable 
= new wxResourceTable
; 
  95 void wxCleanUpResourceSystem(void) 
  97     delete wxDefaultResourceTable
; 
 100 void wxWarning(char *msg
) 
 102   wxMessageBox(msg
, _("Warning"), wxOK
); 
 105 #if !USE_SHARED_LIBRARY 
 106 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
) 
 107 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
) 
 110 wxItemResource::wxItemResource(void) 
 116   x 
= y 
= width 
= height 
= 0; 
 117   value1 
= value2 
= value3 
= value5 
= 0; 
 121   backgroundColour 
= labelColour 
= buttonColour 
= NULL
; 
 126 wxItemResource::~wxItemResource(void) 
 128   if (itemType
) delete[] itemType
; 
 129   if (title
) delete[] title
; 
 130   if (name
) delete[] name
; 
 131   if (value4
) delete[] value4
; 
 136   if (backgroundColour
) 
 137     delete backgroundColour
; 
 142   wxNode 
*node 
= children
.First(); 
 145     wxItemResource 
*item 
= (wxItemResource 
*)node
->Data(); 
 148     node 
= children
.First(); 
 152 void wxItemResource::SetTitle(char *t
) 
 157   if (title
) delete[] title
; 
 159     title 
= copystring(t
); 
 164 void wxItemResource::SetType(char *t
) 
 169   if (itemType
) delete[] itemType
; 
 171     itemType 
= copystring(t
); 
 176 void wxItemResource::SetName(char *n
) 
 181   if (name
) delete[] name
; 
 183     name 
= copystring(n
); 
 188 void wxItemResource::SetStringValues(wxStringList 
*svalues
) 
 193     stringValues 
= svalues
; 
 198 void wxItemResource::SetValue4(char *v
) 
 203   if (value4
) delete[] value4
; 
 205     value4 
= copystring(v
); 
 214 wxResourceTable::wxResourceTable(void):wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
) 
 218 wxResourceTable::~wxResourceTable(void) 
 223 wxItemResource 
*wxResourceTable::FindResource(const wxString
& name
) const 
 225   wxItemResource 
*item 
= (wxItemResource 
*)Get((char *)(const char *)name
); 
 229 void wxResourceTable::AddResource(wxItemResource 
*item
) 
 231   char *name 
= item
->GetName(); 
 233     name 
= item
->GetTitle(); 
 237   // Delete existing resource, if any. 
 243 bool wxResourceTable::DeleteResource(const wxString
& name
) 
 245   wxItemResource 
*item 
= (wxItemResource 
*)Delete((char *)(const char *)name
); 
 248     // See if any resource has this as its child; if so, delete from 
 249     // parent's child list. 
 252     while ((node 
= Next())) 
 254       wxItemResource 
*parent 
= (wxItemResource 
*)node
->Data(); 
 255       if (parent
->GetChildren().Member(item
)) 
 257         parent
->GetChildren().DeleteObject(item
); 
 269 bool wxResourceTable::ParseResourceFile(char *filename
) 
 273   FILE *fd 
= fopen(filename
, "r"); 
 277   while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
) 
 282   return wxResourceInterpretResources(*this, db
); 
 285 bool wxResourceTable::ParseResourceData(char *data
) 
 288   if (!db
.ReadPrologFromString(data
)) 
 290     wxWarning(_("Ill-formed resource file syntax.")); 
 294   return wxResourceInterpretResources(*this, db
); 
 297 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char bits
[], int width
, int height
) 
 299   // Register pre-loaded bitmap data 
 300   wxItemResource 
*item 
= new wxItemResource
; 
 301 //  item->SetType(wxRESOURCE_TYPE_XBM_DATA); 
 302   item
->SetType("wxXBMData"); 
 304   item
->SetValue1((long)bits
); 
 305   item
->SetValue2((long)width
); 
 306   item
->SetValue3((long)height
); 
 311 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char **data
) 
 313   // Register pre-loaded bitmap data 
 314   wxItemResource 
*item 
= new wxItemResource
; 
 315 //  item->SetType(wxRESOURCE_TYPE_XPM_DATA); 
 316   item
->SetType("wxXPMData"); 
 318   item
->SetValue1((long)data
); 
 323 bool wxResourceTable::SaveResource(char *WXUNUSED(filename
)) 
 328 void wxResourceTable::ClearTable(void) 
 331   wxNode 
*node 
= Next(); 
 334     wxNode 
*next 
= Next(); 
 335     wxItemResource 
*item 
= (wxItemResource 
*)node
->Data(); 
 342 wxControl 
*wxResourceTable::CreateItem(wxWindow 
*parent
, wxItemResource 
*childResource
) const 
 344   int id 
= childResource
->GetId(); 
 348   wxControl 
*control 
= NULL
; 
 349   wxString 
itemType(childResource
->GetType()); 
 350   if (itemType 
== wxString("wxButton") || itemType 
== wxString("wxBitmapButton")) 
 352         if (childResource
->GetValue4()) 
 355           wxBitmap 
*bitmap 
= childResource
->GetBitmap(); 
 358             bitmap 
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable 
*)this); 
 359             childResource
->SetBitmap(bitmap
); 
 362            control 
= new wxBitmapButton(parent
, id
, *bitmap
, 
 363              wxPoint(childResource
->GetX(), childResource
->GetY()), 
 364                          wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 365                 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 368           // Normal, text button 
 369           control 
= new wxButton(parent
, id
, childResource
->GetTitle(), 
 370            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 371                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 372            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 374    else if (itemType 
== wxString("wxMessage") || itemType 
== wxString("wxStaticText") || 
 375                 itemType 
== wxString("wxStaticBitmap")) 
 377         if (childResource
->GetValue4()) 
 380           wxBitmap 
*bitmap 
= childResource
->GetBitmap(); 
 383             bitmap 
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable 
*)this); 
 384             childResource
->SetBitmap(bitmap
); 
 386 #if USE_BITMAP_MESSAGE 
 388            control 
= new wxStaticBitmap(parent
, id
, *bitmap
, 
 389              wxPoint(childResource
->GetX(), childResource
->GetY()), 
 390                          wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 391              childResource
->GetStyle(), childResource
->GetName()); 
 396            control 
= new wxStaticText(parent
, id
, childResource
->GetTitle(), 
 397              wxPoint(childResource
->GetX(), childResource
->GetY()), 
 398                          wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 399              childResource
->GetStyle(), childResource
->GetName()); 
 402    else if (itemType 
== wxString("wxText") || itemType 
== wxString("wxTextCtrl") || itemType 
== wxString("wxMultiText")) 
 404         control 
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), 
 405            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 406                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 407            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 409    else if (itemType 
== wxString("wxCheckBox")) 
 411         control 
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), 
 412            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 413                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 414            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 416         ((wxCheckBox 
*)control
)->SetValue((childResource
->GetValue1() != 0)); 
 419    else if (itemType 
== wxString("wxGauge")) 
 421         control 
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), 
 422            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 423                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 424            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 426         ((wxGauge 
*)control
)->SetValue((int)childResource
->GetValue1()); 
 430    else if (itemType 
== wxString("wxRadioButton")) 
 432         control 
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(), 
 433            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 434                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 435            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 439    else if (itemType 
== wxString("wxScrollBar")) 
 441         control 
= new wxScrollBar(parent
, id
, 
 442            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 443            wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 444            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 445         ((wxScrollBar 
*)control
)->SetValue((int)childResource
->GetValue1()); 
 446         ((wxScrollBar 
*)control
)->SetPageSize((int)childResource
->GetValue2()); 
 447         ((wxScrollBar 
*)control
)->SetObjectLength((int)childResource
->GetValue3()); 
 448         ((wxScrollBar 
*)control
)->SetViewLength((int)(long)childResource
->GetValue5()); 
 451    else if (itemType 
== wxString("wxSlider")) 
 453         control 
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(), 
 454            (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), 
 455            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 456            wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 457            childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 459    else if (itemType 
== wxString("wxGroupBox") || itemType 
== wxString("wxStaticBox")) 
 461         control 
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), 
 462            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 463                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 464            childResource
->GetStyle(), childResource
->GetName()); 
 466    else if (itemType 
== wxString("wxListBox")) 
 468         wxStringList 
*stringList 
= childResource
->GetStringValues(); 
 469         wxString 
*strings 
= NULL
; 
 471         if (stringList 
&& (stringList
->Number() > 0)) 
 473           noStrings 
= stringList
->Number(); 
 474           strings 
= new wxString
[noStrings
]; 
 475           wxNode 
*node 
= stringList
->First(); 
 479             strings
[i
] = (char *)node
->Data(); 
 484         control 
= new wxListBox(parent
, id
, 
 485            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 486                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 487            noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 492    else if (itemType 
== wxString("wxChoice")) 
 494         wxStringList 
*stringList 
= childResource
->GetStringValues(); 
 495         wxString 
*strings 
= NULL
; 
 497         if (stringList 
&& (stringList
->Number() > 0)) 
 499           noStrings 
= stringList
->Number(); 
 500           strings 
= new wxString
[noStrings
]; 
 501           wxNode 
*node 
= stringList
->First(); 
 505             strings
[i
] = (char *)node
->Data(); 
 510         control 
= new wxChoice(parent
, id
, 
 511            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 512                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 513            noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 519    else if (itemType 
== wxString("wxComboBox")) 
 521         wxStringList 
*stringList 
= childResource
->GetStringValues(); 
 522         wxString 
*strings 
= NULL
; 
 524         if (stringList 
&& (stringList
->Number() > 0)) 
 526           noStrings 
= stringList
->Number(); 
 527           strings 
= new wxString
[noStrings
]; 
 528           wxNode 
*node 
= stringList
->First(); 
 532             strings
[i
] = (char *)node
->Data(); 
 537         control 
= new wxComboBox(parent
, id
, childResource
->GetValue4(), 
 538            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 539                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 540            noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName()); 
 546    else if (itemType 
== wxString("wxRadioBox")) 
 548         wxStringList 
*stringList 
= childResource
->GetStringValues(); 
 549         wxString 
*strings 
= NULL
; 
 551         if (stringList 
&& (stringList
->Number() > 0)) 
 553           noStrings 
= stringList
->Number(); 
 554           strings 
= new wxString
[noStrings
]; 
 555           wxNode 
*node 
= stringList
->First(); 
 559             strings
[i
] = (char *)node
->Data(); 
 564         control 
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), 
 565            wxPoint(childResource
->GetX(), childResource
->GetY()), 
 566                    wxSize(childResource
->GetWidth(), childResource
->GetHeight()), 
 567            noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
, 
 568                    childResource
->GetName()); 
 574   if (control 
&& childResource
->GetFont()) 
 575     control
->SetFont(*childResource
->GetFont()); 
 580  * Interpret database as a series of resources 
 583 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
) 
 585   wxNode 
*node 
= db
.First(); 
 588     PrologExpr 
*clause 
= (PrologExpr 
*)node
->Data(); 
 589         wxString 
functor(clause
->Functor()); 
 591     wxItemResource 
*item 
= NULL
; 
 592     if (functor 
== "dialog") 
 593       item 
= wxResourceInterpretDialog(table
, clause
); 
 594     else if (functor 
== "panel") 
 595       item 
= wxResourceInterpretDialog(table
, clause
, TRUE
); 
 596     else if (functor 
== "menubar") 
 597       item 
= wxResourceInterpretMenuBar(table
, clause
); 
 598     else if (functor 
== "menu") 
 599       item 
= wxResourceInterpretMenu(table
, clause
); 
 600     else if (functor 
== "string") 
 601       item 
= wxResourceInterpretString(table
, clause
); 
 602     else if (functor 
== "bitmap") 
 603       item 
= wxResourceInterpretBitmap(table
, clause
); 
 604     else if (functor 
== "icon") 
 605       item 
= wxResourceInterpretIcon(table
, clause
); 
 609       // Remove any existing resource of same name 
 611         table
.DeleteResource(item
->GetName()); 
 612       table
.AddResource(item
); 
 619 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage", 
 620  "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText", 
 621  "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox", 
 622  "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar", 
 623  "wxChoice", "wxComboBox" } ; 
 624 static int g_ValidControlClassesCount 
= sizeof(g_ValidControlClasses
) / sizeof(char *) ; 
 626 static bool wxIsValidControlClass(const wxString
& c
) 
 629         for ( i 
= 0; i 
< g_ValidControlClassesCount
; i
++) 
 631                 if ( c 
== g_ValidControlClasses
[i
] ) 
 637 wxItemResource 
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr 
*expr
, bool isPanel
) 
 639   wxItemResource 
*dialogItem 
= new wxItemResource
; 
 641     dialogItem
->SetType("wxPanel"); 
 643     dialogItem
->SetType("wxDialog"); 
 647   char *backColourHex 
= NULL
; 
 648   char *labelColourHex 
= NULL
; 
 649   char *buttonColourHex 
= NULL
; 
 651   long windowStyle 
= wxDEFAULT_DIALOG_STYLE
; 
 655   int x 
= 0; int y 
= 0; int width 
= -1; int height 
= -1; 
 657   PrologExpr 
*labelFontExpr 
= NULL
; 
 658   PrologExpr 
*buttonFontExpr 
= NULL
; 
 659   PrologExpr 
*fontExpr 
= NULL
; 
 660   expr
->AssignAttributeValue("style", &style
); 
 661   expr
->AssignAttributeValue("name", &name
); 
 662   expr
->AssignAttributeValue("title", &title
); 
 663   expr
->AssignAttributeValue("x", &x
); 
 664   expr
->AssignAttributeValue("y", &y
); 
 665   expr
->AssignAttributeValue("width", &width
); 
 666   expr
->AssignAttributeValue("height", &height
); 
 667   expr
->AssignAttributeValue("modal", &isModal
); 
 668   expr
->AssignAttributeValue("label_font", &labelFontExpr
); 
 669   expr
->AssignAttributeValue("button_font", &buttonFontExpr
); 
 670   expr
->AssignAttributeValue("font", &fontExpr
); 
 671   expr
->AssignAttributeValue("background_colour", &backColourHex
); 
 672   expr
->AssignAttributeValue("label_colour", &labelColourHex
); 
 673   expr
->AssignAttributeValue("button_colour", &buttonColourHex
); 
 676   expr
->GetAttributeValue("id", id
); 
 677   dialogItem
->SetId(id
); 
 681     windowStyle 
= wxParseWindowStyle(style
); 
 683   dialogItem
->SetStyle(windowStyle
); 
 684   dialogItem
->SetValue1(isModal
); 
 686     dialogItem
->SetName(name
); 
 688     dialogItem
->SetTitle(title
); 
 689   dialogItem
->SetSize(x
, y
, width
, height
); 
 696     r 
= wxHexToDec(backColourHex
); 
 697     g 
= wxHexToDec(backColourHex
+2); 
 698     b 
= wxHexToDec(backColourHex
+4); 
 699     dialogItem
->SetBackgroundColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
)); 
 700     delete[] backColourHex
; 
 707     r 
= wxHexToDec(labelColourHex
); 
 708     g 
= wxHexToDec(labelColourHex
+2); 
 709     b 
= wxHexToDec(labelColourHex
+4); 
 710     dialogItem
->SetLabelColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
)); 
 711     delete[] labelColourHex
; 
 718     r 
= wxHexToDec(buttonColourHex
); 
 719     g 
= wxHexToDec(buttonColourHex
+2); 
 720     b 
= wxHexToDec(buttonColourHex
+4); 
 721     dialogItem
->SetButtonColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
)); 
 722     delete[] buttonColourHex
; 
 733     dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
)); 
 734   else if (buttonFontExpr
) 
 735     dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
)); 
 736   else if (labelFontExpr
) 
 737     dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
)); 
 739   // Now parse all controls 
 740   PrologExpr 
*controlExpr 
= expr
->GetFirst(); 
 743     if (controlExpr
->Number() == 3) 
 745       wxString 
controlKeyword(controlExpr
->Nth(1)->StringValue()); 
 746       if (controlKeyword 
!= "" && controlKeyword 
== "control") 
 748         // The value part: always a list. 
 749         PrologExpr 
*listExpr 
= controlExpr
->Nth(2); 
 750         if (listExpr
->Type() == PrologList
) 
 752           wxItemResource 
*controlItem 
= wxResourceInterpretControl(table
, listExpr
); 
 755             dialogItem
->GetChildren().Append(controlItem
); 
 760     controlExpr 
= controlExpr
->GetNext(); 
 765 wxItemResource 
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr 
*expr
) 
 767   wxItemResource 
*controlItem 
= new wxItemResource
; 
 769   // First, find the standard features of a control definition: 
 770   // [optional integer/string id], control name, title, style, name, x, y, width, height 
 772   wxString controlType
; 
 777   long windowStyle 
= 0; 
 778   int x 
= 0; int y 
= 0; int width 
= -1; int height 
= -1; 
 781   PrologExpr 
*expr1 
= expr
->Nth(0); 
 783   if ( expr1
->Type() == PrologString 
|| expr1
->Type() == PrologWord 
) 
 785         if ( wxIsValidControlClass(expr1
->StringValue()) ) 
 788                 controlType 
= expr1
->StringValue(); 
 792         wxString 
str(expr1
->StringValue()); 
 793         id 
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
); 
 797                   sprintf(buf
, _("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"), 
 798                  (const char*) expr1
->StringValue()); 
 805                         // Success - we have an id, so the 2nd element must be the control class. 
 806                         controlType 
= expr
->Nth(1)->StringValue(); 
 811   else if (expr1
->Type() == PrologInteger
) 
 813         id 
= (int)expr1
->IntegerValue(); 
 814                 // Success - we have an id, so the 2nd element must be the control class. 
 815                 controlType 
= expr
->Nth(1)->StringValue(); 
 819   expr1 
= expr
->Nth(count
); 
 822         title 
= expr1
->StringValue(); 
 824   expr1 
= expr
->Nth(count
); 
 828     style 
= expr1
->StringValue(); 
 829     windowStyle 
= wxParseWindowStyle(WXSTRINGCAST style
); 
 832   expr1 
= expr
->Nth(count
); 
 835     name 
= expr1
->StringValue(); 
 837   expr1 
= expr
->Nth(count
); 
 840     x 
= (int)expr1
->IntegerValue(); 
 842   expr1 
= expr
->Nth(count
); 
 845     y 
= (int)expr1
->IntegerValue(); 
 847   expr1 
= expr
->Nth(count
); 
 850     width 
= (int)expr1
->IntegerValue(); 
 852   expr1 
= expr
->Nth(count
); 
 855     height 
= (int)expr1
->IntegerValue(); 
 857   controlItem
->SetStyle(windowStyle
); 
 858   controlItem
->SetName(WXSTRINGCAST name
); 
 859   controlItem
->SetTitle(WXSTRINGCAST title
); 
 860   controlItem
->SetSize(x
, y
, width
, height
); 
 861   controlItem
->SetType(WXSTRINGCAST controlType
); 
 862   controlItem
->SetId(id
); 
 864   if (controlType 
== "wxButton") 
 866     // Check for bitmap resource name 
 867     if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
))) 
 869         wxString 
str(expr
->Nth(count
)->StringValue()); 
 870         controlItem
->SetValue4(WXSTRINGCAST str
); 
 872         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 873           controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 876   else if (controlType 
== "wxCheckBox") 
 878     // Check for default value 
 879     if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 881       controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue()); 
 883       if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 884         controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 888   else if (controlType 
== "wxRadioButton") 
 890     // Check for default value 
 891     if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 893       controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue()); 
 895       if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 896         controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 900   else if (controlType 
== "wxText" || controlType 
== "wxTextCtrl") 
 902     // Check for default value 
 903     if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
))) 
 905       wxString 
str(expr
->Nth(count
)->StringValue()); 
 906       controlItem
->SetValue4(WXSTRINGCAST str
); 
 909       if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 911         // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
 912             // Do nothing - no label font any more 
 914         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 915           controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 919   else if (controlType 
== "wxMessage" || controlType 
== "wxStaticText") 
 921     // Check for bitmap resource name 
 922     if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
))) 
 924       wxString 
str(expr
->Nth(count
)->StringValue()); 
 925       controlItem
->SetValue4(WXSTRINGCAST str
); 
 927       if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 928         controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 931   else if (controlType 
== "wxGroupBox" || controlType 
== "wxStaticBox") 
 933     if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 934       controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 936   else if (controlType 
== "wxGauge") 
 938     // Check for default value 
 939     if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 941       controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue()); 
 945       if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 947         controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue()); 
 950         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 952               // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
 956           if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 957             controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 962   else if (controlType 
== "wxSlider") 
 964     // Check for default value 
 965     if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 967       controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue()); 
 971       if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 973         controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue()); 
 977         if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
 979           controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue()); 
 982           if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 984             // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
 988             if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
 989               controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
 995   else if (controlType 
== "wxScrollBar") 
 998     if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
1000       controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue()); 
1004       if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
1006         controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue()); 
1010         if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
1012           controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue()); 
1016           if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
1017             controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue()); 
1022   else if (controlType 
== "wxListBox") 
1024     PrologExpr 
*valueList 
= NULL
; 
1026     if ((valueList 
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
)) 
1028       wxStringList 
*stringList 
= new wxStringList
; 
1029       PrologExpr 
*stringExpr 
= valueList
->GetFirst(); 
1032         stringList
->Add(stringExpr
->StringValue()); 
1033         stringExpr 
= stringExpr
->GetNext(); 
1035       controlItem
->SetStringValues(stringList
); 
1038       // Check for wxSINGLE/wxMULTIPLE 
1039       PrologExpr 
*mult 
= NULL
; 
1040       controlItem
->SetValue1(wxLB_SINGLE
); 
1041       if ((mult 
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
))) 
1043         wxString 
m(mult
->StringValue()); 
1044         if (m 
== "wxMULTIPLE") 
1045           controlItem
->SetValue1(wxLB_MULTIPLE
); 
1046         else if (m 
== "wxEXTENDED") 
1047           controlItem
->SetValue1(wxLB_EXTENDED
); 
1049         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1051           // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
1053           if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1054             controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
1059   else if (controlType 
== "wxChoice") 
1061     PrologExpr 
*valueList 
= NULL
; 
1062     // Check for default value list 
1063     if ((valueList 
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
)) 
1065       wxStringList 
*stringList 
= new wxStringList
; 
1066       PrologExpr 
*stringExpr 
= valueList
->GetFirst(); 
1069         stringList
->Add(stringExpr
->StringValue()); 
1070         stringExpr 
= stringExpr
->GetNext(); 
1072       controlItem
->SetStringValues(stringList
); 
1076       if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1078         // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
1081         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1082           controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
1087   else if (controlType 
== "wxComboBox") 
1089     PrologExpr 
*textValue 
= expr
->Nth(count
); 
1090     if (textValue 
&& (textValue
->Type() == PrologString 
|| textValue
->Type() == PrologWord
)) 
1092       wxString 
str(textValue
->StringValue()); 
1093       controlItem
->SetValue4(WXSTRINGCAST str
); 
1097       PrologExpr 
*valueList 
= NULL
; 
1098       // Check for default value list 
1099       if ((valueList 
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
)) 
1101         wxStringList 
*stringList 
= new wxStringList
; 
1102         PrologExpr 
*stringExpr 
= valueList
->GetFirst(); 
1105           stringList
->Add(stringExpr
->StringValue()); 
1106           stringExpr 
= stringExpr
->GetNext(); 
1108         controlItem
->SetStringValues(stringList
); 
1112         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1114           // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
1117           if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1118             controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
1125   else if (controlType 
== "wxRadioBox") 
1127     PrologExpr 
*valueList 
= NULL
; 
1128     // Check for default value list 
1129     if ((valueList 
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
)) 
1131       wxStringList 
*stringList 
= new wxStringList
; 
1132       PrologExpr 
*stringExpr 
= valueList
->GetFirst(); 
1135         stringList
->Add(stringExpr
->StringValue()); 
1136         stringExpr 
= stringExpr
->GetNext(); 
1138       controlItem
->SetStringValues(stringList
); 
1141       // majorDim (number of rows or cols) 
1142       if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
)) 
1144         controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue()); 
1148         controlItem
->SetValue1(0); 
1150       if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1152         // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); 
1155         if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
) 
1156           controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
))); 
1169 // Forward declaration  
1170 wxItemResource 
*wxResourceInterpretMenu1(wxResourceTable
& table
, PrologExpr 
*expr
); 
1173  * Interpet a menu item 
1176 wxItemResource 
*wxResourceInterpretMenuItem(wxResourceTable
& table
, PrologExpr 
*expr
) 
1178   wxItemResource 
*item 
= new wxItemResource
; 
1180   PrologExpr 
*labelExpr 
= expr
->Nth(0); 
1181   PrologExpr 
*idExpr 
= expr
->Nth(1); 
1182   PrologExpr 
*helpExpr 
= expr
->Nth(2); 
1183   PrologExpr 
*checkableExpr 
= expr
->Nth(3); 
1185   // Further keywords/attributes to follow sometime... 
1186   if (expr
->Number() == 0) 
1188 //    item->SetType(wxRESOURCE_TYPE_SEPARATOR); 
1189     item
->SetType("wxMenuSeparator"); 
1194 //    item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter. 
1195     item
->SetType("wxMenu"); // Well, menu item, but doesn't matter. 
1198       wxString 
str(labelExpr
->StringValue()); 
1199       item
->SetTitle(WXSTRINGCAST str
); 
1204       // If a string or word, must look up in identifier table. 
1205       if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
)) 
1207         wxString 
str(idExpr
->StringValue()); 
1208         id 
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
); 
1212           sprintf(buf
, _("Could not resolve menu id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"), 
1213                  (const char*) idExpr
->StringValue()); 
1217       else if (idExpr
->Type() == PrologInteger
) 
1218         id 
= (int)idExpr
->IntegerValue(); 
1219       item
->SetValue1(id
); 
1223       wxString 
str(helpExpr
->StringValue()); 
1224       item
->SetValue4(WXSTRINGCAST str
); 
1227       item
->SetValue2(checkableExpr
->IntegerValue()); 
1229     // Find the first expression that's a list, for submenu 
1230     PrologExpr 
*subMenuExpr 
= expr
->GetFirst(); 
1231     while (subMenuExpr 
&& (subMenuExpr
->Type() != PrologList
)) 
1232       subMenuExpr 
= subMenuExpr
->GetNext(); 
1236       wxItemResource 
*child 
= wxResourceInterpretMenuItem(table
, subMenuExpr
); 
1237       item
->GetChildren().Append(child
); 
1238       subMenuExpr 
= subMenuExpr
->GetNext(); 
1245  * Interpret a nested list as a menu 
1248 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr) 
1250   wxItemResource *menu = new wxItemResource; 
1251 //  menu->SetType(wxTYPE_MENU); 
1252   menu->SetType("wxMenu"); 
1253   PrologExpr *element = expr->GetFirst(); 
1256     wxItemResource *item = wxResourceInterpretMenuItem(table, element); 
1258       menu->GetChildren().Append(item); 
1259     element = element->GetNext(); 
1265 wxItemResource 
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr 
*expr
) 
1267   PrologExpr 
*listExpr 
= NULL
; 
1268   expr
->AssignAttributeValue("menu", &listExpr
); 
1272   wxItemResource 
*menuResource 
= wxResourceInterpretMenuItem(table
, listExpr
); 
1278   expr
->AssignAttributeValue("name", &name
); 
1281     menuResource
->SetName(name
); 
1285   return menuResource
; 
1288 wxItemResource 
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr 
*expr
) 
1290   PrologExpr 
*listExpr 
= NULL
; 
1291   expr
->AssignAttributeValue("menu", &listExpr
); 
1295   wxItemResource 
*resource 
= new wxItemResource
; 
1296   resource
->SetType("wxMenu"); 
1297 //  resource->SetType(wxTYPE_MENU); 
1299   PrologExpr 
*element 
= listExpr
->GetFirst(); 
1302     wxItemResource 
*menuResource 
= wxResourceInterpretMenuItem(table
, listExpr
); 
1303     resource
->GetChildren().Append(menuResource
); 
1304     element 
= element
->GetNext(); 
1308   expr
->AssignAttributeValue("name", &name
); 
1311     resource
->SetName(name
); 
1318 wxItemResource 
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), PrologExpr 
*WXUNUSED(expr
)) 
1323 wxItemResource 
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), PrologExpr 
*expr
) 
1325   wxItemResource 
*bitmapItem 
= new wxItemResource
; 
1326 //  bitmapItem->SetType(wxTYPE_BITMAP); 
1327   bitmapItem
->SetType("wxBitmap"); 
1329   expr
->AssignAttributeValue("name", &name
); 
1332     bitmapItem
->SetName(name
); 
1335   // Now parse all bitmap specifications 
1336   PrologExpr 
*bitmapExpr 
= expr
->GetFirst(); 
1339     if (bitmapExpr
->Number() == 3) 
1341       wxString 
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue()); 
1342       if (bitmapKeyword 
== "bitmap" || bitmapKeyword 
== "icon") 
1344         // The value part: always a list. 
1345         PrologExpr 
*listExpr 
= bitmapExpr
->Nth(2); 
1346         if (listExpr
->Type() == PrologList
) 
1348           wxItemResource 
*bitmapSpec 
= new wxItemResource
; 
1349 //          bitmapSpec->SetType(wxTYPE_BITMAP); 
1350           bitmapSpec
->SetType("wxBitmap"); 
1352           // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution] 
1353           // where everything after 'filename' is optional. 
1354           PrologExpr 
*nameExpr 
= listExpr
->Nth(0); 
1355           PrologExpr 
*typeExpr 
= listExpr
->Nth(1); 
1356           PrologExpr 
*platformExpr 
= listExpr
->Nth(2); 
1357           PrologExpr 
*coloursExpr 
= listExpr
->Nth(3); 
1358           PrologExpr 
*xresExpr 
= listExpr
->Nth(4); 
1359           PrologExpr 
*yresExpr 
= listExpr
->Nth(5); 
1360           if (nameExpr 
&& nameExpr
->StringValue()) 
1362             wxString 
str(nameExpr
->StringValue()); 
1363             bitmapSpec
->SetName(WXSTRINGCAST str
); 
1365           if (typeExpr 
&& typeExpr
->StringValue()) 
1367             wxString 
str(typeExpr
->StringValue()); 
1368             bitmapSpec
->SetValue1(wxParseWindowStyle(WXSTRINGCAST str
)); 
1371             bitmapSpec
->SetValue1(0); 
1373           if (platformExpr 
&& platformExpr
->StringValue()) 
1375             wxString 
plat(platformExpr
->StringValue()); 
1376             if (plat 
== "windows" || plat 
== "WINDOWS") 
1377               bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
); 
1378             else if (plat 
== "x" || plat 
== "X") 
1379               bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
); 
1380             else if (plat 
== "mac" || plat 
== "MAC") 
1381               bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
); 
1383               bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
); 
1386             bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
); 
1389             bitmapSpec
->SetValue3(coloursExpr
->IntegerValue()); 
1393             xres 
= (int)xresExpr
->IntegerValue(); 
1395             yres 
= (int)yresExpr
->IntegerValue(); 
1396           bitmapSpec
->SetSize(0, 0, xres
, yres
); 
1398           bitmapItem
->GetChildren().Append(bitmapSpec
); 
1402     bitmapExpr 
= bitmapExpr
->GetNext(); 
1408 wxItemResource 
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr 
*expr
) 
1410   wxItemResource 
*item 
= wxResourceInterpretBitmap(table
, expr
); 
1413 //    item->SetType(wxTYPE_ICON); 
1414     item
->SetType("wxIcon"); 
1421 // Interpret list expression as a font 
1422 wxFont 
*wxResourceInterpretFontSpec(PrologExpr 
*expr
) 
1424   if (expr
->Type() != PrologList
) 
1428   int family 
= wxSWISS
; 
1429   int style 
= wxNORMAL
; 
1430   int weight 
= wxNORMAL
; 
1432   wxString 
faceName(""); 
1434   PrologExpr 
*pointExpr 
= expr
->Nth(0); 
1435   PrologExpr 
*familyExpr 
= expr
->Nth(1); 
1436   PrologExpr 
*styleExpr 
= expr
->Nth(2); 
1437   PrologExpr 
*weightExpr 
= expr
->Nth(3); 
1438   PrologExpr 
*underlineExpr 
= expr
->Nth(4); 
1439   PrologExpr 
*faceNameExpr 
= expr
->Nth(5); 
1441     point 
= (int)pointExpr
->IntegerValue(); 
1446     str 
= familyExpr
->StringValue(); 
1447     family 
= (int)wxParseWindowStyle(WXSTRINGCAST str
); 
1451     str 
= styleExpr
->StringValue(); 
1452     style 
= (int)wxParseWindowStyle(WXSTRINGCAST str
); 
1456     str 
= weightExpr
->StringValue(); 
1457     weight 
= (int)wxParseWindowStyle(WXSTRINGCAST str
); 
1460     underline 
= (int)underlineExpr
->IntegerValue(); 
1462     faceName 
= faceNameExpr
->StringValue(); 
1464   char *faceName1 
= NULL
; 
1466     faceName1 
= WXSTRINGCAST faceName
; 
1467   wxFont 
*font 
= wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
, (underline 
!= 0), faceName1
); 
1472  * (Re)allocate buffer for reading in from resource file 
1475 bool wxReallocateResourceBuffer(void) 
1477   if (!wxResourceBuffer
) 
1479     wxResourceBufferSize 
= 1000; 
1480     wxResourceBuffer 
= new char[wxResourceBufferSize
]; 
1483   if (wxResourceBuffer
) 
1485     long newSize 
= wxResourceBufferSize 
+ 1000; 
1486     char *tmp 
= new char[(int)newSize
]; 
1487     strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
); 
1488     delete[] wxResourceBuffer
; 
1489     wxResourceBuffer 
= tmp
; 
1490     wxResourceBufferSize 
= newSize
; 
1495 static bool wxEatWhiteSpace(FILE *fd
) 
1498   if ((ch 
!= ' ') && (ch 
!= '/') && (ch 
!= ' ') && (ch 
!= 10) && (ch 
!= 13) && (ch 
!= 9)) 
1505   while (ch 
== ' ' || ch 
== 10 || ch 
== 13 || ch 
== 9) 
1507   // Check for comment 
1513       bool finished 
= FALSE
; 
1521           int newCh 
= getc(fd
); 
1536   return wxEatWhiteSpace(fd
); 
1539 bool wxGetResourceToken(FILE *fd
) 
1541   if (!wxResourceBuffer
) 
1542     wxReallocateResourceBuffer(); 
1543   wxResourceBuffer
[0] = 0; 
1544   wxEatWhiteSpace(fd
); 
1550     wxResourceBufferCount 
= 0; 
1557         wxResourceBuffer
[wxResourceBufferCount
] = 0; 
1560       // Escaped characters 
1561       else if (ch 
== '\\') 
1563         int newCh 
= getc(fd
); 
1566         else if (newCh 
== 10) 
1574       if (wxResourceBufferCount 
>= wxResourceBufferSize
-1) 
1575         wxReallocateResourceBuffer(); 
1576       wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
; 
1577       wxResourceBufferCount 
++; 
1580     wxResourceBuffer
[wxResourceBufferCount
] = 0; 
1584     wxResourceBufferCount 
= 0; 
1586     while (ch 
!= ' ' && ch 
!= EOF 
&& ch 
!= ' ' && ch 
!= 13 && ch 
!= 9 && ch 
!= 10) 
1588       if (wxResourceBufferCount 
>= wxResourceBufferSize
-1) 
1589         wxReallocateResourceBuffer(); 
1590       wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
; 
1591       wxResourceBufferCount 
++; 
1595     wxResourceBuffer
[wxResourceBufferCount
] = 0; 
1603  * Files are in form: 
1604   static char *name = "...."; 
1605   with possible comments. 
1608 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable 
*table
) 
1611     table 
= wxDefaultResourceTable
; 
1613   // static or #define 
1614   if (!wxGetResourceToken(fd
)) 
1620   if (strcmp(wxResourceBuffer
, "#define") == 0) 
1622     wxGetResourceToken(fd
); 
1623     char *name 
= copystring(wxResourceBuffer
); 
1624     wxGetResourceToken(fd
); 
1625     char *value 
= copystring(wxResourceBuffer
); 
1626     if (isalpha(value
[0])) 
1628       int val 
= (int)atol(value
); 
1629       wxResourceAddIdentifier(name
, val
, table
); 
1634       sprintf(buf
, _("#define %s must be an integer."), name
); 
1645   else if (strcmp(wxResourceBuffer
, "#include") == 0) 
1647     wxGetResourceToken(fd
); 
1648     char *name 
= copystring(wxResourceBuffer
); 
1649     char *actualName 
= name
; 
1651       actualName 
= name 
+ 1; 
1652     int len 
= strlen(name
); 
1653     if ((len 
> 0) && (name
[len
-1] == '"')) 
1655     if (!wxResourceParseIncludeFile(actualName
, table
)) 
1658       sprintf(buf
, _("Could not find resource include file %s."), actualName
); 
1664   else if (strcmp(wxResourceBuffer
, "static") != 0) 
1667     strcpy(buf
, _("Found ")); 
1668     strncat(buf
, wxResourceBuffer
, 30); 
1669     strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource.")); 
1675   if (!wxGetResourceToken(fd
)) 
1677     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
1682   if (strcmp(wxResourceBuffer
, "char") != 0) 
1684     wxWarning(_("Expected 'char' whilst parsing resource.")); 
1689   if (!wxGetResourceToken(fd
)) 
1691     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
1696   if (wxResourceBuffer
[0] != '*') 
1698     wxWarning(_("Expected '*' whilst parsing resource.")); 
1702   strncpy(nameBuf
, wxResourceBuffer
+1, 99); 
1705   if (!wxGetResourceToken(fd
)) 
1707     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
1712   if (strcmp(wxResourceBuffer
, "=") != 0) 
1714     wxWarning(_("Expected '=' whilst parsing resource.")); 
1719   if (!wxGetResourceToken(fd
)) 
1721     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
1727     if (!db
.ReadPrologFromString(wxResourceBuffer
)) 
1730       sprintf(buf
, _("%s: ill-formed resource file syntax."), nameBuf
); 
1736   if (!wxGetResourceToken(fd
)) 
1744  * Parses string window style into integer window style 
1748  * Style flag parsing, e.g. 
1749  * "wxSYSTEM_MENU | wxBORDER" -> integer 
1752 char *wxResourceParseWord(char *s
, int *i
) 
1757   static char buf
[150]; 
1758   int len 
= strlen(s
); 
1761   while ((ii 
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_'))) 
1769   // Eat whitespace and conjunction characters 
1770   while ((ii 
< len
) && 
1771          ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ','))) 
1782 struct wxResourceBitListStruct
 
1788 static wxResourceBitListStruct wxResourceBitListTable
[] = 
1791   { "wxSINGLE", wxLB_SINGLE 
}, 
1792   { "wxMULTIPLE", wxLB_MULTIPLE 
}, 
1793   { "wxEXTENDED", wxLB_EXTENDED 
}, 
1794   { "wxLB_SINGLE", wxLB_SINGLE 
}, 
1795   { "wxLB_MULTIPLE", wxLB_MULTIPLE 
}, 
1796   { "wxLB_EXTENDED", wxLB_EXTENDED 
}, 
1797   { "wxNEEDED_SB", wxNEEDED_SB 
}, 
1798   { "wxALWAYS_SB", wxALWAYS_SB 
}, 
1799   { "wxLB_NEEDED_SB", wxLB_NEEDED_SB 
}, 
1800   { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB 
}, 
1801   { "wxLB_SORT", wxLB_SORT 
}, 
1802   { "wxLB_OWNERDRAW", wxLB_OWNERDRAW 
}, 
1803   { "wxLB_HSCROLL", wxLB_HSCROLL 
}, 
1806   { "wxCB_SIMPLE", wxCB_SIMPLE 
}, 
1807   { "wxCB_DROPDOWN", wxCB_DROPDOWN 
}, 
1808   { "wxCB_READONLY", wxCB_READONLY 
}, 
1809   { "wxCB_SORT", wxCB_SORT 
}, 
1812   { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR 
}, 
1813   { "wxGA_HORIZONTAL", wxGA_HORIZONTAL 
}, 
1814   { "wxGA_VERTICAL", wxGA_VERTICAL 
}, 
1817   { "wxPASSWORD", wxPASSWORD
}, 
1818   { "wxPROCESS_ENTER", wxPROCESS_ENTER
}, 
1819   { "wxTE_PASSWORD", wxTE_PASSWORD
}, 
1820   { "wxTE_READONLY", wxTE_READONLY
}, 
1821   { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
}, 
1822   { "wxTE_MULTILINE", wxTE_MULTILINE
}, 
1824   /* wxRadioBox/wxRadioButton */ 
1825   { "wxRB_GROUP", wxRB_GROUP 
}, 
1826   { "wxRA_HORIZONTAL", wxRA_HORIZONTAL 
}, 
1827   { "wxRA_VERTICAL", wxRA_VERTICAL 
}, 
1830   { "wxSL_HORIZONTAL", wxSL_HORIZONTAL 
}, 
1831   { "wxSL_VERTICAL", wxSL_VERTICAL 
}, 
1832   { "wxSL_AUTOTICKS", wxSL_AUTOTICKS 
}, 
1833   { "wxSL_LABELS", wxSL_LABELS 
}, 
1834   { "wxSL_LEFT", wxSL_LEFT 
}, 
1835   { "wxSL_TOP", wxSL_TOP 
}, 
1836   { "wxSL_RIGHT", wxSL_RIGHT 
}, 
1837   { "wxSL_BOTTOM", wxSL_BOTTOM 
}, 
1838   { "wxSL_BOTH", wxSL_BOTH 
}, 
1839   { "wxSL_SELRANGE", wxSL_SELRANGE 
}, 
1842   { "wxSB_HORIZONTAL", wxSB_HORIZONTAL 
}, 
1843   { "wxSB_VERTICAL", wxSB_VERTICAL 
}, 
1846   { "wxBU_AUTODRAW", wxBU_AUTODRAW 
}, 
1847   { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW 
}, 
1850   { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS 
}, 
1851   { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS 
}, 
1852   { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT 
}, 
1855   { "wxLC_ICON", wxLC_ICON 
}, 
1856   { "wxLC_SMALL_ICON", wxLC_SMALL_ICON 
}, 
1857   { "wxLC_LIST", wxLC_LIST 
}, 
1858   { "wxLC_REPORT", wxLC_REPORT 
}, 
1859   { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP 
}, 
1860   { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT 
}, 
1861   { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE 
}, 
1862   { "wxLC_USER_TEXT", wxLC_USER_TEXT 
}, 
1863   { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS 
}, 
1864   { "wxLC_NO_HEADER", wxLC_NO_HEADER 
}, 
1865   { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER 
}, 
1866   { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL 
}, 
1867   { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING 
}, 
1868   { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING 
}, 
1871   { "wxSP_VERTICAL", wxSP_VERTICAL
}, 
1872   { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
}, 
1873   { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
}, 
1874   { "wxSP_WRAP", wxSP_WRAP
}, 
1877   { "wxSP_NOBORDER", wxSP_NOBORDER
}, 
1878   { "wxSP_3D", wxSP_3D
}, 
1879   { "wxSP_BORDER", wxSP_BORDER
}, 
1882   { "wxTC_MULTILINE", wxTC_MULTILINE
}, 
1883   { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
}, 
1884   { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
}, 
1885   { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
}, 
1888   { "wxST_SIZEGRIP", wxST_SIZEGRIP
}, 
1891   { "wxFIXED_LENGTH", wxFIXED_LENGTH
}, 
1892   { "wxALIGN_LEFT", wxALIGN_LEFT
}, 
1893   { "wxALIGN_CENTER", wxALIGN_CENTER
}, 
1894   { "wxALIGN_CENTRE", wxALIGN_CENTRE
}, 
1895   { "wxALIGN_RIGHT", wxALIGN_RIGHT
}, 
1896   { "wxCOLOURED", wxCOLOURED
}, 
1899   { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
}, 
1900   { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
}, 
1901   { "wxTB_VERTICAL", wxTB_VERTICAL
}, 
1902   { "wxTB_FLAT", wxTB_FLAT
}, 
1905   { "wxVSCROLL", wxVSCROLL 
}, 
1906   { "wxHSCROLL", wxHSCROLL 
}, 
1907   { "wxCAPTION", wxCAPTION 
}, 
1908   { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
}, 
1909   { "wxICONIZE", wxICONIZE
}, 
1910   { "wxMINIMIZE", wxICONIZE
}, 
1911   { "wxMAXIMIZE", wxMAXIMIZE
}, 
1913   { "wxMDI_PARENT", 0}, 
1914   { "wxMDI_CHILD", 0}, 
1915   { "wxTHICK_FRAME", wxTHICK_FRAME
}, 
1916   { "wxRESIZE_BORDER", wxRESIZE_BORDER
}, 
1917   { "wxSYSTEM_MENU", wxSYSTEM_MENU
}, 
1918   { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
}, 
1919   { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
}, 
1920   { "wxRESIZE_BOX", wxRESIZE_BOX
}, 
1921   { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
}, 
1922   { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
}, 
1923   { "wxBORDER", wxBORDER
}, 
1924   { "wxRETAINED", wxRETAINED
}, 
1925   { "wxEDITABLE", wxEDITABLE
}, 
1926   { "wxREADONLY", wxREADONLY
}, 
1927   { "wxNATIVE_IMPL", 0}, 
1928   { "wxEXTENDED_IMPL", 0}, 
1929   { "wxBACKINGSTORE", wxBACKINGSTORE
}, 
1930 //  { "wxFLAT", wxFLAT}, 
1931 //  { "wxMOTIF_RESIZE", wxMOTIF_RESIZE}, 
1932   { "wxFIXED_LENGTH", 0}, 
1933   { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
}, 
1934   { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
}, 
1935   { "wxRAISED_BORDER", wxRAISED_BORDER
}, 
1936   { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
}, 
1937   { "wxSTATIC_BORDER", wxSTATIC_BORDER
}, 
1938   { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
}, 
1939   { "wxNO_BORDER", wxNO_BORDER
}, 
1940   { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
}, 
1942   { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
}, 
1943   { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
}, 
1945   // Text font families 
1946   { "wxDEFAULT", wxDEFAULT
}, 
1947   { "wxDECORATIVE", wxDECORATIVE
}, 
1948   { "wxROMAN", wxROMAN
}, 
1949   { "wxSCRIPT", wxSCRIPT
}, 
1950   { "wxSWISS", wxSWISS
}, 
1951   { "wxMODERN", wxMODERN
}, 
1952   { "wxTELETYPE", wxTELETYPE
}, 
1953   { "wxVARIABLE", wxVARIABLE
}, 
1954   { "wxFIXED", wxFIXED
}, 
1955   { "wxNORMAL", wxNORMAL
}, 
1956   { "wxLIGHT", wxLIGHT
}, 
1957   { "wxBOLD", wxBOLD
}, 
1958   { "wxITALIC", wxITALIC
}, 
1959   { "wxSLANT", wxSLANT
}, 
1960   { "wxSOLID", wxSOLID
}, 
1962   { "wxLONG_DASH", wxLONG_DASH
}, 
1963   { "wxSHORT_DASH", wxSHORT_DASH
}, 
1964   { "wxDOT_DASH", wxDOT_DASH
}, 
1965   { "wxUSER_DASH", wxUSER_DASH
}, 
1966   { "wxTRANSPARENT", wxTRANSPARENT
}, 
1967   { "wxSTIPPLE", wxSTIPPLE
}, 
1968   { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
}, 
1969   { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
}, 
1970   { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
}, 
1971   { "wxCROSS_HATCH", wxCROSS_HATCH
}, 
1972   { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
}, 
1973   { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
}, 
1974   { "wxJOIN_BEVEL", wxJOIN_BEVEL
}, 
1975   { "wxJOIN_MITER", wxJOIN_MITER
}, 
1976   { "wxJOIN_ROUND", wxJOIN_ROUND
}, 
1977   { "wxCAP_ROUND", wxCAP_ROUND
}, 
1978   { "wxCAP_PROJECTING", wxCAP_PROJECTING
}, 
1979   { "wxCAP_BUTT", wxCAP_BUTT
}, 
1982   { "wxCLEAR", wxCLEAR
}, 
1984   { "wxINVERT", wxINVERT
}, 
1985   { "wxOR_REVERSE", wxOR_REVERSE
}, 
1986   { "wxAND_REVERSE", wxAND_REVERSE
}, 
1987   { "wxCOPY", wxCOPY
}, 
1989   { "wxAND_INVERT", wxAND_INVERT
}, 
1990   { "wxNO_OP", wxNO_OP
}, 
1992   { "wxEQUIV", wxEQUIV
}, 
1993   { "wxSRC_INVERT", wxSRC_INVERT
}, 
1994   { "wxOR_INVERT", wxOR_INVERT
}, 
1995   { "wxNAND", wxNAND
}, 
1999   { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
}, 
2000   { "wxFLOOD_BORDER", wxFLOOD_BORDER
}, 
2001   { "wxODDEVEN_RULE", wxODDEVEN_RULE
}, 
2002   { "wxWINDING_RULE", wxWINDING_RULE
}, 
2003   { "wxHORIZONTAL", wxHORIZONTAL
}, 
2004   { "wxVERTICAL", wxVERTICAL
}, 
2005   { "wxBOTH", wxBOTH
}, 
2006   { "wxCENTER_FRAME", wxCENTER_FRAME
}, 
2008   { "wxYES_NO", wxYES_NO
}, 
2009   { "wxCANCEL", wxCANCEL
}, 
2012   { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
}, 
2013   { "wxICON_HAND", wxICON_HAND
}, 
2014   { "wxICON_QUESTION", wxICON_QUESTION
}, 
2015   { "wxICON_INFORMATION", wxICON_INFORMATION
}, 
2016   { "wxICON_STOP", wxICON_STOP
}, 
2017   { "wxICON_ASTERISK", wxICON_ASTERISK
}, 
2018   { "wxICON_MASK", wxICON_MASK
}, 
2019   { "wxCENTRE", wxCENTRE
}, 
2020   { "wxCENTER", wxCENTRE
}, 
2021   { "wxUSER_COLOURS", wxUSER_COLOURS
}, 
2022   { "wxVERTICAL_LABEL", 0}, 
2023   { "wxHORIZONTAL_LABEL", 0}, 
2025   // Bitmap types (not strictly styles) 
2026   { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
}, 
2027   { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
}, 
2028   { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
}, 
2029   { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
}, 
2030   { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
}, 
2031   { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
}, 
2032   { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
}, 
2033   { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
}, 
2034   { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
}, 
2035   { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
}, 
2036   { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
}, 
2037   { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
}, 
2038   { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
}, 
2039   { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
} 
2042 static int wxResourceBitListCount 
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
)); 
2044 long wxParseWindowStyle(char *bitListString
) 
2049   while ((word 
= wxResourceParseWord(bitListString
, &i
))) 
2053     for (j 
= 0; j 
< wxResourceBitListCount
; j
++) 
2054       if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0) 
2056         bitList 
|= wxResourceBitListTable
[j
].bits
; 
2063       sprintf(buf
, _("Unrecognized style %s whilst parsing resource."), word
); 
2072  * Load a bitmap from a wxWindows resource, choosing an optimum 
2073  * depth and appropriate type. 
2076 wxBitmap 
*wxResourceCreateBitmap(char *resource
, wxResourceTable 
*table
) 
2079     table 
= wxDefaultResourceTable
; 
2081   wxItemResource 
*item 
= table
->FindResource(resource
); 
2084     if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0) 
2087       sprintf(buf
, _("%s not a bitmap resource specification."), resource
); 
2091     int thisDepth 
= wxDisplayDepth(); 
2092     long thisNoColours 
= (long)pow(2.0, (double)thisDepth
); 
2094     wxItemResource 
*optResource 
= NULL
; 
2096     // Try to find optimum bitmap for this platform/colour depth 
2097     wxNode 
*node 
= item
->GetChildren().First(); 
2100       wxItemResource 
*child 
= (wxItemResource 
*)node
->Data(); 
2101       int platform 
= (int)child
->GetValue2(); 
2102       int noColours 
= (int)child
->GetValue3(); 
2104       char *name = child->GetName(); 
2105       int bitmapType = (int)child->GetValue1(); 
2106       int xRes = child->GetWidth(); 
2107       int yRes = child->GetHeight(); 
2112         case RESOURCE_PLATFORM_ANY
: 
2114           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2115             optResource 
= child
; 
2118             // Maximise the number of colours. 
2119             // If noColours is zero (unspecified), then assume this 
2120             // is the right one. 
2121             if ((noColours 
== 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2122               optResource 
= child
; 
2127         case RESOURCE_PLATFORM_WINDOWS
: 
2129           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2130             optResource 
= child
; 
2133             // Maximise the number of colours 
2134             if ((noColours 
> 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2135               optResource 
= child
; 
2141         case RESOURCE_PLATFORM_X
: 
2143           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2144             optResource 
= child
; 
2147             // Maximise the number of colours 
2148             if ((noColours 
== 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2149               optResource 
= child
; 
2155         case RESOURCE_PLATFORM_MAC
: 
2157           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2158             optResource 
= child
; 
2161             // Maximise the number of colours 
2162             if ((noColours 
== 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2163               optResource 
= child
; 
2171       node 
= node
->Next(); 
2173     // If no matching resource, fail. 
2177     char *name 
= optResource
->GetName(); 
2178     int bitmapType 
= (int)optResource
->GetValue1(); 
2179     wxBitmap 
*bitmap 
= NULL
; 
2182       case wxBITMAP_TYPE_XBM_DATA
: 
2185         wxItemResource 
*item 
= table
->FindResource(name
); 
2189           sprintf(buf
, _("Failed to find XBM resource %s.\nForgot to use wxResourceLoadBitmapData?"), name
); 
2193         bitmap 
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());  
2195         wxWarning(_("No XBM facility available!")); 
2199       case wxBITMAP_TYPE_XPM_DATA
: 
2201 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW) 
2202         wxItemResource 
*item 
= table
->FindResource(name
); 
2206           sprintf(buf
, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), name
); 
2210         bitmap 
= new wxBitmap(item
->GetValue1()); 
2212         wxWarning(_("No XPM facility available!")); 
2218         bitmap 
= new wxBitmap(name
, bitmapType
); 
2238     sprintf(buf
, _("Bitmap resource specification %s not found."), resource
); 
2245  * Load an icon from a wxWindows resource, choosing an optimum 
2246  * depth and appropriate type. 
2249 wxIcon 
*wxResourceCreateIcon(char *resource
, wxResourceTable 
*table
) 
2252   table 
= wxDefaultResourceTable
; 
2254   wxItemResource 
*item 
= table
->FindResource(resource
); 
2257     if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0) 
2260       sprintf(buf
, _("%s not an icon resource specification."), resource
); 
2264     int thisDepth 
= wxDisplayDepth(); 
2265     long thisNoColours 
= (long)pow(2.0, (double)thisDepth
); 
2267     wxItemResource 
*optResource 
= NULL
; 
2269     // Try to find optimum icon for this platform/colour depth 
2270     wxNode 
*node 
= item
->GetChildren().First(); 
2273       wxItemResource 
*child 
= (wxItemResource 
*)node
->Data(); 
2274       int platform 
= (int)child
->GetValue2(); 
2275       int noColours 
= (int)child
->GetValue3(); 
2277       char *name = child->GetName(); 
2278       int bitmapType = (int)child->GetValue1(); 
2279       int xRes = child->GetWidth(); 
2280       int yRes = child->GetHeight(); 
2285         case RESOURCE_PLATFORM_ANY
: 
2287           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2288             optResource 
= child
; 
2291             // Maximise the number of colours. 
2292             // If noColours is zero (unspecified), then assume this 
2293             // is the right one. 
2294             if ((noColours 
== 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2295               optResource 
= child
; 
2300         case RESOURCE_PLATFORM_WINDOWS
: 
2302           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2303             optResource 
= child
; 
2306             // Maximise the number of colours 
2307             if ((noColours 
> 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2308               optResource 
= child
; 
2314         case RESOURCE_PLATFORM_X
: 
2316           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2317             optResource 
= child
; 
2320             // Maximise the number of colours 
2321             if ((noColours 
== 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2322               optResource 
= child
; 
2328         case RESOURCE_PLATFORM_MAC
: 
2330           if (!optResource 
&& ((noColours 
== 0) || (noColours 
<= thisNoColours
))) 
2331             optResource 
= child
; 
2334             // Maximise the number of colours 
2335             if ((noColours 
== 0) || ((noColours 
<= thisNoColours
) && (noColours 
> optResource
->GetValue3()))) 
2336               optResource 
= child
; 
2344       node 
= node
->Next(); 
2346     // If no matching resource, fail. 
2350     char *name 
= optResource
->GetName(); 
2351     int bitmapType 
= (int)optResource
->GetValue1(); 
2352     wxIcon 
*icon 
= NULL
; 
2355       case wxBITMAP_TYPE_XBM_DATA
: 
2358         wxItemResource 
*item 
= table
->FindResource(name
); 
2362           sprintf(buf
, _("Failed to find XBM resource %s.\nForgot to use wxResourceLoadIconData?"), name
); 
2366         icon 
= new wxIcon((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());  
2368         wxWarning(_("No XBM facility available!")); 
2372       case wxBITMAP_TYPE_XPM_DATA
: 
2374       // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS *** 
2376 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW) 
2377         wxItemResource *item = table->FindResource(name); 
2381           sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name); 
2385         icon = new wxIcon((char **)item->GetValue1()); 
2387         wxWarning(_("No XPM facility available!")); 
2390         wxWarning(_("No XPM icon facility available!")); 
2395         icon 
= new wxIcon(name
, bitmapType
); 
2415     sprintf(buf
, _("Icon resource specification %s not found."), resource
); 
2421 wxMenu 
*wxResourceCreateMenu(wxItemResource 
*item
) 
2423   wxMenu 
*menu 
= new wxMenu
; 
2424   wxNode 
*node 
= item
->GetChildren().First(); 
2427     wxItemResource 
*child 
= (wxItemResource 
*)node
->Data(); 
2428     if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0) 
2429       menu
->AppendSeparator(); 
2430     else if (child
->GetChildren().Number() > 0) 
2432       wxMenu 
*subMenu 
= wxResourceCreateMenu(child
); 
2434         menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4()); 
2438       menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0)); 
2440     node 
= node
->Next(); 
2445 wxMenuBar 
*wxResourceCreateMenuBar(char *resource
, wxResourceTable 
*table
, wxMenuBar 
*menuBar
) 
2448     table 
= wxDefaultResourceTable
; 
2450   wxItemResource 
*menuResource 
= table
->FindResource(resource
); 
2451   if (menuResource 
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0) 
2454       menuBar 
= new wxMenuBar
; 
2455     wxNode 
*node 
= menuResource
->GetChildren().First(); 
2458       wxItemResource 
*child 
= (wxItemResource 
*)node
->Data(); 
2459       wxMenu 
*menu 
= wxResourceCreateMenu(child
); 
2461         menuBar
->Append(menu
, child
->GetTitle()); 
2462       node 
= node
->Next(); 
2469 wxMenu 
*wxResourceCreateMenu(char *resource
, wxResourceTable 
*table
) 
2472     table 
= wxDefaultResourceTable
; 
2474   wxItemResource 
*menuResource 
= table
->FindResource(resource
); 
2475   if (menuResource 
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0) 
2476 //  if (menuResource && (menuResource->GetType() == wxTYPE_MENU)) 
2477     return wxResourceCreateMenu(menuResource
); 
2481 // Global equivalents (so don't have to refer to default table explicitly) 
2482 bool wxResourceParseData(char *resource
, wxResourceTable 
*table
) 
2485     table 
= wxDefaultResourceTable
; 
2487   return table
->ParseResourceData(resource
); 
2490 bool wxResourceParseFile(char *filename
, wxResourceTable 
*table
) 
2493     table 
= wxDefaultResourceTable
; 
2495   return table
->ParseResourceFile(filename
); 
2498 // Register XBM/XPM data 
2499 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable 
*table
) 
2502     table 
= wxDefaultResourceTable
; 
2504   return table
->RegisterResourceBitmapData(name
, bits
, width
, height
); 
2507 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable 
*table
) 
2510     table 
= wxDefaultResourceTable
; 
2512   return table
->RegisterResourceBitmapData(name
, data
); 
2515 void wxResourceClear(wxResourceTable 
*table
) 
2518     table 
= wxDefaultResourceTable
; 
2520   table
->ClearTable(); 
2527 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable 
*table
) 
2530     table 
= wxDefaultResourceTable
; 
2532   table
->identifiers
.Put(name
, (wxObject 
*)value
); 
2536 int wxResourceGetIdentifier(char *name
, wxResourceTable 
*table
) 
2539     table 
= wxDefaultResourceTable
; 
2541   return (int)table
->identifiers
.Get(name
); 
2545  * Parse #include file for #defines (only) 
2548 bool wxResourceParseIncludeFile(char *f
, wxResourceTable 
*table
) 
2551     table 
= wxDefaultResourceTable
; 
2553   FILE *fd 
= fopen(f
, "r"); 
2558   while (wxGetResourceToken(fd
)) 
2560     if (strcmp(wxResourceBuffer
, "#define") == 0) 
2562       wxGetResourceToken(fd
); 
2563       char *name 
= copystring(wxResourceBuffer
); 
2564       wxGetResourceToken(fd
); 
2565       char *value 
= copystring(wxResourceBuffer
); 
2566       if (isdigit(value
[0])) 
2568         int val 
= (int)atol(value
); 
2569         wxResourceAddIdentifier(name
, val
, table
); 
2580  * Reading strings as if they were .wxr files 
2583 static int getc_string(char *s
) 
2585   int ch 
= s
[wxResourceStringPtr
]; 
2590     wxResourceStringPtr 
++; 
2595 static int ungetc_string(void) 
2597   wxResourceStringPtr 
--; 
2601 bool wxEatWhiteSpaceString(char *s
) 
2603   int ch 
= getc_string(s
); 
2607   if ((ch 
!= ' ') && (ch 
!= '/') && (ch 
!= ' ') && (ch 
!= 10) && (ch 
!= 13) && (ch 
!= 9)) 
2614   while (ch 
== ' ' || ch 
== 10 || ch 
== 13 || ch 
== 9) 
2615     ch 
= getc_string(s
); 
2616   // Check for comment 
2619     ch 
= getc_string(s
); 
2622       bool finished 
= FALSE
; 
2625         ch 
= getc_string(s
); 
2630           int newCh 
= getc_string(s
); 
2645   return wxEatWhiteSpaceString(s
); 
2648 bool wxGetResourceTokenString(char *s
) 
2650   if (!wxResourceBuffer
) 
2651     wxReallocateResourceBuffer(); 
2652   wxResourceBuffer
[0] = 0; 
2653   wxEatWhiteSpaceString(s
); 
2655   int ch 
= getc_string(s
); 
2659     wxResourceBufferCount 
= 0; 
2660     ch 
= getc_string(s
); 
2666         wxResourceBuffer
[wxResourceBufferCount
] = 0; 
2669       // Escaped characters 
2670       else if (ch 
== '\\') 
2672         int newCh 
= getc_string(s
); 
2675         else if (newCh 
== 10) 
2683       if (wxResourceBufferCount 
>= wxResourceBufferSize
-1) 
2684         wxReallocateResourceBuffer(); 
2685       wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
; 
2686       wxResourceBufferCount 
++; 
2687       ch 
= getc_string(s
); 
2689     wxResourceBuffer
[wxResourceBufferCount
] = 0; 
2693     wxResourceBufferCount 
= 0; 
2695     while (ch 
!= ' ' && ch 
!= EOF 
&& ch 
!= ' ' && ch 
!= 13 && ch 
!= 9 && ch 
!= 10) 
2697       if (wxResourceBufferCount 
>= wxResourceBufferSize
-1) 
2698         wxReallocateResourceBuffer(); 
2699       wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
; 
2700       wxResourceBufferCount 
++; 
2702       ch 
= getc_string(s
); 
2704     wxResourceBuffer
[wxResourceBufferCount
] = 0; 
2712  * Files are in form: 
2713   static char *name = "...."; 
2714   with possible comments. 
2717 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable 
*table
) 
2720     table 
= wxDefaultResourceTable
; 
2722   // static or #define 
2723   if (!wxGetResourceTokenString(s
)) 
2729   if (strcmp(wxResourceBuffer
, "#define") == 0) 
2731     wxGetResourceTokenString(s
); 
2732     char *name 
= copystring(wxResourceBuffer
); 
2733     wxGetResourceTokenString(s
); 
2734     char *value 
= copystring(wxResourceBuffer
); 
2735     if (isalpha(value
[0])) 
2737       int val 
= (int)atol(value
); 
2738       wxResourceAddIdentifier(name
, val
, table
); 
2743       sprintf(buf
, _("#define %s must be an integer."), name
); 
2755   else if (strcmp(wxResourceBuffer, "#include") == 0) 
2757     wxGetResourceTokenString(s); 
2758     char *name = copystring(wxResourceBuffer); 
2759     char *actualName = name; 
2761       actualName = name + 1; 
2762     int len = strlen(name); 
2763     if ((len > 0) && (name[len-1] == '"')) 
2765     if (!wxResourceParseIncludeFile(actualName, table)) 
2768       sprintf(buf, _("Could not find resource include file %s."), actualName); 
2775   else if (strcmp(wxResourceBuffer
, "static") != 0) 
2778     strcpy(buf
, _("Found ")); 
2779     strncat(buf
, wxResourceBuffer
, 30); 
2780     strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource.")); 
2786   if (!wxGetResourceTokenString(s
)) 
2788     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
2793   if (strcmp(wxResourceBuffer
, "char") != 0) 
2795     wxWarning(_("Expected 'char' whilst parsing resource.")); 
2800   if (!wxGetResourceTokenString(s
)) 
2802     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
2807   if (wxResourceBuffer
[0] != '*') 
2809     wxWarning(_("Expected '*' whilst parsing resource.")); 
2813   strncpy(nameBuf
, wxResourceBuffer
+1, 99); 
2816   if (!wxGetResourceTokenString(s
)) 
2818     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
2823   if (strcmp(wxResourceBuffer
, "=") != 0) 
2825     wxWarning(_("Expected '=' whilst parsing resource.")); 
2830   if (!wxGetResourceTokenString(s
)) 
2832     wxWarning(_("Unexpected end of file whilst parsing resource.")); 
2838     if (!db
.ReadPrologFromString(wxResourceBuffer
)) 
2841       sprintf(buf
, _("%s: ill-formed resource file syntax."), nameBuf
); 
2847   if (!wxGetResourceTokenString(s
)) 
2854 bool wxResourceParseString(char *s
, wxResourceTable 
*table
) 
2857     table 
= wxDefaultResourceTable
; 
2862   // Turn backslashes into spaces  
2865     int len 
= strlen(s
); 
2867     for (i 
= 0; i 
< len
; i
++) 
2868       if (s
[i
] == 92 && s
[i
+1] == 13) 
2876   wxResourceStringPtr 
= 0; 
2879   while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
) 
2883   return wxResourceInterpretResources(*table
, db
); 
2887  * resource loading facility 
2890 bool wxWindow::LoadFromResource(wxWindow 
*parent
, const wxString
& resourceName
, const wxResourceTable 
*table
) 
2893     table 
= wxDefaultResourceTable
; 
2895   wxItemResource 
*resource 
= table
->FindResource((const char *)resourceName
); 
2896 //  if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX)) 
2897   if (!resource 
|| !resource
->GetType() || 
2898     ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0))) 
2901   char *title 
= resource
->GetTitle(); 
2902   long theWindowStyle 
= resource
->GetStyle(); 
2903   bool isModal 
= (resource
->GetValue1() != 0); 
2904   int x 
= resource
->GetX(); 
2905   int y 
= resource
->GetY(); 
2906   int width 
= resource
->GetWidth(); 
2907   int height 
= resource
->GetHeight(); 
2908   char *name 
= resource
->GetName(); 
2910   wxFont 
*theFont 
= resource
->GetFont(); 
2912   if (IsKindOf(CLASSINFO(wxDialog
))) 
2914     wxDialog 
*dialogBox 
= (wxDialog 
*)this; 
2915         long modalStyle 
= isModal 
? wxDIALOG_MODAL 
: 0; 
2916     if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
)) 
2918     dialogBox
->SetClientSize(width
, height
); 
2922     if (!((wxWindow 
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
)) 
2929   if (resource
->GetBackgroundColour()) 
2930     SetBackgroundColour(*resource
->GetBackgroundColour()); 
2933   if (resource
->GetLabelColour()) 
2934     SetForegroundColour(*resource
->GetLabelColour()); 
2935   else if (resource
->GetButtonColour()) 
2936     SetForegroundColour(*resource
->GetButtonColour()); 
2938   // Now create children 
2939   wxNode 
*node 
= resource
->GetChildren().First(); 
2942     wxItemResource 
*childResource 
= (wxItemResource 
*)node
->Data(); 
2944     (void) CreateItem(childResource
, table
); 
2946     node 
= node
->Next(); 
2951 wxControl 
*wxWindow::CreateItem(const wxItemResource 
*resource
, const wxResourceTable 
*table
) 
2954     table 
= wxDefaultResourceTable
; 
2955   return table
->CreateItem((wxWindow 
*)this, (wxItemResource 
*)resource
); 
2958 #endif // USE_WX_RESOURCES