📄 pwlib.cxx
字号:
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();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -