/*---------------------------------------------------------------------------* Copyright (C) 2010-2012 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ // Adds the tab to the list of tabs void TabObject::Add(Window* window, MenuItem* object, bool active) { if (this->next != this) Remove(); TabObject* end = window->dummyTab.prev; end->next = this; this->prev = end; this->next = &window->dummyTab; window->dummyTab.prev = this; this->object = object; this->active = active; this->window = window; } // Removes the tab from the list of tabs void TabObject::Remove() { // Oddly enough, one that isn't attached will end up doing nothing here this->next->prev = this->prev; this->prev->next = this->next; this->next = this; this->prev = this; this->active = false; } // Updates the cursor's position based on tabbing, if need be void WindowManager::UpdateTabbing() { if (!tabIndex || tabSubIndex != -1) return; peripheral->CursorX() = tabIndex->object->x + tabIndex->window->GetX(); peripheral->CursorY() = tabIndex->object->y + tabIndex->window->GetY(); // Make sure the tab is visible in the window! if (peripheral->CursorY() > tabIndex->window->GetTop()) { tabIndex->window->GetOffY() -= peripheral->CursorY() - tabIndex->window->GetTop(); if (tabIndex->window->GetOffY() < 0) tabIndex->window->GetOffY() = 0; tabIndex->window->GetMaster()->scrollBar->pos = tabIndex->window->GetOffY(); peripheral->CursorY() = tabIndex->object->y + tabIndex->window->GetY(); } if (peripheral->CursorY() < tabIndex->window->GetBottom()) { tabIndex->window->GetOffY() += tabIndex->window->GetBottom() - peripheral->CursorY(); if (tabIndex->window->GetOffY() < 0) tabIndex->window->GetOffY() = 0; tabIndex->window->GetMaster()->scrollBar->pos = tabIndex->window->GetOffY(); peripheral->CursorY() = tabIndex->object->y + tabIndex->window->GetY(); } } // Forces the tab to be on something valid, if tab was pressed void WindowManager::ForceValidTabForward() { //OSReport("\nStart: 0x%x\n", tabIndex); if (!tabIndex) return; Window* startWin = tabIndex->window; Window* window = startWin; TabObject* start = tabIndex; while (true) { // Loop through each tab this window has //OSReport("window = 0x%x(%s)\n", window, window->GetName()); while (window->Active() && tabIndex != &window->dummyTab) { //OSReport("0x%x\n", tabIndex); if (tabIndex->active && tabIndex->object->Active()) return; tabIndex = tabIndex->next; if (start == tabIndex) { //OSReport("No tab found!\n"); tabIndex = NULL; tabSubIndex = -1; return; } } //OSReport("-0x%x\n", tabIndex); // If the window has a child, loop through the child window next! if (window->child) { //OSReport("To child! "); window = window->child; tabIndex = window->dummyTab.next; if (start == tabIndex) break; continue; } // If we were in a child window, go back to the original master before going to the next window while (window->master) { window = window->master; //OSReport("master = 0x%x\n", window); } // Find the next non-child window! do { if (window->number + 1 < windowList.size()) window = windowList[window->number + 1]; else window = windowList[0]; //OSReport("next = 0x%x\n", window); } while (window->master); tabIndex = window->dummyTab.next; if (start == tabIndex) break; } //OSReport("No tab found!\n"); tabIndex = NULL; tabSubIndex = -1; } // Forces the tab to be on something valid, if tab was pressed void WindowManager::ForceValidTabBack() { if (!tabIndex) return; Window* startWin = tabIndex->window; Window* window = startWin; TabObject* start = tabIndex; while (true) { // Loop through each tab this window has while (window->Active() && tabIndex != &window->dummyTab) { if (tabIndex->active && tabIndex->object->Active()) return; tabIndex = tabIndex->prev; if (start == tabIndex) { tabIndex = NULL; tabSubIndex = -1; return; } } // If we were in a child window, go to the master next! if (window->master) { window = window->master; tabIndex = window->dummyTab.prev; if (start == tabIndex) break; continue; } // Find the previous non-child window! do { if (window->number > 0) window = windowList[window->number - 1]; else window = windowList[windowList.size() - 1]; } while (window->master); // Go to the furthest child of this window first while (window->child) window = window->child; tabIndex = window->dummyTab.prev; if (start == tabIndex) break; } tabIndex = NULL; tabSubIndex = -1; }