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