⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwlib.cxx

📁 windows mobile phone source code
💻 CXX
📖 第 1 页 / 共 4 页
字号:
/*
 * pwlib.cxx
 *
 * GUI classes.
 *
 * 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: pwlib.cxx,v $
 * Revision 1.82  2000/04/28 06:59:14  robertj
 * Fixed race condition causing asserts in ballon help.
 *
 * Revision 1.81  2000/03/04 13:08:35  robertj
 * Moved common function in open file dialog to common source file.
 *
 * Revision 1.80  1999/11/01 00:07:58  robertj
 * Changed semantics of OnClose() to be the same as PTitledWindow
 *
 * Revision 1.79  1999/08/07 07:13:23  robertj
 * Fixed problems with "balloon help" text popup.
 *
 * Revision 1.78  1999/03/29 03:39:55  robertj
 * Changed semantics of PTitledWindow::OnClose() function.
 *
 * Revision 1.77  1999/03/09 10:30:19  robertj
 * Fixed ability to have PMEMORY_CHECK on/off on both debug/release versions.
 *
 * Revision 1.76  1998/12/02 03:50:11  robertj
 * Unix compatibility changes
 *
 * Revision 1.75  1998/12/01 13:01:10  robertj
 * new directory structure.
 * Unix version
 *
 * Revision 1.74  1998/12/01 11:41:49  craigs
 * Remove warnings under GCC
 *
 * Revision 1.73  1998/10/15 11:32:52  robertj
 * New memory leak detection system.
 *
 * Revision 1.72  1998/10/13 14:06:37  robertj
 * Complete rewrite of memory leak detection code.
 *
 * Revision 1.71  1998/09/23 06:29:54  robertj
 * Added open source copyright license.
 *
 * Revision 1.70  1998/09/22 15:06:54  robertj
 * Fixed confusion in Font Dialog, variable at different levels with same name.
 *
 * Revision 1.69  1998/09/14 12:43:27  robertj
 * Fixed standard "about" dialog
 *
 * Revision 1.68  1997/04/27 05:50:22  robertj
 * DLL support.
 *
 * Revision 1.67  1996/06/28 13:23:21  robertj
 * Temporary disable of balloon help under NT until thread problem fixed.
 *
 * Revision 1.66  1996/06/03 09:59:30  robertj
 * Fixed coordinate system for caret position.
 *
 * Revision 1.65  1996/04/30 12:33:56  robertj
 * Changed "inPixels" boolean to enum for three coordinate systems.
 *
 * Revision 1.64  1996/01/28 02:52:06  robertj
 * Added assert into all Compare functions to assure comparison between compatible objects.
 *
 * Revision 1.63  1995/12/23 03:42:30  robertj
 * Changed version numbers.
 *
 * Revision 1.62  1995/12/10 11:41:44  robertj
 * Changed default default OnAbout() function to have user specified dialog.
 *
 * Revision 1.61  1995/11/20 11:04:52  robertj
 * Fixed bug in scrolling twice on scroll bar click.
 *
 * Revision 1.60  1995/10/14 15:10:14  robertj
 * Added function to update all control values from data pointers.
 *
 * Revision 1.58  1995/08/24 12:37:04  robertj
 * Added standard colours for balloon help windows.
 * Added UpdateCommandSources() to menu start selection.
 *
 * Revision 1.57  1995/08/12 22:34:48  robertj
 * Changed balloon help font to something more portable.
 * Added resID parameter passing to colour dialog Construct() function.
 *
 * Revision 1.56  1995/07/31 12:09:53  robertj
 * Drag track documentation and semantic adjustment.
 * Split off pop up window from balloon.
 *
 * Revision 1.55  1995/07/02 01:22:09  robertj
 * Added drag tracking support.
 * Moved function to .cxx file when fixed bug.
 *
 * Revision 1.54  1995/06/04 12:42:25  robertj
 * Redesign of caret driver functions (made a lot more common).
 * Fixed order of initialisers for GNU.
 *
 * Revision 1.53  1995/04/25 11:11:40  robertj
 * Moved functions to .cxx file to avoid triadic compiler problems.
 * Fixed incorrect parameter on colour component virtual functions.
 *
 * Revision 1.52  1995/04/22 00:51:41  robertj
 * Fixed bug in balloon help for balloon help in a balloon help interactor.
 *
 * Revision 1.51  1995/04/03 11:27:43  robertj
 * Fixed balloon help window so doesn't flash main window.
 *
 * Revision 1.50  1995/04/02 09:27:32  robertj
 * Added "balloon" help.
 *
 * Revision 1.49  1995/02/22 10:54:05  robertj
 * Stopped memory leak by removing stupid mod.
 * ./
 *
 * Revision 1.48  1995/02/22  10:50:38  robertj
 * Changes required for compiling release (optimised) version.
 *
 * Revision 1.47  1995/02/19  04:14:38  robertj
 * Changed font constructor to be more general PString.
 * Added dynamically linked command processing.
 * Added AllowClose() function for PTitledWindow descendents.
 *
 * Revision 1.46  1995/02/05  00:52:17  robertj
 * Fixed default About box, using resource string and memory stats dump.
 *
 * Revision 1.45  1995/01/27  11:15:45  robertj
 * Added description string.
 * Changed face name strings to be caseless.
 *
 * Revision 1.44  1995/01/22  07:29:16  robertj
 * Added font description string.
 * Added font & colour standard dialogs.
 *
 * Revision 1.43  1995/01/21  05:16:27  robertj
 * Modified ShowAll so PScrollable does not change show state of scroll bars..
 *
 * Revision 1.42  1995/01/18  09:03:18  robertj
 * Fixed bug for having multiple top level windows and all closing application.
 *
 * Revision 1.41  1995/01/15  04:57:51  robertj
 * Fixed global cursor set function.
 * Added memory stats to default About box.
 *
 * Revision 1.40  1995/01/07  04:39:47  robertj
 * Redesigned font enumeration code and changed font styles.
 *
 * Revision 1.39  1995/01/06  10:44:01  robertj
 * Changed PRealFont usage from pointer to reference.
 *
 * Revision 1.38  1995/01/02  12:25:48  robertj
 * Added global cursor setting for wait cursor.
 *
 * Revision 1.37  1994/12/21  11:54:21  robertj
 * Documentation and variable normalisation.
 * Fixed bad behaviour in closing PTopLevelWindow
 *
 * Revision 1.36  1994/12/17  01:22:35  robertj
 * Changed semantics of file filering in standard file dialogs.
 *
 * Revision 1.35  1994/12/14  11:17:19  robertj
 * Changed PDIMENSION to be unsigned causing untold number of changes.
 *
 * Revision 1.34  1994/11/19  00:04:38  robertj
 * Removed variable argument list binding for menus and controls.
 * Added clear standard colour.
 *
 * Revision 1.33  1994/11/01  11:56:18  robertj
 * Rearranged stdarg stuff to get over compiler wierdness.
 *
 * Revision 1.32  1994/10/30  11:47:14  robertj
 * Changed mechanism for doing notification callback functions.
 *
 * Revision 1.31  1994/10/24  00:05:46  robertj
 * Fixed bug in dialogs not setting value of first control.
 *
 * Revision 1.30  1994/10/23  03:47:49  robertj
 * Changed colours to have 8 bit components.
 * Completed PScrollable implementation.
 *
 * Revision 1.29  1994/09/25  10:52:58  robertj
 * Removed PNULL_MENU_NOTIFY
 *
 * Revision 1.28  1994/08/21  23:43:02  robertj
 * Added delayed close of interactors to avoid the "delete this" problem.
 *
 * Revision 1.27  1994/08/01  03:41:24  robertj
 * Use of PNEW instead of new for heap debugging. Need undef for Unix end.
 *
 * Revision 1.26  1994/07/27  05:58:07  robertj
 * Synchronisation.
 *
 * Revision 1.25  1994/07/17  10:46:06  robertj
 * Adjusted menu handling so can have orphan sub menus.
 *
 * Revision 1.24  1994/07/02  03:03:49  robertj
 * Time interval and timer redesign.
 *
 * Revision 1.23  1994/06/25  11:55:15  robertj
 * Unix version synchronisation.
 *
 * Revision 1.22  1994/04/20  12:17:44  robertj
 * assert changes
 *
 * Revision 1.21  1994/04/03  08:34:18  robertj
 * Added help and focus functionality.
 *
 * Revision 1.20  1994/04/01  14:04:23  robertj
 * Added OnInit function to all modal dialogs.
 *
 * Revision 1.19  1994/03/07  07:47:00  robertj
 * Major upgrade
 *
 * Revision 1.18  1994/01/03  04:42:23  robertj
 * Mass changes to common container classes and interactors etc etc etc.
 *
 * Revision 1.17  1993/12/31  06:54:17  robertj
 * Made inlines optional for debugging purposes.
 * Added PImgIcon class.
 *
 * Revision 1.16  1993/12/29  04:41:26  robertj
 * Mac port.
 *
 * Revision 1.15  1993/12/24  04:34:31  robertj
 * G++ warning elimination.
 *
 * Revision 1.14  1993/12/24  04:20:52  robertj
 * Mac CFront port.
 *
 * Revision 1.13  1993/12/16  09:22:11  robertj
 * Fixed problems with callback function.
 *
 * Revision 1.12  1993/12/16  06:20:57  robertj
 * Changes to callback function definition due to GCC.
 *
 * Revision 1.11  1993/12/15  21:10:10  robertj
 * Use new function for container class reference count.
 *
 * Revision 1.10  1993/12/04  05:21:26  robertj
 * Moved code from pwlib.inl to reduce its size.
 *
 * Revision 1.9  1993/12/01  16:09:05  robertj
 * Windows NT port.
 *
 * Revision 1.8  1993/11/20  17:26:28  robertj
 * PCanvasState class creation and integration.
 * PPoint and PRect ancestror class becoming private.
 * Shape classes implementation.
 *
 * Revision 1.7  1993/08/27  18:17:47  robertj
 * Added canvas function for drawing bevelled 3D areas.
 * Added timer support.
 * Added group checking of menu items.
 * Fixed some CFront compatibility problems.
 *
 * Revision 1.6  1993/08/24  00:27:59  robertj
 * Rearrangement of pushbutton classes.
 * Added Grey standard colour.
 * Added inPixels parameter to the validate.invalidate functions.
 *
 * Revision 1.5  1993/08/21  17:09:50  robertj
 * Added function to allow setting of menus whenever it is selected.
 *
 * Revision 1.4  1993/08/21  01:50:33  robertj
 * Made Clone() function optional, default will assert if called.
 *
 * Revision 1.3  1993/08/21  01:07:35  robertj
 * Fission of file into bars.cxx & control.cxx
 *
 * Revision 1.2  1993/08/20  21:26:09  robertj
 * Number edit box common code added.
 *
 * Revision 1.7  1993/08/10  12:58:38  robertj
 * Fixed bug in DrawString(), right adjusted text.
 * Very small optimisation of PStringListBox DrawItem() function.
 *
 * Revision 1.6  1993/07/15  04:29:39  robertj
 * Adjustments to the 3D shadowing effect on buttons/status bar etc.
 *
 * Revision 1.5  1993/07/14  12:41:52  robertj
 * Fixed comment leader.
 *
 * Revision 1.4  1993/07/14  02:08:18  robertj
 * Fixed header comment for RCS logs.
 */

