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

📄 controls.cxx

📁 windows mobile phone source code
💻 CXX
📖 第 1 页 / 共 3 页
字号:
void PMultiLineEditBox::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PEditBox::GetCreateWinInfo(wndClass);
  _styleBits |= WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN;
}


void PMultiLineEditBox::_SetDimensions(PDIMENSION width, PDIMENSION height,
                                 CoordinateSystem coords)
{
  GetHWND();

  if (coords == LocalCoords) {
    width = ToPixelsDX(width);
    height = ToPixelsDY(height);
  }

  SetWindowPos(_hWnd, NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER);

  RECT r;
  ::GetWindowRect(_hWnd, &r);
  if ((PDIMENSION)(r.right-r.left) == width && (PDIMENSION)(r.bottom-r.top) == height)
    return;

  width += (PDIMENSION)GetSystemMetrics(SM_CXBORDER)*2 +
           (PDIMENSION)GetSystemMetrics(SM_CXVSCROLL);
  height += (PDIMENSION)GetSystemMetrics(SM_CYBORDER)*2 +
            (PDIMENSION)GetSystemMetrics(SM_CYHSCROLL);
  SetWindowPos(_hWnd, NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER);
}


//////////////////////////////////////////////////////////////////////////////
// PIntegerEditBox

PIntegerEditBox::PIntegerEditBox(PInteractorLayout * parent,
                 PRESOURCE_ID ctlID, const PNotifier & notify, long * valuePtr)
  : PNumberEditBox(parent, ctlID, notify, valuePtr)
{
  PStringArray limits = GetWndText().Tokenise(" ");
  SetWndText("");
  PAssert(limits.GetSize() > 1 && limits[0] == "INTEDITBOX", ControlResourceMismatch);
  minimum = limits.GetSize() < 2 ? LONG_MIN : limits[1].AsInteger();
  maximum = limits.GetSize() < 3 ? LONG_MAX : limits[2].AsInteger();
  nudge   = limits.GetSize() < 4 ? 1 : limits[3].AsInteger();
  base    = (BYTE)(limits.GetSize() < 5 ? 1 : limits[4].AsInteger());
  PAssert(base >= 2 && base <= 36, PInvalidParameter);
}


//////////////////////////////////////////////////////////////////////////////
// PFloatEditBox

PFloatEditBox::PFloatEditBox(PInteractorLayout * parent,
               PRESOURCE_ID ctlID, const PNotifier & notify, double * valuePtr)
  : PNumberEditBox(parent, ctlID, notify, valuePtr)
{
  PStringArray limits = GetWndText().Tokenise(" ");
  SetWndText("");
  PAssert(limits.GetSize() > 1 && limits[0] == "FLOATEDITBOX", ControlResourceMismatch);
  minimum  = limits.GetSize() < 2 ? -HUGE_VAL : limits[1].AsReal();
  maximum  = limits.GetSize() < 3 ?  HUGE_VAL : limits[2].AsReal();
  nudge    = limits.GetSize() < 4 ? 1 : limits[3].AsReal();
  decimals = limits.GetSize() < 5 ? 1 : (int)limits[4].AsInteger();
}


//////////////////////////////////////////////////////////////////////////////
// PPushButton

PPushButton::PPushButton(PInteractorLayout * parent,
                PRESOURCE_ID ctlID, const PNotifier & notify, void * valuePtr)
  : PNamedControl(parent, ctlID, notify, valuePtr)
{
  DWORD style = _styleBits&15;
  PAssert(style == BS_DEFPUSHBUTTON || style == BS_PUSHBUTTON,
                                                     ControlResourceMismatch);
  defaultButton = style == BS_DEFPUSHBUTTON;

  foregroundColour.FromSYSCOLOR(COLOR_BTNTEXT);
  backgroundColour.FromSYSCOLOR(COLOR_BTNFACE);
}


void PPushButton::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PNamedControl::GetCreateWinInfo(wndClass);

  if (defaultButton)
    _styleBits |= BS_DEFPUSHBUTTON;
  else
    _styleBits |= BS_PUSHBUTTON;

  if (!IsClass(PTextButton::Class()))
    _styleBits |= BS_OWNERDRAW;

  foregroundColour.FromSYSCOLOR(COLOR_BTNTEXT);
  backgroundColour.FromSYSCOLOR(COLOR_BTNFACE);
}


int PPushButton::TranslateOption(NMHDR & msg) const
{
  return msg.code == BN_CLICKED ? NotifyChange : -1;
}


//////////////////////////////////////////////////////////////////////////////
// PTextButton

void PTextButton::DefaultDimensions()
{
  PDrawCanvas canvas(this);
  PString name = GetName();
  PDim dim(16, 8);
  if (!name.IsEmpty()) {
    dim = canvas.MeasureString(name);
    // 2 average character width either side of the button text and half a
    // character height above and below
    dim += PDim(16, dim.Height());
    if (dim.Width() < dim.Height()*3)
      dim.SetWidth(dim.Height()*3);
  }
  SetDimensions(dim, LocalCoords);
}


