weld DbNumericField item

Change-Id: I96b7945cdf9f00c3d0a4e043ee77666e19c8a072
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97896
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara
2020-07-03 20:09:37 +01:00
parent 291f1776a6
commit d5b3c5d509
10 changed files with 217 additions and 92 deletions

View File

@@ -497,7 +497,7 @@ DataBrowser::DataBrowser(const css::uno::Reference<css::awt::XWindow> &rParent,
m_nSeekRow( 0 ), m_nSeekRow( 0 ),
m_bIsReadOnly( false ), m_bIsReadOnly( false ),
m_bDataValid( true ), m_bDataValid( true ),
m_aNumberEditField(VclPtr<FormattedControl>::Create(&EditBrowseBox::GetDataWindow())), m_aNumberEditField(VclPtr<FormattedControl>::Create(&EditBrowseBox::GetDataWindow(), false)),
m_aTextEditField(VclPtr<EditControl>::Create(&EditBrowseBox::GetDataWindow())), m_aTextEditField(VclPtr<EditControl>::Create(&EditBrowseBox::GetDataWindow())),
m_pColumnsWin(pColumns), m_pColumnsWin(pColumns),
m_pColorsWin(pColors), m_pColorsWin(pColors),

View File

@@ -186,26 +186,37 @@ namespace svt
virtual void Paste() override; virtual void Paste() override;
}; };
class SVT_DLLPUBLIC EditControlBase : public InterimItemWindow class SVT_DLLPUBLIC ControlBase : public InterimItemWindow
{
public:
ControlBase(BrowserDataWin* pParent, const OUString& rUIXMLDescription, const OString& rID);
bool ControlHasFocus() const;
virtual void dispose() override;
virtual void GetFocus() override;
protected:
void InitControlBase(weld::Widget* pWidget);
private:
weld::Widget* m_pWidget;
};
class SVT_DLLPUBLIC EditControlBase : public ControlBase
{ {
public: public:
EditControlBase(BrowserDataWin* pParent); EditControlBase(BrowserDataWin* pParent);
virtual void dispose() override; virtual void dispose() override;
virtual void GetFocus() override
{
if (m_pEntry)
m_pEntry->grab_focus();
InterimItemWindow::GetFocus();
}
weld::Entry& get_widget() { return *m_pEntry; } weld::Entry& get_widget() { return *m_pEntry; }
virtual void connect_changed(const Link<weld::Entry&, void>& rLink) = 0; virtual void connect_changed(const Link<weld::Entry&, void>& rLink) = 0;
protected: protected:
void init(weld::Entry* pEntry); void InitEditControlBase(weld::Entry* pEntry);
private: private:
weld::Entry* m_pEntry; weld::Entry* m_pEntry;
@@ -422,9 +433,7 @@ namespace svt
DECL_LINK(ModifyHdl, LinkParamNone*, void); DECL_LINK(ModifyHdl, LinkParamNone*, void);
}; };
//= SpinCellController //= SpinCellController
class UNLESS_MERGELIBS(SVT_DLLPUBLIC) SpinCellController final : public CellController class UNLESS_MERGELIBS(SVT_DLLPUBLIC) SpinCellController final : public CellController
{ {
public: public:
@@ -440,9 +449,7 @@ namespace svt
DECL_LINK(ModifyHdl, Edit&, void); DECL_LINK(ModifyHdl, Edit&, void);
}; };
//= CheckBoxControl //= CheckBoxControl
class SVT_DLLPUBLIC CheckBoxControl final : public Control class SVT_DLLPUBLIC CheckBoxControl final : public Control
{ {
VclPtr<CheckBox> pBox; VclPtr<CheckBox> pBox;
@@ -489,19 +496,12 @@ namespace svt
}; };
//= ComboBoxControl //= ComboBoxControl
class SVT_DLLPUBLIC ComboBoxControl final : public InterimItemWindow class SVT_DLLPUBLIC ComboBoxControl final : public ControlBase
{ {
friend class ComboBoxCellController; friend class ComboBoxCellController;
public: public:
ComboBoxControl(vcl::Window* pParent); ComboBoxControl(BrowserDataWin* pParent);
virtual void GetFocus() override
{
if (m_xWidget)
m_xWidget->grab_focus();
InterimItemWindow::GetFocus();
}
weld::ComboBox& get_widget() { return *m_xWidget; } weld::ComboBox& get_widget() { return *m_xWidget; }
@@ -529,19 +529,12 @@ namespace svt
}; };
//= ListBoxControl //= ListBoxControl
class SVT_DLLPUBLIC ListBoxControl final : public InterimItemWindow class SVT_DLLPUBLIC ListBoxControl final : public ControlBase
{ {
friend class ListBoxCellController; friend class ListBoxCellController;
public: public:
ListBoxControl(vcl::Window* pParent); ListBoxControl(BrowserDataWin* pParent);
virtual void GetFocus() override
{
if (m_xWidget)
m_xWidget->grab_focus();
InterimItemWindow::GetFocus();
}
weld::ComboBox& get_widget() { return *m_xWidget; } weld::ComboBox& get_widget() { return *m_xWidget; }
@@ -567,30 +560,43 @@ namespace svt
DECL_LINK(ListBoxSelectHdl, weld::ComboBox&, void); DECL_LINK(ListBoxSelectHdl, weld::ComboBox&, void);
}; };
class SVT_DLLPUBLIC FormattedControl : public EditControlBase class SVT_DLLPUBLIC FormattedControlBase : public EditControlBase
{ {
public: public:
FormattedControl(BrowserDataWin* pParent); FormattedControlBase(BrowserDataWin* pParent, bool bSpinVariant);
virtual void dispose() override; virtual void dispose() override;
virtual void connect_changed(const Link<weld::Entry&, void>& rLink) override virtual void connect_changed(const Link<weld::Entry&, void>& rLink) override;
{
m_xEntryFormatter->connect_changed(rLink);
}
weld::EntryFormatter& get_formatter() { return *m_xEntryFormatter; } weld::EntryFormatter& get_formatter();
private: protected:
bool m_bSpinVariant;
std::unique_ptr<weld::Entry> m_xEntry; std::unique_ptr<weld::Entry> m_xEntry;
std::unique_ptr<weld::FormattedSpinButton> m_xSpinButton;
std::unique_ptr<weld::EntryFormatter> m_xEntryFormatter; std::unique_ptr<weld::EntryFormatter> m_xEntryFormatter;
void InitFormattedControlBase();
};
class SVT_DLLPUBLIC FormattedControl : public FormattedControlBase
{
public:
FormattedControl(BrowserDataWin* pParent, bool bSpinVariant);
};
class SVT_DLLPUBLIC DoubleNumericControl : public FormattedControlBase
{
public:
DoubleNumericControl(BrowserDataWin* pParent, bool bSpinVariant);
}; };
//= FormattedFieldCellController //= FormattedFieldCellController
class SVT_DLLPUBLIC FormattedFieldCellController final : public EditCellController class SVT_DLLPUBLIC FormattedFieldCellController final : public EditCellController
{ {
public: public:
FormattedFieldCellController( FormattedControl* _pFormatted ); FormattedFieldCellController( FormattedControlBase* _pFormatted );
virtual void CommitModifications() override; virtual void CommitModifications() override;
}; };
@@ -827,6 +833,8 @@ namespace svt
SVT_DLLPRIVATE void implActivateCellOnMouseEvent(const BrowserMouseEvent& _rEvt, bool _bUp); SVT_DLLPRIVATE void implActivateCellOnMouseEvent(const BrowserMouseEvent& _rEvt, bool _bUp);
bool ControlHasFocus() const;
DECL_DLLPRIVATE_LINK( ModifyHdl, LinkParamNone*, void ); DECL_DLLPRIVATE_LINK( ModifyHdl, LinkParamNone*, void );
DECL_DLLPRIVATE_LINK( StartEditHdl, void*, void ); DECL_DLLPRIVATE_LINK( StartEditHdl, void*, void );
DECL_DLLPRIVATE_LINK( EndEditHdl, void*, void ); DECL_DLLPRIVATE_LINK( EndEditHdl, void*, void );

