function UINavigation::setRootPage(%this, %rootPage) { if(!isObject(%this.pageStack)) { %this.pageStack = new ArrayObject(); } if(isObject(%this.rootPage)) { %canClose = true; if(%this.rootPage.isMethod("canClose")) %canClose = %this.rootPage.call("canClose"); if(!%canClose) return; //if we're not allowed to close, just bail out wholesale because clearly //something is blocking changes to pages %this.remove(%this.rootPage); if(%this.rootPage.isMethod("onClose")) %this.rootPage.call("onClose"); %this.rootPage.navigation = ""; } %this.rootPage = %rootPage; %this.add(%rootPage); if(%this.resizePages) { %rootPage.resize(%this.position.x, %this.position.y, %this.extent.x, %this.extent.y); } %rootPage.navigation = %this; if(%rootPage.isMethod("onOpen")) %rootPage.call("onOpen"); } function UINavigation::pushPage(%this, %newPage, %callback) { if(!isObject(%this.pageStack)) { %this.pageStack = new ArrayObject(); } %canChange = true; if(%newPage.isMethod("canOpen")) %canChange = %newPage.call("canOpen"); if(!%canChange) return; %currentPage = %this.getCurrentPage(); if(isObject(%currentPage)) { if(%currentPage.isMethod("canClose")) %canChange = %currentPage.call("canClose"); if(!%canChange) return; if(%currentPage.isMethod("onClose")) %currentPage.call("onClose"); } %this.pageStack.push_back(%newPage); %this.add(%newPage); if(%this.resizePages) { %newPage.resize(%this.position.x, %this.position.y, %this.extent.x, %this.extent.y); } if(%newPage.isMethod("onOpen")) %newPage.call("onOpen"); %newPage.navigation = %this; if(%callback !$= "") eval(%callback); } function UINavigation::popPage(%this, %callback) { if(%this.pageStack.count() == 0) return; %currentPage = %this.getCurrentPage(); if(isObject(%currentPage)) { %canChange = true; if(%currentPage.isMethod("canClose")) %canChange = %currentPage.call("canClose"); if(!%canChange) return; } %prevPage = %this.getPreviousPage(); if(isObject(%prevPage)) { %canChange = true; if(%prevPage.isMethod("canOpen")) %canChange = %prevPage.call("canOpen"); if(!%canChange) return; } if(isObject(%currentPage)) { if(%currentPage.isMethod("onClose")) { %currentPage.call("onClose"); } %this.pageStack.pop_back(); %this.remove(%currentPage); %currentPage.navigation = ""; } %newTopPage = %this.getCurrentPage(); if(%newTopPage.isMethod("onOpen")) %newTopPage.call("onOpen"); if(%callback !$= "") eval(%callback); } function UINavigation::popToRoot(%this, %callback) { %pageChanged = false; while(%this.getPageCount() != 0) { %currentPage = %this.getCurrentPage(); if(isObject(%currentPage)) { if(%currentPage.isMethod("canClose")) %canChange = %currentPage.call("canClose"); if(!%canChange) return; } %prevPage = %this.getPreviousPage(); if(isObject(%prevPage)) { if(%prevPage.isMethod("canOpen")) %canChange = %prevPage.call("canOpen"); if(!%canChange) return; } if(isObject(%currentPage)) { if(%currentPage.isMethod("onClose")) { %currentPage.call("onClose"); } %this.pageStack.pop_back(); %this.remove(%currentPage); %currentPage.navigation = ""; } %newTopPage = %this.getCurrentPage(); if(%newTopPage.isMethod("onOpen")) %newTopPage.call("onOpen"); %pageChanged = true; } if(%pageChanged && %callback !$= "") eval(%callback); } function UINavigation::getCurrentPage(%this) { if(isObject(%this.pageStack) && %this.pageStack.count() != 0) { return %this.pageStack.getKey(%this.pageStack.count()-1); } else { if(isObject(%this.rootPage)) return %this.rootPage; } return 0; } function UINavigation::getPreviousPage(%this) { if(isObject(%this.pageStack) && %this.pageStack.count() > 1) { return %this.pageStack.getKey(%this.pageStack.count()-2); } else { if(isObject(%this.rootPage)) return %this.rootPage; } return 0; } function UINavigation::getPageCount(%this) { %count = 0; if(isObject(%this.pageStack)) %count = %this.pageStack.count(); if(isObject(%this.rootPage)) %count++; return %count; }