Added a small test for B_LOCK_FOCUS and B_SUSPEND_VIEW_FOCUS.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22764 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
9bfd424271
commit
3ecd9d8fbb
@ -168,6 +168,7 @@ SubInclude HAIKU_TOP src tests servers app desktop_window ;
|
||||
SubInclude HAIKU_TOP src tests servers app event_mask ;
|
||||
SubInclude HAIKU_TOP src tests servers app following ;
|
||||
SubInclude HAIKU_TOP src tests servers app idle_test ;
|
||||
SubInclude HAIKU_TOP src tests servers app lock_focus ;
|
||||
SubInclude HAIKU_TOP src tests servers app look_and_feel ;
|
||||
SubInclude HAIKU_TOP src tests servers app menu_crash ;
|
||||
SubInclude HAIKU_TOP src tests servers app no_pointer_history ;
|
||||
|
17
src/tests/servers/app/lock_focus/Jamfile
Normal file
17
src/tests/servers/app/lock_focus/Jamfile
Normal file
@ -0,0 +1,17 @@
|
||||
SubDir HAIKU_TOP src tests servers app lock_focus ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
AddSubDirSupportedPlatforms libbe_test ;
|
||||
|
||||
UseHeaders [ FDirName os app ] ;
|
||||
UseHeaders [ FDirName os interface ] ;
|
||||
|
||||
Application LockFocusTest :
|
||||
LockFocusTest.cpp
|
||||
: be
|
||||
;
|
||||
|
||||
if $(TARGET_PLATFORM) = libbe_test {
|
||||
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : LockFocusTest
|
||||
: tests!apps ;
|
||||
}
|
211
src/tests/servers/app/lock_focus/LockFocusTest.cpp
Normal file
211
src/tests/servers/app/lock_focus/LockFocusTest.cpp
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright 2005-2007, Haiku Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
*/
|
||||
|
||||
|
||||
#include <Application.h>
|
||||
#include <MessageRunner.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static const uint32 kMsgUpdate = 'updt';
|
||||
|
||||
|
||||
class View : public BView {
|
||||
public:
|
||||
View(BRect rect);
|
||||
virtual ~View();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
virtual void KeyUp(const char* bytes, int32 numBytes);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
private:
|
||||
void _Update();
|
||||
|
||||
BMessageRunner* fRunner;
|
||||
char fLastKey;
|
||||
bool fPressed;
|
||||
uint8 fLastColor;
|
||||
};
|
||||
|
||||
class Window : public BWindow {
|
||||
public:
|
||||
Window(int32 offset = 0);
|
||||
virtual ~Window();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
};
|
||||
|
||||
class Application : public BApplication {
|
||||
public:
|
||||
Application();
|
||||
|
||||
virtual void ReadyToRun();
|
||||
};
|
||||
|
||||
|
||||
View::View(BRect rect)
|
||||
: BView(rect, "lock focus", B_FOLLOW_ALL, B_WILL_DRAW),
|
||||
fRunner(NULL),
|
||||
fLastKey('\0'),
|
||||
fPressed(false),
|
||||
fLastColor(255)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
View::~View()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::AttachedToWindow()
|
||||
{
|
||||
MakeFocus(this);
|
||||
|
||||
BMessage update(kMsgUpdate);
|
||||
fRunner = new BMessageRunner(this, &update, 16667);
|
||||
|
||||
BFont font;
|
||||
font.SetSize(72);
|
||||
SetFont(&font);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::DetachedFromWindow()
|
||||
{
|
||||
delete fRunner;
|
||||
fRunner = NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::MouseDown(BPoint where)
|
||||
{
|
||||
SetMouseEventMask(0, B_LOCK_WINDOW_FOCUS | B_SUSPEND_VIEW_FOCUS
|
||||
| B_NO_POINTER_HISTORY);
|
||||
|
||||
::Window* window = new ::Window(100);
|
||||
window->Show();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case kMsgUpdate:
|
||||
_Update();
|
||||
break;
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::_Update()
|
||||
{
|
||||
if (fPressed)
|
||||
return;
|
||||
|
||||
if (fLastColor < 255) {
|
||||
fLastColor += 15;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::KeyUp(const char* bytes, int32 numBytes)
|
||||
{
|
||||
fPressed = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
fLastKey = bytes[0];
|
||||
fLastColor = 0;
|
||||
fPressed = true;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::Draw(BRect updateRect)
|
||||
{
|
||||
SetHighColor(fLastColor, fLastColor, fLastColor);
|
||||
DrawString(&fLastKey, 1, BPoint(20, 70));
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Window::Window(int32 offset)
|
||||
: BWindow(BRect(100 + offset, 100 + offset, 400 + offset, 400 + offset),
|
||||
"LockFocus-Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||
{
|
||||
BView *view = new View(Bounds());
|
||||
AddChild(view);
|
||||
}
|
||||
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Window::QuitRequested()
|
||||
{
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Application::Application()
|
||||
: BApplication("application/x-vnd.haiku-lock_focus")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Application::ReadyToRun(void)
|
||||
{
|
||||
Window* window = new Window();
|
||||
window->Show();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
Application app;
|
||||
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user