ultimatepp/bazaar/FormEditor/ExGridCtrl.cpp
koldo ac7821deb8 Form: Form core package, Editor and sample from Sc0rch
git-svn-id: svn://ultimatepp.org/upp/trunk@2412 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2010-05-19 18:38:45 +00:00

84 lines
1.5 KiB
C++

#include "ExGridCtrl.hpp"
ExGridCtrl::ExGridCtrl()
{
_Offset = - GD_HDR_HEIGHT / 2;
_UseKeys = true;
_Info = "";
_X = 0;
_Y = 0;
WhenLeftClick = THISBACK(OnLeftClick);
}
void ExGridCtrl::Paint(Draw &w)
{
GridCtrl::Paint(w);
if (GetCount() == 0)
w.DrawText(GetSize().cx / 2 - _X, GetSize().cy / 2 - _Y - _Offset,
_Info, _Font, _Ink);
}
void ExGridCtrl::SetInfo(const String& info, Font font, Color ink)
{
_Info = info;
_Font = font;
_Ink = ink;
FontInfo fontInfo = _Font.Info();
Size sz = ::GetTextSize(info, font);
_X = sz.cx / 2;
_Y = sz.cy / 2;
}
bool ExGridCtrl::Key(dword key, int count)
{
if (!_UseKeys && !IsEdit())
return GridCtrl::Key(key, count);
bool result;
if (key == K_UP)
{
if (0 < curpos.y || curpos.y <= GetRowCount() + 1)
{
EndEdit();
SetCursor(curpos.y - 1);
result = GridCtrl::Key(key, count);
StartEdit();
return result;
}
}
if (key == K_DOWN)
{
if (0 <= curpos.y || curpos.y < GetRowCount())
{
EndEdit();
SetCursor(curpos.y - 1);
result = GridCtrl::Key(key, count);
StartEdit();
return result;
}
}
return GridCtrl::Key(key, count);
}
void ExGridCtrl::LeftDown(Point p, dword keyflags)
{
if (!(keyflags & K_SHIFT || keyflags & K_CTRL))
ClearSelection();
GridCtrl::LeftDown(p, keyflags);
}
void ExGridCtrl::OnLeftClick()
{
if (!_UseKeys)
return;
SetCursor( Point(1, curpos.y - 1) );
StartEdit();
}