#ifdef __GNUC__
#pragma implementation "commands.h"
#pragma implementation "scrollab.h"
#pragma implementation "balloon.h"
#endif

#include <pwlib.h>

class PAboutDialog : public PModalDialog
{
  PCLASSINFO(PAboutDialog, PModalDialog)
  public:
    PAboutDialog(PInteractor * parent, PRESOURCE_ID id)
      : PModalDialog(parent, id)
    {
      ConstructEnd(id);
      for (PINDEX i = 0; i < GetNumChildren(); i++) {
        if (children[i].IsDescendant(PPushButton::Class())) {
          SetStdButtons((PPushButton *)&children[i]);
          break;
        }
      }
    }
};


#define new PNEW


//////////////////////////////////////////////////////////////////////////////
// PKeyCode

#if defined(_PKEYCODE)

PObject * PKeyCode::Clone() const
{
  return new PKeyCode(value, modifiers);
}


PObject::Comparison PKeyCode::Compare(const PObject & obj) const
{
  PAssert(obj.IsDescendant(PKeyCode::Class()), PInvalidCast);
  const PKeyCode & other = (const PKeyCode &)obj;
  if (value == other.value && modifiers == other.modifiers)
    return EqualTo;
  return value < other.value ? LessThan : GreaterThan;
}


