soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SNcPainter.cpp
1#include "souistd.h"
2#include "core/SNcPainter.h"
3#include "core/SHostWnd.h"
4
5SNSBEGIN
6
7SNcPanel::SNcPanel(IHostProxy *pFrameHost, IItemContainer *pItemContainer)
8 : SOsrPanel(pFrameHost, pItemContainer)
9 , m_bActive(FALSE)
10 , m_crActiveTitle(RGBA(0, 0, 0, 255))
11 , m_crInactiveTitle(RGBA(128, 128, 128, 255))
12
13{
14}
15
17{
18 ISkinObj *pSkin = m_bActive ? m_skinActive : m_skinInactive;
19 CRect rcClient = GetClientRect();
20 if (pSkin)
21 {
22 pSkin->DrawByIndex(pRT, rcClient, 0);
23 }
24 else
25 {
26 COLORREF crBg = GetBkgndColor();
27 if (CR_INVALID != crBg)
28 {
29 pRT->FillSolidRect(&rcClient, crBg);
30 }
31 }
32 return TRUE;
33}
34
35void SNcPanel::SetActive(BOOL bActive)
36{
37 m_bActive = bActive;
38 SWindow *pTitle = FindChildByID(SNcPainter::IDC_SYS_TITLE);
39 if (pTitle)
40 {
41 COLORREF crTitle = bActive ? m_crActiveTitle : m_crInactiveTitle;
42 pTitle->GetStyle().SetTextColor(WndState_Normal, crTitle);
43 }
44}
45
46//////////////////////////////////////////////////////////////////////////
47SNcPainter::SNcPainter(SHostWnd *pHost)
48 : m_pHost(pHost)
49 , m_bInPaint(FALSE)
50 , m_bSysNcPainter(FALSE)
51 , m_bLButtonDown(FALSE)
52 , m_bMouseHover(FALSE)
53{
54 m_root = new SNcPanel(this, this);
55}
56
58{
59 delete m_root;
60}
61
63{
64 m_borderWidth = SLayoutSize();
65 m_titleHeight = SLayoutSize();
66 m_skinBorder = NULL;
67 m_memRT = NULL;
68 m_memTop = NULL;
69 m_memLeft = NULL;
70 m_memBottom = NULL;
71 m_memRight = NULL;
72 m_bSysNcPainter = FALSE;
73 m_bLButtonDown = FALSE;
74}
75
76BOOL SNcPainter::InitFromXml(THIS_ IXmlNode *pXmlNode)
77{
78 SXmlNode xmlNode(pXmlNode);
79 if (!xmlNode || m_pHost->IsTranslucent())
80 {
81 Reset();
82 }
83 else
84 {
85 __baseCls::InitFromXml(pXmlNode);
86 m_root->InitFromXml(pXmlNode);
87 m_memRT = NULL;
88 m_memLeft = m_memRight = m_memTop = m_memBottom = NULL;
89 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, 0, 0);
90 GETRENDERFACTORY->CreateRenderTarget(&m_memLeft, 0, 0);
91 GETRENDERFACTORY->CreateRenderTarget(&m_memRight, 0, 0);
92 GETRENDERFACTORY->CreateRenderTarget(&m_memTop, 0, 0);
93 GETRENDERFACTORY->CreateRenderTarget(&m_memBottom, 0, 0);
94 }
95 return TRUE;
96}
97
98IWindow *SNcPainter::GetRoot(THIS)
99{
100 return m_root;
101}
102
104{
105 return m_pHost->GetScale();
106}
107
108LRESULT SNcPainter::OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
109{
110 if (m_titleHeight.isZero() && m_borderWidth.isZero())
111 {
112 LPNCCALCSIZE_PARAMS pParam = (LPNCCALCSIZE_PARAMS)lParam;
113 INativeWnd *pNative = m_pHost->GetNative();
114 if (bCalcValidRects && (pNative->GetStyle() & WS_CHILDWINDOW))
115 {
116 if (SWP_NOSIZE & pParam->lppos->flags)
117 return 0;
118
119 CRect rcWindow;
120 pNative->GetWindowRect(rcWindow);
121 POINT point = { rcWindow.left, rcWindow.top };
122 ::ScreenToClient(::GetParent(pNative->GetHwnd()), &point);
123 int w = rcWindow.Width();
124 int h = rcWindow.Height();
125
126 rcWindow.left = point.x;
127 rcWindow.top = point.y;
128 rcWindow.right = rcWindow.left + w;
129 rcWindow.bottom = rcWindow.top + h;
130
131 if (0 == (SWP_NOMOVE & pParam->lppos->flags))
132 {
133 rcWindow.left = pParam->lppos->x;
134 rcWindow.top = pParam->lppos->y;
135 }
136
137 rcWindow.right = rcWindow.left + pParam->lppos->cx;
138 rcWindow.bottom = rcWindow.top + pParam->lppos->cy;
139 pParam->rgrc[0] = rcWindow;
140 }
141 else if (bCalcValidRects)
142 {
143 if (SWP_NOSIZE & pParam->lppos->flags)
144 return 0;
145
146 CRect rcWindow;
147 pNative->GetWindowRect(rcWindow);
148 rcWindow = CRect(rcWindow.TopLeft(), CSize(pParam->lppos->cx, pParam->lppos->cy));
149 if (0 == (SWP_NOMOVE & pParam->lppos->flags))
150 {
151 rcWindow.MoveToXY(pParam->lppos->x, pParam->lppos->y);
152 }
153 pParam->rgrc[0] = rcWindow;
154 }
155 else
156 {
157 pNative->GetWindowRect((LPRECT)lParam);
158 }
159 }
160 else
161 {
162 if (bCalcValidRects && IsDrawNc() && !m_pHost->IsIconic())
163 {
164 LPNCCALCSIZE_PARAMS pParam = (LPNCCALCSIZE_PARAMS)lParam;
165 CRect rcWnd = pParam->rgrc[0];
166 rcWnd.MoveToXY(0, 0);
167 CRect &rc = (CRect &)pParam->rgrc[0]; // get the client rectangle
168 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
169 int nTitleHei = m_titleHeight.toPixelSize(GetScale());
170 rc.DeflateRect(nBorderWid, nBorderWid);
171 rc.top += nTitleHei;
172
173 CRect rcCaption(0, 0, rc.Width(), nTitleHei);
174 m_memRT->Resize(rcCaption.Size());
175 m_memRT->SetViewportOrg(CPoint(-nBorderWid, -nBorderWid));
176
177 m_root->Move(rcCaption);
178 m_root->UpdateLayout();
179 m_rcInvalid = rcCaption;
180 m_rcInvalid.OffsetRect(nBorderWid, nBorderWid);
181
182 m_memLeft->Resize(CSize(nBorderWid, rcWnd.Height()));
183 m_memLeft->BeginDraw();
184 m_skinBorder->DrawByIndex(m_memLeft, &rcWnd, 0);
185 m_memLeft->EndDraw();
186
187 m_memRight->Resize(CSize(nBorderWid, rcWnd.Height()));
188 m_memRight->SetViewportOrg(CPoint(-(rcWnd.right - nBorderWid), 0));
189 m_memRight->BeginDraw();
190 m_skinBorder->DrawByIndex(m_memRight, &rcWnd, 0);
191 m_memRight->EndDraw();
192
193 m_memTop->Resize(CSize(rcWnd.Width() - 2 * nBorderWid, nBorderWid));
194 m_memTop->SetViewportOrg(CPoint(-nBorderWid, 0));
195 m_memTop->BeginDraw();
196 m_skinBorder->DrawByIndex(m_memTop, &rcWnd, 0);
197 m_memTop->EndDraw();
198
199 m_memBottom->Resize(CSize(rcWnd.Width() - 2 * nBorderWid, nBorderWid));
200 m_memBottom->SetViewportOrg(CPoint(-nBorderWid, -(rcWnd.bottom - nBorderWid)));
201 m_memBottom->BeginDraw();
202 m_skinBorder->DrawByIndex(m_memBottom, &rcWnd, 0);
203 m_memBottom->EndDraw();
204 }
205 else
206 {
207 SetMsgHandled(FALSE);
208 }
209 }
210 return 0;
211}
212
213BOOL SNcPainter::OnNcActivate(BOOL bActive)
214{
215 if (IsDrawNc())
216 {
217 DWORD dwStyle = m_pHost->GetStyle();
218 if (dwStyle & WS_VISIBLE)
219 m_pHost->SetWindowLongPtr(GWL_STYLE, dwStyle & ~WS_VISIBLE);
220 m_pHost->DefWindowProc();
221 if (dwStyle & WS_VISIBLE)
222 m_pHost->SetWindowLongPtr(GWL_STYLE, dwStyle);
223 m_root->SetActive(bActive);
224
225 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
226 m_rcInvalid = m_root->GetClientRect();
227 m_rcInvalid.OffsetRect(nBorderWid, nBorderWid);
228 m_pHost->SendMessage(WM_NCPAINT, 1);
229 }
230 return TRUE;
231}
232
233UINT SNcPainter::OnNcHitTest(CPoint point)
234{
235 if (m_pHost->IsIconic())
236 return 0;
237 UINT uRet = HTCLIENT;
238 if (IsDrawNc())
239 {
240 do
241 {
242 CRect rcWnd = m_pHost->GetWindowRect();
243 CRect rcClient = m_pHost->GetClientRect();
244 m_pHost->ClientToScreen2(&rcClient);
245 if (rcClient.PtInRect(point))
246 {
247 uRet = HTCLIENT;
248 break;
249 }
250 CRect rcInner = rcWnd;
251 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
252 rcInner.DeflateRect(nBorderWid, nBorderWid);
253 CRect rcTitle = rcInner;
254 rcTitle.bottom = rcClient.top;
255 if (rcTitle.PtInRect(point))
256 {
257 point -= rcTitle.TopLeft();
258 SWND swnd = m_root->SwndFromPoint(point);
259 if (swnd)
260 {
261 SWindow *pWnd = SWindowMgr::GetWindow(swnd);
262 int nId = pWnd->GetID();
263 if (nId == IDC_SYS_ICON)
264 {
265 uRet = HTSYSMENU;
266 break;
267 }
268 }
269 uRet = HTCAPTION;
270 break;
271 }
272
273 if (m_pHost->m_hostAttr.m_bResizable)
274 {
275 // depart border region into 8 parts as expressed below
276 // 012
277 // 3*4
278 // 567
279 CRect rcParts[8];
280 UINT htPart[8];
281
282 htPart[0] = HTTOPLEFT;
283 rcParts[0] = CRect(rcWnd.left, rcWnd.top, rcInner.left, rcInner.top);
284 htPart[1] = HTTOP;
285 rcParts[1] = CRect(rcInner.left, rcWnd.top, rcInner.right, rcInner.top);
286 htPart[2] = HTTOPRIGHT;
287 rcParts[2] = CRect(rcInner.right, rcWnd.top, rcWnd.right, rcInner.top);
288 htPart[3] = HTLEFT;
289 rcParts[3] = CRect(rcWnd.left, rcInner.top, rcInner.left, rcInner.bottom);
290 htPart[4] = HTRIGHT;
291 rcParts[4] = CRect(rcInner.left, rcInner.top, rcWnd.right, rcInner.bottom);
292 htPart[5] = HTBOTTOMLEFT;
293 rcParts[5] = CRect(rcWnd.left, rcInner.top, rcInner.left, rcWnd.bottom);
294 htPart[6] = HTBOTTOM;
295 rcParts[6] = CRect(rcInner.left, rcInner.bottom, rcInner.right, rcWnd.bottom);
296 htPart[7] = HTBOTTOMRIGHT;
297 rcParts[7] = CRect(rcInner.right, rcInner.bottom, rcWnd.right, rcWnd.bottom);
298 for (int i = 0; i < 8; i++)
299 {
300 if (rcParts[i].PtInRect(point))
301 {
302 uRet = htPart[i];
303 break;
304 }
305 }
306 if (uRet == HTCLIENT)
307 uRet = HTBORDER;
308 }
309 else
310 {
311 uRet = HTBORDER;
312 }
313 } while (false);
314 }
315 else if (m_pHost->m_hostAttr.m_bResizable)
316 {
317 do
318 {
319 m_pHost->ScreenToClient(&point);
320 CRect rcMargin = m_pHost->m_hostAttr.GetMargin(GetScale());
321 CRect rcWnd = m_pHost->GetRoot()->GetWindowRect();
322 if (point.x > rcWnd.right - rcMargin.right)
323 {
324 if (point.y > rcWnd.bottom - rcMargin.bottom)
325 {
326 uRet = HTBOTTOMRIGHT;
327 }
328 else if (point.y < rcMargin.top)
329 {
330 uRet = HTTOPRIGHT;
331 }
332 else
333 {
334 uRet = HTRIGHT;
335 }
336 }
337 else if (point.x < rcMargin.left)
338 {
339 if (point.y > rcWnd.bottom - rcMargin.bottom)
340 {
341 uRet = HTBOTTOMLEFT;
342 }
343 else if (point.y < rcMargin.top)
344 {
345 uRet = HTTOPLEFT;
346 }
347 else
348 {
349 uRet = HTLEFT;
350 }
351 }
352 else if (point.y > rcWnd.bottom - rcMargin.bottom)
353 {
354 uRet = HTBOTTOM;
355 }
356 else if (point.y < rcMargin.top)
357 {
358 uRet = HTTOP;
359 }
360 } while (false);
361 }
362 return uRet;
363}
364
366{
367 if (!IsDrawNc())
368 return;
369 // paint non client.
370 CRect rcWnd = m_pHost->GetWindowRect();
371 if ((UINT_PTR)hRgn > 1 && !::RectInRegion(hRgn, &rcWnd))
372 {
373 m_pHost->DefWindowProc(); // just do default thing
374 return; // and quit
375 }
376
377 m_bInPaint = TRUE;
378
379 HDC hdc = ::GetWindowDC(m_pHost->m_hWnd);
380 CRect rcClient = m_pHost->GetClientRect();
381 m_pHost->ClientToScreen2(&rcClient);
382 rcClient.OffsetRect(-rcWnd.TopLeft());
383 ::ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
384 rcWnd.MoveToXY(0, 0);
385 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
386 int nTitleHei = m_titleHeight.toPixelSize(GetScale());
387
388 // draw left
389 {
390 CRect rcDraw(0, 0, nBorderWid, rcWnd.bottom);
391 {
392 HDC memdc = m_memLeft->GetDC(0);
393 BitBlt(hdc, rcDraw.left, rcDraw.top, rcDraw.Width(), rcDraw.Height(), memdc, rcDraw.left, rcDraw.top, SRCCOPY);
394 m_memLeft->ReleaseDC(memdc, &rcDraw);
395 }
396 }
397 // draw top
398 {
399 CRect rcDraw(nBorderWid, 0, rcWnd.right - nBorderWid, nBorderWid);
400 {
401 HDC memdc = m_memTop->GetDC(0);
402 BitBlt(hdc, rcDraw.left, rcDraw.top, rcDraw.Width(), rcDraw.Height(), memdc, rcDraw.left, rcDraw.top, SRCCOPY);
403 m_memTop->ReleaseDC(memdc, &rcDraw);
404 }
405 }
406 // draw right
407 {
408 CRect rcDraw(rcWnd.right - nBorderWid, 0, rcWnd.right, rcWnd.bottom);
409 {
410 HDC memdc = m_memRight->GetDC(0);
411 BitBlt(hdc, rcDraw.left, rcDraw.top, rcDraw.Width(), rcDraw.Height(), memdc, rcDraw.left, rcDraw.top, SRCCOPY);
412 m_memRight->ReleaseDC(memdc, &rcDraw);
413 }
414 }
415 // draw bottom
416 {
417 CRect rcDraw(nBorderWid, rcWnd.bottom - nBorderWid, rcWnd.right - nBorderWid, rcWnd.bottom);
418 {
419 HDC memdc = m_memBottom->GetDC(0);
420 BitBlt(hdc, rcDraw.left, rcDraw.top, rcDraw.Width(), rcDraw.Height(), memdc, rcDraw.left, rcDraw.top, SRCCOPY);
421 m_memBottom->ReleaseDC(memdc, &rcDraw);
422 }
423 }
424
425 { // draw title
426 if (m_root->IsLayoutDirty())
427 m_root->UpdateLayout();
428 m_memRT->BeginDraw();
429 m_memRT->PushClipRect(m_rcInvalid);
430 CRect rcTitle(nBorderWid, nBorderWid, rcWnd.Width() - nBorderWid, nTitleHei + nBorderWid);
431 m_root->Draw(m_memRT, rcTitle);
432 m_memRT->PopClip();
433 m_memRT->EndDraw();
434 HDC memdc = m_memRT->GetDC(0);
435 ::BitBlt(hdc, rcTitle.left, rcTitle.top, rcTitle.Width(), rcTitle.Height(), memdc, rcTitle.left, rcTitle.top, SRCCOPY);
436 m_memRT->ReleaseDC(memdc, &rcTitle);
437 m_rcInvalid = CRect();
438 }
439
440 ::ReleaseDC(m_pHost->m_hWnd, hdc);
441 m_bInPaint = FALSE;
442}
443
445{
446 return !m_pHost->IsTranslucent() && !(m_borderWidth.isZero() && m_titleHeight.isZero());
447}
448
449LRESULT SNcPainter::OnSetText(LPCTSTR pszText)
450{
451 if (!IsDrawNc())
452 {
453 return m_pHost->DefWindowProc();
454 }
455 else
456 {
457 DWORD dwStyle = m_pHost->GetStyle();
458 if (dwStyle & WS_VISIBLE)
459 m_pHost->SetWindowLongPtr(GWL_STYLE, dwStyle & ~WS_VISIBLE);
460 m_pHost->DefWindowProc();
461 if (dwStyle & WS_VISIBLE)
462 m_pHost->SetWindowLongPtr(GWL_STYLE, dwStyle);
463 SWindow *pTitle = m_root->FindChildByID(IDC_SYS_TITLE);
464 if (pTitle)
465 {
466 pTitle->SetWindowText(pszText);
467 }
468 return 0;
469 }
470}
471
472LRESULT SNcPainter::OnRepaint(UINT msg, WPARAM wp, LPARAM lp)
473{
474 if (!IsDrawNc())
475 {
476 return m_pHost->DefWindowProc();
477 }
478 else
479 {
480 InvalidateHostRect(NULL, FALSE);
481 }
482 return 0;
483}
484
486{
487 m_memRT = NULL;
488 m_memTop = NULL;
489 m_memLeft = NULL;
490 m_memBottom = NULL;
491 m_memRight = NULL;
492
493 SetMsgHandled(FALSE);
494}
495
496void SNcPainter::OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture)
497{
498}
499
500BOOL SNcPainter::OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const
501{
502 rcItem = GetHostRect();
503 return TRUE;
504}
505
507{
508 return TRUE;
509}
510
512{
513 return this;
514}
515
517{
518 return m_pHost->OnFireEvent(e);
519}
520
522{
523 return FALSE;
524}
525
527{
528 return TRUE;
529}
530
532{
533 CRect rcItem = m_pHost->GetWindowRect();
534 rcItem.MoveToXY(0, 0);
535 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
536 int nTitleHei = m_titleHeight.toPixelSize(GetScale());
537 rcItem.DeflateRect(nBorderWid, nBorderWid);
538 rcItem.bottom = rcItem.top + nTitleHei;
539 return rcItem;
540}
541
542void SNcPainter::InvalidateHostRect(LPCRECT pRc, BOOL bClip)
543{
544 if (m_bInPaint)
545 return;
546 if (pRc)
547 m_rcInvalid |= *pRc;
548 else
549 m_rcInvalid = GetHostRect();
550 HRGN hRgn = CreateRectRgnIndirect(&m_rcInvalid);
551 m_pHost->SendMessage(WM_NCPAINT, (WPARAM)hRgn);
552 DeleteObject(hRgn);
553}
554
556{
557 if (!m_memLeft)
558 return; // make sure init is done
559 m_pHost->SendMessage(WM_NCPAINT, 1, 0);
560}
561
563{
564 return m_pHost;
565}
566
568{
569 m_memRT->PushClipRect(rc, RGN_AND);
570 return m_memRT;
571}
572
574{
575 m_memRT->PopClip();
576
577 HDC hdc = ::GetWindowDC(m_pHost->m_hWnd);
578 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
579 HDC memdc = m_memRT->GetDC(0);
580 ::BitBlt(hdc, rc->left, rc->top, RectWidth(rc), RectHeight(rc), memdc, rc->left, rc->top, SRCCOPY);
581 m_memRT->ReleaseDC(memdc, rc);
582 ::ReleaseDC(m_pHost->m_hWnd, hdc);
583}
584
585LRESULT SNcPainter::OnNcMouseEvent(UINT msg, WPARAM wp, LPARAM lp)
586{
587 if (wp == HTCAPTION && msg != WM_NCLBUTTONDBLCLK)
588 {
589 m_bMouseHover = TRUE;
590 m_pHost->SetTimer(SHostWnd::kNcCheckTimer, SHostWnd::kNcCheckInterval, NULL);
591 if (msg == WM_NCLBUTTONUP)
592 m_bLButtonDown = FALSE;
593 CPoint pt(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
594 CRect rcWnd = m_pHost->GetWindowRect();
595 pt -= rcWnd.TopLeft();
596 int nBorder = m_borderWidth.toPixelSize(GetScale());
597 pt.x -= nBorder;
598 pt.y -= nBorder;
599 lp = MAKELPARAM(pt.x, pt.y);
600 msg += WM_MOUSEMOVE - WM_NCMOUSEMOVE; // translate nc mouse event to normal mouse event.
601 m_root->DoFrameEvent(msg, wp, lp);
603 }
604 else
605 {
606 m_pHost->DefWindowProc();
607 }
608 return 0;
609}
610
611LRESULT SNcPainter::OnNcMouseLeave(UINT msg, WPARAM wp, LPARAM lp)
612{
613 if (m_bLButtonDown)
614 {
615 OnNcMouseEvent(WM_NCLBUTTONUP, HTCAPTION, MAKELPARAM(-1, -1));
616 }
617 m_root->DoFrameEvent(WM_MOUSELEAVE, 0, 0);
619 m_bMouseHover = FALSE;
620 m_pHost->KillTimer(SHostWnd::kNcCheckTimer);
621 return m_pHost->DefWindowProc();
622}
623
624void SNcPainter::OnNcLButtonDown(UINT nHitTest, CPoint pt)
625{
626 if (nHitTest == HTCAPTION)
627 {
628 m_bLButtonDown = TRUE;
629
630 CRect rcWnd = m_pHost->GetWindowRect();
631 pt -= rcWnd.TopLeft();
632 int nBorder = m_borderWidth.toPixelSize(GetScale());
633 pt.x -= nBorder;
634 pt.y -= nBorder;
635
636 CPoint pt2(pt);
637 SWND swnd = m_root->SwndFromPoint(pt2);
638 if (swnd != 0)
639 {
640 LPARAM lp = MAKELPARAM(pt.x, pt.y);
641 m_root->DoFrameEvent(WM_LBUTTONDOWN, 0, lp);
642 }
643 else
644 {
645 m_pHost->DefWindowProc();
646 }
647 }
648 else
649 {
650 m_pHost->DefWindowProc();
651 }
652}
653
655{
656 static struct SystemID
657 {
658 int id;
659 LPCWSTR pszName;
660 } systemID[] = { IDC_SYS_ICON, L"sysid_icon", IDC_SYS_TITLE, L"sysid_title", IDC_SYS_CLOSE, L"sysid_close", IDC_SYS_MIN, L"sysid_min", IDC_SYS_MAX, L"sysid_max", IDC_SYS_RESTORE, L"sysid_restore" };
661 if (!strValue.IsEmpty())
662 {
663 if (strValue.Left(5).CompareNoCase(L"sysid") == 0)
664 {
665 for (int i = 0; i < ARRAYSIZE(systemID); i++)
666 {
667 if (strValue.CompareNoCase(systemID[i].pszName) == 0)
668 {
669 return systemID[i].id;
670 }
671 }
672 }
673 }
674 return 0;
675}
676
677void SNcPainter::OnSize(UINT nType, CSize size)
678{
679 if (IsDrawNc())
680 {
681 updateSystemButton(m_root, nType);
682 }
683}
684
686{
687 CPoint pt;
688 GetCursorPos(&pt);
689 CRect rcWnd = m_pHost->GetWindowRect();
690 pt -= rcWnd.TopLeft();
691
692 SwndToolTipInfo tipInfo;
693 BOOL bOK = m_root->UpdateToolTip(pt, tipInfo);
694 if (bOK)
695 {
696 m_pHost->_SetToolTipInfo(&tipInfo, TRUE);
697 }
698 else
699 { // hide tooltip
700 m_pHost->_SetToolTipInfo(NULL, TRUE);
701 }
702}
703
705{
706 CSize szRet;
707 int nBorderWid = m_borderWidth.toPixelSize(GetScale());
708 int nTitleHei = m_titleHeight.toPixelSize(GetScale());
709 szRet.cx = nBorderWid * 2;
710 szRet.cy = nBorderWid * 2 + nTitleHei;
711 return szRet;
712}
713
714void SNcPainter::OnLButtonUp(WPARAM wp, LPARAM lp)
715{
716 if (m_bLButtonDown)
717 {
718 OnNcMouseEvent(WM_NCLBUTTONUP, HTCAPTION, MAKELPARAM(-1, -1));
719 }
720}
721
722void SNcPainter::OnMouseMove(WPARAM wp, LPARAM lp)
723{
724 if (m_bMouseHover)
725 {
726 OnNcMouseLeave(0, 0, 0);
727 }
728}
729
730void SNcPainter::OnTimer(UINT_PTR tid)
731{
732 if (tid == SHostWnd::kNcCheckTimer)
733 {
734 POINT pt;
735 ::GetCursorPos(&pt);
736 HWND hHover = ::WindowFromPoint(pt);
737 if (hHover != m_pHost->m_hWnd)
738 {
739 OnMouseMove(0, 0);
740 }
741 }
742 else
743 {
744 SetMsgHandled(FALSE);
745 }
746}
747
748void SNcPainter::updateSystemButton(SWindow *pRoot, UINT nResizeMode)
749{
750 SWindow *pMax = pRoot->FindChildByID(IDC_SYS_MAX);
751 SWindow *pRestore = pRoot->FindChildByID(IDC_SYS_RESTORE);
752 if (pMax && pRestore)
753 {
754 if (nResizeMode == SIZE_MAXIMIZED)
755 {
756 pMax->SetVisible(FALSE);
757 pRestore->SetVisible(TRUE);
758 }
759 else if (nResizeMode == SIZE_RESTORED)
760 {
761 pMax->SetVisible(TRUE);
762 pRestore->SetVisible(FALSE);
763 }
764 }
765}
766
767SNSEND
@ WndState_Normal
Definition SWnd.h:75
GrtFlag
@ kNcCheckTimer
Definition SHostWnd.h:398
@ kNcCheckInterval
Definition SHostWnd.h:399
布局大小类
Definition SLayoutSize.h:10
virtual BOOL IsHostUpdateLocked() const
Checks if host updates are locked.
LRESULT OnSetText(LPCTSTR pszText)
Handles the WM_SETTEXT message.
void OnSize(UINT nType, CSize size)
Handles the WM_SIZE message.
void OnLButtonUp(WPARAM wp, LPARAM lp)
Handles the WM_LBUTTONUP message.
virtual BOOL OnHostFireEvent(IEvtArgs *e)
Called when an event is fired on the host.
virtual ISwndContainer * GetHostContainer()
Gets the host container.
virtual void OnLayoutDirty()
Called when layout is dirty.
virtual CRect GetHostRect() const
Gets the rectangle of the host.
void OnNcLButtonDown(UINT flag, CPoint pt)
Handles the WM_NCLBUTTONDOWN message.
BOOL IsDrawNc() const
Checks if non-client area should be drawn.
CSize GetNcSize() const
Gets the size of the non-client area.
static void updateSystemButton(SWindow *pRoot, UINT nResizeMode)
Updates system buttons in the non-client area.
LRESULT OnNcMouseLeave(UINT msg, WPARAM wp, LPARAM lp)
Handles the WM_NCMOUSELEAVE message.
virtual BOOL IsItemRedrawDelay() const
Checks if item redraw is delayed.
static int toNcBuiltinID(const SStringW &str)
Converts a string to a built-in non-client ID.
void Reset()
Resets the non-client painter.
void OnTimer(UINT_PTR tid)
Handles the WM_TIMER message.
virtual void OnReleaseHostRenderTarget(IRenderTarget *pRT, LPCRECT rc, GrtFlag gdcFlags)
Called to release the host render target.
LRESULT OnRepaint(UINT msg, WPARAM wp, LPARAM lp)
Handles repaint messages.
virtual IRenderTarget * OnGetHostRenderTarget(LPCRECT rc, GrtFlag gdcFlags)
Called to get the host render target.
void OnMouseMove(WPARAM wp, LPARAM lp)
Handles the WM_MOUSEMOVE message.
void OnNcDestroy()
Handles the WM_NCDESTROY message.
virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture)
Called when an item sets capture.
LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
Handles the WM_NCCALCSIZE message.
BOOL OnNcActivate(BOOL bActive)
Handles the WM_NCACTIVATE message.
virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const
Called to get the rectangle of an item.
int GetScale() const
Gets the scale factor.
SNcPainter(SHostWnd *pHost)
Constructor for SNcPainter.
virtual void InvalidateHostRect(LPCRECT pRc, BOOL bClip)
Invalidates a rectangle in the host.
IWindow * GetRoot() OVERRIDE
Gets the root window.
UINT OnNcHitTest(CPoint point)
Handles the WM_NCHITTEST message.
virtual IObject * GetHost()
Gets the host object.
void OnNcPaint(HRGN hRgn)
Handles the WM_NCPAINT message.
~SNcPainter(void)
Destructor for SNcPainter.
virtual BOOL IsHostVisible() const
Checks if the host is visible.
void UpdateToolTip()
Updates the tooltip.
BOOL InitFromXml(IXmlNode *pXmlNode) OVERRIDE
Initializes the non-client painter from an XML node.
LRESULT OnNcMouseEvent(UINT msg, WPARAM wp, LPARAM lp)
Handles non-client mouse events.
BOOL OnEraseBkgnd(IRenderTarget *pRT)
Erases the background of the panel.
SNcPanel(IHostProxy *pFrameHost, IItemContainer *pItemContainer)
Constructor for SNcPanel.
Definition SNcPainter.cpp:7
void SetActive(BOOL bActive)
Sets the active state of the panel.
int GetID() SCONST OVERRIDE
Retrieves the object's ID.
Definition Sobject.hpp:134
A class representing an ASCII string.
Definition sstringw.h:96
int CompareNoCase(const wchar_t *psz) SCONST
Compares the string with another string, ignoring case.
Definition sstringw.cpp:929
BOOL IsEmpty() SCONST
Checks if the string is empty.
SStringW Left(int nCount) const
Extracts the leftmost part of the string.
Definition sstringw.cpp:879
Base class for SOUI DUI windows.
Definition SWnd.h:286
void SetVisible(BOOL bVisible, BOOL bUpdate=FALSE) OVERRIDE
Sets the visibility of the window.
Definition Swnd.cpp:655
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
Definition Swnd.cpp:243
SWindow()
Constructor.
Definition Swnd.cpp:104
void SetWindowText(LPCTSTR lpszText) OVERRIDE
Sets the window text.
Definition Swnd.cpp:311
COLORREF GetBkgndColor() SCONST OVERRIDE
Retrieves the background color of the window.
Definition Swnd.cpp:3386
const SwndStyle & GetStyle() const
Retrieves the style of the window.
Definition Swnd.cpp:716
SWindow * FindChildByID(int nID, int nDeep=-1)
Finds a child window by its ID.
Definition Swnd.cpp:781
static SWindow * GetWindow(SWND swnd)
Retrieves the SWindow pointer from a given handle.
Class representing an XML node.
Definition SXml.h:352
void SetTextColor(int iState, COLORREF cr)
Sets the text color for a specific state.
Definition SWndStyle.h:116
Interface for Native Window Operations.
HWND GetHwnd() PURE
Retrieves the handle to the window.
BOOL GetWindowRect(LPRECT lpRect) SCONST PURE
Retrieves the window rectangle.
DWORD GetStyle() SCONST PURE
Retrieves the window style.
Interface for rendering target objects.
Definition SRender-i.h:1440
HRESULT PushClipRect(LPCRECT pRect, UINT mode=RGN_AND) PURE
Push a rectangular clip region.
HRESULT FillSolidRect(LPCRECT pRect, COLORREF cr) PURE
Fill a rectangle with a solid color.
Interface for Skin Objects.
Definition SSkinobj-i.h:29
void DrawByIndex(IRenderTarget *pRT, LPCRECT rcDraw, int iState) SCONST PURE
Draws the skin object to the specified render target with a given index.
SOUI Window Container Interface.
Interface for XML nodes.
Definition sxml-i.h:128
Information for window tooltips.
Definition SWnd.h:208