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/radiobox.h"
35 #include "wx/listbox.h"
36 #include "wx/choice.h"
37 #include "wx/checkbox.h"
38 #include "wx/slider.h"
39 #include "wx/statbox.h"
43 #include "wx/textctrl.h"
44 #include "wx/msgbxdlg.h"
48 #include "wx/scrolbar.h"
52 #include "wx/combobox.h"
55 #include "wx/validate.h"
64 #include "wx/resource.h"
65 #include "wx/string.h"
66 #include "wx/wxexpr.h"
68 // Forward (private) declarations
69 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
);
70 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
= FALSE
);
71 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
);
72 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
);
73 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
);
74 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, PrologExpr
*expr
);
75 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, PrologExpr
*expr
);
76 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
);
77 // Interpret list expression
78 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
);
80 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
= NULL
);
81 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
= NULL
);
83 wxResourceTable
*wxDefaultResourceTable
= NULL
;
85 static char *wxResourceBuffer
= NULL
;
86 static long wxResourceBufferSize
= 0;
87 static long wxResourceBufferCount
= 0;
88 static int wxResourceStringPtr
= 0;
90 void wxInitializeResourceSystem(void)
92 wxDefaultResourceTable
= new wxResourceTable
;
95 void wxCleanUpResourceSystem(void)
97 delete wxDefaultResourceTable
;
100 void wxWarning(char *msg
)
102 wxMessageBox(msg
, "Warning", wxOK
);
105 #if !USE_SHARED_LIBRARY
106 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
107 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
110 wxItemResource::wxItemResource(void)
116 x
= y
= width
= height
= 0;
117 value1
= value2
= value3
= value5
= 0;
121 backgroundColour
= labelColour
= buttonColour
= NULL
;
126 wxItemResource::~wxItemResource(void)
128 if (itemType
) delete[] itemType
;
129 if (title
) delete[] title
;
130 if (name
) delete[] name
;
131 if (value4
) delete[] value4
;
136 if (backgroundColour
)
137 delete backgroundColour
;
142 wxNode
*node
= children
.First();
145 wxItemResource
*item
= (wxItemResource
*)node
->Data();
148 node
= children
.First();
152 void wxItemResource::SetTitle(char *t
)
157 if (title
) delete[] title
;
159 title
= copystring(t
);
164 void wxItemResource::SetType(char *t
)
169 if (itemType
) delete[] itemType
;
171 itemType
= copystring(t
);
176 void wxItemResource::SetName(char *n
)
181 if (name
) delete[] name
;
183 name
= copystring(n
);
188 void wxItemResource::SetStringValues(wxStringList
*svalues
)
193 stringValues
= svalues
;
198 void wxItemResource::SetValue4(char *v
)
203 if (value4
) delete[] value4
;
205 value4
= copystring(v
);
214 wxResourceTable::wxResourceTable(void):wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
218 wxResourceTable::~wxResourceTable(void)
223 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
225 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
229 void wxResourceTable::AddResource(wxItemResource
*item
)
231 char *name
= item
->GetName();
233 name
= item
->GetTitle();
237 // Delete existing resource, if any.
243 bool wxResourceTable::DeleteResource(const wxString
& name
)
245 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
248 // See if any resource has this as its child; if so, delete from
249 // parent's child list.
252 while ((node
= Next()))
254 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
255 if (parent
->GetChildren().Member(item
))
257 parent
->GetChildren().DeleteObject(item
);
269 bool wxResourceTable::ParseResourceFile(char *filename
)
273 FILE *fd
= fopen(filename
, "r");
277 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
282 return wxResourceInterpretResources(*this, db
);
285 bool wxResourceTable::ParseResourceData(char *data
)
288 if (!db
.ReadPrologFromString(data
))
290 wxWarning("Ill-formed resource file syntax.");
294 return wxResourceInterpretResources(*this, db
);
297 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char bits
[], int width
, int height
)
299 // Register pre-loaded bitmap data
300 wxItemResource
*item
= new wxItemResource
;
301 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
302 item
->SetType("wxXBMData");
304 item
->SetValue1((long)bits
);
305 item
->SetValue2((long)width
);
306 item
->SetValue3((long)height
);
311 bool wxResourceTable::RegisterResourceBitmapData(char *name
, char **data
)
313 // Register pre-loaded bitmap data
314 wxItemResource
*item
= new wxItemResource
;
315 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
316 item
->SetType("wxXPMData");
318 item
->SetValue1((long)data
);
323 bool wxResourceTable::SaveResource(char *WXUNUSED(filename
))
328 void wxResourceTable::ClearTable(void)
331 wxNode
*node
= Next();
334 wxNode
*next
= Next();
335 wxItemResource
*item
= (wxItemResource
*)node
->Data();
342 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, wxItemResource
*childResource
) const
344 int id
= childResource
->GetId();
348 wxControl
*control
= NULL
;
349 wxString
itemType(childResource
->GetType());
350 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
352 if (childResource
->GetValue4())
355 wxBitmap
*bitmap
= childResource
->GetBitmap();
358 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
359 childResource
->SetBitmap(bitmap
);
362 control
= new wxBitmapButton(parent
, id
, *bitmap
,
363 wxPoint(childResource
->GetX(), childResource
->GetY()),
364 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
365 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
368 // Normal, text button
369 control
= new wxButton(parent
, id
, childResource
->GetTitle(),
370 wxPoint(childResource
->GetX(), childResource
->GetY()),
371 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
372 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
374 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
375 itemType
== wxString("wxStaticBitmap"))
377 if (childResource
->GetValue4())
380 wxBitmap
*bitmap
= childResource
->GetBitmap();
383 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
384 childResource
->SetBitmap(bitmap
);
386 #if USE_BITMAP_MESSAGE
388 control
= new wxStaticBitmap(parent
, id
, *bitmap
,
389 wxPoint(childResource
->GetX(), childResource
->GetY()),
390 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
391 childResource
->GetStyle(), childResource
->GetName());
396 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(),
397 wxPoint(childResource
->GetX(), childResource
->GetY()),
398 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
399 childResource
->GetStyle(), childResource
->GetName());
402 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
404 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(),
405 wxPoint(childResource
->GetX(), childResource
->GetY()),
406 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
407 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
409 else if (itemType
== wxString("wxCheckBox"))
411 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(),
412 wxPoint(childResource
->GetX(), childResource
->GetY()),
413 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
414 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
416 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
419 else if (itemType
== wxString("wxGauge"))
421 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(),
422 wxPoint(childResource
->GetX(), childResource
->GetY()),
423 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
424 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
426 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
430 else if (itemType
== wxString("wxRadioButton"))
432 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
433 wxPoint(childResource
->GetX(), childResource
->GetY()),
434 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
435 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
439 else if (itemType
== wxString("wxScrollBar"))
441 control
= new wxScrollBar(parent
, id
,
442 wxPoint(childResource
->GetX(), childResource
->GetY()),
443 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
444 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
445 ((wxScrollBar
*)control
)->SetValue((int)childResource
->GetValue1());
446 ((wxScrollBar
*)control
)->SetPageSize((int)childResource
->GetValue2());
447 ((wxScrollBar
*)control
)->SetObjectLength((int)childResource
->GetValue3());
448 ((wxScrollBar
*)control
)->SetViewLength((int)(long)childResource
->GetValue5());
451 else if (itemType
== wxString("wxSlider"))
453 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
454 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(),
455 wxPoint(childResource
->GetX(), childResource
->GetY()),
456 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
457 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
459 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
461 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(),
462 wxPoint(childResource
->GetX(), childResource
->GetY()),
463 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
464 childResource
->GetStyle(), childResource
->GetName());
466 else if (itemType
== wxString("wxListBox"))
468 wxStringList
*stringList
= childResource
->GetStringValues();
469 wxString
*strings
= NULL
;
471 if (stringList
&& (stringList
->Number() > 0))
473 noStrings
= stringList
->Number();
474 strings
= new wxString
[noStrings
];
475 wxNode
*node
= stringList
->First();
479 strings
[i
] = (char *)node
->Data();
484 control
= new wxListBox(parent
, id
,
485 wxPoint(childResource
->GetX(), childResource
->GetY()),
486 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
487 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
492 else if (itemType
== wxString("wxChoice"))
494 wxStringList
*stringList
= childResource
->GetStringValues();
495 wxString
*strings
= NULL
;
497 if (stringList
&& (stringList
->Number() > 0))
499 noStrings
= stringList
->Number();
500 strings
= new wxString
[noStrings
];
501 wxNode
*node
= stringList
->First();
505 strings
[i
] = (char *)node
->Data();
510 control
= new wxChoice(parent
, id
,
511 wxPoint(childResource
->GetX(), childResource
->GetY()),
512 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
513 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
519 else if (itemType
== wxString("wxComboBox"))
521 wxStringList
*stringList
= childResource
->GetStringValues();
522 wxString
*strings
= NULL
;
524 if (stringList
&& (stringList
->Number() > 0))
526 noStrings
= stringList
->Number();
527 strings
= new wxString
[noStrings
];
528 wxNode
*node
= stringList
->First();
532 strings
[i
] = (char *)node
->Data();
537 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(),
538 wxPoint(childResource
->GetX(), childResource
->GetY()),
539 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
540 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
546 else if (itemType
== wxString("wxRadioBox"))
548 wxStringList
*stringList
= childResource
->GetStringValues();
549 wxString
*strings
= NULL
;
551 if (stringList
&& (stringList
->Number() > 0))
553 noStrings
= stringList
->Number();
554 strings
= new wxString
[noStrings
];
555 wxNode
*node
= stringList
->First();
559 strings
[i
] = (char *)node
->Data();
564 control
= new wxRadioBox(parent
, (const wxWindowID
) id
, wxString(childResource
->GetTitle()),
565 wxPoint(childResource
->GetX(), childResource
->GetY()),
566 wxSize(childResource
->GetWidth(), childResource
->GetHeight()),
567 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
568 childResource
->GetName());
574 if (control
&& childResource
->GetFont())
575 control
->SetFont(*childResource
->GetFont());
580 * Interpret database as a series of resources
583 bool wxResourceInterpretResources(wxResourceTable
& table
, PrologDatabase
& db
)
585 wxNode
*node
= db
.First();
588 PrologExpr
*clause
= (PrologExpr
*)node
->Data();
589 wxString
functor(clause
->Functor());
591 wxItemResource
*item
= NULL
;
592 if (functor
== "dialog")
593 item
= wxResourceInterpretDialog(table
, clause
);
594 else if (functor
== "panel")
595 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
596 else if (functor
== "menubar")
597 item
= wxResourceInterpretMenuBar(table
, clause
);
598 else if (functor
== "menu")
599 item
= wxResourceInterpretMenu(table
, clause
);
600 else if (functor
== "string")
601 item
= wxResourceInterpretString(table
, clause
);
602 else if (functor
== "bitmap")
603 item
= wxResourceInterpretBitmap(table
, clause
);
604 else if (functor
== "icon")
605 item
= wxResourceInterpretIcon(table
, clause
);
609 // Remove any existing resource of same name
611 table
.DeleteResource(item
->GetName());
612 table
.AddResource(item
);
619 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
620 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
621 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
622 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
623 "wxChoice", "wxComboBox" } ;
624 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
626 static bool wxIsValidControlClass(const wxString
& c
)
629 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
631 if ( c
== g_ValidControlClasses
[i
] )
637 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, PrologExpr
*expr
, bool isPanel
)
639 wxItemResource
*dialogItem
= new wxItemResource
;
641 dialogItem
->SetType("wxPanel");
643 dialogItem
->SetType("wxDialog");
647 char *backColourHex
= NULL
;
648 char *labelColourHex
= NULL
;
649 char *buttonColourHex
= NULL
;
651 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
655 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
657 PrologExpr
*labelFontExpr
= NULL
;
658 PrologExpr
*buttonFontExpr
= NULL
;
659 PrologExpr
*fontExpr
= NULL
;
660 expr
->AssignAttributeValue("style", &style
);
661 expr
->AssignAttributeValue("name", &name
);
662 expr
->AssignAttributeValue("title", &title
);
663 expr
->AssignAttributeValue("x", &x
);
664 expr
->AssignAttributeValue("y", &y
);
665 expr
->AssignAttributeValue("width", &width
);
666 expr
->AssignAttributeValue("height", &height
);
667 expr
->AssignAttributeValue("modal", &isModal
);
668 expr
->AssignAttributeValue("label_font", &labelFontExpr
);
669 expr
->AssignAttributeValue("button_font", &buttonFontExpr
);
670 expr
->AssignAttributeValue("font", &fontExpr
);
671 expr
->AssignAttributeValue("background_colour", &backColourHex
);
672 expr
->AssignAttributeValue("label_colour", &labelColourHex
);
673 expr
->AssignAttributeValue("button_colour", &buttonColourHex
);
677 windowStyle
= wxParseWindowStyle(style
);
679 dialogItem
->SetStyle(windowStyle
);
680 dialogItem
->SetValue1(isModal
);
682 dialogItem
->SetName(name
);
684 dialogItem
->SetTitle(title
);
685 dialogItem
->SetSize(x
, y
, width
, height
);
692 r
= wxHexToDec(backColourHex
);
693 g
= wxHexToDec(backColourHex
+2);
694 b
= wxHexToDec(backColourHex
+4);
695 dialogItem
->SetBackgroundColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
696 delete[] backColourHex
;
703 r
= wxHexToDec(labelColourHex
);
704 g
= wxHexToDec(labelColourHex
+2);
705 b
= wxHexToDec(labelColourHex
+4);
706 dialogItem
->SetLabelColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
707 delete[] labelColourHex
;
714 r
= wxHexToDec(buttonColourHex
);
715 g
= wxHexToDec(buttonColourHex
+2);
716 b
= wxHexToDec(buttonColourHex
+4);
717 dialogItem
->SetButtonColour(new wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
718 delete[] buttonColourHex
;
729 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
730 else if (buttonFontExpr
)
731 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
732 else if (labelFontExpr
)
733 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
735 // Now parse all controls
736 PrologExpr
*controlExpr
= expr
->GetFirst();
739 if (controlExpr
->Number() == 3)
741 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
742 if (controlKeyword
!= "" && controlKeyword
== "control")
744 // The value part: always a list.
745 PrologExpr
*listExpr
= controlExpr
->Nth(2);
746 if (listExpr
->Type() == PrologList
)
748 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
751 dialogItem
->GetChildren().Append(controlItem
);
756 controlExpr
= controlExpr
->GetNext();
761 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, PrologExpr
*expr
)
763 wxItemResource
*controlItem
= new wxItemResource
;
765 // First, find the standard features of a control definition:
766 // [optional integer/string id], control name, title, style, name, x, y, width, height
768 wxString controlType
;
773 long windowStyle
= 0;
774 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
777 PrologExpr
*expr1
= expr
->Nth(0);
779 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
781 if ( wxIsValidControlClass(expr1
->StringValue()) )
784 controlType
= expr1
->StringValue();
788 id
= wxResourceGetIdentifier(WXSTRINGCAST expr1
->StringValue(), &table
);
792 sprintf(buf
, "Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)",
793 (const char*) expr1
->StringValue());
800 // Success - we have an id, so the 2nd element must be the control class.
801 controlType
= expr
->Nth(1)->StringValue();
806 else if (expr1
->Type() == PrologInteger
)
808 id
= (int)expr1
->IntegerValue();
809 // Success - we have an id, so the 2nd element must be the control class.
810 controlType
= expr
->Nth(1)->StringValue();
814 expr1
= expr
->Nth(count
);
817 title
= expr1
->StringValue();
819 expr1
= expr
->Nth(count
);
823 style
= expr1
->StringValue();
824 windowStyle
= wxParseWindowStyle(WXSTRINGCAST style
);
827 expr1
= expr
->Nth(count
);
830 name
= expr1
->StringValue();
832 expr1
= expr
->Nth(count
);
835 x
= (int)expr1
->IntegerValue();
837 expr1
= expr
->Nth(count
);
840 y
= (int)expr1
->IntegerValue();
842 expr1
= expr
->Nth(count
);
845 width
= (int)expr1
->IntegerValue();
847 expr1
= expr
->Nth(count
);
850 height
= (int)expr1
->IntegerValue();
852 controlItem
->SetStyle(windowStyle
);
853 controlItem
->SetName(WXSTRINGCAST name
);
854 controlItem
->SetTitle(WXSTRINGCAST title
);
855 controlItem
->SetSize(x
, y
, width
, height
);
856 controlItem
->SetType(WXSTRINGCAST controlType
);
857 controlItem
->SetId(id
);
859 if (controlType
== "wxButton")
861 // Check for bitmap resource name
862 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
864 controlItem
->SetValue4(WXSTRINGCAST expr
->Nth(count
)->StringValue());
866 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
867 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
870 else if (controlType
== "wxCheckBox")
872 // Check for default value
873 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
875 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
877 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
878 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
882 else if (controlType
== "wxRadioButton")
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
== "wxText" || controlType
== "wxTextCtrl")
896 // Check for default value
897 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
899 controlItem
->SetValue4(WXSTRINGCAST expr
->Nth(count
)->StringValue());
902 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
904 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
905 // Do nothing - no label font any more
907 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
908 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
912 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
914 // Check for bitmap resource name
915 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
917 controlItem
->SetValue4(WXSTRINGCAST expr
->Nth(count
)->StringValue());
919 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
920 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
923 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
925 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
926 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
928 else if (controlType
== "wxGauge")
930 // Check for default value
931 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
933 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
937 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
939 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
942 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
944 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
948 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
949 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
954 else if (controlType
== "wxSlider")
956 // Check for default value
957 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
959 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
963 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
965 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
969 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
971 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
974 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
976 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
980 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
981 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
987 else if (controlType
== "wxScrollBar")
990 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
992 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
996 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
998 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1002 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1004 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1008 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1009 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1014 else if (controlType
== "wxListBox")
1016 PrologExpr
*valueList
= NULL
;
1018 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1020 wxStringList
*stringList
= new wxStringList
;
1021 PrologExpr
*stringExpr
= valueList
->GetFirst();
1024 stringList
->Add(stringExpr
->StringValue());
1025 stringExpr
= stringExpr
->GetNext();
1027 controlItem
->SetStringValues(stringList
);
1030 // Check for wxSINGLE/wxMULTIPLE
1031 PrologExpr
*mult
= NULL
;
1032 controlItem
->SetValue1(wxLB_SINGLE
);
1033 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1035 wxString
m(mult
->StringValue());
1036 if (m
== "wxMULTIPLE")
1037 controlItem
->SetValue1(wxLB_MULTIPLE
);
1038 else if (m
== "wxEXTENDED")
1039 controlItem
->SetValue1(wxLB_EXTENDED
);
1041 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1043 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1045 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1046 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1051 else if (controlType
== "wxChoice")
1053 PrologExpr
*valueList
= NULL
;
1054 // Check for default value list
1055 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1057 wxStringList
*stringList
= new wxStringList
;
1058 PrologExpr
*stringExpr
= valueList
->GetFirst();
1061 stringList
->Add(stringExpr
->StringValue());
1062 stringExpr
= stringExpr
->GetNext();
1064 controlItem
->SetStringValues(stringList
);
1068 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1070 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1073 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1074 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1079 else if (controlType
== "wxComboBox")
1081 PrologExpr
*textValue
= expr
->Nth(count
);
1082 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1084 controlItem
->SetValue4(WXSTRINGCAST textValue
->StringValue());
1088 PrologExpr
*valueList
= NULL
;
1089 // Check for default value list
1090 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1092 wxStringList
*stringList
= new wxStringList
;
1093 PrologExpr
*stringExpr
= valueList
->GetFirst();
1096 stringList
->Add(stringExpr
->StringValue());
1097 stringExpr
= stringExpr
->GetNext();
1099 controlItem
->SetStringValues(stringList
);
1103 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1105 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1108 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1109 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1116 else if (controlType
== "wxRadioBox")
1118 PrologExpr
*valueList
= NULL
;
1119 // Check for default value list
1120 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1122 wxStringList
*stringList
= new wxStringList
;
1123 PrologExpr
*stringExpr
= valueList
->GetFirst();
1126 stringList
->Add(stringExpr
->StringValue());
1127 stringExpr
= stringExpr
->GetNext();
1129 controlItem
->SetStringValues(stringList
);
1132 // majorDim (number of rows or cols)
1133 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1135 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1139 controlItem
->SetValue1(0);
1141 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1143 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1146 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1147 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1160 // Forward declaration
1161 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, PrologExpr
*expr
);
1164 * Interpet a menu item
1167 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, PrologExpr
*expr
)
1169 wxItemResource
*item
= new wxItemResource
;
1171 PrologExpr
*labelExpr
= expr
->Nth(0);
1172 PrologExpr
*idExpr
= expr
->Nth(1);
1173 PrologExpr
*helpExpr
= expr
->Nth(2);
1174 PrologExpr
*checkableExpr
= expr
->Nth(3);
1176 // Further keywords/attributes to follow sometime...
1177 if (expr
->Number() == 0)
1179 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1180 item
->SetType("wxMenuSeparator");
1185 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1186 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1189 item
->SetTitle(WXSTRINGCAST labelExpr
->StringValue());
1194 // If a string or word, must look up in identifier table.
1195 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1197 id
= wxResourceGetIdentifier(WXSTRINGCAST idExpr
->StringValue(), &table
);
1201 sprintf(buf
, "Could not resolve menu id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)",
1202 (const char*) idExpr
->StringValue());
1206 else if (idExpr
->Type() == PrologInteger
)
1207 id
= (int)idExpr
->IntegerValue();
1208 item
->SetValue1(id
);
1212 item
->SetValue4(WXSTRINGCAST helpExpr
->StringValue());
1215 item
->SetValue2(checkableExpr
->IntegerValue());
1217 // Find the first expression that's a list, for submenu
1218 PrologExpr
*subMenuExpr
= expr
->GetFirst();
1219 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1220 subMenuExpr
= subMenuExpr
->GetNext();
1224 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1225 item
->GetChildren().Append(child
);
1226 subMenuExpr
= subMenuExpr
->GetNext();
1233 * Interpret a nested list as a menu
1236 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr)
1238 wxItemResource *menu = new wxItemResource;
1239 // menu->SetType(wxTYPE_MENU);
1240 menu->SetType("wxMenu");
1241 PrologExpr *element = expr->GetFirst();
1244 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1246 menu->GetChildren().Append(item);
1247 element = element->GetNext();
1253 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
)
1255 PrologExpr
*listExpr
= NULL
;
1256 expr
->AssignAttributeValue("menu", &listExpr
);
1260 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1266 expr
->AssignAttributeValue("name", &name
);
1269 menuResource
->SetName(name
);
1273 return menuResource
;
1276 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
)
1278 PrologExpr
*listExpr
= NULL
;
1279 expr
->AssignAttributeValue("menu", &listExpr
);
1283 wxItemResource
*resource
= new wxItemResource
;
1284 resource
->SetType("wxMenu");
1285 // resource->SetType(wxTYPE_MENU);
1287 PrologExpr
*element
= listExpr
->GetFirst();
1290 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1291 resource
->GetChildren().Append(menuResource
);
1292 element
= element
->GetNext();
1296 expr
->AssignAttributeValue("name", &name
);
1299 resource
->SetName(name
);
1306 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), PrologExpr
*WXUNUSED(expr
))
1311 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), PrologExpr
*expr
)
1313 wxItemResource
*bitmapItem
= new wxItemResource
;
1314 // bitmapItem->SetType(wxTYPE_BITMAP);
1315 bitmapItem
->SetType("wxBitmap");
1317 expr
->AssignAttributeValue("name", &name
);
1320 bitmapItem
->SetName(name
);
1323 // Now parse all bitmap specifications
1324 PrologExpr
*bitmapExpr
= expr
->GetFirst();
1327 if (bitmapExpr
->Number() == 3)
1329 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1330 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1332 // The value part: always a list.
1333 PrologExpr
*listExpr
= bitmapExpr
->Nth(2);
1334 if (listExpr
->Type() == PrologList
)
1336 wxItemResource
*bitmapSpec
= new wxItemResource
;
1337 // bitmapSpec->SetType(wxTYPE_BITMAP);
1338 bitmapSpec
->SetType("wxBitmap");
1340 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1341 // where everything after 'filename' is optional.
1342 PrologExpr
*nameExpr
= listExpr
->Nth(0);
1343 PrologExpr
*typeExpr
= listExpr
->Nth(1);
1344 PrologExpr
*platformExpr
= listExpr
->Nth(2);
1345 PrologExpr
*coloursExpr
= listExpr
->Nth(3);
1346 PrologExpr
*xresExpr
= listExpr
->Nth(4);
1347 PrologExpr
*yresExpr
= listExpr
->Nth(5);
1348 if (nameExpr
&& nameExpr
->StringValue())
1349 bitmapSpec
->SetName(WXSTRINGCAST nameExpr
->StringValue());
1350 if (typeExpr
&& typeExpr
->StringValue())
1351 bitmapSpec
->SetValue1(wxParseWindowStyle(WXSTRINGCAST typeExpr
->StringValue()));
1353 bitmapSpec
->SetValue1(0);
1355 if (platformExpr
&& platformExpr
->StringValue())
1357 wxString
plat(platformExpr
->StringValue());
1358 if (plat
== "windows" || plat
== "WINDOWS")
1359 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1360 else if (plat
== "x" || plat
== "X")
1361 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1362 else if (plat
== "mac" || plat
== "MAC")
1363 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1365 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1368 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1371 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1375 xres
= (int)xresExpr
->IntegerValue();
1377 yres
= (int)yresExpr
->IntegerValue();
1378 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1380 bitmapItem
->GetChildren().Append(bitmapSpec
);
1384 bitmapExpr
= bitmapExpr
->GetNext();
1390 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
)
1392 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1395 // item->SetType(wxTYPE_ICON);
1396 item
->SetType("wxIcon");
1403 // Interpret list expression as a font
1404 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
)
1406 if (expr
->Type() != PrologList
)
1410 int family
= wxSWISS
;
1411 int style
= wxNORMAL
;
1412 int weight
= wxNORMAL
;
1414 wxString
faceName("");
1416 PrologExpr
*pointExpr
= expr
->Nth(0);
1417 PrologExpr
*familyExpr
= expr
->Nth(1);
1418 PrologExpr
*styleExpr
= expr
->Nth(2);
1419 PrologExpr
*weightExpr
= expr
->Nth(3);
1420 PrologExpr
*underlineExpr
= expr
->Nth(4);
1421 PrologExpr
*faceNameExpr
= expr
->Nth(5);
1423 point
= (int)pointExpr
->IntegerValue();
1425 family
= (int)wxParseWindowStyle(WXSTRINGCAST familyExpr
->StringValue());
1427 style
= (int)wxParseWindowStyle(WXSTRINGCAST styleExpr
->StringValue());
1429 weight
= (int)wxParseWindowStyle(WXSTRINGCAST weightExpr
->StringValue());
1431 underline
= (int)underlineExpr
->IntegerValue();
1433 faceName
= faceNameExpr
->StringValue();
1435 char *faceName1
= NULL
;
1437 faceName1
= WXSTRINGCAST faceName
;
1438 wxFont
*font
= wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
, (underline
!= 0), faceName1
);
1443 * (Re)allocate buffer for reading in from resource file
1446 bool wxReallocateResourceBuffer(void)
1448 if (!wxResourceBuffer
)
1450 wxResourceBufferSize
= 1000;
1451 wxResourceBuffer
= new char[wxResourceBufferSize
];
1454 if (wxResourceBuffer
)
1456 long newSize
= wxResourceBufferSize
+ 1000;
1457 char *tmp
= new char[(int)newSize
];
1458 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1459 delete[] wxResourceBuffer
;
1460 wxResourceBuffer
= tmp
;
1461 wxResourceBufferSize
= newSize
;
1466 static bool wxEatWhiteSpace(FILE *fd
)
1469 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1476 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1478 // Check for comment
1484 bool finished
= FALSE
;
1492 int newCh
= getc(fd
);
1507 return wxEatWhiteSpace(fd
);
1510 bool wxGetResourceToken(FILE *fd
)
1512 if (!wxResourceBuffer
)
1513 wxReallocateResourceBuffer();
1514 wxResourceBuffer
[0] = 0;
1515 wxEatWhiteSpace(fd
);
1521 wxResourceBufferCount
= 0;
1528 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1531 // Escaped characters
1532 else if (ch
== '\\')
1534 int newCh
= getc(fd
);
1537 else if (newCh
== 10)
1545 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1546 wxReallocateResourceBuffer();
1547 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1548 wxResourceBufferCount
++;
1551 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1555 wxResourceBufferCount
= 0;
1557 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1559 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1560 wxReallocateResourceBuffer();
1561 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1562 wxResourceBufferCount
++;
1566 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1574 * Files are in form:
1575 static char *name = "....";
1576 with possible comments.
1579 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1582 table
= wxDefaultResourceTable
;
1584 // static or #define
1585 if (!wxGetResourceToken(fd
))
1591 if (strcmp(wxResourceBuffer
, "#define") == 0)
1593 wxGetResourceToken(fd
);
1594 char *name
= copystring(wxResourceBuffer
);
1595 wxGetResourceToken(fd
);
1596 char *value
= copystring(wxResourceBuffer
);
1597 if (isalpha(value
[0]))
1599 int val
= (int)atol(value
);
1600 wxResourceAddIdentifier(name
, val
, table
);
1605 sprintf(buf
, "#define %s must be an integer.", name
);
1616 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1618 wxGetResourceToken(fd
);
1619 char *name
= copystring(wxResourceBuffer
);
1620 char *actualName
= name
;
1622 actualName
= name
+ 1;
1623 int len
= strlen(name
);
1624 if ((len
> 0) && (name
[len
-1] == '"'))
1626 if (!wxResourceParseIncludeFile(actualName
, table
))
1629 sprintf(buf
, "Could not find resource include file %s.", actualName
);
1635 else if (strcmp(wxResourceBuffer
, "static") != 0)
1638 strcpy(buf
, "Found ");
1639 strncat(buf
, wxResourceBuffer
, 30);
1640 strcat(buf
, ", expected static, #include or #define\nwhilst parsing resource.");
1646 if (!wxGetResourceToken(fd
))
1648 wxWarning("Unexpected end of file whilst parsing resource.");
1653 if (strcmp(wxResourceBuffer
, "char") != 0)
1655 wxWarning("Expected 'char' whilst parsing resource.");
1660 if (!wxGetResourceToken(fd
))
1662 wxWarning("Unexpected end of file whilst parsing resource.");
1667 if (wxResourceBuffer
[0] != '*')
1669 wxWarning("Expected '*' whilst parsing resource.");
1673 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1676 if (!wxGetResourceToken(fd
))
1678 wxWarning("Unexpected end of file whilst parsing resource.");
1683 if (strcmp(wxResourceBuffer
, "=") != 0)
1685 wxWarning("Expected '=' whilst parsing resource.");
1690 if (!wxGetResourceToken(fd
))
1692 wxWarning("Unexpected end of file whilst parsing resource.");
1698 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1701 sprintf(buf
, "%s: ill-formed resource file syntax.", nameBuf
);
1707 if (!wxGetResourceToken(fd
))
1715 * Parses string window style into integer window style
1719 * Style flag parsing, e.g.
1720 * "wxSYSTEM_MENU | wxBORDER" -> integer
1723 char *wxResourceParseWord(char *s
, int *i
)
1728 static char buf
[150];
1729 int len
= strlen(s
);
1732 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1740 // Eat whitespace and conjunction characters
1741 while ((ii
< len
) &&
1742 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1753 struct wxResourceBitListStruct
1759 static wxResourceBitListStruct wxResourceBitListTable
[] =
1762 { "wxSINGLE", wxLB_SINGLE
},
1763 { "wxMULTIPLE", wxLB_MULTIPLE
},
1764 { "wxEXTENDED", wxLB_EXTENDED
},
1765 { "wxLB_SINGLE", wxLB_SINGLE
},
1766 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1767 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1768 { "wxNEEDED_SB", wxNEEDED_SB
},
1769 { "wxALWAYS_SB", wxALWAYS_SB
},
1770 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1771 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1772 { "wxLB_SORT", wxLB_SORT
},
1775 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1776 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1777 { "wxCB_SORT", wxCB_SORT
},
1780 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1783 { "wxPASSWORD", wxPASSWORD
},
1784 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1785 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1786 { "wxTE_READONLY", wxTE_READONLY
},
1787 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1790 { "wxRB_GROUP", wxRB_GROUP
},
1793 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1794 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1795 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1796 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1797 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1800 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1803 { "wxVSCROLL", wxVSCROLL
},
1804 { "wxHSCROLL", wxHSCROLL
},
1805 { "wxCAPTION", wxCAPTION
},
1806 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1807 { "wxICONIZE", wxICONIZE
},
1808 { "wxMINIMIZE", wxICONIZE
},
1809 { "wxMAXIMIZE", wxMAXIMIZE
},
1811 { "wxMDI_PARENT", 0},
1812 { "wxMDI_CHILD", 0},
1813 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1814 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1815 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1816 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1817 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1818 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1819 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1820 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1821 { "wxBORDER", wxBORDER
},
1822 { "wxRETAINED", wxRETAINED
},
1823 { "wxEDITABLE", wxEDITABLE
},
1824 { "wxREADONLY", wxREADONLY
},
1825 { "wxNATIVE_IMPL", 0},
1826 { "wxEXTENDED_IMPL", 0},
1827 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1828 // { "wxFLAT", wxFLAT},
1829 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1830 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1832 #if USE_ENHANCED_DIALOG
1834 { "wxBOTTOM_COMMANDS", wxBOTTOM_COMMANDS
},
1835 { "wxRIGHT_COMMANDS", wxRIGHT_COMMANDS
},
1836 { "wxSTATUS_FOOTER", wxSTATUS_FOOTER
},
1837 { "wxNO_STATUS_FOOTER", wxNO_STATUS_FOOTER
},
1838 { "wxNO_CANCEL_BUTTON", wxNO_CANCEL_BUTTON
},
1839 { "wxCANCEL_BUTTON_FIRST", wxCANCEL_BUTTON_FIRST
},
1840 { "wxCANCEL_BUTTON_SECOND", wxCANCEL_BUTTON_SECOND
},
1841 { "wxCANCEL_BUTTON_LAST", wxCANCEL_BUTTON_LAST
},
1842 { "wxENH_DEFAULT", wxENH_DEFAULT
},
1845 { "wxCOLOURED", wxCOLOURED
},
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(char *bitListString
)
1953 while ((word
= wxResourceParseWord(bitListString
, &i
)))
1957 for (j
= 0; j
< wxResourceBitListCount
; j
++)
1958 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
1960 bitList
|= wxResourceBitListTable
[j
].bits
;
1967 sprintf(buf
, "Unrecognized style %s whilst parsing resource.", word
);
1976 * Load a bitmap from a wxWindows resource, choosing an optimum
1977 * depth and appropriate type.
1980 wxBitmap
*wxResourceCreateBitmap(char *resource
, wxResourceTable
*table
)
1983 table
= wxDefaultResourceTable
;
1985 wxItemResource
*item
= table
->FindResource(resource
);
1988 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
1991 sprintf(buf
, "%s not a bitmap resource specification.", resource
);
1995 int thisDepth
= wxDisplayDepth();
1996 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
1998 wxItemResource
*optResource
= NULL
;
2000 // Try to find optimum bitmap for this platform/colour depth
2001 wxNode
*node
= item
->GetChildren().First();
2004 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2005 int platform
= (int)child
->GetValue2();
2006 int noColours
= (int)child
->GetValue3();
2008 char *name = child->GetName();
2009 int bitmapType = (int)child->GetValue1();
2010 int xRes = child->GetWidth();
2011 int yRes = child->GetHeight();
2016 case RESOURCE_PLATFORM_ANY
:
2018 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2019 optResource
= child
;
2022 // Maximise the number of colours.
2023 // If noColours is zero (unspecified), then assume this
2024 // is the right one.
2025 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2026 optResource
= child
;
2031 case RESOURCE_PLATFORM_WINDOWS
:
2033 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2034 optResource
= child
;
2037 // Maximise the number of colours
2038 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2039 optResource
= child
;
2045 case RESOURCE_PLATFORM_X
:
2047 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2048 optResource
= child
;
2051 // Maximise the number of colours
2052 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2053 optResource
= child
;
2059 case RESOURCE_PLATFORM_MAC
:
2061 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2062 optResource
= child
;
2065 // Maximise the number of colours
2066 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2067 optResource
= child
;
2075 node
= node
->Next();
2077 // If no matching resource, fail.
2081 char *name
= optResource
->GetName();
2082 int bitmapType
= (int)optResource
->GetValue1();
2083 wxBitmap
*bitmap
= NULL
;
2086 case wxBITMAP_TYPE_XBM_DATA
:
2089 wxItemResource
*item
= table
->FindResource(name
);
2093 sprintf(buf
, "Failed to find XBM resource %s.\nForgot to use wxResourceLoadBitmapData?", name
);
2097 bitmap
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2099 wxWarning("No XBM facility available!");
2103 case wxBITMAP_TYPE_XPM_DATA
:
2105 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WINDOWS__) && USE_XPM_IN_MSW)
2106 wxItemResource
*item
= table
->FindResource(name
);
2110 sprintf(buf
, "Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?", name
);
2114 bitmap
= new wxBitmap(item
->GetValue1());
2116 wxWarning("No XPM facility available!");
2122 bitmap
= new wxBitmap(name
, bitmapType
);
2142 sprintf(buf
, "Bitmap resource specification %s not found.", resource
);
2149 * Load an icon from a wxWindows resource, choosing an optimum
2150 * depth and appropriate type.
2153 wxIcon
*wxResourceCreateIcon(char *resource
, wxResourceTable
*table
)
2156 table
= wxDefaultResourceTable
;
2158 wxItemResource
*item
= table
->FindResource(resource
);
2161 if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0)
2164 sprintf(buf
, "%s not an icon resource specification.", resource
);
2168 int thisDepth
= wxDisplayDepth();
2169 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2171 wxItemResource
*optResource
= NULL
;
2173 // Try to find optimum icon for this platform/colour depth
2174 wxNode
*node
= item
->GetChildren().First();
2177 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2178 int platform
= (int)child
->GetValue2();
2179 int noColours
= (int)child
->GetValue3();
2181 char *name = child->GetName();
2182 int bitmapType = (int)child->GetValue1();
2183 int xRes = child->GetWidth();
2184 int yRes = child->GetHeight();
2189 case RESOURCE_PLATFORM_ANY
:
2191 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2192 optResource
= child
;
2195 // Maximise the number of colours.
2196 // If noColours is zero (unspecified), then assume this
2197 // is the right one.
2198 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2199 optResource
= child
;
2204 case RESOURCE_PLATFORM_WINDOWS
:
2206 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2207 optResource
= child
;
2210 // Maximise the number of colours
2211 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2212 optResource
= child
;
2218 case RESOURCE_PLATFORM_X
:
2220 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2221 optResource
= child
;
2224 // Maximise the number of colours
2225 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2226 optResource
= child
;
2232 case RESOURCE_PLATFORM_MAC
:
2234 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2235 optResource
= child
;
2238 // Maximise the number of colours
2239 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2240 optResource
= child
;
2248 node
= node
->Next();
2250 // If no matching resource, fail.
2254 char *name
= optResource
->GetName();
2255 int bitmapType
= (int)optResource
->GetValue1();
2256 wxIcon
*icon
= NULL
;
2259 case wxBITMAP_TYPE_XBM_DATA
:
2262 wxItemResource
*item
= table
->FindResource(name
);
2266 sprintf(buf
, "Failed to find XBM resource %s.\nForgot to use wxResourceLoadIconData?", name
);
2270 icon
= new wxIcon((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2272 wxWarning("No XBM facility available!");
2276 case wxBITMAP_TYPE_XPM_DATA
:
2278 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2280 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WINDOWS__) && USE_XPM_IN_MSW)
2281 wxItemResource *item = table->FindResource(name);
2285 sprintf(buf, "Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?", name);
2289 icon = new wxIcon((char **)item->GetValue1());
2291 wxWarning("No XPM facility available!");
2294 wxWarning("No XPM icon facility available!");
2299 icon
= new wxIcon(name
, bitmapType
);
2319 sprintf(buf
, "Icon resource specification %s not found.", resource
);
2325 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2327 wxMenu
*menu
= new wxMenu
;
2328 wxNode
*node
= item
->GetChildren().First();
2331 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2332 if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0)
2333 menu
->AppendSeparator();
2334 else if (child
->GetChildren().Number() > 0)
2336 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2338 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2342 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2344 node
= node
->Next();
2349 wxMenuBar
*wxResourceCreateMenuBar(char *resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2352 table
= wxDefaultResourceTable
;
2354 wxItemResource
*menuResource
= table
->FindResource(resource
);
2355 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2358 menuBar
= new wxMenuBar
;
2359 wxNode
*node
= menuResource
->GetChildren().First();
2362 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2363 wxMenu
*menu
= wxResourceCreateMenu(child
);
2365 menuBar
->Append(menu
, child
->GetTitle());
2366 node
= node
->Next();
2373 wxMenu
*wxResourceCreateMenu(char *resource
, wxResourceTable
*table
)
2376 table
= wxDefaultResourceTable
;
2378 wxItemResource
*menuResource
= table
->FindResource(resource
);
2379 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2380 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2381 return wxResourceCreateMenu(menuResource
);
2385 // Global equivalents (so don't have to refer to default table explicitly)
2386 bool wxResourceParseData(char *resource
, wxResourceTable
*table
)
2389 table
= wxDefaultResourceTable
;
2391 return table
->ParseResourceData(resource
);
2394 bool wxResourceParseFile(char *filename
, wxResourceTable
*table
)
2397 table
= wxDefaultResourceTable
;
2399 return table
->ParseResourceFile(filename
);
2402 // Register XBM/XPM data
2403 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2406 table
= wxDefaultResourceTable
;
2408 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2411 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable
*table
)
2414 table
= wxDefaultResourceTable
;
2416 return table
->RegisterResourceBitmapData(name
, data
);
2419 void wxResourceClear(wxResourceTable
*table
)
2422 table
= wxDefaultResourceTable
;
2424 table
->ClearTable();
2431 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable
*table
)
2434 table
= wxDefaultResourceTable
;
2436 table
->identifiers
.Put(name
, (wxObject
*)value
);
2440 int wxResourceGetIdentifier(char *name
, wxResourceTable
*table
)
2443 table
= wxDefaultResourceTable
;
2445 return (int)table
->identifiers
.Get(name
);
2449 * Parse #include file for #defines (only)
2452 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
)
2455 table
= wxDefaultResourceTable
;
2457 FILE *fd
= fopen(f
, "r");
2462 while (wxGetResourceToken(fd
))
2464 if (strcmp(wxResourceBuffer
, "#define") == 0)
2466 wxGetResourceToken(fd
);
2467 char *name
= copystring(wxResourceBuffer
);
2468 wxGetResourceToken(fd
);
2469 char *value
= copystring(wxResourceBuffer
);
2470 if (isdigit(value
[0]))
2472 int val
= (int)atol(value
);
2473 wxResourceAddIdentifier(name
, val
, table
);
2484 * Reading strings as if they were .wxr files
2487 static int getc_string(char *s
)
2489 int ch
= s
[wxResourceStringPtr
];
2494 wxResourceStringPtr
++;
2499 static int ungetc_string(void)
2501 wxResourceStringPtr
--;
2505 bool wxEatWhiteSpaceString(char *s
)
2507 int ch
= getc_string(s
);
2511 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2518 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2519 ch
= getc_string(s
);
2520 // Check for comment
2523 ch
= getc_string(s
);
2526 bool finished
= FALSE
;
2529 ch
= getc_string(s
);
2534 int newCh
= getc_string(s
);
2549 return wxEatWhiteSpaceString(s
);
2552 bool wxGetResourceTokenString(char *s
)
2554 if (!wxResourceBuffer
)
2555 wxReallocateResourceBuffer();
2556 wxResourceBuffer
[0] = 0;
2557 wxEatWhiteSpaceString(s
);
2559 int ch
= getc_string(s
);
2563 wxResourceBufferCount
= 0;
2564 ch
= getc_string(s
);
2570 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2573 // Escaped characters
2574 else if (ch
== '\\')
2576 int newCh
= getc_string(s
);
2579 else if (newCh
== 10)
2587 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2588 wxReallocateResourceBuffer();
2589 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2590 wxResourceBufferCount
++;
2591 ch
= getc_string(s
);
2593 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2597 wxResourceBufferCount
= 0;
2599 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2601 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2602 wxReallocateResourceBuffer();
2603 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2604 wxResourceBufferCount
++;
2606 ch
= getc_string(s
);
2608 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2616 * Files are in form:
2617 static char *name = "....";
2618 with possible comments.
2621 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2624 table
= wxDefaultResourceTable
;
2626 // static or #define
2627 if (!wxGetResourceTokenString(s
))
2633 if (strcmp(wxResourceBuffer
, "#define") == 0)
2635 wxGetResourceTokenString(s
);
2636 char *name
= copystring(wxResourceBuffer
);
2637 wxGetResourceTokenString(s
);
2638 char *value
= copystring(wxResourceBuffer
);
2639 if (isalpha(value
[0]))
2641 int val
= (int)atol(value
);
2642 wxResourceAddIdentifier(name
, val
, table
);
2647 sprintf(buf
, "#define %s must be an integer.", name
);
2659 else if (strcmp(wxResourceBuffer, "#include") == 0)
2661 wxGetResourceTokenString(s);
2662 char *name = copystring(wxResourceBuffer);
2663 char *actualName = name;
2665 actualName = name + 1;
2666 int len = strlen(name);
2667 if ((len > 0) && (name[len-1] == '"'))
2669 if (!wxResourceParseIncludeFile(actualName, table))
2672 sprintf(buf, "Could not find resource include file %s.", actualName);
2679 else if (strcmp(wxResourceBuffer
, "static") != 0)
2682 strcpy(buf
, "Found ");
2683 strncat(buf
, wxResourceBuffer
, 30);
2684 strcat(buf
, ", expected static, #include or #define\nwhilst parsing resource.");
2690 if (!wxGetResourceTokenString(s
))
2692 wxWarning("Unexpected end of file whilst parsing resource.");
2697 if (strcmp(wxResourceBuffer
, "char") != 0)
2699 wxWarning("Expected 'char' whilst parsing resource.");
2704 if (!wxGetResourceTokenString(s
))
2706 wxWarning("Unexpected end of file whilst parsing resource.");
2711 if (wxResourceBuffer
[0] != '*')
2713 wxWarning("Expected '*' whilst parsing resource.");
2717 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2720 if (!wxGetResourceTokenString(s
))
2722 wxWarning("Unexpected end of file whilst parsing resource.");
2727 if (strcmp(wxResourceBuffer
, "=") != 0)
2729 wxWarning("Expected '=' whilst parsing resource.");
2734 if (!wxGetResourceTokenString(s
))
2736 wxWarning("Unexpected end of file whilst parsing resource.");
2742 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2745 sprintf(buf
, "%s: ill-formed resource file syntax.", nameBuf
);
2751 if (!wxGetResourceTokenString(s
))
2758 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2761 table
= wxDefaultResourceTable
;
2766 // Turn backslashes into spaces
2769 int len
= strlen(s
);
2771 for (i
= 0; i
< len
; i
++)
2772 if (s
[i
] == 92 && s
[i
+1] == 13)
2780 wxResourceStringPtr
= 0;
2783 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2787 return wxResourceInterpretResources(*table
, db
);
2791 * resource loading facility
2794 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2797 table
= wxDefaultResourceTable
;
2799 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2800 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2801 if (!resource
|| !resource
->GetType() ||
2802 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2805 char *title
= resource
->GetTitle();
2806 long theWindowStyle
= resource
->GetStyle();
2807 bool isModal
= (resource
->GetValue1() != 0);
2808 int x
= resource
->GetX();
2809 int y
= resource
->GetY();
2810 int width
= resource
->GetWidth();
2811 int height
= resource
->GetHeight();
2812 char *name
= resource
->GetName();
2814 wxFont
*theFont
= resource
->GetFont();
2816 if (IsKindOf(CLASSINFO(wxDialog
)))
2818 wxDialog
*dialogBox
= (wxDialog
*)this;
2819 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2820 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2825 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2832 if (resource
->GetBackgroundColour())
2833 SetBackgroundColour(*resource
->GetBackgroundColour());
2836 if (resource
->GetLabelColour())
2837 SetForegroundColour(*resource
->GetLabelColour());
2838 else if (resource
->GetButtonColour())
2839 SetForegroundColour(*resource
->GetButtonColour());
2841 // Now create children
2842 wxNode
*node
= resource
->GetChildren().First();
2845 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2847 (void) CreateItem(childResource
, table
);
2849 node
= node
->Next();
2854 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxResourceTable
*table
)
2857 table
= wxDefaultResourceTable
;
2858 return table
->CreateItem((wxWindow
*)this, (wxItemResource
*)resource
);
2861 #endif // USE_WX_RESOURCES