Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svx/rubydialog.hxx>
21 : #include <tools/shl.hxx>
22 : #include <svx/dialmgr.hxx>
23 : #include <svx/dialogs.hrc>
24 : #include <sfx2/app.hxx>
25 : #include <sfx2/dispatch.hxx>
26 : #include <sfx2/viewfrm.hxx>
27 : #include <svl/eitem.hxx>
28 : #include <com/sun/star/frame/XController.hpp>
29 : #include <com/sun/star/style/XStyle.hpp>
30 : #include <com/sun/star/text/XRubySelection.hpp>
31 : #include <com/sun/star/beans/PropertyValues.hpp>
32 : #include <com/sun/star/beans/XPropertySet.hpp>
33 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 : #include <com/sun/star/container/XNameContainer.hpp>
35 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 : #include <com/sun/star/text/RubyAdjust.hpp>
37 : #include <com/sun/star/view/XSelectionChangeListener.hpp>
38 : #include <com/sun/star/view/XSelectionSupplier.hpp>
39 : #include <cppuhelper/implbase1.hxx>
40 : #include <svtools/colorcfg.hxx>
41 : #include <vcl/layout.hxx>
42 :
43 : using namespace com::sun::star::uno;
44 : using namespace com::sun::star::frame;
45 : using namespace com::sun::star::text;
46 : using namespace com::sun::star::beans;
47 : using namespace com::sun::star::style;
48 : using namespace com::sun::star::view;
49 : using namespace com::sun::star::lang;
50 : using namespace com::sun::star::container;
51 :
52 33 : SFX_IMPL_CHILDWINDOW( SvxRubyChildWindow, SID_RUBY_DIALOG );
53 :
54 : static const sal_Char cRubyBaseText[] = "RubyBaseText";
55 : static const sal_Char cRubyText[] = "RubyText";
56 : static const sal_Char cCharacterStyles[] = "CharacterStyles";
57 : static const sal_Char cRubyAdjust[] = "RubyAdjust";
58 : static const sal_Char cRubyIsAbove[] = "RubyIsAbove";
59 : static const sal_Char cDisplayName[] = "DisplayName";
60 : static const sal_Char cRubyCharStyleName[] = "RubyCharStyleName";
61 : static const sal_Char cRubies[] = "Rubies";
62 :
63 0 : SvxRubyChildWindow::SvxRubyChildWindow( Window* _pParent, sal_uInt16 nId,
64 : SfxBindings* pBindings, SfxChildWinInfo* pInfo) :
65 0 : SfxChildWindow(_pParent, nId)
66 : {
67 0 : SvxRubyDialog* pDlg = new SvxRubyDialog(pBindings, this, _pParent);
68 0 : pWindow = pDlg;
69 :
70 0 : if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
71 0 : pDlg->RollUp();
72 :
73 0 : eChildAlignment = SFX_ALIGN_NOALIGNMENT;
74 :
75 0 : pDlg->Initialize( pInfo );
76 0 : }
77 :
78 0 : SfxChildWinInfo SvxRubyChildWindow::GetInfo() const
79 : {
80 0 : return SfxChildWindow::GetInfo();
81 : }
82 :
83 : class SvxRubyData_Impl : public cppu::WeakImplHelper1
84 : < ::com::sun::star::view::XSelectionChangeListener >
85 : {
86 : Reference<XModel> xModel;
87 : Reference<XRubySelection> xSelection;
88 : Sequence<PropertyValues> aRubyValues;
89 : Reference<XController> xController;
90 : bool bHasSelectionChanged;
91 : public:
92 : SvxRubyData_Impl();
93 : ~SvxRubyData_Impl();
94 :
95 : void SetController(Reference<XController> xCtrl);
96 0 : Reference<XModel> GetModel()
97 : {
98 0 : if(!xController.is())
99 0 : xModel = 0;
100 : else
101 0 : xModel = xController->getModel();
102 0 : return xModel;
103 : }
104 0 : bool HasSelectionChanged() const{return bHasSelectionChanged;}
105 0 : Reference<XRubySelection> GetRubySelection()
106 : {
107 0 : xSelection = Reference<XRubySelection>(xController, UNO_QUERY);
108 0 : return xSelection;
109 : }
110 0 : void UpdateRubyValues()
111 : {
112 0 : if(!xSelection.is())
113 0 : aRubyValues.realloc(0);
114 : else
115 0 : aRubyValues = xSelection->getRubyList(false);
116 0 : bHasSelectionChanged = false;
117 0 : }
118 0 : Sequence<PropertyValues>& GetRubyValues() {return aRubyValues;}
119 : void AssertOneEntry();
120 :
121 : virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (RuntimeException);
122 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (RuntimeException);
123 :
124 : };
125 : //-----------------------------------------------------------------------------
126 0 : SvxRubyData_Impl::SvxRubyData_Impl() :
127 0 : bHasSelectionChanged(false)
128 : {
129 0 : }
130 : //-----------------------------------------------------------------------------
131 0 : SvxRubyData_Impl::~SvxRubyData_Impl()
132 : {
133 0 : }
134 : //-----------------------------------------------------------------------------
135 0 : void SvxRubyData_Impl::SetController(Reference<XController> xCtrl)
136 : {
137 0 : if(xCtrl.get() != xController.get())
138 : {
139 : try
140 : {
141 0 : Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
142 0 : if(xSelSupp.is())
143 0 : xSelSupp->removeSelectionChangeListener(this);
144 :
145 0 : bHasSelectionChanged = true;
146 0 : xController = xCtrl;
147 0 : xSelSupp = Reference<XSelectionSupplier>(xController, UNO_QUERY);
148 0 : if(xSelSupp.is())
149 0 : xSelSupp->addSelectionChangeListener(this);
150 : }
151 0 : catch (const Exception&)
152 : {
153 : }
154 : }
155 0 : }
156 : //-----------------------------------------------------------------------------
157 0 : void SvxRubyData_Impl::selectionChanged( const EventObject& ) throw (RuntimeException)
158 : {
159 0 : bHasSelectionChanged = true;
160 0 : }
161 : //-----------------------------------------------------------------------------
162 0 : void SvxRubyData_Impl::disposing( const EventObject&) throw (RuntimeException)
163 : {
164 : try
165 : {
166 0 : Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
167 0 : if(xSelSupp.is())
168 0 : xSelSupp->removeSelectionChangeListener(this);
169 : }
170 0 : catch (const Exception&)
171 : {
172 : }
173 0 : xController = 0;
174 0 : }
175 : //-----------------------------------------------------------------------------
176 0 : void SvxRubyData_Impl::AssertOneEntry()
177 : {
178 : //create one entry
179 0 : if(!aRubyValues.getLength())
180 : {
181 0 : aRubyValues.realloc(1);
182 0 : Sequence<PropertyValue>& rValues = aRubyValues.getArray()[0];
183 0 : rValues.realloc(5);
184 0 : PropertyValue* pValues = rValues.getArray();
185 0 : pValues[0].Name = cRubyBaseText;
186 0 : pValues[1].Name = cRubyText;
187 0 : pValues[2].Name = cRubyAdjust;
188 0 : pValues[3].Name = cRubyIsAbove;
189 0 : pValues[4].Name = cRubyCharStyleName;
190 : }
191 0 : }
192 :
193 0 : SvxRubyDialog::SvxRubyDialog(SfxBindings *pBind, SfxChildWindow *pCW,
194 : Window* _pParent)
195 : : SfxModelessDialog(pBind, pCW, _pParent, "AsianPhoneticGuideDialog",
196 : "svx/ui/asianphoneticguidedialog.ui")
197 : , nLastPos(0)
198 : , nCurrentEdit(0)
199 : , bModified(false)
200 0 : , pBindings(pBind)
201 : {
202 0 : xImpl = pImpl = new SvxRubyData_Impl;
203 0 : get(m_pLeftFT, "basetextft");
204 0 : get(m_pRightFT, "rubytextft");
205 0 : get(m_pAdjustLB, "adjustlb");
206 0 : get(m_pPositionLB, "positionlb");
207 0 : get(m_pCharStyleFT, "styleft");
208 0 : get(m_pCharStyleLB, "stylelb");
209 0 : m_pCharStyleLB->SetStyle(m_pCharStyleLB->GetStyle() | WB_SORT);
210 0 : get(m_pStylistPB, "styles");
211 0 : get(m_pApplyPB, "apply");
212 0 : get(m_pClosePB, "close");
213 0 : get(m_pPreviewWin, "preview");
214 0 : m_pPreviewWin->setRubyDialog(this);
215 0 : get(m_pScrolledWindow, "scrolledwindow");
216 0 : m_pScrollSB = &m_pScrolledWindow->getVertScrollBar();
217 0 : get(m_pLeft1ED, "Left1ED");
218 0 : get(m_pRight1ED, "Right1ED");
219 0 : get(m_pLeft2ED, "Left2ED");
220 0 : get(m_pRight2ED, "Right2ED");
221 0 : get(m_pLeft3ED, "Left3ED");
222 0 : get(m_pRight3ED, "Right3ED");
223 0 : get(m_pLeft4ED, "Left4ED");
224 0 : get(m_pRight4ED, "Right4ED");
225 0 : aEditArr[0] = m_pLeft1ED; aEditArr[1] = m_pRight1ED;
226 0 : aEditArr[2] = m_pLeft2ED; aEditArr[3] = m_pRight2ED;
227 0 : aEditArr[4] = m_pLeft3ED; aEditArr[5] = m_pRight3ED;
228 0 : aEditArr[6] = m_pLeft4ED; aEditArr[7] = m_pRight4ED;
229 :
230 0 : m_pApplyPB->SetClickHdl(LINK(this, SvxRubyDialog, ApplyHdl_Impl));
231 0 : m_pClosePB->SetClickHdl(LINK(this, SvxRubyDialog, CloseHdl_Impl));
232 0 : m_pStylistPB->SetClickHdl(LINK(this, SvxRubyDialog, StylistHdl_Impl));
233 0 : m_pAdjustLB->SetSelectHdl(LINK(this, SvxRubyDialog, AdjustHdl_Impl));
234 0 : m_pPositionLB->SetSelectHdl(LINK(this, SvxRubyDialog, PositionHdl_Impl));
235 0 : m_pCharStyleLB->SetSelectHdl(LINK(this, SvxRubyDialog, CharStyleHdl_Impl));
236 :
237 0 : Link aScrLk(LINK(this, SvxRubyDialog, ScrollHdl_Impl));
238 0 : m_pScrollSB->SetScrollHdl( aScrLk );
239 0 : m_pScrollSB->SetEndScrollHdl( aScrLk );
240 :
241 0 : Link aEditLk(LINK(this, SvxRubyDialog, EditModifyHdl_Impl));
242 0 : Link aScrollLk(LINK(this, SvxRubyDialog, EditScrollHdl_Impl));
243 0 : Link aJumpLk(LINK(this, SvxRubyDialog, EditJumpHdl_Impl));
244 0 : for(sal_uInt16 i = 0; i < 8; i++)
245 : {
246 0 : aEditArr[i]->SetModifyHdl(aEditLk);
247 0 : aEditArr[i]->SetJumpHdl(aJumpLk);
248 0 : if(!i || 7 == i)
249 0 : aEditArr[i]->SetScrollHdl(aScrollLk);
250 : }
251 :
252 0 : UpdateColors();
253 :
254 0 : String leftLabelName = m_pLeftFT->GetText(), rightLabelName = m_pRightFT->GetText();
255 0 : m_pLeft2ED->SetAccessibleName(leftLabelName);
256 0 : m_pLeft3ED->SetAccessibleName(leftLabelName);
257 0 : m_pLeft4ED->SetAccessibleName(leftLabelName);
258 0 : m_pRight2ED->SetAccessibleName(rightLabelName);
259 0 : m_pRight3ED->SetAccessibleName(rightLabelName);
260 0 : m_pRight4ED->SetAccessibleName(rightLabelName);
261 0 : }
262 :
263 0 : SvxRubyDialog::~SvxRubyDialog()
264 : {
265 0 : ClearCharStyleList();
266 0 : EventObject aEvent;
267 0 : xImpl->disposing(aEvent);
268 0 : }
269 :
270 0 : void SvxRubyDialog::ClearCharStyleList()
271 : {
272 0 : for(sal_uInt16 i = 0; i < m_pCharStyleLB->GetEntryCount(); i++)
273 : {
274 0 : void* pData = m_pCharStyleLB->GetEntryData(i);
275 0 : delete (OUString*)pData;
276 : }
277 0 : m_pCharStyleLB->Clear();
278 0 : }
279 :
280 0 : sal_Bool SvxRubyDialog::Close()
281 : {
282 : pBindings->GetDispatcher()->Execute( SID_RUBY_DIALOG,
283 : SFX_CALLMODE_ASYNCHRON |
284 0 : SFX_CALLMODE_RECORD);
285 0 : return sal_True;
286 : }
287 :
288 0 : void SvxRubyDialog::Activate()
289 : {
290 0 : SfxModelessDialog::Activate();
291 0 : SfxPoolItem* pState = 0;
292 0 : SfxItemState eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
293 0 : sal_Bool bEnable = (eState < SFX_ITEM_AVAILABLE) || !pState || !((SfxBoolItem*)pState)->GetValue();
294 0 : delete pState;
295 0 : m_pStylistPB->Enable(bEnable);
296 : //get selection from current view frame
297 0 : SfxViewFrame* pCurFrm = SfxViewFrame::Current();
298 0 : Reference< XController > xCtrl = pCurFrm->GetFrame().GetController();
299 0 : pImpl->SetController(xCtrl);
300 0 : if(pImpl->HasSelectionChanged())
301 : {
302 :
303 0 : Reference< XRubySelection > xRubySel = pImpl->GetRubySelection();
304 0 : pImpl->UpdateRubyValues();
305 0 : EnableControls(xRubySel.is());
306 0 : if(xRubySel.is())
307 : {
308 0 : Reference< XModel > xModel = pImpl->GetModel();
309 0 : const String sCharStyleSelect = m_pCharStyleLB->GetSelectEntry();
310 0 : ClearCharStyleList();
311 0 : Reference<XStyleFamiliesSupplier> xSupplier(xModel, UNO_QUERY);
312 0 : if(xSupplier.is())
313 : {
314 : try
315 : {
316 0 : Reference<XNameAccess> xFam = xSupplier->getStyleFamilies();
317 0 : Any aChar = xFam->getByName(cCharacterStyles);
318 0 : Reference<XNameContainer> xChar;
319 0 : aChar >>= xChar;
320 0 : Reference<XIndexAccess> xCharIdx(xChar, UNO_QUERY);
321 0 : if(xCharIdx.is())
322 : {
323 0 : OUString sUIName(cDisplayName);
324 0 : for(sal_Int32 nStyle = 0; nStyle < xCharIdx->getCount(); nStyle++)
325 : {
326 0 : Any aStyle = xCharIdx->getByIndex(nStyle);
327 0 : Reference<XStyle> xStyle;
328 0 : aStyle >>= xStyle;
329 0 : Reference<XPropertySet> xPrSet(xStyle, UNO_QUERY);
330 0 : OUString sName, sCoreName;
331 0 : if(xPrSet.is())
332 : {
333 0 : Reference<XPropertySetInfo> xInfo = xPrSet->getPropertySetInfo();
334 0 : if(xInfo->hasPropertyByName(sUIName))
335 : {
336 0 : Any aName = xPrSet->getPropertyValue(sUIName);
337 0 : aName >>= sName;
338 0 : }
339 : }
340 0 : if(xStyle.is())
341 : {
342 0 : sCoreName = xStyle->getName();
343 0 : if(sName.isEmpty())
344 0 : sName = sCoreName;
345 : }
346 0 : if(!sName.isEmpty())
347 : {
348 0 : sal_uInt16 nPos = m_pCharStyleLB->InsertEntry(sName);
349 0 : m_pCharStyleLB->SetEntryData( nPos, new OUString(sCoreName) );
350 :
351 : }
352 0 : }
353 0 : }
354 : }
355 0 : catch (const Exception&)
356 : {
357 : OSL_FAIL("exception in style access");
358 : }
359 0 : if(sCharStyleSelect.Len())
360 0 : m_pCharStyleLB->SelectEntry(sCharStyleSelect);
361 : }
362 0 : m_pCharStyleLB->Enable(xSupplier.is());
363 0 : m_pCharStyleFT->Enable(xSupplier.is());
364 : }
365 0 : Update();
366 0 : m_pPreviewWin->Invalidate();
367 0 : }
368 0 : }
369 :
370 0 : void SvxRubyDialog::Deactivate()
371 : {
372 0 : SfxModelessDialog::Deactivate();
373 0 : }
374 :
375 0 : void SvxRubyDialog::SetText(sal_Int32 nPos, Edit& rLeft, Edit& rRight)
376 : {
377 0 : OUString sLeft, sRight;
378 0 : const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
379 0 : sal_Bool bEnable = aRubyValues.getLength() > nPos;
380 0 : if(bEnable)
381 : {
382 0 : const Sequence<PropertyValue> aProps = aRubyValues.getConstArray()[nPos];
383 0 : const PropertyValue* pProps = aProps.getConstArray();
384 0 : for(sal_Int32 nProp = 0; nProp < aProps.getLength(); nProp++)
385 : {
386 0 : if ( pProps[nProp].Name == cRubyBaseText )
387 0 : pProps[nProp].Value >>= sLeft;
388 0 : else if ( pProps[nProp].Name == cRubyText )
389 0 : pProps[nProp].Value >>= sRight;
390 0 : }
391 : }
392 0 : else if(!nPos)
393 0 : bEnable = sal_True;
394 0 : rLeft.Enable(bEnable);
395 0 : rRight.Enable(bEnable);
396 0 : rLeft.SetText(sLeft);
397 0 : rRight.SetText(sRight);
398 0 : rLeft.SaveValue();
399 0 : rRight.SaveValue();
400 0 : }
401 : //-----------------------------------------------------------------------------
402 0 : void SvxRubyDialog::GetText()
403 : {
404 0 : long nTempLastPos = GetLastPos();
405 0 : for(int i = 0; i < 8; i+=2)
406 : {
407 0 : if(aEditArr[i]->IsEnabled() &&
408 0 : (aEditArr[i]->GetText() != aEditArr[i]->GetSavedValue() ||
409 0 : aEditArr[i + 1]->GetText() != aEditArr[i + 1]->GetSavedValue()))
410 : {
411 0 : Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
412 : DBG_ASSERT(aRubyValues.getLength() > (i / 2 + nTempLastPos), "wrong index" );
413 0 : SetModified(sal_True);
414 0 : Sequence<PropertyValue> &rProps = aRubyValues.getArray()[i / 2 + nTempLastPos];
415 0 : PropertyValue* pProps = rProps.getArray();
416 0 : for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
417 : {
418 0 : if ( pProps[nProp].Name == cRubyBaseText )
419 0 : pProps[nProp].Value <<= OUString(aEditArr[i]->GetText());
420 0 : else if ( pProps[nProp].Name == cRubyText )
421 0 : pProps[nProp].Value <<= OUString(aEditArr[i + 1]->GetText());
422 : }
423 : }
424 : }
425 0 : }
426 : //-----------------------------------------------------------------------------
427 0 : void SvxRubyDialog::Update()
428 : {
429 0 : const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
430 0 : sal_Int32 nLen = aRubyValues.getLength();
431 0 : m_pScrollSB->Enable(nLen > 4);
432 0 : m_pScrollSB->SetRange( Range(0, nLen > 4 ? nLen - 4 : 0));
433 0 : m_pScrollSB->SetThumbPos(0);
434 0 : SetLastPos(0);
435 0 : SetModified(sal_False);
436 :
437 0 : sal_Int16 nAdjust = -1;
438 0 : sal_Int16 nPosition = -1;
439 0 : OUString sCharStyleName, sTmp;
440 0 : bool bCharStyleEqual = true;
441 0 : for(sal_Int32 nRuby = 0; nRuby < nLen; nRuby++)
442 : {
443 0 : const Sequence<PropertyValue> &rProps = aRubyValues.getConstArray()[nRuby];
444 0 : const PropertyValue* pProps = rProps.getConstArray();
445 0 : for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
446 : {
447 0 : if(nAdjust > -2 && pProps[nProp].Name == cRubyAdjust )
448 : {
449 0 : sal_Int16 nTmp = sal_Int16();
450 0 : pProps[nProp].Value >>= nTmp;
451 0 : if(!nRuby)
452 0 : nAdjust = nTmp;
453 0 : else if(nAdjust != nTmp)
454 0 : nAdjust = -2;
455 : }
456 0 : if(nPosition > -2 && pProps[nProp].Name == cRubyIsAbove )
457 : {
458 0 : sal_Bool bTmp = *(sal_Bool*)pProps[nProp].Value.getValue();
459 0 : if(!nRuby)
460 0 : nPosition = bTmp ? 0 : 1;
461 0 : else if( (!nPosition && !bTmp) || (nPosition == 1 && bTmp) )
462 0 : nPosition = -2;
463 : }
464 0 : if(bCharStyleEqual && pProps[nProp].Name == cRubyCharStyleName )
465 : {
466 0 : pProps[nProp].Value >>= sTmp;
467 0 : if(!nRuby)
468 0 : sCharStyleName = sTmp;
469 0 : else if(sCharStyleName != sTmp)
470 0 : bCharStyleEqual = false;
471 : }
472 : }
473 : }
474 0 : if(!nLen)
475 : {
476 : //enable selection if the ruby list is empty
477 0 : nAdjust = 0;
478 0 : nPosition = 0;
479 : }
480 0 : if(nAdjust > -1)
481 0 : m_pAdjustLB->SelectEntryPos(nAdjust);
482 : else
483 0 : m_pAdjustLB->SetNoSelection();
484 0 : if(nPosition > -1)
485 0 : m_pPositionLB->SelectEntryPos(nPosition ? 1 : 0);
486 0 : if(!nLen || (bCharStyleEqual && sCharStyleName.isEmpty()))
487 0 : sCharStyleName = cRubies;
488 0 : if(!sCharStyleName.isEmpty())
489 : {
490 0 : for(sal_uInt16 i = 0; i < m_pCharStyleLB->GetEntryCount(); i++)
491 : {
492 0 : const OUString* pCoreName = (const OUString*)m_pCharStyleLB->GetEntryData(i);
493 0 : if(pCoreName && sCharStyleName == *pCoreName)
494 : {
495 0 : m_pCharStyleLB->SelectEntryPos(i);
496 0 : break;
497 : }
498 : }
499 : }
500 : else
501 0 : m_pCharStyleLB->SetNoSelection();
502 :
503 0 : ScrollHdl_Impl(m_pScrollSB);
504 0 : }
505 :
506 0 : void SvxRubyDialog::GetCurrentText(String& rBase, String& rRuby)
507 : {
508 0 : rBase = aEditArr[nCurrentEdit * 2]->GetText();
509 0 : rRuby = aEditArr[nCurrentEdit * 2 + 1]->GetText();
510 0 : }
511 :
512 0 : IMPL_LINK(SvxRubyDialog, ScrollHdl_Impl, ScrollBar*, pScroll)
513 : {
514 0 : long nPos = pScroll->GetThumbPos();
515 0 : if(GetLastPos() != nPos)
516 : {
517 0 : GetText();
518 : }
519 0 : SetText(nPos++, *m_pLeft1ED, *m_pRight1ED);
520 0 : SetText(nPos++, *m_pLeft2ED, *m_pRight2ED);
521 0 : SetText(nPos++, *m_pLeft3ED, *m_pRight3ED);
522 0 : SetText(nPos, *m_pLeft4ED, *m_pRight4ED);
523 0 : SetLastPos(nPos - 3);
524 0 : m_pPreviewWin->Invalidate();
525 0 : return 0;
526 : }
527 :
528 0 : IMPL_LINK_NOARG(SvxRubyDialog, ApplyHdl_Impl)
529 : {
530 0 : const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
531 0 : if(!aRubyValues.getLength())
532 : {
533 0 : AssertOneEntry();
534 0 : PositionHdl_Impl(m_pPositionLB);
535 0 : AdjustHdl_Impl(m_pAdjustLB);
536 0 : CharStyleHdl_Impl(m_pCharStyleLB);
537 : }
538 0 : GetText();
539 : //reset all edit fields - SaveValue is called
540 0 : ScrollHdl_Impl(m_pScrollSB);
541 :
542 0 : Reference<XRubySelection> xSelection = pImpl->GetRubySelection();
543 0 : if(IsModified() && xSelection.is())
544 : {
545 : try
546 : {
547 0 : xSelection->setRubyList(aRubyValues, false);
548 : }
549 0 : catch (const Exception&)
550 : {
551 : OSL_FAIL("Exception caught");
552 : }
553 : }
554 0 : return 0;
555 : }
556 :
557 0 : IMPL_LINK_NOARG(SvxRubyDialog, CloseHdl_Impl)
558 : {
559 0 : Close();
560 0 : return 0;
561 : }
562 :
563 0 : IMPL_LINK_NOARG(SvxRubyDialog, StylistHdl_Impl)
564 : {
565 0 : SfxPoolItem* pState = 0;
566 0 : SfxItemState eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
567 0 : if(eState <= SFX_ITEM_SET || !pState || !((SfxBoolItem*)pState)->GetValue())
568 : {
569 : pBindings->GetDispatcher()->Execute( SID_STYLE_DESIGNER,
570 : SFX_CALLMODE_ASYNCHRON |
571 0 : SFX_CALLMODE_RECORD);
572 : }
573 0 : delete pState;
574 0 : return 0;
575 : }
576 :
577 0 : IMPL_LINK(SvxRubyDialog, AdjustHdl_Impl, ListBox*, pBox)
578 : {
579 0 : AssertOneEntry();
580 0 : sal_Int16 nAdjust = pBox->GetSelectEntryPos();
581 0 : Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
582 0 : for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
583 : {
584 0 : Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
585 0 : PropertyValue* pProps = rProps.getArray();
586 0 : for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
587 : {
588 0 : if ( pProps[nProp].Name == cRubyAdjust )
589 0 : pProps[nProp].Value <<= nAdjust;
590 : }
591 0 : SetModified(sal_True);
592 : }
593 0 : m_pPreviewWin->Invalidate();
594 0 : return 0;
595 : }
596 :
597 0 : IMPL_LINK(SvxRubyDialog, PositionHdl_Impl, ListBox*, pBox)
598 : {
599 0 : AssertOneEntry();
600 0 : sal_Bool bAbove = !pBox->GetSelectEntryPos();
601 0 : const Type& rType = ::getBooleanCppuType();
602 0 : Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
603 0 : for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
604 : {
605 0 : Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
606 0 : PropertyValue* pProps = rProps.getArray();
607 0 : for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
608 : {
609 0 : if ( pProps[nProp].Name == cRubyIsAbove )
610 0 : pProps[nProp].Value.setValue(&bAbove, rType);
611 : }
612 0 : SetModified(sal_True);
613 : }
614 0 : m_pPreviewWin->Invalidate();
615 0 : return 0;
616 : }
617 :
618 0 : IMPL_LINK_NOARG(SvxRubyDialog, CharStyleHdl_Impl)
619 : {
620 0 : AssertOneEntry();
621 0 : OUString sStyleName;
622 0 : if(LISTBOX_ENTRY_NOTFOUND != m_pCharStyleLB->GetSelectEntryPos())
623 0 : sStyleName = *(OUString*) m_pCharStyleLB->GetEntryData(m_pCharStyleLB->GetSelectEntryPos());
624 0 : Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
625 0 : for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
626 : {
627 0 : Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
628 0 : PropertyValue* pProps = rProps.getArray();
629 0 : for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
630 : {
631 0 : if ( pProps[nProp].Name == cRubyCharStyleName )
632 : {
633 0 : pProps[nProp].Value <<= sStyleName;
634 : }
635 : }
636 0 : SetModified(sal_True);
637 : }
638 0 : return 0;
639 : }
640 :
641 0 : IMPL_LINK(SvxRubyDialog, EditModifyHdl_Impl, Edit*, pEdit)
642 : {
643 0 : for(sal_uInt16 i = 0; i < 8; i++)
644 : {
645 0 : if(pEdit == aEditArr[i])
646 : {
647 0 : nCurrentEdit = i / 2;
648 0 : break;
649 : }
650 : }
651 0 : m_pPreviewWin->Invalidate();
652 0 : return 0;
653 : }
654 :
655 0 : IMPL_LINK(SvxRubyDialog, EditScrollHdl_Impl, sal_Int32*, pParam)
656 : {
657 0 : long nRet = 0;
658 0 : if(m_pScrollSB->IsEnabled())
659 : {
660 : //scroll forward
661 0 : if(*pParam > 0 && (aEditArr[7]->HasFocus() || aEditArr[6]->HasFocus() ))
662 : {
663 0 : if(m_pScrollSB->GetRangeMax() > m_pScrollSB->GetThumbPos())
664 : {
665 0 : m_pScrollSB->SetThumbPos(m_pScrollSB->GetThumbPos() + 1);
666 0 : aEditArr[6]->GrabFocus();
667 0 : nRet = 1;
668 : }
669 : }
670 : //scroll backward
671 0 : else if(m_pScrollSB->GetThumbPos() && (aEditArr[0]->HasFocus()||aEditArr[1]->HasFocus()) )
672 : {
673 0 : m_pScrollSB->SetThumbPos(m_pScrollSB->GetThumbPos() - 1);
674 0 : aEditArr[1]->GrabFocus();
675 0 : nRet = 1;
676 : }
677 0 : if(nRet)
678 0 : ScrollHdl_Impl(m_pScrollSB);
679 : }
680 0 : return nRet;
681 : }
682 :
683 0 : IMPL_LINK(SvxRubyDialog, EditJumpHdl_Impl, sal_Int32*, pParam)
684 : {
685 0 : sal_uInt16 nIndex = USHRT_MAX;
686 0 : for(sal_uInt16 i = 0; i < 8; i++)
687 : {
688 0 : if(aEditArr[i]->HasFocus())
689 0 : nIndex = i;
690 : }
691 0 : if(nIndex < 8)
692 : {
693 0 : if(*pParam > 0)
694 : {
695 0 : if(nIndex < 6)
696 0 : aEditArr[nIndex + 2]->GrabFocus();
697 0 : else if( EditScrollHdl_Impl(pParam))
698 0 : aEditArr[nIndex]->GrabFocus();
699 : }
700 : else
701 : {
702 0 : if(nIndex > 1)
703 0 : aEditArr[nIndex - 2]->GrabFocus();
704 0 : else if( EditScrollHdl_Impl(pParam))
705 0 : aEditArr[nIndex]->GrabFocus();
706 : }
707 : }
708 0 : return 0;
709 : };
710 :
711 0 : void SvxRubyDialog::AssertOneEntry()
712 : {
713 0 : pImpl->AssertOneEntry();
714 0 : }
715 :
716 : // ----------------------------------------------------------------------------
717 :
718 0 : void SvxRubyDialog::UpdateColors( void )
719 : {
720 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
721 0 : svtools::ColorConfig aColorConfig;
722 :
723 0 : Font aFnt( m_pPreviewWin->GetFont() );
724 :
725 0 : Color aNewTextCol( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
726 0 : Color aNewFillCol( rStyleSettings.GetWindowColor() );
727 :
728 0 : if( aNewFillCol != aFnt.GetFillColor() || aNewTextCol != aFnt.GetColor() )
729 : {
730 0 : aFnt.SetFillColor( aNewFillCol );
731 0 : aFnt.SetColor( aNewTextCol );
732 0 : m_pPreviewWin->SetFont( aFnt );
733 :
734 0 : m_pPreviewWin->Invalidate();
735 0 : }
736 0 : }
737 :
738 : // ----------------------------------------------------------------------------
739 :
740 0 : void SvxRubyDialog::DataChanged( const DataChangedEvent& rDCEvt )
741 : {
742 0 : SfxModelessDialog::DataChanged( rDCEvt );
743 :
744 0 : if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
745 0 : UpdateColors();
746 0 : }
747 :
748 0 : void SvxRubyDialog::EnableControls(bool bEnable)
749 : {
750 0 : get_content_area()->Enable(bEnable);
751 0 : m_pApplyPB->Enable(bEnable);
752 0 : }
753 :
754 0 : RubyPreview::RubyPreview(Window *pParent)
755 : : Window(pParent, WB_BORDER)
756 0 : , m_pParentDlg(NULL)
757 : {
758 0 : SetMapMode(MAP_TWIP);
759 0 : SetBorderStyle( WINDOW_BORDER_MONO );
760 0 : }
761 :
762 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeRubyPreview(Window *pParent, VclBuilder::stringmap &)
763 : {
764 0 : return new RubyPreview(pParent);
765 : }
766 :
767 0 : void RubyPreview::Paint( const Rectangle& /* rRect */ )
768 : {
769 0 : Size aWinSize = GetOutputSize();
770 :
771 0 : Font aSaveFont = GetFont();
772 0 : aSaveFont.SetHeight(aWinSize.Height() / 4);
773 0 : SetFont(aSaveFont);
774 :
775 0 : Rectangle aRect(Point(0, 0), aWinSize);
776 0 : SetLineColor();
777 0 : SetFillColor( aSaveFont.GetFillColor() );
778 0 : DrawRect(aRect);
779 :
780 0 : String sBaseText, sRubyText;
781 0 : m_pParentDlg->GetCurrentText(sBaseText, sRubyText);
782 :
783 0 : long nTextHeight = GetTextHeight();
784 0 : long nBaseWidth = GetTextWidth(sBaseText);
785 :
786 0 : Font aRubyFont(aSaveFont);
787 0 : aRubyFont.SetHeight(aRubyFont.GetHeight() * 70 / 100);
788 0 : SetFont(aRubyFont);
789 0 : long nRubyWidth = GetTextWidth(sRubyText);
790 0 : SetFont(aSaveFont);
791 :
792 0 : sal_uInt16 nAdjust = m_pParentDlg->m_pAdjustLB->GetSelectEntryPos();
793 : //use center if no adjustment is available
794 0 : if(nAdjust > 4)
795 0 : nAdjust = 1;
796 :
797 : //which part is stretched ?
798 0 : bool bRubyStretch = nBaseWidth >= nRubyWidth;
799 :
800 0 : long nCenter = aWinSize.Width() / 2;
801 0 : long nLeftStart = nCenter - (bRubyStretch ? (nBaseWidth / 2) : (nRubyWidth / 2));
802 0 : long nRightEnd = nCenter + (bRubyStretch ? (nBaseWidth / 2) : (nRubyWidth / 2));
803 :
804 0 : long nYRuby = aWinSize.Height() / 4 - nTextHeight / 2;
805 0 : long nYBase = aWinSize.Height() * 3 / 4 - nTextHeight / 2;
806 :
807 : //use above also if no selection is set
808 0 : bool bAbove = m_pParentDlg->m_pPositionLB->GetSelectEntryPos() != 1;
809 0 : if(!bAbove)
810 : {
811 0 : long nTmp = nYRuby;
812 0 : nYRuby = nYBase;
813 0 : nYBase = nTmp;
814 : }
815 : long nYOutput, nOutTextWidth;
816 0 : String sOutputText;
817 :
818 :
819 0 : if(bRubyStretch)
820 : {
821 0 : DrawText( Point( nLeftStart , nYBase), sBaseText );
822 0 : nYOutput = nYRuby;
823 0 : sOutputText = sRubyText;
824 0 : nOutTextWidth = nRubyWidth;
825 0 : SetFont(aRubyFont);
826 : }
827 : else
828 : {
829 0 : SetFont(aRubyFont);
830 0 : DrawText( Point( nLeftStart , nYRuby), sRubyText );
831 0 : nYOutput = nYBase;
832 0 : sOutputText = sBaseText;
833 0 : nOutTextWidth = nBaseWidth;
834 0 : SetFont(aSaveFont);
835 : }
836 :
837 0 : switch(nAdjust)
838 : {
839 : case RubyAdjust_LEFT:
840 0 : DrawText( Point( nLeftStart , nYOutput), sOutputText );
841 0 : break;
842 : case RubyAdjust_RIGHT:
843 0 : DrawText( Point( nRightEnd - nOutTextWidth, nYOutput), sOutputText );
844 0 : break;
845 : case RubyAdjust_INDENT_BLOCK:
846 : {
847 0 : long nCharWidth = GetTextWidth(OUString("X"));
848 0 : if(nOutTextWidth < (nRightEnd - nLeftStart - nCharWidth))
849 : {
850 0 : nCharWidth /= 2;
851 0 : nLeftStart += nCharWidth;
852 0 : nRightEnd -= nCharWidth;
853 : }
854 : }
855 : // no break!
856 : case RubyAdjust_BLOCK:
857 0 : if(sOutputText.Len() > 1)
858 : {
859 0 : xub_StrLen nCount = sOutputText.Len();
860 0 : long nSpace = ((nRightEnd - nLeftStart) - GetTextWidth(sOutputText)) / (nCount - 1);
861 0 : for(xub_StrLen i = 0; i < nCount; i++)
862 : {
863 0 : OUString sChar(sOutputText.GetChar(i));
864 0 : DrawText( Point( nLeftStart , nYOutput), sChar);
865 0 : long nCharWidth = GetTextWidth(sChar);
866 0 : nLeftStart += nCharWidth + nSpace;
867 0 : }
868 0 : break;
869 : }
870 : //no break;
871 : case RubyAdjust_CENTER:
872 0 : DrawText( Point( nCenter - nOutTextWidth / 2 , nYOutput), sOutputText );
873 0 : break;
874 : }
875 0 : SetFont(aSaveFont);
876 0 : }
877 :
878 0 : Size RubyPreview::GetOptimalSize() const
879 : {
880 0 : return LogicToPixel(Size(215, 50), MapMode(MAP_APPFONT));
881 : }
882 :
883 0 : void RubyEdit::GetFocus()
884 : {
885 0 : GetModifyHdl().Call(this);
886 0 : Edit::GetFocus();
887 0 : }
888 :
889 0 : long RubyEdit::PreNotify( NotifyEvent& rNEvt )
890 : {
891 0 : long nHandled = 0;
892 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
893 : {
894 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
895 0 : const KeyCode& rKeyCode = pKEvt->GetKeyCode();
896 0 : sal_uInt16 nMod = rKeyCode.GetModifier();
897 0 : sal_uInt16 nCode = rKeyCode.GetCode();
898 0 : if( nCode == KEY_TAB && (!nMod || KEY_SHIFT == nMod))
899 : {
900 0 : sal_Int32 nParam = KEY_SHIFT == nMod ? -1 : 1;
901 0 : if(aScrollHdl.IsSet() && aScrollHdl.Call(&nParam))
902 0 : nHandled = 1;
903 : }
904 0 : else if(KEY_UP == nCode || KEY_DOWN == nCode)
905 : {
906 0 : sal_Int32 nParam = KEY_UP == nCode ? -1 : 1;
907 0 : aJumpHdl.Call(&nParam);
908 : }
909 : }
910 0 : if(!nHandled)
911 0 : nHandled = Edit::PreNotify(rNEvt);
912 0 : return nHandled;
913 : }
914 :
915 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeRubyEdit(Window *pParent, VclBuilder::stringmap &)
916 : {
917 0 : return new RubyEdit(pParent);
918 216 : }
919 :
920 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|