controls.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:34k
- /*
- * controls.cxx
- *
- * Control interactor classes implmentation.
- *
- * 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: controls.cxx,v $
- * Revision 1.63 2000/07/11 19:01:36 robertj
- * Fix of resizing PMultiLineEditBox allowing for scroll bars etc.
- *
- * Revision 1.62 2000/07/11 18:24:03 robertj
- * Fixed incorrect return value on PComboBox::GetCurrent() when no selection.
- *
- * Revision 1.61 2000/06/27 00:14:53 robertj
- * Fixed bug that causes crash when gettng cursor/selection position.
- *
- * Revision 1.60 2000/04/13 23:18:42 robertj
- * Fixed problems with sizing controls with scroll bars.
- *
- * Revision 1.59 2000/04/13 01:37:14 robertj
- * Added missing implementation of PEditBox::GetSelection() on Win32.
- * Added PEditBox::ReplaceSelection() function.
- *
- * Revision 1.58 1999/11/23 05:24:32 robertj
- * Moved function from platform independent to platform dependent files.
- *
- * Revision 1.57 1999/11/16 06:51:42 robertj
- * Created PCustomListBox to allow motif native code PStringListBox implementation
- *
- * Revision 1.56 1998/09/24 03:42:36 robertj
- * Added open software license.
- *
- * Revision 1.55 1998/09/21 13:31:01 robertj
- * Changes to support new PListView class. Different call back method.
- *
- * Revision 1.54 1998/09/14 14:57:46 robertj
- * Fixed incorrect return of owner draw mode for PStringListBox class.
- *
- * Revision 1.53 1998/09/14 13:11:14 robertj
- * Fixed memory leak on delete of PStringList, not deleting all its contents.
- * Added tab stops to string list box.
- *
- * Revision 1.52 1998/09/07 14:02:32 robertj
- * Fixed double delete of PStrings in PStringListBix descendents.
- *
- * Revision 1.51 1998/09/03 15:48:34 robertj
- * Added missing vertical scroll bar on drop down boxes.
- *
- * Revision 1.50 1998/08/06 00:55:59 robertj
- * Fixed using non-standard controls as PControl descendants.
- *
- * Revision 1.49 1998/05/07 05:22:11 robertj
- * Fixed bug in colour setting of radio buttons from resource.
- *
- * Revision 1.48 1998/02/06 04:00:17 robertj
- * Fixed colour of controls, again!
- *
- * Revision 1.47 1998/01/26 00:20:04 robertj
- * Fixed colour of static controls in windows and dialogs.
- *
- * Revision 1.46 1995/11/20 11:07:20 robertj
- * Fixed bug in scroll bar colour.
- * Fixed bug causing double notification in scroll bar click.
- *
- * Revision 1.45 1995/11/09 12:29:56 robertj
- * Moved window style bits to member variable.
- *
- * Revision 1.44 1995/08/24 12:43:52 robertj
- * Function OnEndInput() moved to platform dependent code.
- *
- * Revision 1.43 1995/07/02 06:23:32 robertj
- * Fixed mouse button events not appearing in static text controls.
- * Fixed bug with creating right and centred static text controls being left aligned.
- *
- * Revision 1.42 1995/06/17 11:10:02 robertj
- * Added function to determine if control is a tab stop.
- *
- * Revision 1.41 1995/06/04 12:52:15 robertj
- * Fixed bug in assert of list box resource control.
- *
- * Revision 1.40 1995/04/25 11:44:05 robertj
- * Fixed Borland compiler warnings.
- *
- * Revision 1.39 1995/04/02 09:28:05 robertj
- * Added "balloon" help.
- *
- * Revision 1.38 1995/03/12 05:00:24 robertj
- * Re-organisation of DOS/WIN16 and WIN32 platforms to maximise common code.
- * Used built-in equate for WIN32 API (_WIN32).
- *
- * Revision 1.37 1995/02/19 04:16:31 robertj
- * Added callback when PListBox::SetSelection changes selection.
- * Added dynamically linked command processing.
- *
- * Revision 1.36 1995/02/05 00:57:21 robertj
- * Had to change variable name "small" for MSVC 2.0
- *
- * Revision 1.35 1995/01/28 07:28:49 robertj
- * Assured all Windows strings have n converted to rn and vice versa.
- *
- * Revision 1.34 1995/01/27 11:29:21 robertj
- * Fixed numerous bugs.
- * Fixed bug in nested messages.
- * Underscored library variables.
- *
- */
- #include <pwlib.h>
- #include <math.h>
- static char ControlResourceMismatch[] = "Control class mismatch from resource";
- //////////////////////////////////////////////////////////////////////////////
- // PControl
- PControl::PControl(PInteractor * parent, const PNotifier & notify, void *valuePtr)
- : PInteractor(PAssertNULL(parent)),
- callback(notify)
- {
- PAssert(_hWnd == NULL, PLogicError);
- notifyForStateUpdate = FALSE;
- valuePointer = valuePtr;
- PRESOURCE_ID id = (PRESOURCE_ID)(parent->GetNumChildren() + 100);
- if (parent->IsDescendant(PInteractorLayout::Class())) {
- while (((PInteractorLayout*)parent)->GetControl(id))
- id++;
- }
- controlID = id;
- }
- PControl::PControl(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, void * valuePtr)
- : PInteractor(parent, GetDlgItem(PAssertNULL(parent)->GetHWND(), ctlID)),
- callback(notify)
- {
- PAssert(_hWnd != NULL, "GetDlgItem() failed.");
- notifyForStateUpdate = FALSE;
- valuePointer = valuePtr;
- controlID = ctlID;
- _styleBits = GetWindowLong(_hWnd, GWL_STYLE);
- _exStyleBits = GetWindowLong(_hWnd, GWL_EXSTYLE);
- SubClassControlWndProc();
- }
- BOOL PControl::IsTabStop() const
- {
- return (_styleBits&WS_TABSTOP) != 0;
- }
- void PControl::CreateHWND()
- {
- HINSTANCE hInst = owner->GetInstance();
- WNDCLASS wclass;
- GetCreateWinInfo(wclass);
- if (!GetClassInfo(hInst, wclass.lpszClassName, &wclass))
- PAssertOS(RegisterClass(&wclass));
- _hWnd = CreateWindow(wclass.lpszClassName,
- "",
- _styleBits,
- -100, -100,
- 10, 10,
- parent->GetHWND(),
- (HMENU)(controlID),
- hInst,
- NULL);
- owner->AddWindowHandle(PAssertNULL(_hWnd), this);
- SubClassControlWndProc();
- SetWndFont();
- }
- void PControl::SubClassControlWndProc()
- {
- wndProc = (WNDPROC)GetWindowLong(_hWnd, GWL_WNDPROC);
- WNDPROC pwlibWndProc = owner->GetWndProcPtr(PApplication::WndProcType);
- if (wndProc != pwlibWndProc)
- SetWindowLong(_hWnd, GWL_WNDPROC, (DWORD)pwlibWndProc);
- else
- wndProc = NULL;
- #ifdef _WIN32
- SetClassLong(_hWnd, GCL_STYLE, GetClassLong(_hWnd, GCL_STYLE)|CS_DBLCLKS);
- #else
- SetClassWord(_hWnd, GCW_STYLE, GetClassWord(_hWnd, GCW_STYLE)|CS_DBLCLKS);
- #endif
- }
- void PControl::SetControlID(PRESOURCE_ID ID)
- {
- controlID = ID;
- PSET_WINDOW_VALUE(GetHWND(), ID, controlID);
- }
- void PControl::DefWndProc()
- {
- if (wndProc == NULL)
- PInteractor::DefWndProc();
- else {
- _msg->lResult =
- CallWindowProc(wndProc, _hWnd, _msg->event, _msg->wParam, _msg->lParam);
- _msg->processed = TRUE;
- }
- }
- int PControl::TranslateOption(NMHDR &) const
- {
- return -1;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PNamedControl
- PNamedControl::PNamedControl(PInteractor * parent,
- const PString & newName, const PNotifier & notify, void * valuePtr)
- : PControl(parent, notify, valuePtr), initName(newName)
- {
- }
- void PNamedControl::SetName(const PString & name)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, FALSE, 0L);
- SetWndText(name);
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- InvalidateRect(_hWnd, NULL, TRUE);
- UpdateWindow(_hWnd);
- }
- void PNamedControl::CreateHWND()
- {
- PControl::CreateHWND();
- SetName(initName);
- }
- void PNamedControl::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PControl::GetCreateWinInfo(wndClass);
- wndClass.lpszClassName = "Button";
- _styleBits |= WS_TABSTOP;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PStaticText
- PStaticText::PStaticText(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, void * valuePtr)
- : PNamedControl(parent, ctlID, notify, valuePtr)
- {
- switch (_styleBits&15) {
- case SS_LEFT :
- case SS_SIMPLE :
- case SS_LEFTNOWORDWRAP :
- alignment = PCanvas::LeftAlign;
- break;
- case SS_CENTER :
- alignment = PCanvas::Centred;
- break;
- case SS_RIGHT :
- alignment = PCanvas::RightAlign;
- break;
- default:
- PAssertAlways(ControlResourceMismatch);
- }
- foregroundColour = parent->GetForegroundColour();
- backgroundColour = parent->GetBackgroundColour();
- }
- void PStaticText::SetAlignment(int newAlign)
- {
- if (alignment != newAlign) {
- alignment = newAlign;
- _styleBits &= ~15;
- switch (alignment&PCanvas::HorizontalAlignmentMask) {
- case PCanvas::LeftAlign :
- _styleBits |= SS_LEFT;
- break;
- case PCanvas::Centred :
- _styleBits |= SS_CENTER;
- break;
- case PCanvas::RightAlign :
- _styleBits |= SS_RIGHT;
- }
- SetWindowLong(_hWnd, GWL_STYLE, _styleBits);
- Invalidate();
- }
- }
- void PStaticText::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PNamedControl::GetCreateWinInfo(wndClass);
- wndClass.lpszClassName = "Static";
- switch (alignment&PCanvas::HorizontalAlignmentMask) {
- case PCanvas::RightAlign :
- _styleBits |= SS_RIGHT;
- break;
- case PCanvas::Centred :
- _styleBits |= SS_CENTER;
- break;
- default :
- _styleBits |= SS_LEFT;
- }
- }
- void PStaticText::OnRedraw(PCanvas & canvas)
- {
- if (canvas.NullHDC() &&
- (alignment&PCanvas::VerticalAlignmentMask) == PCanvas::TopAlign)
- PControl::OnRedraw(canvas);
- else
- canvas.DrawString(canvas.GetDrawingBounds(), GetName(), alignment);
- }
- void PStaticText::WndProc()
- {
- if (_msg->event == WM_NCHITTEST)
- _msg->lResult = HTCLIENT;
- else
- PNamedControl::WndProc();
- }
- //////////////////////////////////////////////////////////////////////////////
- // PEditBox
- void PEditBox::SetText(const PString & name)
- {
- SetWndText(name);
- parent->OnControlNotify(*this, EditChange);
- }
- BOOL PEditBox::GetSelection(PINDEX * start, PINDEX * finish) const
- {
- PINDEX dummyStart;
- if (start == NULL)
- start = &dummyStart;
- PINDEX dummyFinish;
- if (finish == NULL)
- finish = &dummyFinish;
- SendMessage(GetHWND(), EM_GETSEL, (WPARAM)start, (LPARAM)finish);
- return *finish > *start;
- }
- int PEditBox::TranslateOption(NMHDR & msg) const
- {
- return msg.code == EN_CHANGE ? NotifyChange : -1;
- }
- void PEditBox::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PControl::GetCreateWinInfo(wndClass);
- wndClass.lpszClassName = "Edit";
- _styleBits |= WS_BORDER|WS_TABSTOP|ES_AUTOHSCROLL;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PPasswordEditBox
- PPasswordEditBox::PPasswordEditBox(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, PString * valuePtr)
- : PEditBox(parent, ctlID, notify, valuePtr)
- {
- PAssert((_styleBits&ES_PASSWORD) != 0, ControlResourceMismatch);
- }
- void PPasswordEditBox::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PEditBox::GetCreateWinInfo(wndClass);
- _styleBits |= ES_PASSWORD;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PMultiLineEditBox
- PMultiLineEditBox::PMultiLineEditBox(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, PString * valuePtr)
- : PEditBox(parent, ctlID, notify, valuePtr)
- {
- PAssert((_styleBits&ES_MULTILINE) != 0, ControlResourceMismatch);
- }
- 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);
- }
- //////////////////////////////////////////////////////////////////////////////
- // 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) {
- SendMessage(GetHWND(), LB_SETCURSEL, index, 0L);
- parent->OnControlNotify(*this, NewSelection);
- }
- }
- void PListBox::Select(PINDEX index, BOOL update, BOOL sel)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);
- SendMessage(_hWnd, LB_SETSEL, sel, MAKELPARAM(index, 0));
- if (!update)
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- parent->OnControlNotify(*this, NewSelection);
- }
- void PListBox::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PControl::GetCreateWinInfo(wndClass);
- wndClass.lpszClassName = "ListBox";
- if (sort)
- _styleBits |= LBS_SORT;
- if (multi)
- _styleBits |= LBS_EXTENDEDSEL;
- if (width != 0)
- _styleBits |= LBS_MULTICOLUMN|WS_HSCROLL;
- else
- _styleBits |= WS_VSCROLL;
- _styleBits |= WS_BORDER|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|LBS_DISABLENOSCROLL;
- }
- int PListBox::TranslateOption(NMHDR & msg) const
- {
- switch (msg.code) {
- case LBN_SELCHANGE :
- return NewSelection;
- case LBN_DBLCLK :
- return DoubleClick;
- }
- return -1;
- }
- void PListBox::CreateHWND()
- {
- PControl::CreateHWND();
- if (width != 0)
- SetColumnWidth(width, FALSE);
- }
- void PListBox::WndProc()
- {
- if (_msg->event == WM_DESTROY && deleteObjects && IsDescendant(PCustomListBox::Class())) {
- for (PINDEX i = 0; i < GetCount(); i++) {
- LPARAM itemData = SendMessage(GetHWND(), LB_GETITEMDATA, i, 0L);
- if (itemData != LB_ERR)
- delete (PObject *)itemData;
- }
- }
- PControl::WndProc();
- }
- BOOL PListBox::AdjustDimensionForScrollBar(UINT) const
- {
- return FALSE;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PStringListBox
- PINDEX PStringListBox::AddString(const PString & str, BOOL update)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);
- PINDEX retval = (PINDEX)SendMessage(_hWnd, LB_ADDSTRING, 0, (DWORD)(const char *)str);
- if (!update)
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- return retval;
- }
- void PStringListBox::InsertString(const PString & str, PINDEX index, BOOL update)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);
- SendMessage(_hWnd, LB_INSERTSTRING, index, (DWORD)(const char *)str);
- if (!update)
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- }
- void PStringListBox::DeleteString(PINDEX index, BOOL update)
- {
- DeleteEntry(index, update);
- }
- PINDEX PStringListBox::FindString(const PString & str, PINDEX startIndex, BOOL exact) const
- {
- if (startIndex == P_MAX_INDEX)
- startIndex = -1;
- long retVal = SendMessage(GetHWND(),
- exact ? LB_FINDSTRINGEXACT : LB_FINDSTRING, startIndex,
- (DWORD)(const char *)str);
- return retVal != LB_ERR ? (PINDEX)retVal : P_MAX_INDEX;
- }
- PString PStringListBox::GetString(PINDEX index) const
- {
- PString str;
- long len = SendMessage(GetHWND(), LB_GETTEXTLEN, index, 0);
- if (len != LB_ERR)
- SendMessage(GetHWND(), LB_GETTEXT, index, (DWORD)str.GetPointer(len+1));
- return str;
- }
- void PStringListBox::SetTabStops(PDIMENSION tab)
- {
- tabStops.SetSize(1);
- tabStops[0] = tab;
- SendMessage(GetHWND(), LB_SETTABSTOPS, 1, (LPARAM)&tab);
- }
- void PStringListBox::SetTabStops(const PORDINATE * tabs, PINDEX count)
- {
- PAssert(count > 0, PInvalidParameter);
- memcpy(tabStops.GetPointer(count), tabs, count*sizeof(int));
- SendMessage(GetHWND(), LB_SETTABSTOPS, count, (LPARAM)tabs);
- }
- void PStringListBox::SetTabStops(const PIntArray & tabs)
- {
- PAssert(tabs.GetSize() > 0, PInvalidParameter);
- SendMessage(GetHWND(), LB_SETTABSTOPS,
- tabs.GetSize(), (LPARAM)(const int *)tabs);
- }
- void PStringListBox::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PListBox::GetCreateWinInfo(wndClass);
- _styleBits |= LBS_USETABSTOPS;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PCustomListBox
- PINDEX PCustomListBox::AddEntry(PObject * obj, BOOL update)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);
- PINDEX retval = (PINDEX)SendMessage(_hWnd, LB_ADDSTRING, 0, (DWORD)obj);
- if (!update)
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- return retval;
- }
- void PCustomListBox::InsertEntry(PObject * obj, PINDEX index, BOOL update)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);
- SendMessage(_hWnd, LB_INSERTSTRING, index, (DWORD)obj);
- if (!update)
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- }
- PINDEX PCustomListBox::FindEntry(const PObject & obj, PINDEX startIndex) const
- {
- if (startIndex == P_MAX_INDEX)
- startIndex = -1;
- long retVal = SendMessage(_hWnd,
- LB_FINDSTRINGEXACT, startIndex, (DWORD)(const char *)(PString &)obj);
- return retVal != LB_ERR ? (PINDEX)retVal : P_MAX_INDEX;
- }
- void PCustomListBox::SetEntry(PObject * obj, PINDEX index, BOOL update)
- {
- SendMessage(GetHWND(), WM_SETREDRAW, update, 0L);
- BOOL doNotify = GetSelection() == index;
- SendMessage(_hWnd, LB_SETITEMDATA, index, (DWORD)obj);
- if (!update)
- SendMessage(_hWnd, WM_SETREDRAW, TRUE, 0L);
- if (doNotify)
- parent->OnControlNotify(*this, NewSelection);
- }
- const PObject * PCustomListBox::GetEntry(PINDEX index) const
- {
- long retVal = SendMessage(GetHWND(), LB_GETITEMDATA, index, 0L);
- return retVal != LB_ERR ? (const PObject *)retVal : NULL;
- }
- void PCustomListBox::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PListBox::GetCreateWinInfo(wndClass);
- _styleBits |= LBS_OWNERDRAWVARIABLE;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PComboBox
- PComboBox::PComboBox(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, PString * valuePtr)
- : PControl(parent, ctlID, notify, valuePtr)
- {
- sort = (_styleBits&CBS_SORT) != 0;
- PAssert((_styleBits&CBS_DROPDOWN) != 0, ControlResourceMismatch);
- }
- PINDEX PComboBox::GetCurrent() const
- {
- long retVal = SendMessage(GetHWND(), CB_GETCURSEL, 0, 0L);
- return retVal != CB_ERR ? (PINDEX)retVal : P_MAX_INDEX;
- }
- void PComboBox::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PControl::GetCreateWinInfo(wndClass);
- wndClass.lpszClassName = "ComboBox";
- if (sort != 0)
- _styleBits |= CBS_SORT;
- _styleBits |= CBS_DROPDOWN|CBS_AUTOHSCROLL|WS_VSCROLL;
- }
- int PComboBox::TranslateOption(NMHDR & msg) const
- {
- switch (msg.code) {
- case CBN_SELCHANGE :
- return NewSelection;
- case CBN_DROPDOWN :
- return ListDropped;
- case CBN_CLOSEUP :
- return ListClosed;
- case CBN_EDITCHANGE :
- return EditChange;
- }
- return -1;
- }
- BOOL PComboBox::OnEndInput()
- {
- parent->OnControlNotify(*this, PEditBox::EndEdit);
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PScrollBar
- PScrollBar::PScrollBar(PInteractorLayout * parent, PRESOURCE_ID ctlID,
- const PNotifier & notify, PSCROLLBAR_VALUE * valuePtr)
- : PControl(parent, ctlID, notify, valuePtr)
- {
- PStringArray limits = GetWndText().Tokenise(" ");
- value = minimum = 0;
- maximum = 100;
- smallNudge = 1;
- largeNudge = 10;
- switch (limits.GetSize()) {
- case 4 :
- largeNudge = (PSCROLLBAR_VALUE)limits[3].AsInteger();
- case 3 :
- smallNudge = (PSCROLLBAR_VALUE)limits[2].AsInteger();
- case 2 :
- maximum = (PSCROLLBAR_VALUE)limits[1].AsInteger();
- case 1 :
- value = minimum = (PSCROLLBAR_VALUE)limits[0].AsInteger();
- }
- SetScrollRange(_hWnd, SB_CTL, minimum, maximum, FALSE);
- SetScrollPos(_hWnd, SB_CTL, value, FALSE);
- tracking = FALSE;
- foregroundColour = owner->GetScrollBarColour();
- backgroundColour = owner->GetScrollBarColour();
- }
- void PScrollBar::SetMaximum(PSCROLLBAR_VALUE val, BOOL redraw)
- {
- maximum = val;
- if (minimum > maximum)
- minimum = maximum;
- SetScrollRange(GetHWND(), SB_CTL, minimum, maximum, redraw);
- SetValue(value);
- }
- void PScrollBar::SetMinimum(PSCROLLBAR_VALUE val, BOOL redraw)
- {
- minimum = val;
- if (maximum < minimum)
- maximum = minimum;
- SetScrollRange(GetHWND(), SB_CTL, minimum, maximum, redraw);
- SetValue(value);
- }
- void PScrollBar::SetValue(PSCROLLBAR_VALUE val, BOOL redraw)
- {
- SetScrollPos(GetHWND(), SB_CTL, val, redraw);
- PSCROLLBAR_VALUE newValue = (PSCROLLBAR_VALUE)GetScrollPos(_hWnd, SB_CTL);
- if (value != newValue) {
- parent->OnControlNotify(*this, StartTrack);
- value = newValue;
- parent->OnControlNotify(*this, EndTrack);
- }
- }
- int PScrollBar::TrackScrollBar(WPARAM code, int trackVal)
- {
- int newVal = value;
- switch (code) {
- case SB_LINEUP :
- newVal -= smallNudge;
- break;
- case SB_LINEDOWN :
- newVal += smallNudge;
- break;
- case SB_PAGEUP :
- newVal -= largeNudge;
- break;
- case SB_PAGEDOWN :
- newVal += largeNudge;
- break;
- case SB_TOP :
- newVal = minimum;
- break;
- case SB_BOTTOM :
- newVal = maximum;
- break;
- case SB_THUMBTRACK :
- case SB_THUMBPOSITION :
- newVal = trackVal;
- }
- SetScrollPos(_hWnd, SB_CTL, newVal, TRUE);
- value = (PSCROLLBAR_VALUE)GetScrollPos(_hWnd, SB_CTL);
- if (tracking) {
- if (code != SB_ENDSCROLL)
- return Tracking;
- tracking = FALSE;
- return EndTrack;
- }
- tracking = TRUE;
- return StartTrack;
- }
- void PScrollBar::CreateHWND()
- {
- PControl::CreateHWND();
- SetScrollRange(_hWnd, SB_CTL, minimum, maximum, FALSE);
- SetScrollPos(_hWnd, SB_CTL, value, TRUE);
- foregroundColour = owner->GetScrollBarColour();
- backgroundColour = owner->GetScrollBarColour();
- }
- void PScrollBar::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PControl::GetCreateWinInfo(wndClass);
- wndClass.lpszClassName = "ScrollBar";
- _styleBits |= WS_TABSTOP;
- }
- PVerticalScrollBar::PVerticalScrollBar(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, PSCROLLBAR_VALUE * valuePtr)
- : PScrollBar(parent, ctlID, notify, valuePtr)
- {
- PAssert((_styleBits&1)!=0, ControlResourceMismatch);
- }
- void PVerticalScrollBar::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PScrollBar::GetCreateWinInfo(wndClass);
- _styleBits |= SBS_VERT;
- }
- PHorizontalScrollBar::PHorizontalScrollBar(PInteractorLayout * parent,
- PRESOURCE_ID ctlID, const PNotifier & notify, PSCROLLBAR_VALUE * valuePtr)
- : PScrollBar(parent, ctlID, notify, valuePtr)
- {
- PAssert((_styleBits&1)==0,ControlResourceMismatch);
- }
- void PHorizontalScrollBar::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PScrollBar::GetCreateWinInfo(wndClass);
- _styleBits |= SBS_HORZ;
- }
- // End Of File ///////////////////////////////////////////////////////////////