Community
    • Login

    How to check if NPP is in rtl or ltr direction?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    rtlsci handle
    4 Posts 2 Posters 2.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ezra SteinmetzE
      Ezra Steinmetz
      last edited by

      Hi
      I’m in the middle of developing a plugin that will remember the text direction for each tab/file and will switch to the right direction when the file is reopened or the user switches back to the tab.
      In order to do that my plugin needs to know at a given moment whether NPP is currently in rtl or ltr.
      I tried to ‘steal’ the following function form NPP’s source code:
      bool isTextDirectionRTL()
      {
      long exStyle = static_cast<long>(::GetWindowLongPtr(nppData._scintillaMainHandle, GWL_EXSTYLE));
      return (exStyle & WS_EX_LAYOUTRTL) != 0;
      }
      It worked for a while but after doing some additional tests I saw that it doesn’t always work. (I guess it has something to do with the fact that the ‘main handle’ doesn’t always point to the required scintilla or something like that)

      For now I’ve decided to create a keyboard shortcut that will call a function in my plugin that will change the text direction (and ask the user to change text direction only this way), this way my plugin can monitor and keep track of the text direction, if anybody knows about a better solution I’d be glad to here.

      1 Reply Last reply Reply Quote 0
      • YaronY
        Yaron
        last edited by

        Hello Ezra,

        You should check first whether the current view is MAIN_VIEW or SUB_VIEW.

        inline HWND getCurrentView()
        {
        	return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ?
        			nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
        }
        

        (From NppHelpers.h in Compare Plugin. Thank you @pnedev).

        And then:

        bool isTextDirectionRTL() const
        {
        	long exStyle = static_cast<long>(::GetWindowLongPtr(getCurrentView(), GWL_EXSTYLE));
        	return (exStyle & WS_EX_LAYOUTRTL) != 0;
        }
        

        This plugin would be important to RTL users.
        Thank you and best of luck.


        How about adding an option to set the default text direction to LTR even if NPP layout is RTL?

        1 Reply Last reply Reply Quote 0
        • Ezra SteinmetzE
          Ezra Steinmetz
          last edited by

          Thanks, that worked!

          1 Reply Last reply Reply Quote 0
          • YaronY
            Yaron
            last edited by

            Great.
            You’re welcome.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors