diff options
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qcompleter.cpp | 106 | ||||
-rw-r--r-- | src/gui/util/qcompleter.h | 1 | ||||
-rw-r--r-- | src/gui/util/qcompleter_p.h | 1 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_s60.cpp | 24 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_win.cpp | 16 | ||||
-rw-r--r-- | src/gui/util/qdesktopservices_x11.cpp | 12 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon.cpp | 5 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_mac.mm | 155 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_p.h | 2 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_qws.cpp | 5 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_win.cpp | 166 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_wince.cpp | 18 | ||||
-rw-r--r-- | src/gui/util/qsystemtrayicon_x11.cpp | 5 | ||||
-rw-r--r-- | src/gui/util/util.pri | 10 |
14 files changed, 304 insertions, 222 deletions
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp index 9a99abe..e718212 100644 --- a/src/gui/util/qcompleter.cpp +++ b/src/gui/util/qcompleter.cpp @@ -62,7 +62,7 @@ \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 0 - A QDirModel can be used to provide auto completion of file names. + A QFileSystemModel can be used to provide auto completion of file names. For example: \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 1 @@ -120,7 +120,7 @@ completion is then performed one level at a time. Let's take the example of a user typing in a file system path. - The model is a (hierarchical) QDirModel. The completion + The model is a (hierarchical) QFileSystemModel. The completion occurs for every element in the path. For example, if the current text is \c C:\Wind, QCompleter might suggest \c Windows to complete the current path element. Similarly, if the current text @@ -130,12 +130,12 @@ split the path into a list of strings that are matched at each level. For \c C:\Windows\Sy, it needs to be split as "C:", "Windows" and "Sy". The default implementation of splitPath(), splits the completionPrefix - using QDir::separator() if the model is a QDirModel. + using QDir::separator() if the model is a QFileSystemModel. To provide completions, QCompleter needs to know the path from an index. This is provided by pathFromIndex(). The default implementation of pathFromIndex(), returns the data for the \l{Qt::EditRole}{edit role} - for list models and the absolute file path if the mode is a QDirModel. + for list models and the absolute file path if the mode is a QFileSystemModel. \sa QAbstractItemModel, QLineEdit, QComboBox, {Completer Example} */ @@ -147,12 +147,14 @@ #include "QtGui/qscrollbar.h" #include "QtGui/qstringlistmodel.h" #include "QtGui/qdirmodel.h" +#include "QtGui/qfilesystemmodel.h" #include "QtGui/qheaderview.h" #include "QtGui/qlistview.h" #include "QtGui/qapplication.h" #include "QtGui/qevent.h" #include "QtGui/qheaderview.h" #include "QtGui/qdesktopwidget.h" +#include "QtGui/qlineedit.h" QT_BEGIN_NAMESPACE @@ -470,9 +472,13 @@ QMatchData QCompletionEngine::filterHistory() QAbstractItemModel *source = c->proxy->sourceModel(); if (curParts.count() <= 1 || c->proxy->showAll || !source) return QMatchData(); - bool dirModel = false; + bool isDirModel = false; + bool isFsModel = false; #ifndef QT_NO_DIRMODEL - dirModel = (qobject_cast<QDirModel *>(source) != 0); + isDirModel = (qobject_cast<QDirModel *>(source) != 0); +#endif +#ifndef QT_NO_FILESYSTEMMODEL + isFsModel = (qobject_cast<QFileSystemModel *>(source) != 0); #endif QVector<int> v; QIndexMapper im(v); @@ -482,7 +488,7 @@ QMatchData QCompletionEngine::filterHistory() QString str = source->index(i, c->column).data().toString(); if (str.startsWith(c->prefix, c->cs) #if (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_OS_SYMBIAN) - && (!dirModel || QDir::toNativeSeparators(str) != QDir::separator()) + && ((!isFsModel && !isDirModel) || QDir::toNativeSeparators(str) != QDir::separator()) #endif ) m.indices.append(i); @@ -843,6 +849,13 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted) completion += QDir::separator(); } #endif +#ifndef QT_NO_FILESYSTEMMODEL + // add a trailing separator in inline + if (mode == QCompleter::InlineCompletion) { + if (qobject_cast<QFileSystemModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir()) + completion += QDir::separator(); + } +#endif } if (highlighted) { @@ -866,7 +879,7 @@ void QCompleterPrivate::showPopup(const QRect& rect) const QRect screen = QApplication::desktop()->availableGeometry(widget); Qt::LayoutDirection dir = widget->layoutDirection(); QPoint pos; - int rw, rh, w; + int rh, w; int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3; QScrollBar *hsb = popup->horizontalScrollBar(); if (hsb && hsb->isVisible()) @@ -874,21 +887,30 @@ void QCompleterPrivate::showPopup(const QRect& rect) if (rect.isValid()) { rh = rect.height(); - w = rw = rect.width(); + w = rect.width(); pos = widget->mapToGlobal(dir == Qt::RightToLeft ? rect.bottomRight() : rect.bottomLeft()); } else { rh = widget->height(); - rw = widget->width(); pos = widget->mapToGlobal(QPoint(0, widget->height() - 2)); w = widget->width(); } - if ((pos.x() + rw) > (screen.x() + screen.width())) + if (w > screen.width()) + w = screen.width(); + if ((pos.x() + w) > (screen.x() + screen.width())) pos.setX(screen.x() + screen.width() - w); if (pos.x() < screen.x()) pos.setX(screen.x()); - if (((pos.y() + rh) > (screen.y() + screen.height())) && ((pos.y() - h - rh) >= 0)) - pos.setY(pos.y() - qMax(h, popup->minimumHeight()) - rh + 2); + + int top = pos.y() - rh - screen.top() + 2; + int bottom = screen.bottom() - pos.y(); + h = qMax(h, popup->minimumHeight()); + if (h > bottom) { + h = qMin(qMax(top, bottom), h); + + if (top > bottom) + pos.setY(pos.y() - h - rh + 2); + } popup->setGeometry(pos.x(), pos.y(), w, h); @@ -896,6 +918,17 @@ void QCompleterPrivate::showPopup(const QRect& rect) popup->show(); } +void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path) +{ + Q_Q(QCompleter); +#ifndef QT_NO_LINEEDIT + QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget); + //the path given by QFileSystemModel does not end with / + if (lineEdit && !lineEdit->text().isEmpty() && !q->completionPrefix().isEmpty() && q->completionPrefix() != path + QLatin1Char('/')) + q->complete(); +#endif +} + /*! Constructs a completer object with the given \a parent. */ @@ -976,7 +1009,7 @@ QWidget *QCompleter::widget() const be list model or a tree model. If a model has been already previously set and it has the QCompleter as its parent, it is deleted. - For convenience, if \a model is a QDirModel, QCompleter switches its + For convenience, if \a model is a QFileSystemModel, QCompleter switches its caseSensitivity to Qt::CaseInsensitive on Windows and Qt::CaseSensitive on other platforms. @@ -1000,6 +1033,18 @@ void QCompleter::setModel(QAbstractItemModel *model) #endif } #endif // QT_NO_DIRMODEL +#ifndef QT_NO_FILESYSTEMMODEL + QFileSystemModel *fsModel = qobject_cast<QFileSystemModel *>(model); + if (fsModel) { +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) + setCaseSensitivity(Qt::CaseInsensitive); +#else + setCaseSensitivity(Qt::CaseSensitive); +#endif + setCompletionRole(QFileSystemModel::FileNameRole); + connect(fsModel, SIGNAL(directoryLoaded(QString)), this, SLOT(_q_fileSystemModelDirectoryLoaded(QString))); + } +#endif // QT_NO_FILESYSTEMMODEL } /*! @@ -1083,7 +1128,7 @@ void QCompleter::setPopup(QAbstractItemView *popup) delete d->popup; if (popup->model() != d->proxy) popup->setModel(d->proxy); -#ifdef Q_OS_MAC +#if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA) popup->show(); #else popup->hide(); @@ -1631,10 +1676,11 @@ QAbstractItemModel *QCompleter::completionModel() const The default implementation returns the \l{Qt::EditRole}{edit role} of the item for list models. It returns the absolute file path if the model is a - QDirModel. + QFileSystemModel. \sa splitPath() */ + QString QCompleter::pathFromIndex(const QModelIndex& index) const { Q_D(const QCompleter); @@ -1644,16 +1690,27 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const QAbstractItemModel *sourceModel = d->proxy->sourceModel(); if (!sourceModel) return QString(); + bool isDirModel = false; + bool isFsModel = false; #ifndef QT_NO_DIRMODEL - QDirModel *dirModel = qobject_cast<QDirModel *>(sourceModel); - if (!dirModel) + isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0; +#endif +#ifndef QT_NO_FILESYSTEMMODEL + isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != 0; #endif + if (!isDirModel && !isFsModel) return sourceModel->data(index, d->role).toString(); QModelIndex idx = index; QStringList list; do { - QString t = sourceModel->data(idx, Qt::EditRole).toString(); + QString t; + if (isDirModel) + t = sourceModel->data(idx, Qt::EditRole).toString(); +#ifndef QT_NO_FILESYSTEMMODEL + else + t = sourceModel->data(idx, QFileSystemModel::FileNameRole).toString(); +#endif list.prepend(t); QModelIndex parent = idx.parent(); idx = parent.sibling(parent.row(), index.column()); @@ -1673,7 +1730,7 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const in the model(). The default implementation of splitPath() splits a file system path based on - QDir::separator() when the sourceModel() is a QDirModel. + QDir::separator() when the sourceModel() is a QFileSystemModel. When used with list models, the first item in the returned list is used for matching. @@ -1683,12 +1740,19 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const QStringList QCompleter::splitPath(const QString& path) const { bool isDirModel = false; + bool isFsModel = false; #ifndef QT_NO_DIRMODEL Q_D(const QCompleter); isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0; #endif +#ifndef QT_NO_FILESYSTEMMODEL +#ifdef QT_NO_DIRMODEL + Q_D(const QCompleter); +#endif + isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != 0; +#endif - if (!isDirModel || path.isEmpty()) + if ((!isDirModel && !isFsModel) || path.isEmpty()) return QStringList(completionPrefix()); QString pathCopy = QDir::toNativeSeparators(path); diff --git a/src/gui/util/qcompleter.h b/src/gui/util/qcompleter.h index 5123a40..0cef9be 100644 --- a/src/gui/util/qcompleter.h +++ b/src/gui/util/qcompleter.h @@ -159,6 +159,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex)) Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&)) Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup()) + Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&)) }; #endif // QT_NO_COMPLETER diff --git a/src/gui/util/qcompleter_p.h b/src/gui/util/qcompleter_p.h index 44be4c0..8f00793 100644 --- a/src/gui/util/qcompleter_p.h +++ b/src/gui/util/qcompleter_p.h @@ -98,6 +98,7 @@ public: void _q_complete(QModelIndex, bool = false); void _q_completionSelected(const QItemSelection&); void _q_autoResizePopup(); + void _q_fileSystemModelDirectoryLoaded(const QString &path); void setCurrentIndex(QModelIndex, bool = true); }; diff --git a/src/gui/util/qdesktopservices_s60.cpp b/src/gui/util/qdesktopservices_s60.cpp index 39240e6..cd023cb 100644 --- a/src/gui/util/qdesktopservices_s60.cpp +++ b/src/gui/util/qdesktopservices_s60.cpp @@ -39,9 +39,6 @@ ** ****************************************************************************/ -// This flag changes the implementation to use S60 CDcoumentHandler -// instead of apparch when opening the files -#define USE_DOCUMENTHANDLER #include <qcoreapplication.h> #include <qdir.h> @@ -56,10 +53,16 @@ #include <rsendas.h> // RSendAs #include <rsendasmessage.h> // RSendAsMessage +#ifdef Q_WS_S60 +// This flag changes the implementation to use S60 CDcoumentHandler +// instead of apparch when opening the files +#define USE_DOCUMENTHANDLER +#endif + // copied from miutset.h, so we don't get a dependency into the app layer const TUid KUidMsgTypeSMTP = {0x10001028}; // 268439592 -#ifdef Q_WS_S60 +#ifdef Q_OS_SYMBIAN # include <pathinfo.h> // PathInfo # ifdef USE_DOCUMENTHANDLER # include <DocumentHandler.h> // CDocumentHandler @@ -220,6 +223,7 @@ static void handleOtherSchemesL(const TDesC& aUrl) TApaTask task = taskList.FindApp(KUidBrowser); if (task.Exists()){ // Switch to existing browser instance + task.BringToForeground(); HBufC8* param8 = HBufC8::NewLC(buf16->Length()); param8->Des().Append(buf16->Des()); task.SendMessage(TUid::Uid( 0 ), *param8); // Uid is not used @@ -264,7 +268,7 @@ static TDriveUnit writableExeDrive() static TPtrC writableDataRoot() { TDriveUnit drive = exeDrive(); -#ifdef Q_WS_S60 +#ifdef Q_OS_SYMBIAN switch(drive.operator TInt()){ case EDriveC: return PathInfo::PhoneMemoryRootPath(); @@ -391,19 +395,19 @@ QString QDesktopServices::storageLocation(StandardLocation type) break; case MusicLocation: path.Append(writableDataRoot()); -#ifdef Q_WS_S60 +#ifdef Q_OS_SYMBIAN path.Append(PathInfo::SoundsPath()); #endif break; case MoviesLocation: path.Append(writableDataRoot()); -#ifdef Q_WS_S60 +#ifdef Q_OS_SYMBIAN path.Append(PathInfo::VideosPath()); #endif break; case PicturesLocation: path.Append(writableDataRoot()); -#ifdef Q_WS_S60 +#ifdef Q_OS_SYMBIAN path.Append(PathInfo::ImagesPath()); #endif break; @@ -415,11 +419,11 @@ QString QDesktopServices::storageLocation(StandardLocation type) //return QDir::homePath(); break; break; case DataLocation: - CEikonEnv::Static()->FsSession().PrivatePath(path); + qt_s60GetRFs().PrivatePath(path); path.Insert(0, writableExeDrive().Name()); break; case CacheLocation: - CEikonEnv::Static()->FsSession().PrivatePath(path); + qt_s60GetRFs().PrivatePath(path); path.Insert(0, writableExeDrive().Name()); path.Append(KCacheSubDir); break; diff --git a/src/gui/util/qdesktopservices_win.cpp b/src/gui/util/qdesktopservices_win.cpp index 359710f..735de04 100644 --- a/src/gui/util/qdesktopservices_win.cpp +++ b/src/gui/util/qdesktopservices_win.cpp @@ -59,7 +59,7 @@ # endif #endif -#if defined(Q_CC_MINGW) && !defined(CSIDL_MYMUSIC) +#ifndef CSIDL_MYMUSIC #define CSIDL_MYMUSIC 13 #define CSIDL_MYVIDEO 14 #endif @@ -97,19 +97,19 @@ static bool launchWebBrowser(const QUrl &url) if (url.scheme() == QLatin1String("mailto")) { //Retrieve the commandline for the default mail client //the default key used below is the command line for the mailto: shell command - DWORD bufferSize = 2 * MAX_PATH; + DWORD bufferSize = sizeof(wchar_t) * MAX_PATH; long returnValue = -1; QString command; HKEY handle; LONG res; - wchar_t keyValue[2 * MAX_PATH] = {0}; + wchar_t keyValue[MAX_PATH] = {0}; QString keyName(QLatin1String("mailto")); //Check if user has set preference, otherwise use default. - res = RegOpenKeyExW(HKEY_CURRENT_USER, - L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice", - 0, KEY_READ, &handle); + res = RegOpenKeyEx(HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice", + 0, KEY_READ, &handle); if (res == ERROR_SUCCESS) { returnValue = RegQueryValueEx(handle, L"Progid", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); if (!returnValue) @@ -121,8 +121,8 @@ static bool launchWebBrowser(const QUrl &url) if (res != ERROR_SUCCESS) return false; - bufferSize = 2 * MAX_PATH; - returnValue = RegQueryValueExW(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); + bufferSize = sizeof(wchar_t) * MAX_PATH; + returnValue = RegQueryValueEx(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(keyValue), &bufferSize); if (!returnValue) command = QString::fromRawData((QChar*)keyValue, bufferSize); RegCloseKey(handle); diff --git a/src/gui/util/qdesktopservices_x11.cpp b/src/gui/util/qdesktopservices_x11.cpp index fe7f9a6..75e7209 100644 --- a/src/gui/util/qdesktopservices_x11.cpp +++ b/src/gui/util/qdesktopservices_x11.cpp @@ -71,10 +71,12 @@ static bool openDocument(const QUrl &url) if (launch(url, QLatin1String("xdg-open"))) return true; - if (X11->desktopEnvironment == DE_GNOME && launch(url, QLatin1String("gnome-open"))) { + // Use the X11->desktopEnvironment value if X11 is non-NULL, + // otherwise just attempt to launch command regardless of the desktop environment + if ((!X11 || (X11 && X11->desktopEnvironment == DE_GNOME)) && launch(url, QLatin1String("gnome-open"))) { return true; } else { - if (X11->desktopEnvironment == DE_KDE && launch(url, QLatin1String("kfmclient exec"))) + if ((!X11 || (X11 && X11->desktopEnvironment == DE_KDE)) && launch(url, QLatin1String("kfmclient exec"))) return true; } @@ -104,10 +106,12 @@ static bool launchWebBrowser(const QUrl &url) if (launch(url, QString::fromLocal8Bit(getenv("BROWSER")))) return true; - if (X11->desktopEnvironment == DE_GNOME && launch(url, QLatin1String("gnome-open"))) { + // Use the X11->desktopEnvironment value if X11 is non-NULL, + // otherwise just attempt to launch command regardless of the desktop environment + if ((!X11 || (X11 && X11->desktopEnvironment == DE_GNOME)) && launch(url, QLatin1String("gnome-open"))) { return true; } else { - if (X11->desktopEnvironment == DE_KDE && launch(url, QLatin1String("kfmclient openURL"))) + if ((!X11 || (X11 && X11->desktopEnvironment == DE_KDE)) && launch(url, QLatin1String("kfmclient openURL"))) return true; } diff --git a/src/gui/util/qsystemtrayicon.cpp b/src/gui/util/qsystemtrayicon.cpp index d7dde87..941961b 100644 --- a/src/gui/util/qsystemtrayicon.cpp +++ b/src/gui/util/qsystemtrayicon.cpp @@ -356,10 +356,7 @@ bool QSystemTrayIcon::isSystemTrayAvailable() */ bool QSystemTrayIcon::supportsMessages() { -#if defined(Q_WS_QWS) - return false; -#endif - return true; + return QSystemTrayIconPrivate::supportsMessages_sys(); } /*! diff --git a/src/gui/util/qsystemtrayicon_mac.mm b/src/gui/util/qsystemtrayicon_mac.mm index d829947..22134cb 100644 --- a/src/gui/util/qsystemtrayicon_mac.mm +++ b/src/gui/util/qsystemtrayicon_mac.mm @@ -75,8 +75,6 @@ #define QT_MAC_SYSTEMTRAY_USE_GROWL -@class QNSMenu; - #include <private/qt_cocoa_helpers_mac_p.h> #include <private/qsystemtrayicon_p.h> #include <qtemporaryfile.h> @@ -93,35 +91,37 @@ extern bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret); //q extern void qtsystray_sendActivated(QSystemTrayIcon *i, int r); //qsystemtrayicon.cpp extern NSString *keySequenceToKeyEqivalent(const QKeySequence &accel); // qmenu_mac.mm extern NSUInteger keySequenceModifierMask(const QKeySequence &accel); // qmenu_mac.mm +extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); QT_END_NAMESPACE QT_USE_NAMESPACE -@class QNSImageView; +@class QT_MANGLE_NAMESPACE(QNSMenu); +@class QT_MANGLE_NAMESPACE(QNSImageView); -@interface QNSStatusItem : NSObject { +@interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject { NSStatusItem *item; QSystemTrayIcon *icon; QSystemTrayIconPrivate *iconPrivate; - QNSImageView *imageCell; + QT_MANGLE_NAMESPACE(QNSImageView) *imageCell; } -(id)initWithIcon:(QSystemTrayIcon*)icon iconPrivate:(QSystemTrayIconPrivate *)iprivate; -(void)dealloc; -(QSystemTrayIcon*)icon; -(NSStatusItem*)item; -(QRectF)geometry; -- (void)triggerSelector:(id)sender; +- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton; - (void)doubleClickSelector:(id)sender; @end -@interface QNSImageView : NSImageView { +@interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView { BOOL down; - QNSStatusItem *parent; + QT_MANGLE_NAMESPACE(QNSStatusItem) *parent; } --(id)initWithParent:(QNSStatusItem*)myParent; +-(id)initWithParent:(QT_MANGLE_NAMESPACE(QNSStatusItem)*)myParent; -(QSystemTrayIcon*)icon; -(void)menuTrackingDone:(NSNotification*)notification; --(void)mousePressed:(NSEvent *)mouseEvent; +-(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton; @end @@ -133,7 +133,7 @@ QT_USE_NAMESPACE #endif -@interface QNSMenu : NSMenu <NSMenuDelegate> { +@interface QT_MANGLE_NAMESPACE(QNSMenu) : NSMenu <NSMenuDelegate> { QMenu *qmenu; } -(QMenu*)menu; @@ -147,14 +147,14 @@ class QSystemTrayIconSys public: QSystemTrayIconSys(QSystemTrayIcon *icon, QSystemTrayIconPrivate *d) { QMacCocoaAutoReleasePool pool; - item = [[QNSStatusItem alloc] initWithIcon:icon iconPrivate:d]; + item = [[QT_MANGLE_NAMESPACE(QNSStatusItem) alloc] initWithIcon:icon iconPrivate:d]; } ~QSystemTrayIconSys() { QMacCocoaAutoReleasePool pool; [[[item item] view] setHidden: YES]; [item release]; } - QNSStatusItem *item; + QT_MANGLE_NAMESPACE(QNSStatusItem) *item; }; void QSystemTrayIconPrivate::install_sys() @@ -226,6 +226,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return true; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return true; +} + void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int) { @@ -298,8 +303,8 @@ QT_END_NAMESPACE @implementation NSStatusItem (Qt) @end -@implementation QNSImageView --(id)initWithParent:(QNSStatusItem*)myParent { +@implementation QT_MANGLE_NAMESPACE(QNSImageView) +-(id)initWithParent:(QT_MANGLE_NAMESPACE(QNSStatusItem)*)myParent { self = [super init]; parent = myParent; down = NO; @@ -333,12 +338,10 @@ QT_END_NAMESPACE [self setNeedsDisplay:YES]; } --(void)mousePressed:(NSEvent *)mouseEvent +-(void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton { - int clickCount = [mouseEvent clickCount]; - down = !down; - if(!down && [self icon]->contextMenu()) - [self icon]->contextMenu()->hide(); + down = YES; + int clickCount = [mouseEvent clickCount]; [self setNeedsDisplay:YES]; #ifndef QT_MAC_USE_COCOA @@ -348,47 +351,52 @@ QT_END_NAMESPACE const short scale = hgt - 4; #endif - if( down && ![self icon]->icon().isNull() ) { + if (![self icon]->icon().isNull() ) { NSImage *nsaltimage = static_cast<NSImage *>(qt_mac_create_nsimage([self icon]->icon().pixmap(QSize(scale, scale), QIcon::Selected))); [self setImage: nsaltimage]; [nsaltimage release]; } - - if (down) - [parent triggerSelector:self]; - else if ((clickCount%2)) + if ((clickCount == 2)) { + [self menuTrackingDone:nil]; [parent doubleClickSelector:self]; - while (down) { - mouseEvent = [[self window] nextEventMatchingMask:NSLeftMouseDownMask | NSLeftMouseUpMask - | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseUpMask - | NSRightMouseDraggedMask]; - switch ([mouseEvent type]) { - case NSRightMouseDown: - case NSRightMouseUp: - case NSLeftMouseDown: - case NSLeftMouseUp: - [self menuTrackingDone:nil]; - break; - case NSRightMouseDragged: - case NSLeftMouseDragged: - default: - /* Ignore any other kind of event. */ - break; - } - }; + } else { + [parent triggerSelector:self button:mouseButton]; + } } -(void)mouseDown:(NSEvent *)mouseEvent { - [self mousePressed:mouseEvent]; + [self mousePressed:mouseEvent button:Qt::LeftButton]; +} + +-(void)mouseUp:(NSEvent *)mouseEvent +{ + Q_UNUSED(mouseEvent); + [self menuTrackingDone:nil]; } - (void)rightMouseDown:(NSEvent *)mouseEvent { - [self mousePressed:mouseEvent]; + [self mousePressed:mouseEvent button:Qt::RightButton]; +} + +-(void)rightMouseUp:(NSEvent *)mouseEvent +{ + Q_UNUSED(mouseEvent); + [self menuTrackingDone:nil]; } +- (void)otherMouseDown:(NSEvent *)mouseEvent +{ + [self mousePressed:mouseEvent button:cocoaButton2QtButton([mouseEvent buttonNumber])]; +} + +-(void)otherMouseUp:(NSEvent *)mouseEvent +{ + Q_UNUSED(mouseEvent); + [self menuTrackingDone:nil]; +} -(void)drawRect:(NSRect)rect { [[parent item] drawStatusBarBackgroundInRect:rect withHighlight:down]; @@ -396,7 +404,7 @@ QT_END_NAMESPACE } @end -@implementation QNSStatusItem +@implementation QT_MANGLE_NAMESPACE(QNSStatusItem) -(id)initWithIcon:(QSystemTrayIcon*)i iconPrivate:(QSystemTrayIconPrivate *)iPrivate { @@ -405,7 +413,7 @@ QT_END_NAMESPACE icon = i; iconPrivate = iPrivate; item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; - imageCell = [[QNSImageView alloc] initWithParent:self]; + imageCell = [[QT_MANGLE_NAMESPACE(QNSImageView) alloc] initWithParent:self]; [item setView: imageCell]; } return self; @@ -433,45 +441,40 @@ QT_END_NAMESPACE } return QRectF(); } -- (void)triggerSelector:(id)sender { + +- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton { Q_UNUSED(sender); - if(!icon) + if (!icon) return; - qtsystray_sendActivated(icon, QSystemTrayIcon::Trigger); + + if (mouseButton == Qt::MidButton) + qtsystray_sendActivated(icon, QSystemTrayIcon::MiddleClick); + else + qtsystray_sendActivated(icon, QSystemTrayIcon::Trigger); + if (icon->contextMenu()) { -#if 0 - const QRectF geom = [self geometry]; - if(!geom.isNull()) { - [[NSNotificationCenter defaultCenter] addObserver:imageCell - selector:@selector(menuTrackingDone:) - name:nil - object:self]; - icon->contextMenu()->exec(geom.topLeft().toPoint(), 0); - [imageCell menuTrackingDone:nil]; - } else -#endif - { #ifndef QT_MAC_USE_COCOA - [[[self item] view] removeAllToolTips]; - iconPrivate->updateToolTip_sys(); + [[[self item] view] removeAllToolTips]; + iconPrivate->updateToolTip_sys(); #endif - NSMenu *m = [[QNSMenu alloc] initWithQMenu:icon->contextMenu()]; - [m setAutoenablesItems: NO]; - [[NSNotificationCenter defaultCenter] addObserver:imageCell - selector:@selector(menuTrackingDone:) - name:NSMenuDidEndTrackingNotification - object:m]; - [item popUpStatusItemMenu: m]; - [m release]; - } + NSMenu *m = [[QT_MANGLE_NAMESPACE(QNSMenu) alloc] initWithQMenu:icon->contextMenu()]; + [m setAutoenablesItems: NO]; + [[NSNotificationCenter defaultCenter] addObserver:imageCell + selector:@selector(menuTrackingDone:) + name:NSMenuDidEndTrackingNotification + object:m]; + [item popUpStatusItemMenu: m]; + [m release]; } } + - (void)doubleClickSelector:(id)sender { Q_UNUSED(sender); if(!icon) return; qtsystray_sendActivated(icon, QSystemTrayIcon::DoubleClick); } + @end class QSystemTrayIconQMenu : public QMenu @@ -482,7 +485,7 @@ private: QSystemTrayIconQMenu(); }; -@implementation QNSMenu +@implementation QT_MANGLE_NAMESPACE(QNSMenu) -(id)initWithQMenu:(QMenu*)qm { self = [super init]; if(self) { @@ -495,7 +498,7 @@ private: return qmenu; } -(void)menuNeedsUpdate:(NSMenu*)nsmenu { - QNSMenu *menu = static_cast<QNSMenu *>(nsmenu); + QT_MANGLE_NAMESPACE(QNSMenu) *menu = static_cast<QT_MANGLE_NAMESPACE(QNSMenu) *>(nsmenu); emit static_cast<QSystemTrayIconQMenu*>(menu->qmenu)->doAboutToShow(); for(int i = [menu numberOfItems]-1; i >= 0; --i) [menu removeItemAtIndex:i]; @@ -540,7 +543,7 @@ private: [nsimage release]; } if(action->menu()) { - QNSMenu *sub = [[QNSMenu alloc] initWithQMenu:action->menu()]; + QT_MANGLE_NAMESPACE(QNSMenu) *sub = [[QT_MANGLE_NAMESPACE(QNSMenu) alloc] initWithQMenu:action->menu()]; [item setSubmenu:sub]; } else { [item setAction:@selector(selectedAction:)]; diff --git a/src/gui/util/qsystemtrayicon_p.h b/src/gui/util/qsystemtrayicon_p.h index e8bf197..4592e43 100644 --- a/src/gui/util/qsystemtrayicon_p.h +++ b/src/gui/util/qsystemtrayicon_p.h @@ -83,7 +83,9 @@ public: void updateMenu_sys(); QRect geometry_sys() const; void showMessage_sys(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs); + static bool isSystemTrayAvailable_sys(); + static bool supportsMessages_sys(); QPointer<QMenu> menu; QIcon icon; diff --git a/src/gui/util/qsystemtrayicon_qws.cpp b/src/gui/util/qsystemtrayicon_qws.cpp index b1b895b..cda47aa 100644 --- a/src/gui/util/qsystemtrayicon_qws.cpp +++ b/src/gui/util/qsystemtrayicon_qws.cpp @@ -75,6 +75,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return false; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return false; +} + void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QString &title, QSystemTrayIcon::MessageIcon icon, diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp index 6e78dfd..fc5de44 100644 --- a/src/gui/util/qsystemtrayicon_win.cpp +++ b/src/gui/util/qsystemtrayicon_win.cpp @@ -41,24 +41,21 @@ #include "qsystemtrayicon_p.h" #ifndef QT_NO_SYSTEMTRAYICON -#define _WIN32_IE 0x0600 //required for NOTIFYICONDATA_V2_SIZE -//missing defines for MINGW : -#ifndef NIN_BALLOONTIMEOUT -#define NIN_BALLOONTIMEOUT (WM_USER + 4) +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 #endif -#ifndef NIN_BALLOONUSERCLICK -#define NIN_BALLOONUSERCLICK (WM_USER + 5) + +#ifndef _WIN32_IE +#define _WIN32_IE 0x600 #endif #include <qt_windows.h> +#include <windowsx.h> #include <commctrl.h> -#include <shlwapi.h> -#include <QBitmap> + #include <private/qsystemlibrary_p.h> #include <QApplication> -#include <QToolTip> -#include <QDesktopWidget> #include <QSettings> QT_BEGIN_NAMESPACE @@ -75,6 +72,30 @@ struct Q_NOTIFYICONIDENTIFIER { GUID guidItem; }; +#ifndef NOTIFYICON_VERSION_4 +#define NOTIFYICON_VERSION_4 4 +#endif + +#ifndef NIN_SELECT +#define NIN_SELECT (WM_USER + 0) +#endif + +#ifndef NIN_KEYSELECT +#define NIN_KEYSELECT (WM_USER + 1) +#endif + +#ifndef NIN_BALLOONTIMEOUT +#define NIN_BALLOONTIMEOUT (WM_USER + 4) +#endif + +#ifndef NIN_BALLOONUSERCLICK +#define NIN_BALLOONUSERCLICK (WM_USER + 5) +#endif + +#ifndef NIF_SHOWTIP +#define NIF_SHOWTIP 0x00000080 +#endif + #define Q_MSGFLT_ALLOW 1 typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation); @@ -88,11 +109,8 @@ public: ~QSystemTrayIconSys(); bool winEvent( MSG *m, long *result ); bool trayMessage(DWORD msg); - bool iconDrawItem(LPDRAWITEMSTRUCT lpdi); void setIconContents(NOTIFYICONDATA &data); bool showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs); - bool allowsMessages(); - bool supportsMessages(); QRect findIconGeometry(const int a_iButtonID); void createIcon(); HICON hIcon; @@ -101,10 +119,11 @@ public: private: uint notifyIconSize; int maxTipLength; + int version; bool ignoreNextMouseRelease; }; -bool QSystemTrayIconSys::allowsMessages() +static bool allowsMessages() { #ifndef QT_NO_SETTINGS QSettings settings(QLatin1String("HKEY_CURRENT_USER\\Software\\Microsoft" @@ -115,16 +134,18 @@ bool QSystemTrayIconSys::allowsMessages() #endif } -bool QSystemTrayIconSys::supportsMessages() -{ - return allowsMessages(); -} - QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *object) : hIcon(0), q(object), ignoreNextMouseRelease(false) { - notifyIconSize = FIELD_OFFSET(NOTIFYICONDATA, guidItem); // NOTIFYICONDATAW_V2_SIZE; + if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) { + notifyIconSize = sizeof(NOTIFYICONDATA); + version = NOTIFYICON_VERSION_4; + } else { + notifyIconSize = NOTIFYICONDATA_V2_SIZE; + version = NOTIFYICON_VERSION; + } + maxTipLength = 128; // For restoring the tray icon after explorer crashes @@ -158,7 +179,7 @@ QSystemTrayIconSys::~QSystemTrayIconSys() void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) { - tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + tnd.uFlags |= NIF_MESSAGE | NIF_ICON | NIF_TIP; tnd.uCallbackMessage = MYWM_NOTIFYICON; tnd.hIcon = hIcon; QString tip = q->toolTip(); @@ -171,7 +192,6 @@ void QSystemTrayIconSys::setIconContents(NOTIFYICONDATA &tnd) static int iconFlag( QSystemTrayIcon::MessageIcon icon ) { -#if NOTIFYICON_VERSION >= 3 switch (icon) { case QSystemTrayIcon::Information: return NIIF_INFO; @@ -185,20 +205,13 @@ static int iconFlag( QSystemTrayIcon::MessageIcon icon ) Q_ASSERT_X(false, "QSystemTrayIconSys::showMessage", "Invalid QSystemTrayIcon::MessageIcon value"); return NIIF_NONE; } -#else - Q_UNUSED(icon); - return 0; -#endif } bool QSystemTrayIconSys::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs) { -#if NOTIFYICON_VERSION >= 3 NOTIFYICONDATA tnd; memset(&tnd, 0, notifyIconSize); - Q_ASSERT(testAttribute(Qt::WA_WState_Created)); - setIconContents(tnd); memcpy(tnd.szInfo, message.utf16(), qMin(message.length() + 1, 256) * sizeof(wchar_t)); memcpy(tnd.szInfoTitle, title.utf16(), qMin(title.length() + 1, 64) * sizeof(wchar_t)); @@ -207,42 +220,36 @@ bool QSystemTrayIconSys::showMessage(const QString &title, const QString &messag tnd.cbSize = notifyIconSize; tnd.hWnd = winId(); tnd.uTimeout = uSecs; - tnd.uFlags = NIF_INFO; + tnd.uFlags = NIF_INFO | NIF_SHOWTIP; + + Q_ASSERT(testAttribute(Qt::WA_WState_Created)); return Shell_NotifyIcon(NIM_MODIFY, &tnd); -#else - Q_UNUSED(title); - Q_UNUSED(message); - Q_UNUSED(type); - Q_UNUSED(uSecs); - return false; -#endif } bool QSystemTrayIconSys::trayMessage(DWORD msg) { NOTIFYICONDATA tnd; memset(&tnd, 0, notifyIconSize); + tnd.uID = q_uNOTIFYICONID; tnd.cbSize = notifyIconSize; tnd.hWnd = winId(); + tnd.uFlags = NIF_SHOWTIP; + tnd.uVersion = version; Q_ASSERT(testAttribute(Qt::WA_WState_Created)); - if (msg != NIM_DELETE) { + if (msg == NIM_ADD || msg == NIM_MODIFY) { setIconContents(tnd); } - return Shell_NotifyIcon(msg, &tnd); -} + bool success = Shell_NotifyIcon(msg, &tnd); -bool QSystemTrayIconSys::iconDrawItem(LPDRAWITEMSTRUCT lpdi) -{ - if (!hIcon) - return false; - - DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, 0, DI_NORMAL); - return true; + if (msg == NIM_ADD) + return success && Shell_NotifyIcon(NIM_SETVERSION, &tnd); + else + return success; } void QSystemTrayIconSys::createIcon() @@ -265,27 +272,24 @@ void QSystemTrayIconSys::createIcon() bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) { switch(m->message) { - case WM_CREATE: -#ifdef GWLP_USERDATA - SetWindowLongPtr(winId(), GWLP_USERDATA, (LONG_PTR)((CREATESTRUCTW*)m->lParam)->lpCreateParams); -#else - SetWindowLong(winId(), GWL_USERDATA, (LONG)((CREATESTRUCTW*)m->lParam)->lpCreateParams); -#endif - break; - - case WM_DRAWITEM: - return iconDrawItem((LPDRAWITEMSTRUCT)m->lParam); - case MYWM_NOTIFYICON: { - RECT r; - GetWindowRect(winId(), &r); - QEvent *e = 0; - Qt::KeyboardModifiers keys = QApplication::keyboardModifiers(); - QPoint gpos = QCursor::pos(); - - switch (m->lParam) { - case WM_LBUTTONUP: + int message = 0; + QPoint gpos; + + if (version == NOTIFYICON_VERSION_4) { + Q_ASSERT(q_uNOTIFYICONID == HIWORD(m->lParam)); + message = LOWORD(m->lParam); + gpos = QPoint(GET_X_LPARAM(m->wParam), GET_Y_LPARAM(m->wParam)); + } else { + Q_ASSERT(q_uNOTIFYICONID == m->wParam); + message = m->lParam; + gpos = QCursor::pos(); + } + + switch (message) { + case NIN_SELECT: + case NIN_KEYSELECT: if (ignoreNextMouseRelease) ignoreNextMouseRelease = false; else @@ -298,11 +302,9 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) emit q->activated(QSystemTrayIcon::DoubleClick); break; - case WM_RBUTTONUP: + case WM_CONTEXTMENU: if (q->contextMenu()) { q->contextMenu()->popup(gpos); - q->contextMenu()->activateWindow(); - //Must be activated for proper keyboardfocus and menu closing on windows: } emit q->activated(QSystemTrayIcon::Context); break; @@ -314,13 +316,9 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case WM_MBUTTONUP: emit q->activated(QSystemTrayIcon::MiddleClick); break; + default: - break; - } - if (e) { - bool res = QApplication::sendEvent(q, e); - delete e; - return res; + break; } break; } @@ -444,7 +442,7 @@ QRect QSystemTrayIconSys::findIconGeometry(const int iconId) void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, int timeOut) { - if (!sys || !sys->allowsMessages()) + if (!sys || !allowsMessages()) return; uint uSecs = 0; @@ -462,21 +460,14 @@ void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString //title is limited to 63 chars + NULL QString titleString = title.left(63) + QChar(); - if (sys->supportsMessages()) { - sys->showMessage(titleString, messageString, type, (unsigned int)uSecs); - } else { - //use fallback - QRect iconPos = sys->findIconGeometry(q_uNOTIFYICONID); - if (iconPos.isValid()) { - QBalloonTip::showBalloon(type, title, message, sys->q, iconPos.center(), uSecs, true); - } - } + sys->showMessage(titleString, messageString, type, uSecs); } QRect QSystemTrayIconPrivate::geometry_sys() const { if (!sys) return QRect(); + return sys->findIconGeometry(q_uNOTIFYICONID); } @@ -522,6 +513,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return true; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return allowsMessages(); +} + QT_END_NAMESPACE #endif diff --git a/src/gui/util/qsystemtrayicon_wince.cpp b/src/gui/util/qsystemtrayicon_wince.cpp index b74420d..e5cf0fd 100644 --- a/src/gui/util/qsystemtrayicon_wince.cpp +++ b/src/gui/util/qsystemtrayicon_wince.cpp @@ -155,10 +155,6 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case MYWM_NOTIFYICON: { - RECT r; - GetWindowRect(winId(), &r); - QEvent *e = 0; - Qt::KeyboardModifiers keys = QApplication::keyboardModifiers(); QPoint gpos = QCursor::pos(); switch (m->lParam) { @@ -186,9 +182,6 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) gpos.ry() = maxY; q->contextMenu()->move(gpos); } - - q->contextMenu()->activateWindow(); - //Must be activated for proper keyboardfocus and menu closing on windows: } emit q->activated(QSystemTrayIcon::Context); break; @@ -196,14 +189,10 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) case WM_MBUTTONUP: emit q->activated(QSystemTrayIcon::MiddleClick); break; + default: break; } - if (e) { - bool res = QApplication::sendEvent(q, e); - delete e; - return res; - } break; } default: @@ -294,6 +283,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return true; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return true; +} + QT_END_NAMESPACE #endif diff --git a/src/gui/util/qsystemtrayicon_x11.cpp b/src/gui/util/qsystemtrayicon_x11.cpp index 82b4325..59fdc07 100644 --- a/src/gui/util/qsystemtrayicon_x11.cpp +++ b/src/gui/util/qsystemtrayicon_x11.cpp @@ -381,6 +381,11 @@ bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() return QSystemTrayIconSys::locateSystemTray() != XNone; } +bool QSystemTrayIconPrivate::supportsMessages_sys() +{ + return true; +} + void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QString &title, QSystemTrayIcon::MessageIcon icon, int msecs) { diff --git a/src/gui/util/util.pri b/src/gui/util/util.pri index 7344fbd..bea520e 100644 --- a/src/gui/util/util.pri +++ b/src/gui/util/util.pri @@ -43,6 +43,12 @@ embedded { } symbian { - LIBS += -lsendas2 -letext -lapmime - contains(QT_CONFIG, s60): LIBS += -lplatformenv -lCommonUI + LIBS += -lsendas2 -letext -lapmime -lplatformenv + contains(QT_CONFIG, s60) { + contains(CONFIG, is_using_gnupoc) { + LIBS += -lcommonui + } else { + LIBS += -lCommonUI + } + } } |