TWebControl is the base class for controls that share a common set
of UI-related properties and methods. TWebControl-derived controls
are usually associated with HTML tags. They thus have tag name, attributes
and body contents. You can override {@link getTagName} to specify the tag name,
{@link addAttributesToRender} to specify the attributes to be rendered,
and {@link renderContents} to customize the body content rendering.
TWebControl encapsulates a set of properties related with CSS style fields,
such as {@link getBackColor BackColor}, {@link getBorderWidth BorderWidth}, etc.
Subclasses of TWebControl typically needs to override {@link addAttributesToRender}
and {@link renderContents}. The former is used to render the attributes
of the HTML tag associated with the control, while the latter is to render
the body contents enclosed within the HTML tag.
/** * Copies basic control attributes from another control. * Properties including AccessKey, ToolTip, TabIndex, Enabled * and Attributes are copied. * @param TWebControl source control */ public function copyBaseAttributes(TWebControl $control) { $this->setAccessKey($control->getAccessKey()); $this->setToolTip($control->getToolTip()); $this->setTabIndex($control->getTabIndex()); if (!$control->getEnabled()) { $this->setEnabled(false); } if ($control->getHasAttributes()) { $this->getAttributes()->copyFrom($control->getAttributes()); } }
/** * Renders the body content of the label. * @param THtmlWriter the renderer */ public function renderContents($writer) { if (($text = $this->getText()) === '') { parent::renderContents($writer); } else { $writer->write($text); } }
/** * Renders body content. * This method overrides the parent implementation by replacing * the body content with the processed text content. * @param THtmlWriter writer */ public function renderContents($writer) { if (($text = $this->getText()) === '' && $this->getHasControls()) { $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter()); parent::renderContents($htmlWriter); $text = $htmlWriter->flush(); } if ($text !== '') { $writer->write($this->processText($text)); } }
/** * Adds attributes related to an HTML image element to renderer. * @param THtmlWriter the writer used for the rendering purpose */ protected function addAttributesToRender($writer) { $writer->addAttribute('src', $this->getImageUrl()); $writer->addAttribute('alt', $this->getAlternateText()); if (($desc = $this->getDescriptionUrl()) !== '') { $writer->addAttribute('longdesc', $desc); } if (($align = $this->getImageAlign()) !== '') { $writer->addAttribute('align', $align); } parent::addAttributesToRender($writer); }
/** * Renders the body content of the hyperlink. * @param THtmlWriter the writer for rendering */ public function renderContents($writer) { if (($imageUrl = $this->getImageUrl()) === '') { if (($text = $this->getText()) !== '') { $writer->write(THttpUtility::htmlEncode($text)); } else { if ($this->getHasControls()) { parent::renderContents($writer); } else { $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl())); } } } else { $this->createImage($imageUrl)->renderControl($writer); } }
/** * Renders body contents of the tab view. * @param THtmlWriter the writer used for the rendering purpose. */ public function renderContents($writer) { if (($text = $this->getText()) !== '') { $writer->write($text); } else { if ($this->getHasControls()) { parent::renderContents($writer); } } }
public function render($writer) { parent::render($writer); if (($butt = $this->getDefaultButton()) !== '') { if (($button = $this->findControl($butt)) === null) { throw new TInvalidDataValueException('panel_defaultbutton_invalid', $butt); } else { $this->getPage()->getClientScript()->registerDefaultButton($this, $button); } } }
/** * Adds attribute name-value pairs to renderer. * This overrides the parent implementation with additional button specific attributes. * @param THtmlWriter the writer used for the rendering purpose */ protected function addAttributesToRender($writer) { if ($this->getID() !== '') { $writer->addAttribute('name', $this->getUniqueID()); } if (($src = $this->getFrameUrl()) !== '') { $writer->addAttribute('src', $src); } if (($align = strtolower($this->getAlign())) !== 'notset') { $writer->addAttribute('align', $align); } $scrollBars = $this->getScrollBars(); if ($scrollBars === TInlineFrameScrollBars::None) { $writer->addAttribute('scrolling', 'no'); } else { if ($scrollBars === TInlineFrameScrollBars::Both) { $writer->addAttribute('scrolling', 'yes'); } } if (!$this->getShowBorder()) { $writer->addAttribute('frameborder', '0'); } if (($longdesc = $this->getDescriptionUrl()) !== '') { $writer->addAttribute('longdesc', $longdesc); } if (($width = $this->getWidth()) !== -1) { $writer->addAttribute('width', $width); } if (($height = $this->getHeight()) !== -1) { $writer->addAttribute('height', $height); } if (($marginheight = $this->getMarginHeight()) !== -1) { $writer->addAttribute('marginheight', $marginheight); } if (($marginwidth = $this->getMarginWidth()) !== -1) { $writer->addAttribute('marginwidth', $marginwidth); } parent::addAttributesToRender($writer); }
/** * Renders the openning tag for the table control which will render table caption if present. * @param THtmlWriter the writer used for the rendering purpose */ public function renderBeginTag($writer) { parent::renderBeginTag($writer); if (($caption = $this->getCaption()) !== '') { if (($align = $this->getCaptionAlign()) !== TTableCaptionAlign::NotSet) { $writer->addAttribute('align', strtolower($align)); } $writer->renderBeginTag('caption'); $writer->write($caption); $writer->renderEndTag(); } }
/** * Renders the body content enclosed between the control tag. * This overrides the parent implementation with nothing to be rendered for input tags, * button tags are rendered normally. * @param THtmlWriter the writer used for the rendering purpose */ public function renderContents($writer) { if ($this->getButtonTag() === TButtonTag::Button) { parent::renderContents($writer); } }
public function render($writer) { $this->registerClientScript(); parent::render($writer); }
/** * Renders the datagrid. * @param THtmlWriter writer for the rendering purpose */ public function render($writer) { if ($this->getHasControls()) { $this->groupCells(); if ($this->_useEmptyTemplate) { $control = new TWebControl(); $control->setID($this->getClientID()); $control->copyBaseAttributes($this); if ($this->getHasStyle()) { $control->getStyle()->copyFrom($this->getStyle()); } $control->renderBeginTag($writer); $this->renderContents($writer); $control->renderEndTag($writer); } else { if ($this->getViewState('ItemCount', 0) > 0) { $this->applyItemStyles(); if ($this->_topPager) { $this->_topPager->renderControl($writer); $writer->writeLine(); } $this->renderTable($writer); if ($this->_bottomPager) { $writer->writeLine(); $this->_bottomPager->renderControl($writer); } } } } }
/** * Creates the child controls of the wizard. * This method overrides the parent implementation. * @param TEventParameter event parameter */ public function onInit($param) { parent::onInit($param); $this->ensureChildControls(); $this->setEnsureId(true); if ($this->getActiveStepIndex() < 0 && $this->getWizardSteps()->getCount() > 0) { $this->setActiveStepIndex(0); } }
/** * Renders the control. * The method overrides the parent implementation by rendering * the pager only when there are two or more pages. * @param THtmlWriter the writer */ public function render($writer) { if ($this->_pageCount > 1) { parent::render($writer); } }
/** * Ensures any pending databind is performed. * This method overrides the parent implementation. * @param TEventParameter event parameter */ public function onPreRender($param) { $this->_prerendered = true; $this->ensureDataBound(); parent::onPreRender($param); }
/** * Registers the checkbox to receive postback data during postback. * This is necessary because a checkbox if unchecked, when postback, * does not have direct mapping between post data and the checkbox name. * * This method overrides the parent implementation and is invoked before render. * @param mixed event parameter */ public function onPreRender($param) { parent::onPreRender($param); if ($this->getEnabled(true)) { $this->getPage()->registerRequiresPostData($this); } }
/** * Adds attribute name-value pairs to renderer. * This method overrides the parent implementation with additional TKeyboard specific attributes. * @param THtmlWriter the writer used for the rendering purpose */ protected function addAttributesToRender($writer) { parent::addAttributesToRender($writer); if ($this->getPage()->getClientSupportsJavaScript()) { $writer->addAttribute('id', $this->getClientID()); } }
/** * Ensure that the ID attribute is rendered and registers the javascript code * for initializing the active control. */ protected function addAttributesToRender($writer) { //calls the TWebControl to avoid rendering other attribute normally render for a textbox. TWebControl::addAttributesToRender($writer); $writer->addAttribute('id', $this->getLabelClientID()); $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions()); }
public function render($writer) { if ($this->getHasPreRendered()) { $this->setDisplay($this->getPageCount() == 1 ? TDisplayStyle::None : TDisplayStyle::Dynamic); TWebControl::render($writer); if ($this->getActiveControl()->canUpdateClientSide()) { $this->getPage()->getCallbackClient()->replaceContent($this, $writer); } } else { $this->getPage()->getAdapter()->registerControlToRender($this, $writer); } }
/** * Sets Enctype of the form on the page. * This method overrides the parent implementation and is invoked before render. * @param mixed event parameter */ public function onPreRender($param) { parent::onPreRender($param); if (($form = $this->getPage()->getForm()) !== null) { $form->setEnctype('multipart/form-data'); } $this->getPage()->getClientScript()->registerHiddenField('MAX_FILE_SIZE', $this->getMaxFileSize()); if ($this->getEnabled(true)) { $this->getPage()->registerRequiresPostData($this); } }
protected function addAttributesToRender($writer) { $display = $this->getDisplay(); $visible = $this->getEnabled(true) && count($this->getErrorMessages()) > 0; if (!$visible) { if ($display === TValidationSummaryDisplayStyle::None || $display === TValidationSummaryDisplayStyle::Dynamic) { $writer->addStyleAttribute('display', 'none'); } else { $writer->addStyleAttribute('visibility', 'hidden'); } } $writer->addAttribute('id', $this->getClientID()); parent::addAttributesToRender($writer); }
/** * Renders the repeated items. * @param THtmlWriter writer for the rendering purpose * @param IRepeatInfoUser repeat information user */ public function renderRepeater($writer, IRepeatInfoUser $user) { if ($this->_repeatLayout === TRepeatLayout::Table) { $control = new TTable(); if ($this->_caption !== '') { $control->setCaption($this->_caption); $control->setCaptionAlign($this->_captionAlign); } } else { if ($this->_repeatLayout === TRepeatLayout::Raw) { $this->renderRawContents($writer, $user); return; } else { $control = new TWebControl(); } } $control->setID($user->getClientID()); $control->copyBaseAttributes($user); if ($user->getHasStyle()) { $control->getStyle()->copyFrom($user->getStyle()); } $control->renderBeginTag($writer); $writer->writeLine(); if ($this->_repeatDirection === TRepeatDirection::Vertical) { $this->renderVerticalContents($writer, $user); } else { $this->renderHorizontalContents($writer, $user); } $control->renderEndTag($writer); }
/** * Registers CSS and JS. * This method is invoked right before the control rendering, if the control is visible. * @param mixed event parameter */ public function onPreRender($param) { parent::onPreRender($param); $this->registerStyleSheet(); $this->registerSliderClientScript(); }
/** * Renders an additional line-break after the opening tag when it * is in MultiLine text mode. * @param THtmlWriter the writer used for the rendering purpose^M */ public function renderBeginTag($writer) { parent::renderBeginTag($writer); if ($this->getTextMode() === 'MultiLine') { $writer->write("\n"); } }
protected function addAttributesToRender($writer) { parent::addAttributesToRender($writer); $writer->addAttribute('id', $this->getClientID()); }