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

📄 pwlib.cxx

📁 windows mobile phone source code
💻 CXX
📖 第 1 页 / 共 4 页
字号:


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 ///////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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