First part of fixes to make this work under MSW.

1. letters actually appear on the screen
2. Clear() works
3. Backspace/Delete in one line works too
4. breaking lines works
5. cursor is now a wxCaret
6. tons of other fixes


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2652 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-06-02 21:26:11 +00:00
parent 379a3b04b9
commit 5bdc3b1d4a
6 changed files with 492 additions and 294 deletions

View File

@ -1,6 +1,6 @@
/*
* Program: wxLayout
*
*
* Author: Karsten Ballüder
*
* Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
@ -61,12 +61,12 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
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");
@ -102,10 +102,11 @@ MyFrame::MyFrame(void) :
#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);
@ -122,11 +123,11 @@ MyFrame::AddSampleText(wxLayoutList *llist)
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();
@ -218,7 +219,7 @@ void MyFrame::OnCommand( wxCommandEvent &event )
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);
@ -314,7 +315,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
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))
@ -340,14 +341,14 @@ void MyFrame::OnPrintPreview(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();
@ -430,7 +431,7 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
// MyApp
//-----------------------------------------------------------------------------
MyApp::MyApp(void) :
MyApp::MyApp(void) :
wxApp( )
{
};

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,12 @@
# 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
@ -38,7 +44,7 @@
#ifdef WXLAYOUT_DEBUG
# define WXLO_TRACE(x) wxLogDebug(x)
#else
# define WXLO_TRACE(x)
# define WXLO_TRACE(x)
#endif
#define WXLO_DEBUG_URECT 0
@ -72,20 +78,22 @@ typedef long CoordType;
// 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
@ -118,7 +126,7 @@ public:
@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
@ -129,11 +137,11 @@ public:
*/
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
@ -154,7 +162,7 @@ public:
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(); }
@ -174,7 +182,21 @@ public:
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.
@ -199,6 +221,9 @@ public:
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.
@ -209,7 +234,7 @@ KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject);
/// The iterator type.
#define wxLOiterator wxLayoutObjectList::iterator
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectText
@ -220,14 +245,14 @@ class wxLayoutObjectText : public wxLayoutObject
{
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
@ -268,7 +293,7 @@ private:
long m_Bottom;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
wxLayoutObjectIcon
@ -284,13 +309,13 @@ public:
~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
@ -309,7 +334,7 @@ private:
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
@ -337,7 +362,7 @@ 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;
@ -345,7 +370,7 @@ public:
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
@ -368,17 +393,18 @@ KBLIST_DEFINE(wxFCEList, wxFontCacheEntry);
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
@ -389,9 +415,9 @@ class wxLayoutObjectCmd : public wxLayoutObject
{
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,
@ -413,19 +439,16 @@ private:
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
@ -443,7 +466,7 @@ public:
@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
@ -457,6 +480,8 @@ public:
void Append(wxLayoutObject * obj)
{
wxASSERT(obj);
obj->AttachToLine(this);
m_ObjectList.push_back(obj);
m_Length += obj->GetLength();
}
@ -483,20 +508,20 @@ public:
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
@ -526,8 +551,8 @@ public:
@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
*/
@ -535,7 +560,7 @@ public:
{
return m_ObjectList.begin();
}
/** Deletes this line, returns pointer to next line.
@param update If true, update all following lines.
*/
@ -557,17 +582,17 @@ public:
//@{
/** 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
@ -631,7 +656,7 @@ public:
void Copy(wxLayoutList *llist,
CoordType from = 0,
CoordType to = -1);
#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
@ -695,13 +720,13 @@ private:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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
{
@ -711,6 +736,11 @@ public:
/// 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,
@ -721,7 +751,7 @@ public:
wxColour *bg=NULL);
/// Empty: clear the list but leave font settings.
void Empty(void);
/**@name Cursor Management */
//@{
/** Set new cursor position.
@ -744,9 +774,9 @@ public:
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); }
@ -754,7 +784,7 @@ public:
/// Returns current cursor position.
const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
const wxPoint &GetCursorPos() const { return m_CursorPos; }
//@}
/**@name Editing functions.
@ -767,7 +797,7 @@ public:
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
@ -788,7 +818,7 @@ public:
@return how many it could not delete
*/
int DeleteLines(int n);
/// Delete to end of line.
void DeleteToEndOfLine(void)
{
@ -843,7 +873,7 @@ public:
/// 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
@ -898,7 +928,7 @@ public:
@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.
@ -911,7 +941,7 @@ public:
@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.
@ -944,6 +974,15 @@ public:
*/
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.
@ -977,7 +1016,7 @@ public:
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));
@ -985,7 +1024,7 @@ public:
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
@ -993,7 +1032,7 @@ public:
@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);
@ -1007,7 +1046,7 @@ private:
/** 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:
@ -1018,13 +1057,17 @@ private:
//@{
/// 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
@ -1045,12 +1088,11 @@ private:
//@}
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The wxLayoutDataObject for exporting data to the clipboard in our
own format.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class wxLayoutDataObject : public wxPrivateDataObject
{
@ -1063,10 +1105,10 @@ public:
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The wxLayoutPrintout object for printing within the wxWindows print
framework.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** This class implements a wxPrintout for printing a wxLayoutList within
the wxWindows printing framework.
@ -1083,7 +1125,7 @@ public:
"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
@ -1114,7 +1156,7 @@ protected:
/* no longer used
virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
*/
*/
private:
/// The list to print.
wxLayoutList *m_llist;

