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

📄 ctrlmisc.c

📁 在ADS环境下MiniGUI的源码
💻 C
字号:
/*
** $Id: ctrlmisc.c,v 1.21 2004/06/26 07:49:31 weiym Exp $
**
** ctrlmisc.c: the Control Misc module.
**
** Copyright (C) 2003 Feynman Software.
** Copyright (C) 1999 ~ 2002 Wei Yongming.
**
** Current maintainer: Wei Yongming.
**
** Create date: 1999/8/23
*/

/*
** 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
*/

/*
** TODO:
*/

#include "stdio.h"

#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "control.h"

#include "ctrlmisc.h"

void GUIAPI NotifyParentEx (HWND hwnd, int id, int code, DWORD add_data)
{
    NOTIFPROC notif_proc = GetNotificationCallback (hwnd);

    if (notif_proc) {
        notif_proc (hwnd, id, code, add_data);
    }
    else {
        SendNotifyMessage (GetParent (hwnd), MSG_COMMAND, 
                                 (WPARAM) MAKELONG (id, code), (LPARAM)hwnd);
    }
}

/****************************** Drawing Helpers *******************************/
void GUIAPI Draw3DThickFrameEx (HDC hdc, HWND hwnd, int l, int t, int r, int b, DWORD flags, gal_pixel fillc)
{
    if ((flags & DF_3DBOX_STATEMASK) == DF_3DBOX_NORMAL) {
        r--;
        b--;

        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_RIGHT_INNER));
        Rectangle(hdc, l, t, r, b);
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER));
        Rectangle(hdc, l, t, r - 1, b - 1);
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_OUTER));
        MoveTo(hdc, l, b);
        LineTo(hdc, r, b);
        LineTo(hdc, r, t);
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_RIGHT_OUTER));
        MoveTo(hdc, l + 1, b - 1);
        LineTo(hdc, l + 1, t + 1);
        LineTo(hdc, r - 1, t + 1); 
    }
    else {
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_OUTER));
        MoveTo(hdc, l, b);
        LineTo(hdc, l, t);
        LineTo(hdc, r, t);
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER));
        MoveTo(hdc, l + 1, b - 1);
        LineTo(hdc, l + 1, t + 1);
        LineTo(hdc, r - 1, t + 1);
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_RIGHT_INNER));
        MoveTo(hdc, l + 1, b - 1);
        LineTo(hdc, r - 1, b - 1);
        LineTo(hdc, r - 1, t + 1);
        SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_RIGHT_OUTER));
        MoveTo(hdc, l, b);
        LineTo(hdc, r, b);
        LineTo(hdc, r, t);
    }

    if (flags & DF_3DBOX_FILL) {
         SetBrushColor (hdc, fillc);
         FillBox (hdc, l + 2, t + 2, r - l - 3, b - t - 3);
    }
}

void GUIAPI Draw3DThinFrameEx (HDC hdc, HWND hwnd, int l, int t, int r, int b, DWORD flags, gal_pixel fillc)
{
    if ((flags & DF_3DBOX_STATEMASK) == DF_3DBOX_NORMAL) {
        SetPenColor(hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_DARK));
        MoveTo(hdc, l, b);
        LineTo(hdc, r, b);
        LineTo(hdc, r, t);
        SetPenColor(hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_LIGHT));
        MoveTo(hdc, l, b);
        LineTo(hdc, l, t);
        LineTo(hdc, r, t); 
    }
    else {
        SetPenColor(hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_LIGHT));
        MoveTo(hdc, l, b);
        LineTo(hdc, r, b);
        LineTo(hdc, r, t);
        SetPenColor(hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_DARK));
        MoveTo(hdc, l, b);
        LineTo(hdc, l, t);
        LineTo(hdc, r, t);
    }

    if (flags & DF_3DBOX_FILL) {
         SetBrushColor (hdc, fillc);
         FillBox(hdc, l + 1, t + 1, r - l - 2, b - t - 2);
    }
}

