From 7ac4610afaa6ec96980ba5477476c72d9c3cf947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 2 Apr 2009 10:01:05 +0000 Subject: [PATCH] * Got rid of the mouse move heuristics again, and tried a cleaner approach by redirecting up/down keys to the list view. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29865 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/charactermap/CharacterWindow.cpp | 45 ++++++++--------------- src/apps/charactermap/CharacterWindow.h | 2 - 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/apps/charactermap/CharacterWindow.cpp b/src/apps/charactermap/CharacterWindow.cpp index 15e6ea1c06..65aadcc988 100644 --- a/src/apps/charactermap/CharacterWindow.cpp +++ b/src/apps/charactermap/CharacterWindow.cpp @@ -38,7 +38,6 @@ static const uint32 kMsgFontSizeChanged = 'fsch'; static const uint32 kMsgPrivateBlocks = 'prbl'; static const uint32 kMsgContainedBlocks = 'cnbl'; static const uint32 kMsgFilterChanged = 'fltr'; -static const uint32 kMsgFilterEntered = 'flte'; static const uint32 kMsgClearFilter = 'clrf'; static const int32 kMinFontSize = 10; @@ -65,31 +64,29 @@ private: mutable char fText[32]; }; -class MouseMovedFilter : public BMessageFilter { +class RedirectUpAndDownFilter : public BMessageFilter { public: - MouseMovedFilter() - : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, B_MOUSE_MOVED) + RedirectUpAndDownFilter(BHandler* target) + : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, B_KEY_DOWN), + fTarget(target) { } - bool HasMoved() const + virtual filter_result Filter(BMessage* message, BHandler** _target) { - return fMouseMoved != 0; - } + const char* bytes; + if (message->FindString("bytes", &bytes) != B_OK) + return B_DISPATCH_MESSAGE; - void ResetMoved() - { - fMouseMoved = 0; - } + if (bytes[0] == B_UP_ARROW + || bytes[0] == B_DOWN_ARROW) + *_target = fTarget; - virtual filter_result Filter(BMessage* message, BHandler** /*_target*/) - { - fMouseMoved++; return B_DISPATCH_MESSAGE; } private: - int32 fMouseMoved; + BHandler* fTarget; }; class EscapeMessageFilter : public BMessageFilter { @@ -137,7 +134,7 @@ CharacterWindow::CharacterWindow() BMenuBar* menuBar = new BMenuBar("menu"); - fFilterControl = new BTextControl("Filter:", NULL, new BMessage(kMsgFilterEntered)); + fFilterControl = new BTextControl("Filter:", NULL, NULL); fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged)); BButton* clearButton = new BButton("clear", "Clear", @@ -240,8 +237,7 @@ CharacterWindow::CharacterWindow() menuBar->AddItem(_CreateFontMenu()); AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter)); - fMouseMovedFilter = new MouseMovedFilter(); - AddCommonFilter(fMouseMovedFilter); + AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView)); // TODO: why is this needed? fUnicodeBlockView->SetTarget(this); @@ -274,9 +270,7 @@ CharacterWindow::MessageReceived(BMessage* message) = static_cast(fUnicodeBlockView->ItemAt(index)); fCharacterView->ScrollTo(item->BlockIndex()); - // Give the filter control focus if we got here by mouse action - if (fMouseMovedFilter->HasMoved()) - fFilterControl->MakeFocus(); + fFilterControl->MakeFocus(); break; } @@ -366,14 +360,7 @@ CharacterWindow::MessageReceived(BMessage* message) case kMsgFilterChanged: fUnicodeBlockView->SetFilter(fFilterControl->Text()); - fMouseMovedFilter->ResetMoved(); - break; - - case kMsgFilterEntered: - if (!fMouseMovedFilter->HasMoved()) { - fUnicodeBlockView->MakeFocus(); - fUnicodeBlockView->Select(0); - } + fUnicodeBlockView->Select(0); break; case kMsgClearFilter: diff --git a/src/apps/charactermap/CharacterWindow.h b/src/apps/charactermap/CharacterWindow.h index 085d36fd4a..7d247535f3 100644 --- a/src/apps/charactermap/CharacterWindow.h +++ b/src/apps/charactermap/CharacterWindow.h @@ -17,7 +17,6 @@ class BSlider; class BStringView; class BTextControl; class CharacterView; -class MouseMovedFilter; class UnicodeBlockView; @@ -44,7 +43,6 @@ private: BMenuItem* fSelectedFontItem; BSlider* fFontSizeSlider; BStringView* fCodeView; - MouseMovedFilter* fMouseMovedFilter; }; #endif // CHARACTER_WINDOW_H