PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/plugin/lib/control_factory.php

https://gitlab.com/slondon/fortissimo
PHP | 231 lines | 210 code | 19 blank | 2 comment | 4 complexity | 4bfd9ce9a0bcd94c7fcf07250bd52c6b MD5 | raw file
  1. <?php
  2. ///////////////////////////////////////////////////////////////////////////
  3. require_once 'lib/action_factory.php';
  4. class ControlFactory
  5. {
  6. public static function add_vgap(&$defs, $vgap)
  7. {
  8. $defs[] = array
  9. (
  10. GuiControlDef::kind => GUI_CONTROL_VGAP,
  11. GuiControlDef::specific_def =>
  12. array
  13. (
  14. GuiVGapDef::vgap => $vgap
  15. ),
  16. );
  17. }
  18. public static function add_label(&$defs, $title, $text)
  19. {
  20. $defs[] = array
  21. (
  22. GuiControlDef::name => '',
  23. GuiControlDef::title => $title,
  24. GuiControlDef::kind => GUI_CONTROL_LABEL,
  25. GuiControlDef::specific_def =>
  26. array
  27. (
  28. GuiLabelDef::caption => $text
  29. ),
  30. );
  31. }
  32. public static function add_button(&$defs,
  33. $handler, $add_params,
  34. $name, $title, $caption, $width)
  35. {
  36. $push_action =
  37. UserInputHandlerRegistry::create_action($handler,
  38. $name, $add_params);
  39. $push_action['params']['action_type'] = 'apply';
  40. $defs[] = array
  41. (
  42. GuiControlDef::name => $name,
  43. GuiControlDef::title => $title,
  44. GuiControlDef::kind => GUI_CONTROL_BUTTON,
  45. GuiControlDef::specific_def =>
  46. array
  47. (
  48. GuiButtonDef::caption => $caption,
  49. GuiButtonDef::width => $width,
  50. GuiButtonDef::push_action => $push_action,
  51. ),
  52. );
  53. }
  54. public static function add_close_dialog_button(&$defs,
  55. $caption, $width)
  56. {
  57. $defs[] = array
  58. (
  59. GuiControlDef::name => 'close',
  60. GuiControlDef::title => null,
  61. GuiControlDef::kind => GUI_CONTROL_BUTTON,
  62. GuiControlDef::specific_def =>
  63. array
  64. (
  65. GuiButtonDef::caption => $caption,
  66. GuiButtonDef::width => $width,
  67. GuiButtonDef::push_action =>
  68. ActionFactory::close_dialog(),
  69. ),
  70. );
  71. }
  72. public static function add_close_dialog_and_apply_button(&$defs,
  73. $handler, $add_params,
  74. $name, $caption, $width)
  75. {
  76. $push_action = UserInputHandlerRegistry::create_action(
  77. $handler, $name, $add_params);
  78. $push_action['params']['action_type'] = 'apply';
  79. $defs[] = array
  80. (
  81. GuiControlDef::name => $name,
  82. GuiControlDef::title => null,
  83. GuiControlDef::kind => GUI_CONTROL_BUTTON,
  84. GuiControlDef::specific_def =>
  85. array
  86. (
  87. GuiButtonDef::caption => $caption,
  88. GuiButtonDef::width => $width,
  89. GuiButtonDef::push_action =>
  90. ActionFactory::close_dialog_and_run($push_action),
  91. ),
  92. );
  93. }
  94. public static function add_custom_close_dialog_and_apply_button(&$defs,
  95. $name, $caption, $width, $action)
  96. {
  97. $defs[] = array
  98. (
  99. GuiControlDef::name => $name,
  100. GuiControlDef::title => null,
  101. GuiControlDef::kind => GUI_CONTROL_BUTTON,
  102. GuiControlDef::params =>
  103. array
  104. (
  105. 'button_caption_centered' => 1,
  106. ),
  107. GuiControlDef::specific_def =>
  108. array
  109. (
  110. GuiButtonDef::caption => $caption,
  111. GuiButtonDef::width => $width,
  112. GuiButtonDef::push_action =>
  113. ActionFactory::close_dialog_and_run($action),
  114. ),
  115. );
  116. }
  117. public static function add_text_field(&$defs,
  118. $handler, $add_params,
  119. $name, $title, $initial_value,
  120. $numeric, $password, $has_osk, $always_active, $width,
  121. $need_confirm = false, $need_apply = false)
  122. {
  123. $apply_action = null;
  124. if ($need_apply)
  125. {
  126. $apply_action = UserInputHandlerRegistry::create_action(
  127. $handler, $name, $add_params);
  128. $apply_action['params']['action_type'] = 'apply';
  129. }
  130. $confirm_action = null;
  131. if ($need_confirm)
  132. {
  133. $confirm_action = UserInputHandlerRegistry::create_action(
  134. $handler, $name, $add_params);
  135. $confirm_action['params']['action_type'] = 'confirm';
  136. }
  137. $defs[] = array
  138. (
  139. GuiControlDef::name => $name,
  140. GuiControlDef::title => $title,
  141. GuiControlDef::kind => GUI_CONTROL_TEXT_FIELD,
  142. GuiControlDef::specific_def =>
  143. array
  144. (
  145. GuiTextFieldDef::initial_value => strval($initial_value),
  146. GuiTextFieldDef::numeric => intval($numeric),
  147. GuiTextFieldDef::password => intval($password),
  148. GuiTextFieldDef::has_osk => intval($has_osk),
  149. GuiTextFieldDef::always_active => intval($always_active),
  150. GuiTextFieldDef::width => intval($width),
  151. GuiTextFieldDef::apply_action => $apply_action,
  152. GuiTextFieldDef::confirm_action => $confirm_action,
  153. ),
  154. );
  155. }
  156. public static function add_combobox(&$defs,
  157. $handler, $add_params,
  158. $name, $title, $initial_value, $value_caption_pairs, $width,
  159. $need_confirm = false, $need_apply = false)
  160. {
  161. $apply_action = null;
  162. if ($need_apply)
  163. {
  164. $apply_action = UserInputHandlerRegistry::create_action(
  165. $handler, $name, $add_params);
  166. $apply_action['params']['action_type'] = 'apply';
  167. }
  168. $confirm_action = null;
  169. if ($need_confirm)
  170. {
  171. $confirm_action = UserInputHandlerRegistry::create_action(
  172. $handler, $name, $add_params);
  173. $confirm_action['params']['action_type'] = 'confirm';
  174. }
  175. $defs[] = array
  176. (
  177. GuiControlDef::name => $name,
  178. GuiControlDef::title => $title,
  179. GuiControlDef::kind => GUI_CONTROL_COMBOBOX,
  180. GuiControlDef::specific_def =>
  181. array
  182. (
  183. GuiComboboxDef::initial_value => $initial_value,
  184. GuiComboboxDef::value_caption_pairs => $value_caption_pairs,
  185. GuiComboboxDef::width => $width,
  186. GuiComboboxDef::apply_action => $apply_action,
  187. GuiComboboxDef::confirm_action => $confirm_action,
  188. ),
  189. );
  190. }
  191. public static function add_multiline_label(&$defs, $title, $text, $lines = 2)
  192. {
  193. $defs[] = array
  194. (
  195. GuiControlDef::name => '',
  196. GuiControlDef::title => $title,
  197. GuiControlDef::kind => GUI_CONTROL_LABEL,
  198. GuiControlDef::specific_def =>
  199. array
  200. (
  201. GuiLabelDef::caption => $text,
  202. ),
  203. GuiControlDef::params =>
  204. array
  205. (
  206. 'max_lines' => $lines,
  207. )
  208. );
  209. }
  210. }
  211. ///////////////////////////////////////////////////////////////////////////
  212. ?>