diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-04-04 16:19:06 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-04-05 20:24:51 +0100 |
commit | 92d43df81e282d20c129b105b2c7300a312091eb (patch) | |
tree | 2163a30e7ac2defdabc0214fc0aeba7f351669c9 /svx/source/sidebar/line/LineWidthPopup.cxx | |
parent | 3c36ba50f65d663f35264f2a11c99c0ff98674a2 (diff) |
convert src line width popup to .ui format
Change-Id: I39e8bfd89538c36c97afb3e4e86c3ba9156274e0
Diffstat (limited to 'svx/source/sidebar/line/LineWidthPopup.cxx')
-rw-r--r-- | svx/source/sidebar/line/LineWidthPopup.cxx | 229 |
1 files changed, 204 insertions, 25 deletions
diff --git a/svx/source/sidebar/line/LineWidthPopup.cxx b/svx/source/sidebar/line/LineWidthPopup.cxx index 02cc9022fdab..9112eb8d0473 100644 --- a/svx/source/sidebar/line/LineWidthPopup.cxx +++ b/svx/source/sidebar/line/LineWidthPopup.cxx @@ -17,52 +17,231 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include <svx/sidebar/LineWidthPopup.hxx> -#include "LineWidthControl.hxx" - #include <svx/sidebar/LinePropertyPanelBase.hxx> - +#include <svx/dialmgr.hxx> +#include <svx/dialogs.hrc> +#include <svx/xlnwtit.hxx> #include <unotools/viewoptions.hxx> - +#include <vcl/svapp.hxx> +#include "LineWidthValueSet.hxx" namespace svx { namespace sidebar { -LineWidthPopup::LineWidthPopup ( - vcl::Window* pParent, - const ::std::function<PopupControl*(PopupContainer*)>& rControlCreator) - : Popup( - pParent, - rControlCreator, - OUString( "Width")) +LineWidthPopup::LineWidthPopup(LinePropertyPanelBase& rParent) + : FloatingWindow(&rParent, "FloatingLineProperty", "svx/ui/floatinglineproperty.ui") + , m_rParent(rParent) + , m_pStr(nullptr) + , m_sPt(SVX_RESSTR(RID_SVXSTR_PT)) + , m_eMapUnit(SFX_MAPUNIT_TWIP) + , m_bVSFocus(true) + , m_bCustom(false) + , m_bCloseByEdit(false) + , m_nCustomWidth(0) + , m_nTmpCustomWidth(0) + , m_aIMGCus(SVX_RES(RID_SVXIMG_WIDTH_CUSTOM)) + , m_aIMGCusGray(SVX_RES(RID_SVXIMG_WIDTH_CUSTOM_GRAY)) { - SetPopupModeEndHandler([this] () { return this->PopupModeEndCallback(); }); + get(m_xMFWidth, "spin"); + + get(m_xBox, "box"); + + m_xVSWidth = VclPtr<LineWidthValueSet>::Create(m_xBox); + + m_xVSWidth->SetStyle(m_xVSWidth->GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT); + + m_pStr = new OUString[9]; + + m_pStr[0] = "0.5"; + m_pStr[1] = "0.8"; + m_pStr[2] = "1.0"; + m_pStr[3] = "1.5"; + m_pStr[4] = "2.3"; + m_pStr[5] = "3.0"; + m_pStr[6] = "4.5"; + m_pStr[7] = "6.0"; + m_pStr[8] = SVX_RESSTR(RID_SVXSTR_WIDTH_LAST_CUSTOM); + + const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() ); + const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0]; + + for(int i = 0; i <= 7 ; i++) + { + m_pStr[i] = m_pStr[i].replace('.', cSep);//Modify + m_pStr[i] += " "; + m_pStr[i] += m_sPt; + } + + for (sal_uInt16 i = 1 ; i <= 9; ++i) + { + m_xVSWidth->InsertItem(i); + m_xVSWidth->SetItemText(i, m_pStr[i-1]); + } + + m_xVSWidth->SetUnit(m_pStr); + m_xVSWidth->SetItemData(1, reinterpret_cast<void*>(5)); + m_xVSWidth->SetItemData(2, reinterpret_cast<void*>(8)); + m_xVSWidth->SetItemData(3, reinterpret_cast<void*>(10)); + m_xVSWidth->SetItemData(4, reinterpret_cast<void*>(15)); + m_xVSWidth->SetItemData(5, reinterpret_cast<void*>(23)); + m_xVSWidth->SetItemData(6, reinterpret_cast<void*>(30)); + m_xVSWidth->SetItemData(7, reinterpret_cast<void*>(45)); + m_xVSWidth->SetItemData(8, reinterpret_cast<void*>(60)); + m_xVSWidth->SetImage(m_aIMGCusGray); + + m_xVSWidth->SetSelItem(0); + + m_xVSWidth->SetSelectHdl(LINK(this, LineWidthPopup, VSSelectHdl)); + m_xMFWidth->SetModifyHdl(LINK(this, LineWidthPopup, MFModifyHdl)); + + m_xVSWidth->StartSelection(); + m_xVSWidth->Show(); +} + +void LineWidthPopup::dispose() +{ + delete[] m_pStr; + m_xVSWidth.disposeAndClear(); + m_xBox.clear(); + m_xMFWidth.clear(); + FloatingWindow::dispose(); } LineWidthPopup::~LineWidthPopup() { + disposeOnce(); } -void LineWidthPopup::SetWidthSelect (long lValue, bool bValuable, SfxMapUnit eMapUnit) +IMPL_LINK_TYPED(LineWidthPopup, VSSelectHdl, ValueSet*, /*pControl*/, void) { - ProvideContainerAndControl(); + sal_uInt16 iPos = m_xVSWidth->GetSelectItemId(); + if (iPos >= 1 && iPos <= 8) + { + sal_IntPtr nVal = LogicToLogic(reinterpret_cast<sal_IntPtr>(m_xVSWidth->GetItemData( iPos )), MAP_POINT, (MapUnit)m_eMapUnit); + nVal = m_xMFWidth->Denormalize(nVal); + XLineWidthItem aWidthItem( nVal ); + m_rParent.setLineWidth(aWidthItem); + m_rParent.SetWidthIcon(iPos); + m_rParent.SetWidth(nVal); + m_bCloseByEdit = false; + m_nTmpCustomWidth = 0; + } + else if (iPos == 9) + {//last custom + //modified + if (m_bCustom) + { + long nVal = LogicToLogic(m_nCustomWidth , MAP_POINT, (MapUnit)m_eMapUnit); + nVal = m_xMFWidth->Denormalize(nVal); + XLineWidthItem aWidthItem( nVal ); + m_rParent.setLineWidth(aWidthItem); + m_rParent.SetWidth(nVal); + m_bCloseByEdit = false; + m_nTmpCustomWidth = 0; + } + else + { + m_xVSWidth->SetNoSelection(); //add , set no selection and keep the last select item + m_xVSWidth->SetFormat(); + m_xVSWidth->Invalidate(); + Invalidate(); + m_xVSWidth->StartSelection(); + } + //modify end + } + if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && m_bCustom)) //add + { + EndPopupMode(); + } +} - LineWidthControl* pControl = dynamic_cast<LineWidthControl*>(mxControl.get()); - if (pControl != nullptr) - pControl->SetWidthSelect(lValue, bValuable, eMapUnit); +IMPL_LINK_TYPED(LineWidthPopup, MFModifyHdl, Edit&, /*rControl*/, void) +{ + if (m_xVSWidth->GetSelItem()) + { + m_xVSWidth->SetSelItem(0); + m_xVSWidth->SetFormat(); + m_xVSWidth->Invalidate(); + Invalidate(); + m_xVSWidth->StartSelection(); + } + long nTmp = static_cast<long>(m_xMFWidth->GetValue()); + long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)m_eMapUnit ); + sal_Int32 nNewWidth = (short)m_xMFWidth->Denormalize( nVal ); + XLineWidthItem aWidthItem(nNewWidth); + m_rParent.setLineWidth(aWidthItem); + + m_bCloseByEdit = true; + m_nTmpCustomWidth = nTmp; } -void LineWidthPopup::PopupModeEndCallback() +void LineWidthPopup::SetWidthSelect(long lValue, bool bValuable, SfxMapUnit eMapUnit) { - LineWidthControl* pControl = dynamic_cast<LineWidthControl*>(mxControl.get()); - if (pControl != nullptr) + m_bVSFocus = true; + m_xVSWidth->SetSelItem(0); + m_bCloseByEdit = false; + m_eMapUnit = eMapUnit; + SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE ); + if (aWinOpt.Exists()) + { + css::uno::Sequence <css::beans::NamedValue> aSeq = aWinOpt.GetUserData(); + OUString aTmp; + if ( aSeq.getLength()) + aSeq[0].Value >>= aTmp; + + OUString aWinData( aTmp ); + m_nCustomWidth = aWinData.toInt32(); + m_bCustom = true; + m_xVSWidth->SetImage(m_aIMGCus); + m_xVSWidth->SetCusEnable(true); + + OUString aStrTip( OUString::number( (double)m_nCustomWidth / 10)); + aStrTip += m_sPt; + m_xVSWidth->SetItemText(9, aStrTip); + } + else { - if (pControl->IsCloseByEdit()) + m_bCustom = false; + m_xVSWidth->SetImage(m_aIMGCusGray); + m_xVSWidth->SetCusEnable(false); + m_xVSWidth->SetItemText(9, m_pStr[8]); + } + + if (bValuable) + { + sal_Int64 nVal = OutputDevice::LogicToLogic(lValue, (MapUnit) eMapUnit, MAP_100TH_MM ); + nVal = m_xMFWidth->Normalize(nVal); + m_xMFWidth->SetValue( nVal, FUNIT_100TH_MM ); + } + else + { + m_xMFWidth->SetText( "" ); + } + + OUString strCurrValue = m_xMFWidth->GetText(); + sal_uInt16 i = 0; + for(; i < 8; i++) + { + if (strCurrValue == m_pStr[i]) { - SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE ); - css::uno::Sequence < css::beans::NamedValue > aSeq - { { "LineWidth", css::uno::makeAny(OUString::number(pControl->GetTmpCustomWidth())) } }; - aWinOpt.SetUserData( aSeq ); + m_xVSWidth->SetSelItem(i+1); + break; } } + + if (i>=8) + { + m_bVSFocus = false; + m_xVSWidth->SetSelItem(0); + } + + m_xVSWidth->SetFormat(); + m_xVSWidth->Invalidate(); + m_xVSWidth->StartSelection(); + + if (m_bVSFocus) + m_xVSWidth->GrabFocus(); + else + m_xMFWidth->GrabFocus(); } } } // end of namespace svx::sidebar |