FontDropDown Class Reference

FontDropDown class itself. More...

#include <fontdrop.h>

Inheritance diagram for FontDropDown:

DropDown ListItem CCObject SimpleCCObject DocumentFontDropDown List of all members.

Public Member Functions

 FontDropDown ()
 Default constructor for FontDropDown Class... Notes: If you mistakenly replace the F with a D you get a great song title...
virtual ~FontDropDown ()
 Default destructor for FontDropDown Class... Notes: If you mistakenly replace the F with a D you get a great song title...
virtual BOOL Init (CWindowID ParentWindow, CGadgetID ParentControl)
 FontDropDown initialiser.
void KillList (void)
 Kills all the items in the drop down and deletes them...
BOOL AddFontToList (TCHAR *FontName, FontClass Type)
 Called for each font installed on the system. Effectively creates the FontPullDown items from the given info.
BOOL FillInFontList ()
 "Fills in" the attached control with appropriate entries for the current FontDropDown settings
BOOL SetTopFontName (StringBase *StrValue, FontClass Type, BOOL Deselect=TRUE)
 Changes the string and bmp in the icon above the font pull down to reflect whatever you give it...
BOOL SetSelection (FontDropItem *TheFont)
 To set the selected item in the list.
FontDropItemDecodeSelection (INT32 SelectionIndex)
 Decodes an index in the dropdown list back into a font.

Public Attributes

List Fonts
BOOL m_MissingItemAdded
FontDropItem TheTopItem

Static Public Attributes

static void * CurrentFontDropDown = 0

Protected Member Functions

virtual BOOL HasIcon (void *ItemData)
 Determine if an item needs an icon next to it.
virtual BOOL DrawIcon (void *ItemData, wxDC &dc, wxRect &IconRect, BOOL Disabled, INT32 flags)
 Draws the icon for an item.
virtual wxString GetText (void *ItemData, INT32 Item)

Friends

class DialogManager

Detailed Description

FontDropDown class itself.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/10/95

Definition at line 170 of file fontdrop.h.


Constructor & Destructor Documentation

FontDropDown::FontDropDown  ) 
 

Default constructor for FontDropDown Class... Notes: If you mistakenly replace the F with a D you get a great song title...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 4/10/95

Definition at line 231 of file fontdrop.cpp.

00232 {
00233     TheTopItem.FontName = _R(IDS_ATM_DEFAULT); // "Default";
00234     TheTopItem.Type = FC_UNDEFINED;
00235     m_MissingItemAdded = FALSE;
00236 }

FontDropDown::~FontDropDown  )  [virtual]
 

Default destructor for FontDropDown Class... Notes: If you mistakenly replace the F with a D you get a great song title...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 5/10/95

Definition at line 250 of file fontdrop.cpp.

00251 {
00252 
00253 }


Member Function Documentation

BOOL FontDropDown::AddFontToList TCHAR FontName,
FontClass  Type
 

Called for each font installed on the system. Effectively creates the FontPullDown items from the given info.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 3/10/95
Parameters:
FontName - Name of font [INPUTS] Type - Type of font
Returns:
TRUE if the font was added to the list ok.

Definition at line 324 of file fontdrop.cpp.

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 }

FontDropItem * FontDropDown::DecodeSelection INT32  SelectionIndex  ) 
 

Decodes an index in the dropdown list back into a font.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 4/10/95
Parameters:
SelectionIndex - The index of the item (which is usually the selected one) [INPUTS] in the combo box.
Returns:
A FontDropItem which is selected... Or NULL if nothing's selected NOTE that if the list is empty, it will return NULL
See also:
FontDropDown::FillInColourList; FontDropDown::AddSpecialEntry

Definition at line 562 of file fontdrop.cpp.

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 }

BOOL FontDropDown::DrawIcon void *  ItemData,
wxDC &  dc,
wxRect &  IconRect,
BOOL  Disabled,
INT32  flags
[protected, virtual]
 

Draws the icon for an item.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 4/10/95
Parameters:
ItemData - Your item data [INPUTS] hDC - The DC to render into IconRect - points at a rectangle (square in fact) to be drawn within Disabled - TRUE if this item is disabled so the icon should be drawn greyed
Returns:
TRUE if this item needs an icon to the left of it, FALSE if not
Notes: Called by HandleDrawItemInternal when this object has been identified as the owner of the control to be redrawn, if HasIcon returned TRUE

This method MUST be overridden by derived classes to provide redraw of their FontDropDown list items. The base class does nothing.

On entry, the DC is ready for you to draw into, including having the camelot palette selected in etc.

See also:
FontDropDown::DrawIcon; FontDropDown::DrawText

Reimplemented from DropDown.

Definition at line 638 of file fontdrop.cpp.

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 }

BOOL FontDropDown::FillInFontList  ) 
 

"Fills in" the attached control with appropriate entries for the current FontDropDown settings

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 3/10/95
Parameters:
[INPUTS] 
Returns:
TRUE if it filled in the list successfully
See also:
FontDropDown::DecodeSelection; FontDropDown::AddSpecialEntry

Definition at line 389 of file fontdrop.cpp.

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 }

wxString FontDropDown::GetText void *  ItemData,
INT32  Item
[protected, virtual]
 

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 3/10/95
Parameters:
ItemData - Your item data [INPUTS]
Returns:
The text

Reimplemented from DropDown.

Definition at line 694 of file fontdrop.cpp.

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 }

BOOL FontDropDown::HasIcon void *  ItemData  )  [protected, virtual]
 

Determine if an item needs an icon next to it.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
ItemData - Your item data [INPUTS]
Returns:
TRUE if this item needs an icon to the left of it, FALSE if not
Notes: Called by HandleDrawItemInternal when this object has been identified as the owner of the control to be redrawn.

This method MUST be overridden by derived classes to provide redraw of their FontDropDown list items. The base class returns FALSE

If you return TRUE, you must also provide the DrawIcon method

See also:
FontDropDown::DrawIcon; FontDropDown::DrawText

Reimplemented from DropDown.

Definition at line 600 of file fontdrop.cpp.

00601 {
00602     // All our items have a space for a truetype icon to their left
00603     return(TRUE);
00604 }

BOOL FontDropDown::Init CWindowID  Window,
CGadgetID  Gadget
[virtual]
 

FontDropDown initialiser.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 26/10/95
Parameters:
Window - The Window in which your dropdown list gadget resides [INPUTS] Gadget - The GadgetID of the deropdown list gadget
Returns:
TRUE if initialised ok...

Reimplemented from DropDown.

Definition at line 272 of file fontdrop.cpp.

00273 {
00274     BOOL ok = DropDown::Init(Window, Gadget);
00275 
00276     return ok;
00277 }

void FontDropDown::KillList void   )  [virtual]
 

Kills all the items in the drop down and deletes them...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 5/10/95

Reimplemented from DropDown.

Definition at line 290 of file fontdrop.cpp.

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 }

BOOL FontDropDown::SetSelection FontDropItem TheFont  ) 
 

To set the selected item in the list.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 4/10/95
Parameters:
TheFont - FontDropItem to select [INPUTS]
Returns:
TRUE if it set the selection OK
See also:
FontDropDown::DecodeSelection; FontDropDown::FillInColourList

Definition at line 473 of file fontdrop.cpp.

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 }

BOOL FontDropDown::SetTopFontName StringBase StrValue,
FontClass  Type,
BOOL  Deselect = TRUE
 

Changes the string and bmp in the icon above the font pull down to reflect whatever you give it...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> Date: 4/10/95
Parameters:
StrValue - Font name, or whatever you want in the icon above the pull down [INPUTS] Type - Type of font - TTF, ATM, etc.... Deselect - If we do an explicit SetSelectedIndex (Or SetSelected) after this call, then set this to FALSE to avoid unneccesary flicker
Returns:
TRUE if ok
See also:
DropDown::HasIcon; DropDown::DrawIcon; DropDown::DrawText

Definition at line 732 of file fontdrop.cpp.

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 }       


Friends And Related Function Documentation

friend class DialogManager [friend]
 

Reimplemented from DropDown.

Definition at line 172 of file fontdrop.h.


Member Data Documentation

void * FontDropDown::CurrentFontDropDown = 0 [static]
 

Definition at line 220 of file fontdrop.h.

List FontDropDown::Fonts
 

Definition at line 223 of file fontdrop.h.

BOOL FontDropDown::m_MissingItemAdded
 

Definition at line 225 of file fontdrop.h.

FontDropItem FontDropDown::TheTopItem
 

Definition at line 228 of file fontdrop.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:54:29 2007 for Camelot by  doxygen 1.4.4