#include "CtrlLib.h" NAMESPACE_UPP #define LLOG(x) // LOG(x) void Pusher::RefreshFocus() { Refresh(); } void Pusher::RefreshPush() { Refresh(); } void Pusher::PerformAction() { WhenAction(); } void Pusher::GotFocus() { RefreshFocus(); } void Pusher::LostFocus() { if(keypush) EndPush(); RefreshFocus(); } void Pusher::LeftDown(Point, dword) { if(Ctrl::ClickFocus() || clickfocus) SetWantFocus(); if(IsReadOnly()) return; push = true; RefreshPush(); WhenPush(); } void Pusher::MouseMove(Point, dword style) { LLOG("Mouse move !"); if(IsReadOnly()) return; bool b = style & K_MOUSELEFT; if(b != push) { push = b; RefreshPush(); } } void Pusher::MouseLeave() { EndPush(); } void Pusher::LeftRepeat(Point, dword) { if(IsReadOnly()) return; WhenRepeat(); } void Pusher::LeftUp(Point, dword) { FinishPush(); } dword Pusher::GetAccessKeys() const { return AccessKeyBit(accesskey); } void Pusher::AssignAccessKeys(dword used) { if(!accesskey) { accesskey = ChooseAccessKey(label, used); if(accesskey) Refresh(); used |= AccessKeyBit(accesskey); } Ctrl::AssignAccessKeys(used); } void Pusher::State(int) { if(keypush && GetTopCtrl() && !GetTopCtrl()->HasFocusDeep()) EndPush(); } void Pusher::KeyPush() { if(IsReadOnly()) return; if(keypush) { WhenRepeat(); return; } push = keypush = true; RefreshPush(); WhenPush(); } bool Pusher::FinishPush() { if(!IsPush()) return false; EndPush(); if(IsReadOnly()) return false; PerformAction(); return true; } bool Pusher::Key(dword key, int) { if(IsReadOnly()) return false; if(key == K_SPACE) { KeyPush(); return true; } if(key == (K_SPACE|K_KEYUP)) return FinishPush(); return false; } bool Pusher::HotKey(dword key) { if(CompareAccessKey(accesskey, key)) { PseudoPush(); return true; } return false; } void Pusher::PseudoPush() { if(IsReadOnly() || !IsEnabled()) return; KeyPush(); Sync(); Sleep(50); FinishPush(); } void Pusher::EndPush() { if(push || keypush) RefreshPush(); keypush = push = false; } Pusher& Pusher::SetFont(Font fnt) { font = fnt; Refresh(); return *this; } Pusher& Pusher::ClickFocus(bool cf) { clickfocus = cf; return *this; } String Pusher::GetDesc() const { return label; } Pusher& Pusher::SetLabel(const char *atext) { accesskey = ExtractAccessKey(atext, label); Refresh(); return *this; } void Pusher::CancelMode() { EndPush(); } int Pusher::GetVisualState() const { return !IsShowEnabled() ? CTRL_DISABLED : IsPush() ? CTRL_PRESSED : HasMouse() ? CTRL_HOT : CTRL_NORMAL; } Pusher::Pusher() { keypush = push = clickfocus = false; accesskey = 0; font = StdFont(); NoInitFocus(); } Pusher::~Pusher() {} // ---------------- CH_STYLE(Button, Style, StyleNormal) { CtrlsImageLook(look, CtrlsImg::I_B); monocolor[0] = monocolor[1] = monocolor[2] = monocolor[3] = Blend(Blend(SColorHighlight, SColorShadow), SColorLabel, 80); textcolor[0] = textcolor[1] = textcolor[2] = SColorLabel(); textcolor[3] = SColorDisabled(); font = StdFont(); pressoffset = Point(0, 0); focusmargin = 3; overpaint = 0; transparent = true; } CH_STYLE(Button, Style, StyleOk) { Assign(Button::StyleNormal()); CtrlsImageLook(look, CtrlsImg::I_OkB); } CH_STYLE(Button, Style, StyleEdge) { Assign(Button::StyleNormal()); CtrlsImageLook(look, CtrlsImg::I_EB); } CH_STYLE(Button, Style, StyleLeftEdge) { Assign(Button::StyleEdge()); } CH_STYLE(Button, Style, StyleScroll) { Assign(Button::StyleNormal()); CtrlsImageLook(look, CtrlsImg::I_SB); } Color ButtonMonoColor(int i) { return Button::StyleNormal().monocolor[i]; } Button& Button::Ok() { if(IsNull(img)) img = St()->ok; type = OK; Refresh(); return *this; } Button& Button::Cancel() { if(IsNull(img)) img = St()->cancel; type = CANCEL; Refresh(); return *this; } Button& Button::Exit() { if(IsNull(img)) img = St()->exit; type = EXIT; Refresh(); return *this; } const Button::Style *GetButtonStyle(const Ctrl *q) { const Button::Style *st = &Button::StyleNormal(); if(q->InFrame()) { st = &Button::StyleEdge(); if(q->GetParent()) { Rect r = q->GetRect(); Size sz = q->GetParent()->GetRect().GetSize(); if(r.right < sz.cx / 2) st = &Button::StyleLeftEdge(); } } return st; } int Button::OverPaint() const { return St()->overpaint; } Button& Button::SetStyle(const Button::Style& s) { if(style != &s) { style = &s; RefreshLayout(); Refresh(); } return *this; } Button& Button::AutoStyle() { style = NULL; RefreshLayout(); Refresh(); return *this; } void Button::Layout() { Transparent(St()->transparent); } void Button::RefreshOK(Ctrl *p) { for(Ctrl *q = p->GetFirstChild(); q; q = q->GetNext()) { Button *b = dynamic_cast