guitool.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 455 行 · 第 1/2 页
C
455 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Dockable GUI toolbar.
*
****************************************************************************/
#include "guiwind.h"
#include <stdlib.h>
#include <string.h>
#include "guixwind.h"
#include "guiscale.h"
#include "guitool.h"
#include "guimapky.h"
#include "guimenus.h"
#include "guixutil.h"
extern WPI_INST GUIResHInst;
extern gui_menu_struct GUIHint[];
/* total height/width taken up by outline around bitmap, on button */
#if defined (__NT__)
#define OUTLINE_AMOUNT 4 // Should be changed later.
#else
#define OUTLINE_AMOUNT 4
#endif
#define BORDER_AMOUNT 1 /* space outside row of buttons */
/*
* GUIXCloseToolBar -- close the tool bar and free memory. Can be called by
* app. Gets called when parent window closed or floating
* toolbar window gets closed.
*/
bool GUIXCloseToolBar( gui_window *wnd )
{
toolbarinfo *toolbar;
int i;
if( ( wnd->toolbar != NULL ) && ( wnd->toolbar->hdl != NULL ) ) {
toolbar = wnd->toolbar;
wnd->toolbar = NULL;
ToolBarFini( toolbar->hdl );
for( i=0; i < toolbar->num; i++ ) {
_wpi_deletebitmap( toolbar->bitmaps[i] );
}
GUIMemFree( toolbar->bitmaps );
GUIMemFree( toolbar );
GUIResizeBackground( wnd, TRUE );
GUIEVENTWND( wnd, GUI_TOOLBAR_DESTROYED, NULL );
}
return( TRUE );
}
static gui_window *GetToolWnd( HWND hwnd )
{
HWND parent;
#ifndef __OS2_PM__
parent = _wpi_getparent( hwnd );
if( parent != HWND_DESKTOP ) {
return( GUIGetWindow( parent ) );
}
#else
parent = _wpi_getparent(_wpi_getparent( hwnd ));
if( parent == HWND_DESKTOP ) {
parent = _wpi_getowner( _wpi_getparent( hwnd ) );
}
if( parent != HWND_DESKTOP ) {
return( GUIGetWindow( parent ) );
}
#endif
return( NULL );
}
void GUIToolBarHelp( HWND hwnd, WPI_PARAM1 id, BOOL down )
{
gui_window *wnd;
gui_menu_styles style;
wnd = GetToolWnd( hwnd );
if( wnd != NULL ) {
style = ( down ? GUI_ENABLED : GUI_IGNORE );
GUIDisplayHintText( wnd, wnd, (int)id, TOOL_HINT, style );
}
}
/*
* GUIToolBarProc - hook message handler for the tool bar.
*/
BOOL GUIToolBarProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
#ifdef __WINDOWS_386__
WPI_MINMAXINFO FAR *minmax;
#else
WPI_MINMAXINFO *minmax;
#endif
gui_window *wnd;
toolbarinfo *toolbar;
HMENU hmenu;
WORD param;
wnd = GetToolWnd( hwnd );
if( wnd == NULL ) {
return( FALSE );
}
toolbar = wnd->toolbar;
if( toolbar == NULL ) {
return( FALSE );
}
switch( msg ) {
case WM_CREATE :
hwnd = _wpi_getframe( hwnd );
hmenu = _wpi_getsystemmenu( hwnd );
if( hmenu != NULLHANDLE ) {
if( _wpi_appendmenu( hmenu, MF_SEPARATOR, 0, 0,
NULLHANDLE, NULL ) ) {
_wpi_appendmenu( hmenu, MF_ENABLED|MF_SYSMENU, 0,
GUIHint[GUI_MENU_FIX_TOOLBAR].id, NULLHANDLE,
GUIHint[GUI_MENU_FIX_TOOLBAR].label );
}
}
break;
#ifdef __OS2_PM__
case WM_CHAR :
case WM_TRANSLATEACCEL :
#else
case WM_SYSKEYDOWN :
case WM_SYSKEYUP :
case WM_KEYUP :
case WM_KEYDOWN :
#endif
return( (BOOL)GUIProcesskey( hwnd, msg, wparam, lparam ) );
case WM_MENUSELECT :
GUIProcessMenuSelect( wnd, hwnd, msg, wparam, lparam );
return( TRUE );
break;
case WM_SYSCOMMAND :
param = _wpi_getid( wparam );
switch( param ) {
case GUI_FIX_TOOLBAR :
GUIChangeToolBar( wnd );
}
break;
#ifndef __OS2_PM__
case WM_NCLBUTTONDBLCLK :
#endif
case WM_RBUTTONDBLCLK :
case WM_LBUTTONDBLCLK :
/* flip the current state of the toolbar -
* if we are fixed then start to float or vice versa
*/
if( !HasToolAtPoint( toolbar->hdl, wparam, lparam ) ) {
#ifdef __OS2_PM__
// Hack: For some reason we will get here with bogus coords,
// we need to ignore the event. Should really find out where
// the message is coming from.
if( (ULONG)wparam != 0x0FFFFFFF )
GUIChangeToolBar( wnd );
#else
GUIChangeToolBar( wnd );
#endif
return( TRUE );
}
break;
case WM_MOVE:
case WM_SIZE:
// Whenever we are moved or sized as a floating toolbar, we remember our position
// so that we can restore it when dbl. clicked
if( toolbar->info.style == TOOLBAR_FLOAT_STYLE ) {
hwnd = _wpi_getframe( hwnd );
_wpi_getwindowrect( hwnd, &( toolbar->floatrect ) );
}
break;
case WM_GETMINMAXINFO:
#ifdef __WINDOWS_386__
minmax = (WPI_MINMAXINFO FAR *)MK_FP32( (void *)lparam );
#else
minmax = (WPI_MINMAXINFO *)lparam;
#endif
_wpi_setmintracksize( minmax, ( toolbar->info.border_size.x +
_wpi_getsystemmetrics( SM_CXFRAME ) ) * 2 +
toolbar->info.button_size.x,
( toolbar->info.border_size.y +
_wpi_getsystemmetrics( SM_CYFRAME ) ) * 2 +
toolbar->info.button_size.y +
_wpi_getsystemmetrics( SM_CYCAPTION ) );
break;
case WM_CLOSE :
GUICloseToolBar( wnd );
return( TRUE );
break;
}
return( FALSE );
}
/*
* GUIXCreateToolBar -- create a tool bar, fixed or not
*/
bool GUIXCreateToolBar( gui_window *wnd, bool fixed, gui_ord height,
int num_toolbar_items, gui_toolbar_struct *toolinfo,
bool excl, gui_colour_set *plain,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?