Ejemplo n.º 1
0
/******************************************************************************
 *  void OnNewWindow(HWND hwnd)
 * 
 *  Window/New Window menu item selected
 *
 *  parameters:
 *      hwnd - window handle of active child window or NULL if none active
 ******************************************************************************/
static void OnNewWindow(HWND hwnd)
{                
    char sz[_MAX_PATH + 1];
    MDICREATESTRUCT mcs;
    CHILDINSTANCEDATA PICFAR* pInstance = ChildGetInstanceData(hwnd);
    CHILDINSTANCEDATA PICFAR* pNew;

    if ( pInstance == 0 )
        return; /* Window/New Window should have been grayed */

    pNew = (CHILDINSTANCEDATA PICFAR*)MiscGlobalAllocPtr(
        sizeof(*pNew) + lstrlen(pInstance->pszFilename) + 1, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
    if ( pNew == 0 )
        return;
        
    *pNew = *pInstance; /* this has the effect of duplicating the modified state
                            of the window as well as of duplicating the src picparm
                            Duplicating the src picparm this way works only because
                            we don't allocate comments, appfields, etc in the 
                            pegasusquery picparm, so it's self-contained */
    pNew->pszFilename  = (LPSTR)pNew + sizeof(*pNew);
    lstrcpy(pNew->pszFilename, pInstance->pszFilename);                            
    pNew->xWindowOrg   = 0;     /* not scrolled to start out */
    pNew->yWindowOrg   = 0;    
    pNew->bRButtonDown = FALSE;             /* should be FALSE anyway */
    assert(!pInstance->bRButtonDown);
    pNew->bLButtonDown = FALSE;             /* should be FALSE anyway */
    assert(!pInstance->bLButtonDown);
    pNew->bDisableSetScrollRanges = FALSE;  /* should be FALSE anyway */
    assert(!pInstance->bDisableSetScrollRanges);
    pNew->hPalette     = NULL;  /* this window will need its own hpalette */
    pNew->nWaitCursor  = 0;
    assert(pInstance->nWaitCursor == 0);

    /* duplicate the source image */
    pNew->pSrc = MiscGlobalAllocPtr(pNew->dwSrcLen, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
    if ( pNew->pSrc == 0 )
        {
        MiscGlobalFreePtr(&pInstance);
        return;
        }
    hmemcpy(pNew->pSrc, pInstance->pSrc, pNew->dwSrcLen);

    /* duplicate the dib unless it's a pointer into the source image */
    if ( pInstance->pDib < pInstance->pSrc ||
         pInstance->pDib >= pInstance->pSrc + pInstance->dwSrcLen )
        {
        pNew->pDib = MiscGlobalAllocPtr(pNew->dwDibLen, IDS_NEWWINDOWOUTOFMEMORY);
            /* "There was not enough memory to create the new window." */
        if ( pNew->pDib == 0 )
            {
            MiscGlobalFreePtr(&pNew->pSrc);
            MiscGlobalFreePtr(&pInstance);
            return;
            }
        hmemcpy(pNew->pDib, pInstance->pDib, pNew->dwDibLen);
        }
    else
        pNew->pDib = pNew->pSrc + ( pInstance->pDib - pInstance->pSrc );

    /* duplicate the dib picparm - through the opcode because there may be comments
        or appfields or overtext or some such which need to be separately allocated,
        and which only the opcode knows enough to allocate
        if not implemented, then old is copied over new above when old instance is
        copied to new instance */
    if ( pNew->pOpenOp->pfnDupPicParm != 0 &&
         !(*pNew->pOpenOp->pfnDupPicParm)(&pInstance->DibPicParm, &pNew->DibPicParm) )
        {
        (*pNew->pOpenOp->pfnCleanup)(pNew->pDib, 0, 0);
        MiscGlobalFreePtr(&pNew->pSrc);
        MiscGlobalFreePtr(&pInstance);
        ErrorMessage(STYLE_ERROR, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
        return;
        }

    /* duplicate image options settings */
    if ( !CtrlDataDup(
            (LPCTRLINITDATA)pInstance->pOpenData,
            (LPCTRLINITDATA PICFAR *)&pNew->pOpenData) )
        {
        (*pNew->pOpenOp->pfnCleanup)(pNew->pDib, &pInstance->DibPicParm, 0);
        MiscGlobalFreePtr(&pNew->pSrc);
        MiscGlobalFreePtr(&pInstance);
        ErrorMessage(STYLE_ERROR, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
        return;
        }

    /* Create MDI child window */
    GetWindowText(hwnd, sz, sizeof(sz));
    mcs.szClass    = MDICHILD_CLASSNAME;
    mcs.szTitle    = pInstance->pszFilename;
    mcs.hOwner     = hinstThis;
    mcs.x          = CW_USEDEFAULT;
    mcs.y          = CW_USEDEFAULT;
    mcs.cx         = CW_USEDEFAULT;
    mcs.cy         = CW_USEDEFAULT;
    mcs.style      = WS_HSCROLL | WS_VSCROLL;
    mcs.lParam     = (LPARAM)pNew;
    if ( ChildGetActive() != NULL && IsZoomed(ChildGetActive()) )
        mcs.style |= WS_MAXIMIZE;
    // tell the MDI Client to create the child 
    LockWindowUpdate(hwndMDIClient);
    hwnd = FORWARD_WM_MDICREATE(hwndMDIClient, (LPMDICREATESTRUCT)&mcs, SendMessage);
    if ( hwnd == NULL )
        {
        LockWindowUpdate(NULL);
        (*pNew->pOpenOp->pfnCleanup)(pNew->pDib, &pInstance->DibPicParm, pNew->pOpenData);
        MiscGlobalFreePtr(&pNew->pSrc);
        MiscGlobalFreePtr(&pInstance);
        ErrorMessage(STYLE_ERROR, IDS_NEWWINDOWCREATE);
        /* "An unexpected error occurred creating the new window." */
        return;
        }
    ShowWindow(hwnd, SW_HIDE);
    LockWindowUpdate(NULL);
    UpdateWindow(hwndMDIClient);

    /* make sure the window isn't bigger than the image */
    ChildSetWindowSize(hwnd);
}
Ejemplo n.º 2
0
/******************************************************************************
 *  void MenuStatus(HMENU hmenu, HWND hwnd)
 * 
 *  enable/gray all menu items
 *
 *  parameters:
 *      hmenu - menu containing the Transform popup (could be frame menu or popup)
 *      hwnd  - active child window or NULL
 *
 *  notes:
 *      some menu items are always enabled and this code doesn't look at them
 *      file/close, file/properties and window menu items are grayed unless there
 *      is an active child.  Others are enabled/grayed by calling MenuStatusFileSave,
 *      MenuStatusFileSaveAs, MenuStatusFileImageOptions or MenuStatusTransform
 *
 *      The only tricky part is to make sure it's the menu bar instead of the
 *      popup as all the popup menu item positions are different.  The popup doesn't
 *      change during its lifetime so we don't have to evaluate it here --
 *      it's evaluated once when its created.  But the various position #define's
 *      (FILE_MENU_POS) have counterparts on the popup which we don't want to confuse.
 *      So we make sure that the hmenu received is from the menu bar.  However, if
 *      the child window is maximized windows adds a system popup menu to the menu
 *      bar in position 0 and slides everything else down.  So we look at the menu
 *      bar popup at position 1.  If it's the "&File" menu, then we know the child
 *      has been maximized and adjust the position we've received so we can use our
 *      same #define's for menu bar pulldown menu positions
 ******************************************************************************/
void MenuStatus(int nPos, HMENU hmenu)
{
    char sz[sizeof("&File") + 1];   /* + 1 to get the next char if menu string is longer
                                        since note that sizeof includes the null terminator */
    HWND hwnd = ChildGetActive();
    CHILDINSTANCEDATA PICFAR* pInstance = ChildGetInstanceData(hwnd);
    UINT flags = MF_BYCOMMAND;

    if ( pInstance == 0 || pInstance->nWaitCursor != 0 )
        hwnd = NULL;

    if ( hwnd != NULL )
        flags = MF_ENABLED;
    else
        flags = MF_GRAYED;
        
    if ( hmenu == GetSubMenu(GetMenu(hwndFrame), nPos) )
        {
        /* now we know its a menubar menu
            if the MDI child menu is maximized, then the MDI child system menu is
            added to the frame menu bar in position 0, sliding everything else down
            and throwing off our position #define's by 1 */
        GetMenuString(GetMenu(hwndFrame), 1, sz, sizeof(sz), MF_BYPOSITION);
        if ( stricmp(sz, "&File") == 0 )
            {
            /* child whildow is maximized */
            if ( nPos == 0 )
                return; /* initmenu for maximized child system menu is ignored */
            nPos--;     /* adjust so our #define's (FILE_MENU_POS, etc.) can be used */
            }
        switch ( nPos )
            {
            case FILE_MENU_POS:
                EnableMenuItem(hmenu, IDM_FILE_CLOSE,      flags);
                EnableMenuItem(hmenu, IDM_FILE_PROPERTIES, flags);
                MenuStatusFileSave(hmenu, hwnd);
                MenuStatusFileSaveAs(hmenu, hwnd);
                MenuStatusImageOptions(hmenu, hwnd);
                break;

            case TRANSFORM_MENU_POS:
                MenuStatusTransform(hmenu, hwnd);
                break;

            case TOOLS_MENU_POS:
                break;

            case WINDOW_MENU_POS:
                EnableMenuItem(hmenu, IDM_WINDOW_NEWWINDOW,      flags);
                EnableMenuItem(hmenu, IDM_WINDOW_CLOSEALL,       flags);
                EnableMenuItem(hmenu, IDM_WINDOW_CASCADE,        flags);
                EnableMenuItem(hmenu, IDM_WINDOW_TILEHORIZONTAL, flags);
                EnableMenuItem(hmenu, IDM_WINDOW_TILEVERTICAL,   flags);
                EnableMenuItem(hmenu, IDM_WINDOW_ARRANGEICONS,   flags);
                break;

            case HELP_MENU_POS:
                break;

            default:
                assert(FALSE);
                break;
            }
        }
}
Ejemplo n.º 3
0
/******************************************************************************
 *  void MenuOnCommand(HMENU hmenu, HWND hwnd)
 * 
 *  frame window WM_COMMAND handler
 *
 *  parameters:
 *      wCmd - menu item id (WM_COMMAND wParam)
 *
 *  returns:
 *      TRUE if the menu item id is recognized
 *
 *  notes:
 *      The following code needs to change if there are more than 10 mru files
 *      more than 100 default options, more than 100 tools or more than 100 transforms
 ******************************************************************************/
BOOL MenuOnCommand(WPARAM wCmd)
{
    HWND hwnd = ChildGetActive();
    CHILDINSTANCEDATA PICFAR* pInstance = ChildGetInstanceData(hwnd);

    if ( pInstance == 0 || pInstance->nWaitCursor != 0 )
        hwnd = NULL;
    
    switch ( wCmd )
        {
        case IDM_FILE_OPEN:
            OpenOnFileOpen();
            break;
        case IDM_FILE_CLOSE:
            OnFileClose(hwnd);
            break;
        case IDM_FILE_SAVE:
            SaveOnFileSave(hwnd);
            break;
        case IDM_FILE_SAVEAS:
            SaveOnFileSaveAs(hwnd);
            break;
        case IDM_FILE_PROPERTIES:
            OnFileProperties(hwnd);
            break;
        case IDM_FILE_IMAGEOPTIONS:
            OnFileImageOptions(hwnd);
            break;
        case IDM_FILE_EXIT:
            SendMessage(hwndFrame, WM_CLOSE, 0, 0);
            break;
        case IDM_FILE_MRUFILE1:
        case IDM_FILE_MRUFILE2:
        case IDM_FILE_MRUFILE3:
        case IDM_FILE_MRUFILE4:
        case IDM_FILE_MRUFILE5:
        case IDM_FILE_MRUFILE6:
        case IDM_FILE_MRUFILE7:
        case IDM_FILE_MRUFILE8:
        case IDM_FILE_MRUFILE9:
            OpenOnFileMruOpen(wCmd - IDM_FILE_MRUFILE1 + 1);
            break;
        
        case IDM_WINDOW_NEWWINDOW:
            OnNewWindow(hwnd);
            break;
        case IDM_WINDOW_CASCADE:
            SendMessage(hwndMDIClient, WM_MDICASCADE, 0, 0);
            break;
        case IDM_WINDOW_TILEHORIZONTAL:
            SendMessage(hwndMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
            break;
        case IDM_WINDOW_TILEVERTICAL:
            SendMessage(hwndMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0);
            break;
        case IDM_WINDOW_ARRANGEICONS:
            SendMessage(hwndMDIClient, WM_MDIICONARRANGE, 0, 0);
            break;
        case IDM_WINDOW_CLOSEALL:
            OnWindowCloseAll();
            break;

        case IDM_HELP_CONTENTS:
            WinHelp(hwndFrame, APPLICATION_HELPFILENAME, HELP_CONTENTS, 0);
            break;

        case IDM_HELP_ABOUT:
            AboutOnHelpAbout();
            break;

        default:
            if ( wCmd >= IDM_FILE_DEFAULTOPTIONS && wCmd < IDM_FILE_DEFAULTOPTIONS + 100 )
                OnFileDefaultOptions(wCmd);
            else if ( wCmd >= IDM_TRANSFORM && wCmd < IDM_TRANSFORM + 100 )
                OnTransform(hwnd, wCmd);
            else if ( wCmd >= IDM_TOOLS && wCmd < IDM_TOOLS + 100 )
                OnTools(wCmd);
            else
                return ( FALSE );
        }
    return ( TRUE );
}
Ejemplo n.º 4
0
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    CLIENTCREATESTRUCT ccs;
    HWND hwndChild = 0;
    
    if ( IsWindow(hwndMDIClient) )
        hwndChild = ChildGetActive();

    switch ( uMsg )
        {
        case WM_CREATE:
            /* following is regular MDI incantation */
            ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), WINDOW_MENU_POS);
            ccs.idFirstChild = IDM_WINDOW_CHILDREN;
            hwndMDIClient = CreateWindow(
                "mdiclient",
                NULL,
                WS_CHILD | WS_CLIPCHILDREN,
                0,
                0,
                0,
                0,
                hWnd,
                0,
                hinstThis,
                &ccs);
            if ( hwndMDIClient != 0 )
                {
                ShowWindow(hwndMDIClient, SW_SHOW);
                /* subclass the hwndMDIClient window so we can change the cursor
                    to a wait cursor when desired */
                pfnOldMDIClientWndProc =
                    (WNDPROC)SetWindowLong(hwndMDIClient, GWL_WNDPROC, (LONG)MDIClientWndProc);
                }
            return ( 0 );
        
        case WM_INITMENUPOPUP:
            /* some popup menu is about to be displayed */
            MenuStatus((int)LOWORD(lParam), (HMENU)wParam);
            return ( 0 );
        
        case WM_COMMAND:
            /* if WM_COMMAND is not from a control (then it's from a menu item) */
            if ( LOWORD(lParam) == 0 && MenuOnCommand(LOWORD(wParam)) )
                return ( 0 );
            break;

        case WM_QUERYENDSESSION:
            return ( ChildQueryCloseAll() );

        case WM_CLOSE:
            if ( !ChildQueryCloseAll() )
                return ( 0 );
            break;                
            
        case WM_DESTROY:
            WinHelp(hwndFrame, APPLICATION_HELPFILENAME, HELP_QUIT, 0);
            PostQuitMessage(0);
            return ( 0 );

        case WM_QUERYNEWPALETTE:
            /* set the system palette to the active child's palette */
            return ( OnQueryNewPalette(hwndChild) );

        case WM_MDIACTIVATE:
            /* set the system palette to the newly active child's palette */
            OnQueryNewPalette((HWND)wParam);
            return ( 0 );

        case WM_PALETTECHANGED:
            /* forwarded to children so they can each realize their background palettes */
            ForwardToChildren(hWnd, uMsg, wParam, lParam);
            return ( 0 );

        case WM_SYSCOLORCHANGE:
            Ctl3dColorChange();
            break;

        case WM_SYSCOMMAND:
            switch ( wParam & 0xfff0 )
                {
                case SC_MAXIMIZE:
                case SC_RESTORE:
                    /* since we effectively change our image origin when maximized or restored,
                        we have to _force_ the window repaint to include the entire window --
                        else win '95 (at least) optimizes away some of the regions */
                    DefFrameProc(hWnd, hwndMDIClient, uMsg, wParam, lParam);
                    if ( IsWindow(hwndChild) )
                        {
                        InvalidateRect(hwndChild, NULL, FALSE);
                        UpdateWindow(hwndChild);
                        }
                    return ( 0 );
                
                default:
                    break;                    
                }
            break;
            
        case WM_MOUSEMOVE:
            if ( nWaitCursor != 0 )
                SetCursor(hWaitCursor);
            else
                SetCursor(hArrowCursor);                
            break;
        
        default:
            break;
        }
    if ( !IsWindow(hwndMDIClient) )
        return ( DefFrameProc(hWnd, 0, uMsg, wParam, lParam) );
    return ( DefFrameProc(hWnd, hwndMDIClient, uMsg, wParam, lParam) );
}