* 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
This commit is contained in:
Axel Dörfler
2009-04-02 10:01:05 +00:00
parent c7c20fc184
commit 7ac4610afa
2 changed files with 16 additions and 31 deletions
+16 -29
View File
@@ -38,7 +38,6 @@ static const uint32 kMsgFontSizeChanged = 'fsch';
static const uint32 kMsgPrivateBlocks = 'prbl'; static const uint32 kMsgPrivateBlocks = 'prbl';
static const uint32 kMsgContainedBlocks = 'cnbl'; static const uint32 kMsgContainedBlocks = 'cnbl';
static const uint32 kMsgFilterChanged = 'fltr'; static const uint32 kMsgFilterChanged = 'fltr';
static const uint32 kMsgFilterEntered = 'flte';
static const uint32 kMsgClearFilter = 'clrf'; static const uint32 kMsgClearFilter = 'clrf';
static const int32 kMinFontSize = 10; static const int32 kMinFontSize = 10;
@@ -65,31 +64,29 @@ private:
mutable char fText[32]; mutable char fText[32];
}; };
class MouseMovedFilter : public BMessageFilter { class RedirectUpAndDownFilter : public BMessageFilter {
public: public:
MouseMovedFilter() RedirectUpAndDownFilter(BHandler* target)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, B_MOUSE_MOVED) : 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() if (bytes[0] == B_UP_ARROW
{ || bytes[0] == B_DOWN_ARROW)
fMouseMoved = 0; *_target = fTarget;
}
virtual filter_result Filter(BMessage* message, BHandler** /*_target*/)
{
fMouseMoved++;
return B_DISPATCH_MESSAGE; return B_DISPATCH_MESSAGE;
} }
private: private:
int32 fMouseMoved; BHandler* fTarget;
}; };
class EscapeMessageFilter : public BMessageFilter { class EscapeMessageFilter : public BMessageFilter {
@@ -137,7 +134,7 @@ CharacterWindow::CharacterWindow()
BMenuBar* menuBar = new BMenuBar("menu"); BMenuBar* menuBar = new BMenuBar("menu");
fFilterControl = new BTextControl("Filter:", NULL, new BMessage(kMsgFilterEntered)); fFilterControl = new BTextControl("Filter:", NULL, NULL);
fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged)); fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged));
BButton* clearButton = new BButton("clear", "Clear", BButton* clearButton = new BButton("clear", "Clear",
@@ -240,8 +237,7 @@ CharacterWindow::CharacterWindow()
menuBar->AddItem(_CreateFontMenu()); menuBar->AddItem(_CreateFontMenu());
AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter)); AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter));
fMouseMovedFilter = new MouseMovedFilter(); AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView));
AddCommonFilter(fMouseMovedFilter);
// TODO: why is this needed? // TODO: why is this needed?
fUnicodeBlockView->SetTarget(this); fUnicodeBlockView->SetTarget(this);
@@ -274,9 +270,7 @@ CharacterWindow::MessageReceived(BMessage* message)
= static_cast<BlockListItem*>(fUnicodeBlockView->ItemAt(index)); = static_cast<BlockListItem*>(fUnicodeBlockView->ItemAt(index));
fCharacterView->ScrollTo(item->BlockIndex()); fCharacterView->ScrollTo(item->BlockIndex());
// Give the filter control focus if we got here by mouse action fFilterControl->MakeFocus();
if (fMouseMovedFilter->HasMoved())
fFilterControl->MakeFocus();
break; break;
} }
@@ -366,14 +360,7 @@ CharacterWindow::MessageReceived(BMessage* message)
case kMsgFilterChanged: case kMsgFilterChanged:
fUnicodeBlockView->SetFilter(fFilterControl->Text()); fUnicodeBlockView->SetFilter(fFilterControl->Text());
fMouseMovedFilter->ResetMoved(); fUnicodeBlockView->Select(0);
break;
case kMsgFilterEntered:
if (!fMouseMovedFilter->HasMoved()) {
fUnicodeBlockView->MakeFocus();
fUnicodeBlockView->Select(0);
}
break; break;
case kMsgClearFilter: case kMsgClearFilter:
-2
View File
@@ -17,7 +17,6 @@ class BSlider;
class BStringView; class BStringView;
class BTextControl; class BTextControl;
class CharacterView; class CharacterView;
class MouseMovedFilter;
class UnicodeBlockView; class UnicodeBlockView;
@@ -44,7 +43,6 @@ private:
BMenuItem* fSelectedFontItem; BMenuItem* fSelectedFontItem;
BSlider* fFontSizeSlider; BSlider* fFontSizeSlider;
BStringView* fCodeView; BStringView* fCodeView;
MouseMovedFilter* fMouseMovedFilter;
}; };
#endif // CHARACTER_WINDOW_H #endif // CHARACTER_WINDOW_H