lstool.c

来自「CC386 is a general-purpose 32-bit C comp」· C语言 代码 · 共 577 行 · 第 1/2 页

C
577
字号
/* 
Copyright 2001-2003 Free Software Foundation, Inc.

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.  

You may contact the author at:

mailto::camille@bluegrass.net

or by snail mail at:

David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222

 **********************************************************************

This is a wrapper for toolbars which is compatible with the docking
window mechanism.

 **********************************************************************

 */
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "winconst.h"
#include "lsctrl.h"

#define TITLEWIDTH 15
#define EDGEWIDTH 1
#define TITLETOP 3
#define BARLEFT 2
#define BARRIGHT 2
#define BARTOP 2

#define INDENT 2

#ifndef __CCDL__
    #ifndef TBSTYLE_TRANSPARENT
        #define TBSTYLE_TRANSPARENT 0x8000
        #define TBSTYLE_FLAT            0x0800
    #endif 

    #ifndef BTNS_SEP
        #define BTNS_SEP TBSTYLE_SEP
    #endif 
    #ifndef TB_SETBUTTONINFO
        #define TBIF_IMAGE              0x00000001
        #define TBIF_TEXT               0x00000002
        #define TBIF_STATE              0x00000004
        #define TBIF_STYLE              0x00000008
        #define TBIF_LPARAM             0x00000010
        #define TBIF_COMMAND            0x00000020
        #define TBIF_SIZE               0x00000040
        typedef struct
        {
            UINT cbSize;
            DWORD dwMask;
            int idCommand;
            int iImage;
            BYTE fsState;
            BYTE fsStyle;
            WORD cx;
            LPDWORD lParam;
            LPSTR pszText;
            int cchText;
        } TBBUTTONINFOA,  *LPTBBUTTONINFOA;

        typedef struct
        {
            UINT cbSize;
            DWORD dwMask;
            int idCommand;
            int iImage;
            BYTE fsState;
            BYTE fsStyle;
            WORD cx;
            LPDWORD lParam;
            LPWSTR pszText;
            int cchText;
        } TBBUTTONINFOW,  *LPTBBUTTONINFOW;

        #ifdef UNICODE
            #define TBBUTTONINFO TBBUTTONINFOW
            #define LPTBBUTTONINFO LPTBBUTTONINFOW
        #else 
            #define TBBUTTONINFO TBBUTTONINFOA
            #define LPTBBUTTONINFO LPTBBUTTONINFOA
        #endif 


        // BUTTONINFO APIs do NOT support the string pool.
        #define TB_GETBUTTONINFOW        (WM_USER + 63)
        #define TB_SETBUTTONINFOW        (WM_USER + 64)
        #define TB_GETBUTTONINFOA        (WM_USER + 65)
        #define TB_SETBUTTONINFOA        (WM_USER + 66)
        #ifdef UNICODE
            #define TB_GETBUTTONINFO        TB_GETBUTTONINFOW
            #define TB_SETBUTTONINFO        TB_SETBUTTONINFOW
        #else 
            #define TB_GETBUTTONINFO        TB_GETBUTTONINFOA
            #define TB_SETBUTTONINFO        TB_SETBUTTONINFOA
        #endif 
    #endif 
#endif 

extern HWND hwndFrame;

static char *szToolBarWindClassName = "ladSoftToolBarWindow";
static TBBUTTON sep = 
{
    0, 0, 0, TBSTYLE_SEP
};
static char *GetTipText(CCW_params *ptr, int id)
{
    int i;
    for (i = 0; i < ptr->u.tb.btncount; i++)
    if (ptr->u.tb.buttons[i].idCommand == id)
    {
        return ptr->u.tb.hints[i];
    }
    return "";
}

//-------------------------------------------------------------------------

static void FormatToolBar(char *buf, HWND hwnd)
{
    TBBUTTON button;
    char *p = buf;
    int i = 0;
    buf[0] = 0;
    while (SendMessage(hwnd, TB_GETBUTTON, i++, (LPARAM) &button))
    {
        if (button.fsStyle == BTNS_SEP)
            sprintf(p, "-1 ");
        else
            sprintf(p, "%d ", button.idCommand);
        p += strlen(p);
    }
}

//-------------------------------------------------------------------------

