6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
35 // defines the status area drawn in the bottom left corner of a Tracker window
38 #include "CountView.h"
40 #include <Application.h>
42 #include <ControlLook.h>
44 #include <MessageFormat.h>
48 #include "ContainerWindow.h"
51 #include "Utilities.h"
54 #undef B_TRANSLATION_CONTEXT
55 #define B_TRANSLATION_CONTEXT "CountView"
58 const bigtime_t kBarberPoleDelay
= 500000;
61 // #pragma mark - BCountView
64 BCountView::BCountView(BPoseView
* view
)
66 BView("CountVw", B_PULSE_NEEDED
| B_WILL_DRAW
),
69 fShowingBarberPole(false),
71 fLastBarberPoleOffset(5),
72 fStartSpinningAfter(0),
76 GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE
,
77 R_BarberPoleBitmap
, &fBarberPoleMap
);
81 BCountView::~BCountView()
83 delete fBarberPoleMap
;
88 BCountView::TrySpinningBarberPole()
90 if (!fShowingBarberPole
)
93 if (fStartSpinningAfter
&& system_time() < fStartSpinningAfter
)
96 // When the barber pole just starts spinning we need to invalidate
97 // the whole rectangle of text and barber pole.
98 // After this the text needs no updating since only the pole changes.
99 if (fStartSpinningAfter
) {
100 fStartSpinningAfter
= 0;
101 Invalidate(TextAndBarberPoleRect());
103 Invalidate(BarberPoleInnerRect());
110 TrySpinningBarberPole();
115 BCountView::EndBarberPole()
117 if (!fShowingBarberPole
)
120 fShowingBarberPole
= false;
126 BCountView::StartBarberPole()
128 AutoLock
<BWindow
> lock(Window());
129 if (fShowingBarberPole
)
132 fShowingBarberPole
= true;
133 fStartSpinningAfter
= system_time() + kBarberPoleDelay
;
134 // wait a bit before showing the barber pole
139 BCountView::BarberPoleInnerRect() const
141 BRect result
= Bounds();
142 result
.InsetBy(3, 4);
143 result
.left
= result
.right
- 7;
144 result
.bottom
= result
.top
+ 7;
150 BCountView::BarberPoleOuterRect() const
152 BRect
result(BarberPoleInnerRect());
153 result
.InsetBy(-1, -1);
159 BCountView::TextInvalRect() const
161 BRect result
= Bounds();
162 result
.InsetBy(4, 3);
164 // if the barber pole is not present, use its space for text
165 if (fShowingBarberPole
)
173 BCountView::TextAndBarberPoleRect() const
175 BRect result
= Bounds();
176 result
.InsetBy(4, 3);
183 BCountView::CheckCount()
185 // invalidate the count text area if necessary
186 if (fLastCount
!= fPoseView
->CountItems()) {
187 fLastCount
= fPoseView
->CountItems();
188 Invalidate(TextInvalRect());
191 // invalidate barber pole area if necessary
192 TrySpinningBarberPole();
197 BCountView::Draw(BRect updateRect
)
199 BRect
bounds(Bounds());
201 rgb_color color
= ViewColor();
203 color
= ui_color(B_DOCUMENT_BACKGROUND_COLOR
);
206 be_control_look
->DrawBorder(this, bounds
, updateRect
,
207 color
, B_PLAIN_BORDER
, 0,
208 BControlLook::B_BOTTOM_BORDER
| BControlLook::B_LEFT_BORDER
);
209 be_control_look
->DrawMenuBarBackground(this, bounds
, updateRect
, color
);
213 itemString
<< TypeAhead();
214 else if (IsFiltering()) {
215 itemString
<< fLastCount
<< " " << Filter();
218 itemString
<< B_TRANSLATE("no items");
220 static BMessageFormat
format(B_TRANSLATE_COMMENT(
221 "{0, plural, one{# item} other{# items}}",
222 "Number of selected items: \"1 item\" or \"2 items\""));
223 format
.Format(itemString
, fLastCount
);
227 BRect
textRect(TextInvalRect());
229 TruncateString(&itemString
, IsTypingAhead() ? B_TRUNCATE_BEGINNING
230 : IsFiltering() ? B_TRUNCATE_MIDDLE
: B_TRUNCATE_END
,
233 if (IsTypingAhead()) {
234 // use a muted gray for the typeahead
235 SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR
));
237 SetHighColor(ui_color(B_PANEL_TEXT_COLOR
));
239 MovePenTo(textRect
.LeftBottom());
240 DrawString(itemString
.String());
244 rgb_color light
= tint_color(ViewColor(), B_LIGHTEN_MAX_TINT
);
245 rgb_color shadow
= tint_color(ViewColor(), B_DARKEN_2_TINT
);
246 rgb_color lightShadow
= tint_color(ViewColor(), B_DARKEN_1_TINT
);
248 BeginLineArray(fShowingBarberPole
&& !fStartSpinningAfter
? 9 : 5);
250 if (!fShowingBarberPole
|| fStartSpinningAfter
) {
255 BRect
barberPoleRect(BarberPoleOuterRect());
257 AddLine(barberPoleRect
.LeftTop(), barberPoleRect
.RightTop(), shadow
);
258 AddLine(barberPoleRect
.LeftTop(), barberPoleRect
.LeftBottom(), shadow
);
259 AddLine(barberPoleRect
.LeftBottom(), barberPoleRect
.RightBottom(), light
);
260 AddLine(barberPoleRect
.RightBottom(), barberPoleRect
.RightTop(), light
);
263 barberPoleRect
.InsetBy(1, 1);
265 BRect
destRect(fBarberPoleMap
266 ? fBarberPoleMap
->Bounds() : BRect(0, 0, 0, 0));
267 destRect
.OffsetTo(barberPoleRect
.LeftTop()
268 - BPoint(0, fLastBarberPoleOffset
));
269 fLastBarberPoleOffset
-= 1;
270 if (fLastBarberPoleOffset
< 0)
271 fLastBarberPoleOffset
= 5;
274 region
.Set(BarberPoleInnerRect());
275 ConstrainClippingRegion(®ion
);
278 DrawBitmap(fBarberPoleMap
, destRect
);
283 BCountView::MouseDown(BPoint
)
285 BContainerWindow
* window
= dynamic_cast<BContainerWindow
*>(Window());
286 ThrowOnAssert(window
!= NULL
);
289 window
->UpdateIfNeeded();
291 if (fPoseView
->IsFilePanel() || fPoseView
->TargetModel() == NULL
)
294 if (!window
->TargetModel()->IsRoot()) {
295 BDirMenu
* menu
= new BDirMenu(NULL
, be_app
, B_REFS_RECEIVED
);
297 if (entry
.SetTo(window
->TargetModel()->EntryRef()) == B_OK
)
298 menu
->Populate(&entry
, Window(), false, false, true, false, true);
300 menu
->Populate(NULL
, Window(), false, false, true, false, true);
302 BPoint point
= Bounds().LeftBottom();
304 ConvertToScreen(&point
);
305 BRect
clickToOpenRect(Bounds());
306 ConvertToScreen(&clickToOpenRect
);
307 menu
->Go(point
, true, true, clickToOpenRect
);
314 BCountView::AttachedToWindow()
316 SetFont(be_plain_font
);
319 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
320 SetLowUIColor(ViewUIColor());
327 BCountView::SetTypeAhead(const char* string
)
329 fTypeAheadString
= string
;
335 BCountView::TypeAhead() const
337 return fTypeAheadString
.String();
342 BCountView::IsTypingAhead() const
344 return fTypeAheadString
.Length() != 0;
349 BCountView::AddFilterCharacter(const char* character
)
351 fFilterString
.AppendChars(character
, 1);
357 BCountView::RemoveFilterCharacter()
359 fFilterString
.TruncateChars(fFilterString
.CountChars() - 1);
365 BCountView::CancelFilter()
367 fFilterString
.Truncate(0);
373 BCountView::Filter() const
375 return fFilterString
.String();
380 BCountView::IsFiltering() const
382 return fFilterString
.Length() > 0;