]> git.saurik.com Git - wxWidgets.git/commitdiff
Improved auto list numbering
authorJulian Smart <julian@anthemion.co.uk>
Fri, 22 Aug 2008 15:21:50 +0000 (15:21 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Fri, 22 Aug 2008 15:21:50 +0000 (15:21 +0000)
Fixed selection bugs

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55176 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/richtext/richtextbuffer.cpp
src/richtext/richtextctrl.cpp
src/richtext/richtextstyles.cpp

index 51506a79d39344b2ddc50f390e15d64334c120c5..1362fab7092a822153d558ac57a8634288df701a 100644 (file)
@@ -5338,8 +5338,14 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int
     {
         if (para && para->GetRange().GetEnd() == pos)
             pos1 ++;
+
+        // Now see if we need to number the paragraph.
         if (newPara->GetAttributes().HasBulletNumber())
-            newPara->GetAttributes().SetBulletNumber(newPara->GetAttributes().GetBulletNumber()+1);
+        {
+            wxRichTextAttr numberingAttr;
+            if (FindNextParagraphNumber(para, numberingAttr))
+                wxRichTextApplyStyle(newPara->GetAttributes(), (const wxRichTextAttr&) numberingAttr);
+        }
     }
 
     action->SetPosition(pos);
@@ -5448,6 +5454,25 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio
                 }
             }
         }
+
+        // Also apply list style if present
+        if (lookUpNewParaStyle && !para->GetAttributes().GetListStyleName().IsEmpty() && GetStyleSheet())
+        {
+            wxRichTextListStyleDefinition* listDef = GetStyleSheet()->FindListStyle(para->GetAttributes().GetListStyleName());
+            if (listDef)
+            {
+                int thisIndent = para->GetAttributes().GetLeftIndent();
+                int thisLevel = para->GetAttributes().HasOutlineLevel() ? para->GetAttributes().GetOutlineLevel() : listDef->FindLevelForIndent(thisIndent);
+
+                // Apply the overall list style, and item style for this level
+                wxRichTextAttr listStyle(listDef->GetCombinedStyleForLevel(thisLevel, GetStyleSheet()));
+                wxRichTextApplyStyle(attr, listStyle);
+                attr.SetOutlineLevel(thisLevel);
+                if (para->GetAttributes().HasBulletNumber())
+                    attr.SetBulletNumber(para->GetAttributes().GetBulletNumber());
+            }
+               }
+
         if (!foundAttributes)
         {
             attr = para->GetAttributes();
@@ -5460,14 +5485,6 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio
             attr.SetFlags(flags);
         }
 
-        // Now see if we need to number the paragraph.
-        if (attr.HasBulletStyle())
-        {
-            wxTextAttr numberingAttr;
-            if (FindNextParagraphNumber(para, numberingAttr))
-                wxRichTextApplyStyle(attr, (const wxTextAttr&) numberingAttr);
-        }
-
         return attr;
     }
     else
index 485aa1e2b123ca0f4d150134f862609933dcb45f..afc25a3e762a805b66626d301f7395d2996cab5b 100644 (file)
@@ -1097,6 +1097,9 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
 {
     if (flags & wxRICHTEXT_SHIFT_DOWN)
     {
+        if (oldPos == newPos)
+            return false;
+
         wxRichTextRange oldSelection = m_selectionRange;
 
         // If not currently selecting, start selecting
@@ -1115,6 +1118,8 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
             // the end.
             if (newPos > m_selectionAnchor)
                 m_selectionRange.SetRange(m_selectionAnchor+1, newPos);
+            else if (newPos == m_selectionAnchor)
+                m_selectionRange = wxRichTextRange(-2, -2);
             else
                 m_selectionRange.SetRange(newPos+1, m_selectionAnchor);
         }
index 0ce957ad79396c22961df3fcfbc98584157140af..dc39222fb15272a6183015963f191298f6d3d903 100644 (file)
@@ -614,18 +614,76 @@ wxString wxRichTextStyleListBox::CreateHTML(wxRichTextStyleDefinition* def) cons
         str << wxT("<td nowrap>");
 
 #ifdef __WXMSW__
-    int size = 3;
+    int size = 2;
 #else
-    int size = 4;
+    int size = 3;
 #endif
 
-    int stdFontSize = 12;
+       // Guess a standard font size
+    int stdFontSize = 0;
+
+    // First see if we have a default/normal style to base the size on
+    wxString normalTranslated(_("normal"));
+    wxString defaultTranslated(_("default"));
+    size_t i;
+    for (i = 0; i < m_styleNames.GetCount(); i++)
+    {
+               wxString name = m_styleNames[i].Lower();
+               if (name.Find(wxT("normal")) != wxNOT_FOUND || name.Find(normalTranslated) != wxNOT_FOUND ||
+                   name.Find(wxT("default")) != wxNOT_FOUND || name.Find(defaultTranslated) != wxNOT_FOUND)
+               {
+               wxRichTextStyleDefinition* d = GetStyleSheet()->FindStyle(m_styleNames[i]);
+               if (d)
+               {
+                       wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet()));
+                       if (attr2.HasFontSize())
+                       {
+                                       stdFontSize = attr2.GetFontSize();
+                                       break;
+                               }
+                       }
+               }
+       }
+
+    if (stdFontSize == 0)
+    {
+        // Look at sizes up to 20 points, and see which is the most common
+        wxArrayInt sizes;
+        size_t maxSize = 20;
+        for (i = 0; i <= maxSize; i++)
+            sizes.Add(0);
+        for (i = 0; i < m_styleNames.GetCount(); i++)
+        {
+            wxRichTextStyleDefinition* d = GetStyleSheet()->FindStyle(m_styleNames[i]);
+            if (d)
+            {
+                wxRichTextAttr attr2(d->GetStyleMergedWithBase(GetStyleSheet()));
+                if (attr2.HasFontSize())
+                {
+                    if (attr2.GetFontSize() <= (int) maxSize)
+                        sizes[attr2.GetFontSize()] ++;
+                }
+            }
+        }
+        int mostCommonSize = 0;
+        for (i = 0; i <= maxSize; i++)
+        {
+            if (sizes[i] > mostCommonSize)
+                mostCommonSize = i;
+               }
+        if (mostCommonSize > 0)
+            stdFontSize = mostCommonSize;
+    }
+
+    if (stdFontSize == 0)
+       stdFontSize = 12;
+
     int thisFontSize = ((attr.GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0) ? attr.GetFontSize() : stdFontSize;
 
     if (thisFontSize < stdFontSize)
-        size ++;
-    else if (thisFontSize > stdFontSize)
         size --;
+    else if (thisFontSize > stdFontSize)
+        size ++;
 
     str += wxT("<font");