using FbTk's new EventHandler interface
This commit is contained in:
parent
97a2ea9d23
commit
43c4469119
2 changed files with 48 additions and 41 deletions
|
@ -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 <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
@ -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: "<<m_history_file<<endl;
|
||||
}
|
||||
|
||||
FbTk::App::instance()->end(); // end application
|
||||
m_end = true; // mark end of processing
|
||||
}
|
||||
|
||||
|
@ -193,6 +195,8 @@ void FbRun::createWindow(int x, int y, size_t width, size_t height) {
|
|||
|
||||
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);
|
||||
|
|
|
@ -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<XEvent> {
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue