interact.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:43k
- /*
- * interact.cxx
- *
- * Interactor classes implementation.
- *
- * 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: interact.cxx,v $
- * Revision 1.75 2000/04/13 23:18:43 robertj
- * Fixed problems with sizing controls with scroll bars.
- *
- * Revision 1.74 2000/03/17 20:32:22 robertj
- * Fixed race conditions in mult-threaded windows (dialogs in particular)
- *
- * Revision 1.73 1999/11/16 06:51:42 robertj
- * Created PCustomListBox to allow motif native code PStringListBox implementation
- *
- * Revision 1.72 1999/10/24 11:41:34 robertj
- * Fixed bug in SetDimensions() to allow for a window with a menu.
- *
- * Revision 1.71 1999/08/25 02:42:13 robertj
- * Fixed problem with creating windows in background threads, not happening until have a message sent.
- *
- * Revision 1.70 1999/08/17 03:46:42 robertj
- * Fixed usage of inlines in optimised version.
- *
- * Revision 1.69 1999/08/07 07:13:23 robertj
- * Fixed problems with "balloon help" text popup.
- *
- * Revision 1.68 1999/03/29 03:39:55 robertj
- * Changed semantics of PTitledWindow::OnClose() function.
- *
- * Revision 1.67 1999/02/16 08:08:07 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.66 1998/09/24 03:42:44 robertj
- * Added open software license.
- *
- * Revision 1.65 1998/09/24 01:55:53 robertj
- * Fixed problems with resizing windows with built in scroll bars.
- *
- * Revision 1.64 1998/09/22 15:15:29 robertj
- * Added more support for common control callbacks, can now set message result.
- * Added correction for invisible scroll bars in resizing windows.
- *
- * Revision 1.63 1998/09/21 13:31:03 robertj
- * Changes to support new PListView class. Different call back method.
- *
- * Revision 1.62 1998/09/14 13:17:22 robertj
- * Fixed memory leak on delete of PStringList, not deleting all its contents.
- * Fixed major memory (resource) leak in control painting.
- *
- * Revision 1.61 1998/09/04 07:03:22 robertj
- * Fixed possible crash on focus change. Depends on timeing of messages.
- * Fixed SetFont() really setting font. If target is not control font may not be set in this way.
- *
- * Revision 1.60 1998/01/26 00:19:53 robertj
- * Fixed colour of static controls in windows and dialogs.
- *
- * Revision 1.59 1997/04/27 05:50:31 robertj
- * DLL support.
- *
- * Revision 1.58 1996/10/31 12:39:57 robertj
- * Added RCS keywords.
- *
- */
- #include <pwlib.h>
- #if !P_USE_INLINES
- #include <pwlib/pwmisc.inl>
- #endif
- void PInteractor::Construct(PInteractor * par, HWND hWnd, BOOL hiddenChild)
- {
- parent = par;
- if (parent != NULL) {
- if (!hiddenChild)
- parent->children.Append(this);
- owner = parent->owner;
- cursorMode = UseParentCursor;
- }
- else {
- owner = &PApplication::Current();
- cursorMode = UseCurrentCursor;
- }
- _hWnd = hWnd;
- if (_hWnd != NULL) {
- owner->AddWindowHandle(_hWnd, this);
- HFONT hFont = (HFONT)(UINT)SendMessage(_hWnd, WM_GETFONT, 0, 0L);
- if (hFont != NULL)
- font = PRealFont(hFont);
- else
- SetFont(parent->GetFont(), TRUE);
- }
- else {
- if (parent != NULL)
- SetFont(parent->GetFont(), TRUE);
- }
- foregroundColour = owner->GetWindowFgColour();
- backgroundColour = owner->GetWindowBkColour();
- caretVisible = 1;
- _in_WM_PAINT = FALSE;
- mouseTrackInteractor = NULL;
- mouseTrackCanvas = NULL;
- hBackgroundBrush = NULL;
- }
- PInteractor::~PInteractor()
- {
- if (hBackgroundBrush != NULL)
- DeleteObject(hBackgroundBrush);
- if (GetFocusInteractor() == this)
- SetFocusInteractor(parent);
- if (parent!=NULL && parent->children.GetObjectsIndex(this) != P_MAX_INDEX) {
- parent->children.DisallowDeleteObjects();
- parent->children.Remove(this);
- parent->children.AllowDeleteObjects();
- }
- if (_hWnd != NULL && _hWnd != P_DEAD_WINDOW)
- DestroyWindow(_hWnd);
- }
- PObject::Comparison PInteractor::Compare(const PObject & obj) const
- {
- PAssert(obj.IsDescendant(PInteractor::Class()), PInvalidParameter);
- return GetHWND() ==
- ((const PInteractor &)obj).GetHWND() ? EqualTo : GreaterThan;
- }
- void PInteractor::SetFont(const PFont & newFont, BOOL toChildren)
- {
- font = PRealFont(newFont);
- if (_hWnd != NULL)
- SetWndFont();
- if (toChildren) {
- for (PINDEX i = 0; i < children.GetSize(); i++)
- children[i].SetFont(font, TRUE);
- }
- }
- void PInteractor::_SetPosition(PORDINATE x, PORDINATE y,
- PositionOrigin xOrigin, PositionOrigin yOrigin)
- {
- PDim myDim = GetStructureBounds(ScreenCoords).Dimensions();
- PDim scrDim = owner->GetPrimaryScreenSize();
- PDim parDim = scrDim;
- PPoint org;
- PInteractor * p = this;
- if (parent != NULL) {
- p = parent;
- parDim = p->GetStructureBounds(ScreenCoords).Dimensions();
- ClientToScreen(p->GetHWND(), org);
- }
- switch (xOrigin) {
- case TopLeftParent:
- case CentreParent :
- case BottomRightParent :
- x = p->ToPixelsX(x) + org.X();
- break;
- case TopLeftPixels:
- case CentrePixels :
- case BottomRightPixels :
- x = x + org.X();
- }
- switch (xOrigin) {
- case CentreParent :
- case CentrePixels :
- x += ((PORDINATE)parDim.Width() - (PORDINATE)myDim.Width())/2;
- break;
- case BottomRightParent :
- case BottomRightPixels :
- x += (PORDINATE)parDim.Width() - (PORDINATE)myDim.Width();
- break;
- case CentreScreen :
- x += ((PORDINATE)scrDim.Width() - (PORDINATE)myDim.Width())/2;
- break;
- case BottomRightScreen :
- x = owner->GetScreenRect().Right() - (PORDINATE)myDim.Width();
- }
- switch (yOrigin) {
- case TopLeftParent:
- case CentreParent :
- case BottomRightParent :
- y = p->ToPixelsY(y) + org.Y();
- break;
- case TopLeftPixels:
- case CentrePixels :
- case BottomRightPixels :
- y = y + org.Y();
- }
- switch (yOrigin) {
- case CentreParent :
- case CentrePixels :
- y += ((PORDINATE)parDim.Height() - (PORDINATE)myDim.Height())/2;
- break;
- case BottomRightParent :
- case BottomRightPixels :
- y += (PORDINATE)parDim.Height() - (PORDINATE)myDim.Height();
- break;
- case CentreScreen :
- y += ((PORDINATE)scrDim.Height() - (PORDINATE)myDim.Height())/2;
- break;
- case BottomRightScreen :
- y = owner->GetScreenRect().Height() - (PORDINATE)myDim.Height();
- }
- if ((_styleBits&0xc0000000) == WS_CHILD) {
- POINT pt;
- pt.x = x;
- pt.y = y;
- ScreenToClient(p->GetHWND(), &pt);
- x = (PORDINATE)pt.x;
- y = (PORDINATE)pt.y;
- }
- SetWindowPos(GetHWND(), NULL, x, y, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
- }
- PPoint PInteractor::GetPosition(CoordinateSystem coords) const
- {
- RECT r;
- GetWindowRect(GetHWND(), &r);
- PPoint p((PORDINATE)r.left, (PORDINATE)r.top);
- if (coords == ScreenCoords)
- return p;
- if (GetParent() != NULL)
- ScreenToClient(GetParent()->GetHWND(), p);
- if (coords == PixelCoords)
- return p;
- const PInteractor * par = parent != NULL ? parent : this;
- return par->FromPixels(p);
- }
- PPoint PInteractor::ToScreen(const PPoint & pt, CoordinateSystem coords) const
- {
- PPoint p;
- switch (coords) {
- case LocalCoords :
- p = ToPixels(pt);
- break;
- case PixelCoords :
- p = pt;
- break;
- case ScreenCoords :
- return pt;
- }
- ClientToScreen(GetHWND(), p);
- return p;
- }
- PPoint PInteractor::FromScreen(const PPoint & pt, CoordinateSystem coords) const
- {
- if (coords == ScreenCoords)
- return pt;
- PPoint p = pt;
- ScreenToClient(GetHWND(), p);
- return coords == PixelCoords ? p : ToPixels(p);
- }
- void PInteractor::_SetDimensions(PDIMENSION width, PDIMENSION height,
- CoordinateSystem coords)
- {
- GetHWND();
- if (coords == LocalCoords) {
- width = ToPixelsDX(width);
- height = ToPixelsDY(height);
- }
- switch (_styleBits&WS_CAPTION) {
- case WS_CAPTION :
- height += (PDIMENSION)GetSystemMetrics(SM_CYCAPTION);
- break;
- case WS_BORDER :
- width += (PDIMENSION)GetSystemMetrics(SM_CXBORDER)*2;
- height += (PDIMENSION)GetSystemMetrics(SM_CYBORDER)*2;
- break;
- case WS_DLGFRAME :
- width += (PDIMENSION)GetSystemMetrics(SM_CXDLGFRAME)*2;
- height += (PDIMENSION)GetSystemMetrics(SM_CYDLGFRAME)*2;
- break;
- }
- if ((_styleBits&WS_VSCROLL) != 0 && AdjustDimensionForScrollBar(SB_VERT))
- width += (PDIMENSION)GetSystemMetrics(SM_CXVSCROLL);
- if ((_styleBits&WS_HSCROLL) != 0 && AdjustDimensionForScrollBar(SB_HORZ))
- height += (PDIMENSION)GetSystemMetrics(SM_CYHSCROLL);
- if ((_exStyleBits&WS_EX_DLGMODALFRAME) != 0) {
- width += (PDIMENSION)GetSystemMetrics(SM_CXDLGFRAME)*2;
- height += (PDIMENSION)GetSystemMetrics(SM_CYDLGFRAME)*2;
- }
- else if ((_styleBits&WS_THICKFRAME) != 0) {
- width += (PDIMENSION)GetSystemMetrics(SM_CXFRAME)*2;
- height += (PDIMENSION)GetSystemMetrics(SM_CYFRAME)*2;
- }
- if ((_styleBits&(WS_CHILD|WS_POPUP|WS_OVERLAPPED)) != WS_CHILD && GetMenu(_hWnd) != NULL)
- height += (PDIMENSION)GetSystemMetrics(SM_CYMENU);
- SetWindowPos(_hWnd, NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER);
- }
- BOOL PInteractor::AdjustDimensionForScrollBar(UINT bar) const
- {
- SCROLLINFO inf;
- inf.cbSize = sizeof(inf);
- inf.fMask = SIF_RANGE|SIF_PAGE;
- GetScrollInfo(_hWnd, bar, &inf);
- return inf.nMin != inf.nMax && inf.nPage < (UINT)(inf.nMax - inf.nMin);
- }
- PDim PInteractor::GetDimensions(CoordinateSystem coords) const
- {
- PRect r;
- GetClientRect(GetHWND(), r);
- if (coords != LocalCoords)
- return r.Dimensions();
- return FromPixels(r.Dimensions());
- }
- PRect PInteractor::GetStructureBounds(CoordinateSystem coords) const
- {
- PRect r;
- GetWindowRect(GetHWND(), r);
- if (coords == ScreenCoords)
- return r;
- PPoint p1(r.Origin());
- ScreenToClient(GetHWND(), p1);
- PPoint p2(r.Corner());
- ScreenToClient(GetHWND(), p2);
- if (coords == PixelCoords)
- return PRect(p1, p2);
- return PRect(FromPixels(p1), FromPixels(p2));
- }
- void PInteractor::_Invalidate(PORDINATE x, PORDINATE y,
- PDIMENSION dx, PDIMENSION dy,
- CoordinateSystem coords)
- {
- RECT cr;
- GetClientRect(GetHWND(), &cr);
- RECT r;
- switch (coords) {
- case LocalCoords :
- r.left = ToPixelsX(x);
- r.top = ToPixelsY(y);
- r.right = ToPixelsX(x+dx);
- r.bottom = ToPixelsY(y+dy);
- break;
- case PixelCoords :
- r.left = x;
- r.top = y;
- r.right = x+dx;
- r.bottom = y+dy;
- break;
- default : // ScreenCoords
- RECT wr;
- GetWindowRect(GetHWND(), &wr);
- r.left = wr.left+x;
- r.top = wr.top+y;
- r.right = x+dx;
- r.bottom = y+dy;
- }
- if (r.left < cr.left)
- r.left = cr.left;
- if (r.right > cr.right)
- r.right = cr.right;
- if (r.top < cr.top)
- r.top = cr.top;
- if (r.bottom > cr.bottom)
- r.bottom = cr.bottom;
- InvalidateRect(_hWnd, &r, FALSE);
- }
- void PInteractor::_Validate(PORDINATE x, PORDINATE y,
- PDIMENSION dx, PDIMENSION dy,
- CoordinateSystem coords)
- {
- RECT cr;
- GetClientRect(GetHWND(), &cr);
- RECT r;
- switch (coords) {
- case LocalCoords :
- r.left = ToPixelsX(x);
- r.top = ToPixelsY(y);
- r.right = ToPixelsX(x+dx);
- r.bottom = ToPixelsY(y+dy);
- break;
- case PixelCoords :
- r.left = x;
- r.top = y;
- r.right = x+dx;
- r.bottom = y+dy;
- break;
- default : // ScreenCoords
- RECT wr;
- GetWindowRect(GetHWND(), &wr);
- r.left = wr.left+x;
- r.top = wr.top+y;
- r.right = x+dx;
- r.bottom = y+dy;
- }
- if (r.left < cr.left)
- r.left = cr.left;
- if (r.right > cr.right)
- r.right = cr.right;
- if (r.top < cr.top)
- r.top = cr.top;
- if (r.bottom > cr.bottom)
- r.bottom = cr.bottom;
- ValidateRect(GetHWND(), &r);
- }
- void PInteractor::ReleaseMouse()
- {
- if (HasMouse())
- ReleaseCapture();
- }
- void PInteractor::SetCursorToParent(BOOL useParent)
- {
- if (cursorMode == UseParentCursor || cursorMode == UseCurrentCursor) {
- cursorMode = useParent ? UseParentCursor : UseCurrentCursor;
- parent->SetWndCursor();
- }
- }
- void PInteractor::SetCursor(const PCursor & newCursor)
- {
- if (cursorMode == UseParentCursor || cursorMode == UseCurrentCursor) {
- cursorMode = UseCurrentCursor;
- cursor = newCursor;
- if (_hWnd != P_DEAD_WINDOW &&
- ContainsPoint(GetCursorPos(ScreenCoords), ScreenCoords))
- SetWndCursor();
- }
- }
- void PInteractor::SetWndCursor() const
- {
- if (cursorMode == UseParentCursor && parent != NULL)
- parent->SetWndCursor();
- else
- ::SetCursor(cursor.GetHCURSOR());
- }
- void PInteractor::_SetCursorPos(PORDINATE x, PORDINATE y,
- CoordinateSystem coords)
- {
- PPoint p(x, y);
- switch (coords) {
- case LocalCoords :
- p = ToPixels(p);
- case PixelCoords :
- ClientToScreen(GetHWND(), p);
- break;
- case ScreenCoords :
- break;
- }
- ::SetCursorPos(p.X(), p.Y());
- }
- PPoint PInteractor::GetCursorPos(CoordinateSystem coords) const
- {
- PPoint p;
- ::GetCursorPos(p);
- if (coords == ScreenCoords)
- return p;
- ::ScreenToClient(GetHWND(), p);
- if (coords == PixelCoords)
- return p;
- return FromPixels(p);
- }
- PDim PInteractor::GetBorderSize() const
- {
- return owner->GetBorderSize();
- }
- const PColour & PInteractor::GetBorderColour() const
- {
- return owner->GetActiveBorderColour();
- }
- void PInteractor::SetBackgroundColour(const PColour & newColour)
- {
- backgroundColour = newColour;
- Invalidate();
- }
- BOOL PInteractor::HandleScrollBar(HWND scrWnd, WPARAM code, int trackVal)
- {
- if (scrWnd == NULL)
- return FALSE;
- PScrollBar * bar = (PScrollBar *)owner->GetWindowObject(scrWnd);
- if (bar == NULL)
- return FALSE;
- OnControlNotify(*bar, bar->TrackScrollBar(code, trackVal));
- return TRUE;
- }
- BOOL PInteractor::HandleCommand(NMHDR & msg)
- {
- if (msg.hwndFrom == NULL)
- return FALSE;
- PControl * control = (PControl*)owner->GetWindowObject(msg.hwndFrom);
- if (control == NULL)
- return FALSE;
- _WindowsMessage * oldMessage = control->_msg;
- control->_msg = _msg;
- int option = control->TranslateOption(msg);
- control->_msg = oldMessage;
- if (option < 0)
- return option < -1;
- OnControlNotify(*control, option);
- return !control->GetNotifier().IsNULL();
- }
- BOOL PInteractor::HandleDrawItem(const DRAWITEMSTRUCT FAR * dis)
- {
- PControl * item = (PControl *)owner->GetWindowObject(dis->hwndItem);
- if (item == NULL)
- return FALSE;
- switch (dis->CtlType) {
- case ODT_BUTTON :
- if (!((PPushButton *)item)->IsOwnerDraw())
- return FALSE;
- break;
- case ODT_LISTBOX :
- if (!item->IsDescendant(PCustomListBox::Class()))
- return FALSE;
- break;
- default :
- return FALSE;
- }
- PDrawCanvas canvas(item, dis->hDC, FALSE, FALSE);
- BOOL focus = (dis->itemState&ODS_FOCUS) != 0;
- BOOL select = (dis->itemState&ODS_SELECTED) != 0;
- if (dis->CtlType == ODT_BUTTON) {
- PPushButton * btn = (PPushButton *)item;
- PRect bounds = btn->DrawButtonSurround(canvas, select);
- btn->OnDrawFace(canvas, bounds, focus, select);
- }
- else {
- PRect bounds = canvas.FromPixels(PRect(dis->rcItem));
- if ((int)dis->itemID < 0)
- canvas.DrawFocusRect(bounds);
- else {
- if (!item->IsEnabled()) {
- canvas.SetTextFgColour(owner->GetGrayTextColour());
- canvas.SetTextBkColour(owner->GetWindowBkColour());
- }
- else if (select) {
- canvas.SetTextFgColour(owner->GetHighlightFgColour());
- canvas.SetTextBkColour(owner->GetHighlightBkColour());
- }
- else {
- canvas.SetTextFgColour(owner->GetWindowFgColour());
- canvas.SetTextBkColour(owner->GetWindowBkColour());
- }
- canvas.SetPenFgColour(canvas.GetTextBkColour());
- canvas.SetPenBkColour(canvas.GetTextBkColour());
- canvas.SetFillFgColour(canvas.GetTextBkColour());
- canvas.SetFillBkColour(canvas.GetTextBkColour());
- ((PCustomListBox *)item)->OnDrawEntry(dis->itemID,
- *(PObject *)dis->itemData, canvas, bounds, focus, select);
- }
- }
- return TRUE;
- }
- BOOL PInteractor::HandleMeasureItem(MEASUREITEMSTRUCT FAR * mis)
- {
- if (mis->CtlType != ODT_LISTBOX)
- return FALSE;
- PCustomListBox * listBox =
- (PCustomListBox *)owner->GetWindowObject(GetDlgItem(_hWnd, mis->CtlID));
- if (listBox == NULL)
- return FALSE;
- if (!listBox->IsDescendant(PCustomListBox::Class()))
- return FALSE;
- PDrawCanvas listBoxCanvas(listBox);
- PDim dim = listBoxCanvas.ToPixels(listBox->OnMeasureEntry(mis->itemID,
- *(PObject *)mis->itemData, listBoxCanvas));
- mis->itemWidth = dim.Width();
- mis->itemHeight = dim.Height();
- return TRUE;
- }
- int PInteractor::HandleCompareItem(const COMPAREITEMSTRUCT FAR * cis)
- {
- if (cis->CtlType != ODT_LISTBOX)
- return P_MAX_INDEX;
- PInteractor * listBox = owner->GetWindowObject(cis->hwndItem);
- if (listBox == NULL)
- return P_MAX_INDEX;
- if (!listBox->IsDescendant(PCustomListBox::Class()))
- return P_MAX_INDEX;
- PObject * obj1 = (PObject *)cis->itemData1;
- PObject * obj2 = (PObject *)cis->itemData2;
- if (obj1 == NULL || obj2 == NULL)
- return P_MAX_INDEX;
- return obj1->Compare(*obj2);
- }
- BOOL PInteractor::HandleDeleteItem(const DELETEITEMSTRUCT FAR * dis)
- {
- if (dis->CtlType != ODT_LISTBOX)
- return FALSE;
- PListBox * listBox = (PListBox*)owner->GetWindowObject(dis->hwndItem);
- if (listBox == NULL)
- return FALSE;
- if (!listBox->IsDescendant(PCustomListBox::Class()))
- return FALSE;
- if (listBox->deleteObjects)
- delete (PObject *)dis->itemData;
- return TRUE;
- }
- static PKeyCode KeyFromMouseEvent(UINT event, WPARAM wParam)
- {
- switch (event) {
- case WM_MBUTTONDOWN :
- case WM_MBUTTONDBLCLK :
- case WM_MBUTTONUP :
- return PKeyCode(TRUE, wParam, PKeyCode::MiddleButton);
- case WM_RBUTTONDOWN :
- case WM_RBUTTONDBLCLK :
- case WM_RBUTTONUP :
- return PKeyCode(TRUE, wParam, PKeyCode::RightButton);
- }
- return PKeyCode(TRUE, wParam, PKeyCode::LeftButton);
- }
- BOOL PInteractor::HandleCtlColour(HWND ctlWnd,
- HDC hDC, const PColour & defFg, const PColour & defBk)
- {
- PInteractor * control = owner->GetWindowObject(ctlWnd);
- if (control == NULL)
- return FALSE;
- const PColour & fg = control->GetForegroundColour();
- const PColour & bk = control->GetBackgroundColour();
- if (fg == defFg && bk == defBk)
- return FALSE;
- SetTextColor(hDC, fg.ToCOLORREF());
- SetBkColor(hDC, bk.ToCOLORREF());
- if (control->hBackgroundBrush == NULL)
- control->hBackgroundBrush = CreateSolidBrush(bk.ToCOLORREF());
- _msg->lResult = (LPARAM)control->hBackgroundBrush;
- return TRUE;
- }
- void PInteractor::WndProc()
- {
- switch (_msg->event) {
- case WM_MOUSEMOVE :
- if (PGET_CLASS_VALUE(_hWnd, HCURSOR) == 0)
- SetWndCursor();
- _OnMouseMove(PKeyCode(TRUE, _msg->wParam, PKeyCode::NullValue), PPoint(_msg->lParam));
- return;
- case WM_LBUTTONDOWN :
- case WM_MBUTTONDOWN :
- case WM_RBUTTONDOWN :
- owner->DoBalloonHelp(NULL);
- if (GetCapture() == NULL)
- SetCapture(_hWnd);
- OnMouseDown(KeyFromMouseEvent(_msg->event, _msg->wParam), PPoint(_msg->lParam), FALSE);
- return;
- case WM_LBUTTONDBLCLK :
- case WM_MBUTTONDBLCLK :
- case WM_RBUTTONDBLCLK :
- owner->DoBalloonHelp(NULL);
- OnMouseDown(KeyFromMouseEvent(_msg->event, _msg->wParam), PPoint(_msg->lParam), TRUE);
- return;
- case WM_LBUTTONUP :
- case WM_MBUTTONUP :
- case WM_RBUTTONUP :
- _OnMouseUp(KeyFromMouseEvent(_msg->event, _msg->wParam), PPoint(_msg->lParam));
- if (GetCapture() == _hWnd)
- ReleaseCapture();
- return;
- case WM_KEYDOWN :
- owner->DoBalloonHelp(NULL);
- if (OnKeyDown(PKeyCode(FALSE, _msg->wParam, HIWORD(_msg->lParam)),
- (_msg->lParam&0x40000000)!=0 ? LOWORD(_msg->lParam) : 0))
- DefWndProc();
- return;
- case WM_KEYUP :
- owner->DoBalloonHelp(NULL);
- OnKeyUp(PKeyCode(FALSE, _msg->wParam, HIWORD(_msg->lParam)));
- return;
- case WM_CHAR :
- OnKeyInput(PString((char)_msg->wParam));
- return;
- case WM_SETFOCUS : {
- caret.Activate(this, caretVisible <= 0);
- OnGainFocus();
- PInteractor * focus = GetFocusInteractor();
- if (focus != this && focus != NULL) {
- if (focus->OnEndInput()) {
- SetFocusInteractor(this);
- OnStartInput();
- }
- else
- focus->GrabFocus();
- }
- break;
- }
- case WM_KILLFOCUS :
- caret.Deactivate(this);
- OnLostFocus();
- break;
- case WM_VSCROLL :
- case WM_HSCROLL :
- #if defined(_WIN32)
- if (HandleScrollBar((HWND)_msg->lParam,
- LOWORD(_msg->wParam), HIWORD(_msg->wParam)))
- #else
- if (HandleScrollBar((HWND)HIWORD(_msg->lParam),
- _msg->wParam, (int)LOWORD(_msg->lParam)))
- #endif
- return;
- break;
- case WM_COMMAND :
- {
- NMHDR msg;
- #if defined(_WIN32)
- msg.hwndFrom = (HWND)_msg->lParam;
- msg.idFrom = LOWORD(_msg->wParam);
- msg.code = HIWORD(_msg->wParam);
- #else
- msg.hwndFrom = (HWND)LOWORD(_msg->lParam);
- msg.idFrom = wParam;
- msg.code = HIWORD(_msg->lParam);
- #endif
- if (HandleCommand(msg))
- return;
- break;
- }
- case WM_NOTIFY :
- if (HandleCommand(*(LPNMHDR)_msg->lParam))
- return;
- break;
- case WM_DRAWITEM :
- if (HandleDrawItem((const DRAWITEMSTRUCT FAR *)_msg->lParam)) {
- _msg->lResult = TRUE;
- return;
- }
- break;
- case WM_MEASUREITEM :
- if (HandleMeasureItem((MEASUREITEMSTRUCT FAR *)_msg->lParam), _hWnd) {
- _msg->lResult = TRUE;
- return;
- }
- break;
- case WM_COMPAREITEM :
- switch (HandleCompareItem((const COMPAREITEMSTRUCT FAR *)_msg->lParam)) {
- case PObject::LessThan :
- _msg->lResult = -1;
- return;
- case PObject::EqualTo :
- _msg->lResult = 0;
- return;
- case PObject::GreaterThan :
- _msg->lResult = 1;
- return;
- }
- break;
- case WM_DELETEITEM :
- if (HandleDeleteItem((const DELETEITEMSTRUCT FAR *)_msg->lParam)) {
- _msg->lResult = TRUE;
- return;
- }
- break;
- case WM_ERASEBKGND :
- if (PGET_CLASS_VALUE(_hWnd, HBRBACKGROUND) == 0) {
- HBRUSH b = CreateSolidBrush(backgroundColour.ToCOLORREF());
- RECT r;
- GetClientRect(_hWnd, &r);
- FillRect((HDC)_msg->wParam, &r, b);
- DeleteObject(b);
- _msg->lResult = TRUE;
- return;
- }
- break;
- #ifdef _WIN32
- case WM_CTLCOLORBTN :
- case WM_CTLCOLORSTATIC :
- if (HandleCtlColour((HWND)_msg->lParam, (HDC)_msg->wParam,
- owner->GetButtonFgColour(), owner->GetButtonBkColour()))
- return;
- break;
- case WM_CTLCOLORSCROLLBAR :
- if (HandleCtlColour((HWND)_msg->lParam, (HDC)_msg->wParam,
- owner->GetScrollBarColour(), owner->GetScrollBarColour()))
- return;
- break;
- case WM_CTLCOLOREDIT :
- case WM_CTLCOLORLISTBOX :
- if (HandleCtlColour((HWND)_msg->lParam, (HDC)_msg->wParam,
- owner->GetWindowFgColour(), owner->GetWindowBkColour()))
- return;
- break;
- #else
- case WM_CTLCOLOR :
- switch (HIWORD(_msg->lParam)) {
- case CTLCOLOR_BTN :
- if (HandleCtlColour((HWND)LOWORD(_msg->lParam), (HDC)_msg->wParam,
- owner->GetButtonFgColour(), owner->GetButtonBkColour()))
- return;
- break;
- case CTLCOLOR_SCROLLBAR :
- if (HandleCtlColour((HWND)LOWORD(_msg->lParam), (HDC)_msg->wParam,
- owner->GetScrollBarColour(), owner->GetScrollBarColour()))
- return;
- break;
- case CTLCOLOR_EDIT :
- case CTLCOLOR_STATIC :
- case CTLCOLOR_LISTBOX :
- if (HandleCtlColour((HWND)LOWORD(_msg->lParam), (HDC)_msg->wParam,
- owner->GetWindowFgColour(), owner->GetWindowBkColour()))
- return;
- break;
- }
- break;
- #endif
- case WM_PAINT :
- if (_in_WM_PAINT)
- DefWndProc();
- else {
- _in_WM_PAINT = TRUE;
- PRedrawCanvas canvas(this, FALSE);
- OnRedraw(canvas);
- if (canvas.NullHDC())
- DefWndProc();
- _in_WM_PAINT = FALSE;
- }
- return;
- case WM_DESTROY :
- owner->DoBalloonHelp(NULL);
- owner->RemoveWindowHandle(_hWnd);
- RemoveWndFont();
- _hWnd = P_DEAD_WINDOW;
- return;
- }
- DefWndProc();
- }
- void PInteractor::DefWndProc()
- {
- _msg->lResult=DefWindowProc(_hWnd, _msg->event, _msg->wParam, _msg->lParam);
- _msg->processed = FALSE;
- }
- void PInteractor::OnMouseDown(PKeyCode, const PPoint &, BOOL)
- {
- if (GetCapture() == _hWnd)
- ReleaseCapture();
- DefWndProc();
- }
- void PInteractor::OnMouseUp(PKeyCode, const PPoint &)
- {
- DefWndProc();
- }
- void PInteractor::OnMouseMove(PKeyCode, const PPoint &)
- {
- DefWndProc();
- }
- BOOL PInteractor::OnKeyDown(PKeyCode, unsigned)
- {
- return TRUE;
- }
- void PInteractor::OnKeyUp(PKeyCode key)
- {
- DefWndProc();
- }
- void PInteractor::OnKeyInput(const PString &)
- {
- DefWndProc();
- }
- void PInteractor::OnGainFocus()
- {
- DefWndProc();
- }
- void PInteractor::OnLostFocus()
- {
- DefWndProc();
- }
- void PInteractor::OnRedraw(PCanvas & canvas)
- {
- if (canvas.NullHDC() && canvas.IsDescendant(PRedrawCanvas::Class())) {
- DefWndProc();
- canvas.SetHDC(GetDC(_hWnd));
- }
- }
- void PInteractor::SetWndFont() const
- {
- RemoveWndFont();
- HFONT hFont = CreateFont(font.GetHeight(TRUE),
- 0, 0, 0,
- font.IsBold() ? FW_BOLD : FW_NORMAL,
- (BYTE)font.IsItalic(),
- (BYTE)font.IsUnderlined(),
- 0, 0, 0, 0, 0, 0,
- font.GetFacename());
- PAssertOS(hFont != NULL);
- SendMessage(GetHWND(), WM_SETFONT, (WPARAM)hFont, 0L);
- if ((HFONT)(UINT)SendMessage(GetHWND(), WM_GETFONT, 0, 0L) != hFont)
- DeleteObject(hFont);
- }
- void PInteractor::RemoveWndFont() const
- {
- HFONT hFont = (HFONT)(UINT)SendMessage(GetHWND(), WM_GETFONT, 0, 0L);
- if (hFont == NULL)
- return;
- HWND parWnd = P_DEAD_WINDOW;
- if (GetParent() != NULL)
- parWnd = GetParent()->_hWnd;
- if (parWnd != P_DEAD_WINDOW &&
- (HFONT)(UINT)SendMessage(parWnd, WM_GETFONT, 0, 0L) == hFont)
- return; // Let parent class delete the hFont
- SendMessage(GetHWND(), WM_SETFONT, NULL, 0L);
- DeleteObject(hFont);
- }
- void PInteractor::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- wndClass.style = CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
- wndClass.lpfnWndProc = owner->GetWndProcPtr(PApplication::WndProcType);
- wndClass.cbClsExtra = 0;
- wndClass.cbWndExtra = 0;
- wndClass.hInstance = owner->GetInstance();
- wndClass.hIcon = NULL;
- wndClass.hCursor = NULL;
- wndClass.hbrBackground = NULL;
- wndClass.lpszMenuName = NULL;
- wndClass.lpszClassName = GetClass();
- _styleBits = WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
- _exStyleBits = WS_EX_NOPARENTNOTIFY;
- }
- PINDEX PInteractor::GetNumChildren()
- {
- if (_hWnd == NULL)
- GetHWND();
- return children.GetSize();
- }
- HWND PInteractor::GetHWND() const
- {
- if (_hWnd == NULL) {
- if (PThread::Current() == owner)
- ((PInteractor*)this)->CreateHWND();
- else {
- // All windows must be created in the main thread, so go to stupid
- // lengths to make sure it happens
- owner->windowsMutex.Wait();
- owner->delayedCreateInteractors.Append((PInteractor*)this);
- owner->windowsMutex.Signal();
- // Post a message to unblock the main loop, so can process above.
- ::PostThreadMessage(owner->GetThreadId(), WM_USER, 0, 0);
- // Wait for main loop thread to do the job.
- owner->delayedCreateInteractorsDone.Wait();
- }
- }
- if (_hWnd != NULL && _hWnd != P_DEAD_WINDOW)
- return _hWnd;
- PAssertAlways(PInvalidWindow);
- return NULL;
- }
- void PInteractor::CreateHWND()
- {
- PAssert(parent != NULL ||
- IsDescendant(PTopLevelWindow::Class()), "Window has no parent");
- HINSTANCE hInst = owner->GetInstance();
- WNDCLASS wclass;
- GetCreateWinInfo(wclass);
- if (!GetClassInfo(hInst, wclass.lpszClassName, &wclass))
- PAssertOS(RegisterClass(&wclass));
- _hWnd = CreateWindowEx(_exStyleBits, wclass.lpszClassName, "", _styleBits,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- parent != NULL ? parent->GetHWND() : NULL,
- NULL, hInst, NULL);
- owner->AddWindowHandle(PAssertNULL(_hWnd), this);
- SetWndFont();
- }
- PString PInteractor::GetWndText(UINT lenMsg,
- UINT getMsg,WPARAM wParamGet, WPARAM wParamLen) const
- {
- PString title;
- HWND hWnd = GetHWND();
- UINT len = (UINT)SendMessage(hWnd, lenMsg, wParamLen, 0L)+1;
- if (len < sizeof(UINT))
- len = sizeof(UINT);
- char * ptr = title.GetPointer(len);
- if (wParamGet == (WPARAM)-1)
- wParamGet = len;
- else
- *(UINT *)ptr = len;
- SendMessage(hWnd, getMsg, wParamGet, (DWORD)(LPSTR)ptr);
- PINDEX pos;
- while ((pos = title.Find("rn")) != P_MAX_INDEX)
- title.Delete(pos, 1);
- return title;
- }
- //////////////////////////////////////////////////////////////////////////////
- PTitledWindow::PTitledWindow(PInteractor * par, unsigned CanDo)
- : PInteractor(par),
- icon(PSTD_ID_ICON_WINDOW)
- {
- focusInteractor = this;
- initFlags = CanDo;
- }
- PTitledWindow::PTitledWindow(unsigned CanDo)
- : icon(PSTD_ID_ICON_WINDOW)
- {
- focusInteractor = this;
- initFlags = CanDo;
- }
- void PTitledWindow::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PInteractor::GetCreateWinInfo(wndClass);
- if ((initFlags&CanClose) == 0)
- wndClass.style |= CS_NOCLOSE;
- wndClass.hIcon = icon.GetHICON();
- if ((initFlags&CanGrow) != 0)
- _styleBits |= WS_THICKFRAME;
- if ((initFlags&CanIconify) != 0)
- _styleBits |= WS_MINIMIZEBOX;
- if ((initFlags&CanZoom) != 0)
- _styleBits |= WS_MAXIMIZEBOX;
- _styleBits |= WS_CAPTION|WS_SYSMENU;
- }
- void PTitledWindow::WndProc()
- {
- switch (_msg->event) {
- case WM_CLOSE :
- Close();
- return;
- case WM_DESTROY :
- OnClose();
- break;
- case WM_SETFOCUS :
- if (GetFocusInteractor() != this) {
- GetFocusInteractor()->GrabFocus();
- DefWndProc();
- return;
- }
- break;
- case WM_NCACTIVATE :
- if (_msg->wParam == FALSE && owner->balloon != NULL) {
- _msg->lResult = 0;
- return;
- }
- break;
- case WM_ACTIVATE :
- OnActivate(LOWORD(_msg->wParam) != WA_INACTIVE);
- break;
- case WM_MDIACTIVATE :
- OnActivate((HWND)(UINT)_msg->lParam == _hWnd);
- break;
- case WM_MOVE :
- OnReposition(PPoint(_msg->lParam));
- break;
- case WM_SIZE :
- if (IsWindowVisible(_hWnd))
- OnResize(PDim::FromDWORD(_msg->lParam),
- _msg->wParam == SIZE_MINIMIZED ? Iconic :
- _msg->wParam == SIZE_MAXIMIZED ? Zoomed : Normalised);
- break;
- case WM_GETMINMAXINFO :
- MINMAXINFO * mmi = (MINMAXINFO *)_msg->lParam;
- PRect client;
- GetClientRect(GetHWND(), client);
- PRect structure = client;
- AdjustWindowRectEx(structure, _styleBits,
- IsDescendant(PTopLevelWindow::Class()) &&
- ((PTopLevelWindow *)this)->GetMenu() != NULL,
- _exStyleBits);
- PDim adjust = structure.Dimensions() - client.Dimensions();
- if (minSize.Width() != 0 && minSize.Height() != 0) {
- mmi->ptMinTrackSize.x = minSize.Width() + adjust.Width();
- mmi->ptMinTrackSize.y = minSize.Height() + adjust.Height();
- }
- if (maxSize.Width() != 0 && maxSize.Height() != 0) {
- mmi->ptMaxTrackSize.x = maxSize.Width() + adjust.Width();
- mmi->ptMaxTrackSize.y = maxSize.Height() + adjust.Height();
- }
- if (zoomSize.Width() != 0 && zoomSize.Height() != 0) {
- mmi->ptMaxSize.x = zoomSize.Width() + adjust.Width();
- mmi->ptMaxSize.y = zoomSize.Height() + adjust.Height();
- }
- break;
- }
- PInteractor::WndProc();
- }
- void PTitledWindow::SetMinSize(const PDim & dim, CoordinateSystem coords)
- {
- if (coords != LocalCoords)
- minSize = dim;
- else
- minSize = ToPixels(dim);
- SetDimensions(GetDimensions(PixelCoords), PixelCoords);
- }
- void PTitledWindow::SetMaxSize(const PDim & dim, CoordinateSystem coords)
- {
- if (coords != LocalCoords)
- maxSize = dim;
- else
- maxSize = ToPixels(dim);
- SetDimensions(GetDimensions(PixelCoords), PixelCoords);
- }
- void PTitledWindow::SetIcon(const PIcon & icn)
- {
- PSET_CLASS_VALUE(GetHWND(), HICON, icn.GetHICON());
- icon = icn;
- }
- void PTitledWindow::OnReposition(const PPoint &)
- {
- DefWndProc();
- }
- void PTitledWindow::OnActivate(BOOL)
- {
- DefWndProc();
- }
- void PTitledWindow::OnResize(const PDim &, ResizeType)
- {
- DefWndProc();
- }
- //////////////////////////////////////////////////////////////////////////////
- PTopLevelWindow::PTopLevelWindow(unsigned CanDo)
- : PTitledWindow(CanDo),
- helpMenu(PResourceString(PSTD_ID_STR_HELP_MENU, "&Help"))
- {
- menu = NULL;
- deleteMenu = FALSE;
- if (owner->mainWindow == NULL)
- owner->mainWindow = this;
- SetTitle(owner->GetName());
- SetMenu(NULL);
- new PMenuItem(PSTD_ID_MENU_HELP_CONTENTS, helpMenu,
- PResourceString(PSTD_ID_STR_HELP_CONTENTS, "&Contents"));
- new PMenuItem(PSTD_ID_STR_HELP_SEARCH, helpMenu,
- PResourceString(PSTD_ID_STR_HELP_SEARCH, "&Search for Help..."));
- new PMenuItem(PSTD_ID_MENU_HELP_ON_HELP, helpMenu,
- PResourceString(PSTD_ID_STR_HELP_ON_HELP, "&How to Use Help"));
- new PMenuSeparator(helpMenu);
- new PMenuItem(PSTD_ID_MENU_ABOUT, helpMenu, owner->GetAboutMenuItemString());
- }
- PTopLevelWindow::~PTopLevelWindow()
- {
- if (deleteMenu)
- delete menu;
- if (owner->mainWindow == this)
- owner->mainWindow = NULL;
- }
- void PTopLevelWindow::WndProc()
- {
- switch (_msg->event) {
- case WM_SYSCOMMAND :
- if (_msg->wParam == PSTD_ID_MENU_ABOUT) {
- owner->OnAbout();
- return;
- }
- break;
- case WM_COMMAND :
- switch (_msg->wParam) {
- case PSTD_ID_MENU_ABOUT :
- owner->OnAbout();
- return;
- case PSTD_ID_MENU_HELP_CONTENTS :
- owner->DoContextHelp(PSTD_ID_HELP_CONTENTS);
- return;
- case PSTD_ID_MENU_HELP_SEARCH :
- owner->DoContextHelp(PSTD_ID_HELP_SEARCH);
- return;
- case PSTD_ID_MENU_HELP_ON_HELP :
- owner->DoContextHelp(PSTD_ID_HELP_ON_HELP);
- return;
- default :
- if (menu != NULL &&
- #if defined(_WIN32)
- _msg->lParam == 0)
- #else
- LOWORD(_msg->lParam) == 0)
- #endif
- {
- PMenuItem*item=menu->GetItemFromKey((PRESOURCE_ID)LOWORD(_msg->wParam));
- if (item != NULL) {
- OnMenuItemSelect(*item);
- return;
- }
- }
- }
- break;
- case WM_INITMENU :
- if (_msg->wParam != 0 && menu != NULL) {
- OnMenuStartSelect();
- return;
- }
- break;
- }
- PTitledWindow::WndProc();
- }
- void PTopLevelWindow::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PTitledWindow::GetCreateWinInfo(wndClass);
- _styleBits &= ~WS_CHILD;
- }
- //////////////////////////////////////////////////////////////////////////////
- PMDIFrameWindow::PMDIFrameWindow(unsigned CanDo)
- : PTopLevelWindow(CanDo),
- windowMenu(PResourceString(PSTD_ID_STR_WINDOW_MENU, "&Window"))
- {
- CLIENTCREATESTRUCT ccs;
- ccs.hWindowMenu = windowMenu.GetHMENU();
- ccs.idFirstChild = 32000;
- mdiClient = CreateWindow("MDICLIENT", "",
- WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_VISIBLE|MDIS_ALLCHILDSTYLES,
- 0, 0, 0, 0, GetHWND(), NULL, owner->GetInstance(), &ccs);
- PAssertNULL(mdiClient);
- owner->mdiClient = mdiClient;
- backgroundColour.FromSYSCOLOR(COLOR_APPWORKSPACE);
- new PMenuItem(PSTD_ID_MENU_WINDOW_CASCADE, windowMenu,
- PResourceString(PSTD_ID_STR_WINDOW_CASCADE, "&Cascade"));
- new PMenuItem(PSTD_ID_MENU_WINDOW_TILE, windowMenu,
- PResourceString(PSTD_ID_STR_WINDOW_TILE, "&Tile"));
- new PMenuItem(PSTD_ID_MENU_WINDOW_ARRANGE, windowMenu,
- PResourceString(PSTD_ID_STR_WINDOW_ARRANGE, "&Arrange Icons"));
- }
- PMDIDocWindow * PMDIFrameWindow::GetActiveDocument()
- {
- HWND hChild = (HWND)(UINT)SendMessage(mdiClient, WM_MDIGETACTIVE, 0, 0L);
- if (hChild == NULL)
- return NULL;
- PInteractor * window = owner->GetWindowObject(hChild);
- return (PMDIDocWindow *)PAssertNULL(window);
- }
- void PMDIFrameWindow::SetDocumentArea(const PRect & rect,
- CoordinateSystem coords)
- {
- switch (coords) {
- case LocalCoords :
- documentArea = ToPixels(rect);
- break;
- case PixelCoords :
- documentArea = rect;
- break;
- case ScreenCoords :
- PPoint origin = rect.Origin();
- ClientToScreen(GetHWND(), origin);
- documentArea = rect;
- documentArea.SetOrigin(origin);
- }
- PRect r = documentArea;
- if (documentArea.IsEmpty())
- r = GetDimensions(PixelCoords);
- SetWindowPos(mdiClient, HWND_BOTTOM,
- r.X(), r.Y(), r.Width(), r.Height(), SWP_NOACTIVATE);
- }
- void PMDIFrameWindow::WndProc()
- {
- switch (_msg->event) {
- case WM_COMMAND :
- switch (_msg->wParam) {
- case PSTD_ID_MENU_WINDOW_CASCADE :
- CascadeDocuments();
- return;
- case PSTD_ID_MENU_WINDOW_TILE :
- TileDocuments(GetKeyState(VK_SHIFT) < 0);
- return;
- case PSTD_ID_MENU_WINDOW_ARRANGE :
- ArrangeIcons();
- return;
- }
- break;
- case WM_SIZE :
- PTopLevelWindow::WndProc();
- SetDocumentArea(documentArea, PixelCoords);
- return;
- }
- PTopLevelWindow::WndProc();
- }
- void PMDIFrameWindow::DefWndProc()
- {
- _msg->lResult = DefFrameProc(_hWnd,
- mdiClient, _msg->event, _msg->wParam, _msg->lParam);
- }
- ///////////////////////////////////////////////////////////////////////////////
- // PMDIDocWindow
- PMDIDocWindow::~PMDIDocWindow()
- {
- if (_hWnd != NULL && _hWnd != P_DEAD_WINDOW)
- SendMessage(((PMDIFrameWindow*)GetParent())->mdiClient,
- WM_MDIDESTROY, (WPARAM)_hWnd, 0L);
- }
- void PMDIDocWindow::CreateHWND()
- {
- PAssert(parent->IsDescendant(PMDIFrameWindow::Class()), "Bad MDI parent");
- HINSTANCE hInst = owner->GetInstance();
- WNDCLASS wclass;
- MDICREATESTRUCT mcs;
- GetCreateWinInfo(wclass);
- mcs.style = _styleBits;
- mcs.szClass = wclass.lpszClassName;
- mcs.szTitle = initialTitle;
- mcs.hOwner = hInst;
- mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
- mcs.lParam = 0;
- if (!GetClassInfo(hInst, wclass.lpszClassName, &wclass))
- PAssertOS(RegisterClass(&wclass));
- #if defined(_WIN32)
- _hWnd = CreateMDIWindow((LPTSTR)mcs.szClass, (LPTSTR)mcs.szTitle,
- mcs.style, mcs.x, mcs.y, mcs.cx, mcs.cy,
- ((PMDIFrameWindow *)parent)->mdiClient,
- hInst, mcs.lParam);
- #else
- _hWnd = (HWND)(UINT)SendMessage(((PMDIFrameWindow *)parent)->mdiClient,
- WM_MDICREATE, 0, (LPARAM)&mcs);
- #endif
- owner->AddWindowHandle(PAssertNULL(_hWnd), this);
- SetWndFont();
- }
- void PMDIDocWindow::DefWndProc()
- {
- _msg->lResult = DefMDIChildProc(_hWnd,_msg->event,_msg->wParam,_msg->lParam);
- }
- void PMDIDocWindow::Show(BOOL visible)
- {
- ShowWindow(GetHWND(), visible ? SW_SHOW : SW_HIDE);
- #if defined(_WIN32)
- SendMessage(((PMDIFrameWindow *)parent)->mdiClient,WM_MDIREFRESHMENU, 0, 0L);
- #else
- SendMessage(((PMDIFrameWindow *)parent)->mdiClient, WM_MDISETMENU, TRUE, 0L);
- #endif
- PDim dim = GetDimensions(PixelCoords);
- PInteractor::_WindowsMessage * oldMsg = _msg;
- PInteractor::_WindowsMessage message;
- message.event = WM_SIZE;
- message.wParam = SIZE_RESTORED;
- message.lParam = dim.ToDWORD();
- message.lResult = 0;
- message.processed = TRUE;
- _msg = &message;
- OnResize(dim, Normalised);
- _msg = oldMsg;
- }
- void PMDIDocWindow::Activate()
- {
- if (!IsVisible())
- Show();
- SendMessage(((PMDIFrameWindow*)parent)->mdiClient,
- WM_MDIACTIVATE, (WPARAM)GetHWND(), 0L);
- }
- void PMDIDocWindow::SetTitle(const PString & title)
- {
- PTitledWindow::SetTitle(title);
- #if defined(_WIN32)
- SendMessage(((PMDIFrameWindow *)parent)->mdiClient,WM_MDIREFRESHMENU, 0, 0L);
- #else
- SendMessage(((PMDIFrameWindow *)parent)->mdiClient, WM_MDISETMENU, TRUE, 0L);
- #endif
- }
- ///////////////////////////////////////////////////////////////////////////////
- // PPopUp
- PPopUp::PPopUp(PInteractor * parent)
- : PInteractor(parent)
- {
- }
- void PPopUp::GetCreateWinInfo(WNDCLASS & wndClass)
- {
- PInteractor::GetCreateWinInfo(wndClass);
- wndClass.style = CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS;
- _styleBits = WS_POPUP|WS_BORDER|WS_DISABLED;
- _exStyleBits |= WS_EX_TOPMOST;
- }
- void PPopUp::WndProc()
- {
- switch (_msg->event) {
- case WM_SETFOCUS :
- case WM_MOUSEMOVE :
- return;
- }
- PInteractor::WndProc();
- }
- // End Of File ///////////////////////////////////////////////////////////////