4 * Resource compiler unix code generator
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.13 1998/12/21 08:02:14 robertj
31 * New directory structure
33 * Revision 1.12 1998/10/16 13:56:58 robertj
34 * Changed resource output files to be the same as for Windows.
35 * Removed warning on unused parameter.
37 * Revision 1.11 1998/09/26 01:24:21 robertj
38 * Added open source license
40 * Revision 1.10 1998/09/26 00:41:29 robertj
41 * Fixed name space conflict with type Cursor.
42 * Fixed innumerable scoping problems in for loops.
43 * Fixed triadic operator type mismatch problem.
45 * Revision 1.9 1996/04/19 13:24:07 craigs
46 * Version before big cleanup
48 * Revision 1.8 1995/08/24 12:53:58 robertj
49 * Added general control type for arbitrary dialog controls.
50 * Added output file extension variable.
52 * Revision 1.2 1995/08/04 06:23:12 robertj
53 * *** empty log message ***
55 * Revision 1.6 1994/12/31 23:27:15 robertj
58 * Revision 1.5 1994/12/05 11:35:31 robertj
61 // Revision 1.1 1993/06/24 19:23:17 craigs
66 #pragma implementation "pwrc.h"
67 #pragma implementation "keycode.h"
74 #include "pwlib/stdresid.h"
78 PString
OutputExtension(".res.cxx");
79 PString
CxxExtension(".cxx");
81 static PString Indent
;
83 static BOOL hack_dialog_initialiser_flag
;
84 static int hack_dialog_id
= -1;
86 static BOOL hack_accel_flag
;
88 static const PString NullString
= "NULL";
89 #define OUTPUTSTRING(s) ((s).IsEmpty() ? NullString : (s))
92 ///////////////////////////////////////////////////////////////
94 // StringDict::PrintOn
97 void StringDict::PrintOn(ostream
& out
) const
99 out
<< "\n\n//\n// String Resources\n//\n\n"
100 << "static PXResource StringResources[] = {\n";
103 for (i
= 0; i
< GetSize(); i
++) {
104 int id
= GetDataAt (i
).GetID();
108 << GetDataAt (i
).GetLiteralText()
112 out
<< " { -1, NULL }\n};\n";
116 ///////////////////////////////////////////////////////////////
122 void MenuItem::PrintOn(ostream
& out
) const
125 if (!hack_accel_flag
)
126 out
<< Indent
<< "{ "
127 << "PXMenuResource::Item, "
134 for (i
= 0; i
< accel
.GetSize(); i
++)
137 << ", (PKeyCode::Value)"
138 << accel
[i
].GetValue()
140 << accel
[i
].GetModifiers()
146 ///////////////////////////////////////////////////////////////
148 // Separator::PrintOn
151 void Separator::PrintOn(ostream
& out
) const
154 if (!hack_accel_flag
)
155 out
<< Indent
<< "{ PXMenuResource::Separator },\n";
159 ///////////////////////////////////////////////////////////////
164 void Menu::PrintOn(ostream
& out
) const
169 if (!hack_accel_flag
)
170 out
<< Indent
<< "{ PXMenuResource::SubMenu, " << textLiteral
<< " },\n";
177 for (i
= 0; i
< items
.GetSize(); i
++)
180 Indent
= Indent
.Left(Indent
.GetLength()-2);
183 // output end of menu
185 if (!hack_accel_flag
)
186 out
<< Indent
<< "{ PXMenuResource::EndMenu },\n";
190 ///////////////////////////////////////////////////////////////
195 void MenuBar::PrintOn(ostream
& out
) const
199 // output header for menubar
201 if (!hack_accel_flag
)
202 out
<< "\n\nstatic PXMenuResource PXMenuBar" << id
<< "[] = {\n"
203 << " { PXMenuResource::MenuBar },\n";
205 out
<< "\n\nstatic PXAcceleratorResource PXAccel" << id
<< "[] = {\n";
210 // output data for menubar
213 for (i
= 0; i
< menus
.GetSize(); i
++)
217 // output trailer for menubar
219 if (!hack_accel_flag
)
220 out
<< "\n { PXMenuResource::EndBar }\n};\n\n";
222 out
<< " { -1, (PKeyCode::Value)0, 0 }\n};\n\n";
226 ///////////////////////////////////////////////////////////////
228 // MenubarDict::PrintOn
231 void MenubarDict::PrintOn(ostream
& out
) const
234 if (!hack_accel_flag
)
235 out
<< "\n\n//\n// Menubar resources\n//";
237 out
<< "\n\n//\n// Accelerator resources\n//";
239 // output each of the menubars
241 for (i
= 0; i
< GetSize(); i
++)
242 out
<< GetDataAt (i
);
244 if (!hack_accel_flag
) {
245 // output list of menubars
246 out
<< "\n\nstatic PXResource MenuBarResources[] = {\n";
247 for (i
= 0; i
< GetSize(); i
++) {
248 int id
= GetDataAt (i
).GetID();
249 out
<< " { " << id
<< ", &PXMenuBar" << id
<< " },\n";
252 // output list of accelerators
253 out
<< "\n\nstatic PXResource AcceleratorResources[] = {\n";
254 for (i
= 0; i
< GetSize(); i
++) {
255 int id
= GetDataAt (i
).GetID();
256 out
<< " { " << id
<< ", &PXAccel" << id
<< " },\n";
259 out
<< " { -1, NULL }\n};\n";
263 ///////////////////////////////////////////////////////////////
265 // output routines for various control types
268 void Point::PrintOn(ostream
& out
) const
270 out
<< ", " << x
<< ',' << y
;
274 void Control::PrintOn(ostream
& out
) const
276 out
<< pos
<< dim
<< ", "
277 << OUTPUTSTRING(textLiteral
)
279 << OUTPUTSTRING(balloonHelp
)
284 void PushButton::PrintOn(ostream
& out
) const
286 if (hack_dialog_initialiser_flag
)
289 out
<< " { PXDialogResource::PushButton";
290 Control::PrintOn(out
);
291 out
<< ", 0x" << setbase(16) << options
<< setbase(10);
296 ostream
& DefPushButton::PrintOn(ostream
& out
) const
298 if (hack_dialog_initialiser_flag
)
301 out
<< " { PXDialogResource::DefPushButton";
302 Control::PrintOn(out
);
308 void CheckBox::PrintOn(ostream
& out
) const
310 if (hack_dialog_initialiser_flag
)
313 out
<< " { PXDialogResource::CheckBox";
314 Control::PrintOn(out
);
319 void Check3Way::PrintOn(ostream
& out
) const
321 if (hack_dialog_initialiser_flag
)
324 out
<< " { PXDialogResource::Check3Way";
325 Control::PrintOn(out
);
330 void RadioButton::PrintOn(ostream
& out
) const
332 if (hack_dialog_initialiser_flag
)
335 out
<< " { PXDialogResource::RadioButton";
336 Control::PrintOn(out
);
341 void LeftText::PrintOn(ostream
& out
) const
343 if (hack_dialog_initialiser_flag
)
346 out
<< " { PXDialogResource::LeftText";
347 Control::PrintOn(out
);
352 void CentreText::PrintOn(ostream
& out
) const
354 if (hack_dialog_initialiser_flag
)
357 out
<< " { PXDialogResource::CentreText";
358 Control::PrintOn(out
);
363 void RightText::PrintOn(ostream
& out
) const
365 if (hack_dialog_initialiser_flag
)
368 out
<< " { PXDialogResource::RightText";
369 Control::PrintOn(out
);
374 void StaticBox::PrintOn(ostream
& out
) const
376 if (hack_dialog_initialiser_flag
)
379 out
<< " { PXDialogResource::StaticBox";
380 Control::PrintOn(out
);
385 void EditBox::PrintOn(ostream
& out
) const
387 if (hack_dialog_initialiser_flag
)
390 out
<< " { PXDialogResource::EditBox";
391 Control::PrintOn(out
);
395 void Password::PrintOn(ostream
& out
) const
397 if (hack_dialog_initialiser_flag
)
400 out
<< " { PXDialogResource::Password";
401 Control::PrintOn(out
);
406 void IntEditBox::PrintOn(ostream
& out
) const
408 if (hack_dialog_initialiser_flag
)
411 out
<< " { PXDialogResource::IntEditBox";
412 Control::PrintOn(out
);
417 void FloatEditBox::PrintOn(ostream
& out
) const
419 if (hack_dialog_initialiser_flag
)
422 out
<< " { PXDialogResource::FloatEditBox";
423 Control::PrintOn(out
);
428 void TextEditor::PrintOn(ostream
& out
) const
430 if (hack_dialog_initialiser_flag
)
433 out
<< " { PXDialogResource::TextEditor";
434 Control::PrintOn(out
);
438 void ListControl::PrintOn(ostream
&) const
442 static void PrintStringList (ostream
& out
, const PString
& name
, const PStringList
& strList
)
445 if (strList
.GetSize() == 0)
447 out
<< "static char *"
451 for (i
= 0; i
< strList
.GetSize(); i
++)
452 out
<< " " << strList
[i
] << ",\n";
457 void ChoiceBox::PrintOn(ostream
& out
) const
459 if (hack_dialog_initialiser_flag
) {
460 if (strList
.GetSize() == 0)
463 << "// Initialiser list for choice box in dialog " << hack_dialog_id
<< "\n"
466 sprintf(buff
, "%i_%i", hack_dialog_id
, id
);
468 PString("ChoiceBoxInit_") + buff
,
473 out
<< " { PXDialogResource::ChoiceBox";
474 Control::PrintOn(out
);
475 out
<< ", 0x" << setbase(16) << options
<< setbase(10);
476 if (strList
.GetSize() != 0)
477 out
<< ", ChoiceBoxInit_" << hack_dialog_id
<< "_" << id
;
481 void ListBox::PrintOn(ostream
& out
) const
483 if (hack_dialog_initialiser_flag
) {
484 if (strList
.GetSize() == 0)
487 << "// Initialiser list for listbox " << id
<< " in dialog " << hack_dialog_id
<< "\n"
490 sprintf(buff
, "%i_%i", hack_dialog_id
, id
);
492 PString("ListBoxInit_") + buff
,
497 out
<< " { PXDialogResource::ListBox";
498 out
<< pos
<< dim
<< ", NULL, NULL, " << id
;
499 out
<< ", 0x" << setbase(16) << options
<< setbase(10);
500 if (strList
.GetSize() != 0)
501 out
<< ", ListBoxInit_" << hack_dialog_id
<< "_" << id
;
506 void ComboBox::PrintOn(ostream
& out
) const
508 if (hack_dialog_initialiser_flag
) {
509 if (strList
.GetSize() == 0)
512 << "// Initialiser list for combo box in dialog " << hack_dialog_id
<< "\n"
515 sprintf(buff
, "%i_%i", hack_dialog_id
, id
);
517 PString("ComboBoxInit_") + buff
,
522 out
<< " { PXDialogResource::ComboBox";
523 Control::PrintOn(out
);
524 out
<< ", 0x" << setbase(16) << options
<< setbase(10);
525 if (strList
.GetSize() != 0)
526 out
<< ", ComboBoxInit_" << hack_dialog_id
<< "_" << id
;
531 void HScrollBar::PrintOn(ostream
& out
) const
533 if (hack_dialog_initialiser_flag
)
536 out
<< " { PXDialogResource::HScrollBar";
537 // Control::PrintOn(out);
539 out
<< pos
<< dim
<< ", "
541 << minimum
<< " " << maximum
<< " " << smallNudge
<< " " << largeNudge
544 << OUTPUTSTRING(balloonHelp
)
551 void VScrollBar::PrintOn(ostream
& out
) const
553 if (hack_dialog_initialiser_flag
)
556 out
<< " { PXDialogResource::VScrollBar";
557 // Control::PrintOn(out);
559 out
<< pos
<< dim
<< ", "
561 << minimum
<< " " << maximum
<< " " << smallNudge
<< " " << largeNudge
564 << OUTPUTSTRING(balloonHelp
)
572 void StaticIcon::PrintOn(ostream
& out
) const
574 if (hack_dialog_initialiser_flag
)
577 out
<< " { PXDialogResource::StaticIcon";
578 Control::PrintOn(out
);
579 out
<< ", " << iconID
<< " },\n";
582 void UserControl::PrintOn(ostream
& out
) const
584 if (hack_dialog_initialiser_flag
)
587 out
<< " { PXDialogResource::UserControl";
588 Control::PrintOn(out
);
592 ///////////////////////////////////////////////////////////////
597 void Layout::PrintOn(ostream
& out
) const
600 // set special hack flag to output list box initialisers
603 hack_dialog_initialiser_flag
= TRUE
;
607 for (i
= 0; i
< itemList
.GetSize(); i
++)
610 hack_dialog_initialiser_flag
= FALSE
;
612 out
<< "\n\nstatic PXDialogResource PXDialog" << id
<< "[] = {\n"
613 << " { PXDialogResource::DialogFrame, "
614 << pos
.X() << ", " << pos
.Y() << ", "
615 << dim
.X() << ", " << dim
.Y() << ", "
616 << OUTPUTSTRING(textLiteral
) << ", "
620 << OUTPUTSTRING(fontName
) << " },\n";
622 for (i
= 0; i
< itemList
.GetSize(); i
++)
625 out
<< " { PXDialogResource::EndItems }\n};\n";
628 ///////////////////////////////////////////////////////////////
630 // DialogDict::PrintOn
633 void DialogDict::PrintOn(ostream
& out
) const
636 out
<< "\n\n//\n// Dialog Resources\n//";
638 // output each of the dialogs
640 for (i
= 0; i
< GetSize(); i
++)
641 out
<< GetDataAt (i
);
643 // output list of dialogs
644 out
<< "\n\nstatic PXResource DialogResources[] = {\n";
645 for (i
= 0; i
< GetSize(); i
++) {
646 int id
= GetDataAt (i
).GetID();
647 out
<< " { " << id
<< ", &PXDialog" << id
<< "},\n";
650 out
<< " { -1, NULL }\n};\n";
654 ///////////////////////////////////////////////////////////////
656 // BinaryData::PrintOn
659 void BinaryData::PrintOn(ostream
& out
) const
661 out
<< " \"" << setbase(16) << setfill('0');
663 for (i
= 0; i
< GetSize(); i
++) {
664 out
<< "\\x" << setw(2) << (theArray
[i
]&0xff);
665 if (i
!= GetSize()-1 && (i
%10) == 9)
668 out
<< setfill(' ') << setbase(10) << '"';
672 ///////////////////////////////////////////////////////////////
677 void PixData::PrintOn(ostream
& out
) const
679 out
<< " \"" << setbase(16) << setfill('0');
681 for (i
= 0; i
< GetSize(); i
++) {
682 out
<< "\\x" << setw(2) << (theArray
[i
]&0xff);
683 if (i
!= GetSize()-1 && (i
%10) == 9)
686 out
<< setfill(' ') << setbase(10) << '"';
690 ///////////////////////////////////////////////////////////////
692 // PixelContents::PrintOn
695 void PixelContents::PrintOn(ostream
& out
) const
713 out
<< " // Pixels\n"
719 out
<< " // AndMask\n"
725 out
<< " // XorMask\n"
731 out
<< " // HotSpot\n"
739 ///////////////////////////////////////////////////////////////
744 void Icon::PrintOn(ostream
& out
) const
746 out
<< "\n\nstatic PXPixelResource PXIcon"
754 ///////////////////////////////////////////////////////////////
759 void IconDict::PrintOn(ostream
& out
) const
761 out
<< "\n\n//\n// Icon Resources\n//\n";
763 // output each of the icons
765 for (i
= 0; i
< GetSize(); i
++)
766 out
<< GetDataAt (i
);
768 // output list of icons
769 out
<< "\n\nstatic PXResource IconResources[] = {\n";
770 for (i
= 0; i
< GetSize(); i
++) {
771 int id
= GetDataAt (i
).GetID();
772 out
<< " { " << id
<< ", &PXIcon" << id
<< "},\n";
775 out
<< " { -1, NULL }\n};\n";
779 ///////////////////////////////////////////////////////////////
781 // CursorResource::PrintOn
784 void CursorResource::PrintOn(ostream
& out
) const
786 out
<< "\n\nstatic PXPixelResource PXCursor"
787 << id
<< " = {\n" << contents
<< "};\n";
791 ///////////////////////////////////////////////////////////////
793 // CursorDict::PrintOn
796 void CursorDict::PrintOn(ostream
& out
) const
798 out
<< "\n\n//\n// Cursor Resources\n//\n";
800 // output each of the cursors
802 for (i
= 0; i
< GetSize(); i
++)
803 out
<< GetDataAt (i
);
805 // output list of cursors
806 out
<< "\n\nstatic PXResource CursorResources[] = {\n";
807 for (i
= 0; i
< GetSize(); i
++) {
808 int id
= GetDataAt (i
).GetID();
809 out
<< " { " << id
<< ", &PXCursor" << id
<< "},\n";
812 out
<< " { -1, NULL }\n};\n";
816 ///////////////////////////////////////////////////////////////
821 void Image::PrintOn(ostream
& out
) const
823 out
<< "\n\nstatic PXPixelResource PXImage"
830 ///////////////////////////////////////////////////////////////
832 // ImageDict::PrintOn
835 void ImageDict::PrintOn(ostream
& out
) const
837 out
<< "\n\n//\n// Image Resources\n//\n";
839 // output each of the images
841 for (i
= 0; i
< GetSize(); i
++)
842 out
<< GetDataAt (i
);
844 // output list of image
845 out
<< "\n\nstatic PXResource ImageResources[] = {\n";
846 for (i
= 0; i
< GetSize(); i
++) {
847 int id
= GetDataAt (i
).GetID();
848 out
<< " {" << id
<< ", &PXImage" << id
<< "},\n";
851 out
<< " { -1, NULL }\n};\n";
855 ///////////////////////////////////////////////////////////////
860 void Pattern::PrintOn(ostream
& out
) const
862 out
<< "\n\n//\n// Pattern Resources\n//\n";
863 // << "\n\nstatic PXPixelResource PXImage"
864 // << id << " = {\n "
870 ///////////////////////////////////////////////////////////////
872 // PatternDict::PrintOn
875 void PatternDict::PrintOn(ostream
& out
) const
877 out
<< "\n\n//\n// Image Resources\n//\n";
879 // // output each of the images
880 // for (PINDEX i = 0; i < GetSize(); i++)
881 // out << GetDataAt (i);
883 // // output list of image
884 // out << "\n\nstatic PXResource ImageResources[] = {\n";
885 // for (i = 0; i < GetSize(); i++) {
886 // int id = GetDataAt (i).GetID();
887 // out << " {" << id << ", &PXImage" << id << "},\n";
890 // out << " { -1, NULL }\n};\n";
893 ///////////////////////////////////////////////////////////////
895 // DataResource::PrintOn
898 void DataResource::PrintOn(ostream
& out
) const
900 static const PString DataString
= "\"DATA\"";
901 out
<< (textConverted
.IsEmpty() ? DataString
: textLiteral
)
908 ///////////////////////////////////////////////////////////////
913 void DataDict::PrintOn(ostream
& out
) const
916 // output each data resource as a static constant array
919 for (i
= 0; i
< GetSize(); i
++) {
920 int id
= GetDataAt (i
).GetID();
921 out
<< "static PXDataResource DataResource"
928 out
<< "\n\n//\n// Arbitrary Data Resources\n//\n"
929 "\n\nstatic PXResource DataResources[] = {\n";
931 for (i
= 0; i
< GetSize(); i
++) {
932 out
<< " { " << (int)GetKeyAt(i
) << ", &DataResource" << (int) GetKeyAt (i
) << "},\n";
935 out
<< " { -1, NULL }\n};\n";
939 ///////////////////////////////////////////////////////////////
944 void ResourceFile::Backend(PFile
& out
)
946 hack_accel_flag
= FALSE
;
948 out
<< "//\n// Resource file generated by Unix PWRC\n//\n\n"
949 "#include <pwlib.h>\n\n"
958 hack_accel_flag
= TRUE
;
962 << "#ifndef PRESOURCESETNAME\n"
963 << "#define PRESOURCESETNAME PXApplicationResources\n"
966 out
<< "\n//\n// list of resources for this program\n//\n\n"
967 << "PXResourceSet PRESOURCESETNAME = { {\n"
968 << " StringResources,\n"
969 << " MenuBarResources,\n"
970 << " DialogResources,\n"
971 << " IconResources,\n"
972 << " CursorResources,\n"
973 << " ImageResources,\n"
974 << " DataResources,\n"
975 << " AcceleratorResources\n"
980 ///////////////////////////////////////////////////////////////
985 void Decompile(PFile
&, PTextFile
&)
987 cerr
<< "The decompile facility is not available on Unix(tm) platforms.\n";