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>
119 virtual void SAL_CALL
selectionChanged(
const css::lang::EventObject& aEvent)
override;
120 virtual void SAL_CALL
disposing(
const css::lang::EventObject& Source)
override;
124 : bHasSelectionChanged(false)
138 Reference<XSelectionSupplier> xSelSupp(
xController, UNO_QUERY);
140 xSelSupp->removeSelectionChangeListener(
this);
146 xSelSupp->addSelectionChangeListener(
this);
159 Reference<XSelectionSupplier> xSelSupp(
xController, UNO_QUERY);
161 xSelSupp->removeSelectionChangeListener(
this);
176 Sequence<PropertyValue>& rValues =
aRubyValues.getArray()[0];
178 PropertyValue*
pValues = rValues.getArray();
179 pValues[0].Name = cRubyBaseText;
182 pValues[3].Name = cRubyPosition;
183 pValues[4].Name = cRubyCharStyleName;
189 "AsianPhoneticGuideDialog")
195 , m_xLeft1ED(m_xBuilder->weld_entry(
"Left1ED"))
196 , m_xRight1ED(m_xBuilder->weld_entry(
"Right1ED"))
197 , m_xLeft2ED(m_xBuilder->weld_entry(
"Left2ED"))
198 , m_xRight2ED(m_xBuilder->weld_entry(
"Right2ED"))
199 , m_xLeft3ED(m_xBuilder->weld_entry(
"Left3ED"))
200 , m_xRight3ED(m_xBuilder->weld_entry(
"Right3ED"))
201 , m_xLeft4ED(m_xBuilder->weld_entry(
"Left4ED"))
202 , m_xRight4ED(m_xBuilder->weld_entry(
"Right4ED"))
203 , m_xScrolledWindow(m_xBuilder->weld_scrolled_window(
"scrolledwindow", true))
204 , m_xAdjustLB(m_xBuilder->weld_combo_box(
"adjustlb"))
205 , m_xPositionLB(m_xBuilder->weld_combo_box(
"positionlb"))
206 , m_xCharStyleFT(m_xBuilder->weld_label(
"styleft"))
207 , m_xCharStyleLB(m_xBuilder->weld_combo_box(
"stylelb"))
208 , m_xStylistPB(m_xBuilder->weld_button(
"styles"))
209 , m_xApplyPB(m_xBuilder->weld_button(
"ok"))
210 , m_xClosePB(m_xBuilder->weld_button(
"close"))
211 , m_xContentArea(
m_xDialog->weld_content_area())
212 , m_xGrid(m_xBuilder->weld_widget(
"grid"))
214 , m_xPreview(new
weld::CustomWeld(*m_xBuilder,
"preview", *m_xPreviewWin))
244 for (sal_uInt16
i = 0;
i < 8;
i++)
286 if (!
m_pImpl->HasSelectionChanged())
289 Reference<XRubySelection> xRubySel =
m_pImpl->GetRubySelection();
295 const OUString sCharStyleSelect =
m_xCharStyleLB->get_active_text();
297 Reference<XStyleFamiliesSupplier> xSupplier(
xModel, UNO_QUERY);
302 Reference<XNameAccess> xFam = xSupplier->getStyleFamilies();
303 Any aChar = xFam->getByName(
"CharacterStyles");
304 Reference<XNameContainer> xChar;
306 Reference<XIndexAccess> xCharIdx(xChar, UNO_QUERY);
309 OUString sUIName(
"DisplayName");
310 for (sal_Int32 nStyle = 0; nStyle < xCharIdx->getCount(); nStyle++)
312 Any aStyle = xCharIdx->getByIndex(nStyle);
313 Reference<XStyle> xStyle;
315 Reference<XPropertySet> xPrSet(xStyle, UNO_QUERY);
316 OUString
sName, sCoreName;
319 Reference<XPropertySetInfo> xInfo = xPrSet->getPropertySetInfo();
320 if (xInfo->hasPropertyByName(sUIName))
322 Any aName = xPrSet->getPropertyValue(sUIName);
328 sCoreName = xStyle->getName();
332 if (!
sName.isEmpty())
343 if (!sCharStyleSelect.isEmpty())
355 OUString sLeft, sRight;
356 const Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
357 bool bEnable = aRubyValues.getLength() >
nPos;
360 const Sequence<PropertyValue> aProps = aRubyValues.getConstArray()[
nPos];
361 for (
const PropertyValue& rProp : aProps)
363 if (rProp.Name == cRubyBaseText)
364 rProp.Value >>= sLeft;
365 else if (rProp.Name == cRubyText)
366 rProp.Value >>= sRight;
384 Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
385 auto aRubyValuesRange = asNonConstRange(aRubyValues);
386 for (
int i = 0;
i < 8;
i += 2)
389 && (
aEditArr[
i]->get_value_changed_from_saved()
390 ||
aEditArr[
i + 1]->get_value_changed_from_saved()))
392 DBG_ASSERT(aRubyValues.getLength() > (
i / 2 + nTempLastPos),
"wrong index");
394 for (PropertyValue& propVal : asNonConstRange(aRubyValuesRange[
i / 2 + nTempLastPos]))
396 if (propVal.Name == cRubyBaseText)
398 else if (propVal.Name == cRubyText)
407 const Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
408 sal_Int32 nLen = aRubyValues.getLength();
418 sal_Int16 nPosition = -1;
420 bool bCharStyleEqual =
true;
421 for (sal_Int32 nRuby = 0; nRuby < nLen; nRuby++)
423 const Sequence<PropertyValue>& rProps = aRubyValues.getConstArray()[nRuby];
424 for (
const PropertyValue& rProp : rProps)
426 if (
nAdjust > -2 && rProp.Name == cRubyAdjust)
428 sal_Int16 nTmp = sal_Int16();
429 rProp.Value >>= nTmp;
435 if (nPosition > -2 && rProp.Name == cRubyPosition)
437 sal_Int16 nTmp = sal_Int16();
438 rProp.Value >>= nTmp;
441 else if (nPosition != nTmp)
444 if (bCharStyleEqual && rProp.Name == cRubyCharStyleName)
446 rProp.Value >>= sTmp;
450 bCharStyleEqual =
false;
494 int nPos = rScroll.vadjustment_get_value();
495 if (GetLastPos() !=
nPos)
499 SetRubyText(
nPos++, *m_xLeft1ED, *m_xRight1ED);
500 SetRubyText(
nPos++, *m_xLeft2ED, *m_xRight2ED);
501 SetRubyText(
nPos++, *m_xLeft3ED, *m_xRight3ED);
502 SetRubyText(
nPos, *m_xLeft4ED, *m_xRight4ED);
503 SetLastPos(
nPos - 3);
504 m_xPreviewWin->Invalidate();
509 const Sequence<PropertyValues>& aRubyValues =
m_pImpl->GetRubyValues();
510 if (!aRubyValues.hasElements())
513 PositionHdl_Impl(*m_xPositionLB);
514 AdjustHdl_Impl(*m_xAdjustLB);
515 CharStyleHdl_Impl(*m_xCharStyleLB);
519 ScrollHdl_Impl(*m_xScrolledWindow);
521 Reference<XRubySelection> xSelection =
m_pImpl->GetRubySelection();
522 if (IsModified() && xSelection.is())
526 xSelection->setRubyList(aRubyValues,
false);
539 std::unique_ptr<SfxBoolItem> pState;
540 SfxItemState eState = pBindings->QueryState(SID_STYLE_DESIGNER, pState);
541 if (eState <= SfxItemState::SET || !pState || !pState->
GetValue())
543 pBindings->GetDispatcher()->Execute(SID_STYLE_DESIGNER,
544 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
551 sal_Int16
nAdjust = rBox.get_active();
554 for (PropertyValue& propVal : asNonConstRange(rProps))
556 if (propVal.Name == cRubyAdjust)
561 m_xPreviewWin->Invalidate();
567 sal_Int16 nPosition = rBox.get_active();
570 for (PropertyValue& propVal : asNonConstRange(rProps))
572 if (propVal.Name == cRubyPosition)
573 propVal.Value <<= nPosition;
577 m_xPreviewWin->Invalidate();
584 if (m_xCharStyleLB->get_active() != -1)
585 sStyleName = m_xCharStyleLB->get_active_id();
588 for (PropertyValue& propVal : asNonConstRange(rProps))
590 if (propVal.Name == cRubyCharStyleName)
592 propVal.Value <<= sStyleName;
601 for (sal_uInt16
i = 0;
i < 8;
i++)
603 if (&rEdit == aEditArr[
i])
605 nCurrentEdit =
i / 2;
609 m_xPreviewWin->Invalidate();
614 EditFocusHdl_Impl(rEdit);
648 bool bHandled =
false;
649 sal_uInt16
nIndex = USHRT_MAX;
650 for (sal_uInt16
i = 0;
i < 8;
i++)
685 : m_pParentDlg(nullptr)
716 OUString sBaseText, sRubyText;
724 rRenderContext.
SetFont(aRubyFont);
730 if (
nAdjust > RubyAdjust_INDENT_BLOCK)
734 bool bRubyStretch = nBaseWidth >= nRubyWidth;
737 tools::Long nHalfWidth = std::max(nBaseWidth, nRubyWidth) / 2;
747 std::swap(nYRuby, nYBase);
748 else if (nRubyPos == 2)
751 nYBase = (aWinSize.
Height() - nTextHeight) / 2;
752 nYRuby = (aWinSize.
Height() - nRubyWidth) / 2;
756 nHalfWidth = nBaseWidth / 2;
757 nLeftStart = nCenter - nHalfWidth;
758 nRightEnd = nCenter + nHalfWidth + nRubyWidth + nTextHeight;
768 OUString sOutputText;
772 rRenderContext.
DrawText(
Point(nLeftStart, nYBase), sBaseText);
774 sOutputText = sRubyText;
775 nOutTextWidth = nRubyWidth;
776 rRenderContext.
SetFont(aRubyFont);
780 rRenderContext.
SetFont(aRubyFont);
781 rRenderContext.
DrawText(
Point(nLeftStart, nYRuby), sRubyText);
783 sOutputText = sBaseText;
784 nOutTextWidth = nBaseWidth;
790 case RubyAdjust_LEFT:
791 rRenderContext.
DrawText(
Point(nLeftStart, nYOutput), sOutputText);
793 case RubyAdjust_RIGHT:
794 rRenderContext.
DrawText(
Point(nRightEnd - nOutTextWidth, nYOutput), sOutputText);
796 case RubyAdjust_INDENT_BLOCK:
799 if (nOutTextWidth < (nRightEnd - nLeftStart - nCharWidth))
802 nLeftStart += nCharWidth;
803 nRightEnd -= nCharWidth;
807 case RubyAdjust_BLOCK:
809 if (sOutputText.getLength() > 1)
811 sal_Int32
nCount = sOutputText.getLength();
813 = ((nRightEnd - nLeftStart) - rRenderContext.
GetTextWidth(sOutputText))
817 OUString sChar(sOutputText[
i]);
820 nLeftStart += nCharWidth + nSpace;
826 case RubyAdjust_CENTER:
827 rRenderContext.
DrawText(
Point(nCenter - nOutTextWidth / 2, nYOutput), sOutputText);
832 rRenderContext.
Pop();
839 CustomWidgetController::SetDrawingArea(pDrawingArea);
844 bool bHandled =
false;
846 sal_uInt16 nCode = rKeyCode.
GetCode();
849 sal_Int32 nParam =
KEY_UP == nCode ? -1 : 1;
850 bHandled = EditJumpHdl_Impl(nParam);
857 bool bHandled =
false;
860 sal_uInt16 nCode = rKeyCode.
GetCode();
863 sal_Int32 nParam =
KEY_SHIFT == nMod ? -1 : 1;
864 if (EditScrollHdl_Impl(nParam))
868 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 SAL_WARN_UNUSED_RESULT 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