[Mwinapi-commits] SF.net SVN: mwinapi:[92] trunk/ManagedWinapi
Status: Beta
Brought to you by:
schierlm
|
From: <sch...@us...> - 2010-02-14 14:15:03
|
Revision: 92
http://mwinapi.svn.sourceforge.net/mwinapi/?rev=92&view=rev
Author: schierlm
Date: 2010-02-14 14:14:56 +0000 (Sun, 14 Feb 2010)
Log Message:
-----------
- WindowContentParser: Add an option to parse only the short description (faster)
- Speed up parsing of details list views enormously
Modified Paths:
--------------
trunk/ManagedWinapi/Contents/ListParser.cs
trunk/ManagedWinapi/Contents/WindowContentParser.cs
trunk/ManagedWinapi/SystemWindow.cs
Modified: trunk/ManagedWinapi/Contents/ListParser.cs
===================================================================
--- trunk/ManagedWinapi/Contents/ListParser.cs 2010-01-02 19:08:51 UTC (rev 91)
+++ trunk/ManagedWinapi/Contents/ListParser.cs 2010-02-14 14:14:56 UTC (rev 92)
@@ -155,6 +155,12 @@
return SystemListBox.FromSystemWindow(sw) != null;
}
+ internal override WindowContent ParsePreviewContent(SystemWindow sw)
+ {
+ SystemListBox slb = SystemListBox.FromSystemWindow(sw);
+ return new ListContent("ListBox", slb.SelectedIndex, slb.SelectedItem, new string[0]);
+ }
+
internal override WindowContent ParseContent(SystemWindow sw)
{
SystemListBox slb = SystemListBox.FromSystemWindow(sw);
@@ -175,6 +181,11 @@
return SystemComboBox.FromSystemWindow(sw) != null;
}
+ internal override WindowContent ParsePreviewContent(SystemWindow sw)
+ {
+ return new ListContent("ComboBox", -1, sw.Text, new string[0]);
+ }
+
internal override WindowContent ParseContent(SystemWindow sw)
{
SystemComboBox slb = SystemComboBox.FromSystemWindow(sw);
@@ -198,11 +209,81 @@
return cnt != 0;
}
+ internal override WindowContent ParsePreviewContent(SystemWindow sw)
+ {
+ uint LVM_GETITEMCOUNT = (0x1000 + 4);
+ int cnt = sw.SendGetMessage(LVM_GETITEMCOUNT);
+ if (cnt == 0) throw new Exception();
+ SystemAccessibleObject o = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
+ if (o.RoleIndex == 33)
+ {
+ return new ListContent("DetailsListView", -1, null, new string[0]);
+ }
+ else
+ {
+ return new ListContent("EmptyListView", -1, null, new string[0]);
+ }
+ }
+
internal override WindowContent ParseContent(SystemWindow sw)
{
uint LVM_GETITEMCOUNT = (0x1000 + 4);
int cnt = sw.SendGetMessage(LVM_GETITEMCOUNT);
if (cnt == 0) throw new Exception();
+ try
+ {
+ SystemListView slv = SystemListView.FromSystemWindow(sw);
+ // are there column headers?
+ string[] hdr = null;
+ SystemListViewColumn[] columns = slv.Columns;
+ if (columns.Length > 0)
+ {
+ hdr = new string[columns.Length];
+ for (int i = 0; i < hdr.Length; i++)
+ {
+ hdr[i] = columns[i].Title;
+ }
+ }
+ int itemCount = slv.Count;
+ List<string> values = new List<string>();
+ for (int i = 0; i < itemCount; i++)
+ {
+ SystemListViewItem item = slv[i];
+ string name = item.Title;
+ if (hdr != null)
+ {
+ for (int j = 1; j < hdr.Length; j++)
+ {
+ SystemListViewItem subitem = slv[i, j];
+ name += "\t" + subitem.Title;
+ }
+ }
+ values.Add(name);
+ }
+ if (hdr != null)
+ {
+ string lines = "", headers = "";
+ foreach (string h in hdr)
+ {
+ if (lines.Length > 0) lines += "\t";
+ if (headers.Length > 0) headers += "\t";
+ headers += h;
+ lines += ListContent.Repeat('~', h.Length);
+ }
+ values.Insert(0, lines);
+ values.Insert(0, headers);
+ return new ListContent("DetailsListView", -1, null, values.ToArray());
+ }
+ else
+ {
+ return new ListContent("ListView", -1, null, values.ToArray());
+ }
+ }
+ catch
+ {
+ // fallback to slower accessible object method
+ if (true) throw;
+ }
SystemAccessibleObject o = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
if (o.RoleIndex == 33)
{
@@ -333,6 +414,16 @@
return cnt != 0;
}
+ internal override WindowContent ParsePreviewContent(SystemWindow sw)
+ {
+ SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
+ if (sao.RoleIndex == 35)
+ {
+ return new ListContent("TreeView", -1, null, new string[0]);
+ }
+ return new ListContent("EmptyTreeView", -1, null, new string[0]);
+ }
+
internal override WindowContent ParseContent(SystemWindow sw)
{
SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);
Modified: trunk/ManagedWinapi/Contents/WindowContentParser.cs
===================================================================
--- trunk/ManagedWinapi/Contents/WindowContentParser.cs 2010-01-02 19:08:51 UTC (rev 91)
+++ trunk/ManagedWinapi/Contents/WindowContentParser.cs 2010-02-14 14:14:56 UTC (rev 92)
@@ -26,11 +26,26 @@
internal abstract bool CanParseContent(SystemWindow sw);
internal abstract WindowContent ParseContent(SystemWindow sw);
+ /// <summary>
+ /// Parse enough content so that the <see cref="WindowContent.ShortDescription"/> is accurate.
+ /// </summary>
+ internal virtual WindowContent ParsePreviewContent(SystemWindow sw)
+ {
+ return ParseContent(sw);
+ }
+
internal static WindowContent Parse(SystemWindow sw)
{
WindowContentParser parser = ContentParserRegistry.Instance.GetParser(sw);
if (parser == null) return null;
return parser.ParseContent(sw);
}
+
+ internal static WindowContent ParsePreview(SystemWindow sw)
+ {
+ WindowContentParser parser = ContentParserRegistry.Instance.GetParser(sw);
+ if (parser == null) return null;
+ return parser.ParsePreviewContent(sw);
+ }
}
}
Modified: trunk/ManagedWinapi/SystemWindow.cs
===================================================================
--- trunk/ManagedWinapi/SystemWindow.cs 2010-01-02 19:08:51 UTC (rev 91)
+++ trunk/ManagedWinapi/SystemWindow.cs 2010-02-14 14:14:56 UTC (rev 92)
@@ -996,6 +996,21 @@
}
/// <summary>
+ /// A preview of the content of this window. Is only supported for some
+ /// kinds of controls (like text or list boxes). This method can be a lot
+ /// faster than the <see cref="Content"/> method, but will only
+ /// guarantee that the <see cref="WindowContent.ShortDescription"/> field is
+ /// filled accurately.
+ /// </summary>
+ public WindowContent PreviewContent
+ {
+ get
+ {
+ return WindowContentParser.ParsePreview(this);
+ }
+ }
+
+ /// <summary>
/// Whether this control, which is a check box or radio button, is checked.
/// </summary>
public CheckState CheckState
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|