MouseMotion while wxTipWindow Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

MouseMotion while wxTipWindow

Post by MoonKid »

I have a wxTreeCtrl and create as a tooltip my own wxTipWindow over its items.

I need to catch the mouse-motion-event on the wxTreeCtrl to know when I have to destroy the wxTipWindow.

But it doesn't work. I can catch the mouse-motion-event to know when I need to create a wxTipWindow.
But if the window is created the event-handling-methode for mouse-motion is not executed until the wxTipWindow is killed (by a timer).
Catching the mouse-motion-event in the TipWindow itself doesn't work, too. Setting the focus back to the TreeCtrl after creating the TipWindow doesn't work, too.

This is the mouse-motion handler methode in the TreeCtrl.

Code: Select all

void BFBackupTree::OnMouseMotion (wxMouseEvent& rEvent)
{
	BFSound::Info();

	// delete the current tip window because of mouse movement
	BFTipWindow::DeleteTipWindow();

	// mouse position
	wxPoint point = rEvent.GetLogicalPosition(wxWindowDC(this));

	// get the item id under the mouse
	int iFlags;
	wxTreeItemId id = HitTest(point, iFlags);

	// is it an item and not the right blank area
	if ( id.IsOk() && !(iFlags & wxTREE_HITTEST_ONITEMRIGHT) )
		BFTipWindow::CreateTipWindow(this, "TIP\nTIP2");

}
On each movement of the mouse a still existing TipWindow should be destroyed first (BFTipWindow::DeleteTipWindow()) before a new one could be created (BFTipWindow::CreateTipWindow()).

This is the BFTipWindow itself.

Code: Select all

/**
 * Name:        BFTipWindow.h
 * Purpose:
 * Author:      Christian Buhtz
 * Modified by:
 * Created:     2009-05-27
 * Copyright:   (c) 2009 Christian Buhtz <[email protected]>
 * Licence:     GNU General Public License (Version 3)
 ***
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***/


#ifndef BFTIPWINDOW_H
#define BFTIPWINDOW_H

#include <wx/timer.h>
#include <wx/tipwin.h>

/// 
class BFTipWindow : public wxTipWindow
{
	private:
		///
		static BFTipWindow*	psInstance_;

		///
		wxTimer				timer_;

        /// ctor
        BFTipWindow ();

		///
		BFTipWindow (wxWindow* pParent, const wxString& strTip);

    public:
		///
		static void CreateTipWindow (wxWindow* pParent, const wxString& strTip);
		///
		static void DeleteTipWindow ();

        /// virtual dtor
        virtual ~BFTipWindow ();

		///
		void OnTimer_Autopop (wxTimerEvent& rEvent);
		///
		void OnMouseMotion (wxMouseEvent& rEvent);

		/** The amount of time (in miliseconds) a pointer must remain stationary
			within a tool's bounding rectangle before the ToolTip
			window appears. */
		static int GetInitialTime ();
		/** The amount of time (in miliseconds) a ToolTip window remains visible
			if the pointer is stationary within a tool's bounding rectangle. */
		static int GetAutopopTime ();

	DECLARE_EVENT_TABLE();
};

#endif
And the code for the TipWindow.

Code: Select all

/**
 * Name:        BFTipWindow.cpp
 * Purpose:
 * Author:      Christian Buhtz
 * Modified by:
 * Created:     2009-05-27
 * Copyright:   (c) 2009 Christian Buhtz <[email protected]>
 * Licence:     GNU General Public License (Version 3)
 ***
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***/


#include "BFTipWindow.h"

#include "ids.h"

#include <wx/settings.h>

#define BF_TIPWINDOW_ID_TIMER_AUTOPOP		1 + BF_TIPWINDOW_ID_HIGHEST

BEGIN_EVENT_TABLE(BFTipWindow, wxTipWindow)
	EVT_MOTION	(						BFTipWindow::OnMouseMotion)
END_EVENT_TABLE()

/*static*/ BFTipWindow* BFTipWindow::psInstance_ = NULL;

BFTipWindow::BFTipWindow (wxWindow* pParent, const wxString& strTip)
		   : wxTipWindow (pParent, strTip),
		     timer_(this, BF_TIPWINDOW_ID_TIMER_AUTOPOP)
{
	// timer event
    Connect
    (
        BF_TIPWINDOW_ID_TIMER_AUTOPOP,
        wxEVT_TIMER,
        wxTimerEventHandler(BFTipWindow::OnTimer_Autopop),
        NULL,
        this
    );

    timer_.Start ( GetAutopopTime(), wxTIMER_ONE_SHOT );
}

BFTipWindow::BFTipWindow ()
		   : wxTipWindow (NULL, wxEmptyString)
{
}


/*virtual*/ BFTipWindow::~BFTipWindow ()
{
	psInstance_ = NULL;
}

void BFTipWindow::OnTimer_Autopop (wxTimerEvent& rEvent)
{
	DeleteTipWindow();
}

// XXX
#include "BFSound.h"

void BFTipWindow::OnMouseMotion (wxMouseEvent& rEvent)
{
	BFSound::Fatal();
	DeleteTipWindow();
}

/*static*/ void BFTipWindow::CreateTipWindow (wxWindow* pParent, const wxString& strTip)
{
	DeleteTipWindow();

	psInstance_ = new BFTipWindow(pParent, strTip);
}

/*static*/ void BFTipWindow::DeleteTipWindow ()
{
	if ( psInstance_ )
		psInstance_->Destroy();
}


/*static*/ int BFTipWindow::GetInitialTime ()
{
	return wxSystemSettings::GetMetric (wxSYS_DCLICK_MSEC);
}

/*static*/ int BFTipWindow::GetAutopopTime ()
{
	return GetInitialTime() * 10;
}
I don't understand why a mouse-motion event isn't catched while a wxTipWindow is alive.
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid »

Has no one an idea what could be behind this problem?
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid »

Can no one help me?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Maybe you could try doing black magic with CaptureMouse() ; otherwise I don't know, sorry
"Keyboard not detected. Press F1 to continue"
-- Windows
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid »

Auria wrote:Maybe you could try doing black magic with CaptureMouse() ; otherwise I don't know, sorry
Nice idea but doesn't work.
Post Reply