//////////////////////////////////////////////////////////////////////////////
// PImageButton

void PImageButton::Construct()
{
  _in_WM_PAINT = TRUE; // Prevent calling OnRedraw in the normal WM_PAINT
}


//////////////////////////////////////////////////////////////////////////////
// PCheck3WayBox

PCheck3WayBox::PCheck3WayBox(PInteractorLayout * parent,
          PRESOURCE_ID ctlID, const PNotifier & notify, CheckValues * valuePtr)
  : PNamedControl(parent, ctlID, notify, valuePtr)
{
  DWORD style = _styleBits&15;
  PAssert(style == BS_AUTO3STATE || style == BS_AUTOCHECKBOX,
                                                     ControlResourceMismatch);
  Construct();
}


void PCheck3WayBox::Construct()
{
  foregroundColour = parent->GetForegroundColour();
  backgroundColour = parent->GetBackgroundColour();
}


void PCheck3WayBox::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PNamedControl::GetCreateWinInfo(wndClass);
  _styleBits |= BS_AUTO3STATE;
}


int PCheck3WayBox::TranslateOption(NMHDR & msg) const
{
  return msg.code == BN_CLICKED ? NotifyChange : -1;
}


//////////////////////////////////////////////////////////////////////////////
// PCheckBox

PCheckBox::PCheckBox(PInteractorLayout * parent,
                 PRESOURCE_ID ctlID, const PNotifier & notify, BOOL * valuePtr)
  : PCheck3WayBox(parent, ctlID, notify, (CheckValues *)valuePtr)
{
  PAssert((_styleBits&15) == BS_AUTOCHECKBOX, ControlResourceMismatch);
}


void PCheckBox::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PCheck3WayBox::GetCreateWinInfo(wndClass);
  _styleBits &= 0xfffffff0;
  _styleBits |= BS_AUTOCHECKBOX;
}


//////////////////////////////////////////////////////////////////////////////
// PRadioButton

PRadioButton::PRadioButton(PInteractorLayout * parent,
               PRESOURCE_ID ctlID, const PNotifier & notify, PINDEX * valuePtr)
  : PNamedControl(parent, ctlID, notify, valuePtr)
{
  PAssert((_styleBits&15) == BS_RADIOBUTTON, ControlResourceMismatch);
  group.DisallowDeleteObjects();
  group.Append(this);
  Construct();
}


void PRadioButton::Construct()
{
  foregroundColour = parent->GetForegroundColour();
  backgroundColour = parent->GetBackgroundColour();
}


PINDEX PRadioButton::GetValue() const
{
  for (PINDEX i = 0; i < group.GetSize(); i++) {
    if (SendMessage(group[i].GetHWND(), BM_GETCHECK, 0, 0L) != 0)
      return i+1;
  }
  return 0;
}


void PRadioButton::SetValue(PINDEX newVal)
{
  for (PINDEX i = 0; i < group.GetSize(); i++)
    SendMessage(group[i].GetHWND(), BM_SETCHECK, newVal == i+1, 0L);
}


void PRadioButton::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PNamedControl::GetCreateWinInfo(wndClass);
  _styleBits |= BS_RADIOBUTTON;
}


int PRadioButton::TranslateOption(NMHDR & msg) const
{
  if (msg.code != BN_CLICKED)
    return -1;

  for (PINDEX i = 0; i < group.GetSize(); i++) {
    PRadioButton & btn = group[i];
    SendMessage(btn.GetHWND(), BM_SETCHECK, &btn == this, 0L);
  }

  return NotifyChange;
}


//////////////////////////////////////////////////////////////////////////////
// PStaticIcon

PStaticIcon::PStaticIcon(PInteractorLayout * parent,
                PRESOURCE_ID ctlID, const PNotifier & notify, void * valuePtr)
  : PControl(parent, ctlID, notify, valuePtr),
#if defined(_WIN32)
    icon((HICON)NULL)
#else
    icon((HICON)GetWindowWord(_hWnd, 4))
#endif
{
  PAssert((_styleBits&15) == SS_ICON, ControlResourceMismatch);

  foregroundColour = parent->GetForegroundColour();
  backgroundColour = parent->GetBackgroundColour();
}


void PStaticIcon::SetIcon(const PIcon & icn)
{
  HICON oldIcon = (HICON)
#if defined(_WIN32)
                SendMessage(GetHWND(), STM_SETICON, (WPARAM)icn.GetHICON(), 0);
#else
                SetWindowWord(GetHWND(), 4, (WORD)icn.GetHICON());
#endif

  if (oldIcon!=NULL && oldIcon!=icon.GetHICON() && oldIcon!=icn.GetHICON())
    DestroyIcon(oldIcon);

  icon = icn;
}


