unix.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:22k
- /*
- * unix.cxx
- *
- * Resource compiler unix code generator
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: unix.cxx,v $
- * Revision 1.13 1998/12/21 08:02:14 robertj
- * New directory structure
- *
- * Revision 1.12 1998/10/16 13:56:58 robertj
- * Changed resource output files to be the same as for Windows.
- * Removed warning on unused parameter.
- *
- * Revision 1.11 1998/09/26 01:24:21 robertj
- * Added open source license
- *
- * Revision 1.10 1998/09/26 00:41:29 robertj
- * Fixed name space conflict with type Cursor.
- * Fixed innumerable scoping problems in for loops.
- * Fixed triadic operator type mismatch problem.
- *
- * Revision 1.9 1996/04/19 13:24:07 craigs
- * Version before big cleanup
- *
- * Revision 1.8 1995/08/24 12:53:58 robertj
- * Added general control type for arbitrary dialog controls.
- * Added output file extension variable.
- *
- * Revision 1.2 1995/08/04 06:23:12 robertj
- * *** empty log message ***
- *
- * Revision 1.6 1994/12/31 23:27:15 robertj
- * Many changes
- *
- * Revision 1.5 1994/12/05 11:35:31 robertj
- * Update.
- *
- // Revision 1.1 1993/06/24 19:23:17 craigs
- // Initial revision
- //
- */
-
- #pragma implementation "pwrc.h"
- #pragma implementation "keycode.h"
-
- #include <fstream.h>
-
- #include "ptlib.h"
-
- #include "pwrc.h"
- #include "pwlib/stdresid.h"
-
- #include <iomanip.h>
-
- PString OutputExtension(".res.cxx");
- PString CxxExtension(".cxx");
-
- static PString Indent;
-
- static BOOL hack_dialog_initialiser_flag;
- static int hack_dialog_id = -1;
-
- static BOOL hack_accel_flag;
-
- static const PString NullString = "NULL";
- #define OUTPUTSTRING(s) ((s).IsEmpty() ? NullString : (s))
-
-
- ///////////////////////////////////////////////////////////////
- //
- // StringDict::PrintOn
- //
-
- void StringDict::PrintOn(ostream & out) const
- {
- out << "nn//n// String Resourcesn//nn"
- << "static PXResource StringResources[] = {n";
-
- PINDEX i;
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " { "
- << id
- << ", "
- << GetDataAt (i).GetLiteralText()
- << " },n";
- }
-
- out << " { -1, NULL }n};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // MenuItem::PrintOn
- //
-
-
- void MenuItem::PrintOn(ostream & out) const
-
- {
- if (!hack_accel_flag)
- out << Indent << "{ "
- << "PXMenuResource::Item, "
- << textLiteral
- << ", "
- << id
- << " },n";
- else {
- PINDEX i;
- for (i = 0; i < accel.GetSize(); i++)
- out << " { "
- << id
- << ", (PKeyCode::Value)"
- << accel[i].GetValue()
- << ", "
- << accel[i].GetModifiers()
- << "},n";
- }
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Separator::PrintOn
- //
-
- void Separator::PrintOn(ostream & out) const
-
- {
- if (!hack_accel_flag)
- out << Indent << "{ PXMenuResource::Separator },n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Menu::PrintOn
- //
-
- void Menu::PrintOn(ostream & out) const
-
- {
- PINDEX i;
-
- if (!hack_accel_flag)
- out << Indent << "{ PXMenuResource::SubMenu, " << textLiteral << " },n";
-
- Indent += " ";
-
- //
- // output items
- //
- for (i = 0; i < items.GetSize(); i++)
- out << items [i];
-
- Indent = Indent.Left(Indent.GetLength()-2);
-
- //
- // output end of menu
- //
- if (!hack_accel_flag)
- out << Indent << "{ PXMenuResource::EndMenu },n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Menubar::PrintOn
- //
-
- void MenuBar::PrintOn(ostream & out) const
-
- {
- //
- // output header for menubar
- //
- if (!hack_accel_flag)
- out << "nnstatic PXMenuResource PXMenuBar" << id << "[] = {n"
- << " { PXMenuResource::MenuBar },n";
- else
- out << "nnstatic PXAcceleratorResource PXAccel" << id << "[] = {n";
-
- Indent = " ";
-
- //
- // output data for menubar
- //
- PINDEX i;
- for (i = 0; i < menus.GetSize(); i++)
- out << menus [i];
-
- //
- // output trailer for menubar
- //
- if (!hack_accel_flag)
- out << "n { PXMenuResource::EndBar }n};nn";
- else
- out << " { -1, (PKeyCode::Value)0, 0 }n};nn";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // MenubarDict::PrintOn
- //
-
- void MenubarDict::PrintOn(ostream & out) const
-
- {
- if (!hack_accel_flag)
- out << "nn//n// Menubar resourcesn//";
- else
- out << "nn//n// Accelerator resourcesn//";
-
- // output each of the menubars
- PINDEX i;
- for (i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
-
- if (!hack_accel_flag) {
- // output list of menubars
- out << "nnstatic PXResource MenuBarResources[] = {n";
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " { " << id << ", &PXMenuBar" << id << " },n";
- }
- } else {
- // output list of accelerators
- out << "nnstatic PXResource AcceleratorResources[] = {n";
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " { " << id << ", &PXAccel" << id << " },n";
- }
- }
- out << " { -1, NULL }n};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // output routines for various control types
- //
-
- void Point::PrintOn(ostream & out) const
- {
- out << ", " << x << ',' << y;
- }
-
-
- void Control::PrintOn(ostream & out) const
- {
- out << pos << dim << ", "
- << OUTPUTSTRING(textLiteral)
- << ", "
- << OUTPUTSTRING(balloonHelp)
- << ", " << id;
- }
-
-
- void PushButton::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::PushButton";
- Control::PrintOn(out);
- out << ", 0x" << setbase(16) << options << setbase(10);
- out << " },n";
- }
-
- #if 0
- ostream & DefPushButton::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::DefPushButton";
- Control::PrintOn(out);
- out << " },n";
- }
- #endif
-
-
- void CheckBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::CheckBox";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void Check3Way::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::Check3Way";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void RadioButton::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::RadioButton";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void LeftText::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::LeftText";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void CentreText::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::CentreText";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void RightText::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::RightText";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void StaticBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::StaticBox";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void EditBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::EditBox";
- Control::PrintOn(out);
- out << " },n";
- }
-
- void Password::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::Password";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void IntEditBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::IntEditBox";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void FloatEditBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::FloatEditBox";
- Control::PrintOn(out);
- out << " },n";
- }
-
-
- void TextEditor::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::TextEditor";
- Control::PrintOn(out);
- out << " },n";
- }
- void ListControl::PrintOn(ostream &) const
- {
- }
- static void PrintStringList (ostream & out, const PString & name, const PStringList & strList)
-
- {
- if (strList.GetSize() == 0)
- return;
- out << "static char *"
- << name
- << "[] = {n";
- PINDEX i;
- for (i = 0; i < strList.GetSize(); i++)
- out << " " << strList[i] << ",n";
- out << " NULL };n";
- }
-
-
- void ChoiceBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag) {
- if (strList.GetSize() == 0)
- return;
- out << "nn//n"
- << "// Initialiser list for choice box in dialog " << hack_dialog_id << "n"
- << "//nn";
- char buff[20];
- sprintf(buff, "%i_%i", hack_dialog_id, id);
- PrintStringList(out,
- PString("ChoiceBoxInit_") + buff,
- strList);
- return;
- }
- out << " { PXDialogResource::ChoiceBox";
- Control::PrintOn(out);
- out << ", 0x" << setbase(16) << options << setbase(10);
- if (strList.GetSize() != 0)
- out << ", ChoiceBoxInit_" << hack_dialog_id << "_" << id;
- out << " },n";
- }
-
- void ListBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag) {
- if (strList.GetSize() == 0)
- return;
- out << "nn//n"
- << "// Initialiser list for listbox " << id << " in dialog " << hack_dialog_id << "n"
- << "//nn";
- char buff[20];
- sprintf(buff, "%i_%i", hack_dialog_id, id);
- PrintStringList(out,
- PString("ListBoxInit_") + buff,
- strList);
- return;
- }
-
- out << " { PXDialogResource::ListBox";
- out << pos << dim << ", NULL, NULL, " << id;
- out << ", 0x" << setbase(16) << options << setbase(10);
- if (strList.GetSize() != 0)
- out << ", ListBoxInit_" << hack_dialog_id << "_" << id;
- out << " },n";
- }
-
-
- void ComboBox::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag) {
- if (strList.GetSize() == 0)
- return;
- out << "nn//n"
- << "// Initialiser list for combo box in dialog " << hack_dialog_id << "n"
- << "//nn";
- char buff[20];
- sprintf(buff, "%i_%i", hack_dialog_id, id);
- PrintStringList(out,
- PString("ComboBoxInit_") + buff,
- strList);
- return;
- }
-
- out << " { PXDialogResource::ComboBox";
- Control::PrintOn(out);
- out << ", 0x" << setbase(16) << options << setbase(10);
- if (strList.GetSize() != 0)
- out << ", ComboBoxInit_" << hack_dialog_id << "_" << id;
- out << " },n";
- }
-
-
- void HScrollBar::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::HScrollBar";
- // Control::PrintOn(out);
- out << pos << dim << ", "
- << """
- << minimum << " " << maximum << " " << smallNudge << " " << largeNudge
- << """
- << ", "
- << OUTPUTSTRING(balloonHelp)
- << ", " << id;
- out << " },n";
- }
-
-
- void VScrollBar::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::VScrollBar";
- // Control::PrintOn(out);
- out << pos << dim << ", "
- << """
- << minimum << " " << maximum << " " << smallNudge << " " << largeNudge
- << """
- << ", "
- << OUTPUTSTRING(balloonHelp)
- << ", "
- << id;
- out << " },n";
- }
-
-
- void StaticIcon::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::StaticIcon";
- Control::PrintOn(out);
- out << ", " << iconID << " },n";
- }
- void UserControl::PrintOn(ostream & out) const
- {
- if (hack_dialog_initialiser_flag)
- return;
-
- out << " { PXDialogResource::UserControl";
- Control::PrintOn(out);
- out << " },n";
- }
-
- ///////////////////////////////////////////////////////////////
- //
- // Dialog::PrintOn
- //
-
- void Layout::PrintOn(ostream & out) const
- {
- //
- // set special hack flag to output list box initialisers
- // Oh the shame!!
- //
- hack_dialog_initialiser_flag = TRUE;
- hack_dialog_id = id;
-
- PINDEX i;
- for (i = 0; i < itemList.GetSize(); i++)
- out << itemList[i];
-
- hack_dialog_initialiser_flag = FALSE;
-
- out << "nnstatic PXDialogResource PXDialog" << id << "[] = {n"
- << " { PXDialogResource::DialogFrame, "
- << pos.X() << ", " << pos.Y() << ", "
- << dim.X() << ", " << dim.Y() << ", "
- << OUTPUTSTRING(textLiteral) << ", "
- << "NULL, "
- << id << ", "
- << fontSize << ", "
- << OUTPUTSTRING(fontName) << " },n";
-
- for (i = 0; i < itemList.GetSize(); i++)
- out << itemList[i];
-
- out << " { PXDialogResource::EndItems }n};n";
- }
-
- ///////////////////////////////////////////////////////////////
- //
- // DialogDict::PrintOn
- //
-
- void DialogDict::PrintOn(ostream & out) const
-
- {
- out << "nn//n// Dialog Resourcesn//";
-
- // output each of the dialogs
- PINDEX i;
- for (i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
-
- // output list of dialogs
- out << "nnstatic PXResource DialogResources[] = {n";
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " { " << id << ", &PXDialog" << id << "},n";
- }
-
- out << " { -1, NULL }n};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // BinaryData::PrintOn
- //
-
- void BinaryData::PrintOn(ostream & out) const
- {
- out << " "" << setbase(16) << setfill('0');
- PINDEX i;
- for (i = 0; i < GetSize(); i++) {
- out << "\x" << setw(2) << (theArray[i]&0xff);
- if (i != GetSize()-1 && (i%10) == 9)
- out << ""n "";
- }
- out << setfill(' ') << setbase(10) << '"';
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // PixData::PrintOn
- //
-
- void PixData::PrintOn(ostream & out) const
- {
- out << " "" << setbase(16) << setfill('0');
- PINDEX i;
- for (i = 0; i < GetSize(); i++) {
- out << "\x" << setw(2) << (theArray[i]&0xff);
- if (i != GetSize()-1 && (i%10) == 9)
- out << ""n "";
- }
- out << setfill(' ') << setbase(10) << '"';
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // PixelContents::PrintOn
- //
-
- void PixelContents::PrintOn(ostream & out) const
- {
- out << " "
- << width
- << ", "
- << height
- << ", "
- << depth
- << ", "
- << endl
- << endl;
-
- out << " // Clutn"
- << clut
- << ", "
- << endl
- << endl;
-
- out << " // Pixelsn"
- << pixels
- << ", "
- << endl
- << endl;
-
- out << " // AndMaskn"
- << andMask
- << ", "
- << endl
- << endl;
-
- out << " // XorMaskn"
- << xorMask
- << ", "
- << endl
- << endl;
-
- out << " // HotSpotn"
- << x
- << ", "
- << y
- << "nn";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Icon::PrintOn
- //
-
- void Icon::PrintOn(ostream & out) const
- {
- out << "nnstatic PXPixelResource PXIcon"
- << id
- << " = {n "
- << contents
- << "};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // IconDict::PrintOn
- //
-
- void IconDict::PrintOn(ostream & out) const
- {
- out << "nn//n// Icon Resourcesn//n";
-
- // output each of the icons
- PINDEX i;
- for (i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
-
- // output list of icons
- out << "nnstatic PXResource IconResources[] = {n";
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " { " << id << ", &PXIcon" << id << "},n";
- }
-
- out << " { -1, NULL }n};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // CursorResource::PrintOn
- //
-
- void CursorResource::PrintOn(ostream & out) const
- {
- out << "nnstatic PXPixelResource PXCursor"
- << id << " = {n" << contents << "};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // CursorDict::PrintOn
- //
-
- void CursorDict::PrintOn(ostream & out) const
- {
- out << "nn//n// Cursor Resourcesn//n";
-
- // output each of the cursors
- PINDEX i;
- for (i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
-
- // output list of cursors
- out << "nnstatic PXResource CursorResources[] = {n";
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " { " << id << ", &PXCursor" << id << "},n";
- }
-
- out << " { -1, NULL }n};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Image::PrintOn
- //
-
- void Image::PrintOn(ostream & out) const
- {
- out << "nnstatic PXPixelResource PXImage"
- << id << " = {n "
- << contents
- << "};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // ImageDict::PrintOn
- //
-
- void ImageDict::PrintOn(ostream & out) const
- {
- out << "nn//n// Image Resourcesn//n";
-
- // output each of the images
- PINDEX i;
- for (i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
-
- // output list of image
- out << "nnstatic PXResource ImageResources[] = {n";
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << " {" << id << ", &PXImage" << id << "},n";
- }
-
- out << " { -1, NULL }n};n";
- }
- ///////////////////////////////////////////////////////////////
- //
- // Pattern::PrintOn
- //
-
- void Pattern::PrintOn(ostream & out) const
- {
- out << "nn//n// Pattern Resourcesn//n";
- // << "nnstatic PXPixelResource PXImage"
- // << id << " = {n "
- // << contents
- // << "};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // PatternDict::PrintOn
- //
-
- void PatternDict::PrintOn(ostream & out) const
- {
- out << "nn//n// Image Resourcesn//n";
-
- // // output each of the images
- // for (PINDEX i = 0; i < GetSize(); i++)
- // out << GetDataAt (i);
- //
- // // output list of image
- // out << "nnstatic PXResource ImageResources[] = {n";
- // for (i = 0; i < GetSize(); i++) {
- // int id = GetDataAt (i).GetID();
- // out << " {" << id << ", &PXImage" << id << "},n";
- // }
- //
- // out << " { -1, NULL }n};n";
- }
-
- ///////////////////////////////////////////////////////////////
- //
- // DataResource::PrintOn
- //
-
- void DataResource::PrintOn(ostream & out) const
- {
- static const PString DataString = ""DATA"";
- out << (textConverted.IsEmpty() ? DataString : textLiteral)
- << ",n "
- << data
- << "n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // DataDict::PrintOn
- //
-
- void DataDict::PrintOn(ostream & out) const
- {
- //
- // output each data resource as a static constant array
- //
- PINDEX i;
- for (i = 0; i < GetSize(); i++) {
- int id = GetDataAt (i).GetID();
- out << "static PXDataResource DataResource"
- << id
- << " = {"
- << GetDataAt (i)
- << "};nn";
- }
-
- out << "nn//n// Arbitrary Data Resourcesn//n"
- "nnstatic PXResource DataResources[] = {n";
-
- for (i = 0; i < GetSize(); i++) {
- out << " { " << (int)GetKeyAt(i) << ", &DataResource" << (int) GetKeyAt (i) << "},n";
- }
-
- out << " { -1, NULL }n};n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Backend
- //
-
- void ResourceFile::Backend(PFile & out)
- {
- hack_accel_flag = FALSE;
-
- out << "//n// Resource file generated by Unix PWRCn//nn"
- "#include <pwlib.h>nn"
- << stringDict
- << menubarDict
- << dialogDict
- << iconDict
- << cursorDict
- << imageDict
- << dataDict;
-
- hack_accel_flag = TRUE;
- out << menubarDict;
-
- out << "nn"
- << "#ifndef PRESOURCESETNAMEn"
- << "#define PRESOURCESETNAME PXApplicationResourcesn"
- << "#endifnnn";
-
- out << "n//n// list of resources for this programn//nn"
- << "PXResourceSet PRESOURCESETNAME = { {n"
- << " StringResources,n"
- << " MenuBarResources,n"
- << " DialogResources,n"
- << " IconResources,n"
- << " CursorResources,n"
- << " ImageResources,n"
- << " DataResources,n"
- << " AcceleratorResourcesn"
- << "} };n";
- }
-
-
- ///////////////////////////////////////////////////////////////
- //
- // Decompiler
- //
-
- void Decompile(PFile &, PTextFile &)
- {
- cerr << "The decompile facility is not available on Unix(tm) platforms.n";
- }
-