windows.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:35k
- /*
- * windows.cxx
- *
- * Resource compiler MS-Windows resource binary file 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: windows.cxx,v $
- * Revision 1.36 2000/06/21 03:15:24 robertj
- * Added ability to append resources to existing file.
- *
- * Revision 1.35 1999/07/27 09:48:13 robertj
- * Removed warning.
- *
- * Revision 1.34 1998/12/23 01:16:15 robertj
- * New directory structure
- *
- * Revision 1.33 1998/09/26 01:24:23 robertj
- * Added open source license
- *
- * Revision 1.32 1998/09/26 01:00:35 robertj
- * Fixed X Windows name conflict.
- *
- * Revision 1.31 1998/09/14 13:54:56 robertj
- * Fixed ansi to unicode conversion in resource output.
- * Added tab stops to list boxes.
- * Fixed group boxes (PStaticBox) so is clipped to specified size allowing single lines.
- *
- * Revision 1.30 1996/01/23 13:26:35 robertj
- * Changed resource ID mechanism.
- *
- * Revision 1.29 1996/01/02 13:06:02 robertj
- * Changes to support editor.
- *
- * Revision 1.28 1995/12/23 03:53:03 robertj
- * Removed multiple classes for layout types.
- *
- * Revision 1.27 1995/12/10 12:12:10 robertj
- * Changes to support graphical resource file editor.
- *
- * Revision 1.26 1995/08/24 12:52:49 robertj
- * Added general control type for arbitrary dialog controls.
- * Added output file extension variable.
- *
- * Revision 1.25 1995/07/02 06:24:24 robertj
- * Fixed bug with menu accelerators resource in WIN32.
- *
- * Revision 1.24 1995/04/22 01:04:29 robertj
- * Fixed styles for controls in WIN16.
- *
- * Revision 1.23 1995/04/02 09:28:18 robertj
- * Added "balloon" help.
- *
- * Revision 1.22 1995/03/22 13:58:25 robertj
- * Fixed bug in colour table in resource images, icons etc.
- *
- * Revision 1.21 1995/02/11 04:15:14 robertj
- * Strange problem with variable "small" in MSVC 2.0.
- *
- * Revision 1.20 1995/01/27 11:25:54 robertj
- * Added pattern resource.
- *
- * Revision 1.19 1995/01/11 09:45:22 robertj
- * Documentation and normalisation.
- *
- * Revision 1.18 1994/12/12 13:14:08 robertj
- * Changed RealEdit to FloatEdit.
- *
- * Revision 1.17 1994/10/30 11:30:39 robertj
- * Fixed standard get directory dialog resource.
- *
- * Revision 1.16 1994/10/23 06:09:03 robertj
- * Changed TextEditor so return does not close dialogs.
- *
- * Revision 1.15 1994/08/22 00:23:54 robertj
- * Fixed bug in standard get directory dialog.
- *
- * Revision 1.14 1994/07/02 03:25:39 robertj
- * Fixed bug.
- *
- * Revision 1.13 1994/06/25 12:16:28 robertj
- * Synchonsiation with unix implementation.
- *
- * Revision 1.12 1994/04/03 08:37:00 robertj
- * *** empty log message ***
- *
- * Revision 1.11 1994/04/01 14:29:16 robertj
- * New format PRC file
- *
- * Revision 1.10 1994/01/03 04:34:30 robertj
- * Changed scan lines in internal structure to top to bottom.
- *
- * Revision 1.9 1993/12/31 07:05:07 robertj
- * Changed pixmap images for one pixel one number in PRC file.
- *
- * Revision 1.8 1993/12/14 18:54:42 robertj
- * WIN32 port.
- *
- * Revision 1.7 1993/08/20 21:31:56 robertj
- * Fixed bug in extra byte in bitmap image raster data.
- *
- * Revision 1.7 1993/08/10 13:08:09 robertj
- * Fixed bug with extra byte in bitmap image scan lines.
- *
- * Revision 1.6 1993/07/17 02:57:00 robertj
- * Further implementation
- *
- * Revision 1.5 1993/07/16 14:48:43 robertj
- * Fixed header comment.
- * Fixed DWORD padding on scan lines in bitmaps.
- *
- * Revision 1.4 1993/07/16 12:53:12 robertj
- * Added converted form of C literal string to resource objects.
- * Changed DIALOGSTRINGS resource format to be more usefull.
- *
- * Revision 1.3 1993/07/15 04:38:31 robertj
- * Rationalised lex.h, parse.h and main.h out of existance.
- *
- * Revision 1.2 1993/07/14 01:57:48 robertj
- * Fixed bug in not getting long alignment in bitmaps.
- *
- * Revision 1.1 1993/07/03 06:00:47 robertj
- * Initial revision
- *
- */
- #include <ptlib.h>
- #ifndef WIN32
- #undef NEAR
- #endif
- #include <windows.h>
- #include <fcntl.h>
- #include "pwrc.h"
- #include "pwlib/stdresid.h"
- #define DIALOGSTRINGS "DIALOGSTRINGS"
- PString OutputExtension(".res");
- PString CxxExtension(".cxx");
- static enum { OutputMenus, CountAccelerators, OutputAccelerators } MenuPass;
- static int HasAccelerators;
- static BYTE LastAcceleratorFlags;
- static BOOL LastMenu;
- static BOOL OutputDialogStrings;
- static BYTE DialogControlCode;
- static DWORD DialogControlStyle;
- static enum {
- BilevelIcon,
- BilevelCursor,
- ColourIcon,
- ColourCursor,
- PixmapImage,
- IconDirMap,
- CursorDirMap
- } OutputIconCursor;
- static WORD IconCursorID;
- static int PixDataWidth;
- static int PixDataDepth;
- //////////////////////////////////////////////////////////////////////////////
- // Support classes for binary stream output
- class BinByte {
- public:
- inline BinByte(int nb)
- : b((char)nb) { }
- inline friend ostream & operator<<(ostream & out, const BinByte & b)
- { out.put(b.b); return out; }
- protected:
- char b;
- };
- class BinWord {
- public:
- inline BinWord(int nw)
- : w((short)nw) { }
- inline friend ostream & operator<<(ostream & out, const BinWord & w)
- { out.write((char *)&w.w, sizeof(w.w)); return out; }
- protected:
- short w;
- };
- #ifdef WIN32
- #define BinTextChar BinWord
- #else
- #define BinTextChar BinByte
- #endif
- class BinLong {
- public:
- inline BinLong(long nl)
- : l(nl) { }
- inline friend ostream & operator<<(ostream & out, const BinLong & l)
- { out.write((char *)&l.l, sizeof(l.l)); return out; }
- protected:
- long l;
- };
- class BinStr {
- public:
- inline BinStr(const PString & str)
- : s(str) { }
- friend ostream & operator<<(ostream & out, const BinStr & s);
- protected:
- PString s;
- };
- static int ConvertAnsiToUnicode(const PString & s, PWORDArray & unicode)
- {
- int len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, s, s.GetLength(), NULL, 0);
- MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, s, -1, unicode.GetPointer(len), len);
- return len;
- }
- ostream & operator<<(ostream & out, const BinStr & s)
- {
- #ifdef WIN32
- PWORDArray wide;
- int len = ConvertAnsiToUnicode(s.s, wide);
- for (int i = 0; i < len; i++)
- out << BinWord(wide[i]);
- return out << BinWord(0);
- #else
- return out << s.s << BinByte(0);
- #endif
- }
- class ResHdr {
- public:
- inline ResHdr(int rType, int rId)
- : type((short)rType), id((short)rId), lenpos(-1) { }
- inline ResHdr(const PString & rType, int rId)
- : sType(rType), id((short)rId), lenpos(-1) { }
- inline void SetType(int rType)
- { type = (short)rType; }
- inline void SetType(const PString & rType)
- { sType = rType; }
- friend ostream & operator<<(ostream & out, ResHdr & h);
- protected:
- short type, id;
- PString sType;
- streampos lenpos;
- streampos endhdrpos;
- };
- ostream & operator<<(ostream & out, ResHdr & h)
- {
- if (h.lenpos != -1) {
- BinLong len = out.tellp() - h.endhdrpos;
- out.seekp(h.lenpos);
- out << len;
- #ifdef WIN32
- out << BinLong(h.endhdrpos - h.lenpos);
- #endif
- out.seekp(0, ios::end);
- }
- else {
- #ifdef WIN32
- while (((h.lenpos = out.tellp())&3) != 0) // Align to long
- out.put(' ');
- out << BinLong(0) << BinLong(0);
- if (h.sType.IsEmpty())
- out << BinWord(0xffff) << BinWord(h.type);
- else
- out << BinStr(h.sType);
- out << BinWord(0xffff) << BinWord(h.id);
- while ((out.tellp()&3) != 0) // Align to long
- out.put(' ');
- out << BinLong(0) << BinLong(0x04091030) << BinLong(0) << BinLong(0);
- #else
- if (h.sType.IsEmpty())
- out << BinByte(0xffff) << BinWord(h.type);
- else
- out << h.sType << BinByte(0);
- out << BinByte(0xff) << BinWord(h.id) << BinWord(0x1030);
- h.lenpos = out.tellp();
- out << BinLong(0);
- #endif
- h.endhdrpos = out.tellp();
- }
- return out;
- }
- ///////////////////////////////////////////////////////////////
- //
- // StringDict::PrintOn
- //
- void StringDict::PrintOn(ostream & out) const
- {
- char set[4096/8];
- memset(set, 0, sizeof(set));
- for (int i = 0; i < GetSize(); i++) {
- unsigned id = (unsigned)GetKeyAt(i) >> 4;
- set[id>>3] |= 1 << (id&7);
- }
- for (i = 0; i < 4096; i++) {
- if ((set[i>>3]&(1<<(i&7))) != 0) {
- ResHdr hdr(6, i+1);
- out << hdr;
- for (int j = 0; j < 16; j++) {
- ResourceObject * res;
- if ((res = (ResourceObject *)GetAt(i*16+j)) == NULL)
- out << BinTextChar(0);
- else {
- #ifdef WIN32
- PWORDArray wide;
- int len = ConvertAnsiToUnicode(res->GetConvertedText(), wide);
- out << BinWord(len);
- for (int k = 0; k < len; k++)
- out << BinWord(wide[k]);
- #else
- out << BinByte(res->GetConvertedText().GetLength()) << res->GetConvertedText();
- #endif
- }
- }
- out << hdr;
- }
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // MenuItem::PrintOn
- //
- void MenuItem::PrintOn(ostream & out) const
- {
- switch (MenuPass) {
- case OutputMenus :
- out << BinWord(LastMenu ? (WORD)MF_END : 0) << BinWord(id);
- if (accel.IsEmpty() || accel[0].GetValue() < PKeyCode::A ||
- accel[0].GetValue() > PKeyCode::Space)
- out << BinStr(textConverted);
- else {
- static char *ValueStrings[] = {
- NULL, NULL, NULL, NULL,
- "A","B","C","D","E","F","G","H","I","J","K","L","M",
- "N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- "NumPad0", "NumPad1", "NumPad2", "NumPad3", "NumPad4",
- "NumPad5", "NumPad6", "NumPad7", "NumPad8", "NumPad9",
- "NumPad+", "NumPad-", "NumPad*", "NumPad/", "NumPad,", "NumPad.",
- "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10","F11","F12",
- "F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24",
- "Up", "Down", "Left", "Right", "PgUp", "PgDn", "Home", "End",
- "Ins", "Del", "Undo", "Cut", "Copy", "Paste", "Clear", "Cancel", "Help", "Quit",
- "BkSp", "Tab", "Enter", "Esc", "Space"
- };
- static int ModifierOrder[] = {
- PKeyCode::Option,
- PKeyCode::Command,
- PKeyCode::Alt,
- PKeyCode::Shift,
- PKeyCode::Control,
- PKeyCode::CapsLock,
- PKeyCode::Accelerator1,
- PKeyCode::Accelerator2,
- 0
- };
- PString modifers;
- for (int i = 0; ModifierOrder[i] != 0; i++) {
- if (accel[0].IsModifier(ModifierOrder[i])) {
- switch (accel[0].GetModifiers() & ModifierOrder[i]) {
- case PKeyCode::Shift:
- modifers += "Shift+";
- break;
- case PKeyCode::Command:
- case PKeyCode::Control:
- case PKeyCode::Accelerator1:
- modifers += "Ctrl+";
- break;
- case PKeyCode::Alt:
- modifers += "Alt+";
- break;
- case PKeyCode::Option:
- modifers += "Opt";
- break;
- case PKeyCode::Accelerator2:
- modifers += "Ctrl+Shift+";
- }
- }
- }
- out << BinStr(textConverted +
- "t" + modifers + ValueStrings[accel[0].GetValue()]);
- }
- break;
- case CountAccelerators :
- if (!accel.IsEmpty())
- HasAccelerators = TRUE;
- break;
- case OutputAccelerators :
- for (PINDEX i = 0; i < accel.GetSize(); i++) {
- static WORD toVK[] = {
- 0, VK_LBUTTON, VK_RBUTTON, VK_MBUTTON,
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD4,
- VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9,
- VK_ADD, VK_SUBTRACT, VK_MULTIPLY, VK_DIVIDE, VK_SEPARATOR, VK_DECIMAL,
- VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8,
- VK_F9, VK_F10, VK_F11, VK_F12, VK_F13, VK_F14, VK_F15, VK_F16,
- VK_F17, VK_F18, VK_F19, VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
- VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_PRIOR, VK_NEXT, VK_HOME, VK_END,
- VK_INSERT, VK_DELETE, VK_F20, VK_F21, VK_F22, VK_F23,
- VK_CLEAR, VK_CANCEL, VK_HELP, VK_F24,
- VK_BACK, VK_TAB, VK_RETURN, VK_ESCAPE, VK_SPACE,
- VK_CAPITAL, VK_SHIFT, VK_CONTROL, VK_MENU, VK_CONTROL, VK_MENU, VK_MENU,
- VK_PAUSE, VK_SELECT, 0x2a, VK_EXECUTE, VK_SNAPSHOT, VK_NUMLOCK, VK_SCROLL,
- 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
- 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe6, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee,
- 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5
- };
- BYTE flags = 1;
- if (accel[i].IsModifier(PKeyCode::Shift))
- flags |= 0x04;
- if (accel[i].IsModifier(PKeyCode::Control|PKeyCode::Command|PKeyCode::Accelerator1))
- flags |= 0x08;
- if (accel[i].IsModifier(PKeyCode::Alt|PKeyCode::Option))
- flags |= 0x10;
- if (accel[i].IsModifier(PKeyCode::Accelerator2))
- flags |= 0x0c;
- LastAcceleratorFlags = flags;
- out << BinTextChar(flags)
- << BinWord(toVK[accel[i].GetValue()])
- << BinWord(id);
- #ifdef WIN32
- out << BinWord(0);
- #endif
- }
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // Separator::PrintOn
- //
- void Separator::PrintOn(ostream & out) const
- {
- if (MenuPass == OutputMenus)
- out << BinWord((WORD)(MF_SEPARATOR|(LastMenu ? MF_END : 0)))
- << BinWord(0) << BinTextChar(0);
- }
- ///////////////////////////////////////////////////////////////
- //
- // Menu::PrintOn
- //
- void Menu::PrintOn(ostream & out) const
- {
- if (MenuPass == OutputMenus)
- out << BinWord((WORD)(MF_POPUP|(LastMenu ? MF_END : 0)))
- << BinStr(textConverted);
- // output items
- for (int i = 0; i < items.GetSize(); i++) {
- LastMenu = i == items.GetSize()-1;
- out << items[i];
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // Menubar::PrintOn
- //
- void MenuBar::PrintOn(ostream & out) const
- {
- ResHdr hdr(4, id);
- switch (MenuPass) {
- case OutputMenus :
- out << hdr << BinWord(0) << BinWord(0);
- break;
- case OutputAccelerators :
- hdr.SetType(9);
- out << hdr;
- break;
- }
-
- // output data for menubar
- for (int i = 0; i < menus.GetSize(); i++) {
- LastMenu = i == menus.GetSize()-1;
- out << menus[i];
- }
- if (MenuPass != CountAccelerators)
- out << hdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // MenubarDict::PrintOn
- //
- void MenubarDict::PrintOn(ostream & out) const
- {
- // output each of the menubars
- for (int i = 0; i < GetSize(); i++) {
- MenuPass = OutputMenus;
- out << GetDataAt(i);
- MenuPass = CountAccelerators;
- HasAccelerators = FALSE;
- out << GetDataAt(i);
- if (HasAccelerators) {
- MenuPass = OutputAccelerators;
- out << GetDataAt(i);
- #ifdef WIN32
- out.seekp(-8, ios::cur);
- #else
- out.seekp(-5, ios::cur);
- #endif
- out << BinByte(LastAcceleratorFlags|0x80);
- out.seekp(0, ios::end);
- }
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // output routines for various control types
- //
- void Point::PrintOn(ostream & out) const
- {
- out << BinWord(x) << BinWord(y);
- }
- void Control::PrintOn(ostream & out) const
- {
- if (OutputDialogStrings) {
- out << BinStr(PString(PString::Literal, balloonHelp));
- return;
- }
- #ifdef WIN32
- while ((out.tellp()&3) != 0) // Align to long
- out.put(' ');
- out << BinLong(DialogControlStyle|WS_VISIBLE|WS_CHILD) << BinLong(0)
- << pos << dim << BinWord(id) << BinWord(0xffff)
- #else
- out << pos << dim << BinWord(id)
- << BinLong(DialogControlStyle|WS_VISIBLE|WS_CHILD)
- #endif
- << BinTextChar(DialogControlCode);
- if (iconID == -1)
- out << BinStr(textConverted) << BinTextChar(0);
- }
- void PushButton::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x80;
- DialogControlStyle = (options&DefaultButtonOption) != 0 ? BS_DEFPUSHBUTTON
- : BS_PUSHBUTTON;
- DialogControlStyle |= WS_TABSTOP;
- Control::PrintOn(out);
- }
- void CheckBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x80;
- DialogControlStyle = BS_AUTOCHECKBOX|WS_TABSTOP;
- Control::PrintOn(out);
- }
- void Check3Way::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x80;
- DialogControlStyle = BS_AUTO3STATE|WS_TABSTOP;
- Control::PrintOn(out);
- }
- void RadioButton::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x80;
- DialogControlStyle = BS_RADIOBUTTON|WS_TABSTOP;
- Control::PrintOn(out);
- }
- void LeftText::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x82;
- DialogControlStyle = SS_LEFT;
- Control::PrintOn(out);
- }
- void CentreText::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x82;
- DialogControlStyle = SS_CENTER;
- Control::PrintOn(out);
- }
- void RightText::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x82;
- DialogControlStyle = SS_RIGHT;
- Control::PrintOn(out);
- }
- void StaticBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x80;
- DialogControlStyle = BS_GROUPBOX|WS_CLIPSIBLINGS;
- Control::PrintOn(out);
- }
- void EditBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x81;
- DialogControlStyle = ES_LEFT|ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP;
- Control::PrintOn(out);
- }
- void IntEditBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x81;
- DialogControlStyle = ES_LEFT|WS_BORDER|WS_TABSTOP;
- ((IntEditBox*)this)->textConverted = psprintf("INTEDITBOX %li %li %li %li",
- minimum, maximum, smallNudge, largeNudge);
- Control::PrintOn(out);
- }
- void FloatEditBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x81;
- DialogControlStyle = ES_LEFT|WS_BORDER|WS_TABSTOP;
- ((FloatEditBox*)this)->textConverted =
- psprintf("FLOATEDITBOX %li %li %li %li",
- minimum, maximum, smallNudge, largeNudge);
- Control::PrintOn(out);
- }
- void TextEditor::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x81;
- DialogControlStyle = ES_LEFT|ES_MULTILINE|ES_WANTRETURN|
- WS_VSCROLL|WS_HSCROLL|WS_BORDER|WS_TABSTOP;
- Control::PrintOn(out);
- }
- void Password::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x81;
- DialogControlStyle = ES_LEFT|ES_PASSWORD|WS_BORDER|WS_TABSTOP;
- Control::PrintOn(out);
- }
- void ListControl::PrintOn(ostream & out) const
- {
- Control::PrintOn(out);
- if (OutputDialogStrings)
- for (PINDEX i = 0; i < strList.GetSize(); i++)
- out << BinStr(PString(PString::Literal, strList[i]));
- }
- void ChoiceBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x85;
- DialogControlStyle = CBS_DROPDOWNLIST|WS_VSCROLL|WS_BORDER|WS_TABSTOP;
- if ((options&Special) != 0)
- DialogControlStyle |= CBS_SORT|CBS_OWNERDRAWFIXED|CBS_HASSTRINGS;
- else if ((options&SortedOption) != 0)
- DialogControlStyle |= CBS_SORT;
- ListControl::PrintOn(out);
- }
- void ListBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x83;
- DialogControlStyle = LBS_USETABSTOPS|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_BORDER|WS_TABSTOP;
- if ((options&Special) != 0)
- DialogControlStyle |= WS_VSCROLL|LBS_OWNERDRAWFIXED|LBS_HASSTRINGS|LBS_SORT;
- else {
- if ((options&SortedOption) != 0)
- DialogControlStyle |= LBS_SORT;
- if ((options&MultiSelectOption) != 0)
- DialogControlStyle |= LBS_EXTENDEDSEL;
- if ((options&MultiColumnOption) != 0)
- DialogControlStyle |= LBS_MULTICOLUMN|WS_HSCROLL;
- else
- DialogControlStyle |= LBS_DISABLENOSCROLL|WS_VSCROLL;
- if (GetResClass() != "PStringListBox")
- DialogControlStyle |= (options&MultiColumnOption) != 0
- ? LBS_OWNERDRAWFIXED : LBS_OWNERDRAWVARIABLE;
- }
- ListControl::PrintOn(out);
- }
- void ComboBox::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x85;
- DialogControlStyle =
- CBS_AUTOHSCROLL|CBS_DROPDOWN|WS_VSCROLL|WS_BORDER|WS_TABSTOP;
- if ((options&SortedOption) != 0)
- DialogControlStyle |= CBS_SORT;
- if ((options&Special) != 0)
- DialogControlStyle |= CBS_OWNERDRAWFIXED|CBS_HASSTRINGS;
- ListControl::PrintOn(out);
- }
- void HScrollBar::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x84;
- DialogControlStyle = SBS_HORZ|WS_TABSTOP;
- ((HScrollBar*)this)->textConverted = psprintf("%li %li %li %li",
- minimum, maximum, smallNudge, largeNudge);
- Control::PrintOn(out);
- }
- void VScrollBar::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x84;
- DialogControlStyle = SBS_VERT|WS_TABSTOP;
- ((VScrollBar*)this)->textConverted = psprintf("%li %li %li %li",
- minimum, maximum, smallNudge, largeNudge);
- Control::PrintOn(out);
- }
- void StaticIcon::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x82;
- DialogControlStyle = SS_ICON;
- Control::PrintOn(out);
- if (!OutputDialogStrings)
- out << BinTextChar(0xffff) << BinWord(iconID) << BinTextChar(0);
- }
- void UserControl::PrintOn(ostream & out) const
- {
- DialogControlCode = 0x82;
- DialogControlStyle = SS_LEFT;
- Control::PrintOn(out);
- }
- ///////////////////////////////////////////////////////////////
- //
- // Layout::PrintOn
- //
- void Layout::PrintOn(ostream & out) const
- {
- ResHdr hdr(5, id);
-
- if (OutputDialogStrings) {
- hdr.SetType(DIALOGSTRINGS);
- out << hdr;
- }
- else {
- DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS|DS_SETFONT;
- if (subtype == 0)
- style |= WS_CHILD;
- else
- style |= WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_MODALFRAME;
- out << hdr
- << BinLong(style) // Window style
- #ifdef WIN32
- << BinLong(0) // Window extended style
- #endif
- << BinTextChar(itemList.GetSize()) // number of items
- << BinWord(pos.X())
- << BinWord(pos.Y())
- << BinWord(dim.X())
- << BinWord(dim.Y())
- << BinTextChar(0) // Menu name (no menu)
- << BinTextChar(0) // Class name (default class)
- << BinStr(textConverted); // caption
- if (fontName.IsEmpty())
- out << BinWord(8) << BinStr("MS Sans Serif");
- else
- out << BinWord(fontSize)
- << BinStr(PString(PString::Literal, fontName));
- }
- for (int i = 0; i < itemList.GetSize(); i++) {
- out << itemList[i];
- if (OutputDialogStrings)
- out << BinTextChar(0); // Terminator
- }
- out << hdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // DialogDict::PrintOn
- //
- void DialogDict::PrintOn(ostream & out) const
- {
- // output each of the dialogs
- for (int i = 0; i < GetSize(); i++) {
- OutputDialogStrings = FALSE;
- out << GetDataAt (i);
- OutputDialogStrings = TRUE;
- out << GetDataAt (i);
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // BinaryData::PrintOn
- //
- void BinaryData::PrintOn(ostream & out) const
- {
- out.write(theArray, GetSize());
- }
- ///////////////////////////////////////////////////////////////
- //
- // PixData::PrintOn
- //
- void PixData::PrintOn(ostream & out) const
- {
- if (PixDataDepth > 8) {
- for (int y = GetSize()/PixDataWidth/3-1; y >= 0; y--) {
- const char * pixels = theArray+y*PixDataWidth*3;
- for (PINDEX x = 0; x < PixDataWidth*3; x++)
- out << *pixels++ << ' ';
- while ((x++&3) != 0) // Align to long
- out.put(' ');
- }
- }
- else {
- for (int y = GetSize()/PixDataWidth-1; y >= 0; y--) {
- const char * pixels = theArray+y*PixDataWidth;
- PINDEX byteCount = 0;
- PINDEX pixelsPerByte = 8/PixDataDepth;
- PINDEX pixelInByte = 0;
- char byte = 0;
- for (PINDEX pix = 0; pix < PixDataWidth; pix++) {
- byte <<= PixDataDepth;
- byte |= *pixels++;
- if (++pixelInByte >= pixelsPerByte) {
- out.put(byte);
- byteCount++;
- pixelInByte = 0;
- byte = 0;
- }
- }
- if (pixelInByte != 0) {
- out.put((char)(byte << (8-pixelInByte)));
- byteCount++;
- }
- while ((byteCount++&3) != 0) // Align to long
- out.put(' ');
- }
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // PixelContents::PrintOn
- //
- void PixelContents::PrintOn(ostream & out) const
- {
- static RGBQUAD bw[2] = { { 0, 0, 0, 0 }, { 255, 255, 255, 0 } };
- PixDataWidth = width;
- BITMAPINFOHEADER bm;
- memset(&bm, 0, sizeof(bm));
- bm.biSize = sizeof(bm);
- bm.biWidth = width;
- bm.biHeight = height;
- bm.biPlanes = 1;
- switch (OutputIconCursor) {
- case BilevelCursor :
- out << BinWord(x) << BinWord(y); // Hotspot
- // Then do common code in BiLevelIcon case
- case BilevelIcon :
- bm.biHeight *= 2;
- bm.biBitCount = 1;
- bm.biSizeImage = ((bm.biWidth+31)/32)*4*bm.biHeight;
- bm.biClrUsed = bm.biClrImportant = 2L;
- out.write((char *)&bm, sizeof(bm));
- out.write((char *)bw, sizeof(bw));
- PixDataDepth = 1;
- out << xorMask << andMask;
- break;
-
- case ColourCursor :
- out << BinWord(x) << BinWord(y); // Hotspot
- // Then do common code in ColourIcon case
- case ColourIcon :
- bm.biHeight *= 2;
- // Then do common code in PixmapImage case
- case PixmapImage :
- bm.biBitCount = (WORD)depth;
- bm.biSizeImage = ((bm.biWidth*bm.biBitCount+31)/32)*4*bm.biHeight;
- bm.biClrUsed = bm.biClrImportant = 1L << bm.biBitCount;
- out.write((char *)&bm, sizeof(bm));
-
- if (depth != 24) {
- for (int i = 0; i < (int)bm.biClrUsed; i++) {
- RGBQUAD rgb;
- rgb.rgbRed = clut[i*3];
- rgb.rgbGreen = clut[i*3+1];
- rgb.rgbBlue = clut[i*3+2];
- rgb.rgbReserved = 0;
- out.write((char *)&rgb, sizeof(rgb));
- }
- }
- PixDataDepth = depth;
- out << pixels;
- PixDataDepth = 1;
- if (andMask.GetSize() > 0)
- out << andMask;
- break;
- case IconDirMap :
- out << BinWord(depth != 1 ? 2 : 1)
- << BinByte(width) << BinByte(height) // First the B/W icon/cursor
- << BinWord(2) // Number of colours
- << BinWord(1) // Bit planes/hotspot x
- << BinWord(1) // Bits per pixel/hotspot y
- << BinLong(sizeof(BITMAPINFOHEADER) +
- 2*andMask.GetSize() + 2*sizeof(RGBQUAD)) // Size
- << BinWord(IconCursorID++);
-
- if (depth != 1)
- out << BinByte(width) << BinByte(height) // Second the colour icon/cursor
- << BinWord(1 << depth) // Number of colours
- << BinWord(1) // Bit planes/hotspot x
- << BinWord(depth) // Bits per pixel/hotspot y
- << BinLong(sizeof(BITMAPINFOHEADER) +
- pixels.GetSize() + andMask.GetSize() +
- (depth != 24 ? ((1<<depth)*sizeof(RGBQUAD)) : 0)) // Size
- << BinWord(IconCursorID++);
- break;
- case CursorDirMap :
- out << BinWord(depth != 1 ? 2 : 1)
- << BinWord(width) << BinWord(height) // First the B/W icon/cursor
- << BinWord(1) // Bit planes
- << BinWord(1) // Bits per pixel
- << BinLong(sizeof(BITMAPINFOHEADER) +
- 2*andMask.GetSize() + 2*sizeof(RGBQUAD)) // Size
- << BinWord(IconCursorID++);
-
- if (depth != 1)
- out << BinWord(width) << BinWord(height) // Second the colour icon/cursor
- << BinWord(1) // Bit planes
- << BinWord(depth) // Bits per pixel
- << BinLong(sizeof(BITMAPINFOHEADER) +
- pixels.GetSize() + andMask.GetSize() +
- (depth != 24 ? ((1<<depth)*sizeof(RGBQUAD)) : 0)) // Size
- << BinWord(IconCursorID++);
- }
- }
- ///////////////////////////////////////////////////////////////
- //
- // Icon::PrintOn
- //
- void Icon::PrintOn(ostream & out) const
- {
- OutputIconCursor = BilevelIcon;
- ResHdr hdr(3, IconCursorID);
- out << hdr << contents << hdr;
- if (contents.depth != 1) {
- OutputIconCursor = ColourIcon;
- ResHdr colhdr(3, IconCursorID+1);
- out << colhdr << contents << colhdr;
- }
- OutputIconCursor = IconDirMap;
- ResHdr dirhdr(14, id);
- out << dirhdr << BinWord(0) << BinWord(1) << contents << dirhdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // IconDict::PrintOn
- //
- void IconDict::PrintOn(ostream & out) const
- {
- IconCursorID = 1;
- // output each of the icons
- for (int i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
- }
- ///////////////////////////////////////////////////////////////
- //
- // Cursor::PrintOn
- //
- void CursorResource::PrintOn(ostream & out) const
- {
- OutputIconCursor = BilevelCursor;
- ResHdr hdr(1, IconCursorID);
- out << hdr << contents << hdr;
- if (contents.depth != 1) {
- OutputIconCursor = ColourCursor;
- ResHdr colhdr(1, IconCursorID+1);
- out << colhdr << contents << colhdr;
- }
- OutputIconCursor = CursorDirMap;
- ResHdr dirhdr(12, id);
- out << dirhdr << BinWord(0) << BinWord(2) << contents << dirhdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // CursorDict::PrintOn
- //
- void CursorDict::PrintOn(ostream & out) const
- {
- IconCursorID = 1;
- // output each of the cursors
- for (int i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
- }
- ///////////////////////////////////////////////////////////////
- //
- // Pattern::PrintOn
- //
- void Pattern::PrintOn(ostream & out) const
- {
- ResHdr hdr(2, id);
- out << hdr << contents << hdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // PatternDict::PrintOn
- //
- void PatternDict::PrintOn(ostream & out) const
- {
- OutputIconCursor = PixmapImage;
- // output each of the bitmaps
- for (int i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
- }
- ///////////////////////////////////////////////////////////////
- //
- // Image::PrintOn
- //
- void Image::PrintOn(ostream & out) const
- {
- ResHdr hdr(2, id);
- out << hdr << contents << hdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // ImageDict::PrintOn
- //
- void ImageDict::PrintOn(ostream & out) const
- {
- OutputIconCursor = PixmapImage;
- // output each of the bitmaps
- for (int i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
- }
- ///////////////////////////////////////////////////////////////
- //
- // DataResource::PrintOn
- //
- void DataResource::PrintOn(ostream & out) const
- {
- ResHdr hdr(10, id);
- if (!textConverted.IsEmpty() && textConverted != "DATA")
- hdr.SetType(textConverted);
- out << hdr << data << hdr;
- }
- ///////////////////////////////////////////////////////////////
- //
- // DataDict::PrintOn
- //
- void DataDict::PrintOn(ostream & out) const
- {
- // output each of the data resources
- for (int i = 0; i < GetSize(); i++)
- out << GetDataAt (i);
- }
- Control * MakeControl(Control * control, int id, int x, int y, int w, int h, char * str = NULL, int opts = 0)
- {
- control->SetID(new ResourceID(id));
- control->SetPos(new Point(x, y));
- control->SetDim(new Point(w, h));
- if (str != NULL)
- control->SetText(new PString(str));
- if (opts != 0)
- control->SetOptions(opts);
- return control;
- }
- ///////////////////////////////////////////////////////////////
- //
- // Backend
- //
- void ResourceFile::Backend(PFile & out)
- {
- // Standard resources (always included)
- if (dialogDict.GetAt(PSTD_ID_DIALOG_OPEN_DIR) == NULL) {
- Layout * layout = new Layout("PModalDialog", 2);
- layout->SetPos (new Point(60, 40));
- layout->SetDim (new Point(170, 135));
- layout->SetText(new PString(""Directory Select""));
- layout->SetID(new ResourceID(PSTD_ID_DIALOG_OPEN_DIR));
- layout->AddControl(MakeControl(new LeftText(), 1090, 6, 6, 76, 9, ""Directory &Name:""));
- layout->AddControl(MakeControl(new EditBox(), 1159, 6, 16, 92, 12));
- layout->AddControl(MakeControl(new ListBox(), 1121, 6, 35, 92, 68, NULL, Special));
- layout->AddControl(MakeControl(new LeftText(), 1091, 6, 105, 92, 9, ""Dri&ves:""));
- layout->AddControl(MakeControl(new ChoiceBox(), 1137, 6, 115, 92, 68, NULL, Special));
- layout->AddControl(MakeControl(new PushButton(), 1, 114, 6, 50, 14, ""&Select"", DefaultButtonOption));
- layout->AddControl(MakeControl(new PushButton(), 2, 114, 26, 50, 14, ""Cancel""));
- layout->AddControl(MakeControl(new PushButton(), 1038, 114, 46, 50, 14, ""&Help""));
- layout->AddControl(MakeControl(new CheckBox(), 1040, 1000, 123, 54, 12, ""&Read Only""));
- layout->AddControl(MakeControl(new EditBox(), 1152, 1000, 16, 90, 12));
- layout->AddControl(MakeControl(new LeftText(), 1089, 1000, 110, 90, 9));
- layout->AddControl(MakeControl(new ChoiceBox(), 1136, 1000, 120, 90, 60));
- layout->AddControl(MakeControl(new LeftText(), 1088, 1000, 4, 999, 9));
- layout->AddControl(MakeControl(new ListBox(), 1120, 1000, 68, 34, 67));
- dialogDict.SetAt(PSTD_ID_DIALOG_OPEN_DIR, layout);
- }
- _setmode(out.GetHandle(), _O_BINARY);
- #ifdef WIN32
- if (out.GetLength() == 0) {
- ResHdr hdr(0, 0);
- out << hdr << hdr;
- }
- #endif
- out << stringDict;
- out << menubarDict;
- out << dialogDict;
- out << iconDict;
- out << cursorDict;
- out << patternDict;
- out << imageDict;
- out << dataDict;
- }
- // End WINDOWS.CXX ////////////////////////////////////////////////////////////