1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "Panel.h" 10 11 #include <stdio.h> 12 13 #include <InterfaceDefs.h> 14 #include <Message.h> 15 #include <MessageFilter.h> 16 17 class EscapeFilter : public BMessageFilter { 18 public: 19 EscapeFilter(Panel* target) 20 : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), 21 fPanel(target) 22 { 23 } 24 virtual ~EscapeFilter() 25 { 26 } 27 virtual filter_result Filter(BMessage* message, BHandler** target) 28 { 29 filter_result result = B_DISPATCH_MESSAGE; 30 switch (message->what) { 31 case B_KEY_DOWN: 32 case B_UNMAPPED_KEY_DOWN: { 33 uint32 key; 34 if (message->FindInt32("raw_char", (int32*)&key) >= B_OK) { 35 if (key == B_ESCAPE) { 36 result = B_SKIP_MESSAGE; 37 fPanel->Cancel(); 38 } 39 } 40 break; 41 } 42 default: 43 break; 44 } 45 return result; 46 } 47 private: 48 Panel* fPanel; 49 }; 50 51 // constructor 52 Panel::Panel(BRect frame, const char* title, 53 window_type type, uint32 flags, 54 uint32 workspace) 55 : BWindow(frame, title, type, flags, workspace) 56 { 57 _InstallFilter(); 58 } 59 60 // constructor 61 Panel::Panel(BRect frame, const char* title, 62 window_look look, window_feel feel, 63 uint32 flags, uint32 workspace) 64 : BWindow(frame, title, look, feel, flags, workspace) 65 { 66 _InstallFilter(); 67 } 68 69 // destructor 70 Panel::~Panel() 71 { 72 } 73 74 // MessageReceived 75 void 76 Panel::Cancel() 77 { 78 PostMessage(B_QUIT_REQUESTED); 79 } 80 81 // _InstallFilter 82 void 83 Panel::_InstallFilter() 84 { 85 AddCommonFilter(new EscapeFilter(this)); 86 } 87