1999-06-07 09:57:14 +00:00
|
|
|
|
/*-*- c++ -*-********************************************************
|
|
|
|
|
* wxLwindow.h : a scrolled Window for displaying/entering rich text*
|
|
|
|
|
* *
|
1999-10-10 16:52:34 +00:00
|
|
|
|
* (C) 1998-1999 by Karsten Ball<EFBFBD>der (karsten@phy.hw.ac.uk) *
|
1999-06-07 09:57:14 +00:00
|
|
|
|
* *
|
|
|
|
|
* $Id$
|
|
|
|
|
*******************************************************************/
|
|
|
|
|
#ifndef WXLWINDOW_H
|
|
|
|
|
#define WXLWINDOW_H
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
# pragma interface "wxlwindow.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef USE_PCH
|
|
|
|
|
# include <wx/wx.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "wxllist.h"
|
|
|
|
|
|
|
|
|
|
#ifndef WXLOWIN_MENU_FIRST
|
|
|
|
|
# define WXLOWIN_MENU_FIRST 12000
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST,
|
|
|
|
|
WXLOWIN_MENU_SMALLER,
|
1999-06-09 11:36:45 +00:00
|
|
|
|
WXLOWIN_MENU_UNDERLINE,
|
|
|
|
|
WXLOWIN_MENU_BOLD,
|
|
|
|
|
WXLOWIN_MENU_ITALICS,
|
1999-06-07 09:57:14 +00:00
|
|
|
|
WXLOWIN_MENU_ROMAN,
|
|
|
|
|
WXLOWIN_MENU_TYPEWRITER,
|
|
|
|
|
WXLOWIN_MENU_SANSSERIF,
|
|
|
|
|
WXLOWIN_MENU_RCLICK,
|
|
|
|
|
WXLOWIN_MENU_DBLCLICK,
|
1999-06-10 17:22:02 +00:00
|
|
|
|
WXLOWIN_MENU_MDOWN,
|
1999-06-09 16:22:24 +00:00
|
|
|
|
WXLOWIN_MENU_LDOWN,
|
1999-06-17 21:40:49 +00:00
|
|
|
|
WXLOWIN_MENU_LCLICK = WXLOWIN_MENU_LDOWN,
|
1999-06-09 16:22:24 +00:00
|
|
|
|
WXLOWIN_MENU_LUP,
|
1999-06-07 09:57:14 +00:00
|
|
|
|
WXLOWIN_MENU_MOUSEMOVE,
|
|
|
|
|
WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
This class is a rich text editing widget.
|
|
|
|
|
*/
|
|
|
|
|
class wxLayoutWindow : public wxScrolledWindow
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** Constructor.
|
|
|
|
|
@param parent parent window to display this panel in
|
|
|
|
|
*/
|
|
|
|
|
wxLayoutWindow(wxWindow *parent);
|
|
|
|
|
|
|
|
|
|
/// Destructor.
|
|
|
|
|
virtual ~wxLayoutWindow();
|
|
|
|
|
|
|
|
|
|
/**@name Editing functionality */
|
|
|
|
|
//@{
|
|
|
|
|
/// Clears the window and sets default parameters.
|
|
|
|
|
void Clear(int family = wxROMAN,
|
|
|
|
|
int size=12,
|
|
|
|
|
int style=wxNORMAL,
|
|
|
|
|
int weight=wxNORMAL,
|
|
|
|
|
int underline=0,
|
|
|
|
|
wxColour *fg=NULL,
|
|
|
|
|
wxColour *bg=NULL);
|
1999-06-11 11:14:47 +00:00
|
|
|
|
|
|
|
|
|
/// override base class virtual to also refresh the scrollbar position
|
|
|
|
|
virtual void Refresh(bool eraseBackground = TRUE,
|
|
|
|
|
const wxRect *rect = (const wxRect *)NULL);
|
|
|
|
|
|
1999-06-07 09:57:14 +00:00
|
|
|
|
/** Sets a background image, only used on screen, not on printouts.
|
|
|
|
|
@param bitmap a pointer to a wxBitmap or NULL to remove it
|
|
|
|
|
*/
|
|
|
|
|
void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
|
|
|
|
|
{
|
|
|
|
|
if(m_BGbitmap) delete m_BGbitmap;
|
|
|
|
|
m_BGbitmap = bitmap;
|
|
|
|
|
}
|
|
|
|
|
/// Enable or disable editing, i.e. processing of keystrokes.
|
1999-06-17 21:40:49 +00:00
|
|
|
|
void SetEditable(bool toggle)
|
|
|
|
|
{ m_Editable = toggle; SetCursorVisibility(toggle); }
|
1999-06-07 09:57:14 +00:00
|
|
|
|
/// Query whether list can be edited by user.
|
|
|
|
|
bool IsEditable(void) const { return m_Editable; }
|
|
|
|
|
/** Sets cursor visibility, visible=1, invisible=0,
|
|
|
|
|
visible-on-demand=-1, to hide it until moved.
|
|
|
|
|
@param visibility -1,0 or 1
|
|
|
|
|
@return the old visibility
|
|
|
|
|
*/
|
|
|
|
|
inline int SetCursorVisibility(int visibility = -1)
|
|
|
|
|
{ int v =m_CursorVisibility;
|
|
|
|
|
m_CursorVisibility = visibility; return v;}
|
|
|
|
|
|
|
|
|
|
/// Pastes text from clipboard.
|
1999-06-10 17:22:02 +00:00
|
|
|
|
void Paste(bool usePrimarySelection = FALSE);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
/** Copies selection to clipboard.
|
|
|
|
|
@param invalidate used internally, see wxllist.h for details
|
|
|
|
|
*/
|
|
|
|
|
bool Copy(bool invalidate = true);
|
|
|
|
|
/// Copies selection to clipboard and deletes it.
|
|
|
|
|
bool Cut(void);
|
|
|
|
|
//@}
|
|
|
|
|
|
1999-10-10 16:52:34 +00:00
|
|
|
|
/// find string in buffer
|
1999-06-07 09:57:14 +00:00
|
|
|
|
bool Find(const wxString &needle,
|
1999-10-10 16:52:34 +00:00
|
|
|
|
wxPoint * fromWhere = NULL,
|
|
|
|
|
const wxString &configPath = "MsgViewFindString");
|
|
|
|
|
/// find the same string again
|
|
|
|
|
bool FindAgain(void);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
|
|
|
|
|
|
|
|
|
|
/** Sets the wrap margin.
|
|
|
|
|
@param margin set this to 0 to disable it
|
|
|
|
|
*/
|
|
|
|
|
void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
|
|
|
|
|
|
|
|
|
|
/** Redraws the window.
|
|
|
|
|
Internally, this stores the parameter and calls a refresh on
|
|
|
|
|
wxMSW, draws directly on wxGTK.
|
|
|
|
|
*/
|
1999-10-10 16:52:34 +00:00
|
|
|
|
void RequestUpdate(const wxRect *updateRect = NULL);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
/// if exact == false, assume 50% extra size for the future
|
|
|
|
|
void ResizeScrollbars(bool exact = false); // don't change this to true!
|
|
|
|
|
|
|
|
|
|
/// if the flag is true, we send events when user clicks on embedded objects
|
|
|
|
|
inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
|
|
|
|
|
|
|
|
|
|
/* Returns a pointer to the wxLayoutList object.
|
|
|
|
|
@return the list
|
|
|
|
|
*/
|
|
|
|
|
wxLayoutList * GetLayoutList(void) { return m_llist; }
|
|
|
|
|
|
|
|
|
|
/**@name Callbacks */
|
|
|
|
|
//@{
|
1999-06-09 22:19:31 +00:00
|
|
|
|
void OnSize(wxSizeEvent &event);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
void OnPaint(wxPaintEvent &event);
|
|
|
|
|
void OnChar(wxKeyEvent& event);
|
|
|
|
|
void OnKeyUp(wxKeyEvent& event);
|
1999-06-09 11:36:45 +00:00
|
|
|
|
void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
|
|
|
|
|
void OnUpdateMenuBold(wxUpdateUIEvent& event);
|
|
|
|
|
void OnUpdateMenuItalic(wxUpdateUIEvent& event);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
void OnMenu(wxCommandEvent& event);
|
1999-06-09 16:22:24 +00:00
|
|
|
|
void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
|
|
|
|
|
void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
|
1999-06-07 09:57:14 +00:00
|
|
|
|
void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
|
1999-06-10 17:22:02 +00:00
|
|
|
|
void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
|
1999-06-07 09:57:14 +00:00
|
|
|
|
void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
|
|
|
|
|
void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
|
|
|
|
|
void OnSetFocus(wxFocusEvent &ev);
|
|
|
|
|
void OnKillFocus(wxFocusEvent &ev);
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
/// Creates a wxMenu for use as a format popup.
|
|
|
|
|
static wxMenu * MakeFormatMenu(void);
|
1999-10-10 16:52:34 +00:00
|
|
|
|
/// Redraws the window, used by RequestUpdate() or OnPaint().
|
1999-06-07 09:57:14 +00:00
|
|
|
|
void InternalPaint(const wxRect *updateRect);
|
|
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
*/
|
|
|
|
|
void SetStatusBar(class wxStatusBar *bar,
|
|
|
|
|
int labelfield = -1,
|
|
|
|
|
int cursorfield = -1)
|
|
|
|
|
{
|
|
|
|
|
m_StatusBar = bar; m_StatusFieldLabel = labelfield;
|
|
|
|
|
m_StatusFieldCursor = cursorfield;
|
|
|
|
|
}
|
1999-10-10 16:52:34 +00:00
|
|
|
|
#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; }
|
|
|
|
|
//@}
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
1999-10-10 16:52:34 +00:00
|
|
|
|
/**@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; }
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
|
1999-06-07 09:57:14 +00:00
|
|
|
|
protected:
|
|
|
|
|
/// generic function for mouse events processing
|
|
|
|
|
void OnMouse(int eventId, wxMouseEvent& event);
|
|
|
|
|
/// as the name says
|
|
|
|
|
void ScrollToCursor(void);
|
|
|
|
|
/// for sending events
|
|
|
|
|
wxWindow *m_Parent;
|
|
|
|
|
/// Shall we send events?
|
|
|
|
|
bool m_doSendEvents;
|
|
|
|
|
/// Where does the current view start?
|
|
|
|
|
int m_ViewStartX; int m_ViewStartY;
|
|
|
|
|
/// Do we currently have the focus?
|
|
|
|
|
bool m_HaveFocus;
|
|
|
|
|
/// do we handle clicks of the right mouse button?
|
|
|
|
|
bool m_DoPopupMenu;
|
|
|
|
|
/// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
|
|
|
|
|
bool m_ScrollToCursor;
|
|
|
|
|
/// Do we currently have a non-standard cursor?
|
|
|
|
|
bool m_HandCursor;
|
|
|
|
|
/// the menu
|
|
|
|
|
wxMenu * m_PopupMenu;
|
|
|
|
|
/// for derived classes, set when mouse is clicked
|
|
|
|
|
wxPoint m_ClickPosition;
|
|
|
|
|
/// for scrollbar calculations:
|
|
|
|
|
int m_maxx;
|
|
|
|
|
int m_maxy;
|
|
|
|
|
int m_lineHeight;
|
1999-06-09 22:19:31 +00:00
|
|
|
|
|
|
|
|
|
/// do we have the corresponding scrollbar?
|
|
|
|
|
bool m_hasHScrollbar,
|
|
|
|
|
m_hasVScrollbar;
|
|
|
|
|
|
1999-06-07 09:57:14 +00:00
|
|
|
|
/** Visibility parameter for cursor. 0/1 as expected, -1: visible
|
|
|
|
|
on demand.
|
|
|
|
|
*/
|
|
|
|
|
int m_CursorVisibility;
|
1999-06-13 17:44:22 +00:00
|
|
|
|
|
|
|
|
|
bool SetAutoDeleteSelection(bool enable = TRUE)
|
|
|
|
|
{
|
|
|
|
|
bool old = m_AutoDeleteSelection;
|
|
|
|
|
m_AutoDeleteSelection = enable;
|
|
|
|
|
return old;
|
|
|
|
|
}
|
1999-06-07 09:57:14 +00:00
|
|
|
|
private:
|
|
|
|
|
/// The layout list to be displayed.
|
|
|
|
|
wxLayoutList *m_llist;
|
|
|
|
|
/// Can user edit the window?
|
|
|
|
|
bool m_Editable;
|
|
|
|
|
/// Are we currently building a selection with the keyboard?
|
|
|
|
|
bool m_Selecting;
|
|
|
|
|
/// wrap margin
|
|
|
|
|
CoordType m_WrapMargin;
|
1999-10-10 16:52:34 +00:00
|
|
|
|
/// Has list changed since last redraw, e.g. in size?
|
|
|
|
|
bool m_Dirty;
|
|
|
|
|
/// Has the list ever been modified?
|
|
|
|
|
bool m_Modified;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
wxMemoryDC *m_memDC;
|
|
|
|
|
wxBitmap *m_bitmap;
|
|
|
|
|
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
|
|
|
|
|
wxBitmap *m_BGbitmap;
|
1999-06-13 17:44:22 +00:00
|
|
|
|
/**@name Some configuration options */
|
|
|
|
|
//@{
|
|
|
|
|
/// Do we want to auto-replace the selection with new text?
|
|
|
|
|
bool m_AutoDeleteSelection;
|
1999-10-10 16:52:34 +00:00
|
|
|
|
#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;
|
|
|
|
|
//@}
|
1999-06-07 09:57:14 +00:00
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|