#endif


//////////////////////////////////////////////////////////////////////////////
// PColour

#if defined(_PCOLOUR)

PColour::PColour(BYTE r, BYTE g, BYTE b, BYTE a)
{
  component[RedComponent] = r;
  component[GreenComponent] = g;
  component[BlueComponent] = b;
  component[AlphaComponent] = a;
}


PColour::PColour(StandardColours col)
{
  static BYTE stdCol[NumStandardColours][NumComponents] = {
    { 0,    0,    0,    0xff }, // Black
    { 0xff, 0,    0,    0xff }, // Red
    { 0,    0xff, 0,    0xff }, // Green
    { 0xff, 0xff, 0,    0xff }, // Yellow
    { 0,    0,    0xff, 0xff }, // Blue
    { 0xff, 0,    0xff, 0xff }, // Magenta
    { 0,    0xff, 0xff, 0xff }, // Cyan
    { 0xff, 0xff, 0xff, 0xff }, // White
    { 0x40, 0x40, 0x40, 0xff }, // Grey
    { 0x80, 0x80, 0x80, 0xff }, // Grey
    { 0xC0, 0xC0, 0xC0, 0xff }, // Grey
    { 0,    0,    0,    0    }  // Clear
  };

  PAssert(col < NumStandardColours, PInvalidParameter);
  for (PINDEX i = 0; i < NumComponents; i++)
    component[i] = stdCol[col][i];
}

