| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- 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;
- }
|