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