PObject * PColour::Clone() const
{
  return new PColour(component[RedComponent],  component[GreenComponent],
                     component[BlueComponent], component[AlphaComponent]);
}


PObject::Comparison PColour::Compare(const PObject & obj) const
{
  PAssert(obj.IsDescendant(PColour::Class()), PInvalidCast);
  const PColour & other = (const PColour &)obj;
  
  for (PINDEX i = 0; i < NumComponents; i++)
    if (component[i] != other.component[i])
      return GreaterThan;
  
  return EqualTo;
}


PINDEX PColour::HashFunction() const
{
  
  return (PINDEX)((component[RedComponent]^0x55) +
                  (component[GreenComponent]^0xaa) +
                  (component[BlueComponent]^0xc3))%51;
}


void PColour::SetRed(BYTE r)
{
  component[RedComponent] = r;
}


void PColour::SetGreen(BYTE g)
{
  component[GreenComponent] = g;
}


void PColour::SetBlue(BYTE b)
{
  component[BlueComponent] = b;
}


void PColour::SetAlpha(BYTE a)
{
  component[AlphaComponent] = a;
}


long PColour::GetDistance(const PColour & other) const
{
  long sum = 0;
  for (PINDEX i = 0; i < AlphaComponent; i++)
    sum += component[i]*other.component[i];
  return sum;
}


#endif


//////////////////////////////////////////////////////////////////////////////
// PRealColour

#if defined(_PREALCOLOUR)

void PRealColour::SetRed(BYTE)
{
  PAssertAlways(PUnimplementedFunction);
}


void PRealColour::SetGreen(BYTE)
{
  PAssertAlways(PUnimplementedFunction);
}


void PRealColour::SetBlue(BYTE)
{
  PAssertAlways(PUnimplementedFunction);
}


void PRealColour::SetAlpha(BYTE)
{
  PAssertAlways(PUnimplementedFunction);
}


#endif


//////////////////////////////////////////////////////////////////////////////
// PFont

#if defined(_PFONT)

PFont::PFont(const PString & theFacename, PDIMENSION theSize, WORD theStyle)
  : facename(theFacename)
{
  size = theSize;
  styles = theStyle;
}


void PFont::Construct(const PCaselessString & fontDescription)
{
  size = 12;
  styles = Regular;

  PStringArray field = fontDescription.Tokenise(",");

  switch (field.GetSize()) {
    case 3 :
      if (field[2].FindOneOf("Bb") != P_MAX_INDEX)
        styles |= Bold;
      if (field[2].FindOneOf("Ii") != P_MAX_INDEX)
        styles |= Italic;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -