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

📄 pwlib.cxx

📁 windows mobile phone source code
💻 CXX
📖 第 1 页 / 共 4 页
字号:
#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());
}

⌨️ 快捷键说明

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