updated richedit and nettest

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3915 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-10-10 16:52:34 +00:00
parent 2726c66d5b
commit 89be8239db
10 changed files with 650 additions and 442 deletions

View File

@@ -2947,11 +2947,13 @@ AC_OUTPUT([
samples/listctrl/Makefile samples/listctrl/Makefile
samples/mdi/Makefile samples/mdi/Makefile
samples/minifram/Makefile samples/minifram/Makefile
samples/minimal/Makefile samples/minimal/Makefile
samples/nettest/Makefile
samples/newgrid/Makefile samples/newgrid/Makefile
samples/notebook/Makefile samples/notebook/Makefile
samples/printing/Makefile samples/printing/Makefile
samples/proplist/Makefile samples/proplist/Makefile
samples/richedit/Makefile
samples/sashtest/Makefile samples/sashtest/Makefile
samples/scroll/Makefile samples/scroll/Makefile
samples/splitter/Makefile samples/splitter/Makefile

View File

@@ -183,6 +183,7 @@ typedef void (wxObject::*wxDialUpEventFunction)(wxDialUpEvent&);
#define EVT_DIALUP_CONNECTED(func) { wxEVT_DIALUP_CONNECTED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxDialUpEventFunction) & func, NULL}, #define EVT_DIALUP_CONNECTED(func) { wxEVT_DIALUP_CONNECTED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxDialUpEventFunction) & func, NULL},
#define EVT_DIALUP_DISCONNECTED(func) { wxEVT_DIALUP_DISCONNECTED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxDialUpEventFunction) & func, NULL}, #define EVT_DIALUP_DISCONNECTED(func) { wxEVT_DIALUP_DISCONNECTED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxDialUpEventFunction) & func, NULL},
#endif // wxUSE_DIALUP_MANAGER #endif // wxUSE_DIALUP_MANAGER
#endif // _WX_NET_H #endif // _WX_NET_H

View File

@@ -0,0 +1,21 @@
#
# File: makefile.unx
# Author: Julian Smart
# Created: 1998
# Updated:
# Copyright: (c) 1998 Julian Smart
#
# "%W% %G%"
#
# Makefile for richedit example (UNIX).
top_srcdir = @top_srcdir@
top_builddir = ../..
program_dir = samples/richedit
PROGRAM=wxLayout
OBJECTS=$(PROGRAM).o kbList.o wxllist.o wxlparser.o wxlwindow.o
include ../../src/makeprog.env

View File

@@ -19,6 +19,7 @@
#include "wxLayout.h" #include "wxLayout.h"
#include <wx/textfile.h> #include <wx/textfile.h>
#include <iostream.h>
#include "Micon.xpm" #include "Micon.xpm"
@@ -299,10 +300,12 @@ void MyFrame::OnCommand( wxCommandEvent &event )
m_lwin->Cut(); m_lwin->Cut();
m_lwin->Refresh(FALSE); m_lwin->Refresh(FALSE);
break; break;
#ifdef M_BASEDIR
case ID_FIND: case ID_FIND:
m_lwin->Find("void"); m_lwin->Find("void");
m_lwin->Refresh(FALSE); m_lwin->Refresh(FALSE);
break; break;
#endif
case ID_HTML: case ID_HTML:
{ {
wxLayoutExportObject *export; wxLayoutExportObject *export;

View File

@@ -34,6 +34,7 @@
#include "Mpch.h" #include "Mpch.h"
#ifdef M_BASEDIR #ifdef M_BASEDIR
# include "Mcommon.h"
# include "gui/wxllist.h" # include "gui/wxllist.h"
# include "gui/wxlparser.h" # include "gui/wxlparser.h"
# define SHOW_SELECTIONS 1 # define SHOW_SELECTIONS 1
@@ -375,7 +376,22 @@ wxLayoutObjectText::Debug(void)
wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap const &icon) wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap const &icon)
{ {
if ( !icon.Ok() )
{
wxFAIL_MSG("invalid icon");
m_Icon = NULL;
return;
}
#ifdef __WXMSW__
// FIXME ugly, ugly, ugly - but the only way to avoid slicing
m_Icon = icon.GetHBITMAP() ? new wxBitmap(icon)
: new wxBitmap(wxBitmap((const wxBitmap &)icon));
#else // !MSW
m_Icon = new wxBitmap(icon); m_Icon = new wxBitmap(icon);
#endif // MSW/!MSW
} }
@@ -634,6 +650,7 @@ wxLayoutLine::wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist)
m_LineNumber = 0; m_LineNumber = 0;
RecalculatePosition(llist); RecalculatePosition(llist);
MarkDirty();
if(m_Previous) if(m_Previous)
{ {
m_LineNumber = m_Previous->GetLineNumber() + 1; m_LineNumber = m_Previous->GetLineNumber() + 1;
@@ -644,8 +661,7 @@ wxLayoutLine::wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist)
if(m_Next) if(m_Next)
{ {
m_Next->m_Previous = this; m_Next->m_Previous = this;
m_Next->MoveLines(+1); m_Next->ReNumber();
m_Next->RecalculatePositions(1,llist);
} }
m_StyleInfo = llist->GetDefaultStyleInfo(); m_StyleInfo = llist->GetDefaultStyleInfo();
@@ -687,28 +703,6 @@ wxLayoutLine::RecalculatePosition(wxLayoutList *llist)
return m_Position; return m_Position;
} }
void
wxLayoutLine::RecalculatePositions(int recurse, wxLayoutList *llist)
{
//FIXME: is this really needed? We run Layout() anyway.
// 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);
}
}
wxLayoutObjectList::iterator wxLayoutObjectList::iterator
wxLayoutLine::FindObject(CoordType xpos, CoordType *offset) const wxLayoutLine::FindObject(CoordType xpos, CoordType *offset) const
@@ -823,11 +817,6 @@ wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj)
MarkDirty(xpos); MarkDirty(xpos);
// If we insert a command object, we need to recalculate all lines
// to update their styleinfo structure.
if(obj->GetType() == WXLO_TYPE_CMD)
MarkNextDirty(-1);
CoordType offset; CoordType offset;
wxLOiterator i = FindObject(xpos, &offset); wxLOiterator i = FindObject(xpos, &offset);
if(i == NULLIT) if(i == NULLIT)
@@ -923,10 +912,6 @@ wxLayoutLine::Delete(CoordType xpos, CoordType npos)
len = (**i).GetLength(); len = (**i).GetLength();
m_Length -= len; m_Length -= len;
npos -= len; npos -= len;
// If we delete a command object, we need to recalculate all lines
// to update their styleinfo structure.
if((**i).GetType() == WXLO_TYPE_CMD)
MarkNextDirty(-1);
m_ObjectList.erase(i); m_ObjectList.erase(i);
} }
else else
@@ -963,18 +948,6 @@ wxLayoutLine::Delete(CoordType xpos, CoordType npos)
return npos; return npos;
} }
void
wxLayoutLine::MarkNextDirty(int recurse)
{
wxLayoutLine *line = GetNextLine();
while(line && (recurse == -1 || recurse >= 0))
{
line->MarkDirty();
line = line->GetNextLine();
if(recurse > 0) recurse --;
}
}
bool bool
wxLayoutLine::DeleteWord(CoordType xpos) wxLayoutLine::DeleteWord(CoordType xpos)
{ {
@@ -1032,28 +1005,15 @@ wxLayoutLine::DeleteLine(bool update, wxLayoutList *llist)
if(m_Previous) if(m_Previous)
m_Previous->m_Next = m_Next; m_Previous->m_Next = m_Next;
// get the line numbers right again
if ( update && m_Next)
m_Next->ReNumber();
MarkDirty();
// we can't use m_Next after "delete this", so we must save this pointer
// first
wxLayoutLine *next = m_Next; wxLayoutLine *next = m_Next;
if ( next )
{
// get the line numbers right again
next->MoveLines(-1);
}
if(update)
{
if ( next )
next->RecalculatePositions(1, llist);
/* We assume that if we have more than one object in the list,
this means that we have a command object, so we need to
update the following lines. */
if(m_ObjectList.size() > 1 ||
( m_ObjectList.begin() != NULLIT &&
(**m_ObjectList.begin()).GetType() == WXLO_TYPE_CMD)
)
MarkNextDirty(-1);
}
delete this; delete this;
llist->DecNumLines(); llist->DecNumLines();
@@ -1138,6 +1098,8 @@ wxLayoutLine::Layout(wxDC &dc,
bool cursorFound = false; bool cursorFound = false;
RecalculatePosition(llist);
if(cursorPos) if(cursorPos)
{ {
*cursorPos = m_Position; *cursorPos = m_Position;
@@ -1250,8 +1212,7 @@ wxLayoutLine::Layout(wxDC &dc,
// tell next line about coordinate change // tell next line about coordinate change
if(m_Next && m_Height != heightOld) if(m_Next && m_Height != heightOld)
{ {
// FIXME isn't this done in RecalculatePositions() below anyhow? m_Next->MarkDirty();
m_Next->RecalculatePositions(0, llist);
} }
// We need to check whether we found a valid cursor size: // We need to check whether we found a valid cursor size:
@@ -1269,7 +1230,6 @@ wxLayoutLine::Layout(wxDC &dc,
if(m_BaseLine >= cursorSize->y) // the normal case anyway if(m_BaseLine >= cursorSize->y) // the normal case anyway
cursorPos->y += m_BaseLine-cursorSize->y; cursorPos->y += m_BaseLine-cursorSize->y;
} }
RecalculatePositions(1, llist);
MarkClean(); MarkClean();
} }
@@ -1281,24 +1241,6 @@ wxLayoutLine::Break(CoordType xpos, wxLayoutList *llist)
MarkDirty(xpos); MarkDirty(xpos);
/* 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
are in an empty line, we want to move down with it. */
if(xpos == 0 && GetLength() > 0)
{ // insert an empty line before this one
wxLayoutLine *prev = new wxLayoutLine(m_Previous, llist);
if(m_Previous == NULL)
{ // We were in first line, need to link in new empty line
// before this.
prev->m_Next = this;
m_Previous = prev;
m_Previous->m_Height = 0; // this is a wild guess
}
if(m_Next)
m_Next->RecalculatePositions(1, llist);
return m_Previous;
}
CoordType offset; CoordType offset;
wxLOiterator i = FindObject(xpos, &offset); wxLOiterator i = FindObject(xpos, &offset);
if(i == NULLIT) if(i == NULLIT)
@@ -1335,10 +1277,20 @@ wxLayoutLine::Break(CoordType xpos, wxLayoutList *llist)
m_ObjectList.remove(i); // remove without deleting it m_ObjectList.remove(i); // remove without deleting it
} }
if(m_Next) if(m_Next)
m_Next->RecalculatePositions(2, llist); m_Next->MarkDirty();
return newLine; return newLine;
} }
void
wxLayoutLine::ReNumber(void)
{
CoordType lineNo = m_Previous ? m_Previous->m_LineNumber+1 : 0;
m_LineNumber = lineNo++;
for(wxLayoutLine *next = GetNextLine();
next; next = next->GetNextLine())
next->m_LineNumber = lineNo++;
}
void void
wxLayoutLine::MergeNextLine(wxLayoutList *llist) wxLayoutLine::MergeNextLine(wxLayoutList *llist)
@@ -1380,7 +1332,7 @@ wxLayoutLine::MergeNextLine(wxLayoutList *llist)
SetNext(nextLine); SetNext(nextLine);
if ( nextLine ) if ( nextLine )
{ {
nextLine->MoveLines(-1); nextLine->ReNumber();
} }
else else
{ {
@@ -1554,12 +1506,15 @@ wxLayoutList::wxLayoutList()
m_numLines = 0; m_numLines = 0;
m_FirstLine = NULL; m_FirstLine = NULL;
SetAutoFormatting(TRUE);
ForceTotalLayout(TRUE); // for the first time, do all
InvalidateUpdateRect(); InvalidateUpdateRect();
Clear(); Clear();
} }
wxLayoutList::~wxLayoutList() wxLayoutList::~wxLayoutList()
{ {
SetAutoFormatting(FALSE);
InternalClear(); InternalClear();
Empty(); Empty();
m_FirstLine->DeleteLine(false, this); m_FirstLine->DeleteLine(false, this);
@@ -1753,7 +1708,7 @@ wxLayoutList::MoveCursorVertically(int n)
if(! m_CursorLine) if(! m_CursorLine)
{ {
m_CursorLine = last; m_CursorLine = last;
m_CursorPos.y ++; m_CursorPos.y --;
rc = false; rc = false;
} }
else else
@@ -1992,7 +1947,8 @@ wxLayoutList::Insert(wxString const &text)
m_movedCursor = true; m_movedCursor = true;
m_CursorLine->RecalculatePositions(0, this); if(m_AutoFormat)
m_CursorLine->MarkDirty();
return true; return true;
} }
@@ -2011,7 +1967,8 @@ wxLayoutList::Insert(wxLayoutObject *obj)
m_CursorPos.x += obj->GetLength(); m_CursorPos.x += obj->GetLength();
m_movedCursor = true; m_movedCursor = true;
m_CursorLine->RecalculatePositions(0, this); if(m_AutoFormat)
m_CursorLine->MarkDirty();
return true; return true;
} }
@@ -2094,7 +2051,7 @@ wxLayoutList::WrapLine(CoordType column)
Delete(1); // delete the space Delete(1); // delete the space
m_CursorPos.x = newpos; m_CursorPos.x = newpos;
m_CursorLine->RecalculatePositions(1, this); m_CursorLine->MarkDirty();
m_movedCursor = true; m_movedCursor = true;
@@ -2197,7 +2154,8 @@ wxLayoutList::DeleteLines(int n)
{ // we cannot delete this line, but we can clear it { // we cannot delete this line, but we can clear it
MoveCursorToBeginOfLine(); MoveCursorToBeginOfLine();
DeleteToEndOfLine(); DeleteToEndOfLine();
m_CursorLine->RecalculatePositions(2, this); if(m_AutoFormat)
m_CursorLine->MarkDirty();
return n-1; return n-1;
} }
//else: //else:
@@ -2208,13 +2166,16 @@ wxLayoutList::DeleteLines(int n)
wxASSERT(m_FirstLine); wxASSERT(m_FirstLine);
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
} }
m_CursorLine->RecalculatePositions(2, this); if(m_AutoFormat)
m_CursorLine->MarkDirty();
return n; return n;
} }
void void
wxLayoutList::Recalculate(wxDC &dc, CoordType bottom) wxLayoutList::Recalculate(wxDC &dc, CoordType bottom)
{ {
if(! m_AutoFormat)
return;
wxLayoutLine *line = m_FirstLine; wxLayoutLine *line = m_FirstLine;
// first, make sure everything is calculated - this might not be // first, make sure everything is calculated - this might not be
@@ -2230,7 +2191,7 @@ wxLayoutList::Recalculate(wxDC &dc, CoordType bottom)
} }
wxPoint wxPoint
wxLayoutList::GetCursorScreenPos(wxDC &dc) wxLayoutList::GetCursorScreenPos(void) const
{ {
return m_CursorScreenPos; return m_CursorScreenPos;
} }
@@ -2247,18 +2208,39 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
// needed, optimise it later // needed, optimise it later
ApplyStyle(m_DefaultStyleInfo, dc); ApplyStyle(m_DefaultStyleInfo, dc);
// This one we always Layout() to get the current cursor
// coordinates on the screen: if(m_ReLayoutAll)
m_CursorLine->MarkDirty(); {
bool wasDirty = false; forceAll = TRUE;
bottom = -1;
}
ForceTotalLayout(FALSE);
// If one line was dirty, we need to re-calculate all
// following lines, too.
bool wasDirty = forceAll;
wxLayoutLine *line = m_FirstLine; wxLayoutLine *line = m_FirstLine;
while(line) while(line)
{ {
if(! wasDirty) if(! wasDirty)
ApplyStyle(line->GetStyleInfo(), dc); ApplyStyle(line->GetStyleInfo(), dc);
if(forceAll || line->IsDirty() if(
|| (cpos && line->GetLineNumber() == cpos->y)) // if any previous line was dirty, we need to layout all
// following lines:
wasDirty
// layout dirty lines:
|| line->IsDirty()
// always layout the cursor line toupdate the cursor
// position and size:
|| line == m_CursorLine
// or if it's the line we are asked to look for:
|| (cpos && line->GetLineNumber() == cpos->y)
)
{ {
if(line->IsDirty())
wasDirty = true;
// The following Layout() calls will update our // The following Layout() calls will update our
// m_CurrentStyleInfo if needed. // m_CurrentStyleInfo if needed.
if(line == m_CursorLine) if(line == m_CursorLine)
@@ -2286,16 +2268,16 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
// little condition to speed up redrawing: // little condition to speed up redrawing:
if(bottom != -1 && line->GetPosition().y > bottom) if(bottom != -1 && line->GetPosition().y > bottom)
break; break;
wasDirty = true;
} }
line->RecalculatePositions(1, this);
line = line->GetNextLine(); line = line->GetNextLine();
} }
#ifndef WXLAYOUT_USE_CARET
// can only be 0 if we are on the first line and have no next line // can only be 0 if we are on the first line and have no next line
wxASSERT(m_CursorSize.x != 0 || (m_CursorLine && wxASSERT(m_CursorSize.x != 0 || (m_CursorLine &&
m_CursorLine->GetNextLine() == NULL && m_CursorLine->GetNextLine() == NULL &&
m_CursorLine == m_FirstLine)); m_CursorLine == m_FirstLine));
#endif // WXLAYOUT_USE_CARET
AddCursorPosToUpdateRect(); AddCursorPosToUpdateRect();
} }
@@ -2311,7 +2293,8 @@ void
wxLayoutList::Draw(wxDC &dc, wxLayoutList::Draw(wxDC &dc,
wxPoint const &offset, wxPoint const &offset,
CoordType top, CoordType top,
CoordType bottom) CoordType bottom,
bool clipStrictly)
{ {
wxLayoutLine *line = m_FirstLine; wxLayoutLine *line = m_FirstLine;
@@ -2332,29 +2315,27 @@ wxLayoutList::Draw(wxDC &dc,
m_Selection.m_discarded = false; m_Selection.m_discarded = false;
} }
/* We need to re-layout all dirty lines to update styleinfos /* This call to Layout() will re-calculate and update all lines
etc. However, somehow we don't find all dirty lines... */ marked as dirty.
Layout(dc); //,-1,true); //FIXME */
Layout(dc, bottom);
ApplyStyle(m_DefaultStyleInfo, dc); ApplyStyle(m_DefaultStyleInfo, dc);
wxBrush brush(m_CurrentStyleInfo.m_bg, wxSOLID); wxBrush brush(m_CurrentStyleInfo.m_bg, wxSOLID);
dc.SetBrush(brush); dc.SetBrush(brush);
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
bool style_set = false;
while(line) while(line)
{ {
// only draw if between top and bottom: // only draw if between top and bottom:
if((top == -1 || if((top == -1 ||
line->GetPosition().y + line->GetHeight() > top)) line->GetPosition().y + line->GetHeight() > top))
{ {
// if(! style_set) ApplyStyle(line->GetStyleInfo(), dc);
{
ApplyStyle(line->GetStyleInfo(), dc);
style_set = true;
}
// little condition to speed up redrawing: // little condition to speed up redrawing:
if(bottom != -1 if( bottom != -1
&& line->GetPosition().y+line->GetHeight() >= bottom) && line->GetPosition().y
+(clipStrictly ? line->GetHeight() : 0) >= bottom)
break; break;
line->Draw(dc, this, offset); line->Draw(dc, this, offset);
} }
@@ -2540,17 +2521,17 @@ wxLayoutList::ContinueSelection(const wxPoint& cposOrig, const wxPoint& spos)
wxASSERT(m_Selection.m_valid == false); wxASSERT(m_Selection.m_valid == false);
WXLO_DEBUG(("Continuing selection at %ld/%ld", cpos.x, cpos.y)); WXLO_DEBUG(("Continuing selection at %ld/%ld", cpos.x, cpos.y));
if ( m_Selection.m_CursorB <= cpos )
{
m_Selection.m_ScreenB = spos; m_Selection.m_ScreenB = spos;
m_Selection.m_CursorB = cpos; m_Selection.m_CursorB = cpos;}
}
else
{
m_Selection.m_ScreenA = spos;
m_Selection.m_CursorA = cpos;
}
void
wxLayoutList::EndSelection(const wxPoint& cposOrig, const wxPoint& spos)
{
wxPoint cpos(cposOrig);
if(cpos.x == -1)
cpos = m_CursorPos;
ContinueSelection(cpos);
WXLO_DEBUG(("Ending selection at %ld/%ld", cpos.x, cpos.y));
// we always want m_CursorA <= m_CursorB! // we always want m_CursorA <= m_CursorB!
if( m_Selection.m_CursorA > m_Selection.m_CursorB ) if( m_Selection.m_CursorA > m_Selection.m_CursorB )
{ {
@@ -2563,18 +2544,12 @@ wxLayoutList::ContinueSelection(const wxPoint& cposOrig, const wxPoint& spos)
m_Selection.m_ScreenB = m_Selection.m_ScreenA; m_Selection.m_ScreenB = m_Selection.m_ScreenA;
m_Selection.m_ScreenA = help; m_Selection.m_ScreenA = help;
} }
}
void
wxLayoutList::EndSelection(const wxPoint& cposOrig, const wxPoint& spos)
{
wxPoint cpos(cposOrig);
if(cpos.x == -1)
cpos = m_CursorPos;
ContinueSelection(cpos);
WXLO_DEBUG(("Ending selection at %ld/%ld", cpos.x, cpos.y));
m_Selection.m_selecting = false; m_Selection.m_selecting = false;
m_Selection.m_valid = true; m_Selection.m_valid = true;
/// In case we just clicked somewhere, the selection will have zero
/// size, so we discard it immediately.
if(m_Selection.m_CursorA == m_Selection.m_CursorB)
DiscardSelection();
} }
void void
@@ -2600,7 +2575,12 @@ wxLayoutList::IsSelected(const wxPoint &cursor) const
if ( !HasSelection() ) if ( !HasSelection() )
return false; return false;
return m_Selection.m_CursorA <= cursor && cursor <= m_Selection.m_CursorB; return (
(m_Selection.m_CursorA <= cursor
&& cursor <= m_Selection.m_CursorB)
|| (m_Selection.m_CursorB <= cursor
&& cursor <= m_Selection.m_CursorA)
);
} }
@@ -2620,7 +2600,10 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
return 0; return 0;
CoordType y = line->GetLineNumber(); CoordType y = line->GetLineNumber();
if(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y) if(
(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
|| (m_Selection.m_CursorB.y < y && m_Selection.m_CursorA.y > y)
)
return 1; return 1;
else if(m_Selection.m_CursorA.y == y) else if(m_Selection.m_CursorA.y == y)
{ {
@@ -2628,7 +2611,18 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
if(m_Selection.m_CursorB.y == y) if(m_Selection.m_CursorB.y == y)
*to = m_Selection.m_CursorB.x; *to = m_Selection.m_CursorB.x;
else else
*to = line->GetLength(); {
if(m_Selection.m_CursorB > m_Selection.m_CursorA)
*to = line->GetLength();
else
*to = 0;
}
if(*to < *from)
{
CoordType help = *to;
*to = *from;
*from = help;
}
return -1; return -1;
} }
else if(m_Selection.m_CursorB.y == y) else if(m_Selection.m_CursorB.y == y)
@@ -2637,7 +2631,18 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
if(m_Selection.m_CursorA.y == y) if(m_Selection.m_CursorA.y == y)
*from = m_Selection.m_CursorA.x; *from = m_Selection.m_CursorA.x;
else else
*from = 0; {
if(m_Selection.m_CursorB > m_Selection.m_CursorA)
*from = 0;
else
*from = line->GetLength();
}
if(*to < *from)
{
CoordType help = *to;
*to = *from;
*from = help;
}
return -1; return -1;
} }
else else
@@ -2665,6 +2670,9 @@ wxLayoutList::DeleteSelection(void)
wxLayoutLine wxLayoutLine
* firstLine = GetLine(m_Selection.m_CursorA.y), * firstLine = GetLine(m_Selection.m_CursorA.y),
* lastLine = GetLine(m_Selection.m_CursorB.y); * lastLine = GetLine(m_Selection.m_CursorB.y);
// be a bit paranoid:
if(! firstLine || ! lastLine)
return;
// First, delete what's left of this line: // First, delete what's left of this line:
MoveCursorTo(m_Selection.m_CursorA); MoveCursorTo(m_Selection.m_CursorA);
@@ -2682,7 +2690,7 @@ wxLayoutList::DeleteSelection(void)
// Recalculate the line positions and numbers but notice that firstLine // Recalculate the line positions and numbers but notice that firstLine
// might not exist any more - it could be deleted by Delete(1) above // might not exist any more - it could be deleted by Delete(1) above
wxLayoutLine *firstLine2 = prevLine ? prevLine->GetNextLine() : m_FirstLine; wxLayoutLine *firstLine2 = prevLine ? prevLine->GetNextLine() : m_FirstLine;
firstLine2->RecalculatePositions(1, this); firstLine2->MarkDirty();
} }
/// Starts highlighting the selection /// Starts highlighting the selection
@@ -2708,6 +2716,37 @@ wxLayoutList::EndHighlighting(wxDC &dc)
} }
wxLayoutLine *
wxLayoutList::GetLine(CoordType index) const
{
wxASSERT_MSG( (0 <= index) && (index < (CoordType)m_numLines),
"invalid index" );
wxLayoutLine *line;
CoordType n = index;
#ifdef DEBUG
CoordType lineNo = 0;
#endif
for ( line = m_FirstLine; line && n-- > 0; line =
line->GetNextLine() )
{
#ifdef DEBUG
wxASSERT(line->GetLineNumber() == lineNo );
lineNo++;
#endif
}
if ( line )
{
// should be the right one
wxASSERT( line->GetLineNumber() == index );
}
return line;
}
wxLayoutList * wxLayoutList *
wxLayoutList::Copy(const wxPoint &from, wxLayoutList::Copy(const wxPoint &from,
const wxPoint &to) const wxPoint &to)
@@ -2782,15 +2821,15 @@ wxLayoutList::GetSelection(wxLayoutDataObject *wxlo, bool invalidate)
{ {
wxString string; wxString string;
wxLayoutExportObject *export; wxLayoutExportObject *exp;
wxLayoutExportStatus status(llist); wxLayoutExportStatus status(llist);
while((export = wxLayoutExport( &status, WXLO_EXPORT_AS_OBJECTS)) != NULL) while((exp = wxLayoutExport( &status, WXLO_EXPORT_AS_OBJECTS)) != NULL)
{ {
if(export->type == WXLO_EXPORT_EMPTYLINE) if(exp->type == WXLO_EXPORT_EMPTYLINE)
; //FIXME missing support for linebreaks in string format ; //FIXME missing support for linebreaks in string format
else else
export->content.object->Write(string); exp->content.object->Write(string);
delete export; delete exp;
} }
wxlo->SetData(string.c_str(), string.Length()+1); wxlo->SetData(string.c_str(), string.Length()+1);
@@ -2861,6 +2900,9 @@ wxLayoutPrintout::wxLayoutPrintout(wxLayoutList *llist,
// remove any highlighting which could interfere with printing: // remove any highlighting which could interfere with printing:
m_llist->StartSelection(); m_llist->StartSelection();
m_llist->EndSelection(); m_llist->EndSelection();
// force a full layout of the list:
m_llist->ForceTotalLayout();
// layout is called in ScaleDC() when we have a DC
} }
wxLayoutPrintout::~wxLayoutPrintout() wxLayoutPrintout::~wxLayoutPrintout()
@@ -2934,7 +2976,8 @@ bool wxLayoutPrintout::OnPrintPage(int page)
// SetDeviceOrigin() doesn't work here, so we need to manually // SetDeviceOrigin() doesn't work here, so we need to manually
// translate all coordinates. // translate all coordinates.
wxPoint translate(m_Offset.x,m_Offset.y-top); wxPoint translate(m_Offset.x,m_Offset.y-top);
m_llist->Draw(*dc, translate, top, bottom); m_llist->Draw(*dc, translate, top, bottom, TRUE /* clip strictly
*/);
return true; return true;
} }
else else
@@ -2947,14 +2990,19 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
determine the correct paper size and scaling. We don't actually determine the correct paper size and scaling. We don't actually
print anything on it. */ print anything on it. */
#ifdef __WXMSW__ #ifdef __WXMSW__
wxPrinterDC psdc("","",WXLLIST_TEMPFILE,false); wxPrinterDC *psdc = new wxPrinterDC("","",WXLLIST_TEMPFILE,false);
#else #else
wxPostScriptDC psdc(WXLLIST_TEMPFILE,false); wxPostScriptDC *psdc = new wxPostScriptDC(WXLLIST_TEMPFILE,false);
#endif #endif
float scale = ScaleDC(&psdc); psdc->StartDoc(m_title);
// before we draw anything, me must make sure the list is properly
// laid out
m_llist->Layout(*psdc);
psdc.GetSize(&m_PageWidth, &m_PageHeight); float scale = ScaleDC(psdc);
psdc->GetSize(&m_PageWidth, &m_PageHeight);
// This sets a left/top origin of 15% and 5%: // This sets a left/top origin of 15% and 5%:
m_Offset = wxPoint((15*m_PageWidth)/100, (5*m_PageHeight)/100); m_Offset = wxPoint((15*m_PageWidth)/100, (5*m_PageHeight)/100);
@@ -2962,14 +3010,6 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
// This is the length of the printable area. // This is the length of the printable area.
m_PrintoutHeight = m_PageHeight - 2*m_Offset.y; m_PrintoutHeight = m_PageHeight - 2*m_Offset.y;
m_PrintoutHeight = (int)( m_PrintoutHeight / scale); // we want to use the real paper height m_PrintoutHeight = (int)( m_PrintoutHeight / scale); // we want to use the real paper height
#if 0
// We should really use the margin settings of wxWindows somehow.
m_Offset = wxPoint(0,0);
// This is the length of the printable area.
m_PrintoutHeight = m_PageHeight;
m_PrintoutHeight = (int)( m_PrintoutHeight / scale); // we want to use the real paper height
#endif
m_NumOfPages = 1 + m_NumOfPages = 1 +
(int)( m_llist->GetSize().y / (float)(m_PrintoutHeight)); (int)( m_llist->GetSize().y / (float)(m_PrintoutHeight));
@@ -2979,6 +3019,8 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
*selPageFrom = 1; *selPageFrom = 1;
*selPageTo = m_NumOfPages; *selPageTo = m_NumOfPages;
psdc->EndDoc();
delete psdc;
wxRemoveFile(WXLLIST_TEMPFILE); wxRemoveFile(WXLLIST_TEMPFILE);
} }

