1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/gdicmn.h"
32 #include "wx/stattext.h"
33 #include "wx/button.h"
34 #include "wx/bmpbuttn.h"
35 #include "wx/radiobox.h"
36 #include "wx/listbox.h"
37 #include "wx/choice.h"
38 #include "wx/checkbox.h"
39 #include "wx/slider.h"
40 #include "wx/statbox.h"
44 #include "wx/textctrl.h"
45 #include "wx/msgdlg.h"
50 #include "wx/scrolbar.h"
54 #include "wx/combobox.h"
57 #include "wx/validate.h"
61 #if wxUSE_WX_RESOURCES
68 #include "wx/resource.h"
69 #include "wx/string.h"
70 #include "wx/wxexpr.h"
72 // Forward (private) declarations
73 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
74 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
75 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
76 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
77 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
78 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
79 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
80 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
81 // Interpret list expression
82 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
84 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
85 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
87 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
89 static char *wxResourceBuffer
= (char *) NULL
;
90 static long wxResourceBufferSize
= 0;
91 static long wxResourceBufferCount
= 0;
92 static int wxResourceStringPtr
= 0;
94 void wxInitializeResourceSystem()
96 wxDefaultResourceTable
= new wxResourceTable
;
99 void wxCleanUpResourceSystem()
101 delete wxDefaultResourceTable
;
102 if (wxResourceBuffer
)
103 delete[] wxResourceBuffer
;
106 void wxLogWarning(char *msg
)
108 wxMessageBox(msg
, _("Warning"), wxOK
);
111 #if !USE_SHARED_LIBRARY
112 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
113 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
116 wxItemResource::wxItemResource()
122 m_x
= m_y
= m_width
= m_height
= 0;
123 m_value1
= m_value2
= m_value3
= m_value5
= 0;
129 wxItemResource::~wxItemResource()
131 wxNode
*node
= m_children
.First();
134 wxItemResource
*item
= (wxItemResource
*)node
->Data();
137 node
= m_children
.First();
145 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
149 wxResourceTable::~wxResourceTable()
154 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
156 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
160 void wxResourceTable::AddResource(wxItemResource
*item
)
162 wxString name
= item
->GetName();
164 name
= item
->GetTitle();
168 // Delete existing resource, if any.
174 bool wxResourceTable::DeleteResource(const wxString
& name
)
176 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
179 // See if any resource has this as its child; if so, delete from
180 // parent's child list.
182 wxNode
*node
= (wxNode
*) NULL
;
183 while ((node
= Next()))
185 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
186 if (parent
->GetChildren().Member(item
))
188 parent
->GetChildren().DeleteObject(item
);
200 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
204 FILE *fd
= fopen((const char*) filename
, "r");
208 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
213 return wxResourceInterpretResources(*this, db
);
216 bool wxResourceTable::ParseResourceData(const wxString
& data
)
219 if (!db
.ReadFromString(data
))
221 wxLogWarning(_("Ill-formed resource file syntax."));
225 return wxResourceInterpretResources(*this, db
);
228 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
230 // Register pre-loaded bitmap data
231 wxItemResource
*item
= new wxItemResource
;
232 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
233 item
->SetType("wxXBMData");
235 item
->SetValue1((long)bits
);
236 item
->SetValue2((long)width
);
237 item
->SetValue3((long)height
);
242 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
244 // Register pre-loaded bitmap data
245 wxItemResource
*item
= new wxItemResource
;
246 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
247 item
->SetType("wxXPMData");
249 item
->SetValue1((long)data
);
254 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
259 void wxResourceTable::ClearTable()
262 wxNode
*node
= Next();
265 wxNode
*next
= Next();
266 wxItemResource
*item
= (wxItemResource
*)node
->Data();
273 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
275 int id
= childResource
->GetId();
279 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
281 wxControl
*control
= (wxControl
*) NULL
;
282 wxString
itemType(childResource
->GetType());
288 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
289 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
293 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
294 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
297 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
299 if (childResource
->GetValue4() != "")
302 wxBitmap bitmap
= childResource
->GetBitmap();
305 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
306 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
309 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
310 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
313 // Normal, text button
314 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
315 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
317 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
318 itemType
== wxString("wxStaticBitmap"))
320 if (childResource
->GetValue4() != "")
323 wxBitmap bitmap
= childResource
->GetBitmap();
326 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
327 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
329 #if wxUSE_BITMAP_MESSAGE
331 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
332 childResource
->GetStyle(), childResource
->GetName());
337 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
338 childResource
->GetStyle(), childResource
->GetName());
341 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
343 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
344 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
346 else if (itemType
== wxString("wxCheckBox"))
348 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
349 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
351 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
354 else if (itemType
== wxString("wxGauge"))
356 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
357 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
359 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
362 #if wxUSE_RADIOBUTTON
363 else if (itemType
== wxString("wxRadioButton"))
365 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
367 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
371 else if (itemType
== wxString("wxScrollBar"))
373 control
= new wxScrollBar(parent
, id
, pos
, size
,
374 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
375 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
376 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
377 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
378 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
381 else if (itemType
== wxString("wxSlider"))
383 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
384 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
385 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
387 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
389 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
390 childResource
->GetStyle(), childResource
->GetName());
392 else if (itemType
== wxString("wxListBox"))
394 wxStringList
& stringList
= childResource
->GetStringValues();
395 wxString
*strings
= (wxString
*) NULL
;
397 if (stringList
.Number() > 0)
399 noStrings
= stringList
.Number();
400 strings
= new wxString
[noStrings
];
401 wxNode
*node
= stringList
.First();
405 strings
[i
] = (char *)node
->Data();
410 control
= new wxListBox(parent
, id
, pos
, size
,
411 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
416 else if (itemType
== wxString("wxChoice"))
418 wxStringList
& stringList
= childResource
->GetStringValues();
419 wxString
*strings
= (wxString
*) NULL
;
421 if (stringList
.Number() > 0)
423 noStrings
= stringList
.Number();
424 strings
= new wxString
[noStrings
];
425 wxNode
*node
= stringList
.First();
429 strings
[i
] = (char *)node
->Data();
434 control
= new wxChoice(parent
, id
, pos
, size
,
435 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
441 else if (itemType
== wxString("wxComboBox"))
443 wxStringList
& stringList
= childResource
->GetStringValues();
444 wxString
*strings
= (wxString
*) NULL
;
446 if (stringList
.Number() > 0)
448 noStrings
= stringList
.Number();
449 strings
= new wxString
[noStrings
];
450 wxNode
*node
= stringList
.First();
454 strings
[i
] = (char *)node
->Data();
459 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
460 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
466 else if (itemType
== wxString("wxRadioBox"))
468 wxStringList
& stringList
= childResource
->GetStringValues();
469 wxString
*strings
= (wxString
*) NULL
;
471 if (stringList
.Number() > 0)
473 noStrings
= stringList
.Number();
474 strings
= new wxString
[noStrings
];
475 wxNode
*node
= stringList
.First();
479 strings
[i
] = (char *)node
->Data();
484 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
485 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
486 childResource
->GetName());
492 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
494 // Don't set font; will be inherited from parent.
498 if (control
&& childResource
->GetFont().Ok())
499 control
->SetFont(childResource
->GetFont());
505 * Interpret database as a series of resources
508 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
510 wxNode
*node
= db
.First();
513 wxExpr
*clause
= (wxExpr
*)node
->Data();
514 wxString
functor(clause
->Functor());
516 wxItemResource
*item
= (wxItemResource
*) NULL
;
517 if (functor
== "dialog")
518 item
= wxResourceInterpretDialog(table
, clause
);
519 else if (functor
== "panel")
520 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
521 else if (functor
== "menubar")
522 item
= wxResourceInterpretMenuBar(table
, clause
);
523 else if (functor
== "menu")
524 item
= wxResourceInterpretMenu(table
, clause
);
525 else if (functor
== "string")
526 item
= wxResourceInterpretString(table
, clause
);
527 else if (functor
== "bitmap")
528 item
= wxResourceInterpretBitmap(table
, clause
);
529 else if (functor
== "icon")
530 item
= wxResourceInterpretIcon(table
, clause
);
534 // Remove any existing resource of same name
535 if (item
->GetName() != "")
536 table
.DeleteResource(item
->GetName());
537 table
.AddResource(item
);
544 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
545 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
546 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
547 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
548 "wxChoice", "wxComboBox" } ;
549 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
551 static bool wxIsValidControlClass(const wxString
& c
)
554 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
556 if ( c
== g_ValidControlClasses
[i
] )
562 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
564 wxItemResource
*dialogItem
= new wxItemResource
;
566 dialogItem
->SetType("wxPanel");
568 dialogItem
->SetType("wxDialog");
572 wxString backColourHex
= "";
573 wxString labelColourHex
= "";
574 wxString buttonColourHex
= "";
576 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
580 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
582 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
583 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
584 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
585 expr
->GetAttributeValue("style", style
);
586 expr
->GetAttributeValue("name", name
);
587 expr
->GetAttributeValue("title", title
);
588 expr
->GetAttributeValue("x", x
);
589 expr
->GetAttributeValue("y", y
);
590 expr
->GetAttributeValue("width", width
);
591 expr
->GetAttributeValue("height", height
);
592 expr
->GetAttributeValue("modal", isModal
);
593 expr
->GetAttributeValue("label_font", &labelFontExpr
);
594 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
595 expr
->GetAttributeValue("font", &fontExpr
);
596 expr
->GetAttributeValue("background_colour", backColourHex
);
597 expr
->GetAttributeValue("label_colour", labelColourHex
);
598 expr
->GetAttributeValue("button_colour", buttonColourHex
);
600 int useDialogUnits
= 0;
601 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
602 if (useDialogUnits
!= 0)
603 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
606 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
607 if (useDefaults
!= 0)
608 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
611 expr
->GetAttributeValue("id", id
);
612 dialogItem
->SetId(id
);
616 windowStyle
= wxParseWindowStyle(style
);
618 dialogItem
->SetStyle(windowStyle
);
619 dialogItem
->SetValue1(isModal
);
620 dialogItem
->SetName(name
);
621 dialogItem
->SetTitle(title
);
622 dialogItem
->SetSize(x
, y
, width
, height
);
624 if (backColourHex
!= "")
629 r
= wxHexToDec(backColourHex
.Mid(0, 2));
630 g
= wxHexToDec(backColourHex
.Mid(2, 2));
631 b
= wxHexToDec(backColourHex
.Mid(4, 2));
632 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
634 if (labelColourHex
!= "")
639 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
640 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
641 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
642 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
644 if (buttonColourHex
!= "")
649 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
650 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
651 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
652 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
656 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
657 else if (buttonFontExpr
)
658 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
659 else if (labelFontExpr
)
660 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
662 // Now parse all controls
663 wxExpr
*controlExpr
= expr
->GetFirst();
666 if (controlExpr
->Number() == 3)
668 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
669 if (controlKeyword
!= "" && controlKeyword
== "control")
671 // The value part: always a list.
672 wxExpr
*listExpr
= controlExpr
->Nth(2);
673 if (listExpr
->Type() == PrologList
)
675 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
678 dialogItem
->GetChildren().Append(controlItem
);
683 controlExpr
= controlExpr
->GetNext();
688 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
690 wxItemResource
*controlItem
= new wxItemResource
;
692 // First, find the standard features of a control definition:
693 // [optional integer/string id], control name, title, style, name, x, y, width, height
695 wxString controlType
;
700 long windowStyle
= 0;
701 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
704 wxExpr
*expr1
= expr
->Nth(0);
706 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
708 if ( wxIsValidControlClass(expr1
->StringValue()) )
711 controlType
= expr1
->StringValue();
715 wxString
str(expr1
->StringValue());
716 id
= wxResourceGetIdentifier(str
, &table
);
719 wxLogWarning(_("Could not resolve control class or id '%s'. "
720 "Use (non-zero) integer instead\n or provide #define "
721 "(see manual for caveats)"),
722 (const char*) expr1
->StringValue());
724 return (wxItemResource
*) NULL
;
728 // Success - we have an id, so the 2nd element must be the control class.
729 controlType
= expr
->Nth(1)->StringValue();
734 else if (expr1
->Type() == PrologInteger
)
736 id
= (int)expr1
->IntegerValue();
737 // Success - we have an id, so the 2nd element must be the control class.
738 controlType
= expr
->Nth(1)->StringValue();
742 expr1
= expr
->Nth(count
);
745 title
= expr1
->StringValue();
747 expr1
= expr
->Nth(count
);
751 style
= expr1
->StringValue();
752 windowStyle
= wxParseWindowStyle(style
);
755 expr1
= expr
->Nth(count
);
758 name
= expr1
->StringValue();
760 expr1
= expr
->Nth(count
);
763 x
= (int)expr1
->IntegerValue();
765 expr1
= expr
->Nth(count
);
768 y
= (int)expr1
->IntegerValue();
770 expr1
= expr
->Nth(count
);
773 width
= (int)expr1
->IntegerValue();
775 expr1
= expr
->Nth(count
);
778 height
= (int)expr1
->IntegerValue();
780 controlItem
->SetStyle(windowStyle
);
781 controlItem
->SetName(name
);
782 controlItem
->SetTitle(title
);
783 controlItem
->SetSize(x
, y
, width
, height
);
784 controlItem
->SetType(controlType
);
785 controlItem
->SetId(id
);
787 if (controlType
== "wxButton")
789 // Check for bitmap resource name
790 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
792 wxString
str(expr
->Nth(count
)->StringValue());
793 controlItem
->SetValue4(str
);
795 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
796 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
799 else if (controlType
== "wxCheckBox")
801 // Check for default value
802 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
804 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
806 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
807 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
810 #if wxUSE_RADIOBUTTON
811 else if (controlType
== "wxRadioButton")
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
)));
823 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
825 // Check for default value
826 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
828 wxString
str(expr
->Nth(count
)->StringValue());
829 controlItem
->SetValue4(str
);
832 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
834 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
835 // Do nothing - no label font any more
837 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
838 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
842 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
844 // Check for bitmap resource name
845 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
847 wxString
str(expr
->Nth(count
)->StringValue());
848 controlItem
->SetValue4(str
);
850 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
851 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
854 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
856 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
857 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
859 else if (controlType
== "wxGauge")
861 // Check for default value
862 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
864 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
868 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
870 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
873 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
875 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
879 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
880 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
885 else if (controlType
== "wxSlider")
887 // Check for default value
888 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
890 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
894 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
896 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
900 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
902 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
905 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
907 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
911 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
912 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
918 else if (controlType
== "wxScrollBar")
921 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
923 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
927 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
929 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
933 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
935 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
939 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
940 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
945 else if (controlType
== "wxListBox")
947 wxExpr
*valueList
= (wxExpr
*) NULL
;
949 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
951 wxStringList stringList
;
952 wxExpr
*stringExpr
= valueList
->GetFirst();
955 stringList
.Add(stringExpr
->StringValue());
956 stringExpr
= stringExpr
->GetNext();
958 controlItem
->SetStringValues(stringList
);
961 // Check for wxSINGLE/wxMULTIPLE
962 wxExpr
*mult
= (wxExpr
*) NULL
;
963 controlItem
->SetValue1(wxLB_SINGLE
);
964 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
966 wxString
m(mult
->StringValue());
967 if (m
== "wxMULTIPLE")
968 controlItem
->SetValue1(wxLB_MULTIPLE
);
969 else if (m
== "wxEXTENDED")
970 controlItem
->SetValue1(wxLB_EXTENDED
);
972 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
974 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
976 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
977 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
982 else if (controlType
== "wxChoice")
984 wxExpr
*valueList
= (wxExpr
*) NULL
;
985 // Check for default value list
986 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
988 wxStringList stringList
;
989 wxExpr
*stringExpr
= valueList
->GetFirst();
992 stringList
.Add(stringExpr
->StringValue());
993 stringExpr
= stringExpr
->GetNext();
995 controlItem
->SetStringValues(stringList
);
999 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1001 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1004 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1005 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1010 else if (controlType
== "wxComboBox")
1012 wxExpr
*textValue
= expr
->Nth(count
);
1013 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1015 wxString
str(textValue
->StringValue());
1016 controlItem
->SetValue4(str
);
1020 wxExpr
*valueList
= (wxExpr
*) NULL
;
1021 // Check for default value list
1022 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1024 wxStringList stringList
;
1025 wxExpr
*stringExpr
= valueList
->GetFirst();
1028 stringList
.Add(stringExpr
->StringValue());
1029 stringExpr
= stringExpr
->GetNext();
1031 controlItem
->SetStringValues(stringList
);
1035 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1037 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1040 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1041 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1048 else if (controlType
== "wxRadioBox")
1050 wxExpr
*valueList
= (wxExpr
*) NULL
;
1051 // Check for default value list
1052 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1054 wxStringList stringList
;
1055 wxExpr
*stringExpr
= valueList
->GetFirst();
1058 stringList
.Add(stringExpr
->StringValue());
1059 stringExpr
= stringExpr
->GetNext();
1061 controlItem
->SetStringValues(stringList
);
1064 // majorDim (number of rows or cols)
1065 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1067 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1071 controlItem
->SetValue1(0);
1073 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1075 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1078 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1079 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1087 return (wxItemResource
*) NULL
;
1092 // Forward declaration
1093 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1096 * Interpet a menu item
1099 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1101 wxItemResource
*item
= new wxItemResource
;
1103 wxExpr
*labelExpr
= expr
->Nth(0);
1104 wxExpr
*idExpr
= expr
->Nth(1);
1105 wxExpr
*helpExpr
= expr
->Nth(2);
1106 wxExpr
*checkableExpr
= expr
->Nth(3);
1108 // Further keywords/attributes to follow sometime...
1109 if (expr
->Number() == 0)
1111 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1112 item
->SetType("wxMenuSeparator");
1117 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1118 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1121 wxString
str(labelExpr
->StringValue());
1122 item
->SetTitle(str
);
1127 // If a string or word, must look up in identifier table.
1128 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1130 wxString
str(idExpr
->StringValue());
1131 id
= wxResourceGetIdentifier(str
, &table
);
1134 wxLogWarning(_("Could not resolve menu id '%s'. "
1135 "Use (non-zero) integer instead\n"
1136 "or provide #define (see manual for caveats)"),
1137 (const char*) idExpr
->StringValue());
1140 else if (idExpr
->Type() == PrologInteger
)
1141 id
= (int)idExpr
->IntegerValue();
1142 item
->SetValue1(id
);
1146 wxString
str(helpExpr
->StringValue());
1147 item
->SetValue4(str
);
1150 item
->SetValue2(checkableExpr
->IntegerValue());
1152 // Find the first expression that's a list, for submenu
1153 wxExpr
*subMenuExpr
= expr
->GetFirst();
1154 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1155 subMenuExpr
= subMenuExpr
->GetNext();
1159 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1160 item
->GetChildren().Append(child
);
1161 subMenuExpr
= subMenuExpr
->GetNext();
1168 * Interpret a nested list as a menu
1171 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1173 wxItemResource *menu = new wxItemResource;
1174 // menu->SetType(wxTYPE_MENU);
1175 menu->SetType("wxMenu");
1176 wxExpr *element = expr->GetFirst();
1179 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1181 menu->GetChildren().Append(item);
1182 element = element->GetNext();
1188 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1190 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1191 expr
->GetAttributeValue("menu", &listExpr
);
1193 return (wxItemResource
*) NULL
;
1195 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1198 return (wxItemResource
*) NULL
;
1201 if (expr
->GetAttributeValue("name", name
))
1203 menuResource
->SetName(name
);
1206 return menuResource
;
1209 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1211 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1212 expr
->GetAttributeValue("menu", &listExpr
);
1214 return (wxItemResource
*) NULL
;
1216 wxItemResource
*resource
= new wxItemResource
;
1217 resource
->SetType("wxMenu");
1218 // resource->SetType(wxTYPE_MENU);
1220 wxExpr
*element
= listExpr
->GetFirst();
1223 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1224 resource
->GetChildren().Append(menuResource
);
1225 element
= element
->GetNext();
1229 if (expr
->GetAttributeValue("name", name
))
1231 resource
->SetName(name
);
1237 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1239 return (wxItemResource
*) NULL
;
1242 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1244 wxItemResource
*bitmapItem
= new wxItemResource
;
1245 // bitmapItem->SetType(wxTYPE_BITMAP);
1246 bitmapItem
->SetType("wxBitmap");
1248 if (expr
->GetAttributeValue("name", name
))
1250 bitmapItem
->SetName(name
);
1252 // Now parse all bitmap specifications
1253 wxExpr
*bitmapExpr
= expr
->GetFirst();
1256 if (bitmapExpr
->Number() == 3)
1258 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1259 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1261 // The value part: always a list.
1262 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1263 if (listExpr
->Type() == PrologList
)
1265 wxItemResource
*bitmapSpec
= new wxItemResource
;
1266 // bitmapSpec->SetType(wxTYPE_BITMAP);
1267 bitmapSpec
->SetType("wxBitmap");
1269 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1270 // where everything after 'filename' is optional.
1271 wxExpr
*nameExpr
= listExpr
->Nth(0);
1272 wxExpr
*typeExpr
= listExpr
->Nth(1);
1273 wxExpr
*platformExpr
= listExpr
->Nth(2);
1274 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1275 wxExpr
*xresExpr
= listExpr
->Nth(4);
1276 wxExpr
*yresExpr
= listExpr
->Nth(5);
1277 if (nameExpr
&& nameExpr
->StringValue())
1279 bitmapSpec
->SetName(nameExpr
->StringValue());
1281 if (typeExpr
&& typeExpr
->StringValue())
1283 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1286 bitmapSpec
->SetValue1(0);
1288 if (platformExpr
&& platformExpr
->StringValue())
1290 wxString
plat(platformExpr
->StringValue());
1291 if (plat
== "windows" || plat
== "WINDOWS")
1292 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1293 else if (plat
== "x" || plat
== "X")
1294 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1295 else if (plat
== "mac" || plat
== "MAC")
1296 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1298 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1301 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1304 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1308 xres
= (int)xresExpr
->IntegerValue();
1310 yres
= (int)yresExpr
->IntegerValue();
1311 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1313 bitmapItem
->GetChildren().Append(bitmapSpec
);
1317 bitmapExpr
= bitmapExpr
->GetNext();
1323 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1325 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1328 // item->SetType(wxTYPE_ICON);
1329 item
->SetType("wxIcon");
1333 return (wxItemResource
*) NULL
;
1336 // Interpret list expression as a font
1337 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1339 if (expr
->Type() != PrologList
)
1343 int family
= wxSWISS
;
1344 int style
= wxNORMAL
;
1345 int weight
= wxNORMAL
;
1347 wxString
faceName("");
1349 wxExpr
*pointExpr
= expr
->Nth(0);
1350 wxExpr
*familyExpr
= expr
->Nth(1);
1351 wxExpr
*styleExpr
= expr
->Nth(2);
1352 wxExpr
*weightExpr
= expr
->Nth(3);
1353 wxExpr
*underlineExpr
= expr
->Nth(4);
1354 wxExpr
*faceNameExpr
= expr
->Nth(5);
1356 point
= (int)pointExpr
->IntegerValue();
1361 str
= familyExpr
->StringValue();
1362 family
= (int)wxParseWindowStyle(str
);
1366 str
= styleExpr
->StringValue();
1367 style
= (int)wxParseWindowStyle(str
);
1371 str
= weightExpr
->StringValue();
1372 weight
= (int)wxParseWindowStyle(str
);
1375 underline
= (int)underlineExpr
->IntegerValue();
1377 faceName
= faceNameExpr
->StringValue();
1379 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1384 * (Re)allocate buffer for reading in from resource file
1387 bool wxReallocateResourceBuffer()
1389 if (!wxResourceBuffer
)
1391 wxResourceBufferSize
= 1000;
1392 wxResourceBuffer
= new char[wxResourceBufferSize
];
1395 if (wxResourceBuffer
)
1397 long newSize
= wxResourceBufferSize
+ 1000;
1398 char *tmp
= new char[(int)newSize
];
1399 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1400 delete[] wxResourceBuffer
;
1401 wxResourceBuffer
= tmp
;
1402 wxResourceBufferSize
= newSize
;
1407 static bool wxEatWhiteSpace(FILE *fd
)
1410 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1417 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1419 // Check for comment
1425 bool finished
= FALSE
;
1433 int newCh
= getc(fd
);
1448 return wxEatWhiteSpace(fd
);
1451 bool wxGetResourceToken(FILE *fd
)
1453 if (!wxResourceBuffer
)
1454 wxReallocateResourceBuffer();
1455 wxResourceBuffer
[0] = 0;
1456 wxEatWhiteSpace(fd
);
1462 wxResourceBufferCount
= 0;
1469 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1472 // Escaped characters
1473 else if (ch
== '\\')
1475 int newCh
= getc(fd
);
1478 else if (newCh
== 10)
1486 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1487 wxReallocateResourceBuffer();
1488 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1489 wxResourceBufferCount
++;
1492 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1496 wxResourceBufferCount
= 0;
1498 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1500 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1501 wxReallocateResourceBuffer();
1502 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1503 wxResourceBufferCount
++;
1507 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1515 * Files are in form:
1516 static char *name = "....";
1517 with possible comments.
1520 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1523 table
= wxDefaultResourceTable
;
1525 // static or #define
1526 if (!wxGetResourceToken(fd
))
1532 if (strcmp(wxResourceBuffer
, "#define") == 0)
1534 wxGetResourceToken(fd
);
1535 char *name
= copystring(wxResourceBuffer
);
1536 wxGetResourceToken(fd
);
1537 char *value
= copystring(wxResourceBuffer
);
1538 if (isalpha(value
[0]))
1540 int val
= (int)atol(value
);
1541 wxResourceAddIdentifier(name
, val
, table
);
1545 wxLogWarning(_("#define %s must be an integer."), name
);
1555 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1557 wxGetResourceToken(fd
);
1558 char *name
= copystring(wxResourceBuffer
);
1559 char *actualName
= name
;
1561 actualName
= name
+ 1;
1562 int len
= strlen(name
);
1563 if ((len
> 0) && (name
[len
-1] == '"'))
1565 if (!wxResourceParseIncludeFile(actualName
, table
))
1567 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1572 else if (strcmp(wxResourceBuffer
, "static") != 0)
1575 strcpy(buf
, _("Found "));
1576 strncat(buf
, wxResourceBuffer
, 30);
1577 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1583 if (!wxGetResourceToken(fd
))
1585 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1590 if (strcmp(wxResourceBuffer
, "char") != 0)
1592 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1597 if (!wxGetResourceToken(fd
))
1599 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1604 if (wxResourceBuffer
[0] != '*')
1606 wxLogWarning(_("Expected '*' whilst parsing resource."));
1610 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1613 if (!wxGetResourceToken(fd
))
1615 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1620 if (strcmp(wxResourceBuffer
, "=") != 0)
1622 wxLogWarning(_("Expected '=' whilst parsing resource."));
1627 if (!wxGetResourceToken(fd
))
1629 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1635 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1637 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1642 if (!wxGetResourceToken(fd
))
1650 * Parses string window style into integer window style
1654 * Style flag parsing, e.g.
1655 * "wxSYSTEM_MENU | wxBORDER" -> integer
1658 char* wxResourceParseWord(char*s
, int *i
)
1661 return (char*) NULL
;
1663 static char buf
[150];
1664 int len
= strlen(s
);
1667 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1675 // Eat whitespace and conjunction characters
1676 while ((ii
< len
) &&
1677 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1683 return (char*) NULL
;
1688 struct wxResourceBitListStruct
1694 static wxResourceBitListStruct wxResourceBitListTable
[] =
1697 { "wxSINGLE", wxLB_SINGLE
},
1698 { "wxMULTIPLE", wxLB_MULTIPLE
},
1699 { "wxEXTENDED", wxLB_EXTENDED
},
1700 { "wxLB_SINGLE", wxLB_SINGLE
},
1701 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1702 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1703 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1704 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1705 { "wxLB_SORT", wxLB_SORT
},
1706 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1707 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1710 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1711 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1712 { "wxCB_READONLY", wxCB_READONLY
},
1713 { "wxCB_SORT", wxCB_SORT
},
1716 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1717 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1718 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1721 { "wxPASSWORD", wxPASSWORD
},
1722 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1723 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1724 { "wxTE_READONLY", wxTE_READONLY
},
1725 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1726 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1728 /* wxRadioBox/wxRadioButton */
1729 { "wxRB_GROUP", wxRB_GROUP
},
1730 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1731 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1734 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1735 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1736 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1737 { "wxSL_LABELS", wxSL_LABELS
},
1738 { "wxSL_LEFT", wxSL_LEFT
},
1739 { "wxSL_TOP", wxSL_TOP
},
1740 { "wxSL_RIGHT", wxSL_RIGHT
},
1741 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1742 { "wxSL_BOTH", wxSL_BOTH
},
1743 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1746 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1747 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1750 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1751 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1754 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1755 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1756 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1759 { "wxLC_ICON", wxLC_ICON
},
1760 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1761 { "wxLC_LIST", wxLC_LIST
},
1762 { "wxLC_REPORT", wxLC_REPORT
},
1763 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1764 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1765 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1766 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1767 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1768 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1769 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1770 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1771 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1772 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1775 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1776 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1777 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1778 { "wxSP_WRAP", wxSP_WRAP
},
1781 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1782 { "wxSP_3D", wxSP_3D
},
1783 { "wxSP_BORDER", wxSP_BORDER
},
1786 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1787 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1788 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1789 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1792 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1795 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1796 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1797 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1798 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1799 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1800 { "wxCOLOURED", wxCOLOURED
},
1803 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1804 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1805 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1806 { "wxTB_FLAT", wxTB_FLAT
},
1809 { "wxVSCROLL", wxVSCROLL
},
1810 { "wxHSCROLL", wxHSCROLL
},
1811 { "wxCAPTION", wxCAPTION
},
1812 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1813 { "wxICONIZE", wxICONIZE
},
1814 { "wxMINIMIZE", wxICONIZE
},
1815 { "wxMAXIMIZE", wxMAXIMIZE
},
1817 { "wxMDI_PARENT", 0},
1818 { "wxMDI_CHILD", 0},
1819 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1820 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1821 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1822 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1823 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1824 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1825 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1826 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1827 { "wxBORDER", wxBORDER
},
1828 { "wxRETAINED", wxRETAINED
},
1829 { "wxNATIVE_IMPL", 0},
1830 { "wxEXTENDED_IMPL", 0},
1831 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1832 // { "wxFLAT", wxFLAT},
1833 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1834 { "wxFIXED_LENGTH", 0},
1835 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1836 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1837 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1838 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1839 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1840 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1841 { "wxNO_BORDER", wxNO_BORDER
},
1842 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1844 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1845 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1847 // Text font families
1848 { "wxDEFAULT", wxDEFAULT
},
1849 { "wxDECORATIVE", wxDECORATIVE
},
1850 { "wxROMAN", wxROMAN
},
1851 { "wxSCRIPT", wxSCRIPT
},
1852 { "wxSWISS", wxSWISS
},
1853 { "wxMODERN", wxMODERN
},
1854 { "wxTELETYPE", wxTELETYPE
},
1855 { "wxVARIABLE", wxVARIABLE
},
1856 { "wxFIXED", wxFIXED
},
1857 { "wxNORMAL", wxNORMAL
},
1858 { "wxLIGHT", wxLIGHT
},
1859 { "wxBOLD", wxBOLD
},
1860 { "wxITALIC", wxITALIC
},
1861 { "wxSLANT", wxSLANT
},
1862 { "wxSOLID", wxSOLID
},
1864 { "wxLONG_DASH", wxLONG_DASH
},
1865 { "wxSHORT_DASH", wxSHORT_DASH
},
1866 { "wxDOT_DASH", wxDOT_DASH
},
1867 { "wxUSER_DASH", wxUSER_DASH
},
1868 { "wxTRANSPARENT", wxTRANSPARENT
},
1869 { "wxSTIPPLE", wxSTIPPLE
},
1870 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1871 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1872 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1873 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1874 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1875 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1876 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1877 { "wxJOIN_MITER", wxJOIN_MITER
},
1878 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1879 { "wxCAP_ROUND", wxCAP_ROUND
},
1880 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1881 { "wxCAP_BUTT", wxCAP_BUTT
},
1884 { "wxCLEAR", wxCLEAR
},
1886 { "wxINVERT", wxINVERT
},
1887 { "wxOR_REVERSE", wxOR_REVERSE
},
1888 { "wxAND_REVERSE", wxAND_REVERSE
},
1889 { "wxCOPY", wxCOPY
},
1891 { "wxAND_INVERT", wxAND_INVERT
},
1892 { "wxNO_OP", wxNO_OP
},
1894 { "wxEQUIV", wxEQUIV
},
1895 { "wxSRC_INVERT", wxSRC_INVERT
},
1896 { "wxOR_INVERT", wxOR_INVERT
},
1897 { "wxNAND", wxNAND
},
1901 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1902 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1903 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1904 { "wxWINDING_RULE", wxWINDING_RULE
},
1905 { "wxHORIZONTAL", wxHORIZONTAL
},
1906 { "wxVERTICAL", wxVERTICAL
},
1907 { "wxBOTH", wxBOTH
},
1908 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1910 { "wxYES_NO", wxYES_NO
},
1911 { "wxCANCEL", wxCANCEL
},
1914 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1915 { "wxICON_HAND", wxICON_HAND
},
1916 { "wxICON_QUESTION", wxICON_QUESTION
},
1917 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1918 { "wxICON_STOP", wxICON_STOP
},
1919 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1920 { "wxICON_MASK", wxICON_MASK
},
1921 { "wxCENTRE", wxCENTRE
},
1922 { "wxCENTER", wxCENTRE
},
1923 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1924 { "wxVERTICAL_LABEL", 0},
1925 { "wxHORIZONTAL_LABEL", 0},
1927 // Bitmap types (not strictly styles)
1928 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1929 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1930 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1931 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1932 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1933 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1934 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1935 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1936 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1937 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1938 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1939 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1940 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1941 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1944 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
1946 long wxParseWindowStyle(const wxString
& bitListString
)
1951 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
1955 for (j
= 0; j
< wxResourceBitListCount
; j
++)
1956 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
1958 bitList
|= wxResourceBitListTable
[j
].bits
;
1964 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
1972 * Load a bitmap from a wxWindows resource, choosing an optimum
1973 * depth and appropriate type.
1976 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
1979 table
= wxDefaultResourceTable
;
1981 wxItemResource
*item
= table
->FindResource(resource
);
1984 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
1986 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
1987 return wxNullBitmap
;
1989 int thisDepth
= wxDisplayDepth();
1990 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
1992 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
1994 // Try to find optimum bitmap for this platform/colour depth
1995 wxNode
*node
= item
->GetChildren().First();
1998 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1999 int platform
= (int)child
->GetValue2();
2000 int noColours
= (int)child
->GetValue3();
2002 char *name = child->GetName();
2003 int bitmapType = (int)child->GetValue1();
2004 int xRes = child->GetWidth();
2005 int yRes = child->GetHeight();
2010 case RESOURCE_PLATFORM_ANY
:
2012 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2013 optResource
= child
;
2016 // Maximise the number of colours.
2017 // If noColours is zero (unspecified), then assume this
2018 // is the right one.
2019 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2020 optResource
= child
;
2025 case RESOURCE_PLATFORM_WINDOWS
:
2027 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2028 optResource
= child
;
2031 // Maximise the number of colours
2032 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2033 optResource
= child
;
2039 case RESOURCE_PLATFORM_X
:
2041 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2042 optResource
= child
;
2045 // Maximise the number of colours
2046 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2047 optResource
= child
;
2053 case RESOURCE_PLATFORM_MAC
:
2055 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2056 optResource
= child
;
2059 // Maximise the number of colours
2060 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2061 optResource
= child
;
2069 node
= node
->Next();
2071 // If no matching resource, fail.
2073 return wxNullBitmap
;
2075 wxString name
= optResource
->GetName();
2076 int bitmapType
= (int)optResource
->GetValue1();
2079 case wxBITMAP_TYPE_XBM_DATA
:
2082 wxItemResource
*item
= table
->FindResource(name
);
2085 wxLogWarning(_("Failed to find XBM resource %s.\n"
2086 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2087 return (wxBitmap
*) NULL
;
2089 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2091 wxLogWarning(_("No XBM facility available!"));
2095 case wxBITMAP_TYPE_XPM_DATA
:
2097 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2098 wxItemResource
*item
= table
->FindResource(name
);
2101 wxLogWarning(_("Failed to find XPM resource %s.\n"
2102 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2103 return (wxBitmap
*) NULL
;
2105 return wxBitmap(item
->GetValue1());
2107 wxLogWarning(_("No XPM facility available!"));
2113 return wxBitmap(name
, bitmapType
);
2117 return wxNullBitmap
;
2121 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2122 return wxNullBitmap
;
2127 * Load an icon from a wxWindows resource, choosing an optimum
2128 * depth and appropriate type.
2131 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2134 table
= wxDefaultResourceTable
;
2136 wxItemResource
*item
= table
->FindResource(resource
);
2139 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2141 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2144 int thisDepth
= wxDisplayDepth();
2145 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2147 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2149 // Try to find optimum icon for this platform/colour depth
2150 wxNode
*node
= item
->GetChildren().First();
2153 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2154 int platform
= (int)child
->GetValue2();
2155 int noColours
= (int)child
->GetValue3();
2157 char *name = child->GetName();
2158 int bitmapType = (int)child->GetValue1();
2159 int xRes = child->GetWidth();
2160 int yRes = child->GetHeight();
2165 case RESOURCE_PLATFORM_ANY
:
2167 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2168 optResource
= child
;
2171 // Maximise the number of colours.
2172 // If noColours is zero (unspecified), then assume this
2173 // is the right one.
2174 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2175 optResource
= child
;
2180 case RESOURCE_PLATFORM_WINDOWS
:
2182 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2183 optResource
= child
;
2186 // Maximise the number of colours
2187 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2188 optResource
= child
;
2194 case RESOURCE_PLATFORM_X
:
2196 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2197 optResource
= child
;
2200 // Maximise the number of colours
2201 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2202 optResource
= child
;
2208 case RESOURCE_PLATFORM_MAC
:
2210 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2211 optResource
= child
;
2214 // Maximise the number of colours
2215 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2216 optResource
= child
;
2224 node
= node
->Next();
2226 // If no matching resource, fail.
2230 wxString name
= optResource
->GetName();
2231 int bitmapType
= (int)optResource
->GetValue1();
2234 case wxBITMAP_TYPE_XBM_DATA
:
2237 wxItemResource
*item
= table
->FindResource(name
);
2240 wxLogWarning(_("Failed to find XBM resource %s.\n"
2241 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2242 return (wxIcon
*) NULL
;
2244 return wxIcon((char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2246 wxLogWarning(_("No XBM facility available!"));
2250 case wxBITMAP_TYPE_XPM_DATA
:
2252 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2254 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2255 wxItemResource *item = table->FindResource(name);
2259 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2263 return wxIcon((char **)item->GetValue1());
2265 wxLogWarning(_("No XPM facility available!"));
2268 wxLogWarning(_("No XPM icon facility available!"));
2274 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2276 return wxIcon(name
, bitmapType
);
2285 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2286 return (wxIcon
*) NULL
;
2290 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2292 wxMenu
*menu
= new wxMenu
;
2293 wxNode
*node
= item
->GetChildren().First();
2296 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2297 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2298 menu
->AppendSeparator();
2299 else if (child
->GetChildren().Number() > 0)
2301 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2303 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2307 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2309 node
= node
->Next();
2314 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2317 table
= wxDefaultResourceTable
;
2319 wxItemResource
*menuResource
= table
->FindResource(resource
);
2320 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2323 menuBar
= new wxMenuBar
;
2324 wxNode
*node
= menuResource
->GetChildren().First();
2327 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2328 wxMenu
*menu
= wxResourceCreateMenu(child
);
2330 menuBar
->Append(menu
, child
->GetTitle());
2331 node
= node
->Next();
2335 return (wxMenuBar
*) NULL
;
2338 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2341 table
= wxDefaultResourceTable
;
2343 wxItemResource
*menuResource
= table
->FindResource(resource
);
2344 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2345 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2346 return wxResourceCreateMenu(menuResource
);
2347 return (wxMenu
*) NULL
;
2350 // Global equivalents (so don't have to refer to default table explicitly)
2351 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2354 table
= wxDefaultResourceTable
;
2356 return table
->ParseResourceData(resource
);
2359 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2362 table
= wxDefaultResourceTable
;
2364 return table
->ParseResourceFile(filename
);
2367 // Register XBM/XPM data
2368 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2371 table
= wxDefaultResourceTable
;
2373 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2376 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2379 table
= wxDefaultResourceTable
;
2381 return table
->RegisterResourceBitmapData(name
, data
);
2384 void wxResourceClear(wxResourceTable
*table
)
2387 table
= wxDefaultResourceTable
;
2389 table
->ClearTable();
2396 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2399 table
= wxDefaultResourceTable
;
2401 table
->identifiers
.Put(name
, (wxObject
*)value
);
2405 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2408 table
= wxDefaultResourceTable
;
2410 return (int)table
->identifiers
.Get(name
);
2414 * Parse #include file for #defines (only)
2417 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2420 table
= wxDefaultResourceTable
;
2422 FILE *fd
= fopen(f
, "r");
2427 while (wxGetResourceToken(fd
))
2429 if (strcmp(wxResourceBuffer
, "#define") == 0)
2431 wxGetResourceToken(fd
);
2432 char *name
= copystring(wxResourceBuffer
);
2433 wxGetResourceToken(fd
);
2434 char *value
= copystring(wxResourceBuffer
);
2435 if (isdigit(value
[0]))
2437 int val
= (int)atol(value
);
2438 wxResourceAddIdentifier(name
, val
, table
);
2449 * Reading strings as if they were .wxr files
2452 static int getc_string(char *s
)
2454 int ch
= s
[wxResourceStringPtr
];
2459 wxResourceStringPtr
++;
2464 static int ungetc_string()
2466 wxResourceStringPtr
--;
2470 bool wxEatWhiteSpaceString(char *s
)
2472 int ch
= getc_string(s
);
2476 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2483 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2484 ch
= getc_string(s
);
2485 // Check for comment
2488 ch
= getc_string(s
);
2491 bool finished
= FALSE
;
2494 ch
= getc_string(s
);
2499 int newCh
= getc_string(s
);
2514 return wxEatWhiteSpaceString(s
);
2517 bool wxGetResourceTokenString(char *s
)
2519 if (!wxResourceBuffer
)
2520 wxReallocateResourceBuffer();
2521 wxResourceBuffer
[0] = 0;
2522 wxEatWhiteSpaceString(s
);
2524 int ch
= getc_string(s
);
2528 wxResourceBufferCount
= 0;
2529 ch
= getc_string(s
);
2535 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2538 // Escaped characters
2539 else if (ch
== '\\')
2541 int newCh
= getc_string(s
);
2544 else if (newCh
== 10)
2552 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2553 wxReallocateResourceBuffer();
2554 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2555 wxResourceBufferCount
++;
2556 ch
= getc_string(s
);
2558 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2562 wxResourceBufferCount
= 0;
2564 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2566 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2567 wxReallocateResourceBuffer();
2568 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2569 wxResourceBufferCount
++;
2571 ch
= getc_string(s
);
2573 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2581 * Files are in form:
2582 static char *name = "....";
2583 with possible comments.
2586 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2589 table
= wxDefaultResourceTable
;
2591 // static or #define
2592 if (!wxGetResourceTokenString(s
))
2598 if (strcmp(wxResourceBuffer
, "#define") == 0)
2600 wxGetResourceTokenString(s
);
2601 char *name
= copystring(wxResourceBuffer
);
2602 wxGetResourceTokenString(s
);
2603 char *value
= copystring(wxResourceBuffer
);
2604 if (isalpha(value
[0]))
2606 int val
= (int)atol(value
);
2607 wxResourceAddIdentifier(name
, val
, table
);
2611 wxLogWarning(_("#define %s must be an integer."), name
);
2622 else if (strcmp(wxResourceBuffer, "#include") == 0)
2624 wxGetResourceTokenString(s);
2625 char *name = copystring(wxResourceBuffer);
2626 char *actualName = name;
2628 actualName = name + 1;
2629 int len = strlen(name);
2630 if ((len > 0) && (name[len-1] == '"'))
2632 if (!wxResourceParseIncludeFile(actualName, table))
2635 sprintf(buf, _("Could not find resource include file %s."), actualName);
2642 else if (strcmp(wxResourceBuffer
, "static") != 0)
2645 strcpy(buf
, _("Found "));
2646 strncat(buf
, wxResourceBuffer
, 30);
2647 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2653 if (!wxGetResourceTokenString(s
))
2655 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2660 if (strcmp(wxResourceBuffer
, "char") != 0)
2662 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2667 if (!wxGetResourceTokenString(s
))
2669 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2674 if (wxResourceBuffer
[0] != '*')
2676 wxLogWarning(_("Expected '*' whilst parsing resource."));
2680 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2683 if (!wxGetResourceTokenString(s
))
2685 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2690 if (strcmp(wxResourceBuffer
, "=") != 0)
2692 wxLogWarning(_("Expected '=' whilst parsing resource."));
2697 if (!wxGetResourceTokenString(s
))
2699 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2705 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2707 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2712 if (!wxGetResourceTokenString(s
))
2719 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2722 table
= wxDefaultResourceTable
;
2727 // Turn backslashes into spaces
2730 int len
= strlen(s
);
2732 for (i
= 0; i
< len
; i
++)
2733 if (s
[i
] == 92 && s
[i
+1] == 13)
2741 wxResourceStringPtr
= 0;
2744 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2748 return wxResourceInterpretResources(*table
, db
);
2752 * resource loading facility
2755 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2758 table
= wxDefaultResourceTable
;
2760 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2761 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2762 if (!resource
|| !resource
->GetType() ||
2763 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2766 wxString
title(resource
->GetTitle());
2767 long theWindowStyle
= resource
->GetStyle();
2768 bool isModal
= (resource
->GetValue1() != 0);
2769 int x
= resource
->GetX();
2770 int y
= resource
->GetY();
2771 int width
= resource
->GetWidth();
2772 int height
= resource
->GetHeight();
2773 wxString name
= resource
->GetName();
2775 if (IsKindOf(CLASSINFO(wxDialog
)))
2777 wxDialog
*dialogBox
= (wxDialog
*)this;
2778 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2779 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2782 // Only reset the client size if we know we're not going to do it again below.
2783 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2784 dialogBox
->SetClientSize(width
, height
);
2786 else if (IsKindOf(CLASSINFO(wxPanel
)))
2788 wxPanel
* panel
= (wxPanel
*)this;
2789 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2794 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2798 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2800 // No need to do this since it's done in wxPanel or wxDialog constructor.
2801 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2805 if (resource
->GetFont().Ok())
2806 SetFont(resource
->GetFont());
2807 if (resource
->GetBackgroundColour().Ok())
2808 SetBackgroundColour(resource
->GetBackgroundColour());
2811 // Should have some kind of font at this point
2812 if (!GetFont()->Ok())
2813 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2814 if (!GetBackgroundColour().Ok())
2815 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2817 // Only when we've created the window and set the font can we set the correct size,
2818 // if based on dialog units.
2819 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2821 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2822 SetClientSize(sz
.x
, sz
.y
);
2824 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2828 // Now create children
2829 wxNode
*node
= resource
->GetChildren().First();
2832 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2834 (void) CreateItem(childResource
, resource
, table
);
2836 node
= node
->Next();
2841 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2844 table
= wxDefaultResourceTable
;
2845 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2848 #endif // wxUSE_WX_RESOURCES