26#include <sfx2/sfxsids.hrc>
30#include <com/sun/star/frame/XController.hpp>
31#include <com/sun/star/style/XStyle.hpp>
32#include <com/sun/star/text/XRubySelection.hpp>
33#include <com/sun/star/beans/PropertyValues.hpp>
34#include <com/sun/star/beans/XPropertySet.hpp>
35#include <com/sun/star/beans/XPropertySetInfo.hpp>
36#include <com/sun/star/container/XNameContainer.hpp>
37#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38#include <com/sun/star/text/RubyAdjust.hpp>
39#include <com/sun/star/view/XSelectionChangeListener.hpp>
40#include <com/sun/star/view/XSelectionSupplier.hpp>
47using namespace css::uno;
48using namespace css::frame;
49using namespace css::text;
50using namespace css::beans;
51using namespace css::style;
52using namespace css::view;
53using namespace css::lang;
54using namespace css::container;
60constexpr OUStringLiteral cRubyBaseText =
u"RubyBaseText";
61constexpr OUStringLiteral cRubyText =
u"RubyText";
62constexpr OUStringLiteral cRubyAdjust =
u"RubyAdjust";
63constexpr OUStringLiteral cRubyPosition =
u"RubyPosition";
64constexpr OUStringLiteral cRubyCharStyleName =
u"RubyCharStyleName";
72 auto xDlg = std::make_shared<SvxRubyDialog>(pBindings,
this, _pParent->
GetFrameWeld());
74 xDlg->Initialize(pInfo);
79class SvxRubyData_Impl :
public cppu::WeakImplHelper<css::view::XSelectionChangeListener>
117 virtual void SAL_CALL
selectionChanged(
const css::lang::EventObject& aEvent)
override;
118 virtual void SAL_CALL
disposing(
const css::lang::EventObject& Source)
override;
122 : bHasSelectionChanged(false)
135 Reference<XSelectionSupplier> xSelSupp(
xController, UNO_QUERY);
137 xSelSupp->removeSelectionChangeListener(
this);
143 xSelSupp->addSelectionChangeListener(
this);
156 Reference<XSelectionSupplier> xSelSupp(
xController, UNO_QUERY);
158 xSelSupp->removeSelectionChangeListener(
this);
172 Sequence<PropertyValue>& rValues =
aRubyValues.getArray()[0];
174 PropertyValue*
pValues = rValues.getArray();
175 pValues[0].Name = cRubyBaseText;
178 pValues[3].Name = cRubyPosition;
179 pValues[4].Name = cRubyCharStyleName;
185 "AsianPhoneticGuideDialog")
191 , m_xLeftFT(m_xBuilder->weld_label(
"basetextft"))
192 , m_xRightFT(m_xBuilder->weld_label(
"rubytextft"))
193 , m_xLeft1ED(m_xBuilder->weld_entry(
"Left1ED"))
194 , m_xRight1ED(m_xBuilder->weld_entry(
"Right1ED"))
195 , m_xLeft2ED(m_xBuilder->weld_entry(
"Left2ED"))
196 , m_xRight2ED(m_xBuilder->weld_entry(
"Right2ED"))
197 , m_xLeft3ED(m_xBuilder->weld_entry(
"Left3ED"))
198 , m_xRight3ED(m_xBuilder->weld_entry(
"Right3ED"))
199 , m_xLeft4ED(m_xBuilder->weld_entry(
"Left4ED"))
200 , m_xRight4ED(m_xBuilder->weld_entry(
"Right4ED"))
201 , m_xScrolledWindow(m_xBuilder->weld_scrolled_window(
"scrolledwindow", true))
202 , m_xAdjustLB(m_xBuilder->weld_combo_box(
"adjustlb"))
203 , m_xPositionLB(m_xBuilder->weld_combo_box(
"positionlb"))
204 , m_xCharStyleFT(m_xBuilder->weld_label(
"styleft"))
205 , m_xCharStyleLB(m_xBuilder->weld_combo_box(
"stylelb"))
206 , m_xStylistPB(m_xBuilder->weld_button(
"styles"))
207 , m_xApplyPB(m_xBuilder->weld_button(
"ok"))
208 , m_xClosePB(m_xBuilder->weld_button(
"close"))
209 , m_xContentArea(
m_xDialog->weld_content_area())
210 , m_xGrid(m_xBuilder->weld_widget(
"grid"))
212 , m_xPreview(new
weld::CustomWeld(*m_xBuilder,
"preview", *m_xPreviewWin))
242 for (sal_uInt16
i = 0;
i < 8;
i++)
283 if (!
m_pImpl->HasSelectionChanged())
286 Reference<XRubySelection> xRubySel =
m_pImpl->GetRubySelection();
292 const OUString sCharStyleSelect =
m_xCharStyleLB->get_active_text();
294 Reference<XStyleFamiliesSupplier> xSupplier(
xModel, UNO_QUERY);
299 Reference<XNameAccess> xFam = xSupplier->getStyleFamilies();
300 Any aChar = xFam->getByName(
"CharacterStyles");
301 Reference<XNameContainer> xChar;
303 Reference<XIndexAccess> xCharIdx(xChar, UNO_QUERY);
306 OUString sUIName(
"DisplayName");
307 for (sal_Int32 nStyle = 0; nStyle < xCharIdx->getCount(); nStyle++)
309 Any aStyle = xCharIdx->getByIndex(nStyle);
310 Reference<XStyle> xStyle;
312 Reference<XPropertySet> xPrSet(xStyle, UNO_QUERY);
313 OUString
sName, sCoreName;
316 Reference<XPropertySetInfo> xInfo = xPrSet->getPropertySetInfo();
317 if (xInfo->hasPropertyByName(sUIName))
319 Any aName = xPrSet->getPropertyValue(sUIName);
325 sCoreName = xStyle->getName();
329 if (!
sName.isEmpty())
340 if (!sCharStyleSelect.isEmpty())
352 OUString sLeft, sRight;
353 const Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
354 bool bEnable = aRubyValues.getLength() >
nPos;
357 const Sequence<PropertyValue> aProps = aRubyValues.getConstArray()[
nPos];
358 for (
const PropertyValue& rProp : aProps)
360 if (rProp.Name == cRubyBaseText)
361 rProp.Value >>= sLeft;
362 else if (rProp.Name == cRubyText)
363 rProp.Value >>= sRight;
381 Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
382 auto aRubyValuesRange = asNonConstRange(aRubyValues);
383 for (
int i = 0;
i < 8;
i += 2)
386 && (
aEditArr[
i]->get_value_changed_from_saved()
387 ||
aEditArr[
i + 1]->get_value_changed_from_saved()))
389 DBG_ASSERT(aRubyValues.getLength() > (
i / 2 + nTempLastPos),
"wrong index");
391 for (PropertyValue& propVal : asNonConstRange(aRubyValuesRange[
i / 2 + nTempLastPos]))
393 if (propVal.Name == cRubyBaseText)
395 else if (propVal.Name == cRubyText)
404 const Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
405 sal_Int32 nLen = aRubyValues.getLength();
414 sal_Int16 nAdjust = -1;
415 sal_Int16 nPosition = -1;
417 bool bCharStyleEqual =
true;
418 for (sal_Int32 nRuby = 0; nRuby < nLen; nRuby++)
420 const Sequence<PropertyValue>& rProps = aRubyValues.getConstArray()[nRuby];
421 for (
const PropertyValue& rProp : rProps)
423 if (nAdjust > -2 && rProp.Name == cRubyAdjust)
425 sal_Int16 nTmp = sal_Int16();
426 rProp.Value >>= nTmp;
429 else if (nAdjust != nTmp)
432 if (nPosition > -2 && rProp.Name == cRubyPosition)
434 sal_Int16 nTmp = sal_Int16();
435 rProp.Value >>= nTmp;
438 else if (nPosition != nTmp)
441 if (bCharStyleEqual && rProp.Name == cRubyCharStyleName)
443 rProp.Value >>= sTmp;
447 bCharStyleEqual =
false;
491 int nPos = rScroll.vadjustment_get_value();
492 if (GetLastPos() !=
nPos)
496 SetRubyText(
nPos++, *m_xLeft1ED, *m_xRight1ED);
497 SetRubyText(
nPos++, *m_xLeft2ED, *m_xRight2ED);
498 SetRubyText(
nPos++, *m_xLeft3ED, *m_xRight3ED);
499 SetRubyText(
nPos, *m_xLeft4ED, *m_xRight4ED);
500 SetLastPos(
nPos - 3);
501 m_xPreviewWin->Invalidate();
506 const Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
507 if (!aRubyValues.hasElements())
510 PositionHdl_Impl(*m_xPositionLB);
511 AdjustHdl_Impl(*m_xAdjustLB);
512 CharStyleHdl_Impl(*m_xCharStyleLB);
516 ScrollHdl_Impl(*m_xScrolledWindow);
518 Reference<XRubySelection> xSelection =
m_pImpl->GetRubySelection();
519 if (IsModified() && xSelection.is())
523 xSelection->setRubyList(aRubyValues,
false);
536 std::unique_ptr<SfxBoolItem> pState;
537 SfxItemState eState = pBindings->QueryState(SID_STYLE_DESIGNER, pState);
538 if (eState <= SfxItemState::SET || !pState || !pState->
GetValue())
540 pBindings->GetDispatcher()->Execute(SID_STYLE_DESIGNER,
541 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
548 sal_Int16 nAdjust = rBox.get_active();
551 for (PropertyValue& propVal : asNonConstRange(rProps))
553 if (propVal.Name == cRubyAdjust)
554 propVal.Value <<= nAdjust;
558 m_xPreviewWin->Invalidate();
564 sal_Int16 nPosition = rBox.get_active();
567 for (PropertyValue& propVal : asNonConstRange(rProps))
569 if (propVal.Name == cRubyPosition)
570 propVal.Value <<= nPosition;
574 m_xPreviewWin->Invalidate();
581 if (m_xCharStyleLB->get_active() != -1)
582 sStyleName = m_xCharStyleLB->get_active_id();
585 for (PropertyValue& propVal : asNonConstRange(rProps))
587 if (propVal.Name == cRubyCharStyleName)
589 propVal.Value <<= sStyleName;
598 for (sal_uInt16
i = 0;
i < 8;
i++)
600 if (&rEdit == aEditArr[
i])
602 nCurrentEdit =
i / 2;
606 m_xPreviewWin->Invalidate();
611 EditFocusHdl_Impl(rEdit);
645 bool bHandled =
false;
646 sal_uInt16
nIndex = USHRT_MAX;
647 for (sal_uInt16
i = 0;
i < 8;
i++)
682 : m_pParentDlg(nullptr)
713 OUString sBaseText, sRubyText;
721 rRenderContext.
SetFont(aRubyFont);
727 if (nAdjust > RubyAdjust_INDENT_BLOCK)
728 nAdjust = RubyAdjust_CENTER;
731 bool bRubyStretch = nBaseWidth >= nRubyWidth;
734 tools::Long nHalfWidth = std::max(nBaseWidth, nRubyWidth) / 2;
749 else if (nRubyPos == 2)
752 nYBase = (aWinSize.
Height() - nTextHeight) / 2;
753 nYRuby = (aWinSize.
Height() - nRubyWidth) / 2;
756 nAdjust = RubyAdjust_RIGHT;
757 nHalfWidth = nBaseWidth / 2;
758 nLeftStart = nCenter - nHalfWidth;
759 nRightEnd = nCenter + nHalfWidth + nRubyWidth + nTextHeight;
769 OUString sOutputText;
773 rRenderContext.
DrawText(
Point(nLeftStart, nYBase), sBaseText);
775 sOutputText = sRubyText;
776 nOutTextWidth = nRubyWidth;
777 rRenderContext.
SetFont(aRubyFont);
781 rRenderContext.
SetFont(aRubyFont);
782 rRenderContext.
DrawText(
Point(nLeftStart, nYRuby), sRubyText);
784 sOutputText = sBaseText;
785 nOutTextWidth = nBaseWidth;
791 case RubyAdjust_LEFT:
792 rRenderContext.
DrawText(
Point(nLeftStart, nYOutput), sOutputText);
794 case RubyAdjust_RIGHT:
795 rRenderContext.
DrawText(
Point(nRightEnd - nOutTextWidth, nYOutput), sOutputText);
797 case RubyAdjust_INDENT_BLOCK:
800 if (nOutTextWidth < (nRightEnd - nLeftStart - nCharWidth))
803 nLeftStart += nCharWidth;
804 nRightEnd -= nCharWidth;
808 case RubyAdjust_BLOCK:
810 if (sOutputText.getLength() > 1)
812 sal_Int32
nCount = sOutputText.getLength();
814 = ((nRightEnd - nLeftStart) - rRenderContext.
GetTextWidth(sOutputText))
818 OUString sChar(sOutputText[
i]);
821 nLeftStart += nCharWidth + nSpace;
827 case RubyAdjust_CENTER:
828 rRenderContext.
DrawText(
Point(nCenter - nOutTextWidth / 2, nYOutput), sOutputText);
833 rRenderContext.
Pop();
840 CustomWidgetController::SetDrawingArea(pDrawingArea);
845 bool bHandled =
false;
851 bHandled = EditJumpHdl_Impl(nParam);
858 bool bHandled =
false;
864 sal_Int32 nParam =
KEY_SHIFT == nMod ? -1 : 1;
865 if (EditScrollHdl_Impl(nParam))
869 bHandled = KeyUpDownHdl_Impl(rKEvt);
const PropertyValue * pValues
Reference< XExecutableDialog > m_xDialog
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Size GetOutputSize() const
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
tools::Long GetTextHeight() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
SvxRubyDialog * m_pParentDlg
virtual ~RubyPreview() override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
void SetController(std::shared_ptr< SfxDialogController > controller)
virtual SfxChildWinInfo GetInfo() const
css::uno::Reference< css::frame::XController > GetController() const
virtual void Activate() override
void ToggleChildWindow(sal_uInt16)
static SfxViewFrame * Current()
SfxFrame & GetFrame() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetWindowColor() const
SvxRubyChildWindow(vcl::Window *, sal_uInt16, SfxBindings *, SfxChildWinInfo const *)
Reference< XController > xController
virtual void SAL_CALL selectionChanged(const css::lang::EventObject &aEvent) override
bool bHasSelectionChanged
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
Reference< XRubySelection > const & GetRubySelection()
Sequence< PropertyValues > & GetRubyValues()
void SetController(const Reference< XController > &xCtrl)
Sequence< PropertyValues > aRubyValues
Reference< XModel > xModel
virtual ~SvxRubyData_Impl() override
Reference< XRubySelection > xSelection
bool HasSelectionChanged() const
Reference< XModel > const & GetModel()
std::unique_ptr< weld::Entry > m_xRight1ED
std::unique_ptr< weld::Widget > m_xGrid
std::unique_ptr< weld::Button > m_xStylistPB
virtual ~SvxRubyDialog() override
std::unique_ptr< weld::Entry > m_xRight4ED
std::unique_ptr< weld::Button > m_xClosePB
rtl::Reference< SvxRubyData_Impl > m_pImpl
std::unique_ptr< weld::Entry > m_xRight3ED
void EnableControls(bool bEnable)
std::unique_ptr< weld::Entry > m_xLeft3ED
virtual void Activate() override
std::unique_ptr< weld::Entry > m_xLeft2ED
std::unique_ptr< weld::Entry > m_xLeft1ED
void GetCurrentText(OUString &rBase, OUString &rRuby)
bool EditJumpHdl_Impl(sal_Int32 nParam)
weld::Entry * aEditArr[8]
void ClearCharStyleList()
std::unique_ptr< weld::ScrolledWindow > m_xScrolledWindow
bool EditScrollHdl_Impl(sal_Int32 nParam)
std::unique_ptr< weld::Button > m_xApplyPB
std::unique_ptr< weld::ComboBox > m_xCharStyleLB
std::unique_ptr< weld::Container > m_xContentArea
void SetRubyText(sal_Int32 nPos, weld::Entry &rLeft, weld::Entry &rRight)
SvxRubyDialog(SfxBindings *pBindings, SfxChildWindow *pCW, weld::Window *pParent)
std::unique_ptr< weld::Entry > m_xLeft4ED
virtual void Close() override
void SetModified(bool bSet)
std::unique_ptr< weld::ComboBox > m_xPositionLB
std::unique_ptr< weld::Label > m_xCharStyleFT
std::unique_ptr< RubyPreview > m_xPreviewWin
void SetLastPos(tools::Long nSet)
tools::Long GetLastPos() const
std::unique_ptr< weld::Entry > m_xRight2ED
std::unique_ptr< weld::ComboBox > m_xAdjustLB
tools::Long GetFontHeight() const
void SetOrientation(Degree10 nLineOrientation)
void SetVertical(bool bVertical)
void SetFillColor(const Color &)
void SetColor(const Color &)
void SetFontHeight(tools::Long nHeight)
const Color & GetFillColor() const
sal_uInt16 GetCode() const
sal_uInt16 GetModifier() const
weld::Window * GetFrameWeld() const
virtual void set_text(const OUString &rText)=0
virtual void connect_changed(const Link< Entry &, void > &rLink)
virtual OUString get_text() const=0
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr sal_uInt16 KEY_TAB
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_DOWN
constexpr sal_uInt16 KEY_SHIFT
#define LINK(Instance, Class, Member)
std::map< sal_Int32, std::shared_ptr< SetItemPropertyStorage > > PropertyValues
SFX_IMPL_CHILDWINDOW(SvxRubyChildWindow, SID_RUBY_DIALOG)
IMPL_LINK(SvxRubyDialog, ScrollHdl_Impl, weld::ScrolledWindow &, rScroll, void)
IMPL_LINK_NOARG(SvxRubyDialog, ApplyHdl_Impl, weld::Button &, void)
Reference< XModel > xModel