00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "precompiled_starmath.hxx"
00038
00039
00040 #ifndef _SFXAPP_HXX //autogen
00041 #include <sfx2/app.hxx>
00042 #endif
00043 #ifndef _SV_VIRDEV_HXX //autogen
00044 #include <vcl/virdev.hxx>
00045 #endif
00046 #ifndef _STRING_HXX
00047 #include <tools/string.hxx>
00048 #endif
00049 #ifndef _TOOLS_TENCCVT_HXX
00050 #include <tools/tenccvt.hxx>
00051 #endif
00052 #ifndef _OSL_THREAD_H_
00053 #include <osl/thread.h>
00054 #endif
00055
00056 #include <tools/stream.hxx>
00057
00058 #include "starmath.hrc"
00059
00060 #include "utility.hxx"
00061 #include "dialog.hxx"
00062 #include "view.hxx"
00063 #include "smdll.hxx"
00064
00065
00066
00067
00070 SmViewShell * SmGetActiveView()
00071 {
00072 SfxViewShell *pView = SfxViewShell::Current();
00073 return PTR_CAST(SmViewShell, pView);
00074 }
00075
00076
00078
00079
00080
00081
00082 SmPickList::SmPickList(USHORT nInitSize, USHORT nMaxSize) :
00083 SfxPtrArr((BYTE) nInitSize, 1)
00084 {
00085 nSize = nMaxSize;
00086 }
00087
00088
00089 SmPickList::~SmPickList()
00090 {
00091 Clear();
00092 }
00093
00094
00095 SmPickList& SmPickList::operator=(const SmPickList& rList)
00096 {
00097 USHORT nPos;
00098
00099 Clear();
00100 nSize = rList.nSize;
00101 for (nPos = 0; nPos < rList.Count(); nPos++)
00102 InsertPtr(nPos, CreateItem(rList.Get(nPos)));
00103
00104 return *this;
00105 }
00106
00107
00108 void SmPickList::Insert(const void *pItem)
00109 {
00110 Remove(pItem);
00111 InsertPtr(0, CreateItem(pItem));
00112
00113 if (Count() > nSize)
00114 {
00115 DestroyItem(GetPtr(nSize));
00116 RemovePtr(nSize, 1);
00117 }
00118 }
00119
00120
00121 void SmPickList::Update(const void *pItem, const void *pNewItem)
00122 {
00123 USHORT nPos;
00124
00125 for (nPos = 0; nPos < Count(); nPos++)
00126 if (CompareItem(GetPtr(nPos), pItem))
00127 {
00128 DestroyItem(GetPtr(nPos));
00129 GetPtr(nPos) = CreateItem(pNewItem);
00130 break;
00131 }
00132 }
00133
00134 void SmPickList::Remove(const void *pItem)
00135 {
00136 USHORT nPos;
00137
00138 for (nPos = 0; nPos < Count(); nPos++)
00139 if (CompareItem(GetPtr(nPos), pItem))
00140 {
00141 DestroyItem(GetPtr(nPos));
00142 RemovePtr(nPos, 1);
00143 break;
00144 }
00145 }
00146
00147 void SmPickList::SetSize(USHORT nNewSize)
00148 {
00149 nSize = nNewSize;
00150
00151 while (Count() > nSize)
00152 {
00153 DestroyItem(GetPtr(Count() - 1));
00154 RemovePtr(Count() - 1, 1);
00155 }
00156 }
00157
00158
00159 BOOL SmPickList::Contains(const void *pItem) const
00160 {
00161 USHORT nPos;
00162
00163 for (nPos = 0; nPos < Count(); nPos++)
00164 if (CompareItem(GetPtr(nPos), pItem))
00165 return TRUE;
00166
00167 return FALSE;
00168 }
00169
00170
00171 void SmPickList::Clear()
00172 {
00173 USHORT nPos;
00174
00175 for (nPos = 0; nPos < Count(); nPos++)
00176 DestroyItem(GetPtr(nPos));
00177
00178 RemovePtr(0, Count());
00179 }
00180
00181
00182
00183
00184
00185 void * SmFontPickList::CreateItem(const String& )
00186 {
00187 return new Font();
00188 }
00189
00190 void * SmFontPickList::CreateItem(const void *pItem)
00191 {
00192 return new Font(*((Font *) pItem));
00193 }
00194
00195 void SmFontPickList::DestroyItem(void *pItem)
00196 {
00197 delete (Font *)pItem;
00198 }
00199
00200 BOOL SmFontPickList::CompareItem(const void *pFirstItem, const void *pSecondItem) const
00201 {
00202 Font *pFirstFont, *pSecondFont;
00203
00204 pFirstFont = (Font *)pFirstItem;
00205 pSecondFont = (Font *)pSecondItem;
00206
00207 if (pFirstFont->GetName() == pSecondFont->GetName())
00208 if ((pFirstFont->GetFamily() == pSecondFont->GetFamily()) &&
00209 (pFirstFont->GetCharSet() == pSecondFont->GetCharSet()) &&
00210 (pFirstFont->GetWeight() == pSecondFont->GetWeight()) &&
00211 (pFirstFont->GetItalic() == pSecondFont->GetItalic()))
00212 return (TRUE);
00213
00214 return FALSE;
00215 }
00216
00217 String SmFontPickList::GetStringItem(void *pItem)
00218 {
00219 Font *pFont;
00220 String aString;
00221 const sal_Char *pDelim = ", ";
00222
00223 pFont = (Font *)pItem;
00224
00225 aString = pFont->GetName();
00226
00227 if (IsItalic( *pFont ))
00228 {
00229 aString.AppendAscii( pDelim );
00230 aString += String(SmResId(RID_FONTITALIC));
00231 }
00232 if (IsBold( *pFont ))
00233 {
00234 aString.AppendAscii( pDelim );
00235 aString += String(SmResId(RID_FONTBOLD));
00236 }
00237
00238 return (aString);
00239 }
00240
00241 void SmFontPickList::Insert(const Font &rFont)
00242 {
00243 SmPickList::Insert((void *)&rFont);
00244 }
00245
00246 void SmFontPickList::Update(const Font &rFont, const Font &rNewFont)
00247 {
00248 SmPickList::Update((void *)&rFont, (void *)&rNewFont);
00249 }
00250
00251 void SmFontPickList::Remove(const Font &rFont)
00252 {
00253 SmPickList::Remove((void *)&rFont);
00254 }
00255
00256
00257 void SmFontPickList::ReadFrom(const SmFontDialog& rDialog)
00258 {
00259 Insert(rDialog.GetFont());
00260 }
00261
00262 void SmFontPickList::WriteTo(SmFontDialog& rDialog) const
00263 {
00264 rDialog.SetFont(Get());
00265 }
00266
00267
00268
00269
00270
00271
00272
00273 IMPL_LINK( SmFontPickListBox, SelectHdl, ListBox *, )
00274 {
00275 USHORT nPos;
00276 String aString;
00277
00278 nPos = GetSelectEntryPos();
00279
00280 if (nPos != 0)
00281 {
00282 SmFontPickList::Insert(Get(nPos));
00283 aString = GetEntry(nPos);
00284 RemoveEntry(nPos);
00285 InsertEntry(aString, 0);
00286 }
00287
00288 SelectEntryPos(0);
00289
00290 return 0;
00291 }
00292
00293
00294 SmFontPickListBox::SmFontPickListBox(Window* pParent, WinBits nWinStyle, USHORT nMax) :
00295 SmFontPickList(nMax, nMax),
00296 ListBox(pParent, nWinStyle)
00297 {
00298 SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
00299 }
00300
00301
00302 SmFontPickListBox::SmFontPickListBox(Window* pParent, const ResId& rResId, USHORT nMax) :
00303 SmFontPickList(nMax, nMax),
00304 ListBox(pParent, rResId)
00305 {
00306 SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
00307 }
00308
00309
00310 SmFontPickListBox& SmFontPickListBox::operator=(const SmFontPickList& rList)
00311 {
00312 USHORT nPos;
00313
00314 *(SmFontPickList *)this = rList;
00315
00316 for (nPos = 0; nPos < Count(); nPos++)
00317 InsertEntry(GetStringItem(GetPtr(nPos)), nPos);
00318
00319 if (Count() > 0)
00320 SelectEntry(GetStringItem(GetPtr(0)));
00321
00322 return *this;
00323 }
00324
00325 void SmFontPickListBox::Insert(const Font &rFont)
00326 {
00327 SmFontPickList::Insert(rFont);
00328
00329 RemoveEntry(GetStringItem(GetPtr(0)));
00330 InsertEntry(GetStringItem(GetPtr(0)), 0);
00331 SelectEntry(GetStringItem(GetPtr(0)));
00332
00333 while (GetEntryCount() > nSize)
00334 RemoveEntry(GetEntryCount() - 1);
00335
00336 return;
00337 }
00338
00339
00340 void SmFontPickListBox::Update(const Font &rFont, const Font &rNewFont)
00341 {
00342 SmFontPickList::Update(rFont, rNewFont);
00343
00344
00345
00346 return;
00347 }
00348
00349
00350 void SmFontPickListBox::Remove(const Font &rFont)
00351 {
00352 SmFontPickList::Remove(rFont);
00353
00354
00355
00356 return;
00357 }
00358
00360
00361 BOOL IsItalic( const Font &rFont )
00362 {
00363 FontItalic eItalic = rFont.GetItalic();
00364
00365 return eItalic == ITALIC_OBLIQUE || eItalic == ITALIC_NORMAL;
00366 }
00367
00368
00369 BOOL IsBold( const Font &rFont )
00370 {
00371 FontWeight eWeight = rFont.GetWeight();
00372 return eWeight != WEIGHT_DONTKNOW && eWeight > WEIGHT_NORMAL;
00373 }
00374
00375
00376 void SmFace::Impl_Init()
00377 {
00378 SetSize( GetSize() );
00379 SetTransparent( TRUE );
00380 SetAlign( ALIGN_BASELINE );
00381 SetColor( COL_AUTO );
00382 }
00383
00384 void SmFace::SetSize(const Size& rSize)
00385 {
00386 Size aSize (rSize);
00387
00388
00389 static int __READONLY_DATA nMinVal = SmPtsTo100th_mm(2);
00390
00391 if (aSize.Height() < nMinVal)
00392 aSize.Height() = nMinVal;
00393
00398
00399 Font::SetSize(aSize);
00400 }
00401
00402
00403 long SmFace::GetBorderWidth() const
00404 {
00405 if (nBorderWidth < 0)
00406 return GetDefaultBorderWidth();
00407 else
00408 return nBorderWidth;
00409 }
00410
00411 SmFace & SmFace::operator = (const SmFace &rFace)
00412 {
00413 Font::operator = (rFace);
00414 nBorderWidth = -1;
00415 return *this;
00416 }
00417
00418
00419 SmFace & operator *= (SmFace &rFace, const Fraction &rFrac)
00420
00421
00422
00423 { const Size &rFaceSize = rFace.GetSize();
00424
00425 rFace.SetSize(Size(Fraction(rFaceSize.Width()) *= rFrac,
00426 Fraction(rFaceSize.Height()) *= rFrac));
00427 return rFace;
00428 }
00429
00430
00431