LibreOffice Module svx (master)  1
rubydialog.cxx
Go to the documentation of this file.
1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  * Licensed to the Apache Software Foundation (ASF) under one or more
11  * contributor license agreements. See the NOTICE file distributed
12  * with this work for additional information regarding copyright
13  * ownership. The ASF licenses this file to you under the Apache
14  * License, Version 2.0 (the "License"); you may not use this file
15  * except in compliance with the License. You may obtain a copy of
16  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 #include <memory>
20 #include <sal/config.h>
21 #include <tools/debug.hxx>
22 #include <tools/diagnose_ex.h>
23 
24 #include <svx/rubydialog.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <sfx2/sfxsids.hrc>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/viewsh.hxx>
29 #include <svl/eitem.hxx>
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>
41 #include <cppuhelper/implbase.hxx>
42 #include <svtools/colorcfg.hxx>
43 #include <vcl/event.hxx>
44 #include <vcl/settings.hxx>
45 #include <vcl/svapp.hxx>
46 
47 using namespace css::uno;
48 using namespace css::frame;
49 using namespace css::text;
50 using namespace css::beans;
51 using namespace css::style;
52 using namespace css::view;
53 using namespace css::lang;
54 using namespace css::container;
55 
57 
58 namespace
59 {
60 
61 const char cRubyBaseText[] = "RubyBaseText";
62 const char cRubyText[] = "RubyText";
63 const char cRubyAdjust[] = "RubyAdjust";
64 const char cRubyPosition[] = "RubyPosition";
65 const char cRubyCharStyleName[] = "RubyCharStyleName";
66 
67 } // end anonymous namespace
68 
69 SvxRubyChildWindow::SvxRubyChildWindow(vcl::Window* _pParent, sal_uInt16 nId,SfxBindings* pBindings, SfxChildWinInfo const * pInfo)
70  : SfxChildWindow(_pParent, nId)
71 {
72  auto xDlg = std::make_shared<SvxRubyDialog>(pBindings, this, _pParent->GetFrameWeld());
73  SetController(xDlg);
74  xDlg->Initialize(pInfo);
75 }
76 
78 {
79  return SfxChildWindow::GetInfo();
80 }
81 
82 class SvxRubyData_Impl : public cppu::WeakImplHelper<css::view::XSelectionChangeListener>
83 {
84  Reference<XModel> xModel;
85  Reference<XRubySelection> xSelection;
86  Sequence<PropertyValues> aRubyValues;
87  Reference<XController> xController;
89 
90 public:
92  virtual ~SvxRubyData_Impl() override;
93 
94  void SetController(const Reference<XController>& xCtrl);
95  Reference<XModel> const & GetModel()
96  {
97  if (!xController.is())
98  xModel = nullptr;
99  else
100  xModel = xController->getModel();
101  return xModel;
102  }
103  bool HasSelectionChanged() const
104  {
105  return bHasSelectionChanged;
106  }
107  Reference<XRubySelection> const & GetRubySelection()
108  {
109  xSelection.set(xController, UNO_QUERY);
110  return xSelection;
111  }
113  {
114  if (!xSelection.is())
115  aRubyValues.realloc(0);
116  else
117  aRubyValues = xSelection->getRubyList(false);
118  bHasSelectionChanged = false;
119  }
120  Sequence<PropertyValues>& GetRubyValues()
121  {
122  return aRubyValues;
123  }
124  void AssertOneEntry();
125 
126  virtual void SAL_CALL selectionChanged(const css::lang::EventObject& aEvent) override;
127  virtual void SAL_CALL disposing( const css::lang::EventObject& Source) override;
128 
129 };
130 
132  : bHasSelectionChanged(false)
133 {
134 }
135 
137 {
138 }
139 
140 void SvxRubyData_Impl::SetController(const Reference<XController>& xCtrl)
141 {
142  if (xCtrl.get() == xController.get())
143  return;
144 
145  try
146  {
147  Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
148  if (xSelSupp.is())
149  xSelSupp->removeSelectionChangeListener(this);
150 
151  bHasSelectionChanged = true;
152  xController = xCtrl;
153  xSelSupp.set(xController, UNO_QUERY);
154  if (xSelSupp.is())
155  xSelSupp->addSelectionChangeListener(this);
156  }
157  catch (const Exception&)
158  {
159  }
160 }
161 
162 void SvxRubyData_Impl::selectionChanged(const EventObject& )
163 {
164  bHasSelectionChanged = true;
165 }
166 
167 void SvxRubyData_Impl::disposing(const EventObject&)
168 {
169  try
170  {
171  Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
172  if (xSelSupp.is())
173  xSelSupp->removeSelectionChangeListener(this);
174  }
175  catch (const Exception&)
176  {
177  }
178  xController = nullptr;
179 }
180 
182 {
183  //create one entry
184  if (!aRubyValues.hasElements())
185  {
186  aRubyValues.realloc(1);
187  Sequence<PropertyValue>& rValues = aRubyValues.getArray()[0];
188  rValues.realloc(5);
189  PropertyValue* pValues = rValues.getArray();
190  pValues[0].Name = cRubyBaseText;
191  pValues[1].Name = cRubyText;
192  pValues[2].Name = cRubyAdjust;
193  pValues[3].Name = cRubyPosition;
194  pValues[4].Name = cRubyCharStyleName;
195  }
196 }
197 
199  : SfxModelessDialogController(pBind, pCW, pParent,
200  "svx/ui/asianphoneticguidedialog.ui", "AsianPhoneticGuideDialog")
201  , nLastPos(0)
202  , nCurrentEdit(0)
203  , bModified(false)
204  , pBindings(pBind)
205  , m_pImpl( new SvxRubyData_Impl )
206  , m_xLeftFT(m_xBuilder->weld_label("basetextft"))
207  , m_xRightFT(m_xBuilder->weld_label("rubytextft"))
208  , m_xLeft1ED(m_xBuilder->weld_entry("Left1ED"))
209  , m_xRight1ED(m_xBuilder->weld_entry("Right1ED"))
210  , m_xLeft2ED(m_xBuilder->weld_entry("Left2ED"))
211  , m_xRight2ED(m_xBuilder->weld_entry("Right2ED"))
212  , m_xLeft3ED(m_xBuilder->weld_entry("Left3ED"))
213  , m_xRight3ED(m_xBuilder->weld_entry("Right3ED"))
214  , m_xLeft4ED(m_xBuilder->weld_entry("Left4ED"))
215  , m_xRight4ED(m_xBuilder->weld_entry("Right4ED"))
216  , m_xScrolledWindow(m_xBuilder->weld_scrolled_window("scrolledwindow", true))
217  , m_xAdjustLB(m_xBuilder->weld_combo_box("adjustlb"))
218  , m_xPositionLB(m_xBuilder->weld_combo_box("positionlb"))
219  , m_xCharStyleFT(m_xBuilder->weld_label("styleft"))
220  , m_xCharStyleLB(m_xBuilder->weld_combo_box("stylelb"))
221  , m_xStylistPB(m_xBuilder->weld_button("styles"))
222  , m_xApplyPB(m_xBuilder->weld_button("ok"))
223  , m_xClosePB(m_xBuilder->weld_button("cancel"))
224  , m_xContentArea(m_xDialog->weld_content_area())
225  , m_xGrid(m_xBuilder->weld_widget("grid"))
226  , m_xPreviewWin(new RubyPreview)
227  , m_xPreview(new weld::CustomWeld(*m_xBuilder, "preview", *m_xPreviewWin))
228 {
229  m_xCharStyleLB->make_sorted();
230  m_xPreviewWin->setRubyDialog(this);
231  m_xScrolledWindow->set_size_request(-1, m_xGrid->get_preferred_size().Height());
232  m_xScrolledWindow->set_vpolicy(VclPolicyType::NEVER);
233 
234  aEditArr[0] = m_xLeft1ED.get(); aEditArr[1] = m_xRight1ED.get();
235  aEditArr[2] = m_xLeft2ED.get(); aEditArr[3] = m_xRight2ED.get();
236  aEditArr[4] = m_xLeft3ED.get(); aEditArr[5] = m_xRight3ED.get();
237  aEditArr[6] = m_xLeft4ED.get(); aEditArr[7] = m_xRight4ED.get();
238 
239  m_xApplyPB->connect_clicked(LINK(this, SvxRubyDialog, ApplyHdl_Impl));
240  m_xClosePB->connect_clicked(LINK(this, SvxRubyDialog, CloseHdl_Impl));
241  m_xStylistPB->connect_clicked(LINK(this, SvxRubyDialog, StylistHdl_Impl));
242  m_xAdjustLB->connect_changed(LINK(this, SvxRubyDialog, AdjustHdl_Impl));
243  m_xPositionLB->connect_changed(LINK(this, SvxRubyDialog, PositionHdl_Impl));
244  m_xCharStyleLB->connect_changed(LINK(this, SvxRubyDialog, CharStyleHdl_Impl));
245 
246  Link<weld::ScrolledWindow&, void> aScrLk(LINK(this, SvxRubyDialog, ScrollHdl_Impl));
247  m_xScrolledWindow->connect_vadjustment_changed(aScrLk);
248 
249  Link<weld::Entry&,void> aEditLk(LINK(this, SvxRubyDialog, EditModifyHdl_Impl));
250  Link<weld::Widget&,void> aFocusLk(LINK(this, SvxRubyDialog, EditFocusHdl_Impl));
251  Link<const KeyEvent&,bool> aKeyUpDownLk(LINK(this, SvxRubyDialog, KeyUpDownHdl_Impl));
252  Link<const KeyEvent&,bool> aKeyTabUpDownLk(LINK(this, SvxRubyDialog, KeyUpDownTabHdl_Impl));
253  for (sal_uInt16 i = 0; i < 8; i++)
254  {
255  aEditArr[i]->connect_changed(aEditLk);
256  aEditArr[i]->connect_focus_in(aFocusLk);
257  if (!i || 7 == i)
258  aEditArr[i]->connect_key_press(aKeyTabUpDownLk);
259  else
260  aEditArr[i]->connect_key_press(aKeyUpDownLk);
261  }
262 }
263 
265 {
267  EventObject aEvent;
268  m_pImpl->disposing(aEvent);
269 }
270 
272 {
273  m_xCharStyleLB->clear();
274 }
275 
277 {
278  if (IsClosing())
279  return;
280  SfxViewFrame* pViewFrame = SfxViewFrame::Current();
281  if (pViewFrame)
282  pViewFrame->ToggleChildWindow(SID_RUBY_DIALOG);
283 }
284 
286 {
288  //get selection from current view frame
289  SfxViewFrame* pCurFrm = SfxViewFrame::Current();
290  Reference< XController > xCtrl = pCurFrm->GetFrame().GetController();
291  m_pImpl->SetController(xCtrl);
292  if (!m_pImpl->HasSelectionChanged())
293  return;
294 
295  Reference< XRubySelection > xRubySel = m_pImpl->GetRubySelection();
296  m_pImpl->UpdateRubyValues();
297  EnableControls(xRubySel.is());
298  if (xRubySel.is())
299  {
300  Reference< XModel > xModel = m_pImpl->GetModel();
301  const OUString sCharStyleSelect = m_xCharStyleLB->get_active_text();
303  Reference<XStyleFamiliesSupplier> xSupplier(xModel, UNO_QUERY);
304  if (xSupplier.is())
305  {
306  try
307  {
308  Reference<XNameAccess> xFam = xSupplier->getStyleFamilies();
309  Any aChar = xFam->getByName("CharacterStyles");
310  Reference<XNameContainer> xChar;
311  aChar >>= xChar;
312  Reference<XIndexAccess> xCharIdx(xChar, UNO_QUERY);
313  if (xCharIdx.is())
314  {
315  OUString sUIName("DisplayName");
316  for (sal_Int32 nStyle = 0; nStyle < xCharIdx->getCount(); nStyle++)
317  {
318  Any aStyle = xCharIdx->getByIndex(nStyle);
319  Reference<XStyle> xStyle;
320  aStyle >>= xStyle;
321  Reference<XPropertySet> xPrSet(xStyle, UNO_QUERY);
322  OUString sName, sCoreName;
323  if (xPrSet.is())
324  {
325  Reference<XPropertySetInfo> xInfo = xPrSet->getPropertySetInfo();
326  if (xInfo->hasPropertyByName(sUIName))
327  {
328  Any aName = xPrSet->getPropertyValue(sUIName);
329  aName >>= sName;
330  }
331  }
332  if (xStyle.is())
333  {
334  sCoreName = xStyle->getName();
335  if (sName.isEmpty())
336  sName = sCoreName;
337  }
338  if (!sName.isEmpty())
339  {
340  m_xCharStyleLB->append(sCoreName, sName);
341 
342  }
343  }
344  }
345  }
346  catch (const Exception&)
347  {
348  TOOLS_WARN_EXCEPTION("svx.dialog", "exception in style access");
349  }
350  if (!sCharStyleSelect.isEmpty())
351  m_xCharStyleLB->set_active_text(sCharStyleSelect);
352  }
353  m_xCharStyleLB->set_sensitive(xSupplier.is());
354  m_xCharStyleFT->set_sensitive(xSupplier.is());
355  }
356  Update();
357  m_xPreviewWin->Invalidate();
358 }
359 
360 void SvxRubyDialog::SetRubyText(sal_Int32 nPos, weld::Entry& rLeft, weld::Entry& rRight)
361 {
362  OUString sLeft, sRight;
363  const Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
364  bool bEnable = aRubyValues.getLength() > nPos;
365  if (bEnable)
366  {
367  const Sequence<PropertyValue> aProps = aRubyValues.getConstArray()[nPos];
368  for (const PropertyValue& rProp : aProps)
369  {
370  if (rProp.Name == cRubyBaseText)
371  rProp.Value >>= sLeft;
372  else if (rProp.Name == cRubyText)
373  rProp.Value >>= sRight;
374  }
375  }
376  else if (!nPos)
377  {
378  bEnable = true;
379  }
380  rLeft.set_sensitive(bEnable);
381  rRight.set_sensitive(bEnable);
382  rLeft.set_text(sLeft);
383  rRight.set_text(sRight);
384  rLeft.save_value();
385  rRight.save_value();
386 }
387 
389 {
390  long nTempLastPos = GetLastPos();
391  for (int i = 0; i < 8; i+=2)
392  {
393  if (aEditArr[i]->get_sensitive() &&
394  (aEditArr[i]->get_value_changed_from_saved() ||
395  aEditArr[i + 1]->get_value_changed_from_saved()))
396  {
397  Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
398  DBG_ASSERT(aRubyValues.getLength() > (i / 2 + nTempLastPos), "wrong index" );
399  SetModified(true);
400  Sequence<PropertyValue>& rProps = aRubyValues.getArray()[i / 2 + nTempLastPos];
401  for (PropertyValue & propVal : rProps)
402  {
403  if (propVal.Name == cRubyBaseText)
404  propVal.Value <<= aEditArr[i]->get_text();
405  else if (propVal.Name == cRubyText)
406  propVal.Value <<= aEditArr[i + 1]->get_text();
407  }
408  }
409  }
410 }
411 
413 {
414  const Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
415  sal_Int32 nLen = aRubyValues.getLength();
416  m_xScrolledWindow->vadjustment_configure(0, 0, !nLen ? 1 : nLen, 1, 4, 4);
417  if (nLen > 4)
418  m_xScrolledWindow->set_vpolicy(VclPolicyType::ALWAYS);
419  else
420  m_xScrolledWindow->set_vpolicy(VclPolicyType::NEVER);
421  SetLastPos(0);
422  SetModified(false);
423 
424  sal_Int16 nAdjust = -1;
425  sal_Int16 nPosition = -1;
426  OUString sCharStyleName, sTmp;
427  bool bCharStyleEqual = true;
428  for (sal_Int32 nRuby = 0; nRuby < nLen; nRuby++)
429  {
430  const Sequence<PropertyValue> &rProps = aRubyValues.getConstArray()[nRuby];
431  for (const PropertyValue& rProp : rProps)
432  {
433  if (nAdjust > -2 && rProp.Name == cRubyAdjust)
434  {
435  sal_Int16 nTmp = sal_Int16();
436  rProp.Value >>= nTmp;
437  if (!nRuby)
438  nAdjust = nTmp;
439  else if(nAdjust != nTmp)
440  nAdjust = -2;
441  }
442  if (nPosition > -2 && rProp.Name == cRubyPosition )
443  {
444  sal_Int16 nTmp = sal_Int16();
445  rProp.Value >>= nTmp;
446  if (!nRuby)
447  nPosition = nTmp;
448  else if(nPosition != nTmp)
449  nPosition = -2;
450  }
451  if (bCharStyleEqual && rProp.Name == cRubyCharStyleName)
452  {
453  rProp.Value >>= sTmp;
454  if (!nRuby)
455  sCharStyleName = sTmp;
456  else if (sCharStyleName != sTmp)
457  bCharStyleEqual = false;
458  }
459  }
460  }
461  if (!nLen)
462  {
463  //enable selection if the ruby list is empty
464  nAdjust = 0;
465  nPosition = 0;
466  }
467  if (nAdjust > -1)
468  m_xAdjustLB->set_active(nAdjust);
469  else
470  m_xAdjustLB->set_active(-1);
471  if (nPosition > -1)
472  m_xPositionLB->set_active(nPosition);
473  if (!nLen || (bCharStyleEqual && sCharStyleName.isEmpty()))
474  sCharStyleName = "Rubies";
475  if (!sCharStyleName.isEmpty())
476  {
477  for (int i = 0, nEntryCount = m_xCharStyleLB->get_count(); i < nEntryCount; i++)
478  {
479  OUString sCoreName = m_xCharStyleLB->get_id(i);
480  if (sCharStyleName == sCoreName)
481  {
482  m_xCharStyleLB->set_active(i);
483  break;
484  }
485  }
486  }
487  else
488  m_xCharStyleLB->set_active(-1);
489 
490  ScrollHdl_Impl(*m_xScrolledWindow);
491 }
492 
493 void SvxRubyDialog::GetCurrentText(OUString& rBase, OUString& rRuby)
494 {
495  rBase = aEditArr[nCurrentEdit * 2]->get_text();
496  rRuby = aEditArr[nCurrentEdit * 2 + 1]->get_text();
497 }
498 
499 IMPL_LINK(SvxRubyDialog, ScrollHdl_Impl, weld::ScrolledWindow&, rScroll, void)
500 {
501  int nPos = rScroll.vadjustment_get_value();
502  if (GetLastPos() != nPos)
503  {
504  GetRubyText();
505  }
506  SetRubyText(nPos++, *m_xLeft1ED, *m_xRight1ED);
507  SetRubyText(nPos++, *m_xLeft2ED, *m_xRight2ED);
508  SetRubyText(nPos++, *m_xLeft3ED, *m_xRight3ED);
509  SetRubyText(nPos, *m_xLeft4ED, *m_xRight4ED);
510  SetLastPos(nPos - 3);
511  m_xPreviewWin->Invalidate();
512 }
513 
515 {
516  const Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
517  if (!aRubyValues.hasElements())
518  {
519  AssertOneEntry();
520  PositionHdl_Impl(*m_xPositionLB);
521  AdjustHdl_Impl(*m_xAdjustLB);
522  CharStyleHdl_Impl(*m_xCharStyleLB);
523  }
524  GetRubyText();
525  //reset all edit fields - SaveValue is called
526  ScrollHdl_Impl(*m_xScrolledWindow);
527 
528  Reference<XRubySelection> xSelection = m_pImpl->GetRubySelection();
529  if (IsModified() && xSelection.is())
530  {
531  try
532  {
533  xSelection->setRubyList(aRubyValues, false);
534  }
535  catch (const Exception&)
536  {
537  TOOLS_WARN_EXCEPTION("svx.dialog", "");
538  }
539  }
540 }
541 
543 {
544  Close();
545 }
546 
547 IMPL_LINK_NOARG(SvxRubyDialog, StylistHdl_Impl, weld::Button&, void)
548 {
549  std::unique_ptr<SfxPoolItem> pState;
550  SfxItemState eState = pBindings->QueryState(SID_STYLE_DESIGNER, pState);
551  if (eState <= SfxItemState::SET || !pState || !static_cast<SfxBoolItem*>(pState.get())->GetValue())
552  {
553  pBindings->GetDispatcher()->Execute(SID_STYLE_DESIGNER,
554  SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
555  }
556 }
557 
558 IMPL_LINK(SvxRubyDialog, AdjustHdl_Impl, weld::ComboBox&, rBox, void)
559 {
560  AssertOneEntry();
561  sal_Int16 nAdjust = rBox.get_active();
562  Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
563  for (PropertyValues & rProps : aRubyValues)
564  {
565  for (PropertyValue & propVal : rProps)
566  {
567  if (propVal.Name == cRubyAdjust)
568  propVal.Value <<= nAdjust;
569  }
570  SetModified(true);
571  }
572  m_xPreviewWin->Invalidate();
573 }
574 
575 IMPL_LINK(SvxRubyDialog, PositionHdl_Impl, weld::ComboBox&, rBox, void)
576 {
577  AssertOneEntry();
578  sal_Int16 nPosition = rBox.get_active();
579  Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
580  for (PropertyValues & rProps : aRubyValues)
581  {
582  for (PropertyValue & propVal : rProps)
583  {
584  if (propVal.Name == cRubyPosition)
585  propVal.Value <<= nPosition;
586  }
587  SetModified(true);
588  }
589  m_xPreviewWin->Invalidate();
590 }
591 
592 IMPL_LINK_NOARG(SvxRubyDialog, CharStyleHdl_Impl, weld::ComboBox&, void)
593 {
594  AssertOneEntry();
595  OUString sStyleName;
596  if (m_xCharStyleLB->get_active() != -1)
597  sStyleName = m_xCharStyleLB->get_active_id();
598  Sequence<PropertyValues>& aRubyValues = m_pImpl->GetRubyValues();
599  for (PropertyValues & rProps : aRubyValues)
600  {
601  for (PropertyValue & propVal : rProps)
602  {
603  if (propVal.Name == cRubyCharStyleName)
604  {
605  propVal.Value <<= sStyleName;
606  }
607  }
608  SetModified(true);
609  }
610 }
611 
612 IMPL_LINK(SvxRubyDialog, EditFocusHdl_Impl, weld::Widget&, rEdit, void)
613 {
614  for (sal_uInt16 i = 0; i < 8; i++)
615  {
616  if (&rEdit == aEditArr[i])
617  {
618  nCurrentEdit = i / 2;
619  break;
620  }
621  }
622  m_xPreviewWin->Invalidate();
623 }
624 
625 IMPL_LINK(SvxRubyDialog, EditModifyHdl_Impl, weld::Entry&, rEdit, void)
626 {
627  EditFocusHdl_Impl(rEdit);
628 }
629 
631 {
632  bool bRet = false;
633  //scroll forward
634  if (nParam > 0 && (aEditArr[7]->has_focus() || aEditArr[6]->has_focus() ))
635  {
636  if (m_xScrolledWindow->vadjustment_get_upper() >
637  m_xScrolledWindow->vadjustment_get_value() + m_xScrolledWindow->vadjustment_get_page_size())
638  {
639  m_xScrolledWindow->vadjustment_set_value(m_xScrolledWindow->vadjustment_get_value() + 1);
640  aEditArr[6]->grab_focus();
641  bRet = true;
642  }
643  }
644  //scroll backward
645  else if (m_xScrolledWindow->vadjustment_get_value() && (aEditArr[0]->has_focus()||aEditArr[1]->has_focus()) )
646  {
647  m_xScrolledWindow->vadjustment_set_value(m_xScrolledWindow->vadjustment_get_value() - 1);
648  aEditArr[1]->grab_focus();
649  bRet = true;
650  }
651  if (bRet)
652  ScrollHdl_Impl(*m_xScrolledWindow);
653  return bRet;
654 }
655 
657 {
658  bool bHandled = false;
659  sal_uInt16 nIndex = USHRT_MAX;
660  for (sal_uInt16 i = 0; i < 8; i++)
661  {
662  if(aEditArr[i]->has_focus())
663  nIndex = i;
664  }
665  if (nIndex < 8)
666  {
667  if (nParam > 0)
668  {
669  if (nIndex < 6)
670  aEditArr[nIndex + 2]->grab_focus();
671  else if( EditScrollHdl_Impl(nParam))
672  aEditArr[nIndex]->grab_focus();
673  }
674  else
675  {
676  if (nIndex > 1)
677  aEditArr[nIndex - 2]->grab_focus();
678  else if( EditScrollHdl_Impl(nParam))
679  aEditArr[nIndex]->grab_focus();
680  }
681  bHandled = true;
682  }
683  return bHandled;
684 }
685 
687 {
688  m_pImpl->AssertOneEntry();
689 }
690 
692 {
693  m_xContentArea->set_sensitive(bEnable);
694  m_xApplyPB->set_sensitive(bEnable);
695 }
696 
698  : m_pParentDlg(nullptr)
699 {
700 }
701 
703 {
704 }
705 
706 void RubyPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
707 {
708  rRenderContext.Push(PushFlags::ALL);
709 
710  rRenderContext.SetMapMode(MapMode(MapUnit::MapTwip));
711 
712  Size aWinSize = rRenderContext.GetOutputSize();
713 
714  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
715  svtools::ColorConfig aColorConfig;
716 
717  Color aNewTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
718  Color aNewFillColor(rStyleSettings.GetWindowColor());
719 
720  vcl::Font aFont = rRenderContext.GetFont();
721  aFont.SetFontHeight(aWinSize.Height() / 4);
722  aFont.SetFillColor(aNewFillColor);
723  aFont.SetColor(aNewTextColor);
724  rRenderContext.SetFont(aFont);
725 
726  tools::Rectangle aRect(Point(0, 0), aWinSize);
727  rRenderContext.SetLineColor();
728  rRenderContext.SetFillColor(aFont.GetFillColor());
729  rRenderContext.DrawRect(aRect);
730 
731  OUString sBaseText, sRubyText;
732  m_pParentDlg->GetCurrentText(sBaseText, sRubyText);
733 
734  long nTextHeight = rRenderContext.GetTextHeight();
735  long nBaseWidth = rRenderContext.GetTextWidth(sBaseText);
736 
737  vcl::Font aRubyFont(aFont);
738  aRubyFont.SetFontHeight(aRubyFont.GetFontHeight() * 70 / 100);
739  rRenderContext.SetFont(aRubyFont);
740  long nRubyWidth = rRenderContext.GetTextWidth(sRubyText);
741  rRenderContext.SetFont(aFont);
742 
743  RubyAdjust nAdjust = static_cast<RubyAdjust>(m_pParentDlg->m_xAdjustLB->get_active());
744  //use center if no adjustment is available
745  if (nAdjust > RubyAdjust_INDENT_BLOCK)
746  nAdjust = RubyAdjust_CENTER;
747 
748  //which part is stretched ?
749  bool bRubyStretch = nBaseWidth >= nRubyWidth;
750 
751  long nCenter = aWinSize.Width() / 2;
752  long nHalfWidth = std::max( nBaseWidth, nRubyWidth ) /2;
753  long nLeftStart = nCenter - nHalfWidth;
754  long nRightEnd = nCenter + nHalfWidth;
755 
756  // Default values for TOP or no selection
757  long nYRuby = aWinSize.Height() / 4 - nTextHeight / 2;
758  long nYBase = aWinSize.Height() * 3 / 4 - nTextHeight / 2;
759 
760  sal_Int16 nRubyPos = m_pParentDlg->m_xPositionLB->get_active();
761  if ( nRubyPos == 1 ) // BOTTOM
762  {
763  long nTmp = nYRuby;
764  nYRuby = nYBase;
765  nYBase = nTmp;
766  }
767  else if ( nRubyPos == 2 ) // RIGHT ( vertically )
768  {
769  // Align the ruby text and base text to the vertical center.
770  nYBase = ( aWinSize.Height() - nTextHeight ) / 2;
771  nYRuby = ( aWinSize.Height() - nRubyWidth ) / 2;
772 
773  // Align the ruby text at the right side of the base text
774  nAdjust = RubyAdjust_RIGHT;
775  nHalfWidth = nBaseWidth / 2;
776  nLeftStart = nCenter - nHalfWidth;
777  nRightEnd = nCenter + nHalfWidth + nRubyWidth + nTextHeight;
778  // Render base text first, then render ruby text on the right.
779  bRubyStretch = true;
780 
781  aRubyFont.SetVertical(true);
782  aRubyFont.SetOrientation(Degree10(2700));
783  }
784 
785  long nYOutput;
786  long nOutTextWidth;
787  OUString sOutputText;
788 
789  if (bRubyStretch)
790  {
791  rRenderContext.DrawText(Point(nLeftStart , nYBase), sBaseText);
792  nYOutput = nYRuby;
793  sOutputText = sRubyText;
794  nOutTextWidth = nRubyWidth;
795  rRenderContext.SetFont(aRubyFont);
796  }
797  else
798  {
799  rRenderContext.SetFont(aRubyFont);
800  rRenderContext.DrawText(Point(nLeftStart , nYRuby), sRubyText);
801  nYOutput = nYBase;
802  sOutputText = sBaseText;
803  nOutTextWidth = nBaseWidth;
804  rRenderContext.SetFont(aFont);
805  }
806 
807  switch (nAdjust)
808  {
809  case RubyAdjust_LEFT:
810  rRenderContext.DrawText(Point(nLeftStart , nYOutput), sOutputText);
811  break;
812  case RubyAdjust_RIGHT:
813  rRenderContext.DrawText(Point(nRightEnd - nOutTextWidth, nYOutput), sOutputText);
814  break;
815  case RubyAdjust_INDENT_BLOCK:
816  {
817  long nCharWidth = rRenderContext.GetTextWidth("X");
818  if (nOutTextWidth < (nRightEnd - nLeftStart - nCharWidth))
819  {
820  nCharWidth /= 2;
821  nLeftStart += nCharWidth;
822  nRightEnd -= nCharWidth;
823  }
824  [[fallthrough]];
825  }
826  case RubyAdjust_BLOCK:
827  {
828  if (sOutputText.getLength() > 1)
829  {
830  sal_Int32 nCount = sOutputText.getLength();
831  long nSpace = ((nRightEnd - nLeftStart) - rRenderContext.GetTextWidth(sOutputText)) / (nCount - 1);
832  for (sal_Int32 i = 0; i < nCount; i++)
833  {
834  OUString sChar(sOutputText[i]);
835  rRenderContext.DrawText(Point(nLeftStart , nYOutput), sChar);
836  long nCharWidth = rRenderContext.GetTextWidth(sChar);
837  nLeftStart += nCharWidth + nSpace;
838  }
839  break;
840  }
841  [[fallthrough]];
842  }
843  case RubyAdjust_CENTER:
844  rRenderContext.DrawText(Point(nCenter - nOutTextWidth / 2 , nYOutput), sOutputText);
845  break;
846  default: break;
847  }
848  rRenderContext.Pop();
849 }
850 
852 {
853  pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 40,
854  pDrawingArea->get_text_height() * 7);
855  CustomWidgetController::SetDrawingArea(pDrawingArea);
856 }
857 
858 IMPL_LINK(SvxRubyDialog, KeyUpDownHdl_Impl, const KeyEvent&, rKEvt, bool)
859 {
860  bool bHandled = false;
861  const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
862  sal_uInt16 nCode = rKeyCode.GetCode();
863  if (KEY_UP == nCode || KEY_DOWN == nCode)
864  {
865  sal_Int32 nParam = KEY_UP == nCode ? -1 : 1;
866  bHandled = EditJumpHdl_Impl(nParam);
867  }
868  return bHandled;
869 }
870 
871 IMPL_LINK(SvxRubyDialog, KeyUpDownTabHdl_Impl, const KeyEvent&, rKEvt, bool)
872 {
873  bool bHandled = false;
874  const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
875  sal_uInt16 nMod = rKeyCode.GetModifier();
876  sal_uInt16 nCode = rKeyCode.GetCode();
877  if (nCode == KEY_TAB && (!nMod || KEY_SHIFT == nMod))
878  {
879  sal_Int32 nParam = KEY_SHIFT == nMod ? -1 : 1;
880  if (EditScrollHdl_Impl(nParam))
881  bHandled = true;
882  }
883  if (!bHandled)
884  bHandled = KeyUpDownHdl_Impl(rKEvt);
885  return bHandled;
886 }
887 
888 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< RubyPreview > m_xPreviewWin
Definition: rubydialog.hxx:94
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
virtual void connect_changed(const Link< Entry &, void > &rLink)
sal_Int32 nIndex
virtual void Close() override
Definition: rubydialog.cxx:276
std::string GetValue
std::unique_ptr< weld::ComboBox > m_xCharStyleLB
Definition: rubydialog.hxx:85
void GetRubyText()
Definition: rubydialog.cxx:388
OUString sCharStyleName
void SetModified(bool bSet)
Definition: rubydialog.hxx:124
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
std::unique_ptr< weld::Container > m_xContentArea
Definition: rubydialog.hxx:91
virtual ~SvxRubyData_Impl() override
Definition: rubydialog.cxx:136
void UpdateRubyValues()
Definition: rubydialog.cxx:112
std::map< sal_Int32, std::shared_ptr< SetItemPropertyStorage > > PropertyValues
sal_uInt16 GetCode() const
std::unique_ptr< weld::Entry > m_xLeft1ED
Definition: rubydialog.hxx:69
IMPL_LINK_NOARG(SvxRubyDialog, ApplyHdl_Impl, weld::Button &, void)
Definition: rubydialog.cxx:514
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: rubydialog.cxx:706
virtual void set_text(const OUString &rText)=0
std::unique_ptr< weld::ScrolledWindow > m_xScrolledWindow
Definition: rubydialog.hxx:78
void SetMapMode()
void AssertOneEntry()
Definition: rubydialog.cxx:686
Reference< XModel > xModel
Definition: rubydialog.cxx:84
SvxRubyDialog * m_pParentDlg
Definition: rubydialog.hxx:34
constexpr sal_uInt16 KEY_UP
tools::Long GetFontHeight() const
void ToggleChildWindow(sal_uInt16)
SvxRubyDialog(SfxBindings *pBindings, SfxChildWindow *pCW, weld::Window *pParent)
Definition: rubydialog.cxx:198
weld::Window * GetFrameWeld() const
std::unique_ptr< weld::Button > m_xClosePB
Definition: rubydialog.hxx:89
void SetRubyText(sal_Int32 nPos, weld::Entry &rLeft, weld::Entry &rRight)
Definition: rubydialog.cxx:360
std::unique_ptr< weld::Button > m_xStylistPB
Definition: rubydialog.hxx:86
std::unique_ptr< weld::Entry > m_xRight1ED
Definition: rubydialog.hxx:70
const vcl::Font & GetFont() const
SfxFrame & GetFrame() const
int nCount
std::unique_ptr< weld::Entry > m_xRight4ED
Definition: rubydialog.hxx:76
SvxRubyChildWindow(vcl::Window *, sal_uInt16, SfxBindings *, SfxChildWinInfo const *)
Definition: rubydialog.cxx:69
Reference< XController > xController
Definition: rubydialog.cxx:87
sal_uInt16 GetModifier() const
void SetLastPos(long nSet)
Definition: rubydialog.hxx:121
sal_uInt16 nCode
void DrawRect(const tools::Rectangle &rRect)
void ClearCharStyleList()
Definition: rubydialog.cxx:271
virtual void Activate() override
Definition: rubydialog.cxx:285
constexpr sal_uInt16 KEY_DOWN
long GetLastPos() const
Definition: rubydialog.hxx:120
void SetLineColor()
#define TOOLS_WARN_EXCEPTION(area, stream)
std::unique_ptr< weld::Entry > m_xLeft4ED
Definition: rubydialog.hxx:75
#define DBG_ASSERT(sCon, aError)
void GetCurrentText(OUString &rBase, OUString &rRuby)
Definition: rubydialog.cxx:493
int i
OUString sName
bool bHasSelectionChanged
Definition: rubydialog.cxx:88
void SetOrientation(Degree10 nLineOrientation)
virtual bool has_focus() const =0
sal_uInt16 & nParam
std::unique_ptr< weld::Button > m_xApplyPB
Definition: rubydialog.hxx:88
Size GetOutputSize() const
Reference< XRubySelection > const & GetRubySelection()
Definition: rubydialog.cxx:107
void SetFillColor()
tools::Long Width() const
virtual ~RubyPreview() override
Definition: rubydialog.cxx:702
virtual void SAL_CALL selectionChanged(const css::lang::EventObject &aEvent) override
Definition: rubydialog.cxx:162
virtual void connect_focus_in(const Link< Widget &, void > &rLink)
Sequence< PropertyValues > aRubyValues
Definition: rubydialog.cxx:86
void SetController(const Reference< XController > &xCtrl)
Definition: rubydialog.cxx:140
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
Definition: rubydialog.cxx:167
virtual void connect_key_press(const Link< const KeyEvent &, bool > &rLink)
bool EditJumpHdl_Impl(sal_Int32 nParam)
Definition: rubydialog.cxx:656
virtual OUString get_text() const =0
weld::Entry * aEditArr[8]
Definition: rubydialog.hxx:65
const PropertyValue * pValues
SFX_IMPL_CHILDWINDOW(SvxRubyChildWindow, SID_RUBY_DIALOG)
virtual void Activate() override
IMPL_LINK(SvxRubyDialog, ScrollHdl_Impl, weld::ScrolledWindow &, rScroll, void)
Definition: rubydialog.cxx:499
static SfxViewFrame * Current()
SfxItemState
weld::Entry & rEdit
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
bool EditScrollHdl_Impl(sal_Int32 nParam)
Definition: rubydialog.cxx:630
bool HasSelectionChanged() const
Definition: rubydialog.cxx:103
void SetFont(const vcl::Font &rNewFont)
std::unique_ptr< weld::Label > m_xCharStyleFT
Definition: rubydialog.hxx:84
virtual void grab_focus()=0
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Reference< XModel > const & GetModel()
Definition: rubydialog.cxx:95
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: rubydialog.cxx:851
tools::Long GetTextHeight() const
css::uno::Reference< css::frame::XController > GetController() const
OUString aName
std::unique_ptr< weld::Entry > m_xRight2ED
Definition: rubydialog.hxx:72
virtual int get_text_height() const =0
void SetController(std::shared_ptr< SfxDialogController > controller)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
Reference< XExecutableDialog > m_xDialog
tools::Long Height() const
void save_value()
const Color & GetWindowColor() const
Reference< XRubySelection > xSelection
Definition: rubydialog.cxx:85
void SetVertical(bool bVertical)
void SetFontHeight(tools::Long nHeight)
Reference< XModel > xModel
std::unique_ptr< weld::ComboBox > m_xPositionLB
Definition: rubydialog.hxx:82
std::unique_ptr< weld::Widget > m_xGrid
Definition: rubydialog.hxx:92
std::unique_ptr< weld::Entry > m_xRight3ED
Definition: rubydialog.hxx:74
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
constexpr sal_uInt16 KEY_SHIFT
virtual void set_size_request(int nWidth, int nHeight)=0
void Push(PushFlags nFlags=PushFlags::ALL)
std::unique_ptr< weld::Entry > m_xLeft3ED
Definition: rubydialog.hxx:73
virtual SfxChildWinInfo GetInfo() const
AnyEventRef aEvent
virtual float get_approximate_digit_width() const =0
virtual ~SvxRubyDialog() override
Definition: rubydialog.cxx:264
sal_uInt16 nPos
virtual void set_sensitive(bool sensitive)=0
constexpr sal_uInt16 KEY_TAB
Sequence< PropertyValues > & GetRubyValues()
Definition: rubydialog.cxx:120
void EnableControls(bool bEnable)
Definition: rubydialog.cxx:691
std::unique_ptr< weld::ComboBox > m_xAdjustLB
Definition: rubydialog.hxx:80
rtl::Reference< SvxRubyData_Impl > m_pImpl
Definition: rubydialog.hxx:64
std::unique_ptr< weld::Entry > m_xLeft2ED
Definition: rubydialog.hxx:71