diff options
| author | 2008-04-08 16:44:05 +0000 | |
|---|---|---|
| committer | 2008-04-08 16:44:05 +0000 | |
| commit | 1a8d02ddbc48debb0cadc992b8f90ccd484f938f (patch) | |
| tree | 022c58acc0ab573c818900af8b13fee17bb34348 | |
| parent | fixed autofools rules for doc/ (diff) | |
| download | KVIrc-1a8d02ddbc48debb0cadc992b8f90ccd484f938f.tar.gz KVIrc-1a8d02ddbc48debb0cadc992b8f90ccd484f938f.tar.bz2 KVIrc-1a8d02ddbc48debb0cadc992b8f90ccd484f938f.zip | |
fixed trayicon and removed old references to dockwidget;
ported tip module;
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@1431 17fca916-40b9-46aa-a4ea-0a15b648b75c
| -rw-r--r-- | TODO-Qt4 | 2 | ||||
| -rw-r--r-- | src/kvirc/kernel/kvi_app.cpp | 2 | ||||
| -rw-r--r-- | src/kvirc/kernel/kvi_iconmanager.h | 2 | ||||
| -rw-r--r-- | src/kvirc/kernel/kvi_internalcmd.h | 4 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_frame.cpp | 5 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_menubar.cpp | 8 | ||||
| -rw-r--r-- | src/modules/options/optw_tray.h | 4 | ||||
| -rw-r--r-- | src/modules/tip/libkvitip.cpp | 17 | ||||
| -rw-r--r-- | src/modules/tip/libkvitip.h | 2 | ||||
| -rw-r--r-- | src/modules/trayicon/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/modules/trayicon/libkvitrayicon.cpp | 89 | ||||
| -rw-r--r-- | src/modules/trayicon/libkvitrayicon.h | 3 | ||||
| -rw-r--r-- | src/modules/trayicon/trayicon.cpp | 296 | ||||
| -rw-r--r-- | src/modules/trayicon/trayicon.h | 100 | ||||
| -rw-r--r-- | src/modules/trayicon/trayicon_mac.cpp | 25 | ||||
| -rw-r--r-- | src/modules/trayicon/trayicon_win.cpp | 263 | ||||
| -rw-r--r-- | src/modules/trayicon/trayicon_x11.cpp | 416 |
17 files changed, 62 insertions, 1181 deletions
@@ -81,6 +81,4 @@ src/modules options reguser - q3support in dialog.* theme - tip torrent - broken - trayicon diff --git a/src/kvirc/kernel/kvi_app.cpp b/src/kvirc/kernel/kvi_app.cpp index 3ff597e2c..f5cd5c03f 100644 --- a/src/kvirc/kernel/kvi_app.cpp +++ b/src/kvirc/kernel/kvi_app.cpp @@ -1577,7 +1577,7 @@ void KviApp::createFrame() } if(KVI_OPTION_BOOL(KviOption_boolShowDockExtension)) - g_pFrame->executeInternalCommand(KVI_INTERNALCOMMAND_DOCKWIDGET_SHOW); + g_pFrame->executeInternalCommand(KVI_INTERNALCOMMAND_TRAYICON_SHOW); if(KVI_OPTION_BOOL(KviOption_boolStartupMinimized)) { diff --git a/src/kvirc/kernel/kvi_iconmanager.h b/src/kvirc/kernel/kvi_iconmanager.h index f68e92df3..662b47f40 100644 --- a/src/kvirc/kernel/kvi_iconmanager.h +++ b/src/kvirc/kernel/kvi_iconmanager.h @@ -149,7 +149,7 @@ #define KVI_SMALLICON_LINUX 111 #define KVI_SMALLICON_LINKS 112 #define KVI_SMALLICON_REGUSERS 113 -#define KVI_SMALLICON_DOCKWIDGET 114 +#define KVI_SMALLICON_TRAYICON 114 #define KVI_SMALLICON_CASCADEWINDOWS 115 #define KVI_SMALLICON_MAXVERTICAL 116 #define KVI_SMALLICON_MAXHORIZONTAL 117 diff --git a/src/kvirc/kernel/kvi_internalcmd.h b/src/kvirc/kernel/kvi_internalcmd.h index f0d5ce95e..d279a97f0 100644 --- a/src/kvirc/kernel/kvi_internalcmd.h +++ b/src/kvirc/kernel/kvi_internalcmd.h @@ -33,8 +33,8 @@ #define KVI_INTERNALCOMMAND_SOCKETSPY_OPEN 6 #define KVI_INTERNALCOMMAND_LINKS_OPEN 7 #define KVI_INTERNALCOMMAND_REGUSER_EDIT 8 -#define KVI_INTERNALCOMMAND_DOCKWIDGET_SHOW 9 -#define KVI_INTERNALCOMMAND_DOCKWIDGET_HIDE 10 +#define KVI_INTERNALCOMMAND_TRAYICON_SHOW 9 +#define KVI_INTERNALCOMMAND_TRAYICON_HIDE 10 #define KVI_INTERNALCOMMAND_TOOLBAREDITOR_OPEN 11 #define KVI_INTERNALCOMMAND_ALIASEDITOR_OPEN 12 #define KVI_INTERNALCOMMAND_TERM_OPEN 13 diff --git a/src/kvirc/ui/kvi_frame.cpp b/src/kvirc/ui/kvi_frame.cpp index 1e1670e44..4f3fb16f9 100644 --- a/src/kvirc/ui/kvi_frame.cpp +++ b/src/kvirc/ui/kvi_frame.cpp @@ -955,7 +955,7 @@ void KviFrame::closeEvent(QCloseEvent *e) if(!dockExtension())
{
- executeInternalCommand(KVI_INTERNALCOMMAND_DOCKWIDGET_SHOW);
+ executeInternalCommand(KVI_INTERNALCOMMAND_TRAYICON_SHOW);
}
if(dockExtension())
{
@@ -1229,7 +1229,6 @@ void KviFrame::restoreToolBarPositions() }
}
-
void KviFrame::createTaskBar()
{
if(KVI_OPTION_BOOL(KviOption_boolUseTreeWindowListTaskBar))
@@ -1336,7 +1335,7 @@ void KviFrame::hideEvent ( QHideEvent * e) if(!dockExtension())
{
- executeInternalCommand(KVI_INTERNALCOMMAND_DOCKWIDGET_SHOW);
+ executeInternalCommand(KVI_INTERNALCOMMAND_TRAYICON_SHOW);
}
QTimer::singleShot( 0, this, SLOT(hide()) );
}
diff --git a/src/kvirc/ui/kvi_menubar.cpp b/src/kvirc/ui/kvi_menubar.cpp index 09bdef1d2..50e708e25 100644 --- a/src/kvirc/ui/kvi_menubar.cpp +++ b/src/kvirc/ui/kvi_menubar.cpp @@ -229,11 +229,11 @@ void KviMenuBar::setupMainPopup() if(m_pFrm->dockExtension()) { - int id = main->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DOCKWIDGET)),__tr2qs("Hide &Dock Icon"),m_pFrm,SLOT(executeInternalCommand(int))); - main->setItemParameter(id,KVI_INTERNALCOMMAND_DOCKWIDGET_HIDE); + int id = main->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TRAYICON)),__tr2qs("Hide &Dock Icon"),m_pFrm,SLOT(executeInternalCommand(int))); + main->setItemParameter(id,KVI_INTERNALCOMMAND_TRAYICON_HIDE); } else { - int id = main->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DOCKWIDGET)),__tr2qs("Show &Dock Icon"),m_pFrm,SLOT(executeInternalCommand(int))); - main->setItemParameter(id,KVI_INTERNALCOMMAND_DOCKWIDGET_SHOW); + int id = main->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TRAYICON)),__tr2qs("Show &Dock Icon"),m_pFrm,SLOT(executeInternalCommand(int))); + main->setItemParameter(id,KVI_INTERNALCOMMAND_TRAYICON_SHOW); } // Qt/Mac creates a Quit item on its own diff --git a/src/modules/options/optw_tray.h b/src/modules/options/optw_tray.h index f6a87fd67..e4665743c 100644 --- a/src/modules/options/optw_tray.h +++ b/src/modules/options/optw_tray.h @@ -25,10 +25,10 @@ #include "kvi_optionswidget.h" #include <qcombobox.h> -#define KVI_OPTIONS_WIDGET_ICON_KviTrayOptionsWidget KVI_SMALLICON_DOCKWIDGET +#define KVI_OPTIONS_WIDGET_ICON_KviTrayOptionsWidget KVI_SMALLICON_TRAYICON #define KVI_OPTIONS_WIDGET_NAME_KviTrayOptionsWidget __tr2qs_no_lookup("Tray icon") #define KVI_OPTIONS_WIDGET_PARENT_KviTrayOptionsWidget KviInterfaceFeaturesOptionsWidget -#define KVI_OPTIONS_WIDGET_KEYWORDS_KviTrayOptionsWidget __tr2qs_no_lookup("tray,dockwidget") +#define KVI_OPTIONS_WIDGET_KEYWORDS_KviTrayOptionsWidget __tr2qs_no_lookup("tray,TRAYICON") class KviTrayOptionsWidget : public KviOptionsWidget { diff --git a/src/modules/tip/libkvitip.cpp b/src/modules/tip/libkvitip.cpp index 11a9d1f49..3cb7c2d1f 100644 --- a/src/modules/tip/libkvitip.cpp +++ b/src/modules/tip/libkvitip.cpp @@ -36,8 +36,7 @@ #include <QPainter> #include <QDesktopWidget> #include <QCloseEvent> -#include <q3simplerichtext.h> -#define KviTalSimpleRichText Q3SimpleRichText +#include <QTextDocument> KviTipWindow * g_pTipWindow = 0; @@ -83,12 +82,10 @@ void KviTipFrame::drawContents(QPainter *p) f.setStyleHint(QFont::SansSerif); f.setPointSize(12); - KviTalSimpleRichText doc(m_szText,f); - doc.setWidth(width() - 80); - - QRegion reg(0,0,1000,20000); - - doc.draw(p,70,10,reg,colorGroup()); + QTextDocument doc(m_szText); + doc.setDefaultFont(f); + doc.setTextWidth(width() - 80); + doc.drawContents(p,contentsRect()); } KviTipWindow::KviTipWindow() @@ -173,7 +170,7 @@ void KviTipWindow::closeConfig() g_pApp->getLocalKvircDirectory(buffer,KviApp::ConfigPlugins,m_szConfigFileName.ptr()); m_pConfig->setSavePath(buffer.ptr()); delete m_pConfig; - m_pConfig = 0; + m_pConfig = 0; } void KviTipWindow::nextTip() @@ -203,7 +200,7 @@ void KviTipWindow::nextTip() KviStr tmp(KviStr::Format,"%u",uNextTip); QString szTip = m_pConfig->readEntry(tmp.ptr(),__tr2qs("<b>Can't find any tip... :(</b>")); - //debug("REDECODED=%s",szTip.utf8().data()); + //qDebug("REDECODED=%s",szTip.utf8().data()); uNextTip++; if(uNextTip >= uNumTips)uNextTip = 0; diff --git a/src/modules/tip/libkvitip.h b/src/modules/tip/libkvitip.h index ffa9f5566..0527d77f3 100644 --- a/src/modules/tip/libkvitip.h +++ b/src/modules/tip/libkvitip.h @@ -40,7 +40,7 @@ public: KviTipFrame(QWidget * par); ~KviTipFrame(); protected: - QString m_szText; + QString m_szText; QPixmap * m_pTipPixmap; protected: virtual void drawContents(QPainter *p); diff --git a/src/modules/trayicon/CMakeLists.txt b/src/modules/trayicon/CMakeLists.txt index 698a9a4f3..b11091c0b 100644 --- a/src/modules/trayicon/CMakeLists.txt +++ b/src/modules/trayicon/CMakeLists.txt @@ -2,15 +2,10 @@ SET(kvitrayicon_MOC_HDRS libkvitrayicon.h - trayicon.h ) SET(kvitrayicon_SRCS libkvitrayicon.cpp - trayicon.cpp - trayicon_x11.cpp - trayicon_mac.cpp - trayicon_win.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/trayicon/libkvitrayicon.cpp b/src/modules/trayicon/libkvitrayicon.cpp index 68714f9cf..fc3286515 100644 --- a/src/modules/trayicon/libkvitrayicon.cpp +++ b/src/modules/trayicon/libkvitrayicon.cpp @@ -20,14 +20,9 @@ // Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // -#include "kvi_settings.h" - -#ifdef COMPILE_ON_WINDOWS - #define ICON_SIZE 16 -#else - #define ICON_SIZE 22 -#endif +#include "libkvitrayicon.h" +#include "kvi_settings.h" #include "kvi_app.h" #include "kvi_module.h" #include "kvi_locale.h" @@ -45,8 +40,6 @@ #include "kvi_doublebuffer.h" #include "kvi_tal_popupmenu.h" -#include "libkvitrayicon.h" - #include <QLabel> #include <QPixmap> #include <QPainter> @@ -57,9 +50,14 @@ #include <stdlib.h> #include <time.h> +#ifdef COMPILE_ON_WINDOWS + #define ICON_SIZE 16 +#else + #define ICON_SIZE 22 +#endif extern KVIRC_API KviPointerHashTable<const char *,KviWindow> * g_pGlobalWindowDict; -static KviPointerList<KviTrayIcon> * g_pDockWidgetList = 0; +static KviPointerList<KviTrayIcon> * g_pTrayIconList = 0; static QPixmap * g_pDock1 = 0; static QPixmap * g_pDock2 = 0; @@ -79,7 +77,7 @@ KviTrayIcon::KviTrayIcon(KviFrame * frm) m_pFlashingTimer = new QTimer(this,"flashing_timer"); connect( m_pFlashingTimer, SIGNAL(timeout()), this, SLOT(flashingTimerShot()) ); m_bFlashed=0; - g_pDockWidgetList->append(this); + g_pTrayIconList->append(this); m_pFrm = frm; m_pFrm->setDockExtension(this); @@ -100,8 +98,8 @@ KviTrayIcon::KviTrayIcon(KviFrame * frm) m_pContextPopup->insertSeparator(); m_iToggleFrame = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_RAW)),QString(""),this,SLOT(toggleParentFrame())); m_pContextPopup->insertSeparator(); - id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DOCKWIDGET)),__tr2qs("Un&dock"),m_pFrm,SLOT(executeInternalCommand(int))); - m_pContextPopup->setItemParameter(id,KVI_INTERNALCOMMAND_DOCKWIDGET_HIDE); + id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TRAYICON)),__tr2qs("Un&dock"),m_pFrm,SLOT(executeInternalCommand(int))); + m_pContextPopup->setItemParameter(id,KVI_INTERNALCOMMAND_TRAYICON_HIDE); id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_QUITAPP)),__tr2qs("&Quit"),g_pApp,SLOT(quit())); m_pContextPopup->setAccel(__tr2qs("Ctrl+Q"),id); connect(m_pContextPopup,SIGNAL(aboutToShow()),this,SLOT(fillContextPopup())); @@ -116,7 +114,7 @@ KviTrayIcon::KviTrayIcon(KviFrame * frm) KviTrayIcon::~KviTrayIcon() { m_pFrm->setDockExtension(0); - g_pDockWidgetList->removeRef(this); + g_pTrayIconList->removeRef(this); } void KviTrayIcon::die() @@ -469,11 +467,10 @@ void KviTrayIcon::updateIcon() setIcon(QIcon(m_CurrentPixmap)); } - -static KviTrayIcon * dockwidget_find(KviFrame *f) +static KviTrayIcon * trayicon_find(KviFrame *f) { - if(!g_pDockWidgetList)return 0; - for(KviTrayIcon * w = g_pDockWidgetList->first();w;w = g_pDockWidgetList->next()) + if(!g_pTrayIconList)return 0; + for(KviTrayIcon * w = g_pTrayIconList->first();w;w = g_pTrayIconList->next()) { if(w->frame() == f)return w; } @@ -514,9 +511,9 @@ static KviTrayIcon * dockwidget_find(KviFrame *f) [cmd]trayicon.hide[/cmd] */ -static bool dockwidget_kvs_cmd_show(KviKvsModuleCommandCall * c) +static bool trayicon_kvs_cmd_show(KviKvsModuleCommandCall * c) { - if(!(dockwidget_find(c->window()->frame()))) + if(!(trayicon_find(c->window()->frame()))) { KviTrayIcon * w = new KviTrayIcon(c->window()->frame()); w->show(); @@ -540,9 +537,9 @@ static bool dockwidget_kvs_cmd_show(KviKvsModuleCommandCall * c) [cmd]trayicon.show[/cmd] */ -static bool dockwidget_kvs_cmd_hide(KviKvsModuleCommandCall * c) +static bool trayicon_kvs_cmd_hide(KviKvsModuleCommandCall * c) { - KviTrayIcon * w= dockwidget_find(c->window()->frame()); + KviTrayIcon * w= trayicon_find(c->window()->frame()); if(w)delete w; // show the parent frame.. otherwise there will be no way to get it back if(!c->window()->frame()->isVisible()) @@ -563,14 +560,14 @@ static bool dockwidget_kvs_cmd_hide(KviKvsModuleCommandCall * c) @syntax: trayicon.hidewindow @description: - Hides the window, assotiated with dockwidget + Hides the window, assotiated with trayicon @seealso: [cmd]trayicon.show[/cmd], [cmd]trayicon.hide[/cmd] */ -static bool dockwidget_kvs_cmd_hidewindow(KviKvsModuleCommandCall * c) +static bool trayicon_kvs_cmd_hidewindow(KviKvsModuleCommandCall * c) { - KviTrayIcon * w= dockwidget_find(c->window()->frame()); + KviTrayIcon * w= trayicon_find(c->window()->frame()); if(w) { c->window()->frame()->hide(); @@ -594,18 +591,16 @@ static bool dockwidget_kvs_cmd_hidewindow(KviKvsModuleCommandCall * c) [cmd]trayicon.show[/cmd] */ -static bool dockwidget_kvs_fnc_isvisible(KviKvsModuleFunctionCall * c) +static bool trayicon_kvs_fnc_isvisible(KviKvsModuleFunctionCall * c) { - c->returnValue()->setBoolean(dockwidget_find(c->window()->frame())); + c->returnValue()->setBoolean(trayicon_find(c->window()->frame())); return true; } - - // ======================================= // init routine // ======================================= -static bool dockwidget_module_init(KviModule * m) +static bool trayicon_module_init(KviModule * m) { QString buffer; #ifdef COMPILE_ON_WINDOWS @@ -627,27 +622,25 @@ static bool dockwidget_module_init(KviModule * m) #else g_pApp->findImage(buffer,"kvi_dock_part-2.png"); #endif - g_pDock3 = new QPixmap(buffer); - - g_pDockWidgetList = new KviPointerList<KviTrayIcon>; - g_pDockWidgetList->setAutoDelete(false); + g_pTrayIconList = new KviPointerList<KviTrayIcon>; + g_pTrayIconList->setAutoDelete(false); - KVSM_REGISTER_SIMPLE_COMMAND(m,"hide",dockwidget_kvs_cmd_hide); - KVSM_REGISTER_SIMPLE_COMMAND(m,"hidewindow",dockwidget_kvs_cmd_hidewindow); - KVSM_REGISTER_SIMPLE_COMMAND(m,"show",dockwidget_kvs_cmd_show); - KVSM_REGISTER_FUNCTION(m,"isVisible",dockwidget_kvs_fnc_isvisible); + KVSM_REGISTER_SIMPLE_COMMAND(m,"hide",trayicon_kvs_cmd_hide); + KVSM_REGISTER_SIMPLE_COMMAND(m,"hidewindow",trayicon_kvs_cmd_hidewindow); + KVSM_REGISTER_SIMPLE_COMMAND(m,"show",trayicon_kvs_cmd_show); + KVSM_REGISTER_FUNCTION(m,"isVisible",trayicon_kvs_fnc_isvisible); return true; } -static bool dockwidget_module_cleanup(KviModule *m) +static bool trayicon_module_cleanup(KviModule *m) { - while(g_pDockWidgetList->first())delete g_pDockWidgetList->first(); - delete g_pDockWidgetList; - g_pDockWidgetList = 0; + while(g_pTrayIconList->first())delete g_pTrayIconList->first(); + delete g_pTrayIconList; + g_pTrayIconList = 0; delete g_pDock1; g_pDock1 = 0; @@ -661,23 +654,23 @@ static bool dockwidget_module_cleanup(KviModule *m) return true; } -static bool dockwidget_module_can_unload(KviModule *) +static bool trayicon_module_can_unload(KviModule *) { - return g_pDockWidgetList->isEmpty(); + return g_pTrayIconList->isEmpty(); } // ======================================= // plugin definition structure // ======================================= KVIRC_MODULE( - "KVIrc dock widget implementation", + "KVIrc Tray Icon Implementation", "4.0.0", "Szymon Stefanek <pragma at kvirc dot net> and Alexey Uzhva <alexey at kvirc dot ru>", "exports the /trayicon.* interface\n", - dockwidget_module_init , - dockwidget_module_can_unload, + trayicon_module_init , + trayicon_module_can_unload, 0, - dockwidget_module_cleanup + trayicon_module_cleanup ) #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/trayicon/libkvitrayicon.h b/src/modules/trayicon/libkvitrayicon.h index 17d22588b..445f2f803 100644 --- a/src/modules/trayicon/libkvitrayicon.h +++ b/src/modules/trayicon/libkvitrayicon.h @@ -25,9 +25,9 @@ #include <QSystemTrayIcon> -class KviTalPopupMenu; class QPixmap; class QTimer; +class KviTalPopupMenu; class KviDynamicToolTip; //class KviFrame; @@ -69,7 +69,6 @@ protected slots: void tipRequest(KviDynamicToolTip *tip,const QPoint &pnt); void doAway(int); void flashingTimerShot(); - void activatedSlot( QSystemTrayIcon::ActivationReason reason ); }; diff --git a/src/modules/trayicon/trayicon.cpp b/src/modules/trayicon/trayicon.cpp deleted file mode 100644 index f3d08ab2f..000000000 --- a/src/modules/trayicon/trayicon.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - * trayicon.cpp - system-independent trayicon class (adapted from Qt example) - * Copyright (C) 2003 Justin Karneges - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#if 0 - -#include "trayicon.h" -#include "kvi_tal_popupmenu.h" - -/*! - \class TrayIcon qtrayicon.h - \brief The TrayIcon class implements an entry in the system tray. -*/ - -/*! - Creates a TrayIcon object. \a parent and \a name are propagated - to the QObject constructor. The icon is initially invisible. - - \sa show -*/ -TrayIcon::TrayIcon( QObject *parent, const char *name ) -: QObject(parent, name), pop(0), d(0) -{ - v_isWMDock = FALSE; -} - -/*! - Creates a TrayIcon object displaying \a icon and \a tooltip, and opening - \a popup when clicked with the right mousebutton. \a parent and \a name are - propagated to the QObject constructor. The icon is initially invisible. - - \sa show -*/ -TrayIcon::TrayIcon( const QPixmap &icon, const QString &tooltip, KviTalPopupMenu *popup, QObject *parent, const char *name ) -: QObject(parent, name), pop(popup), pm(icon), tip(tooltip), d(0) -{ - v_isWMDock = FALSE; - - if ( !pm.width() || !pm.height() ) - pm = QPixmap( 16, 16 ); -} - -/*! - Removes the icon from the system tray and frees all allocated resources. -*/ -TrayIcon::~TrayIcon() -{ - sysRemove(); -} - -/*! - Informs the trayicon that the notification owner has probably been changed; - and that it should attempt to register or re-register. -*/ -void TrayIcon::newTrayOwner() -{ - // detach ourself from any existing notification area. - hide(); - // show ourself on the new notification area - show(); -} - - -/*! - Sets the context menu to \a popup. The context menu will pop up when the - user clicks the system tray entry with the right mouse button. -*/ -void TrayIcon::setPopup( KviTalPopupMenu* popup ) -{ - pop = popup; -} - -/*! - Returns the current popup menu. - - \sa setPopup -*/ -KviTalPopupMenu* TrayIcon::popup() const -{ - return pop; -} - -/*! - \property TrayIcon::icon - \brief the system tray icon. -*/ -void TrayIcon::setIcon( const QPixmap &icon ) -{ - //if(!popup()) { - // tip = ""; - //} - - pm = icon; - sysUpdateIcon(); -} - -QPixmap TrayIcon::icon() const -{ - return pm; -} - -/*! - \property TrayIcon::toolTip - \brief the tooltip for the system tray entry - - On some systems, the tooltip's length is limited and will be truncated as necessary. -*/ -void TrayIcon::setToolTip( const QString &tooltip ) -{ - tip = tooltip; - sysUpdateToolTip(); -} - -QString TrayIcon::toolTip() const -{ - return tip; -} - -/*! - Shows the icon in the system tray. - - \sa hide -*/ -void TrayIcon::show() -{ - sysInstall(); -} - -/*! - Hides the system tray entry. -*/ -void TrayIcon::hide() -{ - sysRemove(); -} - -/*! - \reimp -*/ -bool TrayIcon::event( QEvent *e ) -{ - switch ( e->type() ) { - case QEvent::MouseMove: - mouseMoveEvent( (QMouseEvent*)e ); - break; - - case QEvent::MouseButtonPress: - mousePressEvent( (QMouseEvent*)e ); - break; - - case QEvent::MouseButtonRelease: - mouseReleaseEvent( (QMouseEvent*)e ); - break; - - case QEvent::MouseButtonDblClick: - mouseDoubleClickEvent( (QMouseEvent*)e ); - break; - default: - return QObject::event( e ); - } - - return TRUE; -} - -/*! - This event handler can be reimplemented in a subclass to receive - mouse move events for the system tray entry. - - \sa mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), QMouseEvent -*/ -void TrayIcon::mouseMoveEvent( QMouseEvent *e ) -{ - e->ignore(); -} - -/*! - This event handler can be reimplemented in a subclass to receive - mouse press events for the system tray entry. - - \sa mouseReleaseEvent(), mouseDoubleClickEvent(), - mouseMoveEvent(), QMouseEvent -*/ -void TrayIcon::mousePressEvent( QMouseEvent *e ) -{ -#ifndef Q_WS_WIN -// This is for X11, menus appear on mouse press -// I'm not sure whether Mac should be here or below.. Somebody check? - switch ( e->button() ) { - case Qt::RightButton: - if ( pop ) { - pop->popup( e->globalPos() ); - e->accept(); - } - break; - case Qt::LeftButton: - case Qt::MidButton: - emit clicked( e->globalPos(), e->button() ); - break; - default: - break; - } -#endif - e->ignore(); -} - -/*! - This event handler can be reimplemented in a subclass to receive - mouse release events for the system tray entry. - - The default implementations opens the context menu when the entry - has been clicked with the right mouse button. - - \sa setPopup(), mousePressEvent(), mouseDoubleClickEvent(), - mouseMoveEvent(), QMouseEvent -*/ -void TrayIcon::mouseReleaseEvent( QMouseEvent *e ) -{ -#ifdef Q_WS_WIN -// This is for Windows, where menus appear on mouse release - switch ( e->button() ) { - case Qt::RightButton: - if ( pop ) { - // Necessary to make keyboard focus - // and menu closing work on Windows. - pop->setActiveWindow(); - pop->popup( e->globalPos() ); - pop->setActiveWindow(); - e->accept(); - } - break; - case Qt::LeftButton: - case Qt::MidButton: - emit clicked( e->globalPos(), e->button() ); - break; - default: - break; - } -#endif - e->ignore(); -} - -/*! - This event handler can be reimplemented in a subclass to receive - mouse double click events for the system tray entry. - - Note that the system tray entry gets a mousePressEvent() and a - mouseReleaseEvent() before the mouseDoubleClickEvent(). - - \sa mousePressEvent(), mouseReleaseEvent(), - mouseMoveEvent(), QMouseEvent -*/ -void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e ) -{ - if ( e->button() == Qt::LeftButton ) - emit doubleClicked( e->globalPos() ); - e->accept(); -} - -/*! - \fn void TrayIcon::clicked( const QPoint &p ) - - This signal is emitted when the user clicks the system tray icon - with the left mouse button, with \a p being the global mouse position - at that moment. -*/ - -/*! - \fn void TrayIcon::doubleClicked( const QPoint &p ) - - This signal is emitted when the user double clicks the system tray - icon with the left mouse button, with \a p being the global mouse position - at that moment. -*/ - -void TrayIcon::gotCloseEvent() -{ - closed(); -} - -#endif diff --git a/src/modules/trayicon/trayicon.h b/src/modules/trayicon/trayicon.h deleted file mode 100644 index 17184f638..000000000 --- a/src/modules/trayicon/trayicon.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * trayicon.h - system-independent trayicon class (adapted from Qt example) - * Copyright (C) 2003 Justin Karneges - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef CS_TRAYICON_H -#define CS_TRAYICON_H - -#if 0 - -#include "kvi_settings.h" - -#include <qobject.h> -#include <qimage.h> - -class KviTalPopupMenu; - -class TrayIcon : public QObject -{ - Q_OBJECT - - Q_PROPERTY( QString toolTip READ toolTip WRITE setToolTip ) - Q_PROPERTY( QPixmap icon READ icon WRITE setIcon ) - -public: - TrayIcon( QObject *parent = 0, const char *name = 0 ); - TrayIcon( const QPixmap &, const QString &, KviTalPopupMenu *popup = 0, QObject *parent = 0, const char *name = 0 ); - ~TrayIcon(); - - // use WindowMaker dock mode. ignored on non-X11 platforms - void setWMDock(bool use) { v_isWMDock = use; } - bool isWMDock() { return v_isWMDock; } - - // Set a popup menu to handle RMB - void setPopup( KviTalPopupMenu * ); - KviTalPopupMenu* popup() const; - - QPixmap icon() const; - QString toolTip() const; - - void gotCloseEvent(); - -public slots: - void setIcon( const QPixmap &icon ); - void setToolTip( const QString &tip ); - - void show(); - void hide(); - - void newTrayOwner(); - -signals: - void clicked( const QPoint&, int); - void doubleClicked( const QPoint& ); - void closed(); - -protected: - bool event( QEvent * ); - virtual void mouseMoveEvent( QMouseEvent *e ); - virtual void mousePressEvent( QMouseEvent *e ); - virtual void mouseReleaseEvent( QMouseEvent *e ); - virtual void mouseDoubleClickEvent( QMouseEvent *e ); - -private: - KviTalPopupMenu *pop; - QPixmap pm; - QString tip; - bool v_isWMDock; - - // system-dependant part -public: - class TrayIconPrivate; -private: - TrayIconPrivate *d; - void sysInstall(); - void sysRemove(); - void sysUpdateIcon(); - void sysUpdateToolTip(); - - friend class TrayIconPrivate; -}; - -#endif - -#endif // CS_TRAYICON_H diff --git a/src/modules/trayicon/trayicon_mac.cpp b/src/modules/trayicon/trayicon_mac.cpp deleted file mode 100644 index d192a366b..000000000 --- a/src/modules/trayicon/trayicon_mac.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#if 0 - -#ifdef Q_OS_MACX - -#include "trayicon.h" - -void TrayIcon::sysInstall() -{ -} - -void TrayIcon::sysRemove() -{ -} - -void TrayIcon::sysUpdateIcon() -{ -} - -void TrayIcon::sysUpdateToolTip() -{ -} - -#endif - -#endif diff --git a/src/modules/trayicon/trayicon_win.cpp b/src/modules/trayicon/trayicon_win.cpp deleted file mode 100644 index b23ac93a8..000000000 --- a/src/modules/trayicon/trayicon_win.cpp +++ /dev/null @@ -1,263 +0,0 @@ -#if 0 - -/* - * trayicon_win.cpp - Windows trayicon, adapted from Qt example - * Copyright (C) 2003 Justin Karneges - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "trayicon.h" - -#include <qwidget.h> -#include <qapplication.h> -#include <qimage.h> -#include <qpixmap.h> -#include <qbitmap.h> -#include <qcursor.h> -#include <qlibrary.h> - -#include <qt_windows.h> - -static uint WM_TASKBARCREATED = 0; -#define WM_NOTIFYICON (WM_APP+101) - -typedef BOOL (WINAPI *PtrShell_NotifyIcon)(DWORD,PNOTIFYICONDATA); -static PtrShell_NotifyIcon ptrShell_NotifyIcon = 0; - -static void resolveLibs() -{ - QLibrary lib("shell32"); - lib.setAutoUnload( FALSE ); - static bool triedResolve = FALSE; - if ( !ptrShell_NotifyIcon && !triedResolve ) { - triedResolve = TRUE; - ptrShell_NotifyIcon = (PtrShell_NotifyIcon) lib.resolve( "Shell_NotifyIconW" ); - } -} - -class TrayIcon::TrayIconPrivate : public QWidget -{ -public: - HICON hIcon; - HBITMAP hMask; - TrayIcon *iconObject; - - TrayIconPrivate( TrayIcon *object ) - : QWidget( 0 ), hIcon( 0 ), hMask( 0 ), iconObject( object ) - { - if ( !WM_TASKBARCREATED ) - WM_TASKBARCREATED = RegisterWindowMessage( TEXT("TaskbarCreated") ); - } - - ~TrayIconPrivate() - { - if ( hMask ) { - DeleteObject( hMask ); - hMask = 0; // michalj - } - if ( hIcon ) { - DestroyIcon( hIcon ); - hIcon = 0; // michalj - } - } - - // the unavoidable A/W versions. Don't forget to keep them in sync! - bool trayMessageA( DWORD msg ) - { - NOTIFYICONDATAA tnd; - ZeroMemory( &tnd, sizeof(NOTIFYICONDATAA) ); - tnd.cbSize = sizeof(NOTIFYICONDATAA); - tnd.hWnd = winId(); - tnd.uID = 1; // michalj - - if ( msg != NIM_DELETE ) { - tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP; - tnd.uCallbackMessage= WM_NOTIFYICON; - tnd.hIcon = hIcon; - if ( !iconObject->toolTip().isNull() ) { - // Tip is limited to 63 + NULL; lstrcpyn appends a NULL terminator. - QString tip = iconObject->toolTip().left( 63 ) + QChar(); - lstrcpynA(tnd.szTip, (const char*)tip.local8Bit(), QMIN( tip.length()+1, 64 ) ); - } - } - - return Shell_NotifyIconA(msg, &tnd); - } - -#ifdef UNICODE - bool trayMessageW( DWORD msg ) - { - resolveLibs(); - if ( ! (ptrShell_NotifyIcon && qWinVersion() & Qt::WV_NT_based) ) - return trayMessageA( msg ); - - NOTIFYICONDATAW tnd; - ZeroMemory( &tnd, sizeof(NOTIFYICONDATAW) ); - tnd.cbSize = sizeof(NOTIFYICONDATAW); - tnd.hWnd = winId(); - tnd.uID = 1; // michalj - - if ( msg != NIM_DELETE ) { - tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP; - tnd.uCallbackMessage= WM_NOTIFYICON; - tnd.hIcon = hIcon; - if ( !iconObject->toolTip().isNull() ) { - // Tip is limited to 63 + NULL; lstrcpyn appends a NULL terminator. - QString tip = iconObject->toolTip().left( 63 ) + QChar(); - lstrcpynW(tnd.szTip, (TCHAR*)tip.unicode(), QMIN( tip.length()+1, 64 ) ); - // lstrcpynW(tnd.szTip, (TCHAR*)qt_winTchar( tip, FALSE ), QMIN( tip.length()+1, 64 ) ); - } - } - return ptrShell_NotifyIcon(msg, &tnd); - } -#endif - - bool trayMessage( DWORD msg ) - { - QT_WA( - return trayMessageW(msg); - , - return trayMessageA(msg); - ) - } - - bool iconDrawItem(LPDRAWITEMSTRUCT lpdi) - { - if (!hIcon) - return FALSE; - - DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, NULL, DI_NORMAL ); - return TRUE; - } - - bool winEvent( MSG *m ) - { - switch(m->message) { - case WM_DRAWITEM: - return iconDrawItem( (LPDRAWITEMSTRUCT)m->lParam ); - case WM_NOTIFYICON: - { - QMouseEvent *e = 0; - QPoint gpos = QCursor::pos(); - switch (m->lParam) { - case WM_MOUSEMOVE: e = new QMouseEvent( QEvent::MouseMove, mapFromGlobal( gpos ), gpos, 0, 0 ); break; - case WM_LBUTTONDOWN: e = new QMouseEvent( QEvent::MouseButtonPress, mapFromGlobal( gpos ), gpos, Qt::LeftButton, Qt::LeftButton ); break; - case WM_LBUTTONUP: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::LeftButton, Qt::LeftButton ); break; - case WM_LBUTTONDBLCLK: e = new QMouseEvent( QEvent::MouseButtonDblClick, mapFromGlobal( gpos ), gpos, Qt::LeftButton, Qt::LeftButton ); break; - case WM_RBUTTONDOWN: e = new QMouseEvent( QEvent::MouseButtonPress, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton ); break; - case WM_RBUTTONUP: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton ); break; - case WM_RBUTTONDBLCLK: e = new QMouseEvent( QEvent::MouseButtonDblClick, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton ); break; - case WM_MBUTTONDOWN: e = new QMouseEvent( QEvent::MouseButtonPress, mapFromGlobal( gpos ), gpos, Qt::MidButton, Qt::MidButton ); break; - case WM_MBUTTONUP: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::MidButton, Qt::MidButton ); break; - case WM_MBUTTONDBLCLK: e = new QMouseEvent( QEvent::MouseButtonDblClick, mapFromGlobal( gpos ), gpos, Qt::MidButton, Qt::MidButton ); break; - case WM_CONTEXTMENU: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton ); break; - } - if ( e ) { - bool res = QApplication::sendEvent( iconObject, e ); - delete e; - return res; - } - } - break; - default: - if ( m->message == WM_TASKBARCREATED ) trayMessage( NIM_ADD ); - } - return QWidget::winEvent( m ); - } -}; - -static HBITMAP createIconMask( const QPixmap &qp ) -{ - QImage bm = qp.convertToImage(); - int w = bm.width(); - int h = bm.height(); - int bpl = ((w+15)/16)*2; // bpl, 16 bit alignment - uchar *bits = new uchar[bpl*h]; - bm.invertPixels(); - for ( int y=0; y<h; y++ ) - memcpy( bits+y*bpl, bm.scanLine(y), bpl ); - HBITMAP hbm = CreateBitmap( w, h, 1, 1, bits ); - delete [] bits; - return hbm; -} - -static HICON createIcon( const QPixmap &pm, HBITMAP &hbm ) -{ - QPixmap maskpm( pm.size(), pm.depth(), QPixmap::NormalOptim ); - QBitmap mask( pm.size(), FALSE, QPixmap::NormalOptim ); - if ( pm.mask() ) { - maskpm.fill( Qt::black ); // make masked area black - bitBlt( &mask, 0, 0, pm.mask() ); - } else - maskpm.fill( Qt::color1 ); - - bitBlt( &maskpm, 0, 0, &pm); - ICONINFO iconInfo; - iconInfo.fIcon = TRUE; - iconInfo.hbmMask = hbm = createIconMask(mask); - iconInfo.hbmColor = maskpm.hbm(); - - HICON icon = CreateIconIndirect( &iconInfo ); - DeleteObject(iconInfo.hbmMask); - iconInfo.hbmMask = hbm = 0; // michalj - return icon; -} - -void TrayIcon::sysInstall() -{ - if ( !d ) { - d = new TrayIconPrivate( this ); - d->hIcon = createIcon( pm, d->hMask ); - - d->trayMessage( NIM_ADD ); - } -} - -void TrayIcon::sysRemove() -{ - if ( d ) { - d->trayMessage( NIM_DELETE ); - - delete d; - d = 0; - } -} - -void TrayIcon::sysUpdateIcon() -{ - if ( d ) { - if ( d->hMask ) { - DeleteObject( d->hMask ); - d->hMask = 0; // michalj - } - if ( d->hIcon ) { - DestroyIcon( d->hIcon ); - d->hIcon = 0; // michalj - } - - d->hIcon = createIcon( pm, d->hMask ); - d->trayMessage( NIM_MODIFY ); - } -} - -void TrayIcon::sysUpdateToolTip() -{ - if ( d ) - d->trayMessage( NIM_MODIFY ); -} - -#endif diff --git a/src/modules/trayicon/trayicon_x11.cpp b/src/modules/trayicon/trayicon_x11.cpp deleted file mode 100644 index a64580abb..000000000 --- a/src/modules/trayicon/trayicon_x11.cpp +++ /dev/null @@ -1,416 +0,0 @@ -#if 0 - -/* - * trayicon_x11.cpp - X11 trayicon (for use with KDE and GNOME) - * Copyright (C) 2003 Justin Karneges - * GNOME2 Notification Area support: Tomasz Sterna - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "kvi_settings.h" // Needed for the two define checks below -#ifndef Q_OS_MACX -#ifndef COMPILE_ON_WINDOWS - -#include "trayicon.h" - -#include <qapplication.h> -#include <qimage.h> -#include <qpixmap.h> -#include <qtooltip.h> -#include <qpainter.h> - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/Xatom.h> - -//#if QT_VERSION < 0x030200 -extern Time qt_x_time; -//#endif - -//---------------------------------------------------------------------------- -// common stuff -//---------------------------------------------------------------------------- - -// for Gnome2 Notification Area -static XErrorHandler old_handler = 0; -static int dock_xerror = 0; -extern "C" int dock_xerrhandler(Display* dpy, XErrorEvent* err) -{ - dock_xerror = err->error_code; - return old_handler(dpy, err); -} - -static void trap_errors() -{ - dock_xerror = 0; - old_handler = XSetErrorHandler(dock_xerrhandler); -} - -static bool untrap_errors() -{ - XSetErrorHandler(old_handler); - return (dock_xerror == 0); -} - -static bool send_message( - Display* dpy, /* display */ - Window w, /* sender (tray icon window) */ - long message, /* message opcode */ - long data1, /* message data 1 */ - long data2, /* message data 2 */ - long data3 /* message data 3 */ -) { - XEvent ev; - - memset(&ev, 0, sizeof(ev)); - ev.xclient.type = ClientMessage; - ev.xclient.window = w; - ev.xclient.message_type = XInternAtom (dpy, "_NET_SYSTEM_TRAY_OPCODE", False ); - ev.xclient.format = 32; - ev.xclient.data.l[0] = CurrentTime; - ev.xclient.data.l[1] = message; - ev.xclient.data.l[2] = data1; - ev.xclient.data.l[3] = data2; - ev.xclient.data.l[4] = data3; - - trap_errors(); - XSendEvent(dpy, w, False, NoEventMask, &ev); - XSync(dpy, False); - return untrap_errors(); -} - -#define SYSTEM_TRAY_REQUEST_DOCK 0 -#define SYSTEM_TRAY_BEGIN_MESSAGE 1 -#define SYSTEM_TRAY_CANCEL_MESSAGE 2 - -//---------------------------------------------------------------------------- -// TrayIcon::TrayIconPrivate -//---------------------------------------------------------------------------- - -class TrayIcon::TrayIconPrivate : public QWidget -{ -public: - TrayIconPrivate(TrayIcon *object, int size); - ~TrayIconPrivate() { } - - virtual void initWM(WId icon); - - virtual void setPixmap(const QPixmap &pm); - - virtual void paintEvent(QPaintEvent *); - virtual void enterEvent(QEvent *); - virtual void mouseMoveEvent(QMouseEvent *e); - virtual void mousePressEvent(QMouseEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *e); - virtual void mouseDoubleClickEvent(QMouseEvent *e); - virtual void closeEvent(QCloseEvent *e); - -private: - TrayIcon *iconObject; - QPixmap pix; - int size; -}; - -TrayIcon::TrayIconPrivate::TrayIconPrivate(TrayIcon *object, int _size) - : QWidget(0, "psidock", WRepaintNoErase) -{ - iconObject = object; - size = _size; - - setFocusPolicy(NoFocus); - setBackgroundMode(X11ParentRelative); - - setMinimumSize(size, size); - setMaximumSize(size, size); -} - -// This base stuff is required by both FreeDesktop specification and WindowMaker -void TrayIcon::TrayIconPrivate::initWM(WId icon) -{ - Display *dsp = x11Display(); - WId leader = winId(); - - // set the class hint - XClassHint classhint; - classhint.res_name = (char*)"psidock"; - classhint.res_class = (char*)"Psi"; - XSetClassHint(dsp, leader, &classhint); - - // set the Window Manager hints - XWMHints *hints; - hints = XGetWMHints(dsp, leader); // init hints - hints->flags = WindowGroupHint | IconWindowHint | StateHint; // set the window group hint - hints->window_group = leader; // set the window hint - hints->initial_state = WithdrawnState; // initial state - hints->icon_window = icon; // in WM, this should be winId() of separate widget - hints->icon_x = 0; - hints->icon_y = 0; - XSetWMHints(dsp, leader, hints); // set the window hints for WM to use. - XFree( hints ); -} - -void TrayIcon::TrayIconPrivate::setPixmap(const QPixmap &pm) -{ - pix = pm; - setIcon(pix); - repaint(); -} - -void TrayIcon::TrayIconPrivate::paintEvent(QPaintEvent *) -{ - QPainter p(this); - p.drawPixmap((width() - pix.width())/2, (height() - pix.height())/2, pix); -} - -void TrayIcon::TrayIconPrivate::enterEvent(QEvent *e) -{ - // Taken from KSystemTray.. -//#if QT_VERSION < 0x030200 - //if ( !qApp->focusWidget() ) { - XEvent ev; - memset(&ev, 0, sizeof(ev)); - ev.xfocus.display = qt_xdisplay(); - ev.xfocus.type = FocusIn; - ev.xfocus.window = winId(); - ev.xfocus.mode = NotifyNormal; - ev.xfocus.detail = NotifyAncestor; - Time time = qt_x_time; - qt_x_time = 1; - qApp->x11ProcessEvent( &ev ); - qt_x_time = time; - //} -//#endif - QWidget::enterEvent(e); -} - -void TrayIcon::TrayIconPrivate::mouseMoveEvent(QMouseEvent *e) -{ - QApplication::sendEvent(iconObject, e); -} - -void TrayIcon::TrayIconPrivate::mousePressEvent(QMouseEvent *e) -{ - QApplication::sendEvent(iconObject, e); -} - -void TrayIcon::TrayIconPrivate::mouseReleaseEvent(QMouseEvent *e) -{ - QApplication::sendEvent(iconObject, e); -} - -void TrayIcon::TrayIconPrivate::mouseDoubleClickEvent(QMouseEvent *e) -{ - QApplication::sendEvent(iconObject, e); -} - -void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e) -{ - iconObject->gotCloseEvent(); - e->accept(); -} - -//---------------------------------------------------------------------------- -// TrayIconFreeDesktop -//---------------------------------------------------------------------------- - -class TrayIconFreeDesktop : public TrayIcon::TrayIconPrivate -{ -public: - TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm); -protected: - virtual bool x11Event(XEvent*); -}; - -TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm) - : TrayIconPrivate(object, 22) -{ - initWM( winId() ); - - // initialize NetWM - Display *dsp = x11Display(); - - // dock the widget (adapted from SIM-ICQ) - Screen *screen = XDefaultScreenOfDisplay(dsp); // get the screen - int screen_id = XScreenNumberOfScreen(screen); // and it's number - - // tell X that we want to see ClientMessage and Deleted events, which - // are picked up by QApplication::x11EventFilter - Window root_window = QApplication::desktop()->winId(); - XWindowAttributes attr; - - XGetWindowAttributes(dsp, root_window, &attr); - XSelectInput(dsp, root_window, attr.your_event_mask | StructureNotifyMask); - - char buf[32]; - snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id); - Atom selection_atom = XInternAtom(dsp, buf, false); - XGrabServer(dsp); - Window manager_window = XGetSelectionOwner(dsp, selection_atom); - if ( manager_window != None ) - XSelectInput(dsp, manager_window, StructureNotifyMask); - XUngrabServer(dsp); - XFlush(dsp); - - if ( manager_window != None ) - send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, winId(), 0, 0); - else - { - object->hide(); - return; - } - - // some KDE mumbo-jumbo... why is it there? anybody? - Atom kwm_dockwindow_atom = XInternAtom(dsp, "KWM_DOCKWINDOW", false); - Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false); - - long data = 0; - XChangeProperty(dsp, winId(), kwm_dockwindow_atom, kwm_dockwindow_atom, 32, PropModeReplace, (uchar*)&data, 1); - XChangeProperty(dsp, winId(), kde_net_system_tray_window_for_atom, XA_WINDOW, 32, PropModeReplace, (uchar*)&data, 1); - - setPixmap(pm); -} - -bool TrayIconFreeDesktop::x11Event(XEvent *ev) -{ - switch(ev->type) - { - case ReparentNotify: - show(); - - } - return false; -} - -//---------------------------------------------------------------------------- -// TrayIconWindowMaker -//---------------------------------------------------------------------------- - -class TrayIconWharf : public TrayIcon::TrayIconPrivate -{ -public: - TrayIconWharf(TrayIcon *object, const QPixmap &pm) - : TrayIconPrivate(object, 44) - { - // set the class hint - XClassHint classhint; - classhint.res_name = (char*)"psidock-wharf"; - classhint.res_class = (char*)"Psi"; - XSetClassHint(x11Display(), winId(), &classhint); - - setPixmap(pm); - } - - void setPixmap(const QPixmap &_pm) - { - QPixmap pm; - QImage i = _pm.convertToImage(); - i = i.scale(i.width() * 2, i.height() * 2); - pm.convertFromImage(i); - - TrayIconPrivate::setPixmap(pm); - - // thanks to Robert Spier for this: - // for some reason the repaint() isn't being honored, or isn't for - // the icon. So force one on the widget behind the icon - erase(); - QPaintEvent pe( rect() ); - paintEvent(&pe); - } -}; - -class TrayIconWindowMaker : public TrayIcon::TrayIconPrivate -{ -public: - TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm); - ~TrayIconWindowMaker(); - - void setPixmap(const QPixmap &pm); - -private: - TrayIconWharf *wharf; -}; - -TrayIconWindowMaker::TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm) - : TrayIconPrivate(object, 32) -{ - wharf = new TrayIconWharf(object, pm); - - initWM( wharf->winId() ); -} - -TrayIconWindowMaker::~TrayIconWindowMaker() -{ - delete wharf; -} - -void TrayIconWindowMaker::setPixmap(const QPixmap &pm) -{ - wharf->setPixmap(pm); -} - -//---------------------------------------------------------------------------- -// TrayIcon -//---------------------------------------------------------------------------- - -void TrayIcon::sysInstall() -{ - if ( d ) - return; - - if ( v_isWMDock ) - d = (TrayIconPrivate *)(new TrayIconWindowMaker(this, pm)); - else - d = (TrayIconPrivate *)(new TrayIconFreeDesktop(this, pm)); - - sysUpdateToolTip(); - - if ( v_isWMDock ) - d->show(); -} - -void TrayIcon::sysRemove() -{ - if ( !d ) - return; - - delete d; - d = 0; -} - -void TrayIcon::sysUpdateIcon() -{ - if ( !d ) - return; - - QPixmap pix = pm; - d->setPixmap(pix); -} - -void TrayIcon::sysUpdateToolTip() -{ - if ( !d ) - return; - - if ( tip.isEmpty() ) - QToolTip::remove(d); - else - QToolTip::add(d, tip); -} - -#endif -#endif -#endif |
