| 1 |
#include "varnam_candidate.h" |
| 2 |
#include "varnam_config.h" |
| 3 |
#include "varnam_state.h" |
| 4 |
|
| 5 |
#include <fcitx/candidatelist.h> |
| 6 |
|
| 7 |
namespace fcitx { |
| 8 |
|
| 9 |
VarnamCandidateWord::VarnamCandidateWord(VarnamEngine *engine, const char *text, |
| 10 |
int index) |
| 11 |
: CandidateWord(Text(std::move(text))), engine_(engine), index_(index) {} |
| 12 |
|
| 13 |
void VarnamCandidateWord::select(InputContext *inputContext) const { |
| 14 |
auto state = inputContext->propertyFor(engine_->factory()); |
| 15 |
state->selectCandidate(index_); |
| 16 |
} |
| 17 |
|
| 18 |
VarnamCandidateList::VarnamCandidateList(VarnamEngine *engine, InputContext *ic) |
| 19 |
: engine_(engine), ic_(ic) { |
| 20 |
const VarnamEngineConfig *config = |
| 21 |
static_cast<const VarnamEngineConfig *>(engine_->getConfig()); |
| 22 |
CandidateLayoutHint layout; |
| 23 |
if (!config) { |
| 24 |
VARNAM_WARN() << "Invalid configuration"; |
| 25 |
layout = CandidateLayoutHint::Vertical; |
| 26 |
} else { |
| 27 |
layout = config->candidateLayout.value(); |
| 28 |
} |
| 29 |
setPageable(this); |
| 30 |
setLayoutHint(layout); |
| 31 |
} |
| 32 |
|
| 33 |
void VarnamCandidateList::prev() { |
| 34 |
CommonCandidateList::prev(); |
| 35 |
if (currentPage() >= 0) { |
| 36 |
setPage(currentPage()); |
| 37 |
setCursorPositionAfterPaging(CursorPositionAfterPaging::ResetToFirst); |
| 38 |
} |
| 39 |
ic_->updateUserInterface(UserInterfaceComponent::InputPanel); |
| 40 |
} |
| 41 |
|
| 42 |
void VarnamCandidateList::next() { |
| 43 |
CommonCandidateList::next(); |
| 44 |
if (currentPage() < totalPages()) { |
| 45 |
setPage(currentPage()); |
| 46 |
setGlobalCursorIndex(pageSize() * currentPage() - (pageSize() - 1)); |
| 47 |
} |
| 48 |
ic_->updateUserInterface(UserInterfaceComponent::InputPanel); |
| 49 |
} |
| 50 |
|
| 51 |
bool VarnamCandidateList::usedNextBefore() const { return true; } |
| 52 |
|
| 53 |
void VarnamCandidateList::prevCandidate() { |
| 54 |
CommonCandidateList::prevCandidate(); |
| 55 |
auto state = ic_->propertyFor(engine_->factory()); |
| 56 |
int index = globalCursorIndex(); |
| 57 |
if (index >= pageSize() && (currentPage() > 0)) { |
| 58 |
setPage(currentPage()); |
| 59 |
} |
| 60 |
setGlobalCursorIndex(index); |
| 61 |
state->selectCandidate(cursorIndex()); |
| 62 |
ic_->updateUserInterface(UserInterfaceComponent::InputPanel); |
| 63 |
} |
| 64 |
|
| 65 |
void VarnamCandidateList::nextCandidate() { |
| 66 |
CommonCandidateList::nextCandidate(); |
| 67 |
auto state = ic_->propertyFor(engine_->factory()); |
| 68 |
int index = globalCursorIndex(); |
| 69 |
if (index >= pageSize() && (currentPage() < totalPages())) { |
| 70 |
setPage(currentPage()); |
| 71 |
} |
| 72 |
setGlobalCursorIndex(index); |
| 73 |
state->selectCandidate(cursorIndex()); |
| 74 |
ic_->updateUserInterface(UserInterfaceComponent::InputPanel); |
| 75 |
} |
| 76 |
|
| 77 |
} // namespace fcitx |