~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to src/richtext/richtextbuffer.cpp

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:      Julian Smart
5
5
// Modified by:
6
6
// Created:     2005-09-30
7
 
// RCS-ID:      $Id: richtextbuffer.cpp 63358 2010-02-02 22:19:52Z JS $
 
7
// RCS-ID:      $Id: richtextbuffer.cpp 67111 2011-03-02 20:55:16Z JS $
8
8
// Copyright:   (c) Julian Smart
9
9
// Licence:     wxWindows licence
10
10
/////////////////////////////////////////////////////////////////////////////
1425
1425
        wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph);
1426
1426
        wxASSERT( child != NULL );
1427
1427
 
1428
 
        if (child->GetRange().Contains(pos))
 
1428
        if (child->GetRange().Contains(pos) || pos == child->GetRange().GetStart())
1429
1429
        {
1430
1430
            wxRichTextLineList::compatibility_iterator node2 = child->GetLines().GetFirst();
1431
1431
            while (node2)
3183
3183
            // So when changing a list style interactively, could retrieve level based on current style, then
3184
3184
            // set appropriate indent and apply new style.
3185
3185
 
 
3186
            int outline = -1;
 
3187
            int num = -1;
 
3188
            if (para->GetAttributes().HasOutlineLevel())
 
3189
                outline = para->GetAttributes().GetOutlineLevel();
 
3190
            if (para->GetAttributes().HasBulletNumber())
 
3191
                num = para->GetAttributes().GetBulletNumber();
 
3192
 
3186
3193
            if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && !para->GetAttributes().GetListStyleName().IsEmpty())
3187
3194
            {
3188
3195
                int currentIndent = para->GetAttributes().GetLeftIndent();
3233
3240
                    foundCount ++;
3234
3241
                }
3235
3242
            }
 
3243
 
 
3244
            if (outline != -1)
 
3245
                para->GetAttributes().SetOutlineLevel(outline);
 
3246
            if (num != -1)
 
3247
                para->GetAttributes().SetBulletNumber(num);
3236
3248
        }
3237
3249
 
3238
3250
        node = node->GetNext();
3858
3870
    int lineSpacing = 0;
3859
3871
 
3860
3872
    // Let's assume line spacing of 10 is normal, 15 is 1.5, 20 is 2, etc.
3861
 
    if (attr.GetLineSpacing() != 10 && attr.GetFont().Ok())
 
3873
    if (attr.HasLineSpacing() && attr.GetLineSpacing() > 0 && attr.GetFont().Ok())
3862
3874
    {
3863
3875
        wxCheckSetFont(dc, attr.GetFont());
3864
 
        lineSpacing = (ConvertTenthsMMToPixels(dc, dc.GetCharHeight()) * attr.GetLineSpacing())/10;
 
3876
        lineSpacing = (int) (double(dc.GetCharHeight()) * (double(attr.GetLineSpacing())/10.0 - 1.0));
3865
3877
    }
3866
3878
 
3867
3879
    // Available space for text on each line differs.
3907
3919
    int paraDescent;
3908
3920
 
3909
3921
    // This calculates the partial text extents
3910
 
    GetRangeSize(GetRange(), paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_CACHE_SIZE, wxPoint(0,0));
 
3922
    GetRangeSize(GetRange(), paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_CACHE_SIZE, rect.GetPosition());
3911
3923
    g_UseGlobalPartialTextExtents = false;
3912
3924
#else
3913
3925
    node = m_children.GetFirst();
4118
4130
    ApplyParagraphStyle(attr, rect);
4119
4131
    g_globalDC = NULL;
4120
4132
 
4121
 
    SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceBeforePara + spaceAfterPara));
 
4133
    SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceAfterPara));
4122
4134
 
4123
4135
    m_dirty = false;
4124
4136
 
4521
4533
                int paraDescent;
4522
4534
 
4523
4535
                // This calculates the partial text extents
4524
 
                GetRangeSize(lineRange, paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED, wxPoint(0,0));
 
4536
                GetRangeSize(lineRange, paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED, linePos);
4525
4537
                g_UseGlobalPartialTextExtents = false;
4526
4538
 
4527
4539
                int lastX = linePos.x;
5318
5330
            dc.SetBackgroundMode(wxTRANSPARENT);
5319
5331
    }
5320
5332
 
5321
 
    wxCoord x_orig = x;
 
5333
    wxCoord x_orig = GetParent()->GetPosition().x;
5322
5334
    while (hasTabs)
5323
5335
    {
5324
5336
        // the string has a tab
5394
5406
{
5395
5407
    // Only lay out if we haven't already cached the size
5396
5408
    if (m_size.x == -1)
5397
 
        GetRangeSize(GetRange(), m_size, m_descent, dc, 0, wxPoint(0, 0));
 
5409
        GetRangeSize(GetRange(), m_size, m_descent, dc, 0, GetParent() ? GetParent()->GetPosition() : wxPoint(0, 0));
5398
5410
 
5399
5411
    return true;
5400
5412
}
5417
5429
    wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph);
5418
5430
    wxASSERT (para != NULL);
5419
5431
 
 
5432
    int relativeX = position.x - GetParent()->GetPosition().x;
 
5433
 
5420
5434
    wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes());
5421
5435
 
5422
5436
    // Always assume unformatted text, since at this level we have no knowledge
5507
5521
                    textExtents.Add(oldWidth + p[j]);
5508
5522
 
5509
5523
                if (textExtents.GetCount() > 0)
5510
 
                    absoluteWidth = textExtents[textExtents.GetCount()-1] + position.x;
 
5524
                    absoluteWidth = textExtents[textExtents.GetCount()-1] + relativeX;
5511
5525
                else
