void CTreeView::OnContextMenu(HWND /*hWnd*/, CPoint pt) { if (pt == CPoint(-1, -1)) { RECT rect; GetItemRect(GetSelectedItem(), &rect, true); pt = CPoint(rect.left, rect.bottom - 1); } else { ScreenToClient(&pt); } UINT flags = 0; HTREEITEM hItem = HitTest(pt, &flags); if ((flags & TVHT_ONITEM) == 0) return; SelectItem(hItem); CMenu menuContext; menuContext.LoadMenu(IDR_TREE_CONTEXTMENU); CMenuHandle menuPopup(menuContext.GetSubMenu(0)); ClientToScreen(&pt); menuPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, *m_pMainFrame); }
LRESULT COutputView::OnMsgViewContextMenu(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) { UINT ContextMenuID = (UINT)wParam; CMenu menuContext; menuContext.LoadMenu(IDR_OUTPUT_CONTEXT); CMenuHandle menuPopup(menuContext.GetSubMenu(0)); POINT pt; ::GetCursorPos(&pt); m_CmdBar.TrackPopupMenu(menuPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y); //::TrackPopupMenu(menuPopup, 0, pt.x, pt.y, 0, m_hWnd, NULL); return 0; // ignored. }
void SampleCodeDlg::OnContextMenu(CWindow /*wnd*/, CPoint pt) { CHARRANGE selRange; m_sample.GetSel(selRange); if (pt == CPoint(-1, -1)) pt = m_sample.PosFromChar(selRange.cpMin); else m_sample.ScreenToClient(&pt); CRect rect; m_sample.GetClientRect(&rect); if (!rect.PtInRect(pt)) return; if (selRange.cpMin == selRange.cpMax) m_sample.SetSel(0, -1); CMenu menuContext; menuContext.LoadMenu(IDR_SAMPLE_CONTEXTMENU); CMenuHandle menuPopup(menuContext.GetSubMenu(0)); m_sample.ClientToScreen(&pt); menuPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, *this); }
void SampleContextMenu(CWindow wnd, CRichEditCtrl& ctrl, CPoint pt) { CHARRANGE selRange; ctrl.GetSel(selRange); if (pt == CPoint(-1, -1)) pt = ctrl.PosFromChar(selRange.cpMin); else ctrl.ScreenToClient(&pt); CRect rect; ctrl.GetClientRect(&rect); if (!rect.PtInRect(pt)) return; if (selRange.cpMin == selRange.cpMax) ctrl.SetSel(0, -1); CMenu menuContext; menuContext.LoadMenu(IDR_SAMPLE_CONTEXTMENU); CMenuHandle menuPopup(menuContext.GetSubMenu(0)); ctrl.ClientToScreen(&pt); menuPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, wnd); }
void CLogView::OnContextMenu(HWND /*hWnd*/, CPoint pt) { if (pt == CPoint(-1, -1)) { RECT rect; GetItemRect(GetNextItem(-1, LVNI_ALL | LVNI_FOCUSED), &rect, LVIR_LABEL); pt = CPoint(rect.left, rect.bottom - 1); } else { ScreenToClient(&pt); } UINT flags = 0; HitTest(pt, &flags); if ((flags & LVHT_ONITEM) == 0) return; CMenu menuContext; menuContext.LoadMenu(IDR_LIST_CONTEXTMENU); CMenuHandle menuPopup(menuContext.GetSubMenu(0)); ClientToScreen(&pt); menuPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, *m_pMainFrame); }
LRESULT CMainFrame::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // if((HWND)wParam == m_viewScript.m_hWnd) { CMenu menuContext; menuContext.LoadMenu(IDR_CONTEXTMENU); CMenuHandle menuPopup(menuContext.GetSubMenu(0)); // UIUpdateMenuBar(); // menuPopup.EnableMenuItem(ID_EDIT_CUT, FALSE); // menuPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, LOWORD(lParam), HIWORD(lParam), m_hWnd); // menuPopup.EnableMenuItem(ID_EDIT_CUT, FALSE); m_CmdBar.TrackPopupMenu(menuPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, LOWORD(lParam), HIWORD(lParam)); // UIUpdateMenuBar(); } /* else { bHandled = FALSE; }*/ return 0; }
ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(context) { // left / right scroller icon static QIcon leftIcon = iconFromPNG(":images/mac/left.png"); static QIcon rightIcon = iconFromPNG(":images/mac/right.png"); setContentsMargins(0,0,0,0); // main layout QHBoxLayout *mlayout = new QHBoxLayout(this); mlayout->setSpacing(0); mlayout->setContentsMargins(0,0,0,0); // buttonBar Widget buttonBar = new ButtonBar(this); buttonBar->setFixedHeight(23); buttonBar->setContentsMargins(0,0,0,0); QHBoxLayout *vlayout = new QHBoxLayout(buttonBar); vlayout->setSpacing(0); vlayout->setContentsMargins(0,0,0,0); layout = new QHBoxLayout; layout->setSpacing(2); layout->setContentsMargins(0,0,0,0); vlayout->addLayout(layout); vlayout->addStretch(); // scrollarea scrollArea = new QScrollArea(this); scrollArea->setAutoFillBackground(false); scrollArea->setWidgetResizable(true); scrollArea->setFrameStyle(QFrame::NoFrame); scrollArea->setContentsMargins(0,0,0,0); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setWidget(buttonBar); // scroll area turns it on .. we turn it off! buttonBar->setAutoFillBackground(false); // scroller buttons left = new QToolButton(this); left->setStyleSheet("QToolButton { border: none; padding: 0px; }"); left->setAutoFillBackground(false); left->setFixedSize(20,20); left->setIcon(leftIcon); left->setIconSize(QSize(20,20)); left->setFocusPolicy(Qt::NoFocus); mlayout->addWidget(left); connect(left, SIGNAL(clicked()), this, SLOT(scrollLeft())); // menu bar in the middle of the buttons mlayout->addWidget(scrollArea); right = new QToolButton(this); right->setStyleSheet("QToolButton { border: none; padding: 0px; }"); right->setAutoFillBackground(false); right->setFixedSize(20,20); right->setIcon(rightIcon); right->setIconSize(QSize(20,20)); right->setFocusPolicy(Qt::NoFocus); mlayout->addWidget(right); connect(right, SIGNAL(clicked()), this, SLOT(scrollRight())); // spacer to make the menuButton on the right QLabel *spacer = new QLabel("", this); spacer->setAutoFillBackground(false); spacer->setFixedHeight(20); spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); mlayout->addWidget(spacer); menuButton = new QToolButton(this); menuButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); menuButton->setAutoFillBackground(false); menuButton->setFixedSize(20,20); menuButton->setIcon(iconFromPNG(":images/sidebar/extra.png")); menuButton->setIconSize(QSize(10,10)); menuButton->setFocusPolicy(Qt::NoFocus); mlayout->addWidget(menuButton); //connect(p, SIGNAL(clicked()), action, SLOT(trigger())); QFontMetrics fs(buttonFont); #ifdef Q_OS_MAC setFixedHeight(fs.height()+7); scrollArea->setFixedHeight(fs.height()+7); buttonBar->setFixedHeight(fs.height()+7); #else setFixedHeight(fs.height()+4); scrollArea->setFixedHeight(fs.height()+4); buttonBar->setFixedHeight(fs.height()+4); #endif signalMapper = new QSignalMapper(this); // maps each option connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(clicked(int))); barMenu = new QMenu("Add"); chartMenu = barMenu->addMenu(tr("Add Chart")); // menu connect(menuButton, SIGNAL(clicked()), this, SLOT(menuPopup())); connect(chartMenu, SIGNAL(aboutToShow()), this, SLOT(setChartMenu())); connect(chartMenu, SIGNAL(triggered(QAction*)), context->mainWindow, SLOT(addChart(QAction*))); // trap resize / mouse events installEventFilter(this); // appearance update connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32))); }