📄 toolbar.c
字号:
// $Id: toolbar.c,v 1.3 2000/09/20 01:36:29//// toolbar.c: the toolbar Control module.//// Copyright (C) 1999, 2000, linpus.// Copyright (C) 2000, BluePoint Software.//// Current maitainer: Chen Lei (chenlei@minigui.org).//// Create date: 2000/9/20/*** This library is free software; you can redistribute it and/or** modify it under the terms of the GNU Library General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This library 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** Library General Public License for more details.**** You should have received a copy of the GNU Library General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*//*** Alternatively, the contents of this file may be used under the terms** of the Mozilla Public License (the "MPL License") in which case the** provisions of the MPL License are applicable instead of those above.*///// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------//#include <stdio.h>#include <stdlib.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include "cliprect.h"#include "internals.h"#include "ctrlclass.h"#include "toolbar.h"#include "ctrlmisc.h"#ifndef lint static char fileid[] = "$Id: toolbar.c,v 1.8 2000/11/28 06:41:32 ymwei Exp $";#endifBOOL RegisterToolbarControl (void){ // This control class is "Toolbar" WNDCLASS WndClass; WndClass.spClassName = "toolbar"; WndClass.dwStyle = 0; WndClass.hCursor = GetSystemCursor (IDC_ARROW); WndClass.iBkColor = PIXEL_lightgray; WndClass.WinProc = ToolbarCtrlProc; return AddNewControlClass (&WndClass) == ERR_OK;}void ToolbarControlCleanup (void){ return;}void DrawToolBox (HDC hdc, PTOOLBARCTRL pdata){ TOOLBARITEMDATA* tmpdata; tmpdata = pdata->head; while (tmpdata != NULL) { FillBoxWithBitmap (hdc, (tmpdata->RcTitle)->left , (tmpdata->RcTitle)->top, 0, 0, tmpdata->NBmp); tmpdata = tmpdata->next; }}TOOLBARITEMDATA* GetCurTag(int posx,int posy, PTOOLBARCTRL pdata){ TOOLBARITEMDATA* tmpdata; tmpdata = pdata->head; while (tmpdata != NULL) { if (PtInRect (tmpdata->RcTitle, posx, posy)) { return tmpdata; } tmpdata = tmpdata->next; } return NULL; }void HilightToolBox (HWND hWnd, TOOLBARITEMDATA* pItemdata) //alternative :change it to lineto and moveto instead of three Bitmap.{ HDC hdc; hdc = GetClientDC (hWnd); FillBoxWithBitmap (hdc, (pItemdata->RcTitle)->left, (pItemdata->RcTitle)->top, 0,0, pItemdata->HBmp); ReleaseDC (hdc);}void UnhilightToolBox (HWND hWnd, TOOLBARITEMDATA* pItemdata) //alternative :change it to lineto and moveto instead of three Bitmap.{ HDC hdc; hdc = GetClientDC (hWnd); FillBoxWithBitmap (hdc, (pItemdata->RcTitle)->left, (pItemdata->RcTitle)->top, 0, 0, pItemdata->DBmp); ReleaseDC (hdc);}///////////////////////////////////////////////////////////////////////int ToolbarCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; PCONTROL pCtrl; DWORD dwStyle; PTOOLBARCTRL TbarData; //2000/10/19 added by leon begin DWORD data; //2000/10/19 added by leon end PTOOLBARITEMDATA pTbid; pCtrl = Control (hWnd); dwStyle = pCtrl->dwStyle; switch (message) { case MSG_NCCREATE: break; case MSG_CREATE: TbarData = (TOOLBARCTRL*) malloc (sizeof (TOOLBARCTRL)); TbarData->nCount = 0; TbarData->head = TbarData->tail = NULL; TbarData->iLBDn = 0; SetWindowAdditionalData2(hWnd,(DWORD)TbarData); break; case MSG_PAINT: { TbarData=(PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); hdc = BeginPaint (hWnd); DrawToolBox (hdc, TbarData); EndPaint (hWnd, hdc); } break; case MSG_DESTROY: { TOOLBARITEMDATA* unloaddata; TbarData=(PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); unloaddata = TbarData->head; while( unloaddata != NULL) { free ((RECT*)unloaddata->RcTitle); UnloadBitmap ((PBITMAP)(unloaddata->NBmp)); free ((PBITMAP)(unloaddata->NBmp)); UnloadBitmap ((PBITMAP)(unloaddata->HBmp)); free ((PBITMAP)(unloaddata->HBmp)); UnloadBitmap ((PBITMAP)(unloaddata->DBmp)); free ((PBITMAP)(unloaddata->DBmp)); unloaddata = unloaddata->next; } } break; case TBM_ADDITEM: { TOOLBARITEMINFO* TbarInfo = NULL; TOOLBARITEMDATA* ptemp; RECT rc; TbarData=(PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); TbarInfo = (TOOLBARITEMINFO*) lParam; data = GetWindowAdditionalData (hWnd); TbarData->ItemWidth = HIWORD(data); TbarData->ItemHeight = LOWORD(data); GetClientRect (hWnd, &rc); ptemp = (TOOLBARITEMDATA*)malloc (sizeof (TOOLBARITEMDATA)); ptemp->id = TbarInfo->id; ptemp->insPos = TbarInfo->insPos; ptemp->RcTitle = (RECT*)malloc (sizeof (RECT)); if (TbarData->tail == NULL) (ptemp->RcTitle)->left = 0; else (ptemp->RcTitle)->left = (TbarData->tail)->RcTitle->right; (ptemp->RcTitle)->right = (ptemp->RcTitle)->left+TbarData->ItemWidth; (ptemp->RcTitle)->top = 0; (ptemp->RcTitle)->bottom = (ptemp->RcTitle)->top+TbarData->ItemHeight; ptemp->NBmp = (BITMAP*)malloc (sizeof (BITMAP)); ptemp->HBmp = (BITMAP*)malloc (sizeof (BITMAP)); ptemp->DBmp = (BITMAP*)malloc (sizeof (BITMAP)); LoadBitmap (HDC_SCREEN, ptemp->NBmp, TbarInfo->NBmpPath); LoadBitmap (HDC_SCREEN, ptemp->HBmp, TbarInfo->HBmpPath); LoadBitmap (HDC_SCREEN, ptemp->DBmp, TbarInfo->DBmpPath); ptemp->next = NULL; if (TbarData->nCount == 0) TbarData->head = TbarData->tail = ptemp; else if (TbarData->nCount > 0) { (TbarData->tail)->next = ptemp; TbarData->tail = ptemp; } else { fprintf (stderr, "nCount<0 error!\n");}; // to do. (TbarData->nCount)++; } break; case MSG_MOUSEMOVEIN: { TbarData = (PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); if (!wParam) { hdc = GetClientDC (hWnd); DrawToolBox (hdc, TbarData); ReleaseDC (hdc); } } break; case MSG_LBUTTONDOWN: { int posx, posy; TbarData=(PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); posx = LOWORD (lParam); posy = HIWORD (lParam); if (GetCapture () == hWnd) break; SetCapture (hWnd); //2000/10/19 modified by leon begin if ((pTbid = GetCurTag (posx,posy,TbarData)) == NULL) break; TbarData->iLBDn = 1; TbarData->iSel = pTbid->insPos; UnhilightToolBox (hWnd, GetCurTag (posx, posy, TbarData)); //2000/10/19 modified by leon end } break; case MSG_LBUTTONUP: { int x, y; TbarData=(PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); x = LOWORD(lParam); y = HIWORD(lParam); TbarData->iLBDn = 0; if (GetCapture() != hWnd) break; ReleaseCapture (); ScreenToClient (hWnd, &x, &y); //2000/10/19 modified by leon begin if ((pTbid = GetCurTag(x, y, TbarData)) == NULL) { hdc = GetClientDC (hWnd); DrawToolBox (hdc, TbarData); ReleaseDC (hdc); break; } else HilightToolBox (hWnd, GetCurTag (x, y, TbarData)); InvalidateRect (hWnd, NULL, FALSE); if (TbarData->iSel == pTbid->insPos) SendMessage (GetParent (hWnd), MSG_COMMAND, (WPARAM)MAKELONG (pCtrl->id, GetCurTag (x, y, TbarData)->id), (LPARAM)hWnd); //2000/10/19 modified by leon end } break; case MSG_MOUSEMOVE: { int x, y; TbarData = (PTOOLBARCTRL) GetWindowAdditionalData2(hWnd); x = LOWORD(lParam); y = HIWORD(lParam); if (TbarData->iLBDn == 1) ScreenToClient (hWnd, &x, &y); if (( pTbid = GetCurTag (x, y, TbarData)) == NULL) { hdc = GetClientDC (hWnd); DrawToolBox (hdc, TbarData); ReleaseDC (hdc); break; } if (TbarData->iMvOver != pTbid->insPos) { TbarData->iMvOver = pTbid->insPos; hdc = GetClientDC (hWnd); DrawToolBox (hdc, TbarData); ReleaseDC (hdc); } if (TbarData->iSel == pTbid->insPos && TbarData->iLBDn == 1) UnhilightToolBox (hWnd, GetCurTag (x, y, TbarData)); else if ( TbarData->iLBDn == 0 ) HilightToolBox (hWnd, GetCurTag(x, y, TbarData)); } break; default: break; } return DefaultControlProc (hWnd, message, wParam, lParam);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -