* Copyright (c) 1999-2000, Eric Moon.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "TipWindow.h"
#include "TipView.h"
#include <Debug.h>
#undef B_CATALOG
#define B_CATALOG (&sCatalog)
#include <Catalog.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "TipWindow"
__USE_CORTEX_NAMESPACE
static BCatalog sCatalog("x-vnd.Cortex.TipManager");
TipWindow::~TipWindow() {}
TipWindow::TipWindow(
const char* text) :
BWindow(
BRect(0,0,0,0),
"TipWindow",
B_NO_BORDER_WINDOW_LOOK,
B_FLOATING_ALL_WINDOW_FEEL,
B_NOT_MOVABLE|B_AVOID_FOCUS
B_ALL_WORKSPACES*/),
m_tipView(0) {
if(text)
m_text = text;
}
const char* TipWindow::text() const {
return m_text.Length() ?
m_text.String() :
0;
}
void TipWindow::setText(
const char* text) {
if(!m_tipView)
_createTipView();
m_text = text;
m_tipView->setText(text);
float width, height;
m_tipView->GetPreferredSize(&width, &height);
m_tipView->ResizeTo(width, height);
ResizeTo(width, height);
m_tipView->Invalidate();
}
TipView* TipWindow::createTipView() {
return new TipView;
}
void TipWindow::Show() {
if(!m_tipView)
_createTipView();
_inherited::Show();
}
void TipWindow::Hide() {
_inherited::Hide();
}
void TipWindow::WorkspaceActivated(
int32 workspace,
bool active) {
if(!IsHidden())
Hide();
_inherited::WorkspaceActivated(workspace, active);
}
void TipWindow::_createTipView() {
if(m_tipView)
_destroyTipView();
m_tipView = createTipView();
ASSERT(m_tipView);
AddChild(m_tipView);
if(m_text.Length())
m_tipView->setText(m_text.String());
else
m_tipView->setText(B_TRANSLATE("(no info)"));
}
void TipWindow::_destroyTipView() {
if(!m_tipView)
return;
RemoveChild(m_tipView);
delete m_tipView;
m_tipView = 0;
}