new uvs2 releases : uppsrc-2608 tutorial-38 examples-141 reference-113

git-svn-id: svn://ultimatepp.org/upp/trunk@304 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
mdelfede 2008-06-26 18:25:44 +00:00
parent 197aa4d862
commit f142f49947
16 changed files with 158 additions and 40 deletions

View file

@ -0,0 +1,2 @@
sockaddr_in
0 0 -1

View file

@ -469,7 +469,7 @@ bool FileStream::Open(const char *name, dword mode, mode_t tmode) {
int iomode = mode & ~SHAREMASK;
handle = open(ToSystemCharset(name), iomode == READ ? O_RDONLY :
iomode == CREATE ? O_CREAT|O_RDWR|O_TRUNC :
O_RDWR,
O_RDWR|O_CREAT,
tmode);
if(handle >= 0) {
int64 fsz = LSEEK64_(handle, 0, SEEK_END);

View file

@ -60,7 +60,7 @@ void DHCtrl::State(int reason)
SyncHWND();
break;
case CLOSE:
hwnd = NULL;
CloseHWND();
}
}

View file

@ -8,7 +8,7 @@ NAMESPACE_UPP
#define LOGTIMING 0
#ifdef _DEBUG
#define LOGMESSAGES 0
#define LOGMESSAGES 1
#endif
#define ELOG(x) // RLOG(GetSysTime() << ": " << x)
@ -566,7 +566,7 @@ LRESULT CALLBACK Ctrl::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
RLOG(m->name << ' ' << UPP::Name(w) <<
Sprintf(", wParam = %d (0x%x), lParam = %d (0x%x)",
wParam, wParam, lParam, lParam));
VppLog().Begin();
VppLog() << LOG_BEGIN;
logblk = true;
break;
}
@ -605,7 +605,7 @@ LRESULT CALLBACK Ctrl::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
l = DefWindowProc(hWnd, message, wParam, lParam);
#if LOGMESSAGES
if(logblk)
VppLog().End();
VppLog() << LOG_END;
#endif
return l;
}

View file

