//--------------------------------------------------------------------------- void WordMacros::Replace(const string_t& text, const string_t& repl) { // обходим проблему текста длинее 255 символов const size_t MAX_REPL_LEN = 200; if (repl.size() > MAX_REPL_LEN) { string_t newText; std::vector<string_t> rs; for (size_t i = 0; i < repl.size(); i+= MAX_REPL_LEN) { newText += text + aux::itow(rs.size()); rs.push_back(repl.subString(i, MAX_REPL_LEN)); } Replace(text, newText); for (size_t i = 0; i < rs.size(); ++i) Replace(text + aux::itow(i), rs[i]); return; } m_Macros += "With Selection.Find \n"; m_Macros += " .ClearFormatting \n"; m_Macros += " .Replacement.ClearFormatting \n"; m_Macros += " .Text = \"" + text +"\" \n"; m_Macros += " .Replacement.Text = \"" + repl +"\" \n"; m_Macros += " .Execute Replace:=wdReplaceAll \n"; m_Macros += "End With \n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::SelectionBorderLine() { m_Macros += "With Selection.Borders(wdBorderBottom)\n"; m_Macros += " .LineStyle = Options.DefaultBorderLineStyle\n"; m_Macros += " .LineWidth = Options.DefaultBorderLineWidth\n"; m_Macros += " .Color = Options.DefaultBorderColor\n"; m_Macros += " End With\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::TablesAdd(int rowCount, int colCount) { m_Macros += "ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=" + string_t(aux::itoa(rowCount)) + ", NumColumns:= _ \n"; m_Macros += " " + string_t(aux::itoa(colCount)) + ", DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _ \n"; m_Macros += " wdAutoFitFixed\n"; m_Macros += "With Selection.Tables(1)\n"; /* m_Macros += " If .Style <> \"Сетка таблицы\" Then\n"; m_Macros += " .Style = \"Сетка таблицы\"\n"; m_Macros += " End If\n"; */ m_Macros += " .ApplyStyleHeadingRows = True\n"; m_Macros += " .ApplyStyleLastRow = True\n"; m_Macros += " .ApplyStyleFirstColumn = True\n"; m_Macros += " .ApplyStyleLastColumn = True\n"; m_Macros += "End With\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::SelectionText(const string_t& text) { if (text.empty()) return; if (text == "vbTab") { m_Macros += "Selection.TypeText Text:=vbTab\n"; return; } int end = text.indexOf(L"\n"); if (end > -1) { if (end > 1) m_Macros += "Selection.TypeText Text:=\"" + text.subString(0, end) + "\"\n"; SelectionTypeParagraph(); SelectionText(text.subString(end+1, text.size())); } else m_Macros += "Selection.TypeText Text:=\"" + text + "\"\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::TableStyle(const EStyleBorder& style) { if (style == StyleNone) { m_Macros += "With Selection.Tables(1)\n"; m_Macros += " .Borders(wdBorderLeft).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderRight).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderTop).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderBottom).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderVertical).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone\n"; m_Macros += " .Borders.Shadow = False\n"; m_Macros += "End With\n"; m_Macros += "With Options\n"; m_Macros += " .DefaultBorderLineStyle = wdLineStyleSingle\n"; m_Macros += " .DefaultBorderLineWidth = wdLineWidth050pt\n"; m_Macros += " .DefaultBorderColor = wdColorAutomatic\n"; m_Macros += "End With\n"; } IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::PageSetup(const string_t& param) { m_Macros += "With ActiveDocument.Styles(wdStyleNormal).Font \n"; m_Macros += " If .NameFarEast = .NameAscii Then \n"; m_Macros += " .NameAscii = \"\" \n"; m_Macros += " End If \n"; m_Macros += " .NameFarEast = \"\" \n"; m_Macros += "End With \n"; m_Macros += "With ActiveDocument.PageSetup \n"; m_Macros += " .LineNumbering.Active = False \n"; m_Macros += " .Orientation = wdOrientLandscape \n"; m_Macros += " .TopMargin = CentimetersToPoints(1.5) \n"; m_Macros += " .BottomMargin = CentimetersToPoints(3) \n"; m_Macros += " .LeftMargin = CentimetersToPoints(2) \n"; m_Macros += " .RightMargin = CentimetersToPoints(2) \n"; m_Macros += " .Gutter = CentimetersToPoints(0) \n"; m_Macros += " .HeaderDistance = CentimetersToPoints(1.25) \n"; m_Macros += " .FooterDistance = CentimetersToPoints(1.25) \n"; m_Macros += " .PageWidth = CentimetersToPoints(29.7) \n"; m_Macros += " .PageHeight = CentimetersToPoints(21) \n"; m_Macros += " .FirstPageTray = wdPrinterDefaultBin \n"; m_Macros += " .OtherPagesTray = wdPrinterDefaultBin \n"; m_Macros += " .SectionStart = wdSectionNewPage \n"; m_Macros += " .OddAndEvenPagesHeaderFooter = False \n"; m_Macros += " .DifferentFirstPageHeaderFooter = False \n"; m_Macros += " .VerticalAlignment = wdAlignVerticalTop \n"; m_Macros += " .SuppressEndnotes = False \n"; m_Macros += " .MirrorMargins = False \n"; m_Macros += " .TwoPagesOnOne = False \n"; m_Macros += " .BookFoldPrinting = False \n"; m_Macros += " .BookFoldRevPrinting = False \n"; m_Macros += " .BookFoldPrintingSheets = 1 \n"; m_Macros += " .GutterPos = wdGutterPosLeft \n"; m_Macros += "End With \n"; IsLarge(); }
/* * Name: VrSeek * * Description: * This function changes the byte offset associated with the device, * partition, or file specified by FileId. * * Arguments: * FileId - Supplies the file table index. * Offset - Supplies a poiner to a structure that contains * the offset value. * SeekMode - Supplies the type of positioning to be performed. * * Return Value: * If the specified file is open, then a seek is attempted and * the status of the operation is returned. Otherwise, return * an unsuccessful status. * */ ARC_STATUS VrSeek( IN ULONG FileId, IN PLARGE_INTEGER Offset, IN SEEK_MODE SeekMode ) { LONG Status; debug(VRDBG_RDWR, "VrSeek: Entry - FileId: %d Offset: %x.%x Mode: %x\n", FileId, Offset->HighPart, Offset->LowPart, SeekMode); if (FileId >= FILE_TABLE_SIZE) { return EBADF; } if (FileTable[FileId].Flags.Open != 1) { return EACCES; } if (FileTable[FileId].Flags.Delete == 1) { return EACCES; } if (!(SeekMode == SeekRelative || SeekMode == SeekAbsolute)) { return EINVAL; } // // If the specified device is Network, only set Offset into FileTable // because the Offset is interpreted to be a count of input to ignore. // The offset is cleared after reading the input packet. // if (FileTable[FileId].Flags.NetworkDevice == 1) { (VOID)MoveLargeInt(&FileTable[FileId].Position, Offset); return ESUCCESS; } // // Set the file position according to SeekMode. // if (SeekMode == SeekRelative) { (VOID)AddLargeInt(&FileTable[FileId].Position, Offset); } else { (VOID)MoveLargeInt(&FileTable[FileId].Position, Offset); } // // If FileId is for Network device, the input packets are ignored // according to Offset and then return with ESUCCESS. // if (FileTable[FileId].Flags.NetworkDevice == 1) { while (IsLarge(&FileTable[FileId].Position) == NOT_ZERO_LARGE) { LONG ReadSize; CHAR Buffer[4]; if ((ReadSize = OFRead(FileTable[FileId].IHandle, Buffer, 1)) == -1) { return EIO; } if (ReadSize == 0) { continue; } DecrementLarge(&FileTable[FileId].Position); } return ESUCCESS; } Status = OFSeek(FileTable[FileId].IHandle, FileTable[FileId].Position.HighPart, FileTable[FileId].Position.LowPart); if (Status == -1) { return EINVAL; // XXXX } debug(VRDBG_RDWR, "VrSeek: Exit\n"); return ESUCCESS; }
//--------------------------------------------------------------------------- void WordMacros::UnLock() { m_LargeLock = false; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::Cell(int tableNum, int x, int y, const string_t& param) { m_Macros += "ActiveDocument.Tables(" + string_t(aux::itoa(tableNum)) + ").Cell(" + aux::itoa(x) + "," + aux::itoa(y) + ")." + param + "\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::InsertLine(const string_t& line) { m_Macros += line + "\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::TablesColumns(int tableNum, int colNum, const string_t& param) { m_Macros += "ActiveDocument.Tables(" + string_t(aux::itoa(tableNum)) + ").Columns(" + aux::itoa(colNum) + ")." + param + "\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::SelectionTypeParagraph(int count /* = 1*/) { for (int i = 0; i < count; ++i) m_Macros += "Selection.TypeParagraph\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::SelectionFont(const string_t& param) { m_Macros += "Selection.Font." + param + "\n"; IsLarge(); }
//--------------------------------------------------------------------------- void WordMacros::SelectionParagraphFormat(const string_t& param) { m_Macros += "Selection.ParagraphFormat." + param + "\n"; IsLarge(); }