Source for file CornersStyleCollection.class.php

Documentation is available at CornersStyleCollection.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."GUIManager/StyleCollection.interface.php");
  4.  
  5. /**
  6. * A StyleCollection is one of the tree building pieces of CSS styles. As the name
  7. * suggests it handles a collection of StyleProperties.
  8. *
  9. * The other two CSS styles building pieces are <code>StylePropertiy</code> and
  10. * <code>StyleComponent</code>. To clarify the relationship between these three
  11. * building pieces, consider the following example:
  12. * <pre>
  13. * div {
  14. * margin: 20px;
  15. * border: 1px solid #000;
  16. * }
  17. * </pre>
  18. * <code>div</code> is a <code>StyleCollection</code> consisting of 2
  19. * <code>StyleProperties</code>: <code>margin</code> and <code>border</code>. Each
  20. * of the latter consists of one or more <code>StyleComponents</code>. In
  21. * specific, <code>margin</code> consists of one <code>StyleComponent</code>
  22. * with the value <code>20px</code>, and <code>border</code> has three
  23. * <code>StyleComponents</code> with values <code>1px</code>, <code>solid</code>,
  24. * and <code>#000</code> correspondingly.
  25. *
  26. * @package harmoni.gui
  27. *
  28. * @copyright Copyright &copy; 2005, Middlebury College
  29. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  30. *
  31. * @version $Id: CornersStyleCollection.class.php,v 1.3 2005/12/12 16:06:14 adamfranco Exp $
  32. */
  33. class CornersStyleCollection
  34. extends StyleCollection
  35. {
  36. /**
  37. * @var array $_urls;
  38. * @access private
  39. * @since 11/28/05
  40. */
  41. var $_urls;
  42. /**
  43. * @var array $_positions;
  44. * @access private
  45. * @since 11/28/05
  46. */
  47. var $_positions;
  48. /**
  49. * The constructor.
  50. * @access public
  51. * @param string selector The selector of this StyleCollection.
  52. * @param string classSelector The class selector of this style collection. If <code>null</code>,
  53. * it will be ignored, but the collection will not be able to be applied
  54. * to components.
  55. * @param string displayName The display name of this StyleCollection.
  56. * @param string description The description of this StyleCollection.
  57. ***/
  58. function CornersStyleCollection($selector, $classSelector, $displayName, $description) {
  59. $this->StyleCollection($selector, $classSelector, $displayName, $description);
  60. $this->_positions = array("TopLeft", "TopRight", "BottomLeft", "BottomRight");
  61. $this->_urls = array();
  62. }
  63. /**
  64. * Set the url of the corner image
  65. *
  66. * @param string $position
  67. * @param string $url
  68. * @param optional int $height
  69. * @param optional int $width
  70. * @return void
  71. * @access public
  72. * @since 11/28/05
  73. */
  74. function setBorderUrl ($position, $url, $height = 15, $width = 15) {
  75. if (!in_array($position, $this->_positions))
  76. throwError(new Error("Invalid Position, $position"));
  77. $this->_urls[$position] = $url;
  78. $this->_heights[$position] = $height;
  79. $this->_widths[$position] = $width;
  80. }
  81. /**
  82. * Set the url of the corner image
  83. *
  84. * @param string $position
  85. * @return void
  86. * @access public
  87. * @since 11/28/05
  88. */
  89. function getBorderUrl ($position) {
  90. if (!in_array($position, $this->_positions))
  91. throwError(new Error("Invalid Position, $position"));
  92. return $this->_urls[$position];
  93. }
  94.  
  95. /**
  96. * Returns the CSS code for this StyleCollection.
  97. * @access public
  98. * @param string tabs This is a string (normally a bunch of tabs) that will be
  99. * prepended to each text line. This argument is optional but its usage is highly
  100. * recommended in order to produce a nicely formatted HTML output.
  101. * @return string The CSS code for this StyleCollection.
  102. ***/
  103. function getCSS($tabs = "") {
  104. // nothing to return
  105. if (count($this->_SPs) == 0)
  106. return "";
  107.  
  108. $wrapperValues = array();
  109. $contentValues = array();
  110. $wrapperKeys = array("display", "visibility", "position", "margin", "height", "width");
  111. foreach (array_keys($this->_SPs) as $key) {
  112. if (!in_array($key, $wrapperKeys))
  113. $contentValues[] = $this->_SPs[$key]->getCSS();
  114. else {
  115. if (strstr("margin", $key)) {
  116. $wrapperValues[] = str_replace("margin", "padding", $this->_SPs[$key]->getCSS());
  117. } else {
  118. $wrapperValues[] = $this->_SPs[$key]->getCSS();
  119. }
  120. }
  121. }
  122. $css = $tabs.$this->_selector." {\n\t".$tabs;
  123. $css .= implode("\n\t".$tabs, $wrapperValues);
  124. $css .= "\n".$tabs."\tborder: 0px;\n";
  125. $css .= $tabs."}\n";
  126. $css .= $tabs.$this->_selector."Content {\n\t".$tabs;
  127. $css .= implode("\n\t".$tabs, $contentValues);
  128. $css .= "\n".$tabs."\tmargin: 0px;\n";
  129. $css .= $tabs."}\n";
  130. $css .= $tabs.".".$this->_classSelector."TopCorners, ."
  131. .$this->_classSelector."BottomCorners {\n";
  132. $css .= $tabs."\tmargin: 0px;\n";
  133. $css .= $tabs."\tpadding: 0px;\n";
  134. $css .= $tabs."}\n";
  135. $css .= $tabs.".".$this->_classSelector."Spacer {\n";
  136. $css .= $tabs."\tmargin: 0px; padding: 0px; border: 0px;\n";
  137. $css .= $tabs."\tclear: both;\n";
  138. $css .= $tabs."\tfont-size: 1px; line-height: 1px;\n";
  139. $css .= $tabs."}\n";
  140. $css .= "
  141.  
  142. /* In the CSS below, the numbers used are the following:
  143. 1px: the width of the border
  144. 3px: a fudge factor needed for IE5/win (see below)
  145. 4px: the width of the border (1px) plus the 3px IE5/win fudge factor
  146. 14px: the width or height of the border image
  147. */
  148. ";
  149. $css .= $tabs.".".$this->_classSelector."BorderTL,"
  150. ." .".$this->_classSelector."BorderTR,"
  151. ." .".$this->_classSelector."BorderBL,"
  152. ." .".$this->_classSelector."BorderBR {\n";
  153. $css .= $tabs."\twidth: 14px; height: 14px;\n";
  154. $css .= $tabs."\tpadding: 0px; border: 0px;\n";
  155. $css .= $tabs."\tz-index: 99;\n";
  156. $css .= $tabs."}\n";
  157. $css .= $tabs.".".$this->_classSelector."BorderTL,"
  158. ." .".$this->_classSelector."BorderBL {\n";
  159. $css .= $tabs."\tfloat: left;\n";
  160. $css .= $tabs."\tclear: both;\n";
  161. $css .= $tabs."}\n";
  162. $css .= $tabs.".".$this->_classSelector."BorderTR,"
  163. ." .".$this->_classSelector."BorderBR {\n";
  164. $css .= $tabs."\tfloat: right;\n";
  165. $css .= $tabs."\tclear: right;\n";
  166. $css .= $tabs."}\n";
  167. $css .= $tabs.".".$this->_classSelector."BorderTL {\n";
  168. $css .= $tabs."\tmargin: 0px 0px 0px 0px;\n";
  169. $css .= $tabs."}\n";
  170. $css .= $tabs.".".$this->_classSelector."BorderTR {\n";
  171. $css .= $tabs."\tmargin: -0px -0px 0px 0px;\n";
  172. $css .= $tabs."}\n";
  173. $css .= $tabs.".".$this->_classSelector."BorderBL {\n";
  174. $css .= $tabs."\tmargin: -14px 0px 0px 0px;\n";
  175. $css .= $tabs."}\n";
  176. $css .= $tabs.".".$this->_classSelector."BorderBR {\n";
  177. $css .= $tabs."\tmargin: -14px 0px 0px 0px;\n";
  178. $css .= $tabs."}\n";
  179. // Stuff for aligning on IE
  180. $css .= $tabs.".".$this->_classSelector."BorderTL {\n";
  181. $css .= $tabs."\t margin-left: -4px;\n";
  182. $css .= $tabs."\t ma\\rgin-left: -1px;\n";
  183. $css .= $tabs."}\n";
  184. $css .= $tabs."html>body .".$this->_classSelector."BorderTL {\n";
  185. $css .= $tabs."\t margin-left: 0px;\n";
  186. $css .= $tabs."}\n";
  187. $css .= $tabs.".".$this->_classSelector."BorderTR {\n";
  188. $css .= $tabs."\t margin-right: -4px;\n";
  189. $css .= $tabs."\t ma\\rgin-right: -1px;\n";
  190. $css .= $tabs."}\n";
  191. $css .= $tabs."html>body .".$this->_classSelector."BorderTR {\n";
  192. $css .= $tabs."\t margin-right: 0px;\n";
  193. $css .= $tabs."}\n";
  194. $css .= $tabs.".".$this->_classSelector."BorderBL {\n";
  195. $css .= $tabs."\t margin-left: -3px;\n";
  196. $css .= $tabs."\t ma\\rgin-left: 0px;\n";
  197. $css .= $tabs."}\n";
  198. $css .= $tabs."html>body .".$this->_classSelector."BorderBL {\n";
  199. $css .= $tabs."\t margin-left: -0px;\n";
  200. $css .= $tabs."}\n";
  201. $css .= $tabs.".".$this->_classSelector."BorderBR {\n";
  202. $css .= $tabs."\t margin-left: -3px;\n";
  203. $css .= $tabs."\t ma\\rgin-left: 0px;\n";
  204. $css .= $tabs."}\n";
  205. $css .= $tabs."html>body .".$this->_classSelector."BorderBR {\n";
  206. $css .= $tabs."\t margin-left: 0px;\n";
  207. $css .= $tabs."}\n";
  208. return $css;
  209. }
  210.  
  211. /**
  212. * Return HTML to nested inside of the component's block. This includes
  213. * things such as corner images.
  214. *
  215. * See the example below:
  216. * <pre>
  217. * <div class='block3'>
  218. *
  219. * <!-- preHTML start -->
  220. * <div class="content">
  221. * <img class="borderTL" src="images/block3_TL.gif" width="14" height="14" />
  222. * <img class="borderTR" src="images/block3_TR.gif" width="14" height="14" />
  223. * <!-- preHTML end -->
  224. *
  225. * <h1>Hello world! (this is when my component renders itself)</h1>
  226. *
  227. * <!-- postHTML start -->
  228. * <div class="roundedCornerSpacer">&nbsp;</div>
  229. * </div>
  230. * <div class="bottomCorners">
  231. * <img class="borderBL" src="images/block3_BL.gif" width="14" height="14" />
  232. * <img class="borderBR" src="images/block3_BR.gif" width="14" height="14" />
  233. * </div>
  234. * <!-- postHTML end -->
  235. *
  236. * </div>
  237. * </pre>
  238. *
  239. * @param string $tabs
  240. * @return string
  241. * @access public
  242. * @since 11/22/05
  243. */
  244. function getPreHTML ($tabs) {
  245. $html = $tabs."<div class='".$this->_classSelector."TopCorners'>\n";
  246. $html .= $tabs."\t<img class='".$this->_classSelector."BorderTL' src='"
  247. .$this->getBorderUrl('TopLeft')."' alt='&nbsp;' width='14' height='14' />\n";
  248. $html .= $tabs."\t<img class='".$this->_classSelector."BorderTR' src='"
  249. .$this->getBorderUrl('TopRight')."' alt='&nbsp;' width='14' height='14' />\n";
  250. $html .= $tabs."</div>\n";
  251. $html .= $tabs."<div class='".$this->_classSelector."Content'>\n";
  252. return $html;
  253. }
  254. /**
  255. * Return HTML to nested inside of the component's block. This includes
  256. * things such as corner images.
  257. *
  258. * See the example below:
  259. * <pre>
  260. * <div class='block3'>
  261. *
  262. * <!-- preHTML start -->
  263. * <div class="content">
  264. * <img class="borderTL" src="images/block3_TL.gif" width="14" height="14" />
  265. * <img class="borderTR" src="images/block3_TR.gif" width="14" height="14" />
  266. * <!-- preHTML end -->
  267. *
  268. * <h1>Hello world! (this is when my component renders itself)</h1>
  269. *
  270. * <!-- postHTML start -->
  271. * <div class="roundedCornerSpacer">&nbsp;</div>
  272. * </div>
  273. * <div class="bottomCorners">
  274. * <img class="borderBL" src="images/block3_BL.gif" width="14" height="14" />
  275. * <img class="borderBR" src="images/block3_BR.gif" width="14" height="14" />
  276. * </div>
  277. * <!-- postHTML end -->
  278. *
  279. * </div>
  280. * </pre>
  281. *
  282. * @param string $tabs
  283. * @return string
  284. * @access public
  285. * @since 11/22/05
  286. */
  287. function getPostHTML ($tabs) {
  288. // $html = "\n".$tabs."\t<!-- IE5/win puts the margin-bottom of the content div's final element";
  289. // $html .= "\n".$tabs."\tOUTSIDE the containing box (div.content), instead of putting it inside";
  290. // $html .= "\n".$tabs."\tthe containing box\'s edge. So it needs this spacer. -->\n";
  291. $html = $tabs."\t<div class='".$this->_classSelector."Spacer'>&nbsp;</div>\n";
  292. $html .= $tabs."</div>\n";
  293. // $html .= "<!-- end of div.content -->\n";
  294. $html .= $tabs."<div class='".$this->_classSelector."BottomCorners'>\n";
  295. $html .= $tabs."\t<img class='".$this->_classSelector."BorderBL' src='"
  296. .$this->getBorderUrl('BottomLeft')."' alt='&nbsp;' width='14' height='14' />\n";
  297. $html .= $tabs."\t<img class='".$this->_classSelector."BorderBR' src='"
  298. .$this->getBorderUrl('BottomRight')."' alt='&nbsp;' width='14' height='14' />\n";
  299. $html .= $tabs."</div>\n";
  300. return $html;
  301. }
  302. }
  303.  
  304. ?>

Documentation generated on Wed, 19 Sep 2007 10:22:12 -0400 by phpDocumentor 1.3.0RC3