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

📄 wedit.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
*
*                            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:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <windows.h>
#include <ctype.h>
#include <string.h>
#include "win1632.h"

#include "wglbl.h"
#include "wribbon.h"
#include "wmem.h"
#include "wmain.h"
#include "wnewitem.h"
#include "wdel.h"
#include "wedit.h"
#include "wctl3d.h"
#include "wsetedit.h"
#include "wprev.h"
#include "wclip.h"
#include "wmsgfile.gh"
#include "wmsg.h"
#include "sys_rc.h"
#include "jdlg.h"

/****************************************************************************/
/* macro definitions                                                        */
/****************************************************************************/
#define WEDIT_PAD 4

/****************************************************************************/
/* type definitions                                                         */
/****************************************************************************/

/****************************************************************************/
/* external function prototypes                                             */
/****************************************************************************/
LRESULT WINEXPORT WMenuEditProc ( HWND, UINT, WPARAM, LPARAM );

extern UINT     WClipbdFormat;
extern UINT     WItemClipbdFormat;

/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static Bool  WInitEditWindow            ( WMenuEditInfo * );
static void  WExpandEditWindowItem      ( HWND, HWND, RECT * );

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/
static DLGPROC     WMenuEditWinProc = NULL;
static HBRUSH      WEditWinBrush    = NULL;
static COLORREF    WEditWinColor    = 0;

int appWidth = -1;
int appHeight = -1;

void WInitEditWindows ( HINSTANCE inst )
{
    _wtouch(inst);

    WEditWinColor = GetSysColor( COLOR_BTNFACE );
    WEditWinBrush = CreateSolidBrush ( WEditWinColor );
    WMenuEditWinProc = (DLGPROC)
        MakeProcInstance ( (FARPROC) WMenuEditProc, inst );
}

void WFiniEditWindows ( void )
{
    if ( WEditWinBrush ) {
        DeleteObject ( WEditWinBrush );
    }
    FreeProcInstance ( (FARPROC) WMenuEditWinProc );
}


Bool WCreateMenuEditWindow ( WMenuEditInfo *einfo, HINSTANCE inst )
{
    einfo->edit_dlg = JCreateDialogParam( inst, "WMenuEditDLG", einfo->win,
                                          WMenuEditWinProc, (LPARAM) einfo );

    if( einfo->edit_dlg == (HWND) NULL ) {
        return( FALSE );
    }

    if( !WCreatePrevWindow( inst, einfo ) ) {
        return( FALSE );
    }

    SetWindowPos( einfo->edit_dlg, (HWND)NULL, 0, WGetRibbonHeight(), 0, 0,
                  SWP_NOSIZE | SWP_NOZORDER );

    return( WInitEditWindow( einfo ) );
}

Bool WResizeMenuEditWindow ( WMenuEditInfo *einfo, RECT *prect )
{
    int   width, height, ribbon_depth;
    HWND  win;
    RECT  crect;

    if ( !einfo || !einfo->edit_dlg || !prect  ) {
        return ( FALSE );
    }

    if ( einfo->show_ribbon ) {
        ribbon_depth = WGetRibbonHeight();
    } else {
        ribbon_depth = 0;
    }

    width  = prect->right - prect->left;
    height = prect->bottom - prect->top - ribbon_depth - WGetStatusDepth();

    /* change the size of the divider */
    win = GetDlgItem ( einfo->edit_dlg, IDM_MENUEDBLACKLINE );
    GetWindowRect ( win, &crect );
    SetWindowPos ( win, (HWND) NULL, 0, 0, width,
                   crect.bottom - crect.top,
                   SWP_NOMOVE | SWP_NOZORDER );

    // change the size of the resource name edit field
    win = GetDlgItem( einfo->edit_dlg, IDM_MENUEDRNAME );
    WExpandEditWindowItem( einfo->edit_dlg, win, prect );

    // change the size of the listbox
    win = GetDlgItem( einfo->edit_dlg, IDM_MENUEDLIST );
    WExpandEditWindowItem( einfo->edit_dlg, win, prect );

    SetWindowPos ( einfo->edit_dlg, (HWND)NULL, 0, ribbon_depth,
                   width, height, SWP_NOZORDER );

    // change the size of the preview window
    WExpandEditWindowItem( einfo->edit_dlg, einfo->preview_window, prect );

    return ( TRUE );
}

