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"
66 #include "wx/resource.h"
67 #include "wx/string.h"
68 #include "wx/wxexpr.h"
70 // Forward (private) declarations
71 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
);
72 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
= FALSE
);
73 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
);
74 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
);
75 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
);
76 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, PrologExpr
*expr
);
77 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, PrologExpr
*expr
);
78 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
);
79 // Interpret list expression
80 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
);
82 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
= NULL
);
83 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
= NULL
);
85 wxResourceTable
*wxDefaultResourceTable
= NULL
;
87 static char *wxResourceBuffer
= NULL
;
88 static long wxResourceBufferSize
= 0;
89 static long wxResourceBufferCount
= 0;
90 static int wxResourceStringPtr
= 0;
92 void wxInitializeResourceSystem(void)
94 wxDefaultResourceTable
= new wxResourceTable
;
97 void wxCleanUpResourceSystem(void)
99 delete wxDefaultResourceTable
;
102 void wxLogWarning(char *msg
)
104 wxMessageBox(msg
, _("Warning"), wxOK
);
107 #if !USE_SHARED_LIBRARY
108 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
109 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
112 wxItemResource::wxItemResource(void)
118 x
= y
= width
= height
= 0;
119 value1
= value2
= value3
= value5
= 0;
123 backgroundColour
= labelColour
= buttonColour
= NULL
;
128 wxItemResource::~wxItemResource(void)
130 if (itemType
) delete[] itemType
;
131 if (title
) delete[] title
;
132 if (name
) delete[] name
;
133 if (value4
) delete[] value4
;
138 if (backgroundColour
)
139 delete backgroundColour
;
144 wxNode
*node
= children
.First();
147 wxItemResource
*item
= (wxItemResource
*)node
->Data();
150 node
= children
.First();
154 void wxItemResource::SetTitle(char *t
)
159 if (title
) delete[] title
;
161 title
= copystring(t
);
166 void wxItemResource::SetType(char *t
)
171 if (itemType
) delete[] itemType
;
173 itemType
= copystring(t
);
178 void wxItemResource::SetName(char *n
)
183 if (name
) delete[] name
;
185 name
= copystring(n
);
190 void wxItemResource::SetStringValues(wxStringList
*svalues
)
195 stringValues
= svalues
;
200 void wxItemResource::SetValue4(char *v
)
205 if (value4
) delete[] value4
;
207 value4
= copystring(v
);
216 wxResourceTable::wxResourceTable(void):wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
220 wxResourceTable::~wxResourceTable(void)
225 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
227 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
231 void wxResourceTable::AddResource(wxItemResource
*item
)
233 char *name
= item
->GetName();
235 name
= item
->GetTitle();
239 // Delete existing resource, if any.
245 bool wxResourceTable::DeleteResource(const wxString
& name
)
247 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
250 // See if any resource has this as its child; if so, delete from
251 // parent's child list.
254 while ((node
= Next()))
256 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
257 if (parent
->GetChildren().Member(item
))
259 parent
->GetChildren().DeleteObject(item
);
271 bool wxResourceTable::ParseResourceFile(char *filename
)
275 FILE *fd
= fopen(filename
, "r");
279 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
284 return wxResourceInterpretResources(*this, db
);
287 bool wxResourceTable::ParseResourceData(char *data
)
290 if (!db
.ReadPrologFromString(data
))
292 wxLogWarning(_("Ill-formed resource file syntax."));
296 return wxResourceInterpretResources(*this, db
);
299 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char bits
[], int width
, int height
)
301 // Register pre-loaded bitmap data
302 wxItemResource
*item
= new wxItemResource
;
303 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
304 item
->SetType("wxXBMData");
306 item
->SetValue1((long)bits
);
307 item
->SetValue2((long)width
);
308 item
->SetValue3((long)height
);
313 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char **data
)
315 // Register pre-loaded bitmap data
316 wxItemResource
*item
= new wxItemResource
;
317 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
318 item
->SetType("wxXPMData");
320 item
->SetValue1((long)data
);
325 bool wxResourceTable::SaveResource(char *WXUNUSED(filename
))
330 void wxResourceTable::ClearTable(void)
333 wxNode
*node
= Next();
336 wxNode
*next
= Next();
337 wxItemResource
*item
= (wxItemResource
*)node
->Data();
344 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, wxItemResource
*childResource
) const
346 int id
= childResource
->GetId();
350 wxControl
*control
= NULL
;
351 wxString
itemType(childResource
->GetType());
352 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
354 if (childResource
->GetValue4())
357 wxBitmap
*bitmap
= childResource
->GetBitmap();
360 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
361 childResource
->SetBitmap(bitmap
);
364 control
= new wxBitmapButton(parent
, id
, *bitmap
,
365 wxPoint(childResource
->GetX(), childResource
->GetY()),
366 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
367 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
370 // Normal, text button
371 control
= new wxButton(parent
, id
, childResource
->GetTitle(),
372 wxPoint(childResource
->GetX(), childResource
->GetY()),
373 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
374 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
376 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
377 itemType
== wxString("wxStaticBitmap"))
379 if (childResource
->GetValue4())
382 wxBitmap
*bitmap
= childResource
->GetBitmap();
385 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
386 childResource
->SetBitmap(bitmap
);
388 #if USE_BITMAP_MESSAGE
390 control
= new wxStaticBitmap(parent
, id
, *bitmap
,
391 wxPoint(childResource
->GetX(), childResource
->GetY()),
392 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
393 childResource
->GetStyle(), childResource
->GetName());
398 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(),
399 wxPoint(childResource
->GetX(), childResource
->GetY()),
400 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
401 childResource
->GetStyle(), childResource
->GetName());
404 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
406 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(),
407 wxPoint(childResource
->GetX(), childResource
->GetY()),
408 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
409 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
411 else if (itemType
== wxString("wxCheckBox"))
413 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(),
414 wxPoint(childResource
->GetX(), childResource
->GetY()),
415 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
416 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
418 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
421 else if (itemType
== wxString("wxGauge"))
423 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(),
424 wxPoint(childResource
->GetX(), childResource
->GetY()),
425 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
426 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
428 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
432 else if (itemType
== wxString("wxRadioButton"))
434 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
435 wxPoint(childResource
->GetX(), childResource
->GetY()),
436 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
437 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
441 else if (itemType
== wxString("wxScrollBar"))
443 control
= new wxScrollBar(parent
, id
,
444 wxPoint(childResource
->GetX(), childResource
->GetY()),
445 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
446 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
447 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
448 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
449 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
450 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
453 else if (itemType
== wxString("wxSlider"))
455 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
456 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(),
457 wxPoint(childResource
->GetX(), childResource
->GetY()),
458 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
459 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
461 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
463 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(),
464 wxPoint(childResource
->GetX(), childResource
->GetY()),
465 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
466 childResource
->GetStyle(), childResource
->GetName());
468 else if (itemType
== wxString("wxListBox"))
470 wxStringList
*stringList
= childResource
->GetStringValues();
471 wxString
*strings
= NULL
;
473 if (stringList
&& (stringList
->Number() > 0))
475 noStrings
= stringList
->Number();
476 strings
= new wxString
[noStrings
];
477 wxNode
*node
= stringList
->First();
481 strings
[i
] = (char *)node
->Data();
486 control
= new wxListBox(parent
, id
,
487 wxPoint(childResource
->GetX(), childResource
->GetY()),
488 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
489 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
494 else if (itemType
== wxString("wxChoice"))
496 wxStringList
*stringList
= childResource
->GetStringValues();
497 wxString
*strings
= NULL
;
499 if (stringList
&& (stringList
->Number() > 0))
501 noStrings
= stringList
->Number();
502 strings
= new wxString
[noStrings
];
503 wxNode
*node
= stringList
->First();
507 strings
[i
] = (char *)node
->Data();
512 control
= new wxChoice(parent
, id
,
513 wxPoint(childResource
->GetX(), childResource
->GetY()),
514 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
515 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
521 else if (itemType
== wxString("wxComboBox"))
523 wxStringList
*stringList
= childResource
->GetStringValues();
524 wxString
*strings
= NULL
;
526 if (stringList
&& (stringList
->Number() > 0))
528 noStrings
= stringList
->Number();
529 strings
= new wxString
[noStrings
];
530 wxNode
*node
= stringList
->First();
534 strings
[i
] = (char *)node
->Data();
539 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(),
540 wxPoint(childResource
->GetX(), childResource
->GetY()),
541 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
542 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
548 else if (itemType
== wxString("wxRadioBox"))
550 wxStringList
*stringList
= childResource
->GetStringValues();
551 wxString
*strings
= NULL
;
553 if (stringList
&& (stringList
->Number() > 0))
555 noStrings
= stringList
->Number();
556 strings
= new wxString
[noStrings
];
557 wxNode
*node
= stringList
->First();
561 strings
[i
] = (char *)node
->Data();
566 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()),
567 wxPoint(childResource
->GetX(), childResource
->GetY()),
568 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
569 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
570 childResource
->GetName());
576 if (control
&& childResource
->GetFont())
577 control
->SetFont(*childResource
->GetFont());
582 * Interpret database as a series of resources
585 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
)
587 wxNode
*node
= db
.First();
590 PrologExpr
*clause
= (PrologExpr
*)node
->Data();
591 wxString
functor(clause
->Functor());
593 wxItemResource
*item
= NULL
;
594 if (functor
== "dialog")
595 item
= wxResourceInterpretDialog(table
, clause
);
596 else if (functor
== "panel")
597 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
598 else if (functor
== "menubar")
599 item
= wxResourceInterpretMenuBar(table
, clause
);
600 else if (functor
== "menu")
601 item
= wxResourceInterpretMenu(table
, clause
);
602 else if (functor
== "string")
603 item
= wxResourceInterpretString(table
, clause
);
604 else if (functor
== "bitmap")
605 item
= wxResourceInterpretBitmap(table
, clause
);
606 else if (functor
== "icon")
607 item
= wxResourceInterpretIcon(table
, clause
);
611 // Remove any existing resource of same name
613 table
.DeleteResource(item
->GetName());
614 table
.AddResource(item
);
621 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
622 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
623 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
624 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
625 "wxChoice", "wxComboBox" } ;
626 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
628 static bool wxIsValidControlClass(const wxString
& c
)
631 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
633 if ( c
== g_ValidControlClasses
[i
] )
639 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
)
641 wxItemResource
*dialogItem
= new wxItemResource
;
643 dialogItem
->SetType("wxPanel");
645 dialogItem
->SetType("wxDialog");
649 char *backColourHex
= NULL
;
650 char *labelColourHex
= NULL
;
651 char *buttonColourHex
= NULL
;
653 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
657 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
659 PrologExpr
*labelFontExpr
= NULL
;
660 PrologExpr
*buttonFontExpr
= NULL
;
661 PrologExpr
*fontExpr
= NULL
;
662 expr
->AssignAttributeValue("style", &style
);
663 expr
->AssignAttributeValue("name", &name
);
664 expr
->AssignAttributeValue("title", &title
);
665 expr
->AssignAttributeValue("x", &x
);
666 expr
->AssignAttributeValue("y", &y
);
667 expr
->AssignAttributeValue("width", &width
);
668 expr
->AssignAttributeValue("height", &height
);
669 expr
->AssignAttributeValue("modal", &isModal
);
670 expr
->AssignAttributeValue("label_font", &labelFontExpr
);
671 expr
->AssignAttributeValue("button_font", &buttonFontExpr
);
672 expr
->AssignAttributeValue("font", &fontExpr
);
673 expr
->AssignAttributeValue("background_colour", &backColourHex
);
674 expr
->AssignAttributeValue("label_colour", &labelColourHex
);
675 expr
->AssignAttributeValue("button_colour", &buttonColourHex
);
678 expr
->GetAttributeValue("id", id
);
679 dialogItem
->SetId(id
);
683 windowStyle
= wxParseWindowStyle(style
);
685 dialogItem
->SetStyle(windowStyle
);
686 dialogItem
->SetValue1(isModal
);
688 dialogItem
->SetName(name
);
690 dialogItem
->SetTitle(title
);
691 dialogItem
->SetSize(x
, y
, width
, height
);
698 r
= wxHexToDec(backColourHex
);
699 g
= wxHexToDec(backColourHex
+2);
700 b
= wxHexToDec(backColourHex
+4);
701 dialogItem
->SetBackgroundColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
702 delete[] backColourHex
;
709 r
= wxHexToDec(labelColourHex
);
710 g
= wxHexToDec(labelColourHex
+2);
711 b
= wxHexToDec(labelColourHex
+4);
712 dialogItem
->SetLabelColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
713 delete[] labelColourHex
;
720 r
= wxHexToDec(buttonColourHex
);
721 g
= wxHexToDec(buttonColourHex
+2);
722 b
= wxHexToDec(buttonColourHex
+4);
723 dialogItem
->SetButtonColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
724 delete[] buttonColourHex
;
735 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
736 else if (buttonFontExpr
)
737 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
738 else if (labelFontExpr
)
739 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
741 // Now parse all controls
742 PrologExpr
*controlExpr
= expr
->GetFirst();
745 if (controlExpr
->Number() == 3)
747 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
748 if (controlKeyword
!= "" && controlKeyword
== "control")
750 // The value part: always a list.
751 PrologExpr
*listExpr
= controlExpr
->Nth(2);
752 if (listExpr
->Type() == PrologList
)
754 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
757 dialogItem
->GetChildren().Append(controlItem
);
762 controlExpr
= controlExpr
->GetNext();
767 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
)
769 wxItemResource
*controlItem
= new wxItemResource
;
771 // First, find the standard features of a control definition:
772 // [optional integer/string id], control name, title, style, name, x, y, width, height
774 wxString controlType
;
779 long windowStyle
= 0;
780 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
783 PrologExpr
*expr1
= expr
->Nth(0);
785 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
787 if ( wxIsValidControlClass(expr1
->StringValue()) )
790 controlType
= expr1
->StringValue();
794 wxString
str(expr1
->StringValue());
795 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
798 wxLogWarning(_("Could not resolve control class or id '%s'. "
799 "Use (non-zero) integer instead\n or provide #define "
800 "(see manual for caveats)"),
801 (const char*) expr1
->StringValue());
807 // Success - we have an id, so the 2nd element must be the control class.
808 controlType
= expr
->Nth(1)->StringValue();
813 else if (expr1
->Type() == PrologInteger
)
815 id
= (int)expr1
->IntegerValue();
816 // Success - we have an id, so the 2nd element must be the control class.
817 controlType
= expr
->Nth(1)->StringValue();
821 expr1
= expr
->Nth(count
);
824 title
= expr1
->StringValue();
826 expr1
= expr
->Nth(count
);
830 style
= expr1
->StringValue();
831 windowStyle
= wxParseWindowStyle(WXSTRINGCAST style
);
834 expr1
= expr
->Nth(count
);
837 name
= expr1
->StringValue();
839 expr1
= expr
->Nth(count
);
842 x
= (int)expr1
->IntegerValue();
844 expr1
= expr
->Nth(count
);
847 y
= (int)expr1
->IntegerValue();
849 expr1
= expr
->Nth(count
);
852 width
= (int)expr1
->IntegerValue();
854 expr1
= expr
->Nth(count
);
857 height
= (int)expr1
->IntegerValue();
859 controlItem
->SetStyle(windowStyle
);
860 controlItem
->SetName(WXSTRINGCAST name
);
861 controlItem
->SetTitle(WXSTRINGCAST title
);
862 controlItem
->SetSize(x
, y
, width
, height
);
863 controlItem
->SetType(WXSTRINGCAST controlType
);
864 controlItem
->SetId(id
);
866 if (controlType
== "wxButton")
868 // Check for bitmap resource name
869 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
871 wxString
str(expr
->Nth(count
)->StringValue());
872 controlItem
->SetValue4(WXSTRINGCAST str
);
874 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
875 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
878 else if (controlType
== "wxCheckBox")
880 // Check for default value
881 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
883 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
885 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
886 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
890 else if (controlType
== "wxRadioButton")
892 // Check for default value
893 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
895 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
897 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
898 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
902 else if (controlType
== "wxText" || controlType
== "wxTextCtrl")
904 // Check for default value
905 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
907 wxString
str(expr
->Nth(count
)->StringValue());
908 controlItem
->SetValue4(WXSTRINGCAST str
);
911 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
913 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
914 // Do nothing - no label font any more
916 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
917 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
921 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
923 // Check for bitmap resource name
924 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
926 wxString
str(expr
->Nth(count
)->StringValue());
927 controlItem
->SetValue4(WXSTRINGCAST str
);
929 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
930 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
933 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
935 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
936 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
938 else if (controlType
== "wxGauge")
940 // Check for default value
941 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
943 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
947 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
949 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
952 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
954 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
958 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
959 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
964 else if (controlType
== "wxSlider")
966 // Check for default value
967 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
969 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
973 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
975 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
979 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
981 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
984 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
986 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
990 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
991 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
997 else if (controlType
== "wxScrollBar")
1000 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1002 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1006 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1008 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1012 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1014 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1018 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1019 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1024 else if (controlType
== "wxListBox")
1026 PrologExpr
*valueList
= NULL
;
1028 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1030 wxStringList
*stringList
= new wxStringList
;
1031 PrologExpr
*stringExpr
= valueList
->GetFirst();
1034 stringList
->Add(stringExpr
->StringValue());
1035 stringExpr
= stringExpr
->GetNext();
1037 controlItem
->SetStringValues(stringList
);
1040 // Check for wxSINGLE/wxMULTIPLE
1041 PrologExpr
*mult
= NULL
;
1042 controlItem
->SetValue1(wxLB_SINGLE
);
1043 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1045 wxString
m(mult
->StringValue());
1046 if (m
== "wxMULTIPLE")
1047 controlItem
->SetValue1(wxLB_MULTIPLE
);
1048 else if (m
== "wxEXTENDED")
1049 controlItem
->SetValue1(wxLB_EXTENDED
);
1051 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1053 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1055 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1056 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1061 else if (controlType
== "wxChoice")
1063 PrologExpr
*valueList
= NULL
;
1064 // Check for default value list
1065 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1067 wxStringList
*stringList
= new wxStringList
;
1068 PrologExpr
*stringExpr
= valueList
->GetFirst();
1071 stringList
->Add(stringExpr
->StringValue());
1072 stringExpr
= stringExpr
->GetNext();
1074 controlItem
->SetStringValues(stringList
);
1078 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1080 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1083 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1084 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1089 else if (controlType
== "wxComboBox")
1091 PrologExpr
*textValue
= expr
->Nth(count
);
1092 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1094 wxString
str(textValue
->StringValue());
1095 controlItem
->SetValue4(WXSTRINGCAST str
);
1099 PrologExpr
*valueList
= NULL
;
1100 // Check for default value list
1101 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1103 wxStringList
*stringList
= new wxStringList
;
1104 PrologExpr
*stringExpr
= valueList
->GetFirst();
1107 stringList
->Add(stringExpr
->StringValue());
1108 stringExpr
= stringExpr
->GetNext();
1110 controlItem
->SetStringValues(stringList
);
1114 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1116 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1119 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1120 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1127 else if (controlType
== "wxRadioBox")
1129 PrologExpr
*valueList
= NULL
;
1130 // Check for default value list
1131 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1133 wxStringList
*stringList
= new wxStringList
;
1134 PrologExpr
*stringExpr
= valueList
->GetFirst();
1137 stringList
->Add(stringExpr
->StringValue());
1138 stringExpr
= stringExpr
->GetNext();
1140 controlItem
->SetStringValues(stringList
);
1143 // majorDim (number of rows or cols)
1144 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1146 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1150 controlItem
->SetValue1(0);
1152 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1154 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1157 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1158 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1171 // Forward declaration
1172 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, PrologExpr
*expr
);
1175 * Interpet a menu item
1178 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, PrologExpr
*expr
)
1180 wxItemResource
*item
= new wxItemResource
;
1182 PrologExpr
*labelExpr
= expr
->Nth(0);
1183 PrologExpr
*idExpr
= expr
->Nth(1);
1184 PrologExpr
*helpExpr
= expr
->Nth(2);
1185 PrologExpr
*checkableExpr
= expr
->Nth(3);
1187 // Further keywords/attributes to follow sometime...
1188 if (expr
->Number() == 0)
1190 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1191 item
->SetType("wxMenuSeparator");
1196 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1197 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1200 wxString
str(labelExpr
->StringValue());
1201 item
->SetTitle(WXSTRINGCAST str
);
1206 // If a string or word, must look up in identifier table.
1207 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1209 wxString
str(idExpr
->StringValue());
1210 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
1213 wxLogWarning(_("Could not resolve menu id '%s'. "
1214 "Use (non-zero) integer instead\n"
1215 "or provide #define (see manual for caveats)"),
1216 (const char*) idExpr
->StringValue());
1219 else if (idExpr
->Type() == PrologInteger
)
1220 id
= (int)idExpr
->IntegerValue();
1221 item
->SetValue1(id
);
1225 wxString
str(helpExpr
->StringValue());
1226 item
->SetValue4(WXSTRINGCAST str
);
1229 item
->SetValue2(checkableExpr
->IntegerValue());
1231 // Find the first expression that's a list, for submenu
1232 PrologExpr
*subMenuExpr
= expr
->GetFirst();
1233 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1234 subMenuExpr
= subMenuExpr
->GetNext();
1238 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1239 item
->GetChildren().Append(child
);
1240 subMenuExpr
= subMenuExpr
->GetNext();
1247 * Interpret a nested list as a menu
1250 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr)
1252 wxItemResource *menu = new wxItemResource;
1253 // menu->SetType(wxTYPE_MENU);
1254 menu->SetType("wxMenu");
1255 PrologExpr *element = expr->GetFirst();
1258 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1260 menu->GetChildren().Append(item);
1261 element = element->GetNext();
1267 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
)
1269 PrologExpr
*listExpr
= NULL
;
1270 expr
->AssignAttributeValue("menu", &listExpr
);
1274 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1280 expr
->AssignAttributeValue("name", &name
);
1283 menuResource
->SetName(name
);
1287 return menuResource
;
1290 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
)
1292 PrologExpr
*listExpr
= NULL
;
1293 expr
->AssignAttributeValue("menu", &listExpr
);
1297 wxItemResource
*resource
= new wxItemResource
;
1298 resource
->SetType("wxMenu");
1299 // resource->SetType(wxTYPE_MENU);
1301 PrologExpr
*element
= listExpr
->GetFirst();
1304 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1305 resource
->GetChildren().Append(menuResource
);
1306 element
= element
->GetNext();
1310 expr
->AssignAttributeValue("name", &name
);
1313 resource
->SetName(name
);
1320 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), PrologExpr
*WXUNUSED(expr
))
1325 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), PrologExpr
*expr
)
1327 wxItemResource
*bitmapItem
= new wxItemResource
;
1328 // bitmapItem->SetType(wxTYPE_BITMAP);
1329 bitmapItem
->SetType("wxBitmap");
1331 expr
->AssignAttributeValue("name", &name
);
1334 bitmapItem
->SetName(name
);
1337 // Now parse all bitmap specifications
1338 PrologExpr
*bitmapExpr
= expr
->GetFirst();
1341 if (bitmapExpr
->Number() == 3)
1343 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1344 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1346 // The value part: always a list.
1347 PrologExpr
*listExpr
= bitmapExpr
->Nth(2);
1348 if (listExpr
->Type() == PrologList
)
1350 wxItemResource
*bitmapSpec
= new wxItemResource
;
1351 // bitmapSpec->SetType(wxTYPE_BITMAP);
1352 bitmapSpec
->SetType("wxBitmap");
1354 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1355 // where everything after 'filename' is optional.
1356 PrologExpr
*nameExpr
= listExpr
->Nth(0);
1357 PrologExpr
*typeExpr
= listExpr
->Nth(1);
1358 PrologExpr
*platformExpr
= listExpr
->Nth(2);
1359 PrologExpr
*coloursExpr
= listExpr
->Nth(3);
1360 PrologExpr
*xresExpr
= listExpr
->Nth(4);
1361 PrologExpr
*yresExpr
= listExpr
->Nth(5);
1362 if (nameExpr
&& nameExpr
->StringValue())
1364 wxString
str(nameExpr
->StringValue());
1365 bitmapSpec
->SetName(WXSTRINGCAST str
);
1367 if (typeExpr
&& typeExpr
->StringValue())
1369 wxString
str(typeExpr
->StringValue());
1370 bitmapSpec
->SetValue1(wxParseWindowStyle(WXSTRINGCAST str
));
1373 bitmapSpec
->SetValue1(0);
1375 if (platformExpr
&& platformExpr
->StringValue())
1377 wxString
plat(platformExpr
->StringValue());
1378 if (plat
== "windows" || plat
== "WINDOWS")
1379 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1380 else if (plat
== "x" || plat
== "X")
1381 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1382 else if (plat
== "mac" || plat
== "MAC")
1383 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1385 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1388 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1391 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1395 xres
= (int)xresExpr
->IntegerValue();
1397 yres
= (int)yresExpr
->IntegerValue();
1398 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1400 bitmapItem
->GetChildren().Append(bitmapSpec
);
1404 bitmapExpr
= bitmapExpr
->GetNext();
1410 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
)
1412 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1415 // item->SetType(wxTYPE_ICON);
1416 item
->SetType("wxIcon");
1423 // Interpret list expression as a font
1424 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
)
1426 if (expr
->Type() != PrologList
)
1430 int family
= wxSWISS
;
1431 int style
= wxNORMAL
;
1432 int weight
= wxNORMAL
;
1434 wxString
faceName("");
1436 PrologExpr
*pointExpr
= expr
->Nth(0);
1437 PrologExpr
*familyExpr
= expr
->Nth(1);
1438 PrologExpr
*styleExpr
= expr
->Nth(2);
1439 PrologExpr
*weightExpr
= expr
->Nth(3);
1440 PrologExpr
*underlineExpr
= expr
->Nth(4);
1441 PrologExpr
*faceNameExpr
= expr
->Nth(5);
1443 point
= (int)pointExpr
->IntegerValue();
1448 str
= familyExpr
->StringValue();
1449 family
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1453 str
= styleExpr
->StringValue();
1454 style
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1458 str
= weightExpr
->StringValue();
1459 weight
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1462 underline
= (int)underlineExpr
->IntegerValue();
1464 faceName
= faceNameExpr
->StringValue();
1466 char *faceName1
= NULL
;
1468 faceName1
= WXSTRINGCAST faceName
;
1469 wxFont
*font
= wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
, (underline
!= 0), faceName1
);
1474 * (Re)allocate buffer for reading in from resource file
1477 bool wxReallocateResourceBuffer(void)
1479 if (!wxResourceBuffer
)
1481 wxResourceBufferSize
= 1000;
1482 wxResourceBuffer
= new char[wxResourceBufferSize
];
1485 if (wxResourceBuffer
)
1487 long newSize
= wxResourceBufferSize
+ 1000;
1488 char *tmp
= new char[(int)newSize
];
1489 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1490 delete[] wxResourceBuffer
;
1491 wxResourceBuffer
= tmp
;
1492 wxResourceBufferSize
= newSize
;
1497 static bool wxEatWhiteSpace(FILE *fd
)
1500 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1507 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1509 // Check for comment
1515 bool finished
= FALSE
;
1523 int newCh
= getc(fd
);
1538 return wxEatWhiteSpace(fd
);
1541 bool wxGetResourceToken(FILE *fd
)
1543 if (!wxResourceBuffer
)
1544 wxReallocateResourceBuffer();
1545 wxResourceBuffer
[0] = 0;
1546 wxEatWhiteSpace(fd
);
1552 wxResourceBufferCount
= 0;
1559 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1562 // Escaped characters
1563 else if (ch
== '\\')
1565 int newCh
= getc(fd
);
1568 else if (newCh
== 10)
1576 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1577 wxReallocateResourceBuffer();
1578 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1579 wxResourceBufferCount
++;
1582 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1586 wxResourceBufferCount
= 0;
1588 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1590 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1591 wxReallocateResourceBuffer();
1592 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1593 wxResourceBufferCount
++;
1597 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1605 * Files are in form:
1606 static char *name = "....";
1607 with possible comments.
1610 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1613 table
= wxDefaultResourceTable
;
1615 // static or #define
1616 if (!wxGetResourceToken(fd
))
1622 if (strcmp(wxResourceBuffer
, "#define") == 0)
1624 wxGetResourceToken(fd
);
1625 char *name
= copystring(wxResourceBuffer
);
1626 wxGetResourceToken(fd
);
1627 char *value
= copystring(wxResourceBuffer
);
1628 if (isalpha(value
[0]))
1630 int val
= (int)atol(value
);
1631 wxResourceAddIdentifier(name
, val
, table
);
1635 wxLogWarning(_("#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
))
1657 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1662 else if (strcmp(wxResourceBuffer
, "static") != 0)
1665 strcpy(buf
, _("Found "));
1666 strncat(buf
, wxResourceBuffer
, 30);
1667 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1673 if (!wxGetResourceToken(fd
))
1675 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1680 if (strcmp(wxResourceBuffer
, "char") != 0)
1682 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1687 if (!wxGetResourceToken(fd
))
1689 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1694 if (wxResourceBuffer
[0] != '*')
1696 wxLogWarning(_("Expected '*' whilst parsing resource."));
1700 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1703 if (!wxGetResourceToken(fd
))
1705 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1710 if (strcmp(wxResourceBuffer
, "=") != 0)
1712 wxLogWarning(_("Expected '=' whilst parsing resource."));
1717 if (!wxGetResourceToken(fd
))
1719 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1725 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1727 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1732 if (!wxGetResourceToken(fd
))
1740 * Parses string window style into integer window style
1744 * Style flag parsing, e.g.
1745 * "wxSYSTEM_MENU | wxBORDER" -> integer
1748 char *wxResourceParseWord(char *s
, int *i
)
1753 static char buf
[150];
1754 int len
= strlen(s
);
1757 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1765 // Eat whitespace and conjunction characters
1766 while ((ii
< len
) &&
1767 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1778 struct wxResourceBitListStruct
1784 static wxResourceBitListStruct wxResourceBitListTable
[] =
1787 { "wxSINGLE", wxLB_SINGLE
},
1788 { "wxMULTIPLE", wxLB_MULTIPLE
},
1789 { "wxEXTENDED", wxLB_EXTENDED
},
1790 { "wxLB_SINGLE", wxLB_SINGLE
},
1791 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1792 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1793 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1794 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1795 { "wxLB_SORT", wxLB_SORT
},
1796 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1797 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1800 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1801 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1802 { "wxCB_READONLY", wxCB_READONLY
},
1803 { "wxCB_SORT", wxCB_SORT
},
1806 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1807 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1808 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1811 { "wxPASSWORD", wxPASSWORD
},
1812 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1813 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1814 { "wxTE_READONLY", wxTE_READONLY
},
1815 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1816 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1818 /* wxRadioBox/wxRadioButton */
1819 { "wxRB_GROUP", wxRB_GROUP
},
1820 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1821 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1824 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1825 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1826 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1827 { "wxSL_LABELS", wxSL_LABELS
},
1828 { "wxSL_LEFT", wxSL_LEFT
},
1829 { "wxSL_TOP", wxSL_TOP
},
1830 { "wxSL_RIGHT", wxSL_RIGHT
},
1831 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1832 { "wxSL_BOTH", wxSL_BOTH
},
1833 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1836 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1837 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1840 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1841 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1844 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1845 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1846 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1849 { "wxLC_ICON", wxLC_ICON
},
1850 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1851 { "wxLC_LIST", wxLC_LIST
},
1852 { "wxLC_REPORT", wxLC_REPORT
},
1853 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1854 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1855 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1856 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1857 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1858 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1859 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1860 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1861 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1862 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1865 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1866 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1867 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1868 { "wxSP_WRAP", wxSP_WRAP
},
1871 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1872 { "wxSP_3D", wxSP_3D
},
1873 { "wxSP_BORDER", wxSP_BORDER
},
1876 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1877 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1878 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1879 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1882 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1885 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1886 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1887 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1888 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1889 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1890 { "wxCOLOURED", wxCOLOURED
},
1893 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1894 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1895 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1896 { "wxTB_FLAT", wxTB_FLAT
},
1899 { "wxVSCROLL", wxVSCROLL
},
1900 { "wxHSCROLL", wxHSCROLL
},
1901 { "wxCAPTION", wxCAPTION
},
1902 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1903 { "wxICONIZE", wxICONIZE
},
1904 { "wxMINIMIZE", wxICONIZE
},
1905 { "wxMAXIMIZE", wxMAXIMIZE
},
1907 { "wxMDI_PARENT", 0},
1908 { "wxMDI_CHILD", 0},
1909 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1910 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1911 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1912 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1913 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1914 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1915 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1916 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1917 { "wxBORDER", wxBORDER
},
1918 { "wxRETAINED", wxRETAINED
},
1919 { "wxNATIVE_IMPL", 0},
1920 { "wxEXTENDED_IMPL", 0},
1921 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1922 // { "wxFLAT", wxFLAT},
1923 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1924 { "wxFIXED_LENGTH", 0},
1925 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1926 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1927 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1928 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1929 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1930 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1931 { "wxNO_BORDER", wxNO_BORDER
},
1932 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1934 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1935 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1937 // Text font families
1938 { "wxDEFAULT", wxDEFAULT
},
1939 { "wxDECORATIVE", wxDECORATIVE
},
1940 { "wxROMAN", wxROMAN
},
1941 { "wxSCRIPT", wxSCRIPT
},
1942 { "wxSWISS", wxSWISS
},
1943 { "wxMODERN", wxMODERN
},
1944 { "wxTELETYPE", wxTELETYPE
},
1945 { "wxVARIABLE", wxVARIABLE
},
1946 { "wxFIXED", wxFIXED
},
1947 { "wxNORMAL", wxNORMAL
},
1948 { "wxLIGHT", wxLIGHT
},
1949 { "wxBOLD", wxBOLD
},
1950 { "wxITALIC", wxITALIC
},
1951 { "wxSLANT", wxSLANT
},
1952 { "wxSOLID", wxSOLID
},
1954 { "wxLONG_DASH", wxLONG_DASH
},
1955 { "wxSHORT_DASH", wxSHORT_DASH
},
1956 { "wxDOT_DASH", wxDOT_DASH
},
1957 { "wxUSER_DASH", wxUSER_DASH
},
1958 { "wxTRANSPARENT", wxTRANSPARENT
},
1959 { "wxSTIPPLE", wxSTIPPLE
},
1960 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1961 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1962 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1963 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1964 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1965 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1966 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1967 { "wxJOIN_MITER", wxJOIN_MITER
},
1968 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1969 { "wxCAP_ROUND", wxCAP_ROUND
},
1970 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1971 { "wxCAP_BUTT", wxCAP_BUTT
},
1974 { "wxCLEAR", wxCLEAR
},
1976 { "wxINVERT", wxINVERT
},
1977 { "wxOR_REVERSE", wxOR_REVERSE
},
1978 { "wxAND_REVERSE", wxAND_REVERSE
},
1979 { "wxCOPY", wxCOPY
},
1981 { "wxAND_INVERT", wxAND_INVERT
},
1982 { "wxNO_OP", wxNO_OP
},
1984 { "wxEQUIV", wxEQUIV
},
1985 { "wxSRC_INVERT", wxSRC_INVERT
},
1986 { "wxOR_INVERT", wxOR_INVERT
},
1987 { "wxNAND", wxNAND
},
1991 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1992 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1993 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1994 { "wxWINDING_RULE", wxWINDING_RULE
},
1995 { "wxHORIZONTAL", wxHORIZONTAL
},
1996 { "wxVERTICAL", wxVERTICAL
},
1997 { "wxBOTH", wxBOTH
},
1998 { "wxCENTER_FRAME", wxCENTER_FRAME
},
2000 { "wxYES_NO", wxYES_NO
},
2001 { "wxCANCEL", wxCANCEL
},
2004 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
2005 { "wxICON_HAND", wxICON_HAND
},
2006 { "wxICON_QUESTION", wxICON_QUESTION
},
2007 { "wxICON_INFORMATION", wxICON_INFORMATION
},
2008 { "wxICON_STOP", wxICON_STOP
},
2009 { "wxICON_ASTERISK", wxICON_ASTERISK
},
2010 { "wxICON_MASK", wxICON_MASK
},
2011 { "wxCENTRE", wxCENTRE
},
2012 { "wxCENTER", wxCENTRE
},
2013 { "wxUSER_COLOURS", wxUSER_COLOURS
},
2014 { "wxVERTICAL_LABEL", 0},
2015 { "wxHORIZONTAL_LABEL", 0},
2017 // Bitmap types (not strictly styles)
2018 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
2019 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
2020 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
2021 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2022 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2023 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
2024 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
2025 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
2026 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
2027 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
2028 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
2029 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
2030 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
2031 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
2034 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2036 long wxParseWindowStyle(char *bitListString
)
2041 while ((word
= wxResourceParseWord(bitListString
, &i
)))
2045 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2046 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2048 bitList
|= wxResourceBitListTable
[j
].bits
;
2054 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2062 * Load a bitmap from a wxWindows resource, choosing an optimum
2063 * depth and appropriate type.
2066 wxBitmap
*wxResourceCreateBitmap(char *resource
, wxResourceTable
*table
)
2069 table
= wxDefaultResourceTable
;
2071 wxItemResource
*item
= table
->FindResource(resource
);
2074 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2076 wxLogWarning(_("%s not a bitmap resource specification."), resource
);
2079 int thisDepth
= wxDisplayDepth();
2080 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2082 wxItemResource
*optResource
= NULL
;
2084 // Try to find optimum bitmap for this platform/colour depth
2085 wxNode
*node
= item
->GetChildren().First();
2088 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2089 int platform
= (int)child
->GetValue2();
2090 int noColours
= (int)child
->GetValue3();
2092 char *name = child->GetName();
2093 int bitmapType = (int)child->GetValue1();
2094 int xRes = child->GetWidth();
2095 int yRes = child->GetHeight();
2100 case RESOURCE_PLATFORM_ANY
:
2102 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2103 optResource
= child
;
2106 // Maximise the number of colours.
2107 // If noColours is zero (unspecified), then assume this
2108 // is the right one.
2109 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2110 optResource
= child
;
2115 case RESOURCE_PLATFORM_WINDOWS
:
2117 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2118 optResource
= child
;
2121 // Maximise the number of colours
2122 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2123 optResource
= child
;
2129 case RESOURCE_PLATFORM_X
:
2131 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2132 optResource
= child
;
2135 // Maximise the number of colours
2136 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2137 optResource
= child
;
2143 case RESOURCE_PLATFORM_MAC
:
2145 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2146 optResource
= child
;
2149 // Maximise the number of colours
2150 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2151 optResource
= child
;
2159 node
= node
->Next();
2161 // If no matching resource, fail.
2165 char *name
= optResource
->GetName();
2166 int bitmapType
= (int)optResource
->GetValue1();
2167 wxBitmap
*bitmap
= NULL
;
2170 case wxBITMAP_TYPE_XBM_DATA
:
2173 wxItemResource
*item
= table
->FindResource(name
);
2176 wxLogWarning(_("Failed to find XBM resource %s.\n"
2177 "Forgot to use wxResourceLoadBitmapData?"), name
);
2180 bitmap
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2182 wxLogWarning(_("No XBM facility available!"));
2186 case wxBITMAP_TYPE_XPM_DATA
:
2188 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2189 wxItemResource
*item
= table
->FindResource(name
);
2192 wxLogWarning(_("Failed to find XPM resource %s.\n"
2193 "Forgot to use wxResourceLoadBitmapData?"), name
);
2196 bitmap
= new wxBitmap(item
->GetValue1());
2198 wxLogWarning(_("No XPM facility available!"));
2204 bitmap
= new wxBitmap(name
, bitmapType
);
2223 wxLogWarning(_("Bitmap resource specification %s not found."), resource
);
2229 * Load an icon from a wxWindows resource, choosing an optimum
2230 * depth and appropriate type.
2233 wxIcon
*wxResourceCreateIcon(char *resource
, wxResourceTable
*table
)
2236 table
= wxDefaultResourceTable
;
2238 wxItemResource
*item
= table
->FindResource(resource
);
2241 if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0)
2243 wxLogWarning(_("%s not an icon resource specification."), resource
);
2246 int thisDepth
= wxDisplayDepth();
2247 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2249 wxItemResource
*optResource
= NULL
;
2251 // Try to find optimum icon for this platform/colour depth
2252 wxNode
*node
= item
->GetChildren().First();
2255 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2256 int platform
= (int)child
->GetValue2();
2257 int noColours
= (int)child
->GetValue3();
2259 char *name = child->GetName();
2260 int bitmapType = (int)child->GetValue1();
2261 int xRes = child->GetWidth();
2262 int yRes = child->GetHeight();
2267 case RESOURCE_PLATFORM_ANY
:
2269 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2270 optResource
= child
;
2273 // Maximise the number of colours.
2274 // If noColours is zero (unspecified), then assume this
2275 // is the right one.
2276 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2277 optResource
= child
;
2282 case RESOURCE_PLATFORM_WINDOWS
:
2284 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2285 optResource
= child
;
2288 // Maximise the number of colours
2289 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2290 optResource
= child
;
2296 case RESOURCE_PLATFORM_X
:
2298 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2299 optResource
= child
;
2302 // Maximise the number of colours
2303 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2304 optResource
= child
;
2310 case RESOURCE_PLATFORM_MAC
:
2312 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2313 optResource
= child
;
2316 // Maximise the number of colours
2317 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2318 optResource
= child
;
2326 node
= node
->Next();
2328 // If no matching resource, fail.
2332 char *name
= optResource
->GetName();
2333 int bitmapType
= (int)optResource
->GetValue1();
2334 wxIcon
*icon
= NULL
;
2337 case wxBITMAP_TYPE_XBM_DATA
:
2340 wxItemResource
*item
= table
->FindResource(name
);
2343 wxLogWarning(_("Failed to find XBM resource %s.\n"
2344 "Forgot to use wxResourceLoadIconData?"), name
);
2347 icon
= new wxIcon((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2349 wxLogWarning(_("No XBM facility available!"));
2353 case wxBITMAP_TYPE_XPM_DATA
:
2355 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2357 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2358 wxItemResource *item = table->FindResource(name);
2362 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2366 icon = new wxIcon((char **)item->GetValue1());
2368 wxLogWarning(_("No XPM facility available!"));
2371 wxLogWarning(_("No XPM icon facility available!"));
2376 icon
= new wxIcon(name
, bitmapType
);
2395 wxLogWarning(_("Icon resource specification %s not found."), resource
);
2400 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2402 wxMenu
*menu
= new wxMenu
;
2403 wxNode
*node
= item
->GetChildren().First();
2406 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2407 if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0)
2408 menu
->AppendSeparator();
2409 else if (child
->GetChildren().Number() > 0)
2411 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2413 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2417 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2419 node
= node
->Next();
2424 wxMenuBar
*wxResourceCreateMenuBar(char *resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2427 table
= wxDefaultResourceTable
;
2429 wxItemResource
*menuResource
= table
->FindResource(resource
);
2430 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2433 menuBar
= new wxMenuBar
;
2434 wxNode
*node
= menuResource
->GetChildren().First();
2437 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2438 wxMenu
*menu
= wxResourceCreateMenu(child
);
2440 menuBar
->Append(menu
, child
->GetTitle());
2441 node
= node
->Next();
2448 wxMenu
*wxResourceCreateMenu(char *resource
, wxResourceTable
*table
)
2451 table
= wxDefaultResourceTable
;
2453 wxItemResource
*menuResource
= table
->FindResource(resource
);
2454 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2455 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2456 return wxResourceCreateMenu(menuResource
);
2460 // Global equivalents (so don't have to refer to default table explicitly)
2461 bool wxResourceParseData(char *resource
, wxResourceTable
*table
)
2464 table
= wxDefaultResourceTable
;
2466 return table
->ParseResourceData(resource
);
2469 bool wxResourceParseFile(char *filename
, wxResourceTable
*table
)
2472 table
= wxDefaultResourceTable
;
2474 return table
->ParseResourceFile(filename
);
2477 // Register XBM/XPM data
2478 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2481 table
= wxDefaultResourceTable
;
2483 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2486 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable
*table
)
2489 table
= wxDefaultResourceTable
;
2491 return table
->RegisterResourceBitmapData(name
, data
);
2494 void wxResourceClear(wxResourceTable
*table
)
2497 table
= wxDefaultResourceTable
;
2499 table
->ClearTable();
2506 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable
*table
)
2509 table
= wxDefaultResourceTable
;
2511 table
->identifiers
.Put(name
, (wxObject
*)value
);
2515 int wxResourceGetIdentifier(char *name
, wxResourceTable
*table
)
2518 table
= wxDefaultResourceTable
;
2520 return (int)table
->identifiers
.Get(name
);
2524 * Parse #include file for #defines (only)
2527 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
)
2530 table
= wxDefaultResourceTable
;
2532 FILE *fd
= fopen(f
, "r");
2537 while (wxGetResourceToken(fd
))
2539 if (strcmp(wxResourceBuffer
, "#define") == 0)
2541 wxGetResourceToken(fd
);
2542 char *name
= copystring(wxResourceBuffer
);
2543 wxGetResourceToken(fd
);
2544 char *value
= copystring(wxResourceBuffer
);
2545 if (isdigit(value
[0]))
2547 int val
= (int)atol(value
);
2548 wxResourceAddIdentifier(name
, val
, table
);
2559 * Reading strings as if they were .wxr files
2562 static int getc_string(char *s
)
2564 int ch
= s
[wxResourceStringPtr
];
2569 wxResourceStringPtr
++;
2574 static int ungetc_string(void)
2576 wxResourceStringPtr
--;
2580 bool wxEatWhiteSpaceString(char *s
)
2582 int ch
= getc_string(s
);
2586 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2593 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2594 ch
= getc_string(s
);
2595 // Check for comment
2598 ch
= getc_string(s
);
2601 bool finished
= FALSE
;
2604 ch
= getc_string(s
);
2609 int newCh
= getc_string(s
);
2624 return wxEatWhiteSpaceString(s
);
2627 bool wxGetResourceTokenString(char *s
)
2629 if (!wxResourceBuffer
)
2630 wxReallocateResourceBuffer();
2631 wxResourceBuffer
[0] = 0;
2632 wxEatWhiteSpaceString(s
);
2634 int ch
= getc_string(s
);
2638 wxResourceBufferCount
= 0;
2639 ch
= getc_string(s
);
2645 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2648 // Escaped characters
2649 else if (ch
== '\\')
2651 int newCh
= getc_string(s
);
2654 else if (newCh
== 10)
2662 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2663 wxReallocateResourceBuffer();
2664 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2665 wxResourceBufferCount
++;
2666 ch
= getc_string(s
);
2668 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2672 wxResourceBufferCount
= 0;
2674 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2676 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2677 wxReallocateResourceBuffer();
2678 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2679 wxResourceBufferCount
++;
2681 ch
= getc_string(s
);
2683 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2691 * Files are in form:
2692 static char *name = "....";
2693 with possible comments.
2696 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2699 table
= wxDefaultResourceTable
;
2701 // static or #define
2702 if (!wxGetResourceTokenString(s
))
2708 if (strcmp(wxResourceBuffer
, "#define") == 0)
2710 wxGetResourceTokenString(s
);
2711 char *name
= copystring(wxResourceBuffer
);
2712 wxGetResourceTokenString(s
);
2713 char *value
= copystring(wxResourceBuffer
);
2714 if (isalpha(value
[0]))
2716 int val
= (int)atol(value
);
2717 wxResourceAddIdentifier(name
, val
, table
);
2721 wxLogWarning(_("#define %s must be an integer."), name
);
2732 else if (strcmp(wxResourceBuffer, "#include") == 0)
2734 wxGetResourceTokenString(s);
2735 char *name = copystring(wxResourceBuffer);
2736 char *actualName = name;
2738 actualName = name + 1;
2739 int len = strlen(name);
2740 if ((len > 0) && (name[len-1] == '"'))
2742 if (!wxResourceParseIncludeFile(actualName, table))
2745 sprintf(buf, _("Could not find resource include file %s."), actualName);
2752 else if (strcmp(wxResourceBuffer
, "static") != 0)
2755 strcpy(buf
, _("Found "));
2756 strncat(buf
, wxResourceBuffer
, 30);
2757 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2763 if (!wxGetResourceTokenString(s
))
2765 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2770 if (strcmp(wxResourceBuffer
, "char") != 0)
2772 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2777 if (!wxGetResourceTokenString(s
))
2779 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2784 if (wxResourceBuffer
[0] != '*')
2786 wxLogWarning(_("Expected '*' whilst parsing resource."));
2790 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2793 if (!wxGetResourceTokenString(s
))
2795 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2800 if (strcmp(wxResourceBuffer
, "=") != 0)
2802 wxLogWarning(_("Expected '=' whilst parsing resource."));
2807 if (!wxGetResourceTokenString(s
))
2809 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2815 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2817 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2822 if (!wxGetResourceTokenString(s
))
2829 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2832 table
= wxDefaultResourceTable
;
2837 // Turn backslashes into spaces
2840 int len
= strlen(s
);
2842 for (i
= 0; i
< len
; i
++)
2843 if (s
[i
] == 92 && s
[i
+1] == 13)
2851 wxResourceStringPtr
= 0;
2854 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2858 return wxResourceInterpretResources(*table
, db
);
2862 * resource loading facility
2865 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2868 table
= wxDefaultResourceTable
;
2870 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2871 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2872 if (!resource
|| !resource
->GetType() ||
2873 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2876 char *title
= resource
->GetTitle();
2877 long theWindowStyle
= resource
->GetStyle();
2878 bool isModal
= (resource
->GetValue1() != 0);
2879 int x
= resource
->GetX();
2880 int y
= resource
->GetY();
2881 int width
= resource
->GetWidth();
2882 int height
= resource
->GetHeight();
2883 char *name
= resource
->GetName();
2885 wxFont
*theFont
= resource
->GetFont();
2887 if (IsKindOf(CLASSINFO(wxDialog
)))
2889 wxDialog
*dialogBox
= (wxDialog
*)this;
2890 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2891 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2893 dialogBox
->SetClientSize(width
, height
);
2897 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2904 if (resource
->GetBackgroundColour())
2905 SetBackgroundColour(*resource
->GetBackgroundColour());
2908 if (resource
->GetLabelColour())
2909 SetForegroundColour(*resource
->GetLabelColour());
2910 else if (resource
->GetButtonColour())
2911 SetForegroundColour(*resource
->GetButtonColour());
2913 // Now create children
2914 wxNode
*node
= resource
->GetChildren().First();
2917 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2919 (void) CreateItem(childResource
, table
);
2921 node
= node
->Next();
2926 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxResourceTable
*table
)
2929 table
= wxDefaultResourceTable
;
2930 return table
->CreateItem((wxWindow
*)this, (wxItemResource
*)resource
);
2933 #endif // USE_WX_RESOURCES