Extend the auto-completion framework in order to support using page-up/down
to navigate the choices list. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@501 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
parent
90a69c8e1d
commit
37876e4b33
@ -158,6 +158,36 @@ BAutoCompleter::IsChoiceSelected() const
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BAutoCompleter::CountChoices() const
|
||||
{
|
||||
if (fCompletionStyle && fCompletionStyle->GetChoiceModel())
|
||||
return fCompletionStyle->GetChoiceModel()->CountChoices();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BAutoCompleter::CountVisibleChoices() const
|
||||
{
|
||||
if (fCompletionStyle && fCompletionStyle->GetChoiceView())
|
||||
return fCompletionStyle->GetChoiceView()->CountVisibleChoices();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BAutoCompleter::SelectedChoiceIndex() const
|
||||
{
|
||||
if (fCompletionStyle)
|
||||
return fCompletionStyle->SelectedChoiceIndex();
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BAutoCompleter::ApplyChoice(bool hideChoices)
|
||||
{
|
||||
|
@ -83,6 +83,7 @@ public:
|
||||
= 0;
|
||||
virtual void HideChoices() = 0;
|
||||
virtual bool ChoicesAreShown() = 0;
|
||||
virtual int32 CountVisibleChoices() const = 0;
|
||||
};
|
||||
|
||||
class CompletionStyle {
|
||||
@ -97,6 +98,7 @@ public:
|
||||
virtual bool SelectNext(bool wrap = false) = 0;
|
||||
virtual bool SelectPrevious(bool wrap = false) = 0;
|
||||
virtual bool IsChoiceSelected() const = 0;
|
||||
virtual int32 SelectedChoiceIndex() const = 0;
|
||||
|
||||
virtual void ApplyChoice(bool hideChoices = true) = 0;
|
||||
virtual void CancelChoice() = 0;
|
||||
@ -137,6 +139,9 @@ protected:
|
||||
bool SelectNext(bool wrap = false);
|
||||
bool SelectPrevious(bool wrap = false);
|
||||
bool IsChoiceSelected() const;
|
||||
int32 CountChoices() const;
|
||||
int32 CountVisibleChoices() const;
|
||||
int32 SelectedChoiceIndex() const;
|
||||
|
||||
void ApplyChoice(bool hideChoices = true);
|
||||
void CancelChoice();
|
||||
|
@ -105,6 +105,13 @@ BDefaultCompletionStyle::IsChoiceSelected() const
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BDefaultCompletionStyle::SelectedChoiceIndex() const
|
||||
{
|
||||
return fSelectedIndex;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BDefaultCompletionStyle::ApplyChoice(bool hideChoices)
|
||||
{
|
||||
@ -187,7 +194,7 @@ BDefaultCompletionStyle::EditViewStateChanged(bool updateChoices)
|
||||
// #pragma mark - BDefaultChoiceView::ListView
|
||||
|
||||
|
||||
static const int32 BM_INVOKED = 'bmin';
|
||||
static const int32 MSG_INVOKED = 'invk';
|
||||
|
||||
|
||||
BDefaultChoiceView::ListView::ListView(
|
||||
@ -205,7 +212,7 @@ void
|
||||
BDefaultChoiceView::ListView::AttachedToWindow()
|
||||
{
|
||||
SetTarget(this);
|
||||
SetInvocationMessage(new BMessage(BM_INVOKED));
|
||||
SetInvocationMessage(new BMessage(MSG_INVOKED));
|
||||
BListView::AttachedToWindow();
|
||||
}
|
||||
|
||||
@ -221,7 +228,7 @@ void
|
||||
BDefaultChoiceView::ListView::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch(message->what) {
|
||||
case BM_INVOKED:
|
||||
case MSG_INVOKED:
|
||||
fCompleter->ApplyChoice();
|
||||
break;
|
||||
default:
|
||||
@ -316,7 +323,8 @@ BDefaultChoiceView::ListItem::DrawItem(BView* owner, BRect frame,
|
||||
BDefaultChoiceView::BDefaultChoiceView()
|
||||
:
|
||||
fWindow(NULL),
|
||||
fListView(NULL)
|
||||
fListView(NULL),
|
||||
fMaxVisibleChoices(5)
|
||||
{
|
||||
|
||||
}
|
||||
@ -370,7 +378,7 @@ BDefaultChoiceView::ShowChoices(BAutoCompleter::CompletionStyle* completer)
|
||||
| B_AVOID_FOCUS | B_ASYNCHRONOUS_CONTROLS);
|
||||
fWindow->AddChild(fListView);
|
||||
|
||||
int32 visibleCount = min_c(count, 5);
|
||||
int32 visibleCount = min_c(count, fMaxVisibleChoices);
|
||||
float listHeight = fListView->ItemFrame(visibleCount - 1).bottom + 1;
|
||||
|
||||
BRect pvRect = editView->GetAdjustmentFrame();
|
||||
@ -407,3 +415,31 @@ BDefaultChoiceView::ChoicesAreShown()
|
||||
return (fWindow != NULL);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BDefaultChoiceView::CountVisibleChoices() const
|
||||
{
|
||||
return min_c(fMaxVisibleChoices, fListView->CountItems());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BDefaultChoiceView::SetMaxVisibleChoices(int32 choices)
|
||||
{
|
||||
if (choices < 1)
|
||||
choices = 1;
|
||||
if (choices == fMaxVisibleChoices)
|
||||
return;
|
||||
|
||||
fMaxVisibleChoices = choices;
|
||||
|
||||
// TODO: Update live?
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BDefaultChoiceView::MaxVisibleChoices() const
|
||||
{
|
||||
return fMaxVisibleChoices;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
virtual bool SelectNext(bool wrap = false);
|
||||
virtual bool SelectPrevious(bool wrap = false);
|
||||
virtual bool IsChoiceSelected() const;
|
||||
virtual int32 SelectedChoiceIndex() const;
|
||||
|
||||
virtual void ApplyChoice(bool hideChoices = true);
|
||||
virtual void CancelChoice();
|
||||
@ -60,6 +61,7 @@ protected:
|
||||
virtual void MessageReceived(BMessage* msg);
|
||||
virtual void MouseDown(BPoint point);
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
private:
|
||||
BAutoCompleter::CompletionStyle* fCompleter;
|
||||
};
|
||||
@ -84,10 +86,15 @@ public:
|
||||
BAutoCompleter::CompletionStyle* completer);
|
||||
virtual void HideChoices();
|
||||
virtual bool ChoicesAreShown();
|
||||
virtual int32 CountVisibleChoices() const;
|
||||
|
||||
void SetMaxVisibleChoices(int32 choices);
|
||||
int32 MaxVisibleChoices() const;
|
||||
|
||||
private:
|
||||
BWindow* fWindow;
|
||||
ListView* fListView;
|
||||
int32 fMaxVisibleChoices;
|
||||
};
|
||||
|
||||
#endif // _AUTO_COMPLETER_DEFAULT_IMPL_H
|
||||
|
@ -122,6 +122,23 @@ TextViewCompleter::Filter(BMessage* message, BHandler** target)
|
||||
// See above.
|
||||
ApplyChoice(false);
|
||||
return B_SKIP_MESSAGE;
|
||||
case B_PAGE_UP:
|
||||
{
|
||||
int32 index = SelectedChoiceIndex() - CountVisibleChoices();
|
||||
index = max_c(index, 0);
|
||||
Select(index);
|
||||
ApplyChoice(false);
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
case B_PAGE_DOWN:
|
||||
{
|
||||
int32 index = SelectedChoiceIndex() + CountVisibleChoices();
|
||||
index = min_c(index, CountChoices() - 1);
|
||||
Select(index);
|
||||
ApplyChoice(false);
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
|
||||
case B_ESCAPE:
|
||||
CancelChoice();
|
||||
return B_SKIP_MESSAGE;
|
||||
|
Loading…
Reference in New Issue
Block a user