Added a test application for B_AVOID_FOCUS.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15225 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d9b60a740a
commit
7362a1d7b8
@ -137,6 +137,7 @@ HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : haiku_app_server
|
||||
|
||||
} # if $(TARGET_PLATFORM) = libbe_test
|
||||
|
||||
SubInclude HAIKU_TOP src tests servers app avoid_focus ;
|
||||
SubInclude HAIKU_TOP src tests servers app bitmap_drawing ;
|
||||
SubInclude HAIKU_TOP src tests servers app code_to_name ;
|
||||
SubInclude HAIKU_TOP src tests servers app copy_bits ;
|
||||
|
207
src/tests/servers/app/avoid_focus/AvoidFocus.cpp
Normal file
207
src/tests/servers/app/avoid_focus/AvoidFocus.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2005, Haiku Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
*/
|
||||
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
bool gAvoid = true;
|
||||
|
||||
|
||||
class View : public BView {
|
||||
public:
|
||||
View(BRect rect);
|
||||
virtual ~View();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
virtual void KeyUp(const char* bytes, int32 numBytes);
|
||||
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void Pulse();
|
||||
|
||||
private:
|
||||
BString fChar;
|
||||
bool fPressed;
|
||||
};
|
||||
|
||||
|
||||
View::View(BRect rect)
|
||||
: BView(rect, "desktop view", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED)
|
||||
{
|
||||
SetViewColor(255, 255, 255);
|
||||
SetHighColor(0, 0, 0);
|
||||
SetLowColor(ViewColor());
|
||||
}
|
||||
|
||||
|
||||
View::~View()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::AttachedToWindow()
|
||||
{
|
||||
MakeFocus(true);
|
||||
KeyDown("<>", 2);
|
||||
fPressed = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
fChar = bytes;
|
||||
fPressed = true;
|
||||
SetHighColor(0, 0, 0);
|
||||
Window()->SetPulseRate(200000);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::KeyUp(const char* bytes, int32 numBytes)
|
||||
{
|
||||
fPressed = false;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::MouseDown(BPoint where)
|
||||
{
|
||||
SetHighColor(0, 250, 0);
|
||||
Invalidate();
|
||||
Window()->SetPulseRate(150000);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
||||
{
|
||||
SetHighColor(0, 0, 150);
|
||||
Invalidate();
|
||||
Window()->SetPulseRate(10000);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::Draw(BRect updateRect)
|
||||
{
|
||||
BFont font;
|
||||
font.SetSize(200);
|
||||
|
||||
font_height fontHeight;
|
||||
font.GetHeight(&fontHeight);
|
||||
|
||||
SetFont(&font);
|
||||
MovePenTo(20, ceilf(20 + fontHeight.ascent));
|
||||
|
||||
DrawString(fChar.String());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
View::Pulse()
|
||||
{
|
||||
if (fPressed)
|
||||
return;
|
||||
|
||||
rgb_color color = HighColor();
|
||||
SetHighColor(tint_color(color, B_LIGHTEN_2_TINT));
|
||||
Invalidate();
|
||||
|
||||
if (color.red > 253)
|
||||
Window()->SetPulseRate(0);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
class Window : public BWindow {
|
||||
public:
|
||||
Window();
|
||||
virtual ~Window();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
};
|
||||
|
||||
|
||||
Window::Window()
|
||||
: BWindow(BRect(100, 100, 400, 400), "AvoidFocus-Test",
|
||||
B_TITLED_WINDOW, (gAvoid ? B_AVOID_FOCUS : 0) | 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 -
|
||||
|
||||
|
||||
class Application : public BApplication {
|
||||
public:
|
||||
Application();
|
||||
|
||||
virtual void ReadyToRun();
|
||||
};
|
||||
|
||||
|
||||
Application::Application()
|
||||
: BApplication("application/x-vnd.haiku-avoid_focus")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Application::ReadyToRun()
|
||||
{
|
||||
Window *window = new Window();
|
||||
window->Show();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1 && (!strcmp(argv[1], "false") || (isdigit(argv[1][0]) && atoi(argv[1]) == 0)))
|
||||
gAvoid = false;
|
||||
|
||||
Application app;
|
||||
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
18
src/tests/servers/app/avoid_focus/Jamfile
Normal file
18
src/tests/servers/app/avoid_focus/Jamfile
Normal file
@ -0,0 +1,18 @@
|
||||
SubDir HAIKU_TOP src tests servers app avoid_focus ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
AddSubDirSupportedPlatforms libbe_test ;
|
||||
|
||||
UseHeaders [ FDirName os app ] ;
|
||||
UseHeaders [ FDirName os interface ] ;
|
||||
|
||||
Application AvoidFocus :
|
||||
AvoidFocus.cpp
|
||||
: be
|
||||
;
|
||||
|
||||
if $(TARGET_PLATFORM) = libbe_test {
|
||||
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : AvoidFocus
|
||||
: tests!apps ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user