I was stupid enough to reorganise the way font changes get stored and applied,

so after only four hours work I'm back where I was yesterday. Selections still
buggy.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2454 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-05-13 21:13:26 +00:00
parent c3317e87ec
commit 60a040b3bb
6 changed files with 165 additions and 167 deletions

View File

@@ -43,35 +43,23 @@ their sizes change:
!!! GOOD: this can also be used to recalculate the wxLayoutObjectCmds'
fonts! :-)
- searching for text
- moving cursor in non-edit mode
- cursor screen positioning ignores font sizes once again :-(
--> UpdateCursorScreenPos() cannot work as it ignores previous font formatting commands.
Either draw cursor when drawing text, or wait for new wxLayoutObjectCmd to be fully
implemented.
RECENTLY FIXED (?)
- fix(simplify) cursor size calculation
- delete in empty line doesn't work
- fix horiz scrollbar size OK here, a Mahogany problem?
- with a large number of lines, wraps to top of scrolled window
--> check where the problem lies, add a debug function showing all coordinates
- update rectangle (needs support in wxllist and wxWindows)
--> needs a bit of fixing still
some code bits are commented out in wxlwindow.cpp
offset handling seems a bit dodgy, white shadow to top/left of cursor
- replacement of llist in window
- undo
- font optimisations(!)
- occasionally wraps lines wongly (twice) ??
- UNDO
later:
- DragNDrop ... broken in wxGTK at present
- cut&paste ... broken in wxGTK at present, Paste already implemented
- Selections
- DragNDrop
- More optimisations:
- let each line have a pointer to the last layoutcommand and let that

View File

@@ -116,6 +116,15 @@ MyFrame::MyFrame(void) :
void
MyFrame::AddSampleText(wxLayoutList *llist)
{
#if 0
llist->Clear(wxSWISS,16,wxNORMAL,wxNORMAL, false);
llist->SetFont(-1,-1,-1,-1,-1,"blue");
llist->Insert("blue");
llist->SetFont(-1,-1,-1,-1,-1,"black");
llist->Insert("The quick brown fox jumps over the lazy dog.");
llist->LineBreak();
#endif
llist->SetFont(wxROMAN,16,wxNORMAL,wxNORMAL, false);
llist->Insert("--");
llist->LineBreak();
@@ -130,7 +139,6 @@ MyFrame::AddSampleText(wxLayoutList *llist)
llist->SetFontWeight(wxNORMAL);
llist->Insert("The quick brown fox jumps...");
llist->LineBreak();
llist->Insert("over the lazy dog.");
llist->SetFont(-1,-1,-1,-1,true);
llist->Insert("underlined");
@@ -144,6 +152,7 @@ MyFrame::AddSampleText(wxLayoutList *llist)
llist->SetFont(-1,-1,wxNORMAL);
llist->LineBreak();
#if 0
llist->Insert("and ");
llist->SetFont(-1,-1,wxSLANT);
llist->Insert("slanted");
@@ -188,6 +197,7 @@ MyFrame::AddSampleText(wxLayoutList *llist)
llist->LineBreak();
}
}
#endif
llist->MoveCursorTo(wxPoint(0,0));
m_lwin->SetDirty();
m_lwin->Refresh();

View File

