예제 #1
0
        // -1 on error
        static int GetRebarBandIndexByChildHandle(IntPtr hwndRebar, IntPtr hwndChild)
        {
            Win32.REBARBANDINFO band = new Win32.REBARBANDINFO();
            band.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(band);
            int count = (int)Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_GETBANDCOUNT, 0, 0);

            for (int i = 0; i < count; ++i)
            {
                band.fMask     = Win32.RBBIM_CHILD;
                band.hwndChild = IntPtr.Zero;
                Win32.SendMessage(hwndRebar, Win32.RB_GETBANDINFOW, i, ref band);

                if (band.hwndChild == hwndChild)
                {
                    return(i);
                }
            }

            return(-1);
        }
예제 #2
0
        /*public bool IsToolbarVisible()
         *      {
         *              return IntPtr.Zero != Win32.SendMessage(
         *                      PluginBase.nppData._nppHandle,
         *                      NppMsg.NPPM_ISTOOLBARHIDDEN,
         *                      0,
         *                      0);
         *      }*/

        public void CheckToolbarVisiblity()
        {
            if (currentlyCheckingToolbarVisiblity)
            {
                return;
            }

            try
            {
                currentlyCheckingToolbarVisiblity = true;
                if (!Win32.IsWindow(hwndRebar) || !Win32.IsWindow(hwndToolbar))
                {
                    InitToolbar();

                    Win32.SetWindowLong(
                        Handle,
                        Win32.GWL_STYLE,
                        Win32.WS_CHILD | Win32.GetWindowLong(Handle, Win32.GWL_STYLE));
                }

                Win32.REBARBANDINFO band = new Win32.REBARBANDINFO();
                band.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(band);

                bool show         = false; //Win32.IsWindowVisible(hwndToolbar);
                int  toolbarIndex = GetRebarBandIndexByChildHandle(hwndRebar, hwndToolbar);
                if (toolbarIndex >= 0)
                {
                    band.fMask = Win32.RBBIM_STYLE;
                    Win32.SendMessage(hwndRebar, Win32.RB_GETBANDINFOW, toolbarIndex, ref band);
                    show = (band.fStyle & Win32.RBBS_HIDDEN) == 0;
                }

                if (show == Visible)
                {
                    return;
                }

                int oldPreferredWidth = Main.PreferredToolbarWidth;
                int searchBarIndex    = GetRebarBandIndexByChildHandle(hwndRebar, Handle);
                if (searchBarIndex >= 0)
                {
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_SHOWBAND, searchBarIndex, show ? 1 : 0);
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MINIMIZEBAND, searchBarIndex, 0);
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MAXIMIZEBAND, searchBarIndex, 1);
                    return;
                }

                // not yet inserted

                band.fMask      = Win32.RBBIM_CHILD | Win32.RBBIM_SIZE | Win32.RBBIM_IDEALSIZE | Win32.RBBIM_CHILDSIZE;
                band.fStyle     = Win32.RBBS_GRIPPERALWAYS;
                band.hwndChild  = Handle;
                band.cx         = Size.Width;
                band.cxMinChild = 120;
                band.cxIdeal    = 0;
                band.cyMinChild = frmSearch.Height;
                band.cyMaxChild = frmSearch.Height;
                band.cyChild    = 0;
                band.cyIntegral = 0;

                Width = band.cxMinChild;

                if (!show)
                {
                    band.fStyle |= Win32.RBBS_HIDDEN;
                }

                searchBarIndex = (int)Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_GETBANDCOUNT, 0, 0);
                Win32.SendMessage(hwndRebar, Win32.RB_INSERTBANDW, searchBarIndex, ref band);

                if (searchBarIndex > 0 && show)
                {
                    //Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MINIMIZEBAND, searchBarIndex - 1, 0);
                    //Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MAXIMIZEBAND, searchBarIndex - 1, 1);

                    band.fMask = Win32.RBBIM_SIZE | Win32.RBBIM_IDEALSIZE | Win32.RBBIM_CHILDSIZE | Win32.RBBIM_HEADERSIZE;
                    Win32.SendMessage(hwndRebar, Win32.RB_GETBANDINFOW, searchBarIndex, ref band);

                    // needs to be > cxMinChild, otherwise RB_MAXIMIZEBAND will maximize to fill width
                    band.cxIdeal = Math.Max(oldPreferredWidth - (Width - band.cxMinChild), band.cxMinChild + 1);
                    Win32.SendMessage(hwndRebar, Win32.RB_SETBANDINFOW, searchBarIndex, ref band);

                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MINIMIZEBAND, searchBarIndex, 0);
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MAXIMIZEBAND, searchBarIndex, 1);
                }

                Win32.SendMessage(txtSearch.Handle, (NppMsg)Win32.EM_SETCUEBANNER, 0, "Search Menu & Preferences (Ctrl+M)");
            }
            finally
            {
                currentlyCheckingToolbarVisiblity = false;
            }
        }
