1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
32 #include <sfx2/app.hxx>
33 #include <vcl/virdev.hxx>
34 #include <tools/string.hxx>
35 #include <tools/tenccvt.hxx>
36 #include <osl/thread.h>
38 #include <tools/stream.hxx>
40 #include "starmath.hrc"
42 #include "utility.hxx"
48 // return pointer to active SmViewShell, if this is not possible
50 //!! Since this method is based on the current focus it is somewhat
51 //!! unreliable and may return unexpected 0 pointers!
52 SmViewShell
* SmGetActiveView()
54 SfxViewShell
*pView
= SfxViewShell::Current();
55 return PTR_CAST(SmViewShell
, pView
);
59 ////////////////////////////////////////////////////////////
62 /**************************************************************************/
64 SmPickList::SmPickList(USHORT nInitSize
, USHORT nMaxSize
) :
65 SfxPtrArr((BYTE
) nInitSize
, 1)
71 SmPickList::~SmPickList()
77 SmPickList
& SmPickList::operator=(const SmPickList
& rList
)
83 for (nPos
= 0; nPos
< rList
.Count(); nPos
++)
84 InsertPtr(nPos
, CreateItem(rList
.Get(nPos
)));
90 void SmPickList::Insert(const void *pItem
)
93 InsertPtr(0, CreateItem(pItem
));
97 DestroyItem(GetPtr(nSize
));
103 void SmPickList::Update(const void *pItem
, const void *pNewItem
)
107 for (nPos
= 0; nPos
< Count(); nPos
++)
108 if (CompareItem(GetPtr(nPos
), pItem
))
110 DestroyItem(GetPtr(nPos
));
111 GetPtr(nPos
) = CreateItem(pNewItem
);
116 void SmPickList::Remove(const void *pItem
)
120 for (nPos
= 0; nPos
< Count(); nPos
++)
121 if (CompareItem(GetPtr(nPos
), pItem
))
123 DestroyItem(GetPtr(nPos
));
129 void SmPickList::Clear()
133 for (nPos
= 0; nPos
< Count(); nPos
++)
134 DestroyItem(GetPtr(nPos
));
136 RemovePtr(0, Count());
140 /**************************************************************************/
141 /**************************************************************************/
143 void * SmFontPickList::CreateItem(const String
& /*rString*/)
148 void * SmFontPickList::CreateItem(const void *pItem
)
150 return new Font(*((Font
*) pItem
));
153 void SmFontPickList::DestroyItem(void *pItem
)
155 delete (Font
*)pItem
;
158 BOOL
SmFontPickList::CompareItem(const void *pFirstItem
, const void *pSecondItem
) const
160 Font
*pFirstFont
, *pSecondFont
;
162 pFirstFont
= (Font
*)pFirstItem
;
163 pSecondFont
= (Font
*)pSecondItem
;
165 if (pFirstFont
->GetName() == pSecondFont
->GetName())
166 if ((pFirstFont
->GetFamily() == pSecondFont
->GetFamily()) &&
167 (pFirstFont
->GetCharSet() == pSecondFont
->GetCharSet()) &&
168 (pFirstFont
->GetWeight() == pSecondFont
->GetWeight()) &&
169 (pFirstFont
->GetItalic() == pSecondFont
->GetItalic()))
175 String
SmFontPickList::GetStringItem(void *pItem
)
179 const sal_Char
*pDelim
= ", ";
181 pFont
= (Font
*)pItem
;
183 aString
= pFont
->GetName();
185 if (IsItalic( *pFont
))
187 aString
.AppendAscii( pDelim
);
188 aString
+= String(SmResId(RID_FONTITALIC
));
190 if (IsBold( *pFont
)) // bold?
192 aString
.AppendAscii( pDelim
);
193 aString
+= String(SmResId(RID_FONTBOLD
));
199 void SmFontPickList::Insert(const Font
&rFont
)
201 SmPickList::Insert((void *)&rFont
);
204 void SmFontPickList::Update(const Font
&rFont
, const Font
&rNewFont
)
206 SmPickList::Update((void *)&rFont
, (void *)&rNewFont
);
209 void SmFontPickList::Remove(const Font
&rFont
)
211 SmPickList::Remove((void *)&rFont
);
215 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
217 Insert(rDialog
.GetFont());
220 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
222 rDialog
.SetFont(Get());
226 /**************************************************************************/
229 /**************************************************************************/
231 IMPL_LINK( SmFontPickListBox
, SelectHdl
, ListBox
*, /*pListBox*/ )
236 nPos
= GetSelectEntryPos();
240 SmFontPickList::Insert(Get(nPos
));
241 aString
= GetEntry(nPos
);
243 InsertEntry(aString
, 0);
252 SmFontPickListBox::SmFontPickListBox(Window
* pParent
, const ResId
& rResId
, USHORT nMax
) :
253 SmFontPickList(nMax
, nMax
),
254 ListBox(pParent
, rResId
)
256 SetSelectHdl(LINK(this, SmFontPickListBox
, SelectHdl
));
260 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
264 *(SmFontPickList
*)this = rList
;
266 for (nPos
= 0; nPos
< Count(); nPos
++)
267 InsertEntry(GetStringItem(GetPtr(nPos
)), nPos
);
270 SelectEntry(GetStringItem(GetPtr(0)));
275 void SmFontPickListBox::Insert(const Font
&rFont
)
277 SmFontPickList::Insert(rFont
);
279 RemoveEntry(GetStringItem(GetPtr(0)));
280 InsertEntry(GetStringItem(GetPtr(0)), 0);
281 SelectEntry(GetStringItem(GetPtr(0)));
283 while (GetEntryCount() > nSize
)
284 RemoveEntry(GetEntryCount() - 1);
290 void SmFontPickListBox::Update(const Font
&rFont
, const Font
&rNewFont
)
292 SmFontPickList::Update(rFont
, rNewFont
);
294 // ********************** hier fehlt noch was
300 void SmFontPickListBox::Remove(const Font
&rFont
)
302 SmFontPickList::Remove(rFont
);
304 // ********************** hier fehlt noch was
309 ////////////////////////////////////////
311 BOOL
IsItalic( const Font
&rFont
)
313 FontItalic eItalic
= rFont
.GetItalic();
314 // the code below leaves only _NONE and _DONTKNOW as not italic
315 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
319 BOOL
IsBold( const Font
&rFont
)
321 FontWeight eWeight
= rFont
.GetWeight();
322 return eWeight
!= WEIGHT_DONTKNOW
&& eWeight
> WEIGHT_NORMAL
;
326 void SmFace::Impl_Init()
328 SetSize( GetSize() );
329 SetTransparent( TRUE
);
330 SetAlign( ALIGN_BASELINE
);
331 SetColor( COL_AUTO
);
334 void SmFace::SetSize(const Size
& rSize
)
338 // check the requested size against minimum value
339 static int __READONLY_DATA nMinVal
= SmPtsTo100th_mm(2);
341 if (aSize
.Height() < nMinVal
)
342 aSize
.Height() = nMinVal
;
344 //! we don't force a maximum value here because this may prevent eg the
345 //! parentheses in "left ( ... right )" from matching up with large
346 //! bodies (eg stack{...} with many entries).
347 //! Of course this is holds only if characters are used and not polygons.
349 Font::SetSize(aSize
);
353 long SmFace::GetBorderWidth() const
355 if (nBorderWidth
< 0)
356 return GetDefaultBorderWidth();
361 SmFace
& SmFace::operator = (const SmFace
&rFace
)
363 Font::operator = (rFace
);
369 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
)
370 // scales the width and height of 'rFace' by 'rFrac' and returns a
371 // reference to 'rFace'.
372 // It's main use is to make scaling fonts look easier.
373 { const Size
&rFaceSize
= rFace
.GetSize();
375 rFace
.SetSize(Size(Fraction(rFaceSize
.Width()) *= rFrac
,
376 Fraction(rFaceSize
.Height()) *= rFrac
));