Merge branch 'tipwindow'
Miscellaneous wxTipWindow enhancements, including better high DPI support. See https://github.com/wxWidgets/wxWidgets/pull/1949
This commit is contained in:
@@ -2414,6 +2414,17 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif /* wxUSE_PROPGRID */
|
#endif /* wxUSE_PROPGRID */
|
||||||
|
|
||||||
|
#if wxUSE_TIPWINDOW
|
||||||
|
# if !wxUSE_POPUPWIN
|
||||||
|
# ifdef wxABORT_ON_CONFIG_ERROR
|
||||||
|
# error "wxTipWindow requires wxUSE_POPUPWIN"
|
||||||
|
# else
|
||||||
|
# undef wxUSE_POPUPWIN
|
||||||
|
# define wxUSE_POPUPWIN 1
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif /* wxUSE_TIPWINDOW */
|
||||||
|
|
||||||
#endif /* wxUSE_GUI */
|
#endif /* wxUSE_GUI */
|
||||||
|
|
||||||
#endif /* _WX_CHKCONF_H_ */
|
#endif /* _WX_CHKCONF_H_ */
|
||||||
|
@@ -14,16 +14,7 @@
|
|||||||
|
|
||||||
#if wxUSE_TIPWINDOW
|
#if wxUSE_TIPWINDOW
|
||||||
|
|
||||||
#if wxUSE_POPUPWIN
|
#include "wx/popupwin.h"
|
||||||
#include "wx/popupwin.h"
|
|
||||||
|
|
||||||
#define wxTipWindowBase wxPopupTransientWindow
|
|
||||||
#else
|
|
||||||
#include "wx/frame.h"
|
|
||||||
|
|
||||||
#define wxTipWindowBase wxFrame
|
|
||||||
#endif
|
|
||||||
#include "wx/arrstr.h"
|
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxTipWindowView;
|
class WXDLLIMPEXP_FWD_CORE wxTipWindowView;
|
||||||
|
|
||||||
@@ -31,7 +22,7 @@ class WXDLLIMPEXP_FWD_CORE wxTipWindowView;
|
|||||||
// wxTipWindow
|
// wxTipWindow
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxTipWindow : public wxTipWindowBase
|
class WXDLLIMPEXP_CORE wxTipWindow : public wxPopupTransientWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// the mandatory ctor parameters are: the parent window and the text to
|
// the mandatory ctor parameters are: the parent window and the text to
|
||||||
@@ -69,17 +60,9 @@ protected:
|
|||||||
// event handlers
|
// event handlers
|
||||||
void OnMouseClick(wxMouseEvent& event);
|
void OnMouseClick(wxMouseEvent& event);
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
void OnActivate(wxActivateEvent& event);
|
|
||||||
void OnKillFocus(wxFocusEvent& event);
|
|
||||||
#else // wxUSE_POPUPWIN
|
|
||||||
virtual void OnDismiss() wxOVERRIDE;
|
virtual void OnDismiss() wxOVERRIDE;
|
||||||
#endif // wxUSE_POPUPWIN/!wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxArrayString m_textLines;
|
|
||||||
wxCoord m_heightLine;
|
|
||||||
|
|
||||||
wxTipWindowView *m_view;
|
wxTipWindowView *m_view;
|
||||||
|
|
||||||
wxTipWindow** m_windowPtr;
|
wxTipWindow** m_windowPtr;
|
||||||
|
@@ -33,6 +33,9 @@
|
|||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
|
#include "wx/display.h"
|
||||||
|
#include "wx/vector.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -55,19 +58,15 @@ public:
|
|||||||
void OnMouseClick(wxMouseEvent& event);
|
void OnMouseClick(wxMouseEvent& event);
|
||||||
void OnMouseMove(wxMouseEvent& event);
|
void OnMouseMove(wxMouseEvent& event);
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
void OnKillFocus(wxFocusEvent& event);
|
|
||||||
#endif // wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
// calculate the client rect we need to display the text
|
// calculate the client rect we need to display the text
|
||||||
void Adjust(const wxString& text, wxCoord maxLength);
|
void Adjust(const wxString& text, wxCoord maxLength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxTipWindow* m_parent;
|
wxTipWindow* m_parent;
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
wxVector<wxString> m_textLines;
|
||||||
long m_creationTime;
|
wxCoord m_heightLine;
|
||||||
#endif // !wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
wxDECLARE_NO_COPY_CLASS(wxTipWindowView);
|
wxDECLARE_NO_COPY_CLASS(wxTipWindowView);
|
||||||
@@ -81,15 +80,10 @@ private:
|
|||||||
// event tables
|
// event tables
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(wxTipWindow, wxTipWindowBase)
|
wxBEGIN_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)
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
EVT_KILL_FOCUS(wxTipWindow::OnKillFocus)
|
|
||||||
EVT_ACTIVATE(wxTipWindow::OnActivate)
|
|
||||||
#endif // !wxUSE_POPUPWIN
|
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(wxTipWindowView, wxWindow)
|
wxBEGIN_EVENT_TABLE(wxTipWindowView, wxWindow)
|
||||||
@@ -100,10 +94,6 @@ wxBEGIN_EVENT_TABLE(wxTipWindowView, wxWindow)
|
|||||||
EVT_MIDDLE_DOWN(wxTipWindowView::OnMouseClick)
|
EVT_MIDDLE_DOWN(wxTipWindowView::OnMouseClick)
|
||||||
|
|
||||||
EVT_MOTION(wxTipWindowView::OnMouseMove)
|
EVT_MOTION(wxTipWindowView::OnMouseMove)
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
EVT_KILL_FOCUS(wxTipWindowView::OnKillFocus)
|
|
||||||
#endif // !wxUSE_POPUPWIN
|
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -115,13 +105,7 @@ wxTipWindow::wxTipWindow(wxWindow *parent,
|
|||||||
wxCoord maxLength,
|
wxCoord maxLength,
|
||||||
wxTipWindow** windowPtr,
|
wxTipWindow** windowPtr,
|
||||||
wxRect *rectBounds)
|
wxRect *rectBounds)
|
||||||
#if wxUSE_POPUPWIN
|
|
||||||
: wxPopupTransientWindow(parent)
|
: wxPopupTransientWindow(parent)
|
||||||
#else
|
|
||||||
: wxFrame(parent, wxID_ANY, wxEmptyString,
|
|
||||||
wxDefaultPosition, wxDefaultSize,
|
|
||||||
wxNO_BORDER | wxFRAME_NO_TASKBAR )
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
SetTipWindowPtr(windowPtr);
|
SetTipWindowPtr(windowPtr);
|
||||||
if ( rectBounds )
|
if ( rectBounds )
|
||||||
@@ -133,33 +117,51 @@ wxTipWindow::wxTipWindow(wxWindow *parent,
|
|||||||
SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
|
SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
|
||||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
|
||||||
|
|
||||||
// set size, position and show it
|
|
||||||
m_view = new wxTipWindowView(this);
|
|
||||||
m_view->Adjust(text, maxLength);
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
m_view->SetFocus();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
wxGetMousePosition(&x, &y);
|
wxGetMousePosition(&x, &y);
|
||||||
|
|
||||||
// we want to show the tip below the mouse, not over it
|
// move to the center of the target display so wxTipWindowView will use the
|
||||||
|
// correct DPI
|
||||||
|
wxPoint posScreen;
|
||||||
|
wxSize sizeScreen;
|
||||||
|
|
||||||
|
const int displayNum = wxDisplay::GetFromPoint(wxPoint(x, y));
|
||||||
|
if ( displayNum != wxNOT_FOUND )
|
||||||
|
{
|
||||||
|
const wxRect rectScreen = wxDisplay(displayNum).GetGeometry();
|
||||||
|
posScreen = rectScreen.GetPosition();
|
||||||
|
sizeScreen = rectScreen.GetSize();
|
||||||
|
}
|
||||||
|
else // outside of any display?
|
||||||
|
{
|
||||||
|
// just use the primary one then
|
||||||
|
posScreen = wxPoint(0, 0);
|
||||||
|
sizeScreen = wxGetDisplaySize();
|
||||||
|
}
|
||||||
|
wxPoint center(posScreen.x + sizeScreen.GetWidth() / 2,
|
||||||
|
posScreen.y + sizeScreen.GetHeight() / 2);
|
||||||
|
Move(center, wxSIZE_NO_ADJUSTMENTS);
|
||||||
|
|
||||||
|
// set size, position and show it
|
||||||
|
m_view = new wxTipWindowView(this);
|
||||||
|
m_view->Adjust(text, FromDIP(parent->ToDIP(maxLength)) );
|
||||||
|
|
||||||
|
// we want to show the tip below the mouse, not over it, make sure to not
|
||||||
|
// overflow into the next display
|
||||||
//
|
//
|
||||||
// NB: the reason we use "/ 2" here is that we don't know where the current
|
// NB: the reason we use "/ 2" here is that we don't know where the current
|
||||||
// cursors hot spot is... it would be nice if we could find this out
|
// cursors hot spot is... it would be nice if we could find this out
|
||||||
// though
|
// though
|
||||||
y += wxSystemSettings::GetMetric(wxSYS_CURSOR_Y, this) / 2;
|
int cursorOffset = wxSystemSettings::GetMetric(wxSYS_CURSOR_Y, this) / 2;
|
||||||
|
if (y + cursorOffset >= posScreen.y + sizeScreen.GetHeight())
|
||||||
|
cursorOffset = posScreen.y + sizeScreen.GetHeight() - y - 1;
|
||||||
|
y += cursorOffset;
|
||||||
|
|
||||||
#if wxUSE_POPUPWIN
|
|
||||||
Position(wxPoint(x, y), wxSize(0,0));
|
Position(wxPoint(x, y), wxSize(0,0));
|
||||||
Popup(m_view);
|
Popup(m_view);
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
m_view->CaptureMouse();
|
m_view->CaptureMouse();
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
Move(x, y);
|
|
||||||
Show(true);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTipWindow::~wxTipWindow()
|
wxTipWindow::~wxTipWindow()
|
||||||
@@ -168,11 +170,9 @@ wxTipWindow::~wxTipWindow()
|
|||||||
{
|
{
|
||||||
*m_windowPtr = NULL;
|
*m_windowPtr = NULL;
|
||||||
}
|
}
|
||||||
#if wxUSE_POPUPWIN
|
#ifdef __WXGTK__
|
||||||
#ifdef __WXGTK__
|
if ( m_view->HasCapture() )
|
||||||
if ( m_view->HasCapture() )
|
m_view->ReleaseMouse();
|
||||||
m_view->ReleaseMouse();
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,33 +181,11 @@ void wxTipWindow::OnMouseClick(wxMouseEvent& WXUNUSED(event))
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
void wxTipWindow::OnDismiss()
|
void wxTipWindow::OnDismiss()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // !wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
void wxTipWindow::OnActivate(wxActivateEvent& event)
|
|
||||||
{
|
|
||||||
if (!event.GetActive())
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxTipWindow::OnKillFocus(wxFocusEvent& WXUNUSED(event))
|
|
||||||
{
|
|
||||||
// Under Windows at least, we will get this immediately
|
|
||||||
// because when the view window is focussed, the
|
|
||||||
// tip window goes out of focus.
|
|
||||||
#ifdef __WXGTK__
|
|
||||||
Close();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // wxUSE_POPUPWIN // !wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
void wxTipWindow::SetBoundingRect(const wxRect& rectBound)
|
void wxTipWindow::SetBoundingRect(const wxRect& rectBound)
|
||||||
{
|
{
|
||||||
m_rectBound = rectBound;
|
m_rectBound = rectBound;
|
||||||
@@ -221,7 +199,6 @@ void wxTipWindow::Close()
|
|||||||
m_windowPtr = NULL;
|
m_windowPtr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_POPUPWIN
|
|
||||||
Show(false);
|
Show(false);
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
if ( m_view->HasCapture() )
|
if ( m_view->HasCapture() )
|
||||||
@@ -232,9 +209,6 @@ void wxTipWindow::Close()
|
|||||||
#ifndef __WXOSX__
|
#ifndef __WXOSX__
|
||||||
Destroy();
|
Destroy();
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
wxFrame::Close();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -250,11 +224,9 @@ wxTipWindowView::wxTipWindowView(wxWindow *parent)
|
|||||||
SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
|
SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
|
||||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
m_creationTime = wxGetLocalTime();
|
|
||||||
#endif // !wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
m_parent = (wxTipWindow*)parent;
|
m_parent = (wxTipWindow*)parent;
|
||||||
|
|
||||||
|
m_heightLine = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTipWindowView::Adjust(const wxString& text, wxCoord maxLength)
|
void wxTipWindowView::Adjust(const wxString& text, wxCoord maxLength)
|
||||||
@@ -267,7 +239,6 @@ void wxTipWindowView::Adjust(const wxString& text, wxCoord maxLength)
|
|||||||
wxString current;
|
wxString current;
|
||||||
wxCoord height, width,
|
wxCoord height, width,
|
||||||
widthMax = 0;
|
widthMax = 0;
|
||||||
m_parent->m_heightLine = 0;
|
|
||||||
|
|
||||||
bool breakLine = false;
|
bool breakLine = false;
|
||||||
for ( const wxChar *p = text.c_str(); ; p++ )
|
for ( const wxChar *p = text.c_str(); ; p++ )
|
||||||
@@ -278,10 +249,10 @@ void wxTipWindowView::Adjust(const wxString& text, wxCoord maxLength)
|
|||||||
if ( width > widthMax )
|
if ( width > widthMax )
|
||||||
widthMax = width;
|
widthMax = width;
|
||||||
|
|
||||||
if ( height > m_parent->m_heightLine )
|
if ( height > m_heightLine )
|
||||||
m_parent->m_heightLine = height;
|
m_heightLine = height;
|
||||||
|
|
||||||
m_parent->m_textLines.Add(current);
|
m_textLines.push_back(current);
|
||||||
|
|
||||||
if ( !*p )
|
if ( !*p )
|
||||||
{
|
{
|
||||||
@@ -295,7 +266,7 @@ void wxTipWindowView::Adjust(const wxString& text, wxCoord maxLength)
|
|||||||
else if ( breakLine && (*p == wxT(' ') || *p == wxT('\t')) )
|
else if ( breakLine && (*p == wxT(' ') || *p == wxT('\t')) )
|
||||||
{
|
{
|
||||||
// word boundary - break the line here
|
// word boundary - break the line here
|
||||||
m_parent->m_textLines.Add(current);
|
m_textLines.push_back(current);
|
||||||
current.clear();
|
current.clear();
|
||||||
breakLine = false;
|
breakLine = false;
|
||||||
}
|
}
|
||||||
@@ -309,14 +280,14 @@ void wxTipWindowView::Adjust(const wxString& text, wxCoord maxLength)
|
|||||||
if ( width > widthMax )
|
if ( width > widthMax )
|
||||||
widthMax = width;
|
widthMax = width;
|
||||||
|
|
||||||
if ( height > m_parent->m_heightLine )
|
if ( height > m_heightLine )
|
||||||
m_parent->m_heightLine = height;
|
m_heightLine = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// take into account the border size and the margins
|
// take into account the border size and the margins
|
||||||
width = 2*(TEXT_MARGIN_X + 1) + widthMax;
|
width = 2*(TEXT_MARGIN_X + 1) + widthMax;
|
||||||
height = 2*(TEXT_MARGIN_Y + 1) + wx_truncate_cast(wxCoord, m_parent->m_textLines.GetCount())*m_parent->m_heightLine;
|
height = 2*(TEXT_MARGIN_Y + 1) + wx_truncate_cast(wxCoord, m_textLines.size())*m_heightLine;
|
||||||
m_parent->SetClientSize(width, height);
|
m_parent->SetClientSize(width, height);
|
||||||
SetSize(0, 0, width, height);
|
SetSize(0, 0, width, height);
|
||||||
}
|
}
|
||||||
@@ -343,12 +314,12 @@ void wxTipWindowView::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|||||||
wxPoint pt;
|
wxPoint pt;
|
||||||
pt.x = TEXT_MARGIN_X;
|
pt.x = TEXT_MARGIN_X;
|
||||||
pt.y = TEXT_MARGIN_Y;
|
pt.y = TEXT_MARGIN_Y;
|
||||||
size_t count = m_parent->m_textLines.GetCount();
|
const size_t count = m_textLines.size();
|
||||||
for ( size_t n = 0; n < count; n++ )
|
for ( size_t n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
dc.DrawText(m_parent->m_textLines[n], pt);
|
dc.DrawText(m_textLines[n], pt);
|
||||||
|
|
||||||
pt.y += m_parent->m_heightLine;
|
pt.y += m_heightLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,13 +344,4 @@ void wxTipWindowView::OnMouseMove(wxMouseEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !wxUSE_POPUPWIN
|
|
||||||
void wxTipWindowView::OnKillFocus(wxFocusEvent& WXUNUSED(event))
|
|
||||||
{
|
|
||||||
// Workaround the kill focus event happening just after creation in wxGTK
|
|
||||||
if (wxGetLocalTime() > m_creationTime + 1)
|
|
||||||
m_parent->Close();
|
|
||||||
}
|
|
||||||
#endif // !wxUSE_POPUPWIN
|
|
||||||
|
|
||||||
#endif // wxUSE_TIPWINDOW
|
#endif // wxUSE_TIPWINDOW
|
||||||
|
Reference in New Issue
Block a user