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/bmpbuttn.h"
35 #include "wx/radiobox.h"
36 #include "wx/listbox.h"
37 #include "wx/choice.h"
38 #include "wx/checkbox.h"
39 #include "wx/slider.h"
40 #include "wx/statbox.h"
44 #include "wx/textctrl.h"
45 #include "wx/msgdlg.h"
50 #include "wx/scrolbar.h"
54 #include "wx/combobox.h"
57 #include "wx/validate.h"
68 #include "wx/resource.h"
69 #include "wx/string.h"
70 #include "wx/wxexpr.h"
72 // Forward (private) declarations
73 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
);
74 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
= FALSE
);
75 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
);
76 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
);
77 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
);
78 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, PrologExpr
*expr
);
79 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, PrologExpr
*expr
);
80 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
);
81 // Interpret list expression
82 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
);
84 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
= NULL
);
85 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
= NULL
);
87 wxResourceTable
*wxDefaultResourceTable
= NULL
;
89 static char *wxResourceBuffer
= NULL
;
90 static long wxResourceBufferSize
= 0;
91 static long wxResourceBufferCount
= 0;
92 static int wxResourceStringPtr
= 0;
94 void wxInitializeResourceSystem(void)
96 wxDefaultResourceTable
= new wxResourceTable
;
99 void wxCleanUpResourceSystem(void)
101 delete wxDefaultResourceTable
;
104 void wxLogWarning(char *msg
)
106 wxMessageBox(msg
, _("Warning"), wxOK
);
109 #if !USE_SHARED_LIBRARY
110 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
111 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
114 wxItemResource::wxItemResource(void)
120 x
= y
= width
= height
= 0;
121 value1
= value2
= value3
= value5
= 0;
125 backgroundColour
= labelColour
= buttonColour
= NULL
;
130 wxItemResource::~wxItemResource(void)
132 if (itemType
) delete[] itemType
;
133 if (title
) delete[] title
;
134 if (name
) delete[] name
;
135 if (value4
) delete[] value4
;
140 if (backgroundColour
)
141 delete backgroundColour
;
146 wxNode
*node
= children
.First();
149 wxItemResource
*item
= (wxItemResource
*)node
->Data();
152 node
= children
.First();
156 void wxItemResource::SetTitle(char *t
)
161 if (title
) delete[] title
;
163 title
= copystring(t
);
168 void wxItemResource::SetType(char *t
)
173 if (itemType
) delete[] itemType
;
175 itemType
= copystring(t
);
180 void wxItemResource::SetName(char *n
)
185 if (name
) delete[] name
;
187 name
= copystring(n
);
192 void wxItemResource::SetStringValues(wxStringList
*svalues
)
197 stringValues
= svalues
;
202 void wxItemResource::SetValue4(char *v
)
207 if (value4
) delete[] value4
;
209 value4
= copystring(v
);
218 wxResourceTable::wxResourceTable(void):wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
222 wxResourceTable::~wxResourceTable(void)
227 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
229 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
233 void wxResourceTable::AddResource(wxItemResource
*item
)
235 char *name
= item
->GetName();
237 name
= item
->GetTitle();
241 // Delete existing resource, if any.
247 bool wxResourceTable::DeleteResource(const wxString
& name
)
249 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
252 // See if any resource has this as its child; if so, delete from
253 // parent's child list.
256 while ((node
= Next()))
258 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
259 if (parent
->GetChildren().Member(item
))
261 parent
->GetChildren().DeleteObject(item
);
273 bool wxResourceTable::ParseResourceFile(char *filename
)
277 FILE *fd
= fopen(filename
, "r");
281 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
286 return wxResourceInterpretResources(*this, db
);
289 bool wxResourceTable::ParseResourceData(char *data
)
292 if (!db
.ReadPrologFromString(data
))
294 wxLogWarning(_("Ill-formed resource file syntax."));
298 return wxResourceInterpretResources(*this, db
);
301 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char bits
[], int width
, int height
)
303 // Register pre-loaded bitmap data
304 wxItemResource
*item
= new wxItemResource
;
305 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
306 item
->SetType("wxXBMData");
308 item
->SetValue1((long)bits
);
309 item
->SetValue2((long)width
);
310 item
->SetValue3((long)height
);
315 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char **data
)
317 // Register pre-loaded bitmap data
318 wxItemResource
*item
= new wxItemResource
;
319 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
320 item
->SetType("wxXPMData");
322 item
->SetValue1((long)data
);
327 bool wxResourceTable::SaveResource(char *WXUNUSED(filename
))
332 void wxResourceTable::ClearTable(void)
335 wxNode
*node
= Next();
338 wxNode
*next
= Next();
339 wxItemResource
*item
= (wxItemResource
*)node
->Data();
346 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, wxItemResource
*childResource
) const
348 int id
= childResource
->GetId();
352 wxControl
*control
= NULL
;
353 wxString
itemType(childResource
->GetType());
354 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
356 if (childResource
->GetValue4())
359 wxBitmap
*bitmap
= childResource
->GetBitmap();
362 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
363 childResource
->SetBitmap(bitmap
);
366 control
= new wxBitmapButton(parent
, id
, *bitmap
,
367 wxPoint(childResource
->GetX(), childResource
->GetY()),
368 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
369 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
372 // Normal, text button
373 control
= new wxButton(parent
, id
, childResource
->GetTitle(),
374 wxPoint(childResource
->GetX(), childResource
->GetY()),
375 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
376 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
378 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
379 itemType
== wxString("wxStaticBitmap"))
381 if (childResource
->GetValue4())
384 wxBitmap
*bitmap
= childResource
->GetBitmap();
387 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
388 childResource
->SetBitmap(bitmap
);
390 #if USE_BITMAP_MESSAGE
392 control
= new wxStaticBitmap(parent
, id
, *bitmap
,
393 wxPoint(childResource
->GetX(), childResource
->GetY()),
394 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
395 childResource
->GetStyle(), childResource
->GetName());
400 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(),
401 wxPoint(childResource
->GetX(), childResource
->GetY()),
402 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
403 childResource
->GetStyle(), childResource
->GetName());
406 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
408 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(),
409 wxPoint(childResource
->GetX(), childResource
->GetY()),
410 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
411 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
413 else if (itemType
== wxString("wxCheckBox"))
415 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(),
416 wxPoint(childResource
->GetX(), childResource
->GetY()),
417 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
418 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
420 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
423 else if (itemType
== wxString("wxGauge"))
425 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(),
426 wxPoint(childResource
->GetX(), childResource
->GetY()),
427 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
428 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
430 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
434 else if (itemType
== wxString("wxRadioButton"))
436 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
437 wxPoint(childResource
->GetX(), childResource
->GetY()),
438 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
439 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
443 else if (itemType
== wxString("wxScrollBar"))
445 control
= new wxScrollBar(parent
, id
,
446 wxPoint(childResource
->GetX(), childResource
->GetY()),
447 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
448 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
449 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
450 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
451 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
452 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
455 else if (itemType
== wxString("wxSlider"))
457 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
458 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(),
459 wxPoint(childResource
->GetX(), childResource
->GetY()),
460 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
461 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
463 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
465 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(),
466 wxPoint(childResource
->GetX(), childResource
->GetY()),
467 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
468 childResource
->GetStyle(), childResource
->GetName());
470 else if (itemType
== wxString("wxListBox"))
472 wxStringList
*stringList
= childResource
->GetStringValues();
473 wxString
*strings
= NULL
;
475 if (stringList
&& (stringList
->Number() > 0))
477 noStrings
= stringList
->Number();
478 strings
= new wxString
[noStrings
];
479 wxNode
*node
= stringList
->First();
483 strings
[i
] = (char *)node
->Data();
488 control
= new wxListBox(parent
, id
,
489 wxPoint(childResource
->GetX(), childResource
->GetY()),
490 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
491 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
496 else if (itemType
== wxString("wxChoice"))
498 wxStringList
*stringList
= childResource
->GetStringValues();
499 wxString
*strings
= NULL
;
501 if (stringList
&& (stringList
->Number() > 0))
503 noStrings
= stringList
->Number();
504 strings
= new wxString
[noStrings
];
505 wxNode
*node
= stringList
->First();
509 strings
[i
] = (char *)node
->Data();
514 control
= new wxChoice(parent
, id
,
515 wxPoint(childResource
->GetX(), childResource
->GetY()),
516 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
517 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
523 else if (itemType
== wxString("wxComboBox"))
525 wxStringList
*stringList
= childResource
->GetStringValues();
526 wxString
*strings
= NULL
;
528 if (stringList
&& (stringList
->Number() > 0))
530 noStrings
= stringList
->Number();
531 strings
= new wxString
[noStrings
];
532 wxNode
*node
= stringList
->First();
536 strings
[i
] = (char *)node
->Data();
541 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(),
542 wxPoint(childResource
->GetX(), childResource
->GetY()),
543 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
544 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
550 else if (itemType
== wxString("wxRadioBox"))
552 wxStringList
*stringList
= childResource
->GetStringValues();
553 wxString
*strings
= NULL
;
555 if (stringList
&& (stringList
->Number() > 0))
557 noStrings
= stringList
->Number();
558 strings
= new wxString
[noStrings
];
559 wxNode
*node
= stringList
->First();
563 strings
[i
] = (char *)node
->Data();
568 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()),
569 wxPoint(childResource
->GetX(), childResource
->GetY()),
570 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
571 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
572 childResource
->GetName());
578 if (control
&& childResource
->GetFont())
579 control
->SetFont(*childResource
->GetFont());
584 * Interpret database as a series of resources
587 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
)
589 wxNode
*node
= db
.First();
592 PrologExpr
*clause
= (PrologExpr
*)node
->Data();
593 wxString
functor(clause
->Functor());
595 wxItemResource
*item
= NULL
;
596 if (functor
== "dialog")
597 item
= wxResourceInterpretDialog(table
, clause
);
598 else if (functor
== "panel")
599 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
600 else if (functor
== "menubar")
601 item
= wxResourceInterpretMenuBar(table
, clause
);
602 else if (functor
== "menu")
603 item
= wxResourceInterpretMenu(table
, clause
);
604 else if (functor
== "string")
605 item
= wxResourceInterpretString(table
, clause
);
606 else if (functor
== "bitmap")
607 item
= wxResourceInterpretBitmap(table
, clause
);
608 else if (functor
== "icon")
609 item
= wxResourceInterpretIcon(table
, clause
);
613 // Remove any existing resource of same name
615 table
.DeleteResource(item
->GetName());
616 table
.AddResource(item
);
623 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
624 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
625 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
626 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
627 "wxChoice", "wxComboBox" } ;
628 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
630 static bool wxIsValidControlClass(const wxString
& c
)
633 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
635 if ( c
== g_ValidControlClasses
[i
] )
641 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
)
643 wxItemResource
*dialogItem
= new wxItemResource
;
645 dialogItem
->SetType("wxPanel");
647 dialogItem
->SetType("wxDialog");
651 char *backColourHex
= NULL
;
652 char *labelColourHex
= NULL
;
653 char *buttonColourHex
= NULL
;
655 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
659 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
661 PrologExpr
*labelFontExpr
= NULL
;
662 PrologExpr
*buttonFontExpr
= NULL
;
663 PrologExpr
*fontExpr
= NULL
;
664 expr
->AssignAttributeValue("style", &style
);
665 expr
->AssignAttributeValue("name", &name
);
666 expr
->AssignAttributeValue("title", &title
);
667 expr
->AssignAttributeValue("x", &x
);
668 expr
->AssignAttributeValue("y", &y
);
669 expr
->AssignAttributeValue("width", &width
);
670 expr
->AssignAttributeValue("height", &height
);
671 expr
->AssignAttributeValue("modal", &isModal
);
672 expr
->AssignAttributeValue("label_font", &labelFontExpr
);
673 expr
->AssignAttributeValue("button_font", &buttonFontExpr
);
674 expr
->AssignAttributeValue("font", &fontExpr
);
675 expr
->AssignAttributeValue("background_colour", &backColourHex
);
676 expr
->AssignAttributeValue("label_colour", &labelColourHex
);
677 expr
->AssignAttributeValue("button_colour", &buttonColourHex
);
680 expr
->GetAttributeValue("id", id
);
681 dialogItem
->SetId(id
);
685 windowStyle
= wxParseWindowStyle(style
);
687 dialogItem
->SetStyle(windowStyle
);
688 dialogItem
->SetValue1(isModal
);
690 dialogItem
->SetName(name
);
692 dialogItem
->SetTitle(title
);
693 dialogItem
->SetSize(x
, y
, width
, height
);
700 r
= wxHexToDec(backColourHex
);
701 g
= wxHexToDec(backColourHex
+2);
702 b
= wxHexToDec(backColourHex
+4);
703 dialogItem
->SetBackgroundColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
704 delete[] backColourHex
;
711 r
= wxHexToDec(labelColourHex
);
712 g
= wxHexToDec(labelColourHex
+2);
713 b
= wxHexToDec(labelColourHex
+4);
714 dialogItem
->SetLabelColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
715 delete[] labelColourHex
;
722 r
= wxHexToDec(buttonColourHex
);
723 g
= wxHexToDec(buttonColourHex
+2);
724 b
= wxHexToDec(buttonColourHex
+4);
725 dialogItem
->SetButtonColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
726 delete[] buttonColourHex
;
737 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
738 else if (buttonFontExpr
)
739 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
740 else if (labelFontExpr
)
741 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
743 // Now parse all controls
744 PrologExpr
*controlExpr
= expr
->GetFirst();
747 if (controlExpr
->Number() == 3)
749 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
750 if (controlKeyword
!= "" && controlKeyword
== "control")
752 // The value part: always a list.
753 PrologExpr
*listExpr
= controlExpr
->Nth(2);
754 if (listExpr
->Type() == PrologList
)
756 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
759 dialogItem
->GetChildren().Append(controlItem
);
764 controlExpr
= controlExpr
->GetNext();
769 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
)
771 wxItemResource
*controlItem
= new wxItemResource
;
773 // First, find the standard features of a control definition:
774 // [optional integer/string id], control name, title, style, name, x, y, width, height
776 wxString controlType
;
781 long windowStyle
= 0;
782 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
785 PrologExpr
*expr1
= expr
->Nth(0);
787 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
789 if ( wxIsValidControlClass(expr1
->StringValue()) )
792 controlType
= expr1
->StringValue();
796 wxString
str(expr1
->StringValue());
797 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
800 wxLogWarning(_("Could not resolve control class or id '%s'. "
801 "Use (non-zero) integer instead\n or provide #define "
802 "(see manual for caveats)"),
803 (const char*) expr1
->StringValue());
809 // Success - we have an id, so the 2nd element must be the control class.
810 controlType
= expr
->Nth(1)->StringValue();
815 else if (expr1
->Type() == PrologInteger
)
817 id
= (int)expr1
->IntegerValue();
818 // Success - we have an id, so the 2nd element must be the control class.
819 controlType
= expr
->Nth(1)->StringValue();
823 expr1
= expr
->Nth(count
);
826 title
= expr1
->StringValue();
828 expr1
= expr
->Nth(count
);
832 style
= expr1
->StringValue();
833 windowStyle
= wxParseWindowStyle(WXSTRINGCAST style
);
836 expr1
= expr
->Nth(count
);
839 name
= expr1
->StringValue();
841 expr1
= expr
->Nth(count
);
844 x
= (int)expr1
->IntegerValue();
846 expr1
= expr
->Nth(count
);
849 y
= (int)expr1
->IntegerValue();
851 expr1
= expr
->Nth(count
);
854 width
= (int)expr1
->IntegerValue();
856 expr1
= expr
->Nth(count
);
859 height
= (int)expr1
->IntegerValue();
861 controlItem
->SetStyle(windowStyle
);
862 controlItem
->SetName(WXSTRINGCAST name
);
863 controlItem
->SetTitle(WXSTRINGCAST title
);
864 controlItem
->SetSize(x
, y
, width
, height
);
865 controlItem
->SetType(WXSTRINGCAST controlType
);
866 controlItem
->SetId(id
);
868 if (controlType
== "wxButton")
870 // Check for bitmap resource name
871 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
873 wxString
str(expr
->Nth(count
)->StringValue());
874 controlItem
->SetValue4(WXSTRINGCAST str
);
876 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
877 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
880 else if (controlType
== "wxCheckBox")
882 // Check for default value
883 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
885 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
887 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
888 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
892 else if (controlType
== "wxRadioButton")
894 // Check for default value
895 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
897 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
899 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
900 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
904 else if (controlType
== "wxText" || controlType
== "wxTextCtrl")
906 // Check for default value
907 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
909 wxString
str(expr
->Nth(count
)->StringValue());
910 controlItem
->SetValue4(WXSTRINGCAST str
);
913 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
915 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
916 // Do nothing - no label font any more
918 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
919 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
923 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
925 // Check for bitmap resource name
926 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
928 wxString
str(expr
->Nth(count
)->StringValue());
929 controlItem
->SetValue4(WXSTRINGCAST str
);
931 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
932 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
935 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
937 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
938 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
940 else if (controlType
== "wxGauge")
942 // Check for default value
943 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
945 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
949 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
951 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
954 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
956 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
960 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
961 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
966 else if (controlType
== "wxSlider")
968 // Check for default value
969 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
971 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
975 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
977 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
981 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
983 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
986 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
988 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
992 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
993 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
999 else if (controlType
== "wxScrollBar")
1002 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1004 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1008 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1010 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1014 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1016 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1020 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1021 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1026 else if (controlType
== "wxListBox")
1028 PrologExpr
*valueList
= NULL
;
1030 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1032 wxStringList
*stringList
= new wxStringList
;
1033 PrologExpr
*stringExpr
= valueList
->GetFirst();
1036 stringList
->Add(stringExpr
->StringValue());
1037 stringExpr
= stringExpr
->GetNext();
1039 controlItem
->SetStringValues(stringList
);
1042 // Check for wxSINGLE/wxMULTIPLE
1043 PrologExpr
*mult
= NULL
;
1044 controlItem
->SetValue1(wxLB_SINGLE
);
1045 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1047 wxString
m(mult
->StringValue());
1048 if (m
== "wxMULTIPLE")
1049 controlItem
->SetValue1(wxLB_MULTIPLE
);
1050 else if (m
== "wxEXTENDED")
1051 controlItem
->SetValue1(wxLB_EXTENDED
);
1053 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1055 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1057 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1058 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1063 else if (controlType
== "wxChoice")
1065 PrologExpr
*valueList
= NULL
;
1066 // Check for default value list
1067 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1069 wxStringList
*stringList
= new wxStringList
;
1070 PrologExpr
*stringExpr
= valueList
->GetFirst();
1073 stringList
->Add(stringExpr
->StringValue());
1074 stringExpr
= stringExpr
->GetNext();
1076 controlItem
->SetStringValues(stringList
);
1080 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1082 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1085 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1086 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1091 else if (controlType
== "wxComboBox")
1093 PrologExpr
*textValue
= expr
->Nth(count
);
1094 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1096 wxString
str(textValue
->StringValue());
1097 controlItem
->SetValue4(WXSTRINGCAST str
);
1101 PrologExpr
*valueList
= NULL
;
1102 // Check for default value list
1103 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1105 wxStringList
*stringList
= new wxStringList
;
1106 PrologExpr
*stringExpr
= valueList
->GetFirst();
1109 stringList
->Add(stringExpr
->StringValue());
1110 stringExpr
= stringExpr
->GetNext();
1112 controlItem
->SetStringValues(stringList
);
1116 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1118 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1121 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1122 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1129 else if (controlType
== "wxRadioBox")
1131 PrologExpr
*valueList
= NULL
;
1132 // Check for default value list
1133 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1135 wxStringList
*stringList
= new wxStringList
;
1136 PrologExpr
*stringExpr
= valueList
->GetFirst();
1139 stringList
->Add(stringExpr
->StringValue());
1140 stringExpr
= stringExpr
->GetNext();
1142 controlItem
->SetStringValues(stringList
);
1145 // majorDim (number of rows or cols)
1146 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1148 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1152 controlItem
->SetValue1(0);
1154 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1156 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1159 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1160 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1173 // Forward declaration
1174 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, PrologExpr
*expr
);
1177 * Interpet a menu item
1180 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, PrologExpr
*expr
)
1182 wxItemResource
*item
= new wxItemResource
;
1184 PrologExpr
*labelExpr
= expr
->Nth(0);
1185 PrologExpr
*idExpr
= expr
->Nth(1);
1186 PrologExpr
*helpExpr
= expr
->Nth(2);
1187 PrologExpr
*checkableExpr
= expr
->Nth(3);
1189 // Further keywords/attributes to follow sometime...
1190 if (expr
->Number() == 0)
1192 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1193 item
->SetType("wxMenuSeparator");
1198 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1199 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1202 wxString
str(labelExpr
->StringValue());
1203 item
->SetTitle(WXSTRINGCAST str
);
1208 // If a string or word, must look up in identifier table.
1209 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1211 wxString
str(idExpr
->StringValue());
1212 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
1215 wxLogWarning(_("Could not resolve menu id '%s'. "
1216 "Use (non-zero) integer instead\n"
1217 "or provide #define (see manual for caveats)"),
1218 (const char*) idExpr
->StringValue());
1221 else if (idExpr
->Type() == PrologInteger
)
1222 id
= (int)idExpr
->IntegerValue();
1223 item
->SetValue1(id
);
1227 wxString
str(helpExpr
->StringValue());
1228 item
->SetValue4(WXSTRINGCAST str
);
1231 item
->SetValue2(checkableExpr
->IntegerValue());
1233 // Find the first expression that's a list, for submenu
1234 PrologExpr
*subMenuExpr
= expr
->GetFirst();
1235 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1236 subMenuExpr
= subMenuExpr
->GetNext();
1240 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1241 item
->GetChildren().Append(child
);
1242 subMenuExpr
= subMenuExpr
->GetNext();
1249 * Interpret a nested list as a menu
1252 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr)
1254 wxItemResource *menu = new wxItemResource;
1255 // menu->SetType(wxTYPE_MENU);
1256 menu->SetType("wxMenu");
1257 PrologExpr *element = expr->GetFirst();
1260 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1262 menu->GetChildren().Append(item);
1263 element = element->GetNext();
1269 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
)
1271 PrologExpr
*listExpr
= NULL
;
1272 expr
->AssignAttributeValue("menu", &listExpr
);
1276 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1282 expr
->AssignAttributeValue("name", &name
);
1285 menuResource
->SetName(name
);
1289 return menuResource
;
1292 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
)
1294 PrologExpr
*listExpr
= NULL
;
1295 expr
->AssignAttributeValue("menu", &listExpr
);
1299 wxItemResource
*resource
= new wxItemResource
;
1300 resource
->SetType("wxMenu");
1301 // resource->SetType(wxTYPE_MENU);
1303 PrologExpr
*element
= listExpr
->GetFirst();
1306 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1307 resource
->GetChildren().Append(menuResource
);
1308 element
= element
->GetNext();
1312 expr
->AssignAttributeValue("name", &name
);
1315 resource
->SetName(name
);
1322 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), PrologExpr
*WXUNUSED(expr
))
1327 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), PrologExpr
*expr
)
1329 wxItemResource
*bitmapItem
= new wxItemResource
;
1330 // bitmapItem->SetType(wxTYPE_BITMAP);
1331 bitmapItem
->SetType("wxBitmap");
1333 expr
->AssignAttributeValue("name", &name
);
1336 bitmapItem
->SetName(name
);
1339 // Now parse all bitmap specifications
1340 PrologExpr
*bitmapExpr
= expr
->GetFirst();
1343 if (bitmapExpr
->Number() == 3)
1345 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1346 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1348 // The value part: always a list.
1349 PrologExpr
*listExpr
= bitmapExpr
->Nth(2);
1350 if (listExpr
->Type() == PrologList
)
1352 wxItemResource
*bitmapSpec
= new wxItemResource
;
1353 // bitmapSpec->SetType(wxTYPE_BITMAP);
1354 bitmapSpec
->SetType("wxBitmap");
1356 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1357 // where everything after 'filename' is optional.
1358 PrologExpr
*nameExpr
= listExpr
->Nth(0);
1359 PrologExpr
*typeExpr
= listExpr
->Nth(1);
1360 PrologExpr
*platformExpr
= listExpr
->Nth(2);
1361 PrologExpr
*coloursExpr
= listExpr
->Nth(3);
1362 PrologExpr
*xresExpr
= listExpr
->Nth(4);
1363 PrologExpr
*yresExpr
= listExpr
->Nth(5);
1364 if (nameExpr
&& nameExpr
->StringValue())
1366 wxString
str(nameExpr
->StringValue());
1367 bitmapSpec
->SetName(WXSTRINGCAST str
);
1369 if (typeExpr
&& typeExpr
->StringValue())
1371 wxString
str(typeExpr
->StringValue());
1372 bitmapSpec
->SetValue1(wxParseWindowStyle(WXSTRINGCAST str
));
1375 bitmapSpec
->SetValue1(0);
1377 if (platformExpr
&& platformExpr
->StringValue())
1379 wxString
plat(platformExpr
->StringValue());
1380 if (plat
== "windows" || plat
== "WINDOWS")
1381 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1382 else if (plat
== "x" || plat
== "X")
1383 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1384 else if (plat
== "mac" || plat
== "MAC")
1385 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1387 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1390 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1393 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1397 xres
= (int)xresExpr
->IntegerValue();
1399 yres
= (int)yresExpr
->IntegerValue();
1400 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1402 bitmapItem
->GetChildren().Append(bitmapSpec
);
1406 bitmapExpr
= bitmapExpr
->GetNext();
1412 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
)
1414 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1417 // item->SetType(wxTYPE_ICON);
1418 item
->SetType("wxIcon");
1425 // Interpret list expression as a font
1426 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
)
1428 if (expr
->Type() != PrologList
)
1432 int family
= wxSWISS
;
1433 int style
= wxNORMAL
;
1434 int weight
= wxNORMAL
;
1436 wxString
faceName("");
1438 PrologExpr
*pointExpr
= expr
->Nth(0);
1439 PrologExpr
*familyExpr
= expr
->Nth(1);
1440 PrologExpr
*styleExpr
= expr
->Nth(2);
1441 PrologExpr
*weightExpr
= expr
->Nth(3);
1442 PrologExpr
*underlineExpr
= expr
->Nth(4);
1443 PrologExpr
*faceNameExpr
= expr
->Nth(5);
1445 point
= (int)pointExpr
->IntegerValue();
1450 str
= familyExpr
->StringValue();
1451 family
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1455 str
= styleExpr
->StringValue();
1456 style
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1460 str
= weightExpr
->StringValue();
1461 weight
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1464 underline
= (int)underlineExpr
->IntegerValue();
1466 faceName
= faceNameExpr
->StringValue();
1468 char *faceName1
= NULL
;
1470 faceName1
= WXSTRINGCAST faceName
;
1471 wxFont
*font
= wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
, (underline
!= 0), faceName1
);
1476 * (Re)allocate buffer for reading in from resource file
1479 bool wxReallocateResourceBuffer(void)
1481 if (!wxResourceBuffer
)
1483 wxResourceBufferSize
= 1000;
1484 wxResourceBuffer
= new char[wxResourceBufferSize
];
1487 if (wxResourceBuffer
)
1489 long newSize
= wxResourceBufferSize
+ 1000;
1490 char *tmp
= new char[(int)newSize
];
1491 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1492 delete[] wxResourceBuffer
;
1493 wxResourceBuffer
= tmp
;
1494 wxResourceBufferSize
= newSize
;
1499 static bool wxEatWhiteSpace(FILE *fd
)
1502 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1509 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1511 // Check for comment
1517 bool finished
= FALSE
;
1525 int newCh
= getc(fd
);
1540 return wxEatWhiteSpace(fd
);
1543 bool wxGetResourceToken(FILE *fd
)
1545 if (!wxResourceBuffer
)
1546 wxReallocateResourceBuffer();
1547 wxResourceBuffer
[0] = 0;
1548 wxEatWhiteSpace(fd
);
1554 wxResourceBufferCount
= 0;
1561 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1564 // Escaped characters
1565 else if (ch
== '\\')
1567 int newCh
= getc(fd
);
1570 else if (newCh
== 10)
1578 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1579 wxReallocateResourceBuffer();
1580 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1581 wxResourceBufferCount
++;
1584 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1588 wxResourceBufferCount
= 0;
1590 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1592 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1593 wxReallocateResourceBuffer();
1594 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1595 wxResourceBufferCount
++;
1599 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1607 * Files are in form:
1608 static char *name = "....";
1609 with possible comments.
1612 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1615 table
= wxDefaultResourceTable
;
1617 // static or #define
1618 if (!wxGetResourceToken(fd
))
1624 if (strcmp(wxResourceBuffer
, "#define") == 0)
1626 wxGetResourceToken(fd
);
1627 char *name
= copystring(wxResourceBuffer
);
1628 wxGetResourceToken(fd
);
1629 char *value
= copystring(wxResourceBuffer
);
1630 if (isalpha(value
[0]))
1632 int val
= (int)atol(value
);
1633 wxResourceAddIdentifier(name
, val
, table
);
1637 wxLogWarning(_("#define %s must be an integer."), name
);
1647 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1649 wxGetResourceToken(fd
);
1650 char *name
= copystring(wxResourceBuffer
);
1651 char *actualName
= name
;
1653 actualName
= name
+ 1;
1654 int len
= strlen(name
);
1655 if ((len
> 0) && (name
[len
-1] == '"'))
1657 if (!wxResourceParseIncludeFile(actualName
, table
))
1659 wxLogWarning(_("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 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1682 if (strcmp(wxResourceBuffer
, "char") != 0)
1684 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1689 if (!wxGetResourceToken(fd
))
1691 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1696 if (wxResourceBuffer
[0] != '*')
1698 wxLogWarning(_("Expected '*' whilst parsing resource."));
1702 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1705 if (!wxGetResourceToken(fd
))
1707 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1712 if (strcmp(wxResourceBuffer
, "=") != 0)
1714 wxLogWarning(_("Expected '=' whilst parsing resource."));
1719 if (!wxGetResourceToken(fd
))
1721 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1727 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1729 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1734 if (!wxGetResourceToken(fd
))
1742 * Parses string window style into integer window style
1746 * Style flag parsing, e.g.
1747 * "wxSYSTEM_MENU | wxBORDER" -> integer
1750 char *wxResourceParseWord(char *s
, int *i
)
1755 static char buf
[150];
1756 int len
= strlen(s
);
1759 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1767 // Eat whitespace and conjunction characters
1768 while ((ii
< len
) &&
1769 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1780 struct wxResourceBitListStruct
1786 static wxResourceBitListStruct wxResourceBitListTable
[] =
1789 { "wxSINGLE", wxLB_SINGLE
},
1790 { "wxMULTIPLE", wxLB_MULTIPLE
},
1791 { "wxEXTENDED", wxLB_EXTENDED
},
1792 { "wxLB_SINGLE", wxLB_SINGLE
},
1793 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1794 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1795 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1796 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1797 { "wxLB_SORT", wxLB_SORT
},
1798 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1799 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1802 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1803 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1804 { "wxCB_READONLY", wxCB_READONLY
},
1805 { "wxCB_SORT", wxCB_SORT
},
1808 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1809 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1810 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1813 { "wxPASSWORD", wxPASSWORD
},
1814 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1815 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1816 { "wxTE_READONLY", wxTE_READONLY
},
1817 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1818 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1820 /* wxRadioBox/wxRadioButton */
1821 { "wxRB_GROUP", wxRB_GROUP
},
1822 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1823 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1826 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1827 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1828 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1829 { "wxSL_LABELS", wxSL_LABELS
},
1830 { "wxSL_LEFT", wxSL_LEFT
},
1831 { "wxSL_TOP", wxSL_TOP
},
1832 { "wxSL_RIGHT", wxSL_RIGHT
},
1833 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1834 { "wxSL_BOTH", wxSL_BOTH
},
1835 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1838 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1839 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1842 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1843 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1846 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1847 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1848 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1851 { "wxLC_ICON", wxLC_ICON
},
1852 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1853 { "wxLC_LIST", wxLC_LIST
},
1854 { "wxLC_REPORT", wxLC_REPORT
},
1855 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1856 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1857 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1858 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1859 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1860 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1861 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1862 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1863 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1864 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1867 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1868 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1869 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1870 { "wxSP_WRAP", wxSP_WRAP
},
1873 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1874 { "wxSP_3D", wxSP_3D
},
1875 { "wxSP_BORDER", wxSP_BORDER
},
1878 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1879 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1880 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1881 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1884 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1887 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1888 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1889 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1890 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1891 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1892 { "wxCOLOURED", wxCOLOURED
},
1895 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1896 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1897 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1898 { "wxTB_FLAT", wxTB_FLAT
},
1901 { "wxVSCROLL", wxVSCROLL
},
1902 { "wxHSCROLL", wxHSCROLL
},
1903 { "wxCAPTION", wxCAPTION
},
1904 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1905 { "wxICONIZE", wxICONIZE
},
1906 { "wxMINIMIZE", wxICONIZE
},
1907 { "wxMAXIMIZE", wxMAXIMIZE
},
1909 { "wxMDI_PARENT", 0},
1910 { "wxMDI_CHILD", 0},
1911 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1912 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1913 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1914 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1915 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1916 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1917 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1918 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1919 { "wxBORDER", wxBORDER
},
1920 { "wxRETAINED", wxRETAINED
},
1921 { "wxNATIVE_IMPL", 0},
1922 { "wxEXTENDED_IMPL", 0},
1923 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1924 // { "wxFLAT", wxFLAT},
1925 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1926 { "wxFIXED_LENGTH", 0},
1927 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1928 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1929 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1930 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1931 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1932 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1933 { "wxNO_BORDER", wxNO_BORDER
},
1934 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1936 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1937 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1939 // Text font families
1940 { "wxDEFAULT", wxDEFAULT
},
1941 { "wxDECORATIVE", wxDECORATIVE
},
1942 { "wxROMAN", wxROMAN
},
1943 { "wxSCRIPT", wxSCRIPT
},
1944 { "wxSWISS", wxSWISS
},
1945 { "wxMODERN", wxMODERN
},
1946 { "wxTELETYPE", wxTELETYPE
},
1947 { "wxVARIABLE", wxVARIABLE
},
1948 { "wxFIXED", wxFIXED
},
1949 { "wxNORMAL", wxNORMAL
},
1950 { "wxLIGHT", wxLIGHT
},
1951 { "wxBOLD", wxBOLD
},
1952 { "wxITALIC", wxITALIC
},
1953 { "wxSLANT", wxSLANT
},
1954 { "wxSOLID", wxSOLID
},
1956 { "wxLONG_DASH", wxLONG_DASH
},
1957 { "wxSHORT_DASH", wxSHORT_DASH
},
1958 { "wxDOT_DASH", wxDOT_DASH
},
1959 { "wxUSER_DASH", wxUSER_DASH
},
1960 { "wxTRANSPARENT", wxTRANSPARENT
},
1961 { "wxSTIPPLE", wxSTIPPLE
},
1962 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1963 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1964 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1965 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1966 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1967 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1968 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1969 { "wxJOIN_MITER", wxJOIN_MITER
},
1970 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1971 { "wxCAP_ROUND", wxCAP_ROUND
},
1972 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1973 { "wxCAP_BUTT", wxCAP_BUTT
},
1976 { "wxCLEAR", wxCLEAR
},
1978 { "wxINVERT", wxINVERT
},
1979 { "wxOR_REVERSE", wxOR_REVERSE
},
1980 { "wxAND_REVERSE", wxAND_REVERSE
},
1981 { "wxCOPY", wxCOPY
},
1983 { "wxAND_INVERT", wxAND_INVERT
},
1984 { "wxNO_OP", wxNO_OP
},
1986 { "wxEQUIV", wxEQUIV
},
1987 { "wxSRC_INVERT", wxSRC_INVERT
},
1988 { "wxOR_INVERT", wxOR_INVERT
},
1989 { "wxNAND", wxNAND
},
1993 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1994 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1995 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1996 { "wxWINDING_RULE", wxWINDING_RULE
},
1997 { "wxHORIZONTAL", wxHORIZONTAL
},
1998 { "wxVERTICAL", wxVERTICAL
},
1999 { "wxBOTH", wxBOTH
},
2000 { "wxCENTER_FRAME", wxCENTER_FRAME
},
2002 { "wxYES_NO", wxYES_NO
},
2003 { "wxCANCEL", wxCANCEL
},
2006 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
2007 { "wxICON_HAND", wxICON_HAND
},
2008 { "wxICON_QUESTION", wxICON_QUESTION
},
2009 { "wxICON_INFORMATION", wxICON_INFORMATION
},
2010 { "wxICON_STOP", wxICON_STOP
},
2011 { "wxICON_ASTERISK", wxICON_ASTERISK
},
2012 { "wxICON_MASK", wxICON_MASK
},
2013 { "wxCENTRE", wxCENTRE
},
2014 { "wxCENTER", wxCENTRE
},
2015 { "wxUSER_COLOURS", wxUSER_COLOURS
},
2016 { "wxVERTICAL_LABEL", 0},
2017 { "wxHORIZONTAL_LABEL", 0},
2019 // Bitmap types (not strictly styles)
2020 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
2021 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
2022 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
2023 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2024 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2025 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
2026 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
2027 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
2028 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
2029 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
2030 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
2031 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
2032 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
2033 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
2036 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2038 long wxParseWindowStyle(char *bitListString
)
2043 while ((word
= wxResourceParseWord(bitListString
, &i
)))
2047 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2048 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2050 bitList
|= wxResourceBitListTable
[j
].bits
;
2056 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2064 * Load a bitmap from a wxWindows resource, choosing an optimum
2065 * depth and appropriate type.
2068 wxBitmap
*wxResourceCreateBitmap(char *resource
, wxResourceTable
*table
)
2071 table
= wxDefaultResourceTable
;
2073 wxItemResource
*item
= table
->FindResource(resource
);
2076 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2078 wxLogWarning(_("%s not a bitmap resource specification."), resource
);
2081 int thisDepth
= wxDisplayDepth();
2082 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2084 wxItemResource
*optResource
= NULL
;
2086 // Try to find optimum bitmap for this platform/colour depth
2087 wxNode
*node
= item
->GetChildren().First();
2090 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2091 int platform
= (int)child
->GetValue2();
2092 int noColours
= (int)child
->GetValue3();
2094 char *name = child->GetName();
2095 int bitmapType = (int)child->GetValue1();
2096 int xRes = child->GetWidth();
2097 int yRes = child->GetHeight();
2102 case RESOURCE_PLATFORM_ANY
:
2104 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2105 optResource
= child
;
2108 // Maximise the number of colours.
2109 // If noColours is zero (unspecified), then assume this
2110 // is the right one.
2111 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2112 optResource
= child
;
2117 case RESOURCE_PLATFORM_WINDOWS
:
2119 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2120 optResource
= child
;
2123 // Maximise the number of colours
2124 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2125 optResource
= child
;
2131 case RESOURCE_PLATFORM_X
:
2133 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2134 optResource
= child
;
2137 // Maximise the number of colours
2138 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2139 optResource
= child
;
2145 case RESOURCE_PLATFORM_MAC
:
2147 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2148 optResource
= child
;
2151 // Maximise the number of colours
2152 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2153 optResource
= child
;
2161 node
= node
->Next();
2163 // If no matching resource, fail.
2167 char *name
= optResource
->GetName();
2168 int bitmapType
= (int)optResource
->GetValue1();
2169 wxBitmap
*bitmap
= NULL
;
2172 case wxBITMAP_TYPE_XBM_DATA
:
2175 wxItemResource
*item
= table
->FindResource(name
);
2178 wxLogWarning(_("Failed to find XBM resource %s.\n"
2179 "Forgot to use wxResourceLoadBitmapData?"), name
);
2182 bitmap
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2184 wxLogWarning(_("No XBM facility available!"));
2188 case wxBITMAP_TYPE_XPM_DATA
:
2190 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2191 wxItemResource
*item
= table
->FindResource(name
);
2194 wxLogWarning(_("Failed to find XPM resource %s.\n"
2195 "Forgot to use wxResourceLoadBitmapData?"), name
);
2198 bitmap
= new wxBitmap(item
->GetValue1());
2200 wxLogWarning(_("No XPM facility available!"));
2206 bitmap
= new wxBitmap(name
, bitmapType
);
2225 wxLogWarning(_("Bitmap resource specification %s not found."), resource
);
2231 * Load an icon from a wxWindows resource, choosing an optimum
2232 * depth and appropriate type.
2235 wxIcon
*wxResourceCreateIcon(char *resource
, wxResourceTable
*table
)
2238 table
= wxDefaultResourceTable
;
2240 wxItemResource
*item
= table
->FindResource(resource
);
2243 if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0)
2245 wxLogWarning(_("%s not an icon resource specification."), resource
);
2248 int thisDepth
= wxDisplayDepth();
2249 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2251 wxItemResource
*optResource
= NULL
;
2253 // Try to find optimum icon for this platform/colour depth
2254 wxNode
*node
= item
->GetChildren().First();
2257 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2258 int platform
= (int)child
->GetValue2();
2259 int noColours
= (int)child
->GetValue3();
2261 char *name = child->GetName();
2262 int bitmapType = (int)child->GetValue1();
2263 int xRes = child->GetWidth();
2264 int yRes = child->GetHeight();
2269 case RESOURCE_PLATFORM_ANY
:
2271 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2272 optResource
= child
;
2275 // Maximise the number of colours.
2276 // If noColours is zero (unspecified), then assume this
2277 // is the right one.
2278 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2279 optResource
= child
;
2284 case RESOURCE_PLATFORM_WINDOWS
:
2286 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2287 optResource
= child
;
2290 // Maximise the number of colours
2291 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2292 optResource
= child
;
2298 case RESOURCE_PLATFORM_X
:
2300 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2301 optResource
= child
;
2304 // Maximise the number of colours
2305 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2306 optResource
= child
;
2312 case RESOURCE_PLATFORM_MAC
:
2314 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2315 optResource
= child
;
2318 // Maximise the number of colours
2319 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2320 optResource
= child
;
2328 node
= node
->Next();
2330 // If no matching resource, fail.
2334 char *name
= optResource
->GetName();
2335 int bitmapType
= (int)optResource
->GetValue1();
2336 wxIcon
*icon
= NULL
;
2339 case wxBITMAP_TYPE_XBM_DATA
:
2342 wxItemResource
*item
= table
->FindResource(name
);
2345 wxLogWarning(_("Failed to find XBM resource %s.\n"
2346 "Forgot to use wxResourceLoadIconData?"), name
);
2349 icon
= new wxIcon((char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2351 wxLogWarning(_("No XBM facility available!"));
2355 case wxBITMAP_TYPE_XPM_DATA
:
2357 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2359 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2360 wxItemResource *item = table->FindResource(name);
2364 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2368 icon = new wxIcon((char **)item->GetValue1());
2370 wxLogWarning(_("No XPM facility available!"));
2373 wxLogWarning(_("No XPM icon facility available!"));
2379 wxLogWarning(_("Icon resource specification %s not found."), resource
);
2381 icon
= new wxIcon(name
, bitmapType
);
2401 wxLogWarning(_("Icon resource specification %s not found."), resource
);
2406 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2408 wxMenu
*menu
= new wxMenu
;
2409 wxNode
*node
= item
->GetChildren().First();
2412 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2413 if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0)
2414 menu
->AppendSeparator();
2415 else if (child
->GetChildren().Number() > 0)
2417 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2419 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2423 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2425 node
= node
->Next();
2430 wxMenuBar
*wxResourceCreateMenuBar(char *resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2433 table
= wxDefaultResourceTable
;
2435 wxItemResource
*menuResource
= table
->FindResource(resource
);
2436 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2439 menuBar
= new wxMenuBar
;
2440 wxNode
*node
= menuResource
->GetChildren().First();
2443 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2444 wxMenu
*menu
= wxResourceCreateMenu(child
);
2446 menuBar
->Append(menu
, child
->GetTitle());
2447 node
= node
->Next();
2454 wxMenu
*wxResourceCreateMenu(char *resource
, wxResourceTable
*table
)
2457 table
= wxDefaultResourceTable
;
2459 wxItemResource
*menuResource
= table
->FindResource(resource
);
2460 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2461 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2462 return wxResourceCreateMenu(menuResource
);
2466 // Global equivalents (so don't have to refer to default table explicitly)
2467 bool wxResourceParseData(char *resource
, wxResourceTable
*table
)
2470 table
= wxDefaultResourceTable
;
2472 return table
->ParseResourceData(resource
);
2475 bool wxResourceParseFile(char *filename
, wxResourceTable
*table
)
2478 table
= wxDefaultResourceTable
;
2480 return table
->ParseResourceFile(filename
);
2483 // Register XBM/XPM data
2484 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2487 table
= wxDefaultResourceTable
;
2489 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2492 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable
*table
)
2495 table
= wxDefaultResourceTable
;
2497 return table
->RegisterResourceBitmapData(name
, data
);
2500 void wxResourceClear(wxResourceTable
*table
)
2503 table
= wxDefaultResourceTable
;
2505 table
->ClearTable();
2512 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable
*table
)
2515 table
= wxDefaultResourceTable
;
2517 table
->identifiers
.Put(name
, (wxObject
*)value
);
2521 int wxResourceGetIdentifier(char *name
, wxResourceTable
*table
)
2524 table
= wxDefaultResourceTable
;
2526 return (int)table
->identifiers
.Get(name
);
2530 * Parse #include file for #defines (only)
2533 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
)
2536 table
= wxDefaultResourceTable
;
2538 FILE *fd
= fopen(f
, "r");
2543 while (wxGetResourceToken(fd
))
2545 if (strcmp(wxResourceBuffer
, "#define") == 0)
2547 wxGetResourceToken(fd
);
2548 char *name
= copystring(wxResourceBuffer
);
2549 wxGetResourceToken(fd
);
2550 char *value
= copystring(wxResourceBuffer
);
2551 if (isdigit(value
[0]))
2553 int val
= (int)atol(value
);
2554 wxResourceAddIdentifier(name
, val
, table
);
2565 * Reading strings as if they were .wxr files
2568 static int getc_string(char *s
)
2570 int ch
= s
[wxResourceStringPtr
];
2575 wxResourceStringPtr
++;
2580 static int ungetc_string(void)
2582 wxResourceStringPtr
--;
2586 bool wxEatWhiteSpaceString(char *s
)
2588 int ch
= getc_string(s
);
2592 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2599 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2600 ch
= getc_string(s
);
2601 // Check for comment
2604 ch
= getc_string(s
);
2607 bool finished
= FALSE
;
2610 ch
= getc_string(s
);
2615 int newCh
= getc_string(s
);
2630 return wxEatWhiteSpaceString(s
);
2633 bool wxGetResourceTokenString(char *s
)
2635 if (!wxResourceBuffer
)
2636 wxReallocateResourceBuffer();
2637 wxResourceBuffer
[0] = 0;
2638 wxEatWhiteSpaceString(s
);
2640 int ch
= getc_string(s
);
2644 wxResourceBufferCount
= 0;
2645 ch
= getc_string(s
);
2651 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2654 // Escaped characters
2655 else if (ch
== '\\')
2657 int newCh
= getc_string(s
);
2660 else if (newCh
== 10)
2668 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2669 wxReallocateResourceBuffer();
2670 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2671 wxResourceBufferCount
++;
2672 ch
= getc_string(s
);
2674 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2678 wxResourceBufferCount
= 0;
2680 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2682 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2683 wxReallocateResourceBuffer();
2684 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2685 wxResourceBufferCount
++;
2687 ch
= getc_string(s
);
2689 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2697 * Files are in form:
2698 static char *name = "....";
2699 with possible comments.
2702 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2705 table
= wxDefaultResourceTable
;
2707 // static or #define
2708 if (!wxGetResourceTokenString(s
))
2714 if (strcmp(wxResourceBuffer
, "#define") == 0)
2716 wxGetResourceTokenString(s
);
2717 char *name
= copystring(wxResourceBuffer
);
2718 wxGetResourceTokenString(s
);
2719 char *value
= copystring(wxResourceBuffer
);
2720 if (isalpha(value
[0]))
2722 int val
= (int)atol(value
);
2723 wxResourceAddIdentifier(name
, val
, table
);
2727 wxLogWarning(_("#define %s must be an integer."), name
);
2738 else if (strcmp(wxResourceBuffer, "#include") == 0)
2740 wxGetResourceTokenString(s);
2741 char *name = copystring(wxResourceBuffer);
2742 char *actualName = name;
2744 actualName = name + 1;
2745 int len = strlen(name);
2746 if ((len > 0) && (name[len-1] == '"'))
2748 if (!wxResourceParseIncludeFile(actualName, table))
2751 sprintf(buf, _("Could not find resource include file %s."), actualName);
2758 else if (strcmp(wxResourceBuffer
, "static") != 0)
2761 strcpy(buf
, _("Found "));
2762 strncat(buf
, wxResourceBuffer
, 30);
2763 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2769 if (!wxGetResourceTokenString(s
))
2771 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2776 if (strcmp(wxResourceBuffer
, "char") != 0)
2778 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2783 if (!wxGetResourceTokenString(s
))
2785 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2790 if (wxResourceBuffer
[0] != '*')
2792 wxLogWarning(_("Expected '*' whilst parsing resource."));
2796 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2799 if (!wxGetResourceTokenString(s
))
2801 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2806 if (strcmp(wxResourceBuffer
, "=") != 0)
2808 wxLogWarning(_("Expected '=' whilst parsing resource."));
2813 if (!wxGetResourceTokenString(s
))
2815 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2821 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2823 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2828 if (!wxGetResourceTokenString(s
))
2835 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2838 table
= wxDefaultResourceTable
;
2843 // Turn backslashes into spaces
2846 int len
= strlen(s
);
2848 for (i
= 0; i
< len
; i
++)
2849 if (s
[i
] == 92 && s
[i
+1] == 13)
2857 wxResourceStringPtr
= 0;
2860 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2864 return wxResourceInterpretResources(*table
, db
);
2868 * resource loading facility
2871 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2874 table
= wxDefaultResourceTable
;
2876 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2877 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2878 if (!resource
|| !resource
->GetType() ||
2879 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2882 char *title
= resource
->GetTitle();
2883 long theWindowStyle
= resource
->GetStyle();
2884 bool isModal
= (resource
->GetValue1() != 0);
2885 int x
= resource
->GetX();
2886 int y
= resource
->GetY();
2887 int width
= resource
->GetWidth();
2888 int height
= resource
->GetHeight();
2889 char *name
= resource
->GetName();
2891 wxFont
*theFont
= resource
->GetFont();
2893 if (IsKindOf(CLASSINFO(wxDialog
)))
2895 wxDialog
*dialogBox
= (wxDialog
*)this;
2896 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2897 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2899 dialogBox
->SetClientSize(width
, height
);
2903 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2910 if (resource
->GetBackgroundColour())
2911 SetBackgroundColour(*resource
->GetBackgroundColour());
2914 if (resource
->GetLabelColour())
2915 SetForegroundColour(*resource
->GetLabelColour());
2916 else if (resource
->GetButtonColour())
2917 SetForegroundColour(*resource
->GetButtonColour());
2919 // Now create children
2920 wxNode
*node
= resource
->GetChildren().First();
2923 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2925 (void) CreateItem(childResource
, table
);
2927 node
= node
->Next();
2932 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxResourceTable
*table
)
2935 table
= wxDefaultResourceTable
;
2936 return table
->CreateItem((wxWindow
*)this, (wxItemResource
*)resource
);
2939 #endif // USE_WX_RESOURCES