/*
* Program: wxLayout
- *
+ *
* Author: Karsten Ballüder
*
* Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
MyFrame::MyFrame(void) :
wxFrame( (wxFrame *) NULL, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
{
- CreateStatusBar( 1 );
-
+ CreateStatusBar( 2 );
+
SetStatusText( "wxLayout by Karsten Ballüder." );
wxMenuBar *menu_bar = new wxMenuBar();
-
+
wxMenu *file_menu = new wxMenu;
file_menu->Append(ID_PRINT, "&Print...", "Print");
file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties");
#ifndef __WXMSW__
menu_bar->Show( TRUE );
#endif // MSW
-
+
SetMenuBar( menu_bar );
m_lwin = new wxLayoutWindow(this);
+ m_lwin->SetStatusBar(GetStatusBar(), 0, 1);
m_lwin->SetMouseTracking(true);
m_lwin->SetEditable(true);
m_lwin->SetWrapMargin(40);
llist->SetFont(-1,-1,-1,-1,-1,"black");
llist->Insert("The quick brown fox jumps over the lazy dog.");
llist->LineBreak();
-
+
llist->SetFont(wxROMAN,16,wxNORMAL,wxNORMAL, false);
llist->Insert("--");
llist->LineBreak();
-
+
llist->SetFont(wxROMAN);
llist->Insert("The quick brown fox jumps over the lazy dog.");
llist->LineBreak();
wxPrinter printer;
wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout"));
if (! printer.Print(this, &printout, TRUE))
- wxMessageBox(
+ wxMessageBox(
_("There was a problem with printing the message:\n"
"perhaps your current printer is not set up correctly?"),
_("Printing"), wxOK);
if (! printer.Print(this, &printout, TRUE))
wxMessageBox(
"There was a problem printing.\nPerhaps your current printer is not set correctly?",
- "Printing", wxOK);
+ "Printing", wxOK);
}
void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
// Pass two printout objects: for preview, and possible printing.
wxPrintPreview *preview = new wxPrintPreview(new
wxLayoutPrintout(
- m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
+ m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
if (!preview->Ok())
{
delete preview;
wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK);
return;
}
-
+
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
frame->Centre(wxBOTH);
frame->Initialize();
// MyApp
//-----------------------------------------------------------------------------
-MyApp::MyApp(void) :
+MyApp::MyApp(void) :
wxApp( )
{
};
*******************************************************************/
/*
-
+
*/
-
+
#ifdef __GNUG__
-#pragma implementation "wxllist.h"
+ #pragma implementation "wxllist.h"
#endif
-#include "Mpch.h"
+#include <wx/wxprec.h>
-
-#include "wx/wxprec.h"
#ifdef __BORLANDC__
# pragma hdrstop
#endif
+#include "Mpch.h"
+
#ifdef M_BASEDIR
# include "gui/wxllist.h"
# include "gui/wxlparser.h"
#endif
#ifndef USE_PCH
-# include "iostream.h"
-# include <wx/dc.h>
-# include <wx/dcps.h>
-# include <wx/print.h>
-# include <wx/log.h>
-# include <wx/filefn.h>
+# include <iostream.h>
+
+# include <wx/dc.h>
+# include <wx/dcps.h>
+# include <wx/print.h>
+# include <wx/log.h>
+# include <wx/filefn.h>
#endif
+#ifdef WXLAYOUT_USE_CARET
+# include <wx/caret.h>
+#endif // WXLAYOUT_USE_CARET
+
#include <ctype.h>
/// This should never really get created
#ifdef WXLAYOUT_DEBUG
-# define TypewxString(t) g_aTypewxStrings[t]
+# define TypeString(t) g_aTypeStrings[t]
# define WXLO_DEBUG(x) wxLogDebug x
- static const char *g_aTypewxStrings[] =
- {
+ static const char *g_aTypeStrings[] =
+ {
"invalid", "text", "cmd", "icon"
};
void
wxLayoutObject::Debug(void)
{
- WXLO_DEBUG(("%s",g_aTypewxStrings[GetType()]));
+ WXLO_DEBUG(("%s",g_aTypeStrings[GetType()]));
}
-#else
-# define TypewxString(t) ""
-# define WXLO_DEBUG(x)
+#else
+# define TypeString(t) ""
+# define WXLO_DEBUG(x)
#endif
+// FIXME under MSW, this constant is needed to make the thing properly redraw
+// itself - I don't know where the size calculation error is and I can't
+// waste time looking for it right now. Search for occurences of
+// MSW_CORRECTION to find all the places where I did it.
+#ifdef __WXMSW__
+ static const int MSW_CORRECTION = 10;
+#else
+ static const int MSW_CORRECTION = 0;
+#endif
/// Cursors smaller than this disappear in XOR drawing mode
#define WXLO_MINIMUM_CURSOR_WIDTH 4
#define WXLO_CURSORCHAR "E"
/** @name Helper functions */
//@{
-/// allows me to compare to wxPoints
-bool operator ==(wxPoint const &p1, wxPoint const &p2)
-{
- return p1.x == p2.x && p1.y == p2.y;
-}
-
-/// allows me to compare to wxPoints
-bool operator !=(wxPoint const &p1, wxPoint const &p2)
-{
- return p1.x != p2.x || p1.y != p2.y;
-}
-
/// allows me to compare to wxPoints
bool operator <=(wxPoint const &p1, wxPoint const &p2)
{
r.x = x;
else if(r.x + r.width < x)
r.width = x - r.x;
-
+
if(r.y > y)
r.y = y;
else if(r.y + r.height < y)
from = cptr;
}
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObject
ReadString(tmp, istr);
int type = -1;
sscanf(tmp.c_str(),"%d", &type);
-
+
switch(type)
{
case WXLO_TYPE_TEXT:
}
}
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectText
void
wxLayoutObjectText::Write(wxString &ostr)
{
- ostr << (int) WXLO_TYPE_TEXT << '\n'
+ ostr << (int) WXLO_TYPE_TEXT << '\n'
<< m_Text << '\n';
}
/* static */
{
wxString text;
ReadString(text, istr);
-
+
return new wxLayoutObjectText(text);
}
if(begin < 0) begin = 0;
if( end > (signed)m_Text.Length() )
end = m_Text.Length();
-
+
str = m_Text.Mid(0, begin);
dc.DrawText(str, xpos, ypos);
dc.GetTextExtent(str, &width, &height, &descent);
height, descent = 0l;
if(xpos == 0) return 0; // easy
-
+
while(width < xpos && offs < maxlen)
{
dc.GetTextExtent(m_Text.substr(0,offs),
&width, &height, &descent);
offs++;
}
- /* We have to substract 1 to compensate for the offs++, and another
+ /* We have to substract 1 to compensate for the offs++, and another
one because we don't want to position the cursor behind the
object what we clicked on, but before - otherwise it looks
funny. */
- return (xpos > 2) ? offs-2 : 0;
+ return (xpos > 2) ? offs-2 : 0;
}
void
-wxLayoutObjectText::Layout(wxDC &dc, class wxLayoutList * )
+wxLayoutObjectText::Layout(wxDC &dc, class wxLayoutList *llist)
{
long descent = 0l;
- dc.GetTextExtent(m_Text,&m_Width, &m_Height, &descent);
+ CoordType widthOld = m_Width,
+ heightOld = m_Height;
+ dc.GetTextExtent(m_Text, &m_Width, &m_Height, &descent);
+
+ if ( widthOld != m_Width || heightOld != m_Height )
+ {
+ // as the text length changed, it must be refreshed
+ wxLayoutLine *line = GetLine();
+
+ wxCHECK_RET( line, "wxLayoutObjectText can't refresh itself" );
+
+ // as our size changed, we need to repaint the part which was appended
+ wxPoint position(line->GetPosition());
+
+ // this is not the most efficient way (we repaint the whole line), but
+ // it's not too slow and is *simple*
+ if ( widthOld < m_Width )
+ widthOld = m_Width;
+ if ( heightOld < m_Height )
+ heightOld = m_Height;
+
+ llist->SetUpdateRect(position.x + widthOld + MSW_CORRECTION,
+ position.y + heightOld + MSW_CORRECTION);
+ }
+
m_Bottom = descent;
m_Top = m_Height - m_Bottom;
}
}
#endif
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectIcon
{
wxString file;
ReadString(file, istr);
-
+
if(! wxFileExists(file))
return NULL;
wxLayoutObjectIcon *obj = new wxLayoutObjectIcon;
-
+
if(!obj->m_Icon->LoadFile(file, WXLO_BITMAP_FORMAT))
{
delete obj;
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectCmd
{
family = ifamily; size = isize;
style = istyle; weight = iweight;
- underline = iul;
+ underline = iul != 0;
if(fg)
{
m_fg = *fg;
wxLayoutObjectCmd::wxLayoutObjectCmd(int family, int size, int style, int
weight, int underline,
wxColour *fg, wxColour *bg)
-
+
{
m_StyleInfo = new wxLayoutStyleInfo(family, size,style,weight,underline,fg,bg);
}
}
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The wxLayoutLine object
// Recursing here, drives computation time up exponentially, as
// each line will cause all following lines to be recalculated.
// Yes, or linenumbers go wrong.
-
+
wxASSERT(recurse >= 0);
wxPoint pos = m_Position;
CoordType height = m_Height;
-
+
// WXLO_TRACE("RecalculatePositions()");
RecalculatePosition(llist);
if(m_Next)
if(recurse > 0)
m_Next->RecalculatePositions(--recurse, llist);
else if(pos != m_Position || m_Height != height)
- m_Next->RecalculatePositions(0, llist);
+ m_Next->RecalculatePositions(0, llist);
}
}
i,
found = NULLIT;
CoordType x = 0, len;
-
+
/* We search through the objects. As we don't like returning the
object that the cursor is behind, we just remember such an
object in "found" so we can return it if there is really no
wxASSERT(cxpos);
wxLayoutObjectList::iterator i;
CoordType x = 0, cx = 0, width;
-
+
for(i = m_ObjectList.begin(); i != NULLIT; i++)
{
width = (**i).GetWidth();
cpos = 0,
relpos = -1;
wxString const *text;
-
+
for(wxLOiterator i = m_ObjectList.begin(); i != m_ObjectList.end(); i++)
{
if(cpos >= xpos) // search from here!
{
wxASSERT(xpos >= 0);
wxASSERT(obj != NULL);
+
+ // in any case, the object is going to belong to this line
+ obj->AttachToLine(this);
+
//FIXME: this could be optimised, for now be prudent:
m_Dirty = true;
CoordType offset;
m_ObjectList.insert(i,new wxLayoutObjectText(left));
return true;
}
-
+
bool
wxLayoutLine::Insert(CoordType xpos, wxString text)
{
{
if(xpos == GetLength())
return npos;
- else
+ else
{ // at the end of an object
// move to begin of next object:
i++; offset = 0;
((wxLayoutObjectText *)(*i))->GetText().Remove(offset,max);
}
}
+
return npos;
}
if(i == NULLIT) return false;
if((**i).GetType() != WXLO_TYPE_TEXT)
{
- // This should only happen when at end of line, behind a non-text
+ // This should only happen when at end of line, behind a non-text
// object:
if(offset == (**i).GetLength()) return false;
m_Length -= (**i).GetLength(); // -1
((wxLayoutObjectText *)*i)->GetText().erase(offset,count);
m_Length -= count;
return true;
- }
+ }
}
wxASSERT(0); // we should never arrive here
}
wxLayoutObjectList::iterator i;
wxPoint pos = offset;
pos = pos + GetPosition();
-
+
pos.y += m_BaseLine;
CoordType xpos = 0; // cursorpos, lenght of line
wxLayoutList *llist,
wxPoint *cursorPos,
wxPoint *cursorSize,
- int cx)
+ int cx)
{
wxLayoutObjectList::iterator i;
CoordType
+ oldWidth = m_Width,
oldHeight = m_Height;
CoordType
topHeight, bottomHeight; // above and below baseline
bool cursorFound = false;
m_Dirty = false;
-
+
if(cursorPos)
{
*cursorPos = m_Position;
{
len = cx - count; // pos in object
CoordType width, height, descent;
- dc.GetTextExtent((*(wxLayoutObjectText*)*i).GetText().substr(0,len),
+ dc.GetTextExtent((*(wxLayoutObjectText*)*i).GetText().substr(0,len),
&width, &height, &descent);
cursorPos->x += width;
cursorPos->y = m_Position.y;
cursorSize->y = height;
cursorFound = true; // no more checks
}
- else
+ else
{ // on some other object
CoordType top, bottom; // unused
*cursorSize = (**i).GetSize(&top,&bottom);
if(objTopHeight > topHeight) topHeight = objTopHeight;
if(objBottomHeight > bottomHeight) bottomHeight = objBottomHeight;
}
- if(topHeight + bottomHeight > m_Height) m_Height =
- topHeight+bottomHeight;
+
+ // special case of a line which becomes empty (after deletion, for example):
+ // we should invalidate the screen space it occupied (usually this happens
+ // from wxLayoutObject::Layout called in the loop above)
+ if ( m_ObjectList.empty() )
+ {
+ wxPoint position(GetPosition());
+ llist->SetUpdateRect(position.x + oldWidth + MSW_CORRECTION,
+ position.y + oldHeight + MSW_CORRECTION);
+ }
+
+ if(topHeight + bottomHeight > m_Height)
+ m_Height = topHeight+bottomHeight;
m_BaseLine = topHeight;
if(m_Height == 0)
m_BaseLine = m_Height - descent;
}
-
+
// tell next line about coordinate change
if(m_Next && objHeight != oldHeight)
m_Next->RecalculatePositions(0, llist);
m_Dirty = true;
/* If we are at the begin of a line, we want to move all other
- lines down and stay with the cursor where we are. However, if we
+ lines down and stay with the cursor where we are. However, if we
are in an empty line, we want to move down with it. */
if(xpos == 0 && GetLength() > 0)
{ // insert an empty line before this one
m_Next->RecalculatePositions(1, llist);
return m_Previous;
}
-
+
CoordType offset;
wxLOiterator i = FindObject(xpos, &offset);
if(i == NULLIT)
m_Next->RecalculatePositions(2, llist);
return newLine;
}
-
+
void
wxLayoutLine::MergeNextLine(wxLayoutList *llist)
wxLOiterator i;
//FIXME: this could be optimised, for now be prudent:
m_Dirty = true;
-
+
+ wxLayoutObject *last = NULL;
for(i = list.begin(); i != list.end();)
{
- Append(*i);
- list.remove(i); // remove without deleting it
+ wxLayoutObject *current = *i;
+
+ // merge text objects together for efficiency
+ if ( last && last->GetType() == WXLO_TYPE_TEXT &&
+ current->GetType() == WXLO_TYPE_TEXT )
+ {
+ wxLayoutObjectText *textObj = (wxLayoutObjectText *)last;
+ wxString text(textObj->GetText());
+ text += ((wxLayoutObjectText *)current)->GetText();
+ textObj->SetText(text);
+
+ list.erase(i); // remove and delete it
+ }
+ else
+ {
+ // just append the object "as was"
+ current->UnattachFromLine();
+ Append(current);
+
+ list.remove(i); // remove without deleting it
+ }
}
wxASSERT(list.empty());
+
wxLayoutLine *oldnext = GetNextLine();
- SetNext(GetNextLine()->GetNextLine());
+ wxLayoutLine *nextLine = oldnext->GetNextLine();
+ SetNext(nextLine);
delete oldnext;
- GetNextLine()->MoveLines(-1);
- RecalculatePositions(1, llist);
+ if ( nextLine )
+ {
+ nextLine->MoveLines(-1);
+ }
+
+ // no RecalculatePositions needed - called from Delete() anyhow
}
CoordType
wxLOiterator i = FindObject(column, &offset);
if(i == NULLIT) return -1; // cannot wrap
- // go backwards through the list and look for space in text objects
+ // go backwards through the list and look for space in text objects
do
{
if((**i).GetType() == WXLO_TYPE_TEXT)
pos -= (**i).GetLength();
return pos; // in front of it
}
-
+
#ifdef WXLAYOUT_DEBUG
void
if(to == -1) to = GetLength();
if(from == to) return;
-
+
wxLOiterator first = FindObject(from, &firstOffset);
wxLOiterator last = FindObject(to, &lastOffset);
}
}
- // If we reach here, we can safely copy the whole first object from
+ // If we reach here, we can safely copy the whole first object from
// the firstOffset position on:
if((**first).GetType() == WXLO_TYPE_TEXT && firstOffset != 0)
{
else if(firstOffset == 0)
llist->Insert( (**first).Copy() );
// else nothing to copy :-(
-
+
// Now we copy all objects before the last one:
wxLOiterator i = first; i++;
for( ; i != last; i++)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-
+
The wxLayoutList object
-
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
wxLayoutList::wxLayoutList()
{
+#ifdef WXLAYOUT_USE_CARET
+ m_caret = NULL;
+#endif // WXLAYOUT_USE_CARET
+
m_FirstLine = NULL;
InvalidateUpdateRect();
Clear();
m_DefaultSetting.m_fg = *wxBLACK;
m_DefaultSetting.m_bg_valid = TRUE;
m_DefaultSetting.m_bg = *wxWHITE;
-
+
m_CurrentSetting = m_DefaultSetting;
}
cfg = wxTheColourDatabase->FindColour(fg);
if( bg )
cbg = wxTheColourDatabase->FindColour(bg);
-
+
SetFont(family,size,style,weight,underline,cfg,cbg);
}
wxLayoutList::FindText(const wxString &needle, const wxPoint &cpos) const
{
int xpos;
-
+
wxLayoutLine *line;
for(line = m_FirstLine;
line;
bool
wxLayoutList::MoveCursorTo(wxPoint const &p)
{
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+ AddCursorPosToUpdateRect();
+
wxLayoutLine *line = m_FirstLine;
while(line && line->GetLineNumber() != p.y)
line = line->GetNextLine();
}
return false;
}
-
+
bool
wxLayoutList::MoveCursorVertically(int n)
{
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+ AddCursorPosToUpdateRect();
+
bool rc;
if(n < 0) // move up
{
bool
wxLayoutList::MoveCursorHorizontally(int n)
{
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+ AddCursorPosToUpdateRect();
+
int move;
while(n < 0)
{
wxLayoutList::Insert(wxString const &text)
{
wxASSERT(m_CursorLine);
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+
+ AddCursorPosToUpdateRect();
+
m_CursorLine->Insert(m_CursorPos.x, text);
m_CursorPos.x += text.Length();
m_CursorLine->RecalculatePositions(true, this); //FIXME needed?
wxLayoutList::Insert(wxLayoutObject *obj)
{
wxASSERT(m_CursorLine);
- if(! m_CursorLine) m_CursorLine = GetFirstLine();
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+
+ if(! m_CursorLine)
+ m_CursorLine = GetFirstLine();
+
+ AddCursorPosToUpdateRect();
+
m_CursorLine->Insert(m_CursorPos.x, obj);
m_CursorPos.x += obj->GetLength();
m_CursorLine->RecalculatePositions(true, this); //FIXME needed?
{
wxASSERT(llist);
bool rc = TRUE;
-
+
for(wxLayoutLine *line = llist->GetFirstLine();
line;
line = line->GetNextLine()
return rc;
}
-
-
-
bool
wxLayoutList::LineBreak(void)
{
wxASSERT(m_CursorLine);
bool setFirst = (m_CursorLine == m_FirstLine && m_CursorPos.x == 0);
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+
+ AddCursorPosToUpdateRect();
+
+ wxPoint position(m_CursorLine->GetPosition());
+
+ wxCoord width = m_CursorLine->GetWidth(),
+ height = m_CursorLine->GetHeight();
+
m_CursorLine = m_CursorLine->Break(m_CursorPos.x, this);
if(setFirst) // we were at beginning of first line
m_FirstLine = m_CursorLine->GetPreviousLine();
m_CursorPos.y++;
m_CursorPos.x = 0;
// doesn't help m_CursorLine.MarkDirty();
- m_CursorLine->RecalculatePositions(true, this); //FIXME needed?
+
+ wxLayoutLine *prev = m_CursorLine->GetPreviousLine();
+ wxCHECK_MSG(prev, false, "just broke the line, where is the previous one?");
+
+ height += prev->GetHeight();
+
+ SetUpdateRect(position);
+ SetUpdateRect(position.x + width + MSW_CORRECTION,
+ position.y + height + MSW_CORRECTION);
+
return true;
}
//else:
CoordType newpos = m_CursorPos.x - xpos - 1;
m_CursorPos.x = xpos;
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+
+ AddCursorPosToUpdateRect();
+
LineBreak();
Delete(1); // delete the space
m_CursorPos.x = newpos;
bool
wxLayoutList::Delete(CoordType npos)
{
- wxASSERT(m_CursorLine);
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+ wxCHECK_MSG(m_CursorLine, false, "can't delete in non existing line");
+ wxASSERT_MSG(npos > 0, "nothing to delete?");
+
+ AddCursorPosToUpdateRect();
+
+ // were other lines appended to this one (this is important to know because
+ // this means that our width _increased_ as the result of deletion)
+ bool wasMerged = false;
+
+ // the size of the region to update
+ CoordType totalHeight = m_CursorLine->GetHeight(),
+ totalWidth = m_CursorLine->GetWidth();
+
CoordType left;
do
{
left = m_CursorLine->Delete(m_CursorPos.x, npos);
- if(left == 0)
- return true;
- // More to delete, continue on next line.
- // First, check if line is empty:
- if(m_CursorLine->GetLength() == 0)
- { // in this case, updating could probably be optimised
-#ifdef WXLO_DEBUG
- wxASSERT(DeleteLines(1) == 0);
+
+ if( left > 0 )
+ {
+ // More to delete, continue on next line.
+
+ // First, check if line is empty:
+ if(m_CursorLine->GetLength() == 0)
+ {
+ // in this case, updating could probably be optimised
+#ifdef WXLO_DEBUG
+ wxASSERT(DeleteLines(1) == 0);
#else
- DeleteLines(1);
+ DeleteLines(1);
#endif
-
- left--;
- }
- else
- {
- // Need to join next line
- if(! m_CursorLine->GetNextLine())
- break; // cannot
+
+ left--;
+ }
else
{
- m_CursorLine->MergeNextLine(this);
- left--;
+ // Need to join next line
+ if(! m_CursorLine->GetNextLine())
+ break; // cannot
+ else
+ {
+ wasMerged = true;
+ wxLayoutLine *next = m_CursorLine->GetNextLine();
+ if ( next )
+ totalHeight += next->GetHeight();
+ m_CursorLine->MergeNextLine(this);
+ left--;
+ }
}
}
}
- while(left);
- m_CursorLine->RecalculatePositions(true, this); //FIXME needed?
+ while ( left> 0 );
+
+ // we need to update the whole tail of the line and the lines which
+ // disappeared
+ if ( wasMerged )
+ {
+ wxPoint position(m_CursorLine->GetPosition());
+ SetUpdateRect(position.x + totalWidth + MSW_CORRECTION,
+ position.y + totalHeight + MSW_CORRECTION);
+ }
+
return left == 0;
}
{
wxASSERT(m_CursorLine);
wxLayoutLine *line;
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+
+ AddCursorPosToUpdateRect();
+
while(n > 0)
{
if(!m_CursorLine->GetNextLine())
}
/*
- Is called before each Draw(). Now, it will re-layout all lines which
+ Is called before each Draw(). Now, it will re-layout all lines which
have changed.
*/
void
wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll)
{
wxLayoutLine *line = m_FirstLine;
-
+
// first, make sure everything is calculated - this might not be
// needed, optimise it later
ApplyStyle(&m_DefaultSetting, dc);
m_CursorLine->GetNextLine() == NULL &&
m_CursorLine == m_FirstLine));
#endif
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+ AddCursorPosToUpdateRect();
}
void
{
wxLayoutLine *line = m_FirstLine;
- Layout(dc);
+ Layout(dc);
ApplyStyle(&m_DefaultSetting, dc);
wxBrush brush(m_CurrentSetting.m_bg, wxSOLID);
dc.SetBrush(brush);
dc.SetBackgroundMode(wxTRANSPARENT);
-
+
while(line)
{
// only draw if between top and bottom:
// First, find the right line:
wxLayoutLine *line = m_FirstLine;
wxPoint p;
-
+
// we need to run a layout here to get font sizes right :-(
ApplyStyle(&m_DefaultSetting, dc);
while(line)
cursorPos ? & cursorPos->x : NULL ,
found);
return (i == NULLIT) ? NULL : *i;
-
+
}
wxPoint
return wxPoint(0,0);
wxPoint maxPoint(0,0);
-
+
// find last line:
while(line)
{
void
wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate)
{
- wxPoint coords;
- coords = m_CursorScreenPos;
- coords.x += translate.x;
- coords.y += translate.y;
+ wxPoint coords(m_CursorScreenPos);
+ coords += translate;
#ifdef WXLAYOUT_DEBUG
WXLO_DEBUG(("Drawing cursor (%ld,%ld) at %ld,%ld, size %ld,%ld, line: %ld, len %ld",
(long)m_CursorSize.x, (long)m_CursorSize.y,
(long)m_CursorLine->GetLineNumber(),
(long)m_CursorLine->GetLength()));
+
+ wxLogStatus("Cursor is at (%d, %d)", m_CursorPos.x, m_CursorPos.y);
#endif
-
+
+#ifdef WXLAYOUT_USE_CARET
+ m_caret->Move(coords);
+#else // !WXLAYOUT_USE_CARET
dc.SetBrush(*wxBLACK_BRUSH);
dc.SetLogicalFunction(wxXOR);
dc.SetPen(wxPen(*wxBLACK,1,wxSOLID));
}
dc.SetLogicalFunction(wxCOPY);
//dc.SetBrush(wxNullBrush);
+#endif // WXLAYOUT_USE_CARET/!WXLAYOUT_USE_CARET
}
void
return;
m_Selection.m_valid = false;
-
+
// Only delete part of the current line?
if(m_Selection.m_CursorA.y == m_Selection.m_CursorB.y)
{
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)
else
return NULL;
}
-
+
if(invalidate) m_Selection.m_valid = false;
wxLayoutList *llist = Copy( m_Selection.m_CursorA,
m_Selection.m_CursorB );
-
+
if(llist && wxlo) // export as data object, too
{
wxString string;
export->content.object->Write(string);
delete export;
}
+
wxlo->SetData(string.c_str(), string.Length()+1);
}
return llist;
#ifdef WXLAYOUT_DEBUG
void
-wxLayoutList::Debug(void)
+wxLayoutList::Debug(void)
{
wxLayoutLine *line;
#endif
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutPrintout
m_title = title;
// remove any highlighting which could interfere with printing:
m_llist->StartSelection();
- m_llist->EndSelection();
+ m_llist->EndSelection();
}
wxLayoutPrintout::~wxLayoutPrintout()
{
// The following bit is taken from the printing sample, let's see
// whether it works for us.
-
+
/* You might use THIS code to set the printer DC to ROUGHLY reflect
* the screen text size. This page also draws lines of actual length 5cm
* on the page.
ppiPrinterX = 72;
ppiPrinterY = 72;
}
-
+
// This scales the DC so that the printout roughly represents the
// the screen scaling. The text point size _should_ be the right size
// but in fact is too small for some reason. This is a detail that will
wxDC *dc = GetDC();
ScaleDC(dc);
-
+
if (dc)
{
int top, bottom;
// This is the length of the printable area.
m_PrintoutHeight = m_PageHeight - (int) (m_PageHeight * 0.15);
m_PrintoutHeight = (int)( m_PrintoutHeight / scale); // we want to use the real paper height
-
-
+
+
m_NumOfPages = 1 +
(int)( m_llist->GetSize().y / (float)(m_PrintoutHeight));
const wxBrush& brush = dc.GetBrush();
const wxPen& pen = dc.GetPen();
const wxFont& font = dc.GetFont();
-
+
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(wxPen(*wxBLACK,0,wxSOLID));
dc.DrawRoundedRectangle(topleft.x,
topleft.y,bottomright.x-topleft.x,
- bottomright.y-topleft.y);
+ bottomright.y-topleft.y);
dc.SetBrush(*wxBLACK_BRUSH);
wxFont myfont = wxFont((WXLO_DEFAULTFONTSIZE*12)/10,
wxSWISS,wxNORMAL,wxBOLD,false,"Helvetica");
wxFont &
-wxFontCache::GetFont(int family, int size, int style, int weight,
+wxFontCache::GetFont(int family, int size, int style, int weight,
bool underline)
{
for(wxFCEList::iterator i = m_FontList.begin();
m_FontList.push_back(fce);
return fce->GetFont();
}
-
+
# define WXMENU_LAYOUT_DBLCLICK 1113
#endif
+// use the wxWindows caret class instead of home grown cursor whenever possible
+#ifdef __WXMSW__
+ #undef WXLAYOUT_USE_CARET
+ #define WXLAYOUT_USE_CARET 1
+#endif // __WXMSW__
+
// do not enable debug mode within Mahogany
#if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
# define WXLAYOUT_DEBUG
#ifdef WXLAYOUT_DEBUG
# define WXLO_TRACE(x) wxLogDebug(x)
#else
-# define WXLO_TRACE(x)
+# define WXLO_TRACE(x)
#endif
#define WXLO_DEBUG_URECT 0
// Forward declarations.
class wxLayoutList;
+class wxLayoutLine;
class wxLayoutObject;
-class wxDC;
-class wxColour;
-class wxFont;
+class WXDLLEXPORT wxCaret;
+class WXDLLEXPORT wxColour;
+class WXDLLEXPORT wxDC;
+class WXDLLEXPORT wxFont;
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The wxLayout objects which make up the lines.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
+
/** The base class defining the interface to each object which can be
- part of the layout. Each object needs to draw itself and calculate
+ part of the layout. Each object needs to draw itself and calculate
its size.
*/
class wxLayoutObject
@param dc the wxDC to draw on
@param llist the wxLayoutList
*/
- virtual void Layout(wxDC &dc, class wxLayoutList *llist) = 0;
+ virtual void Layout(wxDC &dc, wxLayoutList *llist) = 0;
/** Draws an object.
@param dc the wxDC to draw on
*/
virtual void Draw(wxDC & /* dc */,
wxPoint const & /* coords */,
- class wxLayoutList *wxllist,
+ wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1) { }
- /** Calculates and returns the size of the object.
+ /** Calculates and returns the size of the object.
@param top where to store height above baseline
@param bottom where to store height below baseline
@return the size of the object's box in pixels
virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; }
/// constructor
- wxLayoutObject() { m_UserData = NULL; }
+ wxLayoutObject() { m_UserData = NULL; m_Line = NULL; }
/// delete the user data
virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
if(m_UserData)
m_UserData->IncRef();
}
-
+
+ /// returns the line we belong to (or NULL)
+ wxLayoutLine *GetLine() const { return m_Line; }
+
+ /// attaches this object to the given line, it's an error to reattach us
+ void AttachToLine(wxLayoutLine *line)
+ {
+ wxASSERT_MSG( !m_Line, "this layout object already belongs to a line" );
+
+ m_Line = line;
+ }
+
+ /// unattaches the object (should reattach it immediately afterwards!)
+ void UnattachFromLine() { if ( m_Line ) m_Line = (wxLayoutLine *)NULL; }
+
/** Return the user data.
Increments the object's reference count. When no longer needed,
caller must call DecRef() on the pointer returned.
protected:
/// optional data for application's use
UserData *m_UserData;
+
+ /// the line of the text we belong to or NULL if we're not shown on screen
+ wxLayoutLine *m_Line;
};
/// Define a list type of wxLayoutObject pointers.
/// The iterator type.
#define wxLOiterator wxLayoutObjectList::iterator
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectText
{
public:
wxLayoutObjectText(const wxString &txt = "");
-
+
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
- virtual void Layout(wxDC &dc, class wxLayoutList *llist);
+ virtual void Layout(wxDC &dc, wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
- class wxLayoutList *wxllist,
+ wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
- /** Calculates and returns the size of the object.
+ /** Calculates and returns the size of the object.
@param top where to store height above baseline
@param bottom where to store height below baseline
@return the size of the object's box in pixels
long m_Bottom;
};
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectIcon
~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; }
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
- virtual void Layout(wxDC &dc, class wxLayoutList *llist);
+ virtual void Layout(wxDC &dc, wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
- class wxLayoutList *wxllist,
+ wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
- /** Calculates and returns the size of the object.
+ /** Calculates and returns the size of the object.
@param top where to store height above baseline
@param bottom where to store height below baseline
@return the size of the object's box in pixels
wxBitmap *m_Icon;
};
-/** This structure holds all formatting information. Members which are
+/** This structure holds all formatting information. Members which are
undefined (for a CmdObject this means: no change), are set to -1.
*/
struct wxLayoutStyleInfo
class wxFontCacheEntry
{
public:
- wxFontCacheEntry(int family, int size, int style, int weight,
+ wxFontCacheEntry(int family, int size, int style, int weight,
bool underline)
{
m_Family = family; m_Size = size; m_Style = style;
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 Matches(int family, int size, int style, int weight,
bool underline) const
{
return size == m_Size && family == m_Family
class wxFontCache
{
public:
- wxFont & GetFont(int family, int size, int style, int weight,
+ 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);
+ return GetFont(si.family, si.size, si.style, si.weight,
+ si.underline != 0);
}
private:
wxFCEList m_FontList;
};
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectCmd
{
public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
- virtual void Layout(wxDC &dc, class wxLayoutList *llist);
+ virtual void Layout(wxDC &dc, wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords,
- class wxLayoutList *wxllist,
+ wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
wxLayoutObjectCmd(int family = -1,
wxLayoutStyleInfo *m_StyleInfo;
};
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The wxLayoutLine object
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/// forward declaration
-class wxLayoutList;
-
/** This class represents a single line of objects to be displayed.
It knows its height and total size and whether it needs to be
redrawn or not.
- It has pointers to its first and next line so it can automatically
+ It has pointers to its first and next line so it can automatically
update them as needed.
*/
class wxLayoutLine
@return true if that xpos existed and the object was inserted
*/
bool Insert(CoordType xpos, wxLayoutObject *obj);
-
+
/** This function inserts text at cursor position xpos.
@param xpos where to insert
@param text the text to insert
void Append(wxLayoutObject * obj)
{
wxASSERT(obj);
+
+ obj->AttachToLine(this);
m_ObjectList.push_back(obj);
m_Length += obj->GetLength();
}
whitespace.
This function does not delete over font changes, i.e. a word
with formatting instructions in the middle of it is treated as
- two (three actually!) words. In fact, if the cursor is on a non-text object, that
+ two (three actually!) words. In fact, if the cursor is on a non-text object, that
one is treated as a word.
@param xpos from where to delete
@return true if a word was deleted
*/
bool DeleteWord(CoordType npos);
- /** Finds a suitable position left to the given column to break the
+ /** Finds a suitable position left to the given column to break the
line.
@param column we want to break the line to the left of this
@return column for breaking line or -1 if no suitable location found
*/
CoordType GetWrapPosition(CoordType column);
-
+
/** Finds the object which covers the cursor position xpos in this
line.
@param xpos the column number
@return the cursoor coord where it was found or -1
*/
CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
-
- /** Get the first object in the list. This is used by the wxlparser
+
+ /** Get the first object in the list. This is used by the wxlparser
functions to export the list.
@return iterator to the first object
*/
{
return m_ObjectList.begin();
}
-
+
/** Deletes this line, returns pointer to next line.
@param update If true, update all following lines.
*/
//@{
/** Draws the line on a wxDC.
@param dc the wxDC to draw on
- @param llist the wxLayoutList
+ @param llist the wxLayoutList
@param offset an optional offset to shift printout
*/
void Draw(wxDC &dc,
wxLayoutList *llist,
const wxPoint &offset = wxPoint(0,0)) const;
-
+
/** Recalculates the positions of objects and the height of the
line.
@param dc the wxDC to draw on
- @param llist th e wxLayoutList
+ @param llist th e wxLayoutList
@param cursorPos if not NULL, set cursor screen position in there
@param cursorSize if not cursorPos != NULL, set cursor size in there
@param cx if cursorPos != NULL, the cursor x position
void Copy(wxLayoutList *llist,
CoordType from = 0,
CoordType to = -1);
-
+
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-
+
The wxLayoutList object
-
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** The wxLayoutList is a list of wxLayoutLine objects. It provides a
- higher level of abstraction for the text and can generally be considered
- as representing "the text".
+ higher level of abstraction for the text and can generally be considered
+ as representing "the text".
*/
class wxLayoutList
{
/// Destructor.
~wxLayoutList();
+#ifdef WXLAYOUT_USE_CARET
+ /// give us the pointer to the caret to use
+ void SetCaret(wxCaret *caret) { m_caret = caret; }
+#endif // WXLAYOUT_USE_CARET
+
/// Clear the list.
void Clear(int family = wxROMAN,
int size=WXLO_DEFAULTFONTSIZE,
wxColour *bg=NULL);
/// Empty: clear the list but leave font settings.
void Empty(void);
-
+
/**@name Cursor Management */
//@{
/** Set new cursor position.
void MoveCursorToEndOfLine(void)
{
wxASSERT(m_CursorLine);
- MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
+ MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
}
-
+
/// Move cursor to begin of line.
void MoveCursorToBeginOfLine(void)
{ MoveCursorHorizontally(-m_CursorPos.x); }
/// Returns current cursor position.
const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
const wxPoint &GetCursorPos() const { return m_CursorPos; }
-
+
//@}
/**@name Editing functions.
bool Insert(wxLayoutObject *obj);
/// Inserts objects at current cursor positions
bool Insert(wxLayoutList *llist);
-
+
/// Inserts a linebreak at current cursor position.
bool LineBreak(void);
/** Wraps the current line. Searches to the left of the cursor to
@return how many it could not delete
*/
int DeleteLines(int n);
-
+
/// Delete to end of line.
void DeleteToEndOfLine(void)
{
/// changes to the next smaller font size
inline void SetFontSmaller(void)
{ SetFont(-1,(10*m_CurrentSetting.size)/12); }
-
+
/// set font family
inline void SetFontFamily(int family) { SetFont(family); }
/// set font size
@param bottom optional y coordinate where to stop calculating
*/
void Recalculate(wxDC &dc, CoordType bottom = -1);
-
+
/** Returns the size of the list in screen coordinates.
The return value only makes sense after the list has been
drawn.
@return cursor position in pixels
*/
wxPoint GetCursorScreenPos(wxDC &dc);
-
+
/** Draws the cursor.
@param active If true, draw a bold cursor to mark window as
active.
*/
inline void SetUpdateRect(const wxPoint &p)
{ SetUpdateRect(p.x,p.y); }
+ /// adds the cursor position to the update rectangle
+ void AddCursorPosToUpdateRect()
+ {
+ #ifndef WXLAYOUT_USE_CARET
+ SetUpdateRect(m_CursorScreenPos);
+ SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+ //#else - the caret will take care of refreshing itself
+ #endif // !WXLAYOUT_USE_CARET
+ }
/// Invalidates the update rectangle.
void InvalidateUpdateRect(void) { m_UpdateRectValid = false; }
/// Returns the update rectangle.
wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = TRUE);
/// Delete selected bit
void DeleteSelection(void);
-
+
wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
const wxPoint &to = wxPoint(-1,-1));
void StartHighlighting(wxDC &dc);
/// ends highlighting of text for selections
void EndHighlighting(wxDC &dc);
-
+
/** Tests whether this layout line is selected and needs
highlighting.
@param line to test for
@param to set to last cursorpos to be highlighted (for returncode == -1)
@return 0 = not selected, 1 = fully selected, -1 = partially
selected
-
+
*/
int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
/** Calculates the cursor position on the screen.
*/
void UpdateCursorScreenPos(wxDC &dc);
-
+
/// The list of lines.
wxLayoutLine *m_FirstLine;
/// The update rectangle which needs to be refreshed:
//@{
/// Where the text cursor (column,line) is.
wxPoint m_CursorPos;
- /// The size of the cursor.
- wxPoint m_CursorSize;
/// Where the cursor should be drawn.
wxPoint m_CursorScreenPos;
/// The line where the cursor is.
wxLayoutLine *m_CursorLine;
- //@}
+ /// The size of the cursor.
+ wxPoint m_CursorSize;
+#ifdef WXLAYOUT_USE_CARET
+ /// the caret
+ wxCaret *m_caret;
+#endif // WXLAYOUT_USE_CARET
+ //@}
/// A structure for the selection.
struct Selection
//@}
};
-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-
+
The wxLayoutDataObject for exporting data to the clipboard in our
own format.
-
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class wxLayoutDataObject : public wxPrivateDataObject
{
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-
+
The wxLayoutPrintout object for printing within the wxWindows print
framework.
-
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** This class implements a wxPrintout for printing a wxLayoutList within
the wxWindows printing framework.
"wxLayout Printout");
/// Destructor.
~wxLayoutPrintout();
-
+
/** Function which prints the n-th page.
@param page the page number to print
@return bool true if we are not at end of document yet
/* no longer used
virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
- */
+ */
private:
/// The list to print.
wxLayoutList *m_llist;
# pragma implementation "wxlparser.h"
#endif
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+# pragma hdrstop
+#endif
+
#include "Mpch.h"
+
#ifdef M_PREFIX
# include "gui/wxllist.h"
# include "gui/wxlparser.h"
/*-*- c++ -*-********************************************************
* wxLwindow.h : a scrolled Window for displaying/entering rich text*
* *
- * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
+ * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
* *
* $Id$
*******************************************************************/
#endif
#include "wx/wxprec.h"
+
#ifdef __BORLANDC__
# pragma hdrstop
#endif
-
#include "Mpch.h"
+
#ifdef M_BASEDIR
# ifndef USE_PCH
# include "Mcommon.h"
#include <wx/textctrl.h>
#include <wx/dataobj.h>
+#ifdef WXLAYOUT_USE_CARET
+# include <wx/caret.h>
+#endif // WXLAYOUT_USE_CARET
+
#include <ctype.h>
#ifdef WXLAYOUT_DEBUG
END_EVENT_TABLE()
wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
- : wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
- wxHSCROLL | wxVSCROLL | wxBORDER)
+ : wxScrolledWindow(parent, -1,
+ wxDefaultPosition, wxDefaultSize,
+ wxHSCROLL | wxVSCROLL | wxBORDER)
{
SetStatusBar(NULL); // don't use statusbar
m_bitmap = new wxBitmap(4,4);
m_bitmapSize = wxPoint(4,4);
m_llist = new wxLayoutList();
+
m_BGbitmap = NULL;
m_ScrollToCursor = false;
SetWrapMargin(0);
EnableScrolling(true,true);
m_maxx = max.x; m_maxy = max.y;
m_Selecting = false;
- SetCursorVisibility(-1);
+
+#ifdef WXLAYOUT_USE_CARET
+ // FIXME cursor size shouldn't be hardcoded
+ wxCaret *caret = new wxCaret(this, 2, 20);
+ SetCaret(caret);
+ m_llist->SetCaret(caret);
+ caret->Show();
+#endif // WXLAYOUT_USE_CARET
+
+ SetCursorVisibility(-1);
SetCursor(wxCURSOR_IBEAM);
SetDirty();
}
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);
+
+ DoPaint((wxRect *)NULL);
}
#ifdef __WXMSW__
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{
wxPaintDC dc( this );
- PrepareDC( dc );
+ PrepareDC( dc );
SetFocus();
wxPoint findPos;
if(!m_HandCursor)
SetCursor(wxCURSOR_HAND);
m_HandCursor = TRUE;
- if(m_StatusBar && m_StatusFieldLabel != -1)
+ if(m_StatusBar && m_StatusFieldLabel != -1)
{
const wxString &label = u->GetLabel();
if(label.Length())
if(m_HandCursor)
SetCursor(wxCURSOR_IBEAM);
m_HandCursor = FALSE;
- if(m_StatusBar && m_StatusFieldLabel != -1)
+ if(m_StatusBar && m_StatusFieldLabel != -1)
m_StatusBar->SetStatusText("", m_StatusFieldLabel);
}
if(event.LeftIsDown())
{
m_llist->StartSelection();
m_Selecting = true;
- DoPaint(FALSE);
+ DoPaint(FALSE);
}
else
{
m_llist->ContinueSelection(cursorPos);
- DoPaint(FALSE);
- }
+ DoPaint(FALSE);
+ }
}
if(m_Selecting && ! event.LeftIsDown())
{
m_llist->EndSelection(cursorPos);
m_Selecting = false;
- DoPaint(FALSE);
+ DoPaint(FALSE);
}
if(u) u->DecRef();
return;
wxLayoutWindow::OnChar(wxKeyEvent& event)
{
int keyCode = event.KeyCode();
-
+
#ifdef WXLAYOUT_DEBUG
if(keyCode == WXK_F1)
{
// If needed, make cursor visible:
if(m_CursorVisibility == -1)
m_CursorVisibility = 1;
-
+
/* These two nested switches work like this:
The first one processes all non-editing keycodes, to move the
cursor, etc. It's default will process all keycodes causing
break;
default:
if(keyCode == 'c' && event.ControlDown())
+ {
+ // this should work even in read-only mode
Copy();
+ }
if( IsEditable() )
{
/* First, handle control keys */
case 'v':
Paste();
break;
- case 'c':
- Copy();
- break;
case 'x':
Cut();
break;
}
SetDirty();
SetModified();
- }// if(IsEditable())
+ }// if(IsEditable())
}// first switch()
if(m_Selecting)
{
x0 *= dx; y0 *= dy;
WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0, y0));
-
+
// Get the size of the visible window:
GetClientSize(&x1,&y1);
wxASSERT(x1 > 0);
wxASSERT(y1 > 0);
// As we have the values anyway, use them to avoid unnecessary
// scrollbar updates.
- if(x1 > m_maxx) m_maxx = x1;
+ if(x1 > m_maxx) m_maxx = x1;
if(y1 > m_maxy) m_maxy = y1;
/* Make sure that the scrollbars are at a position so that the
cursor is visible if we are editing. */
wxPaintDC dc( this );
PrepareDC( dc );
+#ifdef WXLAYOUT_USE_CARET
+ // hide the caret before drawing anything
+ GetCaret()->Hide();
+#endif // WXLAYOUT_USE_CARET
+
int x0,y0,x1,y1, dx, dy;
// Calculate where the top of the visible area is:
wxASSERT(y1 > 0);
// As we have the values anyway, use them to avoid unnecessary
// scrollbar updates.
- if(x1 > m_maxx) m_maxx = x1;
+ if(x1 > m_maxx) m_maxx = x1;
if(y1 > m_maxy) m_maxy = y1;
m_llist->Layout(dc);
ResizeScrollbars();
}
- /* Check whether the window has grown, if so, we need to reallocate
+ /* 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)
{
wxASSERT(m_bitmapSize.x > 0);
wxASSERT(m_bitmapSize.y > 0);
-
+
m_memDC->SelectObject(wxNullBitmap);
delete m_bitmap;
m_bitmapSize = wxPoint(x1,y1);
m_memDC->SetDeviceOrigin(0,0);
m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(),wxSOLID));
m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(),
- 0,wxTRANSPARENT));
+ 0,wxTRANSPARENT));
m_memDC->SetLogicalFunction(wxCOPY);
/* Either fill the background with the background bitmap, or clear
m_memDC->DrawRectangle(0,0,x1, y1);
}
-
+
/* This is the important bit: we tell the list to draw itself: */
#if WXLO_DEBUG_URECT
if(updateRect)
WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
updateRect->x, updateRect->y,
updateRect->x+updateRect->width,
- updateRect->y+updateRect->height));
+ updateRect->y+updateRect->height));
}
#endif
-
+
// Device origins on the memDC are suspect, we translate manually
// with the translate parameter of Draw().
wxPoint offset(-x0+WXLO_XOFFSET,-y0+WXLO_YOFFSET);
// cursor, so that the cursor coordinates get included in the next
// update rectangle (although they are drawn on the memDC, this is
// needed to erase it):
- m_llist->InvalidateUpdateRect();
- if(m_CursorVisibility == 1)
+ m_llist->InvalidateUpdateRect();
+ if(m_CursorVisibility != 0)
m_llist->DrawCursor(*m_memDC,
m_HaveFocus && IsEditable(), // draw a thick
// cursor for editable windows with focus
dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE);
}
+#ifdef WXLAYOUT_USE_CARET
+ // show the caret back after everything is redrawn
+ m_caret->Show();
+#endif // WXLAYOUT_USE_CARET
+
ResetDirty();
m_ScrollToCursor = false;
- if(m_StatusBar && m_StatusFieldCursor != -1)
+ if(m_StatusBar && m_StatusFieldCursor != -1)
{
wxString label;
- label.Printf(_("L:%d C:%d"), m_llist->GetCursorPos().x+1, m_llist->GetCursorPos().y+1);
+ label.Printf(_("Ln:%d Col:%d"),
+ m_llist->GetCursorPos().y+1,
+ m_llist->GetCursorPos().x+1);
m_StatusBar->SetStatusText(label, m_StatusFieldCursor);
}
}
{
wxPoint max = m_llist->GetSize();
- WXLO_DEBUG(("ResizeScrollbars: GetSize: %ld, %ld", (long int)max.x,
+ WXLO_DEBUG(("ResizeScrollbars: GetSize: %ld, %ld", (long int)max.x,
(long int) max.y));
if(max.x > m_maxx || max.y > m_maxy
|| max.x > m_maxx-WXLO_ROFFSET || max.y > m_maxy-WXLO_BOFFSET
|| exact)
{
- if(! exact)
+ if(! exact)
{
// add an extra bit to the sizes to avoid future updates
- max.x = max.x+WXLO_ROFFSET;
+ max.x = max.x+WXLO_ROFFSET;
max.y = max.y+WXLO_BOFFSET;
}
ViewStart(&m_ViewStartX, &m_ViewStartY);
{
}
//FIXME: missing functionality m_llist->Insert(wxldo.GetList());
- }
+ }
else
#endif
{
}
wxTheClipboard->Close();
}
+
#if 0
/* My attempt to get the primary selection, but it does not
work. :-( */
else if(len > 1 && text[len-1] == '\n')
text = text.Mid(0,len-1);
}
-
+
if (wxTheClipboard->Open())
{
wxTheClipboard->Close();
return rc;
}
+
return FALSE;
}
wxPoint * fromWhere)
{
wxPoint found;
-
+
if(fromWhere == NULL)
found = m_llist->FindText(needle, m_llist->GetCursorPos());
else
#endif
-#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0
+#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 1
enum
{