/****************************************************************************** TerSetFrameMarginDist: Set the minimum distance from margin for the frame at which the text starts wrapping around the frame. ******************************************************************************/ BOOL WINAPI _export TerSetFrameMarginDist(HWND hWnd, int dist) { PTERWND w; if (NULL==(w=GetWindowPointer(hWnd))) return FALSE; // get the pointer to window data FrameDistFromMargin=dist; return TRUE; }
/*************************************************************************** TerGetReviewerInfo: Get reviewer info. ****************************************************************************/ BOOL WINAPI _export TerGetReviewerInfo(HWND hWnd, int RevId, LPBYTE name) { PTERWND w; if (NULL==(w=GetWindowPointer(hWnd))) return false; // get the pointer to window data if (RevId<=0 || RevId>=TotalReviewers) return false; if (name) strcpy(name,reviewer[RevId].name); return true; }
LRESULT CALLBACK CMainFrame::MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT lRes = 0; CMainFrame *pWnd = (CMainFrame *)GetWindowPointer(hWnd); switch (message) { case WM_CREATE: { CREATESTRUCT *pcs = (CREATESTRUCT *)lParam; lRes = pWnd->OnCreate(pcs); } break; case WM_COMMAND: lRes = pWnd->OnCommand(wParam, lParam); break; case WM_DESTROY: ::PostQuitMessage(0); break; case WM_NCDESTROY: { if (NULL != pWnd->m_pMDIControl) { lRes = pWnd->m_pMDIControl->DefaultMDIFrameHandler(message, wParam, lParam); } else { lRes = pWnd->DefaultWindowHandler(message, wParam, lParam); } (void)Detach(hWnd); delete pWnd; pWnd = NULL; } break; default: if (NULL != pWnd->m_pMDIControl) { lRes = pWnd->m_pMDIControl->DefaultMDIFrameHandler(message, wParam, lParam); } else { lRes = pWnd->DefaultWindowHandler(message, wParam, lParam); } break; } return lRes; }
/****************************************************************************** TerSetFrameTextDist: Set the minimum distance to maintain between text and the frame border. ******************************************************************************/ BOOL WINAPI _export TerSetFrameTextDist(HWND hWnd, int ParaFID,int dist) { PTERWND w; if (NULL==(w=GetWindowPointer(hWnd))) return FALSE; // get the pointer to window data if (ParaFID<=0) ParaFID=fid(CurLine); if (ParaFID<=0 || ParaFID>=TotalParaFrames || !ParaFrame[ParaFID].InUse) return false; ParaFrame[ParaFID].DistFromText=dist; RequestPagination(w,true); return TRUE; }
/****************************************************************************** TerFindNextChange: Find next change. ******************************************************************************/ BOOL WINAPI _export TerFindNextChange(HWND hWnd, BOOL forward, BOOL repaint) { PTERWND w; int CurCfmt; BOOL result=false; long line; int col; if (NULL==(w=GetWindowPointer(hWnd))) return false; // get the pointer to window data line=CurLine; col=CurCol; CurCfmt=GetCurCfmt(w,line,col); if (TerFont[CurCfmt].DelRev>0) { if (!TerLocateChangedChar(hTerWnd,-1,TerFont[CurCfmt].DelRev,false,&line,&col,forward)) goto END; } else if (TerFont[CurCfmt].InsRev>0) { if (!TerLocateChangedChar(hTerWnd,TerFont[CurCfmt].InsRev,0,false,&line,&col,forward)) goto END; } else if (TerFont[CurCfmt].FmtRev>0) { if (!TerLocateChangedChar2(hTerWnd,-1,-1,TerFont[CurCfmt].FmtRev,false,&line,&col,forward)) goto END; } result=TerLocateChangedChar2(hTerWnd,-1,-1,-1,true,&line,&col,forward); // find for the presense of any reviewer id type (ins, del or fmt types) if (result && !forward) GetChangeBeginPos(w,&line,&col); // position at the first character of the changed text END: if (result) { CurCol=col; if (repaint) TerPosLine(w,line+1); else CurLine=line; } else { if (repaint) MessageBox(hTerWnd,MsgString[MSG_NO_CHANGED_TEXT],"",MB_OK); } return result; }
LRESULT CALLBACK CFidgetApp::CBTProc ( int nCode, WPARAM wParam, LPARAM lParam ) { if ( HCBT_CREATEWND == nCode && NULL != g_theApp.m_pTemp) { HWND hwnd = (HWND)wParam; CWindow *pWnd = GetWindowPointer(hwnd); mux_assert(NULL == pWnd); if (NULL == pWnd) { Attach(hwnd, g_theApp.m_pTemp); g_theApp.m_pTemp = NULL; } } return CallNextHookEx(g_theApp.m_hhk, nCode, wParam, lParam); }
TerCPlusPlus::TerCPlusPlus(HWND hTerWindow) { w = GetWindowPointer(hTerWindow); m_hTerWnd = hTerWindow; }
LRESULT CALLBACK WindowsMessagePump(HWND aWindowHandle, UINT aMessage, WPARAM aWParam, LPARAM aLParam) { Window *window = GetWindowPointer(aWindowHandle); WindowData *windowData = window->mPlatformSpecificData.Get<WindowData>(); switch (aMessage) { // Window Creation case WM_CREATE: { // This aLParam is our Window pointer Window* windowToSet = (Window*)((CREATESTRUCT*)(aLParam))->lpCreateParams; WindowData *windowToSetData = windowToSet->mPlatformSpecificData.Get<WindowData>(); // Set it on the user data section of the window SetWindowPointer(aWindowHandle, windowToSet); windowToSetData->mWindowHandle = aWindowHandle; break; } case WM_MOUSEWHEEL: { window->mMouse.mWheelDelta = GET_WHEEL_DELTA_WPARAM(aWParam) / (float)WHEEL_DELTA; break; } case WM_LBUTTONUP: { // TODO: Change when we have events. Try to figure out how this should actually work. window->mEngine->mGraphicsSystem.mMousePosition.x = LOWORD(aLParam); window->mEngine->mGraphicsSystem.mMousePosition.y = HIWORD(aLParam); window->mMouse.mLeftMouseDown = false; break; } case WM_LBUTTONDOWN: { // TODO: Change when we have events. Try to figure out how this should actually work. window->mEngine->mGraphicsSystem.mMousePosition.x = LOWORD(aLParam); window->mEngine->mGraphicsSystem.mMousePosition.y = HIWORD(aLParam); window->mMouse.mLeftMouseDown = true; break; } case WM_MOUSEMOVE: { window->mMouse.mX = LOWORD(aLParam); window->mMouse.mY = HIWORD(aLParam); break; } // TODO: Add WM_TOUCH // TODO: Add these: // WM_LBUTTONDBLCLK // WM_RBUTTONDBLCLK // WM_MBUTTONDBLCLK // A key has been pressed. //case WM_KEYDOWN: //case WM_SYSKEYDOWN: //{ // window->mKeyboard.UpdateKey(aWParam, true); // break; //} // // // A key has been released. //case WM_KEYUP: //case WM_SYSKEYUP: //{ // window->mKeyboard.UpdateKey(aWParam, false); // break; //} case WM_PAINT: { // TODO: Send FrameUpdate here. // window->mEngine->mGraphicsSystem.Update(0.016f); break; } // Should probably make sure DefWindowProc doesn't get called here. Return? case WM_CLOSE: case WM_DESTROY: { // Only close if we're the most parented window. // TODO: Handle the case of having multiple "topmost" windows. if (window->mParentWindow == nullptr) { window->mEngine->mShouldUpdate = false; } break; } default: { break; } } // Probably want to only do this sometimes not every time we pump. return DefWindowProc(aWindowHandle, aMessage, aWParam, aLParam); }
/****************************************************************************** TerEnableTracking: Enable or disable tracking of text changes. This function returns the previous status. ******************************************************************************/ BOOL WINAPI _export TerEnableTracking(HWND hWnd, bool enable, LPBYTE UName, BOOL UseDefaultClrStyle, DWORD InsStyle, COLORREF InsColor, DWORD DelStyle, COLORREF DelColor) { BYTE name[UNLEN+1]; LPBYTE pName=null; int i,len; SYSTEMTIME SysTime; FILETIME FileTime; WORD DosDate,DosTime; bool NewUser=false; PTERWND w; if (NULL==(w=GetWindowPointer(hWnd))) return false; // get the pointer to window data if (!TerArg.WordWrap) return false; if (TrackChanges == enable) return true; // no status change requested TrackChanges=enable; if (enable) { if (UName && lstrlen(UName)>0) pName=UName; else { // get system user name len=UNLEN; name[0]=0; GetUserName(name,&len); if (len>49) len=49; // StrReviewer limit name[len]=0; pName=name; } // check if this reviewer exists for (i=1;i<TotalReviewers;i++) if (lstrcmpi(reviewer[i].name,pName)==0) break; if (i==TotalReviewers) { i=GetReviewerSlot(w); lstrncpy(reviewer[i].name,pName,49); // copy name reviewer[i].name[49]=0; NewUser=true; } if (!UseDefaultClrStyle) { reviewer[i].InsStyle=InsStyle; reviewer[i].DelStyle=DelStyle; reviewer[i].InsColor=InsColor; reviewer[i].DelColor=DelColor; reviewer[i].FmtColor=InsColor; } TrackRev=i; // current reviewer id // get the current date/time as DWORD GetLocalTime(&SysTime); SystemTimeToFileTime(&SysTime,&FileTime); FileTimeToDosDateTime(&FileTime,&DosDate,&DosTime); TrackTime=(((DWORD)DosDate)<<16)+DosTime; InsertMode=true; // insert mode always true when tracking if (!NewUser) { // font/style might have changed, so recreate the fonts RecreateFonts(w,hTerDC); RequestPagination(w,true); PaintTer(w); } } else { TrackRev=0; TrackTime=0; } return true; }
BOOL WINAPI _export TerLocateChangedChar2(HWND hWnd, int InsRev, int DelRev, int FmtRev,BOOL present, long far *StartLine, int far *StartCol, BOOL forward) { PTERWND w; long line; int i,col,CurCfmt,CurInsRev,CurDelRev,CurFmtRev; LPWORD fmt; if (NULL==(w=GetWindowPointer(hWnd))) return false; // get the pointer to window data // reset the checked flag for (i=0;i<TotalFonts;i++) ResetUintFlag(TerFont[i].flags,FFLAG_CHECKED); // scan each line in the forward direction if (forward) { for (line=(*StartLine);line<TotalLines;line++) { if (line==(*StartLine)) col=*StartCol; else col=0; if (col>=LineLen(line)) continue; // go to next line if (LineLen(line)==0) continue; if (cfmt(line).info.type==UNIFORM) { CurCfmt=cfmt(line).info.fmt; if (True(TerFont[CurCfmt].flags&FFLAG_CHECKED)) continue; // this font id already checked TerFont[CurCfmt].flags|=FFLAG_CHECKED; CurInsRev=TerFont[CurCfmt].InsRev; CurDelRev=TerFont[CurCfmt].DelRev; CurFmtRev=TerFont[CurCfmt].FmtRev; if (LocateRevMatched(w,present,InsRev,DelRev,FmtRev,CurInsRev,CurDelRev,CurFmtRev)) { *StartLine=line; *StartCol=col; return true; } else continue; // style not found } // open the line fmt=OpenCfmt(w,line); for (i=col;i<LineLen(line);i++) { CurCfmt=fmt[i]; if (True(TerFont[CurCfmt].flags&FFLAG_CHECKED)) continue; // this font id already checked TerFont[CurCfmt].flags|=FFLAG_CHECKED; CurInsRev=TerFont[CurCfmt].InsRev; CurDelRev=TerFont[CurCfmt].DelRev; CurFmtRev=TerFont[CurCfmt].FmtRev; if (LocateRevMatched(w,present,InsRev,DelRev,FmtRev,CurInsRev,CurDelRev,CurFmtRev)) { *StartLine=line; *StartCol=i; CloseCfmt(w,line); return true; } } CloseCfmt(w,line); if (line==(TotalLines-1)) { // 20080530: end of the file reached *StartLine=line; *StartCol=LineLen(line); return true; } } } else { // scan each line in the backward direction for (line=(*StartLine);line>=0;line--) { if (line==(*StartLine)) col=*StartCol; else col=LineLen(line)-1; if (col<0) continue; if (LineLen(line)==0) continue; if (cfmt(line).info.type==UNIFORM) { CurCfmt=cfmt(line).info.fmt; if (True(TerFont[CurCfmt].flags&FFLAG_CHECKED)) continue; // this font id already checked TerFont[CurCfmt].flags|=FFLAG_CHECKED; CurInsRev=TerFont[CurCfmt].InsRev; CurDelRev=TerFont[CurCfmt].DelRev; CurFmtRev=TerFont[CurCfmt].FmtRev; if (LocateRevMatched(w,present,InsRev,DelRev,FmtRev,CurInsRev,CurDelRev,CurFmtRev)) { *StartLine=line; *StartCol=col; return true; } else continue; // style not found } // open the line fmt=OpenCfmt(w,line); for (i=col;i>=0;i--) { CurCfmt=fmt[i]; if (True(TerFont[CurCfmt].flags&FFLAG_CHECKED)) continue; // this font id already checked TerFont[CurCfmt].flags|=FFLAG_CHECKED; CurInsRev=TerFont[CurCfmt].InsRev; CurDelRev=TerFont[CurCfmt].DelRev; CurFmtRev=TerFont[CurCfmt].FmtRev; if (LocateRevMatched(w,present,InsRev,DelRev,FmtRev,CurInsRev,CurDelRev,CurFmtRev)) { *StartLine=line; *StartCol=i; CloseCfmt(w,line); return true; } } CloseCfmt(w,line); } } return false; }
/****************************************************************************** TerAcceptChanges: Accept one or all changes. ******************************************************************************/ int WINAPI _export TerAcceptChanges(HWND hWnd, BOOL all, BOOL msg, BOOL repaint) { PTERWND w; int GroupUndoRef; long SaveCurLine; int SaveCurCol,font; int count=0; BOOL first=false; if (NULL==(w=GetWindowPointer(hWnd))) return -1; // get the pointer to window data if (TrackChanges) return -1; // can not accept in track-change in progress // ** Accept current change if (!all) { if (AcceptChange(w,CurLine,CurCol)) { if (repaint) PaintTer(w); return 1; } else return 0; } // ** Accept all if (msg && IDNO==MessageBox(hTerWnd,MsgString[MSG_ACCEPT_CHANGES],"",MB_YESNO)) return -1; GroupUndoRef=UndoRef; // connect undos for all accepts SaveCurLine=CurLine; SaveCurCol=CurCol; // Locate and accept each change CurLine=0; // start from the beginning CurCol=0; font=GetCurCfmt(w,CurLine,CurCol); // check if changes found at the first location first=IsTrackChangeFont(w,font); while (first || TerFindNextChange(hTerWnd,true,false)) { first=false; // at at first location UndoRef=GroupUndoRef; // connect to previous undo if (!AcceptChange(w,CurLine,CurCol)) break; // check for the condition when two strings are back-to-back font=GetCurCfmt(w,CurLine,CurCol); // check if positioned on changed text if (IsTrackChangeFont(w,font)) PrevTextPos(w,&CurLine,&CurCol); // position on a non-changed text just before the current changed text count++; } if (count==0) { // restore the cursor position CurLine=SaveCurLine; CurCol=SaveCurCol; } else if (repaint) { PaintTer(w); } if (msg) { wsprintf(TempString,"%s %d",MsgString[MSG_CHANGES_COUNT],count); MessageBox(hTerWnd,TempString,"",MB_OK); } return count; }