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 #include "wx/settings.h"
74 // Forward (private) declarations
75 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
76 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
77 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
78 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
79 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
80 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
81 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
82 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
83 // Interpret list expression
84 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
86 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
87 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
89 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
91 static char *wxResourceBuffer
= (char *) NULL
;
92 static long wxResourceBufferSize
= 0;
93 static long wxResourceBufferCount
= 0;
94 static int wxResourceStringPtr
= 0;
96 void wxInitializeResourceSystem()
98 wxDefaultResourceTable
= new wxResourceTable
;
101 void wxCleanUpResourceSystem()
103 delete wxDefaultResourceTable
;
104 if (wxResourceBuffer
)
105 delete[] wxResourceBuffer
;
108 void wxLogWarning(char *msg
)
110 wxMessageBox(msg
, _("Warning"), wxOK
);
113 #if !USE_SHARED_LIBRARY
114 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
115 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
118 wxItemResource::wxItemResource()
124 m_x
= m_y
= m_width
= m_height
= 0;
125 m_value1
= m_value2
= m_value3
= m_value5
= 0;
131 wxItemResource::~wxItemResource()
133 wxNode
*node
= m_children
.First();
136 wxItemResource
*item
= (wxItemResource
*)node
->Data();
139 node
= m_children
.First();
147 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
151 wxResourceTable::~wxResourceTable()
156 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
158 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
162 void wxResourceTable::AddResource(wxItemResource
*item
)
164 wxString name
= item
->GetName();
166 name
= item
->GetTitle();
170 // Delete existing resource, if any.
176 bool wxResourceTable::DeleteResource(const wxString
& name
)
178 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
181 // See if any resource has this as its child; if so, delete from
182 // parent's child list.
184 wxNode
*node
= (wxNode
*) NULL
;
185 while ((node
= Next()))
187 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
188 if (parent
->GetChildren().Member(item
))
190 parent
->GetChildren().DeleteObject(item
);
202 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
206 FILE *fd
= fopen((const char*) filename
, "r");
210 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
215 return wxResourceInterpretResources(*this, db
);
218 bool wxResourceTable::ParseResourceData(const wxString
& data
)
221 if (!db
.ReadFromString(data
))
223 wxLogWarning(_("Ill-formed resource file syntax."));
227 return wxResourceInterpretResources(*this, db
);
230 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
232 // Register pre-loaded bitmap data
233 wxItemResource
*item
= new wxItemResource
;
234 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
235 item
->SetType("wxXBMData");
237 item
->SetValue1((long)bits
);
238 item
->SetValue2((long)width
);
239 item
->SetValue3((long)height
);
244 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
246 // Register pre-loaded bitmap data
247 wxItemResource
*item
= new wxItemResource
;
248 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
249 item
->SetType("wxXPMData");
251 item
->SetValue1((long)data
);
256 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
261 void wxResourceTable::ClearTable()
264 wxNode
*node
= Next();
267 wxNode
*next
= Next();
268 wxItemResource
*item
= (wxItemResource
*)node
->Data();
275 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
277 int id
= childResource
->GetId();
281 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
283 wxControl
*control
= (wxControl
*) NULL
;
284 wxString
itemType(childResource
->GetType());
290 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
291 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
295 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
296 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
299 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
301 if (childResource
->GetValue4() != "")
304 wxBitmap bitmap
= childResource
->GetBitmap();
307 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
308 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
311 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
312 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
315 // Normal, text button
316 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
317 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
319 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
320 itemType
== wxString("wxStaticBitmap"))
322 if (childResource
->GetValue4() != "")
325 wxBitmap bitmap
= childResource
->GetBitmap();
328 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
329 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
331 #if wxUSE_BITMAP_MESSAGE
333 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
334 childResource
->GetStyle(), childResource
->GetName());
339 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
340 childResource
->GetStyle(), childResource
->GetName());
343 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
345 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
346 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
348 else if (itemType
== wxString("wxCheckBox"))
350 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
351 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
353 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
356 else if (itemType
== wxString("wxGauge"))
358 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
359 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
361 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
364 #if wxUSE_RADIOBUTTON
365 else if (itemType
== wxString("wxRadioButton"))
367 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
369 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
373 else if (itemType
== wxString("wxScrollBar"))
375 control
= new wxScrollBar(parent
, id
, pos
, size
,
376 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
377 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
378 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
379 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
380 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
383 else if (itemType
== wxString("wxSlider"))
385 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
386 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
387 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
389 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
391 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
392 childResource
->GetStyle(), childResource
->GetName());
394 else if (itemType
== wxString("wxListBox"))
396 wxStringList
& stringList
= childResource
->GetStringValues();
397 wxString
*strings
= (wxString
*) NULL
;
399 if (stringList
.Number() > 0)
401 noStrings
= stringList
.Number();
402 strings
= new wxString
[noStrings
];
403 wxNode
*node
= stringList
.First();
407 strings
[i
] = (char *)node
->Data();
412 control
= new wxListBox(parent
, id
, pos
, size
,
413 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
418 else if (itemType
== wxString("wxChoice"))
420 wxStringList
& stringList
= childResource
->GetStringValues();
421 wxString
*strings
= (wxString
*) NULL
;
423 if (stringList
.Number() > 0)
425 noStrings
= stringList
.Number();
426 strings
= new wxString
[noStrings
];
427 wxNode
*node
= stringList
.First();
431 strings
[i
] = (char *)node
->Data();
436 control
= new wxChoice(parent
, id
, pos
, size
,
437 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
443 else if (itemType
== wxString("wxComboBox"))
445 wxStringList
& stringList
= childResource
->GetStringValues();
446 wxString
*strings
= (wxString
*) NULL
;
448 if (stringList
.Number() > 0)
450 noStrings
= stringList
.Number();
451 strings
= new wxString
[noStrings
];
452 wxNode
*node
= stringList
.First();
456 strings
[i
] = (char *)node
->Data();
461 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
462 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
468 else if (itemType
== wxString("wxRadioBox"))
470 wxStringList
& stringList
= childResource
->GetStringValues();
471 wxString
*strings
= (wxString
*) NULL
;
473 if (stringList
.Number() > 0)
475 noStrings
= stringList
.Number();
476 strings
= new wxString
[noStrings
];
477 wxNode
*node
= stringList
.First();
481 strings
[i
] = (char *)node
->Data();
486 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
487 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
488 childResource
->GetName());
494 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
496 // Don't set font; will be inherited from parent.
500 if (control
&& childResource
->GetFont().Ok())
501 control
->SetFont(childResource
->GetFont());
507 * Interpret database as a series of resources
510 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
512 wxNode
*node
= db
.First();
515 wxExpr
*clause
= (wxExpr
*)node
->Data();
516 wxString
functor(clause
->Functor());
518 wxItemResource
*item
= (wxItemResource
*) NULL
;
519 if (functor
== "dialog")
520 item
= wxResourceInterpretDialog(table
, clause
);
521 else if (functor
== "panel")
522 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
523 else if (functor
== "menubar")
524 item
= wxResourceInterpretMenuBar(table
, clause
);
525 else if (functor
== "menu")
526 item
= wxResourceInterpretMenu(table
, clause
);
527 else if (functor
== "string")
528 item
= wxResourceInterpretString(table
, clause
);
529 else if (functor
== "bitmap")
530 item
= wxResourceInterpretBitmap(table
, clause
);
531 else if (functor
== "icon")
532 item
= wxResourceInterpretIcon(table
, clause
);
536 // Remove any existing resource of same name
537 if (item
->GetName() != "")
538 table
.DeleteResource(item
->GetName());
539 table
.AddResource(item
);
546 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
547 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
548 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
549 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
550 "wxChoice", "wxComboBox" } ;
551 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
553 static bool wxIsValidControlClass(const wxString
& c
)
556 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
558 if ( c
== g_ValidControlClasses
[i
] )
564 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
566 wxItemResource
*dialogItem
= new wxItemResource
;
568 dialogItem
->SetType("wxPanel");
570 dialogItem
->SetType("wxDialog");
574 wxString backColourHex
= "";
575 wxString labelColourHex
= "";
576 wxString buttonColourHex
= "";
578 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
582 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
584 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
585 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
586 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
587 expr
->GetAttributeValue("style", style
);
588 expr
->GetAttributeValue("name", name
);
589 expr
->GetAttributeValue("title", title
);
590 expr
->GetAttributeValue("x", x
);
591 expr
->GetAttributeValue("y", y
);
592 expr
->GetAttributeValue("width", width
);
593 expr
->GetAttributeValue("height", height
);
594 expr
->GetAttributeValue("modal", isModal
);
595 expr
->GetAttributeValue("label_font", &labelFontExpr
);
596 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
597 expr
->GetAttributeValue("font", &fontExpr
);
598 expr
->GetAttributeValue("background_colour", backColourHex
);
599 expr
->GetAttributeValue("label_colour", labelColourHex
);
600 expr
->GetAttributeValue("button_colour", buttonColourHex
);
602 int useDialogUnits
= 0;
603 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
604 if (useDialogUnits
!= 0)
605 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
608 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
609 if (useDefaults
!= 0)
610 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
613 expr
->GetAttributeValue("id", id
);
614 dialogItem
->SetId(id
);
618 windowStyle
= wxParseWindowStyle(style
);
620 dialogItem
->SetStyle(windowStyle
);
621 dialogItem
->SetValue1(isModal
);
622 dialogItem
->SetName(name
);
623 dialogItem
->SetTitle(title
);
624 dialogItem
->SetSize(x
, y
, width
, height
);
626 if (backColourHex
!= "")
631 r
= wxHexToDec(backColourHex
.Mid(0, 2));
632 g
= wxHexToDec(backColourHex
.Mid(2, 2));
633 b
= wxHexToDec(backColourHex
.Mid(4, 2));
634 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
636 if (labelColourHex
!= "")
641 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
642 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
643 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
644 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
646 if (buttonColourHex
!= "")
651 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
652 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
653 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
654 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
658 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
659 else if (buttonFontExpr
)
660 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
661 else if (labelFontExpr
)
662 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
664 // Now parse all controls
665 wxExpr
*controlExpr
= expr
->GetFirst();
668 if (controlExpr
->Number() == 3)
670 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
671 if (controlKeyword
!= "" && controlKeyword
== "control")
673 // The value part: always a list.
674 wxExpr
*listExpr
= controlExpr
->Nth(2);
675 if (listExpr
->Type() == PrologList
)
677 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
680 dialogItem
->GetChildren().Append(controlItem
);
685 controlExpr
= controlExpr
->GetNext();
690 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
692 wxItemResource
*controlItem
= new wxItemResource
;
694 // First, find the standard features of a control definition:
695 // [optional integer/string id], control name, title, style, name, x, y, width, height
697 wxString controlType
;
702 long windowStyle
= 0;
703 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
706 wxExpr
*expr1
= expr
->Nth(0);
708 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
710 if ( wxIsValidControlClass(expr1
->StringValue()) )
713 controlType
= expr1
->StringValue();
717 wxString
str(expr1
->StringValue());
718 id
= wxResourceGetIdentifier(str
, &table
);
721 wxLogWarning(_("Could not resolve control class or id '%s'. "
722 "Use (non-zero) integer instead\n or provide #define "
723 "(see manual for caveats)"),
724 (const char*) expr1
->StringValue());
726 return (wxItemResource
*) NULL
;
730 // Success - we have an id, so the 2nd element must be the control class.
731 controlType
= expr
->Nth(1)->StringValue();
736 else if (expr1
->Type() == PrologInteger
)
738 id
= (int)expr1
->IntegerValue();
739 // Success - we have an id, so the 2nd element must be the control class.
740 controlType
= expr
->Nth(1)->StringValue();
744 expr1
= expr
->Nth(count
);
747 title
= expr1
->StringValue();
749 expr1
= expr
->Nth(count
);
753 style
= expr1
->StringValue();
754 windowStyle
= wxParseWindowStyle(style
);
757 expr1
= expr
->Nth(count
);
760 name
= expr1
->StringValue();
762 expr1
= expr
->Nth(count
);
765 x
= (int)expr1
->IntegerValue();
767 expr1
= expr
->Nth(count
);
770 y
= (int)expr1
->IntegerValue();
772 expr1
= expr
->Nth(count
);
775 width
= (int)expr1
->IntegerValue();
777 expr1
= expr
->Nth(count
);
780 height
= (int)expr1
->IntegerValue();
782 controlItem
->SetStyle(windowStyle
);
783 controlItem
->SetName(name
);
784 controlItem
->SetTitle(title
);
785 controlItem
->SetSize(x
, y
, width
, height
);
786 controlItem
->SetType(controlType
);
787 controlItem
->SetId(id
);
789 if (controlType
== "wxButton")
791 // Check for bitmap resource name
792 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
794 wxString
str(expr
->Nth(count
)->StringValue());
795 controlItem
->SetValue4(str
);
797 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
798 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
801 else if (controlType
== "wxCheckBox")
803 // Check for default value
804 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
806 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
808 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
809 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
812 #if wxUSE_RADIOBUTTON
813 else if (controlType
== "wxRadioButton")
815 // Check for default value
816 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
818 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
820 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
821 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
825 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
827 // Check for default value
828 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
830 wxString
str(expr
->Nth(count
)->StringValue());
831 controlItem
->SetValue4(str
);
834 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
836 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
837 // Do nothing - no label font any more
839 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
840 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
844 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
846 // Check for bitmap resource name
847 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
849 wxString
str(expr
->Nth(count
)->StringValue());
850 controlItem
->SetValue4(str
);
852 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
853 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
856 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
858 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
859 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
861 else if (controlType
== "wxGauge")
863 // Check for default value
864 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
866 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
870 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
872 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
875 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
877 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
881 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
882 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
887 else if (controlType
== "wxSlider")
889 // Check for default value
890 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
892 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
896 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
898 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
902 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
904 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
907 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
909 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
913 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
914 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
920 else if (controlType
== "wxScrollBar")
923 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
925 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
929 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
931 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
935 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
937 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
941 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
942 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
947 else if (controlType
== "wxListBox")
949 wxExpr
*valueList
= (wxExpr
*) NULL
;
951 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
953 wxStringList stringList
;
954 wxExpr
*stringExpr
= valueList
->GetFirst();
957 stringList
.Add(stringExpr
->StringValue());
958 stringExpr
= stringExpr
->GetNext();
960 controlItem
->SetStringValues(stringList
);
963 // Check for wxSINGLE/wxMULTIPLE
964 wxExpr
*mult
= (wxExpr
*) NULL
;
965 controlItem
->SetValue1(wxLB_SINGLE
);
966 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
968 wxString
m(mult
->StringValue());
969 if (m
== "wxMULTIPLE")
970 controlItem
->SetValue1(wxLB_MULTIPLE
);
971 else if (m
== "wxEXTENDED")
972 controlItem
->SetValue1(wxLB_EXTENDED
);
974 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
976 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
978 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
979 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
984 else if (controlType
== "wxChoice")
986 wxExpr
*valueList
= (wxExpr
*) NULL
;
987 // Check for default value list
988 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
990 wxStringList stringList
;
991 wxExpr
*stringExpr
= valueList
->GetFirst();
994 stringList
.Add(stringExpr
->StringValue());
995 stringExpr
= stringExpr
->GetNext();
997 controlItem
->SetStringValues(stringList
);
1001 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1003 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1006 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1007 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1012 else if (controlType
== "wxComboBox")
1014 wxExpr
*textValue
= expr
->Nth(count
);
1015 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1017 wxString
str(textValue
->StringValue());
1018 controlItem
->SetValue4(str
);
1022 wxExpr
*valueList
= (wxExpr
*) NULL
;
1023 // Check for default value list
1024 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1026 wxStringList stringList
;
1027 wxExpr
*stringExpr
= valueList
->GetFirst();
1030 stringList
.Add(stringExpr
->StringValue());
1031 stringExpr
= stringExpr
->GetNext();
1033 controlItem
->SetStringValues(stringList
);
1037 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1039 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1042 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1043 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1050 else if (controlType
== "wxRadioBox")
1052 wxExpr
*valueList
= (wxExpr
*) NULL
;
1053 // Check for default value list
1054 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1056 wxStringList stringList
;
1057 wxExpr
*stringExpr
= valueList
->GetFirst();
1060 stringList
.Add(stringExpr
->StringValue());
1061 stringExpr
= stringExpr
->GetNext();
1063 controlItem
->SetStringValues(stringList
);
1066 // majorDim (number of rows or cols)
1067 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1069 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1073 controlItem
->SetValue1(0);
1075 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1077 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1080 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1081 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1089 return (wxItemResource
*) NULL
;
1094 // Forward declaration
1095 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1098 * Interpet a menu item
1101 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1103 wxItemResource
*item
= new wxItemResource
;
1105 wxExpr
*labelExpr
= expr
->Nth(0);
1106 wxExpr
*idExpr
= expr
->Nth(1);
1107 wxExpr
*helpExpr
= expr
->Nth(2);
1108 wxExpr
*checkableExpr
= expr
->Nth(3);
1110 // Further keywords/attributes to follow sometime...
1111 if (expr
->Number() == 0)
1113 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1114 item
->SetType("wxMenuSeparator");
1119 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1120 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1123 wxString
str(labelExpr
->StringValue());
1124 item
->SetTitle(str
);
1129 // If a string or word, must look up in identifier table.
1130 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1132 wxString
str(idExpr
->StringValue());
1133 id
= wxResourceGetIdentifier(str
, &table
);
1136 wxLogWarning(_("Could not resolve menu id '%s'. "
1137 "Use (non-zero) integer instead\n"
1138 "or provide #define (see manual for caveats)"),
1139 (const char*) idExpr
->StringValue());
1142 else if (idExpr
->Type() == PrologInteger
)
1143 id
= (int)idExpr
->IntegerValue();
1144 item
->SetValue1(id
);
1148 wxString
str(helpExpr
->StringValue());
1149 item
->SetValue4(str
);
1152 item
->SetValue2(checkableExpr
->IntegerValue());
1154 // Find the first expression that's a list, for submenu
1155 wxExpr
*subMenuExpr
= expr
->GetFirst();
1156 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1157 subMenuExpr
= subMenuExpr
->GetNext();
1161 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1162 item
->GetChildren().Append(child
);
1163 subMenuExpr
= subMenuExpr
->GetNext();
1170 * Interpret a nested list as a menu
1173 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1175 wxItemResource *menu = new wxItemResource;
1176 // menu->SetType(wxTYPE_MENU);
1177 menu->SetType("wxMenu");
1178 wxExpr *element = expr->GetFirst();
1181 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1183 menu->GetChildren().Append(item);
1184 element = element->GetNext();
1190 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1192 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1193 expr
->GetAttributeValue("menu", &listExpr
);
1195 return (wxItemResource
*) NULL
;
1197 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1200 return (wxItemResource
*) NULL
;
1203 if (expr
->GetAttributeValue("name", name
))
1205 menuResource
->SetName(name
);
1208 return menuResource
;
1211 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1213 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1214 expr
->GetAttributeValue("menu", &listExpr
);
1216 return (wxItemResource
*) NULL
;
1218 wxItemResource
*resource
= new wxItemResource
;
1219 resource
->SetType("wxMenu");
1220 // resource->SetType(wxTYPE_MENU);
1222 wxExpr
*element
= listExpr
->GetFirst();
1225 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1226 resource
->GetChildren().Append(menuResource
);
1227 element
= element
->GetNext();
1231 if (expr
->GetAttributeValue("name", name
))
1233 resource
->SetName(name
);
1239 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1241 return (wxItemResource
*) NULL
;
1244 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1246 wxItemResource
*bitmapItem
= new wxItemResource
;
1247 // bitmapItem->SetType(wxTYPE_BITMAP);
1248 bitmapItem
->SetType("wxBitmap");
1250 if (expr
->GetAttributeValue("name", name
))
1252 bitmapItem
->SetName(name
);
1254 // Now parse all bitmap specifications
1255 wxExpr
*bitmapExpr
= expr
->GetFirst();
1258 if (bitmapExpr
->Number() == 3)
1260 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1261 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1263 // The value part: always a list.
1264 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1265 if (listExpr
->Type() == PrologList
)
1267 wxItemResource
*bitmapSpec
= new wxItemResource
;
1268 // bitmapSpec->SetType(wxTYPE_BITMAP);
1269 bitmapSpec
->SetType("wxBitmap");
1271 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1272 // where everything after 'filename' is optional.
1273 wxExpr
*nameExpr
= listExpr
->Nth(0);
1274 wxExpr
*typeExpr
= listExpr
->Nth(1);
1275 wxExpr
*platformExpr
= listExpr
->Nth(2);
1276 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1277 wxExpr
*xresExpr
= listExpr
->Nth(4);
1278 wxExpr
*yresExpr
= listExpr
->Nth(5);
1279 if (nameExpr
&& nameExpr
->StringValue())
1281 bitmapSpec
->SetName(nameExpr
->StringValue());
1283 if (typeExpr
&& typeExpr
->StringValue())
1285 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1288 bitmapSpec
->SetValue1(0);
1290 if (platformExpr
&& platformExpr
->StringValue())
1292 wxString
plat(platformExpr
->StringValue());
1293 if (plat
== "windows" || plat
== "WINDOWS")
1294 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1295 else if (plat
== "x" || plat
== "X")
1296 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1297 else if (plat
== "mac" || plat
== "MAC")
1298 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1300 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1303 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1306 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1310 xres
= (int)xresExpr
->IntegerValue();
1312 yres
= (int)yresExpr
->IntegerValue();
1313 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1315 bitmapItem
->GetChildren().Append(bitmapSpec
);
1319 bitmapExpr
= bitmapExpr
->GetNext();
1325 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1327 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1330 // item->SetType(wxTYPE_ICON);
1331 item
->SetType("wxIcon");
1335 return (wxItemResource
*) NULL
;
1338 // Interpret list expression as a font
1339 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1341 if (expr
->Type() != PrologList
)
1345 int family
= wxSWISS
;
1346 int style
= wxNORMAL
;
1347 int weight
= wxNORMAL
;
1349 wxString
faceName("");
1351 wxExpr
*pointExpr
= expr
->Nth(0);
1352 wxExpr
*familyExpr
= expr
->Nth(1);
1353 wxExpr
*styleExpr
= expr
->Nth(2);
1354 wxExpr
*weightExpr
= expr
->Nth(3);
1355 wxExpr
*underlineExpr
= expr
->Nth(4);
1356 wxExpr
*faceNameExpr
= expr
->Nth(5);
1358 point
= (int)pointExpr
->IntegerValue();
1363 str
= familyExpr
->StringValue();
1364 family
= (int)wxParseWindowStyle(str
);
1368 str
= styleExpr
->StringValue();
1369 style
= (int)wxParseWindowStyle(str
);
1373 str
= weightExpr
->StringValue();
1374 weight
= (int)wxParseWindowStyle(str
);
1377 underline
= (int)underlineExpr
->IntegerValue();
1379 faceName
= faceNameExpr
->StringValue();
1381 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1386 * (Re)allocate buffer for reading in from resource file
1389 bool wxReallocateResourceBuffer()
1391 if (!wxResourceBuffer
)
1393 wxResourceBufferSize
= 1000;
1394 wxResourceBuffer
= new char[wxResourceBufferSize
];
1397 if (wxResourceBuffer
)
1399 long newSize
= wxResourceBufferSize
+ 1000;
1400 char *tmp
= new char[(int)newSize
];
1401 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1402 delete[] wxResourceBuffer
;
1403 wxResourceBuffer
= tmp
;
1404 wxResourceBufferSize
= newSize
;
1409 static bool wxEatWhiteSpace(FILE *fd
)
1412 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1419 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1421 // Check for comment
1427 bool finished
= FALSE
;
1435 int newCh
= getc(fd
);
1450 return wxEatWhiteSpace(fd
);
1453 bool wxGetResourceToken(FILE *fd
)
1455 if (!wxResourceBuffer
)
1456 wxReallocateResourceBuffer();
1457 wxResourceBuffer
[0] = 0;
1458 wxEatWhiteSpace(fd
);
1464 wxResourceBufferCount
= 0;
1471 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1474 // Escaped characters
1475 else if (ch
== '\\')
1477 int newCh
= getc(fd
);
1480 else if (newCh
== 10)
1488 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1489 wxReallocateResourceBuffer();
1490 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1491 wxResourceBufferCount
++;
1494 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1498 wxResourceBufferCount
= 0;
1500 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1502 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1503 wxReallocateResourceBuffer();
1504 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1505 wxResourceBufferCount
++;
1509 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1517 * Files are in form:
1518 static char *name = "....";
1519 with possible comments.
1522 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1525 table
= wxDefaultResourceTable
;
1527 // static or #define
1528 if (!wxGetResourceToken(fd
))
1534 if (strcmp(wxResourceBuffer
, "#define") == 0)
1536 wxGetResourceToken(fd
);
1537 char *name
= copystring(wxResourceBuffer
);
1538 wxGetResourceToken(fd
);
1539 char *value
= copystring(wxResourceBuffer
);
1540 if (isalpha(value
[0]))
1542 int val
= (int)atol(value
);
1543 wxResourceAddIdentifier(name
, val
, table
);
1547 wxLogWarning(_("#define %s must be an integer."), name
);
1557 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1559 wxGetResourceToken(fd
);
1560 char *name
= copystring(wxResourceBuffer
);
1561 char *actualName
= name
;
1563 actualName
= name
+ 1;
1564 int len
= strlen(name
);
1565 if ((len
> 0) && (name
[len
-1] == '"'))
1567 if (!wxResourceParseIncludeFile(actualName
, table
))
1569 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1574 else if (strcmp(wxResourceBuffer
, "static") != 0)
1577 strcpy(buf
, _("Found "));
1578 strncat(buf
, wxResourceBuffer
, 30);
1579 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1585 if (!wxGetResourceToken(fd
))
1587 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1592 if (strcmp(wxResourceBuffer
, "char") != 0)
1594 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1599 if (!wxGetResourceToken(fd
))
1601 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1606 if (wxResourceBuffer
[0] != '*')
1608 wxLogWarning(_("Expected '*' whilst parsing resource."));
1612 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1615 if (!wxGetResourceToken(fd
))
1617 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1622 if (strcmp(wxResourceBuffer
, "=") != 0)
1624 wxLogWarning(_("Expected '=' whilst parsing resource."));
1629 if (!wxGetResourceToken(fd
))
1631 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1637 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1639 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1644 if (!wxGetResourceToken(fd
))
1652 * Parses string window style into integer window style
1656 * Style flag parsing, e.g.
1657 * "wxSYSTEM_MENU | wxBORDER" -> integer
1660 char* wxResourceParseWord(char*s
, int *i
)
1663 return (char*) NULL
;
1665 static char buf
[150];
1666 int len
= strlen(s
);
1669 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1677 // Eat whitespace and conjunction characters
1678 while ((ii
< len
) &&
1679 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1685 return (char*) NULL
;
1690 struct wxResourceBitListStruct
1696 static wxResourceBitListStruct wxResourceBitListTable
[] =
1699 { "wxSINGLE", wxLB_SINGLE
},
1700 { "wxMULTIPLE", wxLB_MULTIPLE
},
1701 { "wxEXTENDED", wxLB_EXTENDED
},
1702 { "wxLB_SINGLE", wxLB_SINGLE
},
1703 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1704 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1705 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1706 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1707 { "wxLB_SORT", wxLB_SORT
},
1708 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1709 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1712 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1713 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1714 { "wxCB_READONLY", wxCB_READONLY
},
1715 { "wxCB_SORT", wxCB_SORT
},
1718 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1719 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1720 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1723 { "wxPASSWORD", wxPASSWORD
},
1724 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1725 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1726 { "wxTE_READONLY", wxTE_READONLY
},
1727 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1728 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1730 /* wxRadioBox/wxRadioButton */
1731 { "wxRB_GROUP", wxRB_GROUP
},
1732 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1733 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1736 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1737 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1738 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1739 { "wxSL_LABELS", wxSL_LABELS
},
1740 { "wxSL_LEFT", wxSL_LEFT
},
1741 { "wxSL_TOP", wxSL_TOP
},
1742 { "wxSL_RIGHT", wxSL_RIGHT
},
1743 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1744 { "wxSL_BOTH", wxSL_BOTH
},
1745 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1748 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1749 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1752 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1753 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1756 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1757 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1758 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1761 { "wxLC_ICON", wxLC_ICON
},
1762 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1763 { "wxLC_LIST", wxLC_LIST
},
1764 { "wxLC_REPORT", wxLC_REPORT
},
1765 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1766 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1767 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1768 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1769 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1770 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1771 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1772 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1773 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1774 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1777 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1778 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1779 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1780 { "wxSP_WRAP", wxSP_WRAP
},
1783 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1784 { "wxSP_3D", wxSP_3D
},
1785 { "wxSP_BORDER", wxSP_BORDER
},
1788 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1789 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1790 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1791 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1794 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1797 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1798 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1799 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1800 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1801 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1802 { "wxCOLOURED", wxCOLOURED
},
1805 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1806 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1807 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1808 { "wxTB_FLAT", wxTB_FLAT
},
1811 { "wxVSCROLL", wxVSCROLL
},
1812 { "wxHSCROLL", wxHSCROLL
},
1813 { "wxCAPTION", wxCAPTION
},
1814 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1815 { "wxICONIZE", wxICONIZE
},
1816 { "wxMINIMIZE", wxICONIZE
},
1817 { "wxMAXIMIZE", wxMAXIMIZE
},
1819 { "wxMDI_PARENT", 0},
1820 { "wxMDI_CHILD", 0},
1821 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1822 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1823 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1824 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1825 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1826 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1827 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1828 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1829 { "wxBORDER", wxBORDER
},
1830 { "wxRETAINED", wxRETAINED
},
1831 { "wxNATIVE_IMPL", 0},
1832 { "wxEXTENDED_IMPL", 0},
1833 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1834 // { "wxFLAT", wxFLAT},
1835 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1836 { "wxFIXED_LENGTH", 0},
1837 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1838 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1839 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1840 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1841 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1842 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1843 { "wxNO_BORDER", wxNO_BORDER
},
1844 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1846 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1847 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1849 // Text font families
1850 { "wxDEFAULT", wxDEFAULT
},
1851 { "wxDECORATIVE", wxDECORATIVE
},
1852 { "wxROMAN", wxROMAN
},
1853 { "wxSCRIPT", wxSCRIPT
},
1854 { "wxSWISS", wxSWISS
},
1855 { "wxMODERN", wxMODERN
},
1856 { "wxTELETYPE", wxTELETYPE
},
1857 { "wxVARIABLE", wxVARIABLE
},
1858 { "wxFIXED", wxFIXED
},
1859 { "wxNORMAL", wxNORMAL
},
1860 { "wxLIGHT", wxLIGHT
},
1861 { "wxBOLD", wxBOLD
},
1862 { "wxITALIC", wxITALIC
},
1863 { "wxSLANT", wxSLANT
},
1864 { "wxSOLID", wxSOLID
},
1866 { "wxLONG_DASH", wxLONG_DASH
},
1867 { "wxSHORT_DASH", wxSHORT_DASH
},
1868 { "wxDOT_DASH", wxDOT_DASH
},
1869 { "wxUSER_DASH", wxUSER_DASH
},
1870 { "wxTRANSPARENT", wxTRANSPARENT
},
1871 { "wxSTIPPLE", wxSTIPPLE
},
1872 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1873 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1874 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1875 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1876 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1877 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1878 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1879 { "wxJOIN_MITER", wxJOIN_MITER
},
1880 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1881 { "wxCAP_ROUND", wxCAP_ROUND
},
1882 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1883 { "wxCAP_BUTT", wxCAP_BUTT
},
1886 { "wxCLEAR", wxCLEAR
},
1888 { "wxINVERT", wxINVERT
},
1889 { "wxOR_REVERSE", wxOR_REVERSE
},
1890 { "wxAND_REVERSE", wxAND_REVERSE
},
1891 { "wxCOPY", wxCOPY
},
1893 { "wxAND_INVERT", wxAND_INVERT
},
1894 { "wxNO_OP", wxNO_OP
},
1896 { "wxEQUIV", wxEQUIV
},
1897 { "wxSRC_INVERT", wxSRC_INVERT
},
1898 { "wxOR_INVERT", wxOR_INVERT
},
1899 { "wxNAND", wxNAND
},
1903 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1904 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1905 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1906 { "wxWINDING_RULE", wxWINDING_RULE
},
1907 { "wxHORIZONTAL", wxHORIZONTAL
},
1908 { "wxVERTICAL", wxVERTICAL
},
1909 { "wxBOTH", wxBOTH
},
1910 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1912 { "wxYES_NO", wxYES_NO
},
1913 { "wxCANCEL", wxCANCEL
},
1916 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1917 { "wxICON_HAND", wxICON_HAND
},
1918 { "wxICON_QUESTION", wxICON_QUESTION
},
1919 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1920 { "wxICON_STOP", wxICON_STOP
},
1921 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1922 { "wxICON_MASK", wxICON_MASK
},
1923 { "wxCENTRE", wxCENTRE
},
1924 { "wxCENTER", wxCENTRE
},
1925 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1926 { "wxVERTICAL_LABEL", 0},
1927 { "wxHORIZONTAL_LABEL", 0},
1929 // Bitmap types (not strictly styles)
1930 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1931 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1932 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1933 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1934 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1935 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1936 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1937 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1938 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1939 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1940 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1941 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1942 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1943 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1946 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
1948 long wxParseWindowStyle(const wxString
& bitListString
)
1953 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
1957 for (j
= 0; j
< wxResourceBitListCount
; j
++)
1958 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
1960 bitList
|= wxResourceBitListTable
[j
].bits
;
1966 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
1974 * Load a bitmap from a wxWindows resource, choosing an optimum
1975 * depth and appropriate type.
1978 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
1981 table
= wxDefaultResourceTable
;
1983 wxItemResource
*item
= table
->FindResource(resource
);
1986 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
1988 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
1989 return wxNullBitmap
;
1991 int thisDepth
= wxDisplayDepth();
1992 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
1994 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
1996 // Try to find optimum bitmap for this platform/colour depth
1997 wxNode
*node
= item
->GetChildren().First();
2000 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2001 int platform
= (int)child
->GetValue2();
2002 int noColours
= (int)child
->GetValue3();
2004 char *name = child->GetName();
2005 int bitmapType = (int)child->GetValue1();
2006 int xRes = child->GetWidth();
2007 int yRes = child->GetHeight();
2012 case RESOURCE_PLATFORM_ANY
:
2014 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2015 optResource
= child
;
2018 // Maximise the number of colours.
2019 // If noColours is zero (unspecified), then assume this
2020 // is the right one.
2021 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2022 optResource
= child
;
2027 case RESOURCE_PLATFORM_WINDOWS
:
2029 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2030 optResource
= child
;
2033 // Maximise the number of colours
2034 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2035 optResource
= child
;
2041 case RESOURCE_PLATFORM_X
:
2043 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2044 optResource
= child
;
2047 // Maximise the number of colours
2048 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2049 optResource
= child
;
2055 case RESOURCE_PLATFORM_MAC
:
2057 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2058 optResource
= child
;
2061 // Maximise the number of colours
2062 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2063 optResource
= child
;
2071 node
= node
->Next();
2073 // If no matching resource, fail.
2075 return wxNullBitmap
;
2077 wxString name
= optResource
->GetName();
2078 int bitmapType
= (int)optResource
->GetValue1();
2081 case wxBITMAP_TYPE_XBM_DATA
:
2084 wxItemResource
*item
= table
->FindResource(name
);
2087 wxLogWarning(_("Failed to find XBM resource %s.\n"
2088 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2089 return (wxBitmap
*) NULL
;
2091 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2093 wxLogWarning(_("No XBM facility available!"));
2097 case wxBITMAP_TYPE_XPM_DATA
:
2099 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2100 wxItemResource
*item
= table
->FindResource(name
);
2103 wxLogWarning(_("Failed to find XPM resource %s.\n"
2104 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2105 return (wxBitmap
*) NULL
;
2107 return wxBitmap(item
->GetValue1());
2109 wxLogWarning(_("No XPM facility available!"));
2115 return wxBitmap(name
, bitmapType
);
2119 return wxNullBitmap
;
2123 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2124 return wxNullBitmap
;
2129 * Load an icon from a wxWindows resource, choosing an optimum
2130 * depth and appropriate type.
2133 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2136 table
= wxDefaultResourceTable
;
2138 wxItemResource
*item
= table
->FindResource(resource
);
2141 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2143 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2146 int thisDepth
= wxDisplayDepth();
2147 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2149 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2151 // Try to find optimum icon for this platform/colour depth
2152 wxNode
*node
= item
->GetChildren().First();
2155 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2156 int platform
= (int)child
->GetValue2();
2157 int noColours
= (int)child
->GetValue3();
2159 char *name = child->GetName();
2160 int bitmapType = (int)child->GetValue1();
2161 int xRes = child->GetWidth();
2162 int yRes = child->GetHeight();
2167 case RESOURCE_PLATFORM_ANY
:
2169 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2170 optResource
= child
;
2173 // Maximise the number of colours.
2174 // If noColours is zero (unspecified), then assume this
2175 // is the right one.
2176 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2177 optResource
= child
;
2182 case RESOURCE_PLATFORM_WINDOWS
:
2184 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2185 optResource
= child
;
2188 // Maximise the number of colours
2189 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2190 optResource
= child
;
2196 case RESOURCE_PLATFORM_X
:
2198 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2199 optResource
= child
;
2202 // Maximise the number of colours
2203 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2204 optResource
= child
;
2210 case RESOURCE_PLATFORM_MAC
:
2212 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2213 optResource
= child
;
2216 // Maximise the number of colours
2217 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2218 optResource
= child
;
2226 node
= node
->Next();
2228 // If no matching resource, fail.
2232 wxString name
= optResource
->GetName();
2233 int bitmapType
= (int)optResource
->GetValue1();
2236 case wxBITMAP_TYPE_XBM_DATA
:
2239 wxItemResource
*item
= table
->FindResource(name
);
2242 wxLogWarning(_("Failed to find XBM resource %s.\n"
2243 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2244 return (wxIcon
*) NULL
;
2246 return wxIcon((char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2248 wxLogWarning(_("No XBM facility available!"));
2252 case wxBITMAP_TYPE_XPM_DATA
:
2254 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2256 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2257 wxItemResource *item = table->FindResource(name);
2261 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2265 return wxIcon((char **)item->GetValue1());
2267 wxLogWarning(_("No XPM facility available!"));
2270 wxLogWarning(_("No XPM icon facility available!"));
2276 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2278 return wxIcon(name
, bitmapType
);
2287 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2288 return (wxIcon
*) NULL
;
2292 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2294 wxMenu
*menu
= new wxMenu
;
2295 wxNode
*node
= item
->GetChildren().First();
2298 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2299 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2300 menu
->AppendSeparator();
2301 else if (child
->GetChildren().Number() > 0)
2303 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2305 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2309 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2311 node
= node
->Next();
2316 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2319 table
= wxDefaultResourceTable
;
2321 wxItemResource
*menuResource
= table
->FindResource(resource
);
2322 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2325 menuBar
= new wxMenuBar
;
2326 wxNode
*node
= menuResource
->GetChildren().First();
2329 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2330 wxMenu
*menu
= wxResourceCreateMenu(child
);
2332 menuBar
->Append(menu
, child
->GetTitle());
2333 node
= node
->Next();
2337 return (wxMenuBar
*) NULL
;
2340 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2343 table
= wxDefaultResourceTable
;
2345 wxItemResource
*menuResource
= table
->FindResource(resource
);
2346 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2347 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2348 return wxResourceCreateMenu(menuResource
);
2349 return (wxMenu
*) NULL
;
2352 // Global equivalents (so don't have to refer to default table explicitly)
2353 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2356 table
= wxDefaultResourceTable
;
2358 return table
->ParseResourceData(resource
);
2361 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2364 table
= wxDefaultResourceTable
;
2366 return table
->ParseResourceFile(filename
);
2369 // Register XBM/XPM data
2370 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2373 table
= wxDefaultResourceTable
;
2375 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2378 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2381 table
= wxDefaultResourceTable
;
2383 return table
->RegisterResourceBitmapData(name
, data
);
2386 void wxResourceClear(wxResourceTable
*table
)
2389 table
= wxDefaultResourceTable
;
2391 table
->ClearTable();
2398 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2401 table
= wxDefaultResourceTable
;
2403 table
->identifiers
.Put(name
, (wxObject
*)value
);
2407 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2410 table
= wxDefaultResourceTable
;
2412 return (int)table
->identifiers
.Get(name
);
2416 * Parse #include file for #defines (only)
2419 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2422 table
= wxDefaultResourceTable
;
2424 FILE *fd
= fopen(f
, "r");
2429 while (wxGetResourceToken(fd
))
2431 if (strcmp(wxResourceBuffer
, "#define") == 0)
2433 wxGetResourceToken(fd
);
2434 char *name
= copystring(wxResourceBuffer
);
2435 wxGetResourceToken(fd
);
2436 char *value
= copystring(wxResourceBuffer
);
2437 if (isdigit(value
[0]))
2439 int val
= (int)atol(value
);
2440 wxResourceAddIdentifier(name
, val
, table
);
2451 * Reading strings as if they were .wxr files
2454 static int getc_string(char *s
)
2456 int ch
= s
[wxResourceStringPtr
];
2461 wxResourceStringPtr
++;
2466 static int ungetc_string()
2468 wxResourceStringPtr
--;
2472 bool wxEatWhiteSpaceString(char *s
)
2474 int ch
= getc_string(s
);
2478 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2485 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2486 ch
= getc_string(s
);
2487 // Check for comment
2490 ch
= getc_string(s
);
2493 bool finished
= FALSE
;
2496 ch
= getc_string(s
);
2501 int newCh
= getc_string(s
);
2516 return wxEatWhiteSpaceString(s
);
2519 bool wxGetResourceTokenString(char *s
)
2521 if (!wxResourceBuffer
)
2522 wxReallocateResourceBuffer();
2523 wxResourceBuffer
[0] = 0;
2524 wxEatWhiteSpaceString(s
);
2526 int ch
= getc_string(s
);
2530 wxResourceBufferCount
= 0;
2531 ch
= getc_string(s
);
2537 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2540 // Escaped characters
2541 else if (ch
== '\\')
2543 int newCh
= getc_string(s
);
2546 else if (newCh
== 10)
2554 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2555 wxReallocateResourceBuffer();
2556 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2557 wxResourceBufferCount
++;
2558 ch
= getc_string(s
);
2560 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2564 wxResourceBufferCount
= 0;
2566 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2568 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2569 wxReallocateResourceBuffer();
2570 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2571 wxResourceBufferCount
++;
2573 ch
= getc_string(s
);
2575 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2583 * Files are in form:
2584 static char *name = "....";
2585 with possible comments.
2588 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2591 table
= wxDefaultResourceTable
;
2593 // static or #define
2594 if (!wxGetResourceTokenString(s
))
2600 if (strcmp(wxResourceBuffer
, "#define") == 0)
2602 wxGetResourceTokenString(s
);
2603 char *name
= copystring(wxResourceBuffer
);
2604 wxGetResourceTokenString(s
);
2605 char *value
= copystring(wxResourceBuffer
);
2606 if (isalpha(value
[0]))
2608 int val
= (int)atol(value
);
2609 wxResourceAddIdentifier(name
, val
, table
);
2613 wxLogWarning(_("#define %s must be an integer."), name
);
2624 else if (strcmp(wxResourceBuffer, "#include") == 0)
2626 wxGetResourceTokenString(s);
2627 char *name = copystring(wxResourceBuffer);
2628 char *actualName = name;
2630 actualName = name + 1;
2631 int len = strlen(name);
2632 if ((len > 0) && (name[len-1] == '"'))
2634 if (!wxResourceParseIncludeFile(actualName, table))
2637 sprintf(buf, _("Could not find resource include file %s."), actualName);
2644 else if (strcmp(wxResourceBuffer
, "static") != 0)
2647 strcpy(buf
, _("Found "));
2648 strncat(buf
, wxResourceBuffer
, 30);
2649 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2655 if (!wxGetResourceTokenString(s
))
2657 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2662 if (strcmp(wxResourceBuffer
, "char") != 0)
2664 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2669 if (!wxGetResourceTokenString(s
))
2671 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2676 if (wxResourceBuffer
[0] != '*')
2678 wxLogWarning(_("Expected '*' whilst parsing resource."));
2682 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2685 if (!wxGetResourceTokenString(s
))
2687 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2692 if (strcmp(wxResourceBuffer
, "=") != 0)
2694 wxLogWarning(_("Expected '=' whilst parsing resource."));
2699 if (!wxGetResourceTokenString(s
))
2701 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2707 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2709 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2714 if (!wxGetResourceTokenString(s
))
2721 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2724 table
= wxDefaultResourceTable
;
2729 // Turn backslashes into spaces
2732 int len
= strlen(s
);
2734 for (i
= 0; i
< len
; i
++)
2735 if (s
[i
] == 92 && s
[i
+1] == 13)
2743 wxResourceStringPtr
= 0;
2746 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2750 return wxResourceInterpretResources(*table
, db
);
2754 * resource loading facility
2757 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2760 table
= wxDefaultResourceTable
;
2762 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2763 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2764 if (!resource
|| !resource
->GetType() ||
2765 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2768 wxString
title(resource
->GetTitle());
2769 long theWindowStyle
= resource
->GetStyle();
2770 bool isModal
= (resource
->GetValue1() != 0);
2771 int x
= resource
->GetX();
2772 int y
= resource
->GetY();
2773 int width
= resource
->GetWidth();
2774 int height
= resource
->GetHeight();
2775 wxString name
= resource
->GetName();
2777 if (IsKindOf(CLASSINFO(wxDialog
)))
2779 wxDialog
*dialogBox
= (wxDialog
*)this;
2780 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2781 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2784 // Only reset the client size if we know we're not going to do it again below.
2785 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2786 dialogBox
->SetClientSize(width
, height
);
2788 else if (IsKindOf(CLASSINFO(wxPanel
)))
2790 wxPanel
* panel
= (wxPanel
*)this;
2791 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2796 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2800 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2802 // No need to do this since it's done in wxPanel or wxDialog constructor.
2803 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2807 if (resource
->GetFont().Ok())
2808 SetFont(resource
->GetFont());
2809 if (resource
->GetBackgroundColour().Ok())
2810 SetBackgroundColour(resource
->GetBackgroundColour());
2813 // Should have some kind of font at this point
2814 if (!GetFont()->Ok())
2815 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2816 if (!GetBackgroundColour().Ok())
2817 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2819 // Only when we've created the window and set the font can we set the correct size,
2820 // if based on dialog units.
2821 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2823 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2824 SetClientSize(sz
.x
, sz
.y
);
2826 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2830 // Now create children
2831 wxNode
*node
= resource
->GetChildren().First();
2834 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2836 (void) CreateItem(childResource
, resource
, table
);
2838 node
= node
->Next();
2843 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2846 table
= wxDefaultResourceTable
;
2847 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2850 #endif // wxUSE_WX_RESOURCES