Added context menu
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38044 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include "wx/listctrl.h"
|
#include "wx/listctrl.h"
|
||||||
#include "wx/timer.h" // for wxStopWatch
|
#include "wx/timer.h" // for wxStopWatch
|
||||||
#include "wx/colordlg.h" // for wxGetColourFromUser
|
#include "wx/colordlg.h" // for wxGetColourFromUser
|
||||||
|
#include "wx/settings.h"
|
||||||
|
|
||||||
#include "listtest.h"
|
#include "listtest.h"
|
||||||
|
|
||||||
@@ -120,6 +121,9 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
|
|||||||
|
|
||||||
EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
|
EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
|
||||||
|
|
||||||
|
#if USE_CONTEXT_MENU
|
||||||
|
EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
|
||||||
|
#endif
|
||||||
EVT_CHAR(MyListCtrl::OnChar)
|
EVT_CHAR(MyListCtrl::OnChar)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
@@ -146,7 +150,7 @@ int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData)
|
|||||||
bool MyApp::OnInit()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
// Create the main frame window
|
// Create the main frame window
|
||||||
MyFrame *frame = new MyFrame(wxT("wxListCtrl Test"), 50, 50, 450, 340);
|
MyFrame *frame = new MyFrame(wxT("wxListCtrl Test"));
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
@@ -157,9 +161,12 @@ bool MyApp::OnInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// My frame constructor
|
// My frame constructor
|
||||||
MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h)
|
MyFrame::MyFrame(const wxChar *title)
|
||||||
: wxFrame(NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize))
|
||||||
{
|
{
|
||||||
|
if (wxSystemSettings::GetScreenType() > wxSYS_SCREEN_SMALL)
|
||||||
|
SetSize(wxSize(450, 340));
|
||||||
|
|
||||||
m_listCtrl = NULL;
|
m_listCtrl = NULL;
|
||||||
m_logWindow = NULL;
|
m_logWindow = NULL;
|
||||||
m_smallVirtual = false;
|
m_smallVirtual = false;
|
||||||
@@ -1050,3 +1057,31 @@ void MyListCtrl::InsertItemInReportView(int i)
|
|||||||
buf.Printf(_T("Item %d in column 2"), i);
|
buf.Printf(_T("Item %d in column 2"), i);
|
||||||
SetItem(i, 2, buf);
|
SetItem(i, 2, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_CONTEXT_MENU
|
||||||
|
void MyListCtrl::OnContextMenu(wxContextMenuEvent& event)
|
||||||
|
{
|
||||||
|
wxPoint point = event.GetPosition();
|
||||||
|
// If from keyboard
|
||||||
|
if (point.x == -1 && point.y == -1) {
|
||||||
|
wxSize size = GetSize();
|
||||||
|
point.x = size.x / 2;
|
||||||
|
point.y = size.y / 2;
|
||||||
|
} else {
|
||||||
|
point = ScreenToClient(point);
|
||||||
|
}
|
||||||
|
ShowContextMenu(point);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void MyListCtrl::ShowContextMenu(const wxPoint& pos)
|
||||||
|
{
|
||||||
|
wxMenu menu;
|
||||||
|
|
||||||
|
menu.Append(wxID_ABOUT, _T("&About"));
|
||||||
|
menu.AppendSeparator();
|
||||||
|
menu.Append(wxID_EXIT, _T("E&xit"));
|
||||||
|
|
||||||
|
PopupMenu(&menu, pos.x, pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,14 @@
|
|||||||
// Licence: wxWindows license
|
// Licence: wxWindows license
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// not all ports have support for EVT_CONTEXT_MENU yet, don't define
|
||||||
|
// USE_CONTEXT_MENU for those which don't
|
||||||
|
#if defined(__WXMOTIF__) || defined(__WXPM__) || defined(__WXX11__) || defined(__WXMGL__)
|
||||||
|
#define USE_CONTEXT_MENU 0
|
||||||
|
#else
|
||||||
|
#define USE_CONTEXT_MENU 1
|
||||||
|
#endif
|
||||||
|
|
||||||
// Define a new application type
|
// Define a new application type
|
||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{
|
{
|
||||||
@@ -32,6 +40,9 @@ public:
|
|||||||
: wxListCtrl(parent, id, pos, size, style),
|
: wxListCtrl(parent, id, pos, size, style),
|
||||||
m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
|
m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
|
||||||
{
|
{
|
||||||
|
#ifdef __POCKETPC__
|
||||||
|
EnableContextMenu();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// add one item to the listctrl in report mode
|
// add one item to the listctrl in report mode
|
||||||
@@ -60,6 +71,9 @@ public:
|
|||||||
void OnCacheHint(wxListEvent& event);
|
void OnCacheHint(wxListEvent& event);
|
||||||
|
|
||||||
void OnChar(wxKeyEvent& event);
|
void OnChar(wxKeyEvent& event);
|
||||||
|
#if USE_CONTEXT_MENU
|
||||||
|
void OnContextMenu(wxContextMenuEvent& event);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetColumnImage(int col, int image);
|
void SetColumnImage(int col, int image);
|
||||||
@@ -81,7 +95,7 @@ private:
|
|||||||
class MyFrame: public wxFrame
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyFrame(const wxChar *title, int x, int y, int w, int h);
|
MyFrame(const wxChar *title);
|
||||||
virtual ~MyFrame();
|
virtual ~MyFrame();
|
||||||
|
|
||||||
void DoSize();
|
void DoSize();
|
||||||
|
Reference in New Issue
Block a user