using FbTk's new EventHandler interface

This commit is contained in:
fluxgen 2002-11-27 21:56:56 +00:00
parent 97a2ea9d23
commit 43c4469119
2 changed files with 48 additions and 41 deletions

View file

@ -19,11 +19,12 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // 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 "FbRun.hh"
#include "App.hh" #include "App.hh"
#include "EventManager.hh"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
@ -48,6 +49,7 @@ m_current_history_item(0) {
FbRun::~FbRun() { FbRun::~FbRun() {
hide(); hide();
FbTk::EventManager::instance()->unregisterEventHandler(m_win);
XDestroyWindow(m_display, m_win); XDestroyWindow(m_display, m_win);
} }
@ -70,7 +72,7 @@ void FbRun::run(const std::string &command) {
else else
cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
} }
FbTk::App::instance()->end(); // end application
m_end = true; // mark end of processing 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!"); throw string("Failed to create FbRun window!");
XSelectInput(m_display, m_win, KeyPressMask|ExposureMask); XSelectInput(m_display, m_win, KeyPressMask|ExposureMask);
FbTk::EventManager::instance()->registerEventHandler(*this, m_win);
setNoMaximize(); setNoMaximize();
m_width = width; 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) { void FbRun::keyPressEvent(XKeyEvent &ke) {
switch (xev->type) { KeySym ks;
case KeyPress: { char keychar[1];
KeySym ks; XLookupString(&ke, keychar, 1, &ks, 0);
char keychar[1]; if (ks == XK_Escape) {
XLookupString(&xev->xkey, keychar, 1, &ks, 0); m_end = true;
if (ks == XK_Escape) { hide();
m_end = true; return; // no more processing
hide(); } else if (ks == XK_Return) {
return; // no more processing run(m_runtext);
} else if (ks == XK_Return) { m_runtext = ""; // clear text
run(m_runtext); } else if (ks == XK_BackSpace) {
m_runtext = ""; // clear text if (m_runtext.size() != 0) { // we can't erase what we don't have ;)
} else if (ks == XK_BackSpace) { m_runtext.erase(m_runtext.size()-1);
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:
redrawLabel(); 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; break;
default: case XK_Down:
nextHistoryItem();
break; break;
}
redrawLabel();
} }
} }
void FbRun::exposeEvent(XExposeEvent &ev) {
redrawLabel();
}
void FbRun::getSize(size_t &width, size_t &height) { void FbRun::getSize(size_t &width, size_t &height) {
XWindowAttributes attr; XWindowAttributes attr;
XGetWindowAttributes(m_display, m_win, &attr); XGetWindowAttributes(m_display, m_win, &attr);

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // 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 #ifndef FBRUN_HH
#define FBRUN_HH #define FBRUN_HH
@ -33,7 +33,7 @@
/** /**
Creates and managed a run window Creates and managed a run window
*/ */
class FbRun: public FbTk::EventHandler<XEvent> { class FbRun: public FbTk::EventHandler {
public: public:
FbRun(int x = 0, int y = 0, size_t width = 200); FbRun(int x = 0, int y = 0, size_t width = 200);
~FbRun(); ~FbRun();
@ -63,6 +63,14 @@ public:
@return true on success, else false @return true on success, else false
*/ */
bool loadHistory(const char *filename); bool loadHistory(const char *filename);
/**
@name events
*/
///@{
void exposeEvent(XExposeEvent &ev);
void keyPressEvent(XKeyEvent &ev);
///@}
private: private:
void nextHistoryItem(); void nextHistoryItem();
void prevHistoryItem(); void prevHistoryItem();