@ -276,6 +276,8 @@ void Calendar::LeftDown(Point p, dword keyflags)
else
RefreshDay(newday);
}
WhenSelect();
}
void Calendar::MouseMove(Point p, dword keyflags)
@ -335,7 +337,7 @@ void Calendar::RefreshDay(Point p)
col = p.x;
row = p.y;
int y0 = 2 + (int)((p.y + 2) * rowh);
int y0 = 2 + (int)((p.y + 1) * rowh + hs);
int x0 = bs + 2 + (int)((p.x + 1) * colw);
Refresh(x0, y0, cw, rh);
@ -357,7 +359,7 @@ Point Calendar::GetDay(Point p)
{
for(int i = 0; i < rows; i++)
{
int y0 = 2 + (int)((i + 2) * rowh);
int y0 = 2 + (int)((i + 1) * rowh + hs);
int y1 = y0 + rh;
if(p.y >= y0 && p.y < y1)
@ -380,6 +382,17 @@ Size Calendar::ComputeSize()
spin_month.SetFont(fnt);
spin_year.SetFont(fnt);
spin_all.SetLeftImage(st.spinleftimg);
spin_all.SetRightImage(st.spinrightimg);
spin_month.SetLeftImage(st.spinleftimg);
spin_month.SetRightImage(st.spinrightimg);
spin_year.SetLeftImage(st.spinleftimg);
spin_year.SetRightImage(st.spinrightimg);
spin_all.SetHighlight(st.spinhighlight);
spin_month.SetHighlight(st.spinhighlight);
spin_year.SetHighlight(st.spinhighlight);
Size sz = IsPopUp() ? Size(-1, -1) : GetSize();
Size tsz = GetTextSize("WW", fnt.NoBold().NoUnderline());
Size rsz;
@ -388,10 +401,10 @@ Size Calendar::ComputeSize()
colw = (float)(tsz.cx + 6);
rowh = (float)(tsz.cy + 4);
hs = tsz.cy + 4;
hs = spin_all.GetHeight() + 4;
rsz.cx = bs * 2 + 2 + (int)(colw * (cols + 1));
rsz.cy = 4 + (int)(rowh * (rows + 3));
rsz.cy = (int)(rowh * (rows + 2) + hs);
if(sz.cx > rsz.cx)
{
@ -400,7 +413,7 @@ Size Calendar::ComputeSize()
}
if(sz.cy > rsz.cy)
{
rowh = (sz.cy - 4) / (float) (rows + 3);
rowh = (sz.cy - hs) / (float) (rows + 2);
rsz.cy = sz.cy;
}
@ -434,7 +447,7 @@ void Calendar::Paint(Draw &w)
if(w.IsPainting(0, hs, sz.cx, rh))
{
int y = (int) (rowh + (rowh - fh) / 2.0);
int y = (int) (hs + (rowh - fh) / 2.0);
fnt.NoBold().NoUnderline();
tsz = GetTextSize(t_("Wk"), fnt);
w.DrawText(bs + (cw - tsz.cx) / 2, y, t_("Wk"), fnt, st.week);
@ -468,7 +481,7 @@ void Calendar::Paint(Draw &w)
for(int i = 0; i < rows; i++)
{
int yp = 2 + (int) ((i + 2) * rowh);
int yp = 2 + (int) ((i + 1) * rowh + hs);
int yc = (rh - fh) / 2;
str = AsString(WeekOfYear(d, m, y));
@ -566,7 +579,7 @@ void Calendar::Paint(Draw &w)
}
}
w.DrawRect(bs, (int) (rowh * 2) + 1, sz.cx - bs * 2, 1, st.line);
w.DrawRect(bs, (int) (hs + rowh) + 1, sz.cx - bs * 2, 1, st.line);
w.DrawRect(bs + cw + 1, hs + bs, 1, sz.cy - hs - ts - bs * 1, st.line);
lastrow = row;
@ -1321,6 +1334,7 @@ FlatButton::FlatButton()
bg = Blend(SColorHighlight, White, 50);
fg = SColorPaper;
left = true;
highlight = true;
Transparent();
}
@ -1339,7 +1353,13 @@ void FlatButton::Paint(Draw &w)
int dx = IsPush() * (left ? -1 : 1);
int dy = IsPush();
w.DrawImage((sz.cx - isz.cx) / 2 + dx, (sz.cy - isz.cy) / 2 + dy, img, HasMouse() ? SColorHighlightText() : Black);
Point p((sz.cx - isz.cx) / 2 + dx, (sz.cy - isz.cy) / 2 + dy);
if(highlight)
w.DrawImage(p.x, p.y, img, HasMouse() ? SColorHighlightText() : Black);
else
w.DrawImage(p.x, p.y, img);
}
FlatSpin::FlatSpin()
@ -1371,7 +1391,20 @@ void FlatSpin::SetFont(const Font& fnt)
int FlatSpin::GetWidth(const String& s, bool with_buttons)
{
return (with_buttons ? (CtrlImg::smallleft().GetSize().cx + 8) * 2 : 0) + GetTextSize(s, font).cx;
Size sl = left.GetImage().GetSize();
Size sr = right.GetImage().GetSize();
int width = GetTextSize(s, font).cx;
if(with_buttons)
width += sl.cx + max(8, sl.cx / 2) + sr.cx + max(8, sr.cx / 2);
return width;
}
int FlatSpin::GetHeight()
{
int ih = max(left.GetImage().GetSize().cy + 8, right.GetImage().GetSize().cy + 8);
return max(font.GetHeight(), ih);
}
void FlatSpin::SetText(const String& s)
@ -1396,9 +1429,8 @@ void FlatSpin::SetCallbacks(const Callback &cbl, const Callback& cbr)
void FlatSpin::Layout()
{
Size sz = GetSize();
Size isz = CtrlImg::smallleft().GetSize();
left.LeftPos(0, isz.cx + 8).TopPos(0, sz.cy);
right.RightPos(0, isz.cx + 8).TopPos(0, sz.cy);
left.LeftPos(0, left.GetImage().GetSize().cx + 8).VSizePos();
right.RightPos(0, right.GetImage().GetSize().cx + 8).VSizePos();
}
void FlatSpin::Paint(Draw& w)
@ -1473,6 +1505,9 @@ CH_STYLE(Calendar, Style, StyleDefault)
dayname = SColorText;
week = SColorText;
font = StdFont();
spinleftimg = CtrlImg::smallleft();
spinrightimg = CtrlImg::smallright();
spinhighlight = true;
}
END_UPP_NAMESPACE

