2019-04-19 17:19:57 +08:00
|
|
|
|
#ifndef UI_CONTROL_BUTTON_H_
|
|
|
|
|
#define UI_CONTROL_BUTTON_H_
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
namespace ui
|
|
|
|
|
{
|
|
|
|
|
template<typename InheritType = Control>
|
|
|
|
|
class UILIB_API ButtonTemplate : public LabelTemplate<InheritType>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ButtonTemplate();
|
|
|
|
|
|
|
|
|
|
/// <20><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><E0B7BD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD><E1B9A9><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
virtual void Activate() override;
|
|
|
|
|
virtual void HandleMessage(EventArgs& event) override;
|
2019-07-17 15:29:33 +08:00
|
|
|
|
virtual UINT GetControlFlags() const override;
|
2019-04-19 17:19:57 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param[in] callback Ҫ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return <EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void AttachClick(const EventCallback& callback) { this->OnEvent[kEventClick] += callback; }
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-17 15:29:33 +08:00
|
|
|
|
template<typename InheritType>
|
|
|
|
|
UINT ui::ButtonTemplate<InheritType>::GetControlFlags() const
|
|
|
|
|
{
|
2019-08-26 09:52:10 +08:00
|
|
|
|
return this->IsKeyboardEnabled() && this->IsEnabled() ? UIFLAG_TABSTOP : UIFLAG_DEFAULT;
|
2019-07-17 15:29:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 17:19:57 +08:00
|
|
|
|
template<typename InheritType>
|
|
|
|
|
ButtonTemplate<InheritType>::ButtonTemplate()
|
|
|
|
|
{
|
|
|
|
|
this->m_uTextStyle = DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_NOCLIP | DT_SINGLELINE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename InheritType>
|
|
|
|
|
void ButtonTemplate<InheritType>::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<typename InheritType>
|
|
|
|
|
void ButtonTemplate<InheritType>::Activate()
|
|
|
|
|
{
|
|
|
|
|
if (!this->IsActivatable()) return;
|
|
|
|
|
if (this->m_pWindow != NULL) this->m_pWindow->SendNotify(this, kEventClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef ButtonTemplate<Control> Button;
|
|
|
|
|
typedef ButtonTemplate<Box> ButtonBox;
|
|
|
|
|
|
|
|
|
|
} // namespace ui
|
|
|
|
|
|
|
|
|
|
#endif // UI_CONTROL_BUTTON_H_
|