📄 simpdlg.cxx
字号:
/*
* simpdlg.cxx
*
* Simple dialogs.
*
* 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: simpdlg.cxx,v $
* Revision 1.25 1999/08/07 07:13:23 robertj
* Fixed problems with "balloon help" text popup.
*
* Revision 1.24 1998/12/01 13:01:16 robertj
* new directory structure.
* Unix version
*
* Revision 1.23 1998/09/23 06:29:56 robertj
* Added open source copyright license.
*
* Revision 1.22 1996/04/30 12:34:00 robertj
* Changed "inPixels" boolean to enum for three coordinate systems.
*
* Revision 1.21 1995/06/04 12:43:48 robertj
* Fixed bug with fonts being inherited from parent.
* Fixed bug with Abort Retry Ignore returning incorrect code.
*
* Revision 1.20 1995/04/25 11:28:38 robertj
* Fixed Borland compiler warnings.
*
* Revision 1.19 1995/01/16 09:42:07 robertj
* Documentation.
*
* Revision 1.18 1995/01/15 04:53:10 robertj
* Fixed problems with stdarg and PString parameter on GNU compiler.
*
* Revision 1.17 1995/01/10 11:44:17 robertj
* Removed PString parameter in stdarg function for GNU C++ compatibility.
*
* Revision 1.16 1994/11/19 00:18:35 robertj
* Changed PInteger to be INT, ie standard type like BOOL/WORD etc.
*
* Revision 1.15 1994/10/30 11:47:16 robertj
* Changed mechanism for doing notification callback functions.
*
* Revision 1.14 1994/08/21 23:43:02 robertj
* Changed parameter before variable argument list to NOT be a reference.
*
* Revision 1.13 1994/08/01 03:41:24 robertj
* Use of PNEW instead of new for heap debugging. Need undef for Unix end.
*
* Revision 1.12 1994/07/27 05:58:07 robertj
* Synchronisation.
*
* Revision 1.11 1994/06/25 11:55:15 robertj
* Unix version synchronisation.
*
* Revision 1.10 1994/04/11 12:07:09 robertj
* Fixed bug in icon dimensions.
*
* Revision 1.9 1994/04/03 08:34:18 robertj
* Added help and focus functionality.
*
* Revision 1.8 1994/03/07 07:47:00 robertj
* Major upgrade
*
* Revision 1.7 1993/12/16 06:20:57 robertj
* Changes to callback function definition due to GCC.
*
* Revision 1.6 1993/12/15 10:17:51 robertj
* Moved simple dialog static functions from inline to cxx file.
*
* Revision 1.5 1993/12/06 22:36:38 robertj
* Fixed problem with unimplemented icons.
*
* Revision 1.4 1993/10/16 20:56:30 robertj
* Changed ButtonPressed for X Windows compatibility.
* Added static icon protection against non-implementation.
*
* Revision 1.3 1993/08/24 00:27:59 robertj
* Rearrangement of pushbutton classes, new class added.
*
* Revision 1.2 1993/08/21 04:40:19 robertj
* Fixed icons using wrong constructor.
*
* Revision 1.3 1993/07/14 12:41:52 robertj
* Fixed comment leader.
*
* Revision 1.2 1993/07/14 02:08:18 robertj
* Fixed header comment for RCS logs.
*/
#ifdef __GNUC__
#pragma implementation "simpdlg.h"
#endif
#include <pwlib.h>
#define new PNEW
///////////////////////////////////////////////////////////////////////////////
// PSimpleDialog
#if defined(_PSIMPLEDIALOG)
PSimpleDialog::PSimpleDialog(PInteractor * parent,
const PString & str, ButtonsToHave btns, IconToShow icn)
: PModalDialog(parent)
{
SetFont(owner->GetSystemFont());
PInteractor * topWnd = parent;
while (topWnd->GetParent() != NULL)
topWnd = topWnd->GetParent();
PString title(((PTitledWindow*)topWnd)->GetTitle());
SetTitle(title);
PResourceString okStr (PSTD_ID_STR_OK, "OK");
PResourceString cancelStr(PSTD_ID_STR_CANCEL, "Cancel");
PResourceString yesStr (PSTD_ID_STR_YES, "Yes");
PResourceString noStr (PSTD_ID_STR_NO, "No");
PResourceString abortStr (PSTD_ID_STR_ABORT, "Abort");
PResourceString retryStr (PSTD_ID_STR_RETRY, "Retry");
PResourceString ignoreStr(PSTD_ID_STR_IGNORE, "Ignore");
switch (btns) {
case OkCancelBtn :
btn1 = new PTextButton(this, okStr, PPushButton::DefaultButton);
btn2 = new PTextButton(this, cancelStr);
btn3 = NULL;
btn1val = WasOk;
btn2val = WasCancel;
break;
case YesNoBtn :
btn1 = new PTextButton(this, yesStr, PPushButton::DefaultButton);
btn2 = new PTextButton(this, noStr);
btn3 = NULL;
btn1val = WasYes;
btn2val = WasNo;
break;
case YesNoCancelBtn :
btn1 = new PTextButton(this, yesStr, PPushButton::DefaultButton);
btn2 = new PTextButton(this, noStr);
btn3 = new PTextButton(this, cancelStr);
btn1val = WasYes;
btn2val = WasNo;
btn3val = WasCancel;
break;
case RetryCancelBtn :
btn1 = new PTextButton(this, retryStr, PPushButton::DefaultButton);
btn2 = new PTextButton(this, cancelStr);
btn3 = NULL;
btn1val = WasRetry;
btn2val = WasCancel;
break;
case AbortRetryIgnoreBtn :
btn1 = new PTextButton(this, abortStr);
btn2 = new PTextButton(this, retryStr, PPushButton::DefaultButton);
btn3 = new PTextButton(this, ignoreStr);
btn1val = WasAbort;
btn2val = WasRetry;
btn3val = WasIgnore;
break;
default :
btn1 = new PTextButton(this, okStr, PPushButton::DefaultButton);
btn2 = btn3 = NULL;
btn1val = WasOk;
}
switch (icn) {
#ifdef _PSTATICICON
case InformationIcon :
icon = new PStaticIcon(this, PIcon(PSTD_ID_ICON_INFORMATION));
break;
case QuestionIcon :
icon = new PStaticIcon(this, PIcon(PSTD_ID_ICON_QUESTION));
break;
case ExclamationIcon :
icon = new PStaticIcon(this, PIcon(PSTD_ID_ICON_EXCLAMATION));
break;
case StopSignIcon :
icon = new PStaticIcon(this, PIcon(PSTD_ID_ICON_STOPSIGN));
break;
#endif
default :
icon = NULL;
}
text = new PStaticText(this, str);
PDim tdim(text->GetDimensions(LocalCoords));
PDim dlgdim(tdim); // Start with size of text
PDim idim;
if (icon != NULL) {
idim = icon->GetDimensions(LocalCoords);
idim.SetWidth(idim.Width()*3/2);
}
if (dlgdim.Height() < idim.Height()) // allow enough vertical space for the icon
dlgdim.SetHeight(idim.Height());
dlgdim.SetWidth(dlgdim.Width() + idim.Width()); // allow horizontal space plus half icon width gap
PDim bdim(btn1->GetDimensions(LocalCoords));
if (btn2 != NULL) {
PDim b2dim(btn2->GetDimensions(LocalCoords));
if (bdim.Height() < b2dim.Height())
bdim.SetHeight(b2dim.Height());
if (bdim.Width() < b2dim.Width())
bdim.SetWidth(b2dim.Width());
}
if (btn3 != NULL) {
PDim b3dim(btn3->GetDimensions(LocalCoords));
if (bdim.Height() < b3dim.Height())
bdim.SetHeight(b3dim.Height());
if (bdim.Width() < b3dim.Width())
bdim.SetWidth(b3dim.Width());
}
btn1->SetDimensions(bdim, LocalCoords); // Set buttons to all the same size
if (btn2 != NULL)
btn2->SetDimensions(bdim, LocalCoords);
if (btn3 != NULL)
btn3->SetDimensions(bdim, LocalCoords);
PDim bzonedim(bdim);
if (btn2 != NULL && btn3 != NULL)
bzonedim.SetWidth(bdim.Width()*5); // Total buttons width, 3 buttons + 4 half width gaps
else if (btn2 != NULL)
bzonedim.SetWidth(bdim.Width()*7/2); // Total buttons width, 2 buttons + 3 half width gaps
bzonedim.SetHeight(bzonedim.Height() * 2);
if (dlgdim.Width() < bzonedim.Width()) // Allow enough horizontal space for buttons
dlgdim.SetWidth(bzonedim.Width());
dlgdim.SetHeight(dlgdim.Height() + bzonedim.Height()); // Allow vertical space for buttons with half a button
// height above and below
dlgdim += PDim(20,10); // Left, right and top white space all 10
// Assure it is a minimum width for title
PDim titledim(PDrawCanvas(this).MeasureString(title));
titledim.SetWidth(titledim.Width() + 40);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -