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"
23 #if wxUSE_WX_RESOURCES
26 #pragma warning(disable:4706) // assignment within conditional expression
34 #include "wx/gdicmn.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
47 #include "wx/statbox.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
57 #include "wx/scrolbar.h"
61 #include "wx/combobox.h"
64 #include "wx/validate.h"
73 #include "wx/resource.h"
74 #include "wx/string.h"
75 #include "wx/wxexpr.h"
77 #include "wx/settings.h"
79 // Forward (private) declarations
80 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
81 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
82 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
83 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
84 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
85 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
86 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
87 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
88 // Interpret list expression
89 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
91 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
92 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
94 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
96 static char *wxResourceBuffer
= (char *) NULL
;
97 static long wxResourceBufferSize
= 0;
98 static long wxResourceBufferCount
= 0;
99 static int wxResourceStringPtr
= 0;
101 void wxInitializeResourceSystem()
103 wxDefaultResourceTable
= new wxResourceTable
;
106 void wxCleanUpResourceSystem()
108 delete wxDefaultResourceTable
;
109 if (wxResourceBuffer
)
110 delete[] wxResourceBuffer
;
113 void wxLogWarning(char *msg
)
115 wxMessageBox(msg
, _("Warning"), wxOK
);
118 #if !USE_SHARED_LIBRARY
119 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
120 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
123 wxItemResource::wxItemResource()
129 m_x
= m_y
= m_width
= m_height
= 0;
130 m_value1
= m_value2
= m_value3
= m_value5
= 0;
136 wxItemResource::~wxItemResource()
138 wxNode
*node
= m_children
.First();
141 wxItemResource
*item
= (wxItemResource
*)node
->Data();
144 node
= m_children
.First();
152 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
156 wxResourceTable::~wxResourceTable()
161 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
163 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
167 void wxResourceTable::AddResource(wxItemResource
*item
)
169 wxString name
= item
->GetName();
171 name
= item
->GetTitle();
175 // Delete existing resource, if any.
181 bool wxResourceTable::DeleteResource(const wxString
& name
)
183 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
186 // See if any resource has this as its child; if so, delete from
187 // parent's child list.
189 wxNode
*node
= (wxNode
*) NULL
;
190 while ((node
= Next()))
192 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
193 if (parent
->GetChildren().Member(item
))
195 parent
->GetChildren().DeleteObject(item
);
207 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
211 FILE *fd
= fopen((const char*) filename
, "r");
215 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
220 return wxResourceInterpretResources(*this, db
);
223 bool wxResourceTable::ParseResourceData(const wxString
& data
)
226 if (!db
.ReadFromString(data
))
228 wxLogWarning(_("Ill-formed resource file syntax."));
232 return wxResourceInterpretResources(*this, db
);
235 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
237 // Register pre-loaded bitmap data
238 wxItemResource
*item
= new wxItemResource
;
239 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
240 item
->SetType("wxXBMData");
242 item
->SetValue1((long)bits
);
243 item
->SetValue2((long)width
);
244 item
->SetValue3((long)height
);
249 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
251 // Register pre-loaded bitmap data
252 wxItemResource
*item
= new wxItemResource
;
253 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
254 item
->SetType("wxXPMData");
256 item
->SetValue1((long)data
);
261 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
266 void wxResourceTable::ClearTable()
269 wxNode
*node
= Next();
272 wxNode
*next
= Next();
273 wxItemResource
*item
= (wxItemResource
*)node
->Data();
280 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
282 int id
= childResource
->GetId();
286 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
288 wxControl
*control
= (wxControl
*) NULL
;
289 wxString
itemType(childResource
->GetType());
295 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
296 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
300 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
301 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
304 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
306 if (childResource
->GetValue4() != "")
309 wxBitmap bitmap
= childResource
->GetBitmap();
312 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
313 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
316 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
317 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
320 // Normal, text button
321 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
322 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
324 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
325 itemType
== wxString("wxStaticBitmap"))
327 if (childResource
->GetValue4() != "")
330 wxBitmap bitmap
= childResource
->GetBitmap();
333 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
334 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
336 #if wxUSE_BITMAP_MESSAGE
338 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
339 childResource
->GetStyle(), childResource
->GetName());
344 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
345 childResource
->GetStyle(), childResource
->GetName());
348 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
350 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
351 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
353 else if (itemType
== wxString("wxCheckBox"))
355 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
356 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
358 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
361 else if (itemType
== wxString("wxGauge"))
363 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
364 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
366 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
369 #if wxUSE_RADIOBUTTON
370 else if (itemType
== wxString("wxRadioButton"))
372 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
374 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
378 else if (itemType
== wxString("wxScrollBar"))
380 control
= new wxScrollBar(parent
, id
, pos
, size
,
381 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
383 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
384 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
385 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
386 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
388 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
389 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
393 else if (itemType
== wxString("wxSlider"))
395 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
396 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
397 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
399 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
401 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
402 childResource
->GetStyle(), childResource
->GetName());
404 else if (itemType
== wxString("wxListBox"))
406 wxStringList
& stringList
= childResource
->GetStringValues();
407 wxString
*strings
= (wxString
*) NULL
;
409 if (stringList
.Number() > 0)
411 noStrings
= stringList
.Number();
412 strings
= new wxString
[noStrings
];
413 wxNode
*node
= stringList
.First();
417 strings
[i
] = (char *)node
->Data();
422 control
= new wxListBox(parent
, id
, pos
, size
,
423 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
428 else if (itemType
== wxString("wxChoice"))
430 wxStringList
& stringList
= childResource
->GetStringValues();
431 wxString
*strings
= (wxString
*) NULL
;
433 if (stringList
.Number() > 0)
435 noStrings
= stringList
.Number();
436 strings
= new wxString
[noStrings
];
437 wxNode
*node
= stringList
.First();
441 strings
[i
] = (char *)node
->Data();
446 control
= new wxChoice(parent
, id
, pos
, size
,
447 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
453 else if (itemType
== wxString("wxComboBox"))
455 wxStringList
& stringList
= childResource
->GetStringValues();
456 wxString
*strings
= (wxString
*) NULL
;
458 if (stringList
.Number() > 0)
460 noStrings
= stringList
.Number();
461 strings
= new wxString
[noStrings
];
462 wxNode
*node
= stringList
.First();
466 strings
[i
] = (char *)node
->Data();
471 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
472 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
478 else if (itemType
== wxString("wxRadioBox"))
480 wxStringList
& stringList
= childResource
->GetStringValues();
481 wxString
*strings
= (wxString
*) NULL
;
483 if (stringList
.Number() > 0)
485 noStrings
= stringList
.Number();
486 strings
= new wxString
[noStrings
];
487 wxNode
*node
= stringList
.First();
491 strings
[i
] = (char *)node
->Data();
496 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
497 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
498 childResource
->GetName());
504 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
506 // Don't set font; will be inherited from parent.
510 if (control
&& childResource
->GetFont().Ok())
511 control
->SetFont(childResource
->GetFont());
517 * Interpret database as a series of resources
520 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
522 wxNode
*node
= db
.First();
525 wxExpr
*clause
= (wxExpr
*)node
->Data();
526 wxString
functor(clause
->Functor());
528 wxItemResource
*item
= (wxItemResource
*) NULL
;
529 if (functor
== "dialog")
530 item
= wxResourceInterpretDialog(table
, clause
);
531 else if (functor
== "panel")
532 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
533 else if (functor
== "menubar")
534 item
= wxResourceInterpretMenuBar(table
, clause
);
535 else if (functor
== "menu")
536 item
= wxResourceInterpretMenu(table
, clause
);
537 else if (functor
== "string")
538 item
= wxResourceInterpretString(table
, clause
);
539 else if (functor
== "bitmap")
540 item
= wxResourceInterpretBitmap(table
, clause
);
541 else if (functor
== "icon")
542 item
= wxResourceInterpretIcon(table
, clause
);
546 // Remove any existing resource of same name
547 if (item
->GetName() != "")
548 table
.DeleteResource(item
->GetName());
549 table
.AddResource(item
);
556 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
557 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
558 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
559 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
560 "wxChoice", "wxComboBox" } ;
561 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
563 static bool wxIsValidControlClass(const wxString
& c
)
566 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
568 if ( c
== g_ValidControlClasses
[i
] )
574 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
576 wxItemResource
*dialogItem
= new wxItemResource
;
578 dialogItem
->SetType("wxPanel");
580 dialogItem
->SetType("wxDialog");
584 wxString backColourHex
= "";
585 wxString labelColourHex
= "";
586 wxString buttonColourHex
= "";
588 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
592 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
594 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
595 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
596 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
597 expr
->GetAttributeValue("style", style
);
598 expr
->GetAttributeValue("name", name
);
599 expr
->GetAttributeValue("title", title
);
600 expr
->GetAttributeValue("x", x
);
601 expr
->GetAttributeValue("y", y
);
602 expr
->GetAttributeValue("width", width
);
603 expr
->GetAttributeValue("height", height
);
604 expr
->GetAttributeValue("modal", isModal
);
605 expr
->GetAttributeValue("label_font", &labelFontExpr
);
606 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
607 expr
->GetAttributeValue("font", &fontExpr
);
608 expr
->GetAttributeValue("background_colour", backColourHex
);
609 expr
->GetAttributeValue("label_colour", labelColourHex
);
610 expr
->GetAttributeValue("button_colour", buttonColourHex
);
612 int useDialogUnits
= 0;
613 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
614 if (useDialogUnits
!= 0)
615 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
618 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
619 if (useDefaults
!= 0)
620 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
623 expr
->GetAttributeValue("id", id
);
624 dialogItem
->SetId(id
);
628 windowStyle
= wxParseWindowStyle(style
);
630 dialogItem
->SetStyle(windowStyle
);
631 dialogItem
->SetValue1(isModal
);
632 dialogItem
->SetName(name
);
633 dialogItem
->SetTitle(title
);
634 dialogItem
->SetSize(x
, y
, width
, height
);
636 if (backColourHex
!= "")
641 r
= wxHexToDec(backColourHex
.Mid(0, 2));
642 g
= wxHexToDec(backColourHex
.Mid(2, 2));
643 b
= wxHexToDec(backColourHex
.Mid(4, 2));
644 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
646 if (labelColourHex
!= "")
651 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
652 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
653 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
654 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
656 if (buttonColourHex
!= "")
661 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
662 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
663 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
664 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
668 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
669 else if (buttonFontExpr
)
670 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
671 else if (labelFontExpr
)
672 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
674 // Now parse all controls
675 wxExpr
*controlExpr
= expr
->GetFirst();
678 if (controlExpr
->Number() == 3)
680 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
681 if (controlKeyword
!= "" && controlKeyword
== "control")
683 // The value part: always a list.
684 wxExpr
*listExpr
= controlExpr
->Nth(2);
685 if (listExpr
->Type() == PrologList
)
687 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
690 dialogItem
->GetChildren().Append(controlItem
);
695 controlExpr
= controlExpr
->GetNext();
700 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
702 wxItemResource
*controlItem
= new wxItemResource
;
704 // First, find the standard features of a control definition:
705 // [optional integer/string id], control name, title, style, name, x, y, width, height
707 wxString controlType
;
712 long windowStyle
= 0;
713 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
716 wxExpr
*expr1
= expr
->Nth(0);
718 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
720 if ( wxIsValidControlClass(expr1
->StringValue()) )
723 controlType
= expr1
->StringValue();
727 wxString
str(expr1
->StringValue());
728 id
= wxResourceGetIdentifier(str
, &table
);
731 wxLogWarning(_("Could not resolve control class or id '%s'. "
732 "Use (non-zero) integer instead\n or provide #define "
733 "(see manual for caveats)"),
734 (const char*) expr1
->StringValue());
736 return (wxItemResource
*) NULL
;
740 // Success - we have an id, so the 2nd element must be the control class.
741 controlType
= expr
->Nth(1)->StringValue();
746 else if (expr1
->Type() == PrologInteger
)
748 id
= (int)expr1
->IntegerValue();
749 // Success - we have an id, so the 2nd element must be the control class.
750 controlType
= expr
->Nth(1)->StringValue();
754 expr1
= expr
->Nth(count
);
757 title
= expr1
->StringValue();
759 expr1
= expr
->Nth(count
);
763 style
= expr1
->StringValue();
764 windowStyle
= wxParseWindowStyle(style
);
767 expr1
= expr
->Nth(count
);
770 name
= expr1
->StringValue();
772 expr1
= expr
->Nth(count
);
775 x
= (int)expr1
->IntegerValue();
777 expr1
= expr
->Nth(count
);
780 y
= (int)expr1
->IntegerValue();
782 expr1
= expr
->Nth(count
);
785 width
= (int)expr1
->IntegerValue();
787 expr1
= expr
->Nth(count
);
790 height
= (int)expr1
->IntegerValue();
792 controlItem
->SetStyle(windowStyle
);
793 controlItem
->SetName(name
);
794 controlItem
->SetTitle(title
);
795 controlItem
->SetSize(x
, y
, width
, height
);
796 controlItem
->SetType(controlType
);
797 controlItem
->SetId(id
);
799 if (controlType
== "wxButton")
801 // Check for bitmap resource name
802 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
804 wxString
str(expr
->Nth(count
)->StringValue());
805 controlItem
->SetValue4(str
);
807 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
808 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
811 else if (controlType
== "wxCheckBox")
813 // Check for default value
814 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
816 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
818 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
819 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
822 #if wxUSE_RADIOBUTTON
823 else if (controlType
== "wxRadioButton")
825 // Check for default value
826 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
828 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
830 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
831 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
835 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
837 // Check for default value
838 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
840 wxString
str(expr
->Nth(count
)->StringValue());
841 controlItem
->SetValue4(str
);
844 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
846 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
847 // Do nothing - no label font any more
849 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
850 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
854 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
856 // Check for bitmap resource name
857 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
859 wxString
str(expr
->Nth(count
)->StringValue());
860 controlItem
->SetValue4(str
);
862 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
863 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
866 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
868 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
869 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
871 else if (controlType
== "wxGauge")
873 // Check for default value
874 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
876 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
880 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
882 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
885 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
887 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
891 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
892 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
897 else if (controlType
== "wxSlider")
899 // Check for default value
900 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
902 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
906 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
908 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
912 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
914 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
917 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
919 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
923 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
924 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
930 else if (controlType
== "wxScrollBar")
933 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
935 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
939 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
941 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
945 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
947 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
951 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
952 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
957 else if (controlType
== "wxListBox")
959 wxExpr
*valueList
= (wxExpr
*) NULL
;
961 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
963 wxStringList stringList
;
964 wxExpr
*stringExpr
= valueList
->GetFirst();
967 stringList
.Add(stringExpr
->StringValue());
968 stringExpr
= stringExpr
->GetNext();
970 controlItem
->SetStringValues(stringList
);
972 // This is now obsolete: it's in the window style.
973 // Check for wxSINGLE/wxMULTIPLE
974 wxExpr
*mult
= (wxExpr
*) NULL
;
976 controlItem->SetValue1(wxLB_SINGLE);
978 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
981 wxString m(mult->StringValue());
982 if (m == "wxLB_MULTIPLE")
983 controlItem->SetValue1(wxLB_MULTIPLE);
984 else if (m == "wxLB_EXTENDED")
985 controlItem->SetValue1(wxLB_EXTENDED);
990 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
992 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
994 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
995 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
999 else if (controlType
== "wxChoice")
1001 wxExpr
*valueList
= (wxExpr
*) NULL
;
1002 // Check for default value list
1003 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1005 wxStringList stringList
;
1006 wxExpr
*stringExpr
= valueList
->GetFirst();
1009 stringList
.Add(stringExpr
->StringValue());
1010 stringExpr
= stringExpr
->GetNext();
1012 controlItem
->SetStringValues(stringList
);
1016 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1018 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1021 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1022 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1027 else if (controlType
== "wxComboBox")
1029 wxExpr
*textValue
= expr
->Nth(count
);
1030 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1032 wxString
str(textValue
->StringValue());
1033 controlItem
->SetValue4(str
);
1037 wxExpr
*valueList
= (wxExpr
*) NULL
;
1038 // Check for default value list
1039 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1041 wxStringList stringList
;
1042 wxExpr
*stringExpr
= valueList
->GetFirst();
1045 stringList
.Add(stringExpr
->StringValue());
1046 stringExpr
= stringExpr
->GetNext();
1048 controlItem
->SetStringValues(stringList
);
1052 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1054 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1057 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1058 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1065 else if (controlType
== "wxRadioBox")
1067 wxExpr
*valueList
= (wxExpr
*) NULL
;
1068 // Check for default value list
1069 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1071 wxStringList stringList
;
1072 wxExpr
*stringExpr
= valueList
->GetFirst();
1075 stringList
.Add(stringExpr
->StringValue());
1076 stringExpr
= stringExpr
->GetNext();
1078 controlItem
->SetStringValues(stringList
);
1081 // majorDim (number of rows or cols)
1082 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1084 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1088 controlItem
->SetValue1(0);
1090 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1092 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1095 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1096 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1104 return (wxItemResource
*) NULL
;
1109 // Forward declaration
1110 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1113 * Interpet a menu item
1116 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1118 wxItemResource
*item
= new wxItemResource
;
1120 wxExpr
*labelExpr
= expr
->Nth(0);
1121 wxExpr
*idExpr
= expr
->Nth(1);
1122 wxExpr
*helpExpr
= expr
->Nth(2);
1123 wxExpr
*checkableExpr
= expr
->Nth(3);
1125 // Further keywords/attributes to follow sometime...
1126 if (expr
->Number() == 0)
1128 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1129 item
->SetType("wxMenuSeparator");
1134 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1135 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1138 wxString
str(labelExpr
->StringValue());
1139 item
->SetTitle(str
);
1144 // If a string or word, must look up in identifier table.
1145 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1147 wxString
str(idExpr
->StringValue());
1148 id
= wxResourceGetIdentifier(str
, &table
);
1151 wxLogWarning(_("Could not resolve menu id '%s'. "
1152 "Use (non-zero) integer instead\n"
1153 "or provide #define (see manual for caveats)"),
1154 (const char*) idExpr
->StringValue());
1157 else if (idExpr
->Type() == PrologInteger
)
1158 id
= (int)idExpr
->IntegerValue();
1159 item
->SetValue1(id
);
1163 wxString
str(helpExpr
->StringValue());
1164 item
->SetValue4(str
);
1167 item
->SetValue2(checkableExpr
->IntegerValue());
1169 // Find the first expression that's a list, for submenu
1170 wxExpr
*subMenuExpr
= expr
->GetFirst();
1171 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1172 subMenuExpr
= subMenuExpr
->GetNext();
1176 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1177 item
->GetChildren().Append(child
);
1178 subMenuExpr
= subMenuExpr
->GetNext();
1185 * Interpret a nested list as a menu
1188 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1190 wxItemResource *menu = new wxItemResource;
1191 // menu->SetType(wxTYPE_MENU);
1192 menu->SetType("wxMenu");
1193 wxExpr *element = expr->GetFirst();
1196 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1198 menu->GetChildren().Append(item);
1199 element = element->GetNext();
1205 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1207 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1208 expr
->GetAttributeValue("menu", &listExpr
);
1210 return (wxItemResource
*) NULL
;
1212 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1215 return (wxItemResource
*) NULL
;
1218 if (expr
->GetAttributeValue("name", name
))
1220 menuResource
->SetName(name
);
1223 return menuResource
;
1226 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1228 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1229 expr
->GetAttributeValue("menu", &listExpr
);
1231 return (wxItemResource
*) NULL
;
1233 wxItemResource
*resource
= new wxItemResource
;
1234 resource
->SetType("wxMenu");
1235 // resource->SetType(wxTYPE_MENU);
1237 wxExpr
*element
= listExpr
->GetFirst();
1240 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1241 resource
->GetChildren().Append(menuResource
);
1242 element
= element
->GetNext();
1246 if (expr
->GetAttributeValue("name", name
))
1248 resource
->SetName(name
);
1254 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1256 return (wxItemResource
*) NULL
;
1259 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1261 wxItemResource
*bitmapItem
= new wxItemResource
;
1262 // bitmapItem->SetType(wxTYPE_BITMAP);
1263 bitmapItem
->SetType("wxBitmap");
1265 if (expr
->GetAttributeValue("name", name
))
1267 bitmapItem
->SetName(name
);
1269 // Now parse all bitmap specifications
1270 wxExpr
*bitmapExpr
= expr
->GetFirst();
1273 if (bitmapExpr
->Number() == 3)
1275 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1276 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1278 // The value part: always a list.
1279 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1280 if (listExpr
->Type() == PrologList
)
1282 wxItemResource
*bitmapSpec
= new wxItemResource
;
1283 // bitmapSpec->SetType(wxTYPE_BITMAP);
1284 bitmapSpec
->SetType("wxBitmap");
1286 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1287 // where everything after 'filename' is optional.
1288 wxExpr
*nameExpr
= listExpr
->Nth(0);
1289 wxExpr
*typeExpr
= listExpr
->Nth(1);
1290 wxExpr
*platformExpr
= listExpr
->Nth(2);
1291 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1292 wxExpr
*xresExpr
= listExpr
->Nth(4);
1293 wxExpr
*yresExpr
= listExpr
->Nth(5);
1294 if (nameExpr
&& nameExpr
->StringValue())
1296 bitmapSpec
->SetName(nameExpr
->StringValue());
1298 if (typeExpr
&& typeExpr
->StringValue())
1300 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1303 bitmapSpec
->SetValue1(0);
1305 if (platformExpr
&& platformExpr
->StringValue())
1307 wxString
plat(platformExpr
->StringValue());
1308 if (plat
== "windows" || plat
== "WINDOWS")
1309 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1310 else if (plat
== "x" || plat
== "X")
1311 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1312 else if (plat
== "mac" || plat
== "MAC")
1313 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1315 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1318 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1321 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1325 xres
= (int)xresExpr
->IntegerValue();
1327 yres
= (int)yresExpr
->IntegerValue();
1328 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1330 bitmapItem
->GetChildren().Append(bitmapSpec
);
1334 bitmapExpr
= bitmapExpr
->GetNext();
1340 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1342 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1345 // item->SetType(wxTYPE_ICON);
1346 item
->SetType("wxIcon");
1350 return (wxItemResource
*) NULL
;
1353 // Interpret list expression as a font
1354 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1356 if (expr
->Type() != PrologList
)
1360 int family
= wxSWISS
;
1361 int style
= wxNORMAL
;
1362 int weight
= wxNORMAL
;
1364 wxString
faceName("");
1366 wxExpr
*pointExpr
= expr
->Nth(0);
1367 wxExpr
*familyExpr
= expr
->Nth(1);
1368 wxExpr
*styleExpr
= expr
->Nth(2);
1369 wxExpr
*weightExpr
= expr
->Nth(3);
1370 wxExpr
*underlineExpr
= expr
->Nth(4);
1371 wxExpr
*faceNameExpr
= expr
->Nth(5);
1373 point
= (int)pointExpr
->IntegerValue();
1378 str
= familyExpr
->StringValue();
1379 family
= (int)wxParseWindowStyle(str
);
1383 str
= styleExpr
->StringValue();
1384 style
= (int)wxParseWindowStyle(str
);
1388 str
= weightExpr
->StringValue();
1389 weight
= (int)wxParseWindowStyle(str
);
1392 underline
= (int)underlineExpr
->IntegerValue();
1394 faceName
= faceNameExpr
->StringValue();
1396 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1401 * (Re)allocate buffer for reading in from resource file
1404 bool wxReallocateResourceBuffer()
1406 if (!wxResourceBuffer
)
1408 wxResourceBufferSize
= 1000;
1409 wxResourceBuffer
= new char[wxResourceBufferSize
];
1412 if (wxResourceBuffer
)
1414 long newSize
= wxResourceBufferSize
+ 1000;
1415 char *tmp
= new char[(int)newSize
];
1416 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1417 delete[] wxResourceBuffer
;
1418 wxResourceBuffer
= tmp
;
1419 wxResourceBufferSize
= newSize
;
1424 static bool wxEatWhiteSpace(FILE *fd
)
1427 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1434 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1436 // Check for comment
1442 bool finished
= FALSE
;
1450 int newCh
= getc(fd
);
1465 return wxEatWhiteSpace(fd
);
1468 bool wxGetResourceToken(FILE *fd
)
1470 if (!wxResourceBuffer
)
1471 wxReallocateResourceBuffer();
1472 wxResourceBuffer
[0] = 0;
1473 wxEatWhiteSpace(fd
);
1479 wxResourceBufferCount
= 0;
1486 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1489 // Escaped characters
1490 else if (ch
== '\\')
1492 int newCh
= getc(fd
);
1495 else if (newCh
== 10)
1503 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1504 wxReallocateResourceBuffer();
1505 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1506 wxResourceBufferCount
++;
1509 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1513 wxResourceBufferCount
= 0;
1515 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1517 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1518 wxReallocateResourceBuffer();
1519 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1520 wxResourceBufferCount
++;
1524 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1532 * Files are in form:
1533 static char *name = "....";
1534 with possible comments.
1537 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1540 table
= wxDefaultResourceTable
;
1542 // static or #define
1543 if (!wxGetResourceToken(fd
))
1549 if (strcmp(wxResourceBuffer
, "#define") == 0)
1551 wxGetResourceToken(fd
);
1552 char *name
= copystring(wxResourceBuffer
);
1553 wxGetResourceToken(fd
);
1554 char *value
= copystring(wxResourceBuffer
);
1555 if (isalpha(value
[0]))
1557 int val
= (int)atol(value
);
1558 wxResourceAddIdentifier(name
, val
, table
);
1562 wxLogWarning(_("#define %s must be an integer."), name
);
1572 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1574 wxGetResourceToken(fd
);
1575 char *name
= copystring(wxResourceBuffer
);
1576 char *actualName
= name
;
1578 actualName
= name
+ 1;
1579 int len
= strlen(name
);
1580 if ((len
> 0) && (name
[len
-1] == '"'))
1582 if (!wxResourceParseIncludeFile(actualName
, table
))
1584 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1589 else if (strcmp(wxResourceBuffer
, "static") != 0)
1592 strcpy(buf
, _("Found "));
1593 strncat(buf
, wxResourceBuffer
, 30);
1594 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1600 if (!wxGetResourceToken(fd
))
1602 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1607 if (strcmp(wxResourceBuffer
, "char") != 0)
1609 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1614 if (!wxGetResourceToken(fd
))
1616 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1621 if (wxResourceBuffer
[0] != '*')
1623 wxLogWarning(_("Expected '*' whilst parsing resource."));
1627 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1630 if (!wxGetResourceToken(fd
))
1632 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1637 if (strcmp(wxResourceBuffer
, "=") != 0)
1639 wxLogWarning(_("Expected '=' whilst parsing resource."));
1644 if (!wxGetResourceToken(fd
))
1646 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1652 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1654 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1659 if (!wxGetResourceToken(fd
))
1667 * Parses string window style into integer window style
1671 * Style flag parsing, e.g.
1672 * "wxSYSTEM_MENU | wxBORDER" -> integer
1675 char* wxResourceParseWord(char*s
, int *i
)
1678 return (char*) NULL
;
1680 static char buf
[150];
1681 int len
= strlen(s
);
1684 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1692 // Eat whitespace and conjunction characters
1693 while ((ii
< len
) &&
1694 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1700 return (char*) NULL
;
1705 struct wxResourceBitListStruct
1711 static wxResourceBitListStruct wxResourceBitListTable
[] =
1714 { "wxSINGLE", wxLB_SINGLE
},
1715 { "wxMULTIPLE", wxLB_MULTIPLE
},
1716 { "wxEXTENDED", wxLB_EXTENDED
},
1717 { "wxLB_SINGLE", wxLB_SINGLE
},
1718 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1719 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1720 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1721 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1722 { "wxLB_SORT", wxLB_SORT
},
1723 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1724 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1727 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1728 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1729 { "wxCB_READONLY", wxCB_READONLY
},
1730 { "wxCB_SORT", wxCB_SORT
},
1733 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1734 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1735 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1738 { "wxPASSWORD", wxPASSWORD
},
1739 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1740 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1741 { "wxTE_READONLY", wxTE_READONLY
},
1742 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1743 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1745 /* wxRadioBox/wxRadioButton */
1746 { "wxRB_GROUP", wxRB_GROUP
},
1747 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1748 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1751 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1752 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1753 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1754 { "wxSL_LABELS", wxSL_LABELS
},
1755 { "wxSL_LEFT", wxSL_LEFT
},
1756 { "wxSL_TOP", wxSL_TOP
},
1757 { "wxSL_RIGHT", wxSL_RIGHT
},
1758 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1759 { "wxSL_BOTH", wxSL_BOTH
},
1760 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1763 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1764 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1767 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1768 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1771 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1772 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1773 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1776 { "wxLC_ICON", wxLC_ICON
},
1777 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1778 { "wxLC_LIST", wxLC_LIST
},
1779 { "wxLC_REPORT", wxLC_REPORT
},
1780 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1781 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1782 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1783 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1784 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1785 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1786 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1787 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1788 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1789 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1792 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1793 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1794 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1795 { "wxSP_WRAP", wxSP_WRAP
},
1798 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1799 { "wxSP_3D", wxSP_3D
},
1800 { "wxSP_BORDER", wxSP_BORDER
},
1803 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1804 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1805 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1806 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1809 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1812 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1813 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1814 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1815 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1816 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1817 { "wxCOLOURED", wxCOLOURED
},
1820 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1821 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1822 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1823 { "wxTB_FLAT", wxTB_FLAT
},
1826 { "wxVSCROLL", wxVSCROLL
},
1827 { "wxHSCROLL", wxHSCROLL
},
1828 { "wxCAPTION", wxCAPTION
},
1829 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1830 { "wxICONIZE", wxICONIZE
},
1831 { "wxMINIMIZE", wxICONIZE
},
1832 { "wxMAXIMIZE", wxMAXIMIZE
},
1834 { "wxMDI_PARENT", 0},
1835 { "wxMDI_CHILD", 0},
1836 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1837 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1838 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1839 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1840 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1841 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1842 { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE
},
1843 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE
},
1844 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1845 { "wxBORDER", wxBORDER
},
1846 { "wxRETAINED", wxRETAINED
},
1847 { "wxNATIVE_IMPL", 0},
1848 { "wxEXTENDED_IMPL", 0},
1849 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1850 // { "wxFLAT", wxFLAT},
1851 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1852 { "wxFIXED_LENGTH", 0},
1853 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1854 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1855 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1856 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1857 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1858 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1859 { "wxNO_BORDER", wxNO_BORDER
},
1860 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1862 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1863 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1865 // Text font families
1866 { "wxDEFAULT", wxDEFAULT
},
1867 { "wxDECORATIVE", wxDECORATIVE
},
1868 { "wxROMAN", wxROMAN
},
1869 { "wxSCRIPT", wxSCRIPT
},
1870 { "wxSWISS", wxSWISS
},
1871 { "wxMODERN", wxMODERN
},
1872 { "wxTELETYPE", wxTELETYPE
},
1873 { "wxVARIABLE", wxVARIABLE
},
1874 { "wxFIXED", wxFIXED
},
1875 { "wxNORMAL", wxNORMAL
},
1876 { "wxLIGHT", wxLIGHT
},
1877 { "wxBOLD", wxBOLD
},
1878 { "wxITALIC", wxITALIC
},
1879 { "wxSLANT", wxSLANT
},
1880 { "wxSOLID", wxSOLID
},
1882 { "wxLONG_DASH", wxLONG_DASH
},
1883 { "wxSHORT_DASH", wxSHORT_DASH
},
1884 { "wxDOT_DASH", wxDOT_DASH
},
1885 { "wxUSER_DASH", wxUSER_DASH
},
1886 { "wxTRANSPARENT", wxTRANSPARENT
},
1887 { "wxSTIPPLE", wxSTIPPLE
},
1888 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1889 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1890 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1891 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1892 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1893 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1894 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1895 { "wxJOIN_MITER", wxJOIN_MITER
},
1896 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1897 { "wxCAP_ROUND", wxCAP_ROUND
},
1898 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1899 { "wxCAP_BUTT", wxCAP_BUTT
},
1902 { "wxCLEAR", wxCLEAR
},
1904 { "wxINVERT", wxINVERT
},
1905 { "wxOR_REVERSE", wxOR_REVERSE
},
1906 { "wxAND_REVERSE", wxAND_REVERSE
},
1907 { "wxCOPY", wxCOPY
},
1909 { "wxAND_INVERT", wxAND_INVERT
},
1910 { "wxNO_OP", wxNO_OP
},
1912 { "wxEQUIV", wxEQUIV
},
1913 { "wxSRC_INVERT", wxSRC_INVERT
},
1914 { "wxOR_INVERT", wxOR_INVERT
},
1915 { "wxNAND", wxNAND
},
1919 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1920 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1921 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1922 { "wxWINDING_RULE", wxWINDING_RULE
},
1923 { "wxHORIZONTAL", wxHORIZONTAL
},
1924 { "wxVERTICAL", wxVERTICAL
},
1925 { "wxBOTH", wxBOTH
},
1926 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1928 { "wxYES_NO", wxYES_NO
},
1929 { "wxCANCEL", wxCANCEL
},
1932 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1933 { "wxICON_HAND", wxICON_HAND
},
1934 { "wxICON_QUESTION", wxICON_QUESTION
},
1935 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1936 { "wxICON_STOP", wxICON_STOP
},
1937 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1938 { "wxICON_MASK", wxICON_MASK
},
1939 { "wxCENTRE", wxCENTRE
},
1940 { "wxCENTER", wxCENTRE
},
1941 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1942 { "wxVERTICAL_LABEL", 0},
1943 { "wxHORIZONTAL_LABEL", 0},
1945 // Bitmap types (not strictly styles)
1946 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1947 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1948 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1949 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1950 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1951 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1952 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1953 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1954 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1955 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1956 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1957 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1958 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1959 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1962 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
1964 long wxParseWindowStyle(const wxString
& bitListString
)
1969 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
1973 for (j
= 0; j
< wxResourceBitListCount
; j
++)
1974 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
1976 bitList
|= wxResourceBitListTable
[j
].bits
;
1982 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
1990 * Load a bitmap from a wxWindows resource, choosing an optimum
1991 * depth and appropriate type.
1994 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
1997 table
= wxDefaultResourceTable
;
1999 wxItemResource
*item
= table
->FindResource(resource
);
2002 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2004 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
2005 return wxNullBitmap
;
2007 int thisDepth
= wxDisplayDepth();
2008 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2010 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2012 // Try to find optimum bitmap for this platform/colour depth
2013 wxNode
*node
= item
->GetChildren().First();
2016 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2017 int platform
= (int)child
->GetValue2();
2018 int noColours
= (int)child
->GetValue3();
2020 char *name = child->GetName();
2021 int bitmapType = (int)child->GetValue1();
2022 int xRes = child->GetWidth();
2023 int yRes = child->GetHeight();
2028 case RESOURCE_PLATFORM_ANY
:
2030 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2031 optResource
= child
;
2034 // Maximise the number of colours.
2035 // If noColours is zero (unspecified), then assume this
2036 // is the right one.
2037 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2038 optResource
= child
;
2043 case RESOURCE_PLATFORM_WINDOWS
:
2045 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2046 optResource
= child
;
2049 // Maximise the number of colours
2050 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2051 optResource
= child
;
2057 case RESOURCE_PLATFORM_X
:
2059 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2060 optResource
= child
;
2063 // Maximise the number of colours
2064 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2065 optResource
= child
;
2071 case RESOURCE_PLATFORM_MAC
:
2073 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2074 optResource
= child
;
2077 // Maximise the number of colours
2078 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2079 optResource
= child
;
2087 node
= node
->Next();
2089 // If no matching resource, fail.
2091 return wxNullBitmap
;
2093 wxString name
= optResource
->GetName();
2094 int bitmapType
= (int)optResource
->GetValue1();
2097 case wxBITMAP_TYPE_XBM_DATA
:
2100 wxItemResource
*item
= table
->FindResource(name
);
2103 wxLogWarning(_("Failed to find XBM resource %s.\n"
2104 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2105 return wxNullBitmap
;
2107 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2109 wxLogWarning(_("No XBM facility available!"));
2113 case wxBITMAP_TYPE_XPM_DATA
:
2115 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2116 wxItemResource
*item
= table
->FindResource(name
);
2119 wxLogWarning(_("Failed to find XPM resource %s.\n"
2120 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2121 return wxNullBitmap
;
2123 return wxBitmap(item
->GetValue1());
2125 wxLogWarning(_("No XPM facility available!"));
2131 return wxBitmap(name
, bitmapType
);
2135 return wxNullBitmap
;
2139 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2140 return wxNullBitmap
;
2145 * Load an icon from a wxWindows resource, choosing an optimum
2146 * depth and appropriate type.
2149 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2152 table
= wxDefaultResourceTable
;
2154 wxItemResource
*item
= table
->FindResource(resource
);
2157 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2159 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2162 int thisDepth
= wxDisplayDepth();
2163 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2165 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2167 // Try to find optimum icon for this platform/colour depth
2168 wxNode
*node
= item
->GetChildren().First();
2171 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2172 int platform
= (int)child
->GetValue2();
2173 int noColours
= (int)child
->GetValue3();
2175 char *name = child->GetName();
2176 int bitmapType = (int)child->GetValue1();
2177 int xRes = child->GetWidth();
2178 int yRes = child->GetHeight();
2183 case RESOURCE_PLATFORM_ANY
:
2185 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2186 optResource
= child
;
2189 // Maximise the number of colours.
2190 // If noColours is zero (unspecified), then assume this
2191 // is the right one.
2192 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2193 optResource
= child
;
2198 case RESOURCE_PLATFORM_WINDOWS
:
2200 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2201 optResource
= child
;
2204 // Maximise the number of colours
2205 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2206 optResource
= child
;
2212 case RESOURCE_PLATFORM_X
:
2214 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2215 optResource
= child
;
2218 // Maximise the number of colours
2219 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2220 optResource
= child
;
2226 case RESOURCE_PLATFORM_MAC
:
2228 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2229 optResource
= child
;
2232 // Maximise the number of colours
2233 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2234 optResource
= child
;
2242 node
= node
->Next();
2244 // If no matching resource, fail.
2248 wxString name
= optResource
->GetName();
2249 int bitmapType
= (int)optResource
->GetValue1();
2252 case wxBITMAP_TYPE_XBM_DATA
:
2255 wxItemResource
*item
= table
->FindResource(name
);
2258 wxLogWarning(_("Failed to find XBM resource %s.\n"
2259 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2262 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2264 wxLogWarning(_("No XBM facility available!"));
2268 case wxBITMAP_TYPE_XPM_DATA
:
2270 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2272 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2273 wxItemResource *item = table->FindResource(name);
2277 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2281 return wxIcon((char **)item->GetValue1());
2283 wxLogWarning(_("No XPM facility available!"));
2286 wxLogWarning(_("No XPM icon facility available!"));
2292 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2294 return wxIcon(name
, bitmapType
);
2303 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2308 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2310 wxMenu
*menu
= new wxMenu
;
2311 wxNode
*node
= item
->GetChildren().First();
2314 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2315 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2316 menu
->AppendSeparator();
2317 else if (child
->GetChildren().Number() > 0)
2319 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2321 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2325 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2327 node
= node
->Next();
2332 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2335 table
= wxDefaultResourceTable
;
2337 wxItemResource
*menuResource
= table
->FindResource(resource
);
2338 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2341 menuBar
= new wxMenuBar
;
2342 wxNode
*node
= menuResource
->GetChildren().First();
2345 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2346 wxMenu
*menu
= wxResourceCreateMenu(child
);
2348 menuBar
->Append(menu
, child
->GetTitle());
2349 node
= node
->Next();
2353 return (wxMenuBar
*) NULL
;
2356 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2359 table
= wxDefaultResourceTable
;
2361 wxItemResource
*menuResource
= table
->FindResource(resource
);
2362 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2363 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2364 return wxResourceCreateMenu(menuResource
);
2365 return (wxMenu
*) NULL
;
2368 // Global equivalents (so don't have to refer to default table explicitly)
2369 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2372 table
= wxDefaultResourceTable
;
2374 return table
->ParseResourceData(resource
);
2377 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2380 table
= wxDefaultResourceTable
;
2382 return table
->ParseResourceFile(filename
);
2385 // Register XBM/XPM data
2386 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2389 table
= wxDefaultResourceTable
;
2391 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2394 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2397 table
= wxDefaultResourceTable
;
2399 return table
->RegisterResourceBitmapData(name
, data
);
2402 void wxResourceClear(wxResourceTable
*table
)
2405 table
= wxDefaultResourceTable
;
2407 table
->ClearTable();
2414 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2417 table
= wxDefaultResourceTable
;
2419 table
->identifiers
.Put(name
, (wxObject
*)value
);
2423 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2426 table
= wxDefaultResourceTable
;
2428 return (int)table
->identifiers
.Get(name
);
2432 * Parse #include file for #defines (only)
2435 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2438 table
= wxDefaultResourceTable
;
2440 FILE *fd
= fopen(f
, "r");
2445 while (wxGetResourceToken(fd
))
2447 if (strcmp(wxResourceBuffer
, "#define") == 0)
2449 wxGetResourceToken(fd
);
2450 char *name
= copystring(wxResourceBuffer
);
2451 wxGetResourceToken(fd
);
2452 char *value
= copystring(wxResourceBuffer
);
2453 if (isdigit(value
[0]))
2455 int val
= (int)atol(value
);
2456 wxResourceAddIdentifier(name
, val
, table
);
2467 * Reading strings as if they were .wxr files
2470 static int getc_string(char *s
)
2472 int ch
= s
[wxResourceStringPtr
];
2477 wxResourceStringPtr
++;
2482 static int ungetc_string()
2484 wxResourceStringPtr
--;
2488 bool wxEatWhiteSpaceString(char *s
)
2490 int ch
= getc_string(s
);
2494 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2501 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2502 ch
= getc_string(s
);
2503 // Check for comment
2506 ch
= getc_string(s
);
2509 bool finished
= FALSE
;
2512 ch
= getc_string(s
);
2517 int newCh
= getc_string(s
);
2532 return wxEatWhiteSpaceString(s
);
2535 bool wxGetResourceTokenString(char *s
)
2537 if (!wxResourceBuffer
)
2538 wxReallocateResourceBuffer();
2539 wxResourceBuffer
[0] = 0;
2540 wxEatWhiteSpaceString(s
);
2542 int ch
= getc_string(s
);
2546 wxResourceBufferCount
= 0;
2547 ch
= getc_string(s
);
2553 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2556 // Escaped characters
2557 else if (ch
== '\\')
2559 int newCh
= getc_string(s
);
2562 else if (newCh
== 10)
2570 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2571 wxReallocateResourceBuffer();
2572 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2573 wxResourceBufferCount
++;
2574 ch
= getc_string(s
);
2576 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2580 wxResourceBufferCount
= 0;
2582 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2584 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2585 wxReallocateResourceBuffer();
2586 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2587 wxResourceBufferCount
++;
2589 ch
= getc_string(s
);
2591 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2599 * Files are in form:
2600 static char *name = "....";
2601 with possible comments.
2604 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2607 table
= wxDefaultResourceTable
;
2609 // static or #define
2610 if (!wxGetResourceTokenString(s
))
2616 if (strcmp(wxResourceBuffer
, "#define") == 0)
2618 wxGetResourceTokenString(s
);
2619 char *name
= copystring(wxResourceBuffer
);
2620 wxGetResourceTokenString(s
);
2621 char *value
= copystring(wxResourceBuffer
);
2622 if (isalpha(value
[0]))
2624 int val
= (int)atol(value
);
2625 wxResourceAddIdentifier(name
, val
, table
);
2629 wxLogWarning(_("#define %s must be an integer."), name
);
2640 else if (strcmp(wxResourceBuffer, "#include") == 0)
2642 wxGetResourceTokenString(s);
2643 char *name = copystring(wxResourceBuffer);
2644 char *actualName = name;
2646 actualName = name + 1;
2647 int len = strlen(name);
2648 if ((len > 0) && (name[len-1] == '"'))
2650 if (!wxResourceParseIncludeFile(actualName, table))
2653 sprintf(buf, _("Could not find resource include file %s."), actualName);
2660 else if (strcmp(wxResourceBuffer
, "static") != 0)
2663 strcpy(buf
, _("Found "));
2664 strncat(buf
, wxResourceBuffer
, 30);
2665 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2671 if (!wxGetResourceTokenString(s
))
2673 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2678 if (strcmp(wxResourceBuffer
, "char") != 0)
2680 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2685 if (!wxGetResourceTokenString(s
))
2687 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2692 if (wxResourceBuffer
[0] != '*')
2694 wxLogWarning(_("Expected '*' whilst parsing resource."));
2698 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2701 if (!wxGetResourceTokenString(s
))
2703 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2708 if (strcmp(wxResourceBuffer
, "=") != 0)
2710 wxLogWarning(_("Expected '=' whilst parsing resource."));
2715 if (!wxGetResourceTokenString(s
))
2717 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2723 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2725 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2730 if (!wxGetResourceTokenString(s
))
2737 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2740 table
= wxDefaultResourceTable
;
2745 // Turn backslashes into spaces
2748 int len
= strlen(s
);
2750 for (i
= 0; i
< len
; i
++)
2751 if (s
[i
] == 92 && s
[i
+1] == 13)
2759 wxResourceStringPtr
= 0;
2762 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2766 return wxResourceInterpretResources(*table
, db
);
2770 * resource loading facility
2773 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2776 table
= wxDefaultResourceTable
;
2778 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2779 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2780 if (!resource
|| !resource
->GetType() ||
2781 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2784 wxString
title(resource
->GetTitle());
2785 long theWindowStyle
= resource
->GetStyle();
2786 bool isModal
= (resource
->GetValue1() != 0);
2787 int x
= resource
->GetX();
2788 int y
= resource
->GetY();
2789 int width
= resource
->GetWidth();
2790 int height
= resource
->GetHeight();
2791 wxString name
= resource
->GetName();
2793 if (IsKindOf(CLASSINFO(wxDialog
)))
2795 wxDialog
*dialogBox
= (wxDialog
*)this;
2796 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2797 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2800 // Only reset the client size if we know we're not going to do it again below.
2801 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2802 dialogBox
->SetClientSize(width
, height
);
2804 else if (IsKindOf(CLASSINFO(wxPanel
)))
2806 wxPanel
* panel
= (wxPanel
*)this;
2807 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2812 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2816 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2818 // No need to do this since it's done in wxPanel or wxDialog constructor.
2819 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2823 if (resource
->GetFont().Ok())
2824 SetFont(resource
->GetFont());
2825 if (resource
->GetBackgroundColour().Ok())
2826 SetBackgroundColour(resource
->GetBackgroundColour());
2829 // Should have some kind of font at this point
2830 if (!GetFont().Ok())
2831 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2832 if (!GetBackgroundColour().Ok())
2833 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2835 // Only when we've created the window and set the font can we set the correct size,
2836 // if based on dialog units.
2837 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2839 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2840 SetClientSize(sz
.x
, sz
.y
);
2842 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2846 // Now create children
2847 wxNode
*node
= resource
->GetChildren().First();
2850 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2852 (void) CreateItem(childResource
, resource
, table
);
2854 node
= node
->Next();
2859 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2862 table
= wxDefaultResourceTable
;
2863 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2867 #pragma warning(default:4706) // assignment within conditional expression
2870 #endif // wxUSE_WX_RESOURCES