From b4e43c35140acbce53921ed1b4ba3b04e97b8803 Mon Sep 17 00:00:00 2001 From: VincentWei Date: Thu, 18 Jan 2018 16:51:44 +0800 Subject: [PATCH] tune code for 64 bitts --- configure.ac | 10 +++++++++ include/common.h | 4 ++-- include/ctrl/scrollview.h | 2 +- include/gdi.h | 12 +++++------ include/window.h | 2 +- src/control/listmodel.c | 10 ++++----- src/control/scrollview.c | 2 +- src/control/scrollview_impl.h | 7 +++---- src/control/scrollwnd.c | 8 +++---- src/control/scrollwnd.h | 2 -- src/gui/lf_classic.c | 1 - src/gui/lf_manager.c | 5 +++-- src/gui/window.c | 11 ++++------ src/include/ctrlclass.h | 12 +++++++---- src/include/dc.h | 13 ++++++------ src/include/internals.h | 14 ++++++++----- src/include/newgal.h | 3 ++- src/kernel/cursor.c | 39 ++++++++++++++++++++++++++++------- src/misc/endianrw.c | 4 ++-- src/newgdi/gdi.c | 1 - src/newgdi/icon.c | 2 +- 21 files changed, 100 insertions(+), 64 deletions(-) diff --git a/configure.ac b/configure.ac index 8fb20340..8ba71a9f 100644 --- a/configure.ac +++ b/configure.ac @@ -1727,6 +1727,7 @@ if test "x$devel_mode" = "xyes"; then build_ctrl_bidisledit="yes" build_ctrl_textedit="yes" + build_ctrl_scrollview="yes" build_ctrl_monthcal="yes" build_ctrl_treeview="yes" build_ctrl_treeview_rdr="yes" @@ -1746,6 +1747,15 @@ if test "x$devel_mode" = "xyes"; then CFLAGS="$CFLAGS -Werror" fi +dnl Depedencies +if test "x$build_ctrl_treeview" = "xyes"; then + build_ctrl_scrollview="yes" +fi + +if test "x$build_ctrl_treeview_rdr" = "xyes"; then + build_ctrl_scrollview="yes" +fi + if test "x$use_debug" = "xyes"; then AC_DEFINE(_DEBUG, 1, [Define if build with debugging messages]) diff --git a/include/common.h b/include/common.h index ac1ccbc8..658e7351 100644 --- a/include/common.h +++ b/include/common.h @@ -8,7 +8,7 @@ * \verbatim - Copyright (C) 2002-2012 FMSoft. + Copyright (C) 2002-2018 FMSoft. Copyright (C) 1998-2002 Wei Yongming. All rights reserved by FMSoft (http://www.fmsoft.cn). @@ -238,7 +238,7 @@ MGUI_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); * * to write endianness independent code. */ -#if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || defined(__amd64) || \ +#if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || defined(__amd64) || \ (defined(__alpha__) || defined(__alpha)) || \ defined(__arm__) || \ (defined(__CC_ARM) && !defined(__BIG_ENDIAN)) || \ diff --git a/include/ctrl/scrollview.h b/include/ctrl/scrollview.h index a2216578..907d2111 100644 --- a/include/ctrl/scrollview.h +++ b/include/ctrl/scrollview.h @@ -70,7 +70,7 @@ extern "C" { /** Default container window procedure * \sa DefaultDialogProc */ -MG_EXPORT int GUIAPI DefaultContainerProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam); +MG_EXPORT LRESULT GUIAPI DefaultContainerProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); /** Scrollview item object, use this handle to access a scrollview item */ typedef GHANDLE HSVITEM; diff --git a/include/gdi.h b/include/gdi.h index 962a1d3e..d916b787 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -7,7 +7,7 @@ * \verbatim - Copyright (C) 2002-2012 FMSoft. + Copyright (C) 2002-2018 FMSoft. Copyright (C) 1998-2002 Wei Yongming. All rights reserved by FMSoft (http://www.fmsoft.cn). @@ -8891,20 +8891,20 @@ MG_EXPORT void GUIAPI BIDIGetVisualEmbeddLevels (LOGFONT* log_font, * */ typedef struct _COMP_CTXT { - /** the step of current pixel operations. */ - int step; - /** the pointer to the destination */ gal_uint8* cur_dst; + /** The user context passed to SetUserCompositionOps */ + void* user_comp_ctxt; + /** the pixel value shoulb be skipped (the color key) */ gal_pixel skip_pixel; /** the current pixel value for setpixel and setpixels operation */ gal_pixel cur_pixel; - /** The user context passed to SetUserCompositionOps */ - void* user_comp_ctxt; + /** the step of current pixel operations. */ + int step; } COMP_CTXT; /* diff --git a/include/window.h b/include/window.h index 6eda525f..bc3f6a71 100644 --- a/include/window.h +++ b/include/window.h @@ -4118,7 +4118,7 @@ typedef struct _WINDOWINFO */ static inline const WINDOWINFO* GUIAPI GetWindowInfo (HWND hWnd) { - return (WINDOWINFO*)((unsigned char*)hWnd + 2*sizeof (short)); + return (WINDOWINFO*)hWnd; } /** diff --git a/src/control/listmodel.c b/src/control/listmodel.c index e923411a..9ae6214b 100644 --- a/src/control/listmodel.c +++ b/src/control/listmodel.c @@ -409,27 +409,27 @@ int DefaultItemViewProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam, return 0; case SVM_SETITEMDRAW: - return (int)mglist_set_itemdraw (mglst, (SVITEM_DRAWFUNC)lParam); + return (LRESULT)mglist_set_itemdraw (mglst, (SVITEM_DRAWFUNC)lParam); case SVM_SETITEMINIT: { SVITEM_INITFUNC old_pfn; old_pfn = mglst->iop.initItem; mglst->iop.initItem = (SVITEM_INITFUNC)lParam; - return (int)old_pfn; + return (LRESULT)old_pfn; } case SVM_SETITEMDESTROY: { SVITEM_DESTROYFUNC old_pfn; old_pfn = mglst->iop.destroyItem; mglst->iop.destroyItem = (SVITEM_DESTROYFUNC)lParam; - return (int)old_pfn; + return (LRESULT)old_pfn; } case SVM_GETITEMADDDATA: { if (lParam) - return mglist_get_item_adddata(lParam); + return mglist_get_item_adddata((HITEM)lParam); else { HITEM hitem = (HITEM)mglist_getitem_byindex(mglst, wParam); return mglist_get_item_adddata(hitem); @@ -523,7 +523,7 @@ int DefaultItemViewProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam, { SVITEM_CMP oldcmp = mglst->itemCmp; mglst->itemCmp = (SVITEM_CMP)lParam; - return (int)oldcmp; + return (LRESULT)oldcmp; } case SVM_SORTITEMS: diff --git a/src/control/scrollview.c b/src/control/scrollview.c index 0097ae16..51ce6fd8 100644 --- a/src/control/scrollview.c +++ b/src/control/scrollview.c @@ -430,7 +430,7 @@ void scrollview_destroy (PSVDATA psvdata) } /* --------------------------------------------------------------------------------- */ -static LRESULT ScrollViewCtrlProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT ScrollViewCtrlProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PSVDATA psvdata = NULL; diff --git a/src/control/scrollview_impl.h b/src/control/scrollview_impl.h index eb6cff8e..50e4d460 100644 --- a/src/control/scrollview_impl.h +++ b/src/control/scrollview_impl.h @@ -3,16 +3,14 @@ ** ** scrollview.h: header file of ScrollView control. ** -** Copyright (C) 2004 ~ 2007 Feynman Software. +** Copyright (C) 2004 ~ 2018 FMSoft */ #ifndef _SCROLLVIEW_IMPL_H_ #define _SCROLLVIEW_IMPL_H_ - #include "listmodel.h" - #ifdef __cplusplus extern "C" { @@ -81,7 +79,8 @@ typedef SVDATA *PSVDATA; /* ------------------------- external api -------------------------- */ -MG_EXPORT int ScrollViewCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam); +MG_EXPORT LRESULT ScrollViewCtrlProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + MG_EXPORT int scrollview_init (HWND hWnd, PSVDATA psv); MG_EXPORT void scrollview_destroy (PSVDATA psvdata); MG_EXPORT HSVITEM scrollview_add_item (HWND hWnd, PSVDATA psvdata, HSVITEM hsvi, PSVITEMINFO pii, int *idx); diff --git a/src/control/scrollwnd.c b/src/control/scrollwnd.c index 85ffcaba..76b70296 100644 --- a/src/control/scrollwnd.c +++ b/src/control/scrollwnd.c @@ -220,7 +220,7 @@ static LRESULT ScrollWndCtrlProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM } case SVM_GETCTRL: - return GetDlgItem (pswdata->hContainer, wParam); + return (LRESULT)GetDlgItem (pswdata->hContainer, wParam); case SVM_RESETCONTENT: scrollwnd_reset_content (hWnd, pswdata); @@ -231,7 +231,7 @@ static LRESULT ScrollWndCtrlProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM return 0; case SVM_GETFOCUSCHILD: - return (int)GetFocus (pswdata->hContainer); + return (LRESULT)GetFocus (pswdata->hContainer); }/* end switch */ @@ -285,8 +285,8 @@ static void container_destroy (HWND hWnd, PCONTDATA pcontdata) /* ---------------------------------------------------------------------------- */ -int GUIAPI -DefaultContainerProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam) +LRESULT GUIAPI +DefaultContainerProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PCONTDATA pcontdata = NULL; diff --git a/src/control/scrollwnd.h b/src/control/scrollwnd.h index b1c8d3e3..4bc02808 100644 --- a/src/control/scrollwnd.h +++ b/src/control/scrollwnd.h @@ -50,8 +50,6 @@ typedef struct _swdata } SWDATA; typedef SWDATA *PSWDATA; - -int ScrollWndCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam); int scrollwnd_init (HWND hWnd, PSWDATA psv); void scrollwnd_destroy (PSWDATA pswdata); void scrollwnd_hscroll (HWND hWnd, PSWDATA pswdata, WPARAM wParam, LPARAM lParam); diff --git a/src/gui/lf_classic.c b/src/gui/lf_classic.c index 2e8e519b..4976c298 100644 --- a/src/gui/lf_classic.c +++ b/src/gui/lf_classic.c @@ -374,7 +374,6 @@ static int init (PWERENDERER renderer) renderer->private_info = NULL; - return 0; } diff --git a/src/gui/lf_manager.c b/src/gui/lf_manager.c index abb19e1b..6af2a188 100644 --- a/src/gui/lf_manager.c +++ b/src/gui/lf_manager.c @@ -822,10 +822,11 @@ BOOL mg_InitLFManager (void) /** be sure to success initializing default renderer */ rdr = wnd_lf_info[0].wnd_rdr; - if (NULL == rdr) return FALSE; + if (NULL == rdr) + return FALSE; if (rdr->init && 0 != rdr->init (rdr)) { - _MG_PRINTF ("GUI>InitLFM: fail to initialize default renderer's private info.\n"); + _MG_PRINTF ("GUI>InitLFM: failed to initialize default renderer's private info.\n"); return FALSE; } diff --git a/src/gui/window.c b/src/gui/window.c index 27270b90..8fed0a13 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -4747,20 +4747,17 @@ static BOOL _wndInvalidateRect(HWND hWnd, const RECT* prc, BOOL bEraseBkgnd, int #ifdef _MGRM_THREADS pthread_mutex_lock(&pInvRgn->lock); #endif - if (bEraseBkgnd) - { + if (bEraseBkgnd) { pCtrl->Flags |= WF_ERASEBKGND; } - if(prc) - { + if(prc) { rcInv = *prc; NormalizeRect(&rcInv); if(IntersectRect(&rcInv, &rcInv, &rcClient)) AddClipRect(&pInvRgn->rgn, &rcInv); } - else - { + else { rcInv = rcClient; SetClipRgn(&pInvRgn->rgn, &rcInv); } @@ -4769,7 +4766,7 @@ static BOOL _wndInvalidateRect(HWND hWnd, const RECT* prc, BOOL bEraseBkgnd, int OffsetRect(&rcTemp, pCtrl->cl, pCtrl->ct); //subtract from next sibling controls - if(pCtrl->WinType==TYPE_CONTROL /*&& ( mark & WIRM_NEXT_SIBLING)*/) + if(pCtrl->WinType == TYPE_CONTROL /*&& ( mark & WIRM_NEXT_SIBLING)*/) { for(pNext = pCtrl->next; pNext; pNext = pNext->next) { diff --git a/src/include/ctrlclass.h b/src/include/ctrlclass.h index 89b242b0..a43b18a1 100644 --- a/src/include/ctrlclass.h +++ b/src/include/ctrlclass.h @@ -42,10 +42,6 @@ typedef struct tagCONTROL /* * These fields are similiar with MAINWIN struct. */ - unsigned char DataType; // the data type - unsigned char WinType; // the window type - unsigned short Flags; // speical runtime flags, such EraseBkGnd flags - int left, top; // the position of control in main window's int right, bottom; // client area. @@ -110,6 +106,14 @@ typedef struct tagCONTROL */ struct _wnd_element_data* wed; + /* + * some internal fields + * VM[2018-01-18]: Move these fields from header to here to compatible with WINDOWINFO + */ + unsigned char DataType; // the data type + unsigned char WinType; // the window type + unsigned short Flags; // speical runtime flags, such EraseBkGnd flags + /* * The following members are only implemented for control. */ diff --git a/src/include/dc.h b/src/include/dc.h index 8498e48f..70dd2b28 100644 --- a/src/include/dc.h +++ b/src/include/dc.h @@ -186,11 +186,12 @@ struct tagDC /* === context information. ============================================= */ /* DK[01/22/10]:This segment is binary compatible with _COMP_CTXT struct */ - int step; - gal_uint8* cur_dst; - gal_pixel skip_pixel; - gal_pixel cur_pixel; - void * user_comp_ctxt; + /* VW[01/18/18]:Adjust the fields sequence for 64-bit to ensure 8-byte alignment */ + gal_uint8* cur_dst; + void* user_comp_ctxt; + gal_pixel skip_pixel; + gal_pixel cur_pixel; + int step; /* ====================================================================== */ CLIPRECT* cur_ban; @@ -212,7 +213,7 @@ struct tagDC CB_BITMAP_SCALER_FUNC bitmap_scaler; }; -#define PDC_TO_COMP_CTXT(pdc) ((COMP_CTXT* )(&pdc->step)) +#define PDC_TO_COMP_CTXT(pdc) ((COMP_CTXT* )(&pdc->cur_dst)) extern DC __mg_screen_dc; extern DC __mg_screen_sys_dc; diff --git a/src/include/internals.h b/src/include/internals.h index ed4e679a..0be8e69a 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -293,10 +293,6 @@ typedef struct _MAINWIN /* * These fields are similiar with CONTROL struct. */ - unsigned char DataType; // the data type. - unsigned char WinType; // the window type. - unsigned short Flags; // special runtime flags, such EraseBkGnd flags - int left, top; // the position and size of main window. int right, bottom; @@ -363,9 +359,17 @@ typedef struct _MAINWIN */ struct _wnd_element_data* wed; + /* + * some internal fields + * VM[2018-01-18]: Move these fields from header to here to compatible with WINDOWINFO + */ + unsigned char DataType; // the data type. + unsigned char WinType; // the window type. + unsigned short Flags; // special runtime flags, such EraseBkGnd flags + /* - * Main Window hosting. * The following members are only implemented for main window. + * Main Window hosting. */ struct _MAINWIN* pHosting; // the hosting main window. diff --git a/src/include/newgal.h b/src/include/newgal.h index a74a8326..b87f15c0 100644 --- a/src/include/newgal.h +++ b/src/include/newgal.h @@ -63,7 +63,8 @@ typedef struct GAL_Surface { GAL_PixelFormat *format; /* Read-only */ void *video; /* Read-only */ int w, h; /* Read-only */ - Uint32 pitch; /* Read-only */ + /* VW[2018-01-18]: For 64b, use signed int instead of Uint32 for pitch. */ + int pitch; /* Read-only */ void *pixels; /* Read-write */ int offset; /* Private */ diff --git a/src/kernel/cursor.c b/src/kernel/cursor.c index 1377dec2..617f21ca 100644 --- a/src/kernel/cursor.c +++ b/src/kernel/cursor.c @@ -102,13 +102,17 @@ HCURSOR GUIAPI LoadCursorFromFile(const char* filename) BYTE* image; HCURSOR csr = 0; - if( !(fp = fopen(filename, "rb")) ) return 0; + if (!(fp = fopen(filename, "rb"))) + return 0; fseek(fp, sizeof(WORD16), SEEK_SET); /* the cbType of struct CURSORDIR. */ wTemp = MGUI_ReadLE16FP (fp); - if(wTemp != 2) goto error; + if(wTemp != 2) { + _MG_PRINTF ("LoadCursorFromFile: bad file type: %d\n", wTemp); + goto error; + } /* skip the cdCount of struct CURSORDIR, we always use the first cursor. */ fseek(fp, sizeof(WORD16), SEEK_CUR); @@ -116,7 +120,11 @@ HCURSOR GUIAPI LoadCursorFromFile(const char* filename) /* cursor info, read the members of struct CURSORDIRENTRY. */ w = fgetc (fp); /* the width of first cursor. */ h = fgetc (fp); /* the height of first cursor. */ - if(w != CURSORWIDTH || h != CURSORHEIGHT) goto error; + if (w != CURSORWIDTH || h != CURSORHEIGHT) { + _MG_PRINTF ("LoadCursorFromFile: bad first cursor width (%d) and height (%d)\n", w, h); + goto error; + } + fseek(fp, sizeof(BYTE)*2, SEEK_CUR); /* skip bColorCount and bReserved. */ wTemp = MGUI_ReadLE16FP (fp); xhot = wTemp; @@ -134,16 +142,25 @@ HCURSOR GUIAPI LoadCursorFromFile(const char* filename) fseek(fp, sizeof(DWORD32), SEEK_CUR); /* skip the biSize member. */ imagew = MGUI_ReadLE32FP (fp); imageh = MGUI_ReadLE32FP (fp); - if (imagew > 32 || imageh > 32) { + if (imagew != CURSORWIDTH || imageh != (CURSORHEIGHT*2)) { + _MG_PRINTF ("LoadCursorFromFile: bad cursor image width (%d) and height (%d)\n", imagew, imageh); goto error; } /* check the biPlanes member; */ wTemp = MGUI_ReadLE16FP (fp); - if(wTemp != 1) goto error; + if (wTemp != 1) { + _MG_PRINTF ("LoadCursorFromFile: bad planes (%d)\n", wTemp); + goto error; + } + /* check the biBitCount member; */ wTemp = MGUI_ReadLE16FP (fp); - if(wTemp > 4) goto error; + if (wTemp > 4) { + _MG_PRINTF ("LoadCursorFromFile: bad bit count (%d)\n", wTemp); + goto error; + } + colornum = (int)wTemp; fseek(fp, sizeof(DWORD32), SEEK_CUR); /* skip the biCompression members. */ imagesize = MGUI_ReadLE32FP (fp); @@ -153,20 +170,25 @@ HCURSOR GUIAPI LoadCursorFromFile(const char* filename) /* allocate memory for image. */ if ((image = (BYTE*)ALLOCATE_LOCAL (imagesize)) == NULL) { + _MG_PRINTF ("LoadCursorFromFile: error when allocating memory for image (%d)\n", imagesize); goto error; } /* read image */ - if (fread (image, imagesize, 1, fp) < imagesize) { + if (fread (image, 1, imagesize, fp) < imagesize) { + _MG_PRINTF ("LoadCursorFromFile: error when reading data from file\n"); goto error; } - csr = CreateCursor(xhot, yhot, w, h, + csr = CreateCursor (xhot, yhot, w, h, image + (imagesize - MONOSIZE), image, colornum); DEALLOCATE_LOCAL (image); + fclose (fp); + return csr; error: + _MG_PRINTF ("LoadCursorFromFile: failed when loading cursor from %s\n", filename); fclose (fp); return csr; } @@ -237,6 +259,7 @@ HCURSOR GUIAPI LoadCursorFromMem (const void* area) p + (imagesize - MONOSIZE), p, colornum); error: + _MG_PRINTF ("LoadCursorFromMem: failed when loading cursor from %p\n", area); return 0; } diff --git a/src/misc/endianrw.c b/src/misc/endianrw.c index 54092028..acad8e41 100644 --- a/src/misc/endianrw.c +++ b/src/misc/endianrw.c @@ -111,7 +111,7 @@ Uint16 MGUI_ReadLE16FP (FILE *src) size_t size; size = fread (&value, (sizeof value), 1, src); - if (size < sizeof (value)) + if (size < 1) return -1; return (ArchSwapLE16(value)); @@ -123,7 +123,7 @@ Uint32 MGUI_ReadLE32FP (FILE *src) size_t size; size = fread(&value, (sizeof value), 1, src); - if (size < sizeof (value)) + if (size < 1) return -1; return (ArchSwapLE32(value)); diff --git a/src/newgdi/gdi.c b/src/newgdi/gdi.c index 63571f64..4bbde3d5 100644 --- a/src/newgdi/gdi.c +++ b/src/newgdi/gdi.c @@ -591,7 +591,6 @@ static void _dc_draw_pixel_span_set_1 (COMP_CTXT* comp_ctxt, int w) static void _dc_draw_pixel_span_set_2 (COMP_CTXT* comp_ctxt, int w) { int step = comp_ctxt->step; -// printf("w=%d, %X\t", w, comp_ctxt->cur_pixel); if (comp_ctxt->cur_pixel != 0 || comp_ctxt->step != 1) { Uint16 * dest16 = (Uint16 *)comp_ctxt->cur_dst; if (w < 5 || step != 1) diff --git a/src/newgdi/icon.c b/src/newgdi/icon.c index 616a22c0..966d057f 100644 --- a/src/newgdi/icon.c +++ b/src/newgdi/icon.c @@ -206,7 +206,7 @@ HICON GUIAPI LoadIconFromFile (HDC hdc, const char* filename, int which) goto error; /* read image*/ - if (fread (image, imagesize, 1, fp) < imagesize) { + if (fread (image, 1, imagesize, fp) < imagesize) { goto error_free; }