• R/O
  • SSH
  • HTTPS

rcsharp: コミット


コミットメタ情報

リビジョン12 (tree)
日時2014-04-27 10:39:04
作者srz_zumix

ログメッセージ

listBox, listView の初期化に対応

変更サマリ

差分

--- trunk/Sample/Sample.cpp (revision 11)
+++ trunk/Sample/Sample.cpp (revision 12)
@@ -7,6 +7,10 @@
77
88 #pragma comment(lib, "comctl32.lib")
99
10+#pragma comment(linker,"\"/manifestdependency:type='win32' \
11+name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
12+processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
13+
1014 #define MAX_LOADSTRING 100
1115
1216 // グローバル変数:
@@ -56,6 +60,13 @@
5660 return FALSE;
5761 }
5862 #endif
63+ INITCOMMONCONTROLSEX ic;
64+ ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
65+ ic.dwICC = ICC_LISTVIEW_CLASSES;
66+ if( !InitCommonControlsEx(&ic) )
67+ {
68+ return FALSE;
69+ }
5970
6071 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SAMPLE));
6172
--- trunk/RCSharp/RCFile.cs (revision 11)
+++ trunk/RCSharp/RCFile.cs (revision 12)
@@ -537,7 +537,7 @@
537537 #region ListBox
538538 else if (CSTypeHelper.IsDerived(fi.FieldType, typeof(ListBox)))
539539 {
540- if (!CSRCListBox.Serialize(form, (ListBox)obj, name, resIDs, out str)) continue;
540+ if (!CSRCListBox.Serialize(form, (ListBox)obj, name, resIDs, out str, out init_str, ref m_InitFunction)) continue;
541541 }
542542 #endregion
543543 #region Label
@@ -591,7 +591,7 @@
591591 #region ListView
592592 else if (CSTypeHelper.IsDerived(fi.FieldType, typeof(ListView)))
593593 {
594- if (!CSRCListView.Serialize(form, (ListView)obj, name, resIDs, out str)) continue;
594+ if (!CSRCListView.Serialize(form, (ListView)obj, name, resIDs, out str, out init_str, ref m_InitFunction)) continue;
595595 }
596596 #endregion
597597 #region TreeView
@@ -944,10 +944,12 @@
944944 class CSRCListBox
945945 {
946946 #region Serialize
947- public static bool Serialize(Form form, ListBox ctrl, string name, CSResID resIDs, out string buf)
947+ public static bool Serialize(Form form, ListBox ctrl, string name, CSResID resIDs
948+ , out string buf, out string init_buf, ref CSRCDlgInitFunction init_func)
948949 {
949950 buf = "";
950- if (ctrl == null) return false;
951+ init_buf = "";
952+ if (ctrl == null) return false;
951953 string strID = CSResID.MakeIDString("IDC_", name);
952954 API.LBS style = (API.LBS)API.GetWindowLong(ctrl, API.GWL.GWL_STYLE) & API.LBS.MASK;
953955 string notStyle = CSRCWindow.GetNotStyleString(ctrl);
@@ -957,7 +959,13 @@
957959 , ctrl, null, strID, CSRCWindow.MakeStyleString(style.ToString(), notStyle));
958960 buf += CRLF;
959961
960- return true;
962+ foreach (var item in ctrl.Items)
963+ {
964+ string text = item.ToString();
965+
966+ init_func.ListBox_AddString(strID, text);
967+ }
968+ return true;
961969 }
962970 #endregion
963971
@@ -1136,10 +1144,12 @@
11361144 class CSRCListView
11371145 {
11381146 #region Serialize
1139- public static bool Serialize(Form form, ListView ctrl, string name, CSResID resIDs, out string buf)
1140- {
1147+ public static bool Serialize(Form form, ListView ctrl, string name, CSResID resIDs
1148+ , out string buf, out string init_buf, ref CSRCDlgInitFunction init_func)
1149+ {
11411150 buf = "";
1142- if (ctrl == null) return false;
1151+ init_buf = "";
1152+ if (ctrl == null) return false;
11431153 RES.WS style = (RES.WS)API.GetWindowLong(ctrl, API.GWL.GWL_STYLE);
11441154 API.LVS ctrlstyle = (API.LVS)style & API.LVS.MASK;
11451155 style &= RES.WS.MASK;
@@ -1153,6 +1163,33 @@
11531163 strStyle += style.ToString().Replace(',', '|');
11541164 }
11551165
1166+ string strID = CSResID.MakeIDString("IDC_", name);
1167+ foreach( ColumnHeader col in ctrl.Columns)
1168+ {
1169+ init_func.ListView_InsertColumn(strID, col.Index, (int)col.TextAlign, col.Width, col.Text, col.Index);
1170+ }
1171+ if( ctrl.Groups.Count > 0 )
1172+ {
1173+ foreach (ListViewItem item in ctrl.Items)
1174+ {
1175+ if (item.Group == null)
1176+ {
1177+ init_func.ListView_InsertGroup(strID, 0, 0, "Default");
1178+ break;
1179+ }
1180+ }
1181+ for (int i = 0; i < ctrl.Groups.Count; ++i)
1182+ {
1183+ ListViewGroup group = ctrl.Groups[i];
1184+ init_func.ListView_InsertGroup(strID, i+1, group.GetHashCode(), group.Header);
1185+ }
1186+ }
1187+ foreach (ListViewItem item in ctrl.Items)
1188+ {
1189+ init_func.ListView_InsertItem(strID, item);
1190+ }
1191+ init_func.ListView_EnableGroupView(strID, ctrl.ShowGroups);
1192+
11561193 return CSRCControl.Serialize(form, ctrl, name, resIDs, "SysListView32", strStyle, out buf);
11571194 }
11581195 #endregion
@@ -2216,13 +2253,99 @@
22162253
22172254 public void ComboBox_AddString(string id, string text)
22182255 {
2219- string buf = "SendMessage(GetDlgItem(" + hWndName + ", " + id + "), CB_ADDSTRING, 0, (LPARAM)TEXT(\"" + text + "\"));";
2256+ AddCode("SendMessage(GetDlgItem(" + hWndName + ", " + id + "), CB_ADDSTRING, 0, (LPARAM)TEXT(\"" + text + "\"));");
2257+ }
2258+ public void ListBox_AddString(string id, string text)
2259+ {
2260+ AddCode("SendMessage(GetDlgItem(" + hWndName + ", " + id + "), LB_ADDSTRING, 0, (LPARAM)TEXT(\"" + text + "\"));");
2261+ }
2262+ public void ListView_InsertColumn(string id, int index, int fmt, int cx, string text, int sub)
2263+ {
2264+ AddCode("{");
2265+ string buf = " LVCOLUMN col = { ";
2266+ buf += "LVCF_FMT|LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM";
2267+ buf += ", 0x" + fmt.ToString("X");
2268+ buf += ", " + cx.ToString();
2269+ buf += ", TEXT(\"" + text + "\")";
2270+ buf += ", 0";
2271+ buf += ", " + sub.ToString();
2272+ buf += " };";
22202273 AddCode(buf);
2274+ AddCode(" ListView_InsertColumn(GetDlgItem(" + hWndName + ", " + id + "), " + index.ToString() + ", &col);" + CRLF);
2275+ AddCode("}");
22212276 }
2277+ private void ListView_InsertItem(string id, int index, int indent, string text)
2278+ {
2279+ AddCode(" LVITEM item = {0};");
2280+ AddCode(" item.mask = LVIF_TEXT;");
2281+ AddCode(" item.iItem = " + index.ToString() + ";");
2282+ AddCode(" item.pszText = TEXT(\"" + text + "\");");
2283+ AddDefs("#if (_WIN32_IE >= 0x0300)");
2284+ AddCode(" item.mask |= LVIF_INDENT;");
2285+ AddCode(" item.iIndent = " + indent.ToString() + ";");
2286+ AddDefs("#endif");
2287+ }
2288+ public void ListView_InsertItem(string id, ListViewItem item)
2289+ {
2290+ AddCode("{");
2291+ AddCode(" LVITEM item = {0};");
2292+ AddCode(" item.mask = LVIF_TEXT;");
2293+ AddCode(" item.iItem = " + item.Index.ToString() + ";");
2294+ AddCode(" item.pszText = TEXT(\"" + item.Text + "\");");
2295+ AddDefs("#if (_WIN32_IE >= 0x0300)");
2296+ AddCode(" item.mask |= LVIF_INDENT;");
2297+ AddCode(" item.iIndent = " + item.IndentCount.ToString() + ";");
2298+ AddDefs("#endif");
2299+ if( item.ListView.Groups.Count > 0 )
2300+ {
2301+ AddDefs("#if (_WIN32_IE >= 0x0560)");
2302+ AddCode(" item.mask |= LVIF_GROUPID;");
2303+ if (item.Group != null)
2304+ {
2305+ AddCode(" item.iGroupId = " + item.Group.GetHashCode() + ";");
2306+ }
2307+ else
2308+ {
2309+ AddCode(" item.iGroupId = 0;");
2310+ }
2311+ AddDefs("#endif");
2312+ }
2313+ AddCode(" ListView_InsertItem(GetDlgItem(" + hWndName + ", " + id + "), &item);");
2314+ for (int i = 1; i < item.SubItems.Count; ++i)
2315+ {
2316+ ListViewItem.ListViewSubItem sub = item.SubItems[i];
2317+ ListView_SetItem(id, item.Index, i, sub.Text);
2318+ }
2319+ AddCode("}");
2320+ }
2321+ public void ListView_SetItem(string id, int index, int sub, string text)
2322+ {
2323+ AddCode("");
2324+ AddCode(" item.mask = LVIF_TEXT;");
2325+ AddCode(" item.iItem = " + index.ToString() + ";");
2326+ AddCode(" item.iSubItem = " + sub.ToString() + ";");
2327+ AddCode(" item.pszText = TEXT(\"" + text + "\");");
2328+ AddCode(" ListView_SetItem(GetDlgItem(" + hWndName + ", " + id + "), &item);");
2329+ }
2330+ public void ListView_InsertGroup(string id, int index, int groupId, string text)
2331+ {
2332+ AddCode("{");
2333+ AddCode(" LVGROUP group = {0};");
2334+ AddCode(" group.cbSize = sizeof(LVGROUP);");
2335+ AddCode(" group.mask = LVGF_HEADER | LVGF_GROUPID;");
2336+ AddCode(" group.iGroupId = " + groupId.ToString() + ";");
2337+ AddCode(" group.pszHeader = TEXT(\"" + text + "\");");
2338+ AddCode(" ListView_InsertGroup(GetDlgItem(" + hWndName + ", " + id + "), " + index.ToString() + ", &group);");
2339+ AddCode("}");
2340+ }
2341+ public void ListView_EnableGroupView(string id, bool enable)
2342+ {
2343+ AddCode("ListView_EnableGroupView(GetDlgItem(" + hWndName + ", " + id + "), " + (enable ? "TRUE" : "FALSE") + ");");
2344+ }
2345+
22222346 public void SetText(string id, string text)
22232347 {
2224- string buf = "SetDlgItemText(" + hWndName + ", " + id + ", TEXT(\"" + Regex.Escape(text) + "\"));";
2225- AddCode(buf);
2348+ AddCode("SetDlgItemText(" + hWndName + ", " + id + ", TEXT(\"" + Regex.Escape(text) + "\"));");
22262349 }
22272350
22282351 public void AddCode(string code)
@@ -2232,6 +2355,12 @@
22322355 m_code += CRLF;
22332356 }
22342357
2358+ public void AddDefs(string code)
2359+ {
2360+ m_code += code;
2361+ m_code += CRLF;
2362+ }
2363+
22352364 public string GetCode()
22362365 {
22372366 string buf = "void " + FunctionName + "(" + FunctionArguments + ")";
--- trunk/TestForm/Form1.Designer.cs (revision 11)
+++ trunk/TestForm/Form1.Designer.cs (revision 12)
@@ -29,6 +29,15 @@
2929 private void InitializeComponent()
3030 {
3131 this.components = new System.ComponentModel.Container();
32+ System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("ListViewGroup", System.Windows.Forms.HorizontalAlignment.Left);
33+ System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
34+ "Hoge",
35+ "X",
36+ "Y",
37+ "Z"}, -1);
38+ System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
39+ "Fuga",
40+ "Fuga"}, -1);
3241 this.IDCANCEL = new System.Windows.Forms.Button();
3342 this.button2 = new System.Windows.Forms.Button();
3443 this.IDOK = new System.Windows.Forms.Button();
@@ -45,6 +54,9 @@
4554 this.tabPage2 = new System.Windows.Forms.TabPage();
4655 this.listBox1 = new System.Windows.Forms.ListBox();
4756 this.listView1 = new System.Windows.Forms.ListView();
57+ this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
58+ this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
59+ this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
4860 this.treeView1 = new System.Windows.Forms.TreeView();
4961 this.textBox2 = new System.Windows.Forms.TextBox();
5062 this.textBox3 = new System.Windows.Forms.TextBox();
@@ -230,15 +242,42 @@
230242 //
231243 // listView1
232244 //
233- this.listView1.Location = new System.Drawing.Point(137, 408);
245+ this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
246+ this.columnHeader1,
247+ this.columnHeader2,
248+ this.columnHeader3});
249+ listViewGroup1.Header = "ListViewGroup";
250+ listViewGroup1.Name = "listViewGroup1";
251+ this.listView1.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {
252+ listViewGroup1});
253+ listViewItem2.Group = listViewGroup1;
254+ this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
255+ listViewItem1,
256+ listViewItem2});
257+ this.listView1.Location = new System.Drawing.Point(405, 304);
234258 this.listView1.Name = "listView1";
235- this.listView1.Size = new System.Drawing.Size(121, 88);
259+ this.listView1.Size = new System.Drawing.Size(217, 192);
236260 this.listView1.TabIndex = 12;
237261 this.listView1.UseCompatibleStateImageBehavior = false;
262+ this.listView1.View = System.Windows.Forms.View.Details;
238263 //
264+ // columnHeader1
265+ //
266+ this.columnHeader1.Text = "A";
267+ //
268+ // columnHeader2
269+ //
270+ this.columnHeader2.Text = "B";
271+ this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
272+ //
273+ // columnHeader3
274+ //
275+ this.columnHeader3.Text = "C";
276+ this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
277+ //
239278 // treeView1
240279 //
241- this.treeView1.Location = new System.Drawing.Point(264, 408);
280+ this.treeView1.Location = new System.Drawing.Point(281, 304);
242281 this.treeView1.Name = "treeView1";
243282 this.treeView1.Size = new System.Drawing.Size(118, 88);
244283 this.treeView1.TabIndex = 13;
@@ -265,7 +304,7 @@
265304 // textBox4
266305 //
267306 this.textBox4.AcceptsReturn = true;
268- this.textBox4.Location = new System.Drawing.Point(388, 408);
307+ this.textBox4.Location = new System.Drawing.Point(163, 304);
269308 this.textBox4.Multiline = true;
270309 this.textBox4.Name = "textBox4";
271310 this.textBox4.Size = new System.Drawing.Size(112, 88);
@@ -489,6 +528,9 @@
489528 private System.Windows.Forms.ToolStripMenuItem tesuto2ToolStripMenuItem;
490529 private System.Windows.Forms.ToolStripMenuItem テスト3ToolStripMenuItem;
491530 private System.Windows.Forms.MaskedTextBox maskedTextBox1;
531+ private System.Windows.Forms.ColumnHeader columnHeader1;
532+ private System.Windows.Forms.ColumnHeader columnHeader2;
533+ private System.Windows.Forms.ColumnHeader columnHeader3;
492534 }
493535 }
494536
--- trunk/TestForm/Form2.Designer.cs (revision 11)
+++ trunk/TestForm/Form2.Designer.cs (revision 12)
@@ -99,7 +99,7 @@
9999 this.richTextBox1.Name = "richTextBox1";
100100 this.richTextBox1.Size = new System.Drawing.Size(100, 96);
101101 this.richTextBox1.TabIndex = 5;
102- this.richTextBox1.Text = "";
102+ this.richTextBox1.Text = "abcde";
103103 //
104104 // trackBar1
105105 //
旧リポジトリブラウザで表示