#include "DormantNodeWindow.h"
#include "DormantNodeView.h"
#include "RouteWindow.h"
#include <Application.h>
#undef B_CATALOG
#define B_CATALOG (&sCatalog)
#include <Catalog.h>
#include <Screen.h>
#include <ScrollBar.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "CortexDormantNodeWindow"
__USE_CORTEX_NAMESPACE
#include <Debug.h>
#define D_ALLOC(x)
#define D_HOOK(x)
#define D_MESSAGE(x)
#define D_INTERNAL(x)
static BCatalog sCatalog("x-vnd.Cortex.DormantNodeView");
const BRect DormantNodeWindow::s_initFrame(500.0, 350.0, 640.0, 480.0);
DormantNodeWindow::DormantNodeWindow(
BWindow* parent)
: BWindow(s_initFrame,
B_TRANSLATE("Media add-ons"),
B_FLOATING_WINDOW_LOOK,
B_FLOATING_SUBSET_WINDOW_FEEL,
B_WILL_ACCEPT_FIRST_CLICK|B_AVOID_FOCUS|B_ASYNCHRONOUS_CONTROLS),
m_parent(parent),
m_zoomed(false),
m_zooming(false) {
D_ALLOC(("DormantNodeWindow::DormantNodeWindow()\n"));
ASSERT(m_parent);
AddToSubset(m_parent);
BRect r = Bounds();
r.right -= B_V_SCROLL_BAR_WIDTH;
m_listView = new DormantNodeView(r, "Dormant Node ListView", B_FOLLOW_ALL_SIDES);
r.left = r.right + 1.0;
r.right = r.left + B_V_SCROLL_BAR_WIDTH;
r.InsetBy(0.0, -1.0);
AddChild(new BScrollBar(r, "", m_listView, 0.0, 0.0, B_VERTICAL));
AddChild(m_listView);
_constrainToScreen();
}
DormantNodeWindow::~DormantNodeWindow() {
D_ALLOC(("DormantNodeWindow::~DormantNodeWindow()\n"));
}
bool DormantNodeWindow::QuitRequested() {
D_HOOK(("DormantNodeWindow::QuitRequested()\n"));
m_parent->PostMessage(RouteWindow::M_TOGGLE_DORMANT_NODE_WINDOW);
return false;
}
void DormantNodeWindow::Zoom(
BPoint origin,
float width,
float height) {
D_HOOK(("DormantNodeWindow::Zoom()\n"));
m_zooming = true;
BScreen screen(this);
if (!screen.Frame().Contains(Frame())) {
m_zoomed = false;
}
if (!m_zoomed) {
m_manualSize = Bounds();
m_listView->GetPreferredSize(&width, &height);
ResizeTo(width + B_V_SCROLL_BAR_WIDTH, height);
m_zoomed = true;
_constrainToScreen();
}
else {
ResizeTo(m_manualSize.Width(), m_manualSize.Height());
m_zoomed = false;
}
}
void DormantNodeWindow::_constrainToScreen() {
D_INTERNAL(("DormantNodeWindow::_constrainToScreen()\n"));
BScreen screen(this);
BRect screenRect = screen.Frame();
BRect windowRect = Frame();
if (!screenRect.Intersects(windowRect)) {
windowRect.OffsetTo(screenRect.LeftTop());
MoveTo(windowRect.LeftTop());
windowRect = Frame();
}
if (!screenRect.Contains(windowRect)) {
if (windowRect.left < screenRect.left) {
windowRect.left = screenRect.left + 5.0;
MoveTo(windowRect.LeftTop());
windowRect = Frame();
}
if (windowRect.top < screenRect.top) {
windowRect.top = screenRect.top + 5.0;
MoveTo(windowRect.LeftTop());
windowRect = Frame();
}
if (windowRect.right > screenRect.right) {
windowRect.right = screenRect.right - 5.0;
}
if (windowRect.bottom > screenRect.bottom) {
windowRect.bottom = screenRect.bottom - 5.0;
}
ResizeTo(windowRect.Width(), windowRect.Height());
}
}