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: if (ignoreNextMouseRelease) ignoreNextMouseRelease = false; else emit q->activated(QSystemTrayIcon::Trigger); break; case WM_LBUTTONDBLCLK: ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse // release we must ignore it emit q->activated(QSystemTrayIcon::DoubleClick); break; case WM_RBUTTONUP: if (q->contextMenu()) { q->contextMenu()->popup(gpos); #if defined(Q_WS_WINCE) // We must ensure that the popup menu doesn't show up behind the task bar. QRect desktopRect = qApp->desktop()->availableGeometry(); int maxY = desktopRect.y() + desktopRect.height() - q->contextMenu()->height(); if (gpos.y() > maxY) { gpos.ry() = maxY; q->contextMenu()->move(gpos); } #endif q->contextMenu()->activateWindow(); //Must be activated for proper keyboardfocus and menu closing on windows: } emit q->activated(QSystemTrayIcon::Context); break; #if !defined(Q_WS_WINCE) case NIN_BALLOONUSERCLICK: emit q->messageClicked(); break; #endif 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: if (m->message == MYWM_TASKBARCREATED) trayMessage(NIM_ADD); else return QWidget::winEvent(m, result); break; } return 0; }
bool QSystemTrayIconSys::winEvent( MSG *m, long *result ) { switch(m->message) { case MYWM_NOTIFYICON: { 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 emit q->activated(QSystemTrayIcon::Trigger); break; case WM_LBUTTONDBLCLK: ignoreNextMouseRelease = true; // Since DBLCLICK Generates a second mouse // release we must ignore it emit q->activated(QSystemTrayIcon::DoubleClick); break; case WM_CONTEXTMENU: if (q->contextMenu()) { q->contextMenu()->popup(gpos); q->contextMenu()->activateWindow(); } emit q->activated(QSystemTrayIcon::Context); break; case NIN_BALLOONUSERCLICK: emit q->messageClicked(); break; case WM_MBUTTONUP: emit q->activated(QSystemTrayIcon::MiddleClick); break; default: break; } break; } default: if (m->message == MYWM_TASKBARCREATED) trayMessage(NIM_ADD); else return QWidget::winEvent(m, result); break; } return 0; }
/*! * \param name Window name * \param type Window type (see constants.h for WT_*) * \param parent Parent ID (typically connection ID) * \param activate Activate window on creation * * Creates a new subwindow.\n * Specify Parent 0 if it's a custom (scriptable window).\n * DCC windows sets their parent to the IConnection that created it. It won't be a child of this IConnection though. * \return -1 if failed, otherwise Window ID */ int IdealIRC::CreateSubWindow(QString name, int type, int parent, bool activate) { if (WindowExists(name, parent) == true) return -1; qDebug() << "Creating new subwindow type " << type << " name " << name; IWin *s; if ((type >= WT_DCCSEND) && (type <= WT_DCCCHAT)) { IConnection *c = conlist.value(parent, NULL); s = new IWin(ui->mdiArea, name, type, &conf, &scriptParent, c); parent = 0; } else s = new IWin(ui->mdiArea, name, type, &conf, &scriptParent); IConnection *connection = conlist.value(parent, NULL); if (type == WT_STATUS) { qDebug() << "Window is status, new connection added with id " << s->getId(); connection = new IConnection(this, &chanlist, s->getId(), &conf, &scriptParent, &wsw); connection->setActiveInfo(&activeWname, &activeConn); connect(connection, SIGNAL(connectionClosed()), this, SLOT(connectionClosed())); connect(connection, SIGNAL(connectedToIRC()), this, SLOT(connectionEstablished())); connect(connection, SIGNAL(RequestTrayMsg(QString,QString)), this, SLOT(trayMessage(QString,QString))); } qDebug() << "Connection added, setting pointers"; s->setConnectionPtr(connection); if (connection != NULL) s->setSortRuleMap(connection->getSortRuleMapPtr()); qDebug() << "Pointers set, setting up mdiSubWindow"; QMdiSubWindow *previous = ui->mdiArea->currentSubWindow(); QMdiSubWindow *sw = ui->mdiArea->addSubWindow(s, Qt::SubWindow); qDebug() << "Pointer to subwindow: " << sw; qDebug() << "Icon..."; // Add icon to window QString ico = ":/window/gfx/custom.png"; // Default to this. if (type == WT_PRIVMSG) ico = ":/window/gfx/query.png"; if (type == WT_CHANNEL) ico = ":/window/gfx/channel.png"; if (type == WT_STATUS) ico = ":/window/gfx/status.png"; sw->setWindowIcon(QIcon(ico)); qDebug() << "Treeitem..."; QTreeWidgetItem *treeitem = GetWidgetItem(parent); if (treeitem == NULL) treeitem = new QTreeWidgetItem(ui->treeWidget); else treeitem = new QTreeWidgetItem(treeitem); treeitem->setIcon(0, QIcon(ico)); treeitem->setText(0, name); treeitem->setToolTip(0, name); qDebug() << "subwindow_t instance..."; subwindow_t wt; wt.connection = connection; wt.parent = parent; wt.subwin = sw; wt.treeitem = treeitem; wt.type = type; wt.wid = s->getId(); wt.widget = s; wt.highlight = HL_NONE; qDebug() << "Adding subwindow_t to winlist..."; winlist.insert(s->getId(), wt); wsw.addWindow(type, name, wt.wid, parent); sw->setGeometry(0, 0, 500, 400); if (type == WT_STATUS) { qDebug() << "Adding connection to the list..."; // The Connection class ID is the exact same ID as the status window ID. conlist.insert(s->getId(), connection); treeitem->setExpanded(true); connection->addWindow("STATUS", wt); connect(connection, SIGNAL(RequestWindow(QString,int,int,bool)), this, SLOT(CreateSubWindow(QString,int,int,bool))); connect(connection, SIGNAL(HighlightWindow(int,int)), this, SLOT(Highlight(int,int))); }