You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
435 lines
11 KiB
435 lines
11 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1998 Kurt Granroth (granroth@kde.org)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#ifdef KDE_USE_FINAL
|
||
|
#ifdef KeyRelease
|
||
|
#undef KeyRelease
|
||
|
#endif
|
||
|
#endif
|
||
|
|
||
|
#include <kcursor.h>
|
||
|
|
||
15 years ago
|
#include <tqbitmap.h>
|
||
|
#include <tqcursor.h>
|
||
|
#include <tqevent.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqwidget.h>
|
||
15 years ago
|
|
||
|
#include <kglobal.h>
|
||
|
#include <kconfig.h>
|
||
15 years ago
|
#include <tqscrollview.h>
|
||
15 years ago
|
|
||
|
#include "kcursor_private.h"
|
||
|
|
||
|
KCursor::KCursor()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
TQCursor KCursor::handCursor()
|
||
15 years ago
|
{
|
||
15 years ago
|
static TQCursor *hand_cursor = 0;
|
||
15 years ago
|
|
||
|
if (!hand_cursor)
|
||
|
{
|
||
|
KConfig *config = KGlobal::config();
|
||
|
KConfigGroupSaver saver( config, "General" );
|
||
|
|
||
14 years ago
|
#ifndef Q_WS_WIN // this mask doesn't work too well on win32
|
||
15 years ago
|
if ( config->readEntry("handCursorStyle", "Windows") == "Windows" )
|
||
|
{
|
||
|
static const unsigned char HAND_BITS[] = {
|
||
|
0x80, 0x01, 0x00, 0x40, 0x02, 0x00, 0x40, 0x02, 0x00, 0x40, 0x02,
|
||
|
0x00, 0x40, 0x02, 0x00, 0x40, 0x02, 0x00, 0x40, 0x1e, 0x00, 0x40,
|
||
|
0xf2, 0x00, 0x40, 0x92, 0x01, 0x70, 0x92, 0x02, 0x50, 0x92, 0x04,
|
||
|
0x48, 0x80, 0x04, 0x48, 0x00, 0x04, 0x48, 0x00, 0x04, 0x08, 0x00,
|
||
|
0x04, 0x08, 0x00, 0x04, 0x10, 0x00, 0x04, 0x10, 0x00, 0x04, 0x20,
|
||
|
0x00, 0x02, 0x40, 0x00, 0x02, 0x40, 0x00, 0x01, 0xc0, 0xff, 0x01};
|
||
|
static const unsigned char HAND_MASK_BITS[] = {
|
||
|
0x80, 0x01, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03,
|
||
|
0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x1f, 0x00, 0xc0,
|
||
|
0xff, 0x00, 0xc0, 0xff, 0x01, 0xf0, 0xff, 0x03, 0xf0, 0xff, 0x07,
|
||
|
0xf8, 0xff, 0x07, 0xf8, 0xff, 0x07, 0xf8, 0xff, 0x07, 0xf8, 0xff,
|
||
|
0x07, 0xf8, 0xff, 0x07, 0xf0, 0xff, 0x07, 0xf0, 0xff, 0x07, 0xe0,
|
||
|
0xff, 0x03, 0xc0, 0xff, 0x03, 0xc0, 0xff, 0x01, 0xc0, 0xff, 0x01};
|
||
15 years ago
|
TQBitmap hand_bitmap(22, 22, HAND_BITS, true);
|
||
14 years ago
|
TQBitmap hand_mask(22, 22, HAND_MASK_BITS, true);
|
||
|
hand_cursor = new TQCursor(hand_bitmap, hand_mask, 7, 0);
|
||
15 years ago
|
// Hack to force TQCursor to call XCreatePixmapCursor() immediately
|
||
15 years ago
|
// so the bitmaps don't get pushed out of the Xcursor LRU cache.
|
||
|
hand_cursor->handle();
|
||
|
}
|
||
|
else
|
||
|
#endif //! Q_WS_WIN
|
||
15 years ago
|
hand_cursor = new TQCursor(PointingHandCursor);
|
||
15 years ago
|
}
|
||
|
|
||
|
Q_CHECK_PTR(hand_cursor);
|
||
|
return *hand_cursor;
|
||
|
}
|
||
|
|
||
|
/* XPM */
|
||
|
static const char * const working_cursor_xpm[]={
|
||
|
"32 32 3 1",
|
||
|
"# c None",
|
||
|
"a c #000000",
|
||
|
". c #ffffff",
|
||
|
"..##############################",
|
||
|
".a.##########.aaaa.#############",
|
||
|
".aa.#########.aaaa.#############",
|
||
|
".aaa.#######.aaaaaa.############",
|
||
|
".aaaa.#####.a...a..a..##########",
|
||
|
".aaaaa.####a....a...aa##########",
|
||
|
".aaaaaa.###a...aa...aa##########",
|
||
|
".aaaaaaa.##a..a.....aa##########",
|
||
|
".aaaaaaaa.#.aa.....a..##########",
|
||
|
".aaaaa....##.aaaaaa.############",
|
||
|
".aa.aa.######.aaaa.#############",
|
||
|
".a.#.aa.#####.aaaa.#############",
|
||
|
"..##.aa.########################",
|
||
|
"#####.aa.#######################",
|
||
|
"#####.aa.#######################",
|
||
|
"######..########################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################",
|
||
|
"################################"};
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::workingCursor()
|
||
15 years ago
|
{
|
||
15 years ago
|
static TQCursor *working_cursor = 0;
|
||
15 years ago
|
|
||
|
if (!working_cursor)
|
||
|
{
|
||
15 years ago
|
TQPixmap pm( const_cast< const char** >( working_cursor_xpm ));
|
||
|
working_cursor = new TQCursor( pm, 1, 1 );
|
||
|
// Hack to force TQCursor to call XCreatePixmapCursor() immediately
|
||
15 years ago
|
// so the bitmaps don't get pushed out of the Xcursor LRU cache.
|
||
|
working_cursor->handle();
|
||
|
}
|
||
|
|
||
|
Q_CHECK_PTR(working_cursor);
|
||
|
return *working_cursor;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* All of the follow functions will return the Qt default for now regardless
|
||
|
* of the style. This will change at some later date
|
||
|
*/
|
||
15 years ago
|
TQCursor KCursor::arrowCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqarrowCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::upArrowCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqupArrowCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::crossCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqcrossCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::waitCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqwaitCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::ibeamCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqibeamCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::sizeVerCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqsizeVerCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::sizeHorCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqsizeHorCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::sizeBDiagCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqsizeBDiagCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::sizeFDiagCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqsizeFDiagCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::sizeAllCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqsizeAllCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQCursor KCursor::blankCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqblankCursor;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQCursor KCursor::whatsThisCursor()
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqwhatsThisCursor;
|
||
15 years ago
|
}
|
||
|
|
||
|
// auto-hide cursor stuff
|
||
|
|
||
15 years ago
|
void KCursor::setAutoHideCursor( TQWidget *w, bool enable )
|
||
15 years ago
|
{
|
||
|
setAutoHideCursor( w, enable, false );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCursor::setAutoHideCursor( TQWidget *w, bool enable,
|
||
15 years ago
|
bool customEventFilter )
|
||
|
{
|
||
|
KCursorPrivate::self()->setAutoHideCursor( w, enable, customEventFilter );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCursor::autoHideEventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
|
KCursorPrivate::self()->eventFilter( o, e );
|
||
|
}
|
||
|
|
||
|
void KCursor::setHideCursorDelay( int ms )
|
||
|
{
|
||
|
KCursorPrivate::self()->hideCursorDelay = ms;
|
||
|
}
|
||
|
|
||
|
int KCursor::hideCursorDelay()
|
||
|
{
|
||
|
return KCursorPrivate::self()->hideCursorDelay;
|
||
|
}
|
||
|
|
||
|
// **************************************************************************
|
||
|
|
||
15 years ago
|
KCursorPrivateAutoHideEventFilter::KCursorPrivateAutoHideEventFilter( TQWidget* widget )
|
||
15 years ago
|
: m_widget( widget )
|
||
|
, m_wasMouseTracking( m_widget->hasMouseTracking() )
|
||
|
, m_isCursorHidden( false )
|
||
|
, m_isOwnCursor( false )
|
||
|
{
|
||
|
m_widget->setMouseTracking( true );
|
||
15 years ago
|
connect( &m_autoHideTimer, TQT_SIGNAL( timeout() ),
|
||
|
this, TQT_SLOT( hideCursor() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
KCursorPrivateAutoHideEventFilter::~KCursorPrivateAutoHideEventFilter()
|
||
|
{
|
||
|
if( m_widget != NULL )
|
||
|
m_widget->setMouseTracking( m_wasMouseTracking );
|
||
|
}
|
||
|
|
||
|
void KCursorPrivateAutoHideEventFilter::resetWidget()
|
||
|
{
|
||
|
m_widget = NULL;
|
||
|
}
|
||
|
|
||
|
void KCursorPrivateAutoHideEventFilter::hideCursor()
|
||
|
{
|
||
|
m_autoHideTimer.stop();
|
||
|
|
||
|
if ( m_isCursorHidden )
|
||
|
return;
|
||
|
|
||
|
m_isCursorHidden = true;
|
||
|
|
||
15 years ago
|
TQWidget* w = actualWidget();
|
||
15 years ago
|
|
||
|
m_isOwnCursor = w->ownCursor();
|
||
|
if ( m_isOwnCursor )
|
||
|
m_oldCursor = w->cursor();
|
||
|
|
||
|
w->setCursor( KCursor::blankCursor() );
|
||
|
}
|
||
|
|
||
|
void KCursorPrivateAutoHideEventFilter::unhideCursor()
|
||
|
{
|
||
|
m_autoHideTimer.stop();
|
||
|
|
||
|
if ( !m_isCursorHidden )
|
||
|
return;
|
||
|
|
||
|
m_isCursorHidden = false;
|
||
|
|
||
15 years ago
|
TQWidget* w = actualWidget();
|
||
15 years ago
|
|
||
14 years ago
|
if ( w->cursor().shape() != Qt::BlankCursor ) // someone messed with the cursor already
|
||
15 years ago
|
return;
|
||
|
|
||
|
if ( m_isOwnCursor )
|
||
|
w->setCursor( m_oldCursor );
|
||
|
else
|
||
|
w->unsetCursor();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget* KCursorPrivateAutoHideEventFilter::actualWidget() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQWidget* w = m_widget;
|
||
15 years ago
|
|
||
|
// Is w a scrollview ? Call setCursor on the viewport in that case.
|
||
14 years ago
|
TQScrollView * sv = tqt_dynamic_cast<TQScrollView *>( w );
|
||
15 years ago
|
if ( sv )
|
||
|
w = sv->viewport();
|
||
|
|
||
|
return w;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KCursorPrivateAutoHideEventFilter::eventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
14 years ago
|
Q_ASSERT( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_widget) );
|
||
15 years ago
|
|
||
|
switch ( e->type() )
|
||
|
{
|
||
15 years ago
|
case TQEvent::Create:
|
||
15 years ago
|
// Qt steals mouseTracking on create()
|
||
|
m_widget->setMouseTracking( true );
|
||
|
break;
|
||
15 years ago
|
case TQEvent::Leave:
|
||
|
case TQEvent::FocusOut:
|
||
|
case TQEvent::WindowDeactivate:
|
||
15 years ago
|
unhideCursor();
|
||
|
break;
|
||
15 years ago
|
case TQEvent::KeyPress:
|
||
|
case TQEvent::AccelOverride:
|
||
15 years ago
|
hideCursor();
|
||
|
break;
|
||
15 years ago
|
case TQEvent::Enter:
|
||
|
case TQEvent::FocusIn:
|
||
|
case TQEvent::MouseButtonPress:
|
||
|
case TQEvent::MouseButtonRelease:
|
||
|
case TQEvent::MouseButtonDblClick:
|
||
|
case TQEvent::MouseMove:
|
||
|
case TQEvent::Show:
|
||
|
case TQEvent::Hide:
|
||
|
case TQEvent::Wheel:
|
||
15 years ago
|
unhideCursor();
|
||
|
if ( m_widget->hasFocus() )
|
||
|
m_autoHideTimer.start( KCursorPrivate::self()->hideCursorDelay, true );
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
KCursorPrivate * KCursorPrivate::s_self = 0L;
|
||
|
|
||
|
KCursorPrivate * KCursorPrivate::self()
|
||
|
{
|
||
|
if ( !s_self )
|
||
|
s_self = new KCursorPrivate;
|
||
|
// WABA: We never delete KCursorPrivate. Don't change.
|
||
|
|
||
|
return s_self;
|
||
|
}
|
||
|
|
||
|
KCursorPrivate::KCursorPrivate()
|
||
|
{
|
||
|
hideCursorDelay = 5000; // 5s default value
|
||
|
|
||
|
KConfig *kc = KGlobal::config();
|
||
14 years ago
|
KConfigGroupSaver ks( kc, TQString::tqfromLatin1("KDE") );
|
||
15 years ago
|
enabled = kc->readBoolEntry(
|
||
14 years ago
|
TQString::tqfromLatin1("Autohiding cursor enabled"), true );
|
||
15 years ago
|
}
|
||
|
|
||
|
KCursorPrivate::~KCursorPrivate()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCursorPrivate::setAutoHideCursor( TQWidget *w, bool enable, bool customEventFilter )
|
||
15 years ago
|
{
|
||
|
if ( !w || !enabled )
|
||
|
return;
|
||
|
|
||
|
if ( enable )
|
||
|
{
|
||
13 years ago
|
if ( m_eventFilters.find( w ) != NULL )
|
||
15 years ago
|
return;
|
||
|
KCursorPrivateAutoHideEventFilter* filter = new KCursorPrivateAutoHideEventFilter( w );
|
||
|
m_eventFilters.insert( w, filter );
|
||
|
if ( !customEventFilter )
|
||
|
w->installEventFilter( filter );
|
||
15 years ago
|
connect( w, TQT_SIGNAL( destroyed(TQObject*) ),
|
||
|
this, TQT_SLOT( slotWidgetDestroyed(TQObject*) ) );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
KCursorPrivateAutoHideEventFilter* filter = m_eventFilters.take( w );
|
||
|
if ( filter == NULL )
|
||
|
return;
|
||
|
w->removeEventFilter( filter );
|
||
|
delete filter;
|
||
15 years ago
|
disconnect( w, TQT_SIGNAL( destroyed(TQObject*) ),
|
||
|
this, TQT_SLOT( slotWidgetDestroyed(TQObject*) ) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KCursorPrivate::eventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
|
if ( !enabled )
|
||
|
return false;
|
||
|
|
||
13 years ago
|
KCursorPrivateAutoHideEventFilter* filter = m_eventFilters.find( o );
|
||
15 years ago
|
|
||
|
Q_ASSERT( filter != NULL );
|
||
|
if ( filter == NULL )
|
||
|
return false;
|
||
|
|
||
|
return filter->eventFilter( o, e );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCursorPrivate::slotWidgetDestroyed( TQObject* o )
|
||
15 years ago
|
{
|
||
|
KCursorPrivateAutoHideEventFilter* filter = m_eventFilters.take( o );
|
||
|
|
||
|
Q_ASSERT( filter != NULL );
|
||
|
|
||
|
filter->resetWidget(); // so that dtor doesn't access it
|
||
|
delete filter;
|
||
|
}
|
||
|
|
||
|
#include "kcursor_private.moc"
|