1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
9 #include "../../include/pdfwindow/PDFWindow.h"
10 #include "../../include/pdfwindow/PWL_Wnd.h"
11 #include "../../include/pdfwindow/PWL_Utils.h"
12 #include "../../include/pdfwindow/PWL_ScrollBar.h"
14 /* -------------------------- CPWL_Timer -------------------------- */
16 static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() {
17 // Leak the object at shutdown.
18 static auto timeMap = new std::map<int32_t, CPWL_Timer*>;
22 CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
23 IFX_SystemHandler* pSystemHandler)
24 : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
25 ASSERT(m_pAttached != NULL);
26 ASSERT(m_pSystemHandler != NULL);
29 CPWL_Timer::~CPWL_Timer() {
33 int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) {
36 m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
38 GetPWLTimeMap()[m_nTimerID] = this;
42 void CPWL_Timer::KillPWLTimer() {
46 m_pSystemHandler->KillTimer(m_nTimerID);
47 GetPWLTimeMap().erase(m_nTimerID);
51 void CPWL_Timer::TimerProc(int32_t idEvent) {
52 auto it = GetPWLTimeMap().find(idEvent);
53 if (it == GetPWLTimeMap().end())
56 CPWL_Timer* pTimer = it->second;
57 if (pTimer->m_pAttached)
58 pTimer->m_pAttached->TimerProc();
61 /* -------------------------- CPWL_TimerHandler -------------------------- */
63 CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(NULL) {}
65 CPWL_TimerHandler::~CPWL_TimerHandler() {
69 void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
71 m_pTimer = new CPWL_Timer(this, GetSystemHandler());
74 m_pTimer->SetPWLTimer(nElapse);
77 void CPWL_TimerHandler::EndTimer() {
79 m_pTimer->KillPWLTimer();
82 void CPWL_TimerHandler::TimerProc() {}
84 /* --------------------------- CPWL_MsgControl ---------------------------- */
86 class CPWL_MsgControl {
87 friend class CPWL_Wnd;
90 CPWL_MsgControl(CPWL_Wnd* pWnd) {
91 // PWL_TRACE("new CPWL_MsgControl\n");
97 // PWL_TRACE("~CPWL_MsgControl\n");
102 m_aMousePath.RemoveAll();
103 m_aKeyboardPath.RemoveAll();
104 m_pMainMouseWnd = NULL;
105 m_pMainKeyboardWnd = NULL;
108 FX_BOOL IsWndCreated(const CPWL_Wnd* pWnd) const {
109 return m_pCreatedWnd == pWnd;
112 FX_BOOL IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
113 return pWnd == m_pMainMouseWnd;
116 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
118 for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++)
119 if (m_aMousePath.GetAt(i) == pWnd)
125 FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
126 return pWnd == m_pMainKeyboardWnd;
129 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
131 for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++)
132 if (m_aKeyboardPath.GetAt(i) == pWnd)
138 void SetFocus(CPWL_Wnd* pWnd) {
139 m_aKeyboardPath.RemoveAll();
142 m_pMainKeyboardWnd = pWnd;
144 CPWL_Wnd* pParent = pWnd;
146 m_aKeyboardPath.Add(pParent);
147 pParent = pParent->GetParentWindow();
155 if (m_aKeyboardPath.GetSize() > 0)
156 if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
159 m_pMainKeyboardWnd = NULL;
160 m_aKeyboardPath.RemoveAll();
163 void SetCapture(CPWL_Wnd* pWnd) {
164 m_aMousePath.RemoveAll();
167 m_pMainMouseWnd = pWnd;
169 CPWL_Wnd* pParent = pWnd;
171 m_aMousePath.Add(pParent);
172 pParent = pParent->GetParentWindow();
177 void ReleaseCapture() {
178 m_pMainMouseWnd = NULL;
179 m_aMousePath.RemoveAll();
183 CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
184 CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
185 CPWL_Wnd* m_pCreatedWnd;
186 CPWL_Wnd* m_pMainMouseWnd;
187 CPWL_Wnd* m_pMainKeyboardWnd;
190 /* --------------------------- CPWL_Wnd ---------------------------- */
193 : m_pVScrollBar(NULL),
201 CPWL_Wnd::~CPWL_Wnd() {
202 ASSERT(m_bCreated == FALSE);
205 CFX_ByteString CPWL_Wnd::GetClassName() const {
209 void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
211 m_sPrivateParam = cp;
213 OnCreate(m_sPrivateParam);
215 m_sPrivateParam.rcRectWnd.Normalize();
216 m_rcWindow = m_sPrivateParam.rcRectWnd;
217 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
221 if (m_sPrivateParam.pParentWnd)
222 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
224 PWL_CREATEPARAM ccp = m_sPrivateParam;
226 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
227 ccp.mtChild = CPDF_Matrix(1, 0, 0, 1, 0, 0);
229 CreateScrollBar(ccp);
232 m_bVisible = HasFlag(PWS_VISIBLE);
241 void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
243 void CPWL_Wnd::OnCreated() {}
245 void CPWL_Wnd::OnDestroy() {}
247 void CPWL_Wnd::Destroy() {
253 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
254 if (CPWL_Wnd* pChild = m_aChildren[i]) {
261 if (m_sPrivateParam.pParentWnd)
262 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
268 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
269 m_aChildren.RemoveAll();
270 m_pVScrollBar = NULL;
273 void CPWL_Wnd::Move(const CPDF_Rect& rcNew, FX_BOOL bReset, FX_BOOL bRefresh) {
275 CPDF_Rect rcOld = GetWindowRect();
278 m_rcWindow.Normalize();
280 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
281 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
287 InvalidateRectMove(rcOld, rcNew);
290 m_sPrivateParam.rcRectWnd = m_rcWindow;
294 void CPWL_Wnd::InvalidateRectMove(const CPDF_Rect& rcOld,
295 const CPDF_Rect& rcNew) {
296 CPDF_Rect rcUnion = rcOld;
297 rcUnion.Union(rcNew);
299 InvalidateRect(&rcUnion);
302 void CPWL_Wnd::GetAppearanceStream(CFX_ByteString& sAppStream) {
304 CFX_ByteTextBuf sTextBuf;
305 GetAppearanceStream(sTextBuf);
306 sAppStream += sTextBuf.GetByteString();
310 void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
311 if (IsValid() && IsVisible()) {
312 GetThisAppearanceStream(sAppStream);
313 GetChildAppearanceStream(sAppStream);
317 // if don't set,Get default apperance stream
318 void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
319 CPDF_Rect rectWnd = GetWindowRect();
320 if (!rectWnd.IsEmpty()) {
321 CFX_ByteTextBuf sThis;
323 if (HasFlag(PWS_BACKGROUND))
324 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
326 if (HasFlag(PWS_BORDER)) {
327 sThis << CPWL_Utils::GetBorderAppStream(
328 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
329 GetBorderLeftTopColor(GetBorderStyle()),
330 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
338 void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
339 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
340 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
341 pChild->GetAppearanceStream(sAppStream);
346 void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
347 CPDF_Matrix* pUser2Device) {
348 if (IsValid() && IsVisible()) {
349 DrawThisAppearance(pDevice, pUser2Device);
350 DrawChildAppearance(pDevice, pUser2Device);
354 void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
355 CPDF_Matrix* pUser2Device) {
356 CPDF_Rect rectWnd = GetWindowRect();
357 if (!rectWnd.IsEmpty()) {
358 if (HasFlag(PWS_BACKGROUND)) {
359 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(
360 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
361 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
362 GetBackgroundColor(), GetTransparency());
365 if (HasFlag(PWS_BORDER))
366 CPWL_Utils::DrawBorder(
367 pDevice, pUser2Device, rectWnd, (FX_FLOAT)GetBorderWidth(),
368 GetBorderColor(), GetBorderLeftTopColor(GetBorderStyle()),
369 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
370 GetBorderDash(), GetTransparency());
374 void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
375 CPDF_Matrix* pUser2Device) {
376 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
377 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
378 CPDF_Matrix mt = pChild->GetChildMatrix();
379 if (mt.IsIdentity()) {
380 pChild->DrawAppearance(pDevice, pUser2Device);
382 mt.Concat(*pUser2Device);
383 pChild->DrawAppearance(pDevice, &mt);
389 void CPWL_Wnd::InvalidateRect(CPDF_Rect* pRect) {
391 CPDF_Rect rcRefresh = pRect ? *pRect : GetWindowRect();
393 if (!HasFlag(PWS_NOREFRESHCLIP)) {
394 CPDF_Rect rcClip = GetClipRect();
395 if (!rcClip.IsEmpty()) {
396 rcRefresh.Intersect(rcClip);
400 FX_RECT rcWin = PWLtoWnd(rcRefresh);
401 rcWin.left -= PWL_INVALIDATE_INFLATE;
402 rcWin.top -= PWL_INVALIDATE_INFLATE;
403 rcWin.right += PWL_INVALIDATE_INFLATE;
404 rcWin.bottom += PWL_INVALIDATE_INFLATE;
406 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
407 if (FX_HWND hWnd = GetAttachedHWnd()) {
408 pSH->InvalidateRect(hWnd, rcWin);
414 #define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
415 FX_BOOL CPWL_Wnd::key_method_name(FX_WORD nChar, FX_DWORD nFlag) { \
416 if (IsValid() && IsVisible() && IsEnabled()) { \
417 if (IsWndCaptureKeyboard(this)) { \
418 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
419 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
420 if (IsWndCaptureKeyboard(pChild)) { \
421 return pChild->key_method_name(nChar, nFlag); \
430 #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
431 FX_BOOL CPWL_Wnd::mouse_method_name(const CPDF_Point& point, \
433 if (IsValid() && IsVisible() && IsEnabled()) { \
434 if (IsWndCaptureMouse(this)) { \
435 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
436 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
437 if (IsWndCaptureMouse(pChild)) { \
438 return pChild->mouse_method_name(pChild->ParentToChild(point), \
445 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
446 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
447 if (pChild->WndHitTest(pChild->ParentToChild(point))) { \
448 return pChild->mouse_method_name(pChild->ParentToChild(point), \
453 if (WndHitTest(point)) \
460 PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
461 PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
462 PWL_IMPLEMENT_KEY_METHOD(OnChar)
464 PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
465 PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
466 PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
467 PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
468 PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
469 PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
470 PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
471 PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
472 PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
474 FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta,
475 const CPDF_Point& point,
477 if (IsValid() && IsVisible() && IsEnabled()) {
479 if (IsWndCaptureKeyboard(this)) {
480 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
481 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
482 if (IsWndCaptureKeyboard(pChild)) {
483 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point),
493 void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
494 m_aChildren.Add(pWnd);
497 void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
498 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
499 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
500 if (pChild == pWnd) {
501 m_aChildren.RemoveAt(i);
508 void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
516 case PNM_REMOVECHILD:
524 FX_BOOL CPWL_Wnd::IsValid() const {
528 PWL_CREATEPARAM CPWL_Wnd::GetCreationParam() const {
529 return m_sPrivateParam;
532 CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
533 return m_sPrivateParam.pParentWnd;
536 CPDF_Rect CPWL_Wnd::GetOriginWindowRect() const {
537 return m_sPrivateParam.rcRectWnd;
540 CPDF_Rect CPWL_Wnd::GetWindowRect() const {
544 CPDF_Rect CPWL_Wnd::GetClientRect() const {
545 CPDF_Rect rcWindow = GetWindowRect();
546 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(
547 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
548 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
549 rcClient.right -= pVSB->GetScrollBarWidth();
551 rcClient.Normalize();
552 return rcWindow.Contains(rcClient) ? rcClient : CPDF_Rect();
555 CPDF_Point CPWL_Wnd::GetCenterPoint() const {
556 CPDF_Rect rcClient = GetClientRect();
557 return CPDF_Point((rcClient.left + rcClient.right) * 0.5f,
558 (rcClient.top + rcClient.bottom) * 0.5f);
561 CPDF_Rect CPWL_Wnd::GetClientCenterSquare() const {
562 return CPWL_Utils::GetCenterSquare(GetClientRect());
565 CPDF_Rect CPWL_Wnd::GetWindowCenterSquare() const {
566 return CPWL_Utils::GetCenterSquare(
567 CPWL_Utils::DeflateRect(GetWindowRect(), 0.1f));
570 FX_BOOL CPWL_Wnd::HasFlag(FX_DWORD dwFlags) const {
571 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
574 void CPWL_Wnd::RemoveFlag(FX_DWORD dwFlags) {
575 m_sPrivateParam.dwFlags &= ~dwFlags;
578 void CPWL_Wnd::AddFlag(FX_DWORD dwFlags) {
579 m_sPrivateParam.dwFlags |= dwFlags;
582 CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
583 return m_sPrivateParam.sBackgroundColor;
586 void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
587 m_sPrivateParam.sBackgroundColor = color;
590 void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
591 m_sPrivateParam.sTextColor = color;
594 void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
595 m_sPrivateParam.sTextStrokeColor = color;
598 CPWL_Color CPWL_Wnd::GetTextColor() const {
599 return m_sPrivateParam.sTextColor;
602 CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
603 return m_sPrivateParam.sTextStrokeColor;
606 int32_t CPWL_Wnd::GetBorderStyle() const {
607 return m_sPrivateParam.nBorderStyle;
610 void CPWL_Wnd::SetBorderStyle(int32_t nBorderStyle) {
611 if (HasFlag(PWS_BORDER))
612 m_sPrivateParam.nBorderStyle = nBorderStyle;
615 int32_t CPWL_Wnd::GetBorderWidth() const {
616 if (HasFlag(PWS_BORDER))
617 return m_sPrivateParam.dwBorderWidth;
622 int32_t CPWL_Wnd::GetInnerBorderWidth() const {
624 switch (GetBorderStyle())
628 return GetBorderWidth() / 2;
634 void CPWL_Wnd::SetBorderWidth(int32_t nBorderWidth) {
635 if (HasFlag(PWS_BORDER))
636 m_sPrivateParam.dwBorderWidth = nBorderWidth;
639 CPWL_Color CPWL_Wnd::GetBorderColor() const {
640 if (HasFlag(PWS_BORDER))
641 return m_sPrivateParam.sBorderColor;
646 void CPWL_Wnd::SetBorderColor(const CPWL_Color& color) {
647 if (HasFlag(PWS_BORDER))
648 m_sPrivateParam.sBorderColor = color;
651 CPWL_Dash CPWL_Wnd::GetBorderDash() const {
652 return m_sPrivateParam.sDash;
655 void* CPWL_Wnd::GetAttachedData() const {
656 return m_sPrivateParam.pAttachedData;
659 void CPWL_Wnd::SetBorderDash(const CPWL_Dash& sDash) {
660 if (HasFlag(PWS_BORDER))
661 m_sPrivateParam.sDash = sDash;
664 CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
665 if (HasFlag(PWS_VSCROLL))
666 return m_pVScrollBar;
671 void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
672 CreateVScrollBar(cp);
675 void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
676 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
677 PWL_CREATEPARAM scp = cp;
681 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
683 scp.pParentWnd = this;
684 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
685 scp.eCursorType = FXCT_ARROW;
686 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
688 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
689 m_pVScrollBar->Create(scp);
693 void CPWL_Wnd::SetCapture() {
694 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
695 pMsgCtrl->SetCapture(this);
698 void CPWL_Wnd::ReleaseCapture() {
699 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++)
700 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
701 pChild->ReleaseCapture();
703 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
704 pMsgCtrl->ReleaseCapture();
707 void CPWL_Wnd::SetFocus() {
708 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
709 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
710 pMsgCtrl->KillFocus();
711 pMsgCtrl->SetFocus(this);
715 void CPWL_Wnd::KillFocus() {
716 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
717 if (pMsgCtrl->IsWndCaptureKeyboard(this))
718 pMsgCtrl->KillFocus();
722 void CPWL_Wnd::OnSetFocus() {}
724 void CPWL_Wnd::OnKillFocus() {}
726 FX_BOOL CPWL_Wnd::WndHitTest(const CPDF_Point& point) const {
727 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
730 FX_BOOL CPWL_Wnd::ClientHitTest(const CPDF_Point& point) const {
731 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
734 const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
735 if (m_sPrivateParam.pParentWnd)
736 return m_sPrivateParam.pParentWnd->GetRootWnd();
741 void CPWL_Wnd::SetVisible(FX_BOOL bVisible) {
743 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
744 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
745 pChild->SetVisible(bVisible);
749 if (bVisible != m_bVisible) {
750 m_bVisible = bVisible;
757 void CPWL_Wnd::SetClipRect(const CPDF_Rect& rect) {
759 m_rcClip.Normalize();
762 CPDF_Rect CPWL_Wnd::GetClipRect() const {
766 FX_BOOL CPWL_Wnd::IsReadOnly() const {
767 return HasFlag(PWS_READONLY);
770 void CPWL_Wnd::RePosChildWnd() {
771 CPDF_Rect rcContent = CPWL_Utils::DeflateRect(
772 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
774 CPWL_ScrollBar* pVSB = GetVScrollBar();
776 CPDF_Rect rcVScroll =
777 CPDF_Rect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
778 rcContent.right - 1.0f, rcContent.top);
781 pVSB->Move(rcVScroll, TRUE, FALSE);
784 void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
786 void CPWL_Wnd::SetCursor() {
788 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
789 int32_t nCursorType = GetCreationParam().eCursorType;
790 pSH->SetCursor(nCursorType);
795 void CPWL_Wnd::CreateMsgControl() {
796 if (!m_sPrivateParam.pMsgControl)
797 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
800 void CPWL_Wnd::DestroyMsgControl() {
801 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
802 if (pMsgControl->IsWndCreated(this))
806 CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
807 return m_sPrivateParam.pMsgControl;
810 FX_BOOL CPWL_Wnd::IsCaptureMouse() const {
811 return IsWndCaptureMouse(this);
814 FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
815 if (CPWL_MsgControl* pCtrl = GetMsgControl())
816 return pCtrl->IsWndCaptureMouse(pWnd);
821 FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
822 if (CPWL_MsgControl* pCtrl = GetMsgControl())
823 return pCtrl->IsWndCaptureKeyboard(pWnd);
828 FX_BOOL CPWL_Wnd::IsFocused() const {
829 if (CPWL_MsgControl* pCtrl = GetMsgControl())
830 return pCtrl->IsMainCaptureKeyboard(this);
835 CPDF_Rect CPWL_Wnd::GetFocusRect() const {
836 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
839 FX_FLOAT CPWL_Wnd::GetFontSize() const {
840 return m_sPrivateParam.fFontSize;
843 void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
844 m_sPrivateParam.fFontSize = fFontSize;
847 IFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
848 return m_sPrivateParam.pSystemHandler;
851 IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
852 return m_sPrivateParam.pFocusHandler;
855 IPWL_Provider* CPWL_Wnd::GetProvider() const {
856 return m_sPrivateParam.pProvider;
859 IFX_Edit_FontMap* CPWL_Wnd::GetFontMap() const {
860 return m_sPrivateParam.pFontMap;
863 CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(int32_t nBorderStyle) const {
866 switch (nBorderStyle) {
872 color = CPWL_Color(COLORTYPE_GRAY, 1);
875 color = CPWL_Color(COLORTYPE_GRAY, 0.5f);
884 CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(int32_t nBorderStyle) const {
887 switch (nBorderStyle) {
893 color = CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
896 color = CPWL_Color(COLORTYPE_GRAY, 0.75f);
905 /* ----------------------------------------------------------------- */
907 int32_t CPWL_Wnd::GetTransparency() {
908 return m_sPrivateParam.nTransparency;
911 void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
912 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
913 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
914 pChild->SetTransparency(nTransparency);
918 m_sPrivateParam.nTransparency = nTransparency;
921 CPDF_Matrix CPWL_Wnd::GetWindowMatrix() const {
922 CPDF_Matrix mt = GetChildToRoot();
924 if (IPWL_Provider* pProvider = GetProvider()) {
925 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
932 void CPWL_Wnd::PWLtoWnd(const CPDF_Point& point, int32_t& x, int32_t& y) const {
933 CPDF_Matrix mt = GetWindowMatrix();
934 CPDF_Point pt = point;
935 mt.Transform(pt.x, pt.y);
936 x = (int32_t)(pt.x + 0.5);
937 y = (int32_t)(pt.y + 0.5);
940 FX_RECT CPWL_Wnd::PWLtoWnd(const CPDF_Rect& rect) const {
941 CPDF_Rect rcTemp = rect;
942 CPDF_Matrix mt = GetWindowMatrix();
943 mt.TransformRect(rcTemp);
944 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
945 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
948 FX_HWND CPWL_Wnd::GetAttachedHWnd() const {
949 return m_sPrivateParam.hAttachedWnd;
952 CPDF_Point CPWL_Wnd::ChildToParent(const CPDF_Point& point) const {
953 CPDF_Matrix mt = GetChildMatrix();
957 CPDF_Point pt = point;
958 mt.Transform(pt.x, pt.y);
962 CPDF_Rect CPWL_Wnd::ChildToParent(const CPDF_Rect& rect) const {
963 CPDF_Matrix mt = GetChildMatrix();
968 mt.TransformRect(rc);
972 CPDF_Point CPWL_Wnd::ParentToChild(const CPDF_Point& point) const {
973 CPDF_Matrix mt = GetChildMatrix();
978 CPDF_Point pt = point;
979 mt.Transform(pt.x, pt.y);
983 CPDF_Rect CPWL_Wnd::ParentToChild(const CPDF_Rect& rect) const {
984 CPDF_Matrix mt = GetChildMatrix();
990 mt.TransformRect(rc);
994 CPDF_Matrix CPWL_Wnd::GetChildToRoot() const {
995 CPDF_Matrix mt(1, 0, 0, 1, 0, 0);
996 if (HasFlag(PWS_CHILD)) {
997 const CPWL_Wnd* pParent = this;
999 mt.Concat(pParent->GetChildMatrix());
1000 pParent = pParent->GetParentWindow();
1006 CPDF_Matrix CPWL_Wnd::GetChildMatrix() const {
1007 if (HasFlag(PWS_CHILD))
1008 return m_sPrivateParam.mtChild;
1010 return CPDF_Matrix(1, 0, 0, 1, 0, 0);
1013 void CPWL_Wnd::SetChildMatrix(const CPDF_Matrix& mt) {
1014 m_sPrivateParam.mtChild = mt;
1017 const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
1018 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
1019 return pMsgCtrl->m_pMainKeyboardWnd;
1025 void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) {
1026 if (m_bEnabled != bEnable) {
1027 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
1028 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
1029 pChild->EnableWindow(bEnable);
1033 m_bEnabled = bEnable;
1042 FX_BOOL CPWL_Wnd::IsEnabled() {
1046 void CPWL_Wnd::OnEnabled() {}
1048 void CPWL_Wnd::OnDisabled() {}
1050 FX_BOOL CPWL_Wnd::IsCTRLpressed(FX_DWORD nFlag) const {
1051 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1052 return pSystemHandler->IsCTRLKeyDown(nFlag);
1058 FX_BOOL CPWL_Wnd::IsSHIFTpressed(FX_DWORD nFlag) const {
1059 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1060 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1066 FX_BOOL CPWL_Wnd::IsALTpressed(FX_DWORD nFlag) const {
1067 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1068 return pSystemHandler->IsALTKeyDown(nFlag);
1074 FX_BOOL CPWL_Wnd::IsINSERTpressed(FX_DWORD nFlag) const {
1075 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1076 return pSystemHandler->IsINSERTKeyDown(nFlag);