View File

@@ -27,3 +27,4 @@ svtools/uiconfig/ui/restartdialog.ui://GtkLabel[@id='reason_skia'] orphan-label
svtools/uiconfig/ui/restartdialog.ui://GtkLabel[@id='label'] orphan-label svtools/uiconfig/ui/restartdialog.ui://GtkLabel[@id='label'] orphan-label
svtools/uiconfig/ui/spinfieldcontrol.ui://GtkSpinButton[@id='spinbutton'] no-labelled-by svtools/uiconfig/ui/spinfieldcontrol.ui://GtkSpinButton[@id='spinbutton'] no-labelled-by
svtools/uiconfig/ui/thineditcontrol.ui://GtkEntry[@id='entry'] no-labelled-by svtools/uiconfig/ui/thineditcontrol.ui://GtkEntry[@id='entry'] no-labelled-by
svtools/uiconfig/ui/thineditcontrol.ui://GtkSpinButton[@id='spinbutton'] no-labelled-by

View File

@@ -26,17 +26,18 @@ namespace svt
{ {
//= ComboBoxControl //= ComboBoxControl
ComboBoxControl::ComboBoxControl(vcl::Window* pParent) ComboBoxControl::ComboBoxControl(BrowserDataWin* pParent)
: InterimItemWindow(pParent, "svt/ui/combocontrol.ui", "ComboControl") : ControlBase(pParent, "svt/ui/combocontrol.ui", "ComboControl")
, m_xWidget(m_xBuilder->weld_combo_box("combobox")) , m_xWidget(m_xBuilder->weld_combo_box("combobox"))
{ {
InitControlBase(m_xWidget.get());
m_xWidget->set_entry_width_chars(1); // so a smaller than default width can be used m_xWidget->set_entry_width_chars(1); // so a smaller than default width can be used
} }
void ComboBoxControl::dispose() void ComboBoxControl::dispose()
{ {
m_xWidget.reset(); m_xWidget.reset();
InterimItemWindow::dispose(); ControlBase::dispose();
} }
//= ComboBoxCellController //= ComboBoxCellController
@@ -103,17 +104,18 @@ namespace svt
} }
//= ListBoxControl //= ListBoxControl
ListBoxControl::ListBoxControl(vcl::Window* pParent) ListBoxControl::ListBoxControl(BrowserDataWin* pParent)
: InterimItemWindow(pParent, "svt/ui/listcontrol.ui", "ListControl") : ControlBase(pParent, "svt/ui/listcontrol.ui", "ListControl")
, m_xWidget(m_xBuilder->weld_combo_box("listbox")) , m_xWidget(m_xBuilder->weld_combo_box("listbox"))
{ {
InitControlBase(m_xWidget.get());
m_xWidget->set_size_request(42, -1); // so a later narrow size request can stick m_xWidget->set_size_request(42, -1); // so a later narrow size request can stick
} }
void ListBoxControl::dispose() void ListBoxControl::dispose()
{ {
m_xWidget.reset(); m_xWidget.reset();
InterimItemWindow::dispose(); ControlBase::dispose();
} }
//= ListBoxCellController //= ListBoxCellController
@@ -345,34 +347,66 @@ namespace svt
m_aModifyHdl.Call(nullptr); m_aModifyHdl.Call(nullptr);
} }
EditControlBase::EditControlBase(BrowserDataWin* pParent) ControlBase::ControlBase(BrowserDataWin* pParent, const OUString& rUIXMLDescription, const OString& rID)
: InterimItemWindow(pParent, "svt/ui/thineditcontrol.ui", "EditControl") // *thin*editcontrol has no frame/border : InterimItemWindow(pParent, rUIXMLDescription, rID)
{ {
} }
void EditControlBase::init(weld::Entry* pEntry) bool ControlBase::ControlHasFocus() const
{ {
if (!m_pWidget)
return false;
return m_pWidget->has_focus();
}
void ControlBase::dispose()
{
m_pWidget = nullptr;
InterimItemWindow::dispose();
}
void ControlBase::GetFocus()
{
if (m_pWidget)
m_pWidget->grab_focus();
InterimItemWindow::GetFocus();
}
void ControlBase::InitControlBase(weld::Widget* pWidget)
{
m_pWidget = pWidget;
}
EditControlBase::EditControlBase(BrowserDataWin* pParent)
: ControlBase(pParent, "svt/ui/thineditcontrol.ui", "EditControl") // *thin*editcontrol has no frame/border
{
}
void EditControlBase::InitEditControlBase(weld::Entry* pEntry)
{
InitControlBase(pEntry);
m_pEntry = pEntry; m_pEntry = pEntry;
m_pEntry->show();
m_pEntry->set_width_chars(1); // so a smaller than default width can be used m_pEntry->set_width_chars(1); // so a smaller than default width can be used
m_pEntry->connect_key_press(LINK(this, EditControl, KeyInputHdl)); m_pEntry->connect_key_press(LINK(this, EditControl, KeyInputHdl));
} }
IMPL_LINK(EditControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool) IMPL_LINK(EditControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{ {
return ChildKeyInput(rKEvt); return static_cast<BrowserDataWin*>(GetParent())->GetParent()->ProcessKey(rKEvt);
} }
void EditControlBase::dispose() void EditControlBase::dispose()
{ {
m_pEntry = nullptr; m_pEntry = nullptr;
InterimItemWindow::dispose(); ControlBase::dispose();
} }
EditControl::EditControl(BrowserDataWin* pParent) EditControl::EditControl(BrowserDataWin* pParent)
: EditControlBase(pParent) : EditControlBase(pParent)
, m_xWidget(m_xBuilder->weld_entry("entry")) , m_xWidget(m_xBuilder->weld_entry("entry"))
{ {
init(m_xWidget.get()); InitEditControlBase(m_xWidget.get());
} }
void EditControl::dispose() void EditControl::dispose()
@@ -381,21 +415,62 @@ namespace svt
EditControlBase::dispose(); EditControlBase::dispose();
} }
FormattedControl::FormattedControl(BrowserDataWin* pParent) FormattedControlBase::FormattedControlBase(BrowserDataWin* pParent, bool bSpinVariant)
: EditControlBase(pParent) : EditControlBase(pParent)
, m_bSpinVariant(bSpinVariant)
, m_xEntry(m_xBuilder->weld_entry("entry")) , m_xEntry(m_xBuilder->weld_entry("entry"))
, m_xEntryFormatter(new weld::EntryFormatter(*m_xEntry)) , m_xSpinButton(m_xBuilder->weld_formatted_spin_button("spinbutton"))
{ {
init(m_xEntry.get());
} }
void FormattedControl::dispose() void FormattedControlBase::InitFormattedControlBase()
{
if (m_bSpinVariant)
m_xSpinButton->SetFormatter(m_xEntryFormatter.release());
InitEditControlBase(m_bSpinVariant ? m_xSpinButton.get() : m_xEntry.get());
}
void FormattedControlBase::connect_changed(const Link<weld::Entry&, void>& rLink)
{
get_formatter().connect_changed(rLink);
}
weld::EntryFormatter& FormattedControlBase::get_formatter()
{
if (m_bSpinVariant)
return static_cast<weld::EntryFormatter&>(m_xSpinButton->GetFormatter());
else
return *m_xEntryFormatter;
}
void FormattedControlBase::dispose()
{ {
m_xEntryFormatter.reset(); m_xEntryFormatter.reset();
m_xSpinButton.reset();
m_xEntry.reset(); m_xEntry.reset();
EditControlBase::dispose(); EditControlBase::dispose();
} }
FormattedControl::FormattedControl(BrowserDataWin* pParent, bool bSpinVariant)
: FormattedControlBase(pParent, bSpinVariant)
{
if (bSpinVariant)
m_xEntryFormatter.reset(new weld::EntryFormatter(*m_xSpinButton));
else
m_xEntryFormatter.reset(new weld::EntryFormatter(*m_xEntry));
InitFormattedControlBase();
}
DoubleNumericControl::DoubleNumericControl(BrowserDataWin* pParent, bool bSpinVariant)
: FormattedControlBase(pParent, bSpinVariant)
{
if (bSpinVariant)
m_xEntryFormatter.reset(new weld::DoubleNumericEntry(*m_xSpinButton));
else
m_xEntryFormatter.reset(new weld::DoubleNumericEntry(*m_xEntry));
InitFormattedControlBase();
}
EditCellController::EditCellController(EditControlBase* pEdit) EditCellController::EditCellController(EditControlBase* pEdit)
: CellController(pEdit) : CellController(pEdit)
, m_pEditImplementation(new EntryImplementation(*pEdit)) , m_pEditImplementation(new EntryImplementation(*pEdit))
@@ -506,7 +581,7 @@ namespace svt
} }
//= FormattedFieldCellController //= FormattedFieldCellController
FormattedFieldCellController::FormattedFieldCellController( FormattedControl* _pFormatted ) FormattedFieldCellController::FormattedFieldCellController( FormattedControlBase* _pFormatted )
: EditCellController(_pFormatted) : EditCellController(_pFormatted)
{ {
} }