View File

@ -10,7 +10,14 @@
# 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"

View File

@ -1,7 +1,7 @@
/*-*- 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$
*******************************************************************/
@ -11,12 +11,13 @@
#endif
#include "wx/wxprec.h"
#ifdef __BORLANDC__
# pragma hdrstop
#endif
#include "Mpch.h"
#ifdef M_BASEDIR
# ifndef USE_PCH
# include "Mcommon.h"
@ -41,6 +42,10 @@
#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
@ -71,8 +76,9 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
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
@ -85,6 +91,7 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
m_bitmap = new wxBitmap(4,4);
m_bitmapSize = wxPoint(4,4);
m_llist = new wxLayoutList();
m_BGbitmap = NULL;
m_ScrollToCursor = false;
SetWrapMargin(0);
@ -93,7 +100,16 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
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();
}
@ -121,12 +137,8 @@ wxLayoutWindow::Clear(int family,
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__
@ -142,7 +154,7 @@ void
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{
wxPaintDC dc( this );
PrepareDC( dc );
PrepareDC( dc );
SetFocus();
wxPoint findPos;
@ -173,7 +185,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
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())
@ -186,7 +198,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
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())
@ -195,19 +207,19 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{
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;
@ -257,7 +269,7 @@ void
wxLayoutWindow::OnChar(wxKeyEvent& event)
{
int keyCode = event.KeyCode();
#ifdef WXLAYOUT_DEBUG
if(keyCode == WXK_F1)
{
@ -289,7 +301,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
// 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
@ -323,7 +335,10 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
break;
default:
if(keyCode == 'c' && event.ControlDown())
{
// this should work even in read-only mode
Copy();
}
if( IsEditable() )
{
/* First, handle control keys */
@ -353,9 +368,6 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
case 'v':
Paste();
break;
case 'c':
Copy();
break;
case 'x':
Cut();
break;
@ -420,7 +432,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
}
SetDirty();
SetModified();
}// if(IsEditable())
}// if(IsEditable())
}// first switch()
if(m_Selecting)
{
@ -464,14 +476,14 @@ wxLayoutWindow::ScrollToCursor(void)
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. */
@ -513,6 +525,11 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
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:
@ -526,7 +543,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
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;
@ -542,13 +559,13 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
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);
@ -559,7 +576,7 @@ 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(),
0,wxTRANSPARENT));
0,wxTRANSPARENT));
m_memDC->SetLogicalFunction(wxCOPY);
/* Either fill the background with the background bitmap, or clear
@ -582,7 +599,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
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)
@ -590,10 +607,10 @@ wxLayoutWindow::InternalPaint(const wxRect *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);
@ -603,8 +620,8 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
// 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
@ -636,12 +653,19 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
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);
}
}
@ -652,16 +676,16 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
{
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);
@ -684,7 +708,7 @@ wxLayoutWindow::Paste(void)
{
}
//FIXME: missing functionality m_llist->Insert(wxldo.GetList());
}
}
else
#endif
{
@ -698,6 +722,7 @@ wxLayoutWindow::Paste(void)
}
wxTheClipboard->Close();
}
#if 0
/* My attempt to get the primary selection, but it does not
work. :-( */
@ -746,7 +771,7 @@ wxLayoutWindow::Copy(bool invalidate)
else if(len > 1 && text[len-1] == '\n')
text = text.Mid(0,len-1);
}
if (wxTheClipboard->Open())
{
@ -758,6 +783,7 @@ wxLayoutWindow::Copy(bool invalidate)
wxTheClipboard->Close();
return rc;
}
return FALSE;
}
@ -777,7 +803,7 @@ wxLayoutWindow::Find(const wxString &needle,
wxPoint * fromWhere)
{
wxPoint found;
if(fromWhere == NULL)
found = m_llist->FindText(needle, m_llist->GetCursorPos());
else

View File

@ -23,7 +23,7 @@
#endif
#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0
#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 1
enum
{