View file

@ -15,6 +15,7 @@ public:
Color fg, bg, hl;
bool left;
bool drawedge;
bool highlight;
FlatButton();
@ -29,6 +30,8 @@ public:
Pusher::MouseLeave();
}
const Image& GetImage() { return img; }
FlatButton& SetImage(const Image &_img) {
img = _img;
Refresh();
@ -38,6 +41,7 @@ public:
FlatButton& SetLeft() { left = true; return *this; }
FlatButton& SetRight() { left = false; return *this; }
FlatButton& DrawEdge(bool b) { drawedge = b; return *this; }
FlatButton& Highlight(bool b) { highlight = b;return *this; }
};
class FlatSpin : public Ctrl
@ -59,7 +63,11 @@ public:
FlatSpin& Selectable(bool b = true);
int GetWidth(const String& s, bool with_buttons = true);
int GetHeight();
void SetFont(const Font& fnt);
void SetLeftImage(const Image &img) { left.SetImage(img); }
void SetRightImage(const Image &img) { right.SetImage(img); }
void SetHighlight(bool b) { left.Highlight(b); right.Highlight(b); }
virtual void MouseMove(Point p, dword keyflags);
virtual void MouseLeave();
@ -113,7 +121,10 @@ public:
Color line;
Color dayname;
Color week;
Font font;
Font font;
Image spinleftimg;
Image spinrightimg;
bool spinhighlight;
};
protected:
@ -233,6 +244,8 @@ public:
Calendar& NoOneButton() { one_button = false; return *this; }
void PopUp(Ctrl *owner, Rect &rt);
Callback WhenSelect;
};
struct LineCtrl : Ctrl
@ -483,6 +496,7 @@ public:
cc.calendar <<= THISBACK(OnCalendarChoice);
cc.clock <<= THISBACK(OnClockChoice);
cc.WhenPopDown = THISBACK(OnClose);
cc.calendar.WhenSelect = Proxy(WhenSelect);
}
virtual void GotFocus() { drop.RefreshFrame(); }
@ -501,6 +515,8 @@ public:
DateTimeCtrl& SwapMonthYear(bool b = true) { cc.calendar.SwapMonthYear(b); return *this; }
DateTimeCtrl& OneButton(bool b = true) { cc.calendar.OneButton(true); return *this; }
DateTimeCtrl& NoOneButton() { cc.calendar.OneButton(false); return *this; }
Callback WhenSelect;
};
class DropDate : public DateTimeCtrl<EditDate>

View file