View File

@@ -1,7 +1,7 @@
/*-*- c++ -*-******************************************************** /*-*- c++ -*-********************************************************
* wxLayoutList.h - a formatted text rendering engine for wxWindows * * wxLayoutList.h - a formatted text rendering engine for wxWindows *
* * * *
* (C) 1999 by Karsten Ball<6C>der (Ballueder@usa.net) * * (C) 1999 by Karsten Ball<6C>der (ballueder@gmx.net) *
* * * *
* $Id$ * $Id$
*******************************************************************/ *******************************************************************/
@@ -28,6 +28,8 @@
# define WXMENU_LAYOUT_LCLICK 1111 # define WXMENU_LAYOUT_LCLICK 1111
# define WXMENU_LAYOUT_RCLICK 1112 # define WXMENU_LAYOUT_RCLICK 1112
# define WXMENU_LAYOUT_DBLCLICK 1113 # define WXMENU_LAYOUT_DBLCLICK 1113
#else // for Mahogany only:
# include "MObject.h"
#endif #endif
// use the wxWindows caret class instead of home grown cursor whenever possible // use the wxWindows caret class instead of home grown cursor whenever possible
@@ -96,6 +98,9 @@ class WXDLLEXPORT wxFont;
its size. its size.
*/ */
class wxLayoutObject class wxLayoutObject
#ifdef M_BASEDIR
: public MObject
#endif
{ {
public: public:
/** This structure can be used to contain data associated with the /** This structure can be used to contain data associated with the
@@ -210,6 +215,9 @@ public:
protected: protected:
/// optional data for application's use /// optional data for application's use
UserData *m_UserData; UserData *m_UserData;
#if defined (M_BASEDIR) && defined (DEBUG)
MOBJECT_NAME(wxLayoutObject)
#endif
}; };
/// Define a list type of wxLayoutObject pointers. /// Define a list type of wxLayoutObject pointers.
@@ -640,15 +648,6 @@ public:
CoordType GetHeight(void) const { return m_Height; } CoordType GetHeight(void) const { return m_Height; }
/// Returns the width of this line. /// Returns the width of this line.
CoordType GetWidth(void) const { return m_Width; } CoordType GetWidth(void) const { return m_Width; }
/** This will recalculate the position and size of this line.
If called recursively it will abort if the position of an
object is unchanged, assuming that none of the following
objects need to move.
@param recurse if greater 0 then it will be used as the
minimum(!) recursion level, continue with all lines till the end of
the list or until the coordinates no longer changed.
*/
void RecalculatePositions(int recurse, wxLayoutList *llist);
/// Recalculates the position of this line on the canvas. /// Recalculates the position of this line on the canvas.
wxPoint RecalculatePosition(wxLayoutList *llist); wxPoint RecalculatePosition(wxLayoutList *llist);
@@ -681,10 +680,6 @@ public:
m_Dirty = true; m_Dirty = true;
} }
/** Marks the following lines as dirty.
@param recurse if -1 recurse to end of list, otherwise depth of recursion.
*/
void MarkNextDirty(int recurse = 0);
/// Reset the dirty flag /// Reset the dirty flag
void MarkClean() { m_Dirty = false; m_updateLeft = -1; } void MarkClean() { m_Dirty = false; m_updateLeft = -1; }
@@ -699,17 +694,10 @@ private:
@param height new height @param height new height
*/ */
void SetHeight(CoordType height, wxLayoutList *llist) void SetHeight(CoordType height, wxLayoutList *llist)
{ m_Height = height; RecalculatePositions(true, llist); } { m_Height = height; MarkDirty(); }
/** Moves the linenumbers one on, because a line has been inserted /** Updates the line numbers. */
or deleted. void ReNumber(void);
@param delta either +1 or -1
*/
void MoveLines(int delta)
{
m_LineNumber += delta;
if(m_Next) m_Next->MoveLines(delta);
}
//@} //@}
private: private:
/// The line number. /// The line number.
@@ -776,6 +764,14 @@ public:
/// Empty: clear the list but leave font settings. /// Empty: clear the list but leave font settings.
void Empty(void); void Empty(void);
/** Enable or disable auto-formatting. Normally, while editing this
should be enabled which is the default. While
inserting/deleting lots of text, it makes sense to temporarily
disable this.
@param enable TRUE to enable, FALSE to disable
*/
void SetAutoFormatting(bool enable = TRUE)
{ m_AutoFormat = enable; }
/**@name Cursor Management */ /**@name Cursor Management */
//@{ //@{
/** Set new cursor position. /** Set new cursor position.
@@ -971,10 +967,13 @@ public:
@param offset an optional offset to shift printout @param offset an optional offset to shift printout
@param top optional y coordinate where to start drawing @param top optional y coordinate where to start drawing
@param bottom optional y coordinate where to stop drawing @param bottom optional y coordinate where to stop drawing
@param clipStrictly if set, do not draw objects which reach
beyond "bottom". Set this when printing.
*/ */
void Draw(wxDC &dc, void Draw(wxDC &dc,
const wxPoint &offset = wxPoint(0,0), const wxPoint &offset = wxPoint(0,0),
CoordType top = -1, CoordType bottom = -1); CoordType top = -1, CoordType bottom = -1,
bool clipStrictly = false);
/** Calculates new layout for the list, like Draw() but does not /** Calculates new layout for the list, like Draw() but does not
actually draw it. actually draw it.
@@ -989,6 +988,13 @@ public:
wxPoint *cpos = NULL, wxPoint *cpos = NULL,
wxPoint *csize = NULL); wxPoint *csize = NULL);
/** Ensure that the whole list will be recalculate on the next call
to Layout() or Draw().
@param redrawAll TRUE or FALSE to reset it
*/
void ForceTotalLayout(bool redrawAll = TRUE)
{ m_ReLayoutAll = redrawAll; }
/** Returns the screen coordinates relating to a given cursor /** Returns the screen coordinates relating to a given cursor
position and the size of the cursor at that position. position and the size of the cursor at that position.
@param dc for which to calculate it @param dc for which to calculate it
@@ -1014,9 +1020,8 @@ public:
wxPoint GetSize(void) const; wxPoint GetSize(void) const;
/** Returns the cursor position on the screen. /** Returns the cursor position on the screen.
@return cursor position in pixels
*/ */
wxPoint GetCursorScreenPos(wxDC &dc); wxPoint GetCursorScreenPos(void) const;
/** Draws the cursor. /** Draws the cursor.
@param active If true, draw a bold cursor to mark window as @param active If true, draw a bold cursor to mark window as
@@ -1134,25 +1139,7 @@ public:
void DecNumLines() { m_numLines--; } void DecNumLines() { m_numLines--; }
/// get the line by number /// get the line by number
wxLayoutLine *GetLine(CoordType index) const wxLayoutLine *GetLine(CoordType index) const;
{
wxASSERT_MSG( (0 <= index) && (index < (CoordType)m_numLines),
"invalid index" );
wxLayoutLine *line;
CoordType n = index;
for ( line = m_FirstLine; line && n-- > 0; line = line->GetNextLine() )
;
if ( line )
{
// should be the right one
wxASSERT( line->GetLineNumber() == index );
}
return line;
}
private: private:
/// Clear the list. /// Clear the list.
void InternalClear(void); void InternalClear(void);
@@ -1167,6 +1154,10 @@ private:
/// Is the update rectangle valid? /// Is the update rectangle valid?
bool m_UpdateRectValid; bool m_UpdateRectValid;
/// Shall we auto-format?
bool m_AutoFormat;
/// Shall we re-layout everything?
bool m_ReLayoutAll;
/**@name Cursor Management */ /**@name Cursor Management */
//@{ //@{
/// Where the text cursor (column,line) is. /// Where the text cursor (column,line) is.

