Some other changes, make sure we delete all resources on destruction

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21329 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-06-05 12:10:44 +00:00
parent 75159db429
commit 059ca4bd97
+20 -14
View File
@@ -1,14 +1,15 @@
/* /*
* Copyright 2001-2006, Haiku, Inc. * Copyright 2001-2007, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Marc Flerackers ([email protected]) * Marc Flerackers ([email protected])
* Stefano Ceccherini ([email protected]) * Stefano Ceccherini ([email protected])
*/ */
//! BMenuWindow is a custom BWindow for BMenus. //! BMenuWindow is a custom BWindow for BMenus.
#include <Debug.h>
#include <Menu.h> #include <Menu.h>
#include <MenuPrivate.h> #include <MenuPrivate.h>
@@ -50,12 +51,14 @@ public:
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
}; };
class LowerScroller : public BMenuScroller { class LowerScroller : public BMenuScroller {
public: public:
LowerScroller(BRect frame); LowerScroller(BRect frame);
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
}; };
} // namespace BPrivate } // namespace BPrivate
@@ -142,7 +145,7 @@ LowerScroller::Draw(BRect updateRect)
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
B_DARKEN_2_TINT)); B_DARKEN_2_TINT));
FillRect(Bounds(), B_SOLID_LOW); FillRect(frame, B_SOLID_LOW);
float middle = Bounds().right / 2; float middle = Bounds().right / 2;
@@ -236,6 +239,7 @@ BMenuWindow::BMenuWindow(const char *name)
BMenuWindow::~BMenuWindow() BMenuWindow::~BMenuWindow()
{ {
DetachMenu();
} }
@@ -274,6 +278,9 @@ BMenuWindow::AttachScrollers()
if (!fMenu || !fMenuFrame) if (!fMenu || !fMenuFrame)
return; return;
if (fUpperScroller || fLowerScroller)
debugger("Scrollers are already attached!");
fMenu->MakeFocus(true); fMenu->MakeFocus(true);
BRect frame = Bounds(); BRect frame = Bounds();
@@ -298,6 +305,7 @@ BMenuWindow::DetachScrollers()
{ {
// BeOS doesn't remember the position where the last scrolling ended, // BeOS doesn't remember the position where the last scrolling ended,
// so we just scroll back to the beginning. // so we just scroll back to the beginning.
if (fMenu)
fMenu->ScrollTo(0, 0); fMenu->ScrollTo(0, 0);
if (fLowerScroller) { if (fLowerScroller) {
@@ -317,7 +325,7 @@ BMenuWindow::DetachScrollers()
bool bool
BMenuWindow::CheckForScrolling(BPoint cursor) BMenuWindow::CheckForScrolling(BPoint cursor)
{ {
if (!fMenuFrame) if (!fMenuFrame || !fUpperScroller || !fLowerScroller)
return false; return false;
return _Scroll(cursor); return _Scroll(cursor);
@@ -327,16 +335,15 @@ BMenuWindow::CheckForScrolling(BPoint cursor)
bool bool
BMenuWindow::_Scroll(BPoint cursor) BMenuWindow::_Scroll(BPoint cursor)
{ {
ASSERT((fLowerScroller != NULL));
ASSERT((fUpperScroller != NULL));
ConvertFromScreen(&cursor); ConvertFromScreen(&cursor);
BRect lowerFrame; BRect lowerFrame = fLowerScroller->Frame();
BRect upperFrame; BRect upperFrame = fUpperScroller->Frame();
if (fLowerScroller)
lowerFrame = fLowerScroller->Frame();
if (fUpperScroller)
upperFrame = fUpperScroller->Frame();
if (fLowerScroller && fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) { if (fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) {
if (fValue == 0) { if (fValue == 0) {
fUpperScroller->SetEnabled(true); fUpperScroller->SetEnabled(true);
fUpperScroller->Invalidate(); fUpperScroller->Invalidate();
@@ -354,7 +361,7 @@ BMenuWindow::_Scroll(BPoint cursor)
fMenu->ScrollBy(0, kScrollStep); fMenu->ScrollBy(0, kScrollStep);
fValue += kScrollStep; fValue += kScrollStep;
} }
} else if (fUpperScroller && fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) { } else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) {
if (fValue == fLimit) { if (fValue == fLimit) {
fLowerScroller->SetEnabled(true); fLowerScroller->SetEnabled(true);
fLowerScroller->Invalidate(); fLowerScroller->Invalidate();
@@ -370,9 +377,8 @@ BMenuWindow::_Scroll(BPoint cursor)
fMenu->ScrollBy(0, -kScrollStep); fMenu->ScrollBy(0, -kScrollStep);
fValue -= kScrollStep; fValue -= kScrollStep;
} }
} else { } else
return false; return false;
}
snooze(10000); snooze(10000);