public void TestEmulateChangeItemEventAsync()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1038));
     LVITEM item = new LVITEM();
     item.iItem = 1;
     item.mask = LVIF.TEXT;
     item.pszText = "zzz";
     Async async = new Async();
     list.EmulateChangeItem(item, async);
     Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
 }
 public void TestEmulateChangeStateEvent()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
         delegate { list.EmulateChangeItemState(2, LVIS.FOCUSED, LVIS.FOCUSED); },
         new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ITEMCHANGING),
         new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ITEMCHANGED)
     ));
 }
 public void TestEmulateChangeItemEvent()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
         delegate
         {
             LVITEM item = new LVITEM();
             item.iItem = 1;
             item.mask = LVIF.TEXT;
             item.pszText = "zzz";
             list.EmulateChangeItem(item); 
         },
         new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ITEMCHANGING),
         new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ITEMCHANGED)
     ));
 }
 /// <summary>
 /// カラム設定
 /// </summary>
 /// <param name="list">リストコントロール</param>
 /// <param name="col">カラムデータ</param>
 /// <param name="text">テキスト</param>
 private void SetLVCOLUMN(NativeListControl list, LVCOLUMN_CORE col, string text)
 {
     if (text != null)
     {
         col.pszText = isUni ? (IntPtr)app[typeof(Marshal), "StringToCoTaskMemUni"](text).Core :
                                   (IntPtr)app[typeof(Marshal), "StringToCoTaskMemAnsi"](text).Core;
     }
     int LVM_SETCOLUMN = isUni ? LVM_SETCOLUMNW : LVM_SETCOLUMNA;
     app["Codeer.Friendly.Windows.NativeStandardControls.Inside.NativeMethods.SendMessage"](list.Handle, LVM_SETCOLUMN, new IntPtr(col.iSubItem), col);
     if (text != null)
     {
         app[typeof(Marshal), "FreeCoTaskMem"](col.pszText);
     }
 }
 public void TestTopIndexAndEnsureVisible()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     list.EnsureVisible(list.ItemCount - 1, false);
     Assert.AreEqual(((isUni && OSUtility.Is7or8()) ? 90 : 87), list.TopIndex);
 }
 public void TestFindItem()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     Assert.AreEqual(2, list.FindItem(0, 0, "2-0"));
     Assert.AreEqual(2, list.FindItem(2, 0, "2-0"));
     Assert.AreEqual(-1, list.FindItem(3, 0, "2-0"));
 }
        public void TestGetColumnOver256()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
            StringBuilder overText = new StringBuilder();
            for (int i = 0; i < 259; i++)//ツリーの文字数最大がデフォルトで259。
            {
                overText.Append((i % 10).ToString());
            }

            //設定
            LVCOLUMN_CORE setData = new LVCOLUMN_CORE();
            setData.mask = (int)LVCF.TEXT;
            setData.iSubItem = 0;
            SetLVCOLUMN(list, setData, overText.ToString());

            //取得
            LVCOLUMN getData = new LVCOLUMN();
            getData.mask = LVCF.TEXT;
            list.GetColumn(0, getData);
            Assert.AreEqual(overText.ToString(), getData.pszText);
        }
        public void TestItemRect()
        {
            if (!OSUtility.Is7or8())
            {
                //矩形は環境によって変わるので7のみ。しかし、7なら常に同じ矩形とも限らない。
                //このテストデータが使えるOSの設定は限られる。
                return;
            }

            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
            list.EnsureVisible(list.ItemCount - 1, false);
            if (isUni)
            {
                //GetItemRect
                Assert.AreEqual(new Rectangle(4, 177, 97, 18), list.GetItemRect(list.ItemCount - 1, LVIR.LABEL));

                //GetSubItemRect
                Assert.AreEqual(new Rectangle(100, 177, 102, 18), list.GetSubItemRect(list.ItemCount - 1, 1, LVIR.LABEL));
            }
            else
            {
                //GetItemRect
                Assert.AreEqual(new Rectangle(2, 185, 99, 15), list.GetItemRect(list.ItemCount - 1, LVIR.LABEL));

                //GetSubItemRect
                Assert.AreEqual(new Rectangle(100, 185, 102, 15), list.GetSubItemRect(list.ItemCount - 1, 1, LVIR.LABEL));
            }
        }
        public void TestEdit()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
            list.EmulateEdit(list.ItemCount - 1, "xxx");
            Assert.AreEqual("xxx", list.GetItemText(list.ItemCount - 1, 0));

            //非同期でも同様の効果があることを確認。
            Async a = new Async();
            list.EmulateEdit(list.ItemCount - 1, "yyy", a);
            while (!a.IsCompleted)
            {
                Thread.Sleep(10);
            }
            Assert.AreEqual("yyy", list.GetItemText(list.ItemCount - 1, 0));
        }
 public void TestItemData()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     Assert.AreEqual(new IntPtr(10), list.GetItemData(10));
 }
 public void TestItemText()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     Assert.AreEqual("10-1", list.GetItemText(10, 1));
 }
        public void TestState()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
            list.EmulateChangeItemState(3, LVIS.FOCUSED, LVIS.FOCUSED);
            Assert.AreEqual(list.GetItemState(3, LVIS.FOCUSED), LVIS.FOCUSED);

            //非同期でも同様の効果があることを確認。
            Async a = new Async();
            list.EmulateChangeItemState(5, LVIS.FOCUSED, LVIS.FOCUSED, a);
            a.WaitForCompletion();
            Assert.AreEqual(list.GetItemState(5, LVIS.FOCUSED), LVIS.FOCUSED);
        }
        public void TestSelect()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
            list.EmulateSelect(1, true);
            list.EmulateSelect(5, true);
            AssertEx.AreEqual(list.SelectedIndices, new int[] { 1, 5 });

            //非同期でも同様の効果があることを確認。
            Async a = new Async();
            list.EmulateSelect(5, false, a);
            while (!a.IsCompleted)
            {
                Thread.Sleep(10);
            }
            AssertEx.AreEqual(list.SelectedIndices, new int[] { 1 });
        }
 public void TestView()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     Assert.AreEqual(View.Details, list.View);
 }
 public void TestEmulateSelectEventAsync()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1038));
     Async async = new Async();
     list.EmulateSelect(2, true, async);
     Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
 }
        public void TestCancelEdit()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));

            //編集状態にする。
            list.SetFocus();
            int LVM_EDITLABEL = isUni ? LVM_EDITLABELW : LVM_EDITLABELA;
            list.SetFocus();
            list.SendMessage(LVM_EDITLABEL, new IntPtr(0), IntPtr.Zero);
            new WindowControl(list.App, list.SendMessage(LVM_GETEDITCONTROL, IntPtr.Zero, IntPtr.Zero)).SetWindowText("test");

            //キャンセル。
            list.EmulateCancelEdit();
            Assert.AreEqual("0-0", list.GetItemText(0, 0));
        }
 public void TestEmulateChangeStateAsync()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1038));
     Async async = new Async();
     list.EmulateChangeItemState(2, LVIS.FOCUSED, LVIS.FOCUSED, async);
     Assert.IsTrue(0 < MessageBoxUtility.CloseAll(testDlg, async));
 }
        public void TestGetColumn()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
            LVCOLUMN_CORE setData = new LVCOLUMN_CORE();
            LVCOLUMN column = new LVCOLUMN();
            foreach (LVCF element in (LVCF[])Enum.GetValues(typeof(LVCF)))
            {
                setData.mask |= (int)element;
                column.mask |= element;
            }

            //検証データを設定
            setData.fmt = 0x4802;
            setData.cx = 30;
            setData.iSubItem = 1;
            setData.iImage = 2;
            setData.iOrder = 1;
            setData.cxMin = 20;
            setData.cxDefault = 25;
            setData.cxIdeal = 30;
            SetLVCOLUMN(list, setData, "abc");

            //取得
            list.GetColumn(1, column);
            
            //比較
            Assert.AreEqual(setData.fmt, column.fmt);
            Assert.AreEqual(setData.cx, column.cx);
            Assert.AreEqual("abc", column.pszText); 
            Assert.AreEqual(setData.iSubItem, column.iSubItem);
            Assert.AreEqual(setData.iImage, column.iImage);
            Assert.AreEqual(setData.iOrder, column.iOrder);
            if (isUni && OSUtility.Is7or8())
            {
                Assert.AreEqual(setData.cxMin, column.cxMin);
                Assert.AreEqual(setData.cxDefault, column.cxDefault);
                Assert.AreEqual(setData.cxIdeal, column.cxIdeal);
            }
        }
 public void TestGetItemTextOver256()
 {
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     StringBuilder overText = new StringBuilder();
     for (int i = 0; i < 259; i++)//ツリーの文字数最大がデフォルトで259。
     {
         overText.Append((i % 10).ToString());
     }
     list.EmulateEdit(0, overText.ToString());
     Assert.AreEqual(overText.ToString(), list.GetItemText(0, 0));
 }
        public void TestSetGetItem()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));

            LVITEM setData = new LVITEM();
            LVITEM getData = new LVITEM();
            foreach (LVIF element in (LVIF[])Enum.GetValues(typeof(LVIF)))
            {
                setData.mask |= element;
                getData.mask |= element;
            }
            foreach (LVIS element in (LVIS[])Enum.GetValues(typeof(LVIS)))
            {
                setData.stateMask |= element;
                getData.stateMask |= element;
            }

            //アイテムの変更
            setData.iItem = 2;
            setData.iSubItem = 0;
            setData.state = LVIS.CUT;
            setData.pszText = "abc";
            setData.iImage = 2;
            setData.lParam = new IntPtr(3);
            list.EmulateChangeItem(setData);

            //変更結果の確認
            getData.iItem = 2;
            getData.iSubItem = 0;
            list.GetItem(getData);
            Assert.AreEqual(setData.iItem, getData.iItem);
            Assert.AreEqual(setData.iSubItem, getData.iSubItem);
            Assert.AreEqual(setData.state, getData.state);
            Assert.AreEqual(setData.pszText, getData.pszText);
            Assert.AreEqual(setData.iImage, getData.iImage);
            Assert.AreEqual(setData.lParam, getData.lParam);

            //非同期でも同様の効果があることを確認。
            Async a = new Async();
            setData.pszText = "efg";
            list.EmulateChangeItem(setData, a);
            while (!a.IsCompleted)
            {
                Thread.Sleep(10);
            }
            list.GetItem(getData);
            Assert.AreEqual(setData.pszText, getData.pszText);
        }
 public void TestUniCode()
 {
     if (!isUni)
     {
         return;
     }
     NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
     list.EmulateEdit(0, "𩸽");
     Assert.AreEqual("𩸽", list.GetItemText(0, 0));
 }
        public void TestEmulateEditEvent()
        {
            NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));

            //同期実行。LVN_BEGINLABELEDIT,LVN_ENDLABELEDITが発生していることを確認。
            int LVN_BEGINLABELEDIT = isUni ? LVN_BEGINLABELEDITW : LVN_BEGINLABELEDITA;
            int LVN_ENDLABELEDIT = isUni ? LVN_ENDLABELEDITW : LVN_ENDLABELEDITA;
            Assert.IsTrue(EventChecker.IsSameTestEvent(testDlg,
                delegate { list.EmulateEdit(3, "###"); },
                //無視
                new CodeInfo[]
                {
                    new CodeInfo(0, NativeMethods.WM_COMMAND, EN_SETFOCUS),
                    new CodeInfo(0, NativeMethods.WM_COMMAND, EN_UPDATE),
                    new CodeInfo(0, NativeMethods.WM_COMMAND, EN_CHANGE),
                    new CodeInfo(1, NativeMethods.WM_COMMAND, EN_SETFOCUS),
                    new CodeInfo(1, NativeMethods.WM_COMMAND, EN_UPDATE),
                    new CodeInfo(1, NativeMethods.WM_COMMAND, EN_CHANGE),
                    new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ITEMCHANGING),
                    new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ITEMCHANGED)
                },
                //確認
                new CodeInfo[]
                {
                    new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_BEGINLABELEDIT),
                    new CodeInfo(1037, NativeMethods.WM_NOTIFY, LVN_ENDLABELEDIT)
                }
                ));
        }
 public void TestConstructor()
 {
     //WindowControlから作成。
     {
         NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
         Assert.AreEqual(100, list.ItemCount);
     }
     //ハンドルから作成。
     {
         NativeListControl list = new NativeListControl(app, testDlg.IdentifyFromDialogId(1037).Handle);
         Assert.AreEqual(100, list.ItemCount);
     }
 }
 public void TestItemCount()
 {
      NativeListControl list = new NativeListControl(testDlg.IdentifyFromDialogId(1037));
      Assert.AreEqual(100, list.ItemCount);
 }