Moved to configure.ac
[pwlib.git] / tools / pwrc / unix.cxx
blob2763d5134751d67c77f639748c3ffb69c9f4abcd
1 /*
2 * unix.cxx
3 *
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
18 * under the License.
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): ______________________________________.
29 * $Log$
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
56 * Many changes
58 * Revision 1.5 1994/12/05 11:35:31 robertj
59 * Update.
61 // Revision 1.1 1993/06/24 19:23:17 craigs
62 // Initial revision
63 //
64 */
66 #pragma implementation "pwrc.h"
67 #pragma implementation "keycode.h"
69 #include <fstream.h>
71 #include "ptlib.h"
73 #include "pwrc.h"
74 #include "pwlib/stdresid.h"
76 #include <iomanip.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 ///////////////////////////////////////////////////////////////
93 //
94 // StringDict::PrintOn
95 //
97 void StringDict::PrintOn(ostream & out) const
99 out << "\n\n//\n// String Resources\n//\n\n"
100 << "static PXResource StringResources[] = {\n";
102 PINDEX i;
103 for (i = 0; i < GetSize(); i++) {
104 int id = GetDataAt (i).GetID();
105 out << " { "
106 << id
107 << ", "
108 << GetDataAt (i).GetLiteralText()
109 << " },\n";
112 out << " { -1, NULL }\n};\n";
116 ///////////////////////////////////////////////////////////////
118 // MenuItem::PrintOn
122 void MenuItem::PrintOn(ostream & out) const
125 if (!hack_accel_flag)
126 out << Indent << "{ "
127 << "PXMenuResource::Item, "
128 << textLiteral
129 << ", "
130 << id
131 << " },\n";
132 else {
133 PINDEX i;
134 for (i = 0; i < accel.GetSize(); i++)
135 out << " { "
136 << id
137 << ", (PKeyCode::Value)"
138 << accel[i].GetValue()
139 << ", "
140 << accel[i].GetModifiers()
141 << "},\n";
146 ///////////////////////////////////////////////////////////////
148 // Separator::PrintOn
151 void Separator::PrintOn(ostream & out) const
154 if (!hack_accel_flag)
155 out << Indent << "{ PXMenuResource::Separator },\n";
159 ///////////////////////////////////////////////////////////////
161 // Menu::PrintOn
164 void Menu::PrintOn(ostream & out) const
167 PINDEX i;
169 if (!hack_accel_flag)
170 out << Indent << "{ PXMenuResource::SubMenu, " << textLiteral << " },\n";
172 Indent += " ";
175 // output items
177 for (i = 0; i < items.GetSize(); i++)
178 out << items [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 ///////////////////////////////////////////////////////////////
192 // Menubar::PrintOn
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";
204 else
205 out << "\n\nstatic PXAcceleratorResource PXAccel" << id << "[] = {\n";
207 Indent = " ";
210 // output data for menubar
212 PINDEX i;
213 for (i = 0; i < menus.GetSize(); i++)
214 out << menus [i];
217 // output trailer for menubar
219 if (!hack_accel_flag)
220 out << "\n { PXMenuResource::EndBar }\n};\n\n";
221 else
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//";
236 else
237 out << "\n\n//\n// Accelerator resources\n//";
239 // output each of the menubars
240 PINDEX i;
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";
251 } else {
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)
278 << ", "
279 << OUTPUTSTRING(balloonHelp)
280 << ", " << id;
284 void PushButton::PrintOn(ostream & out) const
286 if (hack_dialog_initialiser_flag)
287 return;
289 out << " { PXDialogResource::PushButton";
290 Control::PrintOn(out);
291 out << ", 0x" << setbase(16) << options << setbase(10);
292 out << " },\n";
295 #if 0
296 ostream & DefPushButton::PrintOn(ostream & out) const
298 if (hack_dialog_initialiser_flag)
299 return;
301 out << " { PXDialogResource::DefPushButton";
302 Control::PrintOn(out);
303 out << " },\n";
305 #endif
308 void CheckBox::PrintOn(ostream & out) const
310 if (hack_dialog_initialiser_flag)
311 return;
313 out << " { PXDialogResource::CheckBox";
314 Control::PrintOn(out);
315 out << " },\n";
319 void Check3Way::PrintOn(ostream & out) const
321 if (hack_dialog_initialiser_flag)
322 return;
324 out << " { PXDialogResource::Check3Way";
325 Control::PrintOn(out);
326 out << " },\n";
330 void RadioButton::PrintOn(ostream & out) const
332 if (hack_dialog_initialiser_flag)
333 return;
335 out << " { PXDialogResource::RadioButton";
336 Control::PrintOn(out);
337 out << " },\n";
341 void LeftText::PrintOn(ostream & out) const
343 if (hack_dialog_initialiser_flag)
344 return;
346 out << " { PXDialogResource::LeftText";
347 Control::PrintOn(out);
348 out << " },\n";
352 void CentreText::PrintOn(ostream & out) const
354 if (hack_dialog_initialiser_flag)
355 return;
357 out << " { PXDialogResource::CentreText";
358 Control::PrintOn(out);
359 out << " },\n";
363 void RightText::PrintOn(ostream & out) const
365 if (hack_dialog_initialiser_flag)
366 return;
368 out << " { PXDialogResource::RightText";
369 Control::PrintOn(out);
370 out << " },\n";
374 void StaticBox::PrintOn(ostream & out) const
376 if (hack_dialog_initialiser_flag)
377 return;
379 out << " { PXDialogResource::StaticBox";
380 Control::PrintOn(out);
381 out << " },\n";
385 void EditBox::PrintOn(ostream & out) const
387 if (hack_dialog_initialiser_flag)
388 return;
390 out << " { PXDialogResource::EditBox";
391 Control::PrintOn(out);
392 out << " },\n";
395 void Password::PrintOn(ostream & out) const
397 if (hack_dialog_initialiser_flag)
398 return;
400 out << " { PXDialogResource::Password";
401 Control::PrintOn(out);
402 out << " },\n";
406 void IntEditBox::PrintOn(ostream & out) const
408 if (hack_dialog_initialiser_flag)
409 return;
411 out << " { PXDialogResource::IntEditBox";
412 Control::PrintOn(out);
413 out << " },\n";
417 void FloatEditBox::PrintOn(ostream & out) const
419 if (hack_dialog_initialiser_flag)
420 return;
422 out << " { PXDialogResource::FloatEditBox";
423 Control::PrintOn(out);
424 out << " },\n";
428 void TextEditor::PrintOn(ostream & out) const
430 if (hack_dialog_initialiser_flag)
431 return;
433 out << " { PXDialogResource::TextEditor";
434 Control::PrintOn(out);
435 out << " },\n";
438 void ListControl::PrintOn(ostream &) const
442 static void PrintStringList (ostream & out, const PString & name, const PStringList & strList)
445 if (strList.GetSize() == 0)
446 return;
447 out << "static char *"
448 << name
449 << "[] = {\n";
450 PINDEX i;
451 for (i = 0; i < strList.GetSize(); i++)
452 out << " " << strList[i] << ",\n";
453 out << " NULL };\n";
457 void ChoiceBox::PrintOn(ostream & out) const
459 if (hack_dialog_initialiser_flag) {
460 if (strList.GetSize() == 0)
461 return;
462 out << "\n\n//\n"
463 << "// Initialiser list for choice box in dialog " << hack_dialog_id << "\n"
464 << "//\n\n";
465 char buff[20];
466 sprintf(buff, "%i_%i", hack_dialog_id, id);
467 PrintStringList(out,
468 PString("ChoiceBoxInit_") + buff,
469 strList);
470 return;
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;
478 out << " },\n";
481 void ListBox::PrintOn(ostream & out) const
483 if (hack_dialog_initialiser_flag) {
484 if (strList.GetSize() == 0)
485 return;
486 out << "\n\n//\n"
487 << "// Initialiser list for listbox " << id << " in dialog " << hack_dialog_id << "\n"
488 << "//\n\n";
489 char buff[20];
490 sprintf(buff, "%i_%i", hack_dialog_id, id);
491 PrintStringList(out,
492 PString("ListBoxInit_") + buff,
493 strList);
494 return;
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;
502 out << " },\n";
506 void ComboBox::PrintOn(ostream & out) const
508 if (hack_dialog_initialiser_flag) {
509 if (strList.GetSize() == 0)
510 return;
511 out << "\n\n//\n"
512 << "// Initialiser list for combo box in dialog " << hack_dialog_id << "\n"
513 << "//\n\n";
514 char buff[20];
515 sprintf(buff, "%i_%i", hack_dialog_id, id);
516 PrintStringList(out,
517 PString("ComboBoxInit_") + buff,
518 strList);
519 return;
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;
527 out << " },\n";
531 void HScrollBar::PrintOn(ostream & out) const
533 if (hack_dialog_initialiser_flag)
534 return;
536 out << " { PXDialogResource::HScrollBar";
537 // Control::PrintOn(out);
539 out << pos << dim << ", "
540 << "\""
541 << minimum << " " << maximum << " " << smallNudge << " " << largeNudge
542 << "\""
543 << ", "
544 << OUTPUTSTRING(balloonHelp)
545 << ", " << id;
547 out << " },\n";
551 void VScrollBar::PrintOn(ostream & out) const
553 if (hack_dialog_initialiser_flag)
554 return;
556 out << " { PXDialogResource::VScrollBar";
557 // Control::PrintOn(out);
559 out << pos << dim << ", "
560 << "\""
561 << minimum << " " << maximum << " " << smallNudge << " " << largeNudge
562 << "\""
563 << ", "
564 << OUTPUTSTRING(balloonHelp)
565 << ", "
566 << id;
568 out << " },\n";
572 void StaticIcon::PrintOn(ostream & out) const
574 if (hack_dialog_initialiser_flag)
575 return;
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)
585 return;
587 out << " { PXDialogResource::UserControl";
588 Control::PrintOn(out);
589 out << " },\n";
592 ///////////////////////////////////////////////////////////////
594 // Dialog::PrintOn
597 void Layout::PrintOn(ostream & out) const
600 // set special hack flag to output list box initialisers
601 // Oh the shame!!
603 hack_dialog_initialiser_flag = TRUE;
604 hack_dialog_id = id;
606 PINDEX i;
607 for (i = 0; i < itemList.GetSize(); i++)
608 out << itemList[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) << ", "
617 << "NULL, "
618 << id << ", "
619 << fontSize << ", "
620 << OUTPUTSTRING(fontName) << " },\n";
622 for (i = 0; i < itemList.GetSize(); i++)
623 out << itemList[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
639 PINDEX i;
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');
662 PINDEX i;
663 for (i = 0; i < GetSize(); i++) {
664 out << "\\x" << setw(2) << (theArray[i]&0xff);
665 if (i != GetSize()-1 && (i%10) == 9)
666 out << "\"\n \"";
668 out << setfill(' ') << setbase(10) << '"';
672 ///////////////////////////////////////////////////////////////
674 // PixData::PrintOn
677 void PixData::PrintOn(ostream & out) const
679 out << " \"" << setbase(16) << setfill('0');
680 PINDEX i;
681 for (i = 0; i < GetSize(); i++) {
682 out << "\\x" << setw(2) << (theArray[i]&0xff);
683 if (i != GetSize()-1 && (i%10) == 9)
684 out << "\"\n \"";
686 out << setfill(' ') << setbase(10) << '"';
690 ///////////////////////////////////////////////////////////////
692 // PixelContents::PrintOn
695 void PixelContents::PrintOn(ostream & out) const
697 out << " "
698 << width
699 << ", "
700 << height
701 << ", "
702 << depth
703 << ", "
704 << endl
705 << endl;
707 out << " // Clut\n"
708 << clut
709 << ", "
710 << endl
711 << endl;
713 out << " // Pixels\n"
714 << pixels
715 << ", "
716 << endl
717 << endl;
719 out << " // AndMask\n"
720 << andMask
721 << ", "
722 << endl
723 << endl;
725 out << " // XorMask\n"
726 << xorMask
727 << ", "
728 << endl
729 << endl;
731 out << " // HotSpot\n"
732 << x
733 << ", "
734 << y
735 << "\n\n";
739 ///////////////////////////////////////////////////////////////
741 // Icon::PrintOn
744 void Icon::PrintOn(ostream & out) const
746 out << "\n\nstatic PXPixelResource PXIcon"
747 << id
748 << " = {\n "
749 << contents
750 << "};\n";
754 ///////////////////////////////////////////////////////////////
756 // IconDict::PrintOn
759 void IconDict::PrintOn(ostream & out) const
761 out << "\n\n//\n// Icon Resources\n//\n";
763 // output each of the icons
764 PINDEX i;
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
801 PINDEX i;
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 ///////////////////////////////////////////////////////////////
818 // Image::PrintOn
821 void Image::PrintOn(ostream & out) const
823 out << "\n\nstatic PXPixelResource PXImage"
824 << id << " = {\n "
825 << contents
826 << "};\n";
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
840 PINDEX i;
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 ///////////////////////////////////////////////////////////////
857 // Pattern::PrintOn
860 void Pattern::PrintOn(ostream & out) const
862 out << "\n\n//\n// Pattern Resources\n//\n";
863 // << "\n\nstatic PXPixelResource PXImage"
864 // << id << " = {\n "
865 // << contents
866 // << "};\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";
888 // }
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)
902 << ",\n "
903 << data
904 << "\n";
908 ///////////////////////////////////////////////////////////////
910 // DataDict::PrintOn
913 void DataDict::PrintOn(ostream & out) const
916 // output each data resource as a static constant array
918 PINDEX i;
919 for (i = 0; i < GetSize(); i++) {
920 int id = GetDataAt (i).GetID();
921 out << "static PXDataResource DataResource"
922 << id
923 << " = {"
924 << GetDataAt (i)
925 << "};\n\n";
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 ///////////////////////////////////////////////////////////////
941 // Backend
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"
950 << stringDict
951 << menubarDict
952 << dialogDict
953 << iconDict
954 << cursorDict
955 << imageDict
956 << dataDict;
958 hack_accel_flag = TRUE;
959 out << menubarDict;
961 out << "\n\n"
962 << "#ifndef PRESOURCESETNAME\n"
963 << "#define PRESOURCESETNAME PXApplicationResources\n"
964 << "#endif\n\n\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"
976 << "} };\n";
980 ///////////////////////////////////////////////////////////////
982 // Decompiler
985 void Decompile(PFile &, PTextFile &)
987 cerr << "The decompile facility is not available on Unix(tm) platforms.\n";