//--------------------------------------------------------------------------- void __fastcall TfrmBillConfig::menuPasteClick(TObject *Sender) { TBillConfig * TmpBillConfig = new TBillConfig(""); if(!CheckClipboard(TmpBillConfig)) { delete TmpBillConfig; return; } AnsiString NewBillName = TmpBillConfig->BillNameList->Strings[0]; _di_IXMLNode BillNode = TmpBillConfig->GetBillNode(TmpBillConfig->BillNameList->Strings[0]); _di_IXMLNode BillNameNode = BillNode->ChildNodes->FindNode("BillName"); if(BillConfig->GetBillNode(NewBillName) != NULL) { int n = 1; do { if(BillConfig->GetBillNode(NewBillName + "的副本(" + IntToStr(n) + ")") == NULL) { NewBillName = NewBillName + "的副本(" + IntToStr(n) + ")"; break; } ++n; }while(true); } BillNameNode->Text = NewBillName; BillConfig->BillRootNode->ChildNodes->Insert(BillConfig->BillRootNode->ChildNodes->Count,BillNode); FillBillList(NULL,NewBillName); delete TmpBillConfig; }
void __fastcall TfrmBillConfig::PopupMenu1Popup(TObject *Sender) { menuEditBill->Enabled = lvBills->Selected != NULL; menuDeleteBill->Enabled = menuEditBill->Enabled; menuCopyBillConfig->Enabled = menuEditBill->Enabled; TBillConfig * BillConfig = new TBillConfig(""); menuPaste->Enabled = CheckClipboard(BillConfig); delete BillConfig; }
BOOL SearchAgain(WORD Flags) /*Flags: 1=Reverse (search in opposite direction) * 2=pop up dialog if not searched before */ { BOOL Return; ULONG OldLength; HideEditCaret(); if (Flags & 2 && !MatchValid) { SearchDialog(); return (TRUE); } OldLength = SelectCount; if (OldLength) { InvalidateArea(&SelectStart, SelectCount, 1); SelectCount = 0; UpdateWindow(hwndMain); } SelectStart = CurrPos; Return = SearchAndStatus(&SelectStart, (WORD)((Flags & 1) | 2)); if (Return) { if ((OldLength==0 && Mode!=InsertMode) || ComparePos(&SelectStart, &CurrPos) == 0) { if (CountBytes(&EndMatch) - CountBytes(&StartPos) == OldLength) { SelectStart = CurrPos; Return = SearchAndStatus(&SelectStart, (WORD)(Flags & 1)); } } if (Return) { NewPosition(&SelectStart); UpdateWindow(hwndMain); SelectStart = StartPos; SelectBytePos = CountBytes(&StartPos); SelectCount = CountBytes(&EndMatch) - SelectBytePos; InvalidateArea(&SelectStart, SelectCount, 0); UpdateWindow(hwndMain); } } CheckClipboard(); ShowEditCaret(); GetXPos(&CurrCol); return (Return); }
BOOL DoCopy(HWND hwnd,void *PGPsc,BOOL bUseCurrent,HWND *hwndFocus) { BOOL ClipOK; HWND hwndEdit; BOOL RetVal=TRUE; char WinClass[256]; PGPContextRef context; DWORD OtherAppThreadID; DWORD OtherAppProcessID; HWND hwndOldFocus; DWORD TrayThreadID; context=(PGPContextRef)PGPsc; *hwndFocus=NULL; if(bUseCurrent) { TrayThreadID=GetCurrentThreadId(); hwndEdit=ReadCurrentFocus(); *hwndFocus=hwndEdit; GetClassName(hwndEdit,WinClass,255); ClipboardWipe(NULL,context); // We can key off WinClass if something else // needs to be done OtherAppThreadID = GetWindowThreadProcessId( hwndEdit, &OtherAppProcessID); AttachThreadInput( TrayThreadID, OtherAppThreadID, TRUE ); hwndOldFocus=SetFocus(hwndEdit); WMCopy(hwndEdit); ClipOK=CheckClipboard(); if(!ClipOK) { // We can key off WinClass if something else // needs to be done EMSetSel(hwndEdit); WMCopy(hwndEdit); ClipOK=CheckClipboard(); if(!ClipOK) { ControlC(); ClipOK=CheckClipboard(); if(!ClipOK) { ControlA(); ControlC(); ClipOK=CheckClipboard(); if(!ClipOK) { RetVal=FALSE; } } } } AttachThreadInput( TrayThreadID, OtherAppThreadID, FALSE ); SetFocus(hwndOldFocus); } if(!RetVal) { #if _DEBUG char szInfo[256]; sprintf(szInfo,"Class %s HWND %x",WinClass,hwndEdit); MessageBox(hwnd,szInfo,"Couldn't get text. _DEBUG VERSION ONLY_ info", MB_OK|MB_ICONSTOP|MB_SETFOREGROUND); #else PGPscMessageBox (hwnd,IDS_PGPERROR,IDS_CANTAUTOCOPY, MB_OK|MB_ICONSTOP); #endif } return RetVal; }
BOOL ClipboardCopy(void) { HGLOBAL hMem; char huge *pMem; LONG lSize; BOOL WideCharConvert = FALSE; UINT Codepage = 0; /*prepare resources...*/ if (!SelectCount) { Error(209); return (FALSE); } if (!OpenClipboard(hwndMain)) { ErrorBox(MB_ICONEXCLAMATION, 302); return (FALSE); } lSize = SelectCount + sizeof(BinaryPart); if (!(GetVersion() & 0x80000000U)) if (UtfEncoding || CharSet == CS_OEM || AnsiCodePage != CP_ACP) { /*copy as wide chars...*/ Codepage = CharSet == CS_OEM ? OemCodePage : AnsiCodePage; if (UtfEncoding != 16) lSize <<= 1; WideCharConvert = TRUE; } hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, lSize); if (!hMem) { CloseClipboard(); ErrorBox(MB_ICONEXCLAMATION, 304); return (FALSE); } pMem = GlobalLock(hMem); if (pMem == NULL) { CloseClipboard(); GlobalFree(hMem); ErrorBox(MB_ICONEXCLAMATION, 305); return (FALSE); } /*copy into memory...*/ { POSITION Pos; ULONG Bytes = SelectCount; UINT i; BOOL NullbyteFound = FALSE; Pos = SelectStart; if (UtfEncoding && WideCharConvert) { POSITION EndPos = Pos; WCHAR *pw = (WCHAR *)pMem; Advance(&EndPos, Bytes); //if (CountBytes(&Pos) != 0 || (i = CharAndAdvance(&Pos)) == C_BOM) i = CharAndAdvance(&Pos); for (;;) { if (ComparePos(&Pos, &EndPos) > 0) break; if (i == C_EOF) break; if (i == C_CRLF) { if ((char *)pw + 6 > pMem + lSize) break; *pw++ = '\r'; i = '\n'; } if ((char *)pw + 4 > pMem + lSize) break; *pw++ = i; i = CharAndAdvance(&Pos); } *pw = '\0'; } else while (Bytes) { LPSTR p, pNull; CharAt(&Pos); /*normalize position and enforce page load*/ i = Pos.p->Fill - Pos.i; if (i > Bytes) i = (UINT)Bytes; p = Pos.p->PageBuf + Pos.i; if (!NullbyteFound && (pNull = _fmemchr(p, '\0', i)) != NULL) { if (ErrorBox(MB_ICONINFORMATION|MB_OKCANCEL, 328) == IDCANCEL) { CloseClipboard(); GlobalUnlock(hMem); GlobalFree(hMem); return (FALSE); } NullbyteFound = TRUE; i = pNull - p + 1; if (CharSet == CS_EBCDIC) EbcdicConvert(pMem, p, i); else if (WideCharConvert) { MultiByteToWideChar(Codepage, 0, p, i, (WCHAR*)pMem, i); pMem += i; } else hmemcpy(pMem, p, i); pMem += i; Bytes -= --i; Pos.i += i; i = wsprintf(BinaryPart, BinaryFormat, Bytes); if (WideCharConvert) { MultiByteToWideChar(Codepage, 0, BinaryPart, i, (WCHAR*)pMem, i); pMem += i; } else hmemcpy(pMem, BinaryPart, i); pMem += i; continue; } if (CharSet == CS_EBCDIC) EbcdicConvert(pMem, Pos.p->PageBuf + Pos.i, i); else if (WideCharConvert) { MultiByteToWideChar(Codepage, 0, Pos.p->PageBuf + Pos.i, i, (WCHAR*)pMem, i); if (CharSet == CS_OEM) { extern WCHAR const MapLowOemToUtf16[33]; PWSTR pw = (WCHAR*)pMem; INT j; for (j=i; j>0; --j) { if (*pw < ' ') { switch (*pw) { case '\0': case '\t': case '\n': case '\r': break; default: *pw = MapLowOemToUtf16[*pw]; } } ++pw; } } pMem += i; } else hmemcpy(pMem, Pos.p->PageBuf + Pos.i, i); pMem += i; Bytes -= i; Pos.i += i; } } /*unlock...*/ GlobalUnlock(hMem); /*clear previous clipboard contents...*/ if (!EmptyClipboard()) { CloseClipboard(); GlobalFree(hMem); ErrorBox(MB_ICONEXCLAMATION, 303); return (FALSE); } /*finally, publish...*/ SetClipboardData(WideCharConvert ? CF_UNICODETEXT : CharSet == CS_OEM ? CF_OEMTEXT : CF_TEXT, hMem); CloseClipboard(); CheckClipboard(); return (TRUE); }
void Undo(WORD Flags) /* Flags: 0 = called as vi-like undo: * undo of whole last operation, * a second undo reverts the undo operation, * entered as character 'u'; * 1 = called as Windows-like undo: * undo last change at one position, * repeated undos go further back in history, * entered as <Alt+Bksp>, menu, or tool button; * 2 = repeated vi-like undo ('.'): * can repeat both undo and redo; * 4 = vi-like undo of whole line: * not yet implemented, * entered as character 'U'; */ { LPUNDO lpUndo; BOOL fUndone = FALSE; ULONG StartSkip = (ULONG)-1; extern INT HexEditFirstNibble; if (Flags & 3) lpUndo = NextSequenceUndo; else { lpUndo = NextSequenceUndo = LastUndo; if (LastUndo != NULL) { LastUndo->Flags |= UD_START; if (LastUndo->Flags & UD_BYUNDO) { if (Redoing && LastUndo->UndoRef!=NULL) lpUndo = LastUndo->UndoRef; Redoing ^= TRUE^FALSE; } else Redoing = FALSE; } } if (lpUndo==NULL || (Redoing && !(lpUndo->Flags & UD_BYUNDO))) { Error(219); return; } if (IsViewOnly()) return; if (UtfEncoding == 16) { /*any undo ops must be double-byte, check before doing anything...*/ LPUNDO lp = lpUndo; ULONG Skip; while (lp != NULL) { if ((Skip = lpUndo->Pos) != (ULONG)-1) { if (lp->DelFill & 1 || lp->Inserted & 1) { ErrorBox(MB_ICONSTOP, 260); return; } if (StartSkip == (ULONG)-1) StartSkip = Skip; if (Flags & 1) break; } if (lp->Flags & UD_NEWOP && StartSkip != (ULONG)-1) break; lp = lp->Prev; } StartSkip = (ULONG)-1; } HideEditCaret(); wsprintf(QueryString, "%s %s, used mem %lu", Redoing ? "redoing" : "undoing", lpUndo->Flags & UD_BYUNDO ? "undo" : "non-undo", UndoMemUsed); QueryTime = GetTickCount(); GlobalUndoFlags |= UD_BYUNDO; StartWithRemove = lpUndo->Flags & UD_START; StartUndoSequence(); if (FirstUndo == NULL || (FirstUndo->Next == NULL && FirstUndo != lpUndo)) lpUndo = NULL; StartWithRemove = TRUE; HexEditFirstNibble = -1; while (lpUndo != NULL) { POSITION Pos; ULONG Skip; if ((Skip = lpUndo->Pos) != (ULONG)-1) { if (StartSkip == (ULONG)-1) StartSkip = Skip; Pos.p = FirstPage; while (Skip >= Pos.p->Fill) { if (!Pos.p->Next) { if (Skip != Pos.p->Fill) { /*must not occur*/ assert(Skip == Pos.p->Fill); /*!?*/ return; } break; } Skip -= Pos.p->Fill; Pos.p = Pos.p->Next; } if (SelectCount) { InvalidateArea(&SelectStart, SelectCount, 1); SelectCount = 0; UpdateWindow(hwndMain); } Pos.i = (UINT)Skip; Pos.f = 0; /*TODO: check flags to be filled here*/ if (lpUndo->Inserted) { SelectStart = Pos; SelectCount = lpUndo->Inserted; SelectBytePos = CountBytes(&SelectStart); DeleteSelected(3); fUndone = TRUE; Indenting = FALSE; } if (lpUndo->DelFill) { LPSTR Buf; LONG ByteCount = CountBytes(&Pos); if (lpUndo->Flags & UD_GLOBALMEM) Buf = GlobalLock(lpUndo->DelMem); else Buf = (LPBYTE)lpUndo + sizeof(UNDO); if (Buf != NULL) { NewPosition(&Pos); InsertBuffer(Buf, lpUndo->DelFill, 0); fUndone = TRUE; if (lpUndo->Flags & UD_GLOBALMEM) GlobalUnlock(lpUndo->DelMem); /*reposition to current position...*/ Pos.p = FirstPage; Pos.i = 0; Advance(&Pos, ByteCount); if (lpUndo->Flags & UD_SELECT && Flags & 1) { SelectStart = Pos; SelectCount = lpUndo->DelFill; SelectBytePos = CountBytes(&SelectStart); InvalidateArea(&SelectStart, SelectCount, 0); CheckClipboard(); } } else ErrorBox(MB_ICONSTOP, 313); } if (Flags & 1) break; } if (lpUndo->Flags & UD_NEWOP && StartSkip != (ULONG)-1) break; lpUndo = lpUndo->Prev; } GlobalUndoFlags = 0; if (lpUndo != NULL) { if (lpUndo->Flags & UD_SAFE) { EnableToolButton(IDB_SAVE, FALSE); SetSafe(FALSE); GlobalUndoFlags = UD_SAFE; } else if (fUndone) SetUnsafe(); LastUndo->UndoRef = NextSequenceUndo = lpUndo->Prev; #if 0 // if (NextSequenceUndo!=NULL && lpUndo->Flags & UD_BYUNDO // && !(NextSequenceUndo->Flags&UD_BYUNDO)) // NextSequenceUndo->Flags &= ~UD_START; #endif } else { if (fUndone) SetUnsafe(); NextSequenceUndo = NULL; } if (Redoing) CheckForUndoneToRelease(FALSE); /*...undo information about redo and previous undo is not needed anymore * because the original undo information will be used instead. */ if (StartSkip != (ULONG)-1) { CurrPos.p = FirstPage; CurrPos.i = 0; Advance(&CurrPos, StartSkip); FindValidPosition(&CurrPos, (WORD)(Mode==InsertMode || Mode==ReplaceMode)); GetXPos(&CurrCol); } if (lpUndo==NULL || NextSequenceUndo==NULL) EnableToolButton(IDB_UNDO, FALSE); ShowEditCaret(); }