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