1*d107581fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d107581fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d107581fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d107581fSAndrew Rist * distributed with this work for additional information 6*d107581fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d107581fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d107581fSAndrew Rist * "License"); you may not use this file except in compliance 9*d107581fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*d107581fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*d107581fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d107581fSAndrew Rist * software distributed under the License is distributed on an 15*d107581fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d107581fSAndrew Rist * KIND, either express or implied. See the License for the 17*d107581fSAndrew Rist * specific language governing permissions and limitations 18*d107581fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*d107581fSAndrew Rist *************************************************************/ 21*d107581fSAndrew Rist 22*d107581fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_starmath.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <sfx2/app.hxx> 29cdf0e10cSrcweir #include <vcl/virdev.hxx> 30cdf0e10cSrcweir #include <tools/string.hxx> 31cdf0e10cSrcweir #include <tools/tenccvt.hxx> 32cdf0e10cSrcweir #include <osl/thread.h> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <tools/stream.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "starmath.hrc" 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include "utility.hxx" 39cdf0e10cSrcweir #include "dialog.hxx" 40cdf0e10cSrcweir #include "view.hxx" 41cdf0e10cSrcweir #include "smdll.hxx" 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir //////////////////////////////////////////////////////////// 45cdf0e10cSrcweir 46cdf0e10cSrcweir // return pointer to active SmViewShell, if this is not possible 47cdf0e10cSrcweir // return 0 instead. 48cdf0e10cSrcweir //!! Since this method is based on the current focus it is somewhat 49cdf0e10cSrcweir //!! unreliable and may return unexpected 0 pointers! 50cdf0e10cSrcweir SmViewShell * SmGetActiveView() 51cdf0e10cSrcweir { 52cdf0e10cSrcweir SfxViewShell *pView = SfxViewShell::Current(); 53cdf0e10cSrcweir return PTR_CAST(SmViewShell, pView); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir //////////////////////////////////////////////////////////// 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir /**************************************************************************/ 61cdf0e10cSrcweir 62cdf0e10cSrcweir SmPickList::SmPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize) : 63cdf0e10cSrcweir SfxPtrArr((sal_uInt8) nInitSize, 1) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir nSize = nMaxSize; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir 69cdf0e10cSrcweir SmPickList::~SmPickList() 70cdf0e10cSrcweir { 71cdf0e10cSrcweir Clear(); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir 75cdf0e10cSrcweir SmPickList& SmPickList::operator=(const SmPickList& rList) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir sal_uInt16 nPos; 78cdf0e10cSrcweir 79cdf0e10cSrcweir Clear(); 80cdf0e10cSrcweir nSize = rList.nSize; 81cdf0e10cSrcweir for (nPos = 0; nPos < rList.Count(); nPos++) 82cdf0e10cSrcweir InsertPtr(nPos, CreateItem(rList.Get(nPos))); 83cdf0e10cSrcweir 84cdf0e10cSrcweir return *this; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir void SmPickList::Insert(const void *pItem) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir Remove(pItem); 91cdf0e10cSrcweir InsertPtr(0, CreateItem(pItem)); 92cdf0e10cSrcweir 93cdf0e10cSrcweir if (Count() > nSize) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir DestroyItem(GetPtr(nSize)); 96cdf0e10cSrcweir RemovePtr(nSize, 1); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir 101cdf0e10cSrcweir void SmPickList::Update(const void *pItem, const void *pNewItem) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir sal_uInt16 nPos; 104cdf0e10cSrcweir 105cdf0e10cSrcweir for (nPos = 0; nPos < Count(); nPos++) 106cdf0e10cSrcweir if (CompareItem(GetPtr(nPos), pItem)) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir DestroyItem(GetPtr(nPos)); 109cdf0e10cSrcweir GetPtr(nPos) = CreateItem(pNewItem); 110cdf0e10cSrcweir break; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir void SmPickList::Remove(const void *pItem) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir sal_uInt16 nPos; 117cdf0e10cSrcweir 118cdf0e10cSrcweir for (nPos = 0; nPos < Count(); nPos++) 119cdf0e10cSrcweir if (CompareItem(GetPtr(nPos), pItem)) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir DestroyItem(GetPtr(nPos)); 122cdf0e10cSrcweir RemovePtr(nPos, 1); 123cdf0e10cSrcweir break; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir void SmPickList::Clear() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir sal_uInt16 nPos; 130cdf0e10cSrcweir 131cdf0e10cSrcweir for (nPos = 0; nPos < Count(); nPos++) 132cdf0e10cSrcweir DestroyItem(GetPtr(nPos)); 133cdf0e10cSrcweir 134cdf0e10cSrcweir RemovePtr(0, Count()); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir 138cdf0e10cSrcweir /**************************************************************************/ 139cdf0e10cSrcweir /**************************************************************************/ 140cdf0e10cSrcweir 141cdf0e10cSrcweir void * SmFontPickList::CreateItem(const String& /*rString*/) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir return new Font(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir void * SmFontPickList::CreateItem(const void *pItem) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir return new Font(*((Font *) pItem)); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir void SmFontPickList::DestroyItem(void *pItem) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir delete (Font *)pItem; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir sal_Bool SmFontPickList::CompareItem(const void *pFirstItem, const void *pSecondItem) const 157cdf0e10cSrcweir { 158cdf0e10cSrcweir Font *pFirstFont, *pSecondFont; 159cdf0e10cSrcweir 160cdf0e10cSrcweir pFirstFont = (Font *)pFirstItem; 161cdf0e10cSrcweir pSecondFont = (Font *)pSecondItem; 162cdf0e10cSrcweir 163cdf0e10cSrcweir if (pFirstFont->GetName() == pSecondFont->GetName()) 164cdf0e10cSrcweir if ((pFirstFont->GetFamily() == pSecondFont->GetFamily()) && 165cdf0e10cSrcweir (pFirstFont->GetCharSet() == pSecondFont->GetCharSet()) && 166cdf0e10cSrcweir (pFirstFont->GetWeight() == pSecondFont->GetWeight()) && 167cdf0e10cSrcweir (pFirstFont->GetItalic() == pSecondFont->GetItalic())) 168cdf0e10cSrcweir return (sal_True); 169cdf0e10cSrcweir 170cdf0e10cSrcweir return sal_False; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir String SmFontPickList::GetStringItem(void *pItem) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Font *pFont; 176cdf0e10cSrcweir String aString; 177cdf0e10cSrcweir const sal_Char *pDelim = ", "; 178cdf0e10cSrcweir 179cdf0e10cSrcweir pFont = (Font *)pItem; 180cdf0e10cSrcweir 181cdf0e10cSrcweir aString = pFont->GetName(); 182cdf0e10cSrcweir 183cdf0e10cSrcweir if (IsItalic( *pFont )) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir aString.AppendAscii( pDelim ); 186cdf0e10cSrcweir aString += String(SmResId(RID_FONTITALIC)); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir if (IsBold( *pFont )) // bold? 189cdf0e10cSrcweir { 190cdf0e10cSrcweir aString.AppendAscii( pDelim ); 191cdf0e10cSrcweir aString += String(SmResId(RID_FONTBOLD)); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir return (aString); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir void SmFontPickList::Insert(const Font &rFont) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir SmPickList::Insert((void *)&rFont); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir void SmFontPickList::Update(const Font &rFont, const Font &rNewFont) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir SmPickList::Update((void *)&rFont, (void *)&rNewFont); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir void SmFontPickList::Remove(const Font &rFont) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir SmPickList::Remove((void *)&rFont); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir 213cdf0e10cSrcweir void SmFontPickList::ReadFrom(const SmFontDialog& rDialog) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir Insert(rDialog.GetFont()); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir void SmFontPickList::WriteTo(SmFontDialog& rDialog) const 219cdf0e10cSrcweir { 220cdf0e10cSrcweir rDialog.SetFont(Get()); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir /**************************************************************************/ 225cdf0e10cSrcweir 226cdf0e10cSrcweir 227cdf0e10cSrcweir /**************************************************************************/ 228cdf0e10cSrcweir 229cdf0e10cSrcweir IMPL_LINK( SmFontPickListBox, SelectHdl, ListBox *, /*pListBox*/ ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir sal_uInt16 nPos; 232cdf0e10cSrcweir String aString; 233cdf0e10cSrcweir 234cdf0e10cSrcweir nPos = GetSelectEntryPos(); 235cdf0e10cSrcweir 236cdf0e10cSrcweir if (nPos != 0) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir SmFontPickList::Insert(Get(nPos)); 239cdf0e10cSrcweir aString = GetEntry(nPos); 240cdf0e10cSrcweir RemoveEntry(nPos); 241cdf0e10cSrcweir InsertEntry(aString, 0); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir SelectEntryPos(0); 245cdf0e10cSrcweir 246cdf0e10cSrcweir return 0; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir 250cdf0e10cSrcweir SmFontPickListBox::SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax) : 251cdf0e10cSrcweir SmFontPickList(nMax, nMax), 252cdf0e10cSrcweir ListBox(pParent, rResId) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl)); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir 258cdf0e10cSrcweir SmFontPickListBox& SmFontPickListBox::operator=(const SmFontPickList& rList) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir sal_uInt16 nPos; 261cdf0e10cSrcweir 262cdf0e10cSrcweir *(SmFontPickList *)this = rList; 263cdf0e10cSrcweir 264cdf0e10cSrcweir for (nPos = 0; nPos < Count(); nPos++) 265cdf0e10cSrcweir InsertEntry(GetStringItem(GetPtr(nPos)), nPos); 266cdf0e10cSrcweir 267cdf0e10cSrcweir if (Count() > 0) 268cdf0e10cSrcweir SelectEntry(GetStringItem(GetPtr(0))); 269cdf0e10cSrcweir 270cdf0e10cSrcweir return *this; 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir void SmFontPickListBox::Insert(const Font &rFont) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir SmFontPickList::Insert(rFont); 276cdf0e10cSrcweir 277cdf0e10cSrcweir RemoveEntry(GetStringItem(GetPtr(0))); 278cdf0e10cSrcweir InsertEntry(GetStringItem(GetPtr(0)), 0); 279cdf0e10cSrcweir SelectEntry(GetStringItem(GetPtr(0))); 280cdf0e10cSrcweir 281cdf0e10cSrcweir while (GetEntryCount() > nSize) 282cdf0e10cSrcweir RemoveEntry(GetEntryCount() - 1); 283cdf0e10cSrcweir 284cdf0e10cSrcweir return; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir 288cdf0e10cSrcweir void SmFontPickListBox::Update(const Font &rFont, const Font &rNewFont) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir SmFontPickList::Update(rFont, rNewFont); 291cdf0e10cSrcweir 292cdf0e10cSrcweir // ********************** hier fehlt noch was 293cdf0e10cSrcweir 294cdf0e10cSrcweir return; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir 298cdf0e10cSrcweir void SmFontPickListBox::Remove(const Font &rFont) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir SmFontPickList::Remove(rFont); 301cdf0e10cSrcweir 302cdf0e10cSrcweir // ********************** hier fehlt noch was 303cdf0e10cSrcweir 304cdf0e10cSrcweir return; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir //////////////////////////////////////// 308cdf0e10cSrcweir 309cdf0e10cSrcweir sal_Bool IsItalic( const Font &rFont ) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir FontItalic eItalic = rFont.GetItalic(); 312cdf0e10cSrcweir // the code below leaves only _NONE and _DONTKNOW as not italic 313cdf0e10cSrcweir return eItalic == ITALIC_OBLIQUE || eItalic == ITALIC_NORMAL; 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir 317cdf0e10cSrcweir sal_Bool IsBold( const Font &rFont ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir FontWeight eWeight = rFont.GetWeight(); 320cdf0e10cSrcweir return eWeight != WEIGHT_DONTKNOW && eWeight > WEIGHT_NORMAL; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir 323cdf0e10cSrcweir 324cdf0e10cSrcweir void SmFace::Impl_Init() 325cdf0e10cSrcweir { 326cdf0e10cSrcweir SetSize( GetSize() ); 327cdf0e10cSrcweir SetTransparent( sal_True ); 328cdf0e10cSrcweir SetAlign( ALIGN_BASELINE ); 329cdf0e10cSrcweir SetColor( COL_AUTO ); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir void SmFace::SetSize(const Size& rSize) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir Size aSize (rSize); 335cdf0e10cSrcweir 336cdf0e10cSrcweir // check the requested size against minimum value 337cdf0e10cSrcweir static int __READONLY_DATA nMinVal = SmPtsTo100th_mm(2); 338cdf0e10cSrcweir 339cdf0e10cSrcweir if (aSize.Height() < nMinVal) 340cdf0e10cSrcweir aSize.Height() = nMinVal; 341cdf0e10cSrcweir 342cdf0e10cSrcweir //! we don't force a maximum value here because this may prevent eg the 343cdf0e10cSrcweir //! parentheses in "left ( ... right )" from matching up with large 344cdf0e10cSrcweir //! bodies (eg stack{...} with many entries). 345cdf0e10cSrcweir //! Of course this is holds only if characters are used and not polygons. 346cdf0e10cSrcweir 347cdf0e10cSrcweir Font::SetSize(aSize); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir 351cdf0e10cSrcweir long SmFace::GetBorderWidth() const 352cdf0e10cSrcweir { 353cdf0e10cSrcweir if (nBorderWidth < 0) 354cdf0e10cSrcweir return GetDefaultBorderWidth(); 355cdf0e10cSrcweir else 356cdf0e10cSrcweir return nBorderWidth; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir SmFace & SmFace::operator = (const SmFace &rFace) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir Font::operator = (rFace); 362cdf0e10cSrcweir nBorderWidth = -1; 363cdf0e10cSrcweir return *this; 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir 367cdf0e10cSrcweir SmFace & operator *= (SmFace &rFace, const Fraction &rFrac) 368cdf0e10cSrcweir // scales the width and height of 'rFace' by 'rFrac' and returns a 369cdf0e10cSrcweir // reference to 'rFace'. 370cdf0e10cSrcweir // It's main use is to make scaling fonts look easier. 371cdf0e10cSrcweir { const Size &rFaceSize = rFace.GetSize(); 372cdf0e10cSrcweir 373cdf0e10cSrcweir rFace.SetSize(Size(Fraction(rFaceSize.Width()) *= rFrac, 374cdf0e10cSrcweir Fraction(rFaceSize.Height()) *= rFrac)); 375cdf0e10cSrcweir return rFace; 376cdf0e10cSrcweir } 377cdf0e10cSrcweir 378cdf0e10cSrcweir 379cdf0e10cSrcweir 380