Added readonly & final checks for Word & Powerpoint

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1754 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-04 16:46:09 +00:00
commit 54b6b4321f
4 changed files with 42 additions and 2 deletions

View file

@ -28,7 +28,14 @@ using Greenshot.Interop;
namespace Greenshot.Interop.Office {
public class PowerpointExporter {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PowerpointExporter));
private static string version = null;
public static bool isAfter2003() {
if (version != null) {
return !version.StartsWith("11");
}
return false;
}
/// <summary>
/// Get the captions of all the open powerpoint presentations
/// </summary>
@ -38,10 +45,18 @@ namespace Greenshot.Interop.Office {
try {
using (IPowerpointApplication powerpointApplication = COMWrapper.GetInstance<IPowerpointApplication>()) {
if (powerpointApplication != null) {
if (version == null) {
version = powerpointApplication.Version;
}
LOG.DebugFormat("Open Presentations: {0}", powerpointApplication.Presentations.Count);
for (int i = 1; i <= powerpointApplication.Presentations.Count; i++) {
IPresentation presentation = powerpointApplication.Presentations.item(i);
if (presentation != null) {
if (presentation != null && presentation.ReadOnly != MsoTriState.msoTrue) {
if (isAfter2003()) {
if (presentation.Final) {
continue;
}
}
presentations.Add(presentation.Name);
}
}

View file

@ -27,7 +27,14 @@ using Greenshot.Interop;
namespace Greenshot.Interop.Office {
public class WordExporter {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordExporter));
private static string version = null;
public static bool isAfter2003() {
if (version != null) {
return !version.StartsWith("11");
}
return false;
}
/// <summary>
/// Insert the bitmap stored under the tempfile path into the word document with the supplied caption
/// </summary>
@ -101,9 +108,19 @@ namespace Greenshot.Interop.Office {
try {
using (IWordApplication wordApplication = COMWrapper.GetInstance<IWordApplication>()) {
if (wordApplication != null) {
//documents.Add(wordApplication.ActiveDocument);
if (version == null) {
version = wordApplication.Version;
}
for (int i = 1; i <= wordApplication.Documents.Count; i++) {
IWordDocument document = wordApplication.Documents.item(i);
if (document.ReadOnly) {
continue;
}
if (isAfter2003()) {
if (document.Final) {
continue;
}
}
documents.Add(document.ActiveWindow.Caption);
}
}

View file

@ -33,6 +33,7 @@ namespace Greenshot.Interop.Office {
bool Visible { get; set; }
void Activate();
IPowerpointWindow ActiveWindow { get; }
string Version { get; }
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.slides_members.aspx
@ -57,6 +58,8 @@ namespace Greenshot.Interop.Office {
string Name { get; }
ISlides Slides { get; }
IPowerpointApplication Application { get; }
MsoTriState ReadOnly { get; }
bool Final { get; set; }
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentations_members.aspx

View file

@ -31,6 +31,7 @@ namespace Greenshot.Interop.Office {
IDocuments Documents { get; }
bool Visible { get; set; }
void Activate();
string Version { get; }
}
// See: http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.documents_members(v=office.11).aspx
@ -44,6 +45,10 @@ namespace Greenshot.Interop.Office {
void Activate();
IWordApplication Application { get; }
IWordWindow ActiveWindow { get; }
bool ReadOnly { get; }
// Only 2007 and later!
bool Final { get; set; }
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.window_members.aspx