2003-10-14 21:06:50 +04:00
|
|
|
/*
|
|
|
|
|
|
|
|
InterfaceUtils.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2002 OpenBeOS.
|
|
|
|
|
|
|
|
Author:
|
|
|
|
Michael Pfeiffer
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifndef _INTERFACE_UTILS_H
|
|
|
|
#define _INTERFACE_UTILS_H
|
|
|
|
|
2008-07-31 00:32:10 +04:00
|
|
|
|
|
|
|
#include <AppDefs.h>
|
2008-07-27 02:36:01 +04:00
|
|
|
#include <MessageFilter.h>
|
2008-07-31 00:32:10 +04:00
|
|
|
#include <Window.h>
|
|
|
|
|
|
|
|
|
|
|
|
class BHandler;
|
|
|
|
class BMessage;
|
2008-07-27 02:36:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
class EscapeMessageFilter : public BMessageFilter
|
|
|
|
{
|
|
|
|
public:
|
2008-07-31 00:32:10 +04:00
|
|
|
EscapeMessageFilter(BWindow *window, int32 what);
|
|
|
|
filter_result Filter(BMessage *msg, BHandler **target);
|
|
|
|
|
|
|
|
private:
|
|
|
|
BWindow* fWindow;
|
|
|
|
int32 fWhat;
|
2008-07-27 02:36:01 +04:00
|
|
|
};
|
|
|
|
|
2003-10-14 21:06:50 +04:00
|
|
|
|
|
|
|
class HWindow : public BWindow
|
|
|
|
{
|
|
|
|
typedef BWindow inherited;
|
2008-07-31 00:32:10 +04:00
|
|
|
public:
|
|
|
|
HWindow(BRect frame, const char *title,
|
|
|
|
window_type type, uint32 flags,
|
|
|
|
uint32 workspace = B_CURRENT_WORKSPACE,
|
|
|
|
uint32 escape_msg = B_QUIT_REQUESTED);
|
|
|
|
HWindow(BRect frame, const char *title,
|
|
|
|
window_look look, window_feel feel, uint32 flags,
|
|
|
|
uint32 workspace = B_CURRENT_WORKSPACE,
|
|
|
|
uint32 escape_msg = B_QUIT_REQUESTED);
|
|
|
|
virtual ~HWindow() {}
|
|
|
|
|
|
|
|
virtual void MessageReceived(BMessage* m);
|
|
|
|
virtual void AboutRequested();
|
|
|
|
virtual const char* AboutText() const { return NULL; }
|
2003-10-14 21:06:50 +04:00
|
|
|
|
2008-07-31 00:32:10 +04:00
|
|
|
protected:
|
|
|
|
void Init(uint32 escape_msg);
|
2003-10-14 21:06:50 +04:00
|
|
|
};
|
|
|
|
|
2008-07-27 02:36:01 +04:00
|
|
|
|
2003-10-14 21:06:50 +04:00
|
|
|
class BlockingWindow : public HWindow
|
|
|
|
{
|
2008-07-31 00:32:10 +04:00
|
|
|
typedef HWindow inherited;
|
2003-10-14 21:06:50 +04:00
|
|
|
public:
|
2008-07-31 00:32:10 +04:00
|
|
|
BlockingWindow(BRect frame, const char *title,
|
|
|
|
window_type type, uint32 flags,
|
|
|
|
uint32 workspace = B_CURRENT_WORKSPACE,
|
|
|
|
uint32 escape_msg = B_QUIT_REQUESTED);
|
|
|
|
BlockingWindow(BRect frame, const char *title,
|
|
|
|
window_look look, window_feel feel, uint32 flags,
|
|
|
|
uint32 workspace = B_CURRENT_WORKSPACE,
|
|
|
|
uint32 escape_msg = B_QUIT_REQUESTED);
|
|
|
|
virtual ~BlockingWindow();
|
|
|
|
|
|
|
|
virtual bool QuitRequested();
|
2003-10-14 21:06:50 +04:00
|
|
|
// Quit() is called by child class with result code
|
2008-07-31 00:32:10 +04:00
|
|
|
void Quit(status_t result);
|
2003-10-14 21:06:50 +04:00
|
|
|
// Show window and wait for it to quit, returns result code
|
2008-07-31 00:32:10 +04:00
|
|
|
virtual status_t Go();
|
2003-10-14 21:06:50 +04:00
|
|
|
// Or quit window e.g. something went wrong in constructor
|
2008-07-31 00:32:10 +04:00
|
|
|
virtual void Quit();
|
2007-01-20 18:52:37 +03:00
|
|
|
// Sets the result that is returned when the user closes the window.
|
|
|
|
// Default is B_OK.
|
2008-07-31 00:32:10 +04:00
|
|
|
void SetUserQuitResult(status_t result);
|
2003-10-14 21:06:50 +04:00
|
|
|
|
2008-07-31 00:32:10 +04:00
|
|
|
private:
|
|
|
|
void Init(const char* title);
|
2003-10-14 21:06:50 +04:00
|
|
|
|
2008-07-31 00:32:10 +04:00
|
|
|
private:
|
|
|
|
status_t fUserQuitResult;
|
|
|
|
bool fReadyToQuit;
|
|
|
|
sem_id fExitSem;
|
|
|
|
status_t* fResult;
|
2003-10-14 21:06:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|