Skip to content

Commit 7fb1d17

Browse files
author
achellies
committed
update
1 parent 1bd0f90 commit 7fb1d17

File tree

7 files changed

+361
-9
lines changed

7 files changed

+361
-9
lines changed

src/duibrowser/DuiBrowser.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@
184184
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
185185
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
186186
>
187+
<File
188+
RelativePath=".\debug.cpp"
189+
>
190+
</File>
187191
<File
188192
RelativePath=".\frame.cpp"
189193
>
@@ -210,6 +214,10 @@
210214
Filter="h;hpp;hxx;hm;inl;inc;xsd"
211215
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
212216
>
217+
<File
218+
RelativePath=".\debug.hpp"
219+
>
220+
</File>
213221
<File
214222
RelativePath=".\frame.hpp"
215223
>

src/duibrowser/UIWebkit.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ CWebkitUI::~CWebkitUI()
3838
delete[] bitmap_bits_;
3939
}
4040

41-
bool CWebkitUI::LayoutChanged()
41+
bool CWebkitUI::LayoutChanged(RECT rc)
4242
{
4343
did_first_layout_ = true;
44-
Invalidate();
44+
45+
CRect invalidateRect = m_rcItem;
46+
if (!invalidateRect.IsRectEmpty())
47+
{
48+
invalidateRect.left += rc.left;
49+
invalidateRect.top += rc.top;
50+
invalidateRect.right = invalidateRect.left + rc.right - rc.left;
51+
invalidateRect.bottom = invalidateRect.top + rc.bottom - rc.top;
52+
InvalidateRect(GetManager()->GetPaintWindow(), &invalidateRect, TRUE);
53+
}
4554

4655
return did_first_layout_;
4756
}
@@ -207,8 +216,8 @@ void CWebkitUI::DoEvent(TEventUI& event)
207216
int uLineDelta = 3;
208217
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &uLineDelta, 0);
209218

210-
if( LOWORD(event.wParam) == SB_LINEUP ) mouseEvent.mLineDelta = uLineDelta;
211-
else mouseEvent.mLineDelta = -uLineDelta;
219+
if( LOWORD(event.wParam) == SB_LINEUP ) mouseEvent.mLineDelta = static_cast<float>(uLineDelta);
220+
else mouseEvent.mLineDelta = static_cast<float>(-uLineDelta);
212221
mouseEvent.mbShift = ((event.wKeyState & MK_SHIFT) != 0);
213222
mouseEvent.mbControl = ((event.wKeyState & MK_CONTROL) != 0);
214223
mouseEvent.mbAlt = ((event.wKeyState & MK_ALT) != 0);

src/duibrowser/UIWebkit.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CWebkitUI : public CControlUI
5252
virtual void DoPaint(void* ctx, const RECT& rcPaint);
5353
virtual void SetPos(RECT rc);
5454

55-
bool LayoutChanged();
55+
bool LayoutChanged(RECT rc);
5656

5757
protected:
5858
void RestoreSurfaceBuffer();

src/duibrowser/bin/DuiBrowser.exe

-440 KB
Binary file not shown.

