Permalink
Browse files

Close about window on escape

  • Loading branch information...
1 parent 9f7ac43 commit 381629a7b6d4c88f2fe857b6220dca8438fcfdb1 @jscipione jscipione committed Feb 11, 2013
Showing with 45 additions and 0 deletions.
  1. +45 −0 src/kits/shared/AboutWindow.cpp
@@ -20,7 +20,10 @@
#include <Font.h>
#include <GroupLayoutBuilder.h>
#include <GroupView.h>
+#include <InterfaceDefs.h>
#include <LayoutBuilder.h>
+#include <Message.h>
+#include <MessageFilter.h>
#include <Point.h>
#include <Roster.h>
#include <Screen.h>
@@ -42,6 +45,46 @@ using BPrivate::gSystemCatalog;
#define B_TRANSLATION_CONTEXT "AboutWindow"
+class EscapeFilter : public BMessageFilter {
+ public:
+ EscapeFilter(BWindow* target)
+ :
+ BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
+ fTarget(target)
+ {
+ }
+ virtual ~EscapeFilter()
+ {
+ }
+ virtual filter_result
+ Filter(BMessage* message, BHandler** target)
+ {
+ filter_result result = B_DISPATCH_MESSAGE;
+ switch (message->what) {
+ case B_KEY_DOWN:
+ case B_UNMAPPED_KEY_DOWN: {
+ uint32 key;
+ if (message->FindInt32("raw_char",
+ (int32*)&key) >= B_OK) {
+ if (key == B_ESCAPE) {
+ result = B_SKIP_MESSAGE;
+ fTarget->PostMessage(
+ B_QUIT_REQUESTED);
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ return result;
+ }
+ private:
+ BWindow* fTarget;
+};
+
+
class StripeView : public BView {
public:
StripeView(BBitmap* icon);
@@ -366,6 +409,8 @@ BAboutWindow::BAboutWindow(const char* appName, const char* signature)
AddChild(fAboutView);
MoveTo(AboutPosition(Frame().Width(), Frame().Height()));
+
+ AddCommonFilter(new EscapeFilter(this));
}

0 comments on commit 381629a

Please sign in to comment.