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