public void MonthCalendarChildAccessibleObject_RuntimeId_HasThreeExpectedItems()
        {
            using MonthCalendar control = new MonthCalendar();

            control.CreateControl();
            MonthCalendarAccessibleObject      controlAccessibleObject = (MonthCalendarAccessibleObject)control.AccessibilityObject;
            MonthCalendarChildAccessibleObject accessibleObject        = new SubObject(controlAccessibleObject);

            Assert.Equal(3, accessibleObject.RuntimeId.Length);
            Assert.Equal(AccessibleObject.RuntimeIDFirstItem, accessibleObject.RuntimeId[0]);
            Assert.Equal(PARAM.ToInt(control.Handle), accessibleObject.RuntimeId[1]);
            Assert.Equal(accessibleObject.GetChildId(), accessibleObject.RuntimeId[2]);
            Assert.True(control.IsHandleCreated);
        }
 private int DisplayIndexToID(int displayIndex)
 {
     Debug.Assert(!owner.VirtualMode, "in virtual mode, this method does not make any sense");
     if (owner.IsHandleCreated && !owner.ListViewHandleDestroyed)
     {
         // Obtain internal index of the item
         var lvItem = new LVITEMW
         {
             mask  = LVIF.PARAM,
             iItem = displayIndex
         };
         User32.SendMessageW(owner, (User32.WM)LVM.GETITEMW, IntPtr.Zero, ref lvItem);
         return(PARAM.ToInt(lvItem.lParam));
     }
     else
     {
         return(this[displayIndex].ID);
     }
 }