static int ParseToolBar(char *buf, HWND hwnd, CCW_params *ptr, TBBUTTON
    *buttons)
{
    int rv = 0, i, id, count;
    char *p = buf;
    while (*p)
    {
        if (!isdigit(*p) &&  *p != '-')
            break;
        sscanf(p, "%d %n", &id, &count);
        p += count;
        if (id ==  - 1)
            buttons[rv++] = sep;
        else
        {
            for (i = 0; i < ptr->u.tb.btncount; i++)
            if (ptr->u.tb.buttons[i].idCommand == id)
            {

                buttons[rv] = ptr->u.tb.buttons[i];
                buttons[rv].fsStyle |= TBSTYLE_WRAPABLE;
                rv++;

            }
        }
        while (isspace(*p))
            p++;
    }
    return rv;

}

//-------------------------------------------------------------------------

static void ChangeTips(int num, HWND hwnd, TBBUTTON *buttons, CCW_params *ptr)
{
    int i;
    char *tip;
    TBBUTTONINFO s;
    memset(&s, 0, sizeof(s));
    if (num)
    {
        for (i = 0; i < num; i++)
        {
            tip = GetTipText(ptr, buttons[i].idCommand);
            if (tip)
            {
                s.cbSize = sizeof(s);
                s.dwMask = TBIF_TEXT;
                s.pszText = tip;
                s.cchText = strlen(tip);
                SendMessage(hwnd, TB_SETBUTTONINFO, buttons[i].idCommand, 
                    (LPARAM) &s);
            }
        }
    }
}

//-------------------------------------------------------------------------

static void SetRectSize(HWND hwnd, CCW_params *ptr)
{
    RECT r;
    TBBUTTON button;
    int num = 0;
    while (SendMessage(hwnd, TB_GETBUTTON, num, (LPARAM) &button))
        num++;
    if (hwnd == ptr->u.tb.hWnd)
    {
        MoveWindow(ptr->self, 0, INDENT, 1000, 1000, 0);
        SendMessage(hwnd, TB_GETITEMRECT, num - 1, (LPARAM) &r);
        ptr->u.tb.hsize.cx = r.right + GetSystemMetrics(SM_CXFRAME) *2;
        ptr->u.tb.hsize.cy = r.bottom + GetSystemMetrics(SM_CYFRAME) *2;

    }
    else
    {
        SendMessage(hwnd, TB_SETROWS, MAKEWPARAM(num, FALSE), (LPARAM) &r);
        //         SendMessage(hwnd,TB_GETITEMRECT,num-1,(LPARAM) & r) ;
        ptr->u.tb.vsize.cy = r.bottom + GetSystemMetrics(SM_CXFRAME) *2;
        ptr->u.tb.vsize.cx = r.right + GetSystemMetrics(SM_CYFRAME) *2;
    }
}

//-------------------------------------------------------------------------

static void ChangeButtons(int num, HWND hwnd, TBBUTTON *buttons, CCW_params
    *ptr)
{
    if (num)
    {
        int i;
        while (SendMessage(hwnd, TB_DELETEBUTTON, 0, 0))
            ;
        for (i = 0; i < num; i++)
            SendMessage(hwnd, TB_INSERTBUTTON, i + 1, (LPARAM) &buttons[i]);
        ChangeTips(ptr->u.tb.btncount, hwnd, buttons, ptr);
        SetRectSize(hwnd, ptr);
    }
}

//-------------------------------------------------------------------------

static void CopyButtons(CCW_params *ptr)
{
    TBBUTTON buttons[60];
    int i = 0;
    HWND hwnds, hwndd;

    if (ptr->vertical)
    {
        hwnds = ptr->u.tb.vWnd;
        hwndd = ptr->u.tb.hWnd;
    }
    else
    {
        hwnds = ptr->u.tb.hWnd;
        hwndd = ptr->u.tb.vWnd;
    }
    while (SendMessage(hwnds, TB_GETBUTTON, i, (LPARAM) &buttons[i]))
        i++;
    ChangeButtons(i, hwndd, buttons, ptr);
}

//-------------------------------------------------------------------------

int GetToolBarData(HWND hwnd, char *horiz, char *vert)
{
    char hbuf[512], vbuf[512];
    CCW_params *ptr = (CCW_params*)GetWindowLong(hwnd, 0);
    FormatToolBar(horiz, ptr->u.tb.hWnd);

⌨️ 快捷键说明

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