Back to index

nux  3.0.0
xtest-focus-on-mouse-enter.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Inalogic Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00018  *
00019  */
00020 
00021 #include "Nux/Nux.h"
00022 #include "Nux/WindowThread.h"
00023 #include "Nux/VLayout.h"
00024 #include "Nux/ProgramFramework/ProgramTemplate.h"
00025 #include "Nux/ProgramFramework/TestView.h"
00026 #include <X11/extensions/XTest.h>
00027 #include <X11/keysym.h>
00028 #include "nux_automated_test_framework.h"
00029 
00030 class FocusOnMouseEnterTest: public ProgramTemplate
00031 {
00032 public:
00033   FocusOnMouseEnterTest(const char* program_name, int window_width, int window_height, int program_life_span);
00034   ~FocusOnMouseEnterTest();
00035 
00036   virtual void UserInterfaceSetup();
00037 
00038   nux::TestView* focus_view_;
00039   nux::TestView* no_focus_view_;
00040 };
00041 
00042 FocusOnMouseEnterTest::FocusOnMouseEnterTest(const char* program_name,
00043                                             int window_width,
00044                                             int window_height,
00045                                             int program_life_span)
00046 : ProgramTemplate(program_name, window_width, window_height, program_life_span)
00047 , focus_view_(nullptr)
00048 , no_focus_view_(nullptr)
00049 {
00050 }
00051 
00052 FocusOnMouseEnterTest::~FocusOnMouseEnterTest()
00053 {}
00054 
00055 void FocusOnMouseEnterTest::UserInterfaceSetup()
00056 {
00057   nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00058   main_layout->SetSpaceBetweenChildren(10);
00059   main_layout->SetPadding(10, 10);
00060 
00061   no_focus_view_ = new nux::TestView(NUX_TRACKER_LOCATION);
00062   no_focus_view_->can_focus_ = true;
00063   no_focus_view_->SetAcceptKeyNavFocusOnMouseEnter(false);
00064   main_layout->AddView(no_focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00065 
00066   focus_view_ = new nux::TestView(NUX_TRACKER_LOCATION);
00067   focus_view_->can_focus_ = true;
00068   focus_view_->SetAcceptKeyNavFocusOnMouseEnter(true);
00069   main_layout->AddView(focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00070 
00071   static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
00072 
00073   nux::ColorLayer background(nux::Color(0xFF4D4D4D));
00074   static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
00075 }
00076 
00077 FocusOnMouseEnterTest* focus_on_mouse_enter_test = nullptr;
00078 
00079 void TestingThread(nux::NThread* thread, void* user_data)
00080 {
00081   while (focus_on_mouse_enter_test->ReadyToGo() == false)
00082   {
00083     nuxDebugMsg("Waiting to start");
00084     nux::SleepForMilliseconds(300);
00085   }
00086 
00087   nux::SleepForMilliseconds(1000);
00088 
00089   nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
00090 
00091   NuxAutomatedTestFramework test(wnd_thread);
00092 
00093   test.Startup();
00094 
00095   // Set the mouse at coordinates (0, 0) (top-left corner) on the display
00096   test.PutMouseAt(0, 0);
00097 
00098   test.TestReportMsg(focus_on_mouse_enter_test->focus_view_, "Focus view created");
00099   test.TestReportMsg(focus_on_mouse_enter_test->no_focus_view_, "No focus view created");
00100 
00101   // Move mouse to center of no_focus_view_
00102   test.ViewSendMouseMotionToCenter(focus_on_mouse_enter_test->no_focus_view_);
00103   nux::SleepForMilliseconds(500);
00104   test.TestReportMsg(!focus_on_mouse_enter_test->no_focus_view_->has_focus_, "no_focus_view_ did not take the focus");
00105 
00106    // Move mouse to center of focus_view_
00107   test.ViewSendMouseMotionToCenter(focus_on_mouse_enter_test->focus_view_);
00108   nux::SleepForMilliseconds(500);
00109   test.TestReportMsg(focus_on_mouse_enter_test->focus_view_->has_focus_, "focus_view_ has the focus");
00110 
00111   if (test.WhenDoneTerminateProgram())
00112   {
00113     nux::SleepForMilliseconds(1000);
00114     wnd_thread->ExitMainLoop();
00115   }
00116   nuxDebugMsg("Exit testing thread");
00117 }
00118 
00119 int main(int argc, char** argv)
00120 {
00121   int xstatus = XInitThreads();
00122   nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
00123 
00124   focus_on_mouse_enter_test = new FocusOnMouseEnterTest("Focus On Mouse Enter Test", 300, 300, 15000);
00125   focus_on_mouse_enter_test->Startup();
00126   focus_on_mouse_enter_test->UserInterfaceSetup();
00127 
00128   nux::SystemThread* test_thread = nux::CreateSystemThread(focus_on_mouse_enter_test->GetWindowThread(),
00129                                                            &TestingThread,
00130                                                            focus_on_mouse_enter_test->GetWindowThread());
00131 
00132   test_thread->Start(focus_on_mouse_enter_test);
00133 
00134   focus_on_mouse_enter_test->Run();
00135 
00136   delete test_thread;
00137   delete focus_on_mouse_enter_test;
00138 
00139   return 0;
00140 }