added FromPoint test
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -65,8 +65,11 @@ public:
|
|||||||
|
|
||||||
// event handlers (these functions should _not_ be virtual)
|
// event handlers (these functions should _not_ be virtual)
|
||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
|
void OnFromPoint(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
|
||||||
|
void OnLeftClick(wxMouseEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// any class wishing to process wxWindows events must use this macro
|
// any class wishing to process wxWindows events must use this macro
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
@@ -82,6 +85,8 @@ enum
|
|||||||
// menu items
|
// menu items
|
||||||
Display_Quit = 1,
|
Display_Quit = 1,
|
||||||
|
|
||||||
|
Display_FromPoint,
|
||||||
|
|
||||||
// it is important for the id corresponding to the "About" command to have
|
// it is important for the id corresponding to the "About" command to have
|
||||||
// this standard value as otherwise it won't be handled properly under Mac
|
// this standard value as otherwise it won't be handled properly under Mac
|
||||||
// (where it is special and put into the "Apple" menu)
|
// (where it is special and put into the "Apple" menu)
|
||||||
@@ -97,7 +102,10 @@ enum
|
|||||||
// simple menu events like this the static method is much simpler.
|
// simple menu events like this the static method is much simpler.
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_MENU(Display_Quit, MyFrame::OnQuit)
|
EVT_MENU(Display_Quit, MyFrame::OnQuit)
|
||||||
|
EVT_MENU(Display_FromPoint, MyFrame::OnFromPoint)
|
||||||
EVT_MENU(Display_About, MyFrame::OnAbout)
|
EVT_MENU(Display_About, MyFrame::OnAbout)
|
||||||
|
|
||||||
|
EVT_LEFT_UP(MyFrame::OnLeftClick)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// Create a new application object: this macro will allow wxWindows to create
|
// Create a new application object: this macro will allow wxWindows to create
|
||||||
@@ -145,23 +153,27 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
|
|||||||
|
|
||||||
#if wxUSE_MENUS
|
#if wxUSE_MENUS
|
||||||
// create a menu bar
|
// create a menu bar
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuDisplay = new wxMenu;
|
||||||
|
menuDisplay->Append(Display_FromPoint, _("&Find from point..."));
|
||||||
|
menuDisplay->AppendSeparator();
|
||||||
|
menuDisplay->Append(Display_Quit, _("E&xit\tAlt-X"), _("Quit this program"));
|
||||||
|
|
||||||
// the "About" item should be in the help menu
|
// the "About" item should be in the help menu
|
||||||
wxMenu *helpMenu = new wxMenu;
|
wxMenu *helpMenu = new wxMenu;
|
||||||
helpMenu->Append(Display_About, _("&About...\tF1"), _("Show about dialog"));
|
helpMenu->Append(Display_About, _("&About...\tF1"), _("Show about dialog"));
|
||||||
|
|
||||||
menuFile->Append(Display_Quit, _("E&xit\tAlt-X"), _("Quit this program"));
|
|
||||||
|
|
||||||
// now append the freshly created menu to the menu bar...
|
// now append the freshly created menu to the menu bar...
|
||||||
wxMenuBar *menuBar = new wxMenuBar();
|
wxMenuBar *menuBar = new wxMenuBar();
|
||||||
menuBar->Append(menuFile, _("&File"));
|
menuBar->Append(menuDisplay, _("&Display"));
|
||||||
menuBar->Append(helpMenu, _("&Help"));
|
menuBar->Append(helpMenu, _("&Help"));
|
||||||
|
|
||||||
// ... and attach this menu bar to the frame
|
// ... and attach this menu bar to the frame
|
||||||
SetMenuBar(menuBar);
|
SetMenuBar(menuBar);
|
||||||
#endif // wxUSE_MENUS
|
#endif // wxUSE_MENUS
|
||||||
|
|
||||||
|
// create status bar
|
||||||
|
CreateStatusBar();
|
||||||
|
|
||||||
// create child controls
|
// create child controls
|
||||||
wxNotebook *notebook = new wxNotebook(this, -1);
|
wxNotebook *notebook = new wxNotebook(this, -1);
|
||||||
const size_t count = wxDisplay::GetCount();
|
const size_t count = wxDisplay::GetCount();
|
||||||
@@ -176,14 +188,22 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
|
|||||||
sizer->AddGrowableCol(1);
|
sizer->AddGrowableCol(1);
|
||||||
|
|
||||||
const wxRect r(display.GetGeometry());
|
const wxRect r(display.GetGeometry());
|
||||||
sizer->Add(new wxStaticText(page, -1, _T("Geometry: ")));
|
sizer->Add(new wxStaticText(page, -1, _T("Origin: ")));
|
||||||
sizer->Add(new wxStaticText
|
sizer->Add(new wxStaticText
|
||||||
(
|
(
|
||||||
page,
|
page,
|
||||||
-1,
|
-1,
|
||||||
wxString::Format(_T("(%d, %d)-(%d, %d)"),
|
wxString::Format(_T("(%d, %d)"),
|
||||||
r.x, r.y,
|
r.x, r.y)
|
||||||
r.x + r.width, r.y + r.height)
|
));
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(page, -1, _T("Size: ")));
|
||||||
|
sizer->Add(new wxStaticText
|
||||||
|
(
|
||||||
|
page,
|
||||||
|
-1,
|
||||||
|
wxString::Format(_T("(%d, %d)"),
|
||||||
|
r.width, r.height)
|
||||||
));
|
));
|
||||||
|
|
||||||
sizer->Add(new wxStaticText(page, -1, _T("Depth: ")));
|
sizer->Add(new wxStaticText(page, -1, _T("Depth: ")));
|
||||||
@@ -194,6 +214,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
|
|||||||
wxString::Format(_T("%d bpp"), display.GetDepth())
|
wxString::Format(_T("%d bpp"), display.GetDepth())
|
||||||
));
|
));
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(page, -1, _T("Name: ")));
|
||||||
|
sizer->Add(new wxStaticText(page, -1, display.GetName()));
|
||||||
|
|
||||||
sizer->Add(new wxStaticText(page, -1, _T("Colour: ")));
|
sizer->Add(new wxStaticText(page, -1, _T("Colour: ")));
|
||||||
sizer->Add(new wxStaticText(page, -1, display.IsColour() ? _T("Yes")
|
sizer->Add(new wxStaticText(page, -1, display.IsColour() ? _T("Yes")
|
||||||
: _T("No")));
|
: _T("No")));
|
||||||
@@ -224,3 +247,30 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|||||||
wxOK | wxICON_INFORMATION,
|
wxOK | wxICON_INFORMATION,
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnFromPoint(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
SetStatusText(_T("Press the mouse anywhere..."));
|
||||||
|
|
||||||
|
CaptureMouse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnLeftClick(wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
if ( HasCapture() )
|
||||||
|
{
|
||||||
|
// mouse events are in client coords, wxDisplay works in screen ones
|
||||||
|
const wxPoint ptScreen = ClientToScreen(event.GetPosition());
|
||||||
|
int dpy = wxDisplay::GetFromPoint(ptScreen);
|
||||||
|
if ( dpy == wxNOT_FOUND )
|
||||||
|
{
|
||||||
|
wxLogError(_T("Mouse clicked outside of display!!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLogStatus(this, _T("Mouse clicked in display %d (at (%d, %d))"),
|
||||||
|
dpy, ptScreen.x, ptScreen.y);
|
||||||
|
|
||||||
|
ReleaseMouse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user