void GUIAPI Draw3DBorderEx (HDC hdc, HWND hwnd, int l, int t, int r, int b)
{
    SetPenColor(hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_LIGHT));
    Rectangle (hdc, l + 1, t + 1, r - 1, b - 1);

    SetPenColor(hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_DARK));
    Rectangle (hdc, l, t, r - 2, b - 2);
}

void GUIAPI DisabledTextOutEx (HDC hdc, HWND hwnd, int x, int y, const char* szText)
{
    SetBkMode (hdc, BM_TRANSPARENT);
    SetTextColor (hdc, GetWindowElementColor (WEC_3DBOX_LIGHT));
    TextOut (hdc, x + 1, y + 1, szText);
    SetTextColor (hdc, GetWindowElementColor (WEC_3DBOX_DARK));
    TextOut (hdc, x, y, szText);
}

void Draw3DControlFrameEx (HDC hdc, HWND hwnd, int x0, int y0, int x1, int y1, 
            DWORD flags, gal_pixel fillc)
{
    int left, top, right, bottom;
    left = MIN (x0, x1);
    top  = MIN (y0, y1);
    right = MAX (x0, x1);
    bottom = MAX (y0, y1);
    
    if (flags & DF_3DBOX_FILL) {
        SetBrushColor (hdc, fillc);
        FillBox (hdc, left + 1, top + 1, right - left - 1 , bottom - top - 1); 
    }

    if ((flags & DF_3DBOX_STATEMASK) == DF_3DBOX_PRESSED) {
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_DARK));
        MoveTo (hdc, left, bottom);
        LineTo (hdc, left, top);
        LineTo (hdc, right, top);
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_LIGHT));
        MoveTo (hdc, left, bottom);
        LineTo (hdc, right, bottom);
        LineTo (hdc, right, top);

        left++; top++; right--; bottom--;
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WED_3DBOX_REVERSE));
        MoveTo (hdc, left, bottom);
        LineTo (hdc, left, top);
        LineTo (hdc, right, top);
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_DARK));
        MoveTo (hdc, left, bottom);
        LineTo (hdc, right, bottom);
        LineTo (hdc, right, top);
    }
    else {
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_LIGHT));
        MoveTo (hdc, left, bottom);
        LineTo (hdc, left, top);
        LineTo (hdc, right, top);
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WED_3DBOX_REVERSE));
        LineTo (hdc, right, bottom);
        LineTo (hdc, left, bottom);

        left++; top++; right--; bottom--;
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WEC_3DBOX_DARK));
        MoveTo (hdc, left, bottom);
        LineTo (hdc, left, top);
        LineTo (hdc, right, top);
        SetPenColor (hdc, GetWindowElementColorEx (hwnd, WED_3DBOX_REVERSE));
        LineTo (hdc, right, bottom);
        LineTo (hdc, left, bottom);
    }
}

void DrawFlatControlFrameEx (HDC hdc, HWND hwnd, int x0, int y0, int x1, int y1, 
            int corner, DWORD flags, gal_pixel fillc)
{
    int left, top, right, bottom;
    left = MIN (x0, x1);
    top  = MIN (y0, y1);
    right = MAX (x0, x1);
    bottom = MAX (y0, y1);
    
    if (flags & DF_3DBOX_FILL) {
        SetBrushColor (hdc, fillc);
        FillBox (hdc, left, top, right - left + 1, bottom - top + 1); 
    }

    SetPenColor (hdc, GetWindowElementColor (WEC_FLAT_BORDER));

    if (corner < 1) {
        Rectangle (hdc, left, top, right, bottom);
        return;
    }

    if ((flags & DF_3DBOX_STATEMASK) == DF_3DBOX_NORMAL) {
        right --; bottom --;
    }

    MoveTo (hdc, left + corner, top);
    LineTo (hdc, right - corner, top);
    LineTo (hdc, right, top + corner);
    LineTo (hdc, right, bottom - corner);
    LineTo (hdc, right - corner, bottom);
    LineTo (hdc, left + corner, bottom);
    LineTo (hdc, left, bottom - corner);
    LineTo (hdc, left, top + corner);
    LineTo (hdc, left + corner, top);

    corner++;
    if ((flags & DF_3DBOX_STATEMASK) == DF_3DBOX_NORMAL) {
        MoveTo (hdc, right + 1, top + corner);
        LineTo (hdc, right + 1, bottom - corner);
        MoveTo (hdc, left + corner, bottom + 1);
        LineTo (hdc, right - corner + 1, bottom + 1);
    }
    else {
        MoveTo (hdc, left + corner, top + 1);
        LineTo (hdc, right - corner, top + 1);
        MoveTo (hdc, left + 1, top + corner);
        LineTo (hdc, left + 1, bottom - corner);
    }
}

