menuNavigation.tscript 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. function UINavigation::setRootPage(%this, %rootPage)
  2. {
  3. if(!isObject(%this.pageStack))
  4. {
  5. %this.pageStack = new ArrayObject();
  6. }
  7. if(isObject(%this.rootPage))
  8. {
  9. %canClose = true;
  10. if(%this.rootPage.isMethod("canClose"))
  11. %canClose = %this.rootPage.call("canClose");
  12. if(!%canClose)
  13. return; //if we're not allowed to close, just bail out wholesale because clearly
  14. //something is blocking changes to pages
  15. %this.remove(%this.rootPage);
  16. if(%this.rootPage.isMethod("onClose"))
  17. %this.rootPage.call("onClose");
  18. %this.rootPage.navigation = "";
  19. }
  20. %this.rootPage = %rootPage;
  21. %this.add(%rootPage);
  22. if(%this.resizePages)
  23. {
  24. %rootPage.resize(%this.position.x, %this.position.y,
  25. %this.extent.x, %this.extent.y);
  26. }
  27. %rootPage.navigation = %this;
  28. if(%rootPage.isMethod("onOpen"))
  29. %rootPage.call("onOpen");
  30. }
  31. function UINavigation::pushPage(%this, %newPage, %callback)
  32. {
  33. if(!isObject(%this.pageStack))
  34. {
  35. %this.pageStack = new ArrayObject();
  36. }
  37. %canChange = true;
  38. if(%newPage.isMethod("canOpen"))
  39. %canChange = %newPage.call("canOpen");
  40. if(!%canChange)
  41. return;
  42. %currentPage = %this.getCurrentPage();
  43. if(isObject(%currentPage))
  44. {
  45. if(%currentPage.isMethod("canClose"))
  46. %canChange = %currentPage.call("canClose");
  47. if(!%canChange)
  48. return;
  49. if(%currentPage.isMethod("onClose"))
  50. %currentPage.call("onClose");
  51. }
  52. %this.pageStack.push_back(%newPage);
  53. %this.add(%newPage);
  54. if(%this.resizePages)
  55. {
  56. %newPage.resize(%this.position.x, %this.position.y,
  57. %this.extent.x, %this.extent.y);
  58. }
  59. if(%newPage.isMethod("onOpen"))
  60. %newPage.call("onOpen");
  61. %newPage.navigation = %this;
  62. if(%callback !$= "")
  63. eval(%callback);
  64. }
  65. function UINavigation::popPage(%this, %callback)
  66. {
  67. if(%this.pageStack.count() == 0)
  68. return;
  69. %currentPage = %this.getCurrentPage();
  70. if(isObject(%currentPage))
  71. {
  72. %canChange = true;
  73. if(%currentPage.isMethod("canClose"))
  74. %canChange = %currentPage.call("canClose");
  75. if(!%canChange)
  76. return;
  77. }
  78. %prevPage = %this.getPreviousPage();
  79. if(isObject(%prevPage))
  80. {
  81. %canChange = true;
  82. if(%prevPage.isMethod("canOpen"))
  83. %canChange = %prevPage.call("canOpen");
  84. if(!%canChange)
  85. return;
  86. }
  87. if(isObject(%currentPage))
  88. {
  89. if(%currentPage.isMethod("onClose"))
  90. {
  91. %currentPage.call("onClose");
  92. }
  93. %this.pageStack.pop_back();
  94. %this.remove(%currentPage);
  95. %currentPage.navigation = "";
  96. }
  97. %newTopPage = %this.getCurrentPage();
  98. if(%newTopPage.isMethod("onOpen"))
  99. %newTopPage.call("onOpen");
  100. if(%callback !$= "")
  101. eval(%callback);
  102. }
  103. function UINavigation::popToRoot(%this, %callback)
  104. {
  105. %pageChanged = false;
  106. while(%this.getPageCount() != 0)
  107. {
  108. %currentPage = %this.getCurrentPage();
  109. if(isObject(%currentPage))
  110. {
  111. if(%currentPage.isMethod("canClose"))
  112. %canChange = %currentPage.call("canClose");
  113. if(!%canChange)
  114. return;
  115. }
  116. %prevPage = %this.getPreviousPage();
  117. if(isObject(%prevPage))
  118. {
  119. if(%prevPage.isMethod("canOpen"))
  120. %canChange = %prevPage.call("canOpen");
  121. if(!%canChange)
  122. return;
  123. }
  124. if(isObject(%currentPage))
  125. {
  126. if(%currentPage.isMethod("onClose"))
  127. {
  128. %currentPage.call("onClose");
  129. }
  130. %this.pageStack.pop_back();
  131. %this.remove(%currentPage);
  132. %currentPage.navigation = "";
  133. }
  134. %newTopPage = %this.getCurrentPage();
  135. if(%newTopPage.isMethod("onOpen"))
  136. %newTopPage.call("onOpen");
  137. %pageChanged = true;
  138. }
  139. if(%pageChanged && %callback !$= "")
  140. eval(%callback);
  141. }
  142. function UINavigation::getCurrentPage(%this)
  143. {
  144. if(isObject(%this.pageStack) && %this.pageStack.count() != 0)
  145. {
  146. return %this.pageStack.getKey(%this.pageStack.count()-1);
  147. }
  148. else
  149. {
  150. if(isObject(%this.rootPage))
  151. return %this.rootPage;
  152. }
  153. return 0;
  154. }
  155. function UINavigation::getPreviousPage(%this)
  156. {
  157. if(isObject(%this.pageStack) && %this.pageStack.count() > 1)
  158. {
  159. return %this.pageStack.getKey(%this.pageStack.count()-2);
  160. }
  161. else
  162. {
  163. if(isObject(%this.rootPage))
  164. return %this.rootPage;
  165. }
  166. return 0;
  167. }
  168. function UINavigation::getPageCount(%this)
  169. {
  170. %count = 0;
  171. if(isObject(%this.pageStack))
  172. %count = %this.pageStack.count();
  173. if(isObject(%this.rootPage))
  174. %count++;
  175. return %count;
  176. }