[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
[XaraXtreme-dev] Font dropdown fix
- From: Martin Wuerthner <lists@xxxxxxxxxxxxxxx>
- Date: Mon, 22 May 2006 21:03:16 +0200
- Subject: [XaraXtreme-dev] Font dropdown fix
Find attached below a proposed fix for bug 1057. It adds a transient
entry to the font dropdown list while a substituted font is the
current font. This allows the font name (followed by "(missing)") to
be displayed.
The string " (missing)" is currently a literal in the code. Do I need
to do anything special to expose it for translation?
Martin
Index: wxOil/dropdown.h
===================================================================
--- wxOil/dropdown.h (Revision 1162)
+++ wxOil/dropdown.h (Arbeitskopie)
@@ -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: wxOil/dropdown.cpp
===================================================================
--- wxOil/dropdown.cpp (Revision 1162)
+++ wxOil/dropdown.cpp (Arbeitskopie)
@@ -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: wxOil/fontdrop.h
===================================================================
--- wxOil/fontdrop.h (Revision 1162)
+++ wxOil/fontdrop.h (Arbeitskopie)
@@ -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: wxOil/fontdrop.cpp
===================================================================
--- wxOil/fontdrop.cpp (Revision 1162)
+++ wxOil/fontdrop.cpp (Arbeitskopie)
@@ -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)
Index: tools/textinfo.cpp
===================================================================
--- tools/textinfo.cpp (Revision 1162)
+++ tools/textinfo.cpp (Arbeitskopie)
@@ -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();
- }
}
}
}