]> git.saurik.com Git - wxWidgets.git/blob - src/common/resource.cpp
added new project file having the new files
[wxWidgets.git] / src / common / resource.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: resource.cpp
3 // Purpose: Resource system
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "resource.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #if wxUSE_WX_RESOURCES
24
25 #ifdef __VISUALC__
26 #pragma warning(disable:4706) // assignment within conditional expression
27 #endif // VC++
28
29 #ifndef WX_PRECOMP
30 #include "wx/defs.h"
31 #include "wx/setup.h"
32 #include "wx/list.h"
33 #include "wx/hash.h"
34 #include "wx/gdicmn.h"
35 #include "wx/utils.h"
36 #include "wx/types.h"
37 #include "wx/menu.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
47 #include "wx/icon.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
50 #include "wx/gauge.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
53 #include "wx/intl.h"
54 #endif
55
56 #include "wx/listctrl.h"
57
58 #if wxUSE_RADIOBTN
59 #include "wx/radiobut.h"
60 #endif
61
62 #if wxUSE_SCROLLBAR
63 #include "wx/scrolbar.h"
64 #endif
65
66 #if wxUSE_COMBOBOX
67 #include "wx/combobox.h"
68 #endif
69
70 #include "wx/validate.h"
71
72 #include "wx/log.h"
73
74 #include <ctype.h>
75 #include <math.h>
76 #include <stdlib.h>
77 #include <string.h>
78
79 #include "wx/resource.h"
80 #include "wx/string.h"
81 #include "wx/wxexpr.h"
82
83 #include "wx/settings.h"
84 #include "wx/stream.h"
85
86 // Forward (private) declarations
87 bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db);
88 wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE);
89 wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr);
90 wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr);
91 wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr);
92 wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr);
93 wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr);
94 wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr);
95 // Interpret list expression
96 wxFont wxResourceInterpretFontSpec(wxExpr *expr);
97
98 bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL);
99 bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) ;
100 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL);
101
102 wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL;
103
104 char *wxResourceBuffer = (char *) NULL;
105 long wxResourceBufferSize = 0;
106 long wxResourceBufferCount = 0;
107 int wxResourceStringPtr = 0;
108
109 void wxInitializeResourceSystem()
110 {
111 wxDefaultResourceTable = new wxResourceTable;
112 }
113
114 void wxCleanUpResourceSystem()
115 {
116 delete wxDefaultResourceTable;
117 if (wxResourceBuffer)
118 delete[] wxResourceBuffer;
119 }
120
121 void wxLogWarning(char *msg)
122 {
123 wxMessageBox(msg, _("Warning"), wxOK);
124 }
125
126 IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject)
127 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable)
128
129 wxItemResource::wxItemResource()
130 {
131 m_itemType = "";
132 m_title = "";
133 m_name = "";
134 m_windowStyle = 0;
135 m_x = m_y = m_width = m_height = 0;
136 m_value1 = m_value2 = m_value3 = m_value5 = 0;
137 m_value4 = "";
138 m_windowId = 0;
139 m_exStyle = 0;
140 }
141
142 wxItemResource::~wxItemResource()
143 {
144 wxNode *node = m_children.First();
145 while (node)
146 {
147 wxItemResource *item = (wxItemResource *)node->Data();
148 delete item;
149 delete node;
150 node = m_children.First();
151 }
152 }
153
154 /*
155 * Resource table
156 */
157
158 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING)
159 {
160 }
161
162 wxResourceTable::~wxResourceTable()
163 {
164 ClearTable();
165 }
166
167 wxItemResource *wxResourceTable::FindResource(const wxString& name) const
168 {
169 wxItemResource *item = (wxItemResource *)Get(WXSTRINGCAST name);
170 return item;
171 }
172
173 void wxResourceTable::AddResource(wxItemResource *item)
174 {
175 wxString name = item->GetName();
176 if (name == wxT(""))
177 name = item->GetTitle();
178 if (name == wxT(""))
179 name = wxT("no name");
180
181 // Delete existing resource, if any.
182 Delete(name);
183
184 Put(name, item);
185 }
186
187 bool wxResourceTable::DeleteResource(const wxString& name)
188 {
189 wxItemResource *item = (wxItemResource *)Delete(WXSTRINGCAST name);
190 if (item)
191 {
192 // See if any resource has this as its child; if so, delete from
193 // parent's child list.
194 BeginFind();
195 wxNode *node = (wxNode *) NULL;
196 node = Next();
197 while (node != NULL)
198 {
199 wxItemResource *parent = (wxItemResource *)node->Data();
200 if (parent->GetChildren().Member(item))
201 {
202 parent->GetChildren().DeleteObject(item);
203 break;
204 }
205 node = Next();
206 }
207
208 delete item;
209 return TRUE;
210 }
211 else
212 return FALSE;
213 }
214
215 bool wxResourceTable::ParseResourceFile( wxInputStream *is )
216 {
217 wxExprDatabase db;
218 int len = is->StreamSize() ;
219
220 bool eof = FALSE;
221 while ( is->TellI() + 10 < len) // it's a hack because the streams dont support EOF
222 {
223 wxResourceReadOneResource(is, db, &eof, this) ;
224 }
225 return wxResourceInterpretResources(*this, db);
226 }
227
228 bool wxResourceTable::ParseResourceFile(const wxString& filename)
229 {
230 wxExprDatabase db;
231
232 FILE *fd = wxFopen(filename, _T("r"));
233 if (!fd)
234 return FALSE;
235 bool eof = FALSE;
236 while (wxResourceReadOneResource(fd, db, &eof, this) && !eof)
237 {
238 // Loop
239 }
240 fclose(fd);
241 return wxResourceInterpretResources(*this, db);
242 }
243
244 bool wxResourceTable::ParseResourceData(const wxString& data)
245 {
246 wxExprDatabase db;
247 if (!db.ReadFromString(data))
248 {
249 wxLogWarning(_("Ill-formed resource file syntax."));
250 return FALSE;
251 }
252
253 return wxResourceInterpretResources(*this, db);
254 }
255
256 bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height)
257 {
258 // Register pre-loaded bitmap data
259 wxItemResource *item = new wxItemResource;
260 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
261 item->SetType(wxT("wxXBMData"));
262 item->SetName(name);
263 item->SetValue1((long)bits);
264 item->SetValue2((long)width);
265 item->SetValue3((long)height);
266 AddResource(item);
267 return TRUE;
268 }
269
270 bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char **data)
271 {
272 // Register pre-loaded bitmap data
273 wxItemResource *item = new wxItemResource;
274 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
275 item->SetType(wxT("wxXPMData"));
276 item->SetName(name);
277 item->SetValue1((long)data);
278 AddResource(item);
279 return TRUE;
280 }
281
282 bool wxResourceTable::SaveResource(const wxString& WXUNUSED(filename))
283 {
284 return FALSE;
285 }
286
287 void wxResourceTable::ClearTable()
288 {
289 BeginFind();
290 wxNode *node = Next();
291 while (node)
292 {
293 wxNode *next = Next();
294 wxItemResource *item = (wxItemResource *)node->Data();
295 delete item;
296 delete node;
297 node = next;
298 }
299 }
300
301 wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* childResource, const wxItemResource* parentResource) const
302 {
303 int id = childResource->GetId();
304 if ( id == 0 )
305 id = -1;
306
307 bool dlgUnits = ((parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0);
308
309 wxControl *control = (wxControl *) NULL;
310 wxString itemType(childResource->GetType());
311
312 wxPoint pos;
313 wxSize size;
314 if (dlgUnits)
315 {
316 pos = parent->ConvertDialogToPixels(wxPoint(childResource->GetX(), childResource->GetY()));
317 size = parent->ConvertDialogToPixels(wxSize(childResource->GetWidth(), childResource->GetHeight()));
318 }
319 else
320 {
321 pos = wxPoint(childResource->GetX(), childResource->GetY());
322 size = wxSize(childResource->GetWidth(), childResource->GetHeight());
323 }
324
325 if (itemType == wxString(wxT("wxButton")) || itemType == wxString(wxT("wxBitmapButton")))
326 {
327 if (childResource->GetValue4() != wxT(""))
328 {
329 // Bitmap button
330 wxBitmap bitmap = childResource->GetBitmap();
331 if (!bitmap.Ok())
332 {
333 bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this);
334 ((wxItemResource*) childResource)->SetBitmap(bitmap);
335 }
336 if (!bitmap.Ok())
337 bitmap.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE);
338 control = new wxBitmapButton(parent, id, bitmap, pos, size,
339 childResource->GetStyle() | wxBU_AUTODRAW, wxDefaultValidator, childResource->GetName());
340 }
341 else
342 // Normal, text button
343 control = new wxButton(parent, id, childResource->GetTitle(), pos, size,
344 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
345 }
346 else if (itemType == wxString(wxT("wxMessage")) || itemType == wxString(wxT("wxStaticText")) ||
347 itemType == wxString(wxT("wxStaticBitmap")))
348 {
349 if (childResource->GetValue4() != wxT("") || itemType == wxString(wxT("wxStaticBitmap")) )
350 {
351 // Bitmap message
352 wxBitmap bitmap = childResource->GetBitmap();
353 if (!bitmap.Ok())
354 {
355 bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this);
356 ((wxItemResource*) childResource)->SetBitmap(bitmap);
357 }
358 #if wxUSE_BITMAP_MESSAGE
359 #ifdef __WXMSW__
360 // Use a default bitmap
361 if (!bitmap.Ok())
362 bitmap.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE);
363 #endif
364
365 if (bitmap.Ok())
366 control = new wxStaticBitmap(parent, id, bitmap, pos, size,
367 childResource->GetStyle(), childResource->GetName());
368 #endif
369 }
370 else
371 {
372 control = new wxStaticText(parent, id, childResource->GetTitle(), pos, size,
373 childResource->GetStyle(), childResource->GetName());
374 }
375 }
376 else if (itemType == wxString(wxT("wxText")) || itemType == wxString(wxT("wxTextCtrl")) || itemType == wxString(wxT("wxMultiText")))
377 {
378 control = new wxTextCtrl(parent, id, childResource->GetValue4(), pos, size,
379 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
380 }
381 else if (itemType == wxString(wxT("wxCheckBox")))
382 {
383 control = new wxCheckBox(parent, id, childResource->GetTitle(), pos, size,
384 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
385
386 ((wxCheckBox *)control)->SetValue((childResource->GetValue1() != 0));
387 }
388 #if wxUSE_GAUGE
389 else if (itemType == wxString(wxT("wxGauge")))
390 {
391 control = new wxGauge(parent, id, (int)childResource->GetValue2(), pos, size,
392 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
393
394 ((wxGauge *)control)->SetValue((int)childResource->GetValue1());
395 }
396 #endif
397 #if wxUSE_RADIOBTN
398 else if (itemType == wxString(wxT("wxRadioButton")))
399 {
400 control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(),
401 pos, size,
402 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
403 }
404 #endif
405 #if wxUSE_SCROLLBAR
406 else if (itemType == wxString(wxT("wxScrollBar")))
407 {
408 control = new wxScrollBar(parent, id, pos, size,
409 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
410 /*
411 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
412 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
413 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
414 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
415 */
416 ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(),
417 (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),FALSE);
418
419 }
420 #endif
421 else if (itemType == wxString(wxT("wxSlider")))
422 {
423 control = new wxSlider(parent, id, (int)childResource->GetValue1(),
424 (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size,
425 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
426 }
427 else if (itemType == wxString(wxT("wxGroupBox")) || itemType == wxString(wxT("wxStaticBox")))
428 {
429 control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size,
430 childResource->GetStyle(), childResource->GetName());
431 }
432 else if (itemType == wxString(wxT("wxListBox")))
433 {
434 wxStringList& stringList = childResource->GetStringValues();
435 wxString *strings = (wxString *) NULL;
436 int noStrings = 0;
437 if (stringList.Number() > 0)
438 {
439 noStrings = stringList.Number();
440 strings = new wxString[noStrings];
441 wxNode *node = stringList.First();
442 int i = 0;
443 while (node)
444 {
445 strings[i] = (wxChar *)node->Data();
446 i ++;
447 node = node->Next();
448 }
449 }
450 control = new wxListBox(parent, id, pos, size,
451 noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
452
453 if (strings)
454 delete[] strings;
455 }
456 else if (itemType == wxString(wxT("wxChoice")))
457 {
458 wxStringList& stringList = childResource->GetStringValues();
459 wxString *strings = (wxString *) NULL;
460 int noStrings = 0;
461 if (stringList.Number() > 0)
462 {
463 noStrings = stringList.Number();
464 strings = new wxString[noStrings];
465 wxNode *node = stringList.First();
466 int i = 0;
467 while (node)
468 {
469 strings[i] = (wxChar *)node->Data();
470 i ++;
471 node = node->Next();
472 }
473 }
474 control = new wxChoice(parent, id, pos, size,
475 noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
476
477 if (strings)
478 delete[] strings;
479 }
480 #if wxUSE_COMBOBOX
481 else if (itemType == wxString(wxT("wxComboBox")))
482 {
483 wxStringList& stringList = childResource->GetStringValues();
484 wxString *strings = (wxString *) NULL;
485 int noStrings = 0;
486 if (stringList.Number() > 0)
487 {
488 noStrings = stringList.Number();
489 strings = new wxString[noStrings];
490 wxNode *node = stringList.First();
491 int i = 0;
492 while (node)
493 {
494 strings[i] = (wxChar *)node->Data();
495 i ++;
496 node = node->Next();
497 }
498 }
499 control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size,
500 noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
501
502 if (strings)
503 delete[] strings;
504 }
505 #endif
506 else if (itemType == wxString(wxT("wxRadioBox")))
507 {
508 wxStringList& stringList = childResource->GetStringValues();
509 wxString *strings = (wxString *) NULL;
510 int noStrings = 0;
511 if (stringList.Number() > 0)
512 {
513 noStrings = stringList.Number();
514 strings = new wxString[noStrings];
515 wxNode *node = stringList.First();
516 int i = 0;
517 while (node)
518 {
519 strings[i] = (wxChar *)node->Data();
520 i ++;
521 node = node->Next();
522 }
523 }
524 control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size,
525 noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator,
526 childResource->GetName());
527
528 if (strings)
529 delete[] strings;
530 }
531
532 if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
533 {
534 // Don't set font; will be inherited from parent.
535 }
536 else
537 {
538 if (control && childResource->GetFont().Ok())
539 {
540 control->SetFont(childResource->GetFont());
541
542 #ifdef __WXMSW__
543 // Force the layout algorithm since the size changes the layout
544 if (control->IsKindOf(CLASSINFO(wxRadioBox)))
545 {
546 control->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT);
547 }
548 #endif
549 }
550 }
551 return control;
552 }
553
554 /*
555 * Interpret database as a series of resources
556 */
557
558 bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db)
559 {
560 wxNode *node = db.First();
561 while (node)
562 {
563 wxExpr *clause = (wxExpr *)node->Data();
564 wxString functor(clause->Functor());
565
566 wxItemResource *item = (wxItemResource *) NULL;
567 if (functor == wxT("dialog"))
568 item = wxResourceInterpretDialog(table, clause);
569 else if (functor == wxT("panel"))
570 item = wxResourceInterpretDialog(table, clause, TRUE);
571 else if (functor == wxT("menubar"))
572 item = wxResourceInterpretMenuBar(table, clause);
573 else if (functor == wxT("menu"))
574 item = wxResourceInterpretMenu(table, clause);
575 else if (functor == wxT("string"))
576 item = wxResourceInterpretString(table, clause);
577 else if (functor == wxT("bitmap"))
578 item = wxResourceInterpretBitmap(table, clause);
579 else if (functor == wxT("icon"))
580 item = wxResourceInterpretIcon(table, clause);
581
582 if (item)
583 {
584 // Remove any existing resource of same name
585 if (item->GetName() != wxT(""))
586 table.DeleteResource(item->GetName());
587 table.AddResource(item);
588 }
589 node = node->Next();
590 }
591 return TRUE;
592 }
593
594 static const wxChar *g_ValidControlClasses[] =
595 {
596 wxT("wxButton"),
597 wxT("wxBitmapButton"),
598 wxT("wxMessage"),
599 wxT("wxStaticText"),
600 wxT("wxStaticBitmap"),
601 wxT("wxText"),
602 wxT("wxTextCtrl"),
603 wxT("wxMultiText"),
604 wxT("wxListBox"),
605 wxT("wxRadioBox"),
606 wxT("wxRadioButton"),
607 wxT("wxCheckBox"),
608 wxT("wxBitmapCheckBox"),
609 wxT("wxGroupBox"),
610 wxT("wxStaticBox"),
611 wxT("wxSlider"),
612 wxT("wxGauge"),
613 wxT("wxScrollBar"),
614 wxT("wxChoice"),
615 wxT("wxComboBox")
616 };
617
618 static bool wxIsValidControlClass(const wxString& c)
619 {
620 for ( size_t i = 0; i < WXSIZEOF(g_ValidControlClasses); i++ )
621 {
622 if ( c == g_ValidControlClasses[i] )
623 return TRUE;
624 }
625 return FALSE;
626 }
627
628 wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel)
629 {
630 wxItemResource *dialogItem = new wxItemResource;
631 if (isPanel)
632 dialogItem->SetType(wxT("wxPanel"));
633 else
634 dialogItem->SetType(wxT("wxDialog"));
635 wxString style = wxT("");
636 wxString title = wxT("");
637 wxString name = wxT("");
638 wxString backColourHex = wxT("");
639 wxString labelColourHex = wxT("");
640 wxString buttonColourHex = wxT("");
641
642 long windowStyle = wxDEFAULT_DIALOG_STYLE;
643 if (isPanel)
644 windowStyle = 0;
645
646 int x = 0; int y = 0; int width = -1; int height = -1;
647 int isModal = 0;
648 wxExpr *labelFontExpr = (wxExpr *) NULL;
649 wxExpr *buttonFontExpr = (wxExpr *) NULL;
650 wxExpr *fontExpr = (wxExpr *) NULL;
651 expr->GetAttributeValue(wxT("style"), style);
652 expr->GetAttributeValue(wxT("name"), name);
653 expr->GetAttributeValue(wxT("title"), title);
654 expr->GetAttributeValue(wxT("x"), x);
655 expr->GetAttributeValue(wxT("y"), y);
656 expr->GetAttributeValue(wxT("width"), width);
657 expr->GetAttributeValue(wxT("height"), height);
658 expr->GetAttributeValue(wxT("modal"), isModal);
659 expr->GetAttributeValue(wxT("label_font"), &labelFontExpr);
660 expr->GetAttributeValue(wxT("button_font"), &buttonFontExpr);
661 expr->GetAttributeValue(wxT("font"), &fontExpr);
662 expr->GetAttributeValue(wxT("background_colour"), backColourHex);
663 expr->GetAttributeValue(wxT("label_colour"), labelColourHex);
664 expr->GetAttributeValue(wxT("button_colour"), buttonColourHex);
665
666 int useDialogUnits = 0;
667 expr->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits);
668 if (useDialogUnits != 0)
669 dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS);
670
671 int useDefaults = 0;
672 expr->GetAttributeValue(wxT("use_system_defaults"), useDefaults);
673 if (useDefaults != 0)
674 dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS);
675
676 int id = 0;
677 expr->GetAttributeValue(wxT("id"), id);
678 dialogItem->SetId(id);
679
680 if (style != wxT(""))
681 {
682 windowStyle = wxParseWindowStyle(style);
683 }
684 dialogItem->SetStyle(windowStyle);
685 dialogItem->SetValue1(isModal);
686 if (windowStyle & wxDIALOG_MODAL) // Uses style in wxWin 2
687 dialogItem->SetValue1(TRUE);
688
689 dialogItem->SetName(name);
690 dialogItem->SetTitle(title);
691 dialogItem->SetSize(x, y, width, height);
692
693 // Check for wxWin 1.68-style specifications
694 if (style.Find(wxT("VERTICAL_LABEL")) != -1)
695 dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL);
696 else if (style.Find(wxT("HORIZONTAL_LABEL")) != -1)
697 dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL);
698
699 if (backColourHex != wxT(""))
700 {
701 int r = 0;
702 int g = 0;
703 int b = 0;
704 r = wxHexToDec(backColourHex.Mid(0, 2));
705 g = wxHexToDec(backColourHex.Mid(2, 2));
706 b = wxHexToDec(backColourHex.Mid(4, 2));
707 dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b));
708 }
709 if (labelColourHex != wxT(""))
710 {
711 int r = 0;
712 int g = 0;
713 int b = 0;
714 r = wxHexToDec(labelColourHex.Mid(0, 2));
715 g = wxHexToDec(labelColourHex.Mid(2, 2));
716 b = wxHexToDec(labelColourHex.Mid(4, 2));
717 dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b));
718 }
719 if (buttonColourHex != wxT(""))
720 {
721 int r = 0;
722 int g = 0;
723 int b = 0;
724 r = wxHexToDec(buttonColourHex.Mid(0, 2));
725 g = wxHexToDec(buttonColourHex.Mid(2, 2));
726 b = wxHexToDec(buttonColourHex.Mid(4, 2));
727 dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b));
728 }
729
730 if (fontExpr)
731 dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr));
732 else if (buttonFontExpr)
733 dialogItem->SetFont(wxResourceInterpretFontSpec(buttonFontExpr));
734 else if (labelFontExpr)
735 dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr));
736
737 // Now parse all controls
738 wxExpr *controlExpr = expr->GetFirst();
739 while (controlExpr)
740 {
741 if (controlExpr->Number() == 3)
742 {
743 wxString controlKeyword(controlExpr->Nth(1)->StringValue());
744 if (controlKeyword != wxT("") && controlKeyword == wxT("control"))
745 {
746 // The value part: always a list.
747 wxExpr *listExpr = controlExpr->Nth(2);
748 if (listExpr->Type() == PrologList)
749 {
750 wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr);
751 if (controlItem)
752 {
753 dialogItem->GetChildren().Append(controlItem);
754 }
755 }
756 }
757 }
758 controlExpr = controlExpr->GetNext();
759 }
760 return dialogItem;
761 }
762
763 wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr)
764 {
765 wxItemResource *controlItem = new wxItemResource;
766
767 // First, find the standard features of a control definition:
768 // [optional integer/string id], control name, title, style, name, x, y, width, height
769
770 wxString controlType;
771 wxString style;
772 wxString title;
773 wxString name;
774 int id = 0;
775 long windowStyle = 0;
776 int x = 0; int y = 0; int width = -1; int height = -1;
777 int count = 0;
778
779 wxExpr *expr1 = expr->Nth(0);
780
781 if ( expr1->Type() == PrologString || expr1->Type() == PrologWord )
782 {
783 if ( wxIsValidControlClass(expr1->StringValue()) )
784 {
785 count = 1;
786 controlType = expr1->StringValue();
787 }
788 else
789 {
790 wxString str(expr1->StringValue());
791 id = wxResourceGetIdentifier(str, &table);
792 if (id == 0)
793 {
794 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
795 (const wxChar*) expr1->StringValue());
796 delete controlItem;
797 return (wxItemResource *) NULL;
798 }
799 else
800 {
801 // Success - we have an id, so the 2nd element must be the control class.
802 controlType = expr->Nth(1)->StringValue();
803 count = 2;
804 }
805 }
806 }
807 else if (expr1->Type() == PrologInteger)
808 {
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();
812 count = 2;
813 }
814
815 expr1 = expr->Nth(count);
816 count ++;
817 if ( expr1 )
818 title = expr1->StringValue();
819
820 expr1 = expr->Nth(count);
821 count ++;
822 if (expr1)
823 {
824 style = expr1->StringValue();
825 windowStyle = wxParseWindowStyle(style);
826 }
827
828 expr1 = expr->Nth(count);
829 count ++;
830 if (expr1)
831 name = expr1->StringValue();
832
833 expr1 = expr->Nth(count);
834 count ++;
835 if (expr1)
836 x = (int)expr1->IntegerValue();
837
838 expr1 = expr->Nth(count);
839 count ++;
840 if (expr1)
841 y = (int)expr1->IntegerValue();
842
843 expr1 = expr->Nth(count);
844 count ++;
845 if (expr1)
846 width = (int)expr1->IntegerValue();
847
848 expr1 = expr->Nth(count);
849 count ++;
850 if (expr1)
851 height = (int)expr1->IntegerValue();
852
853 controlItem->SetStyle(windowStyle);
854 controlItem->SetName(name);
855 controlItem->SetTitle(title);
856 controlItem->SetSize(x, y, width, height);
857 controlItem->SetType(controlType);
858 controlItem->SetId(id);
859
860 // Check for wxWin 1.68-style specifications
861 if (style.Find(wxT("VERTICAL_LABEL")) != -1)
862 controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL);
863 else if (style.Find(wxT("HORIZONTAL_LABEL")) != -1)
864 controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL);
865
866 if (controlType == wxT("wxButton"))
867 {
868 // Check for bitmap resource name (in case loading old-style resource file)
869 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
870 {
871 wxString str(expr->Nth(count)->StringValue());
872 count ++;
873
874 if (str != wxT(""))
875 {
876 controlItem->SetValue4(str);
877 controlItem->SetType(wxT("wxBitmapButton"));
878 }
879 }
880 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
881 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
882 }
883 else if (controlType == wxT("wxBitmapButton"))
884 {
885 // Check for bitmap resource name
886 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
887 {
888 wxString str(expr->Nth(count)->StringValue());
889 controlItem->SetValue4(str);
890 count ++;
891 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
892 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
893 }
894 }
895 else if (controlType == wxT("wxCheckBox"))
896 {
897 // Check for default value
898 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
899 {
900 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
901 count ++;
902 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
903 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
904 }
905 }
906 #if wxUSE_RADIOBTN
907 else if (controlType == wxT("wxRadioButton"))
908 {
909 // Check for default value
910 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
911 {
912 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
913 count ++;
914 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
915 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
916 }
917 }
918 #endif
919 else if (controlType == wxT("wxText") || controlType == wxT("wxTextCtrl") || controlType == wxT("wxMultiText"))
920 {
921 // Check for default value
922 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
923 {
924 wxString str(expr->Nth(count)->StringValue());
925 controlItem->SetValue4(str);
926 count ++;
927
928 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
929 {
930 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
931 // Skip past the obsolete label font spec if there are two consecutive specs
932 if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
933 count ++;
934 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
935 }
936 }
937 }
938 else if (controlType == wxT("wxMessage") || controlType == wxT("wxStaticText"))
939 {
940 // Check for bitmap resource name (in case it's an old-style .wxr file)
941 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
942 {
943 wxString str(expr->Nth(count)->StringValue());
944 controlItem->SetValue4(str);
945 count ++;
946 controlItem->SetType(wxT("wxStaticText"));
947 }
948 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
949 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
950 }
951 else if (controlType == wxT("wxStaticBitmap"))
952 {
953 // Check for bitmap resource name
954 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
955 {
956 wxString str(expr->Nth(count)->StringValue());
957 controlItem->SetValue4(str);
958 count ++;
959 }
960 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
961 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
962 }
963 else if (controlType == wxT("wxGroupBox") || controlType == wxT("wxStaticBox"))
964 {
965 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
966 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
967 }
968 else if (controlType == wxT("wxGauge"))
969 {
970 // Check for default value
971 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
972 {
973 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
974 count ++;
975
976 // Check for range
977 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
978 {
979 controlItem->SetValue2(expr->Nth(count)->IntegerValue());
980 count ++;
981
982 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
983 {
984 // Skip past the obsolete label font spec if there are two consecutive specs
985 if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
986 count ++;
987 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
988 }
989 }
990 }
991 }
992 else if (controlType == wxT("wxSlider"))
993 {
994 // Check for default value
995 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
996 {
997 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
998 count ++;
999
1000 // Check for min
1001 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1002 {
1003 controlItem->SetValue2(expr->Nth(count)->IntegerValue());
1004 count ++;
1005
1006 // Check for max
1007 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1008 {
1009 controlItem->SetValue3(expr->Nth(count)->IntegerValue());
1010 count ++;
1011
1012 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1013 {
1014 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1015 // do nothing
1016 count ++;
1017
1018 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1019 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1020 }
1021 }
1022 }
1023 }
1024 }
1025 else if (controlType == wxT("wxScrollBar"))
1026 {
1027 // DEFAULT VALUE
1028 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1029 {
1030 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
1031 count ++;
1032
1033 // PAGE LENGTH
1034 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1035 {
1036 controlItem->SetValue2(expr->Nth(count)->IntegerValue());
1037 count ++;
1038
1039 // OBJECT LENGTH
1040 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1041 {
1042 controlItem->SetValue3(expr->Nth(count)->IntegerValue());
1043 count ++;
1044
1045 // VIEW LENGTH
1046 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1047 controlItem->SetValue5(expr->Nth(count)->IntegerValue());
1048 }
1049 }
1050 }
1051 }
1052 else if (controlType == wxT("wxListBox"))
1053 {
1054 wxExpr *valueList = (wxExpr *) NULL;
1055
1056 if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
1057 {
1058 wxStringList stringList;
1059 wxExpr *stringExpr = valueList->GetFirst();
1060 while (stringExpr)
1061 {
1062 stringList.Add(stringExpr->StringValue());
1063 stringExpr = stringExpr->GetNext();
1064 }
1065 controlItem->SetStringValues(stringList);
1066 count ++;
1067 // This is now obsolete: it's in the window style.
1068 // Check for wxSINGLE/wxMULTIPLE
1069 wxExpr *mult = (wxExpr *) NULL;
1070 /*
1071 controlItem->SetValue1(wxLB_SINGLE);
1072 */
1073 if (((mult = expr->Nth(count)) != 0) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord)))
1074 {
1075 /*
1076 wxString m(mult->StringValue());
1077 if (m == "wxLB_MULTIPLE")
1078 controlItem->SetValue1(wxLB_MULTIPLE);
1079 else if (m == "wxLB_EXTENDED")
1080 controlItem->SetValue1(wxLB_EXTENDED);
1081 */
1082 // Ignore the value
1083 count ++;
1084 }
1085 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1086 {
1087 // Skip past the obsolete label font spec if there are two consecutive specs
1088 if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
1089 count ++;
1090 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1091 }
1092 }
1093 }
1094 else if (controlType == wxT("wxChoice"))
1095 {
1096 wxExpr *valueList = (wxExpr *) NULL;
1097 // Check for default value list
1098 if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
1099 {
1100 wxStringList stringList;
1101 wxExpr *stringExpr = valueList->GetFirst();
1102 while (stringExpr)
1103 {
1104 stringList.Add(stringExpr->StringValue());
1105 stringExpr = stringExpr->GetNext();
1106 }
1107 controlItem->SetStringValues(stringList);
1108
1109 count ++;
1110
1111 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1112 {
1113 // Skip past the obsolete label font spec if there are two consecutive specs
1114 if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
1115 count ++;
1116 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1117 }
1118 }
1119 }
1120 #if wxUSE_COMBOBOX
1121 else if (controlType == wxT("wxComboBox"))
1122 {
1123 wxExpr *textValue = expr->Nth(count);
1124 if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord))
1125 {
1126 wxString str(textValue->StringValue());
1127 controlItem->SetValue4(str);
1128
1129 count ++;
1130
1131 wxExpr *valueList = (wxExpr *) NULL;
1132 // Check for default value list
1133 if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
1134 {
1135 wxStringList stringList;
1136 wxExpr *stringExpr = valueList->GetFirst();
1137 while (stringExpr)
1138 {
1139 stringList.Add(stringExpr->StringValue());
1140 stringExpr = stringExpr->GetNext();
1141 }
1142 controlItem->SetStringValues(stringList);
1143
1144 count ++;
1145
1146 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1147 {
1148 // Skip past the obsolete label font spec if there are two consecutive specs
1149 if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
1150 count ++;
1151 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1152 }
1153 }
1154 }
1155 }
1156 #endif
1157 #if 1
1158 else if (controlType == wxT("wxRadioBox"))
1159 {
1160 wxExpr *valueList = (wxExpr *) NULL;
1161 // Check for default value list
1162 if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList))
1163 {
1164 wxStringList stringList;
1165 wxExpr *stringExpr = valueList->GetFirst();
1166 while (stringExpr)
1167 {
1168 stringList.Add(stringExpr->StringValue());
1169 stringExpr = stringExpr->GetNext();
1170 }
1171 controlItem->SetStringValues(stringList);
1172 count ++;
1173
1174 // majorDim (number of rows or cols)
1175 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1176 {
1177 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
1178 count ++;
1179 }
1180 else
1181 controlItem->SetValue1(0);
1182
1183 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1184 {
1185 // Skip past the obsolete label font spec if there are two consecutive specs
1186 if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList)
1187 count ++;
1188 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1189 }
1190 }
1191 }
1192 #endif
1193 else
1194 {
1195 delete controlItem;
1196 return (wxItemResource *) NULL;
1197 }
1198 return controlItem;
1199 }
1200
1201 // Forward declaration
1202 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr);
1203
1204 /*
1205 * Interpet a menu item
1206 */
1207
1208 wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr)
1209 {
1210 wxItemResource *item = new wxItemResource;
1211
1212 wxExpr *labelExpr = expr->Nth(0);
1213 wxExpr *idExpr = expr->Nth(1);
1214 wxExpr *helpExpr = expr->Nth(2);
1215 wxExpr *checkableExpr = expr->Nth(3);
1216
1217 // Further keywords/attributes to follow sometime...
1218 if (expr->Number() == 0)
1219 {
1220 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1221 item->SetType(wxT("wxMenuSeparator"));
1222 return item;
1223 }
1224 else
1225 {
1226 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1227 item->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1228 if (labelExpr)
1229 {
1230 wxString str(labelExpr->StringValue());
1231 item->SetTitle(str);
1232 }
1233 if (idExpr)
1234 {
1235 int id = 0;
1236 // If a string or word, must look up in identifier table.
1237 if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord))
1238 {
1239 wxString str(idExpr->StringValue());
1240 id = wxResourceGetIdentifier(str, &table);
1241 if (id == 0)
1242 {
1243 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1244 (const wxChar*) idExpr->StringValue());
1245 }
1246 }
1247 else if (idExpr->Type() == PrologInteger)
1248 id = (int)idExpr->IntegerValue();
1249 item->SetValue1(id);
1250 }
1251 if (helpExpr)
1252 {
1253 wxString str(helpExpr->StringValue());
1254 item->SetValue4(str);
1255 }
1256 if (checkableExpr)
1257 item->SetValue2(checkableExpr->IntegerValue());
1258
1259 // Find the first expression that's a list, for submenu
1260 wxExpr *subMenuExpr = expr->GetFirst();
1261 while (subMenuExpr && (subMenuExpr->Type() != PrologList))
1262 subMenuExpr = subMenuExpr->GetNext();
1263
1264 while (subMenuExpr)
1265 {
1266 wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr);
1267 item->GetChildren().Append(child);
1268 subMenuExpr = subMenuExpr->GetNext();
1269 }
1270 }
1271 return item;
1272 }
1273
1274 /*
1275 * Interpret a nested list as a menu
1276 */
1277 /*
1278 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1279 {
1280 wxItemResource *menu = new wxItemResource;
1281 // menu->SetType(wxTYPE_MENU);
1282 menu->SetType("wxMenu");
1283 wxExpr *element = expr->GetFirst();
1284 while (element)
1285 {
1286 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1287 if (item)
1288 menu->GetChildren().Append(item);
1289 element = element->GetNext();
1290 }
1291 return menu;
1292 }
1293 */
1294
1295 wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr)
1296 {
1297 wxExpr *listExpr = (wxExpr *) NULL;
1298 expr->GetAttributeValue(wxT("menu"), &listExpr);
1299 if (!listExpr)
1300 return (wxItemResource *) NULL;
1301
1302 wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
1303
1304 if (!menuResource)
1305 return (wxItemResource *) NULL;
1306
1307 wxString name;
1308 if (expr->GetAttributeValue(wxT("name"), name))
1309 {
1310 menuResource->SetName(name);
1311 }
1312
1313 return menuResource;
1314 }
1315
1316 wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr)
1317 {
1318 wxExpr *listExpr = (wxExpr *) NULL;
1319 expr->GetAttributeValue(wxT("menu"), &listExpr);
1320 if (!listExpr)
1321 return (wxItemResource *) NULL;
1322
1323 wxItemResource *resource = new wxItemResource;
1324 resource->SetType(wxT("wxMenu"));
1325 // resource->SetType(wxTYPE_MENU);
1326
1327 wxExpr *element = listExpr->GetFirst();
1328 while (element)
1329 {
1330 wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
1331 resource->GetChildren().Append(menuResource);
1332 element = element->GetNext();
1333 }
1334
1335 wxString name;
1336 if (expr->GetAttributeValue(wxT("name"), name))
1337 {
1338 resource->SetName(name);
1339 }
1340
1341 return resource;
1342 }
1343
1344 wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr))
1345 {
1346 return (wxItemResource *) NULL;
1347 }
1348
1349 wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr)
1350 {
1351 wxItemResource *bitmapItem = new wxItemResource;
1352 // bitmapItem->SetType(wxTYPE_BITMAP);
1353 bitmapItem->SetType(wxT("wxBitmap"));
1354 wxString name;
1355 if (expr->GetAttributeValue(wxT("name"), name))
1356 {
1357 bitmapItem->SetName(name);
1358 }
1359 // Now parse all bitmap specifications
1360 wxExpr *bitmapExpr = expr->GetFirst();
1361 while (bitmapExpr)
1362 {
1363 if (bitmapExpr->Number() == 3)
1364 {
1365 wxString bitmapKeyword(bitmapExpr->Nth(1)->StringValue());
1366 if (bitmapKeyword == wxT("bitmap") || bitmapKeyword == wxT("icon"))
1367 {
1368 // The value part: always a list.
1369 wxExpr *listExpr = bitmapExpr->Nth(2);
1370 if (listExpr->Type() == PrologList)
1371 {
1372 wxItemResource *bitmapSpec = new wxItemResource;
1373 // bitmapSpec->SetType(wxTYPE_BITMAP);
1374 bitmapSpec->SetType(wxT("wxBitmap"));
1375
1376 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1377 // where everything after 'filename' is optional.
1378 wxExpr *nameExpr = listExpr->Nth(0);
1379 wxExpr *typeExpr = listExpr->Nth(1);
1380 wxExpr *platformExpr = listExpr->Nth(2);
1381 wxExpr *coloursExpr = listExpr->Nth(3);
1382 wxExpr *xresExpr = listExpr->Nth(4);
1383 wxExpr *yresExpr = listExpr->Nth(5);
1384 if (nameExpr && nameExpr->StringValue() != wxT(""))
1385 {
1386 bitmapSpec->SetName(nameExpr->StringValue());
1387 }
1388 if (typeExpr && typeExpr->StringValue() != wxT(""))
1389 {
1390 bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue()));
1391 }
1392 else
1393 bitmapSpec->SetValue1(0);
1394
1395 if (platformExpr && platformExpr->StringValue() != wxT(""))
1396 {
1397 wxString plat(platformExpr->StringValue());
1398 if (plat == wxT("windows") || plat == wxT("WINDOWS"))
1399 bitmapSpec->SetValue2(RESOURCE_PLATFORM_WINDOWS);
1400 else if (plat == wxT("x") || plat == wxT("X"))
1401 bitmapSpec->SetValue2(RESOURCE_PLATFORM_X);
1402 else if (plat == wxT("mac") || plat == wxT("MAC"))
1403 bitmapSpec->SetValue2(RESOURCE_PLATFORM_MAC);
1404 else
1405 bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY);
1406 }
1407 else
1408 bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY);
1409
1410 if (coloursExpr)
1411 bitmapSpec->SetValue3(coloursExpr->IntegerValue());
1412 int xres = 0;
1413 int yres = 0;
1414 if (xresExpr)
1415 xres = (int)xresExpr->IntegerValue();
1416 if (yresExpr)
1417 yres = (int)yresExpr->IntegerValue();
1418 bitmapSpec->SetSize(0, 0, xres, yres);
1419
1420 bitmapItem->GetChildren().Append(bitmapSpec);
1421 }
1422 }
1423 }
1424 bitmapExpr = bitmapExpr->GetNext();
1425 }
1426
1427 return bitmapItem;
1428 }
1429
1430 wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr)
1431 {
1432 wxItemResource *item = wxResourceInterpretBitmap(table, expr);
1433 if (item)
1434 {
1435 // item->SetType(wxTYPE_ICON);
1436 item->SetType(wxT("wxIcon"));
1437 return item;
1438 }
1439 else
1440 return (wxItemResource *) NULL;
1441 }
1442
1443 // Interpret list expression as a font
1444 wxFont wxResourceInterpretFontSpec(wxExpr *expr)
1445 {
1446 if (expr->Type() != PrologList)
1447 return wxNullFont;
1448
1449 int point = 10;
1450 int family = wxSWISS;
1451 int style = wxNORMAL;
1452 int weight = wxNORMAL;
1453 int underline = 0;
1454 wxString faceName(wxT(""));
1455
1456 wxExpr *pointExpr = expr->Nth(0);
1457 wxExpr *familyExpr = expr->Nth(1);
1458 wxExpr *styleExpr = expr->Nth(2);
1459 wxExpr *weightExpr = expr->Nth(3);
1460 wxExpr *underlineExpr = expr->Nth(4);
1461 wxExpr *faceNameExpr = expr->Nth(5);
1462 if (pointExpr)
1463 point = (int)pointExpr->IntegerValue();
1464
1465 wxString str;
1466 if (familyExpr)
1467 {
1468 str = familyExpr->StringValue();
1469 family = (int)wxParseWindowStyle(str);
1470 }
1471 if (styleExpr)
1472 {
1473 str = styleExpr->StringValue();
1474 style = (int)wxParseWindowStyle(str);
1475 }
1476 if (weightExpr)
1477 {
1478 str = weightExpr->StringValue();
1479 weight = (int)wxParseWindowStyle(str);
1480 }
1481 if (underlineExpr)
1482 underline = (int)underlineExpr->IntegerValue();
1483 if (faceNameExpr)
1484 faceName = faceNameExpr->StringValue();
1485
1486 wxFont font(point, family, style, weight, (underline != 0), faceName);
1487 return font;
1488 }
1489
1490 // Separate file for the remainder of this, for BC++/Win16
1491
1492 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1493 /*
1494 * (Re)allocate buffer for reading in from resource file
1495 */
1496
1497 bool wxReallocateResourceBuffer()
1498 {
1499 if (!wxResourceBuffer)
1500 {
1501 wxResourceBufferSize = 1000;
1502 wxResourceBuffer = new char[wxResourceBufferSize];
1503 return TRUE;
1504 }
1505 if (wxResourceBuffer)
1506 {
1507 long newSize = wxResourceBufferSize + 1000;
1508 char *tmp = new char[(int)newSize];
1509 strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount);
1510 delete[] wxResourceBuffer;
1511 wxResourceBuffer = tmp;
1512 wxResourceBufferSize = newSize;
1513 }
1514 return TRUE;
1515 }
1516
1517 static bool wxEatWhiteSpace(FILE *fd)
1518 {
1519 int ch = 0;
1520
1521 while ((ch = getc(fd)) != EOF)
1522 {
1523 switch (ch)
1524 {
1525 case ' ':
1526 case 0x0a:
1527 case 0x0d:
1528 case 0x09:
1529 break;
1530 case '/':
1531 {
1532 int prev_ch = ch;
1533 ch = getc(fd);
1534 if (ch == EOF)
1535 {
1536 ungetc(prev_ch, fd);
1537 return TRUE;
1538 }
1539
1540 if (ch == '*')
1541 {
1542 // Eat C comment
1543 prev_ch = 0;
1544 while ((ch = getc(fd)) != EOF)
1545 {
1546 if (ch == '/' && prev_ch == '*')
1547 break;
1548 prev_ch = ch;
1549 }
1550 }
1551 else if (ch == '/')
1552 {
1553 // Eat C++ comment
1554 static char buffer[255];
1555 fgets(buffer, 255, fd);
1556 }
1557 else
1558 {
1559 ungetc(prev_ch, fd);
1560 ungetc(ch, fd);
1561 return TRUE;
1562 }
1563 }
1564 break;
1565 default:
1566 ungetc(ch, fd);
1567 return TRUE;
1568
1569 }
1570 }
1571 return FALSE;
1572 }
1573 static bool wxEatWhiteSpace(wxInputStream *is)
1574 {
1575 int ch = is->GetC() ;
1576 if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
1577 {
1578 is->Ungetch(ch);
1579 return TRUE;
1580 }
1581
1582 // Eat whitespace
1583 while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
1584 ch = is->GetC();
1585 // Check for comment
1586 if (ch == '/')
1587 {
1588 ch = is->GetC();
1589 if (ch == '*')
1590 {
1591 bool finished = FALSE;
1592 while (!finished)
1593 {
1594 ch = is->GetC();
1595 if (ch == EOF)
1596 return FALSE;
1597 if (ch == '*')
1598 {
1599 int newCh = is->GetC();
1600 if (newCh == '/')
1601 finished = TRUE;
1602 else
1603 {
1604 is->Ungetch(ch);
1605 }
1606 }
1607 }
1608 }
1609 else // False alarm
1610 return FALSE;
1611 }
1612 else
1613 is->Ungetch(ch);
1614 return wxEatWhiteSpace(is);
1615 }
1616
1617 bool wxGetResourceToken(FILE *fd)
1618 {
1619 if (!wxResourceBuffer)
1620 wxReallocateResourceBuffer();
1621 wxResourceBuffer[0] = 0;
1622 wxEatWhiteSpace(fd);
1623
1624 int ch = getc(fd);
1625 if (ch == '"')
1626 {
1627 // Get string
1628 wxResourceBufferCount = 0;
1629 ch = getc(fd);
1630 while (ch != '"')
1631 {
1632 int actualCh = ch;
1633 if (ch == EOF)
1634 {
1635 wxResourceBuffer[wxResourceBufferCount] = 0;
1636 return FALSE;
1637 }
1638 // Escaped characters
1639 else if (ch == '\\')
1640 {
1641 int newCh = getc(fd);
1642 if (newCh == '"')
1643 actualCh = '"';
1644 else if (newCh == 10)
1645 actualCh = 10;
1646 else
1647 {
1648 ungetc(newCh, fd);
1649 }
1650 }
1651
1652 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1653 wxReallocateResourceBuffer();
1654 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
1655 wxResourceBufferCount ++;
1656 ch = getc(fd);
1657 }
1658 wxResourceBuffer[wxResourceBufferCount] = 0;
1659 }
1660 else
1661 {
1662 wxResourceBufferCount = 0;
1663 // Any other token
1664 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
1665 {
1666 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1667 wxReallocateResourceBuffer();
1668 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
1669 wxResourceBufferCount ++;
1670
1671 ch = getc(fd);
1672 }
1673 wxResourceBuffer[wxResourceBufferCount] = 0;
1674 if (ch == EOF)
1675 return FALSE;
1676 }
1677 return TRUE;
1678 }
1679
1680 bool wxGetResourceToken(wxInputStream *is)
1681 {
1682 if (!wxResourceBuffer)
1683 wxReallocateResourceBuffer();
1684 wxResourceBuffer[0] = 0;
1685 wxEatWhiteSpace(is);
1686
1687 int ch = is->GetC() ;
1688 if (ch == '"')
1689 {
1690 // Get string
1691 wxResourceBufferCount = 0;
1692 ch = is->GetC();
1693 while (ch != '"')
1694 {
1695 int actualCh = ch;
1696 if (ch == EOF)
1697 {
1698 wxResourceBuffer[wxResourceBufferCount] = 0;
1699 return FALSE;
1700 }
1701 // Escaped characters
1702 else if (ch == '\\')
1703 {
1704 int newCh = is->GetC();
1705 if (newCh == '"')
1706 actualCh = '"';
1707 else if (newCh == 10)
1708 actualCh = 10;
1709 else if (newCh == 13) // mac
1710 actualCh = 10;
1711 else
1712 {
1713 is->Ungetch(newCh);
1714 }
1715 }
1716
1717 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1718 wxReallocateResourceBuffer();
1719 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
1720 wxResourceBufferCount ++;
1721 ch = is->GetC();
1722 }
1723 wxResourceBuffer[wxResourceBufferCount] = 0;
1724 }
1725 else
1726 {
1727 wxResourceBufferCount = 0;
1728 // Any other token
1729 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
1730 {
1731 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1732 wxReallocateResourceBuffer();
1733 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
1734 wxResourceBufferCount ++;
1735
1736 ch = is->GetC();
1737 }
1738 wxResourceBuffer[wxResourceBufferCount] = 0;
1739 if (ch == EOF)
1740 return FALSE;
1741 }
1742 return TRUE;
1743 }
1744
1745 /*
1746 * Files are in form:
1747 static char *name = "....";
1748 with possible comments.
1749 */
1750
1751 bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table)
1752 {
1753 if (!table)
1754 table = wxDefaultResourceTable;
1755
1756 // static or #define
1757 if (!wxGetResourceToken(fd))
1758 {
1759 *eof = TRUE;
1760 return FALSE;
1761 }
1762
1763 if (strcmp(wxResourceBuffer, "#define") == 0)
1764 {
1765 wxGetResourceToken(fd);
1766 wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
1767 wxGetResourceToken(fd);
1768 wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
1769 if (wxIsdigit(value[0]))
1770 {
1771 int val = (int)wxAtol(value);
1772 wxResourceAddIdentifier(name, val, table);
1773 }
1774 else
1775 {
1776 wxLogWarning(_("#define %s must be an integer."), name);
1777 delete[] name;
1778 delete[] value;
1779 return FALSE;
1780 }
1781 delete[] name;
1782 delete[] value;
1783
1784 return TRUE;
1785 }
1786 else if (strcmp(wxResourceBuffer, "#include") == 0)
1787 {
1788 wxGetResourceToken(fd);
1789 wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
1790 wxChar *actualName = name;
1791 if (name[0] == wxT('"'))
1792 actualName = name + 1;
1793 int len = wxStrlen(name);
1794 if ((len > 0) && (name[len-1] == wxT('"')))
1795 name[len-1] = 0;
1796 if (!wxResourceParseIncludeFile(actualName, table))
1797 {
1798 wxLogWarning(_("Could not find resource include file %s."), actualName);
1799 }
1800 delete[] name;
1801 return TRUE;
1802 }
1803 else if (strcmp(wxResourceBuffer, "static") != 0)
1804 {
1805 wxChar buf[300];
1806 wxStrcpy(buf, _("Found "));
1807 wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30);
1808 wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
1809 wxLogWarning(buf);
1810 return FALSE;
1811 }
1812
1813 // char
1814 if (!wxGetResourceToken(fd))
1815 {
1816 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1817 *eof = TRUE;
1818 return FALSE;
1819 }
1820
1821 if (strcmp(wxResourceBuffer, "char") != 0)
1822 {
1823 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1824 return FALSE;
1825 }
1826
1827 // *name
1828 if (!wxGetResourceToken(fd))
1829 {
1830 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1831 *eof = TRUE;
1832 return FALSE;
1833 }
1834
1835 if (wxResourceBuffer[0] != '*')
1836 {
1837 wxLogWarning(_("Expected '*' whilst parsing resource."));
1838 return FALSE;
1839 }
1840 wxChar nameBuf[100];
1841 wxMB2WX(nameBuf, wxResourceBuffer+1, 99);
1842 nameBuf[99] = 0;
1843
1844 // =
1845 if (!wxGetResourceToken(fd))
1846 {
1847 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1848 *eof = TRUE;
1849 return FALSE;
1850 }
1851
1852 if (strcmp(wxResourceBuffer, "=") != 0)
1853 {
1854 wxLogWarning(_("Expected '=' whilst parsing resource."));
1855 return FALSE;
1856 }
1857
1858 // String
1859 if (!wxGetResourceToken(fd))
1860 {
1861 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1862 *eof = TRUE;
1863 return FALSE;
1864 }
1865 else
1866 {
1867 if (!db.ReadPrologFromString(wxResourceBuffer))
1868 {
1869 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
1870 return FALSE;
1871 }
1872 }
1873 // Semicolon
1874 if (!wxGetResourceToken(fd))
1875 {
1876 *eof = TRUE;
1877 }
1878 return TRUE;
1879 }
1880
1881 bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table)
1882 {
1883 if (!table)
1884 table = wxDefaultResourceTable;
1885
1886 // static or #define
1887 if (!wxGetResourceToken(fd))
1888 {
1889 *eof = TRUE;
1890 return FALSE;
1891 }
1892
1893 if (strcmp(wxResourceBuffer, "#define") == 0)
1894 {
1895 wxGetResourceToken(fd);
1896 wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer));
1897 wxGetResourceToken(fd);
1898 wxChar *value = copystring(wxConvLibc.cMB2WX(wxResourceBuffer));
1899 if (wxIsalpha(value[0]))
1900 {
1901 int val = (int)wxAtol(value);
1902 wxResourceAddIdentifier(name, val, table);
1903 }
1904 else
1905 {
1906 wxLogWarning(_("#define %s must be an integer."), name);
1907 delete[] name;
1908 delete[] value;
1909 return FALSE;
1910 }
1911 delete[] name;
1912 delete[] value;
1913
1914 return TRUE;
1915 }
1916 else if (strcmp(wxResourceBuffer, "#include") == 0)
1917 {
1918 wxGetResourceToken(fd);
1919 wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer));
1920 wxChar *actualName = name;
1921 if (name[0] == wxT('"'))
1922 actualName = name + 1;
1923 int len = wxStrlen(name);
1924 if ((len > 0) && (name[len-1] == wxT('"')))
1925 name[len-1] = 0;
1926 if (!wxResourceParseIncludeFile(actualName, table))
1927 {
1928 wxLogWarning(_("Could not find resource include file %s."), actualName);
1929 }
1930 delete[] name;
1931 return TRUE;
1932 }
1933 else if (strcmp(wxResourceBuffer, "static") != 0)
1934 {
1935 wxChar buf[300];
1936 wxStrcpy(buf, _("Found "));
1937 wxStrncat(buf, wxConvLibc.cMB2WX(wxResourceBuffer), 30);
1938 wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
1939 wxLogWarning(buf);
1940 return FALSE;
1941 }
1942
1943 // char
1944 if (!wxGetResourceToken(fd))
1945 {
1946 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1947 *eof = TRUE;
1948 return FALSE;
1949 }
1950
1951 if (strcmp(wxResourceBuffer, "char") != 0)
1952 {
1953 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1954 return FALSE;
1955 }
1956
1957 // *name
1958 if (!wxGetResourceToken(fd))
1959 {
1960 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1961 *eof = TRUE;
1962 return FALSE;
1963 }
1964
1965 if (wxResourceBuffer[0] != '*')
1966 {
1967 wxLogWarning(_("Expected '*' whilst parsing resource."));
1968 return FALSE;
1969 }
1970 char nameBuf[100];
1971 strncpy(nameBuf, wxResourceBuffer+1, 99);
1972
1973 // =
1974 if (!wxGetResourceToken(fd))
1975 {
1976 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1977 *eof = TRUE;
1978 return FALSE;
1979 }
1980
1981 if (strcmp(wxResourceBuffer, "=") != 0)
1982 {
1983 wxLogWarning(_("Expected '=' whilst parsing resource."));
1984 return FALSE;
1985 }
1986
1987 // String
1988 if (!wxGetResourceToken(fd))
1989 {
1990 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1991 *eof = TRUE;
1992 return FALSE;
1993 }
1994 else
1995 {
1996 if (!db.ReadPrologFromString(wxResourceBuffer))
1997 {
1998 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
1999 return FALSE;
2000 }
2001 }
2002 // Semicolon
2003 if (!wxGetResourceToken(fd))
2004 {
2005 *eof = TRUE;
2006 }
2007 return TRUE;
2008 }
2009
2010 /*
2011 * Parses string window style into integer window style
2012 */
2013
2014 /*
2015 * Style flag parsing, e.g.
2016 * "wxSYSTEM_MENU | wxBORDER" -> integer
2017 */
2018
2019 wxChar* wxResourceParseWord(wxChar*s, int *i)
2020 {
2021 if (!s)
2022 return (wxChar*) NULL;
2023
2024 static wxChar buf[150];
2025 int len = wxStrlen(s);
2026 int j = 0;
2027 int ii = *i;
2028 while ((ii < len) && (wxIsalpha(s[ii]) || (s[ii] == wxT('_'))))
2029 {
2030 buf[j] = s[ii];
2031 j ++;
2032 ii ++;
2033 }
2034 buf[j] = 0;
2035
2036 // Eat whitespace and conjunction characters
2037 while ((ii < len) &&
2038 ((s[ii] == wxT(' ')) || (s[ii] == wxT('|')) || (s[ii] == wxT(','))))
2039 {
2040 ii ++;
2041 }
2042 *i = ii;
2043 if (j == 0)
2044 return (wxChar*) NULL;
2045 else
2046 return buf;
2047 }
2048
2049 struct wxResourceBitListStruct
2050 {
2051 wxChar *word;
2052 long bits;
2053 };
2054
2055 static wxResourceBitListStruct wxResourceBitListTable[] =
2056 {
2057 /* wxListBox */
2058 { wxT("wxSINGLE"), wxLB_SINGLE },
2059 { wxT("wxMULTIPLE"), wxLB_MULTIPLE },
2060 { wxT("wxEXTENDED"), wxLB_EXTENDED },
2061 { wxT("wxLB_SINGLE"), wxLB_SINGLE },
2062 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE },
2063 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED },
2064 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB },
2065 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB },
2066 { wxT("wxLB_SORT"), wxLB_SORT },
2067 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW },
2068 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL },
2069
2070 /* wxComboxBox */
2071 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE },
2072 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN },
2073 { wxT("wxCB_READONLY"), wxCB_READONLY },
2074 { wxT("wxCB_SORT"), wxCB_SORT },
2075
2076 /* wxGauge */
2077 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR },
2078 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL },
2079 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL },
2080
2081 /* wxTextCtrl */
2082 { wxT("wxPASSWORD"), wxPASSWORD},
2083 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER},
2084 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD},
2085 { wxT("wxTE_READONLY"), wxTE_READONLY},
2086 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER},
2087 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE},
2088 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL},
2089
2090 /* wxRadioBox/wxRadioButton */
2091 { wxT("wxRB_GROUP"), wxRB_GROUP },
2092 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS },
2093 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS },
2094 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL },
2095 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL },
2096
2097 /* wxSlider */
2098 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL },
2099 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL },
2100 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS },
2101 { wxT("wxSL_LABELS"), wxSL_LABELS },
2102 { wxT("wxSL_LEFT"), wxSL_LEFT },
2103 { wxT("wxSL_TOP"), wxSL_TOP },
2104 { wxT("wxSL_RIGHT"), wxSL_RIGHT },
2105 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM },
2106 { wxT("wxSL_BOTH"), wxSL_BOTH },
2107 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE },
2108
2109 /* wxScrollBar */
2110 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL },
2111 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL },
2112
2113 /* wxButton */
2114 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW },
2115 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW },
2116
2117 /* wxTreeCtrl */
2118 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS },
2119 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS },
2120 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT },
2121
2122 /* wxListCtrl */
2123 { wxT("wxLC_ICON"), wxLC_ICON },
2124 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON },
2125 { wxT("wxLC_LIST"), wxLC_LIST },
2126 { wxT("wxLC_REPORT"), wxLC_REPORT },
2127 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP },
2128 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT },
2129 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE },
2130 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT },
2131 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS },
2132 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER },
2133 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER },
2134 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL },
2135 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING },
2136 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING },
2137
2138 /* wxSpinButton */
2139 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL},
2140 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL},
2141 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS},
2142 { wxT("wxSP_WRAP"), wxSP_WRAP},
2143
2144 /* wxSplitterWnd */
2145 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER},
2146 { wxT("wxSP_3D"), wxSP_3D},
2147 { wxT("wxSP_BORDER"), wxSP_BORDER},
2148
2149 /* wxTabCtrl */
2150 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE},
2151 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY},
2152 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH},
2153 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW},
2154
2155 /* wxStatusBar95 */
2156 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP},
2157
2158 /* wxControl */
2159 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH},
2160 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT},
2161 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER},
2162 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE},
2163 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT},
2164 { wxT("wxCOLOURED"), wxCOLOURED},
2165
2166 /* wxToolBar */
2167 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS},
2168 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL},
2169 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL},
2170 { wxT("wxTB_FLAT"), wxTB_FLAT},
2171
2172 /* wxDialog */
2173 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL },
2174
2175 /* Generic */
2176 { wxT("wxVSCROLL"), wxVSCROLL },
2177 { wxT("wxHSCROLL"), wxHSCROLL },
2178 { wxT("wxCAPTION"), wxCAPTION },
2179 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP},
2180 { wxT("wxICONIZE"), wxICONIZE},
2181 { wxT("wxMINIMIZE"), wxICONIZE},
2182 { wxT("wxMAXIMIZE"), wxMAXIMIZE},
2183 { wxT("wxSDI"), 0},
2184 { wxT("wxMDI_PARENT"), 0},
2185 { wxT("wxMDI_CHILD"), 0},
2186 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME},
2187 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER},
2188 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU},
2189 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX},
2190 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX},
2191 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX},
2192 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE},
2193 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE},
2194 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE},
2195 { wxT("wxBORDER"), wxBORDER},
2196 { wxT("wxRETAINED"), wxRETAINED},
2197 { wxT("wxNATIVE_IMPL"), 0},
2198 { wxT("wxEXTENDED_IMPL"), 0},
2199 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE},
2200 // { wxT("wxFLAT"), wxFLAT},
2201 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2202 { wxT("wxFIXED_LENGTH"), 0},
2203 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER},
2204 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER},
2205 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER},
2206 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER},
2207 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER},
2208 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW},
2209 { wxT("wxNO_BORDER"), wxNO_BORDER},
2210 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN},
2211 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS},
2212 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2213
2214 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ},
2215 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT},
2216
2217 // Text font families
2218 { wxT("wxDEFAULT"), wxDEFAULT},
2219 { wxT("wxDECORATIVE"), wxDECORATIVE},
2220 { wxT("wxROMAN"), wxROMAN},
2221 { wxT("wxSCRIPT"), wxSCRIPT},
2222 { wxT("wxSWISS"), wxSWISS},
2223 { wxT("wxMODERN"), wxMODERN},
2224 { wxT("wxTELETYPE"), wxTELETYPE},
2225 { wxT("wxVARIABLE"), wxVARIABLE},
2226 { wxT("wxFIXED"), wxFIXED},
2227 { wxT("wxNORMAL"), wxNORMAL},
2228 { wxT("wxLIGHT"), wxLIGHT},
2229 { wxT("wxBOLD"), wxBOLD},
2230 { wxT("wxITALIC"), wxITALIC},
2231 { wxT("wxSLANT"), wxSLANT},
2232 { wxT("wxSOLID"), wxSOLID},
2233 { wxT("wxDOT"), wxDOT},
2234 { wxT("wxLONG_DASH"), wxLONG_DASH},
2235 { wxT("wxSHORT_DASH"), wxSHORT_DASH},
2236 { wxT("wxDOT_DASH"), wxDOT_DASH},
2237 { wxT("wxUSER_DASH"), wxUSER_DASH},
2238 { wxT("wxTRANSPARENT"), wxTRANSPARENT},
2239 { wxT("wxSTIPPLE"), wxSTIPPLE},
2240 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH},
2241 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH},
2242 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH},
2243 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH},
2244 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH},
2245 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH},
2246 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL},
2247 { wxT("wxJOIN_MITER"), wxJOIN_MITER},
2248 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND},
2249 { wxT("wxCAP_ROUND"), wxCAP_ROUND},
2250 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING},
2251 { wxT("wxCAP_BUTT"), wxCAP_BUTT},
2252
2253 // Logical ops
2254 { wxT("wxCLEAR"), wxCLEAR},
2255 { wxT("wxXOR"), wxXOR},
2256 { wxT("wxINVERT"), wxINVERT},
2257 { wxT("wxOR_REVERSE"), wxOR_REVERSE},
2258 { wxT("wxAND_REVERSE"), wxAND_REVERSE},
2259 { wxT("wxCOPY"), wxCOPY},
2260 { wxT("wxAND"), wxAND},
2261 { wxT("wxAND_INVERT"), wxAND_INVERT},
2262 { wxT("wxNO_OP"), wxNO_OP},
2263 { wxT("wxNOR"), wxNOR},
2264 { wxT("wxEQUIV"), wxEQUIV},
2265 { wxT("wxSRC_INVERT"), wxSRC_INVERT},
2266 { wxT("wxOR_INVERT"), wxOR_INVERT},
2267 { wxT("wxNAND"), wxNAND},
2268 { wxT("wxOR"), wxOR},
2269 { wxT("wxSET"), wxSET},
2270
2271 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE},
2272 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER},
2273 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE},
2274 { wxT("wxWINDING_RULE"), wxWINDING_RULE},
2275 { wxT("wxHORIZONTAL"), wxHORIZONTAL},
2276 { wxT("wxVERTICAL"), wxVERTICAL},
2277 { wxT("wxBOTH"), wxBOTH},
2278 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME},
2279 { wxT("wxOK"), wxOK},
2280 { wxT("wxYES_NO"), wxYES_NO},
2281 { wxT("wxCANCEL"), wxCANCEL},
2282 { wxT("wxYES"), wxYES},
2283 { wxT("wxNO"), wxNO},
2284 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION},
2285 { wxT("wxICON_HAND"), wxICON_HAND},
2286 { wxT("wxICON_QUESTION"), wxICON_QUESTION},
2287 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION},
2288 { wxT("wxICON_STOP"), wxICON_STOP},
2289 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK},
2290 { wxT("wxICON_MASK"), wxICON_MASK},
2291 { wxT("wxCENTRE"), wxCENTRE},
2292 { wxT("wxCENTER"), wxCENTRE},
2293 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS},
2294 { wxT("wxVERTICAL_LABEL"), 0},
2295 { wxT("wxHORIZONTAL_LABEL"), 0},
2296
2297 // Bitmap types (not strictly styles)
2298 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM},
2299 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM},
2300 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP},
2301 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE},
2302 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE},
2303 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF},
2304 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF},
2305 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO},
2306 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE},
2307 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR},
2308 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE},
2309 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA},
2310 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA},
2311 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY}
2312 };
2313
2314 static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct));
2315
2316 long wxParseWindowStyle(const wxString& bitListString)
2317 {
2318 int i = 0;
2319 wxChar *word;
2320 long bitList = 0;
2321 word = wxResourceParseWord(WXSTRINGCAST bitListString, &i);
2322 while (word != NULL)
2323 {
2324 bool found = FALSE;
2325 int j;
2326 for (j = 0; j < wxResourceBitListCount; j++)
2327 if (wxStrcmp(wxResourceBitListTable[j].word, word) == 0)
2328 {
2329 bitList |= wxResourceBitListTable[j].bits;
2330 found = TRUE;
2331 break;
2332 }
2333 if (!found)
2334 {
2335 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word);
2336 return 0;
2337 }
2338 word = wxResourceParseWord(WXSTRINGCAST bitListString, &i);
2339 }
2340 return bitList;
2341 }
2342
2343 /*
2344 * Load a bitmap from a wxWindows resource, choosing an optimum
2345 * depth and appropriate type.
2346 */
2347
2348 wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table)
2349 {
2350 if (!table)
2351 table = wxDefaultResourceTable;
2352
2353 wxItemResource *item = table->FindResource(resource);
2354 if (item)
2355 {
2356 if ((item->GetType() == wxT("")) || (item->GetType() != wxT("wxBitmap")))
2357 {
2358 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar*) resource);
2359 return wxNullBitmap;
2360 }
2361 int thisDepth = wxDisplayDepth();
2362 long thisNoColours = (long)pow(2.0, (double)thisDepth);
2363
2364 wxItemResource *optResource = (wxItemResource *) NULL;
2365
2366 // Try to find optimum bitmap for this platform/colour depth
2367 wxNode *node = item->GetChildren().First();
2368 while (node)
2369 {
2370 wxItemResource *child = (wxItemResource *)node->Data();
2371 int platform = (int)child->GetValue2();
2372 int noColours = (int)child->GetValue3();
2373 /*
2374 char *name = child->GetName();
2375 int bitmapType = (int)child->GetValue1();
2376 int xRes = child->GetWidth();
2377 int yRes = child->GetHeight();
2378 */
2379
2380 switch (platform)
2381 {
2382 case RESOURCE_PLATFORM_ANY:
2383 {
2384 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2385 optResource = child;
2386 else
2387 {
2388 // Maximise the number of colours.
2389 // If noColours is zero (unspecified), then assume this
2390 // is the right one.
2391 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2392 optResource = child;
2393 }
2394 break;
2395 }
2396 #ifdef __WXMSW__
2397 case RESOURCE_PLATFORM_WINDOWS:
2398 {
2399 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2400 optResource = child;
2401 else
2402 {
2403 // Maximise the number of colours
2404 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2405 optResource = child;
2406 }
2407 break;
2408 }
2409 #endif
2410 #ifdef __WXGTK__
2411 case RESOURCE_PLATFORM_X:
2412 {
2413 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2414 optResource = child;
2415 else
2416 {
2417 // Maximise the number of colours
2418 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2419 optResource = child;
2420 }
2421 break;
2422 }
2423 #endif
2424 #ifdef wx_max
2425 case RESOURCE_PLATFORM_MAC:
2426 {
2427 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2428 optResource = child;
2429 else
2430 {
2431 // Maximise the number of colours
2432 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2433 optResource = child;
2434 }
2435 break;
2436 }
2437 #endif
2438 default:
2439 break;
2440 }
2441 node = node->Next();
2442 }
2443 // If no matching resource, fail.
2444 if (!optResource)
2445 return wxNullBitmap;
2446
2447 wxString name = optResource->GetName();
2448 int bitmapType = (int)optResource->GetValue1();
2449 switch (bitmapType)
2450 {
2451 case wxBITMAP_TYPE_XBM_DATA:
2452 {
2453 #ifdef __WXGTK__
2454 wxItemResource *item = table->FindResource(name);
2455 if (!item)
2456 {
2457 wxLogWarning(_("Failed to find XBM resource %s.\n"
2458 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar*) name);
2459 return wxNullBitmap;
2460 }
2461 return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ;
2462 #else
2463 wxLogWarning(_("No XBM facility available!"));
2464 break;
2465 #endif
2466 }
2467 case wxBITMAP_TYPE_XPM_DATA:
2468 {
2469 wxItemResource *item = table->FindResource(name);
2470 if (!item)
2471 {
2472 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar*) name);
2473 return wxNullBitmap;
2474 }
2475 return wxBitmap((char **)item->GetValue1());
2476 }
2477 default:
2478 {
2479 return wxBitmap(name, (wxBitmapType)bitmapType);
2480 }
2481 }
2482 #ifndef __WXGTK__
2483 return wxNullBitmap;
2484 #endif
2485 }
2486 else
2487 {
2488 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar*) resource);
2489 return wxNullBitmap;
2490 }
2491 }
2492
2493 /*
2494 * Load an icon from a wxWindows resource, choosing an optimum
2495 * depth and appropriate type.
2496 */
2497
2498 wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table)
2499 {
2500 if (!table)
2501 table = wxDefaultResourceTable;
2502
2503 wxItemResource *item = table->FindResource(resource);
2504 if (item)
2505 {
2506 if ((item->GetType() == wxT("")) || wxStrcmp(item->GetType(), wxT("wxIcon")) != 0)
2507 {
2508 wxLogWarning(_("%s not an icon resource specification."), (const wxChar*) resource);
2509 return wxNullIcon;
2510 }
2511 int thisDepth = wxDisplayDepth();
2512 long thisNoColours = (long)pow(2.0, (double)thisDepth);
2513
2514 wxItemResource *optResource = (wxItemResource *) NULL;
2515
2516 // Try to find optimum icon for this platform/colour depth
2517 wxNode *node = item->GetChildren().First();
2518 while (node)
2519 {
2520 wxItemResource *child = (wxItemResource *)node->Data();
2521 int platform = (int)child->GetValue2();
2522 int noColours = (int)child->GetValue3();
2523 /*
2524 char *name = child->GetName();
2525 int bitmapType = (int)child->GetValue1();
2526 int xRes = child->GetWidth();
2527 int yRes = child->GetHeight();
2528 */
2529
2530 switch (platform)
2531 {
2532 case RESOURCE_PLATFORM_ANY:
2533 {
2534 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2535 optResource = child;
2536 else
2537 {
2538 // Maximise the number of colours.
2539 // If noColours is zero (unspecified), then assume this
2540 // is the right one.
2541 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2542 optResource = child;
2543 }
2544 break;
2545 }
2546 #ifdef __WXMSW__
2547 case RESOURCE_PLATFORM_WINDOWS:
2548 {
2549 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2550 optResource = child;
2551 else
2552 {
2553 // Maximise the number of colours
2554 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2555 optResource = child;
2556 }
2557 break;
2558 }
2559 #endif
2560 #ifdef __WXGTK__
2561 case RESOURCE_PLATFORM_X:
2562 {
2563 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2564 optResource = child;
2565 else
2566 {
2567 // Maximise the number of colours
2568 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2569 optResource = child;
2570 }
2571 break;
2572 }
2573 #endif
2574 #ifdef wx_max
2575 case RESOURCE_PLATFORM_MAC:
2576 {
2577 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2578 optResource = child;
2579 else
2580 {
2581 // Maximise the number of colours
2582 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2583 optResource = child;
2584 }
2585 break;
2586 }
2587 #endif
2588 default:
2589 break;
2590 }
2591 node = node->Next();
2592 }
2593 // If no matching resource, fail.
2594 if (!optResource)
2595 return wxNullIcon;
2596
2597 wxString name = optResource->GetName();
2598 int bitmapType = (int)optResource->GetValue1();
2599 switch (bitmapType)
2600 {
2601 case wxBITMAP_TYPE_XBM_DATA:
2602 {
2603 #ifdef __WXGTK__
2604 wxItemResource *item = table->FindResource(name);
2605 if (!item)
2606 {
2607 wxLogWarning(_("Failed to find XBM resource %s.\n"
2608 "Forgot to use wxResourceLoadIconData?"), (const wxChar*) name);
2609 return wxNullIcon;
2610 }
2611 return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3());
2612 #else
2613 wxLogWarning(_("No XBM facility available!"));
2614 break;
2615 #endif
2616 }
2617 case wxBITMAP_TYPE_XPM_DATA:
2618 {
2619 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2620 /*
2621 wxItemResource *item = table->FindResource(name);
2622 if (!item)
2623 {
2624 char buf[400];
2625 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2626 wxLogWarning(buf);
2627 return NULL;
2628 }
2629 return wxIcon((char **)item->GetValue1());
2630 */
2631 wxLogWarning(_("No XPM icon facility available!"));
2632 break;
2633 }
2634 default:
2635 {
2636 #ifdef __WXGTK__
2637 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource);
2638 break;
2639 #else
2640 return wxIcon(name, bitmapType);
2641 #endif
2642 }
2643 }
2644 return wxNullIcon;
2645 }
2646 else
2647 {
2648 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource);
2649 return wxNullIcon;
2650 }
2651 }
2652
2653 #if wxUSE_MENUS
2654
2655 wxMenu *wxResourceCreateMenu(wxItemResource *item)
2656 {
2657 wxMenu *menu = new wxMenu;
2658 wxNode *node = item->GetChildren().First();
2659 while (node)
2660 {
2661 wxItemResource *child = (wxItemResource *)node->Data();
2662 if ((child->GetType() != wxT("")) && (child->GetType() == wxT("wxMenuSeparator")))
2663 menu->AppendSeparator();
2664 else if (child->GetChildren().Number() > 0)
2665 {
2666 wxMenu *subMenu = wxResourceCreateMenu(child);
2667 if (subMenu)
2668 menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4());
2669 }
2670 else
2671 {
2672 menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0));
2673 }
2674 node = node->Next();
2675 }
2676 return menu;
2677 }
2678
2679 wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar)
2680 {
2681 if (!table)
2682 table = wxDefaultResourceTable;
2683
2684 wxItemResource *menuResource = table->FindResource(resource);
2685 if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu")))
2686 {
2687 if (!menuBar)
2688 menuBar = new wxMenuBar;
2689 wxNode *node = menuResource->GetChildren().First();
2690 while (node)
2691 {
2692 wxItemResource *child = (wxItemResource *)node->Data();
2693 wxMenu *menu = wxResourceCreateMenu(child);
2694 if (menu)
2695 menuBar->Append(menu, child->GetTitle());
2696 node = node->Next();
2697 }
2698 return menuBar;
2699 }
2700 return (wxMenuBar *) NULL;
2701 }
2702
2703 wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table)
2704 {
2705 if (!table)
2706 table = wxDefaultResourceTable;
2707
2708 wxItemResource *menuResource = table->FindResource(resource);
2709 if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu")))
2710 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2711 return wxResourceCreateMenu(menuResource);
2712 return (wxMenu *) NULL;
2713 }
2714
2715 #endif // wxUSE_MENUS
2716
2717 // Global equivalents (so don't have to refer to default table explicitly)
2718 bool wxResourceParseData(const wxString& resource, wxResourceTable *table)
2719 {
2720 if (!table)
2721 table = wxDefaultResourceTable;
2722
2723 return table->ParseResourceData(resource);
2724 }
2725
2726 bool wxResourceParseFile(const wxString& filename, wxResourceTable *table)
2727 {
2728 if (!table)
2729 table = wxDefaultResourceTable;
2730
2731 return table->ParseResourceFile(filename);
2732 }
2733
2734 // Register XBM/XPM data
2735 bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table)
2736 {
2737 if (!table)
2738 table = wxDefaultResourceTable;
2739
2740 return table->RegisterResourceBitmapData(name, bits, width, height);
2741 }
2742
2743 bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table)
2744 {
2745 if (!table)
2746 table = wxDefaultResourceTable;
2747
2748 return table->RegisterResourceBitmapData(name, data);
2749 }
2750
2751 void wxResourceClear(wxResourceTable *table)
2752 {
2753 if (!table)
2754 table = wxDefaultResourceTable;
2755
2756 table->ClearTable();
2757 }
2758
2759 /*
2760 * Identifiers
2761 */
2762
2763 bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table)
2764 {
2765 if (!table)
2766 table = wxDefaultResourceTable;
2767
2768 table->identifiers.Put(name, (wxObject *)(long)value);
2769 return TRUE;
2770 }
2771
2772 int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table)
2773 {
2774 if (!table)
2775 table = wxDefaultResourceTable;
2776
2777 return (int)(long)table->identifiers.Get(name);
2778 }
2779
2780 /*
2781 * Parse #include file for #defines (only)
2782 */
2783
2784 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table)
2785 {
2786 if (!table)
2787 table = wxDefaultResourceTable;
2788
2789 FILE *fd = wxFopen(f, _T("r"));
2790 if (!fd)
2791 {
2792 return FALSE;
2793 }
2794 while (wxGetResourceToken(fd))
2795 {
2796 if (strcmp(wxResourceBuffer, "#define") == 0)
2797 {
2798 wxGetResourceToken(fd);
2799 wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2800 wxGetResourceToken(fd);
2801 wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2802 if (wxIsdigit(value[0]))
2803 {
2804 int val = (int)wxAtol(value);
2805 wxResourceAddIdentifier(name, val, table);
2806 }
2807 delete[] name;
2808 delete[] value;
2809 }
2810 }
2811 fclose(fd);
2812 return TRUE;
2813 }
2814
2815 /*
2816 * Reading strings as if they were .wxr files
2817 */
2818
2819 static int getc_string(char *s)
2820 {
2821 int ch = s[wxResourceStringPtr];
2822 if (ch == 0)
2823 return EOF;
2824 else
2825 {
2826 wxResourceStringPtr ++;
2827 return ch;
2828 }
2829 }
2830
2831 static int ungetc_string()
2832 {
2833 wxResourceStringPtr --;
2834 return 0;
2835 }
2836
2837 bool wxEatWhiteSpaceString(char *s)
2838 {
2839 int ch = 0;
2840
2841 while ((ch = getc_string(s)) != EOF)
2842 {
2843 switch (ch)
2844 {
2845 case ' ':
2846 case 0x0a:
2847 case 0x0d:
2848 case 0x09:
2849 break;
2850 case '/':
2851 {
2852 int prev_ch = ch;
2853 ch = getc_string(s);
2854 if (ch == EOF)
2855 {
2856 ungetc_string();
2857 return TRUE;
2858 }
2859
2860 if (ch == '*')
2861 {
2862 // Eat C comment
2863 prev_ch = 0;
2864 while ((ch = getc_string(s)) != EOF)
2865 {
2866 if (ch == '/' && prev_ch == '*')
2867 break;
2868 prev_ch = ch;
2869 }
2870 }
2871 else
2872 {
2873 ungetc_string();
2874 ungetc_string();
2875 return TRUE;
2876 }
2877 }
2878 break;
2879 default:
2880 ungetc_string();
2881 return TRUE;
2882
2883 }
2884 }
2885 return FALSE;
2886 }
2887
2888 bool wxGetResourceTokenString(char *s)
2889 {
2890 if (!wxResourceBuffer)
2891 wxReallocateResourceBuffer();
2892 wxResourceBuffer[0] = 0;
2893 wxEatWhiteSpaceString(s);
2894
2895 int ch = getc_string(s);
2896 if (ch == '"')
2897 {
2898 // Get string
2899 wxResourceBufferCount = 0;
2900 ch = getc_string(s);
2901 while (ch != '"')
2902 {
2903 int actualCh = ch;
2904 if (ch == EOF)
2905 {
2906 wxResourceBuffer[wxResourceBufferCount] = 0;
2907 return FALSE;
2908 }
2909 // Escaped characters
2910 else if (ch == '\\')
2911 {
2912 int newCh = getc_string(s);
2913 if (newCh == '"')
2914 actualCh = '"';
2915 else if (newCh == 10)
2916 actualCh = 10;
2917 else
2918 {
2919 ungetc_string();
2920 }
2921 }
2922
2923 if (wxResourceBufferCount >= wxResourceBufferSize-1)
2924 wxReallocateResourceBuffer();
2925 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
2926 wxResourceBufferCount ++;
2927 ch = getc_string(s);
2928 }
2929 wxResourceBuffer[wxResourceBufferCount] = 0;
2930 }
2931 else
2932 {
2933 wxResourceBufferCount = 0;
2934 // Any other token
2935 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
2936 {
2937 if (wxResourceBufferCount >= wxResourceBufferSize-1)
2938 wxReallocateResourceBuffer();
2939 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
2940 wxResourceBufferCount ++;
2941
2942 ch = getc_string(s);
2943 }
2944 wxResourceBuffer[wxResourceBufferCount] = 0;
2945 if (ch == EOF)
2946 return FALSE;
2947 }
2948 return TRUE;
2949 }
2950
2951 /*
2952 * Files are in form:
2953 static char *name = "....";
2954 with possible comments.
2955 */
2956
2957 bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table)
2958 {
2959 if (!table)
2960 table = wxDefaultResourceTable;
2961
2962 // static or #define
2963 if (!wxGetResourceTokenString(s))
2964 {
2965 *eof = TRUE;
2966 return FALSE;
2967 }
2968
2969 if (strcmp(wxResourceBuffer, "#define") == 0)
2970 {
2971 wxGetResourceTokenString(s);
2972 wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2973 wxGetResourceTokenString(s);
2974 wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2975 if (wxIsdigit(value[0]))
2976 {
2977 int val = (int)wxAtol(value);
2978 wxResourceAddIdentifier(name, val, table);
2979 }
2980 else
2981 {
2982 wxLogWarning(_("#define %s must be an integer."), name);
2983 delete[] name;
2984 delete[] value;
2985 return FALSE;
2986 }
2987 delete[] name;
2988 delete[] value;
2989
2990 return TRUE;
2991 }
2992 /*
2993 else if (strcmp(wxResourceBuffer, "#include") == 0)
2994 {
2995 wxGetResourceTokenString(s);
2996 char *name = copystring(wxResourceBuffer);
2997 char *actualName = name;
2998 if (name[0] == '"')
2999 actualName = name + 1;
3000 int len = strlen(name);
3001 if ((len > 0) && (name[len-1] == '"'))
3002 name[len-1] = 0;
3003 if (!wxResourceParseIncludeFile(actualName, table))
3004 {
3005 char buf[400];
3006 sprintf(buf, _("Could not find resource include file %s."), actualName);
3007 wxLogWarning(buf);
3008 }
3009 delete[] name;
3010 return TRUE;
3011 }
3012 */
3013 else if (strcmp(wxResourceBuffer, "static") != 0)
3014 {
3015 wxChar buf[300];
3016 wxStrcpy(buf, _("Found "));
3017 wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30);
3018 wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
3019 wxLogWarning(buf);
3020 return FALSE;
3021 }
3022
3023 // char
3024 if (!wxGetResourceTokenString(s))
3025 {
3026 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3027 *eof = TRUE;
3028 return FALSE;
3029 }
3030
3031 if (strcmp(wxResourceBuffer, "char") != 0)
3032 {
3033 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3034 return FALSE;
3035 }
3036
3037 // *name
3038 if (!wxGetResourceTokenString(s))
3039 {
3040 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3041 *eof = TRUE;
3042 return FALSE;
3043 }
3044
3045 if (wxResourceBuffer[0] != '*')
3046 {
3047 wxLogWarning(_("Expected '*' whilst parsing resource."));
3048 return FALSE;
3049 }
3050 wxChar nameBuf[100];
3051 wxMB2WX(nameBuf, wxResourceBuffer+1, 99);
3052 nameBuf[99] = 0;
3053
3054 // =
3055 if (!wxGetResourceTokenString(s))
3056 {
3057 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3058 *eof = TRUE;
3059 return FALSE;
3060 }
3061
3062 if (strcmp(wxResourceBuffer, "=") != 0)
3063 {
3064 wxLogWarning(_("Expected '=' whilst parsing resource."));
3065 return FALSE;
3066 }
3067
3068 // String
3069 if (!wxGetResourceTokenString(s))
3070 {
3071 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3072 *eof = TRUE;
3073 return FALSE;
3074 }
3075 else
3076 {
3077 if (!db.ReadPrologFromString(wxResourceBuffer))
3078 {
3079 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
3080 return FALSE;
3081 }
3082 }
3083 // Semicolon
3084 if (!wxGetResourceTokenString(s))
3085 {
3086 *eof = TRUE;
3087 }
3088 return TRUE;
3089 }
3090
3091 bool wxResourceParseString(char *s, wxResourceTable *table)
3092 {
3093 if (!table)
3094 table = wxDefaultResourceTable;
3095
3096 if (!s)
3097 return FALSE;
3098
3099 // Turn backslashes into spaces
3100 if (s)
3101 {
3102 int len = strlen(s);
3103 int i;
3104 for (i = 0; i < len; i++)
3105 if (s[i] == 92 && s[i+1] == 13)
3106 {
3107 s[i] = ' ';
3108 s[i+1] = ' ';
3109 }
3110 }
3111
3112 wxExprDatabase db;
3113 wxResourceStringPtr = 0;
3114
3115 bool eof = FALSE;
3116 while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof)
3117 {
3118 // Loop
3119 }
3120 return wxResourceInterpretResources(*table, db);
3121 }
3122
3123 /*
3124 * resource loading facility
3125 */
3126
3127 bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table)
3128 {
3129 if (!table)
3130 table = wxDefaultResourceTable;
3131
3132 wxItemResource *resource = table->FindResource((const wxChar *)resourceName);
3133 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3134 if (!resource || (resource->GetType() == wxT("")) ||
3135 ! ((resource->GetType() == wxT("wxDialog")) || (resource->GetType() == wxT("wxPanel"))))
3136 return FALSE;
3137
3138 wxString title(resource->GetTitle());
3139 long theWindowStyle = resource->GetStyle();
3140 bool isModal = (resource->GetValue1() != 0) ;
3141 int x = resource->GetX();
3142 int y = resource->GetY();
3143 int width = resource->GetWidth();
3144 int height = resource->GetHeight();
3145 wxString name = resource->GetName();
3146
3147 if (IsKindOf(CLASSINFO(wxDialog)))
3148 {
3149 wxDialog *dialogBox = (wxDialog *)this;
3150 long modalStyle = isModal ? wxDIALOG_MODAL : 0;
3151 if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name))
3152 return FALSE;
3153
3154 // Only reset the client size if we know we're not going to do it again below.
3155 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0)
3156 dialogBox->SetClientSize(width, height);
3157 }
3158 else if (IsKindOf(CLASSINFO(wxPanel)))
3159 {
3160 wxPanel* panel = (wxPanel *)this;
3161 if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle | wxTAB_TRAVERSAL, name))
3162 return FALSE;
3163 }
3164 else
3165 {
3166 if (!((wxWindow *)this)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
3167 return FALSE;
3168 }
3169
3170 if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
3171 {
3172 // No need to do this since it's done in wxPanel or wxDialog constructor.
3173 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
3174 }
3175 else
3176 {
3177 if (resource->GetFont().Ok())
3178 SetFont(resource->GetFont());
3179 if (resource->GetBackgroundColour().Ok())
3180 SetBackgroundColour(resource->GetBackgroundColour());
3181 }
3182
3183 // Should have some kind of font at this point
3184 if (!GetFont().Ok())
3185 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
3186 if (!GetBackgroundColour().Ok())
3187 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
3188
3189 // Only when we've created the window and set the font can we set the correct size,
3190 // if based on dialog units.
3191 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
3192 {
3193 wxSize sz = ConvertDialogToPixels(wxSize(width, height));
3194 SetClientSize(sz.x, sz.y);
3195
3196 wxPoint pt = ConvertDialogToPixels(wxPoint(x, y));
3197 Move(pt.x, pt.y);
3198 }
3199
3200 // Now create children
3201 wxNode *node = resource->GetChildren().First();
3202 while (node)
3203 {
3204 wxItemResource *childResource = (wxItemResource *)node->Data();
3205
3206 (void) CreateItem(childResource, resource, table);
3207
3208 node = node->Next();
3209 }
3210 return TRUE;
3211 }
3212
3213 wxControl *wxWindowBase::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table)
3214 {
3215 if (!table)
3216 table = wxDefaultResourceTable;
3217 return table->CreateItem((wxWindow *)this, resource, parentResource);
3218 }
3219
3220 #ifdef __VISUALC__
3221 #pragma warning(default:4706) // assignment within conditional expression
3222 #endif // VC++
3223
3224 #endif
3225 // BC++/Win16
3226
3227 #endif // wxUSE_WX_RESOURCES