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());
382 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
383 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
384 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
385 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
388 else if (itemType
== wxString("wxSlider"))
390 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
391 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
392 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
394 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
396 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
397 childResource
->GetStyle(), childResource
->GetName());
399 else if (itemType
== wxString("wxListBox"))
401 wxStringList
& stringList
= childResource
->GetStringValues();
402 wxString
*strings
= (wxString
*) NULL
;
404 if (stringList
.Number() > 0)
406 noStrings
= stringList
.Number();
407 strings
= new wxString
[noStrings
];
408 wxNode
*node
= stringList
.First();
412 strings
[i
] = (char *)node
->Data();
417 control
= new wxListBox(parent
, id
, pos
, size
,
418 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
423 else if (itemType
== wxString("wxChoice"))
425 wxStringList
& stringList
= childResource
->GetStringValues();
426 wxString
*strings
= (wxString
*) NULL
;
428 if (stringList
.Number() > 0)
430 noStrings
= stringList
.Number();
431 strings
= new wxString
[noStrings
];
432 wxNode
*node
= stringList
.First();
436 strings
[i
] = (char *)node
->Data();
441 control
= new wxChoice(parent
, id
, pos
, size
,
442 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
448 else if (itemType
== wxString("wxComboBox"))
450 wxStringList
& stringList
= childResource
->GetStringValues();
451 wxString
*strings
= (wxString
*) NULL
;
453 if (stringList
.Number() > 0)
455 noStrings
= stringList
.Number();
456 strings
= new wxString
[noStrings
];
457 wxNode
*node
= stringList
.First();
461 strings
[i
] = (char *)node
->Data();
466 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
467 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
473 else if (itemType
== wxString("wxRadioBox"))
475 wxStringList
& stringList
= childResource
->GetStringValues();
476 wxString
*strings
= (wxString
*) NULL
;
478 if (stringList
.Number() > 0)
480 noStrings
= stringList
.Number();
481 strings
= new wxString
[noStrings
];
482 wxNode
*node
= stringList
.First();
486 strings
[i
] = (char *)node
->Data();
491 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
492 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
493 childResource
->GetName());
499 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
501 // Don't set font; will be inherited from parent.
505 if (control
&& childResource
->GetFont().Ok())
506 control
->SetFont(childResource
->GetFont());
512 * Interpret database as a series of resources
515 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
517 wxNode
*node
= db
.First();
520 wxExpr
*clause
= (wxExpr
*)node
->Data();
521 wxString
functor(clause
->Functor());
523 wxItemResource
*item
= (wxItemResource
*) NULL
;
524 if (functor
== "dialog")
525 item
= wxResourceInterpretDialog(table
, clause
);
526 else if (functor
== "panel")
527 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
528 else if (functor
== "menubar")
529 item
= wxResourceInterpretMenuBar(table
, clause
);
530 else if (functor
== "menu")
531 item
= wxResourceInterpretMenu(table
, clause
);
532 else if (functor
== "string")
533 item
= wxResourceInterpretString(table
, clause
);
534 else if (functor
== "bitmap")
535 item
= wxResourceInterpretBitmap(table
, clause
);
536 else if (functor
== "icon")
537 item
= wxResourceInterpretIcon(table
, clause
);
541 // Remove any existing resource of same name
542 if (item
->GetName() != "")
543 table
.DeleteResource(item
->GetName());
544 table
.AddResource(item
);
551 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
552 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
553 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
554 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
555 "wxChoice", "wxComboBox" } ;
556 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
558 static bool wxIsValidControlClass(const wxString
& c
)
561 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
563 if ( c
== g_ValidControlClasses
[i
] )
569 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
571 wxItemResource
*dialogItem
= new wxItemResource
;
573 dialogItem
->SetType("wxPanel");
575 dialogItem
->SetType("wxDialog");
579 wxString backColourHex
= "";
580 wxString labelColourHex
= "";
581 wxString buttonColourHex
= "";
583 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
587 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
589 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
590 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
591 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
592 expr
->GetAttributeValue("style", style
);
593 expr
->GetAttributeValue("name", name
);
594 expr
->GetAttributeValue("title", title
);
595 expr
->GetAttributeValue("x", x
);
596 expr
->GetAttributeValue("y", y
);
597 expr
->GetAttributeValue("width", width
);
598 expr
->GetAttributeValue("height", height
);
599 expr
->GetAttributeValue("modal", isModal
);
600 expr
->GetAttributeValue("label_font", &labelFontExpr
);
601 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
602 expr
->GetAttributeValue("font", &fontExpr
);
603 expr
->GetAttributeValue("background_colour", backColourHex
);
604 expr
->GetAttributeValue("label_colour", labelColourHex
);
605 expr
->GetAttributeValue("button_colour", buttonColourHex
);
607 int useDialogUnits
= 0;
608 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
609 if (useDialogUnits
!= 0)
610 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
613 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
614 if (useDefaults
!= 0)
615 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
618 expr
->GetAttributeValue("id", id
);
619 dialogItem
->SetId(id
);
623 windowStyle
= wxParseWindowStyle(style
);
625 dialogItem
->SetStyle(windowStyle
);
626 dialogItem
->SetValue1(isModal
);
627 dialogItem
->SetName(name
);
628 dialogItem
->SetTitle(title
);
629 dialogItem
->SetSize(x
, y
, width
, height
);
631 if (backColourHex
!= "")
636 r
= wxHexToDec(backColourHex
.Mid(0, 2));
637 g
= wxHexToDec(backColourHex
.Mid(2, 2));
638 b
= wxHexToDec(backColourHex
.Mid(4, 2));
639 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
641 if (labelColourHex
!= "")
646 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
647 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
648 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
649 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
651 if (buttonColourHex
!= "")
656 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
657 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
658 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
659 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
663 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
664 else if (buttonFontExpr
)
665 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
666 else if (labelFontExpr
)
667 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
669 // Now parse all controls
670 wxExpr
*controlExpr
= expr
->GetFirst();
673 if (controlExpr
->Number() == 3)
675 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
676 if (controlKeyword
!= "" && controlKeyword
== "control")
678 // The value part: always a list.
679 wxExpr
*listExpr
= controlExpr
->Nth(2);
680 if (listExpr
->Type() == PrologList
)
682 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
685 dialogItem
->GetChildren().Append(controlItem
);
690 controlExpr
= controlExpr
->GetNext();
695 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
697 wxItemResource
*controlItem
= new wxItemResource
;
699 // First, find the standard features of a control definition:
700 // [optional integer/string id], control name, title, style, name, x, y, width, height
702 wxString controlType
;
707 long windowStyle
= 0;
708 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
711 wxExpr
*expr1
= expr
->Nth(0);
713 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
715 if ( wxIsValidControlClass(expr1
->StringValue()) )
718 controlType
= expr1
->StringValue();
722 wxString
str(expr1
->StringValue());
723 id
= wxResourceGetIdentifier(str
, &table
);
726 wxLogWarning(_("Could not resolve control class or id '%s'. "
727 "Use (non-zero) integer instead\n or provide #define "
728 "(see manual for caveats)"),
729 (const char*) expr1
->StringValue());
731 return (wxItemResource
*) NULL
;
735 // Success - we have an id, so the 2nd element must be the control class.
736 controlType
= expr
->Nth(1)->StringValue();
741 else if (expr1
->Type() == PrologInteger
)
743 id
= (int)expr1
->IntegerValue();
744 // Success - we have an id, so the 2nd element must be the control class.
745 controlType
= expr
->Nth(1)->StringValue();
749 expr1
= expr
->Nth(count
);
752 title
= expr1
->StringValue();
754 expr1
= expr
->Nth(count
);
758 style
= expr1
->StringValue();
759 windowStyle
= wxParseWindowStyle(style
);
762 expr1
= expr
->Nth(count
);
765 name
= expr1
->StringValue();
767 expr1
= expr
->Nth(count
);
770 x
= (int)expr1
->IntegerValue();
772 expr1
= expr
->Nth(count
);
775 y
= (int)expr1
->IntegerValue();
777 expr1
= expr
->Nth(count
);
780 width
= (int)expr1
->IntegerValue();
782 expr1
= expr
->Nth(count
);
785 height
= (int)expr1
->IntegerValue();
787 controlItem
->SetStyle(windowStyle
);
788 controlItem
->SetName(name
);
789 controlItem
->SetTitle(title
);
790 controlItem
->SetSize(x
, y
, width
, height
);
791 controlItem
->SetType(controlType
);
792 controlItem
->SetId(id
);
794 if (controlType
== "wxButton")
796 // Check for bitmap resource name
797 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
799 wxString
str(expr
->Nth(count
)->StringValue());
800 controlItem
->SetValue4(str
);
802 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
803 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
806 else if (controlType
== "wxCheckBox")
808 // Check for default value
809 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
811 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
813 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
814 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
817 #if wxUSE_RADIOBUTTON
818 else if (controlType
== "wxRadioButton")
820 // Check for default value
821 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
823 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
825 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
826 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
830 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
832 // Check for default value
833 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
835 wxString
str(expr
->Nth(count
)->StringValue());
836 controlItem
->SetValue4(str
);
839 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
841 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
842 // Do nothing - no label font any more
844 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
845 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
849 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
851 // Check for bitmap resource name
852 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
854 wxString
str(expr
->Nth(count
)->StringValue());
855 controlItem
->SetValue4(str
);
857 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
858 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
861 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
863 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
864 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
866 else if (controlType
== "wxGauge")
868 // Check for default value
869 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
871 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
875 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
877 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
880 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
882 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
886 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
887 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
892 else if (controlType
== "wxSlider")
894 // Check for default value
895 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
897 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
901 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
903 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
907 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
909 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
912 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
914 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
918 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
919 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
925 else if (controlType
== "wxScrollBar")
928 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
930 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
934 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
936 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
940 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
942 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
946 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
947 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
952 else if (controlType
== "wxListBox")
954 wxExpr
*valueList
= (wxExpr
*) NULL
;
956 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
958 wxStringList stringList
;
959 wxExpr
*stringExpr
= valueList
->GetFirst();
962 stringList
.Add(stringExpr
->StringValue());
963 stringExpr
= stringExpr
->GetNext();
965 controlItem
->SetStringValues(stringList
);
967 // This is now obsolete: it's in the window style.
968 // Check for wxSINGLE/wxMULTIPLE
969 wxExpr
*mult
= (wxExpr
*) NULL
;
971 controlItem->SetValue1(wxLB_SINGLE);
973 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
976 wxString m(mult->StringValue());
977 if (m == "wxLB_MULTIPLE")
978 controlItem->SetValue1(wxLB_MULTIPLE);
979 else if (m == "wxLB_EXTENDED")
980 controlItem->SetValue1(wxLB_EXTENDED);
985 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
987 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
989 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
990 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
994 else if (controlType
== "wxChoice")
996 wxExpr
*valueList
= (wxExpr
*) NULL
;
997 // Check for default value list
998 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1000 wxStringList stringList
;
1001 wxExpr
*stringExpr
= valueList
->GetFirst();
1004 stringList
.Add(stringExpr
->StringValue());
1005 stringExpr
= stringExpr
->GetNext();
1007 controlItem
->SetStringValues(stringList
);
1011 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1013 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1016 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1017 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1022 else if (controlType
== "wxComboBox")
1024 wxExpr
*textValue
= expr
->Nth(count
);
1025 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1027 wxString
str(textValue
->StringValue());
1028 controlItem
->SetValue4(str
);
1032 wxExpr
*valueList
= (wxExpr
*) NULL
;
1033 // Check for default value list
1034 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1036 wxStringList stringList
;
1037 wxExpr
*stringExpr
= valueList
->GetFirst();
1040 stringList
.Add(stringExpr
->StringValue());
1041 stringExpr
= stringExpr
->GetNext();
1043 controlItem
->SetStringValues(stringList
);
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1049 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1052 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1053 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1060 else if (controlType
== "wxRadioBox")
1062 wxExpr
*valueList
= (wxExpr
*) NULL
;
1063 // Check for default value list
1064 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1066 wxStringList stringList
;
1067 wxExpr
*stringExpr
= valueList
->GetFirst();
1070 stringList
.Add(stringExpr
->StringValue());
1071 stringExpr
= stringExpr
->GetNext();
1073 controlItem
->SetStringValues(stringList
);
1076 // majorDim (number of rows or cols)
1077 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1079 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1083 controlItem
->SetValue1(0);
1085 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1087 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1090 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1091 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1099 return (wxItemResource
*) NULL
;
1104 // Forward declaration
1105 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1108 * Interpet a menu item
1111 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1113 wxItemResource
*item
= new wxItemResource
;
1115 wxExpr
*labelExpr
= expr
->Nth(0);
1116 wxExpr
*idExpr
= expr
->Nth(1);
1117 wxExpr
*helpExpr
= expr
->Nth(2);
1118 wxExpr
*checkableExpr
= expr
->Nth(3);
1120 // Further keywords/attributes to follow sometime...
1121 if (expr
->Number() == 0)
1123 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1124 item
->SetType("wxMenuSeparator");
1129 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1130 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1133 wxString
str(labelExpr
->StringValue());
1134 item
->SetTitle(str
);
1139 // If a string or word, must look up in identifier table.
1140 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1142 wxString
str(idExpr
->StringValue());
1143 id
= wxResourceGetIdentifier(str
, &table
);
1146 wxLogWarning(_("Could not resolve menu id '%s'. "
1147 "Use (non-zero) integer instead\n"
1148 "or provide #define (see manual for caveats)"),
1149 (const char*) idExpr
->StringValue());
1152 else if (idExpr
->Type() == PrologInteger
)
1153 id
= (int)idExpr
->IntegerValue();
1154 item
->SetValue1(id
);
1158 wxString
str(helpExpr
->StringValue());
1159 item
->SetValue4(str
);
1162 item
->SetValue2(checkableExpr
->IntegerValue());
1164 // Find the first expression that's a list, for submenu
1165 wxExpr
*subMenuExpr
= expr
->GetFirst();
1166 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1167 subMenuExpr
= subMenuExpr
->GetNext();
1171 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1172 item
->GetChildren().Append(child
);
1173 subMenuExpr
= subMenuExpr
->GetNext();
1180 * Interpret a nested list as a menu
1183 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1185 wxItemResource *menu = new wxItemResource;
1186 // menu->SetType(wxTYPE_MENU);
1187 menu->SetType("wxMenu");
1188 wxExpr *element = expr->GetFirst();
1191 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1193 menu->GetChildren().Append(item);
1194 element = element->GetNext();
1200 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1202 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1203 expr
->GetAttributeValue("menu", &listExpr
);
1205 return (wxItemResource
*) NULL
;
1207 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1210 return (wxItemResource
*) NULL
;
1213 if (expr
->GetAttributeValue("name", name
))
1215 menuResource
->SetName(name
);
1218 return menuResource
;
1221 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1223 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1224 expr
->GetAttributeValue("menu", &listExpr
);
1226 return (wxItemResource
*) NULL
;
1228 wxItemResource
*resource
= new wxItemResource
;
1229 resource
->SetType("wxMenu");
1230 // resource->SetType(wxTYPE_MENU);
1232 wxExpr
*element
= listExpr
->GetFirst();
1235 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1236 resource
->GetChildren().Append(menuResource
);
1237 element
= element
->GetNext();
1241 if (expr
->GetAttributeValue("name", name
))
1243 resource
->SetName(name
);
1249 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1251 return (wxItemResource
*) NULL
;
1254 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1256 wxItemResource
*bitmapItem
= new wxItemResource
;
1257 // bitmapItem->SetType(wxTYPE_BITMAP);
1258 bitmapItem
->SetType("wxBitmap");
1260 if (expr
->GetAttributeValue("name", name
))
1262 bitmapItem
->SetName(name
);
1264 // Now parse all bitmap specifications
1265 wxExpr
*bitmapExpr
= expr
->GetFirst();
1268 if (bitmapExpr
->Number() == 3)
1270 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1271 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1273 // The value part: always a list.
1274 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1275 if (listExpr
->Type() == PrologList
)
1277 wxItemResource
*bitmapSpec
= new wxItemResource
;
1278 // bitmapSpec->SetType(wxTYPE_BITMAP);
1279 bitmapSpec
->SetType("wxBitmap");
1281 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1282 // where everything after 'filename' is optional.
1283 wxExpr
*nameExpr
= listExpr
->Nth(0);
1284 wxExpr
*typeExpr
= listExpr
->Nth(1);
1285 wxExpr
*platformExpr
= listExpr
->Nth(2);
1286 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1287 wxExpr
*xresExpr
= listExpr
->Nth(4);
1288 wxExpr
*yresExpr
= listExpr
->Nth(5);
1289 if (nameExpr
&& nameExpr
->StringValue())
1291 bitmapSpec
->SetName(nameExpr
->StringValue());
1293 if (typeExpr
&& typeExpr
->StringValue())
1295 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1298 bitmapSpec
->SetValue1(0);
1300 if (platformExpr
&& platformExpr
->StringValue())
1302 wxString
plat(platformExpr
->StringValue());
1303 if (plat
== "windows" || plat
== "WINDOWS")
1304 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1305 else if (plat
== "x" || plat
== "X")
1306 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1307 else if (plat
== "mac" || plat
== "MAC")
1308 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1310 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1313 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1316 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1320 xres
= (int)xresExpr
->IntegerValue();
1322 yres
= (int)yresExpr
->IntegerValue();
1323 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1325 bitmapItem
->GetChildren().Append(bitmapSpec
);
1329 bitmapExpr
= bitmapExpr
->GetNext();
1335 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1337 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1340 // item->SetType(wxTYPE_ICON);
1341 item
->SetType("wxIcon");
1345 return (wxItemResource
*) NULL
;
1348 // Interpret list expression as a font
1349 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1351 if (expr
->Type() != PrologList
)
1355 int family
= wxSWISS
;
1356 int style
= wxNORMAL
;
1357 int weight
= wxNORMAL
;
1359 wxString
faceName("");
1361 wxExpr
*pointExpr
= expr
->Nth(0);
1362 wxExpr
*familyExpr
= expr
->Nth(1);
1363 wxExpr
*styleExpr
= expr
->Nth(2);
1364 wxExpr
*weightExpr
= expr
->Nth(3);
1365 wxExpr
*underlineExpr
= expr
->Nth(4);
1366 wxExpr
*faceNameExpr
= expr
->Nth(5);
1368 point
= (int)pointExpr
->IntegerValue();
1373 str
= familyExpr
->StringValue();
1374 family
= (int)wxParseWindowStyle(str
);
1378 str
= styleExpr
->StringValue();
1379 style
= (int)wxParseWindowStyle(str
);
1383 str
= weightExpr
->StringValue();
1384 weight
= (int)wxParseWindowStyle(str
);
1387 underline
= (int)underlineExpr
->IntegerValue();
1389 faceName
= faceNameExpr
->StringValue();
1391 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1396 * (Re)allocate buffer for reading in from resource file
1399 bool wxReallocateResourceBuffer()
1401 if (!wxResourceBuffer
)
1403 wxResourceBufferSize
= 1000;
1404 wxResourceBuffer
= new char[wxResourceBufferSize
];
1407 if (wxResourceBuffer
)
1409 long newSize
= wxResourceBufferSize
+ 1000;
1410 char *tmp
= new char[(int)newSize
];
1411 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1412 delete[] wxResourceBuffer
;
1413 wxResourceBuffer
= tmp
;
1414 wxResourceBufferSize
= newSize
;
1419 static bool wxEatWhiteSpace(FILE *fd
)
1422 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1429 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1431 // Check for comment
1437 bool finished
= FALSE
;
1445 int newCh
= getc(fd
);
1460 return wxEatWhiteSpace(fd
);
1463 bool wxGetResourceToken(FILE *fd
)
1465 if (!wxResourceBuffer
)
1466 wxReallocateResourceBuffer();
1467 wxResourceBuffer
[0] = 0;
1468 wxEatWhiteSpace(fd
);
1474 wxResourceBufferCount
= 0;
1481 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1484 // Escaped characters
1485 else if (ch
== '\\')
1487 int newCh
= getc(fd
);
1490 else if (newCh
== 10)
1498 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1499 wxReallocateResourceBuffer();
1500 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1501 wxResourceBufferCount
++;
1504 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1508 wxResourceBufferCount
= 0;
1510 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1512 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1513 wxReallocateResourceBuffer();
1514 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1515 wxResourceBufferCount
++;
1519 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1527 * Files are in form:
1528 static char *name = "....";
1529 with possible comments.
1532 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1535 table
= wxDefaultResourceTable
;
1537 // static or #define
1538 if (!wxGetResourceToken(fd
))
1544 if (strcmp(wxResourceBuffer
, "#define") == 0)
1546 wxGetResourceToken(fd
);
1547 char *name
= copystring(wxResourceBuffer
);
1548 wxGetResourceToken(fd
);
1549 char *value
= copystring(wxResourceBuffer
);
1550 if (isalpha(value
[0]))
1552 int val
= (int)atol(value
);
1553 wxResourceAddIdentifier(name
, val
, table
);
1557 wxLogWarning(_("#define %s must be an integer."), name
);
1567 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1569 wxGetResourceToken(fd
);
1570 char *name
= copystring(wxResourceBuffer
);
1571 char *actualName
= name
;
1573 actualName
= name
+ 1;
1574 int len
= strlen(name
);
1575 if ((len
> 0) && (name
[len
-1] == '"'))
1577 if (!wxResourceParseIncludeFile(actualName
, table
))
1579 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1584 else if (strcmp(wxResourceBuffer
, "static") != 0)
1587 strcpy(buf
, _("Found "));
1588 strncat(buf
, wxResourceBuffer
, 30);
1589 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1595 if (!wxGetResourceToken(fd
))
1597 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1602 if (strcmp(wxResourceBuffer
, "char") != 0)
1604 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1609 if (!wxGetResourceToken(fd
))
1611 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1616 if (wxResourceBuffer
[0] != '*')
1618 wxLogWarning(_("Expected '*' whilst parsing resource."));
1622 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1625 if (!wxGetResourceToken(fd
))
1627 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1632 if (strcmp(wxResourceBuffer
, "=") != 0)
1634 wxLogWarning(_("Expected '=' whilst parsing resource."));
1639 if (!wxGetResourceToken(fd
))
1641 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1647 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1649 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1654 if (!wxGetResourceToken(fd
))
1662 * Parses string window style into integer window style
1666 * Style flag parsing, e.g.
1667 * "wxSYSTEM_MENU | wxBORDER" -> integer
1670 char* wxResourceParseWord(char*s
, int *i
)
1673 return (char*) NULL
;
1675 static char buf
[150];
1676 int len
= strlen(s
);
1679 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1687 // Eat whitespace and conjunction characters
1688 while ((ii
< len
) &&
1689 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1695 return (char*) NULL
;
1700 struct wxResourceBitListStruct
1706 static wxResourceBitListStruct wxResourceBitListTable
[] =
1709 { "wxSINGLE", wxLB_SINGLE
},
1710 { "wxMULTIPLE", wxLB_MULTIPLE
},
1711 { "wxEXTENDED", wxLB_EXTENDED
},
1712 { "wxLB_SINGLE", wxLB_SINGLE
},
1713 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1714 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1715 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1716 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1717 { "wxLB_SORT", wxLB_SORT
},
1718 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1719 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1722 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1723 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1724 { "wxCB_READONLY", wxCB_READONLY
},
1725 { "wxCB_SORT", wxCB_SORT
},
1728 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1729 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1730 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1733 { "wxPASSWORD", wxPASSWORD
},
1734 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1735 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1736 { "wxTE_READONLY", wxTE_READONLY
},
1737 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1738 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1740 /* wxRadioBox/wxRadioButton */
1741 { "wxRB_GROUP", wxRB_GROUP
},
1742 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1743 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1746 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1747 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1748 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1749 { "wxSL_LABELS", wxSL_LABELS
},
1750 { "wxSL_LEFT", wxSL_LEFT
},
1751 { "wxSL_TOP", wxSL_TOP
},
1752 { "wxSL_RIGHT", wxSL_RIGHT
},
1753 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1754 { "wxSL_BOTH", wxSL_BOTH
},
1755 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1758 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1759 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1762 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1763 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1766 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1767 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1768 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1771 { "wxLC_ICON", wxLC_ICON
},
1772 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1773 { "wxLC_LIST", wxLC_LIST
},
1774 { "wxLC_REPORT", wxLC_REPORT
},
1775 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1776 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1777 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1778 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1779 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1780 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1781 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1782 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1783 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1784 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1787 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1788 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1789 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1790 { "wxSP_WRAP", wxSP_WRAP
},
1793 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1794 { "wxSP_3D", wxSP_3D
},
1795 { "wxSP_BORDER", wxSP_BORDER
},
1798 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1799 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1800 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1801 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1804 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1807 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1808 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1809 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1810 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1811 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1812 { "wxCOLOURED", wxCOLOURED
},
1815 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1816 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1817 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1818 { "wxTB_FLAT", wxTB_FLAT
},
1821 { "wxVSCROLL", wxVSCROLL
},
1822 { "wxHSCROLL", wxHSCROLL
},
1823 { "wxCAPTION", wxCAPTION
},
1824 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1825 { "wxICONIZE", wxICONIZE
},
1826 { "wxMINIMIZE", wxICONIZE
},
1827 { "wxMAXIMIZE", wxMAXIMIZE
},
1829 { "wxMDI_PARENT", 0},
1830 { "wxMDI_CHILD", 0},
1831 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1832 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1833 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1834 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1835 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1836 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1837 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1838 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1839 { "wxBORDER", wxBORDER
},
1840 { "wxRETAINED", wxRETAINED
},
1841 { "wxNATIVE_IMPL", 0},
1842 { "wxEXTENDED_IMPL", 0},
1843 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1844 // { "wxFLAT", wxFLAT},
1845 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1846 { "wxFIXED_LENGTH", 0},
1847 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1848 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1849 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1850 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1851 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1852 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1853 { "wxNO_BORDER", wxNO_BORDER
},
1854 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1856 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1857 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1859 // Text font families
1860 { "wxDEFAULT", wxDEFAULT
},
1861 { "wxDECORATIVE", wxDECORATIVE
},
1862 { "wxROMAN", wxROMAN
},
1863 { "wxSCRIPT", wxSCRIPT
},
1864 { "wxSWISS", wxSWISS
},
1865 { "wxMODERN", wxMODERN
},
1866 { "wxTELETYPE", wxTELETYPE
},
1867 { "wxVARIABLE", wxVARIABLE
},
1868 { "wxFIXED", wxFIXED
},
1869 { "wxNORMAL", wxNORMAL
},
1870 { "wxLIGHT", wxLIGHT
},
1871 { "wxBOLD", wxBOLD
},
1872 { "wxITALIC", wxITALIC
},
1873 { "wxSLANT", wxSLANT
},
1874 { "wxSOLID", wxSOLID
},
1876 { "wxLONG_DASH", wxLONG_DASH
},
1877 { "wxSHORT_DASH", wxSHORT_DASH
},
1878 { "wxDOT_DASH", wxDOT_DASH
},
1879 { "wxUSER_DASH", wxUSER_DASH
},
1880 { "wxTRANSPARENT", wxTRANSPARENT
},
1881 { "wxSTIPPLE", wxSTIPPLE
},
1882 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1883 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1884 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1885 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1886 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1887 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1888 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1889 { "wxJOIN_MITER", wxJOIN_MITER
},
1890 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1891 { "wxCAP_ROUND", wxCAP_ROUND
},
1892 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1893 { "wxCAP_BUTT", wxCAP_BUTT
},
1896 { "wxCLEAR", wxCLEAR
},
1898 { "wxINVERT", wxINVERT
},
1899 { "wxOR_REVERSE", wxOR_REVERSE
},
1900 { "wxAND_REVERSE", wxAND_REVERSE
},
1901 { "wxCOPY", wxCOPY
},
1903 { "wxAND_INVERT", wxAND_INVERT
},
1904 { "wxNO_OP", wxNO_OP
},
1906 { "wxEQUIV", wxEQUIV
},
1907 { "wxSRC_INVERT", wxSRC_INVERT
},
1908 { "wxOR_INVERT", wxOR_INVERT
},
1909 { "wxNAND", wxNAND
},
1913 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1914 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1915 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1916 { "wxWINDING_RULE", wxWINDING_RULE
},
1917 { "wxHORIZONTAL", wxHORIZONTAL
},
1918 { "wxVERTICAL", wxVERTICAL
},
1919 { "wxBOTH", wxBOTH
},
1920 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1922 { "wxYES_NO", wxYES_NO
},
1923 { "wxCANCEL", wxCANCEL
},
1926 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1927 { "wxICON_HAND", wxICON_HAND
},
1928 { "wxICON_QUESTION", wxICON_QUESTION
},
1929 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1930 { "wxICON_STOP", wxICON_STOP
},
1931 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1932 { "wxICON_MASK", wxICON_MASK
},
1933 { "wxCENTRE", wxCENTRE
},
1934 { "wxCENTER", wxCENTRE
},
1935 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1936 { "wxVERTICAL_LABEL", 0},
1937 { "wxHORIZONTAL_LABEL", 0},
1939 // Bitmap types (not strictly styles)
1940 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1941 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1942 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1943 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1944 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1945 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1946 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1947 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1948 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1949 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1950 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1951 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1952 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1953 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1956 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
1958 long wxParseWindowStyle(const wxString
& bitListString
)
1963 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
1967 for (j
= 0; j
< wxResourceBitListCount
; j
++)
1968 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
1970 bitList
|= wxResourceBitListTable
[j
].bits
;
1976 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
1984 * Load a bitmap from a wxWindows resource, choosing an optimum
1985 * depth and appropriate type.
1988 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
1991 table
= wxDefaultResourceTable
;
1993 wxItemResource
*item
= table
->FindResource(resource
);
1996 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
1998 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
1999 return wxNullBitmap
;
2001 int thisDepth
= wxDisplayDepth();
2002 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2004 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2006 // Try to find optimum bitmap for this platform/colour depth
2007 wxNode
*node
= item
->GetChildren().First();
2010 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2011 int platform
= (int)child
->GetValue2();
2012 int noColours
= (int)child
->GetValue3();
2014 char *name = child->GetName();
2015 int bitmapType = (int)child->GetValue1();
2016 int xRes = child->GetWidth();
2017 int yRes = child->GetHeight();
2022 case RESOURCE_PLATFORM_ANY
:
2024 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2025 optResource
= child
;
2028 // Maximise the number of colours.
2029 // If noColours is zero (unspecified), then assume this
2030 // is the right one.
2031 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2032 optResource
= child
;
2037 case RESOURCE_PLATFORM_WINDOWS
:
2039 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2040 optResource
= child
;
2043 // Maximise the number of colours
2044 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2045 optResource
= child
;
2051 case RESOURCE_PLATFORM_X
:
2053 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2054 optResource
= child
;
2057 // Maximise the number of colours
2058 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2059 optResource
= child
;
2065 case RESOURCE_PLATFORM_MAC
:
2067 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2068 optResource
= child
;
2071 // Maximise the number of colours
2072 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2073 optResource
= child
;
2081 node
= node
->Next();
2083 // If no matching resource, fail.
2085 return wxNullBitmap
;
2087 wxString name
= optResource
->GetName();
2088 int bitmapType
= (int)optResource
->GetValue1();
2091 case wxBITMAP_TYPE_XBM_DATA
:
2094 wxItemResource
*item
= table
->FindResource(name
);
2097 wxLogWarning(_("Failed to find XBM resource %s.\n"
2098 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2099 return (wxBitmap
*) NULL
;
2101 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2103 wxLogWarning(_("No XBM facility available!"));
2107 case wxBITMAP_TYPE_XPM_DATA
:
2109 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2110 wxItemResource
*item
= table
->FindResource(name
);
2113 wxLogWarning(_("Failed to find XPM resource %s.\n"
2114 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2115 return (wxBitmap
*) NULL
;
2117 return wxBitmap(item
->GetValue1());
2119 wxLogWarning(_("No XPM facility available!"));
2125 return wxBitmap(name
, bitmapType
);
2129 return wxNullBitmap
;
2133 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2134 return wxNullBitmap
;
2139 * Load an icon from a wxWindows resource, choosing an optimum
2140 * depth and appropriate type.
2143 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2146 table
= wxDefaultResourceTable
;
2148 wxItemResource
*item
= table
->FindResource(resource
);
2151 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2153 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2156 int thisDepth
= wxDisplayDepth();
2157 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2159 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2161 // Try to find optimum icon for this platform/colour depth
2162 wxNode
*node
= item
->GetChildren().First();
2165 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2166 int platform
= (int)child
->GetValue2();
2167 int noColours
= (int)child
->GetValue3();
2169 char *name = child->GetName();
2170 int bitmapType = (int)child->GetValue1();
2171 int xRes = child->GetWidth();
2172 int yRes = child->GetHeight();
2177 case RESOURCE_PLATFORM_ANY
:
2179 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2180 optResource
= child
;
2183 // Maximise the number of colours.
2184 // If noColours is zero (unspecified), then assume this
2185 // is the right one.
2186 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2187 optResource
= child
;
2192 case RESOURCE_PLATFORM_WINDOWS
:
2194 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2195 optResource
= child
;
2198 // Maximise the number of colours
2199 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2200 optResource
= child
;
2206 case RESOURCE_PLATFORM_X
:
2208 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2209 optResource
= child
;
2212 // Maximise the number of colours
2213 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2214 optResource
= child
;
2220 case RESOURCE_PLATFORM_MAC
:
2222 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2223 optResource
= child
;
2226 // Maximise the number of colours
2227 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2228 optResource
= child
;
2236 node
= node
->Next();
2238 // If no matching resource, fail.
2242 wxString name
= optResource
->GetName();
2243 int bitmapType
= (int)optResource
->GetValue1();
2246 case wxBITMAP_TYPE_XBM_DATA
:
2249 wxItemResource
*item
= table
->FindResource(name
);
2252 wxLogWarning(_("Failed to find XBM resource %s.\n"
2253 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2254 return (wxIcon
*) NULL
;
2256 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2258 wxLogWarning(_("No XBM facility available!"));
2262 case wxBITMAP_TYPE_XPM_DATA
:
2264 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2266 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2267 wxItemResource *item = table->FindResource(name);
2271 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2275 return wxIcon((char **)item->GetValue1());
2277 wxLogWarning(_("No XPM facility available!"));
2280 wxLogWarning(_("No XPM icon facility available!"));
2286 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2288 return wxIcon(name
, bitmapType
);
2297 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2298 return (wxIcon
*) NULL
;
2302 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2304 wxMenu
*menu
= new wxMenu
;
2305 wxNode
*node
= item
->GetChildren().First();
2308 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2309 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2310 menu
->AppendSeparator();
2311 else if (child
->GetChildren().Number() > 0)
2313 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2315 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2319 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2321 node
= node
->Next();
2326 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2329 table
= wxDefaultResourceTable
;
2331 wxItemResource
*menuResource
= table
->FindResource(resource
);
2332 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2335 menuBar
= new wxMenuBar
;
2336 wxNode
*node
= menuResource
->GetChildren().First();
2339 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2340 wxMenu
*menu
= wxResourceCreateMenu(child
);
2342 menuBar
->Append(menu
, child
->GetTitle());
2343 node
= node
->Next();
2347 return (wxMenuBar
*) NULL
;
2350 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2353 table
= wxDefaultResourceTable
;
2355 wxItemResource
*menuResource
= table
->FindResource(resource
);
2356 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2357 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2358 return wxResourceCreateMenu(menuResource
);
2359 return (wxMenu
*) NULL
;
2362 // Global equivalents (so don't have to refer to default table explicitly)
2363 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2366 table
= wxDefaultResourceTable
;
2368 return table
->ParseResourceData(resource
);
2371 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2374 table
= wxDefaultResourceTable
;
2376 return table
->ParseResourceFile(filename
);
2379 // Register XBM/XPM data
2380 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2383 table
= wxDefaultResourceTable
;
2385 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2388 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2391 table
= wxDefaultResourceTable
;
2393 return table
->RegisterResourceBitmapData(name
, data
);
2396 void wxResourceClear(wxResourceTable
*table
)
2399 table
= wxDefaultResourceTable
;
2401 table
->ClearTable();
2408 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2411 table
= wxDefaultResourceTable
;
2413 table
->identifiers
.Put(name
, (wxObject
*)value
);
2417 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2420 table
= wxDefaultResourceTable
;
2422 return (int)table
->identifiers
.Get(name
);
2426 * Parse #include file for #defines (only)
2429 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2432 table
= wxDefaultResourceTable
;
2434 FILE *fd
= fopen(f
, "r");
2439 while (wxGetResourceToken(fd
))
2441 if (strcmp(wxResourceBuffer
, "#define") == 0)
2443 wxGetResourceToken(fd
);
2444 char *name
= copystring(wxResourceBuffer
);
2445 wxGetResourceToken(fd
);
2446 char *value
= copystring(wxResourceBuffer
);
2447 if (isdigit(value
[0]))
2449 int val
= (int)atol(value
);
2450 wxResourceAddIdentifier(name
, val
, table
);
2461 * Reading strings as if they were .wxr files
2464 static int getc_string(char *s
)
2466 int ch
= s
[wxResourceStringPtr
];
2471 wxResourceStringPtr
++;
2476 static int ungetc_string()
2478 wxResourceStringPtr
--;
2482 bool wxEatWhiteSpaceString(char *s
)
2484 int ch
= getc_string(s
);
2488 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2495 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2496 ch
= getc_string(s
);
2497 // Check for comment
2500 ch
= getc_string(s
);
2503 bool finished
= FALSE
;
2506 ch
= getc_string(s
);
2511 int newCh
= getc_string(s
);
2526 return wxEatWhiteSpaceString(s
);
2529 bool wxGetResourceTokenString(char *s
)
2531 if (!wxResourceBuffer
)
2532 wxReallocateResourceBuffer();
2533 wxResourceBuffer
[0] = 0;
2534 wxEatWhiteSpaceString(s
);
2536 int ch
= getc_string(s
);
2540 wxResourceBufferCount
= 0;
2541 ch
= getc_string(s
);
2547 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2550 // Escaped characters
2551 else if (ch
== '\\')
2553 int newCh
= getc_string(s
);
2556 else if (newCh
== 10)
2564 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2565 wxReallocateResourceBuffer();
2566 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2567 wxResourceBufferCount
++;
2568 ch
= getc_string(s
);
2570 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2574 wxResourceBufferCount
= 0;
2576 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2578 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2579 wxReallocateResourceBuffer();
2580 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2581 wxResourceBufferCount
++;
2583 ch
= getc_string(s
);
2585 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2593 * Files are in form:
2594 static char *name = "....";
2595 with possible comments.
2598 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2601 table
= wxDefaultResourceTable
;
2603 // static or #define
2604 if (!wxGetResourceTokenString(s
))
2610 if (strcmp(wxResourceBuffer
, "#define") == 0)
2612 wxGetResourceTokenString(s
);
2613 char *name
= copystring(wxResourceBuffer
);
2614 wxGetResourceTokenString(s
);
2615 char *value
= copystring(wxResourceBuffer
);
2616 if (isalpha(value
[0]))
2618 int val
= (int)atol(value
);
2619 wxResourceAddIdentifier(name
, val
, table
);
2623 wxLogWarning(_("#define %s must be an integer."), name
);
2634 else if (strcmp(wxResourceBuffer, "#include") == 0)
2636 wxGetResourceTokenString(s);
2637 char *name = copystring(wxResourceBuffer);
2638 char *actualName = name;
2640 actualName = name + 1;
2641 int len = strlen(name);
2642 if ((len > 0) && (name[len-1] == '"'))
2644 if (!wxResourceParseIncludeFile(actualName, table))
2647 sprintf(buf, _("Could not find resource include file %s."), actualName);
2654 else if (strcmp(wxResourceBuffer
, "static") != 0)
2657 strcpy(buf
, _("Found "));
2658 strncat(buf
, wxResourceBuffer
, 30);
2659 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2665 if (!wxGetResourceTokenString(s
))
2667 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2672 if (strcmp(wxResourceBuffer
, "char") != 0)
2674 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2679 if (!wxGetResourceTokenString(s
))
2681 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2686 if (wxResourceBuffer
[0] != '*')
2688 wxLogWarning(_("Expected '*' whilst parsing resource."));
2692 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2695 if (!wxGetResourceTokenString(s
))
2697 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2702 if (strcmp(wxResourceBuffer
, "=") != 0)
2704 wxLogWarning(_("Expected '=' whilst parsing resource."));
2709 if (!wxGetResourceTokenString(s
))
2711 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2717 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2719 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2724 if (!wxGetResourceTokenString(s
))
2731 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2734 table
= wxDefaultResourceTable
;
2739 // Turn backslashes into spaces
2742 int len
= strlen(s
);
2744 for (i
= 0; i
< len
; i
++)
2745 if (s
[i
] == 92 && s
[i
+1] == 13)
2753 wxResourceStringPtr
= 0;
2756 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2760 return wxResourceInterpretResources(*table
, db
);
2764 * resource loading facility
2767 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2770 table
= wxDefaultResourceTable
;
2772 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2773 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2774 if (!resource
|| !resource
->GetType() ||
2775 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2778 wxString
title(resource
->GetTitle());
2779 long theWindowStyle
= resource
->GetStyle();
2780 bool isModal
= (resource
->GetValue1() != 0);
2781 int x
= resource
->GetX();
2782 int y
= resource
->GetY();
2783 int width
= resource
->GetWidth();
2784 int height
= resource
->GetHeight();
2785 wxString name
= resource
->GetName();
2787 if (IsKindOf(CLASSINFO(wxDialog
)))
2789 wxDialog
*dialogBox
= (wxDialog
*)this;
2790 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2791 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2794 // Only reset the client size if we know we're not going to do it again below.
2795 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2796 dialogBox
->SetClientSize(width
, height
);
2798 else if (IsKindOf(CLASSINFO(wxPanel
)))
2800 wxPanel
* panel
= (wxPanel
*)this;
2801 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2806 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2810 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2812 // No need to do this since it's done in wxPanel or wxDialog constructor.
2813 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2817 if (resource
->GetFont().Ok())
2818 SetFont(resource
->GetFont());
2819 if (resource
->GetBackgroundColour().Ok())
2820 SetBackgroundColour(resource
->GetBackgroundColour());
2823 // Should have some kind of font at this point
2824 if (!GetFont()->Ok())
2825 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2826 if (!GetBackgroundColour().Ok())
2827 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2829 // Only when we've created the window and set the font can we set the correct size,
2830 // if based on dialog units.
2831 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2833 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2834 SetClientSize(sz
.x
, sz
.y
);
2836 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2840 // Now create children
2841 wxNode
*node
= resource
->GetChildren().First();
2844 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2846 (void) CreateItem(childResource
, resource
, table
);
2848 node
= node
->Next();
2853 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2856 table
= wxDefaultResourceTable
;
2857 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2861 #pragma warning(default:4706) // assignment within conditional expression
2864 #endif // wxUSE_WX_RESOURCES