Esempio n. 3
0
        protected override bool ProcessKeyEventArgs(ref Message m)
        {
            switch ((Keys)PARAM.ToInt(m.WParam))
            {
            case Keys.Enter:
                if (m.Msg == (int)User32.WM.CHAR &&
                    !(ModifierKeys == Keys.Shift && Multiline && AcceptsReturn))
                {
                    // Ignore the Enter key and don't add it to the textbox content. This happens when failing validation brings
                    // up a dialog box for example.
                    // Shift-Enter for multiline textboxes need to be accepted however.
                    return(true);
                }

                break;

            case Keys.LineFeed:
                if (m.Msg == (int)User32.WM.CHAR &&
                    ModifierKeys == Keys.Control && Multiline && AcceptsReturn)
                {
                    // Ignore linefeed character when user hits Ctrl-Enter to commit the cell.
                    return(true);
                }

                break;

            case Keys.A:
                if (m.Msg == (int)User32.WM.KEYDOWN && ModifierKeys == Keys.Control)
                {
                    SelectAll();
                    return(true);
                }

                break;
            }

            return(base.ProcessKeyEventArgs(ref m));
        }
            BOOL IMsoComponentManager.FPushMessageLoop(
                UIntPtr dwComponentID,
                msoloop uReason,
                void *pvLoopData)
            {
                // Hold onto old state to allow restore before we exit...
                msocstate currentLoopState = _currentState;
                BOOL      continueLoop     = BOOL.TRUE;

                if (!OleComponents.TryGetValue(dwComponentID, out ComponentHashtableEntry entry))
                {
                    return(BOOL.FALSE);
                }

                IMsoComponent prevActive = _activeComponent;

                try
                {
                    User32.MSG    msg = new User32.MSG();
                    IMsoComponent requestingComponent = entry.component;
                    _activeComponent = requestingComponent;

                    Debug.WriteLineIf(
                        CompModSwitches.MSOComponentManager.TraceInfo,
                        $"ComponentManager : Pushing message loop {uReason}");
                    Debug.Indent();

                    while (continueLoop.IsTrue())
                    {
                        // Determine the component to route the message to
                        IMsoComponent component = _trackingComponent ?? _activeComponent ?? requestingComponent;

                        bool useAnsi = false;
                        BOOL peeked  = User32.PeekMessageW(ref msg);

                        if (peeked.IsTrue())
                        {
                            useAnsi = msg.hwnd != IntPtr.Zero && User32.IsWindowUnicode(msg.hwnd).IsFalse();
                            if (useAnsi)
                            {
                                peeked = User32.PeekMessageA(ref msg);
                            }
                        }

                        if (peeked.IsTrue())
                        {
                            continueLoop = component.FContinueMessageLoop(uReason, pvLoopData, &msg);

                            // If the component wants us to process the message, do it.
                            if (continueLoop.IsTrue())
                            {
                                if (useAnsi)
                                {
                                    User32.GetMessageA(ref msg);
                                    Debug.Assert(User32.IsWindowUnicode(msg.hwnd).IsFalse());
                                }
                                else
                                {
                                    User32.GetMessageW(ref msg);
                                    Debug.Assert(msg.hwnd == IntPtr.Zero || User32.IsWindowUnicode(msg.hwnd).IsTrue());
                                }

                                if (msg.message == User32.WM.QUIT)
                                {
                                    Debug.WriteLineIf(
                                        CompModSwitches.MSOComponentManager.TraceInfo,
                                        "ComponentManager : Normal message loop termination");

                                    ThreadContext.FromCurrent().DisposeThreadWindows();

                                    if (uReason != msoloop.Main)
                                    {
                                        User32.PostQuitMessage(PARAM.ToInt(msg.wParam));
                                    }

                                    continueLoop = BOOL.FALSE;
                                    break;
                                }

                                // Now translate and dispatch the message.
                                //
                                // Reading through the rather sparse documentation,
                                // it seems we should only call FPreTranslateMessage
                                // on the active component.
                                if (component.FPreTranslateMessage(&msg).IsFalse())
                                {
                                    User32.TranslateMessage(ref msg);
                                    if (useAnsi)
                                    {
                                        User32.DispatchMessageA(ref msg);
                                    }
                                    else
                                    {
                                        User32.DispatchMessageW(ref msg);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // If this is a DoEvents loop, then get out. There's nothing left for us to do.
                            if (uReason == msoloop.DoEvents || uReason == msoloop.DoEventsModal)
                            {
                                break;
                            }

                            // Nothing is on the message queue. Perform idle processing and then do a WaitMessage.
                            bool continueIdle = false;

                            if (OleComponents is not null)
                            {
                                foreach (ComponentHashtableEntry idleEntry in OleComponents.Values)
                                {
                                    continueIdle |= idleEntry.component.FDoIdle(msoidlef.All).IsTrue();
                                }
                            }

                            // Give the component one more chance to terminate the message loop.
                            continueLoop = component.FContinueMessageLoop(uReason, pvLoopData, null);

                            if (continueLoop.IsTrue())
                            {
                                if (continueIdle)
                                {
                                    // If someone has asked for idle time, give it to them.  However,
                                    // don't cycle immediately; wait up to 100ms.  Why?  Because we don't
                                    // want someone to attach to idle, forget to detach, and then cause
                                    // CPU to end up in race condition.  For Windows Forms this generally isn't an issue because
                                    // our component always returns false from its idle request
                                    User32.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, User32.QS.ALLINPUT, User32.MWMO.INPUTAVAILABLE);
                                }
                                else
                                {
                                    // We should call GetMessage here, but we cannot because
                                    // the component manager requires that we notify the
                                    // active component before we pull the message off the
                                    // queue.  This is a bit of a problem, because WaitMessage
                                    // waits for a NEW message to appear on the queue.  If a
                                    // message appeared between processing and now WaitMessage
                                    // would wait for the next message.  We minimize this here
                                    // by calling PeekMessage.
                                    if (User32.PeekMessageW(ref msg, IntPtr.Zero, 0, 0, User32.PM.NOREMOVE).IsFalse())
                                    {
                                        User32.WaitMessage();
                                    }
                                }
                            }
                        }
                    }

                    Debug.Unindent();
                    Debug.WriteLineIf(CompModSwitches.MSOComponentManager.TraceInfo, $"ComponentManager : message loop {uReason} complete.");
                }
                finally
                {
                    _currentState    = currentLoopState;
                    _activeComponent = prevActive;
                }

                return(continueLoop.IsFalse() ? BOOL.TRUE : BOOL.FALSE);
            }
Esempio n. 5
0
 public unsafe void ToInt_x32_Result()
 {
     Assert.Equal((int)0x01020304, PARAM.ToInt((nint)0x01020304));
     Assert.Equal(unchecked ((int)0xF1F2F3F4), PARAM.ToInt(unchecked ((nint)0xF1F2F3F4)));
 }
Esempio n. 6
0
 public unsafe void ToInt_x64_Result()
 {
     Assert.Equal((int)0x01020304, PARAM.ToInt(unchecked ((nint)0x0506070801020304)));
     Assert.Equal(unchecked ((int)0xF1F2F3F4), PARAM.ToInt(unchecked ((nint)0xF5F6F7F8F1F2F3F4)));
 }