void PStaticIcon::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PControl::GetCreateWinInfo(wndClass);

  wndClass.lpszClassName = "Static";
  _styleBits |= SS_ICON;
}


#if defined(_WIN32)
void PStaticIcon::WndProc()
{
  PControl::WndProc();
  if (_msg->event == WM_CREATE && icon.GetHICON() == NULL)
    icon = PIcon((HICON)SendMessage(_hWnd, STM_GETICON, 0, 0));
}
#endif


//////////////////////////////////////////////////////////////////////////////
// PStaticBox

PStaticBox::PStaticBox(PInteractorLayout * parent,
                PRESOURCE_ID ctlID, const PNotifier & notify, void * valuePtr)
  : PNamedControl(parent, ctlID, notify, valuePtr)
{
  PAssert((_styleBits&15) == BS_GROUPBOX, ControlResourceMismatch);
  foregroundColour = parent->GetForegroundColour();
  backgroundColour = parent->GetBackgroundColour();
}


void PStaticBox::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PNamedControl::GetCreateWinInfo(wndClass);
  _styleBits |= BS_GROUPBOX;
}


//////////////////////////////////////////////////////////////////////////////
// PStaticRect

void PStaticRect::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PControl::GetCreateWinInfo(wndClass);
  wndClass.lpszClassName = "Static";
  _styleBits |= SS_LEFT;
}


//////////////////////////////////////////////////////////////////////////////
// PChoiceBox

PChoiceBox::PChoiceBox(PInteractorLayout * parent,
               PRESOURCE_ID ctlID, const PNotifier & notify, PINDEX * valuePtr)
  : PControl(parent, ctlID, notify, valuePtr)
{
  sort  = (_styleBits&CBS_SORT) != 0;
  PAssert((_styleBits&CBS_DROPDOWNLIST) != 0, ControlResourceMismatch);
}


void PChoiceBox::GetCreateWinInfo(WNDCLASS & wndClass)
{
  PControl::GetCreateWinInfo(wndClass);

  wndClass.lpszClassName = "ComboBox";
  if (sort)
    _styleBits |= CBS_SORT;
  _styleBits |= WS_BORDER|CBS_DROPDOWNLIST|WS_VSCROLL;
}


int PChoiceBox::TranslateOption(NMHDR & msg) const
{
  switch (msg.code) {
    case CBN_SELCHANGE :
      return NewSelection;
    case CBN_DROPDOWN :
      return ListDropped;
    case CBN_CLOSEUP :
      return ListClosed;
  }
  return -1;
}


//////////////////////////////////////////////////////////////////////////////
// PListBox

PListBox::PListBox(PInteractorLayout * parent,
               PRESOURCE_ID ctlID, const PNotifier & notify, PINDEX * valuePtr)
  : PControl(parent, ctlID, notify, valuePtr)
{
  sort  = (_styleBits&LBS_SORT) != 0;
  multi = (_styleBits&LBS_EXTENDEDSEL) != 0;
  width = (PDIMENSION)((_styleBits&LBS_MULTICOLUMN) != 0 ? 20 : 0);
  PAssert((_styleBits&LBS_NOTIFY) != 0, ControlResourceMismatch);
}


void PListBox::Construct()
{
  if (width != 0 && _hWnd != NULL)
    SetColumnWidth(width, FALSE);
}


void PListBox::DeleteEntry(PINDEX index, BOOL update)
{
  SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);

  BOOL doNotify = GetSelection() == index;

  SendMessage(_hWnd, LB_DELETESTRING, index, 0L);

  if (!update)
    SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);

  if (doNotify)
    parent->OnControlNotify(*this, NewSelection);
}


void PListBox::DeleteAllEntries(BOOL update)
{
  SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);

  BOOL doNotify = GetSelection() != P_MAX_INDEX;

  SendMessage(_hWnd, LB_RESETCONTENT, 0, 0L);

  if (!update)
    SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);

  if (doNotify)
    parent->OnControlNotify(*this, NewSelection);
}


void PListBox::SetColumnWidth(PDIMENSION newWidth, BOOL update)
{
  PAssert(width != 0 && newWidth != 0, PInvalidParameter);
  width = newWidth;

  SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);

  SendMessage(_hWnd, LB_SETCOLUMNWIDTH, newWidth, 0L);

  if (!update)
    SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
}


void PListBox::SetTopIndex(PINDEX index, BOOL update)
{
  SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);

  SendMessage(_hWnd, LB_SETTOPINDEX, index, 0L);

  if (!update)
    SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
}


PINDEX PListBox::GetSelection() const
{
  long retVal = SendMessage(GetHWND(), LB_GETCURSEL, 0, 0L);
  return retVal != LB_ERR ? (PINDEX)retVal : P_MAX_INDEX;
}


void PListBox::SetSelection(PINDEX index)
{
  if (GetSelection() != index) {

⌨️ 快捷键说明

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