wxLayoutStyleInfo ctor reverted back to the original, selection works better
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -642,6 +642,8 @@ wxLayoutLine::wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist)
|
|||||||
m_Next->MoveLines(+1);
|
m_Next->MoveLines(+1);
|
||||||
m_Next->RecalculatePositions(1,llist);
|
m_Next->RecalculatePositions(1,llist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_StyleInfo = llist->GetDefaultStyleInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLayoutLine::~wxLayoutLine()
|
wxLayoutLine::~wxLayoutLine()
|
||||||
@@ -1131,12 +1133,18 @@ wxLayoutLine::Layout(wxDC &dc,
|
|||||||
else
|
else
|
||||||
str = WXLO_CURSORCHAR;
|
str = WXLO_CURSORCHAR;
|
||||||
dc.GetTextExtent(str, &width, &height, &descent);
|
dc.GetTextExtent(str, &width, &height, &descent);
|
||||||
wxASSERT(cursorSize);
|
|
||||||
// Just in case some joker inserted an empty string object:
|
if ( cursorSize )
|
||||||
if(width == 0) width = WXLO_MINIMUM_CURSOR_WIDTH;
|
{
|
||||||
if(height == 0) height = sizeObj.y;
|
// Just in case some joker inserted an empty string object:
|
||||||
cursorSize->x = width;
|
if(width == 0)
|
||||||
cursorSize->y = height;
|
width = WXLO_MINIMUM_CURSOR_WIDTH;
|
||||||
|
if(height == 0)
|
||||||
|
height = sizeObj.y;
|
||||||
|
cursorSize->x = width;
|
||||||
|
cursorSize->y = height;
|
||||||
|
}
|
||||||
|
|
||||||
cursorFound = true; // no more checks
|
cursorFound = true; // no more checks
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1206,7 +1214,7 @@ wxLayoutLine::Layout(wxDC &dc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We need to check whether we found a valid cursor size:
|
// We need to check whether we found a valid cursor size:
|
||||||
if(cursorPos)
|
if(cursorPos && cursorSize)
|
||||||
{
|
{
|
||||||
// this might be the case if the cursor is at the end of the
|
// this might be the case if the cursor is at the end of the
|
||||||
// line or on a command object:
|
// line or on a command object:
|
||||||
@@ -1755,7 +1763,7 @@ wxLayoutList::MoveCursorHorizontally(int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxLayoutList::MoveCursorWord(int n)
|
wxLayoutList::MoveCursorWord(int n, bool untilNext)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( m_CursorLine, false, "no current line" );
|
wxCHECK_MSG( m_CursorLine, false, "no current line" );
|
||||||
wxCHECK_MSG( n == -1 || n == +1, false, "not implemented yet" );
|
wxCHECK_MSG( n == -1 || n == +1, false, "not implemented yet" );
|
||||||
@@ -1805,25 +1813,41 @@ wxLayoutList::MoveCursorWord(int n)
|
|||||||
|
|
||||||
if ( canAdvance )
|
if ( canAdvance )
|
||||||
{
|
{
|
||||||
const char *start = tobj->GetText().c_str();
|
const wxString& text = tobj->GetText();
|
||||||
|
const char *start = text.c_str();
|
||||||
|
const char *end = start + text.length();
|
||||||
const char *p = start + offset;
|
const char *p = start + offset;
|
||||||
|
|
||||||
|
if ( n < 0 )
|
||||||
|
{
|
||||||
|
if ( offset > 0 )
|
||||||
|
p--;
|
||||||
|
}
|
||||||
|
|
||||||
// to the beginning/end of the next/prev word
|
// to the beginning/end of the next/prev word
|
||||||
while ( isspace(*p) )
|
while ( p >= start && p < end && isspace(*p) )
|
||||||
{
|
{
|
||||||
n > 0 ? p++ : p--;
|
n > 0 ? p++ : p--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// go to the end/beginning of the word (in a broad sense...)
|
// go to the end/beginning of the word (in a broad sense...)
|
||||||
while ( p >= start && !isspace(*p) )
|
while ( p >= start && p < end && !isspace(*p) )
|
||||||
{
|
{
|
||||||
n > 0 ? p++ : p--;
|
n > 0 ? p++ : p--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( n > 0 )
|
if ( n > 0 )
|
||||||
{
|
{
|
||||||
// now advance to the beginning of the next word
|
if ( untilNext )
|
||||||
while ( isspace(*p) )
|
{
|
||||||
|
// now advance to the beginning of the next word
|
||||||
|
while ( isspace(*p) && p < end )
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // backwards
|
||||||
|
{
|
||||||
|
if ( isspace(*p) )
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2185,6 +2209,23 @@ wxLayoutList::Draw(wxDC &dc,
|
|||||||
{
|
{
|
||||||
wxLayoutLine *line = m_FirstLine;
|
wxLayoutLine *line = m_FirstLine;
|
||||||
|
|
||||||
|
if ( m_Selection.m_discarded )
|
||||||
|
{
|
||||||
|
// calculate them if we don't have them already
|
||||||
|
if ( !m_Selection.HasValidScreenCoords() )
|
||||||
|
{
|
||||||
|
m_Selection.m_ScreenA = GetScreenPos(dc, m_Selection.m_CursorA);
|
||||||
|
m_Selection.m_ScreenB = GetScreenPos(dc, m_Selection.m_CursorB);
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalidate the area which was previousle selected - and which is not
|
||||||
|
// selected any more
|
||||||
|
SetUpdateRect(m_Selection.m_ScreenA);
|
||||||
|
SetUpdateRect(m_Selection.m_ScreenB);
|
||||||
|
|
||||||
|
m_Selection.m_discarded = false;
|
||||||
|
}
|
||||||
|
|
||||||
/* We need to re-layout all dirty lines to update styleinfos
|
/* We need to re-layout all dirty lines to update styleinfos
|
||||||
etc. However, somehow we don't find all dirty lines... */
|
etc. However, somehow we don't find all dirty lines... */
|
||||||
Layout(dc); //,-1,true); //FIXME
|
Layout(dc); //,-1,true); //FIXME
|
||||||
@@ -2438,28 +2479,17 @@ wxLayoutList::DiscardSelection()
|
|||||||
|
|
||||||
m_Selection.m_valid =
|
m_Selection.m_valid =
|
||||||
m_Selection.m_selecting = false;
|
m_Selection.m_selecting = false;
|
||||||
|
m_Selection.m_discarded = true;
|
||||||
// invalidate the area which was previousle selected - and which is not
|
|
||||||
// selected any more
|
|
||||||
if ( m_Selection.HasValidScreenCoords() )
|
|
||||||
{
|
|
||||||
SetUpdateRect(m_Selection.m_ScreenA);
|
|
||||||
SetUpdateRect(m_Selection.m_ScreenB);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxLayoutList::IsSelecting(void)
|
wxLayoutList::IsSelecting(void) const
|
||||||
{
|
{
|
||||||
return m_Selection.m_selecting;
|
return m_Selection.m_selecting;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxLayoutList::IsSelected(const wxPoint &cursor)
|
wxLayoutList::IsSelected(const wxPoint &cursor) const
|
||||||
{
|
{
|
||||||
if ( !HasSelection() )
|
if ( !HasSelection() )
|
||||||
return false;
|
return false;
|
||||||
|
@@ -324,11 +324,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
struct wxLayoutStyleInfo
|
struct wxLayoutStyleInfo
|
||||||
{
|
{
|
||||||
wxLayoutStyleInfo(int ifamily = wxDEFAULT,
|
wxLayoutStyleInfo(int ifamily = -1,
|
||||||
int isize = WXLO_DEFAULTFONTSIZE,
|
int isize = -1,
|
||||||
int istyle = wxNORMAL,
|
int istyle = -1,
|
||||||
int iweight = wxNORMAL,
|
int iweight = -1,
|
||||||
int iul = FALSE,
|
int iul = -1,
|
||||||
wxColour *fg = NULL,
|
wxColour *fg = NULL,
|
||||||
wxColour *bg = NULL);
|
wxColour *bg = NULL);
|
||||||
wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
|
wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
|
||||||
@@ -783,9 +783,11 @@ public:
|
|||||||
bool MoveCursorHorizontally(int n);
|
bool MoveCursorHorizontally(int n);
|
||||||
/** Move cursor to the left or right counting in words
|
/** Move cursor to the left or right counting in words
|
||||||
@param n = number of positions in words
|
@param n = number of positions in words
|
||||||
|
@param untilNext: puts the cursor at the start of the next word if true,
|
||||||
|
leaves it at the end of the current one otherwise
|
||||||
@return bool if it could be moved
|
@return bool if it could be moved
|
||||||
*/
|
*/
|
||||||
bool MoveCursorWord(int n);
|
bool MoveCursorWord(int n, bool untilNext = true);
|
||||||
|
|
||||||
/// Move cursor to end of line.
|
/// Move cursor to end of line.
|
||||||
void MoveCursorToEndOfLine(void)
|
void MoveCursorToEndOfLine(void)
|
||||||
@@ -1070,9 +1072,9 @@ public:
|
|||||||
/// Discard the current selection
|
/// Discard the current selection
|
||||||
void DiscardSelection();
|
void DiscardSelection();
|
||||||
/// Are we still selecting text?
|
/// Are we still selecting text?
|
||||||
bool IsSelecting(void);
|
bool IsSelecting(void) const;
|
||||||
/// Is the given point (text coords) selected?
|
/// Is the given point (text coords) selected?
|
||||||
bool IsSelected(const wxPoint &cursor);
|
bool IsSelected(const wxPoint &cursor) const;
|
||||||
/// Do we have a non null selection?
|
/// Do we have a non null selection?
|
||||||
bool HasSelection() const
|
bool HasSelection() const
|
||||||
{ return m_Selection.m_valid || m_Selection.m_selecting; }
|
{ return m_Selection.m_valid || m_Selection.m_selecting; }
|
||||||
@@ -1140,9 +1142,11 @@ private:
|
|||||||
/// selection.state and begin/end coordinates
|
/// selection.state and begin/end coordinates
|
||||||
struct Selection
|
struct Selection
|
||||||
{
|
{
|
||||||
Selection() { m_valid = false; m_selecting = false; }
|
Selection() { m_valid = m_selecting = m_discarded = false; }
|
||||||
|
|
||||||
bool m_valid;
|
bool m_valid;
|
||||||
bool m_selecting;
|
bool m_selecting;
|
||||||
|
bool m_discarded; // may be TRUE only until the next redraw
|
||||||
|
|
||||||
// returns true if we already have the screen coordinates of the
|
// returns true if we already have the screen coordinates of the
|
||||||
// selection start and end
|
// selection start and end
|
||||||
|
@@ -6,9 +6,9 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
*******************************************************************/
|
*******************************************************************/
|
||||||
|
|
||||||
// ===========================================================================
|
// ============================================================================
|
||||||
// declarations
|
// declarations
|
||||||
// ===========================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// headers
|
// headers
|
||||||
@@ -89,7 +89,8 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
|||||||
EVT_CHAR (wxLayoutWindow::OnChar)
|
EVT_CHAR (wxLayoutWindow::OnChar)
|
||||||
EVT_KEY_UP (wxLayoutWindow::OnKeyUp)
|
EVT_KEY_UP (wxLayoutWindow::OnKeyUp)
|
||||||
|
|
||||||
EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick)
|
EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown)
|
||||||
|
EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp)
|
||||||
EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick)
|
EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick)
|
||||||
EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick)
|
EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick)
|
||||||
EVT_MOTION (wxLayoutWindow::OnMouseMove)
|
EVT_MOTION (wxLayoutWindow::OnMouseMove)
|
||||||
@@ -103,9 +104,16 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
|||||||
EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus)
|
EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// ===========================================================================
|
// ----------------------------------------------------------------------------
|
||||||
|
// function prototypes
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
|
||||||
|
static bool IsDirectionKey(long keyCode);
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ===========================================================================
|
// ============================================================================
|
||||||
|
|
||||||
/* LEAVE IT HERE UNTIL WXGTK WORKS AGAIN!!! */
|
/* LEAVE IT HERE UNTIL WXGTK WORKS AGAIN!!! */
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
@@ -212,8 +220,10 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
|||||||
findPos.x -= WXLO_XOFFSET;
|
findPos.x -= WXLO_XOFFSET;
|
||||||
findPos.y -= WXLO_YOFFSET;
|
findPos.y -= WXLO_YOFFSET;
|
||||||
|
|
||||||
if(findPos.x < 0) findPos.x = 0;
|
if(findPos.x < 0)
|
||||||
if(findPos.y < 0) findPos.y = 0;
|
findPos.x = 0;
|
||||||
|
if(findPos.y < 0)
|
||||||
|
findPos.y = 0;
|
||||||
|
|
||||||
m_ClickPosition = wxPoint(event.GetX(), event.GetY());
|
m_ClickPosition = wxPoint(event.GetX(), event.GetY());
|
||||||
|
|
||||||
@@ -223,98 +233,116 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
|||||||
&cursorPos, &found);
|
&cursorPos, &found);
|
||||||
wxLayoutObject::UserData *u = obj ? obj->GetUserData() : NULL;
|
wxLayoutObject::UserData *u = obj ? obj->GetUserData() : NULL;
|
||||||
|
|
||||||
//has the mouse only been moved?
|
// has the mouse only been moved?
|
||||||
if(eventId == WXLOWIN_MENU_MOUSEMOVE)
|
switch ( eventId )
|
||||||
{
|
{
|
||||||
// found is only true if we are really over an object, not just
|
case WXLOWIN_MENU_MOUSEMOVE:
|
||||||
// behind it
|
// found is only true if we are really over an object, not just
|
||||||
if(found && u && ! m_Selecting)
|
// behind it
|
||||||
{
|
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(!m_HandCursor)
|
||||||
if(label.Length())
|
SetCursor(wxCURSOR_HAND);
|
||||||
m_StatusBar->SetStatusText(label,
|
m_HandCursor = TRUE;
|
||||||
m_StatusFieldLabel);
|
if(m_StatusBar && m_StatusFieldLabel != -1)
|
||||||
}
|
{
|
||||||
}
|
const wxString &label = u->GetLabel();
|
||||||
else
|
if(label.Length())
|
||||||
{
|
m_StatusBar->SetStatusText(label,
|
||||||
if(m_HandCursor)
|
m_StatusFieldLabel);
|
||||||
SetCursor(wxCURSOR_IBEAM);
|
}
|
||||||
m_HandCursor = FALSE;
|
|
||||||
if(m_StatusBar && m_StatusFieldLabel != -1)
|
|
||||||
m_StatusBar->SetStatusText("", m_StatusFieldLabel);
|
|
||||||
}
|
|
||||||
if(event.LeftIsDown())
|
|
||||||
{
|
|
||||||
if(! m_Selecting)
|
|
||||||
{
|
|
||||||
m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition);
|
|
||||||
m_Selecting = true;
|
|
||||||
DoPaint(); // TODO: we don't have to redraw everything!
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(m_HandCursor)
|
||||||
|
SetCursor(wxCURSOR_IBEAM);
|
||||||
|
m_HandCursor = FALSE;
|
||||||
|
if(m_StatusBar && m_StatusFieldLabel != -1)
|
||||||
|
m_StatusBar->SetStatusText("", m_StatusFieldLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// selecting?
|
||||||
|
if ( event.LeftIsDown() )
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( m_Selecting, "should be set in OnMouseLeftDown" );
|
||||||
|
|
||||||
m_llist->ContinueSelection(cursorPos, m_ClickPosition);
|
m_llist->ContinueSelection(cursorPos, m_ClickPosition);
|
||||||
DoPaint(); // TODO: we don't have to redraw everything!
|
DoPaint(); // TODO: we don't have to redraw everything!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(m_Selecting && ! event.LeftIsDown())
|
|
||||||
{
|
|
||||||
m_llist->EndSelection(cursorPos, m_ClickPosition);
|
|
||||||
m_Selecting = false;
|
|
||||||
DoPaint(); // TODO: we don't have to redraw everything!
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( u )
|
if ( u )
|
||||||
{
|
{
|
||||||
u->DecRef();
|
u->DecRef();
|
||||||
u = NULL;
|
u = NULL;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if(eventId == WXLOWIN_MENU_LCLICK)
|
|
||||||
{
|
|
||||||
// always move cursor to mouse click:
|
|
||||||
m_llist->MoveCursorTo(cursorPos);
|
|
||||||
|
|
||||||
// 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);
|
||||||
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);
|
DoPaint(); // TODO: we don't have to redraw everything!
|
||||||
x0 *= dx; y0 *= dy;
|
}
|
||||||
|
|
||||||
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 != 0)
|
if(m_CursorVisibility == -1)
|
||||||
{
|
m_CursorVisibility = 1;
|
||||||
// draw a thick cursor for editable windows with focus
|
|
||||||
m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// VZ: this should be unnecessary because mouse can only click on a
|
if(m_CursorVisibility != 0)
|
||||||
// visible part of the canvas
|
{
|
||||||
|
// draw a thick cursor for editable windows with focus
|
||||||
|
m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// VZ: this should be unnecessary because mouse can only click on a
|
||||||
|
// visible part of the canvas
|
||||||
#if 0
|
#if 0
|
||||||
ScrollToCursor();
|
ScrollToCursor();
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
DoPaint(); // DoPaint suppresses flicker under GTK
|
DoPaint(); // DoPaint suppresses flicker under GTK
|
||||||
#endif // wxGTK
|
#endif // wxGTK
|
||||||
|
|
||||||
|
// start selection
|
||||||
|
m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition);
|
||||||
|
m_Selecting = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WXLOWIN_MENU_LUP:
|
||||||
|
if ( m_Selecting )
|
||||||
|
{
|
||||||
|
m_llist->EndSelection();
|
||||||
|
m_Selecting = false;
|
||||||
|
|
||||||
|
DoPaint(); // TODO: we don't have to redraw everything!
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
|
||||||
|
DoPaint(); // TODO: we don't have to redraw everything!
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify about mouse events?
|
// notify about mouse events?
|
||||||
@@ -344,9 +372,10 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
|||||||
u->DecRef();
|
u->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// ----------------------------------------------------------------------------
|
||||||
* Some simple keyboard handling.
|
// keyboard handling.
|
||||||
*/
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
wxLayoutWindow::OnChar(wxKeyEvent& event)
|
wxLayoutWindow::OnChar(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
@@ -360,24 +389,32 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(! m_Selecting && event.ShiftDown())
|
wxASSERT_MSG( !m_Selecting || event.ShiftDown(),
|
||||||
|
"m_Selecting is normally reset in OnKeyUp() when Shift "
|
||||||
|
"goes up!" );
|
||||||
|
|
||||||
|
if ( !m_Selecting && m_llist->HasSelection() )
|
||||||
{
|
{
|
||||||
switch(keyCode)
|
// pressing any non-arrow key replaces the selection
|
||||||
|
if ( !IsDirectionKey(keyCode) )
|
||||||
|
{
|
||||||
|
m_llist->DeleteSelection();
|
||||||
|
}
|
||||||
|
else if ( !event.ShiftDown() )
|
||||||
|
{
|
||||||
|
m_llist->DiscardSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// <Shift>+<arrow> starts selection
|
||||||
|
if ( event.ShiftDown() && IsDirectionKey(keyCode) )
|
||||||
|
{
|
||||||
|
if ( !m_Selecting )
|
||||||
{
|
{
|
||||||
case WXK_UP:
|
|
||||||
case WXK_DOWN:
|
|
||||||
case WXK_RIGHT:
|
|
||||||
case WXK_LEFT:
|
|
||||||
case WXK_PRIOR:
|
|
||||||
case WXK_NEXT:
|
|
||||||
case WXK_HOME:
|
|
||||||
case WXK_END:
|
|
||||||
m_Selecting = true;
|
m_Selecting = true;
|
||||||
m_llist->StartSelection();
|
m_llist->StartSelection();
|
||||||
break;
|
|
||||||
default:
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
//else: just continue the old selection
|
||||||
}
|
}
|
||||||
|
|
||||||
// If needed, make cursor visible:
|
// If needed, make cursor visible:
|
||||||
@@ -505,7 +542,8 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
|||||||
m_llist->Delete(1);
|
m_llist->Delete(1);
|
||||||
break;
|
break;
|
||||||
case WXK_BACK: // backspace
|
case WXK_BACK: // backspace
|
||||||
if(m_llist->MoveCursorHorizontally(-1)) m_llist->Delete(1);
|
if(m_llist->MoveCursorHorizontally(-1))
|
||||||
|
m_llist->Delete(1);
|
||||||
break;
|
break;
|
||||||
case WXK_RETURN:
|
case WXK_RETURN:
|
||||||
if(m_WrapMargin > 0)
|
if(m_WrapMargin > 0)
|
||||||
@@ -528,15 +566,11 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
|||||||
SetModified();
|
SetModified();
|
||||||
}// if(IsEditable())
|
}// if(IsEditable())
|
||||||
}// first switch()
|
}// first switch()
|
||||||
if(m_Selecting)
|
|
||||||
|
if ( m_Selecting )
|
||||||
{
|
{
|
||||||
if(event.ShiftDown())
|
// continue selection to the current (new) cursor position
|
||||||
m_llist->ContinueSelection();
|
m_llist->ContinueSelection();
|
||||||
else
|
|
||||||
{
|
|
||||||
m_llist->EndSelection();
|
|
||||||
m_Selecting = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
|
// we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
|
||||||
@@ -551,11 +585,12 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
|||||||
void
|
void
|
||||||
wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
|
wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
if(event.KeyCode() == WXK_SHIFT && m_llist->IsSelecting())
|
if ( event.KeyCode() == WXK_SHIFT && m_Selecting )
|
||||||
{
|
{
|
||||||
m_llist->EndSelection();
|
m_llist->EndSelection();
|
||||||
m_Selecting = false;
|
m_Selecting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,6 +857,10 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// clipboard operations
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
wxLayoutWindow::Paste(void)
|
wxLayoutWindow::Paste(void)
|
||||||
{
|
{
|
||||||
@@ -926,6 +965,11 @@ wxLayoutWindow::Cut(void)
|
|||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// searching
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxLayoutWindow::Find(const wxString &needle,
|
wxLayoutWindow::Find(const wxString &needle,
|
||||||
wxPoint * fromWhere)
|
wxPoint * fromWhere)
|
||||||
@@ -950,6 +994,10 @@ wxLayoutWindow::Find(const wxString &needle,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// popup menu stuff
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxMenu *
|
wxMenu *
|
||||||
wxLayoutWindow::MakeFormatMenu()
|
wxLayoutWindow::MakeFormatMenu()
|
||||||
{
|
{
|
||||||
@@ -1014,6 +1062,10 @@ void wxLayoutWindow::OnMenu(wxCommandEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// focus
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
|
wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
|
||||||
{
|
{
|
||||||
@@ -1027,3 +1079,26 @@ wxLayoutWindow::OnKillFocus(wxFocusEvent &ev)
|
|||||||
m_HaveFocus = false;
|
m_HaveFocus = false;
|
||||||
ev.Skip();
|
ev.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// private functions
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static bool IsDirectionKey(long keyCode)
|
||||||
|
{
|
||||||
|
switch(keyCode)
|
||||||
|
{
|
||||||
|
case WXK_UP:
|
||||||
|
case WXK_DOWN:
|
||||||
|
case WXK_RIGHT:
|
||||||
|
case WXK_LEFT:
|
||||||
|
case WXK_PRIOR:
|
||||||
|
case WXK_NEXT:
|
||||||
|
case WXK_HOME:
|
||||||
|
case WXK_END:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -36,8 +36,9 @@ enum
|
|||||||
WXLOWIN_MENU_TYPEWRITER,
|
WXLOWIN_MENU_TYPEWRITER,
|
||||||
WXLOWIN_MENU_SANSSERIF,
|
WXLOWIN_MENU_SANSSERIF,
|
||||||
WXLOWIN_MENU_RCLICK,
|
WXLOWIN_MENU_RCLICK,
|
||||||
WXLOWIN_MENU_LCLICK,
|
|
||||||
WXLOWIN_MENU_DBLCLICK,
|
WXLOWIN_MENU_DBLCLICK,
|
||||||
|
WXLOWIN_MENU_LDOWN,
|
||||||
|
WXLOWIN_MENU_LUP,
|
||||||
WXLOWIN_MENU_MOUSEMOVE,
|
WXLOWIN_MENU_MOUSEMOVE,
|
||||||
WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
|
WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
|
||||||
};
|
};
|
||||||
@@ -133,7 +134,8 @@ public:
|
|||||||
void OnUpdateMenuBold(wxUpdateUIEvent& event);
|
void OnUpdateMenuBold(wxUpdateUIEvent& event);
|
||||||
void OnUpdateMenuItalic(wxUpdateUIEvent& event);
|
void OnUpdateMenuItalic(wxUpdateUIEvent& event);
|
||||||
void OnMenu(wxCommandEvent& event);
|
void OnMenu(wxCommandEvent& event);
|
||||||
void OnLeftMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LCLICK, event); }
|
void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
|
||||||
|
void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
|
||||||
void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
|
void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
|
||||||
void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
|
void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
|
||||||
void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
|
void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
|
||||||
|
Reference in New Issue
Block a user