Merged in from Mahogany. A bit better and safer.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2497 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-05-18 15:05:29 +00:00
parent fac2987b2f
commit 974a5cccc1
5 changed files with 74 additions and 12 deletions

View File

@@ -18,10 +18,13 @@ TODO
- UNDO!! - UNDO!!
- replacement of llist in window - replacement of llist in window
- selection highlighting is a bit broken
Improve speed! (See layout problem below!)
The following two probs can probably be fixed by adding the The following two probs can probably be fixed by adding the
RecalculateLayout() method: RecalculateLayout() method:
Funny re-layout shows again in sample text. Funny re-layout shows again in sample text.
(Gone after calling layout for all objects before drawing one.)
Printing works again, but layout at begin of new page is corrupted. Printing works again, but layout at begin of new page is corrupted.

View File

@@ -598,6 +598,11 @@ wxLayoutLine::RecalculatePosition(wxLayoutList *llist)
void void
wxLayoutLine::RecalculatePositions(int recurse, wxLayoutList *llist) 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.
return;
wxASSERT(recurse >= 0); wxASSERT(recurse >= 0);
wxPoint pos = m_Position; wxPoint pos = m_Position;
CoordType height = m_Height; CoordType height = m_Height;
@@ -1243,6 +1248,7 @@ wxLayoutLine::Copy(wxLayoutList *llist,
CoordType firstOffset, lastOffset; CoordType firstOffset, lastOffset;
if(to == -1) to = GetLength(); if(to == -1) to = GetLength();
if(from == to) return;
wxLOiterator first = FindObject(from, &firstOffset); wxLOiterator first = FindObject(from, &firstOffset);
wxLOiterator last = FindObject(to, &lastOffset); wxLOiterator last = FindObject(to, &lastOffset);
@@ -1562,6 +1568,7 @@ bool
wxLayoutList::Insert(wxLayoutObject *obj) wxLayoutList::Insert(wxLayoutObject *obj)
{ {
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
if(! m_CursorLine) m_CursorLine = GetFirstLine();
SetUpdateRect(m_CursorScreenPos); SetUpdateRect(m_CursorScreenPos);
SetUpdateRect(m_CursorScreenPos+m_CursorSize); SetUpdateRect(m_CursorScreenPos+m_CursorSize);
m_CursorLine->Insert(m_CursorPos.x, obj); m_CursorLine->Insert(m_CursorPos.x, obj);

View File

@@ -99,10 +99,13 @@ public:
struct UserData struct UserData
{ {
UserData() { m_refcount = 1; } UserData() { m_refcount = 1; }
void IncRef(void) { m_refcount++; } inline void IncRef(void) { m_refcount++; }
void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;} inline void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;}
inline void SetLabel(const wxString &l) { m_label = l; }
inline const wxString & GetLabel(void) const { return m_label; }
private: private:
int m_refcount; int m_refcount;
wxString m_label;
protected: protected:
virtual ~UserData() { wxASSERT(m_refcount == 0); } virtual ~UserData() { wxASSERT(m_refcount == 0); }
/// prevents gcc from generating stupid warnings /// prevents gcc from generating stupid warnings
@@ -161,6 +164,7 @@ public:
/** Tells the object about some user data. This data is associated /** Tells the object about some user data. This data is associated
with the object and will be deleted at destruction time. with the object and will be deleted at destruction time.
It is reference counted.
*/ */
void SetUserData(UserData *data) void SetUserData(UserData *data)
{ {
@@ -171,8 +175,11 @@ public:
m_UserData->IncRef(); m_UserData->IncRef();
} }
/** Return the user data. */ /** Return the user data.
void * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; } Increments the object's reference count. When no longer needed,
caller must call DecRef() on the pointer returned.
*/
UserData * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
/** Makes a copy of this object. /** Makes a copy of this object.
*/ */
@@ -745,8 +752,8 @@ public:
{ MoveCursorHorizontally(-m_CursorPos.x); } { MoveCursorHorizontally(-m_CursorPos.x); }
/// Returns current cursor position. /// Returns current cursor position.
wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; } const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
wxPoint GetCursorPos() const { return m_CursorPos; } const wxPoint &GetCursorPos() const { return m_CursorPos; }
//@} //@}

View File

@@ -75,6 +75,7 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
wxHSCROLL | wxVSCROLL | wxBORDER) wxHSCROLL | wxVSCROLL | wxBORDER)
{ {
SetStatusBar(NULL); // don't use statusbar
m_Editable = false; m_Editable = false;
m_doSendEvents = false; m_doSendEvents = false;
m_ViewStartX = 0; m_ViewStartY = 0; m_ViewStartX = 0; m_ViewStartY = 0;
@@ -160,23 +161,33 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
bool found; bool found;
wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos, wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos,
&cursorPos, &found); &cursorPos, &found);
wxLayoutObject::UserData *u = obj ? obj->GetUserData() : NULL;
//has the mouse only been moved? //has the mouse only been moved?
if(eventId == WXLOWIN_MENU_MOUSEMOVE) if(eventId == WXLOWIN_MENU_MOUSEMOVE)
{ {
// 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 && obj && obj->GetUserData() != NULL) if(found && u)
{ {
if(!m_HandCursor) if(!m_HandCursor)
SetCursor(wxCURSOR_HAND); SetCursor(wxCURSOR_HAND);
m_HandCursor = TRUE; m_HandCursor = TRUE;
if(m_StatusBar && m_StatusFieldLabel != -1)
{
const wxString &label = u->GetLabel();
if(label.Length())
m_StatusBar->SetStatusText(label,
m_StatusFieldLabel);
}
} }
else else
{ {
if(m_HandCursor) if(m_HandCursor)
SetCursor(wxCURSOR_IBEAM); SetCursor(wxCURSOR_IBEAM);
m_HandCursor = FALSE; m_HandCursor = FALSE;
if(m_StatusBar && m_StatusFieldLabel != -1)
m_StatusBar->SetStatusText("", m_StatusFieldLabel);
} }
if(event.LeftIsDown()) if(event.LeftIsDown())
{ {
@@ -198,6 +209,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
m_Selecting = false; m_Selecting = false;
DoPaint(FALSE); DoPaint(FALSE);
} }
if(u) u->DecRef();
return; return;
} }
@@ -210,18 +222,24 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
ScrollToCursor(); ScrollToCursor();
DoPaint(FALSE); // DoPaint suppresses flicker under GTK DoPaint(FALSE); // DoPaint suppresses flicker under GTK
} }
if(!m_doSendEvents) // nothing to do if(!m_doSendEvents) // nothing to do
{
if(u) u->DecRef();
return; return;
}
// only do the menu if activated, editable and not on a clickable object // only do the menu if activated, editable and not on a clickable object
if(eventId == WXLOWIN_MENU_RCLICK if(eventId == WXLOWIN_MENU_RCLICK
&& IsEditable() && IsEditable()
&& (! obj || (obj && obj->GetUserData() == NULL)) && (! obj || u == NULL))
)
{ {
PopupMenu(m_PopupMenu, m_ClickPosition.x, m_ClickPosition.y); PopupMenu(m_PopupMenu, m_ClickPosition.x, m_ClickPosition.y);
if(u) u->DecRef();
return; return;
} }
if(u) u->DecRef();
// find the object at this position // find the object at this position
if(obj) if(obj)
{ {
@@ -412,7 +430,10 @@ void
wxLayoutWindow::OnKeyUp(wxKeyEvent& event) wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
{ {
if(event.KeyCode() == WXK_SHIFT && m_llist->IsSelecting()) if(event.KeyCode() == WXK_SHIFT && m_llist->IsSelecting())
{
m_llist->EndSelection(); m_llist->EndSelection();
m_Selecting = false;
}
event.Skip(); event.Skip();
} }
@@ -605,6 +626,12 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
ResetDirty(); ResetDirty();
m_ScrollToCursor = false; m_ScrollToCursor = false;
if(m_StatusBar && m_StatusFieldCursor != -1)
{
wxString label;
label.Printf(_("L:%d C:%d"), m_llist->GetCursorPos().x+1, m_llist->GetCursorPos().y+1);
m_StatusBar->SetStatusText(label, m_StatusFieldCursor);
}
} }
// change the range and position of scrollbars // change the range and position of scrollbars

