diff --git a/user/wxLayout/TODO b/user/wxLayout/TODO index 3f65a621c5..f19ba13770 100644 --- a/user/wxLayout/TODO +++ b/user/wxLayout/TODO @@ -11,12 +11,20 @@ BUGS - delete in empty line doesn't always work - fix initial scrollbar sizes - fix horiz scrollbar size - - occasionally wraps lines wongly (twice) ?? TODO ===================================================================== +Selections: + - moving in negative direction doesn't work + - selection state not properly reset, only works once + - selecting non-text objects is strange + +wxllist::GetSize() requires extra Layout() call, which should not be +necessary. Find out why this is so. + + - Image at end of a message doesn't get considered properly in wxLayoutList::GetSize(), so it cannot be seen - searching for text diff --git a/user/wxLayout/wxLayout.cpp b/user/wxLayout/wxLayout.cpp index 4d8d9baf90..7a0e4e3436 100644 --- a/user/wxLayout/wxLayout.cpp +++ b/user/wxLayout/wxLayout.cpp @@ -36,7 +36,7 @@ IMPLEMENT_APP(MyApp) enum ids{ ID_ADD_SAMPLE = 1, ID_CLEAR, ID_PRINT, ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS, ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS, - ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, + ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT, ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT, ID_TEST, ID_LONG_TEST }; @@ -94,6 +94,7 @@ MyFrame::MyFrame(void) : edit_menu->Append(ID_NOWRAP, "No-wrap mode", "Deactivate wrapping."); edit_menu->AppendSeparator(); edit_menu->Append(ID_COPY, "Copy", "Copy text to clipboard."); + edit_menu->Append(ID_CUT, "Cut", "Cut text to clipboard."); edit_menu->Append(ID_PASTE,"Paste", "Paste text from clipboard."); menu_bar->Append(edit_menu, "Edit" ); @@ -231,9 +232,15 @@ void MyFrame::OnCommand( wxCommandEvent &event ) break; case ID_PASTE: m_lwin->Paste(); + m_lwin->Refresh(FALSE); break; case ID_COPY: m_lwin->Copy(); + m_lwin->Refresh(FALSE); + break; + case ID_CUT: + m_lwin->Cut(); + m_lwin->Refresh(FALSE); break; case ID_HTML: { diff --git a/user/wxLayout/wxllist.cpp b/user/wxLayout/wxllist.cpp index b39029807a..4f9db2af9e 100644 --- a/user/wxLayout/wxllist.cpp +++ b/user/wxLayout/wxllist.cpp @@ -27,6 +27,7 @@ # define SHOW_SELECTIONS 1 #else # include "wxllist.h" +# include "wxlparser.h" # define SHOW_SELECTIONS 1 #endif @@ -209,7 +210,7 @@ wxLayoutObjectText::GetOffsetScreen(wxDC &dc, CoordType xpos) const } void -wxLayoutObjectText::Layout(wxDC &dc) +wxLayoutObjectText::Layout(wxDC &dc, class wxLayoutList * ) { long descent = 0l; @@ -262,7 +263,7 @@ wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords, } void -wxLayoutObjectIcon::Layout(wxDC & /* dc */) +wxLayoutObjectIcon::Layout(wxDC & /* dc */, class wxLayoutList * ) { } @@ -278,54 +279,108 @@ wxLayoutObjectIcon::GetSize(CoordType *top, CoordType *bottom) const /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - wxLayoutObjectIcon + wxLayoutObjectCmd * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +wxLayoutStyleInfo::wxLayoutStyleInfo(int ifamily, + int isize, + int istyle, + int iweight, + int iul, + wxColour *fg, + wxColour *bg) +{ + family = ifamily; size = isize; + style = istyle; weight = iweight; + underline = iul; + if(fg) + { + fg_valid = true; + fg_red = fg->Red(); + fg_blue = fg->Blue(); + fg_green = fg->Green(); + } + else + fg_valid = false; + if(bg) + { + bg_valid = true; + bg_red = bg->Red(); + bg_blue = bg->Blue(); + bg_green = bg->Green(); + } + else + bg_valid = false; +} + +#define SET_SI(what) tmp.what = (what != -1) ? what : ( si ? si->what : wxNORMAL); + + +wxFont * +wxLayoutStyleInfo::GetFont(wxLayoutStyleInfo *si) +{ + 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); + +} + wxLayoutObjectCmd::wxLayoutObjectCmd(int size, int family, int style, int - weight, bool underline, - wxColour &fg, wxColour &bg) + weight, int underline, + wxColour *fg, wxColour *bg) { - m_font = new wxFont(size,family,style,weight,underline); - m_ColourFG = fg; - m_ColourBG = bg; + m_StyleInfo = new + wxLayoutStyleInfo(size,family,style,weight,underline,fg,bg); + m_font = m_StyleInfo->GetFont(NULL); } wxLayoutObject * wxLayoutObjectCmd::Copy(void) { - wxLayoutStyleInfo si; - GetStyle(&si); + 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( - si.size, si.family, si.style, si.weight, si.underline, - m_ColourFG, m_ColourBG); + m_StyleInfo->size, + m_StyleInfo->family, + m_StyleInfo->style, + m_StyleInfo->weight, + m_StyleInfo->underline, + fg, bg); obj->SetUserData(m_UserData); + + if(fg) delete fg; + if(bg) delete bg; return obj; } wxLayoutObjectCmd::~wxLayoutObjectCmd() { + delete m_StyleInfo; delete m_font; } -void -wxLayoutObjectCmd::GetStyle(wxLayoutStyleInfo *si) const +wxLayoutStyleInfo * +wxLayoutObjectCmd::GetStyle(void) const { - si->size = m_font->GetPointSize(); - si->family = m_font->GetFamily(); - si->style = m_font->GetStyle(); - si->underline = m_font->GetUnderlined(); - si->weight = m_font->GetWeight(); - - si->fg_red = m_ColourFG.Red(); - si->fg_green = m_ColourFG.Green(); - si->fg_blue = m_ColourFG.Blue(); - si->bg_red = m_ColourBG.Red(); - si->bg_green = m_ColourBG.Green(); - si->bg_blue = m_ColourBG.Blue(); + return m_StyleInfo; } void @@ -333,19 +388,16 @@ wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */, wxLayoutList *wxllist, CoordType begin, CoordType /* len */) { - wxASSERT(m_font); + wxASSERT(m_StyleInfo); dc.SetFont(*m_font); - dc.SetTextForeground(m_ColourFG); - dc.SetTextBackground(m_ColourBG); - if(wxllist) - wxllist->SetColour_Internal(&m_ColourFG,& m_ColourBG); + wxllist->ApplyStyle(m_StyleInfo, dc); } void -wxLayoutObjectCmd::Layout(wxDC &dc) +wxLayoutObjectCmd::Layout(wxDC &dc, class wxLayoutList * llist) { // this get called, so that recalculation uses right font sizes - Draw(dc, wxPoint(0,0), NULL); + Draw(dc, wxPoint(0,0), llist); } @@ -456,7 +508,7 @@ wxLayoutLine::FindObjectScreen(wxDC &dc, for(i = m_ObjectList.begin(); i != NULLIT; i++) { - (**i).Layout(dc); +//FIXME! (**i).Layout(dc, NULL); width = (**i).GetWidth(); if( x <= xpos && xpos <= x + width ) { @@ -678,6 +730,7 @@ wxLayoutLine::Draw(wxDC &dc, CoordType from, to, tempto; int highlight = llist->IsSelected(this, &from, &to); + WXLO_DEBUG(("highlight=%d", highlight )); if(highlight == 1) // we need to draw the whole line inverted! llist->StartHighlighting(dc); else @@ -743,7 +796,7 @@ wxLayoutLine::Layout(wxDC &dc, for(i = m_ObjectList.begin(); i != NULLIT; i++) { - (**i).Layout(dc); + (**i).Layout(dc, llist); size = (**i).GetSize(&objTopHeight, &objBottomHeight); if(cursorPos && ! cursorFound) @@ -1092,6 +1145,14 @@ wxLayoutList::InternalClear(void) 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; } void @@ -1104,13 +1165,9 @@ wxLayoutList::SetFont(int family, int size, int style, int weight, if(style != -1) m_FontStyle = style; if(weight != -1) m_FontWeight = weight; if(underline != -1) m_FontUnderline = underline != 0; - - if(fg != NULL) m_ColourFG = *fg; - if(bg != NULL) m_ColourBG = *bg; - Insert( new wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle,m_FontWeight,m_FontUnderline, - m_ColourFG, m_ColourBG)); + fg, bg)); } void @@ -1127,37 +1184,20 @@ wxLayoutList::SetFont(int family, int size, int style, int weight, if( bg ) cbg = wxTheColourDatabase->FindColour(bg); - SetFont(family,size,style,weight,underline,cfg,cbg); + SetFont(size,family,style,weight,underline,cfg,cbg); } void wxLayoutList::Clear(int family, int size, int style, int weight, - int /* underline */, wxColour *fg, wxColour *bg) + int underline, wxColour *fg, wxColour *bg) { InternalClear(); - // set defaults - m_FontPtSize = size; - m_FontUnderline = false; - m_FontFamily = family; - m_FontStyle = style; - m_FontWeight = weight; - if(fg) - m_ColourFG = *fg; - else - m_ColourFG = *wxBLACK; - if(bg) - m_ColourBG = *bg; - else - m_ColourBG = *wxWHITE; - if(m_DefaultSetting) delete m_DefaultSetting; - m_DefaultSetting = new - wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle, - m_FontWeight,m_FontUnderline, - m_ColourFG, m_ColourBG); + m_DefaultSetting = new + wxLayoutStyleInfo(family,size,style,weight,underline,fg,bg); } @@ -1291,6 +1331,7 @@ wxLayoutList::Insert(wxString const &text) SetUpdateRect(m_CursorScreenPos+m_CursorSize); m_CursorLine->Insert(m_CursorPos.x, text); m_CursorPos.x += text.Length(); + m_CursorLine->RecalculatePositions(true, this); //FIXME needed? return true; } @@ -1302,6 +1343,7 @@ wxLayoutList::Insert(wxLayoutObject *obj) SetUpdateRect(m_CursorScreenPos+m_CursorSize); m_CursorLine->Insert(m_CursorPos.x, obj); m_CursorPos.x += obj->GetLength(); + m_CursorLine->RecalculatePositions(true, this); //FIXME needed? return true; } @@ -1317,6 +1359,7 @@ wxLayoutList::LineBreak(void) m_FirstLine = m_CursorLine->GetPreviousLine(); m_CursorPos.y++; m_CursorPos.x = 0; + m_CursorLine->RecalculatePositions(true, this); //FIXME needed? return true; } @@ -1338,6 +1381,7 @@ wxLayoutList::WrapLine(CoordType column) LineBreak(); Delete(1); // delete the space m_CursorPos.x = newpos; + m_CursorLine->RecalculatePositions(true, this); //FIXME needed? return true; } } @@ -1379,6 +1423,7 @@ wxLayoutList::Delete(CoordType npos) } } while(left); + m_CursorLine->RecalculatePositions(true, this); //FIXME needed? return left == 0; } @@ -1416,7 +1461,7 @@ wxLayoutList::Recalculate(wxDC &dc, CoordType bottom) // first, make sure everything is calculated - this might not be // needed, optimise it later - m_DefaultSetting->Layout(dc); + ApplyStyle(m_DefaultSetting, dc); while(line) { line->RecalculatePosition(this); // so we don't need to do it all the time @@ -1447,7 +1492,7 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom) // first, make sure everything is calculated - this might not be // needed, optimise it later - m_DefaultSetting->Layout(dc); + ApplyStyle(m_DefaultSetting, dc); while(line) { if(line == m_CursorLine) @@ -1479,7 +1524,7 @@ wxLayoutList::Draw(wxDC &dc, wxLayoutLine *line = m_FirstLine; Layout(dc, bottom); - m_DefaultSetting->Draw(dc, wxPoint(0,0), this); + ApplyStyle(m_DefaultSetting, dc); wxBrush brush(m_ColourBG, wxSOLID); dc.SetBrush(brush); @@ -1514,7 +1559,7 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos, wxPoint p; // we need to run a layout here to get font sizes right :-( - m_DefaultSetting->Layout(dc); + ApplyStyle(m_DefaultSetting, dc); while(line) { p = line->GetPosition(); @@ -1706,7 +1751,62 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from, return 0; } +void +wxLayoutList::DeleteSelection(void) +{ + if(! m_Selection.m_valid) + return; + m_Selection.m_valid = false; + + // Only delete part of the current line? + if(m_Selection.m_CursorA.y == m_Selection.m_CursorB.y) + { + MoveCursorTo(m_Selection.m_CursorA); + Delete(m_Selection.m_CursorB.x - m_Selection.m_CursorA.x); + return; + } + + + wxLayoutLine + * firstLine = NULL, + * lastLine = NULL; + + for(firstLine = m_FirstLine; + firstLine && firstLine->GetLineNumber() < m_Selection.m_CursorA.y; + firstLine=firstLine->GetNextLine()) + ; + if(!firstLine || firstLine->GetLineNumber() != m_Selection.m_CursorA.y) + return; + + + for(lastLine = m_FirstLine; + lastLine && lastLine->GetLineNumber() < m_Selection.m_CursorB.y; + lastLine=lastLine->GetNextLine()) + ; + if(!lastLine || lastLine->GetLineNumber() != m_Selection.m_CursorB.y) + return; + + + // We now know that the two lines are different: + + // First, delete what's left of this line: + MoveCursorTo(m_Selection.m_CursorA); + DeleteToEndOfLine(); + + wxLayoutLine *nextLine = firstLine->GetNextLine(); + while(nextLine && nextLine != lastLine) + nextLine = nextLine->DeleteLine(false, this); + + // Now nextLine = lastLine; + Delete(1); // This joins firstLine and nextLine + Delete(m_Selection.m_CursorB.x); // This deletes the first x + // positions + + /// Recalculate: + firstLine->RecalculatePositions(1, this); +} + /// Starts highlighting the selection void wxLayoutList::StartHighlighting(wxDC &dc) @@ -1767,11 +1867,15 @@ wxLayoutList::Copy(const wxPoint &from, { // Extract objects from first line firstLine->Copy(llist, from.x); + llist->LineBreak(); // Extract all lines between for(wxLayoutLine *line = firstLine->GetNextLine(); line != lastLine; line = line->GetNextLine()) + { line->Copy(llist); + llist->LineBreak(); + } // Extract objects from last line lastLine->Copy(llist, 0, to.x); } @@ -1782,11 +1886,57 @@ wxLayoutList * wxLayoutList::GetSelection(void) { if(! m_Selection.m_valid) - return NULL; - + { + if(m_Selection.m_selecting) + EndSelection(); + else + return NULL; + } + + m_Selection.m_valid = false; return Copy( m_Selection.m_CursorA, m_Selection.m_CursorB ); } + + + +#define COPY_SI(what) if(si->what != -1) m_CurrentSetting.what = si->what; + +void +wxLayoutList::ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc) +{ + COPY_SI(family); + COPY_SI(size); + COPY_SI(style); + COPY_SI(weight); + COPY_SI(underline); + + if(si->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; + } + if(si->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_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); +} + + #ifdef WXLAYOUT_DEBUG void diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index a3e4cb438f..b181235238 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -40,7 +40,7 @@ # define WXLO_TRACE(x) #endif - +#define WXLO_DEBUG_URECT 0 #ifndef WXLO_DEFAULTFONTSIZE # define WXLO_DEFAULTFONTSIZE 12 @@ -106,8 +106,9 @@ public: virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; } /** Calculates the size of an object. @param dc the wxDC to draw on + @param llist the wxLayoutList */ - virtual void Layout(wxDC &) = 0; + virtual void Layout(wxDC &dc, class wxLayoutList *llist) = 0; /** Draws an object. @param dc the wxDC to draw on @@ -194,7 +195,7 @@ public: wxLayoutObjectText(const wxString &txt); virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; } - virtual void Layout(wxDC &dc); + virtual void Layout(wxDC &dc, class wxLayoutList *llist); virtual void Draw(wxDC &dc, wxPoint const &coords, class wxLayoutList *wxllist, CoordType begin = -1, @@ -254,7 +255,7 @@ public: ~wxLayoutObjectIcon() { delete m_Icon; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; } - virtual void Layout(wxDC &dc); + virtual void Layout(wxDC &dc, class wxLayoutList *llist); virtual void Draw(wxDC &dc, wxPoint const &coords, class wxLayoutList *wxllist, CoordType begin = -1, @@ -277,16 +278,34 @@ private: wxBitmap *m_Icon; }; -/// for export to html: +/** This structure holds all formatting information. Members which are + undefined (for a CmdObject this means: no change), are set to -1. +*/ struct wxLayoutStyleInfo { - wxLayoutStyleInfo() + wxLayoutStyleInfo(int ifamily = -1, + int isize = -1, + int istyle = -1, + int iweight = -1, + int iul = -1, + wxColour *fg = NULL, + wxColour *bg = NULL); + wxColour * GetBGColour() const { - family = -1; // this marks the styleinfo as uninitialised + return fg_valid ? new + wxColour(bg_red,bg_green,bg_blue) + : wxWHITE; } - int size, family, style, weight; - bool underline; + wxFont *GetFont(wxLayoutStyleInfo *); + /// 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; }; @@ -301,29 +320,28 @@ class wxLayoutObjectCmd : public wxLayoutObject { public: virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; } - virtual void Layout(wxDC &dc); + virtual void Layout(wxDC &dc, class wxLayoutList *llist); virtual void Draw(wxDC &dc, wxPoint const &coords, class wxLayoutList *wxllist, CoordType begin = -1, CoordType end = -1); - wxLayoutObjectCmd(int size, int family, int style, int weight, - bool underline, - wxColour &fg, wxColour &bg); + wxLayoutObjectCmd(int size = -1, + int family = -1, + int style = -1, + int weight = -1, + int underline = -1, + wxColour *fg = NULL, + wxColour *bg = NULL); ~wxLayoutObjectCmd(); /** Stores the current style in the styleinfo structure */ - void GetStyle(wxLayoutStyleInfo *si) const; - /// return the background colour for setting colour of window - wxColour &GetBGColour(void) { return m_ColourBG; } + wxLayoutStyleInfo * GetStyle(void) const; /** Makes a copy of this object. */ virtual wxLayoutObject *Copy(void); private: /// the font to use wxFont *m_font; - /// foreground colour - wxColour m_ColourFG; - /// background colour - wxColour m_ColourBG; + wxLayoutStyleInfo *m_StyleInfo; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -748,16 +766,13 @@ public: { SetFont(-1,-1,-1,-1,-1,fg,bg); } - /// Used by wxLayoutObjectCmd only: - void SetColour_Internal(wxColour *fg, wxColour *bg) - { if(fg) m_ColourFG = *fg; if(bg) m_ColourBG = *bg; } /** Returns a pointer to the default settings. This is only valid temporarily and should not be stored anywhere. @return the default settings of the list */ - wxLayoutObjectCmd *GetDefaults(void) { return m_DefaultSetting ; } + wxLayoutStyleInfo *GetDefaults(void) { return m_DefaultSetting ; } //@} /**@name Drawing */ @@ -859,6 +874,8 @@ public: /// Return the selection as a wxLayoutList: wxLayoutList *GetSelection(void); + /// Delete selected bit + void DeleteSelection(void); wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0), const wxPoint &to = wxPoint(-1,-1)); @@ -878,7 +895,9 @@ public: */ int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to); - + + + void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc); #ifdef WXLAYOUT_DEBUG void Debug(void); #endif @@ -924,7 +943,9 @@ private: wxColour m_ColourFG; wxColour m_ColourBG; /// the default setting: - wxLayoutObjectCmd *m_DefaultSetting; + wxLayoutStyleInfo *m_DefaultSetting; + /// the current setting: + wxLayoutStyleInfo m_CurrentSetting; //@} }; diff --git a/user/wxLayout/wxlparser.cpp b/user/wxLayout/wxlparser.cpp index eac7dfcb3b..df42c8ea8d 100644 --- a/user/wxLayout/wxlparser.cpp +++ b/user/wxLayout/wxlparser.cpp @@ -71,23 +71,27 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, static char buffer[20]; wxString html; - wxLayoutStyleInfo si; - cmd.GetStyle(&si); + wxLayoutStyleInfo *si = cmd.GetStyle(); int size, sizecount; html += "fg_valid) + { + html +="color="; + sprintf(buffer,"\"#%02X%02X%02X\"", si->fg_red,si->fg_green,si->fg_blue); + html += buffer; + } - - html += " bgcolor="; - sprintf(buffer,"\"#%02X%02X%02X\"", si.bg_red,si.bg_green,si.bg_blue); - html += buffer; - - switch(si.family) + if(si->bg_valid) + { + html += " bgcolor="; + sprintf(buffer,"\"#%02X%02X%02X\"", si->bg_red,si->bg_green,si->bg_blue); + html += buffer; + } + + switch(si->family) { case wxSWISS: case wxMODERN: @@ -101,12 +105,12 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, } size = BASE_SIZE; sizecount = 0; - while(size < si.size && sizecount < 5) + while(size < si->size && sizecount < 5) { sizecount ++; size = (size*12)/10; } - while(size > si.size && sizecount > -5) + while(size > si->size && sizecount > -5) { sizecount --; size = (size*10)/12; @@ -120,28 +124,28 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, if(styleInfo != NULL) html =""+html; // terminate any previous font command - if((si.weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD))) + if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD))) html += ""; else - if(si.weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD))) + if(si->weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD))) html += ""; - if(si.style == wxSLANT) - si.style = wxITALIC; // the same for html + if(si->style == wxSLANT) + si->style = wxITALIC; // the same for html - if((si.style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC))) + if((si->style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC))) html += ""; else - if(si.style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC))) + if(si->style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC))) html += ""; - if(si.underline && ( (!styleInfo) || ! styleInfo->underline)) + if(si->underline && ( (!styleInfo) || ! styleInfo->underline)) html += ""; - else if(si.underline == false && ( styleInfo && styleInfo->underline)) + else if(si->underline == false && ( styleInfo && styleInfo->underline)) html += ""; - *styleInfo = si; // update last style info + *styleInfo = *si; // update last style info return html; } @@ -150,7 +154,7 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list) { - list->GetDefaults()->GetStyle(&m_si); + m_si = *list->GetDefaults(); m_line = list->GetFirstLine(); m_iterator = m_line->GetFirstObject(); } diff --git a/user/wxLayout/wxlwindow.cpp b/user/wxLayout/wxlwindow.cpp index a64e4286ae..5d36dfa9a3 100644 --- a/user/wxLayout/wxlwindow.cpp +++ b/user/wxLayout/wxlwindow.cpp @@ -105,6 +105,28 @@ wxLayoutWindow::~wxLayoutWindow() SetBackgroundBitmap(NULL); } +void +wxLayoutWindow::Clear(int family, + int size, + int style, + int weight, + int underline, + wxColour *fg, + wxColour *bg) +{ + GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg); + SetBackgroundColour(*GetLayoutList()->GetDefaults()->GetBGColour()); + ResizeScrollbars(true); + SetDirty(); + SetModified(false); + wxRect r; + int w,h; + r.x = r.y = 0; GetSize(&w,&h); + r.width = w; + r.height = h; + DoPaint(&r); +} + #ifdef __WXMSW__ long wxLayoutWindow::MSWGetDlgCode() @@ -193,40 +215,35 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) void wxLayoutWindow::OnChar(wxKeyEvent& event) { + int keyCode = event.KeyCode(); + #ifdef WXLAYOUT_DEBUG - if(event.KeyCode() == WXK_F1) + if(keyCode == WXK_F1) { m_llist->Debug(); return; } #endif - - long keyCode = event.KeyCode(); - if(m_Selecting && ! event.ShiftDown()) + + if(! m_Selecting && event.ShiftDown()) { - m_llist->EndSelection(); - m_Selecting = false; - } - else - if(! m_Selecting && event.ShiftDown()) + switch(keyCode) { - switch(keyCode) - { - case WXK_UP: - case WXK_DOWN: - case WXK_RIGHT: - case WXK_LEFT: - case WXK_PRIOR: - case WXK_NEXT: - case WXK_HOME: - case WXK_END: - m_Selecting = true; - m_llist->StartSelection(); - break; - default: - ; - } + case WXK_UP: + case WXK_DOWN: + case WXK_RIGHT: + case WXK_LEFT: + case WXK_PRIOR: + case WXK_NEXT: + case WXK_HOME: + case WXK_END: + m_Selecting = true; + m_llist->StartSelection(); + break; + default: + ; } + } /* These two nested switches work like this: The first one processes all non-editing keycodes, to move the @@ -348,6 +365,17 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) SetModified(); }// if(IsEditable()) }// first switch() + if(m_Selecting) + { + if(event.ShiftDown()) + m_llist->ContinueSelection(); + else + { + m_llist->EndSelection(); + m_Selecting = false; + } + } + ScrollToCursor(); wxRect r = *m_llist->GetUpdateRect(); DoPaint(&r); @@ -445,8 +473,10 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) updateRect->y+updateRect->height)); if(IsDirty()) + { +//FIXME m_llist->Layout(dc); ResizeScrollbars(); - + } /* Check whether the window has grown, if so, we need to reallocate the bitmap to be larger. */ if(x1 > m_bitmapSize.x || y1 > m_bitmapSize.y) @@ -462,8 +492,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); @@ -489,10 +519,12 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) /* This is the important bit: we tell the list to draw itself: */ +#if WXLO_DEBUG_URECT WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld", updateRect->x, updateRect->y, updateRect->x+updateRect->width, updateRect->y+updateRect->height)); +#endif // Device origins on the memDC are suspect, we translate manually // with the translate parameter of Draw(). @@ -592,6 +624,13 @@ wxLayoutWindow::Paste(void) bool wxLayoutWindow::Copy(void) { + // Calling GetSelection() will automatically do an EndSelection() + // on the list, but we need to take a note of it, too: + if(m_Selecting) + { + m_Selecting = false; + m_llist->EndSelection(); + } wxLayoutList *llist = m_llist->GetSelection(); if(! llist) return FALSE; @@ -606,6 +645,16 @@ wxLayoutWindow::Copy(void) delete export; } delete llist; + + // The exporter always appends a newline, so we chop it off if it + // is there: + { + size_t len = text.Length(); + if(len > 2 && text[len-2] == '\r') // Windows + text = text.Mid(0,len-2); + else if(len > 1 && text[len-1] == '\n') + text = text.Mid(0,len-1); + } // Read some text if (wxTheClipboard->Open()) @@ -618,6 +667,18 @@ wxLayoutWindow::Copy(void) return FALSE; } +bool +wxLayoutWindow::Cut(void) +{ + if(Copy()) + { + m_llist->DeleteSelection(); + return TRUE; + } + else + return FALSE; +} + wxMenu * wxLayoutWindow::MakeFormatMenu() { diff --git a/user/wxLayout/wxlwindow.h b/user/wxLayout/wxlwindow.h index e8cb71b4d8..8efd166fce 100644 --- a/user/wxLayout/wxlwindow.h +++ b/user/wxLayout/wxlwindow.h @@ -65,20 +65,7 @@ public: int weight=wxNORMAL, int underline=0, wxColour *fg=NULL, - wxColour *bg=NULL) - { - GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg); - SetBackgroundColour(GetLayoutList()->GetDefaults()->GetBGColour()); - ResizeScrollbars(true); - SetDirty(); - SetModified(false); - wxRect r; - int w,h; - r.x = r.y = 0; GetSize(&w,&h); - r.width = w; - r.height = h; - DoPaint(&r); - } + wxColour *bg=NULL); /** Sets a background image, only used on screen, not on printouts. @param bitmap a pointer to a wxBitmap or NULL to remove it */ @@ -95,6 +82,8 @@ public: void Paste(void); /// Copies selection to clipboard. bool Copy(void); + /// Copies selection to clipboard and deletes it. + bool Cut(void); //@}