00001 // $Id: fontdrop.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // fontdrop.cpp - Font drop-down list support 00100 00101 /* 00102 */ 00103 00104 00105 //----------------------------------------------------------------------------------------- 00106 // Include files 00107 00108 #include "camtypes.h" 00109 #include "fontdrop.h" 00110 00111 #include "camelot.h" 00112 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00113 #include "fontbase.h" 00114 #include "textinfo.h" 00115 #include "gbrush.h" 00116 //#include "textres.h" 00117 //#include "richard.h" 00118 //#include "richard2.h" 00119 00120 // These required for the document drop font handling class 00121 //#include "app.h" // FONTMANAGER - in camtypes.h [AUTOMATICALLY REMOVED] 00122 #include "progress.h" // BeginSlowJob ... 00123 //#include "mario.h" // _R(IDS_NO_FONTSINDOC) 00124 #include "fontlist.h" 00125 #include "fontman.h" // Fontmanager 00126 #include "cartprov.h" 00127 //#include "will2.h" // _R(IDS_K_FINFODLG_DASH) 00128 00129 class Document; 00130 00131 //----------------------------------------------------------------------------------------- 00132 // Implementation of dynamic classes 00133 00134 CC_IMPLEMENT_DYNCREATE(FontDropItem, CCObject); 00135 CC_IMPLEMENT_DYNCREATE(FontDropEnumFont, OILEnumFonts); 00136 CC_IMPLEMENT_DYNCREATE(FontDropDown, ListItem); 00137 CC_IMPLEMENT_DYNCREATE(DocumentFontDropDown, ListItem); 00138 00139 00140 //----------------------------------------------------------------------------------------- 00141 // This must be defined AFTER all CC_IMPLEMENT_DYNCREATE calls 00142 #define new CAM_DEBUG_NEW 00143 00144 00145 //----------------------------------------------------------------------------------------- 00146 // Enumerating fonts uses a callback function, which in turn needs to access the original FontDropDown caller... 00147 void * FontDropDown::CurrentFontDropDown = 0; 00148 00149 /******************************************************************************************** 00150 00151 > FontDropItem::FontDropItem() 00152 00153 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00154 Date: 3/10/95 00155 00156 Purpose: Default FontDropDownListItem constructor 00157 00158 ********************************************************************************************/ 00159 00160 FontDropItem::FontDropItem() 00161 { 00162 FontName = _T(""); 00163 Type = FC_UNDEFINED; 00164 } 00165 00166 /******************************************************************************************** 00167 00168 > FontDropItem::FontDropItem(TCHAR *Name, FontClass FontType) 00169 00170 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00171 Date: 3/10/95 00172 00173 Inputs: Name - Font Typeface name that will be displayed and used 00174 FontType - Type of Font this item is describing - FC_ATM for example 00175 00176 Purpose: Better FontDropDownListItem constructor 00177 00178 ********************************************************************************************/ 00179 00180 FontDropItem::FontDropItem(TCHAR *Name, FontClass FontType) 00181 { 00182 FontName = Name; 00183 Type = FontType; 00184 } 00185 00186 00187 /******************************************************************************************** 00188 00189 > BOOL FontDropEnumFont::NewFont(Type, ENUMLOGFONT *lpelf) 00190 00191 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00192 Date: 3/10/95 00193 00194 Inputs: Type - Type of font 00195 lpelf - Logfont pointer 00196 lpntm - NewTextMetrics pointer 00197 lppnse - Panose pointer 00198 00199 Returns: TRUE if the font was added to the list ok. 00200 00201 Purpose: Called for each font installed on the system. Effectively creates the FontPullDown 00202 items from the given info. 00203 00204 ********************************************************************************************/ 00205 00206 BOOL FontDropEnumFont::NewFont(FontClass Type, ENUMLOGFONT *lpelf) 00207 { 00208 count++; 00209 00210 ERROR3IF(((FontDropDown *)FontDropDown::CurrentFontDropDown) == NULL, "CurrentFontDropDown is NULL in NewFont"); 00211 if(((FontDropDown *)FontDropDown::CurrentFontDropDown) != NULL) 00212 return ((FontDropDown *)FontDropDown::CurrentFontDropDown) 00213 -> AddFontToList((TCHAR *)lpelf->elfLogFont.FaceName, Type); 00214 00215 return FALSE; 00216 } 00217 00218 00219 /******************************************************************************************** 00220 00221 > FontDropDown::FontDropDown() 00222 00223 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00224 Date: 4/10/95 00225 00226 Purpose: Default constructor for FontDropDown Class... 00227 Notes: If you mistakenly replace the F with a D you get a great song title... 00228 00229 ********************************************************************************************/ 00230 00231 FontDropDown::FontDropDown() 00232 { 00233 TheTopItem.FontName = _R(IDS_ATM_DEFAULT); // "Default"; 00234 TheTopItem.Type = FC_UNDEFINED; 00235 m_MissingItemAdded = FALSE; 00236 } 00237 00238 /******************************************************************************************** 00239 00240 > FontDropDown::~FontDropDown() 00241 00242 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00243 Date: 5/10/95 00244 00245 Purpose: Default destructor for FontDropDown Class... 00246 Notes: If you mistakenly replace the F with a D you get a great song title... 00247 00248 ********************************************************************************************/ 00249 00250 FontDropDown::~FontDropDown() 00251 { 00252 00253 } 00254 00255 00256 /******************************************************************************************** 00257 00258 > virtual BOOL FontDropDown::Init(CWindowID Window, CGadgetID Gadget) 00259 00260 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00261 Date: 26/10/95 00262 00263 Inputs: Window - The Window in which your dropdown list gadget resides 00264 Gadget - The GadgetID of the deropdown list gadget 00265 00266 Returns: TRUE if initialised ok... 00267 00268 Purpose: FontDropDown initialiser 00269 00270 ********************************************************************************************/ 00271 00272 BOOL FontDropDown::Init(CWindowID Window, CGadgetID Gadget) 00273 { 00274 BOOL ok = DropDown::Init(Window, Gadget); 00275 00276 return ok; 00277 } 00278 00279 /******************************************************************************************** 00280 00281 > void FontDropDown::KillList(void) 00282 00283 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00284 Date: 5/10/95 00285 00286 Purpose: Kills all the items in the drop down and deletes them... 00287 00288 ********************************************************************************************/ 00289 00290 void FontDropDown::KillList(void) 00291 { 00292 ClearList(); 00293 00294 ListItem *Item = Fonts.GetTail(); 00295 00296 // Loop through list, deleting items and reclaiming memory 00297 while(Item != NULL) 00298 { 00299 ListItem* Prev = Fonts.GetPrev(Item); 00300 delete( (FontDropItem*)((Fonts.RemoveItem(Item))) ); 00301 Item = Prev; 00302 } 00303 m_MissingItemAdded = FALSE; 00304 } 00305 00306 00307 /******************************************************************************************** 00308 00309 > BOOL FontDropDown::AddFontToList(TCHAR *FontName, FontClass Type) 00310 00311 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00312 Date: 3/10/95 00313 00314 Inputs: FontName - Name of font 00315 Type - Type of font 00316 00317 Returns: TRUE if the font was added to the list ok. 00318 00319 Purpose: Called for each font installed on the system. Effectively creates the FontPullDown 00320 items from the given info. 00321 00322 ********************************************************************************************/ 00323 00324 BOOL FontDropDown::AddFontToList(TCHAR *FontName, FontClass Type) 00325 { 00326 FontDropItem *Item = new FontDropItem(FontName, Type); 00327 if(Item == NULL) 00328 { 00329 ERROR3("FontDropDown::AddFontToList couldn't create Item"); 00330 return FALSE; 00331 } 00332 00333 // Add the item into the list, in a sorted fashion... 00334 ListItem *TheItem = Fonts.GetHead(); 00335 00336 if(TheItem == NULL) 00337 { 00338 Fonts.AddTail(Item); 00339 return TRUE; 00340 } 00341 00342 if( ((FontDropItem *)TheItem)->FontName > String_64(FontName)) 00343 { 00344 Fonts.InsertBefore(TheItem, Item); 00345 return TRUE; 00346 } 00347 00348 while (TheItem != NULL) 00349 { 00350 ListItem *TheNextItem = Fonts.GetNext(TheItem); 00351 00352 if(TheNextItem == NULL) 00353 { 00354 Fonts.InsertAfter(TheItem, Item); 00355 return TRUE; 00356 } 00357 00358 if(((FontDropItem *)TheNextItem)->FontName > String_64(FontName)) 00359 { 00360 Fonts.InsertBefore(TheNextItem, Item); 00361 return TRUE; 00362 } 00363 00364 // Try the next item 00365 TheItem = TheNextItem; 00366 } 00367 00368 return TRUE; 00369 } 00370 00371 /******************************************************************************************** 00372 00373 > BOOL FontDropDown::FillInFontList() 00374 00375 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00376 Date: 3/10/95 00377 00378 Inputs: 00379 00380 Returns: TRUE if it filled in the list successfully 00381 00382 Purpose: "Fills in" the attached control with appropriate entries for the current 00383 FontDropDown settings 00384 00385 SeeAlso: FontDropDown::DecodeSelection; FontDropDown::AddSpecialEntry 00386 00387 ********************************************************************************************/ 00388 00389 BOOL FontDropDown::FillInFontList() 00390 { 00391 ERROR2IF(ParentDlg == NULL, FALSE, "FontDropDown not properly initialised"); 00392 TRACEUSER("wuerthne", _T("FillInFontList")); 00393 00394 SetListRedraw(FALSE); // Disable redraw while updating 00395 ClearList(); // Delete combobox contents 00396 00397 // Setup the static class pointer variable so we can add things to this dropdown... 00398 CurrentFontDropDown = (void *)this; 00399 00400 if(Fonts.GetCount() == 0) 00401 { 00402 TRACEUSER("wuerthne", _T("FontDropDown enumerating fonts")); 00403 FontDropEnumFont EnumObj; 00404 EnumObj.Execute(); 00405 00406 // Loop through the list, checking for ATM / TTF duplicates, and remove the TTF ones from the list 00407 FontDropItem *Item = (FontDropItem *)Fonts.GetHead(); 00408 while (Item != NULL) 00409 { 00410 FontClass ItemType = Item->Type; 00411 if(ItemType == FC_ATM) 00412 { 00413 // It's an ATM font, go through whole list checking for TTF equiv. 00414 BOOL Removed = FALSE; 00415 String_64 ItemName(Item->FontName); 00416 FontDropItem *InnerLoopItem = (FontDropItem *)Fonts.GetHead(); 00417 while (InnerLoopItem != NULL && Removed == FALSE) 00418 { 00419 // Have we found our font ? Remove it if we have... 00420 if((InnerLoopItem->Type == FC_TRUETYPE) && (InnerLoopItem->FontName == ItemName)) 00421 { 00422 Fonts.RemoveItem((ListItem *)InnerLoopItem); 00423 delete InnerLoopItem; 00424 InnerLoopItem = NULL; 00425 Removed = TRUE; 00426 } 00427 00428 // Get the next item 00429 if(!Removed) 00430 InnerLoopItem = (FontDropItem *)Fonts.GetNext((ListItem *)InnerLoopItem); 00431 } 00432 } 00433 // Get the next item 00434 Item = (FontDropItem *)Fonts.GetNext((ListItem *)Item); 00435 } 00436 } 00437 00438 ListItem *Item = Fonts.GetHead(); 00439 00440 while (Item != NULL) 00441 { 00442 // Add the font in the list to the combo box 00443 AddItem((void *) Item); 00444 00445 // Try the next item 00446 Item = Fonts.GetNext(Item); 00447 } 00448 00449 SetListRedraw(TRUE); // Re-enable redraw 00450 00451 return(TRUE); 00452 } 00453 00454 00455 00456 /******************************************************************************************** 00457 00458 > BOOL FontDropDown::SetSelection(FontDropItem *TheFont) 00459 00460 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00461 Date: 4/10/95 00462 00463 Inputs: TheFont - FontDropItem to select 00464 00465 Returns: TRUE if it set the selection OK 00466 00467 Purpose: To set the selected item in the list 00468 00469 SeeAlso: FontDropDown::DecodeSelection; FontDropDown::FillInColourList 00470 00471 ********************************************************************************************/ 00472 00473 BOOL FontDropDown::SetSelection(FontDropItem *TheFont) 00474 { 00475 ERROR2IF(ParentDlg == NULL, FALSE, "FontDropDown not properly initialised"); 00476 00477 INT32 SelectedIndex = -1; 00478 00479 TRACEUSER("wuerthne", _T("SetSelection to %s"), (TCHAR*)TheFont->FontName); 00480 00481 INT32 Index = 0; 00482 INT32 MaxIndex = GetNumberOfItems(); 00483 00484 while (Index < MaxIndex) 00485 { 00486 if ( (TheFont->FontName == ((FontDropItem *) GetItemData(Index))->FontName) 00487 && (TheFont->Type == ((FontDropItem *) GetItemData(Index))->Type) ) 00488 { 00489 SelectedIndex = Index; 00490 break; 00491 } 00492 00493 Index++; 00494 } 00495 00496 if (Index == MaxIndex) 00497 { 00498 TRACEUSER("wuerthne", _T("font not in list, Index = %d"), Index); 00499 // font was not in the list, so make sure there is a special item at the 00500 // end to accomodate it 00501 String_64 NewName(TheFont->FontName); 00502 NewName += String_64(_R(IDS_FONTMISSING)); 00503 00504 if (m_MissingItemAdded) 00505 { 00506 TRACEUSER("wuerthne", _T("update missing item")); 00507 FontDropItem *Item = (FontDropItem*)Fonts.GetTail(); 00508 Item->SetInfo(NewName, FC_UNDEFINED); 00509 SelectedIndex = Index - 1; 00510 } 00511 else 00512 { 00513 TRACEUSER("wuerthne", _T("add missing item")); 00514 FontDropItem *Item = new FontDropItem(NewName, FC_UNDEFINED); 00515 Fonts.AddTail(Item); 00516 AddItem((void*) Item); 00517 m_MissingItemAdded = TRUE; 00518 SelectedIndex = Index; 00519 } 00520 } 00521 else 00522 { 00523 // the font was in the list, so if there is a "missing" item at the end remove it 00524 // (unless of course, the selected item *is* the "missing" item, but this cannot 00525 // normally happen because our item has the added text " (missing)") 00526 if (m_MissingItemAdded && SelectedIndex != MaxIndex - 1) 00527 { 00528 TRACEUSER("wuerthne", _T("remove missing item")); 00529 delete( (FontDropItem*)((Fonts.RemoveItem(Fonts.GetTail()))) ); 00530 m_MissingItemAdded = FALSE; 00531 00532 // delete the item from the combo box 00533 DeleteItem(MaxIndex - 1); 00534 } 00535 } 00536 TRACEUSER("wuerthne", _T("setting index to %d"), SelectedIndex); 00537 SetSelectedIndex(SelectedIndex); // And set the appropriate selected item 00538 TRACEUSER("wuerthne", _T("SetSelection done")); 00539 return(TRUE); 00540 } 00541 00542 00543 /******************************************************************************************** 00544 00545 > FontDropItem *FontDropDown::DecodeSelection(INT32 SelectionIndex) 00546 00547 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00548 Date: 4/10/95 00549 00550 Inputs: SelectionIndex - The index of the item (which is usually the selected one) 00551 in the combo box. 00552 00553 Returns: A FontDropItem which is selected... Or NULL if nothing's selected 00554 NOTE that if the list is empty, it will return NULL 00555 00556 Purpose: Decodes an index in the dropdown list back into a font 00557 00558 SeeAlso: FontDropDown::FillInColourList; FontDropDown::AddSpecialEntry 00559 00560 ********************************************************************************************/ 00561 00562 FontDropItem *FontDropDown::DecodeSelection(INT32 SelectionIndex) 00563 { 00564 // do not allow the extra "missing" item to be selected 00565 if (SelectionIndex == GetNumberOfItems() - 1 && m_MissingItemAdded) return NULL; 00566 FontDropItem *Fred = (FontDropItem *) GetItemData(SelectionIndex); 00567 00568 if (Fred==&TheTopItem) 00569 return(NULL); 00570 00571 return Fred; 00572 } 00573 00574 00575 /******************************************************************************************** 00576 00577 > virtual BOOL FontDropDown::HasIcon(void * ItemData) 00578 00579 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00580 Date: 13/9/95 00581 00582 Inputs: ItemData - Your item data 00583 00584 Returns: TRUE if this item needs an icon to the left of it, FALSE if not 00585 00586 Purpose: Determine if an item needs an icon next to it 00587 00588 Notes: Called by HandleDrawItemInternal when this object has been identified as the 00589 owner of the control to be redrawn. 00590 00591 This method MUST be overridden by derived classes to provide redraw of their 00592 FontDropDown list items. The base class returns FALSE 00593 00594 If you return TRUE, you must also provide the DrawIcon method 00595 00596 SeeAlso: FontDropDown::DrawIcon; FontDropDown::DrawText 00597 00598 ********************************************************************************************/ 00599 00600 BOOL FontDropDown::HasIcon(void * ItemData) 00601 { 00602 // All our items have a space for a truetype icon to their left 00603 return(TRUE); 00604 } 00605 00606 00607 00608 /******************************************************************************************** 00609 00610 > virtual BOOL FontDropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect, 00611 BOOL Disabled, INT32 flags) 00612 00613 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00614 Date: 4/10/95 00615 00616 Inputs: ItemData - Your item data 00617 hDC - The DC to render into 00618 IconRect - points at a rectangle (square in fact) to be drawn within 00619 Disabled - TRUE if this item is disabled so the icon should be drawn greyed 00620 00621 Returns: TRUE if this item needs an icon to the left of it, FALSE if not 00622 00623 Purpose: Draws the icon for an item 00624 00625 Notes: Called by HandleDrawItemInternal when this object has been identified as the 00626 owner of the control to be redrawn, if HasIcon returned TRUE 00627 00628 This method MUST be overridden by derived classes to provide redraw of their 00629 FontDropDown list items. The base class does nothing. 00630 00631 On entry, the DC is ready for you to draw into, including having the camelot 00632 palette selected in etc. 00633 00634 SeeAlso: FontDropDown::DrawIcon; FontDropDown::DrawText 00635 00636 ********************************************************************************************/ 00637 00638 BOOL FontDropDown::DrawIcon(void * ItemData, wxDC& dc, wxRect& IconRect, BOOL Disabled, INT32 flags) 00639 { 00640 ResourceID BitmapID = 0; 00641 FontClass Type; 00642 00643 if ((ItemData==&TheTopItem) || !ItemData) 00644 Type = TheTopItem.Type; 00645 else 00646 Type = ((FontDropItem *)ItemData)->Type; 00647 00648 switch(Type) 00649 { 00650 case FC_TRUETYPE: 00651 BitmapID = _R(IDB_TTF_SYMBOL); 00652 break; 00653 00654 case FC_ATM: 00655 BitmapID = _R(IDB_ATM_SYMBOL); 00656 break; 00657 00658 case FC_UNDEFINED: 00659 BitmapID = _R(IDB_UNKNOWNFONT_SYMBOL); 00660 break; 00661 00662 default: 00663 BitmapID = 0; 00664 break; 00665 } 00666 00667 if(BitmapID == 0) 00668 return FALSE; 00669 00670 wxBitmap * pBitmap = CamArtProvider::Get()->FindBitmap(BitmapID, (CamArtFlags)(CAF_DEFAULT|(Disabled?CAF_GREYED:0))); 00671 if (!pBitmap) 00672 return FALSE; 00673 00674 dc.DrawBitmap(*pBitmap, IconRect.GetLeft(), IconRect.GetTop(), TRUE); 00675 00676 return TRUE; 00677 } 00678 00679 00680 00681 /******************************************************************************************** 00682 00683 > virtual wxString FontDropDown::GetText(void * ItemData, INT32 Item) 00684 00685 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00686 Date: 3/10/95 00687 00688 Inputs: ItemData - Your item data 00689 00690 Returns: The text 00691 00692 ********************************************************************************************/ 00693 00694 wxString FontDropDown::GetText(void * ItemData, INT32 Item) 00695 { 00696 ERROR3IF(ItemData == NULL, "NULL Itemdata in FontDropDown::DrawText"); 00697 00698 String_64 TextToDisplay(_T("")); 00699 00700 if (!ItemData || Item<0 || (ItemData==&TheTopItem)) 00701 TextToDisplay = TheTopItem.FontName; 00702 else 00703 TextToDisplay = (((FontDropItem *)ItemData)->FontName); 00704 00705 // and draw the text... 00706 return(wxString((TCHAR *)TextToDisplay)); 00707 } 00708 00709 00710 00711 00712 /******************************************************************************************** 00713 00714 > BOOL FontDropDown::SetTopFontName(StringBase* StrValue, FontClass Type, BOOL Deselect = TRUE) 00715 00716 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00717 Date: 4/10/95 00718 00719 Inputs: StrValue - Font name, or whatever you want in the icon above the pull down 00720 Type - Type of font - TTF, ATM, etc.... 00721 Deselect - If we do an explicit SetSelectedIndex (Or SetSelected) after this 00722 call, then set this to FALSE to avoid unneccesary flicker 00723 Returns: TRUE if ok 00724 00725 Purpose: Changes the string and bmp in the icon above the font pull down to reflect 00726 whatever you give it... 00727 00728 SeeAlso: DropDown::HasIcon; DropDown::DrawIcon; DropDown::DrawText 00729 00730 ********************************************************************************************/ 00731 00732 BOOL FontDropDown::SetTopFontName(StringBase* StrValue, FontClass Type, BOOL Deselect) 00733 { 00734 TheTopItem.FontName = *StrValue; 00735 TheTopItem.Type = Type; 00736 00737 // Deselect any selected items 00738 if(Deselect) 00739 SetSelectedIndex(-1); 00740 00741 return TRUE; 00742 } 00743 00744 /******************************************************************************************** 00745 ***** DocumentFontDropDown class ***** 00746 ********************************************************************************************/ 00747 00748 /******************************************************************************************** 00749 00750 > DocumentFontDropDown::DocumentFontDropDown() 00751 00752 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00753 Date: 13/11/95 00754 00755 Purpose: Default constructor for DocumentFontDropDown Class... 00756 00757 ********************************************************************************************/ 00758 00759 DocumentFontDropDown::DocumentFontDropDown() 00760 { 00761 TheTopItem.FontName = _R(IDS_NO_FONTSINDOC); 00762 TheTopItem.Type = FC_UNDEFINED; 00763 } 00764 00765 /******************************************************************************************** 00766 00767 > DocumentFontDropDown::~DocumentFontDropDown() 00768 00769 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00770 Date: 13/11/95 00771 00772 Purpose: Default destructor for DocumentFontDropDown Class... 00773 00774 ********************************************************************************************/ 00775 00776 DocumentFontDropDown::~DocumentFontDropDown() 00777 { 00778 KillList(); 00779 } 00780 00781 00782 /******************************************************************************************** 00783 00784 > BOOL DocumentFontDropDown::FillInFontList(Document * WorkDoc) 00785 00786 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00787 Date: 13/11/95 00788 00789 Inputs: WorkDoc pointer to the document to extact the font list from, NULL if none 00790 which means show blank list 00791 00792 Returns: TRUE if it filled in the list successfully 00793 00794 Purpose: "Fills in" the attached control with appropriate entries for the current 00795 DocumentFontDropDown settings. To do this it reads the current fonts from the 00796 specified document. If the document is NULL then it will show a blank list. 00797 If no document fonts are in use then it will also show a blank list and fill 00798 in the top entry with a suitable message. 00799 00800 SeeAlso: FontDropDown::DecodeSelection; FontDropDown::AddSpecialEntry 00801 00802 ********************************************************************************************/ 00803 00804 BOOL DocumentFontDropDown::FillInFontList(Document * WorkDoc) 00805 { 00806 ERROR2IF(ParentDlg == NULL, FALSE, "FontDropDown not properly initialised"); 00807 00808 BeginSlowJob(); 00809 00810 SetListRedraw(FALSE); // Disable redraw while updating 00811 KillList(); // Delete combobox contents and empty the fonts list 00812 //ClearList(); // Delete combobox contents 00813 00814 // Setup the static class pointer variable so we can add things to this dropdown... 00815 CurrentFontDropDown = (void *)this; 00816 00817 //if(Fonts.GetCount() == 0) 00818 //{ 00819 if (WorkDoc == NULL) 00820 { 00821 // Fill in one item in the list which is no document fonts being used 00822 String_8 DashString(_R(IDS_K_FINFODLG_DASH)); 00823 TheTopItem.FontName = DashString; 00824 TheTopItem.Type = FC_UNDEFINED; 00825 //AddFontToList((TCHAR*)&TheTopItem.FontName, TheTopItem.Type); 00826 } 00827 else 00828 { 00829 // Build the font list for the specified document 00830 // This will NOT be alphabetical 00831 FontList DocFonts; 00832 DocFonts.Build(WorkDoc); 00833 00834 FontListItem* FontItem = DocFonts.GetFirstItem(); 00835 if (FontItem == NULL) 00836 { 00837 // Fill in one item in the list which is no document fonts being used 00838 TheTopItem.FontName = _R(IDS_NO_FONTSINDOC); 00839 TheTopItem.Type = FC_UNDEFINED; 00840 //AddFontToList((TCHAR*)&TheTopItem.FontName, TheTopItem.Type); 00841 } 00842 else 00843 { 00844 //BOOL FirstInList = TRUE; 00845 00846 // fill up the list 00847 while (FontItem != NULL) 00848 { 00849 // get the name 00850 String_64 Name = FontItem->GetFontName(); 00851 00852 WORD Handle = FONTMANAGER->GetFontHandle(&Name); 00853 00854 // check the style 00855 INT32 Style = FontItem->GetFontStyle(); 00856 if(Style & 1) 00857 Name += _T(" -Bold"); 00858 if(Style & 2) 00859 Name += _T(" -Italic"); 00860 00861 if(Handle > 0) 00862 { 00863 if (FONTMANAGER->IsFontReplaced(Handle)) 00864 Name += _T(" *"); 00865 } 00866 FontClass Type = FontItem->GetFontClass(); 00867 00868 AddFontToList(Name, Type); 00869 00870 FontItem = DocFonts.GetNextItem(FontItem); 00871 00872 ContinueSlowJob(); 00873 } 00874 } 00875 } 00876 //} 00877 00878 // Work out the top item, if any, on the alphabetically sorted list 00879 // ready for putting in the top combo box item 00880 FontDropItem *pTopItem = (FontDropItem *)Fonts.GetHead(); 00881 if (pTopItem != NULL) 00882 { 00883 // Fill in the top item in the list 00884 TheTopItem.FontName = pTopItem->FontName; 00885 TheTopItem.Type = pTopItem->Type; 00886 } 00887 00888 ListItem *Item = Fonts.GetHead(); 00889 00890 while (Item != NULL) 00891 { 00892 // Add the font in the list to the combo box 00893 AddItem((void *) Item); 00894 00895 // Try the next item 00896 Item = Fonts.GetNext(Item); 00897 } 00898 00899 // Re-enable redraw 00900 SetListRedraw(TRUE); 00901 00902 // We have no concept of a selected font 00903 SetSelectedIndex(-1); 00904 00905 EndSlowJob(); 00906 00907 return(TRUE); 00908 }