Skip to content

Commit

Permalink
weld ODateTimeDialog
Browse files Browse the repository at this point in the history
Change-Id: Id93147f1d442e1e5f1cfba8ef2f9e476f4f6d728
Reviewed-on: https://gerrit.libreoffice.org/54623
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
  • Loading branch information
Caolán McNamara committed May 21, 2018
1 parent 17ad732 commit 4da8aef
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 114 deletions.
143 changes: 60 additions & 83 deletions reportdesign/source/ui/dlg/DateTime.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,20 @@ using namespace ::comphelper;

// class ODateTimeDialog

ODateTimeDialog::ODateTimeDialog( vcl::Window* _pParent
,const uno::Reference< report::XSection >& _xHoldAlive
,OReportController* _pController)
: ModalDialog( _pParent, "DateTimeDialog" , "modules/dbreport/ui/datetimedialog.ui" )
ODateTimeDialog::ODateTimeDialog(weld::Window* _pParent, const uno::Reference< report::XSection >& _xHoldAlive,
OReportController* _pController)
: GenericDialogController(_pParent, "modules/dbreport/ui/datetimedialog.ui", "DateTimeDialog")

, m_aDateControlling()
, m_aTimeControlling()
, m_pController(_pController)
, m_xHoldAlive(_xHoldAlive)
, m_xDate(m_xBuilder->weld_check_button("date"))
, m_xFTDateFormat(m_xBuilder->weld_label("datelistbox_label"))
, m_xDateListBox(m_xBuilder->weld_combo_box_text("datelistbox"))
, m_xTime(m_xBuilder->weld_check_button("time"))
, m_xFTTimeFormat(m_xBuilder->weld_label("timelistbox_label"))
, m_xTimeListBox(m_xBuilder->weld_combo_box_text("timelistbox"))
, m_xPB_OK(m_xBuilder->weld_button("ok"))
{
get(m_pDate,"date");
get(m_pFTDateFormat,"datelistbox_label");
get(m_pDateListBox,"datelistbox");
get(m_pTime,"time");
get(m_pFTTimeFormat,"timelistbox_label");
get(m_pTimeListBox,"timelistbox");
get(m_pPB_OK,"ok");


try
{
SvtSysLocale aSysLocale;
Expand All @@ -71,60 +66,36 @@ ODateTimeDialog::ODateTimeDialog( vcl::Window* _pParent
{
}

m_pDateListBox->SelectEntryPos(0);

m_pTimeListBox->SelectEntryPos(0);

// use nice enhancement, to toggle enable/disable if a checkbox is checked or not
m_aDateControlling.enableOnCheckMark( *m_pDate, *m_pFTDateFormat, *m_pDateListBox);
m_aTimeControlling.enableOnCheckMark( *m_pTime, *m_pFTTimeFormat, *m_pTimeListBox);

CheckBox* aCheckBoxes[] = { m_pDate,m_pTime};
for (CheckBox* pCheckBox : aCheckBoxes)
pCheckBox->SetClickHdl(LINK(this,ODateTimeDialog,CBClickHdl));
m_xDateListBox->set_active(0);
m_xTimeListBox->set_active(0);

weld::CheckButton* aCheckBoxes[] = { m_xDate.get(), m_xTime.get() };
for (weld::CheckButton* pCheckBox : aCheckBoxes)
pCheckBox->connect_toggled(LINK(this,ODateTimeDialog,CBClickHdl));
}

void ODateTimeDialog::InsertEntry(sal_Int16 _nNumberFormatId)
void ODateTimeDialog::InsertEntry(sal_Int16 _nNumberFormatId)
{
const bool bTime = util::NumberFormat::TIME == _nNumberFormatId;
weld::ComboBoxText* pListBox = m_xDateListBox.get();
if (bTime)
pListBox = m_xTimeListBox.get();

const uno::Reference< util::XNumberFormatter> xNumberFormatter = m_pController->getReportNumberFormatter();
const uno::Reference< util::XNumberFormats> xFormats = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats();
const uno::Sequence<sal_Int32> aFormatKeys = xFormats->queryKeys(_nNumberFormatId,m_nLocale,true);
const sal_Int32* pIter = aFormatKeys.getConstArray();
const sal_Int32* pEnd = pIter + aFormatKeys.getLength();
for (;pIter != pEnd; ++pIter)
{
const bool bTime = util::NumberFormat::TIME == _nNumberFormatId;
ListBox* pListBox = m_pDateListBox;
if ( bTime )
pListBox = m_pTimeListBox;

const uno::Reference< util::XNumberFormatter> xNumberFormatter = m_pController->getReportNumberFormatter();
const uno::Reference< util::XNumberFormats> xFormats = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats();
const uno::Sequence<sal_Int32> aFormatKeys = xFormats->queryKeys(_nNumberFormatId,m_nLocale,true);
const sal_Int32* pIter = aFormatKeys.getConstArray();
const sal_Int32* pEnd = pIter + aFormatKeys.getLength();
for(;pIter != pEnd;++pIter)
{
const sal_Int16 nPos = pListBox->InsertEntry(getFormatStringByKey(*pIter,xFormats,bTime));
pListBox->SetEntryData(nPos, reinterpret_cast<void*>(*pIter));
}
pListBox->append(OUString::number(*pIter), getFormatStringByKey(*pIter,xFormats,bTime));
}

ODateTimeDialog::~ODateTimeDialog()
{
disposeOnce();
}

void ODateTimeDialog::dispose()
{
m_pDate.clear();
m_pFTDateFormat.clear();
m_pDateListBox.clear();
m_pTime.clear();
m_pFTTimeFormat.clear();
m_pTimeListBox.clear();
m_pPB_OK.clear();
ModalDialog::dispose();
}

short ODateTimeDialog::Execute()
short ODateTimeDialog::execute()
{
short nRet = ModalDialog::Execute();
if ( nRet == RET_OK && (m_pDate->IsChecked() || m_pTime->IsChecked()) )
short nRet = m_xDialog->run();
if (nRet == RET_OK && (m_xDate->get_active() || m_xTime->get_active()))
{
try
{
Expand All @@ -134,27 +105,30 @@ short ODateTimeDialog::Execute()
aValues[nLength++].Value <<= m_xHoldAlive;

aValues[nLength].Name = PROPERTY_TIME_STATE;
aValues[nLength++].Value <<= m_pTime->IsChecked();
aValues[nLength++].Value <<= m_xTime->get_active();

aValues[nLength].Name = PROPERTY_DATE_STATE;
aValues[nLength++].Value <<= m_pDate->IsChecked();
aValues[nLength++].Value <<= m_xDate->get_active();

aValues[nLength].Name = PROPERTY_FORMATKEYDATE;
aValues[nLength++].Value <<= getFormatKey(true);

aValues[nLength].Name = PROPERTY_FORMATKEYTIME;
aValues[nLength++].Value <<= getFormatKey(false);

OutputDevice* pDefDev = Application::GetDefaultDevice();
sal_Int32 nWidth = 0;
if ( m_pDate->IsChecked() )
if ( m_xDate->get_active() )
{
OUString sDateFormat = m_pDateListBox->GetSelectedEntry();
nWidth = LogicToLogic(PixelToLogic(Size(GetCtrlTextWidth(sDateFormat),0)).Width(),GetMapMode().GetMapUnit(),MapUnit::Map100thMM);
OUString sDateFormat = m_xDateListBox->get_active_text();
nWidth = OutputDevice::LogicToLogic(pDefDev->PixelToLogic(Size(pDefDev->GetCtrlTextWidth(sDateFormat),0)).Width(),
pDefDev->GetMapMode().GetMapUnit(),MapUnit::Map100thMM);
}
if ( m_pTime->IsChecked() )
if ( m_xTime->get_active() )
{
OUString sDateFormat = m_pTimeListBox->GetSelectedEntry();
nWidth = ::std::max<sal_Int32>(LogicToLogic(PixelToLogic(Size(GetCtrlTextWidth(sDateFormat),0)).Width(),GetMapMode().GetMapUnit(),MapUnit::Map100thMM),nWidth);
OUString sDateFormat = m_xTimeListBox->get_active_text();
nWidth = ::std::max<sal_Int32>(OutputDevice::LogicToLogic(pDefDev->PixelToLogic(Size(pDefDev->GetCtrlTextWidth(sDateFormat),0)).Width(),
pDefDev->GetMapMode().GetMapUnit(),MapUnit::Map100thMM),nWidth);
}

if ( nWidth > 4000 )
Expand Down Expand Up @@ -198,20 +172,23 @@ OUString ODateTimeDialog::getFormatStringByKey(::sal_Int32 _nNumberFormatKey,con
return xPreviewer->convertNumberToPreviewString(sFormat,nValue,m_nLocale,true);
}

IMPL_LINK( ODateTimeDialog, CBClickHdl, Button*, _pBox, void )
IMPL_LINK_NOARG(ODateTimeDialog, CBClickHdl, weld::ToggleButton&, void)
{
if ( _pBox == m_pDate || _pBox == m_pTime)
const bool bDate = m_xDate->get_active();
m_xFTDateFormat->set_sensitive(bDate);
m_xDateListBox->set_sensitive(bDate);

const bool bTime = m_xTime->get_active();
m_xFTTimeFormat->set_sensitive(bTime);
m_xTimeListBox->set_sensitive(bTime);

if (!bDate && !bTime)
{
bool bDate = m_pDate->IsChecked();
bool bTime = m_pTime->IsChecked();
if (!bDate && !bTime)
{
m_pPB_OK->Disable();
}
else
{
m_pPB_OK->Enable();
}
m_xPB_OK->set_sensitive(false);
}
else
{
m_xPB_OK->set_sensitive(true);
}
}

Expand All @@ -220,11 +197,11 @@ sal_Int32 ODateTimeDialog::getFormatKey(bool _bDate) const
sal_Int32 nFormatKey;
if ( _bDate )
{
nFormatKey = static_cast<sal_Int32>(reinterpret_cast<sal_IntPtr>(m_pDateListBox->GetSelectedEntryData()));
nFormatKey = m_xDateListBox->get_active_id().toInt32();
}
else
{
nFormatKey = static_cast<sal_Int32>(reinterpret_cast<sal_IntPtr>(m_pTimeListBox->GetSelectedEntryData()));
nFormatKey = m_xTimeListBox->get_active_id().toInt32();
}
return nFormatKey;
}
Expand Down
39 changes: 15 additions & 24 deletions reportdesign/source/ui/inc/DateTime.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#ifndef INCLUDED_REPORTDESIGN_SOURCE_UI_INC_DATETIME_HXX
#define INCLUDED_REPORTDESIGN_SOURCE_UI_INC_DATETIME_HXX

#include <vcl/dialog.hxx>
#include <vcl/fixed.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/field.hxx>
#include <vcl/button.hxx>
#include <vcl/weld.hxx>
#include <com/sun/star/report/XSection.hpp>
#include <com/sun/star/util/XNumberFormats.hpp>
#include <com/sun/star/lang/Locale.hpp>
Expand All @@ -38,24 +34,21 @@ class OReportController;
|* Groups and Sorting dialog
|*
\************************************************************************/
class ODateTimeDialog : public ModalDialog
class ODateTimeDialog : public weld::GenericDialogController
{
VclPtr<CheckBox> m_pDate;
VclPtr<FixedText> m_pFTDateFormat;
VclPtr<ListBox> m_pDateListBox;
VclPtr<CheckBox> m_pTime;
VclPtr<FixedText> m_pFTTimeFormat;
VclPtr<ListBox> m_pTimeListBox;
VclPtr<OKButton> m_pPB_OK;

svt::ControlDependencyManager m_aDateControlling;
svt::ControlDependencyManager m_aTimeControlling;

::rptui::OReportController* m_pController;
css::uno::Reference< css::report::XSection>
m_xHoldAlive;
css::lang::Locale m_nLocale;

std::unique_ptr<weld::CheckButton> m_xDate;
std::unique_ptr<weld::Label> m_xFTDateFormat;
std::unique_ptr<weld::ComboBoxText> m_xDateListBox;
std::unique_ptr<weld::CheckButton> m_xTime;
std::unique_ptr<weld::Label> m_xFTTimeFormat;
std::unique_ptr<weld::ComboBoxText> m_xTimeListBox;
std::unique_ptr<weld::Button> m_xPB_OK;

/** returns the format string
*
* \param _nNumberFormatKey the number format key
Expand All @@ -70,19 +63,17 @@ class ODateTimeDialog : public ModalDialog
*/
sal_Int32 getFormatKey(bool _bDate) const;

DECL_LINK( CBClickHdl, Button*, void );
DECL_LINK(CBClickHdl, weld::ToggleButton&, void);
ODateTimeDialog(const ODateTimeDialog&) = delete;
void operator =(const ODateTimeDialog&) = delete;

// fill methods
void InsertEntry(sal_Int16 _nNumberFormatId);
public:
ODateTimeDialog( vcl::Window* pParent
,const css::uno::Reference< css::report::XSection>& _xHoldAlive
,::rptui::OReportController* _pController);
virtual ~ODateTimeDialog() override;
virtual void dispose() override;
virtual short Execute() override;
ODateTimeDialog(weld::Window* pParent,
const css::uno::Reference< css::report::XSection>& _xHoldAlive,
::rptui::OReportController* _pController);
short execute();
};

} // namespace rptui
Expand Down
4 changes: 2 additions & 2 deletions reportdesign/source/ui/report/ReportController.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,8 @@ void OReportController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >
{
if ( !aArgs.getLength() )
{
ScopedVclPtrInstance< ODateTimeDialog > aDlg(getView(),getDesignView()->getCurrentSection(),this);
aDlg->Execute();
ODateTimeDialog aDlg(getFrameWeld(), getDesignView()->getCurrentSection(), this);
aDlg.execute();
}
else
createDateTime(aArgs);
Expand Down
16 changes: 11 additions & 5 deletions reportdesign/uiconfig/dbreport/ui/datetimedialog.ui
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.22.1 -->
<interface domain="rpt">
<requires lib="gtk+" version="3.18"/>
<object class="GtkDialog" id="DateTimeDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes" context="datetimedialog|DateTimeDialog">Date and Time</property>
<property name="modal">True</property>
<property name="default_width">0</property>
<property name="default_height">0</property>
<property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
Expand Down Expand Up @@ -104,10 +110,10 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="datetimedialog|datelistbox_label">_Format:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">datelistbox</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
Expand Down Expand Up @@ -136,18 +142,18 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="datetimedialog|timelistbox_label">Fo_rmat:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">timelistbox</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="timelistbox">
<object class="GtkComboBoxText" id="timelistbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
Expand All @@ -158,7 +164,7 @@
</packing>
</child>
<child>
<object class="GtkComboBox" id="datelistbox">
<object class="GtkComboBoxText" id="datelistbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
Expand Down

0 comments on commit 4da8aef

Please sign in to comment.