src/duibrowser/debug.cpp

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
//
2+
// debug.cpp
3+
// ~~~~~~~~~
4+
//
5+
// Copyright (c) 2011 achellies (achellies at 163 dot com)
6+
//
7+
// This code may be used in compiled form in any way you desire. This
8+
// source file may be redistributed by any means PROVIDING it is
9+
// not sold for profit without the authors written consent, and
10+
// providing that this notice and the authors name is included.
11+
//
12+
// This file is provided "as is" with no expressed or implied warranty.
13+
// The author accepts no liability if it causes any damage to you or your
14+
// computer whatsoever. It's free, so don't hassle me about it.
15+
//
16+
// Beware of bugs.
17+
//
18+
19+
#include "stdafx.h"
20+
#include "debug.hpp"
21+
#include <winbase.h>
22+
23+
#if defined(DBG_THREADSAFE)
24+
25+
class OS_CLockable
26+
{
27+
public:
28+
// ## Constructor / Destructor
29+
OS_CLockable();
30+
~OS_CLockable();
31+
32+
// ....................................................................
33+
// METHOD NAME: Acquire
34+
// DESCRIPTION:
35+
// Acquires a lock, blocking.
36+
// PARAMETERS:
37+
// none
38+
// RETURN VALUE:
39+
// none
40+
// ....................................................................
41+
void Acquire();
42+
43+
// ....................................................................
44+
// METHOD NAME: Release
45+
// DESCRIPTION:
46+
// Releases the lock.
47+
// object.
48+
// PARAMETERS:
49+
// none
50+
// RETURN VALUE:
51+
// none
52+
// ....................................................................
53+
void Release();
54+
55+
private:
56+
DWORD dwVersion;
57+
DWORD dwWindowsMajorVersion;
58+
DWORD dwWindowsMinorVersion;
59+
// ## Instance Variables
60+
61+
CRITICAL_SECTION m_critSec;
62+
63+
// ## declarations with no implementations (prevent accidental use)
64+
65+
OS_CLockable (const OS_CLockable&);
66+
OS_CLockable& operator= (const OS_CLockable&);
67+
};
68+
69+
// ............................................................................
70+
// CLASS NAME: OS_CAutoLock
71+
//
72+
// RESPONSIBILITIES:
73+
// Provides automatic locking and unlocking of an OS_CLockable object
74+
// within a code scope.
75+
//
76+
// NOTES:
77+
// ............................................................................
78+
class OS_CAutoLock
79+
{
80+
public:
81+
82+
// ## Constructors
83+
OS_CAutoLock(OS_CLockable &lockable) : m_lockable(lockable)
84+
{lockable.Acquire(); };
85+
86+
// ## Destructor
87+
~OS_CAutoLock() { m_lockable.Release();};
88+
89+
private:
90+
91+
// The controlled lockable object
92+
OS_CLockable &m_lockable;
93+
94+
// ## declarations with no implementations (prevent accidental use)
95+
96+
OS_CAutoLock ();
97+
OS_CAutoLock (const OS_CAutoLock&);
98+
OS_CAutoLock& operator= (const OS_CAutoLock&);
99+
};
100+
101+
// ----------------------------------------------------------------------------
102+
// OS_CLockable METHOD DEFINITIONS
103+
// ----------------------------------------------------------------------------
104+
105+
// ...........................................................................
106+
//
107+
// NAME: OS_CLockable::OS_CLockable (Constructor)
108+
//
109+
// IMPLEMENTATION NOTES:
110+
// ...........................................................................
111+
OS_CLockable::OS_CLockable()
112+
{
113+
OSVERSIONINFO osvi = {0};
114+
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
115+
GetVersionEx(&osvi);
116+
dwWindowsMajorVersion = osvi.dwMajorVersion;
117+
dwWindowsMinorVersion = osvi.dwMinorVersion;
118+
if(dwWindowsMajorVersion < 6)
119+
::InitializeCriticalSection(&m_critSec);
120+
121+
return;
122+
}
123+
124+
// ...........................................................................
125+
//
126+
// NAME: OS_CLockable::~OS_CLockable (Destructor)
127+
//
128+
// IMPLEMENTATION NOTES:
129+
// ...........................................................................
130+
OS_CLockable::~OS_CLockable()
131+
{
132+
if(dwWindowsMajorVersion < 6)
133+
::DeleteCriticalSection(&m_critSec);
134+
135+
return;
136+
}
137+
138+
// ...........................................................................
139+
//
140+
// NAME: OS_CLockable::Acquire
141+
//
142+
// IMPLEMENTATION NOTES:
143+
// ...........................................................................
144+
void OS_CLockable::Acquire()
145+
{
146+
if(dwWindowsMajorVersion < 6)
147+
::EnterCriticalSection(&m_critSec);
148+
}
149+
150+
// ...........................................................................
151+
//
152+
// NAME: OS_CLockable::Release
153+
//
154+
// IMPLEMENTATION NOTES:
155+
// ...........................................................................
156+
void OS_CLockable::Release()
157+
{
158+
if(dwWindowsMajorVersion < 6)
159+
::LeaveCriticalSection(&m_critSec);
160+
}
161+
#endif
162+
163+
#define MAX_LOG_FILE_SIZE static_cast<int>(1024*1024/2)
164+
165+
#ifdef _DEBUG
166+
int g_iDebugLevel = DBG_VERBOSE;
167+
#else
168+
int g_iDebugLevel = DBG_ERROR;
169+
#endif
170+
171+
bool g_bSaveLogFile = false;
172+
173+
TCHAR g_bLogSavePath[MAX_PATH] = _T("\\storage card\\hwsys");
174+
175+
static TCHAR s_szLogFile[MAX_PATH] = {0};
176+
static bool s_bLogPathInit = false;
177+
178+
#if defined(DBG_THREADSAFE)
179+
static OS_CLockable s_mtxEntry;
180+
#endif
181+
182+
BOOL DbgPrint(__in LPCTSTR lpszFormatString, ...)
183+
{
184+
BOOL bResult = TRUE;
185+
186+
va_list VAList;
187+
va_start(VAList, lpszFormatString);
188+
189+
if (g_bSaveLogFile)
190+
{
191+
#if defined(DBG_THREADSAFE)
192+
OS_CAutoLock lock(s_mtxEntry);
193+
#endif
194+
if (!s_bLogPathInit)
195+
{
196+
SYSTEMTIME stime = {0};
197+
GetLocalTime(&stime);
198+
#if defined(UNDER_CE)
199+
_stprintf(s_szLogFile, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
200+
#else
201+
_stprintf_s(s_szLogFile, MAX_PATH, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
202+
#endif
203+
s_bLogPathInit = true;
204+
}
205+
206+
FILE* pFile = _tfopen(s_szLogFile, _T("a"));
207+
if (pFile != NULL)
208+
{
209+
fseek(pFile,SEEK_END,0);
210+
long cbSize = ftell(pFile);
211+
if (cbSize > MAX_LOG_FILE_SIZE)
212+
{
213+
fclose(pFile);
214+
{
215+
SYSTEMTIME stime = {0};
216+
GetLocalTime(&stime);
217+
#if defined(UNDER_CE)
218+
_stprintf(s_szLogFile, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
219+
#else
220+
_stprintf_s(s_szLogFile, MAX_PATH, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
221+
#endif
222+
s_bLogPathInit = true;
223+
}
224+
pFile = _tfopen(s_szLogFile, _T("a"));
225+
if (pFile == NULL)
226+
{
227+
return FALSE;
228+
}
229+
}
230+
_vftprintf(pFile, lpszFormatString, VAList);
231+
fflush(pFile);
232+
fclose(pFile);
233+
pFile = NULL;
234+
}
235+
}
236+
else
237+
{
238+
#if defined(UNDER_CE)
239+
_vtprintf(lpszFormatString, VAList);
240+
#else
241+
TCHAR szBuf[MAX_PATH * 2] = {0};
242+
_vstprintf_s(szBuf, MAX_PATH, lpszFormatString, VAList);
243+
OutputDebugString(szBuf);
244+
#endif
245+
}
246+
va_end(VAList);
247+
248+
return bResult;
249+
}

src/duibrowser/debug.hpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// debug.hpp
3+
// ~~~~~~~~~
4+
//
5+
// Copyright (c) 2011 achellies (achellies at 163 dot com)
6+
//
7+
// This code may be used in compiled form in any way you desire. This
8+
// source file may be redistributed by any means PROVIDING it is
9+
// not sold for profit without the authors written consent, and
10+
// providing that this notice and the authors name is included.
11+
//
12+
// This file is provided "as is" with no expressed or implied warranty.
13+
// The author accepts no liability if it causes any damage to you or your
14+
// computer whatsoever. It's free, so don't hassle me about it.
15+
//
16+
// Beware of bugs.
17+
//
18+
19+
#ifndef _DEBUG_HPP
20+
#define _DEBUG_HPP
21+
22+
#include <stdio.h>
23+
24+
#define WIDEN2(x) L ## x
25+
#define WIDEN(x) WIDEN2(x)
26+
#define __WFILE__ WIDEN(__FILE__)
27+
28+
#ifdef UNICODE
29+
#define __TFILE__ __WFILE__
30+
#else
31+
#define __TFILE__ __FILE__
32+
#endif
33+
34+
#define DBG_THREADSAFE
35+
36+
#define DBG_VERBOSE 1
37+
#define DBG_TERSE 2
38+
#define DBG_WARNING 3
39+
#define DBG_ERROR 4
40+
41+
extern int g_iDebugLevel;
42+
extern bool g_bSaveLogFile;
43+
extern TCHAR g_bLogSavePath[MAX_PATH];
44+
45+
BOOL DbgPrint(__in LPCTSTR lpszFormatString,...);
46+
47+
#define DBGMSG(level, prefix, msg) { \
48+
INT dbgLevel = level; \
49+
if (g_iDebugLevel <= (dbgLevel)) { \
50+
DbgPrint(_T("%s\t\tFILE:%s\t\tLINE:%d\t\t"),prefix,__TFILE__,__LINE__);\
51+
DbgPrint(msg); \
52+
} \
53+
}
54+
55+
#define DBGPRINT(level, msg) { \
56+
INT dbgLevel = level; \
57+
if (g_iDebugLevel <= (dbgLevel)) { \
58+
DbgPrint(_T("FILE:%s\t\tLINE:%d\t\t"),__TFILE__,__LINE__);\
59+
DbgPrint(msg); \
60+
} \
61+
}
62+
63+
#ifdef _DEBUG
64+
65+
#define VERBOSE(...) DBGPRINT(DBG_VERBOSE, ##__VA_ARGS__)
66+
#define TERSE(...) DBGPRINT(DBG_TERSE, ##__VA_ARGS__)
67+
68+
#else // !DBG
69+
70+
#define VERBOSE(...) __noop
71+
#define TERSE(...) __noop
72+
//#define WARNING(...) __noop
73+
//#define ERR(...) __noop
74+
//#define DBGMSG(level, prefix, ...) __noop
75+
//#define DBGPRINT(level, ...) __noop
76+
77+
#endif
78+
#define WARNING(...) DBGMSG(DBG_WARNING,_T("WRN"), ##__VA_ARGS__)
79+
#define ERR(...) DBGMSG(DBG_ERROR,_T("ERR"), ##__VA_ARGS__)
80+
81+
#endif // _DEBUG_HPP

0 commit comments

Comments
 (0)