From 92549cd7502296328aecef23dab6d7fc0e847645 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 16 Nov 2016 07:32:48 -0800 Subject: Continue nit cleanup in fwl/core Review-Url: https://codereview.chromium.org/2506493003 --- xfa/fwl/core/cfwl_combobox.cpp | 4 - xfa/fwl/core/cfwl_edit.cpp | 4 - xfa/fwl/core/cfwl_listbox.cpp | 6 +- xfa/fwl/core/cfwl_widget.cpp | 27 ++--- xfa/fwl/core/cfwl_widget.h | 4 +- xfa/fwl/core/cfwl_widgetmgr.cpp | 119 +++++++++--------- xfa/fwl/core/cfx_barcode.cpp | 16 +++ xfa/fwl/core/fwl_noteimp.cpp | 262 ++++++++++++++++++++-------------------- xfa/fwl/core/fwl_noteimp.h | 25 ++-- 9 files changed, 231 insertions(+), 236 deletions(-) (limited to 'xfa/fwl') diff --git a/xfa/fwl/core/cfwl_combobox.cpp b/xfa/fwl/core/cfwl_combobox.cpp index a8211e9773..fcdbec9489 100644 --- a/xfa/fwl/core/cfwl_combobox.cpp +++ b/xfa/fwl/core/cfwl_combobox.cpp @@ -18,10 +18,6 @@ IFWL_ComboBox* ToComboBox(IFWL_Widget* widget) { return static_cast(widget); } -const IFWL_ComboBox* ToComboBox(const IFWL_Widget* widget) { - return static_cast(widget); -} - } // namespace CFWL_ComboBox::CFWL_ComboBox(const IFWL_App* app) diff --git a/xfa/fwl/core/cfwl_edit.cpp b/xfa/fwl/core/cfwl_edit.cpp index dc01e2213a..447dbc8fb2 100644 --- a/xfa/fwl/core/cfwl_edit.cpp +++ b/xfa/fwl/core/cfwl_edit.cpp @@ -17,10 +17,6 @@ IFWL_Edit* ToEdit(IFWL_Widget* widget) { return static_cast(widget); } -const IFWL_Edit* ToEdit(const IFWL_Widget* widget) { - return static_cast(widget); -} - } // namespace CFWL_Edit::CFWL_Edit(const IFWL_App* app) : CFWL_Widget(app) {} diff --git a/xfa/fwl/core/cfwl_listbox.cpp b/xfa/fwl/core/cfwl_listbox.cpp index c5bf881074..5b2ad5efbd 100644 --- a/xfa/fwl/core/cfwl_listbox.cpp +++ b/xfa/fwl/core/cfwl_listbox.cpp @@ -47,13 +47,9 @@ bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) return false; - int32_t iCount = CountItems(m_pIface.get()); int32_t iSel = nIndex + 1; - if (iSel >= iCount) { + if (iSel >= CountItems(m_pIface.get())) iSel = nIndex - 1; - if (iSel < 0) - iSel = -1; - } if (iSel >= 0) { CFWL_ListItem* pSel = static_cast(GetItem(m_pIface.get(), iSel)); diff --git a/xfa/fwl/core/cfwl_widget.cpp b/xfa/fwl/core/cfwl_widget.cpp index fb44ded269..7cd2ca3913 100644 --- a/xfa/fwl/core/cfwl_widget.cpp +++ b/xfa/fwl/core/cfwl_widget.cpp @@ -27,14 +27,6 @@ void CFWL_Widget::Initialize() { m_pIface->SetAssociateWidget(this); } -IFWL_Widget* CFWL_Widget::GetWidget() { - return m_pIface.get(); -} - -const IFWL_Widget* CFWL_Widget::GetWidget() const { - return m_pIface.get(); -} - void CFWL_Widget::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { if (m_pIface) m_pIface->GetWidgetRect(rect, bAutoSize); @@ -52,9 +44,7 @@ void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, } uint32_t CFWL_Widget::GetStylesEx() { - if (!m_pIface) - return 0; - return m_pIface->GetStylesEx(); + return m_pIface ? m_pIface->GetStylesEx() : 0; } void CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, @@ -77,21 +67,18 @@ void CFWL_Widget::SetLayoutItem(void* pItem) { } void CFWL_Widget::Update() { - if (!m_pIface) - return; - m_pIface->Update(); + if (m_pIface) + m_pIface->Update(); } void CFWL_Widget::LockUpdate() { - if (!m_pIface) - return; - m_pIface->LockUpdate(); + if (m_pIface) + m_pIface->LockUpdate(); } void CFWL_Widget::UnlockUpdate() { - if (!m_pIface) - return; - m_pIface->UnlockUpdate(); + if (m_pIface) + m_pIface->UnlockUpdate(); } FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { diff --git a/xfa/fwl/core/cfwl_widget.h b/xfa/fwl/core/cfwl_widget.h index 5461f480fd..7f486585ab 100644 --- a/xfa/fwl/core/cfwl_widget.h +++ b/xfa/fwl/core/cfwl_widget.h @@ -23,8 +23,8 @@ class CFWL_Widget { explicit CFWL_Widget(const IFWL_App*); virtual ~CFWL_Widget(); - IFWL_Widget* GetWidget(); - const IFWL_Widget* GetWidget() const; + IFWL_Widget* GetWidget() { return m_pIface.get(); } + IFWL_Widget* GetWidget() const { return m_pIface.get(); } void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false); void SetWidgetRect(const CFX_RectF& rect); diff --git a/xfa/fwl/core/cfwl_widgetmgr.cpp b/xfa/fwl/core/cfwl_widgetmgr.cpp index 310577c1f5..5ef17907aa 100644 --- a/xfa/fwl/core/cfwl_widgetmgr.cpp +++ b/xfa/fwl/core/cfwl_widgetmgr.cpp @@ -57,10 +57,12 @@ IFWL_Widget* CFWL_WidgetMgr::GetOwnerWidget(IFWL_Widget* pWidget) const { IFWL_Widget* CFWL_WidgetMgr::GetFirstSiblingWidget(IFWL_Widget* pWidget) const { CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget); - pItem = pItem ? pItem->pPrevious : nullptr; // Not self. + if (!pItem) + return nullptr; + + pItem = pItem->pPrevious; while (pItem && pItem->pPrevious) pItem = pItem->pPrevious; - return pItem ? pItem->pWidget : nullptr; } @@ -81,10 +83,12 @@ IFWL_Widget* CFWL_WidgetMgr::GetFirstChildWidget(IFWL_Widget* pWidget) const { IFWL_Widget* CFWL_WidgetMgr::GetLastChildWidget(IFWL_Widget* pWidget) const { CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget); - pItem = pItem ? pItem->pChild : nullptr; + if (!pItem) + return nullptr; + + pItem = pItem->pChild; while (pItem && pItem->pNext) pItem = pItem->pNext; - return pItem ? pItem->pWidget : nullptr; } @@ -104,42 +108,43 @@ void CFWL_WidgetMgr::SetWidgetIndex(IFWL_Widget* pWidget, int32_t nIndex) { return; if (!pItem->pParent) return; + CFWL_WidgetMgrItem* pChild = pItem->pParent->pChild; int32_t i = 0; while (pChild) { if (pChild == pItem) { if (i == nIndex) return; - if (pChild->pPrevious) { + if (pChild->pPrevious) pChild->pPrevious->pNext = pChild->pNext; - } - if (pChild->pNext) { + if (pChild->pNext) pChild->pNext->pPrevious = pChild->pPrevious; - } - if (pItem->pParent->pChild == pItem) { + if (pItem->pParent->pChild == pItem) pItem->pParent->pChild = pItem->pNext; - } + pItem->pNext = nullptr; pItem->pPrevious = nullptr; break; } - if (!pChild->pNext) { + if (!pChild->pNext) break; - } + pChild = pChild->pNext; ++i; } + pChild = pItem->pParent->pChild; if (pChild) { if (nIndex < 0) { - while (pChild->pNext) { + while (pChild->pNext) pChild = pChild->pNext; - } + pChild->pNext = pItem; pItem->pPrevious = pChild; pItem->pNext = nullptr; return; } + i = 0; while (i < nIndex && pChild->pNext) { pChild = pChild->pNext; @@ -157,9 +162,8 @@ void CFWL_WidgetMgr::SetWidgetIndex(IFWL_Widget* pWidget, int32_t nIndex) { } pChild->pPrevious = pItem; pItem->pNext = pChild; - if (pItem->pParent->pChild == pChild) { + if (pItem->pParent->pChild == pChild) pItem->pParent->pChild = pItem; - } } else { pItem->pParent->pChild = pItem; pItem->pPrevious = nullptr; @@ -205,39 +209,35 @@ void CFWL_WidgetMgr::InsertWidget(IFWL_Widget* pParent, pParentItem->pParent = GetWidgetMgrItem(nullptr); SetWidgetIndex(pParent, -1); } + CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pChild); if (!pItem) { pItem = new CFWL_WidgetMgrItem(pChild); m_mapWidgetItem[pChild].reset(pItem); } if (pItem->pParent && pItem->pParent != pParentItem) { - if (pItem->pPrevious) { + if (pItem->pPrevious) pItem->pPrevious->pNext = pItem->pNext; - } - if (pItem->pNext) { + if (pItem->pNext) pItem->pNext->pPrevious = pItem->pPrevious; - } - if (pItem->pParent->pChild == pItem) { + if (pItem->pParent->pChild == pItem) pItem->pParent->pChild = pItem->pNext; - } } pItem->pParent = pParentItem; SetWidgetIndex(pChild, nIndex); } + void CFWL_WidgetMgr::RemoveWidget(IFWL_Widget* pWidget) { CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget); - if (!pItem) { + if (!pItem) return; - } - if (pItem->pPrevious) { + if (pItem->pPrevious) pItem->pPrevious->pNext = pItem->pNext; - } - if (pItem->pNext) { + if (pItem->pNext) pItem->pNext->pPrevious = pItem->pPrevious; - } - if (pItem->pParent && pItem->pParent->pChild == pItem) { + if (pItem->pParent && pItem->pParent->pChild == pItem) pItem->pParent->pChild = pItem->pNext; - } + CFWL_WidgetMgrItem* pChild = pItem->pChild; while (pChild) { CFWL_WidgetMgrItem* pNext = pChild->pNext; @@ -246,6 +246,7 @@ void CFWL_WidgetMgr::RemoveWidget(IFWL_Widget* pWidget) { } m_mapWidgetItem.erase(pWidget); } + void CFWL_WidgetMgr::SetOwner(IFWL_Widget* pOwner, IFWL_Widget* pOwned) { CFWL_WidgetMgrItem* pParentItem = GetWidgetMgrItem(pOwner); if (!pParentItem) { @@ -254,6 +255,7 @@ void CFWL_WidgetMgr::SetOwner(IFWL_Widget* pOwner, IFWL_Widget* pOwned) { pParentItem->pParent = GetWidgetMgrItem(nullptr); SetWidgetIndex(pOwner, -1); } + CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pOwned); if (!pItem) { pItem = new CFWL_WidgetMgrItem(pOwned); @@ -267,15 +269,13 @@ void CFWL_WidgetMgr::SetParent(IFWL_Widget* pParent, IFWL_Widget* pChild) { if (!pItem) return; if (pItem->pParent && pItem->pParent != pParentItem) { - if (pItem->pPrevious) { + if (pItem->pPrevious) pItem->pPrevious->pNext = pItem->pNext; - } - if (pItem->pNext) { + if (pItem->pNext) pItem->pNext->pPrevious = pItem->pPrevious; - } - if (pItem->pParent->pChild == pItem) { + if (pItem->pParent->pChild == pItem) pItem->pParent->pChild = pItem->pNext; - } + pItem->pNext = nullptr; pItem->pPrevious = nullptr; } @@ -285,23 +285,24 @@ void CFWL_WidgetMgr::SetParent(IFWL_Widget* pParent, IFWL_Widget* pChild) { void CFWL_WidgetMgr::SetWidgetRect_Native(IFWL_Widget* pWidget, const CFX_RectF& rect) { - if (FWL_UseOffscreen(pWidget)) { - CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget); - pItem->iRedrawCounter++; - if (pItem->pOffscreen) { - CFX_RenderDevice* pDevice = pItem->pOffscreen->GetRenderDevice(); - if (pDevice && pDevice->GetBitmap()) { - CFX_DIBitmap* pBitmap = pDevice->GetBitmap(); - if (pBitmap->GetWidth() - rect.width > 1 || - pBitmap->GetHeight() - rect.height > 1) { - pItem->pOffscreen.reset(); - } + if (!FWL_UseOffscreen(pWidget)) + return; + + CFWL_WidgetMgrItem* pItem = GetWidgetMgrItem(pWidget); + pItem->iRedrawCounter++; + if (pItem->pOffscreen) { + CFX_RenderDevice* pDevice = pItem->pOffscreen->GetRenderDevice(); + if (pDevice && pDevice->GetBitmap()) { + CFX_DIBitmap* pBitmap = pDevice->GetBitmap(); + if (pBitmap->GetWidth() - rect.width > 1 || + pBitmap->GetHeight() - rect.height > 1) { + pItem->pOffscreen.reset(); } } + } #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) - pItem->bOutsideChanged = !m_rtScreen.Contains(rect); + pItem->bOutsideChanged = !m_rtScreen.Contains(rect); #endif - } } IFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(IFWL_Widget* parent, @@ -309,6 +310,7 @@ IFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(IFWL_Widget* parent, FX_FLOAT y) { if (!parent) return nullptr; + FX_FLOAT x1; FX_FLOAT y1; IFWL_Widget* child = GetLastChildWidget(parent); @@ -386,9 +388,9 @@ void CFWL_WidgetMgr::GetSameGroupRadioButton( IFWL_Widget* pRadioButton, CFX_ArrayTemplate& group) const { IFWL_Widget* pFirst = GetFirstSiblingWidget(pRadioButton); - if (!pFirst) { + if (!pFirst) pFirst = pRadioButton; - } + int32_t iGroup = CountRadioButtonGroup(pFirst); if (iGroup < 2) return; @@ -400,6 +402,7 @@ IFWL_Widget* CFWL_WidgetMgr::GetDefaultButton(IFWL_Widget* pParent) const { (pParent->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) { return pParent; } + IFWL_Widget* child = pParent->GetOwnerApp()->GetWidgetMgr()->GetFirstChildWidget(pParent); while (child) { @@ -407,10 +410,9 @@ IFWL_Widget* CFWL_WidgetMgr::GetDefaultButton(IFWL_Widget* pParent) const { (child->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) { return child; } - IFWL_Widget* find = GetDefaultButton(child); - if (find) { + if (IFWL_Widget* find = GetDefaultButton(child)) return find; - } + child = child->GetOwnerApp()->GetWidgetMgr()->GetNextSiblingWidget(child); } return nullptr; @@ -435,9 +437,9 @@ CFWL_WidgetMgrItem* CFWL_WidgetMgr::GetWidgetMgrItem( bool CFWL_WidgetMgr::IsAbleNative(IFWL_Widget* pWidget) const { if (!pWidget) return false; - if (!pWidget->IsInstance(FX_WSTRC(FWL_CLASS_Form))) { + if (!pWidget->IsInstance(FX_WSTRC(FWL_CLASS_Form))) return false; - } + uint32_t dwStyles = pWidget->GetStyles(); return ((dwStyles & FWL_WGTSTYLE_WindowTypeMask) == FWL_WGTSTYLE_OverLapper) || @@ -501,6 +503,7 @@ void CFWL_WidgetMgr::OnDrawWidget(IFWL_Widget* pWidget, CFX_RectF clipCopy; pWidget->GetWidgetRect(clipCopy); clipCopy.left = clipCopy.top = 0; + if (UseOffscreenDirect(pWidget)) { DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); return; @@ -575,9 +578,8 @@ void CFWL_WidgetMgr::DrawChild(IFWL_Widget* parent, widgetMatrix.Translate(rtWidget.left, rtWidget.top, true); if (IFWL_WidgetDelegate* pDelegate = child->GetDelegate()) { - if (IsFormDisabled() || IsNeedRepaint(child, &widgetMatrix, rtClip)) { + if (IsFormDisabled() || IsNeedRepaint(child, &widgetMatrix, rtClip)) pDelegate->OnDrawWidget(pGraphics, &widgetMatrix); - } } if (!bFormDisable) pGraphics->RestoreGraphState(); @@ -632,6 +634,7 @@ bool CFWL_WidgetMgr::IsNeedRepaint(IFWL_Widget* pWidget, pItem->iRedrawCounter = 0; return true; } + CFX_RectF rtWidget; pWidget->GetWidgetRect(rtWidget); rtWidget.left = rtWidget.top = 0; diff --git a/xfa/fwl/core/cfx_barcode.cpp b/xfa/fwl/core/cfx_barcode.cpp index 8d9517903c..12c0cb0929 100644 --- a/xfa/fwl/core/cfx_barcode.cpp +++ b/xfa/fwl/core/cfx_barcode.cpp @@ -60,21 +60,27 @@ bool CFX_Barcode::Create(BC_TYPE type) { m_pBCEngine.reset(CreateBarCodeEngineObject(type)); return !!m_pBCEngine; } + BC_TYPE CFX_Barcode::GetType() { return m_pBCEngine ? m_pBCEngine->GetType() : BC_UNKNOWN; } + bool CFX_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { return m_pBCEngine ? m_pBCEngine->SetCharEncoding(encoding) : false; } + bool CFX_Barcode::SetModuleHeight(int32_t moduleHeight) { return m_pBCEngine ? m_pBCEngine->SetModuleHeight(moduleHeight) : false; } + bool CFX_Barcode::SetModuleWidth(int32_t moduleWidth) { return m_pBCEngine ? m_pBCEngine->SetModuleWidth(moduleWidth) : false; } + bool CFX_Barcode::SetHeight(int32_t height) { return m_pBCEngine ? m_pBCEngine->SetHeight(height) : false; } + bool CFX_Barcode::SetWidth(int32_t width) { return m_pBCEngine ? m_pBCEngine->SetWidth(width) : false; } @@ -97,6 +103,7 @@ bool CFX_Barcode::SetPrintChecksum(bool checksum) { return false; } } + bool CFX_Barcode::SetDataLength(int32_t length) { switch (GetType()) { case BC_CODE39: @@ -115,6 +122,7 @@ bool CFX_Barcode::SetDataLength(int32_t length) { return false; } } + bool CFX_Barcode::SetCalChecksum(bool state) { switch (GetType()) { case BC_CODE39: @@ -133,6 +141,7 @@ bool CFX_Barcode::SetCalChecksum(bool state) { return false; } } + bool CFX_Barcode::SetFont(CFX_Font* pFont) { switch (GetType()) { case BC_CODE39: @@ -150,6 +159,7 @@ bool CFX_Barcode::SetFont(CFX_Font* pFont) { return false; } } + bool CFX_Barcode::SetFontSize(FX_FLOAT size) { switch (GetType()) { case BC_CODE39: @@ -187,6 +197,7 @@ bool CFX_Barcode::SetFontColor(FX_ARGB color) { return false; } } + bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { typedef bool (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC); memptrtype memptr = nullptr; @@ -207,6 +218,7 @@ bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) { } return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(location) : false; } + bool CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { typedef bool (CBC_CodeBase::*memptrtype)(int32_t); memptrtype memptr = nullptr; @@ -222,6 +234,7 @@ bool CFX_Barcode::SetWideNarrowRatio(int32_t ratio) { } return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(ratio) : false; } + bool CFX_Barcode::SetStartChar(FX_CHAR start) { typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); memptrtype memptr = nullptr; @@ -234,6 +247,7 @@ bool CFX_Barcode::SetStartChar(FX_CHAR start) { } return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(start) : false; } + bool CFX_Barcode::SetEndChar(FX_CHAR end) { typedef bool (CBC_CodeBase::*memptrtype)(FX_CHAR); memptrtype memptr = nullptr; @@ -246,6 +260,7 @@ bool CFX_Barcode::SetEndChar(FX_CHAR end) { } return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(end) : false; } + bool CFX_Barcode::SetVersion(int32_t version) { typedef bool (CBC_CodeBase::*memptrtype)(int32_t); memptrtype memptr = nullptr; @@ -258,6 +273,7 @@ bool CFX_Barcode::SetVersion(int32_t version) { } return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(version) : false; } + bool CFX_Barcode::SetErrorCorrectionLevel(int32_t level) { typedef bool (CBC_CodeBase::*memptrtype)(int32_t); memptrtype memptr = nullptr; diff --git a/xfa/fwl/core/fwl_noteimp.cpp b/xfa/fwl/core/fwl_noteimp.cpp index 716aa24e5f..1e2b7bf479 100644 --- a/xfa/fwl/core/fwl_noteimp.cpp +++ b/xfa/fwl/core/fwl_noteimp.cpp @@ -23,6 +23,7 @@ CFWL_NoteDriver::CFWL_NoteDriver() m_pNoteLoop(pdfium::MakeUnique()) { PushNoteLoop(m_pNoteLoop.get()); } + CFWL_NoteDriver::~CFWL_NoteDriver() { ClearEventTargets(true); } @@ -77,19 +78,20 @@ CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() { m_noteLoopQueue.RemoveAt(pos - 1); return p; } + bool CFWL_NoteDriver::SetFocus(IFWL_Widget* pFocus, bool bNotify) { - if (m_pFocus == pFocus) { + if (m_pFocus == pFocus) return true; - } + IFWL_Widget* pPrev = m_pFocus; m_pFocus = pFocus; if (pPrev) { CFWL_MsgKillFocus ms; ms.m_pDstTarget = pPrev; ms.m_pSrcTarget = pPrev; - if (bNotify) { + if (bNotify) ms.m_dwExtend = 1; - } + if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) pDelegate->OnProcessMessage(&ms); } @@ -102,10 +104,8 @@ bool CFWL_NoteDriver::SetFocus(IFWL_Widget* pFocus, bool bNotify) { CFWL_MsgSetFocus ms; ms.m_pDstTarget = pFocus; - if (bNotify) { + if (bNotify) ms.m_dwExtend = 1; - } - if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) pDelegate->OnProcessMessage(&ms); } @@ -115,51 +115,44 @@ bool CFWL_NoteDriver::SetFocus(IFWL_Widget* pFocus, bool bNotify) { void CFWL_NoteDriver::Run() { #if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \ _FX_OS_ == _FX_WIN64_) - CFWL_NoteLoop* pTopLoop = nullptr; for (;;) { - pTopLoop = GetTopLoop(); + CFWL_NoteLoop* pTopLoop = GetTopLoop(); if (!pTopLoop || !pTopLoop->ContinueModal()) break; - if (UnqueueMessage(pTopLoop)) - continue; + UnqueueMessage(pTopLoop); } #endif } void CFWL_NoteDriver::NotifyTargetHide(IFWL_Widget* pNoteTarget) { - if (m_pFocus == pNoteTarget) { + if (m_pFocus == pNoteTarget) m_pFocus = nullptr; - } - if (m_pHover == pNoteTarget) { + if (m_pHover == pNoteTarget) m_pHover = nullptr; - } - if (m_pGrab == pNoteTarget) { + if (m_pGrab == pNoteTarget) m_pGrab = nullptr; - } } + void CFWL_NoteDriver::NotifyTargetDestroy(IFWL_Widget* pNoteTarget) { - if (m_pFocus == pNoteTarget) { + if (m_pFocus == pNoteTarget) m_pFocus = nullptr; - } - if (m_pHover == pNoteTarget) { + if (m_pHover == pNoteTarget) m_pHover = nullptr; - } - if (m_pGrab == pNoteTarget) { + if (m_pGrab == pNoteTarget) m_pGrab = nullptr; - } + UnregisterEventTarget(pNoteTarget); - int32_t count = m_forms.GetSize(); - for (int32_t nIndex = 0; nIndex < count; nIndex++) { + + for (int32_t nIndex = 0; nIndex < m_forms.GetSize(); nIndex++) { IFWL_Form* pForm = static_cast(m_forms[nIndex]); - if (!pForm) { + if (!pForm) continue; - } + IFWL_Widget* pSubFocus = pForm->GetSubFocus(); if (!pSubFocus) return; - if (pSubFocus == pNoteTarget) { + if (pSubFocus == pNoteTarget) pForm->SetSubFocus(nullptr); - } } } @@ -168,174 +161,178 @@ void CFWL_NoteDriver::RegisterForm(IFWL_Widget* pForm) { return; m_forms.Add(pForm); - if (m_forms.GetSize() == 1) { - CFWL_NoteLoop* pLoop = - static_cast(m_noteLoopQueue.GetAt(0)); - if (!pLoop) - return; - pLoop->SetMainForm(pForm); - } + if (m_forms.GetSize() != 1) + return; + + CFWL_NoteLoop* pLoop = m_noteLoopQueue.GetAt(0); + if (!pLoop) + return; + + pLoop->SetMainForm(pForm); } void CFWL_NoteDriver::UnRegisterForm(IFWL_Widget* pForm) { if (!pForm) return; + int32_t nIndex = m_forms.Find(pForm); if (nIndex < 0) return; + m_forms.RemoveAt(nIndex); } -bool CFWL_NoteDriver::QueueMessage(CFWL_Message* pMessage) { + +void CFWL_NoteDriver::QueueMessage(CFWL_Message* pMessage) { pMessage->Retain(); m_noteQueue.Add(pMessage); - return true; } -bool CFWL_NoteDriver::UnqueueMessage(CFWL_NoteLoop* pNoteLoop) { - if (m_noteQueue.GetSize() < 1) { - return false; - } + +void CFWL_NoteDriver::UnqueueMessage(CFWL_NoteLoop* pNoteLoop) { + if (m_noteQueue.GetSize() < 1) + return; + CFWL_Message* pMessage = m_noteQueue[0]; m_noteQueue.RemoveAt(0); if (!IsValidMessage(pMessage)) { pMessage->Release(); - return true; + return; } ProcessMessage(pMessage); - pMessage->Release(); - return true; } + CFWL_NoteLoop* CFWL_NoteDriver::GetTopLoop() const { int32_t size = m_noteLoopQueue.GetSize(); if (size <= 0) return nullptr; - return static_cast(m_noteLoopQueue[size - 1]); + return m_noteLoopQueue[size - 1]; } -bool CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) { +void CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) { CFWL_WidgetMgr* pWidgetMgr = pMessage->m_pDstTarget->GetOwnerApp()->GetWidgetMgr(); IFWL_Widget* pMessageForm = pWidgetMgr->IsFormDisabled() ? pMessage->m_pDstTarget : GetMessageForm(pMessage->m_pDstTarget); if (!pMessageForm) - return false; - if (DispatchMessage(pMessage, pMessageForm)) { - if (pMessage->GetClassID() == CFWL_MessageType::Mouse) - MouseSecondary(static_cast(pMessage)); - return true; - } - return false; + return; + if (!DispatchMessage(pMessage, pMessageForm)) + return; + + if (pMessage->GetClassID() == CFWL_MessageType::Mouse) + MouseSecondary(pMessage); } bool CFWL_NoteDriver::DispatchMessage(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) { - bool bRet = false; switch (pMessage->GetClassID()) { case CFWL_MessageType::SetFocus: { - bRet = DoSetFocus(static_cast(pMessage), pMessageForm); + if (!DoSetFocus(pMessage, pMessageForm)) + return false; break; } case CFWL_MessageType::KillFocus: { - bRet = - DoKillFocus(static_cast(pMessage), pMessageForm); + if (!DoKillFocus(pMessage, pMessageForm)) + return false; break; } case CFWL_MessageType::Key: { - bRet = DoKey(static_cast(pMessage), pMessageForm); + if (!DoKey(pMessage, pMessageForm)) + return false; break; } case CFWL_MessageType::Mouse: { - bRet = DoMouse(static_cast(pMessage), pMessageForm); + if (!DoMouse(pMessage, pMessageForm)) + return false; break; } case CFWL_MessageType::MouseWheel: { - bRet = DoWheel(static_cast(pMessage), pMessageForm); + if (!DoWheel(pMessage, pMessageForm)) + return false; break; } - default: { - bRet = true; + default: break; - } - } - if (bRet) { - if (IFWL_WidgetDelegate* pDelegate = - pMessage->m_pDstTarget->GetDelegate()) { - pDelegate->OnProcessMessage(pMessage); - } } - return bRet; + if (IFWL_WidgetDelegate* pDelegate = pMessage->m_pDstTarget->GetDelegate()) + pDelegate->OnProcessMessage(pMessage); + + return true; } -bool CFWL_NoteDriver::DoSetFocus(CFWL_MsgSetFocus* pMsg, +bool CFWL_NoteDriver::DoSetFocus(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) { CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); if (pWidgetMgr->IsFormDisabled()) { - m_pFocus = pMsg->m_pDstTarget; + m_pFocus = pMessage->m_pDstTarget; return true; } - IFWL_Widget* pWidget = pMsg->m_pDstTarget; - if (pWidget) { - IFWL_Form* pForm = static_cast(pWidget); - IFWL_Widget* pSubFocus = pForm->GetSubFocus(); - if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) { - pMsg->m_pDstTarget = pSubFocus; - if (m_pFocus != pMsg->m_pDstTarget) { - m_pFocus = pMsg->m_pDstTarget; - return true; - } + + IFWL_Widget* pWidget = pMessage->m_pDstTarget; + if (!pWidget) + return false; + + IFWL_Form* pForm = static_cast(pWidget); + IFWL_Widget* pSubFocus = pForm->GetSubFocus(); + if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) { + pMessage->m_pDstTarget = pSubFocus; + if (m_pFocus != pMessage->m_pDstTarget) { + m_pFocus = pMessage->m_pDstTarget; + return true; } } return false; } -bool CFWL_NoteDriver::DoKillFocus(CFWL_MsgKillFocus* pMsg, + +bool CFWL_NoteDriver::DoKillFocus(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) { CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); if (pWidgetMgr->IsFormDisabled()) { - if (m_pFocus == pMsg->m_pDstTarget) { + if (m_pFocus == pMessage->m_pDstTarget) m_pFocus = nullptr; - } return true; } - IFWL_Form* pForm = static_cast(pMsg->m_pDstTarget); - if (pForm) { - IFWL_Widget* pSubFocus = pForm->GetSubFocus(); - if (pSubFocus && (pSubFocus->GetStates() & FWL_WGTSTATE_Focused)) { - pMsg->m_pDstTarget = pSubFocus; - if (m_pFocus == pMsg->m_pDstTarget) { - m_pFocus = nullptr; - return true; - } + + IFWL_Form* pForm = static_cast(pMessage->m_pDstTarget); + if (!pForm) + return false; + + IFWL_Widget* pSubFocus = pForm->GetSubFocus(); + if (pSubFocus && (pSubFocus->GetStates() & FWL_WGTSTATE_Focused)) { + pMessage->m_pDstTarget = pSubFocus; + if (m_pFocus == pMessage->m_pDstTarget) { + m_pFocus = nullptr; + return true; } } return false; } -bool CFWL_NoteDriver::DoKey(CFWL_MsgKey* pMsg, IFWL_Widget* pMessageForm) { + +bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) { + CFWL_MsgKey* pMsg = static_cast(pMessage); #if (_FX_OS_ != _FX_MACOSX_) if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && pMsg->m_dwKeyCode == FWL_VKEY_Tab) { CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); IFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget); IFWL_Widget* pFocus = m_pFocus; - if (m_pFocus) { - if (pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) - pFocus = nullptr; - } + if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) + pFocus = nullptr; + bool bFind = false; IFWL_Widget* pNextTabStop = pWidgetMgr->NextTab(pForm, pFocus, bFind); if (!pNextTabStop) { bFind = false; pNextTabStop = pWidgetMgr->NextTab(pForm, nullptr, bFind); } - if (pNextTabStop == pFocus) { + if (pNextTabStop == pFocus) return true; - } - if (pNextTabStop) { + if (pNextTabStop) SetFocus(pNextTabStop); - } return true; } #endif + if (!m_pFocus) { if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && pMsg->m_dwKeyCode == FWL_VKEY_Return) { @@ -351,26 +348,29 @@ bool CFWL_NoteDriver::DoKey(CFWL_MsgKey* pMsg, IFWL_Widget* pMessageForm) { pMsg->m_pDstTarget = m_pFocus; return true; } -bool CFWL_NoteDriver::DoMouse(CFWL_MsgMouse* pMsg, IFWL_Widget* pMessageForm) { + +bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage, + IFWL_Widget* pMessageForm) { + CFWL_MsgMouse* pMsg = static_cast(pMessage); if (pMsg->m_dwCmd == FWL_MouseCommand::Leave || pMsg->m_dwCmd == FWL_MouseCommand::Hover || pMsg->m_dwCmd == FWL_MouseCommand::Enter) { return !!pMsg->m_pDstTarget; } - if (pMsg->m_pDstTarget != pMessageForm) { + if (pMsg->m_pDstTarget != pMessageForm) pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy); - } - if (!DoMouseEx(pMsg, pMessageForm)) { + if (!DoMouseEx(pMsg, pMessageForm)) pMsg->m_pDstTarget = pMessageForm; - } return true; } -bool CFWL_NoteDriver::DoWheel(CFWL_MsgMouseWheel* pMsg, + +bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) { CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); if (!pWidgetMgr) return false; + CFWL_MsgMouseWheel* pMsg = static_cast(pMessage); IFWL_Widget* pDst = pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); if (!pDst) @@ -381,7 +381,7 @@ bool CFWL_NoteDriver::DoWheel(CFWL_MsgMouseWheel* pMsg, return true; } -bool CFWL_NoteDriver::DoMouseEx(CFWL_MsgMouse* pMsg, +bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) { CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); if (!pWidgetMgr) @@ -389,31 +389,36 @@ bool CFWL_NoteDriver::DoMouseEx(CFWL_MsgMouse* pMsg, IFWL_Widget* pTarget = nullptr; if (m_pGrab) pTarget = m_pGrab; + + CFWL_MsgMouse* pMsg = static_cast(pMessage); if (!pTarget) { pTarget = pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); } if (pTarget) { - if (pMessageForm != pTarget) { + if (pMessageForm != pTarget) pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy); - } } if (!pTarget) return false; + pMsg->m_pDstTarget = pTarget; return true; } -void CFWL_NoteDriver::MouseSecondary(CFWL_MsgMouse* pMsg) { - IFWL_Widget* pTarget = pMsg->m_pDstTarget; - if (pTarget == m_pHover) { + +void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { + IFWL_Widget* pTarget = pMessage->m_pDstTarget; + if (pTarget == m_pHover) return; - } + + CFWL_MsgMouse* pMsg = static_cast(pMessage); if (m_pHover) { CFWL_MsgMouse msLeave; msLeave.m_pDstTarget = m_pHover; msLeave.m_fx = pMsg->m_fx; msLeave.m_fy = pMsg->m_fy; pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy); + msLeave.m_dwFlags = 0; msLeave.m_dwCmd = FWL_MouseCommand::Leave; DispatchMessage(&msLeave, nullptr); @@ -423,6 +428,7 @@ void CFWL_NoteDriver::MouseSecondary(CFWL_MsgMouse* pMsg) { return; } m_pHover = pTarget; + CFWL_MsgMouse msHover; msHover.m_pDstTarget = pTarget; msHover.m_fx = pMsg->m_fx; @@ -431,16 +437,16 @@ void CFWL_NoteDriver::MouseSecondary(CFWL_MsgMouse* pMsg) { msHover.m_dwCmd = FWL_MouseCommand::Hover; DispatchMessage(&msHover, nullptr); } + bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { - int32_t iCount = m_noteLoopQueue.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - CFWL_NoteLoop* pNoteLoop = static_cast(m_noteLoopQueue[i]); + for (int32_t i = 0; i < m_noteLoopQueue.GetSize(); i++) { + CFWL_NoteLoop* pNoteLoop = m_noteLoopQueue[i]; IFWL_Widget* pForm = pNoteLoop->GetForm(); if (pForm && (pForm == pMessage->m_pDstTarget)) return true; } - iCount = m_forms.GetSize(); - for (int32_t j = 0; j < iCount; j++) { + + for (int32_t j = 0; j < m_forms.GetSize(); j++) { IFWL_Form* pForm = static_cast(m_forms[j]); if (pForm == pMessage->m_pDstTarget) return true; @@ -452,14 +458,12 @@ IFWL_Widget* CFWL_NoteDriver::GetMessageForm(IFWL_Widget* pDstTarget) { int32_t iTrackLoop = m_noteLoopQueue.GetSize(); if (iTrackLoop <= 0) return nullptr; + IFWL_Widget* pMessageForm = nullptr; - if (iTrackLoop > 1) { - CFWL_NoteLoop* pNootLoop = - static_cast(m_noteLoopQueue[iTrackLoop - 1]); - pMessageForm = pNootLoop->GetForm(); - } else if (m_forms.Find(pDstTarget) < 0) { + if (iTrackLoop > 1) + pMessageForm = m_noteLoopQueue[iTrackLoop - 1]->GetForm(); + else if (m_forms.Find(pDstTarget) < 0) pMessageForm = pDstTarget; - } if (!pMessageForm && pDstTarget) { CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr(); if (!pWidgetMgr) @@ -482,6 +486,7 @@ void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener) : m_pListener(pListener), m_bInvalid(false) {} + CFWL_EventTarget::~CFWL_EventTarget() { m_eventSources.RemoveAll(); } @@ -503,6 +508,7 @@ bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { pDelegate->OnProcessEvent(pEvent); return true; } + FX_POSITION pos = m_eventSources.GetStartPosition(); while (pos) { IFWL_Widget* pSource = nullptr; diff --git a/xfa/fwl/core/fwl_noteimp.h b/xfa/fwl/core/fwl_noteimp.h index 320ea44f84..9eaaed596f 100644 --- a/xfa/fwl/core/fwl_noteimp.h +++ b/xfa/fwl/core/fwl_noteimp.h @@ -17,11 +17,6 @@ #include "xfa/fxgraphics/cfx_graphics.h" class CFWL_EventTarget; -class CFWL_MsgKey; -class CFWL_MsgKillFocus; -class CFWL_MsgMouse; -class CFWL_MsgMouseWheel; -class CFWL_MsgSetFocus; class CFWL_TargetImp; class IFWL_ToolTip; class IFWL_Widget; @@ -72,19 +67,19 @@ class CFWL_NoteDriver { void RegisterForm(IFWL_Widget* pForm); void UnRegisterForm(IFWL_Widget* pForm); - bool QueueMessage(CFWL_Message* pMessage); - bool UnqueueMessage(CFWL_NoteLoop* pNoteLoop); - bool ProcessMessage(CFWL_Message* pMessage); + void QueueMessage(CFWL_Message* pMessage); + void UnqueueMessage(CFWL_NoteLoop* pNoteLoop); + void ProcessMessage(CFWL_Message* pMessage); private: bool DispatchMessage(CFWL_Message* pMessage, IFWL_Widget* pMessageForm); - bool DoSetFocus(CFWL_MsgSetFocus* pMsg, IFWL_Widget* pMessageForm); - bool DoKillFocus(CFWL_MsgKillFocus* pMsg, IFWL_Widget* pMessageForm); - bool DoKey(CFWL_MsgKey* pMsg, IFWL_Widget* pMessageForm); - bool DoMouse(CFWL_MsgMouse* pMsg, IFWL_Widget* pMessageForm); - bool DoWheel(CFWL_MsgMouseWheel* pMsg, IFWL_Widget* pMessageForm); - bool DoMouseEx(CFWL_MsgMouse* pMsg, IFWL_Widget* pMessageForm); - void MouseSecondary(CFWL_MsgMouse* pMsg); + bool DoSetFocus(CFWL_Message* pMsg, IFWL_Widget* pMessageForm); + bool DoKillFocus(CFWL_Message* pMsg, IFWL_Widget* pMessageForm); + bool DoKey(CFWL_Message* pMsg, IFWL_Widget* pMessageForm); + bool DoMouse(CFWL_Message* pMsg, IFWL_Widget* pMessageForm); + bool DoWheel(CFWL_Message* pMsg, IFWL_Widget* pMessageForm); + bool DoMouseEx(CFWL_Message* pMsg, IFWL_Widget* pMessageForm); + void MouseSecondary(CFWL_Message* pMsg); bool IsValidMessage(CFWL_Message* pMessage); IFWL_Widget* GetMessageForm(IFWL_Widget* pDstTarget); -- cgit v1.2.3