1/* 2 3InterfaceUtils.cpp 4 5Copyright (c) 2002 Haiku. 6 7Author: 8 Michael Pfeiffer 9 10Permission is hereby granted, free of charge, to any person obtaining a copy of 11this software and associated documentation files (the "Software"), to deal in 12the Software without restriction, including without limitation the rights to 13use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 14of the Software, and to permit persons to whom the Software is furnished to do 15so, subject to the following conditions: 16 17The above copyright notice and this permission notice shall be included in all 18copies or substantial portions of the Software. 19 20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26THE SOFTWARE. 27 28*/ 29#ifndef _INTERFACE_UTILS_H 30#define _INTERFACE_UTILS_H 31 32 33#include <AppDefs.h> 34#include <MessageFilter.h> 35#include <Window.h> 36 37 38class BHandler; 39class BMessage; 40 41 42class EscapeMessageFilter : public BMessageFilter 43{ 44public: 45 EscapeMessageFilter(BWindow *window, int32 what); 46 filter_result Filter(BMessage *msg, BHandler **target); 47 48private: 49 BWindow* fWindow; 50 int32 fWhat; 51}; 52 53 54class HWindow : public BWindow 55{ 56 typedef BWindow inherited; 57public: 58 HWindow(BRect frame, const char *title, 59 window_type type, uint32 flags, 60 uint32 workspace = B_CURRENT_WORKSPACE, 61 uint32 escape_msg = B_QUIT_REQUESTED); 62 HWindow(BRect frame, const char *title, 63 window_look look, window_feel feel, uint32 flags, 64 uint32 workspace = B_CURRENT_WORKSPACE, 65 uint32 escape_msg = B_QUIT_REQUESTED); 66 virtual ~HWindow() {} 67 68 virtual void MessageReceived(BMessage* m); 69 virtual void AboutRequested(); 70 virtual const char* AboutText() const { return NULL; } 71 72protected: 73 void Init(uint32 escape_msg); 74}; 75 76 77class BlockingWindow : public HWindow 78{ 79 typedef HWindow inherited; 80public: 81 BlockingWindow(BRect frame, const char *title, 82 window_type type, uint32 flags, 83 uint32 workspace = B_CURRENT_WORKSPACE, 84 uint32 escape_msg = B_QUIT_REQUESTED); 85 BlockingWindow(BRect frame, const char *title, 86 window_look look, window_feel feel, uint32 flags, 87 uint32 workspace = B_CURRENT_WORKSPACE, 88 uint32 escape_msg = B_QUIT_REQUESTED); 89 virtual ~BlockingWindow(); 90 91 virtual bool QuitRequested(); 92 // Quit() is called by child class with result code 93 void Quit(status_t result); 94 // Show window and wait for it to quit, returns result code 95 virtual status_t Go(); 96 // Or quit window e.g. something went wrong in constructor 97 virtual void Quit(); 98 // Sets the result that is returned when the user closes the window. 99 // Default is B_OK. 100 void SetUserQuitResult(status_t result); 101 102private: 103 void Init(const char* title); 104 105private: 106 status_t fUserQuitResult; 107 bool fReadyToQuit; 108 sem_id fExitSem; 109 status_t* fResult; 110}; 111 112#endif 113