From 43c4469119b5b5357d01e59a23cf541fb233bd28 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Wed, 27 Nov 2002 21:56:56 +0000 Subject: using FbTk's new EventHandler interface --- util/fbrun/FbRun.cc | 77 ++++++++++++++++++++++++++--------------------------- util/fbrun/FbRun.hh | 12 +++++++-- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 7aa7938..1dc5ae7 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc @@ -19,11 +19,12 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbRun.cc,v 1.7 2002/11/26 17:13:36 fluxgen Exp $ +// $Id: FbRun.cc,v 1.8 2002/11/27 21:56:56 fluxgen Exp $ #include "FbRun.hh" #include "App.hh" +#include "EventManager.hh" #include #include @@ -48,6 +49,7 @@ m_current_history_item(0) { FbRun::~FbRun() { hide(); + FbTk::EventManager::instance()->unregisterEventHandler(m_win); XDestroyWindow(m_display, m_win); } @@ -70,7 +72,7 @@ void FbRun::run(const std::string &command) { else cerr<<"FbRun Warning: Can't write command history to file: "<end(); // end application m_end = true; // mark end of processing } @@ -192,7 +194,9 @@ void FbRun::createWindow(int x, int y, size_t width, size_t height) { throw string("Failed to create FbRun window!"); XSelectInput(m_display, m_win, KeyPressMask|ExposureMask); - + + FbTk::EventManager::instance()->registerEventHandler(*this, m_win); + setNoMaximize(); m_width = width; @@ -200,48 +204,43 @@ void FbRun::createWindow(int x, int y, size_t width, size_t height) { } -void FbRun::handleEvent(XEvent * const xev) { - switch (xev->type) { - case KeyPress: { - KeySym ks; - char keychar[1]; - XLookupString(&xev->xkey, keychar, 1, &ks, 0); - if (ks == XK_Escape) { - m_end = true; - hide(); - return; // no more processing - } else if (ks == XK_Return) { - run(m_runtext); - m_runtext = ""; // clear text - } else if (ks == XK_BackSpace) { - if (m_runtext.size() != 0) { // we can't erase what we don't have ;) - m_runtext.erase(m_runtext.size()-1); - redrawLabel(); - } - } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { - m_runtext+=keychar[0]; // append character - redrawLabel(); - } else if (IsCursorKey(ks)) { - - switch (ks) { - case XK_Up: - prevHistoryItem(); - break; - case XK_Down: - nextHistoryItem(); - break; - } - redrawLabel(); - } - } break; - case Expose: +void FbRun::keyPressEvent(XKeyEvent &ke) { + KeySym ks; + char keychar[1]; + XLookupString(&ke, keychar, 1, &ks, 0); + if (ks == XK_Escape) { + m_end = true; + hide(); + return; // no more processing + } else if (ks == XK_Return) { + run(m_runtext); + m_runtext = ""; // clear text + } else if (ks == XK_BackSpace) { + if (m_runtext.size() != 0) { // we can't erase what we don't have ;) + m_runtext.erase(m_runtext.size()-1); redrawLabel(); + } + } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { + m_runtext+=keychar[0]; // append character + redrawLabel(); + } else if (IsCursorKey(ks)) { + + switch (ks) { + case XK_Up: + prevHistoryItem(); break; - default: + case XK_Down: + nextHistoryItem(); break; + } + redrawLabel(); } } +void FbRun::exposeEvent(XExposeEvent &ev) { + redrawLabel(); +} + void FbRun::getSize(size_t &width, size_t &height) { XWindowAttributes attr; XGetWindowAttributes(m_display, m_win, &attr); diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh index efcd54f..41e5925 100644 --- a/util/fbrun/FbRun.hh +++ b/util/fbrun/FbRun.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbRun.hh,v 1.6 2002/11/15 14:03:14 fluxgen Exp $ +// $Id: FbRun.hh,v 1.7 2002/11/27 21:56:02 fluxgen Exp $ #ifndef FBRUN_HH #define FBRUN_HH @@ -33,7 +33,7 @@ /** Creates and managed a run window */ -class FbRun: public FbTk::EventHandler { +class FbRun: public FbTk::EventHandler { public: FbRun(int x = 0, int y = 0, size_t width = 200); ~FbRun(); @@ -63,6 +63,14 @@ public: @return true on success, else false */ bool loadHistory(const char *filename); + /** + @name events + */ + ///@{ + void exposeEvent(XExposeEvent &ev); + void keyPressEvent(XKeyEvent &ev); + ///@} + private: void nextHistoryItem(); void prevHistoryItem(); -- cgit v0.11.2