예제 #3
0
        /*public bool IsToolbarVisible()
         *      {
         *              return IntPtr.Zero != Win32.SendMessage(
         *                      PluginBase.nppData._nppHandle,
         *                      NppMsg.NPPM_ISTOOLBARHIDDEN,
         *                      0,
         *                      0);
         *      }*/

        public void CheckToolbarVisiblity()
        {
            if (currentlyCheckingToolbarVisiblity)
            {
                return;
            }

            try
            {
                currentlyCheckingToolbarVisiblity = true;
                if (!Win32.IsWindow(hwndRebar) || !Win32.IsWindow(HwndToolbar))
                {
                    InitToolbar();

                    Win32.SetWindowLong(
                        Handle,
                        Win32.GWL_STYLE,
                        Win32.WS_CHILD | Win32.GetWindowLong(Handle, Win32.GWL_STYLE));
                }

                Win32.REBARBANDINFO band = new Win32.REBARBANDINFO();
                band.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(band);

                bool show         = false; //Win32.IsWindowVisible(hwndToolbar);
                int  toolbarIndex = GetRebarBandIndexByChildHandle(hwndRebar, HwndToolbar);
                if (toolbarIndex >= 0)
                {
                    band.fMask = Win32.RBBIM_STYLE;
                    Win32.SendMessage(hwndRebar, Win32.RB_GETBANDINFOW, toolbarIndex, ref band);
                    show = (band.fStyle & Win32.RBBS_HIDDEN) == 0;
                }

                if (show == Visible)
                {
                    return;
                }

                int oldPreferredWidth = Main.PreferredToolbarWidth;
                int searchBarIndex    = GetRebarBandIndexByChildHandle(hwndRebar, Handle);
                if (searchBarIndex >= 0)
                {
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_SHOWBAND, searchBarIndex, show ? 1 : 0);
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MINIMIZEBAND, searchBarIndex, 0);
                    Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_MAXIMIZEBAND, searchBarIndex, 1);
                    return;
                }

                // not yet inserted

                band.fMask      = Win32.RBBIM_CHILD | Win32.RBBIM_SIZE | Win32.RBBIM_IDEALSIZE | Win32.RBBIM_CHILDSIZE;
                band.fStyle     = Win32.RBBS_GRIPPERALWAYS;
                band.hwndChild  = Handle;
                band.cx         = Size.Width;
                band.cxMinChild = 120;
                band.cxIdeal    = 0;
                band.cyMinChild = frmSearch.Height;
                band.cyMaxChild = frmSearch.Height;
                band.cyChild    = 0;
                band.cyIntegral = 0;

                Width = band.cxMinChild;

                if (!show)
                {
                    band.fStyle |= Win32.RBBS_HIDDEN;
                }

                searchBarIndex = (int)Win32.SendMessage(hwndRebar, (NppMsg)Win32.RB_GETBANDCOUNT, 0, 0);
                Win32.SendMessage(hwndRebar, Win32.RB_INSERTBANDW, searchBarIndex, ref band);

                if (searchBarIndex > 0 && show)
                {
                    Win32.SendMessage(hwndRebar, Win32.RB_SETBANDWIDTH, searchBarIndex, oldPreferredWidth);
                    int extraMargin = Width - oldPreferredWidth;
                    if (extraMargin > 0 && extraMargin < oldPreferredWidth)
                    {
                        Win32.SendMessage(hwndRebar, Win32.RB_SETBANDWIDTH, searchBarIndex, oldPreferredWidth - extraMargin);
                    }
                }

                string cuebanner = "Search Menu & Preferences";
                string shortcut  = Main.GetMenuSearchShortcut();
                if (shortcut != "")
                {
                    cuebanner = string.Format("{0} ({1})", cuebanner, shortcut);
                }
                Win32.SendMessage(txtSearch.Handle, (NppMsg)Win32.EM_SETCUEBANNER, 0, cuebanner);
            }
            finally
            {
                currentlyCheckingToolbarVisiblity = false;
            }
        }