Update ooo320-m1
[ooovba.git] / svx / source / dialog / rubydialog.cxx
blob5e67d87e284508c67bfeb8f547187b5f7ff0c8fa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rubydialog.cxx,v $
10 * $Revision: 1.30 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <rubydialog.hxx>
34 #include <tools/shl.hxx>
35 #include <svx/dialmgr.hxx>
36 #include <svx/dialogs.hrc>
37 #include <rubydialog.hrc>
38 #include <sfx2/app.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <svtools/eitem.hxx>
42 #include <com/sun/star/frame/XController.hpp>
43 #include <com/sun/star/style/XStyle.hpp>
44 #include <com/sun/star/text/XRubySelection.hpp>
45 #include <com/sun/star/beans/PropertyValues.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/XPropertySetInfo.hpp>
48 #include <com/sun/star/container/XNameContainer.hpp>
49 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
50 #include <com/sun/star/text/RubyAdjust.hpp>
51 #include <com/sun/star/view/XSelectionChangeListener.hpp>
52 #include <com/sun/star/view/XSelectionSupplier.hpp>
53 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
54 #include <cppuhelper/implbase1.hxx>
55 #endif
56 #include <svtools/colorcfg.hxx>
58 using namespace com::sun::star::uno;
59 using namespace com::sun::star::frame;
60 using namespace com::sun::star::text;
61 using namespace com::sun::star::beans;
62 using namespace com::sun::star::style;
63 using namespace com::sun::star::text;
64 using namespace com::sun::star::view;
65 using namespace com::sun::star::lang;
66 using namespace com::sun::star::container;
67 using rtl::OUString;
69 #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
71 SFX_IMPL_CHILDWINDOW( SvxRubyChildWindow, SID_RUBY_DIALOG );
73 static const sal_Char cRubyBaseText[] = "RubyBaseText";
74 static const sal_Char cRubyText[] = "RubyText";
75 static const sal_Char cCharacterStyles[] = "CharacterStyles";
76 static const sal_Char cRubyAdjust[] = "RubyAdjust";
77 static const sal_Char cRubyIsAbove[] = "RubyIsAbove";
78 static const sal_Char cDisplayName[] = "DisplayName";
79 static const sal_Char cRubyCharStyleName[] = "RubyCharStyleName";
80 static const sal_Char cRubies[] = "Rubies";
81 /* -----------------------------09.01.01 17:24--------------------------------
83 ---------------------------------------------------------------------------*/
84 SvxRubyChildWindow::SvxRubyChildWindow( Window* _pParent, USHORT nId,
85 SfxBindings* pBindings, SfxChildWinInfo* pInfo) :
86 SfxChildWindow(_pParent, nId)
88 pWindow = new SvxRubyDialog( pBindings, this, _pParent, SVX_RES( RID_SVXDLG_RUBY ) );
89 SvxRubyDialog* pDlg = (SvxRubyDialog*) pWindow;
91 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
92 pDlg->RollUp();
94 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
96 pDlg->Initialize( pInfo );
98 /* -----------------------------10.01.01 13:53--------------------------------
100 ---------------------------------------------------------------------------*/
101 SfxChildWinInfo SvxRubyChildWindow::GetInfo() const
103 return SfxChildWindow::GetInfo();
105 /* -----------------------------09.01.01 17:17--------------------------------
107 ---------------------------------------------------------------------------*/
108 class SvxRubyData_Impl : public cppu::WeakImplHelper1
109 < ::com::sun::star::view::XSelectionChangeListener >
111 Reference<XModel> xModel;
112 Reference<XRubySelection> xSelection;
113 Sequence<PropertyValues> aRubyValues;
114 Reference<XController> xController;
115 sal_Bool bHasSelectionChanged;
116 public:
117 SvxRubyData_Impl();
118 ~SvxRubyData_Impl();
120 void SetController(Reference<XController> xCtrl);
121 Reference<XModel> GetModel()
123 if(!xController.is())
124 xModel = 0;
125 else
126 xModel = xController->getModel();
127 return xModel;
129 sal_Bool HasSelectionChanged() const{return bHasSelectionChanged;}
130 Reference<XRubySelection> GetRubySelection()
132 xSelection = Reference<XRubySelection>(xController, UNO_QUERY);
133 return xSelection;
135 void UpdateRubyValues(sal_Bool bAutoUpdate)
137 if(!xSelection.is())
138 aRubyValues.realloc(0);
139 else
140 aRubyValues = xSelection->getRubyList(bAutoUpdate);
141 bHasSelectionChanged = sal_False;
143 Sequence<PropertyValues>& GetRubyValues() {return aRubyValues;}
144 void AssertOneEntry();
146 virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (RuntimeException);
147 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (RuntimeException);
150 //-----------------------------------------------------------------------------
151 SvxRubyData_Impl::SvxRubyData_Impl() :
152 bHasSelectionChanged(sal_False)
155 //-----------------------------------------------------------------------------
156 SvxRubyData_Impl::~SvxRubyData_Impl()
159 //-----------------------------------------------------------------------------
160 void SvxRubyData_Impl::SetController(Reference<XController> xCtrl)
162 if(xCtrl.get() != xController.get())
166 Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
167 if(xSelSupp.is())
168 xSelSupp->removeSelectionChangeListener(this);
170 bHasSelectionChanged = sal_True;
171 xController = xCtrl;
172 xSelSupp = Reference<XSelectionSupplier>(xController, UNO_QUERY);
173 if(xSelSupp.is())
174 xSelSupp->addSelectionChangeListener(this);
176 catch(Exception&)
180 //-----------------------------------------------------------------------------
181 void SvxRubyData_Impl::selectionChanged( const EventObject& ) throw (RuntimeException)
183 bHasSelectionChanged = sal_True;
185 //-----------------------------------------------------------------------------
186 void SvxRubyData_Impl::disposing( const EventObject&) throw (RuntimeException)
190 Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
191 if(xSelSupp.is())
192 xSelSupp->removeSelectionChangeListener(this);
194 catch(Exception&)
196 xController = 0;
198 //-----------------------------------------------------------------------------
199 void SvxRubyData_Impl::AssertOneEntry()
201 //create one entry
202 if(!aRubyValues.getLength())
204 aRubyValues.realloc(1);
205 Sequence<PropertyValue>& rValues = aRubyValues.getArray()[0];
206 rValues.realloc(5);
207 PropertyValue* pValues = rValues.getArray();
208 pValues[0].Name = C2U(cRubyBaseText);
209 pValues[1].Name = C2U(cRubyText);
210 pValues[2].Name = C2U(cRubyAdjust);
211 pValues[3].Name = C2U(cRubyIsAbove);
212 pValues[4].Name = C2U(cRubyCharStyleName);
215 /* ---------------------------------------------------------------------------
217 ---------------------------------------------------------------------------*/
218 SvxRubyDialog::SvxRubyDialog( SfxBindings *pBind, SfxChildWindow *pCW,
219 Window* _pParent, const ResId& rResId ) :
220 SfxModelessDialog( pBind, pCW, _pParent, rResId ),
221 aLeftFT(this, ResId(FT_LEFT,*rResId.GetResMgr() )),
222 aLeft1ED(this, ResId(ED_LEFT_1,*rResId.GetResMgr() )),
223 aRightFT(this, ResId(FT_RIGHT,*rResId.GetResMgr() )),
224 aRight1ED(this, ResId(ED_RIGHT_1,*rResId.GetResMgr() )),
225 aLeft2ED(this, ResId(ED_LEFT_2,*rResId.GetResMgr() )),
226 aRight2ED(this, ResId(ED_RIGHT_2,*rResId.GetResMgr() )),
227 aLeft3ED(this, ResId(ED_LEFT_3,*rResId.GetResMgr() )),
228 aRight3ED(this, ResId(ED_RIGHT_3,*rResId.GetResMgr() )),
229 aLeft4ED(this, ResId(ED_LEFT_4,*rResId.GetResMgr() )),
230 aRight4ED(this, ResId(ED_RIGHT_4,*rResId.GetResMgr() )),
231 aScrollSB(this, ResId(SB_SCROLL,*rResId.GetResMgr() )),
232 aAutoDetectionCB(this, ResId(CB_AUTO_DETECT,*rResId.GetResMgr() )),
233 aAdjustFT(this, ResId(FT_ADJUST,*rResId.GetResMgr() )),
234 aAdjustLB(this, ResId(LB_ADJUST,*rResId.GetResMgr() )),
235 aPositionFT(this, ResId(FT_POSITION,*rResId.GetResMgr() )),
236 aPositionLB(this, ResId(LB_POSITION,*rResId.GetResMgr() )),
237 aCharStyleFT(this, ResId(FT_CHAR_STYLE,*rResId.GetResMgr() )),
238 aCharStyleLB(this, ResId(LB_CHAR_STYLE,*rResId.GetResMgr() )),
239 aStylistPB(this, ResId(PB_STYLIST,*rResId.GetResMgr() )),
240 aPreviewFT(this, ResId(FT_PREVIEW,*rResId.GetResMgr() )),
241 aPreviewWin(*this, ResId(WIN_PREVIEW,*rResId.GetResMgr() )),
242 aApplyPB(this, ResId(PB_APPLY,*rResId.GetResMgr() )),
243 aClosePB(this, ResId(PB_CLOSE,*rResId.GetResMgr() )),
244 aHelpPB(this, ResId(PB_HELP,*rResId.GetResMgr() )),
245 nLastPos(0),
246 nCurrentEdit(0),
247 bModified(FALSE),
248 pBindings(pBind)
250 xImpl = pImpl = new SvxRubyData_Impl;
251 FreeResource();
252 //#85638# automatic detection not yet available
253 aAutoDetectionCB.Hide();
254 aEditArr[0] = &aLeft1ED; aEditArr[1] = &aRight1ED;
255 aEditArr[2] = &aLeft2ED; aEditArr[3] = &aRight2ED;
256 aEditArr[4] = &aLeft3ED; aEditArr[5] = &aRight3ED;
257 aEditArr[6] = &aLeft4ED; aEditArr[7] = &aRight4ED;
259 aApplyPB.SetClickHdl(LINK(this, SvxRubyDialog, ApplyHdl_Impl));
260 aClosePB.SetClickHdl(LINK(this, SvxRubyDialog, CloseHdl_Impl));
261 aStylistPB.SetClickHdl(LINK(this, SvxRubyDialog, StylistHdl_Impl));
262 aAutoDetectionCB.SetClickHdl(LINK(this, SvxRubyDialog, AutomaticHdl_Impl));
263 aAdjustLB.SetSelectHdl(LINK(this, SvxRubyDialog, AdjustHdl_Impl));
264 aPositionLB.SetSelectHdl(LINK(this, SvxRubyDialog, PositionHdl_Impl));
265 aCharStyleLB.SetSelectHdl(LINK(this, SvxRubyDialog, CharStyleHdl_Impl));
267 Link aScrLk(LINK(this, SvxRubyDialog, ScrollHdl_Impl));
268 aScrollSB.SetScrollHdl( aScrLk );
269 aScrollSB.SetEndScrollHdl( aScrLk );
271 Link aEditLk(LINK(this, SvxRubyDialog, EditModifyHdl_Impl));
272 Link aScrollLk(LINK(this, SvxRubyDialog, EditScrollHdl_Impl));
273 Link aJumpLk(LINK(this, SvxRubyDialog, EditJumpHdl_Impl));
274 for(USHORT i = 0; i < 8; i++)
276 aEditArr[i]->SetModifyHdl(aEditLk);
277 aEditArr[i]->SetJumpHdl(aJumpLk);
278 if(!i || 7 == i)
279 aEditArr[i]->SetScrollHdl(aScrollLk);
282 UpdateColors();
284 /* -----------------------------09.01.01 17:17--------------------------------
286 ---------------------------------------------------------------------------*/
287 SvxRubyDialog::~SvxRubyDialog()
289 ClearCharStyleList();
290 EventObject aEvent;
291 xImpl->disposing(aEvent);
293 /* -----------------------------01.02.01 10:29--------------------------------
295 ---------------------------------------------------------------------------*/
296 void SvxRubyDialog::ClearCharStyleList()
298 for(USHORT i = 0; i < aCharStyleLB.GetEntryCount(); i++)
300 void* pData = aCharStyleLB.GetEntryData(i);
301 delete (OUString*)pData;
303 aCharStyleLB.Clear();
305 /* -----------------------------09.01.01 17:17--------------------------------
307 ---------------------------------------------------------------------------*/
308 BOOL SvxRubyDialog::Close()
310 pBindings->GetDispatcher()->Execute( SID_RUBY_DIALOG,
311 SFX_CALLMODE_ASYNCHRON |
312 SFX_CALLMODE_RECORD);
313 return TRUE;
315 /* -----------------------------29.01.01 15:26--------------------------------
317 ---------------------------------------------------------------------------*/
318 void SvxRubyDialog::Activate()
320 SfxModelessDialog::Activate();
321 SfxPoolItem* pState = 0;
322 SfxItemState eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
323 sal_Bool bEnable = (eState < SFX_ITEM_AVAILABLE) || !pState || !((SfxBoolItem*)pState)->GetValue();
324 aStylistPB.Enable(bEnable);
325 //get selection from current view frame
326 SfxViewFrame* pCurFrm = SfxViewFrame::Current();
327 Reference< XController > xCtrl = pCurFrm->GetFrame()->GetController();
328 pImpl->SetController(xCtrl);
329 if(pImpl->HasSelectionChanged())
332 Reference< XRubySelection > xRubySel = pImpl->GetRubySelection();
333 pImpl->UpdateRubyValues(aAutoDetectionCB.IsChecked());
334 EnableControls(xRubySel.is());
335 if(xRubySel.is())
337 Reference< XModel > xModel = pImpl->GetModel();
338 const String sCharStyleSelect = aCharStyleLB.GetSelectEntry();
339 ClearCharStyleList();
340 Reference<XStyleFamiliesSupplier> xSupplier(xModel, UNO_QUERY);
341 if(xSupplier.is())
345 Reference<XNameAccess> xFam = xSupplier->getStyleFamilies();
346 Any aChar = xFam->getByName(C2U(cCharacterStyles));
347 Reference<XNameContainer> xChar;
348 aChar >>= xChar;
349 Reference<XIndexAccess> xCharIdx(xChar, UNO_QUERY);
350 if(xCharIdx.is())
352 OUString sUIName(C2U(cDisplayName));
353 for(sal_Int32 nStyle = 0; nStyle < xCharIdx->getCount(); nStyle++)
355 Any aStyle = xCharIdx->getByIndex(nStyle);
356 Reference<XStyle> xStyle;
357 aStyle >>= xStyle;
358 Reference<XPropertySet> xPrSet(xStyle, UNO_QUERY);
359 OUString sName, sCoreName;
360 if(xPrSet.is())
362 Reference<XPropertySetInfo> xInfo = xPrSet->getPropertySetInfo();
363 if(xInfo->hasPropertyByName(sUIName))
365 Any aName = xPrSet->getPropertyValue(sUIName);
366 aName >>= sName;
369 Reference<XNamed> xNamed(xStyle, UNO_QUERY);
370 if(xNamed.is())
372 sCoreName = xNamed->getName();
373 if(!sName.getLength())
374 sName = sCoreName;
376 if(sName.getLength())
378 USHORT nPos = aCharStyleLB.InsertEntry(sName);
379 aCharStyleLB.SetEntryData( nPos, new OUString(sCoreName) );
385 catch(Exception&)
387 DBG_ERROR("exception in style access");
389 if(sCharStyleSelect.Len())
390 aCharStyleLB.SelectEntry(sCharStyleSelect);
392 aCharStyleLB.Enable(xSupplier.is());
393 aCharStyleFT.Enable(xSupplier.is());
395 Update();
396 aPreviewWin.Invalidate();
399 /* -----------------------------29.01.01 15:26--------------------------------
401 ---------------------------------------------------------------------------*/
402 void SvxRubyDialog::Deactivate()
404 SfxModelessDialog::Deactivate();
406 /* -----------------------------30.01.01 15:35--------------------------------
408 ---------------------------------------------------------------------------*/
409 void SvxRubyDialog::SetText(sal_Int32 nPos, Edit& rLeft, Edit& rRight)
411 OUString sLeft, sRight;
412 const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
413 BOOL bEnable = aRubyValues.getLength() > nPos;
414 if(bEnable)
416 const Sequence<PropertyValue> aProps = aRubyValues.getConstArray()[nPos];
417 const PropertyValue* pProps = aProps.getConstArray();
418 for(sal_Int32 nProp = 0; nProp < aProps.getLength(); nProp++)
420 if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyBaseText)))
421 pProps[nProp].Value >>= sLeft;
422 else if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyText)))
423 pProps[nProp].Value >>= sRight;
426 else if(!nPos)
427 bEnable = TRUE;
428 rLeft.Enable(bEnable);
429 rRight.Enable(bEnable);
430 rLeft.SetText(sLeft);
431 rRight.SetText(sRight);
432 rLeft.SaveValue();
433 rRight.SaveValue();
435 //-----------------------------------------------------------------------------
436 void SvxRubyDialog::GetText()
438 long nTempLastPos = GetLastPos();
439 for(int i = 0; i < 8; i+=2)
441 if(aEditArr[i]->IsEnabled() &&
442 (aEditArr[i]->GetText() != aEditArr[i]->GetSavedValue() ||
443 aEditArr[i + 1]->GetText() != aEditArr[i + 1]->GetSavedValue()))
445 Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
446 DBG_ASSERT(aRubyValues.getLength() > (i / 2 + nTempLastPos), "wrong index" );
447 SetModified(TRUE);
448 Sequence<PropertyValue> &rProps = aRubyValues.getArray()[i / 2 + nTempLastPos];
449 PropertyValue* pProps = rProps.getArray();
450 for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
452 if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyBaseText)))
453 pProps[nProp].Value <<= OUString(aEditArr[i]->GetText());
454 else if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyText)))
455 pProps[nProp].Value <<= OUString(aEditArr[i + 1]->GetText());
460 //-----------------------------------------------------------------------------
461 void SvxRubyDialog::Update()
463 const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
464 sal_Int32 nLen = aRubyValues.getLength();
465 aScrollSB.Enable(nLen > 4);
466 aScrollSB.SetRange( Range(0, nLen > 4 ? nLen - 4 : 0));
467 aScrollSB.SetThumbPos(0);
468 SetLastPos(0);
469 SetModified(FALSE);
471 sal_Int16 nAdjust = -1;
472 sal_Int16 nPosition = -1;
473 OUString sCharStyleName, sTmp;
474 sal_Bool bCharStyleEqual = sal_True;
475 for(sal_Int32 nRuby = 0; nRuby < nLen; nRuby++)
477 const Sequence<PropertyValue> &rProps = aRubyValues.getConstArray()[nRuby];
478 const PropertyValue* pProps = rProps.getConstArray();
479 for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
481 if(nAdjust > -2 &&
482 pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyAdjust)))
484 sal_Int16 nTmp = sal_Int16();
485 pProps[nProp].Value >>= nTmp;
486 if(!nRuby)
487 nAdjust = nTmp;
488 else if(nAdjust != nTmp)
489 nAdjust = -2;
491 if(nPosition > -2 &&
492 pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyIsAbove)))
494 sal_Bool bTmp = *(sal_Bool*)pProps[nProp].Value.getValue();
495 if(!nRuby)
496 nPosition = bTmp ? 0 : 1;
497 else if( (!nPosition && !bTmp) || (nPosition == 1 && bTmp) )
498 nPosition = -2;
500 if(bCharStyleEqual &&
501 pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyCharStyleName)))
503 pProps[nProp].Value >>= sTmp;
504 if(!nRuby)
505 sCharStyleName = sTmp;
506 else if(sCharStyleName != sTmp)
507 bCharStyleEqual = sal_False;
511 if(!nLen)
513 //enable selection if the ruby list is empty
514 nAdjust = 0;
515 nPosition = 0;
517 if(nAdjust > -1)
518 aAdjustLB.SelectEntryPos(nAdjust);
519 else
520 aAdjustLB.SetNoSelection();
521 if(nPosition > -1)
522 aPositionLB.SelectEntryPos(nPosition ? 1 : 0);
523 if(!nLen || (bCharStyleEqual && !sCharStyleName.getLength()))
524 sCharStyleName = C2U(cRubies);
525 if(sCharStyleName.getLength())
527 for(USHORT i = 0; i < aCharStyleLB.GetEntryCount(); i++)
529 const OUString* pCoreName = (const OUString*)aCharStyleLB.GetEntryData(i);
530 if(pCoreName && sCharStyleName == *pCoreName)
532 aCharStyleLB.SelectEntryPos(i);
533 break;
537 else
538 aCharStyleLB.SetNoSelection();
540 ScrollHdl_Impl(&aScrollSB);
542 /* -----------------------------16.02.01 14:01--------------------------------
544 ---------------------------------------------------------------------------*/
545 void SvxRubyDialog::GetCurrentText(String& rBase, String& rRuby)
547 rBase = aEditArr[nCurrentEdit * 2]->GetText();
548 rRuby = aEditArr[nCurrentEdit * 2 + 1]->GetText();
550 /* -----------------------------31.01.01 14:09--------------------------------
552 ---------------------------------------------------------------------------*/
553 IMPL_LINK(SvxRubyDialog, ScrollHdl_Impl, ScrollBar*, pScroll)
555 long nPos = pScroll->GetThumbPos();
556 if(GetLastPos() != nPos)
558 GetText();
560 SetText(nPos++, aLeft1ED, aRight1ED);
561 SetText(nPos++, aLeft2ED, aRight2ED);
562 SetText(nPos++, aLeft3ED, aRight3ED);
563 SetText(nPos, aLeft4ED, aRight4ED);
564 SetLastPos(nPos - 3);
565 aPreviewWin.Invalidate();
566 return 0;
568 /* -----------------------------30.01.01 14:48--------------------------------
570 ---------------------------------------------------------------------------*/
571 IMPL_LINK(SvxRubyDialog, ApplyHdl_Impl, PushButton*, EMPTYARG)
573 const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
574 if(!aRubyValues.getLength())
576 AssertOneEntry();
577 PositionHdl_Impl(&aPositionLB);
578 AdjustHdl_Impl(&aAdjustLB);
579 CharStyleHdl_Impl(&aCharStyleLB);
581 GetText();
582 //reset all edit fields - SaveValue is called
583 ScrollHdl_Impl(&aScrollSB);
585 Reference<XRubySelection> xSelection = pImpl->GetRubySelection();
586 if(IsModified() && xSelection.is())
590 xSelection->setRubyList(aRubyValues, aAutoDetectionCB.IsChecked());
592 catch(Exception& )
594 DBG_ERROR("Exception caught");
597 return 0;
599 /* -----------------------------29.01.01 09:38--------------------------------
601 ---------------------------------------------------------------------------*/
602 IMPL_LINK(SvxRubyDialog, CloseHdl_Impl, PushButton*, EMPTYARG)
604 Close();
605 return 0;
607 /* -----------------------------29.01.01 15:10--------------------------------
609 ---------------------------------------------------------------------------*/
610 IMPL_LINK(SvxRubyDialog, StylistHdl_Impl, PushButton*, EMPTYARG)
612 SfxPoolItem* pState = 0;
613 SfxItemState eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
614 if(eState <= SFX_ITEM_SET || !pState || !((SfxBoolItem*)pState)->GetValue())
616 pBindings->GetDispatcher()->Execute( SID_STYLE_DESIGNER,
617 SFX_CALLMODE_ASYNCHRON |
618 SFX_CALLMODE_RECORD);
620 return 0;
622 /* -----------------------------30.01.01 15:32--------------------------------
624 ---------------------------------------------------------------------------*/
625 IMPL_LINK(SvxRubyDialog, AutomaticHdl_Impl, CheckBox*, pBox)
627 pImpl->UpdateRubyValues(pBox->IsChecked());
628 Update();
629 return 0;
631 /* -----------------------------31.01.01 16:37--------------------------------
633 ---------------------------------------------------------------------------*/
634 IMPL_LINK(SvxRubyDialog, AdjustHdl_Impl, ListBox*, pBox)
636 AssertOneEntry();
637 sal_Int16 nAdjust = pBox->GetSelectEntryPos();
638 Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
639 for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
641 Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
642 PropertyValue* pProps = rProps.getArray();
643 for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
645 if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyAdjust)))
646 pProps[nProp].Value <<= nAdjust;
648 SetModified(TRUE);
650 aPreviewWin.Invalidate();
651 return 0;
653 /* -----------------------------01.06.01 10:24--------------------------------
655 ---------------------------------------------------------------------------*/
656 IMPL_LINK(SvxRubyDialog, PositionHdl_Impl, ListBox*, pBox)
658 AssertOneEntry();
659 sal_Bool bAbove = !pBox->GetSelectEntryPos();
660 const Type& rType = ::getBooleanCppuType();
661 Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
662 for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
664 Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
665 PropertyValue* pProps = rProps.getArray();
666 for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
668 if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyIsAbove)))
669 pProps[nProp].Value.setValue(&bAbove, rType);
671 SetModified(TRUE);
673 aPreviewWin.Invalidate();
674 return 0;
676 /* -----------------------------01.02.01 10:06--------------------------------
678 ---------------------------------------------------------------------------*/
679 IMPL_LINK(SvxRubyDialog, CharStyleHdl_Impl, ListBox*, EMPTYARG )
681 AssertOneEntry();
682 OUString sStyleName;
683 if(LISTBOX_ENTRY_NOTFOUND != aCharStyleLB.GetSelectEntryPos())
684 sStyleName = *(OUString*) aCharStyleLB.GetEntryData(aCharStyleLB.GetSelectEntryPos());
685 Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
686 for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
688 Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
689 PropertyValue* pProps = rProps.getArray();
690 for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
692 if(pProps[nProp].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cRubyCharStyleName)))
694 pProps[nProp].Value <<= sStyleName;
697 SetModified(TRUE);
699 return 0;
701 /* -----------------------------16.02.01 08:35--------------------------------
703 ---------------------------------------------------------------------------*/
704 IMPL_LINK(SvxRubyDialog, EditModifyHdl_Impl, Edit*, pEdit)
706 for(USHORT i = 0; i < 8; i++)
708 if(pEdit == aEditArr[i])
710 nCurrentEdit = i / 2;
711 break;
714 aPreviewWin.Invalidate();
715 return 0;
717 /* -----------------------------17.07.01 09:11--------------------------------
719 ---------------------------------------------------------------------------*/
720 IMPL_LINK(SvxRubyDialog, EditScrollHdl_Impl, sal_Int32*, pParam)
722 long nRet = 0;
723 if(aScrollSB.IsEnabled())
725 //scroll forward
726 if(*pParam > 0 && (aEditArr[7]->HasFocus() || aEditArr[6]->HasFocus() ))
728 if(aScrollSB.GetRangeMax() > aScrollSB.GetThumbPos())
730 aScrollSB.SetThumbPos(aScrollSB.GetThumbPos() + 1);
731 aEditArr[6]->GrabFocus();
732 nRet = 1;
735 //scroll backward
736 else if(aScrollSB.GetThumbPos() && (aEditArr[0]->HasFocus()||aEditArr[1]->HasFocus()) )
738 aScrollSB.SetThumbPos(aScrollSB.GetThumbPos() - 1);
739 aEditArr[1]->GrabFocus();
740 nRet = 1;
742 if(nRet)
743 ScrollHdl_Impl(&aScrollSB);
745 return nRet;
747 /* -----------------------------20.07.2001 15:18------------------------------
749 ---------------------------------------------------------------------------*/
750 IMPL_LINK(SvxRubyDialog, EditJumpHdl_Impl, sal_Int32*, pParam)
752 USHORT nIndex = USHRT_MAX;
753 for(USHORT i = 0; i < 8; i++)
755 if(aEditArr[i]->HasFocus())
756 nIndex = i;
758 if(nIndex < 8)
760 if(*pParam > 0)
762 if(nIndex < 6)
763 aEditArr[nIndex + 2]->GrabFocus();
764 else if( EditScrollHdl_Impl(pParam))
765 aEditArr[nIndex]->GrabFocus();
767 else
769 if(nIndex > 1)
770 aEditArr[nIndex - 2]->GrabFocus();
771 else if( EditScrollHdl_Impl(pParam))
772 aEditArr[nIndex]->GrabFocus();
775 return 0;
777 /* -----------------------------19.06.01 11:33--------------------------------
779 ---------------------------------------------------------------------------*/
780 void SvxRubyDialog::AssertOneEntry()
782 pImpl->AssertOneEntry();
785 // ----------------------------------------------------------------------------
787 void SvxRubyDialog::UpdateColors( void )
789 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
790 svtools::ColorConfig aColorConfig;
792 Font aFnt( aPreviewWin.GetFont() );
794 Color aNewTextCol( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
795 Color aNewFillCol( rStyleSettings.GetWindowColor() );
797 if( aNewFillCol != aFnt.GetFillColor() || aNewTextCol != aFnt.GetColor() )
799 aFnt.SetFillColor( aNewFillCol );
800 aFnt.SetColor( aNewTextCol );
801 aPreviewWin.SetFont( aFnt );
803 aPreviewWin.Invalidate();
807 // ----------------------------------------------------------------------------
809 void SvxRubyDialog::DataChanged( const DataChangedEvent& rDCEvt )
811 SfxModelessDialog::DataChanged( rDCEvt );
813 if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
814 UpdateColors();
817 /* -----------------------------29.01.01 15:44--------------------------------
819 ---------------------------------------------------------------------------*/
820 void lcl_MoveBox(long nOffset, Edit& rLeft, Edit& rRight)
822 Size aLeftSz(rLeft.GetSizePixel());
823 Point aRightPos(rRight.GetPosPixel());
824 Size aRightSz(rRight.GetSizePixel());
825 aLeftSz.Width() += nOffset;
826 aRightSz.Width() -= nOffset;
827 aRightPos.X() += nOffset;
828 rLeft.SetSizePixel(aLeftSz);
829 rRight.SetPosSizePixel(aRightPos, aRightSz);
832 /* -----------------------------16.02.01 08:09--------------------------------
834 ---------------------------------------------------------------------------*/
835 RubyPreview::RubyPreview(SvxRubyDialog& rParent, const ResId& rResId) :
836 Window(&rParent, rResId),
837 rParentDlg(rParent)
839 SetMapMode(MAP_TWIP);
840 Size aWinSize = GetOutputSize();
842 Font aFont = GetFont();
843 aFont.SetHeight(aWinSize.Height() / 4);
844 SetFont(aFont);
846 SetBorderStyle( WINDOW_BORDER_MONO );
848 /* -----------------------------29.01.01 14:05--------------------------------
850 ---------------------------------------------------------------------------*/
851 void RubyPreview::Paint( const Rectangle& /* rRect */ )
853 Font aRubyFont = GetFont();
854 Font aSaveFont(aRubyFont);
855 aRubyFont.SetHeight(aRubyFont.GetHeight() * 70 / 100);
857 Size aWinSize = GetOutputSize();
858 Rectangle aRect(Point(0, 0), aWinSize);
859 SetLineColor();
860 SetFillColor( aSaveFont.GetFillColor() );
861 DrawRect(aRect);
863 String sBaseText, sRubyText;
864 rParentDlg.GetCurrentText(sBaseText, sRubyText);
866 long nTextHeight = GetTextHeight();
867 long nBaseWidth = GetTextWidth(sBaseText);
868 SetFont(aRubyFont);
869 long nRubyWidth = GetTextWidth(sRubyText);
870 SetFont(aSaveFont);
872 USHORT nAdjust = rParentDlg.aAdjustLB.GetSelectEntryPos();
873 //use center if no adjustment is available
874 if(nAdjust > 4)
875 nAdjust = 1;
877 //which part is stretched ?
878 sal_Bool bRubyStretch = nBaseWidth >= nRubyWidth;
880 long nCenter = aWinSize.Width() / 2;
881 long nLeftStart = nCenter - (bRubyStretch ? (nBaseWidth / 2) : (nRubyWidth / 2));
882 long nRightEnd = nCenter + (bRubyStretch ? (nBaseWidth / 2) : (nRubyWidth / 2));
884 long nYRuby = aWinSize.Height() / 4 - nTextHeight / 2;
885 long nYBase = aWinSize.Height() * 3 / 4 - nTextHeight / 2;
887 //use above also if no selection is set
888 BOOL bAbove = rParentDlg.aPositionLB.GetSelectEntryPos() != 1;
889 if(!bAbove)
891 long nTmp = nYRuby;
892 nYRuby = nYBase;
893 nYBase = nTmp;
895 long nYOutput, nOutTextWidth;
896 String sOutputText;
899 if(bRubyStretch)
901 DrawText( Point( nLeftStart , nYBase), sBaseText );
902 nYOutput = nYRuby;
903 sOutputText = sRubyText;
904 nOutTextWidth = nRubyWidth;
905 SetFont(aRubyFont);
907 else
909 SetFont(aRubyFont);
910 DrawText( Point( nLeftStart , nYRuby), sRubyText );
911 nYOutput = nYBase;
912 sOutputText = sBaseText;
913 nOutTextWidth = nBaseWidth;
914 SetFont(aSaveFont);
917 switch(nAdjust)
919 case RubyAdjust_LEFT:
920 DrawText( Point( nLeftStart , nYOutput), sOutputText );
921 break;
922 case RubyAdjust_RIGHT:
923 DrawText( Point( nRightEnd - nOutTextWidth, nYOutput), sOutputText );
924 break;
925 case RubyAdjust_INDENT_BLOCK:
927 long nCharWidth = GetTextWidth(String::CreateFromAscii("X"));
928 if(nOutTextWidth < (nRightEnd - nLeftStart - nCharWidth))
930 nCharWidth /= 2;
931 nLeftStart += nCharWidth;
932 nRightEnd -= nCharWidth;
935 // no break!
936 case RubyAdjust_BLOCK:
937 if(sOutputText.Len() > 1)
939 xub_StrLen nCount = sOutputText.Len();
940 long nSpace = ((nRightEnd - nLeftStart) - GetTextWidth(sOutputText)) / (nCount - 1);
941 for(xub_StrLen i = 0; i < nCount; i++)
943 sal_Unicode cChar = sOutputText.GetChar(i);
944 DrawText( Point( nLeftStart , nYOutput), cChar);
945 long nCharWidth = GetTextWidth(cChar);
946 nLeftStart += nCharWidth + nSpace;
948 break;
950 //no break;
951 case RubyAdjust_CENTER:
952 DrawText( Point( nCenter - nOutTextWidth / 2 , nYOutput), sOutputText );
953 break;
955 SetFont(aSaveFont);
957 /* -----------------------------16.02.01 15:12--------------------------------
959 ---------------------------------------------------------------------------*/
960 void RubyEdit::GetFocus()
962 GetModifyHdl().Call(this);
963 Edit::GetFocus();
965 /* -----------------------------17.07.01 09:00--------------------------------
967 ---------------------------------------------------------------------------*/
968 long RubyEdit::PreNotify( NotifyEvent& rNEvt )
970 long nHandled = 0;
971 if ( rNEvt.GetType() == EVENT_KEYINPUT )
973 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
974 const KeyCode& rKeyCode = pKEvt->GetKeyCode();
975 USHORT nMod = rKeyCode.GetModifier();
976 USHORT nCode = rKeyCode.GetCode();
977 if( nCode == KEY_TAB && (!nMod || KEY_SHIFT == nMod))
979 sal_Int32 nParam = KEY_SHIFT == nMod ? -1 : 1;
980 if(aScrollHdl.IsSet() && aScrollHdl.Call(&nParam))
981 nHandled = 1;
983 else if(KEY_UP == nCode || KEY_DOWN == nCode)
985 sal_Int32 nParam = KEY_UP == nCode ? -1 : 1;
986 aJumpHdl.Call(&nParam);
989 if(!nHandled)
990 nHandled = Edit::PreNotify(rNEvt);
991 return nHandled;