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;
}
wxLayoutObjectCmd::~wxLayoutObjectCmd()
{
delete m_StyleInfo;
- if(m_font) delete m_font;
}
wxLayoutStyleInfo *
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);
}
@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,
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!
*cursorPos = m_Position;
if(cursorSize) *cursorSize = wxPoint(0,0);
}
-
+
+ llist->ApplyStyle(&m_StyleInfo, dc);
for(i = m_ObjectList.begin(); i != NULLIT; i++)
{
(**i).Layout(dc, llist);
if(m_BaseLine >= cursorSize->y) // the normal case anyway
cursorPos->y += m_BaseLine-cursorSize->y;
}
+ RecalculatePositions(1, llist);
}
wxLayoutList::wxLayoutList()
{
- m_DefaultSetting = NULL;
m_FirstLine = NULL;
- m_ColourFG = *wxBLACK;
- m_ColourBG = *wxWHITE;
InvalidateUpdateRect();
Clear();
}
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
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
if( bg )
cbg = wxTheColourDatabase->FindColour(bg);
- SetFont(size,family,style,weight,underline,cfg,cbg);
+ SetFont(family,size,style,weight,underline,cfg,cbg);
}
void
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
// 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
// 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
{
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)
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();
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
}
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
}
-#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);
}
#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();
+}
+
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;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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,
*/
virtual wxLayoutObject *Copy(void);
private:
- /// the font to use
- wxFont *m_font;
wxLayoutStyleInfo *m_StyleInfo;
};
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
+ wxLayoutStyleInfo &GetStyleInfo() { return m_StyleInfo; }
private:
/// Destructor is private. Use DeleteLine() to remove it.
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:
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); }
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 ; }
//@}
*/
int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
-
void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
#ifdef WXLAYOUT_DEBUG
void Debug(void);
} 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;
//@}