@ -302,6 +302,15 @@ void TabCtrl::Set(int i)
ScrollInto(sel);
}
void TabCtrl::Set(Ctrl& slave)
{
for(int i = 0; i < tab.GetCount(); i++)
if(tab[i].slave == &slave) {
Set(i);
return;
}
}
void TabCtrl::SetData(const Value& data)
{
Set(data);

View file

@ -117,6 +117,7 @@ public:
const Item& GetItem(int i) const { return tab[i]; }
void Set(int i);
void Set(Ctrl& slave);
int Get() const { return sel; }
void GoNext() { Go(1); }

View file

@ -259,8 +259,12 @@ void AlphaBlendStraightOpaque(RGBA *t, const RGBA *s, int len)
void AlphaBlendStraightOpaque(RGBA *t, const RGBA *s, int len, int alpha)
{
if(alpha >= 256) {
AlphaBlendStraightOpaque(t, s, len);
return;
}
const RGBA *e = s + len;
alpha *= 0x101;
alpha *= 0x102;
while(s < e) {
int a = (s->a * alpha) >> 16;
t->r += a * (s->r - t->r) >> 8;

View file

@ -91,6 +91,7 @@ void GLCtrl::StdView()
LRESULT GLCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
DDUMP(message);
if(message == WM_PAINT && hDC && hRC) {
wglMakeCurrent(hDC, hRC);
GLPaint();

View file

@ -239,10 +239,10 @@ bool MySqlConnection::Execute() {
s++;
}
Cancel();
Stream *trace = session.GetTrace();
/* Stream *trace = session.GetTrace();
dword time;
if(session.IsTraceTime())
time = GetTickCount();
time = GetTickCount();*/
if(mysql_query(mysql, query)) {
session.SetError(mysql_error(mysql), query);
return false;

View file

@ -85,16 +85,22 @@ SqlBool SqlFirstRow() {
return SqlCol("ROWNUM") == 1;
}
SqlBool Like(const SqlVal& a, const SqlVal& b) {
return SqlBool(a, SqlCase(MY_SQL, " like binary ")(" like "), b, SqlS::COMP);
SqlBool Like(const SqlVal& a, const SqlVal& b, bool cs) {
return SqlBool(a, SqlCase
(MY_SQL, " like binary ")
(PGSQL, cs ? " like " : " ilike ")
(" like "), b, SqlS::COMP);
}
SqlBool LikeUpperAscii(const SqlVal& a, const SqlVal& b) {
return Like(UpperAscii(a), UpperAscii(b));
}
SqlBool NotLike(const SqlVal& a, const SqlVal& b) {
return SqlBool(a, " not like ", b, SqlS::COMP);
SqlBool NotLike(const SqlVal& a, const SqlVal& b, bool cs) {
return SqlBool(a, SqlCase
(PGSQL, cs ? "not like " : " not ilike ")
(" not like "), b, SqlS::COMP);
}
SqlBool Between(const SqlVal& a, const SqlVal& l, const SqlVal& h) {

View file

@ -47,6 +47,16 @@ SqlS::SqlS(const SqlS& a, const char *o, const SqlS& b, int pr) {
priority = pr;
}
SqlVal SqlVal::As(const char *as) const {
SqlVal v;
v.SetHigh(text + ~SqlCase(MSSQL | PGSQL, " as ")(" ") + as);
return v;
}
SqlVal SqlVal::As(const SqlId& id) const {
return As(~~id);
}
SqlVal::SqlVal(const String& x) {
if(UPP::IsNull(x))
SetNull();
@ -120,6 +130,18 @@ SqlVal::SqlVal(SqlCol id) {
SetHigh(id.ToString());
}
SqlVal::SqlVal(const SqlSelect& x) {
SetHigh('(' + ((SqlStatement) x).GetText() + ')');
}
SqlVal::SqlVal(const SqlBool& x) {
SetHigh(~x);
}
SqlVal::SqlVal(const Case& x) {
SetHigh(~x);
}
SqlVal operator-(const SqlVal& a) {
return SqlVal('-' + a(SqlS::UNARY), SqlS::UNARY);
}

View file

@ -11,6 +11,8 @@ enum {
class SqlBool;
class SqlVal;
class SqlSet;
class SqlSelect;
class Case;
// ----------
@ -157,6 +159,9 @@ public:
void SetHigh(const String& s) { text = s; priority = HIGH; }
bool IsNull() const { return priority == NULLVAL; }
SqlVal As(const char *as) const;
SqlVal As(const SqlId& id) const;
SqlVal() {}
SqlVal(const String& s, int pr) : SqlS(s, pr) {}
SqlVal(const SqlS& a, const char *o, const SqlS& b, int pa, int pb)
@ -176,6 +181,9 @@ public:
SqlVal(SqlId id);
SqlVal(const SqlId& (*id)());
SqlVal(SqlCol id);
SqlVal(const SqlSelect& x);
SqlVal(const SqlBool& x);
SqlVal(const Case& x);
};
SqlVal operator-(const SqlVal& a);
@ -313,8 +321,8 @@ inline SqlBool IsNull(const SqlId& a) { return SqlIsNull(a); }
inline SqlBool IsNull(const SqlVal& a) { return SqlIsNull(a); }
inline SqlBool IsNull(const SqlCol& a) { return SqlIsNull(a); }
SqlBool Like(const SqlVal& a, const SqlVal& b);
SqlBool NotLike(const SqlVal& a, const SqlVal& b);
SqlBool Like(const SqlVal& a, const SqlVal& b, bool cs = false);
SqlBool NotLike(const SqlVal& a, const SqlVal& b, bool cs = false);
SqlBool Between(const SqlVal& a, const SqlVal& low, const SqlVal& high);
SqlBool NotBetween(const SqlVal&a, const SqlVal& low, const SqlVal& high);
@ -340,7 +348,23 @@ inline SqlBool operator!=(const SqlVal& a, const SqlSet& b) { return NotIn(a, b)
inline const SqlVal& operator+(const SqlVal& a) { return a; }
//////////////////////////////////////////////////////////////////////
class Case : public SqlS, Moveable<Case> {
public:
Case(const SqlBool& cond, const SqlVal& val)
{
text = "case when " + ~cond + " then " + ~val + " end";
}
Case& operator()(const SqlBool& cond, const SqlVal& val)
{
text.Insert(text.GetLength() - 4, " when " + ~cond + " then " + ~val);
return *this;
}
Case& operator()(const SqlVal& val)
{
text.Insert(text.GetLength() - 4, " else " + ~val);
return *this;
}
};
class Sql;

View file

@ -135,7 +135,7 @@ bool Socket::Data::Open(bool block)
return true;
}
bool Socket::Data::OpenServer(int port, bool nodelay, int listen_count, bool block)
bool Socket::Data::OpenServer(int port, bool nodelay, int listen_count, bool block, bool reuse)
{
if(!Open(block))
return false;
@ -146,6 +146,10 @@ bool Socket::Data::OpenServer(int port, bool nodelay, int listen_count, bool blo
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = htonl(INADDR_ANY);
if(reuse) {
int optval = 1;
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (const char *)&optval, sizeof(optval));
}
if(bind(socket, (const sockaddr *)&sin, sizeof(sin))) {
SetSockError(NFormat("bind(port=%d)", port));
return false;
@ -405,12 +409,6 @@ void Socket::Data::Block(bool b)
is_blocking = b;
}
void Socket::Data::Reuse()
{
int optval = 1;
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (const char *)&optval, sizeof(optval));
}
/*
void Socket::Data::WriteTimeout(int msecs)
{
@ -815,10 +813,10 @@ void Socket::SetSockError(SOCKET socket, const char *context, const char *errord
SetErrorText(err);
}
bool ServerSocket(Socket& socket, int port, bool nodelay, int listen_count, bool blocking)
bool ServerSocket(Socket& socket, int port, bool nodelay, int listen_count, bool blocking, bool reuse)
{
One<Socket::Data> data = new Socket::Data;
if(!data->OpenServer(port, nodelay, listen_count, blocking))
if(!data->OpenServer(port, nodelay, listen_count, blocking, reuse))
return false;
socket.Attach(data);
return true;

View file

@ -14,7 +14,7 @@ public:
virtual ~Data() { CloseRaw(0); }
bool Open(bool is_blocking);
bool OpenServer(int port, bool nodelay, int listen_count, bool is_blocking);
bool OpenServer(int port, bool nodelay, int listen_count, bool is_blocking, bool reuse = true);
bool OpenClient(const char *host, int port, bool nodelay, dword *my_addr, int timeout, bool is_blocking);
bool IsOpen() const { return socket != INVALID_SOCKET; }
bool CloseRaw(int timeout_msec);
@ -148,5 +148,5 @@ public:
};
#endif
bool ServerSocket(Socket& socket, int port, bool nodelay = true, int listen_count = 5, bool is_blocking = true);
bool ServerSocket(Socket& socket, int port, bool nodelay = true, int listen_count = 5, bool is_blocking = true, bool reuse = true);
bool ClientSocket(Socket& socket, const char *host, int port, bool nodelay = true, dword *my_addr = NULL, int timeout = DEFAULT_CONNECT_TIMEOUT, bool is_blocking = true);