[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : alex
Repository : xara
Revision   : 1164
Date       : Mon May 22 20:11:59 BST 2006

Changed paths:
   M /Trunk/XaraLX/tools/textinfo.cpp
   M /Trunk/XaraLX/wxOil/dropdown.cpp
   M /Trunk/XaraLX/wxOil/dropdown.h
   M /Trunk/XaraLX/wxOil/fontdrop.cpp
   M /Trunk/XaraLX/wxOil/fontdrop.h

Commit Martin W's patch re missing font names


Diff:
Index: Trunk/XaraLX/tools/textinfo.cpp
===================================================================
--- Trunk/XaraLX/tools/textinfo.cpp	(revision 1163)
+++ Trunk/XaraLX/tools/textinfo.cpp	(revision 1164)
@@ -2514,17 +2514,19 @@
 						if (NameDropDown != NULL)
 						{
 							FontDropItem *Selected = NameDropDown->DecodeSelection((INT32)SelIndex);
-
-							if (FONTMANAGER->IsFontInstalled(&Selected->FontName, Selected->Type))
+							if (Selected)
 							{
-								if (SetCurrentFontName(&Selected->FontName, Selected->Type, TRUE))
-									OnFieldChange(FontNameA);
+								if (FONTMANAGER->IsFontInstalled(&Selected->FontName, Selected->Type))
+								{
+									if (SetCurrentFontName(&Selected->FontName, Selected->Type, TRUE))
+										OnFieldChange(FontNameA);
+								}
+								else
+								{
+									InformWarning(_R(IDS_INVALIDFONT));
+									Update();
+								}
 							}
-							else
-							{
-								InformWarning(_R(IDS_INVALIDFONT));
-								Update();
-							}			 
 						}
 					}
 				}
Index: Trunk/XaraLX/wxOil/dropdown.h
===================================================================
--- Trunk/XaraLX/wxOil/dropdown.h	(revision 1163)
+++ Trunk/XaraLX/wxOil/dropdown.h	(revision 1164)
@@ -157,6 +157,9 @@
 	void AddItem(void * ItemData);
 				// Adds an item to the end of the list
 
+	void DeleteItem(INT32 index);
+				// Deletes an item
+
 	void SetSelectedIndex(INT32 SelectedIndex);
 				// Sets the index of the selected item
 
Index: Trunk/XaraLX/wxOil/dropdown.cpp
===================================================================
--- Trunk/XaraLX/wxOil/dropdown.cpp	(revision 1163)
+++ Trunk/XaraLX/wxOil/dropdown.cpp	(revision 1164)
@@ -400,8 +400,34 @@
 		pGadget->SetString(n, GetText(ItemData, n));
 }
 