View File

@@ -163,7 +163,19 @@ public:
bool IsModified(void) const { return m_Modified; } bool IsModified(void) const { return m_Modified; }
/// Mark list as modified or unchanged. /// Mark list as modified or unchanged.
void SetModified(bool modified = true) { m_Modified = modified; } void SetModified(bool modified = true) { m_Modified = modified; }
/** Tell window to update a wxStatusBar with UserData labels and
cursor positions.
@param bar wxStatusBar pointer
@param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
@param cursorfield field to use for cursor position, or -1 to disable
*/
inline SetStatusBar(class wxStatusBar *bar,
int labelfield = -1,
int cursorfield = -1)
{
m_StatusBar = bar; m_StatusFieldLabel = labelfield;
m_StatusFieldCursor = cursorfield;
}
protected: protected:
/// generic function for mouse events processing /// generic function for mouse events processing
void OnMouse(int eventId, wxMouseEvent& event); void OnMouse(int eventId, wxMouseEvent& event);
@@ -211,6 +223,12 @@ private:
wxMemoryDC *m_memDC; wxMemoryDC *m_memDC;
wxBitmap *m_bitmap; wxBitmap *m_bitmap;
wxPoint m_bitmapSize; wxPoint m_bitmapSize;
/// A frame's statusbar to update
class wxStatusBar *m_StatusBar;
/// statusbar field for labels
int m_StatusFieldLabel;
/// statusbar field for cursor positions
int m_StatusFieldCursor;
/// a pointer to a bitmap for the background /// a pointer to a bitmap for the background
wxBitmap *m_BGbitmap; wxBitmap *m_BGbitmap;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()