wxTipWindow is now a wxPopupTransientWindow instead of a wxFrame.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12773 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2001-11-30 23:02:27 +00:00
parent d323d966dd
commit 8962e1d938
3 changed files with 124 additions and 33 deletions

View File

@@ -9,7 +9,8 @@ will create it when required.
\wxheading{Derived from} \wxheading{Derived from}
\helpref{wxFrame}{wxframe}\\ wxPopupTransientWindow\\
wxPopupWindow\\
\helpref{wxWindow}{wxwindow}\\ \helpref{wxWindow}{wxwindow}\\
\helpref{wxEvtHandler}{wxevthandler}\\ \helpref{wxEvtHandler}{wxevthandler}\\
\helpref{wxObject}{wxobject} \helpref{wxObject}{wxobject}

View File

@@ -17,15 +17,15 @@
#pragma interface "tipwin.h" #pragma interface "tipwin.h"
#endif #endif
#include "wx/frame.h" #include "wx/popupwin.h"
#if wxUSE_POPUPWIN
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxTipWindow // wxTipWindow
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxTipWindow : public wxFrame class WXDLLEXPORT wxTipWindow : public wxPopupTransientWindow
{ {
friend class wxTipWindowView;
public: public:
// Supply windowPtr for it to null the given address // Supply windowPtr for it to null the given address
// when the window has closed. // when the window has closed.
@@ -36,11 +36,15 @@ public:
void SetTipWindowPtr(wxTipWindow** windowPtr) { m_windowPtr = windowPtr; } void SetTipWindowPtr(wxTipWindow** windowPtr) { m_windowPtr = windowPtr; }
// calculate the client rect we need to display the text
void Adjust(const wxString& text, wxCoord maxLength);
void Close();
protected: protected:
// event handlers // event handlers
void OnMouseClick(wxMouseEvent& event); void OnMouseClick(wxMouseEvent& event);
void OnActivate(wxActivateEvent& event); void OnPaint(wxPaintEvent& event);
void OnKillFocus(wxFocusEvent& event);
private: private:
wxArrayString m_textLines; wxArrayString m_textLines;
@@ -50,4 +54,5 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif // wxUSE_POPUPWIN
#endif // _WX_TIPWIN_H_ #endif // _WX_TIPWIN_H_

View File

@@ -51,14 +51,15 @@ static const wxCoord TEXT_MARGIN_Y = 3;
// event tables // event tables
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxTipWindow, wxFrame) BEGIN_EVENT_TABLE(wxTipWindow, wxPopupTransientWindow)
EVT_LEFT_DOWN(wxTipWindow::OnMouseClick) EVT_LEFT_DOWN(wxTipWindow::OnMouseClick)
EVT_RIGHT_DOWN(wxTipWindow::OnMouseClick) EVT_RIGHT_DOWN(wxTipWindow::OnMouseClick)
EVT_MIDDLE_DOWN(wxTipWindow::OnMouseClick) EVT_MIDDLE_DOWN(wxTipWindow::OnMouseClick)
EVT_KILL_FOCUS(wxTipWindow::OnKillFocus) EVT_PAINT(wxTipWindow::OnPaint)
EVT_ACTIVATE(wxTipWindow::OnActivate)
END_EVENT_TABLE() END_EVENT_TABLE()
#if 0
// Viewer window to put in the frame // Viewer window to put in the frame
class wxTipWindowView: public wxWindow class wxTipWindowView: public wxWindow
{ {
@@ -85,7 +86,7 @@ BEGIN_EVENT_TABLE(wxTipWindowView, wxWindow)
EVT_MIDDLE_DOWN(wxTipWindowView::OnMouseClick) EVT_MIDDLE_DOWN(wxTipWindowView::OnMouseClick)
EVT_KILL_FOCUS(wxTipWindowView::OnKillFocus) EVT_KILL_FOCUS(wxTipWindowView::OnKillFocus)
END_EVENT_TABLE() END_EVENT_TABLE()
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxTipWindow // wxTipWindow
@@ -94,10 +95,10 @@ END_EVENT_TABLE()
wxTipWindow::wxTipWindow(wxWindow *parent, wxTipWindow::wxTipWindow(wxWindow *parent,
const wxString& text, const wxString& text,
wxCoord maxLength, wxTipWindow** windowPtr) wxCoord maxLength, wxTipWindow** windowPtr)
: wxFrame(parent, -1, _T(""), : wxPopupTransientWindow(parent)
wxDefaultPosition, wxDefaultSize,
wxNO_BORDER | wxFRAME_NO_TASKBAR )
{ {
m_windowPtr = windowPtr;
// set colours // set colours
SetForegroundColour(*wxBLACK); SetForegroundColour(*wxBLACK);
@@ -108,18 +109,15 @@ wxTipWindow::wxTipWindow(wxWindow *parent,
#endif #endif
SetBackgroundColour(bkCol); SetBackgroundColour(bkCol);
// set position and size // set size and position
Adjust(text, maxLength);
int x, y; int x, y;
wxGetMousePosition(&x, &y); wxGetMousePosition(&x, &y);
Move(x, y + 20); Position(wxPoint(x, y+10), wxSize(0,0));
wxTipWindowView* tipWindowView = new wxTipWindowView(this); //Show(TRUE);
tipWindowView->Adjust(text, maxLength); Popup();
SetFocus();
m_windowPtr = windowPtr;
Show(TRUE);
tipWindowView->SetFocus();
} }
wxTipWindow::~wxTipWindow() wxTipWindow::~wxTipWindow()
@@ -135,26 +133,112 @@ void wxTipWindow::OnMouseClick(wxMouseEvent& WXUNUSED(event))
Close(); Close();
} }
void wxTipWindow::OnActivate(wxActivateEvent& event)
void wxTipWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
{ {
if (!event.GetActive()) wxPaintDC dc(this);
Close();
wxRect rect;
wxSize size = GetClientSize();
rect.width = size.x;
rect.height = size.y;
// first filll the background
dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID));
dc.SetPen( * wxBLACK_PEN );
dc.DrawRectangle(rect);
// and then draw the text line by line
dc.SetFont(GetFont());
wxPoint pt;
pt.x = TEXT_MARGIN_X;
pt.y = TEXT_MARGIN_Y;
size_t count = m_textLines.GetCount();
for ( size_t n = 0; n < count; n++ )
{
dc.DrawText(m_textLines[n], pt);
pt.y += m_heightLine;
}
} }
void wxTipWindow::OnKillFocus(wxFocusEvent& WXUNUSED(event))
void wxTipWindow::Adjust(const wxString& text, wxCoord maxLength)
{ {
// Under Windows at least, we will get this immediately wxClientDC dc(this);
// because when the view window is focussed, the dc.SetFont(GetFont());
// tip window goes out of focus.
#ifdef __WXGTK__ // calculate the length: we want each line be no longer than maxLength
Close(); // pixels and we only break lines at words boundary
#endif wxString current;
wxCoord height, width,
widthMax = 0;
m_heightLine = 0;
bool breakLine = FALSE;
for ( const wxChar *p = text.c_str(); ; p++ )
{
if ( *p == _T('\n') || *p == _T('\0') )
{
dc.GetTextExtent(current, &width, &height);
if ( width > widthMax )
widthMax = width;
if ( height > m_heightLine )
m_heightLine = height;
m_textLines.Add(current);
if ( !*p )
{
// end of text
break;
}
current.clear();
breakLine = FALSE;
}
else if ( breakLine && (*p == _T(' ') || *p == _T('\t')) )
{
// word boundary - break the line here
m_textLines.Add(current);
current.clear();
breakLine = FALSE;
}
else // line goes on
{
current += *p;
dc.GetTextExtent(current, &width, &height);
if ( width > maxLength )
breakLine = TRUE;
if ( width > widthMax )
widthMax = width;
if ( height > m_heightLine )
m_heightLine = height;
}
}
// take into account the border size and the margins
SetClientSize(2*(TEXT_MARGIN_X + 1) + widthMax,
2*(TEXT_MARGIN_Y + 1) + m_textLines.GetCount() * m_heightLine);
} }
void wxTipWindow::Close()
{
Show(FALSE);
Destroy();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxTipWindowView // wxTipWindowView
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if 0
wxTipWindowView::wxTipWindowView(wxWindow *parent) wxTipWindowView::wxTipWindowView(wxWindow *parent)
: wxWindow(parent, -1, : wxWindow(parent, -1,
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
@@ -280,3 +364,4 @@ void wxTipWindowView::OnKillFocus(wxFocusEvent& WXUNUSED(event))
GetParent()->Close(); GetParent()->Close();
} }
#endif