+/********************************************************************************************
 
+>	void DropDown::DeleteItem(INT32 index)
 
+	Author:		Martin Wuerthner <xara@xxxxxxxxxxxxxxx>
+	Date:		22/05/06
+
+	Inputs:		index - the index of the item to be removed
+	Purpose:	Removes an item from the list
+
+********************************************************************************************/
+
+void DropDown::DeleteItem(INT32 index)
+{
+	wxOwnerDrawnComboBox * pGadget = GetBox();
+	if (!pGadget)
+		return;
+	INT32 count = (INT32)pGadget->GetCount();
+	if (index >= 0 && index < count)
+	{
+		pGadget->Delete(index);
+	}
+	else
+	{
+		ERROR3("DropDown::RemoveItem - attempt to delete non-existing item");
+	}
+}
+
 /********************************************************************************************
 
 >	void DropDown::SetSelectedIndex(INT32 SelectedIndex)
Index: Trunk/XaraLX/wxOil/fontdrop.h
===================================================================
--- Trunk/XaraLX/wxOil/fontdrop.h	(revision 1163)
+++ Trunk/XaraLX/wxOil/fontdrop.h	(revision 1164)
@@ -128,6 +128,8 @@
 
 public:
 	String_64	GetFontName() { return FontName; }
+	void SetInfo(String_64& theFontName, FontClass theType)
+		{ FontName = theFontName; Type = theType; }
 };
 
 
@@ -220,6 +222,8 @@
 	// List of font items
 	List Fonts;
 
+	BOOL m_MissingItemAdded;
+
 	// We need a special entry for the top item...
 	FontDropItem TheTopItem;
 
Index: Trunk/XaraLX/wxOil/fontdrop.cpp
===================================================================
--- Trunk/XaraLX/wxOil/fontdrop.cpp	(revision 1163)
+++ Trunk/XaraLX/wxOil/fontdrop.cpp	(revision 1164)
@@ -232,6 +232,7 @@
 {
 	TheTopItem.FontName = _R(IDS_ATM_DEFAULT); // "Default";
 	TheTopItem.Type = FC_UNDEFINED;
+	m_MissingItemAdded = FALSE;
 }
 
 /********************************************************************************************
@@ -299,6 +300,7 @@
 		delete( (FontDropItem*)((Fonts.RemoveItem(Item))) );
 		Item = Prev;
 	}
+	m_MissingItemAdded = FALSE;
 }
 
 
@@ -387,6 +389,7 @@
 BOOL FontDropDown::FillInFontList()
 {
 	ERROR2IF(ParentDlg == NULL, FALSE, "FontDropDown not properly initialised");
+	TRACEUSER("wuerthne", _T("FillInFontList"));
 
 	SetListRedraw(FALSE);										// Disable redraw while updating
 	ClearList();												// Delete combobox contents
@@ -396,6 +399,7 @@
 
 	if(Fonts.GetCount() == 0)
 	{
+		TRACEUSER("wuerthne", _T("FontDropDown enumerating fonts"));
 		FontDropEnumFont EnumObj;
 		EnumObj.Execute();
 
@@ -472,6 +476,8 @@
 
 	INT32 SelectedIndex = -1;
 
+    TRACEUSER("wuerthne", _T("SetSelection to %s"), (TCHAR*)TheFont->FontName);
+
 	INT32 Index = 0;
 	INT32 MaxIndex = GetNumberOfItems();
 
@@ -487,8 +493,48 @@
 		Index++;
 	}
 
+	if (Index == MaxIndex)
+	{
+		TRACEUSER("wuerthne", _T("font not in list, Index = %d"), Index);
+		// font was not in the list, so make sure there is a special item at the
+		// end to accomodate it
+		String_64 NewName(TheFont->FontName + _T(" (missing)"));
+			
+		if (m_MissingItemAdded)
+		{
+			TRACEUSER("wuerthne", _T("update missing item"));
+			FontDropItem *Item = (FontDropItem*)Fonts.GetTail();
+			Item->SetInfo(NewName, TheFont->Type);
+			SelectedIndex = Index - 1;
+		}
+		else
+		{
+			TRACEUSER("wuerthne", _T("add missing item"));
+			FontDropItem *Item = new FontDropItem(NewName, TheFont->Type);
+			Fonts.AddTail(Item);
+			AddItem((void*) Item);
+			m_MissingItemAdded = TRUE;
+			SelectedIndex = Index;
+		}
+	}
+	else
+	{
+		// the font was in the list, so if there is a "missing" item at the end remove it
+		// (unless of course, the selected item *is* the "missing" item, but this cannot
+		// normally happen because our item has the added text " (missing)")
+		if (m_MissingItemAdded && SelectedIndex != MaxIndex - 1)
+		{
+			TRACEUSER("wuerthne", _T("remove missing item"));
+			delete( (FontDropItem*)((Fonts.RemoveItem(Fonts.GetTail()))) );
+			m_MissingItemAdded = FALSE;
+
+			// delete the item from the combo box
+			DeleteItem(MaxIndex - 1);
+		}
+	}
+	TRACEUSER("wuerthne", _T("setting index to %d"), SelectedIndex);
 	SetSelectedIndex(SelectedIndex);						// And set the appropriate selected item
-  
+	TRACEUSER("wuerthne", _T("SetSelection done"));
 	return(TRUE);
 }
 
@@ -514,6 +560,8 @@
 
 FontDropItem *FontDropDown::DecodeSelection(INT32 SelectionIndex)
 {
+	// do not allow the extra "missing" item to be selected
+	if (SelectionIndex == GetNumberOfItems() - 1 && m_MissingItemAdded) return NULL;
 	FontDropItem *Fred = (FontDropItem *) GetItemData(SelectionIndex);
 
 	if (Fred==&TheTopItem)


Xara