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
, (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 wxString
str(expr1
->StringValue());
789 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
793 sprintf(buf
, "Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)",
794 (const char*) expr1
->StringValue());
801 // Success - we have an id, so the 2nd element must be the control class.
802 controlType
= expr
->Nth(1)->StringValue();
807 else if (expr1
->Type() == PrologInteger
)
809 id
= (int)expr1
->IntegerValue();
810 // Success - we have an id, so the 2nd element must be the control class.
811 controlType
= expr
->Nth(1)->StringValue();
815 expr1
= expr
->Nth(count
);
818 title
= expr1
->StringValue();
820 expr1
= expr
->Nth(count
);
824 style
= expr1
->StringValue();
825 windowStyle
= wxParseWindowStyle(WXSTRINGCAST style
);
828 expr1
= expr
->Nth(count
);
831 name
= expr1
->StringValue();
833 expr1
= expr
->Nth(count
);
836 x
= (int)expr1
->IntegerValue();
838 expr1
= expr
->Nth(count
);
841 y
= (int)expr1
->IntegerValue();
843 expr1
= expr
->Nth(count
);
846 width
= (int)expr1
->IntegerValue();
848 expr1
= expr
->Nth(count
);
851 height
= (int)expr1
->IntegerValue();
853 controlItem
->SetStyle(windowStyle
);
854 controlItem
->SetName(WXSTRINGCAST name
);
855 controlItem
->SetTitle(WXSTRINGCAST title
);
856 controlItem
->SetSize(x
, y
, width
, height
);
857 controlItem
->SetType(WXSTRINGCAST controlType
);
858 controlItem
->SetId(id
);
860 if (controlType
== "wxButton")
862 // Check for bitmap resource name
863 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
865 wxString
str(expr
->Nth(count
)->StringValue());
866 controlItem
->SetValue4(WXSTRINGCAST str
);
868 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
869 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
872 else if (controlType
== "wxCheckBox")
874 // Check for default value
875 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
877 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
879 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
880 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
884 else if (controlType
== "wxRadioButton")
886 // Check for default value
887 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
889 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
891 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
892 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
896 else if (controlType
== "wxText" || controlType
== "wxTextCtrl")
898 // Check for default value
899 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
901 wxString
str(expr
->Nth(count
)->StringValue());
902 controlItem
->SetValue4(WXSTRINGCAST str
);
905 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
907 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
908 // Do nothing - no label font any more
910 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
911 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
915 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
917 // Check for bitmap resource name
918 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
920 wxString
str(expr
->Nth(count
)->StringValue());
921 controlItem
->SetValue4(WXSTRINGCAST str
);
923 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
924 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
927 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
929 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
930 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
932 else if (controlType
== "wxGauge")
934 // Check for default value
935 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
937 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
941 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
943 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
946 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
948 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
952 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
953 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
958 else if (controlType
== "wxSlider")
960 // Check for default value
961 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
963 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
967 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
969 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
973 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
975 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
978 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
980 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
984 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
985 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
991 else if (controlType
== "wxScrollBar")
994 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
996 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1000 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1002 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1006 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1008 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1012 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1013 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1018 else if (controlType
== "wxListBox")
1020 PrologExpr
*valueList
= NULL
;
1022 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1024 wxStringList
*stringList
= new wxStringList
;
1025 PrologExpr
*stringExpr
= valueList
->GetFirst();
1028 stringList
->Add(stringExpr
->StringValue());
1029 stringExpr
= stringExpr
->GetNext();
1031 controlItem
->SetStringValues(stringList
);
1034 // Check for wxSINGLE/wxMULTIPLE
1035 PrologExpr
*mult
= NULL
;
1036 controlItem
->SetValue1(wxLB_SINGLE
);
1037 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1039 wxString
m(mult
->StringValue());
1040 if (m
== "wxMULTIPLE")
1041 controlItem
->SetValue1(wxLB_MULTIPLE
);
1042 else if (m
== "wxEXTENDED")
1043 controlItem
->SetValue1(wxLB_EXTENDED
);
1045 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1047 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1049 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1050 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1055 else if (controlType
== "wxChoice")
1057 PrologExpr
*valueList
= NULL
;
1058 // Check for default value list
1059 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1061 wxStringList
*stringList
= new wxStringList
;
1062 PrologExpr
*stringExpr
= valueList
->GetFirst();
1065 stringList
->Add(stringExpr
->StringValue());
1066 stringExpr
= stringExpr
->GetNext();
1068 controlItem
->SetStringValues(stringList
);
1072 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1074 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1077 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1078 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1083 else if (controlType
== "wxComboBox")
1085 PrologExpr
*textValue
= expr
->Nth(count
);
1086 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1088 wxString
str(textValue
->StringValue());
1089 controlItem
->SetValue4(WXSTRINGCAST str
);
1093 PrologExpr
*valueList
= NULL
;
1094 // Check for default value list
1095 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1097 wxStringList
*stringList
= new wxStringList
;
1098 PrologExpr
*stringExpr
= valueList
->GetFirst();
1101 stringList
->Add(stringExpr
->StringValue());
1102 stringExpr
= stringExpr
->GetNext();
1104 controlItem
->SetStringValues(stringList
);
1108 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1110 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1113 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1114 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1121 else if (controlType
== "wxRadioBox")
1123 PrologExpr
*valueList
= NULL
;
1124 // Check for default value list
1125 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1127 wxStringList
*stringList
= new wxStringList
;
1128 PrologExpr
*stringExpr
= valueList
->GetFirst();
1131 stringList
->Add(stringExpr
->StringValue());
1132 stringExpr
= stringExpr
->GetNext();
1134 controlItem
->SetStringValues(stringList
);
1137 // majorDim (number of rows or cols)
1138 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1140 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1144 controlItem
->SetValue1(0);
1146 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1148 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1151 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1152 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1165 // Forward declaration
1166 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, PrologExpr
*expr
);
1169 * Interpet a menu item
1172 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, PrologExpr
*expr
)
1174 wxItemResource
*item
= new wxItemResource
;
1176 PrologExpr
*labelExpr
= expr
->Nth(0);
1177 PrologExpr
*idExpr
= expr
->Nth(1);
1178 PrologExpr
*helpExpr
= expr
->Nth(2);
1179 PrologExpr
*checkableExpr
= expr
->Nth(3);
1181 // Further keywords/attributes to follow sometime...
1182 if (expr
->Number() == 0)
1184 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1185 item
->SetType("wxMenuSeparator");
1190 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1191 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1194 wxString
str(labelExpr
->StringValue());
1195 item
->SetTitle(WXSTRINGCAST str
);
1200 // If a string or word, must look up in identifier table.
1201 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1203 wxString
str(idExpr
->StringValue());
1204 id
= wxResourceGetIdentifier(WXSTRINGCAST str
, &table
);
1208 sprintf(buf
, "Could not resolve menu id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)",
1209 (const char*) idExpr
->StringValue());
1213 else if (idExpr
->Type() == PrologInteger
)
1214 id
= (int)idExpr
->IntegerValue();
1215 item
->SetValue1(id
);
1219 wxString
str(helpExpr
->StringValue());
1220 item
->SetValue4(WXSTRINGCAST str
);
1223 item
->SetValue2(checkableExpr
->IntegerValue());
1225 // Find the first expression that's a list, for submenu
1226 PrologExpr
*subMenuExpr
= expr
->GetFirst();
1227 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1228 subMenuExpr
= subMenuExpr
->GetNext();
1232 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1233 item
->GetChildren().Append(child
);
1234 subMenuExpr
= subMenuExpr
->GetNext();
1241 * Interpret a nested list as a menu
1244 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, PrologExpr *expr)
1246 wxItemResource *menu = new wxItemResource;
1247 // menu->SetType(wxTYPE_MENU);
1248 menu->SetType("wxMenu");
1249 PrologExpr *element = expr->GetFirst();
1252 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1254 menu->GetChildren().Append(item);
1255 element = element->GetNext();
1261 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, PrologExpr
*expr
)
1263 PrologExpr
*listExpr
= NULL
;
1264 expr
->AssignAttributeValue("menu", &listExpr
);
1268 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1274 expr
->AssignAttributeValue("name", &name
);
1277 menuResource
->SetName(name
);
1281 return menuResource
;
1284 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, PrologExpr
*expr
)
1286 PrologExpr
*listExpr
= NULL
;
1287 expr
->AssignAttributeValue("menu", &listExpr
);
1291 wxItemResource
*resource
= new wxItemResource
;
1292 resource
->SetType("wxMenu");
1293 // resource->SetType(wxTYPE_MENU);
1295 PrologExpr
*element
= listExpr
->GetFirst();
1298 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1299 resource
->GetChildren().Append(menuResource
);
1300 element
= element
->GetNext();
1304 expr
->AssignAttributeValue("name", &name
);
1307 resource
->SetName(name
);
1314 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), PrologExpr
*WXUNUSED(expr
))
1319 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), PrologExpr
*expr
)
1321 wxItemResource
*bitmapItem
= new wxItemResource
;
1322 // bitmapItem->SetType(wxTYPE_BITMAP);
1323 bitmapItem
->SetType("wxBitmap");
1325 expr
->AssignAttributeValue("name", &name
);
1328 bitmapItem
->SetName(name
);
1331 // Now parse all bitmap specifications
1332 PrologExpr
*bitmapExpr
= expr
->GetFirst();
1335 if (bitmapExpr
->Number() == 3)
1337 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1338 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1340 // The value part: always a list.
1341 PrologExpr
*listExpr
= bitmapExpr
->Nth(2);
1342 if (listExpr
->Type() == PrologList
)
1344 wxItemResource
*bitmapSpec
= new wxItemResource
;
1345 // bitmapSpec->SetType(wxTYPE_BITMAP);
1346 bitmapSpec
->SetType("wxBitmap");
1348 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1349 // where everything after 'filename' is optional.
1350 PrologExpr
*nameExpr
= listExpr
->Nth(0);
1351 PrologExpr
*typeExpr
= listExpr
->Nth(1);
1352 PrologExpr
*platformExpr
= listExpr
->Nth(2);
1353 PrologExpr
*coloursExpr
= listExpr
->Nth(3);
1354 PrologExpr
*xresExpr
= listExpr
->Nth(4);
1355 PrologExpr
*yresExpr
= listExpr
->Nth(5);
1356 if (nameExpr
&& nameExpr
->StringValue())
1358 wxString
str(nameExpr
->StringValue());
1359 bitmapSpec
->SetName(WXSTRINGCAST str
);
1361 if (typeExpr
&& typeExpr
->StringValue())
1363 wxString
str(typeExpr
->StringValue());
1364 bitmapSpec
->SetValue1(wxParseWindowStyle(WXSTRINGCAST str
));
1367 bitmapSpec
->SetValue1(0);
1369 if (platformExpr
&& platformExpr
->StringValue())
1371 wxString
plat(platformExpr
->StringValue());
1372 if (plat
== "windows" || plat
== "WINDOWS")
1373 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1374 else if (plat
== "x" || plat
== "X")
1375 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1376 else if (plat
== "mac" || plat
== "MAC")
1377 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1379 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1382 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1385 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1389 xres
= (int)xresExpr
->IntegerValue();
1391 yres
= (int)yresExpr
->IntegerValue();
1392 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1394 bitmapItem
->GetChildren().Append(bitmapSpec
);
1398 bitmapExpr
= bitmapExpr
->GetNext();
1404 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, PrologExpr
*expr
)
1406 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1409 // item->SetType(wxTYPE_ICON);
1410 item
->SetType("wxIcon");
1417 // Interpret list expression as a font
1418 wxFont
*wxResourceInterpretFontSpec(PrologExpr
*expr
)
1420 if (expr
->Type() != PrologList
)
1424 int family
= wxSWISS
;
1425 int style
= wxNORMAL
;
1426 int weight
= wxNORMAL
;
1428 wxString
faceName("");
1430 PrologExpr
*pointExpr
= expr
->Nth(0);
1431 PrologExpr
*familyExpr
= expr
->Nth(1);
1432 PrologExpr
*styleExpr
= expr
->Nth(2);
1433 PrologExpr
*weightExpr
= expr
->Nth(3);
1434 PrologExpr
*underlineExpr
= expr
->Nth(4);
1435 PrologExpr
*faceNameExpr
= expr
->Nth(5);
1437 point
= (int)pointExpr
->IntegerValue();
1442 str
= familyExpr
->StringValue();
1443 family
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1447 str
= styleExpr
->StringValue();
1448 style
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1452 str
= weightExpr
->StringValue();
1453 weight
= (int)wxParseWindowStyle(WXSTRINGCAST str
);
1456 underline
= (int)underlineExpr
->IntegerValue();
1458 faceName
= faceNameExpr
->StringValue();
1460 char *faceName1
= NULL
;
1462 faceName1
= WXSTRINGCAST faceName
;
1463 wxFont
*font
= wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
, (underline
!= 0), faceName1
);
1468 * (Re)allocate buffer for reading in from resource file
1471 bool wxReallocateResourceBuffer(void)
1473 if (!wxResourceBuffer
)
1475 wxResourceBufferSize
= 1000;
1476 wxResourceBuffer
= new char[wxResourceBufferSize
];
1479 if (wxResourceBuffer
)
1481 long newSize
= wxResourceBufferSize
+ 1000;
1482 char *tmp
= new char[(int)newSize
];
1483 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1484 delete[] wxResourceBuffer
;
1485 wxResourceBuffer
= tmp
;
1486 wxResourceBufferSize
= newSize
;
1491 static bool wxEatWhiteSpace(FILE *fd
)
1494 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1501 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1503 // Check for comment
1509 bool finished
= FALSE
;
1517 int newCh
= getc(fd
);
1532 return wxEatWhiteSpace(fd
);
1535 bool wxGetResourceToken(FILE *fd
)
1537 if (!wxResourceBuffer
)
1538 wxReallocateResourceBuffer();
1539 wxResourceBuffer
[0] = 0;
1540 wxEatWhiteSpace(fd
);
1546 wxResourceBufferCount
= 0;
1553 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1556 // Escaped characters
1557 else if (ch
== '\\')
1559 int newCh
= getc(fd
);
1562 else if (newCh
== 10)
1570 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1571 wxReallocateResourceBuffer();
1572 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1573 wxResourceBufferCount
++;
1576 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1580 wxResourceBufferCount
= 0;
1582 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1584 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1585 wxReallocateResourceBuffer();
1586 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1587 wxResourceBufferCount
++;
1591 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1599 * Files are in form:
1600 static char *name = "....";
1601 with possible comments.
1604 bool wxResourceReadOneResource(FILE *fd
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1607 table
= wxDefaultResourceTable
;
1609 // static or #define
1610 if (!wxGetResourceToken(fd
))
1616 if (strcmp(wxResourceBuffer
, "#define") == 0)
1618 wxGetResourceToken(fd
);
1619 char *name
= copystring(wxResourceBuffer
);
1620 wxGetResourceToken(fd
);
1621 char *value
= copystring(wxResourceBuffer
);
1622 if (isalpha(value
[0]))
1624 int val
= (int)atol(value
);
1625 wxResourceAddIdentifier(name
, val
, table
);
1630 sprintf(buf
, "#define %s must be an integer.", name
);
1641 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1643 wxGetResourceToken(fd
);
1644 char *name
= copystring(wxResourceBuffer
);
1645 char *actualName
= name
;
1647 actualName
= name
+ 1;
1648 int len
= strlen(name
);
1649 if ((len
> 0) && (name
[len
-1] == '"'))
1651 if (!wxResourceParseIncludeFile(actualName
, table
))
1654 sprintf(buf
, "Could not find resource include file %s.", actualName
);
1660 else if (strcmp(wxResourceBuffer
, "static") != 0)
1663 strcpy(buf
, "Found ");
1664 strncat(buf
, wxResourceBuffer
, 30);
1665 strcat(buf
, ", expected static, #include or #define\nwhilst parsing resource.");
1671 if (!wxGetResourceToken(fd
))
1673 wxWarning("Unexpected end of file whilst parsing resource.");
1678 if (strcmp(wxResourceBuffer
, "char") != 0)
1680 wxWarning("Expected 'char' whilst parsing resource.");
1685 if (!wxGetResourceToken(fd
))
1687 wxWarning("Unexpected end of file whilst parsing resource.");
1692 if (wxResourceBuffer
[0] != '*')
1694 wxWarning("Expected '*' whilst parsing resource.");
1698 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1701 if (!wxGetResourceToken(fd
))
1703 wxWarning("Unexpected end of file whilst parsing resource.");
1708 if (strcmp(wxResourceBuffer
, "=") != 0)
1710 wxWarning("Expected '=' whilst parsing resource.");
1715 if (!wxGetResourceToken(fd
))
1717 wxWarning("Unexpected end of file whilst parsing resource.");
1723 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1726 sprintf(buf
, "%s: ill-formed resource file syntax.", nameBuf
);
1732 if (!wxGetResourceToken(fd
))
1740 * Parses string window style into integer window style
1744 * Style flag parsing, e.g.
1745 * "wxSYSTEM_MENU | wxBORDER" -> integer
1748 char *wxResourceParseWord(char *s
, int *i
)
1753 static char buf
[150];
1754 int len
= strlen(s
);
1757 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1765 // Eat whitespace and conjunction characters
1766 while ((ii
< len
) &&
1767 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1778 struct wxResourceBitListStruct
1784 static wxResourceBitListStruct wxResourceBitListTable
[] =
1787 { "wxSINGLE", wxLB_SINGLE
},
1788 { "wxMULTIPLE", wxLB_MULTIPLE
},
1789 { "wxEXTENDED", wxLB_EXTENDED
},
1790 { "wxLB_SINGLE", wxLB_SINGLE
},
1791 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1792 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1793 { "wxNEEDED_SB", wxNEEDED_SB
},
1794 { "wxALWAYS_SB", wxALWAYS_SB
},
1795 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1796 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1797 { "wxLB_SORT", wxLB_SORT
},
1798 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1799 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1802 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1803 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1804 { "wxCB_READONLY", wxCB_READONLY
},
1805 { "wxCB_SORT", wxCB_SORT
},
1808 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1809 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1810 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1813 { "wxPASSWORD", wxPASSWORD
},
1814 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1815 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1816 { "wxTE_READONLY", wxTE_READONLY
},
1817 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1818 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1820 /* wxRadioBox/wxRadioButton */
1821 { "wxRB_GROUP", wxRB_GROUP
},
1822 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1823 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1826 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1827 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1828 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1829 { "wxSL_LABELS", wxSL_LABELS
},
1830 { "wxSL_LEFT", wxSL_LEFT
},
1831 { "wxSL_TOP", wxSL_TOP
},
1832 { "wxSL_RIGHT", wxSL_RIGHT
},
1833 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1834 { "wxSL_BOTH", wxSL_BOTH
},
1835 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1838 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1839 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1842 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1843 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1846 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1847 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1850 { "wxLC_ICON", wxLC_ICON
},
1851 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1852 { "wxLC_LIST", wxLC_LIST
},
1853 { "wxLC_REPORT", wxLC_REPORT
},
1854 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1855 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1856 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1857 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1858 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1859 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1860 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1861 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1862 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1863 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1866 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1867 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1868 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1869 { "wxSP_WRAP", wxSP_WRAP
},
1872 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1873 { "wxSP_3D", wxSP_3D
},
1874 { "wxSP_BORDER", wxSP_BORDER
},
1877 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1878 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1879 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1880 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1883 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1886 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1887 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1888 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1889 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1890 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1891 { "wxCOLOURED", wxCOLOURED
},
1894 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1897 { "wxVSCROLL", wxVSCROLL
},
1898 { "wxHSCROLL", wxHSCROLL
},
1899 { "wxCAPTION", wxCAPTION
},
1900 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1901 { "wxICONIZE", wxICONIZE
},
1902 { "wxMINIMIZE", wxICONIZE
},
1903 { "wxMAXIMIZE", wxMAXIMIZE
},
1905 { "wxMDI_PARENT", 0},
1906 { "wxMDI_CHILD", 0},
1907 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1908 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1909 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1910 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1911 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1912 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1913 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1914 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1915 { "wxBORDER", wxBORDER
},
1916 { "wxRETAINED", wxRETAINED
},
1917 { "wxEDITABLE", wxEDITABLE
},
1918 { "wxREADONLY", wxREADONLY
},
1919 { "wxNATIVE_IMPL", 0},
1920 { "wxEXTENDED_IMPL", 0},
1921 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1922 // { "wxFLAT", wxFLAT},
1923 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1924 { "wxFIXED_LENGTH", 0},
1925 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1926 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1927 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1928 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1929 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1930 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1931 { "wxNO_BORDER", wxNO_BORDER
},
1932 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1934 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1935 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1937 // Text font families
1938 { "wxDEFAULT", wxDEFAULT
},
1939 { "wxDECORATIVE", wxDECORATIVE
},
1940 { "wxROMAN", wxROMAN
},
1941 { "wxSCRIPT", wxSCRIPT
},
1942 { "wxSWISS", wxSWISS
},
1943 { "wxMODERN", wxMODERN
},
1944 { "wxTELETYPE", wxTELETYPE
},
1945 { "wxVARIABLE", wxVARIABLE
},
1946 { "wxFIXED", wxFIXED
},
1947 { "wxNORMAL", wxNORMAL
},
1948 { "wxLIGHT", wxLIGHT
},
1949 { "wxBOLD", wxBOLD
},
1950 { "wxITALIC", wxITALIC
},
1951 { "wxSLANT", wxSLANT
},
1952 { "wxSOLID", wxSOLID
},
1954 { "wxLONG_DASH", wxLONG_DASH
},
1955 { "wxSHORT_DASH", wxSHORT_DASH
},
1956 { "wxDOT_DASH", wxDOT_DASH
},
1957 { "wxUSER_DASH", wxUSER_DASH
},
1958 { "wxTRANSPARENT", wxTRANSPARENT
},
1959 { "wxSTIPPLE", wxSTIPPLE
},
1960 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1961 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1962 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1963 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1964 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1965 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1966 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1967 { "wxJOIN_MITER", wxJOIN_MITER
},
1968 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1969 { "wxCAP_ROUND", wxCAP_ROUND
},
1970 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1971 { "wxCAP_BUTT", wxCAP_BUTT
},
1974 { "wxCLEAR", wxCLEAR
},
1976 { "wxINVERT", wxINVERT
},
1977 { "wxOR_REVERSE", wxOR_REVERSE
},
1978 { "wxAND_REVERSE", wxAND_REVERSE
},
1979 { "wxCOPY", wxCOPY
},
1981 { "wxAND_INVERT", wxAND_INVERT
},
1982 { "wxNO_OP", wxNO_OP
},
1984 { "wxEQUIV", wxEQUIV
},
1985 { "wxSRC_INVERT", wxSRC_INVERT
},
1986 { "wxOR_INVERT", wxOR_INVERT
},
1987 { "wxNAND", wxNAND
},
1991 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1992 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1993 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1994 { "wxWINDING_RULE", wxWINDING_RULE
},
1995 { "wxHORIZONTAL", wxHORIZONTAL
},
1996 { "wxVERTICAL", wxVERTICAL
},
1997 { "wxBOTH", wxBOTH
},
1998 { "wxCENTER_FRAME", wxCENTER_FRAME
},
2000 { "wxYES_NO", wxYES_NO
},
2001 { "wxCANCEL", wxCANCEL
},
2004 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
2005 { "wxICON_HAND", wxICON_HAND
},
2006 { "wxICON_QUESTION", wxICON_QUESTION
},
2007 { "wxICON_INFORMATION", wxICON_INFORMATION
},
2008 { "wxICON_STOP", wxICON_STOP
},
2009 { "wxICON_ASTERISK", wxICON_ASTERISK
},
2010 { "wxICON_MASK", wxICON_MASK
},
2011 { "wxCENTRE", wxCENTRE
},
2012 { "wxCENTER", wxCENTRE
},
2013 { "wxUSER_COLOURS", wxUSER_COLOURS
},
2014 { "wxVERTICAL_LABEL", 0},
2015 { "wxHORIZONTAL_LABEL", 0},
2017 // Bitmap types (not strictly styles)
2018 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
2019 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
2020 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
2021 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2022 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
2023 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
2024 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
2025 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
2026 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
2027 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
2028 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
2029 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
2030 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
2031 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
2034 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2036 long wxParseWindowStyle(char *bitListString
)
2041 while ((word
= wxResourceParseWord(bitListString
, &i
)))
2045 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2046 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2048 bitList
|= wxResourceBitListTable
[j
].bits
;
2055 sprintf(buf
, "Unrecognized style %s whilst parsing resource.", word
);
2064 * Load a bitmap from a wxWindows resource, choosing an optimum
2065 * depth and appropriate type.
2068 wxBitmap
*wxResourceCreateBitmap(char *resource
, wxResourceTable
*table
)
2071 table
= wxDefaultResourceTable
;
2073 wxItemResource
*item
= table
->FindResource(resource
);
2076 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2079 sprintf(buf
, "%s not a bitmap resource specification.", resource
);
2083 int thisDepth
= wxDisplayDepth();
2084 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2086 wxItemResource
*optResource
= 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.
2169 char *name
= optResource
->GetName();
2170 int bitmapType
= (int)optResource
->GetValue1();
2171 wxBitmap
*bitmap
= NULL
;
2174 case wxBITMAP_TYPE_XBM_DATA
:
2177 wxItemResource
*item
= table
->FindResource(name
);
2181 sprintf(buf
, "Failed to find XBM resource %s.\nForgot to use wxResourceLoadBitmapData?", name
);
2185 bitmap
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2187 wxWarning("No XBM facility available!");
2191 case wxBITMAP_TYPE_XPM_DATA
:
2193 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2194 wxItemResource
*item
= table
->FindResource(name
);
2198 sprintf(buf
, "Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?", name
);
2202 bitmap
= new wxBitmap(item
->GetValue1());
2204 wxWarning("No XPM facility available!");
2210 bitmap
= new wxBitmap(name
, bitmapType
);
2230 sprintf(buf
, "Bitmap resource specification %s not found.", resource
);
2237 * Load an icon from a wxWindows resource, choosing an optimum
2238 * depth and appropriate type.
2241 wxIcon
*wxResourceCreateIcon(char *resource
, wxResourceTable
*table
)
2244 table
= wxDefaultResourceTable
;
2246 wxItemResource
*item
= table
->FindResource(resource
);
2249 if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0)
2252 sprintf(buf
, "%s not an icon resource specification.", resource
);
2256 int thisDepth
= wxDisplayDepth();
2257 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2259 wxItemResource
*optResource
= NULL
;
2261 // Try to find optimum icon for this platform/colour depth
2262 wxNode
*node
= item
->GetChildren().First();
2265 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2266 int platform
= (int)child
->GetValue2();
2267 int noColours
= (int)child
->GetValue3();
2269 char *name = child->GetName();
2270 int bitmapType = (int)child->GetValue1();
2271 int xRes = child->GetWidth();
2272 int yRes = child->GetHeight();
2277 case RESOURCE_PLATFORM_ANY
:
2279 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2280 optResource
= child
;
2283 // Maximise the number of colours.
2284 // If noColours is zero (unspecified), then assume this
2285 // is the right one.
2286 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2287 optResource
= child
;
2292 case RESOURCE_PLATFORM_WINDOWS
:
2294 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2295 optResource
= child
;
2298 // Maximise the number of colours
2299 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2300 optResource
= child
;
2306 case RESOURCE_PLATFORM_X
:
2308 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2309 optResource
= child
;
2312 // Maximise the number of colours
2313 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2314 optResource
= child
;
2320 case RESOURCE_PLATFORM_MAC
:
2322 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2323 optResource
= child
;
2326 // Maximise the number of colours
2327 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2328 optResource
= child
;
2336 node
= node
->Next();
2338 // If no matching resource, fail.
2342 char *name
= optResource
->GetName();
2343 int bitmapType
= (int)optResource
->GetValue1();
2344 wxIcon
*icon
= NULL
;
2347 case wxBITMAP_TYPE_XBM_DATA
:
2350 wxItemResource
*item
= table
->FindResource(name
);
2354 sprintf(buf
, "Failed to find XBM resource %s.\nForgot to use wxResourceLoadIconData?", name
);
2358 icon
= new wxIcon((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2360 wxWarning("No XBM facility available!");
2364 case wxBITMAP_TYPE_XPM_DATA
:
2366 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2368 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2369 wxItemResource *item = table->FindResource(name);
2373 sprintf(buf, "Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?", name);
2377 icon = new wxIcon((char **)item->GetValue1());
2379 wxWarning("No XPM facility available!");
2382 wxWarning("No XPM icon facility available!");
2387 icon
= new wxIcon(name
, bitmapType
);
2407 sprintf(buf
, "Icon resource specification %s not found.", resource
);
2413 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2415 wxMenu
*menu
= new wxMenu
;
2416 wxNode
*node
= item
->GetChildren().First();
2419 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2420 if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0)
2421 menu
->AppendSeparator();
2422 else if (child
->GetChildren().Number() > 0)
2424 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2426 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2430 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2432 node
= node
->Next();
2437 wxMenuBar
*wxResourceCreateMenuBar(char *resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2440 table
= wxDefaultResourceTable
;
2442 wxItemResource
*menuResource
= table
->FindResource(resource
);
2443 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2446 menuBar
= new wxMenuBar
;
2447 wxNode
*node
= menuResource
->GetChildren().First();
2450 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2451 wxMenu
*menu
= wxResourceCreateMenu(child
);
2453 menuBar
->Append(menu
, child
->GetTitle());
2454 node
= node
->Next();
2461 wxMenu
*wxResourceCreateMenu(char *resource
, wxResourceTable
*table
)
2464 table
= wxDefaultResourceTable
;
2466 wxItemResource
*menuResource
= table
->FindResource(resource
);
2467 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2468 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2469 return wxResourceCreateMenu(menuResource
);
2473 // Global equivalents (so don't have to refer to default table explicitly)
2474 bool wxResourceParseData(char *resource
, wxResourceTable
*table
)
2477 table
= wxDefaultResourceTable
;
2479 return table
->ParseResourceData(resource
);
2482 bool wxResourceParseFile(char *filename
, wxResourceTable
*table
)
2485 table
= wxDefaultResourceTable
;
2487 return table
->ParseResourceFile(filename
);
2490 // Register XBM/XPM data
2491 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2494 table
= wxDefaultResourceTable
;
2496 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2499 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable
*table
)
2502 table
= wxDefaultResourceTable
;
2504 return table
->RegisterResourceBitmapData(name
, data
);
2507 void wxResourceClear(wxResourceTable
*table
)
2510 table
= wxDefaultResourceTable
;
2512 table
->ClearTable();
2519 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable
*table
)
2522 table
= wxDefaultResourceTable
;
2524 table
->identifiers
.Put(name
, (wxObject
*)value
);
2528 int wxResourceGetIdentifier(char *name
, wxResourceTable
*table
)
2531 table
= wxDefaultResourceTable
;
2533 return (int)table
->identifiers
.Get(name
);
2537 * Parse #include file for #defines (only)
2540 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
)
2543 table
= wxDefaultResourceTable
;
2545 FILE *fd
= fopen(f
, "r");
2550 while (wxGetResourceToken(fd
))
2552 if (strcmp(wxResourceBuffer
, "#define") == 0)
2554 wxGetResourceToken(fd
);
2555 char *name
= copystring(wxResourceBuffer
);
2556 wxGetResourceToken(fd
);
2557 char *value
= copystring(wxResourceBuffer
);
2558 if (isdigit(value
[0]))
2560 int val
= (int)atol(value
);
2561 wxResourceAddIdentifier(name
, val
, table
);
2572 * Reading strings as if they were .wxr files
2575 static int getc_string(char *s
)
2577 int ch
= s
[wxResourceStringPtr
];
2582 wxResourceStringPtr
++;
2587 static int ungetc_string(void)
2589 wxResourceStringPtr
--;
2593 bool wxEatWhiteSpaceString(char *s
)
2595 int ch
= getc_string(s
);
2599 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2606 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2607 ch
= getc_string(s
);
2608 // Check for comment
2611 ch
= getc_string(s
);
2614 bool finished
= FALSE
;
2617 ch
= getc_string(s
);
2622 int newCh
= getc_string(s
);
2637 return wxEatWhiteSpaceString(s
);
2640 bool wxGetResourceTokenString(char *s
)
2642 if (!wxResourceBuffer
)
2643 wxReallocateResourceBuffer();
2644 wxResourceBuffer
[0] = 0;
2645 wxEatWhiteSpaceString(s
);
2647 int ch
= getc_string(s
);
2651 wxResourceBufferCount
= 0;
2652 ch
= getc_string(s
);
2658 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2661 // Escaped characters
2662 else if (ch
== '\\')
2664 int newCh
= getc_string(s
);
2667 else if (newCh
== 10)
2675 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2676 wxReallocateResourceBuffer();
2677 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2678 wxResourceBufferCount
++;
2679 ch
= getc_string(s
);
2681 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2685 wxResourceBufferCount
= 0;
2687 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2689 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2690 wxReallocateResourceBuffer();
2691 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2692 wxResourceBufferCount
++;
2694 ch
= getc_string(s
);
2696 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2704 * Files are in form:
2705 static char *name = "....";
2706 with possible comments.
2709 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2712 table
= wxDefaultResourceTable
;
2714 // static or #define
2715 if (!wxGetResourceTokenString(s
))
2721 if (strcmp(wxResourceBuffer
, "#define") == 0)
2723 wxGetResourceTokenString(s
);
2724 char *name
= copystring(wxResourceBuffer
);
2725 wxGetResourceTokenString(s
);
2726 char *value
= copystring(wxResourceBuffer
);
2727 if (isalpha(value
[0]))
2729 int val
= (int)atol(value
);
2730 wxResourceAddIdentifier(name
, val
, table
);
2735 sprintf(buf
, "#define %s must be an integer.", name
);
2747 else if (strcmp(wxResourceBuffer, "#include") == 0)
2749 wxGetResourceTokenString(s);
2750 char *name = copystring(wxResourceBuffer);
2751 char *actualName = name;
2753 actualName = name + 1;
2754 int len = strlen(name);
2755 if ((len > 0) && (name[len-1] == '"'))
2757 if (!wxResourceParseIncludeFile(actualName, table))
2760 sprintf(buf, "Could not find resource include file %s.", actualName);
2767 else if (strcmp(wxResourceBuffer
, "static") != 0)
2770 strcpy(buf
, "Found ");
2771 strncat(buf
, wxResourceBuffer
, 30);
2772 strcat(buf
, ", expected static, #include or #define\nwhilst parsing resource.");
2778 if (!wxGetResourceTokenString(s
))
2780 wxWarning("Unexpected end of file whilst parsing resource.");
2785 if (strcmp(wxResourceBuffer
, "char") != 0)
2787 wxWarning("Expected 'char' whilst parsing resource.");
2792 if (!wxGetResourceTokenString(s
))
2794 wxWarning("Unexpected end of file whilst parsing resource.");
2799 if (wxResourceBuffer
[0] != '*')
2801 wxWarning("Expected '*' whilst parsing resource.");
2805 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2808 if (!wxGetResourceTokenString(s
))
2810 wxWarning("Unexpected end of file whilst parsing resource.");
2815 if (strcmp(wxResourceBuffer
, "=") != 0)
2817 wxWarning("Expected '=' whilst parsing resource.");
2822 if (!wxGetResourceTokenString(s
))
2824 wxWarning("Unexpected end of file whilst parsing resource.");
2830 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2833 sprintf(buf
, "%s: ill-formed resource file syntax.", nameBuf
);
2839 if (!wxGetResourceTokenString(s
))
2846 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2849 table
= wxDefaultResourceTable
;
2854 // Turn backslashes into spaces
2857 int len
= strlen(s
);
2859 for (i
= 0; i
< len
; i
++)
2860 if (s
[i
] == 92 && s
[i
+1] == 13)
2868 wxResourceStringPtr
= 0;
2871 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2875 return wxResourceInterpretResources(*table
, db
);
2879 * resource loading facility
2882 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2885 table
= wxDefaultResourceTable
;
2887 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2888 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2889 if (!resource
|| !resource
->GetType() ||
2890 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2893 char *title
= resource
->GetTitle();
2894 long theWindowStyle
= resource
->GetStyle();
2895 bool isModal
= (resource
->GetValue1() != 0);
2896 int x
= resource
->GetX();
2897 int y
= resource
->GetY();
2898 int width
= resource
->GetWidth();
2899 int height
= resource
->GetHeight();
2900 char *name
= resource
->GetName();
2902 wxFont
*theFont
= resource
->GetFont();
2904 if (IsKindOf(CLASSINFO(wxDialog
)))
2906 wxDialog
*dialogBox
= (wxDialog
*)this;
2907 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2908 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2913 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2920 if (resource
->GetBackgroundColour())
2921 SetBackgroundColour(*resource
->GetBackgroundColour());
2924 if (resource
->GetLabelColour())
2925 SetForegroundColour(*resource
->GetLabelColour());
2926 else if (resource
->GetButtonColour())
2927 SetForegroundColour(*resource
->GetButtonColour());
2929 // Now create children
2930 wxNode
*node
= resource
->GetChildren().First();
2933 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2935 (void) CreateItem(childResource
, table
);
2937 node
= node
->Next();
2942 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxResourceTable
*table
)
2945 table
= wxDefaultResourceTable
;
2946 return table
->CreateItem((wxWindow
*)this, (wxItemResource
*)resource
);
2949 #endif // USE_WX_RESOURCES