5512
 
                    absoluteWidth = position.x;
 
5526
                    absoluteWidth = relativeX;
5513
5527
            }
5514
5528
            else
5515
5529
#endif
5538
5552
 
5539
5553
                    notFound = false;
5540
5554
 
5541
 
                    width = nextTabPos - position.x;
 
5555
                    width = nextTabPos - relativeX;
5542
5556
 
5543
5557
#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS
5544
5558
                    if (g_UseGlobalPartialTextExtents)
5689
5703
 
5690
5704
    if (textObject)
5691
5705
    {
 
5706
        bool isEmpty = m_text.IsEmpty();
5692
5707
        m_text += textObject->GetText();
5693
 
        wxRichTextApplyStyle(m_attributes, textObject->GetAttributes());
 
5708
        // Don't keep an empty object's attributes
 
5709
        if (isEmpty)
 
5710
            m_attributes = textObject->GetAttributes();
 
5711
        else
 
5712
            wxRichTextApplyStyle(m_attributes, textObject->GetAttributes());
5694
5713
        return true;
5695
5714
    }
5696
5715
    else
5804
5823
}
5805
5824
 
5806
5825
/// Submit command to insert paragraphs
5807
 
bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags)
 
5826
bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int WXUNUSED(flags))
5808
5827
{
5809
5828
    wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, this, ctrl, false);
5810
5829
 
5811
 
    wxTextAttrEx attr(GetDefaultStyle());
5812
 
 
5813
 
    wxTextAttrEx* p = NULL;
5814
 
    wxTextAttrEx paraAttr;
5815
 
    if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
5816
 
    {
5817
 
        paraAttr = GetStyleForNewParagraph(pos);
5818
 
        if (!paraAttr.IsDefault())
5819
 
            p = & paraAttr;
5820
 
    }
5821
 
    else
5822
 
        p = & attr;
5823
 
 
5824
5830
    action->GetNewParagraphs() = paragraphs;
5825
5831
 
5826
 
    if (p && !p->IsDefault())
5827
 
    {
5828
 
        for (wxRichTextObjectList::compatibility_iterator node = action->GetNewParagraphs().GetChildren().GetFirst(); node; node = node->GetNext())
5829
 
        {
5830
 
            wxRichTextObject* child = node->GetData();
5831
 
            child->SetAttributes(*p);
5832
 
        }
5833
 
    }
5834
 
 
5835
5832
    action->SetPosition(pos);
5836
5833
 
5837
5834
    wxRichTextRange range = wxRichTextRange(pos, pos + paragraphs.GetRange().GetEnd() - 1);
6973
6970
 
6974
6971
        dc.DrawPolygon(3, pts);
6975
6972
    }
 
6973
    else if (bulletAttr.GetBulletName() == wxT("standard/circle-outline"))
 
6974
    {
 
6975
        wxCheckSetBrush(dc, *wxTRANSPARENT_BRUSH);
 
6976
        dc.DrawEllipse(x, y, bulletWidth, bulletHeight);
 
6977
    }
6976
6978
    else // "standard/circle", and catch-all
6977
6979
    {
6978
6980
        dc.DrawEllipse(x, y, bulletWidth, bulletHeight);
7040
7042
bool wxRichTextStdRenderer::EnumerateStandardBulletNames(wxArrayString& bulletNames)
7041
7043
{
7042
7044
    bulletNames.Add(wxTRANSLATE("standard/circle"));
 
7045
    bulletNames.Add(wxTRANSLATE("standard/circle-outline"));
7043
7046
    bulletNames.Add(wxTRANSLATE("standard/square"));
7044
7047
    bulletNames.Add(wxTRANSLATE("standard/diamond"));
7045
7048
    bulletNames.Add(wxTRANSLATE("standard/triangle"));
8704
8707
    attr.SetTabs(GetTabs());
8705
8708
    attr.SetLeftIndent(GetLeftIndent(), GetLeftSubIndent());
8706
8709
    attr.SetRightIndent(GetRightIndent());
8707
 
    attr.SetFont(CreateFont());
 
8710
    if (HasFont())
 
8711
        attr.SetFont(CreateFont());
8708
8712
 
8709
8713
    attr.SetParagraphSpacingAfter(m_paragraphSpacingAfter);
8710
8714
    attr.SetParagraphSpacingBefore(m_paragraphSpacingBefore);
9506
9510
    buf[1] = hexArray[secondDigit];
9507
9511
}
9508
9512
 
 
9513
inline int wxRichTextHexToDec(const wxChar* buf)
 
9514
{
 
9515
    int firstDigit, secondDigit;
 
9516
 
 
9517
    if (buf[0] >= wxT('A'))
 
9518
        firstDigit = buf[0] - wxT('A') + 10;
 
9519
    else
 
9520
       firstDigit = buf[0] - wxT('0');
 
9521
 
 
9522
    if (buf[1] >= wxT('A'))
 
9523
        secondDigit = buf[1] - wxT('A') + 10;
 
9524
    else
 
9525
        secondDigit = buf[1] - wxT('0');
 
9526
 
 
9527
    return (firstDigit & 0xF) * 16 + (secondDigit & 0xF );
 
9528
}
 
9529
 
 
9530
 
9509
9531
// Write data in hex to a stream
9510
9532
bool wxRichTextImageBlock::WriteHex(wxOutputStream& stream)
9511
9533
{
9555
9577
        str[0] = stream.GetC();
9556
9578
        str[1] = stream.GetC();
9557
9579
 
9558
 
        m_data[i] = (unsigned char)wxHexToDec(str);
 
9580
        m_data[i] = (unsigned char)wxRichTextHexToDec(str);
9559
9581
    }
9560
9582
 
9561
9583
    m_dataSize = dataSize;