1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource writing functionality
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
40 #include "wx/scrolbar.h"
41 #include "wx/string.h"
45 char *SafeString(char *s
);
46 char *SafeWord(char *s
);
48 // Save an association between the child resource and the panel item, to allow
49 // us not to require unique window names.
50 wxControl
*wxResourceTableWithSaving::CreateItem(wxPanel
*panel
, wxItemResource
*childResource
)
52 wxControl
*item
= wxResourceTable::CreateItem(panel
, childResource
);
54 wxResourceManager::GetCurrentResourceManager()->GetResourceAssociations().Put((long)childResource
, item
);
58 void wxResourceTableWithSaving::OutputFont(ostream
& stream
, wxFont
*font
)
60 stream
<< "[" << font
->GetPointSize() << ", '";
61 stream
<< font
->GetFamilyString() << "', '";
62 stream
<< font
->GetStyleString() << "', '";
63 stream
<< font
->GetWeightString() << "', ";
64 stream
<< (int)font
->GetUnderlined();
65 if (font
->GetFaceName() != "")
66 stream
<< ", '" << font
->GetFaceName() << "'";
71 * Resource table with saving (basic one only has loading)
74 bool wxResourceTableWithSaving::Save(const wxString
& filename
)
76 ofstream
stream(((wxString
&) filename
).GetData());
84 wxItemResource
*item
= (wxItemResource
*)node
->Data();
85 wxString
resType(item
->GetType());
87 if (resType
== "wxDialogBox" || resType
== "wxDialog" || resType
== "wxPanel" || resType
== "wxBitmap")
89 if (!SaveResource(stream
, item
))
96 bool wxResourceTableWithSaving::SaveResource(ostream
& stream
, wxItemResource
*item
)
99 wxString
itemType(item
->GetType());
101 if (itemType
== "wxDialogBox" || itemType
== "wxDialog" || itemType
== "wxPanel")
103 if (itemType
== "wxDialogBox" || itemType
== "wxDialog")
105 stream
<< "static char *" << item
->GetName() << " = \"dialog(name = '" << item
->GetName() << "',\\\n";
106 GenerateDialogStyleString(item
->GetStyle(), styleBuf
);
110 stream
<< "static char *" << item
->GetName() << " = \"panel(name = '" << item
->GetName() << "',\\\n";
111 GeneratePanelStyleString(item
->GetStyle(), styleBuf
);
113 stream
<< " style = '" << styleBuf
<< "',\\\n";
114 stream
<< " title = '" << item
->GetTitle() << "',\\\n";
115 stream
<< " x = " << item
->GetX() << ", y = " << item
->GetY();
116 stream
<< ", width = " << item
->GetWidth() << ", height = " << item
->GetHeight();
117 // stream << " modal = " << item->GetValue1();
119 if (1) // item->GetStyle() & wxNO_3D)
121 if (item
->GetBackgroundColour())
124 wxDecToHex(item
->GetBackgroundColour()->Red(), buf
);
125 wxDecToHex(item
->GetBackgroundColour()->Green(), buf
+2);
126 wxDecToHex(item
->GetBackgroundColour()->Blue(), buf
+4);
129 stream
<< ",\\\n " << "background_colour = '" << buf
<< "'";
132 if (item
->GetLabelColour())
135 wxDecToHex(item
->GetLabelColour()->Red(), buf
);
136 wxDecToHex(item
->GetLabelColour()->Green(), buf
+2);
137 wxDecToHex(item
->GetLabelColour()->Blue(), buf
+4);
140 stream
<< ",\\\n " << "label_colour = '" << buf
<< "'";
142 if (item
->GetButtonColour())
145 wxDecToHex(item
->GetButtonColour()->Red(), buf
);
146 wxDecToHex(item
->GetButtonColour()->Green(), buf
+2);
147 wxDecToHex(item
->GetButtonColour()->Blue(), buf
+4);
150 stream
<< ",\\\n " << "button_colour = '" << buf
<< "'";
156 if (item
->GetFont() && item
->GetFont()->Ok())
158 stream
<< ",\\\n font = ";
159 OutputFont(stream
, item
->GetFont());
162 if (item
->GetChildren().Number() > 0)
166 wxNode
*node
= item
->GetChildren().First();
169 wxItemResource
*child
= (wxItemResource
*)node
->Data();
171 stream
<< " control = [";
173 SaveResource(stream
, child
);
181 stream
<< ").\";\n\n";
183 else if (itemType
== "wxButton" || itemType
== "wxBitmapButton")
185 GenerateButtonStyleString(item
->GetStyle(), styleBuf
);
186 stream
<< itemType
<< ", " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
187 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
188 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
189 if (item
->GetValue4())
190 stream
<< ", '" << item
->GetValue4() << "'";
194 OutputFont(stream
, item
->GetFont());
197 else if (itemType
== "wxStaticText" || itemType
== "wxStaticBitmap")
199 GenerateMessageStyleString(item
->GetStyle(), styleBuf
);
200 stream
<< itemType
<< ", " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
201 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
202 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
203 if (item
->GetValue4())
204 stream
<< ", '" << item
->GetValue4() << "'";
208 OutputFont(stream
, item
->GetFont());
211 else if (itemType
== "wxCheckBox")
213 GenerateCheckBoxStyleString(item
->GetStyle(), styleBuf
);
214 stream
<< "wxCheckBox, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
215 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
216 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
217 stream
<< ", " << item
->GetValue1();
221 OutputFont(stream
, item
->GetFont());
224 else if (itemType
== "wxRadioButton")
226 GenerateRadioButtonStyleString(item
->GetStyle(), styleBuf
);
227 stream
<< "wxRadioButton, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
228 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
229 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
230 stream
<< ", " << item
->GetValue1();
234 OutputFont(stream
, item
->GetFont());
237 else if (itemType
== "wxStaticBox")
239 GenerateGroupBoxStyleString(item
->GetStyle(), styleBuf
);
240 stream
<< "wxGroupBox, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
241 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
242 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
246 OutputFont(stream
, item
->GetFont());
249 else if (itemType
== "wxText" || itemType
== "wxMultiText" || itemType
== "wxTextCtrl")
251 GenerateTextStyleString(item
->GetStyle(), styleBuf
);
252 stream
<< "wxTextCtrl, ";
253 stream
<< SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
254 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
255 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
256 stream
<< ", " << SafeWord(item
->GetValue4());
260 OutputFont(stream
, item
->GetFont());
263 else if (itemType
== "wxGauge")
265 GenerateGaugeStyleString(item
->GetStyle(), styleBuf
);
266 stream
<< "wxGauge, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
267 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
268 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
269 stream
<< ", " << item
->GetValue1() << ", " << item
->GetValue2();
273 OutputFont(stream
, item
->GetFont());
276 else if (itemType
== "wxSlider")
278 GenerateSliderStyleString(item
->GetStyle(), styleBuf
);
279 stream
<< "wxSlider, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
280 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
281 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
282 stream
<< ", " << item
->GetValue1() << ", " << item
->GetValue2() << ", " << item
->GetValue3();
286 OutputFont(stream
, item
->GetFont());
289 else if (itemType
== "wxScrollBar")
291 GenerateScrollBarStyleString(item
->GetStyle(), styleBuf
);
292 stream
<< "wxScrollBar, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
293 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
294 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
295 stream
<< ", " << item
->GetValue1() << ", " << item
->GetValue2() << ", " << item
->GetValue3() << ", ";
296 stream
<< item
->GetValue5();
298 else if (itemType
== "wxListBox")
300 GenerateListBoxStyleString(item
->GetStyle(), styleBuf
);
301 stream
<< "wxListBox, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
302 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
303 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
305 // Default list of values
308 if (item
->GetStringValues())
310 wxNode
*node
= item
->GetStringValues()->First();
313 char *s
= (char *)node
->Data();
314 stream
<< SafeWord(s
);
321 switch (item
->GetValue1())
325 stream
<< "'wxLB_MULTIPLE'";
330 stream
<< "'wxLB_EXTENDED'";
336 stream
<< "'wxLB_SINGLE'";
343 OutputFont(stream
, item
->GetFont());
346 else if (itemType
== "wxChoice")
348 GenerateChoiceStyleString(item
->GetStyle(), styleBuf
);
349 stream
<< "wxChoice, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
350 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
351 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
353 // Default list of values
356 if (item
->GetStringValues())
358 wxNode
*node
= item
->GetStringValues()->First();
361 char *s
= (char *)node
->Data();
362 stream
<< SafeWord(s
);
372 OutputFont(stream
, item
->GetFont());
375 else if (itemType
== "wxRadioBox")
377 // Must write out the orientation and number of rows/cols!!
378 GenerateRadioBoxStyleString(item
->GetStyle(), styleBuf
);
379 stream
<< "wxRadioBox, " << SafeWord(item
->GetTitle()) << ", '" << styleBuf
<< "', ";
380 stream
<< SafeWord(item
->GetName()) << ", " << item
->GetX() << ", " << item
->GetY() << ", ";
381 stream
<< item
->GetWidth() << ", " << item
->GetHeight();
383 // Default list of values
386 if (item
->GetStringValues())
388 wxNode
*node
= item
->GetStringValues()->First();
391 char *s
= (char *)node
->Data();
392 stream
<< SafeWord(s
);
398 stream
<< "], " << item
->GetValue1();
402 OutputFont(stream
, item
->GetFont());
405 else if (itemType
== "wxBitmap")
407 stream
<< "static char *" << item
->GetName() << " = \"bitmap(name = '" << item
->GetName() << "',\\\n";
409 wxNode
*node
= item
->GetChildren().First();
412 wxItemResource
*child
= (wxItemResource
*)node
->Data();
413 stream
<< " bitmap = [";
416 strcpy(buf
, child
->GetName());
418 wxDos2UnixFilename(buf
);
421 stream
<< "'" << buf
<< "', ";
423 int bitmapType
= (int)child
->GetValue1();
426 case wxBITMAP_TYPE_XBM_DATA
:
428 stream
<< "wxBITMAP_TYPE_XBM_DATA";
431 case wxBITMAP_TYPE_XPM_DATA
:
433 stream
<< "wxBITMAP_TYPE_XPM_DATA";
436 case wxBITMAP_TYPE_XBM
:
438 stream
<< "wxBITMAP_TYPE_XBM";
441 case wxBITMAP_TYPE_XPM
:
443 stream
<< "wxBITMAP_TYPE_XPM";
446 case wxBITMAP_TYPE_BMP
:
448 stream
<< "wxBITMAP_TYPE_BMP";
451 case wxBITMAP_TYPE_BMP_RESOURCE
:
453 stream
<< "wxBITMAP_TYPE_BMP_RESOURCE";
456 case wxBITMAP_TYPE_GIF
:
458 stream
<< "wxBITMAP_TYPE_GIF";
461 case wxBITMAP_TYPE_TIF
:
463 stream
<< "wxBITMAP_TYPE_TIF";
466 case wxBITMAP_TYPE_ICO
:
468 stream
<< "wxBITMAP_TYPE_ICO";
471 case wxBITMAP_TYPE_ICO_RESOURCE
:
473 stream
<< "wxBITMAP_TYPE_ICO_RESOURCE";
476 case wxBITMAP_TYPE_CUR
:
478 stream
<< "wxBITMAP_TYPE_CUR";
481 case wxBITMAP_TYPE_CUR_RESOURCE
:
483 stream
<< "wxBITMAP_TYPE_CUR_RESOURCE";
487 case wxBITMAP_TYPE_ANY
:
489 stream
<< "wxBITMAP_TYPE_ANY";
494 int platform
= child
->GetValue2();
497 case RESOURCE_PLATFORM_WINDOWS
:
499 stream
<< "'WINDOWS'";
502 case RESOURCE_PLATFORM_X
:
507 case RESOURCE_PLATFORM_MAC
:
512 case RESOURCE_PLATFORM_ANY
:
518 int noColours
= (int)child
->GetValue3();
520 stream
<< ", " << noColours
;
529 stream
<< ").\";\n\n";
534 void wxResourceTableWithSaving::GenerateWindowStyleString(long windowStyle
, char *buf
)
536 GenerateStyle(buf
, windowStyle
, wxNO_3D
, "wxNO_3D");
537 GenerateStyle(buf
, windowStyle
, wxVSCROLL
, "wxVSCROLL");
538 GenerateStyle(buf
, windowStyle
, wxHSCROLL
, "wxHSCROLL");
539 GenerateStyle(buf
, windowStyle
, wxBORDER
, "wxBORDER");
542 void wxResourceTableWithSaving::GenerateDialogStyleString(long windowStyle
, char *buf
)
545 GenerateWindowStyleString(windowStyle
, buf
);
548 GenerateStyle(buf, windowStyle, wxRETAINED, "wxRETAINED");
550 if (!GenerateStyle(buf
, windowStyle
, wxDEFAULT_DIALOG_STYLE
, "wxDEFAULT_DIALOG_STYLE"))
552 GenerateStyle(buf
, windowStyle
, wxCAPTION
, "wxCAPTION");
553 GenerateStyle(buf
, windowStyle
, wxTHICK_FRAME
, "wxTHICK_FRAME");
554 GenerateStyle(buf
, windowStyle
, wxRESIZE_BORDER
, "wxRESIZE_BORDER");
555 GenerateStyle(buf
, windowStyle
, wxSYSTEM_MENU
, "wxSYSTEM_MENU");
556 GenerateStyle(buf
, windowStyle
, wxMINIMIZE_BOX
, "wxMINIMIZE_BOX");
557 GenerateStyle(buf
, windowStyle
, wxMAXIMIZE_BOX
, "wxMAXIMIZE_BOX");
559 if (strlen(buf
) == 0)
563 void wxResourceTableWithSaving::GeneratePanelStyleString(long windowStyle
, char *buf
)
566 GenerateWindowStyleString(windowStyle
, buf
);
569 GenerateStyle(buf, windowStyle, wxRETAINED, "wxRETAINED");
571 if (strlen(buf
) == 0)
576 void wxResourceTableWithSaving::GenerateItemStyleString(long windowStyle
, char *buf
)
578 GenerateWindowStyleString(windowStyle
, buf
);
580 GenerateStyle(buf
, windowStyle
, wxHORIZONTAL
, "wxHORIZONTAL");
581 GenerateStyle(buf
, windowStyle
, wxVERTICAL
, "wxVERTICAL");
584 void wxResourceTableWithSaving::GenerateRadioBoxStyleString(long windowStyle
, char *buf
)
587 GenerateItemStyleString(windowStyle
, buf
);
589 if (strlen(buf
) == 0)
593 void wxResourceTableWithSaving::GenerateMessageStyleString(long windowStyle
, char *buf
)
596 GenerateItemStyleString(windowStyle
, buf
);
598 if (strlen(buf
) == 0)
602 void wxResourceTableWithSaving::GenerateTextStyleString(long windowStyle
, char *buf
)
605 GenerateItemStyleString(windowStyle
, buf
);
607 GenerateStyle(buf
, windowStyle
, wxTE_PROCESS_ENTER
, "wxTE_PROCESS_ENTER");
608 GenerateStyle(buf
, windowStyle
, wxTE_READONLY
, "wxTE_READONLY");
609 GenerateStyle(buf
, windowStyle
, wxTE_PASSWORD
, "wxTE_PASSWORD");
610 GenerateStyle(buf
, windowStyle
, wxTE_MULTILINE
, "wxTE_MULTILINE");
612 if (strlen(buf
) == 0)
616 void wxResourceTableWithSaving::GenerateButtonStyleString(long windowStyle
, char *buf
)
619 GenerateItemStyleString(windowStyle
, buf
);
621 if (strlen(buf
) == 0)
625 void wxResourceTableWithSaving::GenerateCheckBoxStyleString(long windowStyle
, char *buf
)
628 GenerateItemStyleString(windowStyle
, buf
);
630 if (strlen(buf
) == 0)
634 void wxResourceTableWithSaving::GenerateRadioButtonStyleString(long windowStyle
, char *buf
)
637 GenerateItemStyleString(windowStyle
, buf
);
639 if (strlen(buf
) == 0)
643 void wxResourceTableWithSaving::GenerateListBoxStyleString(long windowStyle
, char *buf
)
646 GenerateItemStyleString(windowStyle
, buf
);
648 GenerateStyle(buf
, windowStyle
, wxLB_ALWAYS_SB
, "wxLB_ALWAYS_SB");
649 GenerateStyle(buf
, windowStyle
, wxLB_SORT
, "wxLB_SORT");
650 // GenerateStyle(buf, windowStyle, wxLB_SINGLE, "wxLB_SINGLE"); // Done already
651 GenerateStyle(buf
, windowStyle
, wxLB_MULTIPLE
, "wxLB_MULTIPLE");
652 GenerateStyle(buf
, windowStyle
, wxLB_EXTENDED
, "wxLB_EXTENDED");
654 if (strlen(buf
) == 0)
658 void wxResourceTableWithSaving::GenerateSliderStyleString(long windowStyle
, char *buf
)
661 GenerateItemStyleString(windowStyle
, buf
);
663 if (strlen(buf
) == 0)
667 void wxResourceTableWithSaving::GenerateGroupBoxStyleString(long windowStyle
, char *buf
)
670 GenerateItemStyleString(windowStyle
, buf
);
672 if (strlen(buf
) == 0)
676 void wxResourceTableWithSaving::GenerateGaugeStyleString(long windowStyle
, char *buf
)
679 GenerateItemStyleString(windowStyle
, buf
);
681 GenerateStyle(buf
, windowStyle
, wxGA_PROGRESSBAR
, "wxGA_PROGRESSBAR");
683 if (strlen(buf
) == 0)
687 void wxResourceTableWithSaving::GenerateChoiceStyleString(long windowStyle
, char *buf
)
690 GenerateItemStyleString(windowStyle
, buf
);
692 if (strlen(buf
) == 0)
696 void wxResourceTableWithSaving::GenerateScrollBarStyleString(long windowStyle
, char *buf
)
699 GenerateItemStyleString(windowStyle
, buf
);
701 if (strlen(buf
) == 0)
705 bool wxResourceTableWithSaving::GenerateStyle(char *buf
, long windowStyle
, long flag
, char *strStyle
)
707 if ((windowStyle
& flag
) == flag
)
711 strcat(buf
, strStyle
);
718 // Returns quoted string or "NULL"
719 char *SafeString(char *s
)
725 strcpy(wxBuffer
, "\"");
727 strcat(wxBuffer
, "\"");
732 // Returns quoted string or ''
733 char *SafeWord(char *s
)
739 strcpy(wxBuffer
, "'");
741 strcat(wxBuffer
, "'");