summaryrefslogtreecommitdiff
path: root/dbaccess/source/ui/querydesign/TableWindow.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'dbaccess/source/ui/querydesign/TableWindow.cxx')
-rw-r--r--dbaccess/source/ui/querydesign/TableWindow.cxx199
1 files changed, 84 insertions, 115 deletions
diff --git a/dbaccess/source/ui/querydesign/TableWindow.cxx b/dbaccess/source/ui/querydesign/TableWindow.cxx
index d32ba27b90ca..a1e4d34c1d56 100644
--- a/dbaccess/source/ui/querydesign/TableWindow.cxx
+++ b/dbaccess/source/ui/querydesign/TableWindow.cxx
@@ -25,12 +25,15 @@
#include <JoinTableView.hxx>
#include <JoinDesignView.hxx>
#include <osl/diagnose.h>
+#include <utility>
#include <vcl/svapp.hxx>
-#include <vcl/wall.hxx>
#include <vcl/settings.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <vcl/ptrstyle.hxx>
+#include <vcl/wall.hxx>
+#include <vcl/weldutils.hxx>
+#include <comphelper/diagnose_ex.hxx>
#include <com/sun/star/container/XContainer.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -39,19 +42,13 @@
#include <bitmaps.hlst>
#include <TableWindowAccess.hxx>
#include <connectivity/dbtools.hxx>
-#include <vcl/treelistentry.hxx>
-#include <vcl/builder.hxx>
using namespace dbaui;
-using namespace ::utl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::sdb;
-using namespace ::com::sun::star::sdbc;
-using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::accessibility;
namespace DatabaseObject = css::sdb::application::DatabaseObject;
@@ -86,17 +83,15 @@ void Draw3DBorder(vcl::RenderContext& rRenderContext, const tools::Rectangle& rR
}
-OTableWindow::OTableWindow( vcl::Window* pParent, const TTableWindowData::value_type& pTabWinData )
- : ::comphelper::OContainerListener(m_aMutex)
- ,Window( pParent, WB_3DLOOK|WB_MOVEABLE )
- ,m_aTypeImage( VclPtr<FixedImage>::Create(this) )
- ,m_xTitle( VclPtr<OTableWindowTitle>::Create(this) )
- ,m_pData( pTabWinData )
- ,m_nMoveCount(0)
- ,m_nMoveIncrement(1)
- ,m_nSizingFlags( SizingFlags::NONE )
+OTableWindow::OTableWindow( vcl::Window* pParent, TTableWindowData::value_type pTabWinData )
+ : ::comphelper::OContainerListener(m_aMutex)
+ , Window( pParent, WB_3DLOOK|WB_MOVEABLE )
+ , m_xTitle( VclPtr<OTableWindowTitle>::Create(this) )
+ , m_pData(std::move( pTabWinData ))
+ , m_nMoveCount(0)
+ , m_nMoveIncrement(1)
+ , m_nSizingFlags( SizingFlags::NONE )
{
-
// Set position and size
if( GetData()->HasPosition() )
SetPosPixel( GetData()->GetPosition() );
@@ -123,13 +118,12 @@ void OTableWindow::dispose()
{
if (m_xListBox)
{
- OSL_ENSURE(m_xListBox->GetEntryCount()==0,"Forgot to call EmptyListbox()!");
+ OSL_ENSURE(m_xListBox->get_widget().n_children()==0,"Forgot to call EmptyListbox()!");
}
m_xListBox.disposeAndClear();
if ( m_pContainerListener.is() )
m_pContainerListener->dispose();
- m_aTypeImage.disposeAndClear();
m_xTitle.disposeAndClear();
vcl::Window::dispose();
}
@@ -179,7 +173,10 @@ void OTableWindow::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
void OTableWindow::FillListBox()
{
- m_xListBox->Clear();
+ clearListBox();
+ weld::TreeView& rTreeView = m_xListBox->get_widget();
+ assert(!rTreeView.n_children());
+
if ( !m_pContainerListener.is() )
{
Reference< XContainer> xContainer(m_pData->getColumns(),UNO_QUERY);
@@ -188,12 +185,11 @@ void OTableWindow::FillListBox()
}
// mark all primary keys with special image
- Image aPrimKeyImage(StockImage::Yes, BMP_PRIMARY_KEY);
+ OUString aPrimKeyImage(BMP_PRIMARY_KEY);
if (GetData()->IsShowAll())
{
- SvTreeListEntry* pEntry = m_xListBox->InsertEntry( OUString("*") );
- pEntry->SetUserData( createUserData(nullptr,false) );
+ rTreeView.append(weld::toId(createUserData(nullptr,false)), OUString("*"));
}
Reference<XNameAccess> xPKeyColumns;
@@ -203,7 +199,7 @@ void OTableWindow::FillListBox()
}
catch(Exception&)
{
- OSL_FAIL("Exception occurred!");
+ TOOLS_WARN_EXCEPTION( "dbaccess", "");
}
try
{
@@ -214,25 +210,27 @@ void OTableWindow::FillListBox()
const OUString* pIter = aColumns.getConstArray();
const OUString* pEnd = pIter + aColumns.getLength();
- SvTreeListEntry* pEntry = nullptr;
for (; pIter != pEnd; ++pIter)
{
bool bPrimaryKeyColumn = xPKeyColumns.is() && xPKeyColumns->hasByName( *pIter );
- // is this column in the primary key
- if ( bPrimaryKeyColumn )
- pEntry = m_xListBox->InsertEntry(*pIter, aPrimKeyImage, aPrimKeyImage);
- else
- pEntry = m_xListBox->InsertEntry(*pIter);
+ OUString sId;
Reference<XPropertySet> xColumn(xColumns->getByName(*pIter),UNO_QUERY);
- if ( xColumn.is() )
- pEntry->SetUserData( createUserData(xColumn,bPrimaryKeyColumn) );
+ if (xColumn.is())
+ sId = weld::toId(createUserData(xColumn, bPrimaryKeyColumn));
+
+ rTreeView.append(sId, *pIter);
+
+ // is this column in the primary key
+ if ( bPrimaryKeyColumn )
+ rTreeView.set_image(rTreeView.n_children() - 1, aPrimKeyImage);
}
+
}
}
catch(Exception&)
{
- OSL_FAIL("Exception occurred!");
+ TOOLS_WARN_EXCEPTION( "dbaccess", "");
}
}
@@ -252,33 +250,22 @@ void OTableWindow::clearListBox()
if ( !m_xListBox )
return;
- SvTreeListEntry* pEntry = m_xListBox->First();
-
- while(pEntry)
- {
- void* pUserData = pEntry->GetUserData();
+ weld::TreeView& rTreeView = m_xListBox->get_widget();
+ rTreeView.all_foreach([this, &rTreeView](weld::TreeIter& rEntry){
+ void* pUserData = weld::fromId<void*>(rTreeView.get_id(rEntry));
deleteUserData(pUserData);
- SvTreeListEntry* pNextEntry = m_xListBox->Next(pEntry);
- m_xListBox->GetModel()->Remove(pEntry);
- pEntry = pNextEntry;
- }
+ return false;
+ });
+
+ rTreeView.clear();
}
void OTableWindow::impl_updateImage()
{
+ weld::Image& rImage = m_xTitle->GetImage();
ImageProvider aImageProvider( getDesignView()->getController().getConnection() );
-
- Image aImage;
- aImageProvider.getImages( GetComposedName(), m_pData->isQuery() ? DatabaseObject::QUERY : DatabaseObject::TABLE, aImage );
-
- if ( !aImage )
- {
- OSL_FAIL( "OTableWindow::impl_updateImage: no images!" );
- return;
- }
-
- m_aTypeImage->SetModeImage( aImage );
- m_aTypeImage->Show();
+ rImage.set_from_icon_name(aImageProvider.getImageId(GetComposedName(), m_pData->isQuery() ? DatabaseObject::QUERY : DatabaseObject::TABLE));
+ rImage.show();
}
bool OTableWindow::Init()
@@ -287,20 +274,21 @@ bool OTableWindow::Init()
if ( !m_xListBox )
{
m_xListBox = VclPtr<OTableWindowListBox>::Create(this);
- OSL_ENSURE( m_xListBox != nullptr, "OTableWindow::Init() : CreateListBox returned NULL !" );
- m_xListBox->SetSelectionMode( SelectionMode::Multiple );
+ assert(m_xListBox && "OTableWindow::Init() : CreateListBox returned NULL !");
+ m_xListBox->get_widget().set_selection_mode(SelectionMode::Multiple);
}
// Set the title
- m_xTitle->SetText( m_pData->GetWinName() );
+ weld::Label& rLabel = m_xTitle->GetLabel();
+ rLabel.set_label(m_pData->GetWinName());
+ rLabel.set_tooltip_text(GetComposedName());
m_xTitle->Show();
m_xListBox->Show();
// add the fields to the ListBox
- clearListBox();
FillListBox();
- m_xListBox->SelectAll( false );
+ m_xListBox->get_widget().unselect_all();
impl_updateImage();
@@ -428,25 +416,20 @@ void OTableWindow::Resize()
Size aOutSize = GetOutputSizePixel();
aOutSize = Size(CalcZoom(aOutSize.Width()),CalcZoom(aOutSize.Height()));
- long nTitleHeight = CalcZoom( GetTextHeight() )+ CalcZoom( 4 );
+ tools::Long nTitleHeight = CalcZoom( GetTextHeight() )+ CalcZoom( 4 );
// Set the title and ListBox
- long n5Pos = CalcZoom(5);
- long nPositionX = n5Pos;
- long nPositionY = n5Pos;
-
- // position the image which indicates the type
- m_aTypeImage->SetPosPixel( Point( nPositionX, nPositionY ) );
- Size aImageSize( m_aTypeImage->GetImage().GetSizePixel() );
- m_aTypeImage->SetSizePixel( aImageSize );
+ tools::Long n5Pos = CalcZoom(5);
+ tools::Long nPositionX = n5Pos;
+ tools::Long nPositionY = n5Pos;
- if ( nTitleHeight < aImageSize.Height() )
- nTitleHeight = aImageSize.Height();
+ Size aPreferredSize = m_xTitle->get_preferred_size();
+ if (nTitleHeight < aPreferredSize.Height())
+ nTitleHeight = aPreferredSize.Height();
- nPositionX += aImageSize.Width() + CalcZoom( 2 );
m_xTitle->SetPosSizePixel( Point( nPositionX, nPositionY ), Size( aOutSize.Width() - nPositionX - n5Pos, nTitleHeight ) );
- long nTitleToList = CalcZoom( 3 );
+ tools::Long nTitleToList = CalcZoom( 3 );
m_xListBox->SetPosSizePixel(
Point( n5Pos, nPositionY + nTitleHeight + nTitleToList ),
@@ -458,10 +441,10 @@ void OTableWindow::Resize()
void OTableWindow::SetBoldTitle( bool bBold )
{
- vcl::Font aFont = m_xTitle->GetFont();
- aFont.SetWeight( bBold?WEIGHT_BOLD:WEIGHT_NORMAL );
- m_xTitle->SetFont( aFont );
- m_xTitle->Invalidate();
+ weld::Label& rLabel = m_xTitle->GetLabel();
+ vcl::Font aFont = rLabel.get_font();
+ aFont.SetWeight(bBold ? WEIGHT_BOLD : WEIGHT_NORMAL);
+ rLabel.set_font(aFont);
}
void OTableWindow::GetFocus()
@@ -475,8 +458,12 @@ void OTableWindow::GetFocus()
void OTableWindow::setActive(bool _bActive)
{
SetBoldTitle( _bActive );
- if (!_bActive && m_xListBox && m_xListBox->GetSelectionCount() != 0)
- m_xListBox->SelectAll(false);
+ if (_bActive || !m_xListBox)
+ return;
+
+ weld::TreeView& rTreeView = m_xListBox->get_widget();
+ if (rTreeView.get_selected_index() != -1)
+ rTreeView.unselect_all();
}
void OTableWindow::Remove()
@@ -488,23 +475,6 @@ void OTableWindow::Remove()
pTabWinCont->Invalidate();
}
-bool OTableWindow::HandleKeyInput( const KeyEvent& rEvt )
-{
- const vcl::KeyCode& rCode = rEvt.GetKeyCode();
- sal_uInt16 nCode = rCode.GetCode();
- bool bShift = rCode.IsShift();
- bool bCtrl = rCode.IsMod1();
-
- bool bHandle = false;
-
- if( !bCtrl && !bShift && (nCode==KEY_DELETE) )
- {
- Remove();
- bHandle = true;
- }
- return bHandle;
-}
-
bool OTableWindow::ExistsAConn() const
{
return getTableView()->ExistsAConn(this);
@@ -513,17 +483,13 @@ bool OTableWindow::ExistsAConn() const
void OTableWindow::EnumValidFields(std::vector< OUString>& arrstrFields)
{
arrstrFields.clear();
+ weld::TreeView& rTreeView = m_xListBox->get_widget();
+
// This default implementation counts every item in the ListBox ... for any other behaviour it must be over-written
- if ( m_xListBox )
- {
- arrstrFields.reserve(m_xListBox->GetEntryCount());
- SvTreeListEntry* pEntryLoop = m_xListBox->First();
- while (pEntryLoop)
- {
- arrstrFields.push_back(m_xListBox->GetEntryText(pEntryLoop));
- pEntryLoop = m_xListBox->Next(pEntryLoop);
- }
- }
+ rTreeView.all_foreach([&rTreeView, &arrstrFields](weld::TreeIter& rEntry){
+ arrstrFields.push_back(rTreeView.get_text(rEntry));
+ return false;
+ });
}
void OTableWindow::StateChanged( StateChangedType nType )
@@ -540,7 +506,7 @@ void OTableWindow::StateChanged( StateChangedType nType )
vcl::Font aFont = rStyleSettings.GetGroupFont();
if ( IsControlFont() )
aFont.Merge( GetControlFont() );
- SetZoomedPointFont(*this, aFont);
+ SetZoomedPointFont(*GetOutDev(), aFont);
m_xTitle->SetZoom(GetZoom());
m_xListBox->SetZoom(GetZoom());
@@ -567,16 +533,19 @@ void OTableWindow::Command(const CommandEvent& rEvt)
ptWhere = rEvt.GetMousePosPixel();
else
{
- SvTreeListEntry* pCurrent = m_xListBox->GetCurEntry();
- if ( pCurrent )
- ptWhere = m_xListBox->GetEntryPosition(pCurrent);
+ weld::TreeView& rTreeView = m_xListBox->get_widget();
+ std::unique_ptr<weld::TreeIter> xCurrent = rTreeView.make_iterator();
+ if (rTreeView.get_cursor(xCurrent.get()))
+ ptWhere = rTreeView.get_row_area(*xCurrent).Center();
else
ptWhere = m_xTitle->GetPosPixel();
}
- VclBuilder aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "dbaccess/ui/jointablemenu.ui", "");
- VclPtr<PopupMenu> aContextMenu(aBuilder.get_menu("menu"));
- if (aContextMenu->Execute(this, ptWhere))
+ ::tools::Rectangle aRect(ptWhere, Size(1, 1));
+ weld::Window* pPopupParent = weld::GetPopupParent(*this, aRect);
+ std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "dbaccess/ui/jointablemenu.ui"));
+ std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
+ if (!xContextMenu->popup_at_rect(pPopupParent, aRect).isEmpty())
Remove();
}
break;
@@ -591,7 +560,7 @@ bool OTableWindow::PreNotify(NotifyEvent& rNEvt)
bool bHandled = false;
switch (rNEvt.GetType())
{
- case MouseNotifyEvent::KEYINPUT:
+ case NotifyEventType::KEYINPUT:
{
if ( getDesignView()->getController().isReadOnly() )
break;
@@ -701,7 +670,7 @@ bool OTableWindow::PreNotify(NotifyEvent& rNEvt)
}
break;
}
- case MouseNotifyEvent::KEYUP:
+ case NotifyEventType::KEYUP:
{
const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
const vcl::KeyCode& rCode = pKeyEvent->GetKeyCode();
@@ -723,7 +692,7 @@ bool OTableWindow::PreNotify(NotifyEvent& rNEvt)
OUString OTableWindow::getTitle() const
{
- return m_xTitle->GetText();
+ return m_xTitle->GetLabel().get_label();
}
void OTableWindow::_elementInserted( const container::ContainerEvent& /*_rEvent*/ )