diff --git a/src/apps/webpositive/autocompletion/AutoCompleter.cpp b/src/apps/webpositive/autocompletion/AutoCompleter.cpp index 2e5d45e164..09060512f6 100644 --- a/src/apps/webpositive/autocompletion/AutoCompleter.cpp +++ b/src/apps/webpositive/autocompletion/AutoCompleter.cpp @@ -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) { diff --git a/src/apps/webpositive/autocompletion/AutoCompleter.h b/src/apps/webpositive/autocompletion/AutoCompleter.h index 16a94559b4..dab8268db2 100644 --- a/src/apps/webpositive/autocompletion/AutoCompleter.h +++ b/src/apps/webpositive/autocompletion/AutoCompleter.h @@ -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(); diff --git a/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.cpp b/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.cpp index 5760852400..1f7f27c3ea 100644 --- a/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.cpp +++ b/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.cpp @@ -105,6 +105,13 @@ BDefaultCompletionStyle::IsChoiceSelected() const } +int32 +BDefaultCompletionStyle::SelectedChoiceIndex() const +{ + return fSelectedIndex; +} + + void BDefaultCompletionStyle::ApplyChoice(bool hideChoices) { @@ -187,13 +194,13 @@ BDefaultCompletionStyle::EditViewStateChanged(bool updateChoices) // #pragma mark - BDefaultChoiceView::ListView -static const int32 BM_INVOKED = 'bmin'; +static const int32 MSG_INVOKED = 'invk'; BDefaultChoiceView::ListView::ListView( BAutoCompleter::CompletionStyle* completer) : - BListView(BRect(0,0,100,100), "ChoiceViewList"), + BListView(BRect(0, 0, 100, 100), "ChoiceViewList"), fCompleter(completer) { // we need to check if user clicks outside of window-bounds: @@ -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) { } @@ -359,7 +367,7 @@ BDefaultChoiceView::ShowChoices(BAutoCompleter::CompletionStyle* completer) fListView = new ListView(completer); int32 count = choiceModel->CountChoices(); - for(int32 i=0; iAddItem( new ListItem(choiceModel->ChoiceAt(i)) ); @@ -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; +} + diff --git a/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.h b/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.h index 216a2d7f78..6c3e50e8f5 100644 --- a/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.h +++ b/src/apps/webpositive/autocompletion/AutoCompleterDefaultImpl.h @@ -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 diff --git a/src/apps/webpositive/autocompletion/TextViewCompleter.cpp b/src/apps/webpositive/autocompletion/TextViewCompleter.cpp index 3f83e884d8..66e95e9ae6 100644 --- a/src/apps/webpositive/autocompletion/TextViewCompleter.cpp +++ b/src/apps/webpositive/autocompletion/TextViewCompleter.cpp @@ -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;