void GUIAPI DrawBoxFromBitmap (HDC hdc, const RECT* box, const BITMAP* bmp, BOOL h_v, BOOL do_clip)
{
    int bmp_w, bmp_h, bmp_x, bmp_y, x, y;

    if (do_clip)
        ClipRectIntersect (hdc, box);

    if (h_v) {
        bmp_w = bmp->bmWidth/3;
        bmp_h = bmp->bmHeight;
        bmp_y = (box->bottom + box->top - bmp_h)>>1;

        FillBoxWithBitmapPart (hdc, box->left, bmp_y,
                        bmp_w, bmp_h, 0, 0, bmp, 0, 0);
        for (x = box->left + bmp_w; x < box->right - bmp_w; x += bmp_w)
            FillBoxWithBitmapPart (hdc, x, bmp_y,
                        bmp_w, bmp_h, 0, 0, bmp, bmp_w, 0);
        FillBoxWithBitmapPart (hdc, box->right - bmp_w, bmp_y, 
                        bmp_w, bmp_h, 0, 0, bmp, bmp_w*2, 0);
    }
    else {
        bmp_w = bmp->bmWidth;
        bmp_h = bmp->bmHeight/3;
        bmp_x = (box->right + box->left - bmp_w)>>1;

        FillBoxWithBitmapPart (hdc, bmp_x, box->top,
                        bmp_w, bmp_h, 0, 0, bmp, 0, 0);
        for (y = box->top + bmp_h; y < box->bottom - bmp_h; y += bmp_h)
            FillBoxWithBitmapPart (hdc, bmp_x, y,
                        bmp_w, bmp_h, 0, 0, bmp, 0, bmp_h);
        FillBoxWithBitmapPart (hdc, bmp_x, box->bottom - bmp_h,
                        bmp_w, bmp_h, 0, 0, bmp, 0, bmp_h*2);
    }
}

int EditOnEraseBackground (HWND hWnd, HDC hdc, const RECT* pClipRect)
{
    RECT rcTemp;
    BOOL fGetDC = FALSE;
    BOOL hidden;

    if (GetWindowExStyle (hWnd) & WS_EX_TRANSPARENT)
        return 0;

    hidden = HideCaret (hWnd);

    if (hdc == 0) {
        hdc = GetClientDC (hWnd);
        fGetDC = TRUE;
    }

    GetClientRect (hWnd, &rcTemp);

    if (pClipRect)
        ClipRectIntersect (hdc, pClipRect);

    if (GetWindowStyle (hWnd) & WS_DISABLED)
        SetBrushColor (hdc, GetWindowElementColor (BKC_EDIT_DISABLED));
    else
        SetBrushColor (hdc, GetWindowBkColor (hWnd));

    FillBox (hdc, rcTemp.left, rcTemp.top, RECTW (rcTemp), RECTH (rcTemp));

    if (fGetDC)
        ReleaseDC (hdc);

    if (hidden)
        ShowCaret (hWnd);

    return 0;
}

⌨️ 快捷键说明

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