1: <?php   
  2:     /**
  3:      * Triggered when the selected item has changed. Not every select event
  4:      * will fire a change event.
  5:      * 
  6:      *  * event Type: Event 
  7:      * 
  8:      *  * ui Type: Object 
  9:      * 
 10:      *  * item Type: jQuery The active item.
 11:      * 
 12:      */
 13:     class QSelectMenu_ChangeEvent extends QJqUiEvent {
 14:         const EventName = 'selectmenuchange';
 15:     }
 16:     /**
 17:      * Triggered when the menu is hidden.
 18:      * 
 19:      *  * event Type: Event 
 20:      * 
 21:      * _Note: The ui object is empty but included for consistency with other
 22:      * events._  */
 23:     class QSelectMenu_CloseEvent extends QJqUiEvent {
 24:         const EventName = 'selectmenuclose';
 25:     }
 26:     /**
 27:      * Triggered when the selectmenu is created.
 28:      * 
 29:      *  * event Type: Event 
 30:      *  * ui Type: Object 
 31:      * 
 32:      * _Note: The ui object is empty but included for consistency with other
 33:      * events._  */
 34:     class QSelectMenu_CreateEvent extends QJqUiEvent {
 35:         const EventName = 'selectmenucreate';
 36:     }
 37:     /**
 38:      * Triggered when an items gains focus.
 39:      * 
 40:      *  * event Type: Event 
 41:      * 
 42:      *  * ui Type: Object 
 43:      * 
 44:      *  * item Type: jQuery The focused item.
 45:      * 
 46:      */
 47:     class QSelectMenu_FocusEvent extends QJqUiEvent {
 48:         const EventName = 'selectmenufocus';
 49:     }
 50:     /**
 51:      * Triggered when the menu is opened.
 52:      * 
 53:      *  * event Type: Event 
 54:      * 
 55:      * _Note: The ui object is empty but included for consistency with other
 56:      * events._  */
 57:     class QSelectMenu_OpenEvent extends QJqUiEvent {
 58:         const EventName = 'selectmenuopen';
 59:     }
 60:     /**
 61:      * Triggered when a menu item is selected.
 62:      * 
 63:      *  * event Type: Event 
 64:      * 
 65:      *  * ui Type: Object 
 66:      * 
 67:      *  * item Type: jQuery The selected item.
 68:      * 
 69:      */
 70:     class QSelectMenu_SelectEvent extends QJqUiEvent {
 71:         const EventName = 'selectmenuselect';
 72:     }
 73: 
 74:     /* Custom "property" event classes for this control */
 75: 
 76:     /**
 77:      * Generated QSelectMenuGen class.
 78:      * 
 79:      * This is the QSelectMenuGen class which is automatically generated
 80:      * by scraping the JQuery UI documentation website. As such, it includes all the options
 81:      * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
 82:      * the QSelectMenuBase class for any glue code to make this class more
 83:      * usable in QCubed.
 84:      * 
 85:      * @see QSelectMenuBase
 86:      * @package Controls\Base
 87:      * @property mixed $AppendTo
 88:      * Which element to append the menu to. When the value is null, the
 89:      * parents of the <select> are checked for a class name of ui-front. If
 90:      * an element with the ui-front class name is found, the menu is appended
 91:      * to that element. Regardless of the value, if no element is found, the
 92:      * menu is appended to the body.
 93:      *
 94:      * @property boolean $Disabled
 95:      * Disables the selectmenu if set to true.
 96:      *
 97:      * @property mixed $Icons
 98:      * Icons to use for the button, matching an icon defined by the jQuery UI
 99:      * CSS Framework. 
100:      * 
101:      *  * button (string, default: "ui-icon-triangle-1-s")
102:      * 
103: 
104:      *
105:      * @property mixed $Position
106:      * Identifies the position of the menu in relation to the associated
107:      * button element. You can refer to the jQuery UI Position utility for
108:      * more details about the various options.
109:      *
110:      * @property integer $Width
111:      * The width of the menu, in pixels. When the value is null, the width of
112:      * the native select is used.
113:      *
114:      */
115: 
116:     class QSelectMenuGen extends QListBox   {
117:         protected $strJavaScripts = __JQUERY_EFFECTS__;
118:         protected $strStyleSheets = __JQUERY_CSS__;
119:         /** @var mixed */
120:         protected $mixAppendTo = null;
121:         /** @var boolean */
122:         protected $blnDisabled = null;
123:         /** @var mixed */
124:         protected $mixIcons = null;
125:         /** @var mixed */
126:         protected $mixPosition = null;
127:         /** @var integer */
128:         protected $intWidth = null;
129: 
130:         /**
131:          * Builds the option array to be sent to the widget constructor.
132:          *
133:          * @return array key=>value array of options
134:          */
135:         protected function MakeJqOptions() {
136:             $jqOptions = null;
137:             if (!is_null($val = $this->AppendTo)) {$jqOptions['appendTo'] = $val;}
138:             if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
139:             if (!is_null($val = $this->Icons)) {$jqOptions['icons'] = $val;}
140:             if (!is_null($val = $this->Position)) {$jqOptions['position'] = $val;}
141:             if (!is_null($val = $this->Width)) {$jqOptions['width'] = $val;}
142:             return $jqOptions;
143:         }
144: 
145:         /**
146:          * Return the JavaScript function to call to associate the widget with the control.
147:          *
148:          * @return string
149:          */
150:         public function GetJqSetupFunction() {
151:             return 'selectmenu';
152:         }
153: 
154:         /**
155:          * Returns the script that attaches the JQueryUI widget to the html object.
156:          *
157:          * @return string
158:          */
159:         public function GetEndScript() {
160:             $strId = $this->GetJqControlId();
161:             $jqOptions = $this->makeJqOptions();
162:             $strFunc = $this->getJqSetupFunction();
163: 
164:             if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
165:                 // If events are not attached to the actual object being drawn, then the old events will not get
166:                 // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
167:                 QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
168:             }
169: 
170:             // Attach the javascript widget to the html object
171:             if (empty($jqOptions)) {
172:                 QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
173:             } else {
174:                 QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
175:             }
176: 
177:             return parent::GetEndScript();
178:         }
179: 
180:         /**
181:          * Closes the menu.
182:          * 
183:          *  * This method does not accept any arguments.
184:          */
185:         public function Close() {
186:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "close", QJsPriority::Low);
187:         }
188:         /**
189:          * Removes the selectmenu functionality completely. This will return the
190:          * element back to its pre-init state.
191:          * 
192:          *  * This method does not accept any arguments.
193:          */
194:         public function Destroy() {
195:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
196:         }
197:         /**
198:          * Disables the selectmenu.
199:          * 
200:          *  * This method does not accept any arguments.
201:          */
202:         public function Disable() {
203:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
204:         }
205:         /**
206:          * Enables the selectmenu.
207:          * 
208:          *  * This method does not accept any arguments.
209:          */
210:         public function Enable() {
211:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
212:         }
213:         /**
214:          * Retrieves the selectmenus instance object. If the element does not
215:          * have an associated instance, undefined is returned. 
216:          * 
217:          * Unlike other widget methods, instance() is safe to call on any element
218:          * after the selectmenu plugin has loaded.
219:          * 
220:          *  * This method does not accept any arguments.
221:          */
222:         public function Instance() {
223:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
224:         }
225:         /**
226:          * Returns a jQuery object containing the menu element.
227:          * 
228:          *  * This method does not accept any arguments.
229:          */
230:         public function MenuWidget() {
231:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "menuWidget", QJsPriority::Low);
232:         }
233:         /**
234:          * Opens the menu.
235:          * 
236:          *  * This method does not accept any arguments.
237:          */
238:         public function Open() {
239:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "open", QJsPriority::Low);
240:         }
241:         /**
242:          * Gets the value currently associated with the specified optionName. 
243:          * 
244:          * Note: For options that have objects as their value, you can get the
245:          * value of a specific key by using dot notation. For example, "foo.bar"
246:          * would get the value of the bar property on the foo option.
247:          * 
248:          *  * optionName Type: String The name of the option to get.
249:          * @param $optionName
250:          */
251:         public function Option($optionName) {
252:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
253:         }
254:         /**
255:          * Gets an object containing key/value pairs representing the current
256:          * selectmenu options hash.
257:          * 
258:          *  * This signature does not accept any arguments.
259:          */
260:         public function Option1() {
261:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
262:         }
263:         /**
264:          * Sets the value of the selectmenu option associated with the specified
265:          * optionName. 
266:          * 
267:          * Note: For options that have objects as their value, you can set the
268:          * value of just one property by using dot notation for optionName. For
269:          * example, "foo.bar" would update only the bar property of the foo
270:          * option.
271:          * 
272:          *  * optionName Type: String The name of the option to set.
273:          *  * value Type: Object A value to set for the option.
274:          * @param $optionName
275:          * @param $value
276:          */
277:         public function Option2($optionName, $value) {
278:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
279:         }
280:         /**
281:          * Sets one or more options for the selectmenu.
282:          * 
283:          *  * options Type: Object A map of option-value pairs to set.
284:          * @param $options
285:          */
286:         public function Option3($options) {
287:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
288:         }
289:         /**
290:          * Parses the original element and re-renders the menu. Processes any
291:          * <option> or <optgroup> elements that were added, removed or disabled.
292:          * 
293:          *  * This method does not accept any arguments.
294:          */
295:         public function Refresh() {
296:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "refresh", QJsPriority::Low);
297:         }
298: 
299: 
300:         public function __get($strName) {
301:             switch ($strName) {
302:                 case 'AppendTo': return $this->mixAppendTo;
303:                 case 'Disabled': return $this->blnDisabled;
304:                 case 'Icons': return $this->mixIcons;
305:                 case 'Position': return $this->mixPosition;
306:                 case 'Width': return $this->intWidth;
307:                 default: 
308:                     try { 
309:                         return parent::__get($strName); 
310:                     } catch (QCallerException $objExc) { 
311:                         $objExc->IncrementOffset(); 
312:                         throw $objExc; 
313:                     }
314:             }
315:         }
316: 
317:         public function __set($strName, $mixValue) {
318:             switch ($strName) {
319:                 case 'AppendTo':
320:                     $this->mixAppendTo = $mixValue;
321:                     $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'appendTo', $mixValue);
322:                     break;
323: 
324:                 case 'Disabled':
325:                     try {
326:                         $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
327:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
328:                         break;
329:                     } catch (QInvalidCastException $objExc) {
330:                         $objExc->IncrementOffset();
331:                         throw $objExc;
332:                     }
333: 
334:                 case 'Icons':
335:                     $this->mixIcons = $mixValue;
336:                     $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'icons', $mixValue);
337:                     break;
338: 
339:                 case 'Position':
340:                     $this->mixPosition = $mixValue;
341:                     $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'position', $mixValue);
342:                     break;
343: 
344:                 case 'Width':
345:                     try {
346:                         $this->intWidth = QType::Cast($mixValue, QType::Integer);
347:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'width', $this->intWidth);
348:                         break;
349:                     } catch (QInvalidCastException $objExc) {
350:                         $objExc->IncrementOffset();
351:                         throw $objExc;
352:                     }
353: 
354: 
355:                 case 'Enabled':
356:                     $this->Disabled = !$mixValue;   // Tie in standard QCubed functionality
357:                     parent::__set($strName, $mixValue);
358:                     break;
359:                     
360:                 default:
361:                     try {
362:                         parent::__set($strName, $mixValue);
363:                         break;
364:                     } catch (QCallerException $objExc) {
365:                         $objExc->IncrementOffset();
366:                         throw $objExc;
367:                     }
368:             }
369:         }
370: 
371:         /**
372:         * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
373:         * used by the ModelConnector designer dialog to display a list of options for the control.
374:         * @return QModelConnectorParam[]
375:         **/
376:         public static function GetModelConnectorParams() {
377:             return array_merge(parent::GetModelConnectorParams(), array(
378:                 new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the selectmenu if set to true.', QType::Boolean),
379:                 new QModelConnectorParam (get_called_class(), 'Width', 'The width of the menu, in pixels. When the value is null, the width ofthe native select is used.', QType::Integer),
380:             ));
381:         }
382:     }