1c284bb0fSMatt Madia/*
2c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon.
3c284bb0fSMatt Madia * All rights reserved.
4c284bb0fSMatt Madia *
5c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without
6c284bb0fSMatt Madia * modification, are permitted provided that the following conditions
7c284bb0fSMatt Madia * are met:
8c284bb0fSMatt Madia *
9c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright
10c284bb0fSMatt Madia *    notice, this list of conditions, and the following disclaimer.
11c284bb0fSMatt Madia *
12c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright
13c284bb0fSMatt Madia *    notice, this list of conditions, and the following disclaimer in the
14c284bb0fSMatt Madia *    documentation and/or other materials provided with the distribution.
15c284bb0fSMatt Madia *
16c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products
17c284bb0fSMatt Madia *    derived from this software without specific prior written permission.
18c284bb0fSMatt Madia *
19c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c284bb0fSMatt Madia */
30c284bb0fSMatt Madia
31c284bb0fSMatt Madia
32a0795c6fSMarcus Overhagen// TipWindow.cpp
33a0795c6fSMarcus Overhagen
34a0795c6fSMarcus Overhagen#include "TipWindow.h"
35a0795c6fSMarcus Overhagen#include "TipView.h"
36a0795c6fSMarcus Overhagen
37a0795c6fSMarcus Overhagen#include <Debug.h>
38a0795c6fSMarcus Overhagen
39a0795c6fSMarcus Overhagen__USE_CORTEX_NAMESPACE
40a0795c6fSMarcus Overhagen
41a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
42a0795c6fSMarcus Overhagen// *** dtor/ctors
43a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
44a0795c6fSMarcus Overhagen
45a0795c6fSMarcus OverhagenTipWindow::~TipWindow() {}
46a0795c6fSMarcus OverhagenTipWindow::TipWindow(
4723e67806SIthamar R. Adema	const char*							text) :
48a0795c6fSMarcus Overhagen	BWindow(
49a0795c6fSMarcus Overhagen		BRect(0,0,0,0),
50a0795c6fSMarcus Overhagen		"TipWindow",
51a0795c6fSMarcus Overhagen		B_NO_BORDER_WINDOW_LOOK,
52a0795c6fSMarcus Overhagen		B_FLOATING_ALL_WINDOW_FEEL,
53a0795c6fSMarcus Overhagen		B_NOT_MOVABLE|B_AVOID_FOCUS/*,
54a0795c6fSMarcus Overhagen		B_ALL_WORKSPACES*/),
55a0795c6fSMarcus Overhagen	// the TipView is created on demand
56a0795c6fSMarcus Overhagen	m_tipView(0) {
57a0795c6fSMarcus Overhagen
58a0795c6fSMarcus Overhagen	if(text)
59a0795c6fSMarcus Overhagen		m_text = text;
60a0795c6fSMarcus Overhagen}
61a0795c6fSMarcus Overhagen
62a0795c6fSMarcus Overhagen
63a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
64a0795c6fSMarcus Overhagen// *** operations (LOCK REQUIRED)
65a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
66a0795c6fSMarcus Overhagen
67a0795c6fSMarcus Overhagenconst char* TipWindow::text() const {
68a0795c6fSMarcus Overhagen	return m_text.Length() ?
69a0795c6fSMarcus Overhagen		m_text.String() :
70a0795c6fSMarcus Overhagen		0;
71a0795c6fSMarcus Overhagen}
72a0795c6fSMarcus Overhagen
73a0795c6fSMarcus Overhagenvoid TipWindow::setText(
74a0795c6fSMarcus Overhagen	const char*							text) {
75a0795c6fSMarcus Overhagen
76a0795c6fSMarcus Overhagen	if(!m_tipView)
77a0795c6fSMarcus Overhagen		_createTipView();
78a0795c6fSMarcus Overhagen
79a0795c6fSMarcus Overhagen	m_text = text;
80a0795c6fSMarcus Overhagen	m_tipView->setText(text);
81a0795c6fSMarcus Overhagen
82a0795c6fSMarcus Overhagen	// size to fit view
83a0795c6fSMarcus Overhagen	float width, height;
84a0795c6fSMarcus Overhagen	m_tipView->GetPreferredSize(&width, &height);
85a0795c6fSMarcus Overhagen	m_tipView->ResizeTo(width, height);
86a0795c6fSMarcus Overhagen	ResizeTo(width, height);
87a0795c6fSMarcus Overhagen
88a0795c6fSMarcus Overhagen	m_tipView->Invalidate();
89a0795c6fSMarcus Overhagen}
90a0795c6fSMarcus Overhagen
91a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
92a0795c6fSMarcus Overhagen// *** hooks
93a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
94a0795c6fSMarcus Overhagen
95a0795c6fSMarcus Overhagen// override to substitute your own view class
96a0795c6fSMarcus OverhagenTipView* TipWindow::createTipView() {
97a0795c6fSMarcus Overhagen	return new TipView;
98a0795c6fSMarcus Overhagen}
99a0795c6fSMarcus Overhagen
100a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
101a0795c6fSMarcus Overhagen// *** BWindow
102a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
103a0795c6fSMarcus Overhagen
104a0795c6fSMarcus Overhagen// initializes the tip view
105a0795c6fSMarcus Overhagenvoid TipWindow::Show() {
106a0795c6fSMarcus Overhagen
107a0795c6fSMarcus Overhagen	// initialize the tip view if necessary
108a0795c6fSMarcus Overhagen	if(!m_tipView)
109a0795c6fSMarcus Overhagen		_createTipView();
110a0795c6fSMarcus Overhagen
111a0795c6fSMarcus Overhagen	_inherited::Show();
112a0795c6fSMarcus Overhagen}
113a0795c6fSMarcus Overhagen
114a0795c6fSMarcus Overhagen// remove tip view? +++++
115a0795c6fSMarcus Overhagenvoid TipWindow::Hide() {
116a0795c6fSMarcus Overhagen	_inherited::Hide();
117a0795c6fSMarcus Overhagen}
118a0795c6fSMarcus Overhagen
119a0795c6fSMarcus Overhagen
120a0795c6fSMarcus Overhagen// hides the window when the user switches workspaces
121a0795c6fSMarcus Overhagen// +++++ should it be restored when the user switches back?
122a0795c6fSMarcus Overhagenvoid TipWindow::WorkspaceActivated(
123a0795c6fSMarcus Overhagen	int32										workspace,
124a0795c6fSMarcus Overhagen	bool										active) {
125a0795c6fSMarcus Overhagen
126a0795c6fSMarcus Overhagen	// don't confuse the user
127a0795c6fSMarcus Overhagen	if(!IsHidden())
128a0795c6fSMarcus Overhagen		Hide();
129a0795c6fSMarcus Overhagen
130a0795c6fSMarcus Overhagen	_inherited::WorkspaceActivated(workspace, active);
131a0795c6fSMarcus Overhagen}
132a0795c6fSMarcus Overhagen
133a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
134a0795c6fSMarcus Overhagen// implementation
135a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
136a0795c6fSMarcus Overhagen
137a0795c6fSMarcus Overhagenvoid TipWindow::_createTipView() {
138a0795c6fSMarcus Overhagen	if(m_tipView)
139a0795c6fSMarcus Overhagen		_destroyTipView();
140a0795c6fSMarcus Overhagen	m_tipView = createTipView();
141a0795c6fSMarcus Overhagen	ASSERT(m_tipView);
142a0795c6fSMarcus Overhagen
143a0795c6fSMarcus Overhagen	AddChild(m_tipView);
144a0795c6fSMarcus Overhagen
145a0795c6fSMarcus Overhagen	if(m_text.Length())
146a0795c6fSMarcus Overhagen		m_tipView->setText(m_text.String());
147a0795c6fSMarcus Overhagen	else
148a0795c6fSMarcus Overhagen		m_tipView->setText("(no info)");
149a0795c6fSMarcus Overhagen}
150a0795c6fSMarcus Overhagen
151a0795c6fSMarcus Overhagenvoid TipWindow::_destroyTipView() {
152a0795c6fSMarcus Overhagen	if(!m_tipView)
153a0795c6fSMarcus Overhagen		return;
154a0795c6fSMarcus Overhagen	RemoveChild(m_tipView);
155a0795c6fSMarcus Overhagen	delete m_tipView;
156a0795c6fSMarcus Overhagen	m_tipView = 0;
157a0795c6fSMarcus Overhagen}
158a0795c6fSMarcus Overhagen
15923e67806SIthamar R. Adema// END -- TipWindow.cpp --
160