pwlib.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:50k
- /*
- * 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;
- if (field[2].FindOneOf("Uu") != P_MAX_INDEX)
- styles |= Underline;
- // Then do next case
- case 2 :
- size = (PDIMENSION)field[1].AsInteger();
- // Then do next case
- case 1 :
- facename = field[0];
- }
- }
- PObject * PFont::Clone() const
- {
- return new PFont(facename, size, styles);
- }
- PObject::Comparison PFont::Compare(const PObject & obj) const
- {
- PAssert(obj.IsDescendant(PFont::Class()), PInvalidCast);
- const PFont & other = (const PFont &)obj;
- return size == other.size &&
- styles == other.styles &&
- facename == other.facename
- ? EqualTo : GreaterThan;
- }
- PCaselessString PFont::GetDescription() const
- {
- PString desc = facename + ',' + PString(PString::Unsigned, size);
- if (styles != Regular)
- desc += ',';
- if (IsBold())
- desc += 'B';
- if (IsItalic())
- desc += 'I';
- if (IsUnderlined())
- desc += 'U';
- return desc;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PFontFamily
- #if defined(_PFONTFAMILY)
- PObject::Comparison PFontFamily::Compare(const PObject & obj) const
- {
- PAssert(obj.IsDescendant(PFontFamily::Class()), PInvalidCast);
- return facename.Compare(((const PFontFamily &)obj).facename);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PCaret
- #if defined(_PCARET)
- PObject::Comparison PCaret::Compare(const PObject & obj) const
- {
- PAssert(obj.IsDescendant(PCaret::Class()), PInvalidCast);
- return caretSize.Compare(((const PCaret &)obj).caretSize);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PInteractor
- #if defined (_PINTERACTOR)
- PRect PInteractor::GetDrawingBounds(CoordinateSystem coords) const
- {
- return GetDimensions(coords);
- }
- BOOL PInteractor::IsChild(PInteractor * parent) const
- {
- for (PINDEX i = 0; i < parent->GetNumChildren(); i++) {
- if (&parent[i] == this)
- return TRUE;
- }
- return FALSE;
- }
- void PInteractor::UpdateCommandSources()
- {
- PInteractor * top = this;
- while (top->GetParent() != NULL)
- top = top->GetParent();
- top->UpdateMyCommandSources();
- }
- void PInteractor::UpdateMyCommandSources()
- {
- for (PINDEX i = 0; i < GetNumChildren(); i++)
- children[i].UpdateMyCommandSources();
- }
- void PInteractor::SetAllCursors(const PCursor & newCursor)
- {
- savedCursor = cursor;
- SetCursor(newCursor);
- switch (cursorMode) {
- case UseCurrentCursor :
- cursorMode = UseSetAllCursor;
- break;
- case UseParentCursor :
- cursorMode = UseSetAllParentCursor;
- break;
- default :
- return;
- }
- for (PINDEX i = 0; i < GetNumChildren(); i++)
- children[i].SetAllCursors(newCursor);
- }
- void PInteractor::RestoreAllCursors()
- {
- for (PINDEX i = 0; i < GetNumChildren(); i++)
- children[i].RestoreAllCursors();
- cursorMode = UseCurrentCursor;
- SetCursor(savedCursor);
- switch (cursorMode) {
- case UseSetAllCursor :
- cursorMode = UseCurrentCursor;
- break;
- case UseSetAllParentCursor :
- cursorMode = UseParentCursor;
- break;
- default :
- break;
- }
- }
- void PInteractor::_SetCaretPos(PORDINATE x, PORDINATE y,
- CoordinateSystem coords)
- {
- switch (coords) {
- case LocalCoords :
- caretPosition = PPoint(FromPixelsDX(x), FromPixelsDY(y));
- break;
- case PixelCoords :
- caretPosition = PPoint(x, y);
- break;
- case ScreenCoords :
- caretPosition = FromScreen(x, y, PixelCoords);
- }
- caret.SetPosition(this);
- }
- PPoint PInteractor::GetCaretPos(CoordinateSystem coords) const
- {
- switch (coords) {
- case LocalCoords :
- return FromPixels(caretPosition);
- case ScreenCoords :
- return ToScreen(caretPosition, PixelCoords);
- case PixelCoords:
- default:
- break;
- }
- return caretPosition;
- }
- void PInteractor::ShowCaret(BOOL show)
- {
- caretVisible += show ? -1 : 1;
- if (show && caretVisible == 0)
- caret.Show(this);
- else if (!show && caretVisible == 1)
- caret.Hide(this);
- }
- void PInteractor::SetFocusInteractor(PInteractor * interactor)
- {
- if (parent != NULL)
- parent->SetFocusInteractor(interactor);
- }
- PInteractor * PInteractor::GetFocusInteractor() const
- {
- return (parent != NULL) ? parent->GetFocusInteractor() : (PInteractor *)NULL;
- }
- PCanvas * PInteractor::StartMouseTrack(PInteractor * child, BOOL wantCanvas)
- {
- PAssert(mouseTrackInteractor == NULL, "Starting new mouse track while tracking.");
- mouseTrackInteractor = child;
- if (wantCanvas) {
- mouseTrackCanvas = new PDrawCanvas(this, TRUE, TRUE);
- mouseTrackCanvas->SetPenMode(PCanvas::InvertDst);
- mouseTrackCanvas->SetFillMode(PCanvas::InvertDst);
- }
- if (child != this)
- GrabMouse();
- return mouseTrackCanvas;
- }
- void PInteractor::OnMouseTrack(PCanvas *, const PPoint &, BOOL)
- {
- }
- void PInteractor::_OnMouseMove(PKeyCode button, const PPoint & where)
- {
- if (mouseTrackInteractor == NULL)
- OnMouseMove(button, where);
- else {
- if (HasMouse())
- mouseTrackInteractor->OnMouseTrack(mouseTrackCanvas, where, FALSE);
- else
- _OnMouseUp(button, where);
- }
- owner->DoBalloonHelp(this);
- }
- void PInteractor::_OnMouseUp(PKeyCode button, const PPoint & where)
- {
- if (mouseTrackInteractor == NULL)
- OnMouseUp(button, where);
- else {
- mouseTrackInteractor->OnMouseTrack(mouseTrackCanvas, where, TRUE);
- delete mouseTrackCanvas;
- if (this != mouseTrackInteractor)
- ReleaseMouse();
- mouseTrackInteractor = NULL;
- mouseTrackCanvas = NULL;
- }
- }
- void PInteractor::OnStartInput()
- {
- }
- BOOL PInteractor::OnEndInput()
- {
- return TRUE;
- }
- void PInteractor::OnControlNotify(PControl & control, int option)
- {
- #if defined (_PCONTROL)
- control.TransferValue(option);
- PNotifier callback = control.GetNotifier();
- if (!callback.IsNULL())
- callback(control, option);
- #endif
- }
- void PInteractor::OnSelectHelp()
- {
- if (parent != NULL)
- parent->OnSelectHelp();
- }
- PBalloon * PInteractor::OnBalloonHelp()
- {
- return (parent != NULL) ? parent->OnBalloonHelp() : (PBalloon *)NULL;
- }
- void PInteractor::ShowAll()
- {
- for (PINDEX i = 0; i < GetNumChildren(); i++)
- children[i].ShowAll();
- Show();
- }
- void PInteractor::AutoAdjustBounds(PRect & bounds, AutoAdjustType type)
- {
- PDim dim = GetDimensions(PixelCoords);
- PDIMENSION vsWidth = owner->GetVScrollWidth();
- PDIMENSION hsHeight = owner->GetHScrollHeight();
- PRect structure = GetStructureBounds(PixelCoords);
- PDim extra = structure.Dimensions() - dim;
- switch (type) {
- case AdjustBounds :
- SetPosition(bounds.Left(), bounds.Top(), TopLeftPixels, TopLeftPixels);
- SetDimensions(bounds.Width()-extra.Width(),
- bounds.Height()-extra.Height(), PixelCoords);
- break;
- case AdjustTop :
- SetPosition(bounds.Left(), bounds.Top(), TopLeftPixels, TopLeftPixels);
- SetDimensions(bounds.Width()-extra.Width(), dim.Height(), PixelCoords);
- bounds.SetTop(bounds.Top() + dim.Height() + extra.Height());
- break;
- case AdjustBottom :
- SetDimensions(bounds.Width()-extra.Width(), dim.Height(), PixelCoords);
- bounds.SetBottom(bounds.Bottom() - dim.Height() - extra.Height());
- SetPosition(bounds.Left(), bounds.Bottom(), TopLeftPixels,TopLeftPixels);
- break;
- case AdjustLeft :
- SetPosition(bounds.Left(), bounds.Top(), TopLeftPixels, TopLeftPixels);
- SetDimensions(dim.Width(), bounds.Height()-extra.Height(), PixelCoords);
- bounds.SetLeft(bounds.Left() + dim.Width() + extra.Width());
- break;
- case AdjustRight :
- SetDimensions(dim.Width(), bounds.Height()-extra.Height(), PixelCoords);
- bounds.SetRight(bounds.Right() - dim.Width() - extra.Width());
- SetPosition(bounds.Right(), bounds.Top(), TopLeftPixels, TopLeftPixels);
- break;
- case AdjustVScrollOnly :
- SetDimensions(vsWidth, bounds.Height(), PixelCoords);
- bounds.SetRight(bounds.Right() - vsWidth);
- SetPosition(bounds.Right(), bounds.Top(), TopLeftPixels, TopLeftPixels);
- break;
- case AdjustHScrollOnly :
- SetDimensions(bounds.Width(), hsHeight, PixelCoords);
- bounds.SetBottom(bounds.Bottom() - hsHeight);
- SetPosition(bounds.Left(), bounds.Bottom(), TopLeftPixels,TopLeftPixels);
- break;
- case AdjustVScrollBeforeHScroll :
- SetDimensions(vsWidth, bounds.Height() - hsHeight, PixelCoords);
- bounds.SetRight(bounds.Right() - vsWidth);
- SetPosition(bounds.Right(), bounds.Top(), TopLeftPixels,TopLeftPixels);
- break;
- case AdjustHScrollAfterVScroll :
- SetDimensions(bounds.Width(), hsHeight, PixelCoords);
- bounds.SetBottom(bounds.Bottom() - hsHeight);
- SetPosition(bounds.Left(), bounds.Bottom(), TopLeftPixels,TopLeftPixels);
- break;
- }
- }
- PORDINATE PInteractor::ToPixelsX(PORDINATE x) const
- {
- return (PORDINATE)(((long)x*(PORDINATE)font.GetAvgWidth(TRUE)+2)/4);
- }
- PORDINATE PInteractor::ToPixelsY(PORDINATE y) const
- {
- return (PORDINATE)(((long)y*(PORDINATE)font.GetHeight(TRUE)+4)/8);
- }
- PORDINATE PInteractor::FromPixelsX(PORDINATE x) const
- {
- int fontScaleX = font.GetAvgWidth(TRUE);
- return (PORDINATE)(((long)x*4+fontScaleX/2)/fontScaleX);
- }
- PORDINATE PInteractor::FromPixelsY(PORDINATE y) const
- {
- int fontScaleY = font.GetHeight(TRUE);
- return (PORDINATE)(((long)y*8+fontScaleY/2)/fontScaleY);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PInteractorLayout
- #if defined(_PINTERACTORLAYOUT)
- PControl * PInteractorLayout::GetControl(PRESOURCE_ID id)
- {
- for (PINDEX i = 0; i < GetNumChildren(); i++) {
- PInteractor & child = children[i];
- if (child.IsDescendant(PControl::Class()) &&
- ((PControl &)child).GetControlID() == id)
- return (PControl *)&child;
- }
- return NULL;
- }
- void PInteractorLayout::SetFocusInteractor(PInteractor * interactor)
- {
- focusInteractor = interactor;
- }
- PInteractor * PInteractorLayout::GetFocusInteractor() const
- {
- return focusInteractor;
- }
- void PInteractorLayout::UpdateControls()
- {
- for (PINDEX i = 0; i < GetNumChildren(); i++)
- if (children[i].IsDescendant(PControl::Class()))
- ((PControl &)children[i]).TransferValue(PControl::NotifyUpdate);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PDialog
- #if defined(_PDIALOG)
- void PDialog::Close()
- {
- OnClose();
- owner->DelayedCloseInteractor(this);
- }
- void PDialog::OnClose()
- {
- }
- void PDialog::OnOk()
- {
- Close();
- }
- void PDialog::OnCancel()
- {
- Close();
- }
- void PDialog::StdButtonPressed(PPushButton & button, INT)
- {
- if (&button == ok)
- OnOk();
- else if (&button == help)
- OnSelectHelp();
- else
- OnCancel();
- }
- void PDialog::SetStdButtons(PPushButton * okBtn,
- PPushButton * cancelBtn, PPushButton * helpBtn)
- {
- if ((ok = okBtn) != NULL)
- ok->SetNotifier(PCREATE_NOTIFIER(StdButtonPressed));
- if ((cancel = cancelBtn) != NULL)
- cancel->SetNotifier(PCREATE_NOTIFIER(StdButtonPressed));
- if ((help = helpBtn) != NULL)
- help->SetNotifier(PCREATE_NOTIFIER(StdButtonPressed));
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PFloatingDialog
- #if defined(_PFLOATINGDIALOG)
- PFloatingDialog::PFloatingDialog(PInteractor * parent)
- : PDialog(parent)
- {
- Construct();
- }
- PFloatingDialog::PFloatingDialog(PInteractor * parent, PRESOURCE_ID resID)
- : PDialog(parent, resID)
- {
- Construct();
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PModalDialog
- #if defined(_PMODALDIALOG)
- void PModalDialog::OnInit()
- {
- UpdateControls();
- Save();
- }
- void PModalDialog::OnOk()
- {
- EndModal(TRUE);
- }
- void PModalDialog::OnCancel()
- {
- Restore();
- EndModal(FALSE);
- }
- void PModalDialog::Save()
- {
- }
- void PModalDialog::Restore()
- {
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PFileDialog
- #if defined (_PFILEDIALOG)
- void PFileDialog::OnFileSelect(const PFilePath &)
- {
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // POpenFileDialog
- #if defined (_POPENFILEDIALOG)
- PINDEX POpenFileDialog::AddFileType(const PString & type)
- {
- PINDEX i = fileTypes.GetSize();
- fileTypes[i] = type;
- return i;
- }
- BOOL POpenFileDialog::OnFilterFile(const PFilePath &)
- {
- return TRUE;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PPrintDialog
- #ifdef _PPRINTDIALOG
- PPrintDialog::PPrintDialog(PInteractor * parent, PRESOURCE_ID resID)
- : PModalDialog(parent, resID)
- {
- Construct();
- }
- PPrintDialog::PPrintDialog(PInteractor * parent,
- const PPrintInfo & info, PRESOURCE_ID resID)
- : PModalDialog(parent, resID),
- printInfo(info)
- {
- Construct();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PPrinterSetupDialog
- #ifdef _PPRINTERSETUPDIALOG
- PPrinterSetupDialog::PPrinterSetupDialog(PInteractor * parent,
- PRESOURCE_ID resID)
- : PPrintDialog(parent, resID)
- {
- Construct();
- }
- PPrinterSetupDialog::PPrinterSetupDialog(PInteractor * parent,
- const PPrintInfo & info, PRESOURCE_ID resID)
- : PPrintDialog(parent, info, resID)
- {
- Construct();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PPrintJobDialog
- #ifdef _PPRINTJOBDIALOG
- PPrintJobDialog::PPrintJobDialog(PInteractor * parent, PRESOURCE_ID resID)
- : PPrintDialog(parent, resID)
- {
- Construct();
- }
- PPrintJobDialog::PPrintJobDialog(PInteractor * parent,
- const PPrintInfo & info, PRESOURCE_ID resID)
- : PPrintDialog(parent, info, resID)
- {
- Construct();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PFontDialog
- #ifdef _PFONTDIALOG
- PFontDialog::PFontDialog(PInteractor * parent,
- PPrintCanvas * pCanvas, PRESOURCE_ID resID)
- : PModalDialog(parent, resID),
- selectedFont(owner->GetSystemFont()),
- printerCanvas(pCanvas)
- {
- Construct(resID);
- }
- PFontDialog::PFontDialog(PInteractor * parent,
- const PFont & newFont, PPrintCanvas * pCanvas, PRESOURCE_ID resID)
- : PModalDialog(parent, resID),
- selectedFont(newFont),
- printerCanvas(pCanvas)
- {
- Construct(resID);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PColourDialog
- #ifdef _PCOLOURDIALOG
- PColourDialog::PColourDialog(PInteractor * parent, PRESOURCE_ID resID)
- : PModalDialog(parent, resID)
- {
- Construct(resID);
- }
- PColourDialog::PColourDialog(PInteractor * parent,
- const PColour & newColour, PRESOURCE_ID resID)
- : PModalDialog(parent, resID),
- colour(newColour)
- {
- Construct(resID);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PTitledWindow
- #if defined (_PTITLEDWINDOW)
- PDim PTitledWindow::GetMinSize(CoordinateSystem coords)
- {
- if (coords != LocalCoords)
- return minSize;
- return FromPixels(minSize);
- }
- PDim PTitledWindow::GetMaxSize(CoordinateSystem coords)
- {
- if (coords != LocalCoords)
- return maxSize;
- return ToPixels(maxSize);
- }
- PDim PTitledWindow::GetZoomSize(CoordinateSystem coords)
- {
- if (coords != LocalCoords)
- return zoomSize;
- return ToPixels(zoomSize);
- }
- void PTitledWindow::SetZoomSize(const PDim & dim, CoordinateSystem coords)
- {
- if (coords != LocalCoords)
- zoomSize = dim;
- else
- zoomSize = ToPixels(dim);
- }
- void PTitledWindow::SetFocusInteractor(PInteractor * interactor)
- {
- focusInteractor = interactor;
- }
- PInteractor * PTitledWindow::GetFocusInteractor() const
- {
- return focusInteractor;
- }
- void PTitledWindow::OnClose()
- {
- }
- BOOL PTitledWindow::Close()
- {
- if (!AllowClose(FALSE))
- return FALSE;
- owner->DelayedCloseInteractor(this);
- return TRUE;
- }
- BOOL PTitledWindow::AllowClose(BOOL)
- {
- return TRUE;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PTopLevelWindow
- #if defined (_PTOPLEVELWINDOW) && defined (_PMENUITEM)
- BOOL PTopLevelWindow::Close()
- {
- if (this != owner->GetWindow())
- return PTitledWindow::Close();
- if (!AllowClose(TRUE))
- return FALSE;
- PINDEX i;
- for (i = 0; i < GetNumChildren(); i++) {
- if (children[i].IsDescendant(PTitledWindow::Class()))
- if (!((PTitledWindow&)children[i]).AllowClose(TRUE))
- return FALSE;
- }
- for (i = 0; i < GetNumChildren(); i++) {
- if (children[i].IsDescendant(PTitledWindow::Class()))
- ((PTitledWindow&)children[i]).Close();
- }
- OnClose();
- owner->Terminate();
- return TRUE;
- }
- void PTopLevelWindow::UpdateMyCommandSources()
- {
- if (menu != NULL)
- menu->UpdateMyCommandSources();
- PTitledWindow::UpdateMyCommandSources();
- }
- void PTopLevelWindow::OnMenuStartSelect()
- {
- UpdateCommandSources();
- }
- void PTopLevelWindow::OnMenuItemSelect(PMenuItem & item)
- {
- PNotifier notifier = item.GetNotifier();
- if (!notifier.IsNULL())
- notifier(item, 0);
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PMDIFrameWindow
- #if defined(_PMDIFRAMEWINDOW)
- PRect PMDIFrameWindow::GetDocumentArea(CoordinateSystem coords) const
- {
- if (coords != LocalCoords)
- return documentArea;
- return FromPixels(documentArea);
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PBalloon
- PBalloon::PBalloon(PInteractor * parent)
- : PPopUp(parent)
- {
- Construct();
- }
- PBalloon::PBalloon(PInteractor * parent, const PString & text)
- : PPopUp(parent),
- balloonText(text)
- {
- Construct();
- SetText(text);
- }
- void PBalloon::Construct()
- {
- owner->DoBalloonHelp(this, 1); // Initialise the new balloon help window
- SetForegroundColour(owner->GetBalloonFgColour());
- SetBackgroundColour(owner->GetBalloonBkColour());
- SetFont(owner->GetBalloonFont());
- }
- void PBalloon::SetText(const PString & text)
- {
- balloonText = text;
- PDrawCanvas canvas(this);
- SetDimensions(canvas.MeasureString(balloonText) + PDim(2, 2), LocalCoords);
- PDim myDim = GetDimensions(PixelCoords);
- PRect r = parent->GetStructureBounds(ScreenCoords);
- r.Offset(r.Width()/8, r.Height() + myDim.Height()/2);
- r.SetDimensions(myDim);
- PRect scr = owner->GetScreenRect();
- if (r.Right() > scr.Right())
- r.SetX(scr.Right() - r.Width());
- if (r.Bottom() > scr.Bottom())
- r.SetY(scr.Bottom() - r.Height());
- SetPosition(r.X(), r.Y(), TopLeftScreen, TopLeftScreen);
- Show();
- }
- void PBalloon::OnRedraw(PCanvas & canvas)
- {
- canvas.DrawString(canvas.GetDrawingBounds(),
- balloonText, PCanvas::Centred|PCanvas::CentreVertical);
- }
- ///////////////////////////////////////////////////////////////////////////////
- // PScrollable & PScroller
- #if defined(_PSCROLLABLE)
- PScroller::PScroller(PInteractor * parent)
- : PInteractor(parent)
- {
- vScroll = new PVerticalScrollBar(this, PCREATE_NOTIFIER(ScrollBarNotify), 0);
- vScroll->Show();
- hScroll = new PHorizontalScrollBar(this,PCREATE_NOTIFIER(ScrollBarNotify),0);
- hScroll->Show();
- }
- PScrollable & PScroller::GetContents()
- {
- PINDEX num = GetNumChildren();
- while (num > 2) {
- num--;
- PInteractor & contents = children[num];
- if (contents.IsDescendant(PScrollable::Class()))
- return (PScrollable &)contents;
- }
- PAssertAlways("No scrollable window in scroller");
- return *(PScrollable *)this;
- }
- void PScroller::ShowAll()
- {
- GetContents().Show();
- Show();
- }
- void PScroller::_SetDimensions(PDIMENSION width, PDIMENSION height,
- CoordinateSystem coords)
- {
- PInteractor::_SetDimensions(width, height, coords);
- PRect bounds(GetDimensions(PixelCoords));
- if (hScroll->IsVisible() && vScroll->IsVisible()) {
- vScroll->AutoAdjustBounds(bounds, AdjustVScrollBeforeHScroll);
- hScroll->AutoAdjustBounds(bounds, AdjustHScrollAfterVScroll);
- }
- else if (vScroll->IsVisible())
- vScroll->AutoAdjustBounds(bounds, AdjustVScrollOnly);
- else if (hScroll->IsVisible())
- hScroll->AutoAdjustBounds(bounds, AdjustHScrollOnly);
- PScrollable & contents = GetContents();
- contents.AutoAdjustBounds(bounds);
- contents.SetScrollRange(contents.GetScrollRange());
- }
- void PScroller::ScrollBarNotify(PScrollBar &, INT option)
- {
- if (option != PScrollBar::StartTrack)
- GetContents().ScrollTo(hScroll->GetValue(), vScroll->GetValue());
- }
- PScrollable::PScrollable(PScroller * parent)
- : PInteractor(parent), scrollRange(0, 0, 10000, 10000), scaleFactor(1, 1)
- {
- }
- PRect PScrollable::GetDrawingBounds(CoordinateSystem coords) const
- {
- PRect r(scrollRange.Origin()*scaleFactor, scrollRange.Corner()*scaleFactor);
- if (coords != LocalCoords)
- return r;
- return FromPixels(r);
- }
- static void AdjustScrollBar(PORDINATE min, PORDINATE max, PORDINATE scale,
- PDIMENSION window, PScrollBar * scroll)
- {
- int winSize = window/scale;
- int maxAdjusted = max - min - winSize;
- if (maxAdjusted < min)
- maxAdjusted = min;
- scroll->SetMinimum((PSCROLLBAR_VALUE)min);
- scroll->SetMaximum((PSCROLLBAR_VALUE)maxAdjusted);
- scroll->SetSmallNudge((PSCROLLBAR_VALUE)((winSize+9)/10));
- scroll->SetLargeNudge((PSCROLLBAR_VALUE)((winSize*9+9)/10));
- }
- void PScrollable::SetScrollRange(const PRect & rect)
- {
- scrollRange = rect;
- PScroller * scroller = (PScroller *)GetParent();
- PDim dim = GetDimensions(PixelCoords);
- AdjustScrollBar(scrollRange.Left(), scrollRange.Right(),
- scaleFactor.X(), dim.Width(), scroller->hScroll);
- AdjustScrollBar(scrollRange.Top(), scrollRange.Bottom(),
- scaleFactor.Y(), dim.Height(), scroller->vScroll);
- origin.SetX(scroller->hScroll->GetValue());
- origin.SetY(scroller->vScroll->GetValue());
- }
- void PScrollable::SetScaleFactor(const PPoint & scale)
- {
- PAssert(scale.X() > 0 && scale.Y() > 0, PInvalidParameter);
- scaleFactor = scale;
- SetScrollRange(GetScrollRange());
- }
- void PScrollable::ScrollTo(const PPoint & newOrg)
- {
- PPoint oldOrigin = origin;
- PScroller * scroller = (PScroller *)GetParent();
- PNotifier notifer = scroller->hScroll->GetNotifier();
- scroller->hScroll->SetNotifier(PNotifier());
- scroller->hScroll->SetValue((PSCROLLBAR_VALUE)newOrg.X());
- scroller->hScroll->SetNotifier(notifer);
- notifer = scroller->vScroll->GetNotifier();
- scroller->vScroll->SetNotifier(PNotifier());
- scroller->vScroll->SetValue((PSCROLLBAR_VALUE)newOrg.Y());
- scroller->vScroll->SetNotifier(notifer);
- origin.SetX(scroller->hScroll->GetValue());
- origin.SetY(scroller->vScroll->GetValue());
- OnScroll(oldOrigin - origin);
- }
- void PScrollable::OnScroll(const PPoint & scrollDelta)
- {
- if (scrollDelta.X() == 0 && scrollDelta.Y() == 0)
- return;
- PDim dim = GetDimensions(PixelCoords);
- PPoint delta = scrollDelta * scaleFactor;
- if ((PDIMENSION)PABS(delta.X()) > dim.Width() ||
- (PDIMENSION)PABS(delta.Y()) > dim.Height()) {
- Invalidate();
- return;
- }
- PDrawCanvas canvas(this, TRUE);
- canvas.Scroll(delta, PRect(dim));
- if (delta.X() > 0)
- Invalidate(0, 0, (PDIMENSION)delta.X(), dim.Height(), PixelCoords);
- else if (delta.X() < 0) {
- PORDINATE x=(dim.Width()/scaleFactor.X()+scrollDelta.X())*scaleFactor.X();
- Invalidate(x, 0, dim.Width()-x, dim.Height(), PixelCoords);
- }
- if (delta.Y() > 0)
- Invalidate(0, 0, dim.Width(), (PDIMENSION)delta.Y(), PixelCoords);
- else if (delta.Y() < 0) {
- PORDINATE y=(dim.Height()/scaleFactor.Y()+scrollDelta.Y())*scaleFactor.Y();
- Invalidate(0, y, dim.Width(), dim.Height()-y, PixelCoords);
- }
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PMenuEntry
- #if defined(_PMENUENTRY)
- PMenuEntry::PMenuEntry()
- {
- itsMenu = NULL;
- }
- PMenuEntry::PMenuEntry(PSubMenu & menu, PMenuEntry * before)
- {
- itsMenu = &menu;
- if (before != NULL)
- itsMenu->entries.Insert(*before, this);
- else
- itsMenu->entries.Append(this);
- }
- PObject::Comparison PMenuEntry::Compare(const PObject & obj) const
- {
- PAssert(obj.IsDescendant(PMenuEntry::Class()), PInvalidCast);
- const PMenuEntry & other = (const PMenuEntry &)obj;
- int myPosition = GetPosition();
- int otherPosition = other.GetPosition();
- if (itsMenu != other.itsMenu)
- return itsMenu->Compare(*other.itsMenu);
- if (myPosition > otherPosition)
- return GreaterThan;
- if (myPosition < otherPosition)
- return LessThan;
- return EqualTo;
- }
- PRootMenu * PMenuEntry::GetRootMenu() const
- {
- PSubMenu * root = GetMenu();
- if (root != NULL) {
- while (root->GetMenu() != NULL)
- root = root->GetMenu();
- if (root->IsDescendant(PRootMenu::Class()))
- return (PRootMenu *)root;
- }
- return NULL;
- }
- BOOL PMenuEntry::IsMenuItemCheckGroup(const PMenuItem &) const
- {
- return FALSE;
- }
- void PMenuEntry::UpdateMyCommandSources()
- {
- // Do nothing
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PMenuItem
- #if defined(_PMENUITEM)
- PMenuItem::PMenuItem(PSubMenu & menu,
- const PString & itemName, PMenuEntry * before)
- : PMenuEntry(menu, before),
- name(itemName),
- checkPointer(NULL),
- notifyForStateUpdate(FALSE)
- {
- Construct(TRUE);
- }
- PMenuItem::PMenuItem(PSubMenu & menu, const PString & itemName,
- const PNotifier & func, BOOL update, PMenuEntry * before)
- : PMenuEntry(menu, before),
- name(itemName),
- callback(func),
- checkPointer(NULL),
- notifyForStateUpdate(update)
- {
- Construct(TRUE);
- }
- PMenuItem::PMenuItem(PSubMenu & menu, const PString & itemName,
- const PKeyCode & accel, const PNotifier & func,
- BOOL update, PMenuEntry * before)
- : PMenuEntry(menu, before),
- name(itemName),
- callback(func),
- checkPointer(NULL),
- notifyForStateUpdate(update)
- {
- accelerator = accel;
- Construct(TRUE);
- }
- PMenuItem::PMenuItem(PRESOURCE_ID newID,
- PSubMenu & menu, const char * itemName, const PKeyCode & accel)
- : PMenuEntry(menu, NULL),
- name(itemName),
- accelerator(accel),
- checkPointer(NULL),
- notifyForStateUpdate(FALSE)
- {
- menuID = newID;
- Construct(FALSE);
- }
- PMenuItem::~PMenuItem()
- {
- PRootMenu * root = GetRootMenu();
- if (root != NULL)
- root->keyedItems.SetAt(menuID, NULL);
- }
- PString PMenuItem::GetString() const
- {
- return name;
- }
- void PMenuItem::UpdateMyCommandSources()
- {
- if (notifyForStateUpdate && !callback.IsNULL())
- callback(*this, TRUE);
- }
- BOOL PMenuItem::IsMenuItemCheckGroup(const PMenuItem & groupItem) const
- {
- return groupItem.GetNotifier() == callback;
- }
- void PMenuItem::SetGroupCheck(PINDEX newItem)
- {
- PINDEX i = GetPosition();
- PSubMenu & myMenu = *itsMenu;
- while (i > 0 && myMenu[i-1].IsMenuItemCheckGroup(*this))
- i--;
- PINDEX pos = i;
- while (i < myMenu.GetSize() && myMenu[i].IsMenuItemCheckGroup(*this)) {
- ((PMenuItem &)myMenu[i]).Check((i - pos) == (newItem - 1));
- i++;
- }
- }
- void PMenuItem::SetGroupCheck()
- {
- PINDEX pos = GetPosition();
- PINDEX i = pos;
- PSubMenu & myMenu = *itsMenu;
- while (i > 0 && myMenu[i-1].IsMenuItemCheckGroup(*this))
- i--;
- while (i < myMenu.GetSize() && myMenu[i].IsMenuItemCheckGroup(*this)) {
- ((PMenuItem &)myMenu[i]).Check(i == pos);
- i++;
- }
- }
- PINDEX PMenuItem::GetGroupCheck() const
- {
- PINDEX i = GetPosition();
- PSubMenu & myMenu = *itsMenu;
- while (i > 0 && myMenu[i-1].IsMenuItemCheckGroup(*this))
- i--;
- PINDEX pos = i;
- while (i < myMenu.GetSize() && myMenu[i].IsMenuItemCheckGroup(*this)) {
- if (((PMenuItem &)myMenu[i]).IsChecked())
- return i - pos + 1;
- i++;
- }
- return 0;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PMenuSeparator
- #if defined(_PMENUSEPARATOR)
- PString PMenuSeparator::GetString() const
- {
- return "";
- }
- void PMenuSeparator::SetString(const PString &)
- {
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PSubMenu
- #if defined(_PSUBMENU)
- void PSubMenu::UpdateMyCommandSources()
- {
- for (PINDEX i = 0; i < GetSize(); i++)
- entries[i].UpdateMyCommandSources();
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PResourceString
- #if defined(_PRESOURCESTRING)
- PResourceString::PResourceString(PRESOURCE_ID resID)
- {
- Construct(resID);
- }
- PResourceString::PResourceString(PRESOURCE_ID resID, const PString & dflt)
- {
- Construct(resID);
- if (IsEmpty())
- strcpy(GetPointer(dflt.GetLength()+1), dflt);
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PApplication
- #if defined(_PAPPLICATION)
- PApplication & PApplication::Current()
- {
- PApplication & app = (PApplication &)PProcess::Current();
- PAssert(app.IsDescendant(PApplication::Class()), "Invalid PApplication class");
- return app;
- }
- void PApplication::Construct()
- {
- balloonee = NULL;
- balloon = NULL;
- blowUpTimer.SetNotifier(PCREATE_NOTIFIER(BlowUpBalloon));
- aboutMenuItemString = PResourceString(PSTD_ID_STR_ABOUT_MENU, "&About...");
- aboutDialogID = 0;
- }
- void PApplication::PassMainLoop()
- {
- }
- void PApplication::OnAbout()
- {
- if (aboutDialogID != 0) {
- PAboutDialog dlg(mainWindow, aboutDialogID);
- dlg.RunModal();
- }
- else {
- PResourceString title(PSTD_ID_STR_ABOUT_TEXT,
- "Portable Windows Library Application");
- PStringStream s;
- s << title << 'n' << GetName();
- if (!GetVersion(TRUE).IsEmpty())
- s << " v" << GetVersion(TRUE);
- if (!GetManufacturer().IsEmpty())
- s << " by " << GetManufacturer();
- #if PMEMORY_CHECK
- PMemoryHeap::DumpStatistics(s);
- #endif
- PSimpleDialog::Info(mainWindow, s);
- }
- }
- PBalloon * PApplication::DoBalloonHelp(PInteractor * interactor, int action)
- {
- switch (action) {
- case 0 :
- if (balloon == NULL)
- if (interactor != NULL)
- blowUpTimer = blowUpTimeout;
- else
- blowUpTimer = 0;
- else if (balloon != interactor && balloon->GetParent() != interactor) {
- PBalloon * oldBalloon = balloon;
- PBalloon * newBalloon = balloon;
- if (interactor != NULL)
- newBalloon = interactor->OnBalloonHelp();
- if (oldBalloon == newBalloon)
- blowUpTimer = 0;
- else {
- delete oldBalloon;
- balloon = newBalloon;
- }
- }
- balloonee = interactor;
- break;
- case 1 :
- balloon = (PBalloon *)interactor;
- }
- return balloon;
- }
- void PApplication::BlowUpBalloon(PTimer &, INT)
- {
- if (balloonee != NULL)
- balloon = balloonee->OnBalloonHelp();
- }
- void PApplication::DelayedCloseInteractor(PInteractor * interactor)
- {
- if (delayedCloseInteractors.GetObjectsIndex(interactor) == P_MAX_INDEX)
- delayedCloseInteractors.Append(interactor);
- }
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // PCommandSink
- PCommandSink::PCommandSink(const char * className, const char * commandName)
- {
- PApplication::Current().commandManager.Register(className, commandName, this);
- }
- BOOL PCommandSink::Enabled(PTitledWindow *) const
- {
- return TRUE;
- }
- PINDEX PCommandSink::Value(PTitledWindow *) const
- {
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // PCommandSource
- void PCommandSource::Call(PObject & notifier, INT extra) const
- {
- PCommandSink * sink = NULL;
- PTitledWindow * wind = (PTitledWindow *)object;
- if (wind->IsDescendant(PMDIFrameWindow::Class())) {
- PMDIDocWindow * child = ((PMDIFrameWindow *)wind)->GetActiveDocument();
- if (child != NULL) {
- unsigned ancestor = 0;
- for (;;) {
- const char * className = child->GetClass(ancestor);
- if (strcmp(className, PMDIDocWindow::Class()) == 0)
- break;
- sink = PApplication::Current().commandManager.Find(className, name);
- if (sink != NULL) {
- wind = child;
- break;
- }
- ancestor++;
- }
- }
- }
- if (sink == NULL)
- sink = PApplication::Current().commandManager.Find(wind->GetClass(),name);
- if (notifier.IsDescendant(PMenuItem::Class())) {
- if (extra) {
- PMenuItem & item = (PMenuItem &)notifier;
- item.Enable(sink != NULL && sink->Enabled(wind));
- item.SetGroupCheck(sink != NULL ? sink->Value(wind) : 0);
- }
- else if (sink != NULL)
- sink->Execute(wind);
- }
- else {
- PControl & item = (PControl &)notifier;
- switch (extra) {
- case PControl::NotifyUpdate :
- if (sink != NULL)
- sink->Value(wind);
- break;
- case PControl::NotifyEnable :
- item.Enable(sink != NULL && sink->Enabled(wind));
- break;
- case PControl::NotifyChange :
- if (sink != NULL)
- sink->Execute(wind);
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- // PCommandManager
- void PCommandManager::Register(const char * className,
- const char * commandName, PCommandSink * sink)
- {
- PString classNameString = className;
- if (commands.GetAt(classNameString) == NULL)
- commands.SetAt(classNameString, new CommandsByName);
- commands[classNameString].SetAt(PString(commandName), sink);
- }
- PCommandSink * PCommandManager::Find(const PString & className,
- const PString & commandName)
- {
- if (commands.GetAt(className) == NULL)
- return NULL;
- return (PCommandSink *)commands[className].GetAt(commandName);
- }
- #undef new
- // End Of File ///////////////////////////////////////////////////////////////