/****************************Module*Header******************************\ * Copyright (c) 1987 - 1991 Microsoft Corporation * \***********************************************************************/ /******************************************************** * * * file: ParentWP.c * * system: PC Paintbrush for MS-Windows * * descr: window proc for parent window * * date: 03/18/87 @ 11:00 * * * ********************************************************/ #include #include "port1632.h" #include "shellapi.h" #ifdef DBCS_IME #include #endif //#define NOEXTERN #include "pbrush.h" #include "pbserver.h" /* OLE server functions and variables */ #ifdef DBCS_IME #include #endif int UpdateCount = 0; #ifdef DBCS_IME /* IME can only be used when user selects text function */ BOOL bInitialIMEState; BOOL bGetIMEState = FALSE; // 02/12/93 raid #3725 #endif extern HWND pbrushWnd[]; extern int defaultWid, defaultHgt; extern BOOL drawing; extern HWND zoomOutWnd; extern RECT pbrushRct[]; extern BOOL inMagnify, mouseFlag, bZoomedOut; extern BOOL imageFlag; extern TCHAR fileName[]; extern TCHAR noFile[]; extern int theTool, theSize, theForeg; extern BOOL bIsPrinterDefault; extern TCHAR deviceStr[]; extern HPALETTE hPalette; extern BOOL bJustActivated; extern int theBackg; extern DWORD *rgbColor; extern int SizeTable[]; extern int YPosTable[]; extern HWND mouseWnd; extern BOOL TerminateKill; extern BOOL IsCanceled; extern WNDPROC lpMouseDlg, lpColorDlg, lpNullWP; extern BOOL bPrtCreateErr; extern PRINTDLG PD; #define SIZE_FUDGE 7 void FileDragOpen( TCHAR szPath[]); void doDrop( HANDLE wParam, HWND hwnd); long FAR PASCAL ParentWP(HWND hWnd, UINT message, WPARAM wParam, LONG lParam) { static int Thing; static int RepeatCount = 0; static long lastMsgTime = 0; static WORD lastMsgWParam = 0; static BOOL processCntrlI = TRUE; static BOOL printerChanged = FALSE; static int CurrentWindow = PAINTid; HWND theWnd; WORD shiftStates; long lResult; int i, command, answer; HMENU hMenu; HDC hdcPrint, parentDC; HCURSOR oldcsr; RECT trect, trect1; POINT tpoint, cursDiff; int x, y; DWORD dwMsgPos; HPALETTE hOldPalette = NULL; BOOL bButtonDown; WORD scrollAmount; switch (message) { case WM_ERRORMSG: SimpleMessage((WORD)wParam, (LPTSTR)lParam, MB_OK | MB_ICONEXCLAMATION); break; /* create and initialize the image and file buffers */ case WM_ACTIVATE: if((GET_WM_ACTIVATE_STATE(wParam,lParam) == 0) && TerminateKill) { DB_OUTF((acDbgBfr,TEXT("wParam = %lx, lParam = %ld WM_ACTIVATE in parentwp\n"), wParam,lParam)); SendMessage(pbrushWnd[PAINTid], WM_TERMINATE, 0, 0L); } else if(GET_WM_ACTIVATE_STATE(wParam,lParam) == 2 && !IsIconic(hWnd)) { GetWindowRect(pbrushWnd[PAINTid], &trect); dwMsgPos = GetMessagePos(); LONG2POINT(dwMsgPos,tpoint); bJustActivated = PtInRect(&trect, tpoint); } lResult = DefWindowProc(hWnd,message,wParam,lParam); if(printerChanged) { PostMessage(pbrushWnd[PARENTid], WM_ERRORMSG, IDSPrinterChange, 0L); printerChanged = FALSE; } return(lResult); break; case WM_CREATE: defaultWid = GetSystemMetrics(SM_CXSCREEN); defaultHgt = GetSystemMetrics(SM_CYSCREEN); break; #ifdef DBCS_IME // control IME status when focus messages are received case WM_SETFOCUS: bInitialIMEState = WINNLSEnableIME(NULL,FALSE); // KKBUGFIX //02/12/93 raid #3725 bGetIMEState = TRUE; break; case WM_KILLFOCUS: // KKBUGFIX //02/12/93 raid #3725 if(bGetIMEState) { WINNLSEnableIME(NULL,bInitialIMEState); bGetIMEState = FALSE; } break; #endif case WM_SYSCOMMAND: if(drawing) break; oldcsr = SetCursor(LoadCursor(NULL, IDC_WAIT)); command = wParam & 0xFFF0; if(!inMagnify && command != SC_MOUSEMENU && command != SC_KEYMENU) { SendMessage(pbrushWnd[PAINTid], WM_TERMINATE, 0, 0L); UpdatImg(); } else if(inMagnify && (command == SC_ICON || command == SC_CLOSE)) { SendMessage(pbrushWnd[PAINTid], WM_ZOOMACCEPT, 0, 0L); SendMessage(pbrushWnd[PAINTid], WM_TERMINATE, 0, 0L); UpdatImg(); } else if(bZoomedOut || (inMagnify && command != SC_MOUSEMENU && command != SC_KEYMENU)) SendMessage(pbrushWnd[PAINTid], WM_SCROLLINIT, 0, 0L); else if(command == SC_MOUSEMENU || command == SC_KEYMENU) SendMessage(pbrushWnd[PAINTid], WM_HIDECURSOR, 0, 0L); SetCursor(oldcsr); return(DefWindowProc(hWnd,message,wParam,lParam)); break; /* enable paste item if bitmap in clipboard */ case WM_INITMENU: SendMessage(pbrushWnd[PAINTid], WM_HIDECURSOR, 0, 0l); hMenu = GetMenu(hWnd); EnableMenuItem(hMenu, EDITpaste, (!inMagnify && (IsClipboardFormatAvailable(CF_BITMAP) || IsClipboardFormatAvailable(CF_DIB) || IsClipboardFormatAvailable(CF_METAFILEPICT) || IsClipboardFormatAvailable(CF_TEXT))) ? MF_ENABLED : MF_GRAYED); CheckMenuItem(hMenu, MISCOmitPictureFormat, (MF_BYCOMMAND | (fOmitPictureFormat ? MF_CHECKED : MF_UNCHECKED))); if(bPrtCreateErr) { bPrtCreateErr = FALSE; GetPrintParms(NULL); } EnableMenuItem(hMenu, FILEprint, bPrtCreateErr? MF_GRAYED : MF_ENABLED); // if (!fOLE) { // EnableMenuItem(hMenu, EDITcutpict, MF_GRAYED); // EnableMenuItem(hMenu, EDITcopypict, MF_GRAYED); // } break; case WM_COMMAND: if(pbrushWnd[PARENTid] && (GET_WM_COMMAND_ID(wParam,lParam)!=STYLEitalic || processCntrlI)) MenuCmd(hWnd,GET_WM_COMMAND_ID(wParam,lParam)); break; case WM_DESTROY: #ifdef DBCS_IME /* backup IME status before we gone */ // KKBUGFIX //02/12/93 raid #3725 if(bGetIMEState) { WINNLSEnableIME(NULL, bInitialIMEState); bGetIMEState = FALSE; } #endif /* delete allocated image and file buffer memory */ FreeImg(); // TerminateShapeLibrary(); Help(hWnd, HELP_QUIT, 0L); if (lpMouseDlg) FreeProcInstance(lpMouseDlg); if (lpColorDlg) FreeProcInstance(lpColorDlg); if (lpNullWP) FreeProcInstance(lpNullWP); if(hPalette) DeleteObject(hPalette); hPalette = NULL; pbrushWnd[PARENTid] = NULL; /* signal parent window invalid */ PostQuitMessage(0); break; case WM_MOVE: /* if(bZoomedOut) { MoveWindow(zoomOutWnd, pbrushRct[PAINTid].left, pbrushRct[PAINTid].top, pbrushRct[PAINTid].right - pbrushRct[PAINTid].left, pbrushRct[PAINTid].bottom - pbrushRct[PAINTid].top, TRUE); GetWindowRect(pbrushWnd[PAINTid], &trect); MoveWindow(zoomOutWnd, trect.left, trect.top, trect.right - trect.left, trect.bottom - trect.top, TRUE); } */ /* reposition the mouse window */ if(mouseFlag) { GetWindowRect(mouseWnd, &trect); GetWindowRect(pbrushWnd[PARENTid], &trect1); MoveWindow(mouseWnd, trect1.right - 2 * GetSystemMetrics(SM_CXSIZE) - GetSystemMetrics(SM_CXFRAME) - (trect.right - trect.left) - 8, trect1.top + GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYBORDER), trect.right - trect.left, trect.bottom - trect.top, TRUE); } return(DefWindowProc(hWnd,message,wParam,lParam)); break; case WM_SIZE: oldcsr = SetCursor(LoadCursor(NULL, IDC_WAIT)); if(wParam != SIZEICONIC) { pbrushRct[PARENTid].right = LOWORD(lParam); pbrushRct[PARENTid].bottom = HIWORD(lParam); if(pbrushWnd[PAINTid] && IsWindow(pbrushWnd[PAINTid])) { CalcWnds(NOCHANGEWINDOW, NOCHANGEWINDOW, NOCHANGEWINDOW, NOCHANGEWINDOW); for(i=1; i 0) --Thing; goto MoveToolCurs; case PAINTid: cursDiff.x = -RepeatCount; cursDiff.y = 0; goto MovePaintCurs; case SIZEid: goto MoveSizeCurs; case COLORid: if(Thing > 1) Thing -= 2; goto MoveColorCurs; } } break; case VK_UP: RepeatCount++; if(!bButtonDown && (GetKeyState(VK_SHIFT)&0x8000)) PostMessage(pbrushWnd[PAINTid], WM_VSCROLL, SB_LINEUP, 0l); else { switch (CurrentWindow) { case TOOLid: if(Thing > 1) Thing -= 2; goto MoveToolCurs; case PAINTid: cursDiff.x = 0; cursDiff.y = -RepeatCount; goto MovePaintCurs; case SIZEid: if(Thing > 0) --Thing; goto MoveSizeCurs; case COLORid: if(Thing > 0) --Thing; goto MoveColorCurs; } } break; case VK_DOWN: RepeatCount++; if(!bButtonDown && (GetKeyState(VK_SHIFT)&0x8000)) PostMessage(pbrushWnd[PAINTid], WM_VSCROLL, SB_LINEDOWN, 0l); else { switch (CurrentWindow) { case TOOLid: if(Thing < MAXtools-2) Thing += 2; goto MoveToolCurs; case PAINTid: cursDiff.x = 0; cursDiff.y = RepeatCount; goto MovePaintCurs; case SIZEid: if(Thing < NUM_SIZES-1) ++Thing; goto MoveSizeCurs; case COLORid: if(Thing < MAXcolors-1) ++Thing; goto MoveColorCurs; } } break; case VK_TAB: processCntrlI = FALSE; dwMsgPos = GetMessagePos(); LONG2POINT(dwMsgPos,tpoint); SendMessage(theWnd, WM_LBUTTONUP, shiftStates, MAKELONG((tpoint.x - trect1.left) - GetSystemMetrics(SM_CXBORDER), (tpoint.y - trect1.top) - GetSystemMetrics(SM_CYBORDER))); do { if(!(GetKeyState(VK_SHIFT) & 0x8000)) CurrentWindow = CurrentWindow % 4 + 1; else CurrentWindow = (CurrentWindow + 2) % 4 + 1; if(bZoomedOut && CurrentWindow == PAINTid) theWnd = zoomOutWnd; else theWnd = pbrushWnd[CurrentWindow]; } while (!IsWindowVisible(theWnd)); GetWindowRect(theWnd, &trect1); GetClientRect(theWnd, &trect); switch (CurrentWindow) { case TOOLid: Thing = theTool; goto MoveToolCurs; case PAINTid: cursDiff.x = cursDiff.y = 0; goto MovePaintCurs; case SIZEid: for(Thing=0; SizeTable[Thing]> 1) * 2 + 1)) / MAXtools; goto MoveMiscCurs; MoveSizeCurs: x = trect.right /2; y = (int)((long)(YPosTable[Thing] + SizeTable[Thing]/2) * (trect.bottom - trect.top) / SIZE_EXTY); goto MoveMiscCurs; MoveColorCurs: x = ((((Thing >> 1) << 1) + 5) * (trect.right/ COLORdiv)) / 2; y = (((Thing % 2) * 2 + 1) * trect.bottom) / 4 ; goto MoveMiscCurs; MoveMiscCurs: SetCursorPos(trect1.left + GetSystemMetrics(SM_CXBORDER) + x, trect1.top + GetSystemMetrics(SM_CYBORDER) + y); break; MovePaintCurs: ClientToScreen(theWnd, ((LPPOINT)&trect) ); ClientToScreen(theWnd, ((LPPOINT)&trect) + 1); GetCursorPos(&tpoint); tpoint.x += cursDiff.x; tpoint.y += cursDiff.y; tpoint.x = min(max(tpoint.x, trect.left), trect.right - 1); tpoint.y = min(max(tpoint.y, trect.top ), trect.bottom - 1); SetCursorPos(tpoint.x, tpoint.y); break; default: break; } break; #ifdef KOREA case WM_INTERIM: #endif case WM_CHAR: SendMessage(pbrushWnd[PAINTid], message, wParam, lParam); break; #ifdef JAPAN // added by Hiraisi case WM_IME_REPORT: return( SendMessage(pbrushWnd[PAINTid], message, wParam, lParam) ); break; #endif case WM_WININICHANGE: case PBM_INITFONTPRINT: oldcsr = SetCursor(LoadCursor(NULL, IDC_WAIT)); if (message != PBM_INITFONTPRINT) { if(!bIsPrinterDefault) if(!(hdcPrint = GetPrtDC())) { bIsPrinterDefault = TRUE; printerChanged = TRUE; hWnd = GetActiveWindow(); for(i=1; i