View File

@@ -178,7 +178,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
int mode, int flags) int mode, int flags)
{ {
wxASSERT(status); wxASSERT(status);
wxLayoutExportObject * export; wxLayoutExportObject * exp;
if(status->m_iterator == NULLIT) // end of line if(status->m_iterator == NULLIT) // end of line
{ {
@@ -186,29 +186,29 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
// reached end of list // reached end of list
return NULL; return NULL;
} }
export = new wxLayoutExportObject(); exp = new wxLayoutExportObject();
wxLayoutObjectType type; wxLayoutObjectType type;
if(status->m_iterator != NULLIT) if(status->m_iterator != NULLIT)
{ {
type = (** status->m_iterator).GetType(); type = (** status->m_iterator).GetType();
if( mode == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case if( mode == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
{ {
export->type = WXLO_EXPORT_OBJECT; exp->type = WXLO_EXPORT_OBJECT;
export->content.object = *status->m_iterator; exp->content.object = *status->m_iterator;
status->m_iterator++; status->m_iterator++;
return export; return exp;
} }
} }
else else
{ // iterator == NULLIT { // iterator == NULLIT
if(mode == WXLO_EXPORT_AS_OBJECTS) if(mode == WXLO_EXPORT_AS_OBJECTS)
{ {
export->type = WXLO_EXPORT_EMPTYLINE; exp->type = WXLO_EXPORT_EMPTYLINE;
export->content.object = NULL; //empty line exp->content.object = NULL; //empty line
status->m_line = status->m_line->GetNextLine(); status->m_line = status->m_line->GetNextLine();
if(status->m_line) if(status->m_line)
status->m_iterator = status->m_line->GetFirstObject(); status->m_iterator = status->m_line->GetFirstObject();
return export; return exp;
} }
else else
type = WXLO_TYPE_TEXT; type = WXLO_TYPE_TEXT;
@@ -254,9 +254,9 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
status->m_iterator++; status->m_iterator++;
} }
export->type = (mode == WXLO_EXPORT_AS_HTML) exp->type = (mode == WXLO_EXPORT_AS_HTML)
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT; ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
export->content.text = str; exp->content.text = str;
return export; return exp;
} }

View File

@@ -1,7 +1,7 @@
/*-*- c++ -*-******************************************************** /*-*- c++ -*-********************************************************
* wxLwindow.h : a scrolled Window for displaying/entering rich text* * wxLwindow.h : a scrolled Window for displaying/entering rich text*
* * * *
* (C) 1998, 1999 by Karsten Ball<6C>der (Ballueder@usa.net) * * (C) 1998, 1999 by Karsten Ball<6C>der (karsten@phy.hw.ac.uk) *
* * * *
* $Id$ * $Id$
*******************************************************************/ *******************************************************************/
@@ -34,6 +34,9 @@
# endif // USE_PCH # endif // USE_PCH
# include "gui/wxlwindow.h" # include "gui/wxlwindow.h"
# include "gui/wxlparser.h" # include "gui/wxlparser.h"
# include "MDialogs.h"
# include "strutil.h"
#else #else
# ifdef __WXMSW__ # ifdef __WXMSW__
# include <wx/msw/private.h> # include <wx/msw/private.h>
@@ -57,7 +60,7 @@
// macros // macros
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#ifdef WXLAYOUT_DEBUG #ifdef DEBUG
# define WXLO_DEBUG(x) wxLogDebug x # define WXLO_DEBUG(x) wxLogDebug x
#else #else
# define WXLO_DEBUG(x) # define WXLO_DEBUG(x)
@@ -75,6 +78,10 @@
#define WXLO_ROFFSET 20 #define WXLO_ROFFSET 20
#define WXLO_BOFFSET 20 #define WXLO_BOFFSET 20
/// scroll margins when selecting with the mouse
#define WXLO_SCROLLMARGIN_X 10
#define WXLO_SCROLLMARGIN_Y 10
/// the size of one scrollbar page in pixels /// the size of one scrollbar page in pixels
static const int X_SCROLL_PAGE = 10; static const int X_SCROLL_PAGE = 10;
static const int Y_SCROLL_PAGE = 20; static const int Y_SCROLL_PAGE = 20;
@@ -105,6 +112,8 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus) EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus)
EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus) EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus)
// EVT_IDLE(wxLayoutWindow::ResizeScrollbars)
END_EVENT_TABLE() END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -119,7 +128,7 @@ static bool IsDirectionKey(long keyCode);
// ============================================================================ // ============================================================================
#ifndef wxWANTS_CHARS #ifndef wxWANTS_CHARS
#define wxWANTS_CHARS 0 # define wxWANTS_CHARS 0
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -146,6 +155,9 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
m_llist = new wxLayoutList(); m_llist = new wxLayoutList();
m_BGbitmap = NULL; m_BGbitmap = NULL;
m_ScrollToCursor = false; m_ScrollToCursor = false;
#ifndef __WXMSW__
m_FocusFollowMode = false;
#endif
SetWrapMargin(0); SetWrapMargin(0);
// no scrollbars initially // no scrollbars initially
@@ -194,8 +206,7 @@ wxLayoutWindow::Clear(int family,
wxScrolledWindow::Clear(); wxScrolledWindow::Clear();
ResizeScrollbars(true); ResizeScrollbars(true);
SetDirty(); SetDirty();
SetModified(false); SetModified(FALSE);
if ( m_Editable ) if ( m_Editable )
m_CursorVisibility = 1; m_CursorVisibility = 1;
@@ -204,15 +215,12 @@ wxLayoutWindow::Clear(int family,
GetCaret()->Show(); GetCaret()->Show();
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
DoPaint((wxRect *)NULL); RequestUpdate((wxRect *)NULL);
} }
void wxLayoutWindow::Refresh(bool eraseBackground, const wxRect *rect) void wxLayoutWindow::Refresh(bool eraseBackground, const wxRect *rect)
{ {
wxScrolledWindow::Refresh(eraseBackground, rect); wxScrolledWindow::Refresh(eraseBackground, rect);
ResizeScrollbars();
//FIXME is this needed? It causes problems... ScrollToCursor();
} }
void void
@@ -220,15 +228,12 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{ {
wxClientDC dc( this ); wxClientDC dc( this );
PrepareDC( dc ); PrepareDC( dc );
#ifdef __WXMSW__ if ( eventId != WXLOWIN_MENU_MOUSEMOVE
if ( eventId != WXLOWIN_MENU_MOUSEMOVE ) #ifndef __WXMSW__
|| m_FocusFollowMode
#endif #endif
{ )
// moving the mouse in a window shouldn't give it the focus!
// Oh yes! wxGTK's focus handling is so broken, that this is the
// only sensible way to go.
SetFocus(); SetFocus();
}
wxPoint findPos; wxPoint findPos;
findPos.x = dc.DeviceToLogicalX(event.GetX()); findPos.x = dc.DeviceToLogicalX(event.GetX());
@@ -238,12 +243,43 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
findPos.y -= WXLO_YOFFSET; findPos.y -= WXLO_YOFFSET;
if(findPos.x < 0) if(findPos.x < 0)
findPos.x = 0; findPos.x = 0;
if(findPos.y < 0) if(findPos.y < 0)
findPos.y = 0; findPos.y = 0;
m_ClickPosition = wxPoint(event.GetX(), event.GetY()); m_ClickPosition = wxPoint(event.GetX(), event.GetY());
// Scroll the window if the mouse is at the end of it:
if(m_Selecting && eventId == WXLOWIN_MENU_MOUSEMOVE)
{
//WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
int left, top;
ViewStart(&left, &top);
wxSize size = GetClientSize();
int xdelta, ydelta;
if(event.GetX() < WXLO_SCROLLMARGIN_X)
xdelta = -(WXLO_SCROLLMARGIN_X-event.GetX());
else if(event.GetX() > size.x-WXLO_SCROLLMARGIN_X)
xdelta = event.GetX()-size.x+WXLO_SCROLLMARGIN_X;
else
xdelta = 0;
if(event.GetY() < WXLO_SCROLLMARGIN_Y)
ydelta = -(WXLO_SCROLLMARGIN_Y-event.GetY());
else if(event.GetY() > size.y-WXLO_SCROLLMARGIN_Y)
ydelta = event.GetY()-size.y+WXLO_SCROLLMARGIN_Y;
else
ydelta = 0;
//WXLO_DEBUG(("xdelta: %d", (int) xdelta));
if(xdelta != 0 || ydelta != 0)
{
top += ydelta; if(top < 0) top = 0;
left += xdelta; if(left < 0) left = 0;
Scroll(left, top);
}
}
wxPoint cursorPos; wxPoint cursorPos;
bool found; bool found;
wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos, wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos,
@@ -253,141 +289,132 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
// has the mouse only been moved? // has the mouse only been moved?
switch ( eventId ) switch ( eventId )
{ {
case WXLOWIN_MENU_MOUSEMOVE: case WXLOWIN_MENU_MOUSEMOVE:
{ {
// this variables is used to only erase the message in the status // this variables is used to only erase the message in the status
// bar if we had put it there previously - otherwise empting status // bar if we had put it there previously - otherwise empting status
// bar might be undesirable // bar might be undesirable
static bool s_hasPutMessageInStatusBar = false; static bool s_hasPutMessageInStatusBar = false;
// found is only true if we are really over an object, not just // found is only true if we are really over an object, not just
// behind it // behind it
if(found && u && ! m_Selecting) if(found && u && ! m_Selecting)
{
if(!m_HandCursor)
SetCursor(wxCURSOR_HAND);
m_HandCursor = TRUE;
if(m_StatusBar && m_StatusFieldLabel != -1)
{
const wxString &label = u->GetLabel();
if(label.Length())
{ {
if(!m_HandCursor) m_StatusBar->SetStatusText(label,
SetCursor(wxCURSOR_HAND); m_StatusFieldLabel);
m_HandCursor = TRUE; s_hasPutMessageInStatusBar = true;
if(m_StatusBar && m_StatusFieldLabel != -1)
{
const wxString &label = u->GetLabel();
if(label.Length())
{
m_StatusBar->SetStatusText(label,
m_StatusFieldLabel);
s_hasPutMessageInStatusBar = true;
}
}
}
else
{
if(m_HandCursor)
SetCursor(wxCURSOR_IBEAM);
m_HandCursor = FALSE;
if( m_StatusBar && m_StatusFieldLabel != -1 &&
s_hasPutMessageInStatusBar )
{
m_StatusBar->SetStatusText("", m_StatusFieldLabel);
}
} }
} }
}
// selecting? else
if ( event.LeftIsDown() ) {
if(m_HandCursor)
SetCursor(wxCURSOR_IBEAM);
m_HandCursor = FALSE;
if( m_StatusBar && m_StatusFieldLabel != -1 &&
s_hasPutMessageInStatusBar )
{ {
// m_Selecting might not be set if the button got pressed m_StatusBar->SetStatusText("", m_StatusFieldLabel);
// outside this window, so check for it:
if( m_Selecting )
{
m_llist->ContinueSelection(cursorPos, m_ClickPosition);
DoPaint(); // TODO: we don't have to redraw everything!
}
} }
}
}
if ( u ) // selecting?
{ if ( event.LeftIsDown() )
u->DecRef(); {
u = NULL; // m_Selecting might not be set if the button got pressed
} // outside this window, so check for it:
break; if( m_Selecting )
{
m_llist->ContinueSelection(cursorPos, m_ClickPosition);
RequestUpdate(); // TODO: we don't have to redraw everything!
}
}
case WXLOWIN_MENU_LDOWN: if ( u )
{ {
// always move cursor to mouse click: u->DecRef();
// if ( obj ) u = NULL;
{ }
// we have found the real position break;
m_llist->MoveCursorTo(cursorPos);
}
// else
// {
// // click beyond the end of the text
// m_llist->MoveCursorToEnd();
// }
// clicking a mouse removes the selection case WXLOWIN_MENU_LDOWN:
if ( m_llist->HasSelection() ) {
{ // always move cursor to mouse click:
m_llist->DiscardSelection(); m_llist->MoveCursorTo(cursorPos);
m_Selecting = false;
DoPaint(); // TODO: we don't have to redraw everything!
}
// Calculate where the top of the visible area is: // clicking a mouse removes the selection
int x0, y0; if ( m_llist->HasSelection() )
ViewStart(&x0,&y0); {
int dx, dy; m_llist->DiscardSelection();
GetScrollPixelsPerUnit(&dx, &dy); m_Selecting = false;
x0 *= dx; y0 *= dy; RequestUpdate(); // TODO: we don't have to redraw everything!
}
wxPoint offset(-x0+WXLO_XOFFSET, -y0+WXLO_YOFFSET); // Calculate where the top of the visible area is:
int x0, y0;
ViewStart(&x0,&y0);
int dx, dy;
GetScrollPixelsPerUnit(&dx, &dy);
x0 *= dx; y0 *= dy;
if(m_CursorVisibility == -1) wxPoint offset(-x0+WXLO_XOFFSET, -y0+WXLO_YOFFSET);
m_CursorVisibility = 1;
if(m_CursorVisibility == -1)
m_CursorVisibility = 1;
#ifdef WXLAYOUT_USE_CARET #ifdef WXLAYOUT_USE_CARET
if ( m_CursorVisibility == 1 ) if ( m_CursorVisibility == 1 )
GetCaret()->Show(); GetCaret()->Show();
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
if(m_CursorVisibility) if(m_CursorVisibility)
{ {
// draw a thick cursor for editable windows with focus // draw a thick cursor for editable windows with focus
m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset); m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset);
} }
#ifdef __WXGTK__ #ifdef __WXGTK__
DoPaint(); // DoPaint suppresses flicker under GTK RequestUpdate(); // RequestUpdate suppresses flicker under GTK
#endif // wxGTK #endif // wxGTK
// start selection // start selection
m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition); m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition);
m_Selecting = true; m_Selecting = true;
} }
break; break;
case WXLOWIN_MENU_LUP: case WXLOWIN_MENU_LUP:
if ( m_Selecting ) if ( m_Selecting )
{ {
m_llist->EndSelection();
m_Selecting = false;
DoPaint(); // TODO: we don't have to redraw everything!
}
break;
case WXLOWIN_MENU_MDOWN:
Paste(TRUE);
break;
case WXLOWIN_MENU_DBLCLICK:
// select a word under cursor
m_llist->MoveCursorTo(cursorPos);
m_llist->MoveCursorWord(-1);
m_llist->StartSelection();
m_llist->MoveCursorWord(1, false);
m_llist->EndSelection(); m_llist->EndSelection();
m_Selecting = false; m_Selecting = false;
DoPaint(); // TODO: we don't have to redraw everything!
break; RequestUpdate(); // TODO: we don't have to redraw everything!
}
break;
case WXLOWIN_MENU_MDOWN:
Paste(TRUE);
break;
case WXLOWIN_MENU_DBLCLICK:
// select a word under cursor
m_llist->MoveCursorTo(cursorPos);
m_llist->MoveCursorWord(-1);
m_llist->StartSelection();
m_llist->MoveCursorWord(1, false);
m_llist->EndSelection();
m_Selecting = false;
RequestUpdate(); // TODO: we don't have to redraw everything!
break;
} }
// notify about mouse events? // notify about mouse events?
@@ -440,6 +467,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
{ {
m_Selecting = false; m_Selecting = false;
m_llist->EndSelection(); m_llist->EndSelection();
m_llist->DiscardSelection(); //FIXME: correct?
} }
// If we deleted the selection here, we must not execute the // If we deleted the selection here, we must not execute the
@@ -455,14 +483,15 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
{ {
m_llist->DeleteSelection(); m_llist->DeleteSelection();
deletedSelection = true; deletedSelection = true;
SetDirty();
} }
// <Shift>+<arrow> starts selection // <Shift>+<arrow> starts selection
if ( IsDirectionKey(keyCode) ) if ( IsDirectionKey(keyCode) )
{ {
// just continue the old selection
if ( m_Selecting ) if ( m_Selecting )
{ {
// just continue the old selection
if( event.ShiftDown() ) if( event.ShiftDown() )
m_llist->ContinueSelection(); m_llist->ContinueSelection();
else else
@@ -476,7 +505,6 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
m_Selecting = true; m_Selecting = true;
m_llist->StartSelection(); m_llist->StartSelection();
} }
} }
// If needed, make cursor visible: // If needed, make cursor visible:
@@ -526,18 +554,33 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
else else
m_llist->MoveCursorToEndOfLine(); m_llist->MoveCursorToEndOfLine();
break; break;
default: default:
if(keyCode == 'c' && ctrlDown)
{ if(ctrlDown && ! IsEditable())
// this should work even in read-only mode switch(keyCode)
Copy(); {
} case 'c':
// this should work even in read-only mode
Copy();
break;
#ifdef M_BASEDIR
case 's': // search
Find("");
break;
case 't': // search again
FindAgain();
break;
#endif
default:
;
}
else if( IsEditable() ) else if( IsEditable() )
{ {
/* First, handle control keys */ /* First, handle control keys */
if(ctrlDown && ! event.AltDown()) if(ctrlDown && ! event.AltDown())
{ {
if(keyCode >= 'A' && keyCode <= 'Z')
keyCode = tolower(keyCode);
switch(keyCode) switch(keyCode)
{ {
case WXK_INSERT: case WXK_INSERT:
@@ -545,23 +588,44 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
break; break;
case WXK_DELETE : case WXK_DELETE :
if(! deletedSelection) if(! deletedSelection)
{
m_llist->DeleteWord(); m_llist->DeleteWord();
SetDirty();
}
break; break;
case 'd': case 'd':
if(! deletedSelection) // already done if(! deletedSelection) // already done
{
m_llist->Delete(1); m_llist->Delete(1);
SetDirty();
}
break; break;
case 'y': case 'y':
m_llist->DeleteLines(1); m_llist->DeleteLines(1);
SetDirty();
break; break;
case 'h': // like backspace case 'h': // like backspace
if(m_llist->MoveCursorHorizontally(-1)) m_llist->Delete(1); if(m_llist->MoveCursorHorizontally(-1))
{
m_llist->Delete(1);
SetDirty();
}
break; break;
case 'u': #ifdef M_BASEDIR
case 's': // search
Find("");
break;
case 't': // search again
FindAgain();
break;
#endif
case 'u':
m_llist->DeleteToBeginOfLine(); m_llist->DeleteToBeginOfLine();
SetDirty();
break; break;
case 'k': case 'k':
m_llist->DeleteToEndOfLine(); m_llist->DeleteToEndOfLine();
SetDirty();
break; break;
case 'v': case 'v':
Paste(); Paste();
@@ -586,6 +650,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
case WXK_DELETE: case WXK_DELETE:
case 'd': case 'd':
m_llist->DeleteWord(); m_llist->DeleteWord();
SetDirty();
break; break;
default: default:
; ;
@@ -605,45 +670,57 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
Cut(); Cut();
else else
if(! deletedSelection) if(! deletedSelection)
{
m_llist->Delete(1); m_llist->Delete(1);
SetDirty();
}
break; break;
case WXK_BACK: // backspace case WXK_BACK: // backspace
if(! deletedSelection) if(! deletedSelection)
if(m_llist->MoveCursorHorizontally(-1)) if(m_llist->MoveCursorHorizontally(-1))
{
m_llist->Delete(1); m_llist->Delete(1);
SetDirty();
}
break; break;
case WXK_RETURN: case WXK_RETURN:
if(m_WrapMargin > 0) if(m_WrapMargin > 0)
m_llist->WrapLine(m_WrapMargin); m_llist->WrapLine(m_WrapMargin);
m_llist->LineBreak(); m_llist->LineBreak();
SetDirty();
break; break;
case WXK_TAB: case WXK_TAB:
if ( !event.ShiftDown() ) if ( !event.ShiftDown() )
{ {
// TODO should be configurable // TODO should be configurable
static const int tabSize = 8; static const int tabSize = 8;
CoordType x = m_llist->GetCursorPos().x; CoordType x = m_llist->GetCursorPos().x;
size_t numSpaces = tabSize - x % tabSize; size_t numSpaces = tabSize - x % tabSize;
m_llist->Insert(wxString(' ', numSpaces)); m_llist->Insert(wxString(' ', numSpaces));
SetDirty();
} }
break; break;
default: default:
if((!(event.ControlDown() || event.AltDown() || event.MetaDown())) if((!(event.ControlDown() || event.AltDown()
//#if 0
///FIXME: wxGTK reports MetaDown always
|| event.MetaDown()
//#endif
))
&& (keyCode < 256 && keyCode >= 32) && (keyCode < 256 && keyCode >= 32)
) )
{ {
if(m_WrapMargin > 0 && isspace(keyCode)) if(m_WrapMargin > 0 && isspace(keyCode))
m_llist->WrapLine(m_WrapMargin); m_llist->WrapLine(m_WrapMargin);
m_llist->Insert((char)keyCode); m_llist->Insert((char)keyCode);
SetDirty();
} }
break; break;
} }
} }
SetDirty();
SetModified();
}// if(IsEditable()) }// if(IsEditable())
}// first switch() }// first switch()
@@ -652,14 +729,9 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
// continue selection to the current (new) cursor position // continue selection to the current (new) cursor position
m_llist->ContinueSelection(); m_llist->ContinueSelection();
} }
// we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
// ne cursor position might be outside the current scrolllbar range
ResizeScrollbars();
ScrollToCursor(); ScrollToCursor();
// refresh the screen // refresh the screen
DoPaint(m_llist->GetUpdateRect()); RequestUpdate(m_llist->GetUpdateRect());
} }
void void
@@ -678,8 +750,9 @@ wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
void void
wxLayoutWindow::ScrollToCursor(void) wxLayoutWindow::ScrollToCursor(void)
{ {
wxClientDC dc( this ); //is always needed to make sure we know where the cursor is
PrepareDC( dc ); //if(IsDirty())
RequestUpdate(m_llist->GetUpdateRect());
int x0,y0,x1,y1, dx, dy; int x0,y0,x1,y1, dx, dy;
@@ -693,13 +766,10 @@ wxLayoutWindow::ScrollToCursor(void)
// Get the size of the visible window: // Get the size of the visible window:
GetClientSize(&x1, &y1); GetClientSize(&x1, &y1);
// update the cursor screen position
m_llist->Layout(dc);
// Make sure that the scrollbars are at a position so that the cursor is // Make sure that the scrollbars are at a position so that the cursor is
// visible if we are editing // visible if we are editing
WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor)); WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor));
wxPoint cc = m_llist->GetCursorScreenPos(dc); wxPoint cc = m_llist->GetCursorScreenPos();
// the cursor should be completely visible in both directions // the cursor should be completely visible in both directions
wxPoint cs(m_llist->GetCursorSize()); wxPoint cs(m_llist->GetCursorSize());
@@ -723,9 +793,9 @@ wxLayoutWindow::ScrollToCursor(void)
{ {
// set new view start // set new view start
Scroll(nx == -1 ? -1 : (nx+dx-1)/dx, ny == -1 ? -1 : (ny+dy-1)/dy); Scroll(nx == -1 ? -1 : (nx+dx-1)/dx, ny == -1 ? -1 : (ny+dy-1)/dy);
// avoid recursion // avoid recursion
m_ScrollToCursor = false; m_ScrollToCursor = false;
RequestUpdate();
} }
} }
@@ -737,7 +807,7 @@ wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event))
} }
void void
wxLayoutWindow::DoPaint(const wxRect *updateRect) wxLayoutWindow::RequestUpdate(const wxRect *updateRect)
{ {
#ifdef __WXGTK__ #ifdef __WXGTK__
// Calling Refresh() causes bad flicker under wxGTK!!! // Calling Refresh() causes bad flicker under wxGTK!!!
@@ -782,8 +852,16 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
} }
if(IsDirty()) if(IsDirty())
{ {
WXLO_DEBUG(("InternalPaint, isdirty, list size: %ld,%ld",
(unsigned long) m_llist->GetSize().x,
(unsigned long) m_llist->GetSize().y));
// m_llist->ForceTotalLayout();
m_llist->Layout(dc); m_llist->Layout(dc);
WXLO_DEBUG(("InternalPaint, isdirty, list size after layout: %ld,%ld",
(unsigned long) m_llist->GetSize().x,
(unsigned long) m_llist->GetSize().y));
ResizeScrollbars(); ResizeScrollbars();
ResetDirty();
} }
/* Check whether the window has grown, if so, we need to reallocate /* Check whether the window has grown, if so, we need to reallocate
@@ -881,7 +959,6 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
ResetDirty(); ResetDirty();
m_ScrollToCursor = false;
if ( m_StatusBar && m_StatusFieldCursor != -1 ) if ( m_StatusBar && m_StatusFieldCursor != -1 )
{ {
@@ -905,9 +982,7 @@ void
wxLayoutWindow::OnSize(wxSizeEvent &event) wxLayoutWindow::OnSize(wxSizeEvent &event)
{ {
if ( m_llist ) if ( m_llist )
{
ResizeScrollbars(); ResizeScrollbars();
}
event.Skip(); event.Skip();
} }
@@ -916,6 +991,17 @@ wxLayoutWindow::OnSize(wxSizeEvent &event)
void void
wxLayoutWindow::ResizeScrollbars(bool exact) wxLayoutWindow::ResizeScrollbars(bool exact)
{ {
if(IsDirty())
{
wxClientDC dc( this );
PrepareDC( dc );
// m_llist->ForceTotalLayout();
m_llist->Layout(dc);
ResetDirty();
RequestUpdate();
}
wxPoint max = m_llist->GetSize(); wxPoint max = m_llist->GetSize();
wxSize size = GetClientSize(); wxSize size = GetClientSize();
@@ -1016,6 +1102,7 @@ wxLayoutWindow::Paste(bool primary)
wxTheClipboard->GetData(&data); wxTheClipboard->GetData(&data);
wxString text = data.GetText(); wxString text = data.GetText();
wxLayoutImportText( m_llist, text); wxLayoutImportText( m_llist, text);
SetDirty();
} }
} }
wxTheClipboard->Close(); wxTheClipboard->Close();
@@ -1039,13 +1126,13 @@ wxLayoutWindow::Copy(bool invalidate)
return FALSE; return FALSE;
// Export selection as text: // Export selection as text:
wxString text; wxString text;
wxLayoutExportObject *export; wxLayoutExportObject *exp;
wxLayoutExportStatus status(llist); wxLayoutExportStatus status(llist);
while((export = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL) while((exp = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
{ {
if(export->type == WXLO_EXPORT_TEXT) if(exp->type == WXLO_EXPORT_TEXT)
text << *(export->content.text); text << *(exp->content.text);
delete export; delete exp;
} }
delete llist; delete llist;
@@ -1080,6 +1167,7 @@ wxLayoutWindow::Cut(void)
if(Copy(false)) // do not invalidate selection after copy if(Copy(false)) // do not invalidate selection after copy
{ {
m_llist->DeleteSelection(); m_llist->DeleteSelection();
SetDirty();
return TRUE; return TRUE;
} }
else else
@@ -1090,16 +1178,31 @@ wxLayoutWindow::Cut(void)
// searching // searching
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#ifdef M_BASEDIR
bool bool
wxLayoutWindow::Find(const wxString &needle, wxLayoutWindow::Find(const wxString &needle,
wxPoint * fromWhere) wxPoint * fromWhere,
const wxString &configPath)
{ {
wxPoint found; wxPoint found;
if(fromWhere == NULL) if(needle.Length() == 0)
found = m_llist->FindText(needle, m_llist->GetCursorPos()); {
if( ! MInputBox(&m_FindString,
_("Find text"),
_(" Find:"),
this,
configPath, "")
|| strutil_isempty(m_FindString))
return true;
}
else else
found = m_llist->FindText(needle, *fromWhere); m_FindString = needle;
if(fromWhere == NULL)
found = m_llist->FindText(m_FindString, m_llist->GetCursorPos());
else
found = m_llist->FindText(m_FindString, *fromWhere);
if(found.x != -1) if(found.x != -1)
{ {
if(fromWhere) if(fromWhere)
@@ -1109,11 +1212,21 @@ wxLayoutWindow::Find(const wxString &needle,
} }
m_llist->MoveCursorTo(found); m_llist->MoveCursorTo(found);
ScrollToCursor(); ScrollToCursor();
RequestUpdate();
return true; return true;
} }
return false; return false;
} }
bool
wxLayoutWindow::FindAgain(void)
{
bool rc = Find(m_FindString);
return rc;
}
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// popup menu stuff // popup menu stuff
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1157,21 +1270,21 @@ void wxLayoutWindow::OnMenu(wxCommandEvent& event)
switch (event.GetId()) switch (event.GetId())
{ {
case WXLOWIN_MENU_LARGER: case WXLOWIN_MENU_LARGER:
m_llist->SetFontLarger(); DoPaint(); break; m_llist->SetFontLarger(); RequestUpdate(); break;
case WXLOWIN_MENU_SMALLER: case WXLOWIN_MENU_SMALLER:
m_llist->SetFontSmaller(); DoPaint(); break; m_llist->SetFontSmaller(); RequestUpdate(); break;
case WXLOWIN_MENU_UNDERLINE: case WXLOWIN_MENU_UNDERLINE:
m_llist->ToggleFontUnderline(); DoPaint(); break; m_llist->ToggleFontUnderline(); RequestUpdate(); break;
case WXLOWIN_MENU_BOLD: case WXLOWIN_MENU_BOLD:
m_llist->ToggleFontWeight(); DoPaint(); break; m_llist->ToggleFontWeight(); RequestUpdate(); break;
case WXLOWIN_MENU_ITALICS: case WXLOWIN_MENU_ITALICS:
m_llist->ToggleFontItalics(); DoPaint(); break; m_llist->ToggleFontItalics(); RequestUpdate(); break;
case WXLOWIN_MENU_ROMAN: case WXLOWIN_MENU_ROMAN:
m_llist->SetFontFamily(wxROMAN); DoPaint(); break; m_llist->SetFontFamily(wxROMAN); RequestUpdate(); break;
case WXLOWIN_MENU_TYPEWRITER: case WXLOWIN_MENU_TYPEWRITER:
m_llist->SetFontFamily(wxFIXED); DoPaint(); break; m_llist->SetFontFamily(wxFIXED); RequestUpdate(); break;
case WXLOWIN_MENU_SANSSERIF: case WXLOWIN_MENU_SANSSERIF:
m_llist->SetFontFamily(wxSWISS); DoPaint(); break; m_llist->SetFontFamily(wxSWISS); RequestUpdate(); break;
} }
} }
@@ -1184,7 +1297,7 @@ wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
{ {
m_HaveFocus = true; m_HaveFocus = true;
ev.Skip(); ev.Skip();
DoPaint(); // cursor must change RequestUpdate(); // cursor must change
} }
void void
@@ -1192,7 +1305,7 @@ wxLayoutWindow::OnKillFocus(wxFocusEvent &ev)
{ {
m_HaveFocus = false; m_HaveFocus = false;
ev.Skip(); ev.Skip();
DoPaint();// cursor must change RequestUpdate();// cursor must change
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -1,7 +1,7 @@
/*-*- c++ -*-******************************************************** /*-*- c++ -*-********************************************************
* wxLwindow.h : a scrolled Window for displaying/entering rich text* * wxLwindow.h : a scrolled Window for displaying/entering rich text*
* * * *
* (C) 1998,1999 by Karsten Ball<6C>der (Ballueder@usa.net) * * (C) 1998-1999 by Karsten Ball<6C>der (karsten@phy.hw.ac.uk) *
* * * *
* $Id$ * $Id$
*******************************************************************/ *******************************************************************/
@@ -106,8 +106,15 @@ public:
bool Cut(void); bool Cut(void);
//@} //@}
#ifdef M_BASEDIR
/// find string in buffer
bool Find(const wxString &needle, bool Find(const wxString &needle,
wxPoint * fromWhere = NULL); wxPoint * fromWhere = NULL,
const wxString &configPath = "MsgViewFindString");
/// find the same string again
bool FindAgain(void);
#endif
void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; } void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
@@ -120,7 +127,7 @@ public:
Internally, this stores the parameter and calls a refresh on Internally, this stores the parameter and calls a refresh on
wxMSW, draws directly on wxGTK. wxMSW, draws directly on wxGTK.
*/ */
void DoPaint(const wxRect *updateRect = NULL); void RequestUpdate(const wxRect *updateRect = NULL);
/// if exact == false, assume 50% extra size for the future /// if exact == false, assume 50% extra size for the future
void ResizeScrollbars(bool exact = false); // don't change this to true! void ResizeScrollbars(bool exact = false); // don't change this to true!
@@ -155,22 +162,9 @@ public:
/// Creates a wxMenu for use as a format popup. /// Creates a wxMenu for use as a format popup.
static wxMenu * MakeFormatMenu(void); static wxMenu * MakeFormatMenu(void);
/**@name Dirty flag handling for optimisations. */ /// Redraws the window, used by RequestUpdate() or OnPaint().
//@{
/// Set dirty flag.
void SetDirty(void) { m_Dirty = true; }
/// Query whether window needs redrawing.
bool IsDirty(void) const { return m_Dirty; }
/// Reset dirty flag.
void ResetDirty(void) { m_Dirty = false; }
//@}
/// Redraws the window, used by DoPaint() or OnPaint().
void InternalPaint(const wxRect *updateRect); void InternalPaint(const wxRect *updateRect);
/// Has list been modified/edited?
bool IsModified(void) const { return m_Modified; }
/// Mark list as modified or unchanged.
void SetModified(bool modified = true) { m_Modified = modified; }
/** Tell window to update a wxStatusBar with UserData labels and /** Tell window to update a wxStatusBar with UserData labels and
cursor positions. cursor positions.
@param bar wxStatusBar pointer @param bar wxStatusBar pointer
@@ -184,6 +178,35 @@ public:
m_StatusBar = bar; m_StatusFieldLabel = labelfield; m_StatusBar = bar; m_StatusFieldLabel = labelfield;
m_StatusFieldCursor = cursorfield; m_StatusFieldCursor = cursorfield;
} }
#ifndef __WXMSW__
/// Enable or disable focus follow mode under non-MSW
void SetFocusFollowMode(bool enable = TRUE)
{ m_FocusFollowMode = enable; }
#endif
/**@name Modified flag handling, will not get reset by list unless
in Clear() */
//@{
/// Set dirty flag.
void SetModified(bool modified = TRUE) { m_Modified = modified; }
/// Query whether window needs redrawing.
bool IsModified(void) const { return m_Modified; }
//@}
/**@name Dirty flag handling for optimisations.
Normally one should only need to call SetDirty(), e.g. when
manipulating the wxLayoutList directly, so the window will update
itself. ResetDirty() and IsDirty() should only be used
internally. */
//@{
/// Set dirty flag.
void SetDirty(void) { m_Dirty = true; m_Modified = true; }
/// Query whether window needs redrawing.
bool IsDirty(void) const { return m_Dirty; }
/// Reset dirty flag.
void ResetDirty(void) { m_Dirty = false; }
//@}
protected: protected:
/// generic function for mouse events processing /// generic function for mouse events processing
@@ -237,10 +260,10 @@ private:
bool m_Selecting; bool m_Selecting;
/// wrap margin /// wrap margin
CoordType m_WrapMargin; CoordType m_WrapMargin;
/// Is list dirty (for redraws, internal use)? /// Has list changed since last redraw, e.g. in size?
bool m_Dirty; bool m_Dirty;
/// Has list been edited? /// Has the list ever been modified?
bool m_Modified; bool m_Modified;
wxMemoryDC *m_memDC; wxMemoryDC *m_memDC;
wxBitmap *m_bitmap; wxBitmap *m_bitmap;
wxPoint m_bitmapSize; wxPoint m_bitmapSize;
@@ -256,7 +279,13 @@ private:
//@{ //@{
/// Do we want to auto-replace the selection with new text? /// Do we want to auto-replace the selection with new text?
bool m_AutoDeleteSelection; bool m_AutoDeleteSelection;
//@} #ifndef __WXMSW__
/// Do we want the focus to follow the mouse?
bool m_FocusFollowMode;
#endif
/// For finding text and finding it again:
wxString m_FindString;
//@}
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -472,36 +472,42 @@ wxDialUpManagerImpl::CheckStatusInternal(void)
// This can be used under Win 9x, too! // This can be used under Win 9x, too!
struct hostent *hp; struct hostent *hp;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
int sockfd;
m_IsOnline = 0; // assume false m_IsOnline = 0; // assume false
if((hp = gethostbyname(m_BeaconHost)) == NULL) if((hp = gethostbyname(m_BeaconHost)) == NULL)
return; // no DNS no net return; // no DNS no net
serv_addr.sin_family = hp->h_addrtype; serv_addr.sin_family = hp->h_addrtype;
memcpy(&serv_addr.sin_addr,hp->h_addr, hp->h_length); memcpy(&serv_addr.sin_addr,hp->h_addr, hp->h_length);
serv_addr.sin_port = htons(m_BeaconPort); serv_addr.sin_port = htons(m_BeaconPort);
// PING method:
int sockfd;
if( ( sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) if( ( sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0)
{ {
// sys_error("cannot create socket for gw"); // sys_error("cannot create socket for gw");
return; return;
} }
// PING method:
if(sendto(sockfd, "hello", strlen("hello"), /* flags */ 0, if(sendto(sockfd, "hello",
(struct sockaddr *)&serv_addr, strlen("hello"), /* flags */ 0,
(struct sockaddr *) &serv_addr,
sizeof(serv_addr)) == -1) sizeof(serv_addr)) == -1)
{
close(sockfd);
return; return;
#if 0 }
#if 0
if( connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) if( connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{ {
//sys_error("cannot connect to server"); //sys_error("cannot connect to server");
return; return;
} }
//connected! //connected!
close(sockfd);
#endif #endif
close(sockfd);
m_IsOnline = TRUE; m_IsOnline = TRUE;
} }