1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
//
// Copyleft RIME Developers
// License: GPLv3
//
// 2011-03-14 GONG Chen <chen.sst@gmail.com>
//
#ifndef RIME_ENGINE_H_
#define RIME_ENGINE_H_
#include <string>
#include <rime/common.h>
#include <rime/messenger.h>
namespace rime {
class KeyEvent;
class Schema;
class Context;
class Engine : public Messenger {
public:
typedef signal<void (const std::string& commit_text)> CommitSink;
virtual ~Engine();
virtual bool ProcessKey(const KeyEvent& key_event) { return false; }
virtual void ApplySchema(Schema* schema) {}
virtual void CommitText(std::string text) { sink_(text); }
Schema* schema() const { return schema_.get(); }
Context* context() const { return context_.get(); }
CommitSink& sink() { return sink_; }
Context* active_context() const {
return active_context_ ? active_context_ : context_.get();
}
void set_active_context(Context* context = NULL) {
active_context_ = context;
}
static Engine* Create();
protected:
Engine();
scoped_ptr<Schema> schema_;
scoped_ptr<Context> context_;
CommitSink sink_;
Context* active_context_;
};
} // namespace rime
#endif // RIME_ENGINE_H_
|