control.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:33k
- /*
- * control.cxx
- *
- * Control interactor 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: control.cxx,v $
- * Revision 1.55 1999/11/23 05:24:32 robertj
- * Moved function from platform independent to platform dependent files.
- *
- * Revision 1.54 1999/11/23 05:08:47 craigs
- * Moved PTextButton::DefaultDimensions to platform dependent code
- *
- * Revision 1.53 1999/11/16 06:51:41 robertj
- * Created PCustomListBox to allow motif native code PStringListBox implementation
- *
- * Revision 1.52 1999/11/16 05:23:22 craigs
- * Changed for creation of PCustomListBox class
- *
- * Revision 1.51 1999/09/05 14:39:22 robertj
- * GNU 2.95 compatibility
- *
- * Revision 1.50 1999/08/07 07:13:23 robertj
- * Fixed problems with "balloon help" text popup.
- *
- * Revision 1.49 1998/09/23 06:29:37 robertj
- * Added open source copyright license.
- *
- * Revision 1.48 1998/09/14 12:41:52 robertj
- * Added tab stops to string output in list box.
- *
- * Revision 1.47 1998/02/24 23:07:27 robertj
- * Fixed background colour for static text (another constructor) on simple dialogs
- *
- * Revision 1.46 1998/02/06 04:00:16 robertj
- * Fixed colour of controls, again!
- *
- * Revision 1.45 1996/11/04 03:39:56 robertj
- * Fixed default dimensions of check box and radio button.
- *
- * Revision 1.44 1996/04/30 12:33:50 robertj
- * Changed "inPixels" boolean to enum for three coordinate systems.
- *
- * Revision 1.43 1995/11/09 12:20:34 robertj
- * Added static (filled) rectange control.
- *
- * Revision 1.42 1995/10/14 15:08:24 robertj
- * Added addition of colection as strings to box.
- *
- * Revision 1.41 1995/08/12 22:33:12 robertj
- * Moved OnEndInput() function to platform dependent code.
- *
- * Revision 1.40 1995/06/17 00:46:42 robertj
- * Added missing constructor for PTextButton.
- *
- * Revision 1.39 1995/06/04 12:40:18 robertj
- * Removed non-portable function ltoa.
- *
- * Revision 1.38 1995/04/25 11:29:19 robertj
- * Fixed Borland compiler warnings.
- *
- * Revision 1.37 1995/04/02 09:27:29 robertj
- * Added "balloon" help.
- *
- * Revision 1.36 1995/02/19 04:19:20 robertj
- * Added dynamically linked command processing.
- *
- * Revision 1.35 1995/02/05 00:50:42 robertj
- * Had to change variable name "small" for MSVC 2.0
- * Added notification of end input.
- *
- * Revision 1.34 1995/01/27 11:13:18 robertj
- * Changed alignment mask from enum to int.
- * Changed state of checkbox from CheckValue to BOOL.
- *
- * Revision 1.33 1995/01/18 10:58:15 robertj
- * No need for constructors of images.
- *
- * Revision 1.32 1995/01/18 09:02:23 robertj
- * Added separate image icon for enabled and disabled button.
- *
- * Revision 1.31 1995/01/06 10:43:56 robertj
- * Changed PRealFont usage from pointer to reference.
- *
- * Revision 1.30 1995/01/01 01:06:18 robertj
- * Incorrect position of text in list boxes
- *
- * Revision 1.29 1994/12/21 11:58:24 robertj
- * Documentation and variable normalisation.
- *
- * Revision 1.28 1994/12/14 11:17:15 robertj
- * Changed PDIMENSION to be unsigned causing untold number of changes.
- *
- * Revision 1.27 1994/12/05 11:27:16 robertj
- * Changed 3 way check box constructor to be similar to other constructors.
- *
- * Revision 1.26 1994/11/19 00:01:04 robertj
- * Added notifier & value to main PControl constructor
- *
- * Revision 1.25 1994/10/30 11:47:11 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.24 1994/08/21 23:43:02 robertj
- * Added undef of new for Unix build system.
- *
- * Revision 1.23 1994/07/27 05:58:07 robertj
- * Synchronisation.
- *
- * Revision 1.22 1994/07/02 03:03:49 robertj
- * Fixed bug in list box construction.
- *
- * Revision 1.21 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.20 1994/04/20 12:17:44 robertj
- * assert changes
- *
- * Revision 1.19 1994/04/11 14:09:03 robertj
- * Fixed bug in static icon, not being set on windows platforms.
- *
- * Revision 1.18 1994/04/03 08:34:18 robertj
- * Added help and focus functionality.
- *
- * Revision 1.17 1994/04/01 14:01:49 robertj
- * Added PControl level DefaultDimensions.
- * Moved PStringListBox constructor to platform specific sections.
- *
- * Revision 1.16 1994/03/07 07:47:00 robertj
- * Major upgrade
- *
- * Revision 1.15 1994/01/15 02:53:45 robertj
- * Moved control constructors to common code and added platform dependent Construct() function.
- *
- * Revision 1.14 1993/12/31 06:53:48 robertj
- * Added PImgIcon class.
- *
- * Revision 1.13 1993/12/16 06:21:00 robertj
- * Cannot do triadic conditionals with objects in GCC.
- *
- * 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
- * Changed group in radio buttons to use containers reference system.
- * Added optional deletion of objects in a list box.
- *
- * Revision 1.10 1993/12/04 05:23:06 robertj
- * Moved code from pwlib.inl
- *
- * Revision 1.9 1993/12/01 16:09:05 robertj
- * Windows NT port.
- *
- * Revision 1.8 1993/11/20 17:26:28 robertj
- * Change of PImage to PPixels in picture buttons.
- *
- * Revision 1.7 1993/09/29 03:06:30 robertj
- * Moved PListBox contructor to platform specific modules.
- * Removed cursor setting for PComboBoxes
- *
- * Revision 1.6 1993/09/27 16:35:25 robertj
- * Removed special constructor for dialog resource loading.
- * Fixed standard string list item draw function colour setting.
- * Fixed graying of standard push buttons.
- *
- * Revision 1.5 1993/08/31 03:38:02 robertj
- * Added #if protection for platforms that haven't implemented everything yet.
- *
- * Revision 1.4 1993/08/24 00:27:59 robertj
- * Rearranged push button classes and reimplemented text/image buttons.
- *
- * Revision 1.3 1993/08/21 17:09:50 robertj
- * Fixed cursor setting in text editing controls
- *
- * Revision 1.2 1993/08/21 01:50:33 robertj
- * Made Clone() function optional, default will assert if called.
- *
- * Revision 1.1 1993/08/21 01:07:35 robertj
- * Initial revision
- *
- */
- #include <pwlib.h>
- #include <ctype.h>
- #define new PNEW
- //////////////////////////////////////////////////////////////////////////////
- // PControl
- #if defined (_PCONTROL)
- void PControl::DefaultDimensions()
- {
- }
- void PControl::TransferValue(int)
- {
- }
- void PControl::UpdateMyCommandSources()
- {
- if (notifyForStateUpdate && !callback.IsNULL())
- callback(*this, NotifyEnable);
- }
- PBalloon * PControl::OnBalloonHelp()
- {
- if (balloonHelpText.IsEmpty())
- return parent->OnBalloonHelp();
- return new PBalloon(this, balloonHelpText);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PStaticText
- #if defined (_PSTATICTEXT)
- PStaticText::PStaticText(PInteractor * parent, int align)
- : PNamedControl(parent)
- {
- alignment = align;
- foregroundColour = parent->GetForegroundColour();
- backgroundColour = parent->GetBackgroundColour();
- }
- PStaticText::PStaticText(PInteractor * parent, const PString & str, int align)
- : PNamedControl(parent)
- {
- alignment = align;
- foregroundColour = parent->GetForegroundColour();
- backgroundColour = parent->GetBackgroundColour();
- SetName(str);
- DefaultDimensions();
- }
- void PStaticText::DefaultDimensions()
- {
- PDrawCanvas canvas(this);
- PDim dim = canvas.MeasureString(GetName());
- dim += PDim(1,1);
- PDIMENSION maxX = owner->GetScreenRect().Width()*4/5;
- if (dim.Width() > maxX)
- dim.SetWidth(maxX);
- SetDimensions(dim, LocalCoords);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PStaticBox
- #if defined (_PSTATICBOX)
- PStaticBox::PStaticBox(PInteractor * parent)
- : PNamedControl(parent)
- {
- foregroundColour = parent->GetForegroundColour();
- backgroundColour = parent->GetBackgroundColour();
- }
- PStaticBox::PStaticBox(PInteractor * parent, const PString & str)
- : PNamedControl(parent, str, PNotifier(), NULL)
- {
- foregroundColour = parent->GetForegroundColour();
- backgroundColour = parent->GetBackgroundColour();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PStaticIcon
- #if defined (_PSTATICICON)
- PStaticIcon::PStaticIcon(PInteractor * parent, const PIcon & icn)
- : PControl(parent, PNotifier(), NULL), icon(icn)
- {
- SetIcon(icon);
- DefaultDimensions();
- foregroundColour = parent->GetForegroundColour();
- backgroundColour = parent->GetBackgroundColour();
- }
- void PStaticIcon::DefaultDimensions()
- {
- SetDimensions(icon.GetDimensions(), PixelCoords);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PStaticRect
- #if defined (_PSTATICRECT)
- PStaticRect::PStaticRect(PInteractor * parent)
- : PControl(parent, PNotifier(), NULL)
- {
- SetBackgroundColour(owner->GetWindowFgColour());
- }
- PStaticRect::PStaticRect(PInteractor * parent, const PColour & colour)
- : PControl(parent, PNotifier(), NULL)
- {
- SetBackgroundColour(colour);
- }
- PStaticRect::PStaticRect(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, void * valuePtr)
- : PControl(parent, ctlID, notify, valuePtr)
- {
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PEditBox
- #if defined(_PEDITBOX)
- BOOL PEditBox::OnEndInput()
- {
- parent->OnControlNotify(*this, PEditBox::EndEdit);
- return TRUE;
- }
- void PEditBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetText(*(PString *)valuePointer);
- else
- *(PString *)valuePointer = GetText();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PNumberEditBox
- #if defined(_PNUMBEREDITBOX)
- PNumberEditBox::PNumberEditBox(PInteractor * parent)
- : PEditBox(parent)
- {
- nudgeUp = new NudgeButton(this, TRUE);
- nudgeUp->SetNotifier(PCREATE_NOTIFIER(Nudged));
- nudgeDown = new NudgeButton(this, FALSE);
- nudgeDown->SetNotifier(PCREATE_NOTIFIER(Nudged));
- }
- void PNumberEditBox::Nudged(NudgeButton & control, INT)
- {
- if (&control == nudgeUp)
- AddNudge();
- else
- SubtractNudge();
- }
- PNumberEditBox::NudgeButton::NudgeButton(PNumberEditBox * parent, BOOL isUp)
- : PPushButton(parent),
- up(isUp)
- {
- }
- void PNumberEditBox::NudgeButton::OnDrawFace(PCanvas & canvas,
- const PRect & rect, BOOL hasFocus, BOOL)
- {
- if (up) {
- canvas.SetCurrentPosition(rect.Left(), rect.Bottom());
- canvas.DrawLine((rect.Left() + rect.Right())/2, rect.Top());
- canvas.DrawLine(rect.Right(), rect.Bottom());
- canvas.DrawLine(rect.Left(), rect.Bottom());
- }
- else {
- canvas.SetCurrentPosition(rect.Left(), rect.Top());
- canvas.DrawLine((rect.Left() + rect.Right())/2, rect.Bottom());
- canvas.DrawLine(rect.Right(), rect.Top());
- canvas.DrawLine(rect.Left(), rect.Top());
- }
- if (hasFocus)
- canvas.DrawFocusRect(rect);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PIntegerEditBox
- #if defined(_PINTEGEREDITBOX)
- PIntegerEditBox::PIntegerEditBox(PInteractor * parent,
- long min, long max, long val, long ndg, BYTE numBase)
- : PNumberEditBox(parent)
- {
- SetMinimum(min);
- SetMaximum(max);
- SetNudge(ndg);
- SetBase(numBase);
- SetValue(val);
- }
- BOOL PIntegerEditBox::OnEndInput()
- {
- parent->OnControlNotify(*this, PEditBox::EndEdit);
- long val = GetValue();
- if (val < minimum || val > maximum) {
- PSound::Beep();
- return FALSE;
- }
- return TRUE;
- }
- void PIntegerEditBox::OnKeyInput(const PString & str)
- {
- char c = (char)toupper(str[0]);
- char maxletter = '@';
- char maxdigit = (char)(base+'0'-1);
- if (maxdigit > '9') {
- maxdigit = '9';
- maxletter = (char)(base-10+'A'-1);
- }
- if (iscntrl(c) || c == '-' || c == '+' ||
- (c >= '0' && c <= maxdigit) || (c >= '0' && c <= maxletter))
- PNumberEditBox::OnKeyInput(str);
- }
- void PIntegerEditBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetValue(*(long *)valuePointer);
- else if (option == EndEdit)
- *(long *)valuePointer = GetValue();
- }
- void PIntegerEditBox::AddNudge()
- {
- SetValue(GetValue()+nudge);
- }
- void PIntegerEditBox::SubtractNudge()
- {
- SetValue(GetValue()-nudge);
- }
- void PIntegerEditBox::SetValue(long val)
- {
- if (val < minimum)
- val = minimum;
- else if (val > maximum)
- val = maximum;
- PString str(PString::Signed, val, base);
- SetText(str);
- }
- long PIntegerEditBox::GetValue() const
- {
- return GetText().AsInteger(base);
- }
- void PIntegerEditBox::SetNudge(long val)
- {
- PAssert(val > 0, PInvalidParameter);
- nudge = val;
- }
- void PIntegerEditBox::SetBase(BYTE val)
- {
- PAssert(val >= 2 && val <= 36, PInvalidParameter);
- base = val;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PFloatEditBox
- #if defined(_PFLOATEDITBOX)
- PFloatEditBox::PFloatEditBox(PInteractor * parent,
- double min, double max, double val, double ndg, unsigned decs)
- : PNumberEditBox(parent)
- {
- SetMinimum(min);
- SetMaximum(max);
- SetNudge(ndg);
- SetDecimals(decs);
- SetValue(val);
- }
- BOOL PFloatEditBox::OnEndInput()
- {
- parent->OnControlNotify(*this, PEditBox::EndEdit);
- double val = GetValue();
- if (val < minimum || val > maximum) {
- PSound::Beep();
- return FALSE;
- }
- return TRUE;
- }
- void PFloatEditBox::OnKeyInput(const PString & str)
- {
- char c = str[0];
- if (iscntrl(c) || isdigit(c) ||
- c == '-' || c == '+' || c == '.' || toupper(c) == 'E')
- PNumberEditBox::OnKeyInput(str);
- }
- void PFloatEditBox::AddNudge()
- {
- SetValue(GetValue()+nudge);
- }
- void PFloatEditBox::SubtractNudge()
- {
- SetValue(GetValue()-nudge);
- }
- void PFloatEditBox::SetValue(double val)
- {
- if (val < minimum)
- val = minimum;
- else if (val > maximum)
- val = maximum;
- SetText(psprintf(psprintf("%%0.%dg", decimals), (double)val));
- }
- double PFloatEditBox::GetValue() const
- {
- return GetText().AsReal();
- }
- void PFloatEditBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetValue(*(double *)valuePointer);
- else if (option == EndEdit)
- *(double *)valuePointer = GetValue();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PPushButton
- #if defined(_PPUSHBUTTON)
- PPushButton::PPushButton(PInteractor * parent, ButtonType deflt)
- : PNamedControl(parent),
- defaultButton(deflt == DefaultButton)
- {
- Construct();
- }
- PPushButton::PPushButton(PInteractor * parent,
- const PString & name, ButtonType deflt, const PNotifier & notify)
- : PNamedControl(parent, name, notify, NULL),
- defaultButton(deflt == DefaultButton)
- {
- Construct();
- }
- PRect PPushButton::DrawButtonSurround(PCanvas & canvas, BOOL isSelected)
- {
- canvas.SetMappingRect(canvas.GetViewportRect());
- PRect bounds = canvas.GetDrawingBounds();
- canvas.SetPenFgColour(owner->GetButtonFgColour());
- canvas.SetFillFgColour(owner->GetButtonBkColour());
- canvas.DrawRoundRect(bounds, 2, 2);
- PDim border = owner->GetBorderSize();
- PDim border2 = border * 2;
- bounds.Inflate(-(PORDINATE)border.Width(), -(PORDINATE)border.Height());
- if (defaultButton) {
- canvas.DrawRect(bounds);
- bounds.Inflate(-(PORDINATE)border.Width(), -(PORDINATE)border.Height());
- }
- canvas.SetPenFgColour(owner->GetButtonShadowColour());
- if (!isSelected) {
- canvas.SetPenWidth(border.Height());
- canvas.DrawLine(
- bounds.Left(), bounds.Bottom()-border.Height(),
- bounds.Right()-border.Width(), bounds.Bottom()-border.Height());
- canvas.DrawLine(
- bounds.Left()+border.Width(), bounds.Bottom()-border2.Height(),
- bounds.Right()-border.Width(), bounds.Bottom()-border2.Height());
- canvas.SetPenWidth(border.Width());
- canvas.DrawLine(
- bounds.Right()-border.Width(), bounds.Top(),
- bounds.Right()-border.Width(), bounds.Bottom());
- canvas.DrawLine(
- bounds.Right()-border2.Width(), bounds.Top()+border.Height(),
- bounds.Right()-border2.Width(), bounds.Bottom());
- canvas.SetPenFgColour(owner->GetButtonLightingColour());
- }
- canvas.SetCurrentPosition(bounds.Left(), bounds.Bottom()-border2.Height());
- canvas.SetPenWidth(border.Width());
- canvas.DrawLine(bounds.Left(), bounds.Top());
- canvas.SetPenWidth(border.Height());
- canvas.DrawLine(bounds.Right()-border.Width(), bounds.Top());
- bounds.Inflate(-(PORDINATE)border.Width()*3, -(PORDINATE)border.Height()*3);
- if (isSelected)
- bounds.Offset(border.Width(), border.Height());
- if (IsEnabled())
- canvas.SetTextFgColour(owner->GetButtonFgColour());
- else
- canvas.SetTextFgColour(owner->GetGrayTextColour());
- canvas.SetTextBkColour(owner->GetButtonBkColour());
- return bounds;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PTextButton
- #if defined(_PTEXTBUTTON)
-
- PTextButton::PTextButton(PInteractor * parent,
- const PString & name, ButtonType deflt)
- : PPushButton(parent, name, deflt, PNotifier())
- {
- Construct();
- DefaultDimensions();
- }
- PTextButton::PTextButton(PInteractor * parent,
- const PString & name, const PNotifier & notify, ButtonType deflt)
- : PPushButton(parent, name, deflt, notify)
- {
- Construct();
- DefaultDimensions();
- }
- void PTextButton::OnDrawFace(PCanvas & canvas,
- const PRect & rect, BOOL hasFocus, BOOL)
- {
- canvas.DrawString(rect, GetName(), PCanvas::Centred|PCanvas::CentreVertical);
- if (hasFocus) {
- PDim dim = canvas.MeasureString(GetName()) + owner->GetBorderSize()*2;
- PRect r(rect.Left()+(rect.Width()-dim.Width())/2,
- rect.Top()+(rect.Height()-dim.Height())/2,
- dim.Width(), dim.Height());
- canvas.DrawFocusRect(r);
- }
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PImageButton
- #if defined(_PIMAGEBUTTON)
- PImageButton::PImageButton(PInteractor * parent, ButtonType deflt)
- : PPushButton(parent, deflt)
- {
- Construct();
- DefaultDimensions();
- }
- PImageButton::PImageButton(PInteractor *parent,
- const PImgIcon & img, ButtonType deflt)
- : PPushButton(parent, "", deflt, PNotifier()),
- enabledImage(img),
- disabledImage(img)
- {
- Construct();
- DefaultDimensions();
- }
- PImageButton::PImageButton(PInteractor *parent,
- const PImgIcon & img, const PNotifier & notify, ButtonType deflt)
- : PPushButton(parent, "", deflt, notify),
- enabledImage(img),
- disabledImage(img)
- {
- Construct();
- DefaultDimensions();
- }
- PImageButton::PImageButton(PInteractor *parent,
- const PImgIcon & enabImg,
- const PImgIcon & disabImg,
- ButtonType deflt)
- : PPushButton(parent, "", deflt, PNotifier()),
- enabledImage(enabImg),
- disabledImage(disabImg)
- {
- Construct();
- DefaultDimensions();
- }
- PImageButton::PImageButton(PInteractor *parent,
- const PImgIcon & enabImg,
- const PImgIcon & disabImg,
- const PNotifier & notify,
- ButtonType deflt)
- : PPushButton(parent, "", deflt, notify),
- enabledImage(enabImg),
- disabledImage(disabImg)
- {
- Construct();
- DefaultDimensions();
- }
- void PImageButton::DefaultDimensions()
- {
- PDim edim = enabledImage.GetDimensions();
- PDim ddim = disabledImage.GetDimensions();
- PDim dim(PMAX(edim.Width(),ddim.Width()), PMAX(edim.Height(),ddim.Height()));
- SetDimensions(dim+owner->GetBorderSize()*9, PixelCoords);
- }
- void PImageButton::OnDrawFace(PCanvas & canvas,
- const PRect & rect, BOOL hasFocus, BOOL)
- {
- canvas.SetFillFgColour(owner->GetButtonFgColour());
- canvas.SetFillBkColour(owner->GetButtonBkColour());
- PImgIcon & image = IsEnabled() ? enabledImage : disabledImage;
- PPoint pos = rect.Origin() + (rect.Dimensions() - image.GetDimensions())/2;
- canvas.DrawImgIcon(pos, image);
- if (hasFocus)
- canvas.DrawFocusRect(rect);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PCheck3WayBox
- #if defined(_PCHECK3WAYBOX)
- PCheck3WayBox::PCheck3WayBox(PInteractor * parent, CheckValues)
- : PNamedControl(parent)
- {
- Construct();
- }
- PCheck3WayBox::PCheck3WayBox(PInteractor * parent,
- const PString & name, CheckValues value)
- : PNamedControl(parent)
- {
- Construct();
- SetName(name);
- SetValue(value);
- DefaultDimensions();
- }
- PCheck3WayBox::PCheck3WayBox(PInteractor * parent,
- const PString & name, const PNotifier & notify, CheckValues value)
- : PNamedControl(parent)
- {
- Construct();
- SetName(name);
- SetValue(value);
- SetNotifier(notify);
- DefaultDimensions();
- }
- void PCheck3WayBox::DefaultDimensions()
- {
- PDrawCanvas canvas(this);
- PDim dim = canvas.MeasureString(GetName());
- dim.AddWidth(16); // Allow 4 font width left of text
- dim.AddHeight(4); // Allow 1/4 font height above and below text
- SetDimensions(dim, LocalCoords);
- }
- void PCheck3WayBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetValue(*(CheckValues *)valuePointer);
- else
- *(CheckValues *)valuePointer = GetValue();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PCheckBox
- #if defined(_PCHECKBOX)
- PCheckBox::PCheckBox(PInteractor * parent, BOOL value)
- : PCheck3WayBox(parent)
- {
- SetValue(value);
- }
- PCheckBox::PCheckBox(PInteractor * parent, const PString & name, BOOL value)
- : PCheck3WayBox(parent)
- {
- SetName(name);
- SetValue(value);
- DefaultDimensions();
- }
- PCheckBox::PCheckBox(PInteractor * parent,
- const PString & name, const PNotifier & notify)
- : PCheck3WayBox(parent)
- {
- SetName(name);
- SetNotifier(notify);
- DefaultDimensions();
- }
- void PCheckBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetValue(*(BOOL *)valuePointer);
- else
- *(BOOL *)valuePointer = GetValue();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PRadioButton
- #if defined(_PRADIOBUTTON)
- PRadioButton::PRadioButton(PInteractor * parent)
- : PNamedControl(parent)
- {
- group.DisallowDeleteObjects();
- group.Append(this);
- Construct();
- }
- PRadioButton::PRadioButton(PInteractor * parent, const PString & name)
- : PNamedControl(parent)
- {
- group.DisallowDeleteObjects();
- group.Append(this);
- Construct();
- SetName(name);
- DefaultDimensions();
- }
- PRadioButton::PRadioButton(PInteractor * parent,
- const PString & name, const PNotifier & notify)
- : PNamedControl(parent)
- {
- group.DisallowDeleteObjects();
- group.Append(this);
- Construct();
- SetName(name);
- SetNotifier(notify);
- DefaultDimensions();
- }
- PRadioButton::PRadioButton(PInteractor * parent,
- const PString & name, PRadioButton & groupButton)
- : PNamedControl(parent)
- {
- Construct();
- AddToGroup(groupButton);
- SetName(name);
- DefaultDimensions();
- }
- PRadioButton::PRadioButton(PInteractor * parent, const PString & name,
- const PNotifier & notify, PRadioButton & groupButton)
- : PNamedControl(parent)
- {
- Construct();
- AddToGroup(groupButton);
- SetName(name);
- SetNotifier(notify);
- DefaultDimensions();
- }
- void PRadioButton::AddToGroup(PRadioButton & groupButton)
- {
- group = groupButton.group;
- group.Append(this);
- }
- void PRadioButton::DefaultDimensions()
- {
- PDrawCanvas canvas(this);
- PDim dim = canvas.MeasureString(GetName());
- dim.AddWidth(16); // Allow 4 font width left of text
- dim.AddHeight(4); // Allow 1/4 font height above and below text
- SetDimensions(dim, LocalCoords); // Allow 1/4 font height above and below text
- }
- void PRadioButton::TransferValue(int option)
- {
- if (option == NotifyUpdate) {
- if (valuePointer != NULL)
- SetValue(*(PINDEX *)valuePointer);
- }
- else {
- for (PINDEX i = 0; i < group.GetSize(); i++)
- if (group[i].valuePointer != NULL)
- *(PINDEX *)group[i].valuePointer = GetValue();
- }
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PChoiceBox
- #if defined(_PCHOICEBOX)
- PChoiceBox::PChoiceBox(PInteractor * parent, StringSorting sorted)
- : PControl(parent, PNotifier(), NULL)
- {
- sort = sorted == Sorted;
- Construct();
- }
- PChoiceBox::PChoiceBox(PInteractor * parent,
- const PNotifier & notify, StringSorting sorted)
- : PControl(parent, notify, NULL)
- {
- sort = sorted == Sorted;
- Construct();
- }
- void PChoiceBox::AddStrings(const PCollection & objects)
- {
- PINDEX last = objects.GetSize() - 1;
- for (PINDEX i = 0; i <= last; i++) {
- PObject & obj = *objects.GetAt(i);
- if (obj.IsDescendant(PString::Class()))
- AddString((PString &)obj);
- else {
- PStringStream str;
- str << obj;
- AddString(str);
- }
- }
- }
- void PChoiceBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetSelection(*(PINDEX *)valuePointer);
- else
- *(PINDEX *)valuePointer = GetSelection();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PListBox
- #if defined(_PLISTBOX)
- PListBox::PListBox(PInteractor * parent,
- StringSorting sorted,
- SelectType select,
- PDIMENSION columnWidth,
- BOOL deleteObj)
- : PControl(parent, PNotifier(), NULL)
- {
- sort = sorted == Sorted;
- multi = select == MultiSelect;
- width = columnWidth;
- deleteObjects = deleteObj;
- Construct();
- }
- PListBox::PListBox(PInteractor * parent,
- const PNotifier & notify,
- StringSorting sorted,
- SelectType select,
- PDIMENSION columnWidth,
- BOOL deleteObj)
- : PControl(parent, notify, NULL)
- {
- sort = sorted == Sorted;
- multi = select == MultiSelect;
- width = columnWidth;
- deleteObjects = deleteObj;
- Construct();
- }
- void PListBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetSelection(*(PINDEX *)valuePointer);
- else
- *(PINDEX *)valuePointer = GetSelection();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PStringListBox
- #if defined(_PSTRINGLISTBOX)
- void PStringListBox::AddStrings(const PCollection & objects, BOOL update)
- {
- PINDEX last = objects.GetSize() - 1;
- for (PINDEX i = 0; i <= last; i++) {
- PObject & obj = *objects.GetAt(i);
- if (obj.IsDescendant(PString::Class()))
- AddString((PString &)obj, update && i < last);
- else {
- PStringStream str;
- str << obj;
- AddString(str, update && i < last);
- }
- }
- }
- void PStringListBox::SetString(const PString & str, PINDEX index, BOOL update)
- {
- DeleteString(index, FALSE);
- InsertString(str, index, update);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PCustomListBox
- #if defined(_PCUSTOMLISTBOX)
- void PCustomListBox::AddEntries(const PCollection & objects, BOOL update)
- {
- PINDEX last = objects.GetSize() - 1;
- for (PINDEX i = 0; i <= last; i++)
- AddEntry(objects.GetAt(i), update && i < last);
- }
- PDim PCustomListBox::OnMeasureEntry(PINDEX, PObject &, PCanvas & canvas)
- {
- return PDim(GetDimensions(LocalCoords).Width(),
- canvas.FromPointsY(canvas.GetFont().GetHeight())+1);
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PComboBox
- #if defined(_PCOMBOBOX)
- PComboBox::PComboBox(PInteractor * parent, StringSorting sorted)
- : PControl(parent, PNotifier(), NULL)
- {
- sort = sorted == Sorted;
- Construct();
- }
- PComboBox::PComboBox(PInteractor * parent,
- const PNotifier & notify, StringSorting sorted)
- : PControl(parent, notify, NULL)
- {
- sort = sorted == Sorted;
- Construct();
- }
- void PComboBox::AddStrings(const PCollection & objects)
- {
- PINDEX last = objects.GetSize() - 1;
- for (PINDEX i = 0; i <= last; i++) {
- PObject & obj = *objects.GetAt(i);
- if (obj.IsDescendant(PString::Class()))
- AddString((PString &)obj);
- else {
- PStringStream str;
- str << obj;
- AddString(str);
- }
- }
- }
- void PComboBox::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetText(*(PString *)valuePointer);
- else if (option == NewSelection)
- *(PString *)valuePointer = GetString(GetCurrent());
- else if (option == EditChange)
- *(PString *)valuePointer = GetText();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PScrollBar
- #if defined(_PSCROLLBAR)
- PScrollBar::PScrollBar(PInteractor * parent,
- PSCROLLBAR_VALUE max, PSCROLLBAR_VALUE min, PSCROLLBAR_VALUE val,
- PSCROLLBAR_VALUE sml, PSCROLLBAR_VALUE lge)
- : PControl(parent, PNotifier(), NULL)
- {
- maximum = max;
- minimum = min;
- value = val;
- smallNudge = sml;
- largeNudge = lge;
- Construct();
- }
- PScrollBar::PScrollBar(PInteractor * parent, const PNotifier & notify,
- PSCROLLBAR_VALUE max, PSCROLLBAR_VALUE min, PSCROLLBAR_VALUE val,
- PSCROLLBAR_VALUE sml, PSCROLLBAR_VALUE lge)
- : PControl(parent, notify, NULL)
- {
- maximum = max;
- minimum = min;
- value = val;
- smallNudge = sml;
- largeNudge = lge;
- Construct();
- }
- void PScrollBar::TransferValue(int option)
- {
- if (valuePointer != NULL)
- if (option == NotifyUpdate)
- SetValue(*(PSCROLLBAR_VALUE *)valuePointer);
- else
- *(PSCROLLBAR_VALUE *)valuePointer = GetValue();
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PHorizontalScrollBar
- #if defined(_PHORIZONTALSCROLLBAR)
- PHorizontalScrollBar::PHorizontalScrollBar(PInteractor * parent,
- PSCROLLBAR_VALUE max, PSCROLLBAR_VALUE min, PSCROLLBAR_VALUE val,
- PSCROLLBAR_VALUE sml, PSCROLLBAR_VALUE lge)
- : PScrollBar(parent, max, min, val, sml, lge)
- {
- }
- PHorizontalScrollBar::PHorizontalScrollBar(PInteractor * parent,
- const PNotifier & notify,
- PSCROLLBAR_VALUE max, PSCROLLBAR_VALUE min, PSCROLLBAR_VALUE val,
- PSCROLLBAR_VALUE sml, PSCROLLBAR_VALUE lge)
- : PScrollBar(parent, notify, max, min, val, sml, lge)
- {
- }
- #endif
- //////////////////////////////////////////////////////////////////////////////
- // PVerticalScrollBar
- #if defined(_PVERTICALSCROLLBAR)
- PVerticalScrollBar::PVerticalScrollBar(PInteractor * parent,
- PSCROLLBAR_VALUE max, PSCROLLBAR_VALUE min, PSCROLLBAR_VALUE val,
- PSCROLLBAR_VALUE sml, PSCROLLBAR_VALUE lge)
- : PScrollBar(parent, max, min, val, sml, lge)
- {
- }
- PVerticalScrollBar::PVerticalScrollBar(PInteractor * parent,
- const PNotifier & notify,
- PSCROLLBAR_VALUE max, PSCROLLBAR_VALUE min, PSCROLLBAR_VALUE val,
- PSCROLLBAR_VALUE sml, PSCROLLBAR_VALUE lge)
- : PScrollBar(parent, notify, max, min, val, sml, lge)
- {
- }
- #endif
- #undef new
- // End Of File ///////////////////////////////////////////////////////////////