diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-08-06 12:18:43 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-08-09 20:18:47 +0200 |
commit | 7614efb59d948ca07c16e32523831b81922ac8f9 (patch) | |
tree | 7b242432e4e5a31fd7b8c32851efc58284f58ae6 /dbaccess/source | |
parent | a3a6ff25f5749207dbfae3d22ec5f2a3c8623d9a (diff) |
weld OCreationList
Change-Id: Ia234233cd44b91518c22e125fef4180068b07be4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100255
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'dbaccess/source')
-rw-r--r-- | dbaccess/source/ui/app/AppDetailView.cxx | 313 | ||||
-rw-r--r-- | dbaccess/source/ui/app/AppDetailView.hxx | 43 |
2 files changed, 74 insertions, 282 deletions
diff --git a/dbaccess/source/ui/app/AppDetailView.cxx b/dbaccess/source/ui/app/AppDetailView.cxx index 469c0c113050..a052f5c556bb 100644 --- a/dbaccess/source/ui/app/AppDetailView.cxx +++ b/dbaccess/source/ui/app/AppDetailView.cxx @@ -56,8 +56,6 @@ using namespace ::com::sun::star::beans; using ::com::sun::star::util::URL; using ::com::sun::star::sdb::application::NamedDatabaseObject; -#define SPACEBETWEENENTRIES 4 - TaskEntry::TaskEntry( const char* _pAsciiUNOCommand, const char* _pHelpID, const char* pTitleResourceID ) :sUNOCommand( OUString::createFromAscii( _pAsciiUNOCommand ) ) ,pHelpID( _pHelpID ) @@ -66,269 +64,88 @@ TaskEntry::TaskEntry( const char* _pAsciiUNOCommand, const char* _pHelpID, const } OCreationList::OCreationList( OTasksWindow& _rParent ) - :SvTreeListBox( &_rParent, WB_TABSTOP | WB_HASBUTTONSATROOT | WB_HASBUTTONS ) - ,m_rTaskWindow( _rParent ) - ,m_pMouseDownEntry( nullptr ) - ,m_pLastActiveEntry( nullptr ) -{ - SetSpaceBetweenEntries(SPACEBETWEENENTRIES); - SetSelectionMode( SelectionMode::NONE ); - SetNoAutoCurEntry( true ); - SetNodeDefaultImages( ); -} - -void OCreationList::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect ) -{ - SetBackground(); - - if (m_pMouseDownEntry) - m_aOriginalFont = rRenderContext.GetFont(); - - m_aOriginalBackgroundColor = rRenderContext.GetBackground().GetColor(); - SvTreeListBox::Paint(rRenderContext, _rRect); - rRenderContext.SetBackground(m_aOriginalBackgroundColor); - - if (m_pMouseDownEntry) - rRenderContext.SetFont(m_aOriginalFont); -} - -void OCreationList::PreparePaint(vcl::RenderContext& rRenderContext, SvTreeListEntry& rEntry) -{ - Wallpaper aEntryBackground(m_aOriginalBackgroundColor); - - if (&rEntry == GetCurEntry()) - { - // draw a selection background - bool bIsMouseDownEntry = ( &rEntry == m_pMouseDownEntry ); - vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, GetBoundingRect(&rEntry), - bIsMouseDownEntry ? 1 : 2, false, true, false ); - - if (bIsMouseDownEntry) - { - vcl::Font aFont(rRenderContext.GetFont()); - aFont.SetColor(rRenderContext.GetSettings().GetStyleSettings().GetHighlightTextColor()); - rRenderContext.SetFont(aFont); - } - - // and temporary set a transparent background, for all the other - // paint operations the SvTreeListBox is going to do - aEntryBackground = Wallpaper(); - } - - rRenderContext.SetBackground(aEntryBackground); - rEntry.SetBackColor(aEntryBackground.GetColor()); -} - -tools::Rectangle OCreationList::GetFocusRect(const SvTreeListEntry* _pEntry, long _nLine) -{ - tools::Rectangle aRect = SvTreeListBox::GetFocusRect( _pEntry, _nLine ); - aRect.SetLeft( 0 ); - - // try to let the focus rect start before the bitmap item - this looks better - const SvLBoxItem* pBitmapItem = _pEntry->GetFirstItem(SvLBoxItemType::ContextBmp); - SvLBoxTab* pTab = pBitmapItem ? GetTab( _pEntry, pBitmapItem ) : nullptr; - SvViewDataItem* pItemData = pBitmapItem ? GetViewDataItem( _pEntry, pBitmapItem ) : nullptr; - OSL_ENSURE( pTab && pItemData, "OCreationList::GetFocusRect: could not find the first bitmap item!" ); - if ( pTab && pItemData ) - aRect.SetLeft( pTab->GetPos() - pItemData->mnWidth / 2 ); - - // inflate the rectangle a little bit - looks better, too - aRect.SetLeft( std::max< long >( 0, aRect.Left() - 2 ) ); - aRect.SetRight( std::min< long >( GetOutputSizePixel().Width() - 1, aRect.Right() + 2 ) ); - - return aRect; -} - -void OCreationList::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ ) -{ - // don't give this to the base class, it does a ReleaseMouse as very first action - // Though I think this is a bug (it should ReleaseMouse only if it is going to do - // something with the drag-event), I hesitate to fix it in the current state, - // since I don't overlook the consequences, and we're close to 2.0...) -} - -void OCreationList::ModelHasCleared() + : InterimItemWindow(&_rParent, "dbaccess/ui/creationlistbox.ui", "CreationListBox") + , m_xTreeView(m_xBuilder->weld_tree_view("treeview")) + , m_rTaskWindow( _rParent ) + , m_nCursorIndex(-1) { - SvTreeListBox::ModelHasCleared(); - m_pLastActiveEntry = nullptr; - m_pMouseDownEntry = nullptr; -} + InitControlBase(m_xTreeView.get()); -void OCreationList::GetFocus() -{ - SvTreeListBox::GetFocus(); - if ( !GetCurEntry() ) - setCurrentEntryInvalidate( m_pLastActiveEntry ? m_pLastActiveEntry : GetFirstEntryInView() ); + m_xTreeView->set_help_id(HID_APP_CREATION_LIST); + m_xTreeView->connect_row_activated(LINK(this, OCreationList, onSelected)); + m_xTreeView->connect_changed(LINK(this, OCreationList, OnEntrySelectHdl)); + m_xTreeView->connect_key_press(LINK(this, OCreationList, KeyInputHdl)); + m_xTreeView->connect_focus_in(LINK(this, OCreationList, FocusInHdl)); + m_xTreeView->connect_focus_out(LINK(this, OCreationList, FocusOutHdl)); } -void OCreationList::LoseFocus() +IMPL_LINK(OCreationList, KeyInputHdl, const KeyEvent&, rKEvt, bool) { - SvTreeListBox::LoseFocus(); - m_pLastActiveEntry = GetCurEntry(); - setCurrentEntryInvalidate( nullptr ); + return ChildKeyInput(rKEvt); } -void OCreationList::MouseButtonDown( const MouseEvent& rMEvt ) +void OCreationList::dispose() { - SvTreeListBox::MouseButtonDown( rMEvt ); - - OSL_ENSURE( !m_pMouseDownEntry, "OCreationList::MouseButtonDown: I missed some mouse event!" ); - m_pMouseDownEntry = GetCurEntry(); - if ( m_pMouseDownEntry ) - { - InvalidateEntry( m_pMouseDownEntry ); - CaptureMouse(); - } + m_xTreeView.reset(); + InterimItemWindow::dispose(); } -void OCreationList::MouseMove( const MouseEvent& rMEvt ) +void OCreationList::updateHelpText() { - if ( rMEvt.IsLeaveWindow() ) - { - setCurrentEntryInvalidate( nullptr ); - } - else if ( !rMEvt.IsSynthetic() ) - { - SvTreeListEntry* pEntry = GetEntry( rMEvt.GetPosPixel() ); - - if ( m_pMouseDownEntry ) - { - // we're currently in a "mouse down" phase - OSL_ENSURE( IsMouseCaptured(), "OCreationList::MouseMove: inconsistence (1)!" ); - if ( pEntry == m_pMouseDownEntry ) - { - setCurrentEntryInvalidate( m_pMouseDownEntry ); - } - else - { - OSL_ENSURE( ( GetCurEntry() == m_pMouseDownEntry ) || !GetCurEntry(), - "OCreationList::MouseMove: inconsistence (2)!" ); - setCurrentEntryInvalidate( nullptr ); - } - } - else - { - // the user is simply hovering with the mouse - if ( setCurrentEntryInvalidate( pEntry ) ) - { - if ( !m_pMouseDownEntry ) - updateHelpText(); - } - } - } - - SvTreeListBox::MouseMove(rMEvt); + const char* pHelpTextId = nullptr; + int nCurEntry = m_xTreeView->get_selected_index(); + if (nCurEntry != -1) + pHelpTextId = reinterpret_cast<TaskEntry*>(m_xTreeView->get_id(nCurEntry).toUInt64())->pHelpID; + m_rTaskWindow.setHelpText(pHelpTextId); } -void OCreationList::MouseButtonUp( const MouseEvent& rMEvt ) +IMPL_LINK(OCreationList, onSelected, weld::TreeView&, rTreeView, bool) { - SvTreeListEntry* pEntry = GetEntry( rMEvt.GetPosPixel() ); - bool bExecute = false; - // Was the mouse released over the active entry? - // (i.e. the entry which was under the mouse when the button went down) - if ( pEntry && ( m_pMouseDownEntry == pEntry ) ) - { - if ( !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() && rMEvt.IsLeft() && rMEvt.GetClicks() == 1 ) - bExecute = true; - } - - if ( m_pMouseDownEntry ) - { - OSL_ENSURE( IsMouseCaptured(), "OCreationList::MouseButtonUp: hmmm... no mouse captured, but an active entry?" ); - ReleaseMouse(); - - InvalidateEntry( m_pMouseDownEntry ); - m_pMouseDownEntry = nullptr; - } - - SvTreeListBox::MouseButtonUp( rMEvt ); + int nCurEntry = rTreeView.get_cursor_index(); + assert(nCurEntry != -1 && "OCreationList::onSelected: invalid entry!"); + URL aCommand; + aCommand.Complete = reinterpret_cast<TaskEntry*>(rTreeView.get_id(nCurEntry).toUInt64())->sUNOCommand; + m_rTaskWindow.getDetailView()->getBorderWin().getView()->getAppController().executeChecked( aCommand, Sequence< PropertyValue >() ); - if ( bExecute ) - onSelected( pEntry ); + return true; } -bool OCreationList::setCurrentEntryInvalidate( SvTreeListEntry* _pEntry ) +void OCreationList::GetFocus() { - if ( GetCurEntry() != _pEntry ) - { - if ( GetCurEntry() ) - InvalidateEntry( GetCurEntry() ); - SetCurEntry( _pEntry ); - if ( GetCurEntry() ) - { - InvalidateEntry( GetCurEntry() ); - CallEventListeners( VclEventId::ListboxTreeSelect, GetCurEntry() ); - } - updateHelpText(); - return true; - } - return false; + InterimItemWindow::GetFocus(); + if (!m_xTreeView) + return; + FocusInHdl(*m_xTreeView); } -void OCreationList::updateHelpText() +IMPL_LINK_NOARG(OCreationList, FocusInHdl, weld::Widget&, void) { - const char* pHelpTextId = nullptr; - if ( GetCurEntry() ) - pHelpTextId = static_cast< TaskEntry* >( GetCurEntry()->GetUserData() )->pHelpID; - m_rTaskWindow.setHelpText(pHelpTextId); + m_xTreeView->select(m_nCursorIndex != -1 ? m_nCursorIndex : 0); } -void OCreationList::onSelected( SvTreeListEntry const * _pEntry ) const +IMPL_LINK_NOARG(OCreationList, FocusOutHdl, weld::Widget&, void) { - OSL_ENSURE( _pEntry, "OCreationList::onSelected: invalid entry!" ); - URL aCommand; - aCommand.Complete = static_cast< TaskEntry* >( _pEntry->GetUserData() )->sUNOCommand; - m_rTaskWindow.getDetailView()->getBorderWin().getView()->getAppController().executeChecked( aCommand, Sequence< PropertyValue >() ); + m_nCursorIndex = m_xTreeView->get_cursor_index(); + m_xTreeView->unselect_all(); } -void OCreationList::KeyInput( const KeyEvent& rKEvt ) +IMPL_LINK_NOARG(OCreationList, OnEntrySelectHdl, weld::TreeView&, void) { - const vcl::KeyCode& rCode = rKEvt.GetKeyCode(); - if ( !rCode.IsMod1() && !rCode.IsMod2() && !rCode.IsShift() ) - { - if ( rCode.GetCode() == KEY_RETURN ) - { - SvTreeListEntry* pEntry = GetCurEntry() ? GetCurEntry() : FirstSelected(); - if ( pEntry ) - onSelected( pEntry ); - return; - } - } - SvTreeListEntry* pOldCurrent = GetCurEntry(); - SvTreeListBox::KeyInput(rKEvt); - SvTreeListEntry* pNewCurrent = GetCurEntry(); - - if ( pOldCurrent != pNewCurrent ) - { - if ( pOldCurrent ) - InvalidateEntry( pOldCurrent ); - if ( pNewCurrent ) - { - InvalidateEntry( pNewCurrent ); - CallEventListeners( VclEventId::ListboxSelect, pNewCurrent ); - } - updateHelpText(); - } + updateHelpText(); } OTasksWindow::OTasksWindow(vcl::Window* _pParent,OApplicationDetailView* _pDetailView) : Window(_pParent,WB_DIALOGCONTROL ) ,m_aCreation(VclPtr<OCreationList>::Create(*this)) ,m_aDescription(VclPtr<FixedText>::Create(this)) - ,m_aHelpText(VclPtr<FixedText>::Create(this,WB_WORDBREAK)) ,m_aFL(VclPtr<FixedLine>::Create(this,WB_VERT)) + ,m_aHelpText(VclPtr<FixedText>::Create(this,WB_WORDBREAK)) ,m_pDetailView(_pDetailView) { - m_aCreation->SetHelpId(HID_APP_CREATION_LIST); - m_aCreation->SetSelectHdl(LINK(this, OTasksWindow, OnEntrySelectHdl)); m_aHelpText->SetHelpId(HID_APP_HELP_TEXT); m_aDescription->SetHelpId(HID_APP_DESCRIPTION_TEXT); m_aDescription->SetText(DBA_RES(STR_DESCRIPTION)); - Image aFolderImage = ImageProvider::getFolderImage( css::sdb::application::DatabaseObject::FORM ); - m_aCreation->SetDefaultCollapsedEntryBmp( aFolderImage ); - m_aCreation->SetDefaultExpandedEntryBmp( aFolderImage ); - ImplInitSettings(); } @@ -388,24 +205,11 @@ void OTasksWindow::ImplInitSettings() void OTasksWindow::setHelpText(const char* pId) { if (pId) - { - OUString sText = DBA_RES(pId); - m_aHelpText->SetText(sText); - } + m_aHelpText->SetText(DBA_RES(pId)); else - { m_aHelpText->SetText(OUString()); } -} - -IMPL_LINK_NOARG(OTasksWindow, OnEntrySelectHdl, SvTreeListBox*, void) -{ - SvTreeListEntry* pEntry = m_aCreation->GetHdlEntry(); - if ( pEntry ) - m_aHelpText->SetText(DBA_RES(static_cast<TaskEntry*>(pEntry->GetUserData())->pHelpID)); -} - void OTasksWindow::Resize() { // parent window dimension @@ -456,15 +260,13 @@ void OTasksWindow::fillTaskEntryList( const TaskEntryList& _rList ) const Reference< XGraphic >* pImages( aImages.getConstArray() ); + weld::TreeView& rTreeView = m_aCreation->get_widget(); + size_t nIndex = 0; for (auto const& task : _rList) { - SvTreeListEntry* pEntry = m_aCreation->InsertEntry(task.sTitle); - pEntry->SetUserData( new TaskEntry(task) ); - - Image aImage( *pImages ); - m_aCreation->SetExpandedEntryBmp( pEntry, aImage ); - m_aCreation->SetCollapsedEntryBmp( pEntry, aImage ); - ++pImages; + OUString sId = OUString::number(reinterpret_cast<sal_uInt64>(new TaskEntry(task))); + rTreeView.append(sId, task.sTitle); + rTreeView.set_image(nIndex++, *pImages++); } } catch(Exception&) @@ -472,7 +274,7 @@ void OTasksWindow::fillTaskEntryList( const TaskEntryList& _rList ) } m_aCreation->Show(); - m_aCreation->SelectAll(false); + m_aCreation->get_widget().unselect_all(); m_aHelpText->Show(); m_aDescription->Show(); m_aFL->Show(); @@ -482,16 +284,15 @@ void OTasksWindow::fillTaskEntryList( const TaskEntryList& _rList ) void OTasksWindow::Clear() { - m_aCreation->resetLastActive(); - SvTreeListEntry* pEntry = m_aCreation->First(); - while ( pEntry ) - { - delete static_cast< TaskEntry* >( pEntry->GetUserData() ); - pEntry = m_aCreation->Next(pEntry); - } - m_aCreation->Clear(); -} + weld::TreeView& rTreeView = m_aCreation->get_widget(); + rTreeView.all_foreach([&rTreeView](weld::TreeIter& rEntry){ + TaskEntry* pUserData = reinterpret_cast<TaskEntry*>(rTreeView.get_id(rEntry).toUInt64()); + delete pUserData; + return false; + }); + rTreeView.clear(); +} OApplicationDetailView::OApplicationDetailView(OAppBorderWindow& _rParent,PreviewMode _ePreviewMode) : OSplitterView(&_rParent ) ,m_aHorzSplitter(VclPtr<Splitter>::Create(this)) diff --git a/dbaccess/source/ui/app/AppDetailView.hxx b/dbaccess/source/ui/app/AppDetailView.hxx index 60ddddb384c0..835a0ae61c0b 100644 --- a/dbaccess/source/ui/app/AppDetailView.hxx +++ b/dbaccess/source/ui/app/AppDetailView.hxx @@ -25,6 +25,7 @@ #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp> #include <vcl/split.hxx> #include <vcl/fixed.hxx> +#include <vcl/InterimItemWindow.hxx> #include <vcl/mnemonic.hxx> #include <IClipBoardTest.hxx> #include "AppTitleWindow.hxx" @@ -43,39 +44,30 @@ namespace dbaui class OAppDetailPageHelper; class OTasksWindow; - class OCreationList : public SvTreeListBox + class OCreationList final : public InterimItemWindow { - OTasksWindow& m_rTaskWindow; - - // members related to drawing the currently hovered/selected entry - SvTreeListEntry* m_pMouseDownEntry; - SvTreeListEntry* m_pLastActiveEntry; - Color m_aOriginalBackgroundColor; - vcl::Font m_aOriginalFont; + std::unique_ptr<weld::TreeView> m_xTreeView; + OTasksWindow& m_rTaskWindow; + int m_nCursorIndex; public: explicit OCreationList( OTasksWindow& _rParent ); - // Window overrides - virtual void MouseMove( const MouseEvent& rMEvt ) override; - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; - virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; - virtual void KeyInput( const KeyEvent& rKEvt ) override; - virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; - virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ) override; - virtual void GetFocus() override; - virtual void LoseFocus() override; + virtual void dispose() override; - void resetLastActive() { m_pLastActiveEntry = nullptr;} + weld::TreeView& get_widget() { return *m_xTreeView; } + const weld::TreeView& get_widget() const { return *m_xTreeView; } - void updateHelpText(); + virtual void GetFocus() override; - protected: - virtual void PreparePaint(vcl::RenderContext& rRenderContext, SvTreeListEntry& rEntry) override; - virtual tools::Rectangle GetFocusRect(const SvTreeListEntry* _pEntry, long _nLine) override; - virtual void ModelHasCleared() override; + void updateHelpText(); private: - void onSelected( SvTreeListEntry const * _pEntry ) const; + DECL_LINK(onSelected, weld::TreeView&, bool); + DECL_LINK(OnEntrySelectHdl, weld::TreeView&, void); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + DECL_LINK(FocusInHdl, weld::Widget&, void); + DECL_LINK(FocusOutHdl, weld::Widget&, void); + /** sets a new current entry, and invalidates the old and the new one, if necessary @return <TRUE/> if and only if the "current entry" changed */ @@ -107,11 +99,10 @@ namespace dbaui { VclPtr<OCreationList> m_aCreation; VclPtr<FixedText> m_aDescription; - VclPtr<FixedText> m_aHelpText; VclPtr<FixedLine> m_aFL; + VclPtr<FixedText> m_aHelpText; VclPtr<OApplicationDetailView> m_pDetailView; - DECL_LINK( OnEntrySelectHdl, SvTreeListBox*, void ); void ImplInitSettings(); protected: virtual void DataChanged(const DataChangedEvent& rDCEvt) override; |