⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollwnd.c

📁 有了操作系统、TCP/IP协议栈、文件系统
💻 C
字号:
/*** $Id: scrollwnd.c,v 1.9 2005/01/19 05:41:06 clear Exp $**** scrollwnd.c: scrollwnd control, a scrollable container window**** Copyright (C) 2004 Feynman Software.** ** Current maintainer: Zhong Shuyi (zhongsy@minigui.org).**** Create date: 2004/03/01*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "ctrl/ctrlhelper.h"#include "ctrl/scrollview.h"#include "cliprect.h"#include "internals.h"#include "ctrlclass.h"#ifdef _CTRL_SCROLLVIEW#include "ctrlmisc.h"#include "scrolled.h"#include "scrollwnd.h"/* ---------------------------------------------------------------------------- *//* internal used static function declarations */static BOOL RegisterContainer (void);static void container_reset_content (HWND hWnd, PCONTDATA pcontdata);/* ---------------------------------------------------------------------------- *//* adjust the position and size of the container window */static void scrollwnd_set_container (HWND hWnd, PSCRDATA pscrdata, BOOL visChanged){    PSWDATA pswdata = (PSWDATA) GetWindowAdditionalData2 (hWnd);    MoveWindow (pswdata->hContainer, -pscrdata->nContX, -pscrdata->nContY,                pscrdata->nContWidth,                pscrdata->nContHeight, TRUE);}int scrollwnd_add_controls (HWND hWnd, PSWDATA pswdata,                              int ctrl_nr, PCTRLDATA pCtrlData){    int i;    HWND hCtrl;    if (!pCtrlData || ctrl_nr <= 0)        return -1;    for (i = 0; i < ctrl_nr; i++) {        hCtrl = CreateWindowEx (pCtrlData->class_name,                                pCtrlData->caption,                                pCtrlData->dwStyle | WS_CHILD,                                pCtrlData->dwExStyle,                                pCtrlData->id,                                pCtrlData->x, pCtrlData->y,                                pCtrlData->w, pCtrlData->h,                                pswdata->hContainer,                                pCtrlData->dwAddData);        if (hCtrl == HWND_INVALID) {            return FALSE;        }        pCtrlData ++;    }    return 0;}static void create_container (HWND hWnd, PSWDATA pswdata){    PCONTAINERINFO cont_info = (PCONTAINERINFO) GetWindowAdditionalData(hWnd);#if 0    if (cont_info) {        pswdata->nContX = cont_info->x;        pswdata->nContY = cont_info->y;        if (cont_info->w > 0) pswdata->nContWidth = cont_info->w;        if (cont_info->h > 0) pswdata->nContHeight = cont_info->h;    }#endif    pswdata->hContainer = CreateWindowEx (CTRL_CONTAINER, "",                             WS_VISIBLE, WS_EX_NONE,                            IDC_STATIC,                            pswdata->scrdata.nContX, pswdata->scrdata.nContY,                            pswdata->scrdata.nContWidth, pswdata->scrdata.nContHeight,                            hWnd, 0);    pswdata->pContdata = (PCONTDATA) GetWindowAdditionalData2 (pswdata->hContainer);    if (cont_info && cont_info->user_proc)        SetWindowCallbackProc (pswdata->hContainer, cont_info->user_proc);    if (cont_info && (cont_info->controlnr > 0))        scrollwnd_add_controls (hWnd, pswdata, cont_info->controlnr, cont_info->controls);    SendMessage (pswdata->hContainer, MSG_INITCONTAINER, 0, cont_info ? cont_info->dwAddData : 0);}/* * initialize scrollwnd internal structure */static int svInitData (HWND hWnd, PSWDATA pswdata){    scrolled_init (hWnd, &pswdata->scrdata, 0, 0);    pswdata->scrdata.move_content = scrollwnd_set_container;     pswdata->flags = 0;    create_container (hWnd, pswdata);    return 0;}/*  * shoulded be called before scrollwnd is used * hWnd: the scrolled window */int scrollwnd_init (HWND hWnd, PSWDATA pswdata){    if (!pswdata)        return -1;    SetWindowAdditionalData2 (hWnd, 0);    ShowScrollBar (hWnd, SB_HORZ, FALSE);    ShowScrollBar (hWnd, SB_VERT, FALSE);    svInitData (hWnd, pswdata);    SetWindowAdditionalData2 (hWnd, (DWORD) pswdata);    /* set scrollbar status */    scrolled_set_hscrollinfo (hWnd, &pswdata->scrdata);    scrolled_set_vscrollinfo (hWnd, &pswdata->scrdata);                                        return 0;}/* * destroy a scrollwnd */void scrollwnd_destroy (PSWDATA pswdata){    DestroyWindow (pswdata->hContainer);}/* --------------------------------------------------------------------------------- */void scrollwnd_reset_content (HWND hWnd, PSWDATA pswdata){    /* delete all container content */    container_reset_content (pswdata->hContainer, pswdata->pContdata);    if (pswdata->scrdata.sbPolicy != SB_POLICY_ALWAYS) {        ShowScrollBar (hWnd, SB_HORZ, FALSE);        ShowScrollBar (hWnd, SB_VERT, FALSE);    }    /* reset content and viewport size */    scrolled_init_contsize (hWnd, &pswdata->scrdata);    /* reset container window */    //FIXME    scrollwnd_set_container (hWnd, &pswdata->scrdata, TRUE);    /* reset viewport window */    scrolled_set_visible (hWnd, &pswdata->scrdata);    scrolled_set_hscrollinfo (hWnd, &pswdata->scrdata);    scrolled_set_vscrollinfo (hWnd, &pswdata->scrdata);    //InvalidateRect (pswdata->hContainer, NULL, TRUE);    scrollwnd_refresh_content (pswdata);}/* --------------------------------------------------------------------------------- */int ScrollWndCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    PSWDATA pswdata = NULL;    if (message != MSG_CREATE)        pswdata = (PSWDATA) GetWindowAdditionalData2 (hWnd);    switch (message) {    case MSG_CREATE:    {        pswdata = (PSWDATA) malloc(sizeof (SWDATA));        if (!pswdata)            return -1;        scrollwnd_init (hWnd, pswdata);        break;    }    case MSG_DESTROY:        scrollwnd_destroy (pswdata);        free (pswdata);        break;        case MSG_ERASEBKGND:        EditOnEraseBackground (hWnd, (HDC)wParam, (const RECT*)lParam);        return 0;    case MSG_GETDLGCODE:        return DLGC_WANTTAB | DLGC_WANTARROWS;    case SVM_ADDCTRLS:    {        int ctrl_nr = (int)wParam;        PCTRLDATA pCtrlData = (PCTRLDATA)lParam;        scrollwnd_add_controls (hWnd, pswdata, ctrl_nr, pCtrlData);        return 0;    }    case SVM_GETCTRL:        return GetDlgItem (pswdata->hContainer, wParam);    case SVM_RESETCONTENT:        scrollwnd_reset_content (hWnd, pswdata);        return 0;    case SVM_SETCONTAINERPROC:        scrollwnd_set_container_proc (pswdata, (WNDPROC)lParam);        return 0;    case SVM_GETFOCUSCHILD:        return (int)GetFocus (pswdata->hContainer);    }/* end switch */    return DefaultScrolledProc (hWnd, message, wParam, lParam);}BOOL RegisterScrollWndControl (void){    WNDCLASS WndClass;    if (!RegisterContainer ())        return FALSE;    WndClass.spClassName = CTRL_SCROLLWND;    WndClass.dwStyle     = WS_NONE;    WndClass.dwExStyle   = WS_EX_NONE;    WndClass.hCursor     = GetSystemCursor (IDC_ARROW);    WndClass.iBkColor    = GetWindowElementColor (BKC_CONTROL_DEF);    WndClass.WinProc     = ScrollWndCtrlProc;    return AddNewControlClass (&WndClass) == ERR_OK;}/* ------------------------------------ container --------------------------- */static PCONTDATA container_init (HWND hWnd){    PCONTDATA pcontdata;    if ( !(pcontdata = (PCONTDATA) malloc (sizeof (CONTDATA))) )        return NULL;    pcontdata->hSV = GetParent(hWnd);    pcontdata->flags = 0;    SetWindowAdditionalData2 (hWnd, (DWORD) pcontdata);    return pcontdata;}static void container_reset_content (HWND hWnd, PCONTDATA pcontdata){    DestroyAllControls (hWnd);}static void container_destroy (HWND hWnd, PCONTDATA pcontdata){    container_reset_content (hWnd, pcontdata);    free (pcontdata);}/* ---------------------------------------------------------------------------- */int GUIAPI DefaultContainerProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    PCONTDATA pcontdata = NULL;    switch (message) {    case MSG_CREATE:        if ( !container_init (hWnd) )            return -1;        break;    case MSG_DESTROY:        pcontdata = (PCONTDATA) GetWindowAdditionalData2 (hWnd);        container_destroy (hWnd, pcontdata);        break;    case MSG_ERASEBKGND:        EditOnEraseBackground (hWnd, (HDC)wParam, (const RECT*)lParam);        return 0;    case MSG_COMMAND:        pcontdata = (PCONTDATA) GetWindowAdditionalData2 (hWnd);        SendNotifyMessage (GetParent(pcontdata->hSV), MSG_SVCONTCMD, wParam, lParam);        break;    } /* end switch */    return DefaultPageProc (hWnd, message, wParam, lParam);    //return DefaultControlProc (hWnd, message, wParam, lParam);}static BOOL RegisterContainer (void){    WNDCLASS WndClass;    WndClass.spClassName = CTRL_CONTAINER;    WndClass.dwStyle     = WS_NONE;    WndClass.dwExStyle   = WS_EX_NONE;    WndClass.hCursor     = GetSystemCursor (IDC_ARROW);    WndClass.iBkColor    = GetWindowElementColor (BKC_CONTROL_DEF);    WndClass.WinProc     = DefaultContainerProc;    return AddNewControlClass (&WndClass) == ERR_OK;}#endif /* _CTRL_SCROLLVIEW */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -