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"
68 #include "wx/resource.h"
69 #include "wx/string.h"
70 #include "wx/wxexpr.h"
72 // Forward (private) declarations
73 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
);
74 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
= FALSE
);
75 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
);
76 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
);
77 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
);
78 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, PrologExpr
*expr
);
79 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, PrologExpr
*expr
);
80 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
);
81 // Interpret list expression
82 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
);
84 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
85 bool wxResourceParseIncludeFile(char *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(void)
96 wxDefaultResourceTable
= new wxResourceTable
;
99 void wxCleanUpResourceSystem(void)
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(void)
118 itemType
= (char *) NULL
;
119 title
= (char *) NULL
;
120 name
= (char *) NULL
;
122 x
= y
= width
= height
= 0;
123 value1
= value2
= value3
= value5
= 0;
124 value4
= (char *) NULL
;
125 stringValues
= (wxStringList
*) NULL
;
126 bitmap
= (wxBitmap
*) NULL
;
127 backgroundColour
= labelColour
= buttonColour
= (wxColour
*) NULL
;
128 windowFont
= (wxFont
*) NULL
;
132 wxItemResource::~wxItemResource(void)
134 if (itemType
) delete[] itemType
;
135 if (title
) delete[] title
;
136 if (name
) delete[] name
;
137 if (value4
) delete[] value4
;
142 if (backgroundColour
)
143 delete backgroundColour
;
148 wxNode
*node
= children
.First();
151 wxItemResource
*item
= (wxItemResource
*)node
->Data();
154 node
= children
.First();
158 void wxItemResource::SetTitle(char *t
)
163 if (title
) delete[] title
;
165 title
= copystring(t
);
167 title
= (char *) NULL
;
170 void wxItemResource::SetType(char *t
)
175 if (itemType
) delete[] itemType
;
177 itemType
= copystring(t
);
179 itemType
= (char *) NULL
;
182 void wxItemResource::SetName(char *n
)
187 if (name
) delete[] name
;
189 name
= copystring(n
);
191 name
= (char *) NULL
;
194 void wxItemResource::SetStringValues(wxStringList
*svalues
)
199 stringValues
= svalues
;
201 stringValues
= (wxStringList
*) NULL
;
204 void wxItemResource::SetValue4(char *v
)
209 if (value4
) delete[] value4
;
211 value4
= copystring(v
);
213 value4
= (char *) NULL
;
220 wxResourceTable::wxResourceTable(void):wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
224 wxResourceTable::~wxResourceTable(void)
229 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
231 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
235 void wxResourceTable::AddResource(wxItemResource
*item
)
237 char *name
= item
->GetName();
239 name
= item
->GetTitle();
243 // Delete existing resource, if any.
249 bool wxResourceTable::DeleteResource(const wxString
& name
)
251 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
254 // See if any resource has this as its child; if so, delete from
255 // parent's child list.
257 wxNode
*node
= (wxNode
*) NULL
;
258 while ((node
= Next()))
260 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
261 if (parent
->GetChildren().Member(item
))
263 parent
->GetChildren().DeleteObject(item
);
275 bool wxResourceTable::ParseResourceFile(char *filename
)
279 FILE *fd
= fopen(filename
, "r");
283 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
288 return wxResourceInterpretResources(*this, db
);
291 bool wxResourceTable::ParseResourceData(char *data
)
294 if (!db
.ReadPrologFromString(data
))
296 wxLogWarning(_("Ill-formed resource file syntax."));
300 return wxResourceInterpretResources(*this, db
);
303 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char bits
[], int width
, int height
)
305 // Register pre-loaded bitmap data
306 wxItemResource
*item
= new wxItemResource
;
307 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
308 item
->SetType("wxXBMData");
310 item
->SetValue1((long)bits
);
311 item
->SetValue2((long)width
);
312 item
->SetValue3((long)height
);
317 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char **data
)
319 // Register pre-loaded bitmap data
320 wxItemResource
*item
= new wxItemResource
;
321 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
322 item
->SetType("wxXPMData");
324 item
->SetValue1((long)data
);
329 bool wxResourceTable::SaveResource(char *WXUNUSED(filename
))
334 void wxResourceTable::ClearTable(void)
337 wxNode
*node
= Next();
340 wxNode
*next
= Next();
341 wxItemResource
*item
= (wxItemResource
*)node
->Data();
348 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, wxItemResource
*childResource
) const
350 int id
= childResource
->GetId();
354 wxControl
*control
= (wxControl
*) NULL
;
355 wxString
itemType(childResource
->GetType());
356 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
358 if (childResource
->GetValue4())
361 wxBitmap
*bitmap
= childResource
->GetBitmap();
364 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
365 childResource
->SetBitmap(bitmap
);
368 control
= new wxBitmapButton(parent
, id
, *bitmap
,
369 wxPoint(childResource
->GetX(), childResource
->GetY()),
370 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
371 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
374 // Normal, text button
375 control
= new wxButton(parent
, id
, childResource
->GetTitle(),
376 wxPoint(childResource
->GetX(), childResource
->GetY()),
377 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
378 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
380 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
381 itemType
== wxString("wxStaticBitmap"))
383 if (childResource
->GetValue4())
386 wxBitmap
*bitmap
= childResource
->GetBitmap();
389 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
390 childResource
->SetBitmap(bitmap
);
392 #if USE_BITMAP_MESSAGE
394 control
= new wxStaticBitmap(parent
, id
, *bitmap
,
395 wxPoint(childResource
->GetX(), childResource
->GetY()),
396 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
397 childResource
->GetStyle(), childResource
->GetName());
402 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(),
403 wxPoint(childResource
->GetX(), childResource
->GetY()),
404 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
405 childResource
->GetStyle(), childResource
->GetName());
408 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
410 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(),
411 wxPoint(childResource
->GetX(), childResource
->GetY()),
412 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
413 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
415 else if (itemType
== wxString("wxCheckBox"))
417 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(),
418 wxPoint(childResource
->GetX(), childResource
->GetY()),
419 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
420 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
422 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
425 else if (itemType
== wxString("wxGauge"))
427 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(),
428 wxPoint(childResource
->GetX(), childResource
->GetY()),
429 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
430 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
432 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
436 else if (itemType
== wxString("wxRadioButton"))
438 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
439 wxPoint(childResource
->GetX(), childResource
->GetY()),
440 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
441 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
445 else if (itemType
== wxString("wxScrollBar"))
447 control
= new wxScrollBar(parent
, id
,
448 wxPoint(childResource
->GetX(), childResource
->GetY()),
449 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
450 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
451 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
452 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
453 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
454 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
457 else if (itemType
== wxString("wxSlider"))
459 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
460 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(),
461 wxPoint(childResource
->GetX(), childResource
->GetY()),
462 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
463 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
465 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
467 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(),
468 wxPoint(childResource
->GetX(), childResource
->GetY()),
469 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
470 childResource
->GetStyle(), childResource
->GetName());
472 else if (itemType
== wxString("wxListBox"))
474 wxStringList
*stringList
= childResource
->GetStringValues();
475 wxString
*strings
= (wxString
*) NULL
;
477 if (stringList
&& (stringList
->Number() > 0))
479 noStrings
= stringList
->Number();
480 strings
= new wxString
[noStrings
];
481 wxNode
*node
= stringList
->First();
485 strings
[i
] = (char *)node
->Data();
490 control
= new wxListBox(parent
, id
,
491 wxPoint(childResource
->GetX(), childResource
->GetY()),
492 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
493 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
498 else if (itemType
== wxString("wxChoice"))
500 wxStringList
*stringList
= childResource
->GetStringValues();
501 wxString
*strings
= (wxString
*) NULL
;
503 if (stringList
&& (stringList
->Number() > 0))
505 noStrings
= stringList
->Number();
506 strings
= new wxString
[noStrings
];
507 wxNode
*node
= stringList
->First();
511 strings
[i
] = (char *)node
->Data();
516 control
= new wxChoice(parent
, id
,
517 wxPoint(childResource
->GetX(), childResource
->GetY()),
518 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
519 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
525 else if (itemType
== wxString("wxComboBox"))
527 wxStringList
*stringList
= childResource
->GetStringValues();
528 wxString
*strings
= (wxString
*) NULL
;
530 if (stringList
&& (stringList
->Number() > 0))
532 noStrings
= stringList
->Number();
533 strings
= new wxString
[noStrings
];
534 wxNode
*node
= stringList
->First();
538 strings
[i
] = (char *)node
->Data();
543 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(),
544 wxPoint(childResource
->GetX(), childResource
->GetY()),
545 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
546 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
552 else if (itemType
== wxString("wxRadioBox"))
554 wxStringList
*stringList
= childResource
->GetStringValues();
555 wxString
*strings
= (wxString
*) NULL
;
557 if (stringList
&& (stringList
->Number() > 0))
559 noStrings
= stringList
->Number();
560 strings
= new wxString
[noStrings
];
561 wxNode
*node
= stringList
->First();
565 strings
[i
] = (char *)node
->Data();
570 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()),
571 wxPoint(childResource
->GetX(), childResource
->GetY()),
572 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
573 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
574 childResource
->GetName());
580 if (control
&& childResource
->GetFont())
581 control
->SetFont(*childResource
->GetFont());
586 * Interpret database as a series of resources
589 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
)
591 wxNode
*node
= db
.First();
594 PrologExpr
*clause
= (PrologExpr
*)node
->Data();
595 wxString
functor(clause
->Functor());
597 wxItemResource
*item
= (wxItemResource
*) NULL
;
598 if (functor
== "dialog")
599 item
= wxResourceInterpretDialog(table
, clause
);
600 else if (functor
== "panel")
601 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
602 else if (functor
== "menubar")
603 item
= wxResourceInterpretMenuBar(table
, clause
);
604 else if (functor
== "menu")
605 item
= wxResourceInterpretMenu(table
, clause
);
606 else if (functor
== "string")
607 item
= wxResourceInterpretString(table
, clause
);
608 else if (functor
== "bitmap")
609 item
= wxResourceInterpretBitmap(table
, clause
);
610 else if (functor
== "icon")
611 item
= wxResourceInterpretIcon(table
, clause
);
615 // Remove any existing resource of same name
617 table
.DeleteResource(item
->GetName());
618 table
.AddResource(item
);
625 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
626 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
627 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
628 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
629 "wxChoice", "wxComboBox" } ;
630 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
632 static bool wxIsValidControlClass(const wxString
& c
)
635 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
637 if ( c
== g_ValidControlClasses
[i
] )
643 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
)
645 wxItemResource
*dialogItem
= new wxItemResource
;
647 dialogItem
->SetType("wxPanel");
649 dialogItem
->SetType("wxDialog");
650 char *style
= (char *) NULL
;
651 char *title
= (char *) NULL
;
652 char *name
= (char *) NULL
;
653 char *backColourHex
= (char *) NULL
;
654 char *labelColourHex
= (char *) NULL
;
655 char *buttonColourHex
= (char *) NULL
;
657 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
661 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
663 PrologExpr
*labelFontExpr
= (PrologExpr
*) NULL
;
664 PrologExpr
*buttonFontExpr
= (PrologExpr
*) NULL
;
665 PrologExpr
*fontExpr
= (PrologExpr
*) NULL
;
666 expr
->AssignAttributeValue("style", &style
);
667 expr
->AssignAttributeValue("name", &name
);
668 expr
->AssignAttributeValue("title", &title
);
669 expr
->AssignAttributeValue("x", &x
);
670 expr
->AssignAttributeValue("y", &y
);
671 expr
->AssignAttributeValue("width", &width
);
672 expr
->AssignAttributeValue("height", &height
);
673 expr
->AssignAttributeValue("modal", &isModal
);
674 expr
->AssignAttributeValue("label_font", &labelFontExpr
);
675 expr
->AssignAttributeValue("button_font", &buttonFontExpr
);
676 expr
->AssignAttributeValue("font", &fontExpr
);
677 expr
->AssignAttributeValue("background_colour", &backColourHex
);
678 expr
->AssignAttributeValue("label_colour", &labelColourHex
);
679 expr
->AssignAttributeValue("button_colour", &buttonColourHex
);
682 expr
->GetAttributeValue("id", id
);
683 dialogItem
->SetId(id
);
687 windowStyle
= wxParseWindowStyle(style
);
689 dialogItem
->SetStyle(windowStyle
);
690 dialogItem
->SetValue1(isModal
);
692 dialogItem
->SetName(name
);
694 dialogItem
->SetTitle(title
);
695 dialogItem
->SetSize(x
, y
, width
, height
);
702 r
= wxHexToDec(backColourHex
);
703 g
= wxHexToDec(backColourHex
+2);
704 b
= wxHexToDec(backColourHex
+4);
705 dialogItem
->SetBackgroundColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
706 delete[] backColourHex
;
713 r
= wxHexToDec(labelColourHex
);
714 g
= wxHexToDec(labelColourHex
+2);
715 b
= wxHexToDec(labelColourHex
+4);
716 dialogItem
->SetLabelColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
717 delete[] labelColourHex
;
724 r
= wxHexToDec(buttonColourHex
);
725 g
= wxHexToDec(buttonColourHex
+2);
726 b
= wxHexToDec(buttonColourHex
+4);
727 dialogItem
->SetButtonColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
728 delete[] buttonColourHex
;
739 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
740 else if (buttonFontExpr
)
741 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
742 else if (labelFontExpr
)
743 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
745 // Now parse all controls
746 PrologExpr
*controlExpr
= expr
->GetFirst();
749 if (controlExpr
->Number() == 3)
751 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
752 if (controlKeyword
!= "" && controlKeyword
== "control")
754 // The value part: always a list.
755 PrologExpr
*listExpr
= controlExpr
->Nth(2);
756 if (listExpr
->Type() == PrologList
)
758 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
761 dialogItem
->GetChildren().Append(controlItem
);
766 controlExpr
= controlExpr
->GetNext();
771 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
)
773 wxItemResource
*controlItem
= new wxItemResource
;
775 // First, find the standard features of a control definition:
776 // [optional integer/string id], control name, title, style, name, x, y, width, height
778 wxString controlType
;
783 long windowStyle
= 0;
784 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
787 PrologExpr
*expr1
= expr
->Nth(0);
789 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
791 if ( wxIsValidControlClass(expr1
->StringValue()) )
794 controlType
= expr1
->StringValue();
798 wxString
str(expr1
->StringValue());
799 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
802 wxLogWarning(_("Could not resolve control class or id '%s'. "
803 "Use (non-zero) integer instead\n or provide #define "
804 "(see manual for caveats)"),
805 (const char*) expr1
->StringValue());
807 return (wxItemResource
*) NULL
;
811 // Success - we have an id, so the 2nd element must be the control class.
812 controlType
= expr
->Nth(1)->StringValue();
817 else if (expr1
->Type() == PrologInteger
)
819 id
= (int)expr1
->IntegerValue();
820 // Success - we have an id, so the 2nd element must be the control class.
821 controlType
= expr
->Nth(1)->StringValue();
825 expr1
= expr
->Nth(count
);
828 title
= expr1
->StringValue();
830 expr1
= expr
->Nth(count
);
834 style
= expr1
->StringValue();
835 windowStyle
= wxParseWindowStyle(WXSTRINGCAST style
);
838 expr1
= expr
->Nth(count
);
841 name
= expr1
->StringValue();
843 expr1
= expr
->Nth(count
);
846 x
= (int)expr1
->IntegerValue();
848 expr1
= expr
->Nth(count
);
851 y
= (int)expr1
->IntegerValue();
853 expr1
= expr
->Nth(count
);
856 width
= (int)expr1
->IntegerValue();
858 expr1
= expr
->Nth(count
);
861 height
= (int)expr1
->IntegerValue();
863 controlItem
->SetStyle(windowStyle
);
864 controlItem
->SetName(WXSTRINGCAST name
);
865 controlItem
->SetTitle(WXSTRINGCAST title
);
866 controlItem
->SetSize(x
, y
, width
, height
);
867 controlItem
->SetType(WXSTRINGCAST controlType
);
868 controlItem
->SetId(id
);
870 if (controlType
== "wxButton")
872 // Check for bitmap resource name
873 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
875 wxString
str(expr
->Nth(count
)->StringValue());
876 controlItem
->SetValue4(WXSTRINGCAST str
);
878 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
879 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
882 else if (controlType
== "wxCheckBox")
884 // Check for default value
885 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
887 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
889 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
890 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
894 else if (controlType
== "wxRadioButton")
896 // Check for default value
897 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
899 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
901 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
902 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
906 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
908 // Check for default value
909 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
911 wxString
str(expr
->Nth(count
)->StringValue());
912 controlItem
->SetValue4(WXSTRINGCAST str
);
915 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
917 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
918 // Do nothing - no label font any more
920 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
921 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
925 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
927 // Check for bitmap resource name
928 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
930 wxString
str(expr
->Nth(count
)->StringValue());
931 controlItem
->SetValue4(WXSTRINGCAST str
);
933 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
934 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
937 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
939 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
940 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
942 else if (controlType
== "wxGauge")
944 // Check for default value
945 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
947 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
951 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
953 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
956 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
958 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
962 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
963 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
968 else if (controlType
== "wxSlider")
970 // Check for default value
971 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
973 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
977 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
979 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
983 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
985 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
988 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
990 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
994 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
995 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1001 else if (controlType
== "wxScrollBar")
1004 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1006 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1010 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1012 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1016 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1018 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1022 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1023 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1028 else if (controlType
== "wxListBox")
1030 PrologExpr
*valueList
= (PrologExpr
*) NULL
;
1032 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1034 wxStringList
*stringList
= new wxStringList
;
1035 PrologExpr
*stringExpr
= valueList
->GetFirst();
1038 stringList
->Add(stringExpr
->StringValue());
1039 stringExpr
= stringExpr
->GetNext();
1041 controlItem
->SetStringValues(stringList
);
1044 // Check for wxSINGLE/wxMULTIPLE
1045 PrologExpr
*mult
= (PrologExpr
*) NULL
;
1046 controlItem
->SetValue1(wxLB_SINGLE
);
1047 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1049 wxString
m(mult
->StringValue());
1050 if (m
== "wxMULTIPLE")
1051 controlItem
->SetValue1(wxLB_MULTIPLE
);
1052 else if (m
== "wxEXTENDED")
1053 controlItem
->SetValue1(wxLB_EXTENDED
);
1055 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1057 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1059 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1060 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1065 else if (controlType
== "wxChoice")
1067 PrologExpr
*valueList
= (PrologExpr
*) NULL
;
1068 // Check for default value list
1069 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1071 wxStringList
*stringList
= new wxStringList
;
1072 PrologExpr
*stringExpr
= valueList
->GetFirst();
1075 stringList
->Add(stringExpr
->StringValue());
1076 stringExpr
= stringExpr
->GetNext();
1078 controlItem
->SetStringValues(stringList
);
1082 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1084 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1087 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1088 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1093 else if (controlType
== "wxComboBox")
1095 PrologExpr
*textValue
= expr
->Nth(count
);
1096 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1098 wxString
str(textValue
->StringValue());
1099 controlItem
->SetValue4(WXSTRINGCAST str
);
1103 PrologExpr
*valueList
= (PrologExpr
*) NULL
;
1104 // Check for default value list
1105 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1107 wxStringList
*stringList
= new wxStringList
;
1108 PrologExpr
*stringExpr
= valueList
->GetFirst();
1111 stringList
->Add(stringExpr
->StringValue());
1112 stringExpr
= stringExpr
->GetNext();
1114 controlItem
->SetStringValues(stringList
);
1118 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1120 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1123 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1124 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1131 else if (controlType
== "wxRadioBox")
1133 PrologExpr
*valueList
= (PrologExpr
*) NULL
;
1134 // Check for default value list
1135 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1137 wxStringList
*stringList
= new wxStringList
;
1138 PrologExpr
*stringExpr
= valueList
->GetFirst();
1141 stringList
->Add(stringExpr
->StringValue());
1142 stringExpr
= stringExpr
->GetNext();
1144 controlItem
->SetStringValues(stringList
);
1147 // majorDim (number of rows or cols)
1148 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1150 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1154 controlItem
->SetValue1(0);
1156 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1158 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1161 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1162 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1170 return (wxItemResource
*) NULL
;
1175 // Forward declaration
1176 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, PrologExpr
*expr
);
1179 * Interpet a menu item
1182 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, PrologExpr
*expr
)
1184 wxItemResource
*item
= new wxItemResource
;
1186 PrologExpr
*labelExpr
= expr
->Nth(0);
1187 PrologExpr
*idExpr
= expr
->Nth(1);
1188 PrologExpr
*helpExpr
= expr
->Nth(2);
1189 PrologExpr
*checkableExpr
= expr
->Nth(3);
1191 // Further keywords/attributes to follow sometime...
1192 if (expr
->Number() == 0)
1194 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1195 item
->SetType("wxMenuSeparator");
1200 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1201 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1204 wxString
str(labelExpr
->StringValue());
1205 item
->SetTitle(WXSTRINGCAST str
);
1210 // If a string or word, must look up in identifier table.
1211 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1213 wxString
str(idExpr
->StringValue());
1214 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
1217 wxLogWarning(_("Could not resolve menu id '%s'. "
1218 "Use (non-zero) integer instead\n"
1219 "or provide #define (see manual for caveats)"),
1220 (const char*) idExpr
->StringValue());
1223 else if (idExpr
->Type() == PrologInteger
)
1224 id
= (int)idExpr
->IntegerValue();
1225 item
->SetValue1(id
);
1229 wxString
str(helpExpr
->StringValue());
1230 item
->SetValue4(WXSTRINGCAST str
);
1233 item
->SetValue2(checkableExpr
->IntegerValue());
1235 // Find the first expression that's a list, for submenu
1236 PrologExpr
*subMenuExpr
= expr
->GetFirst();
1237 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1238 subMenuExpr
= subMenuExpr
->GetNext();
1242 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1243 item
->GetChildren().Append(child
);
1244 subMenuExpr
= subMenuExpr
->GetNext();
1251 * Interpret a nested list as a menu
1254 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr)
1256 wxItemResource *menu = new wxItemResource;
1257 // menu->SetType(wxTYPE_MENU);
1258 menu->SetType("wxMenu");
1259 PrologExpr *element = expr->GetFirst();
1262 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1264 menu->GetChildren().Append(item);
1265 element = element->GetNext();
1271 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
)
1273 PrologExpr
*listExpr
= (PrologExpr
*) NULL
;
1274 expr
->AssignAttributeValue("menu", &listExpr
);
1276 return (wxItemResource
*) NULL
;
1278 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1281 return (wxItemResource
*) NULL
;
1283 char *name
= (char *) NULL
;
1284 expr
->AssignAttributeValue("name", &name
);
1287 menuResource
->SetName(name
);
1291 return menuResource
;
1294 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
)
1296 PrologExpr
*listExpr
= (PrologExpr
*) NULL
;
1297 expr
->AssignAttributeValue("menu", &listExpr
);
1299 return (wxItemResource
*) NULL
;
1301 wxItemResource
*resource
= new wxItemResource
;
1302 resource
->SetType("wxMenu");
1303 // resource->SetType(wxTYPE_MENU);
1305 PrologExpr
*element
= listExpr
->GetFirst();
1308 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1309 resource
->GetChildren().Append(menuResource
);
1310 element
= element
->GetNext();
1313 char *name
= (char *) NULL
;
1314 expr
->AssignAttributeValue("name", &name
);
1317 resource
->SetName(name
);
1324 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), PrologExpr
*WXUNUSED(expr
))
1326 return (wxItemResource
*) NULL
;
1329 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), PrologExpr
*expr
)
1331 wxItemResource
*bitmapItem
= new wxItemResource
;
1332 // bitmapItem->SetType(wxTYPE_BITMAP);
1333 bitmapItem
->SetType("wxBitmap");
1334 char *name
= (char *) NULL
;
1335 expr
->AssignAttributeValue("name", &name
);
1338 bitmapItem
->SetName(name
);
1341 // Now parse all bitmap specifications
1342 PrologExpr
*bitmapExpr
= expr
->GetFirst();
1345 if (bitmapExpr
->Number() == 3)
1347 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1348 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1350 // The value part: always a list.
1351 PrologExpr
*listExpr
= bitmapExpr
->Nth(2);
1352 if (listExpr
->Type() == PrologList
)
1354 wxItemResource
*bitmapSpec
= new wxItemResource
;
1355 // bitmapSpec->SetType(wxTYPE_BITMAP);
1356 bitmapSpec
->SetType("wxBitmap");
1358 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1359 // where everything after 'filename' is optional.
1360 PrologExpr
*nameExpr
= listExpr
->Nth(0);
1361 PrologExpr
*typeExpr
= listExpr
->Nth(1);
1362 PrologExpr
*platformExpr
= listExpr
->Nth(2);
1363 PrologExpr
*coloursExpr
= listExpr
->Nth(3);
1364 PrologExpr
*xresExpr
= listExpr
->Nth(4);
1365 PrologExpr
*yresExpr
= listExpr
->Nth(5);
1366 if (nameExpr
&& nameExpr
->StringValue())
1368 wxString
str(nameExpr
->StringValue());
1369 bitmapSpec
->SetName(WXSTRINGCAST str
);
1371 if (typeExpr
&& typeExpr
->StringValue())
1373 wxString
str(typeExpr
->StringValue());
1374 bitmapSpec
->SetValue1(wxParseWindowStyle(WXSTRINGCAST str
));
1377 bitmapSpec
->SetValue1(0);
1379 if (platformExpr
&& platformExpr
->StringValue())
1381 wxString
plat(platformExpr
->StringValue());
1382 if (plat
== "windows" || plat
== "WINDOWS")
1383 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1384 else if (plat
== "x" || plat
== "X")
1385 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1386 else if (plat
== "mac" || plat
== "MAC")
1387 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1389 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1392 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1395 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1399 xres
= (int)xresExpr
->IntegerValue();
1401 yres
= (int)yresExpr
->IntegerValue();
1402 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1404 bitmapItem
->GetChildren().Append(bitmapSpec
);
1408 bitmapExpr
= bitmapExpr
->GetNext();
1414 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
)
1416 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1419 // item->SetType(wxTYPE_ICON);
1420 item
->SetType("wxIcon");
1424 return (wxItemResource
*) NULL
;
1427 // Interpret list expression as a font
1428 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
)
1430 if (expr
->Type() != PrologList
)
1431 return (wxFont
*) NULL
;
1434 int family
= wxSWISS
;
1435 int style
= wxNORMAL
;
1436 int weight
= wxNORMAL
;
1438 wxString
faceName("");
1440 PrologExpr
*pointExpr
= expr
->Nth(0);
1441 PrologExpr
*familyExpr
= expr
->Nth(1);
1442 PrologExpr
*styleExpr
= expr
->Nth(2);
1443 PrologExpr
*weightExpr
= expr
->Nth(3);
1444 PrologExpr
*underlineExpr
= expr
->Nth(4);
1445 PrologExpr
*faceNameExpr
= expr
->Nth(5);
1447 point
= (int)pointExpr
->IntegerValue();
1452 str
= familyExpr
->StringValue();
1453 family
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1457 str
= styleExpr
->StringValue();
1458 style
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1462 str
= weightExpr
->StringValue();
1463 weight
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1466 underline
= (int)underlineExpr
->IntegerValue();
1468 faceName
= faceNameExpr
->StringValue();
1470 char *faceName1
= (char *) NULL
;
1472 faceName1
= WXSTRINGCAST faceName
;
1473 wxFont
*font
= wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
, (underline
!= 0), faceName1
);
1478 * (Re)allocate buffer for reading in from resource file
1481 bool wxReallocateResourceBuffer(void)
1483 if (!wxResourceBuffer
)
1485 wxResourceBufferSize
= 1000;
1486 wxResourceBuffer
= new char[wxResourceBufferSize
];
1489 if (wxResourceBuffer
)
1491 long newSize
= wxResourceBufferSize
+ 1000;
1492 char *tmp
= new char[(int)newSize
];
1493 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1494 delete[] wxResourceBuffer
;
1495 wxResourceBuffer
= tmp
;
1496 wxResourceBufferSize
= newSize
;
1501 static bool wxEatWhiteSpace(FILE *fd
)
1504 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1511 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1513 // Check for comment
1519 bool finished
= FALSE
;
1527 int newCh
= getc(fd
);
1542 return wxEatWhiteSpace(fd
);
1545 bool wxGetResourceToken(FILE *fd
)
1547 if (!wxResourceBuffer
)
1548 wxReallocateResourceBuffer();
1549 wxResourceBuffer
[0] = 0;
1550 wxEatWhiteSpace(fd
);
1556 wxResourceBufferCount
= 0;
1563 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1566 // Escaped characters
1567 else if (ch
== '\\')
1569 int newCh
= getc(fd
);
1572 else if (newCh
== 10)
1580 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1581 wxReallocateResourceBuffer();
1582 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1583 wxResourceBufferCount
++;
1586 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1590 wxResourceBufferCount
= 0;
1592 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1594 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1595 wxReallocateResourceBuffer();
1596 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1597 wxResourceBufferCount
++;
1601 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1609 * Files are in form:
1610 static char *name = "....";
1611 with possible comments.
1614 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1617 table
= wxDefaultResourceTable
;
1619 // static or #define
1620 if (!wxGetResourceToken(fd
))
1626 if (strcmp(wxResourceBuffer
, "#define") == 0)
1628 wxGetResourceToken(fd
);
1629 char *name
= copystring(wxResourceBuffer
);
1630 wxGetResourceToken(fd
);
1631 char *value
= copystring(wxResourceBuffer
);
1632 if (isalpha(value
[0]))
1634 int val
= (int)atol(value
);
1635 wxResourceAddIdentifier(name
, val
, table
);
1639 wxLogWarning(_("#define %s must be an integer."), name
);
1649 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1651 wxGetResourceToken(fd
);
1652 char *name
= copystring(wxResourceBuffer
);
1653 char *actualName
= name
;
1655 actualName
= name
+ 1;
1656 int len
= strlen(name
);
1657 if ((len
> 0) && (name
[len
-1] == '"'))
1659 if (!wxResourceParseIncludeFile(actualName
, table
))
1661 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1666 else if (strcmp(wxResourceBuffer
, "static") != 0)
1669 strcpy(buf
, _("Found "));
1670 strncat(buf
, wxResourceBuffer
, 30);
1671 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1677 if (!wxGetResourceToken(fd
))
1679 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1684 if (strcmp(wxResourceBuffer
, "char") != 0)
1686 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1691 if (!wxGetResourceToken(fd
))
1693 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1698 if (wxResourceBuffer
[0] != '*')
1700 wxLogWarning(_("Expected '*' whilst parsing resource."));
1704 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1707 if (!wxGetResourceToken(fd
))
1709 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1714 if (strcmp(wxResourceBuffer
, "=") != 0)
1716 wxLogWarning(_("Expected '=' whilst parsing resource."));
1721 if (!wxGetResourceToken(fd
))
1723 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1729 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1731 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1736 if (!wxGetResourceToken(fd
))
1744 * Parses string window style into integer window style
1748 * Style flag parsing, e.g.
1749 * "wxSYSTEM_MENU | wxBORDER" -> integer
1752 char *wxResourceParseWord(char *s
, int *i
)
1755 return (char *) NULL
;
1757 static char buf
[150];
1758 int len
= strlen(s
);
1761 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1769 // Eat whitespace and conjunction characters
1770 while ((ii
< len
) &&
1771 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1777 return (char *) NULL
;
1782 struct wxResourceBitListStruct
1788 static wxResourceBitListStruct wxResourceBitListTable
[] =
1791 { "wxSINGLE", wxLB_SINGLE
},
1792 { "wxMULTIPLE", wxLB_MULTIPLE
},
1793 { "wxEXTENDED", wxLB_EXTENDED
},
1794 { "wxLB_SINGLE", wxLB_SINGLE
},
1795 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1796 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1797 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1798 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1799 { "wxLB_SORT", wxLB_SORT
},
1800 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1801 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1804 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1805 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1806 { "wxCB_READONLY", wxCB_READONLY
},
1807 { "wxCB_SORT", wxCB_SORT
},
1810 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1811 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1812 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1815 { "wxPASSWORD", wxPASSWORD
},
1816 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1817 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1818 { "wxTE_READONLY", wxTE_READONLY
},
1819 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1820 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1822 /* wxRadioBox/wxRadioButton */
1823 { "wxRB_GROUP", wxRB_GROUP
},
1824 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1825 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1828 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1829 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1830 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1831 { "wxSL_LABELS", wxSL_LABELS
},
1832 { "wxSL_LEFT", wxSL_LEFT
},
1833 { "wxSL_TOP", wxSL_TOP
},
1834 { "wxSL_RIGHT", wxSL_RIGHT
},
1835 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1836 { "wxSL_BOTH", wxSL_BOTH
},
1837 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1840 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1841 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1844 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1845 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1848 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1849 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1850 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1853 { "wxLC_ICON", wxLC_ICON
},
1854 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1855 { "wxLC_LIST", wxLC_LIST
},
1856 { "wxLC_REPORT", wxLC_REPORT
},
1857 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1858 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1859 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1860 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1861 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1862 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1863 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1864 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1865 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1866 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1869 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1870 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1871 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1872 { "wxSP_WRAP", wxSP_WRAP
},
1875 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1876 { "wxSP_3D", wxSP_3D
},
1877 { "wxSP_BORDER", wxSP_BORDER
},
1880 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1881 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1882 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1883 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1886 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1889 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1890 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1891 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1892 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1893 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1894 { "wxCOLOURED", wxCOLOURED
},
1897 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1898 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1899 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1900 { "wxTB_FLAT", wxTB_FLAT
},
1903 { "wxVSCROLL", wxVSCROLL
},
1904 { "wxHSCROLL", wxHSCROLL
},
1905 { "wxCAPTION", wxCAPTION
},
1906 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1907 { "wxICONIZE", wxICONIZE
},
1908 { "wxMINIMIZE", wxICONIZE
},
1909 { "wxMAXIMIZE", wxMAXIMIZE
},
1911 { "wxMDI_PARENT", 0},
1912 { "wxMDI_CHILD", 0},
1913 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1914 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1915 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1916 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1917 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1918 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1919 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1920 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1921 { "wxBORDER", wxBORDER
},
1922 { "wxRETAINED", wxRETAINED
},
1923 { "wxNATIVE_IMPL", 0},
1924 { "wxEXTENDED_IMPL", 0},
1925 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1926 // { "wxFLAT", wxFLAT},
1927 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1928 { "wxFIXED_LENGTH", 0},
1929 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1930 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1931 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1932 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1933 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1934 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1935 { "wxNO_BORDER", wxNO_BORDER
},
1936 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1938 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1939 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1941 // Text font families
1942 { "wxDEFAULT", wxDEFAULT
},
1943 { "wxDECORATIVE", wxDECORATIVE
},
1944 { "wxROMAN", wxROMAN
},
1945 { "wxSCRIPT", wxSCRIPT
},
1946 { "wxSWISS", wxSWISS
},
1947 { "wxMODERN", wxMODERN
},
1948 { "wxTELETYPE", wxTELETYPE
},
1949 { "wxVARIABLE", wxVARIABLE
},
1950 { "wxFIXED", wxFIXED
},
1951 { "wxNORMAL", wxNORMAL
},
1952 { "wxLIGHT", wxLIGHT
},
1953 { "wxBOLD", wxBOLD
},
1954 { "wxITALIC", wxITALIC
},
1955 { "wxSLANT", wxSLANT
},
1956 { "wxSOLID", wxSOLID
},
1958 { "wxLONG_DASH", wxLONG_DASH
},
1959 { "wxSHORT_DASH", wxSHORT_DASH
},
1960 { "wxDOT_DASH", wxDOT_DASH
},
1961 { "wxUSER_DASH", wxUSER_DASH
},
1962 { "wxTRANSPARENT", wxTRANSPARENT
},
1963 { "wxSTIPPLE", wxSTIPPLE
},
1964 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1965 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1966 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1967 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1968 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1969 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1970 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1971 { "wxJOIN_MITER", wxJOIN_MITER
},
1972 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1973 { "wxCAP_ROUND", wxCAP_ROUND
},
1974 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1975 { "wxCAP_BUTT", wxCAP_BUTT
},
1978 { "wxCLEAR", wxCLEAR
},
1980 { "wxINVERT", wxINVERT
},
1981 { "wxOR_REVERSE", wxOR_REVERSE
},
1982 { "wxAND_REVERSE", wxAND_REVERSE
},
1983 { "wxCOPY", wxCOPY
},
1985 { "wxAND_INVERT", wxAND_INVERT
},
1986 { "wxNO_OP", wxNO_OP
},
1988 { "wxEQUIV", wxEQUIV
},
1989 { "wxSRC_INVERT", wxSRC_INVERT
},
1990 { "wxOR_INVERT", wxOR_INVERT
},
1991 { "wxNAND", wxNAND
},
1995 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1996 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1997 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1998 { "wxWINDING_RULE", wxWINDING_RULE
},
1999 { "wxHORIZONTAL", wxHORIZONTAL
},
2000 { "wxVERTICAL", wxVERTICAL
},
2001 { "wxBOTH", wxBOTH
},
2002 { "wxCENTER_FRAME", wxCENTER_FRAME
},
2004 { "wxYES_NO", wxYES_NO
},
2005 { "wxCANCEL", wxCANCEL
},
2008 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
2009 { "wxICON_HAND", wxICON_HAND
},
2010 { "wxICON_QUESTION", wxICON_QUESTION
},
2011 { "wxICON_INFORMATION", wxICON_INFORMATION
},
2012 { "wxICON_STOP", wxICON_STOP
},
2013 { "wxICON_ASTERISK", wxICON_ASTERISK
},
2014 { "wxICON_MASK", wxICON_MASK
},
2015 { "wxCENTRE", wxCENTRE
},
2016 { "wxCENTER", wxCENTRE
},
2017 { "wxUSER_COLOURS", wxUSER_COLOURS
},
2018 { "wxVERTICAL_LABEL", 0},
2019 { "wxHORIZONTAL_LABEL", 0},
2021 // Bitmap types (not strictly styles)
2022 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
2023 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
2024 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
2025 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2026 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2027 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
2028 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
2029 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
2030 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
2031 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
2032 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
2033 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
2034 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
2035 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
2038 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2040 long wxParseWindowStyle(char *bitListString
)
2045 while ((word
= wxResourceParseWord(bitListString
, &i
)))
2049 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2050 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2052 bitList
|= wxResourceBitListTable
[j
].bits
;
2058 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2066 * Load a bitmap from a wxWindows resource, choosing an optimum
2067 * depth and appropriate type.
2070 wxBitmap
*wxResourceCreateBitmap(char *resource
, wxResourceTable
*table
)
2073 table
= wxDefaultResourceTable
;
2075 wxItemResource
*item
= table
->FindResource(resource
);
2078 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2080 wxLogWarning(_("%s not a bitmap resource specification."), resource
);
2081 return (wxBitmap
*) NULL
;
2083 int thisDepth
= wxDisplayDepth();
2084 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2086 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2088 // Try to find optimum bitmap for this platform/colour depth
2089 wxNode
*node
= item
->GetChildren().First();
2092 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2093 int platform
= (int)child
->GetValue2();
2094 int noColours
= (int)child
->GetValue3();
2096 char *name = child->GetName();
2097 int bitmapType = (int)child->GetValue1();
2098 int xRes = child->GetWidth();
2099 int yRes = child->GetHeight();
2104 case RESOURCE_PLATFORM_ANY
:
2106 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2107 optResource
= child
;
2110 // Maximise the number of colours.
2111 // If noColours is zero (unspecified), then assume this
2112 // is the right one.
2113 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2114 optResource
= child
;
2119 case RESOURCE_PLATFORM_WINDOWS
:
2121 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2122 optResource
= child
;
2125 // Maximise the number of colours
2126 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2127 optResource
= child
;
2133 case RESOURCE_PLATFORM_X
:
2135 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2136 optResource
= child
;
2139 // Maximise the number of colours
2140 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2141 optResource
= child
;
2147 case RESOURCE_PLATFORM_MAC
:
2149 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2150 optResource
= child
;
2153 // Maximise the number of colours
2154 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2155 optResource
= child
;
2163 node
= node
->Next();
2165 // If no matching resource, fail.
2167 return (wxBitmap
*) NULL
;
2169 char *name
= optResource
->GetName();
2170 int bitmapType
= (int)optResource
->GetValue1();
2171 wxBitmap
*bitmap
= (wxBitmap
*) NULL
;
2174 case wxBITMAP_TYPE_XBM_DATA
:
2177 wxItemResource
*item
= table
->FindResource(name
);
2180 wxLogWarning(_("Failed to find XBM resource %s.\n"
2181 "Forgot to use wxResourceLoadBitmapData?"), name
);
2182 return (wxBitmap
*) NULL
;
2184 bitmap
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2186 wxLogWarning(_("No XBM facility available!"));
2190 case wxBITMAP_TYPE_XPM_DATA
:
2192 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2193 wxItemResource
*item
= table
->FindResource(name
);
2196 wxLogWarning(_("Failed to find XPM resource %s.\n"
2197 "Forgot to use wxResourceLoadBitmapData?"), name
);
2198 return (wxBitmap
*) NULL
;
2200 bitmap
= new wxBitmap(item
->GetValue1());
2202 wxLogWarning(_("No XPM facility available!"));
2208 bitmap
= new wxBitmap(name
, bitmapType
);
2213 return (wxBitmap
*) NULL
;
2222 return (wxBitmap
*) NULL
;
2227 wxLogWarning(_("Bitmap resource specification %s not found."), resource
);
2228 return (wxBitmap
*) NULL
;
2233 * Load an icon from a wxWindows resource, choosing an optimum
2234 * depth and appropriate type.
2237 wxIcon
*wxResourceCreateIcon(char *resource
, wxResourceTable
*table
)
2240 table
= wxDefaultResourceTable
;
2242 wxItemResource
*item
= table
->FindResource(resource
);
2245 if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0)
2247 wxLogWarning(_("%s not an icon resource specification."), resource
);
2248 return (wxIcon
*) NULL
;
2250 int thisDepth
= wxDisplayDepth();
2251 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2253 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2255 // Try to find optimum icon for this platform/colour depth
2256 wxNode
*node
= item
->GetChildren().First();
2259 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2260 int platform
= (int)child
->GetValue2();
2261 int noColours
= (int)child
->GetValue3();
2263 char *name = child->GetName();
2264 int bitmapType = (int)child->GetValue1();
2265 int xRes = child->GetWidth();
2266 int yRes = child->GetHeight();
2271 case RESOURCE_PLATFORM_ANY
:
2273 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2274 optResource
= child
;
2277 // Maximise the number of colours.
2278 // If noColours is zero (unspecified), then assume this
2279 // is the right one.
2280 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2281 optResource
= child
;
2286 case RESOURCE_PLATFORM_WINDOWS
:
2288 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2289 optResource
= child
;
2292 // Maximise the number of colours
2293 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2294 optResource
= child
;
2300 case RESOURCE_PLATFORM_X
:
2302 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2303 optResource
= child
;
2306 // Maximise the number of colours
2307 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2308 optResource
= child
;
2314 case RESOURCE_PLATFORM_MAC
:
2316 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2317 optResource
= child
;
2320 // Maximise the number of colours
2321 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2322 optResource
= child
;
2330 node
= node
->Next();
2332 // If no matching resource, fail.
2334 return (wxIcon
*) NULL
;
2336 char *name
= optResource
->GetName();
2337 int bitmapType
= (int)optResource
->GetValue1();
2338 wxIcon
*icon
= (wxIcon
*) NULL
;
2341 case wxBITMAP_TYPE_XBM_DATA
:
2344 wxItemResource
*item
= table
->FindResource(name
);
2347 wxLogWarning(_("Failed to find XBM resource %s.\n"
2348 "Forgot to use wxResourceLoadIconData?"), name
);
2349 return (wxIcon
*) NULL
;
2351 icon
= new wxIcon((char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2353 wxLogWarning(_("No XBM facility available!"));
2357 case wxBITMAP_TYPE_XPM_DATA
:
2359 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2361 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2362 wxItemResource *item = table->FindResource(name);
2366 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2370 icon = new wxIcon((char **)item->GetValue1());
2372 wxLogWarning(_("No XPM facility available!"));
2375 wxLogWarning(_("No XPM icon facility available!"));
2381 wxLogWarning(_("Icon resource specification %s not found."), resource
);
2383 icon
= new wxIcon(name
, bitmapType
);
2389 return (wxIcon
*) NULL
;
2398 return (wxIcon
*) NULL
;
2403 wxLogWarning(_("Icon resource specification %s not found."), resource
);
2404 return (wxIcon
*) NULL
;
2408 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2410 wxMenu
*menu
= new wxMenu
;
2411 wxNode
*node
= item
->GetChildren().First();
2414 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2415 if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0)
2416 menu
->AppendSeparator();
2417 else if (child
->GetChildren().Number() > 0)
2419 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2421 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2425 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2427 node
= node
->Next();
2432 wxMenuBar
*wxResourceCreateMenuBar(char *resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2435 table
= wxDefaultResourceTable
;
2437 wxItemResource
*menuResource
= table
->FindResource(resource
);
2438 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2441 menuBar
= new wxMenuBar
;
2442 wxNode
*node
= menuResource
->GetChildren().First();
2445 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2446 wxMenu
*menu
= wxResourceCreateMenu(child
);
2448 menuBar
->Append(menu
, child
->GetTitle());
2449 node
= node
->Next();
2453 return (wxMenuBar
*) NULL
;
2456 wxMenu
*wxResourceCreateMenu(char *resource
, wxResourceTable
*table
)
2459 table
= wxDefaultResourceTable
;
2461 wxItemResource
*menuResource
= table
->FindResource(resource
);
2462 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2463 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2464 return wxResourceCreateMenu(menuResource
);
2465 return (wxMenu
*) NULL
;
2468 // Global equivalents (so don't have to refer to default table explicitly)
2469 bool wxResourceParseData(char *resource
, wxResourceTable
*table
)
2472 table
= wxDefaultResourceTable
;
2474 return table
->ParseResourceData(resource
);
2477 bool wxResourceParseFile(char *filename
, wxResourceTable
*table
)
2480 table
= wxDefaultResourceTable
;
2482 return table
->ParseResourceFile(filename
);
2485 // Register XBM/XPM data
2486 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2489 table
= wxDefaultResourceTable
;
2491 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2494 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable
*table
)
2497 table
= wxDefaultResourceTable
;
2499 return table
->RegisterResourceBitmapData(name
, data
);
2502 void wxResourceClear(wxResourceTable
*table
)
2505 table
= wxDefaultResourceTable
;
2507 table
->ClearTable();
2514 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable
*table
)
2517 table
= wxDefaultResourceTable
;
2519 table
->identifiers
.Put(name
, (wxObject
*)value
);
2523 int wxResourceGetIdentifier(char *name
, wxResourceTable
*table
)
2526 table
= wxDefaultResourceTable
;
2528 return (int)table
->identifiers
.Get(name
);
2532 * Parse #include file for #defines (only)
2535 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
)
2538 table
= wxDefaultResourceTable
;
2540 FILE *fd
= fopen(f
, "r");
2545 while (wxGetResourceToken(fd
))
2547 if (strcmp(wxResourceBuffer
, "#define") == 0)
2549 wxGetResourceToken(fd
);
2550 char *name
= copystring(wxResourceBuffer
);
2551 wxGetResourceToken(fd
);
2552 char *value
= copystring(wxResourceBuffer
);
2553 if (isdigit(value
[0]))
2555 int val
= (int)atol(value
);
2556 wxResourceAddIdentifier(name
, val
, table
);
2567 * Reading strings as if they were .wxr files
2570 static int getc_string(char *s
)
2572 int ch
= s
[wxResourceStringPtr
];
2577 wxResourceStringPtr
++;
2582 static int ungetc_string(void)
2584 wxResourceStringPtr
--;
2588 bool wxEatWhiteSpaceString(char *s
)
2590 int ch
= getc_string(s
);
2594 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2601 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2602 ch
= getc_string(s
);
2603 // Check for comment
2606 ch
= getc_string(s
);
2609 bool finished
= FALSE
;
2612 ch
= getc_string(s
);
2617 int newCh
= getc_string(s
);
2632 return wxEatWhiteSpaceString(s
);
2635 bool wxGetResourceTokenString(char *s
)
2637 if (!wxResourceBuffer
)
2638 wxReallocateResourceBuffer();
2639 wxResourceBuffer
[0] = 0;
2640 wxEatWhiteSpaceString(s
);
2642 int ch
= getc_string(s
);
2646 wxResourceBufferCount
= 0;
2647 ch
= getc_string(s
);
2653 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2656 // Escaped characters
2657 else if (ch
== '\\')
2659 int newCh
= getc_string(s
);
2662 else if (newCh
== 10)
2670 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2671 wxReallocateResourceBuffer();
2672 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2673 wxResourceBufferCount
++;
2674 ch
= getc_string(s
);
2676 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2680 wxResourceBufferCount
= 0;
2682 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2684 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2685 wxReallocateResourceBuffer();
2686 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2687 wxResourceBufferCount
++;
2689 ch
= getc_string(s
);
2691 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2699 * Files are in form:
2700 static char *name = "....";
2701 with possible comments.
2704 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2707 table
= wxDefaultResourceTable
;
2709 // static or #define
2710 if (!wxGetResourceTokenString(s
))
2716 if (strcmp(wxResourceBuffer
, "#define") == 0)
2718 wxGetResourceTokenString(s
);
2719 char *name
= copystring(wxResourceBuffer
);
2720 wxGetResourceTokenString(s
);
2721 char *value
= copystring(wxResourceBuffer
);
2722 if (isalpha(value
[0]))
2724 int val
= (int)atol(value
);
2725 wxResourceAddIdentifier(name
, val
, table
);
2729 wxLogWarning(_("#define %s must be an integer."), name
);
2740 else if (strcmp(wxResourceBuffer, "#include") == 0)
2742 wxGetResourceTokenString(s);
2743 char *name = copystring(wxResourceBuffer);
2744 char *actualName = name;
2746 actualName = name + 1;
2747 int len = strlen(name);
2748 if ((len > 0) && (name[len-1] == '"'))
2750 if (!wxResourceParseIncludeFile(actualName, table))
2753 sprintf(buf, _("Could not find resource include file %s."), actualName);
2760 else if (strcmp(wxResourceBuffer
, "static") != 0)
2763 strcpy(buf
, _("Found "));
2764 strncat(buf
, wxResourceBuffer
, 30);
2765 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2771 if (!wxGetResourceTokenString(s
))
2773 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2778 if (strcmp(wxResourceBuffer
, "char") != 0)
2780 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2785 if (!wxGetResourceTokenString(s
))
2787 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2792 if (wxResourceBuffer
[0] != '*')
2794 wxLogWarning(_("Expected '*' whilst parsing resource."));
2798 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2801 if (!wxGetResourceTokenString(s
))
2803 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2808 if (strcmp(wxResourceBuffer
, "=") != 0)
2810 wxLogWarning(_("Expected '=' whilst parsing resource."));
2815 if (!wxGetResourceTokenString(s
))
2817 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2823 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2825 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2830 if (!wxGetResourceTokenString(s
))
2837 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2840 table
= wxDefaultResourceTable
;
2845 // Turn backslashes into spaces
2848 int len
= strlen(s
);
2850 for (i
= 0; i
< len
; i
++)
2851 if (s
[i
] == 92 && s
[i
+1] == 13)
2859 wxResourceStringPtr
= 0;
2862 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2866 return wxResourceInterpretResources(*table
, db
);
2870 * resource loading facility
2873 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2876 table
= wxDefaultResourceTable
;
2878 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2879 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2880 if (!resource
|| !resource
->GetType() ||
2881 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2884 char *title
= resource
->GetTitle();
2885 long theWindowStyle
= resource
->GetStyle();
2886 bool isModal
= (resource
->GetValue1() != 0);
2887 int x
= resource
->GetX();
2888 int y
= resource
->GetY();
2889 int width
= resource
->GetWidth();
2890 int height
= resource
->GetHeight();
2891 char *name
= resource
->GetName();
2893 wxFont
*theFont
= resource
->GetFont();
2895 if (IsKindOf(CLASSINFO(wxDialog
)))
2897 wxDialog
*dialogBox
= (wxDialog
*)this;
2898 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2899 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2901 dialogBox
->SetClientSize(width
, height
);
2905 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2912 if (resource
->GetBackgroundColour())
2913 SetBackgroundColour(*resource
->GetBackgroundColour());
2916 if (resource
->GetLabelColour())
2917 SetForegroundColour(*resource
->GetLabelColour());
2918 else if (resource
->GetButtonColour())
2919 SetForegroundColour(*resource
->GetButtonColour());
2921 // Now create children
2922 wxNode
*node
= resource
->GetChildren().First();
2925 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2927 (void) CreateItem(childResource
, table
);
2929 node
= node
->Next();
2934 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxResourceTable
*table
)
2937 table
= wxDefaultResourceTable
;
2938 return table
->CreateItem((wxWindow
*)this, (wxItemResource
*)resource
);
2941 #endif // USE_WX_RESOURCES