void WExpandEditWindowItem( HWND hDlg, HWND win, RECT *prect )
{
    RECT  crect, t;

    if( win == (HWND)NULL ) {
        return;
    }

    /* expand the child window */
    GetWindowRect ( win, &crect );
    MapWindowPoints ( (HWND)NULL, hDlg, (POINT *)&crect, 2 );
    t.left   = 0;
    t.top    = 0;
    t.right  = 0;
    t.bottom = WEDIT_PAD;
    MapDialogRect ( hDlg, &t );
    SetWindowPos ( win, (HWND) NULL, 0, 0,
                   prect->right - crect.left - t.bottom,
                   crect.bottom - crect.top,
                   SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
    InvalidateRect ( win, NULL, TRUE );

}

void WSetEditWindowControls( WMenuEditInfo *einfo, WMenuEntry *entry )
{
    Bool        enable;

    // can this entry be reset or changed
    enable = ( entry != NULL );
    EnableWindow( GetDlgItem( einfo->edit_dlg, IDM_MENUEDRESET ), enable );
    EnableWindow( GetDlgItem( einfo->edit_dlg, IDM_MENUEDCHANGE ), enable );

    // can this entry be shifted left
    enable = ( entry && ( entry->parent != NULL ) && !entry->next );
    EnableWindow( GetDlgItem( einfo->edit_dlg, IDM_MENUEDSHIFTLEFT ), enable );

    // can this entry be shifted right
    enable = ( entry && entry->prev && entry->prev->item->IsPopup );
    EnableWindow( GetDlgItem( einfo->edit_dlg, IDM_MENUEDSHIFTRIGHT ), enable );

    return;
}

Bool WSetEditWindowMenuEntry ( WMenuEditInfo *einfo, WMenuEntry *entry )
{
    Bool        ok;
    Bool        pop_sep;
    MenuFlags   flags;
    uint_16     id;
    char        *text;

    ok = ( einfo && einfo->edit_dlg && entry );

    if( ok ) {
        if( entry->item->IsPopup ) {
            flags = entry->item->Item.Popup.ItemFlags;
            text  = entry->item->Item.Popup.ItemText;
        } else {
            flags = entry->item->Item.Normal.ItemFlags;
            id    = entry->item->Item.Normal.ItemID;
            text  = entry->item->Item.Normal.ItemText;
        }
        ok = WSetEditWindowText ( einfo->edit_dlg, flags, text );
    }

    if ( ok ) {
        ok = WSetEditWindowFlags ( einfo->edit_dlg, flags, FALSE );
    }

    if ( ok ) {
        pop_sep = ( entry->item->IsPopup || ( flags & MENU_SEPARATOR ) );
        ok = WSetEditWindowID( einfo->edit_dlg, id, pop_sep, entry->symbol );
    }

    return ( ok );
}

static Bool WQueryNukePopup( WMenuEditInfo *einfo )
{
    int         ret;
    UINT        style;
    char        *title;
    char        *text;

    style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;
    title = WCreateEditTitle( einfo );
    text = WAllocRCString( W_QUERYNUKEPOPUP );

    ret = MessageBox( einfo->edit_dlg, text, title, style );

    if( text ) {
        WFreeRCString( text );
    }
    if( title ) {
        WMemFree( title );
    }

    if( ret == IDYES ) {
        return( TRUE );
    }

    return( FALSE );
}

Bool WGetEditWindowMenuEntry( WMenuEditInfo *einfo, WMenuEntry *entry,
                              Bool test_mod, Bool *reset )
{
    MenuFlags   flags;
    MenuFlags   iflags;
    uint_16     id;
    char        *text;
    char        *symbol;
    Bool        ok;

    flags = 0;
    id = 0;
    text = NULL;
    symbol = NULL;

    if( reset ) {
        *reset = FALSE;
    }

    ok = ( einfo && einfo->edit_dlg && entry );

    if( ok ) {
        ok = WGetEditWindowFlags( einfo->edit_dlg, &flags );
    }

    if ( ok ) {
        if( !( flags & MENU_SEPARATOR ) ) {
            ok = WGetEditWindowText ( einfo->edit_dlg, &text );
        }
    }

    if( ok ) {
        if( !( flags & MENU_POPUP ) ) {
            ok = WGetEditWindowID( einfo->edit_dlg, &symbol, &id,
                                   einfo->info->symbol_table,
                                   einfo->combo_change );
        }
    }

    /* check if anything was actually modified */
    if ( ok ) {
        // make sure the symbol info did not change
        ok = ( !entry->symbol && symbol ) || ( entry->symbol && !symbol );
        if( !ok ) {
            ok = symbol && stricmp( entry->symbol, symbol );
            if( !ok ) {
                iflags = entry->item->Item.Popup.ItemFlags;
                iflags &= ~MENU_ENDMENU;
                ok = ( iflags != flags );
                if( !ok ) {
                    if( flags & MENU_POPUP ) {
                        ok = strcmp( entry->item->Item.Popup.ItemText, text );
                    } else if( flags & MENU_SEPARATOR ) {
                        ok = FALSE;
                    } else {
                        ok = ( entry->item->Item.Normal.ItemID != id ) ||
                               strcmp( entry->item->Item.Normal.ItemText, text );
                    }
                }
            }
        }
        if( test_mod ) {
            return( ok );
        }
    }

    if( ok ) {
        if( entry->item->IsPopup ) {
            if( entry->child && ( (flags & MENU_POPUP) == 0 ) ) {
                ok = WQueryNukePopup( einfo );
            }
        }
    }

    if( ok ) {
        if( entry->item->IsPopup ) {
            if( (flags & MENU_POPUP) == 0 ) {
                if( reset ) {
                    *reset = TRUE;
                }
                entry->preview_popup = (HMENU)NULL;
                if( entry->child ) {
                    WFreeMenuEntries( entry->child );
                    entry->child = NULL;
                }
            }
            if( entry->item->Item.Popup.ItemText ) {
                WMemFree( entry->item->Item.Popup.ItemText );
            }
        } else {
            // if the item is being changed from a normal item into a popup
            // or separator then reset the preview
            if( ( (flags & MENU_POPUP) != 0 ) ||
                ( (flags & MENU_SEPARATOR) != 0 ) ) {
                if( reset ) {
                    *reset = TRUE;
                }
                entry->preview_popup = (HMENU)NULL;
            }
            if( entry->item->Item.Normal.ItemText ) {
                WMemFree( entry->item->Item.Normal.ItemText );
            }
        }
        if( entry->symbol ) {
            WMemFree( entry->symbol );
        }
        entry->item->IsPopup = ( (flags & MENU_POPUP) != 0 );
        if( entry->item->IsPopup ) {
            entry->item->Item.Popup.ItemText = text;
            entry->item->Item.Popup.ItemFlags = flags;

⌨️ 快捷键说明

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