View File

@@ -210,7 +210,7 @@ namespace svt
if (IsEditing()) if (IsEditing())
{ {
EnableAndShow(); EnableAndShow();
if (!aController->GetWindow().HasFocus() && (m_pFocusWhileRequest.get() == Application::GetFocusWindow())) if (!ControlHasFocus() && (m_pFocusWhileRequest.get() == Application::GetFocusWindow()))
aController->GetWindow().GrabFocus(); aController->GetWindow().GrabFocus();
} }
} }
@@ -450,7 +450,6 @@ namespace svt
} }
} }
void EditBrowseBox::MouseButtonUp( const BrowserMouseEvent& rEvt ) void EditBrowseBox::MouseButtonUp( const BrowserMouseEvent& rEvt )
{ {
// absorb double clicks // absorb double clicks
@@ -466,6 +465,13 @@ namespace svt
implActivateCellOnMouseEvent(rEvt, true); implActivateCellOnMouseEvent(rEvt, true);
} }
bool EditBrowseBox::ControlHasFocus() const
{
Window* pControlWindow = aController ? &aController->GetWindow() : nullptr;
if (ControlBase* pControlBase = dynamic_cast<ControlBase*>(pControlWindow))
return pControlBase->ControlHasFocus();
return pControlWindow && pControlWindow->HasChildPathFocus();
}
void EditBrowseBox::implActivateCellOnMouseEvent(const BrowserMouseEvent& _rEvt, bool _bUp) void EditBrowseBox::implActivateCellOnMouseEvent(const BrowserMouseEvent& _rEvt, bool _bUp)
{ {
@@ -473,7 +479,7 @@ namespace svt
ActivateCell(); ActivateCell();
else if (IsEditing() && !aController->GetWindow().IsEnabled()) else if (IsEditing() && !aController->GetWindow().IsEnabled())
DeactivateCell(); DeactivateCell();
else if (IsEditing() && !aController->GetWindow().HasChildPathFocus()) else if (IsEditing() && !ControlHasFocus())
AsynchGetFocus(); AsynchGetFocus();
if (!(IsEditing() && aController->GetWindow().IsEnabled() && aController->WantMouseEvent())) if (!(IsEditing() && aController->GetWindow().IsEnabled() && aController->WantMouseEvent()))
@@ -652,7 +658,7 @@ namespace svt
{ {
if (rEvt.GetType() == MouseNotifyEvent::KEYINPUT) if (rEvt.GetType() == MouseNotifyEvent::KEYINPUT)
{ {
if ( (IsEditing() && Controller()->GetWindow().HasChildPathFocus()) if ( (IsEditing() && ControlHasFocus())
|| rEvt.GetWindow() == &GetDataWindow() || rEvt.GetWindow() == &GetDataWindow()
|| (!IsEditing() && HasChildPathFocus()) || (!IsEditing() && HasChildPathFocus())
) )

View File

@@ -124,7 +124,7 @@ void EditBrowseBox::GrabTableFocus()
void EditBrowseBox::DetermineFocus( const GetFocusFlags _nGetFocusFlags ) void EditBrowseBox::DetermineFocus( const GetFocusFlags _nGetFocusFlags )
{ {
bool bFocus = false; bool bFocus = ControlHasFocus();
for (vcl::Window* pWindow = Application::GetFocusWindow(); for (vcl::Window* pWindow = Application::GetFocusWindow();
pWindow && !bFocus; pWindow && !bFocus;
pWindow = pWindow->GetParent()) pWindow = pWindow->GetParent())

View File

@@ -6,11 +6,12 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child> <child>
<object class="GtkEntry" id="entry"> <object class="GtkEntry" id="entry">
<property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="has_frame">False</property> <property name="has_frame">False</property>
@@ -23,5 +24,17 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkSpinButton" id="spinbutton">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="has_frame">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object> </object>
</interface> </interface>

View File

@@ -57,7 +57,6 @@
#include <rtl/math.hxx> #include <rtl/math.hxx>
#include <svtools/calendar.hxx> #include <svtools/calendar.hxx>
#include <vcl/button.hxx> #include <vcl/button.hxx>
#include <vcl/fmtfield.hxx>
#include <svl/numuno.hxx> #include <svl/numuno.hxx>
#include <svl/zforlist.hxx> #include <svl/zforlist.hxx>
#include <svx/dialmgr.hxx> #include <svx/dialmgr.hxx>
@@ -917,13 +916,29 @@ namespace
{ {
void lcl_implAlign( vcl::Window* _pWindow, WinBits _nAlignmentBit ) void lcl_implAlign( vcl::Window* _pWindow, WinBits _nAlignmentBit )
{ {
if (EditControlBase* pControl = dynamic_cast<EditControlBase*>(_pWindow))
{
switch (_nAlignmentBit)
{
case WB_LEFT:
pControl->get_widget().set_alignment(TxtAlign::Left);
break;
case WB_CENTER:
pControl->get_widget().set_alignment(TxtAlign::Center);
break;
case WB_RIGHT:
pControl->get_widget().set_alignment(TxtAlign::Right);
break;
}
return;
}
WinBits nStyle = _pWindow->GetStyle(); WinBits nStyle = _pWindow->GetStyle();
nStyle &= ~(WB_LEFT | WB_RIGHT | WB_CENTER); nStyle &= ~(WB_LEFT | WB_RIGHT | WB_CENTER);
_pWindow->SetStyle( nStyle | _nAlignmentBit ); _pWindow->SetStyle( nStyle | _nAlignmentBit );
} }
} }
void DbCellControl::AlignControl(sal_Int16 nAlignment) void DbCellControl::AlignControl(sal_Int16 nAlignment)
{ {
WinBits nAlignmentBit = 0; WinBits nAlignmentBit = 0;
@@ -1247,8 +1262,8 @@ void DbFormattedField::Init( BrowserDataWin& rParent, const Reference< XRowSet >
Reference< css::beans::XPropertySet > xUnoModel = m_rColumn.getModel(); Reference< css::beans::XPropertySet > xUnoModel = m_rColumn.getModel();
auto xEditControl = VclPtr<FormattedControl>::Create(&rParent); auto xEditControl = VclPtr<FormattedControl>::Create(&rParent, false);
auto xEditPainter = VclPtr<FormattedControl>::Create(&rParent); auto xEditPainter = VclPtr<FormattedControl>::Create(&rParent, false);
weld::EntryFormatter& rControlFormatter = xEditControl->get_formatter(); weld::EntryFormatter& rControlFormatter = xEditControl->get_formatter();
weld::EntryFormatter& rPainterFormatter = xEditPainter->get_formatter(); weld::EntryFormatter& rPainterFormatter = xEditPainter->get_formatter();
@@ -1452,7 +1467,7 @@ void DbFormattedField::Init( BrowserDataWin& rParent, const Reference< XRowSet >
CellControllerRef DbFormattedField::CreateController() const CellControllerRef DbFormattedField::CreateController() const
{ {
return new ::svt::FormattedFieldCellController(static_cast<FormattedControl*>(m_pWindow.get())); return new ::svt::FormattedFieldCellController(static_cast<FormattedControlBase*>(m_pWindow.get()));
} }
void DbFormattedField::_propertyChanged( const PropertyChangeEvent& _rEvent ) void DbFormattedField::_propertyChanged( const PropertyChangeEvent& _rEvent )
@@ -1463,9 +1478,9 @@ void DbFormattedField::_propertyChanged( const PropertyChangeEvent& _rEvent )
DBG_ASSERT(m_pWindow && m_pPainter, "DbFormattedField::_propertyChanged : where are my windows ?"); DBG_ASSERT(m_pWindow && m_pPainter, "DbFormattedField::_propertyChanged : where are my windows ?");
if (m_pWindow) if (m_pWindow)
static_cast<FormattedControl*>(m_pWindow.get())->get_formatter().SetFormatKey(nNewKey); static_cast<FormattedControlBase*>(m_pWindow.get())->get_formatter().SetFormatKey(nNewKey);
if (m_pPainter) if (m_pPainter)
static_cast<FormattedControl*>(m_pPainter.get())->get_formatter().SetFormatKey(nNewKey); static_cast<FormattedControlBase*>(m_pPainter.get())->get_formatter().SetFormatKey(nNewKey);
} }
else else
{ {
@@ -1483,7 +1498,7 @@ OUString DbFormattedField::GetFormatText(const Reference< css::sdb::XColumn >& _
if (!_rxField.is()) if (!_rxField.is())
return OUString(); return OUString();
FormattedControl* pControl = static_cast<FormattedControl*>(m_pPainter.get()); FormattedControlBase* pControl = static_cast<FormattedControlBase*>(m_pPainter.get());
weld::EntryFormatter& rPainterFormatter = pControl->get_formatter(); weld::EntryFormatter& rPainterFormatter = pControl->get_formatter();
OUString aText; OUString aText;
@@ -1527,7 +1542,7 @@ void DbFormattedField::UpdateFromField(const Reference< css::sdb::XColumn >& _rx
{ {
try try
{ {
FormattedControl* pEditControl = static_cast<FormattedControl*>(m_pWindow.get()); FormattedControlBase* pEditControl = static_cast<FormattedControlBase*>(m_pWindow.get());
weld::Entry& rEntry = pEditControl->get_widget(); weld::Entry& rEntry = pEditControl->get_widget();
weld::EntryFormatter& rEditFormatter = pEditControl->get_formatter(); weld::EntryFormatter& rEditFormatter = pEditControl->get_formatter();
@@ -1569,7 +1584,7 @@ void DbFormattedField::updateFromModel( Reference< XPropertySet > _rxModel )
{ {
OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFormattedField::updateFromModel: invalid call!" ); OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFormattedField::updateFromModel: invalid call!" );
FormattedControl* pEditControl = static_cast<FormattedControl*>(m_pWindow.get()); FormattedControlBase* pEditControl = static_cast<FormattedControlBase*>(m_pWindow.get());
weld::Entry& rEntry = pEditControl->get_widget(); weld::Entry& rEntry = pEditControl->get_widget();
weld::EntryFormatter& rEditFormatter = pEditControl->get_formatter(); weld::EntryFormatter& rEditFormatter = pEditControl->get_formatter();
@@ -1593,7 +1608,7 @@ bool DbFormattedField::commitControl()
{ {
Any aNewVal; Any aNewVal;
FormattedControl* pEditControl = static_cast<FormattedControl*>(m_pWindow.get()); FormattedControlBase* pEditControl = static_cast<FormattedControlBase*>(m_pWindow.get());
weld::Entry& rEntry = pEditControl->get_widget(); weld::Entry& rEntry = pEditControl->get_widget();
weld::EntryFormatter& rEditFormatter = pEditControl->get_formatter(); weld::EntryFormatter& rEditFormatter = pEditControl->get_formatter();
@@ -1883,6 +1898,10 @@ DbNumericField::DbNumericField( DbGridColumn& _rColumn )
doPropertyListening( FM_PROP_SHOWTHOUSANDSEP ); doPropertyListening( FM_PROP_SHOWTHOUSANDSEP );
} }
CellControllerRef DbNumericField::CreateController() const
{
return new ::svt::FormattedFieldCellController(static_cast<FormattedControlBase*>(m_pWindow.get()));
}
void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel ) void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
{ {
@@ -1898,13 +1917,13 @@ void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySe
sal_Int16 nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) ); sal_Int16 nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) );
bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) ); bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) );
Formatter& rEditFormatter = static_cast<DoubleNumericField*>(m_pWindow.get())->GetFormatter(); Formatter& rEditFormatter = static_cast<FormattedControlBase*>(m_pWindow.get())->get_formatter();
rEditFormatter.SetMinValue(nMin); rEditFormatter.SetMinValue(nMin);
rEditFormatter.SetMaxValue(nMax); rEditFormatter.SetMaxValue(nMax);
rEditFormatter.SetSpinSize(nStep); rEditFormatter.SetSpinSize(nStep);
rEditFormatter.SetStrictFormat(bStrict); rEditFormatter.SetStrictFormat(bStrict);
Formatter& rPaintFormatter = static_cast<DoubleNumericField*>(m_pPainter.get())->GetFormatter(); Formatter& rPaintFormatter = static_cast<FormattedControlBase*>(m_pPainter.get())->get_formatter();
rPaintFormatter.SetMinValue(nMin); rPaintFormatter.SetMinValue(nMin);
rPaintFormatter.SetMaxValue(nMax); rPaintFormatter.SetMaxValue(nMax);
rPaintFormatter.SetStrictFormat(bStrict); rPaintFormatter.SetStrictFormat(bStrict);
@@ -1939,16 +1958,15 @@ void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySe
rPaintFormatter.SetFormat( sFormatString, aAppLanguage ); rPaintFormatter.SetFormat( sFormatString, aAppLanguage );
} }
VclPtr<Control> DbNumericField::createField(BrowserDataWin* _pParent, bool bSpinButton, const Reference< XPropertySet >& /*_rxModel*/) VclPtr<Control> DbNumericField::createField(BrowserDataWin* pParent, bool bSpinButton, const Reference<XPropertySet>& /*rxModel*/)
{ {
WinBits _nFieldStyle = bSpinButton ? (WB_REPEAT | WB_SPIN) : 0; return VclPtr<DoubleNumericControl>::Create(pParent, bSpinButton);
return VclPtr<DoubleNumericField>::Create( _pParent, _nFieldStyle );
} }
namespace namespace
{ {
OUString lcl_setFormattedNumeric_nothrow( DoubleNumericField& _rField, const DbCellControl& _rControl, OUString lcl_setFormattedNumeric_nothrow( FormattedControlBase& _rField, const DbCellControl& _rControl,
const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter ) const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
{ {
OUString sValue; OUString sValue;
@@ -1959,8 +1977,8 @@ namespace
double fValue = _rControl.GetValue( _rxField, _rxFormatter ); double fValue = _rControl.GetValue( _rxField, _rxFormatter );
if ( !_rxField->wasNull() ) if ( !_rxField->wasNull() )
{ {
_rField.GetFormatter().SetValue( fValue ); _rField.get_formatter().SetValue(fValue);
sValue = _rField.GetText(); sValue = _rField.get_widget().get_text();
} }
} }
catch( const Exception& ) catch( const Exception& )
@@ -1974,36 +1992,39 @@ namespace
OUString DbNumericField::GetFormatText(const Reference< css::sdb::XColumn >& _rxField, const Reference< css::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/) OUString DbNumericField::GetFormatText(const Reference< css::sdb::XColumn >& _rxField, const Reference< css::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/)
{ {
return lcl_setFormattedNumeric_nothrow(dynamic_cast<DoubleNumericField&>(*m_pPainter), *this, _rxField, _rxFormatter); return lcl_setFormattedNumeric_nothrow(dynamic_cast<FormattedControlBase&>(*m_pPainter), *this, _rxField, _rxFormatter);
} }
void DbNumericField::UpdateFromField(const Reference< css::sdb::XColumn >& _rxField, const Reference< css::util::XNumberFormatter >& _rxFormatter) void DbNumericField::UpdateFromField(const Reference< css::sdb::XColumn >& _rxField, const Reference< css::util::XNumberFormatter >& _rxFormatter)
{ {
lcl_setFormattedNumeric_nothrow(dynamic_cast<DoubleNumericField&>(*m_pWindow), *this, _rxField, _rxFormatter); lcl_setFormattedNumeric_nothrow(dynamic_cast<FormattedControlBase&>(*m_pWindow), *this, _rxField, _rxFormatter);
} }
void DbNumericField::updateFromModel( Reference< XPropertySet > _rxModel ) void DbNumericField::updateFromModel( Reference< XPropertySet > _rxModel )
{ {
OSL_ENSURE( _rxModel.is() && m_pWindow, "DbNumericField::updateFromModel: invalid call!" ); OSL_ENSURE( _rxModel.is() && m_pWindow, "DbNumericField::updateFromModel: invalid call!" );
FormattedControlBase* pControl = static_cast<FormattedControlBase*>(m_pWindow.get());
double dValue = 0; double dValue = 0;
if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue ) if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue )
{ {
Formatter& rFormatter = static_cast<DoubleNumericField*>(m_pWindow.get())->GetFormatter(); Formatter& rFormatter = pControl->get_formatter();
rFormatter.SetValue(dValue); rFormatter.SetValue(dValue);
} }
else else
m_pWindow->SetText( OUString() ); pControl->get_widget().set_text(OUString());
} }
bool DbNumericField::commitControl() bool DbNumericField::commitControl()
{ {
OUString aText( m_pWindow->GetText()); FormattedControlBase* pControl = static_cast<FormattedControlBase*>(m_pWindow.get());
OUString aText(pControl->get_widget().get_text());
Any aVal; Any aVal;
if (!aText.isEmpty()) // not empty if (!aText.isEmpty()) // not empty
{ {
Formatter& rFormatter = static_cast<DoubleNumericField*>(m_pWindow.get())->GetFormatter(); Formatter& rFormatter = pControl->get_formatter();
double fValue = rFormatter.GetValue(); double fValue = rFormatter.GetValue();
aVal <<= fValue; aVal <<= fValue;
} }

View File

@@ -628,11 +628,13 @@ protected:
virtual void implAdjustGenericFieldSetting( const css::uno::Reference< css::beans::XPropertySet >& _rxModel ) override; virtual void implAdjustGenericFieldSetting( const css::uno::Reference< css::beans::XPropertySet >& _rxModel ) override;
}; };
class DbNumericField : public DbSpinField class DbNumericField : public DbSpinField
{ {
public: public:
DbNumericField(DbGridColumn& _rColumn); DbNumericField(DbGridColumn& _rColumn);
virtual ::svt::CellControllerRef CreateController() const override;
virtual OUString GetFormatText(const css::uno::Reference< css::sdb::XColumn >& _rxField, const css::uno::Reference< css::util::XNumberFormatter >& xFormatter, Color** ppColor = nullptr) override; virtual OUString GetFormatText(const css::uno::Reference< css::sdb::XColumn >& _rxField, const css::uno::Reference< css::util::XNumberFormatter >& xFormatter, Color** ppColor = nullptr) override;
virtual void UpdateFromField(const css::uno::Reference< css::sdb::XColumn >& _rxField, const css::uno::Reference< css::util::XNumberFormatter >& xFormatter) override; virtual void UpdateFromField(const css::uno::Reference< css::sdb::XColumn >& _rxField, const css::uno::Reference< css::util::XNumberFormatter >& xFormatter) override;
@@ -652,7 +654,6 @@ protected:
void implAdjustGenericFieldSetting( const css::uno::Reference< css::beans::XPropertySet >& _rxModel ) override; void implAdjustGenericFieldSetting( const css::uno::Reference< css::beans::XPropertySet >& _rxModel ) override;
}; };
class DbFilterField final class DbFilterField final
:public DbCellControl :public DbCellControl
,public ::svxform::OSQLParserClient ,public ::svxform::OSQLParserClient

View File

@@ -3182,7 +3182,7 @@ void SalInstanceEntry::set_alignment(TxtAlign eXAlign)
} }
WinBits nBits = m_xEntry->GetStyle(); WinBits nBits = m_xEntry->GetStyle();
nBits &= ~(WB_LEFT | WB_CENTER | WB_RIGHT); nBits &= ~(WB_LEFT | WB_CENTER | WB_RIGHT);
m_xEntry->SetStyle(nBits & nAlign); m_xEntry->SetStyle(nBits | nAlign);
} }
SalInstanceEntry::~SalInstanceEntry() SalInstanceEntry::~SalInstanceEntry()