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 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
},
1773 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1774 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1777 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1778 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1779 { "wxCB_READONLY", wxCB_READONLY
},
1780 { "wxCB_SORT", wxCB_SORT
},
1783 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1784 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1785 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1788 { "wxPASSWORD", wxPASSWORD
},
1789 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1790 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1791 { "wxTE_READONLY", wxTE_READONLY
},
1792 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1793 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1795 /* wxRadioBox/wxRadioButton */
1796 { "wxRB_GROUP", wxRB_GROUP
},
1797 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1798 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1801 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1802 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1803 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1804 { "wxSL_LABELS", wxSL_LABELS
},
1805 { "wxSL_LEFT", wxSL_LEFT
},
1806 { "wxSL_TOP", wxSL_TOP
},
1807 { "wxSL_RIGHT", wxSL_RIGHT
},
1808 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1809 { "wxSL_BOTH", wxSL_BOTH
},
1810 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1813 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1814 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1817 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1818 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1821 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1822 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1825 { "wxLC_ICON", wxLC_ICON
},
1826 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1827 { "wxLC_LIST", wxLC_LIST
},
1828 { "wxLC_REPORT", wxLC_REPORT
},
1829 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1830 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1831 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1832 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1833 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1834 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1835 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1836 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1837 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1838 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1841 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1842 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1843 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1844 { "wxSP_WRAP", wxSP_WRAP
},
1847 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1848 { "wxSP_3D", wxSP_3D
},
1849 { "wxSP_BORDER", wxSP_BORDER
},
1852 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1853 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1854 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1855 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1858 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1861 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1862 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1863 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1864 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1865 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1866 { "wxCOLOURED", wxCOLOURED
},
1869 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1872 { "wxVSCROLL", wxVSCROLL
},
1873 { "wxHSCROLL", wxHSCROLL
},
1874 { "wxCAPTION", wxCAPTION
},
1875 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1876 { "wxICONIZE", wxICONIZE
},
1877 { "wxMINIMIZE", wxICONIZE
},
1878 { "wxMAXIMIZE", wxMAXIMIZE
},
1880 { "wxMDI_PARENT", 0},
1881 { "wxMDI_CHILD", 0},
1882 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1883 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1884 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1885 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1886 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1887 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1888 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME
},
1889 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1890 { "wxBORDER", wxBORDER
},
1891 { "wxRETAINED", wxRETAINED
},
1892 { "wxEDITABLE", wxEDITABLE
},
1893 { "wxREADONLY", wxREADONLY
},
1894 { "wxNATIVE_IMPL", 0},
1895 { "wxEXTENDED_IMPL", 0},
1896 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1897 // { "wxFLAT", wxFLAT},
1898 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1899 { "wxFIXED_LENGTH", 0},
1900 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1901 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1902 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1903 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1904 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1905 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1906 { "wxNO_BORDER", wxNO_BORDER
},
1907 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1909 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1910 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1912 // Text font families
1913 { "wxDEFAULT", wxDEFAULT
},
1914 { "wxDECORATIVE", wxDECORATIVE
},
1915 { "wxROMAN", wxROMAN
},
1916 { "wxSCRIPT", wxSCRIPT
},
1917 { "wxSWISS", wxSWISS
},
1918 { "wxMODERN", wxMODERN
},
1919 { "wxTELETYPE", wxTELETYPE
},
1920 { "wxVARIABLE", wxVARIABLE
},
1921 { "wxFIXED", wxFIXED
},
1922 { "wxNORMAL", wxNORMAL
},
1923 { "wxLIGHT", wxLIGHT
},
1924 { "wxBOLD", wxBOLD
},
1925 { "wxITALIC", wxITALIC
},
1926 { "wxSLANT", wxSLANT
},
1927 { "wxSOLID", wxSOLID
},
1929 { "wxLONG_DASH", wxLONG_DASH
},
1930 { "wxSHORT_DASH", wxSHORT_DASH
},
1931 { "wxDOT_DASH", wxDOT_DASH
},
1932 { "wxUSER_DASH", wxUSER_DASH
},
1933 { "wxTRANSPARENT", wxTRANSPARENT
},
1934 { "wxSTIPPLE", wxSTIPPLE
},
1935 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1936 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1937 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1938 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1939 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1940 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1941 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1942 { "wxJOIN_MITER", wxJOIN_MITER
},
1943 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1944 { "wxCAP_ROUND", wxCAP_ROUND
},
1945 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1946 { "wxCAP_BUTT", wxCAP_BUTT
},
1949 { "wxCLEAR", wxCLEAR
},
1951 { "wxINVERT", wxINVERT
},
1952 { "wxOR_REVERSE", wxOR_REVERSE
},
1953 { "wxAND_REVERSE", wxAND_REVERSE
},
1954 { "wxCOPY", wxCOPY
},
1956 { "wxAND_INVERT", wxAND_INVERT
},
1957 { "wxNO_OP", wxNO_OP
},
1959 { "wxEQUIV", wxEQUIV
},
1960 { "wxSRC_INVERT", wxSRC_INVERT
},
1961 { "wxOR_INVERT", wxOR_INVERT
},
1962 { "wxNAND", wxNAND
},
1966 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1967 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1968 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1969 { "wxWINDING_RULE", wxWINDING_RULE
},
1970 { "wxHORIZONTAL", wxHORIZONTAL
},
1971 { "wxVERTICAL", wxVERTICAL
},
1972 { "wxBOTH", wxBOTH
},
1973 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1975 { "wxYES_NO", wxYES_NO
},
1976 { "wxCANCEL", wxCANCEL
},
1979 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1980 { "wxICON_HAND", wxICON_HAND
},
1981 { "wxICON_QUESTION", wxICON_QUESTION
},
1982 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1983 { "wxICON_STOP", wxICON_STOP
},
1984 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1985 { "wxICON_MASK", wxICON_MASK
},
1986 { "wxCENTRE", wxCENTRE
},
1987 { "wxCENTER", wxCENTRE
},
1988 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1989 { "wxVERTICAL_LABEL", 0},
1990 { "wxHORIZONTAL_LABEL", 0},
1992 // Bitmap types (not strictly styles)
1993 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1994 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1995 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1996 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1997 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1998 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1999 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
2000 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
2001 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
2002 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
2003 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
2004 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
2005 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
2006 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
2009 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2011 long wxParseWindowStyle(char *bitListString
)
2016 while ((word
= wxResourceParseWord(bitListString
, &i
)))
2020 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2021 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2023 bitList
|= wxResourceBitListTable
[j
].bits
;
2030 sprintf(buf
, "Unrecognized style %s whilst parsing resource.", word
);
2039 * Load a bitmap from a wxWindows resource, choosing an optimum
2040 * depth and appropriate type.
2043 wxBitmap
*wxResourceCreateBitmap(char *resource
, wxResourceTable
*table
)
2046 table
= wxDefaultResourceTable
;
2048 wxItemResource
*item
= table
->FindResource(resource
);
2051 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2054 sprintf(buf
, "%s not a bitmap resource specification.", resource
);
2058 int thisDepth
= wxDisplayDepth();
2059 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2061 wxItemResource
*optResource
= NULL
;
2063 // Try to find optimum bitmap for this platform/colour depth
2064 wxNode
*node
= item
->GetChildren().First();
2067 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2068 int platform
= (int)child
->GetValue2();
2069 int noColours
= (int)child
->GetValue3();
2071 char *name = child->GetName();
2072 int bitmapType = (int)child->GetValue1();
2073 int xRes = child->GetWidth();
2074 int yRes = child->GetHeight();
2079 case RESOURCE_PLATFORM_ANY
:
2081 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2082 optResource
= child
;
2085 // Maximise the number of colours.
2086 // If noColours is zero (unspecified), then assume this
2087 // is the right one.
2088 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2089 optResource
= child
;
2094 case RESOURCE_PLATFORM_WINDOWS
:
2096 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2097 optResource
= child
;
2100 // Maximise the number of colours
2101 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2102 optResource
= child
;
2108 case RESOURCE_PLATFORM_X
:
2110 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2111 optResource
= child
;
2114 // Maximise the number of colours
2115 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2116 optResource
= child
;
2122 case RESOURCE_PLATFORM_MAC
:
2124 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2125 optResource
= child
;
2128 // Maximise the number of colours
2129 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2130 optResource
= child
;
2138 node
= node
->Next();
2140 // If no matching resource, fail.
2144 char *name
= optResource
->GetName();
2145 int bitmapType
= (int)optResource
->GetValue1();
2146 wxBitmap
*bitmap
= NULL
;
2149 case wxBITMAP_TYPE_XBM_DATA
:
2152 wxItemResource
*item
= table
->FindResource(name
);
2156 sprintf(buf
, "Failed to find XBM resource %s.\nForgot to use wxResourceLoadBitmapData?", name
);
2160 bitmap
= new wxBitmap((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2162 wxWarning("No XBM facility available!");
2166 case wxBITMAP_TYPE_XPM_DATA
:
2168 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2169 wxItemResource
*item
= table
->FindResource(name
);
2173 sprintf(buf
, "Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?", name
);
2177 bitmap
= new wxBitmap(item
->GetValue1());
2179 wxWarning("No XPM facility available!");
2185 bitmap
= new wxBitmap(name
, bitmapType
);
2205 sprintf(buf
, "Bitmap resource specification %s not found.", resource
);
2212 * Load an icon from a wxWindows resource, choosing an optimum
2213 * depth and appropriate type.
2216 wxIcon
*wxResourceCreateIcon(char *resource
, wxResourceTable
*table
)
2219 table
= wxDefaultResourceTable
;
2221 wxItemResource
*item
= table
->FindResource(resource
);
2224 if (!item
->GetType() || strcmp(item
->GetType(), "wxIcon") != 0)
2227 sprintf(buf
, "%s not an icon resource specification.", resource
);
2231 int thisDepth
= wxDisplayDepth();
2232 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2234 wxItemResource
*optResource
= NULL
;
2236 // Try to find optimum icon for this platform/colour depth
2237 wxNode
*node
= item
->GetChildren().First();
2240 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2241 int platform
= (int)child
->GetValue2();
2242 int noColours
= (int)child
->GetValue3();
2244 char *name = child->GetName();
2245 int bitmapType = (int)child->GetValue1();
2246 int xRes = child->GetWidth();
2247 int yRes = child->GetHeight();
2252 case RESOURCE_PLATFORM_ANY
:
2254 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2255 optResource
= child
;
2258 // Maximise the number of colours.
2259 // If noColours is zero (unspecified), then assume this
2260 // is the right one.
2261 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2262 optResource
= child
;
2267 case RESOURCE_PLATFORM_WINDOWS
:
2269 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2270 optResource
= child
;
2273 // Maximise the number of colours
2274 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2275 optResource
= child
;
2281 case RESOURCE_PLATFORM_X
:
2283 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2284 optResource
= child
;
2287 // Maximise the number of colours
2288 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2289 optResource
= child
;
2295 case RESOURCE_PLATFORM_MAC
:
2297 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2298 optResource
= child
;
2301 // Maximise the number of colours
2302 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2303 optResource
= child
;
2311 node
= node
->Next();
2313 // If no matching resource, fail.
2317 char *name
= optResource
->GetName();
2318 int bitmapType
= (int)optResource
->GetValue1();
2319 wxIcon
*icon
= NULL
;
2322 case wxBITMAP_TYPE_XBM_DATA
:
2325 wxItemResource
*item
= table
->FindResource(name
);
2329 sprintf(buf
, "Failed to find XBM resource %s.\nForgot to use wxResourceLoadIconData?", name
);
2333 icon
= new wxIcon((char *)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2335 wxWarning("No XBM facility available!");
2339 case wxBITMAP_TYPE_XPM_DATA
:
2341 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2343 #if (defined(__X__) && USE_XPM_IN_X) || (defined(__WXMSW__) && USE_XPM_IN_MSW)
2344 wxItemResource *item = table->FindResource(name);
2348 sprintf(buf, "Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?", name);
2352 icon = new wxIcon((char **)item->GetValue1());
2354 wxWarning("No XPM facility available!");
2357 wxWarning("No XPM icon facility available!");
2362 icon
= new wxIcon(name
, bitmapType
);
2382 sprintf(buf
, "Icon resource specification %s not found.", resource
);
2388 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2390 wxMenu
*menu
= new wxMenu
;
2391 wxNode
*node
= item
->GetChildren().First();
2394 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2395 if (child
->GetType() && strcmp(child
->GetType(), "wxMenuSeparator") == 0)
2396 menu
->AppendSeparator();
2397 else if (child
->GetChildren().Number() > 0)
2399 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2401 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2405 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2407 node
= node
->Next();
2412 wxMenuBar
*wxResourceCreateMenuBar(char *resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2415 table
= wxDefaultResourceTable
;
2417 wxItemResource
*menuResource
= table
->FindResource(resource
);
2418 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2421 menuBar
= new wxMenuBar
;
2422 wxNode
*node
= menuResource
->GetChildren().First();
2425 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2426 wxMenu
*menu
= wxResourceCreateMenu(child
);
2428 menuBar
->Append(menu
, child
->GetTitle());
2429 node
= node
->Next();
2436 wxMenu
*wxResourceCreateMenu(char *resource
, wxResourceTable
*table
)
2439 table
= wxDefaultResourceTable
;
2441 wxItemResource
*menuResource
= table
->FindResource(resource
);
2442 if (menuResource
&& menuResource
->GetType() && strcmp(menuResource
->GetType(), "wxMenu") == 0)
2443 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2444 return wxResourceCreateMenu(menuResource
);
2448 // Global equivalents (so don't have to refer to default table explicitly)
2449 bool wxResourceParseData(char *resource
, wxResourceTable
*table
)
2452 table
= wxDefaultResourceTable
;
2454 return table
->ParseResourceData(resource
);
2457 bool wxResourceParseFile(char *filename
, wxResourceTable
*table
)
2460 table
= wxDefaultResourceTable
;
2462 return table
->ParseResourceFile(filename
);
2465 // Register XBM/XPM data
2466 bool wxResourceRegisterBitmapData(char *name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2469 table
= wxDefaultResourceTable
;
2471 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2474 bool wxResourceRegisterBitmapData(char *name
, char **data
, wxResourceTable
*table
)
2477 table
= wxDefaultResourceTable
;
2479 return table
->RegisterResourceBitmapData(name
, data
);
2482 void wxResourceClear(wxResourceTable
*table
)
2485 table
= wxDefaultResourceTable
;
2487 table
->ClearTable();
2494 bool wxResourceAddIdentifier(char *name
, int value
, wxResourceTable
*table
)
2497 table
= wxDefaultResourceTable
;
2499 table
->identifiers
.Put(name
, (wxObject
*)value
);
2503 int wxResourceGetIdentifier(char *name
, wxResourceTable
*table
)
2506 table
= wxDefaultResourceTable
;
2508 return (int)table
->identifiers
.Get(name
);
2512 * Parse #include file for #defines (only)
2515 bool wxResourceParseIncludeFile(char *f
, wxResourceTable
*table
)
2518 table
= wxDefaultResourceTable
;
2520 FILE *fd
= fopen(f
, "r");
2525 while (wxGetResourceToken(fd
))
2527 if (strcmp(wxResourceBuffer
, "#define") == 0)
2529 wxGetResourceToken(fd
);
2530 char *name
= copystring(wxResourceBuffer
);
2531 wxGetResourceToken(fd
);
2532 char *value
= copystring(wxResourceBuffer
);
2533 if (isdigit(value
[0]))
2535 int val
= (int)atol(value
);
2536 wxResourceAddIdentifier(name
, val
, table
);
2547 * Reading strings as if they were .wxr files
2550 static int getc_string(char *s
)
2552 int ch
= s
[wxResourceStringPtr
];
2557 wxResourceStringPtr
++;
2562 static int ungetc_string(void)
2564 wxResourceStringPtr
--;
2568 bool wxEatWhiteSpaceString(char *s
)
2570 int ch
= getc_string(s
);
2574 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2581 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2582 ch
= getc_string(s
);
2583 // Check for comment
2586 ch
= getc_string(s
);
2589 bool finished
= FALSE
;
2592 ch
= getc_string(s
);
2597 int newCh
= getc_string(s
);
2612 return wxEatWhiteSpaceString(s
);
2615 bool wxGetResourceTokenString(char *s
)
2617 if (!wxResourceBuffer
)
2618 wxReallocateResourceBuffer();
2619 wxResourceBuffer
[0] = 0;
2620 wxEatWhiteSpaceString(s
);
2622 int ch
= getc_string(s
);
2626 wxResourceBufferCount
= 0;
2627 ch
= getc_string(s
);
2633 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2636 // Escaped characters
2637 else if (ch
== '\\')
2639 int newCh
= getc_string(s
);
2642 else if (newCh
== 10)
2650 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2651 wxReallocateResourceBuffer();
2652 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2653 wxResourceBufferCount
++;
2654 ch
= getc_string(s
);
2656 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2660 wxResourceBufferCount
= 0;
2662 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2664 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2665 wxReallocateResourceBuffer();
2666 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2667 wxResourceBufferCount
++;
2669 ch
= getc_string(s
);
2671 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2679 * Files are in form:
2680 static char *name = "....";
2681 with possible comments.
2684 bool wxResourceReadOneResourceString(char *s
, PrologDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2687 table
= wxDefaultResourceTable
;
2689 // static or #define
2690 if (!wxGetResourceTokenString(s
))
2696 if (strcmp(wxResourceBuffer
, "#define") == 0)
2698 wxGetResourceTokenString(s
);
2699 char *name
= copystring(wxResourceBuffer
);
2700 wxGetResourceTokenString(s
);
2701 char *value
= copystring(wxResourceBuffer
);
2702 if (isalpha(value
[0]))
2704 int val
= (int)atol(value
);
2705 wxResourceAddIdentifier(name
, val
, table
);
2710 sprintf(buf
, "#define %s must be an integer.", name
);
2722 else if (strcmp(wxResourceBuffer, "#include") == 0)
2724 wxGetResourceTokenString(s);
2725 char *name = copystring(wxResourceBuffer);
2726 char *actualName = name;
2728 actualName = name + 1;
2729 int len = strlen(name);
2730 if ((len > 0) && (name[len-1] == '"'))
2732 if (!wxResourceParseIncludeFile(actualName, table))
2735 sprintf(buf, "Could not find resource include file %s.", actualName);
2742 else if (strcmp(wxResourceBuffer
, "static") != 0)
2745 strcpy(buf
, "Found ");
2746 strncat(buf
, wxResourceBuffer
, 30);
2747 strcat(buf
, ", expected static, #include or #define\nwhilst parsing resource.");
2753 if (!wxGetResourceTokenString(s
))
2755 wxWarning("Unexpected end of file whilst parsing resource.");
2760 if (strcmp(wxResourceBuffer
, "char") != 0)
2762 wxWarning("Expected 'char' whilst parsing resource.");
2767 if (!wxGetResourceTokenString(s
))
2769 wxWarning("Unexpected end of file whilst parsing resource.");
2774 if (wxResourceBuffer
[0] != '*')
2776 wxWarning("Expected '*' whilst parsing resource.");
2780 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2783 if (!wxGetResourceTokenString(s
))
2785 wxWarning("Unexpected end of file whilst parsing resource.");
2790 if (strcmp(wxResourceBuffer
, "=") != 0)
2792 wxWarning("Expected '=' whilst parsing resource.");
2797 if (!wxGetResourceTokenString(s
))
2799 wxWarning("Unexpected end of file whilst parsing resource.");
2805 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2808 sprintf(buf
, "%s: ill-formed resource file syntax.", nameBuf
);
2814 if (!wxGetResourceTokenString(s
))
2821 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2824 table
= wxDefaultResourceTable
;
2829 // Turn backslashes into spaces
2832 int len
= strlen(s
);
2834 for (i
= 0; i
< len
; i
++)
2835 if (s
[i
] == 92 && s
[i
+1] == 13)
2843 wxResourceStringPtr
= 0;
2846 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2850 return wxResourceInterpretResources(*table
, db
);
2854 * resource loading facility
2857 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2860 table
= wxDefaultResourceTable
;
2862 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2863 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2864 if (!resource
|| !resource
->GetType() ||
2865 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2868 char *title
= resource
->GetTitle();
2869 long theWindowStyle
= resource
->GetStyle();
2870 bool isModal
= (resource
->GetValue1() != 0);
2871 int x
= resource
->GetX();
2872 int y
= resource
->GetY();
2873 int width
= resource
->GetWidth();
2874 int height
= resource
->GetHeight();
2875 char *name
= resource
->GetName();
2877 wxFont
*theFont
= resource
->GetFont();
2879 if (IsKindOf(CLASSINFO(wxDialog
)))
2881 wxDialog
*dialogBox
= (wxDialog
*)this;
2882 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2883 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2888 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2895 if (resource
->GetBackgroundColour())
2896 SetBackgroundColour(*resource
->GetBackgroundColour());
2899 if (resource
->GetLabelColour())
2900 SetForegroundColour(*resource
->GetLabelColour());
2901 else if (resource
->GetButtonColour())
2902 SetForegroundColour(*resource
->GetButtonColour());
2904 // Now create children
2905 wxNode
*node
= resource
->GetChildren().First();
2908 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2910 (void) CreateItem(childResource
, table
);
2912 node
= node
->Next();
2917 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxResourceTable
*table
)
2920 table
= wxDefaultResourceTable
;
2921 return table
->CreateItem((wxWindow
*)this, (wxItemResource
*)resource
);
2924 #endif // USE_WX_RESOURCES