@@ -297,76 +297,57 @@ wxLayoutStyleInfo::wxLayoutStyleInfo(int ifamily,
underline = iul;
if(fg)
{
fg_valid = true;
fg_red = fg->Red();
fg_blue = fg->Blue();
fg_green = fg->Green();
m_fg = *fg;
m_fg_valid = TRUE;
}
else
fg_valid = false;
m_fg = *wxBLACK;
if(bg)
{
bg_valid = true;
bg_red = bg->Red();
bg_blue = bg->Blue();
bg_green = bg->Green();
m_bg = *bg;
m_bg_valid = TRUE;
}
else
bg_valid = false;
m_bg = *wxWHITE;
}
#define SET_SI(what) tmp.what = (what != -1) ? what : ( si ? si->what : wxNORMAL);
#define COPY_SI_(what) if(right.what != -1) what = right.what;
wxFont *
wxLayoutStyleInfo::GetFont(wxLayoutStyleInfo *si)
wxLayoutStyleInfo &
wxLayoutStyleInfo::operator=(const wxLayoutStyleInfo &right)
{
wxLayoutStyleInfo tmp;
SET_SI(family);
SET_SI(size);
SET_SI(style);
SET_SI(weight);
SET_SI(underline);
return new wxFont(tmp.size,tmp.family,tmp.style,tmp.weight,tmp.underline);
COPY_SI_(family);
COPY_SI_(style);
COPY_SI_(size);
COPY_SI_(weight);
COPY_SI_(underline);
if(right.m_fg_valid) m_fg = right.m_fg;
if(right.m_bg_valid) m_bg = right.m_bg;
return *this;
}
wxLayoutObjectCmd::wxLayoutObjectCmd(int size, int family, int style, int
wxLayoutObjectCmd::wxLayoutObjectCmd(int family, int size, int style, int
weight, int underline,
wxColour *fg, wxColour *bg)
{
m_StyleInfo = new
wxLayoutStyleInfo(size,family,style,weight,underline,fg,bg);
m_font = NULL;
m_StyleInfo = new wxLayoutStyleInfo(family, size,style,weight,underline,fg,bg);
}
wxLayoutObject *
wxLayoutObjectCmd::Copy(void)
{
wxColour
* fg = NULL,
* bg = NULL;
if(m_StyleInfo->fg_valid)
fg = new
wxColour(m_StyleInfo->fg_red,m_StyleInfo->fg_green,m_StyleInfo->fg_blue);
if(m_StyleInfo->bg_valid)
bg = new
wxColour(m_StyleInfo->bg_red,m_StyleInfo->bg_green,m_StyleInfo->bg_blue);
wxLayoutObjectCmd *obj = new wxLayoutObjectCmd(
m_StyleInfo->size,
m_StyleInfo->family,
m_StyleInfo->style,
m_StyleInfo->weight,
m_StyleInfo->underline,
fg, bg);
m_StyleInfo->m_fg_valid ?
&m_StyleInfo->m_fg : NULL,
m_StyleInfo->m_bg_valid ?
&m_StyleInfo->m_bg : NULL);
obj->SetUserData(m_UserData);
if(fg) delete fg;
if(bg) delete bg;
return obj;
}
@@ -374,7 +355,6 @@ wxLayoutObjectCmd::Copy(void)
wxLayoutObjectCmd::~wxLayoutObjectCmd()
{
delete m_StyleInfo;
if(m_font) delete m_font;
}
wxLayoutStyleInfo *
@@ -389,17 +369,12 @@ wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */,
CoordType begin, CoordType /* len */)
{
wxASSERT(m_StyleInfo);
dc.SetFont(*m_font);
wxllist->ApplyStyle(m_StyleInfo, dc);
}
void
wxLayoutObjectCmd::Layout(wxDC &dc, class wxLayoutList * llist)
{
if(m_font) delete m_font;
m_font = m_StyleInfo->GetFont(llist->GetStyleInfo());
// this get called, so that recalculation uses right font sizes
Draw(dc, wxPoint(0,0), llist);
}
@@ -540,7 +515,7 @@ wxLayoutLine::FindObjectScreen(wxDC &dc,
@return the cursoor coord where it was found or -1
*/
CoordType
wxLayoutLine::FindText(const wxString &needle, CoordType xpos = 0) const
wxLayoutLine::FindText(const wxString &needle, CoordType xpos) const
{
int
cpos = 0,
@@ -769,6 +744,7 @@ wxLayoutLine::Draw(wxDC &dc,
CoordType xpos = 0; // cursorpos, lenght of line
CoordType from, to, tempto;
llist->ApplyStyle(&((wxLayoutLine *)this)->m_StyleInfo, dc);
int highlight = llist->IsSelected(this, &from, &to);
// WXLO_DEBUG(("highlight=%d", highlight ));
if(highlight == 1) // we need to draw the whole line inverted!
@@ -834,6 +810,7 @@ wxLayoutLine::Layout(wxDC &dc,
if(cursorSize) *cursorSize = wxPoint(0,0);
}
llist->ApplyStyle(&m_StyleInfo, dc);
for(i = m_ObjectList.begin(); i != NULLIT; i++)
{
(**i).Layout(dc, llist);
@@ -926,6 +903,7 @@ wxLayoutLine::Layout(wxDC &dc,
if(m_BaseLine >= cursorSize->y) // the normal case anyway
cursorPos->y += m_BaseLine-cursorSize->y;
}
RecalculatePositions(1, llist);
}
@@ -1150,10 +1128,7 @@ wxLayoutLine::Copy(wxLayoutList *llist,
wxLayoutList::wxLayoutList()
{
m_DefaultSetting = NULL;
m_FirstLine = NULL;
m_ColourFG = *wxBLACK;
m_ColourBG = *wxWHITE;
InvalidateUpdateRect();
Clear();
}
@@ -1183,19 +1158,20 @@ void
wxLayoutList::InternalClear(void)
{
Empty();
if(m_DefaultSetting)
{
delete m_DefaultSetting;
m_DefaultSetting = NULL;
}
m_Selection.m_selecting = false;
m_Selection.m_valid = false;
m_CurrentSetting.family = wxSWISS;
m_CurrentSetting.size = WXLO_DEFAULTFONTSIZE;
m_CurrentSetting.style = wxNORMAL;
m_CurrentSetting.weight = wxNORMAL;
m_CurrentSetting.underline = 0;
m_DefaultSetting.family = wxSWISS;
m_DefaultSetting.size = WXLO_DEFAULTFONTSIZE;
m_DefaultSetting.style = wxNORMAL;
m_DefaultSetting.weight = wxNORMAL;
m_DefaultSetting.underline = 0;
m_DefaultSetting.m_fg_valid = TRUE;
m_DefaultSetting.m_fg = *wxBLACK;
m_DefaultSetting.m_bg_valid = TRUE;
m_DefaultSetting.m_bg = *wxWHITE;
m_CurrentSetting = m_DefaultSetting;
}
void
@@ -1208,27 +1184,16 @@ wxLayoutList::SetFont(int family, int size, int style, int weight,
if(style != -1) m_CurrentSetting.style = style;
if(weight != -1) m_CurrentSetting.weight = weight;
if(underline != -1) m_CurrentSetting.underline = underline != 0;
if(fg)
{
m_CurrentSetting.fg_valid = true;
m_CurrentSetting.fg_red = fg->Red();
m_CurrentSetting.fg_blue = fg->Blue();
m_CurrentSetting.fg_green = fg->Green();
}
if(bg)
{
m_CurrentSetting.bg_valid = true;
m_CurrentSetting.bg_red = bg->Red();
m_CurrentSetting.bg_blue = bg->Blue();
m_CurrentSetting.bg_green = bg->Green();
}
if(fg) m_CurrentSetting.m_fg = *fg;
if(bg) m_CurrentSetting.m_bg = *bg;
Insert(
new wxLayoutObjectCmd(
m_CurrentSetting.size,
m_CurrentSetting.family,
m_CurrentSetting.size,
m_CurrentSetting.style,
m_CurrentSetting.weight,
m_CurrentSetting.underline, fg, bg));
m_CurrentSetting.underline,
fg, bg));
}
void
@@ -1245,7 +1210,7 @@ wxLayoutList::SetFont(int family, int size, int style, int weight,
if( bg )
cbg = wxTheColourDatabase->FindColour(bg);
SetFont(size,family,style,weight,underline,cfg,cbg);
SetFont(family,size,style,weight,underline,cfg,cbg);
}
void
@@ -1253,12 +1218,9 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
int underline, wxColour *fg, wxColour *bg)
{
InternalClear();
if(m_DefaultSetting)
delete m_DefaultSetting;
m_DefaultSetting = new
wxLayoutStyleInfo(family,size,style,weight,underline,fg,bg);
m_DefaultSetting = wxLayoutStyleInfo(family, size, style, weight,
underline, fg, bg);
m_CurrentSetting = m_DefaultSetting;
}
wxPoint
@@ -1544,7 +1506,7 @@ wxLayoutList::Recalculate(wxDC &dc, CoordType bottom)
// first, make sure everything is calculated - this might not be
// needed, optimise it later
ApplyStyle(m_DefaultSetting, dc);
ApplyStyle(&m_DefaultSetting, dc);
while(line)
{
line->RecalculatePosition(this); // so we don't need to do it all the time
@@ -1575,9 +1537,10 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom)
// first, make sure everything is calculated - this might not be
// needed, optimise it later
ApplyStyle(m_DefaultSetting, dc);
ApplyStyle(&m_DefaultSetting, dc);
while(line)
{
line->GetStyleInfo() = m_CurrentSetting;
if(line == m_CursorLine)
line->Layout(dc, this, (wxPoint *)&m_CursorScreenPos, (wxPoint *)&m_CursorSize, m_CursorPos.x);
else
@@ -1606,9 +1569,8 @@ wxLayoutList::Draw(wxDC &dc,
{
wxLayoutLine *line = m_FirstLine;
Layout(dc, bottom);
ApplyStyle(m_DefaultSetting, dc);
wxBrush brush(m_ColourBG, wxSOLID);
ApplyStyle(&m_DefaultSetting, dc);
wxBrush brush(m_DefaultSetting.m_bg, wxSOLID);
dc.SetBrush(brush);
while(line)
@@ -1638,7 +1600,7 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos,
wxPoint p;
// we need to run a layout here to get font sizes right :-(
ApplyStyle(m_DefaultSetting, dc);
ApplyStyle(&m_DefaultSetting, dc);
while(line)
{
p = line->GetPosition();
@@ -1892,8 +1854,8 @@ void
wxLayoutList::StartHighlighting(wxDC &dc)
{
#if SHOW_SELECTIONS
dc.SetTextForeground(m_ColourBG);
dc.SetTextBackground(m_ColourFG);
dc.SetTextForeground(m_CurrentSetting.m_bg);
dc.SetTextBackground(m_CurrentSetting.m_fg);
#endif
}
@@ -1902,8 +1864,8 @@ void
wxLayoutList::EndHighlighting(wxDC &dc)
{
#if SHOW_SELECTIONS
dc.SetTextForeground(m_ColourFG);
dc.SetTextBackground(m_ColourBG);
dc.SetTextForeground(m_CurrentSetting.m_fg);
dc.SetTextBackground(m_CurrentSetting.m_bg);
#endif
}
@@ -1979,41 +1941,30 @@ wxLayoutList::GetSelection(void)
#define COPY_SI(what) if(si->what != -1) m_CurrentSetting.what = si->what;
#define COPY_SI(what) if(si->what != -1) { m_CurrentSetting.what = si->what; fontChanged = TRUE; }
void
wxLayoutList::ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc)
{
bool fontChanged = FALSE;
COPY_SI(family);
COPY_SI(size);
COPY_SI(style);
COPY_SI(weight);
COPY_SI(underline);
if(fontChanged)
dc.SetFont( m_FontCache.GetFont(m_CurrentSetting) );
if(si->fg_valid)
if(si->m_fg_valid)
{
m_CurrentSetting.fg_valid = true;
m_CurrentSetting.fg_red = si->fg_red;
m_CurrentSetting.fg_green = si->fg_green;
m_CurrentSetting.fg_blue = si->fg_blue;
m_CurrentSetting.m_fg = si->m_fg;
dc.SetTextForeground(m_CurrentSetting.m_fg);
}
if(si->bg_valid)
if(si->m_bg_valid)
{
m_CurrentSetting.bg_valid = true;
m_CurrentSetting.bg_red = si->bg_red;
m_CurrentSetting.bg_green = si->bg_green;
m_CurrentSetting.bg_blue = si->bg_blue;
m_CurrentSetting.m_bg = si->m_bg;
dc.SetTextBackground(m_CurrentSetting.m_bg);
}
m_ColourFG = wxColour(m_CurrentSetting.fg_red,
m_CurrentSetting.fg_green,
m_CurrentSetting.fg_blue);
m_ColourBG = wxColour(m_CurrentSetting.bg_red,
m_CurrentSetting.bg_green,
m_CurrentSetting.bg_blue);
dc.SetTextForeground(m_ColourFG);
dc.SetTextBackground(m_ColourBG);
}
@@ -2203,3 +2154,18 @@ wxLayoutPrintout::DrawHeader(wxDC &dc,
#endif
wxFont &
wxFontCache::GetFont(int family, int size, int style, int weight,
bool underline)
{
for(wxFCEList::iterator i = m_FontList.begin();
i != m_FontList.end(); i++)
if( (**i).Matches(family, size, style, weight, underline) )
return (**i).GetFont();
// not found:
wxFontCacheEntry *fce = new wxFontCacheEntry(family, size, style,
weight, underline);
m_FontList.push_back(fce);
return fce->GetFont();
}

View File

@@ -290,23 +290,61 @@ struct wxLayoutStyleInfo
int iul = -1,
wxColour *fg = NULL,
wxColour *bg = NULL);
wxColour * GetBGColour() const
wxColour & GetBGColour()
{
return fg_valid ? new
wxColour(bg_red,bg_green,bg_blue)
: wxWHITE;
return m_bg;
}
wxFont *GetFont(wxLayoutStyleInfo *);
wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
/// Font change parameters.
int size, family, style, weight, underline;
/// Is foreground colour valid to bet set?
bool fg_valid;
/// Is background colour valid to bet set?
bool bg_valid;
/// Foreground colour RGB values.
unsigned fg_red, fg_green, fg_blue;
/// Background colour RGB values.
unsigned bg_red, bg_green, bg_blue;
/// Colours
wxColour m_bg, m_fg;
bool m_fg_valid, m_bg_valid;
};
class wxFontCacheEntry
{
public:
wxFontCacheEntry(int family, int size, int style, int weight,
bool underline)
{
m_Family = family; m_Size = size; m_Style = style;
m_Weight = weight; m_Underline = underline;
m_Font = new wxFont(m_Size, m_Family,
m_Style, m_Weight, m_Underline);
}
bool Matches(int family, int size, int style, int weight,
bool underline) const
{
return size == m_Size && family == m_Family
&& style == m_Style && weight == m_Weight
&& underline == m_Underline;
}
wxFont & GetFont(void) { return *m_Font; }
~wxFontCacheEntry()
{
delete m_Font;
}
private:
wxFont *m_Font;
int m_Family, m_Size, m_Style, m_Weight;
bool m_Underline;
};
KBLIST_DEFINE(wxFCEList, wxFontCacheEntry);
class wxFontCache
{
public:
wxFont & GetFont(int family, int size, int style, int weight,
bool underline);
wxFont & GetFont(wxLayoutStyleInfo const &si)
{
return GetFont(si.family, si.size, si.style, si.weight, si.underline);
}
private:
wxFCEList m_FontList;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -325,8 +363,8 @@ public:
class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
wxLayoutObjectCmd(int size = -1,
int family = -1,
wxLayoutObjectCmd(int family = -1,
int size = -1,
int style = -1,
int weight = -1,
int underline = -1,
@@ -339,8 +377,6 @@ public:
*/
virtual wxLayoutObject *Copy(void);
private:
/// the font to use
wxFont *m_font;
wxLayoutStyleInfo *m_StyleInfo;
};
@@ -566,6 +602,7 @@ public:
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
wxLayoutStyleInfo &GetStyleInfo() { return m_StyleInfo; }
private:
/// Destructor is private. Use DeleteLine() to remove it.
@@ -611,6 +648,8 @@ private:
wxLayoutLine *m_Previous;
/// Pointer to next line if it exists.
wxLayoutLine *m_Next;
/// A StyleInfo structure, holding the current settings.
wxLayoutStyleInfo m_StyleInfo;
/// Just to suppress gcc compiler warnings.
friend class dummy;
private:
@@ -760,10 +799,10 @@ public:
char const *bg = NULL);
/// changes to the next larger font size
inline void SetFontLarger(void)
{ SetFont(-1,(12*m_FontPtSize)/10); }
{ SetFont(-1,(12*m_CurrentSetting.size)/10); }
/// changes to the next smaller font size
inline void SetFontSmaller(void)
{ SetFont(-1,(10*m_FontPtSize)/12); }
{ SetFont(-1,(10*m_CurrentSetting.size)/12); }
/// set font family
inline void SetFontFamily(int family) { SetFont(family); }
@@ -789,7 +828,7 @@ public:
anywhere.
@return the default settings of the list
*/
wxLayoutStyleInfo *GetDefaults(void) { return m_DefaultSetting ; }
wxLayoutStyleInfo *GetDefaults(void) { return &m_DefaultSetting ; }
wxLayoutStyleInfo *GetStyleInfo(void) { return &m_CurrentSetting ; }
//@}
@@ -914,7 +953,6 @@ public:
*/
int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
#ifdef WXLAYOUT_DEBUG
void Debug(void);
@@ -954,14 +992,10 @@ private:
} m_Selection;
/** @name Font parameters. */
//@{
int m_FontFamily, m_FontStyle, m_FontWeight;
int m_FontPtSize;
bool m_FontUnderline;
/// colours:
wxColour m_ColourFG;
wxColour m_ColourBG;
/// this object manages the fonts for us
wxFontCache m_FontCache;
/// the default setting:
wxLayoutStyleInfo *m_DefaultSetting;
wxLayoutStyleInfo m_DefaultSetting;
/// the current setting:
wxLayoutStyleInfo m_CurrentSetting;
//@}

View File

@@ -77,17 +77,17 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
html += "<font ";
if(si->fg_valid)
if(si->m_fg_valid)
{
html +="color=";
sprintf(buffer,"\"#%02X%02X%02X\"", si->fg_red,si->fg_green,si->fg_blue);
sprintf(buffer,"\"#%02X%02X%02X\"", si->m_fg.Red(),si->m_fg.Green(),si->m_fg.Blue());
html += buffer;
}
if(si->bg_valid)
if(si->m_bg_valid)
{
html += " bgcolor=";
sprintf(buffer,"\"#%02X%02X%02X\"", si->bg_red,si->bg_green,si->bg_blue);
sprintf(buffer,"\"#%02X%02X%02X\"", si->m_bg.Red(),si->m_bg.Green(),si->m_bg.Blue());
html += buffer;
}

View File

@@ -115,7 +115,7 @@ wxLayoutWindow::Clear(int family,
wxColour *bg)
{
GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
SetBackgroundColour(*GetLayoutList()->GetDefaults()->GetBGColour());
SetBackgroundColour(GetLayoutList()->GetDefaults()->GetBGColour());
ResizeScrollbars(true);
SetDirty();
SetModified(false);
@@ -494,8 +494,8 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
}
m_memDC->SetDeviceOrigin(0,0);
m_memDC->SetBrush(wxBrush(*m_llist->GetDefaults()->GetBGColour(),wxSOLID));
m_memDC->SetPen(wxPen(*m_llist->GetDefaults()->GetBGColour(),
m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(),wxSOLID));
m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(),
0,wxTRANSPARENT));
m_memDC->SetLogicalFunction(wxCOPY);