#ifndef UI_CONTROL_BUTTON_H_ #define UI_CONTROL_BUTTON_H_ #pragma once namespace ui { template class UILIB_API ButtonTemplate : public LabelTemplate { public: ButtonTemplate(); /// 重写父类方法,提供个性化功能,请参考父类声明 virtual void Activate() override; virtual void HandleMessage(EventArgs& event) override; virtual UINT GetControlFlags() const override; /** * @brief 绑定鼠标点击处理函数 * @param[in] callback 要绑定的回调函数 * @return 无 */ void AttachClick(const EventCallback& callback) { this->OnEvent[kEventClick] += callback; } }; template UINT ui::ButtonTemplate::GetControlFlags() const { return this->IsKeyboardEnabled() && this->IsEnabled() ? UIFLAG_TABSTOP : UIFLAG_DEFAULT; } template ButtonTemplate::ButtonTemplate() { this->m_uTextStyle = DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_NOCLIP | DT_SINGLELINE; } template void ButtonTemplate::HandleMessage(EventArgs& event) { if (!this->IsMouseEnabled() && event.Type > kEventMouseBegin && event.Type < kEventMouseEnd) { if (this->m_pParent != NULL) this->m_pParent->HandleMessageTemplate(event); else __super::HandleMessage(event); return; } if (event.Type == kEventKeyDown) { if (this->IsKeyboardEnabled()) { if (event.chKey == VK_SPACE || event.chKey == VK_RETURN) { Activate(); return; } } } if (event.Type == kEventInternalMenu) { if (this->IsContextMenuUsed()) { this->m_pWindow->SendNotify(this, kEventMouseMenu, event.wParam, event.lParam); } return; } __super::HandleMessage(event); } template void ButtonTemplate::Activate() { if (!this->IsActivatable()) return; if (this->m_pWindow != NULL) this->m_pWindow->SendNotify(this, kEventClick); } typedef ButtonTemplate Button; typedef ButtonTemplate ButtonBox; } // namespace ui #endif // UI_CONTROL_BUTTON_H_