{"id":3580,"date":"2014-04-27T06:13:17","date_gmt":"2014-04-27T14:13:17","guid":{"rendered":"http:\/\/keithcu.com\/wordpress\/?p=3580"},"modified":"2014-04-30T15:47:32","modified_gmt":"2014-04-30T23:47:32","slug":"shipping-the-libreoffice-hidpi-patches-or-how-i-learned-to-love-heartbleed","status":"publish","type":"post","link":"https:\/\/keithcu.com\/wordpress\/?p=3580","title":{"rendered":"Shipping LibreOffice HiDPI Patches, or How I Learned to Love Heartbleed"},"content":{"rendered":"<p>I wrote my story about getting some <a href=\"http:\/\/keithcu.com\/wordpress\/?p=3444\">HiDPI patches into LibreOffice<\/a>, but it was an unfinished one because while the code had gotten accepted into the main Master branch, there was a lot remaining. It hadn&#8217;t shipped, I&#8217;d only tested it on Gnome and KDE, it hadn&#8217;t been tried on Windows, and didn\u2019t work on the Mac. Worst of all, because it missed the December 20 cutoff date for 4.2.0, it was on the default next release train for 4.3.0 in late July.<\/p>\n<p>LibreOffice has a two-part release process. You are encouraged to submit code into the main tree where it can sit for up to 6 months. Twice per year, it is branched and shipped. In between these major releases, every month or so, a minor release is made containing high priority fixes. Meanwhile most of the development team moves ahead adding features and cleanup for the upcoming release.<\/p>\n<p>The code was too late for 4.2.0, and so it wasn&#8217;t getting much feedback. Very few people run the daily builds, with all the releases and release-candidates to test. A friendly chap named Darcy from Australia showed up on the QA alias, built LibreOffice on his Fedora 20 laptop, and <a href=\"http:\/\/nabble.documentfoundation.org\/Libreoffice-qa-HiDPI-testing-for-LibreOffice-4-2-1-tp4095055p4096402.html\">verified that it worked<\/a>, but that was it. The only way to get this code tested was to get it out there.<\/p>\n<p>I had also decided to stop working after the second batch. I had improved the most noticeable parts of the product, but I was also steadily making more potential problems for myself. Software isn&#8217;t just about code, it is about standing behind your work. I could prove <i><span style=\"font-weight: normal;\">most <\/span><\/i>of my changes were fine, but I was changing places where I didn&#8217;t always understand what was going on around. I could justify my fixes, but not the code around it.<\/p>\n<p>Even though LibreOffice is built by a community where other people can <i>fix<\/i> your bugs, other people can also<i> <\/i><i>find<\/i> your bugs. If your code is causing problems, and no one has time to look into it, it can be reverted. The work is interesting, but I was just a motivated user with some free time during the Christmas holiday. I wanted to reserve time to deal with the inevitable complaints.<\/p>\n<p>In spite of the lack of feedback, since it makes a visual and usability difference, why wait? More computers with these beautiful screens are coming out every day. A very high-resolution screen is the best reason to buy a new laptop. There should be a free software experience that we can enjoy looking at. LibreOffice has plenty of ways to improve, but it can look good in the meanwhile.<\/p>\n<h1 class=\"western\">Sidebar<\/h1>\n<p>The Sidebar was one of the areas I had kept putting off and almost didn&#8217;t work on. It is about 70,000 lines of new code providing an alternate UI, and I wanted to focus on the existing one first. I have been using this codebase for almost 10 years and had never missed it. The code was also written by someone from IBM, and so I couldn&#8217;t trust that anyone in LibreOffice would be able to help me.<\/p>\n<p>I also hoped that maybe the Apache team would notice bug reports and fix the Sidebar themselves. LibreOffice grabs fixes from Apache on a daily basis. Only about half the changes are useful because in many cases LibreOffice has already done the work, but any pieces of value are ported over, and just a small part of LibreOffice&#8217;s churn of the their thousands of improvements per release.<\/p>\n<p>I considered sending an email to the Apache OpenOffice alias asking if they were aware of the problem, and whether they were planning to work on it. It is more efficient to coordinate efforts and not have multiple people re-learning each other&#8217;s work. It took me hours to fix problems that could have been fixed over lunch by the person who wrote the code. However, while LibreOffice is taking patches from Apache OpenOffice, the groups are generally not actively planning work, and so asking for HiDPI support for the Sidebar would have been a breach of protocol.<\/p>\n<p>In addition, the codebases are diverging so fixes might not be usable. Apache OpenOffice doesn&#8217;t have the OutputDevice::DPIScaleFactor API, so the patches wouldn&#8217;t have been directly usable. I didn\u2019t try Apache OpenOffice on Linux, but I did try it on Windows 8.1 and sidebar bitmaps looked doubled. However, Windows 8.1 might have been artificially scaling the entire Apache OpenOffice UI because the text was a blurry mess compared to LibreOffice:<br \/>\n<a href=\"http:\/\/keithcu.com\/wordpress\/wp-content\/uploads\/2014\/04\/OOLO2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3584\" src=\"http:\/\/keithcu.com\/wordpress\/wp-content\/uploads\/2014\/04\/OOLO2.png\" alt=\"OOLO2\" width=\"560\" height=\"220\" \/><\/a><br \/>\nSo I could imagine that fixing the Sidebar for LibreOffice would not be a high priority for Apache.<\/p>\n<p>While I personally don&#8217;t care about the Sidebar, it is now turned on by default for Impress. I knew that the more places I fixed, the stronger argument I would have to convince people to get the improvements out there. I realized I just needed to motivate myself to learn the code. So while I was in rural northern Michigan with my family over the holiday, there were some quiet nights, and I dug in and learned the Sidebar well enough to fix the major issues. It was the same process and techniques I had used for the other parts of the code. As per usual, finding the correct place to put in a fix was the hardest part.<\/p>\n<p>I&#8217;m glad I worked on it because not only did it make the Sidebar fit in visually with the other improvements, it fixed a crashing bug. LibreOffice&#8217;s Sidebar is better than OpenOffice&#8217;s in that it has dynamic layout when docked. However, the bigger buttons created something wider than the maximum width allowed. With the sidebar starting in an invalid state, the product would still work, but if you tried to resize it with the mouse, you could sometimes get LibreOffice to hang. If you push software beyond its limits, bad things can happen.<\/p>\n<p>I don\u2019t even remember clearly how I found the place to fix, but by just reading enough code, I found the routine SidebarController::RestrictWidth.<\/p>\n<pre>@@<span class=\"operator\"> -<\/span><span class=\"int\">1109<\/span><span class=\"operator\">,<\/span><span class=\"int\">7<\/span><span class=\"operator\"> +<\/span><span class=\"int\">1112<\/span><span class=\"operator\">,<\/span><span class=\"int\">8<\/span> @@<span class=\"type\"> void<\/span> SidebarController<span class=\"operator\">::<\/span>RestrictWidth<span class=\"operator\"> (<\/span>sal_Int32 nWidth<span class=\"operator\">)<\/span><span class=\"keyword\">\r\nconst<\/span> sal_uInt16 nSetId<span class=\"operator\"> (<\/span>pSplitWindow<span class=\"operator\">-&gt;<\/span>GetSet<span class=\"operator\">(<\/span>nId<span class=\"operator\">));<\/span>\r\n\tpSplitWindow<span class=\"operator\">-&gt;<\/span>SetItemSizeRange<span class=\"operator\">(<\/span>nSetId<span class=\"operator\">,\r\n-<\/span> \tRange<span class=\"operator\">(<\/span>TabBar<span class=\"operator\">::<\/span>GetDefaultWidth<span class=\"operator\">() +<\/span> nWidth<span class=\"operator\">,<\/span> gnMaximumSidebarWidth<span class=\"operator\">));\r\n+<\/span> \tRange<span class=\"operator\">(<\/span>TabBar<span class=\"operator\">::<\/span>GetDefaultWidth<span class=\"operator\">() *<\/span> mpTabBar<span class=\"operator\">-&gt;<\/span>GetDPIScaleFactor<span class=\"operator\">() +<\/span> nWidth<span class=\"operator\">,\r\n+<\/span> \tgnMaximumSidebarWidth<span class=\"operator\"> *<\/span> mpTabBar<span class=\"operator\">-&gt;<\/span>GetDPIScaleFactor<span class=\"operator\">()));\r\n\t}\r\n}<\/span><\/pre>\n<h1>Getting on the 4.2.3 release train<\/h1>\n<p>Since it was a batch of new code to a stable branch, the LibreOffice Engineering Steering Committee had a <a href=\"http:\/\/nabble.documentfoundation.org\/minutes-of-ESC-call-td4097864.html\">discussion<\/a> about it in one of their weekly meetings:<\/p>\n<pre><span class=\"operator\">*<\/span> HiDPI patches<span class=\"flow\"> for<\/span><span class=\"float\"> 4.2<\/span><span class=\"operator\">.<\/span>x<span class=\"operator\">? (<\/span>Kendy<span class=\"operator\">)\r\n    +<\/span> LibreOffice does<span class=\"operator\"> not<\/span> look good on HiDPI screens at all<span class=\"operator\"> -<\/span> close to unusable<span class=\"operator\">\r\n    +<\/span> proposal to merge the HiDPI work to<span class=\"float\"> 4.2<\/span><span class=\"operator\">.<\/span>x as a late feature<span class=\"operator\">\r\n        +<\/span> I would split the work into<span class=\"char\"> 'safe'<\/span><span class=\"operator\"> and<\/span><span class=\"char\"> 'need real review'<\/span> parts<span class=\"operator\"> &amp;<\/span> push to a branch<span class=\"operator\">\r\n        +<\/span> can I get ESC approval<span class=\"operator\"> \/<\/span><span class=\"int\"> 3<\/span> independent reviews<span class=\"flow\"> for<\/span> that<span class=\"operator\"> ?\r\n    +<\/span> is it a feature<span class=\"operator\"> or<\/span> a bug<span class=\"operator\">-<\/span>fix<span class=\"operator\"> ? (<\/span>Michael<span class=\"operator\">)\r\n        +<\/span> most of the pieces going in enclosed in an<span class=\"flow\"> if<\/span><span class=\"operator\"> (<\/span>hidpi<span class=\"operator\">) ...\r\n            +<\/span> checking that everything in the right<span class=\"flow\"> if<\/span><span class=\"operator\">.\r\n        +<\/span> less safe part is checking<span class=\"operator\"> \/<\/span> setting that flag<span class=\"operator\">;<\/span> a small VCL piece<span class=\"operator\">.\r\n    +<\/span> Michael<span class=\"operator\"> \/<\/span> Caol\u00e1n<span class=\"type\"> signed<\/span> up to review as<span class=\"operator\">\/<\/span>when there is a branch<span class=\"operator\">.<\/span><\/pre>\n<p>Once they gave their support, Kendy prepared for the patches for review.<\/p>\n<p><span style=\"font-weight: normal;\">Working with free software can be fun, but it can also be upsetting because problems can show up at any time. <\/span>I was happy to see Kendy&#8217;s mail to the alias asking for review of the Gerrit patches, but not for very long because Norbert Thiebaud objected to them for the Mac. So after <a href=\"http:\/\/nabble.documentfoundation.org\/Hi-DPI-patches-for-4-2-td4100852.html\">a flurry of emails over 3 days<\/a>, we eventually got that resolved <a href=\"https:\/\/gerrit.libreoffice.org\/#\/c\/8560\/\">with another patch<\/a>. So within a few days after that, the patches got reviewed and into the build for 4.2.3-rc1.<\/p>\n<h1 class=\"western\">Windows<\/h1>\n<p>I was happy to see my efforts finally get into RC build, but I wasn&#8217;t happy for very long because this screenshot with clipped toolbar buttons showed up in my inbox:<\/p>\n<p><a href=\"http:\/\/i.imgur.com\/NADAvYi.png\"><img decoding=\"async\" class=\"alignnone\" src=\"http:\/\/i.imgur.com\/NADAvYi.png\" alt=\"\" height=\"449\" \/><\/a><\/p>\n<p><span style=\"font-weight: normal;\">This was upsetting for several reasons. The first is that it could have been found on master months before. Instead, it showed up on a day when I had my own things to work on. But instead of being able to focus on my tasks, I kept thinking about the toolbars, and what was I going to do about it?<\/span><\/p>\n<p><span style=\"font-weight: normal;\">I had been wondering for months what would happen when this code was tried on Windows. LibreOffice is created primarily by Linux developers, but Windows is the most popular OS for their users. My machine shipped with Windows but I had wiped it within a few hours and so couldn&#8217;t try it. I had used Windows for 15 years, but the last time was 9 years ago and I had no plans to go back.<\/span><\/p>\n<p><span style=\"font-weight: normal;\">I had envisioned various possibilities for what might happen on Windows, but cut-off toolbar buttons was not one of them. <\/span>I also didn\u2019t understand the toolbar layout code. I had written a toolbar manager before and didn\u2019t want to volunteer any of my life on that boring problem.<\/p>\n<p>However, I felt bad and that I should at least put some effort into trying to fix the problem. So that evening, I decided to just read through the toolbar code from beginning to end and see if I found anything obviously wrong. You don&#8217;t have to be very clever to notice a bloody knife at a murder scene.<\/p>\n<p>And so I read through toolbox.cxx, including the toolbar layout code, and didn\u2019t notice anything that stood out. So I next went to toolbox2.cxx. About halfway down, I found something suspicious:<\/p>\n<pre><span class=\"comment\">\/*static*\/<\/span> Size\r\nToolBox<span class=\"operator\">::<\/span>GetDefaultImageSize<span class=\"operator\">(<\/span><span class=\"type\">bool<\/span> bLarge<span class=\"operator\">)\r\n{<\/span><span class=\"keyword\">\r\n    const<\/span><span class=\"type\"> long<\/span> TB_SMALLIMAGESIZE<span class=\"operator\"> =<\/span><span class=\"int\" style=\"color: #ff0000;\"> 16<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n    if<\/span><span class=\"operator\"> (!<\/span>bLarge<span class=\"operator\">) {<\/span><span class=\"flow\">\r\n        return<\/span> Size<span class=\"operator\">(<\/span>TB_SMALLIMAGESIZE<span class=\"operator\">,<\/span> TB_SMALLIMAGESIZE<span class=\"operator\">);\r\n    }<\/span>\r\n\r\n    OUString iconTheme<span class=\"operator\"> =<\/span> Application<span class=\"operator\">::<\/span>GetSettings<span class=\"operator\">().<\/span>GetStyleSettings<span class=\"operator\">().<\/span>DetermineIconTheme<span class=\"operator\">();<\/span><span class=\"flow\">\r\n    return<\/span> vcl<span class=\"operator\">::<\/span>IconThemeInfo<span class=\"operator\">::<\/span>SizeByThemeName<span class=\"operator\">(<\/span>iconTheme<span class=\"operator\">);\r\n}<\/span>\r\n<\/pre>\n<p>That 16 was a sign of a place that needed doubling. I didn&#8217;t yet know who used that function and whether it would make a difference, but opengrok helped me and found that it was called by the main toolbar layout routine.<\/p>\n<p>So I made a change:<\/p>\n<pre><span class=\"int\">1738<\/span><span class=\"comment\">     \/\/ set defaults if image or text is needed but empty\r\n<\/span><span class=\"int\">1739<\/span>     nDefWidth<span class=\"operator\">       =<\/span> GetDefaultImageSize<span class=\"operator\">().<\/span>Width<span class=\"operator\">() <span style=\"color: #ff0000;\">*<\/span><\/span> <span style=\"color: #ff0000;\">GetDPIScaleFactor<\/span><span class=\"operator\"><span style=\"color: #ff0000;\">()<\/span>;<\/span><span class=\"int\">\r\n1740<\/span>     nDefHeight<span class=\"operator\">      =<\/span> GetDefaultImageSize<span class=\"operator\">().<\/span>Height<span class=\"operator\">() <span style=\"color: #ff0000;\">*<\/span><\/span> <span style=\"color: #ff0000;\">GetDPIScaleFactor<\/span><span class=\"operator\"><span style=\"color: #ff0000;\">()<\/span>;<\/span>\r\n<\/pre>\n<p>However, I couldn\u2019t tell whether it would fix the problem. The comment above the code, while happily in English, explained it was relevant only for empty toolbars. This was not a case I care about.<\/p>\n<p>So I changed the code, and hoped the comment was wrong, but didn&#8217;t understand what the implication was. It was a change I would try if I had a Windows box. It requires much less mental effort to test a change than to manually prove what happens in a big function. As long as you can test something, you can postpone the necessity of full understanding.<\/p>\n<p>Here is the main toolbar layout routine. I\u2019ve highlighted in red all the references to the variable I changed.<\/p>\n<pre><span class=\"type\">bool<\/span> ToolBox<span class=\"operator\">::<\/span>ImplCalcItem<span class=\"operator\">()\r\n{<\/span><span class=\"comment\">\r\n\r\n    \/\/ recalc required ?\r\n<\/span><span class=\"flow\">    if<\/span><span class=\"operator\"> ( !<\/span>mbCalc<span class=\"operator\"> )<\/span><span class=\"flow\">\r\n        return<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;<\/span>\r\n\r\n    ImplDisableFlatButtons<span class=\"operator\">();<\/span><span class=\"type\">\r\n\r\n    long<\/span>            nDefWidth<span class=\"operator\">;<\/span><span class=\"type\">\r\n    long<\/span>            nDefHeight<span class=\"operator\">;<\/span><span class=\"type\">\r\n    long<\/span>            nMaxWidth<span class=\"operator\"> =<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">;<\/span><span class=\"type\">\r\n    long<\/span>            nMaxHeight<span class=\"operator\"> =<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">;<\/span><span class=\"type\">\r\n    long<\/span>            nMinWidth<span class=\"operator\">   =<\/span><span class=\"int\"> 6<\/span><span class=\"operator\">;<\/span><span class=\"type\">\r\n    long<\/span>            nMinHeight<span class=\"operator\">  =<\/span><span class=\"int\"> 6<\/span><span class=\"operator\">;<\/span><span class=\"type\">\r\n    long<\/span>            nDropDownArrowWidth<span class=\"operator\"> =<\/span> TB_DROPDOWNARROWWIDTH<span class=\"operator\">;<\/span><span class=\"comment\">\r\n\r\n    \/\/ set defaults if image or text is needed but empty\r\n<\/span>    <span style=\"color: #ff0000;\">nDefWidth<\/span><span class=\"operator\">       =<\/span> GetDefaultImageSize<span class=\"operator\">().<\/span>Width<span class=\"operator\">() <span style=\"color: #ff0000;\">*<\/span><\/span><span style=\"color: #ff0000;\"> GetDPIScaleFactor<\/span><span class=\"operator\"><span style=\"color: #ff0000;\">()<\/span>;<\/span>\r\n    <span style=\"color: #ff0000;\">nDefHeight<\/span><span class=\"operator\">      =<\/span> GetDefaultImageSize<span class=\"operator\">().<\/span>Height<span class=\"operator\">() <span style=\"color: #ff0000;\">*<\/span><\/span><span style=\"color: #ff0000;\"> GetDPIScaleFactor<\/span><span class=\"operator\"><span style=\"color: #ff0000;\">()<\/span>;<\/span>\r\n\r\n    mnWinHeight<span class=\"operator\"> =<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">;<\/span><span class=\"comment\">\r\n    \/\/ determine minimum size necessary in NWF\r\n<\/span><span class=\"operator\">    {<\/span>\r\n        Rectangle aRect<span class=\"operator\">(<\/span> Point<span class=\"operator\">(<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">,<\/span><span class=\"int\"> 0<\/span><span class=\"operator\"> ),<\/span> Size<span class=\"operator\">(<\/span> nMinWidth<span class=\"operator\">,<\/span> nMinHeight<span class=\"operator\"> ) );<\/span>\r\n        Rectangle aReg<span class=\"operator\">(<\/span> aRect<span class=\"operator\"> );<\/span>\r\n        ImplControlValue aVal<span class=\"operator\">;<\/span>\r\n        Rectangle aNativeBounds<span class=\"operator\">,<\/span> aNativeContent<span class=\"operator\">;<\/span><span class=\"flow\">\r\n        if<\/span><span class=\"operator\">(<\/span> IsNativeControlSupported<span class=\"operator\">(<\/span> CTRL_TOOLBAR<span class=\"operator\">,<\/span> PART_BUTTON<span class=\"operator\"> ) )\r\n        {<\/span><span class=\"flow\">\r\n            if<\/span><span class=\"operator\">(<\/span> GetNativeControlRegion<span class=\"operator\">(<\/span> CTRL_TOOLBAR<span class=\"operator\">,<\/span> PART_BUTTON<span class=\"operator\">,<\/span>\r\n                                        aReg<span class=\"operator\">,<\/span>\r\n                                        CTRL_STATE_ENABLED<span class=\"operator\"> |<\/span> CTRL_STATE_ROLLOVER<span class=\"operator\">,<\/span>\r\n                                        aVal<span class=\"operator\">,<\/span> OUString<span class=\"operator\">(),<\/span>\r\n                                        aNativeBounds<span class=\"operator\">,<\/span> aNativeContent<span class=\"operator\"> ) )\r\n            {<\/span>\r\n                aRect<span class=\"operator\"> =<\/span> aNativeBounds<span class=\"operator\">;<\/span><span class=\"flow\">\r\n                if<\/span><span class=\"operator\">(<\/span> aRect<span class=\"operator\">.<\/span>GetWidth<span class=\"operator\">() &gt;<\/span> nMinWidth<span class=\"operator\"> )<\/span>\r\n                    nMinWidth<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">.<\/span>GetWidth<span class=\"operator\">();<\/span><span class=\"flow\">\r\n                if<\/span><span class=\"operator\">(<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">() &gt;<\/span> nMinHeight<span class=\"operator\"> )<\/span>\r\n                    nMinHeight<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">();<\/span><span class=\"flow\">\r\n                if<\/span><span class=\"operator\">(<\/span> nDropDownArrowWidth<span class=\"operator\"> &lt;<\/span> nMinWidth<span class=\"operator\"> )<\/span>\r\n                    nDropDownArrowWidth<span class=\"operator\"> =<\/span> nMinWidth<span class=\"operator\">;<\/span><span class=\"flow\">\r\n                if<\/span><span class=\"operator\">(<\/span> nMinWidth<span class=\"operator\"> &gt;<\/span> mpData<span class=\"operator\">-&gt;<\/span>mnMenuButtonWidth<span class=\"operator\"> )<\/span>\r\n                    mpData<span class=\"operator\">-&gt;<\/span>mnMenuButtonWidth<span class=\"operator\"> =<\/span> nMinWidth<span class=\"operator\">;<\/span><span class=\"flow\">\r\n                else if<\/span><span class=\"operator\">(<\/span> nMinWidth<span class=\"operator\"> &lt;<\/span> TB_MENUBUTTON_SIZE<span class=\"operator\"> )<\/span>\r\n                    mpData<span class=\"operator\">-&gt;<\/span>mnMenuButtonWidth<span class=\"operator\"> =<\/span> TB_MENUBUTTON_SIZE<span class=\"operator\">;\r\n            }\r\n        }<\/span><span class=\"comment\">\r\n\r\n        \/\/ also calculate the area for comboboxes, drop down list boxes and spinfields\r\n        \/\/ as these are often inserted into toolboxes; set mnWinHeight to the\r\n        \/\/ greater of those values to prevent toolbar flickering (#i103385#)\r\n<\/span>        aRect<span class=\"operator\"> =<\/span> Rectangle<span class=\"operator\">(<\/span> Point<span class=\"operator\">(<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">,<\/span><span class=\"int\"> 0<\/span><span class=\"operator\"> ),<\/span> Size<span class=\"operator\">(<\/span> nMinWidth<span class=\"operator\">,<\/span> nMinHeight<span class=\"operator\"> ) );<\/span>\r\n        aReg<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">;<\/span><span class=\"flow\">\r\n        if<\/span><span class=\"operator\">(<\/span> GetNativeControlRegion<span class=\"operator\">(<\/span> CTRL_COMBOBOX<span class=\"operator\">,<\/span> PART_ENTIRE_CONTROL<span class=\"operator\">,<\/span>\r\n                                    aReg<span class=\"operator\">,<\/span>\r\n                                    CTRL_STATE_ENABLED<span class=\"operator\"> |<\/span> CTRL_STATE_ROLLOVER<span class=\"operator\">,<\/span>\r\n                                    aVal<span class=\"operator\">,<\/span> OUString<span class=\"operator\">(),<\/span>\r\n                                    aNativeBounds<span class=\"operator\">,<\/span> aNativeContent<span class=\"operator\"> ) )\r\n        {<\/span>\r\n            aRect<span class=\"operator\"> =<\/span> aNativeBounds<span class=\"operator\">;<\/span><span class=\"flow\">\r\n            if<\/span><span class=\"operator\">(<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">() &gt;<\/span> mnWinHeight<span class=\"operator\"> )<\/span>\r\n                mnWinHeight<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">();\r\n        }<\/span>\r\n        aRect<span class=\"operator\"> =<\/span> Rectangle<span class=\"operator\">(<\/span> Point<span class=\"operator\">(<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">,<\/span><span class=\"int\"> 0<\/span><span class=\"operator\"> ),<\/span> Size<span class=\"operator\">(<\/span> nMinWidth<span class=\"operator\">,<\/span> nMinHeight<span class=\"operator\"> ) );<\/span>\r\n        aReg<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">;<\/span><span class=\"flow\">\r\n        if<\/span><span class=\"operator\">(<\/span> GetNativeControlRegion<span class=\"operator\">(<\/span> CTRL_LISTBOX<span class=\"operator\">,<\/span> PART_ENTIRE_CONTROL<span class=\"operator\">,<\/span>\r\n                                    aReg<span class=\"operator\">,<\/span>\r\n                                    CTRL_STATE_ENABLED<span class=\"operator\"> |<\/span> CTRL_STATE_ROLLOVER<span class=\"operator\">,<\/span>\r\n                                    aVal<span class=\"operator\">,<\/span> OUString<span class=\"operator\">(),<\/span>\r\n                                    aNativeBounds<span class=\"operator\">,<\/span> aNativeContent<span class=\"operator\"> ) )\r\n        {<\/span>\r\n            aRect<span class=\"operator\"> =<\/span> aNativeBounds<span class=\"operator\">;<\/span><span class=\"flow\">\r\n            if<\/span><span class=\"operator\">(<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">() &gt;<\/span> mnWinHeight<span class=\"operator\"> )<\/span>\r\n                mnWinHeight<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">();\r\n        }<\/span>\r\n        aRect<span class=\"operator\"> =<\/span> Rectangle<span class=\"operator\">(<\/span> Point<span class=\"operator\">(<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">,<\/span><span class=\"int\"> 0<\/span><span class=\"operator\"> ),<\/span> Size<span class=\"operator\">(<\/span> nMinWidth<span class=\"operator\">,<\/span> nMinHeight<span class=\"operator\"> ) );<\/span>\r\n        aReg<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">;<\/span><span class=\"flow\">\r\n        if<\/span><span class=\"operator\">(<\/span> GetNativeControlRegion<span class=\"operator\">(<\/span> CTRL_SPINBOX<span class=\"operator\">,<\/span> PART_ENTIRE_CONTROL<span class=\"operator\">,<\/span>\r\n                                    aReg<span class=\"operator\">,<\/span>\r\n                                    CTRL_STATE_ENABLED<span class=\"operator\"> |<\/span> CTRL_STATE_ROLLOVER<span class=\"operator\">,<\/span>\r\n                                    aVal<span class=\"operator\">,<\/span> OUString<span class=\"operator\">(),<\/span>\r\n                                    aNativeBounds<span class=\"operator\">,<\/span> aNativeContent<span class=\"operator\"> ) )\r\n        {<\/span>\r\n            aRect<span class=\"operator\"> =<\/span> aNativeBounds<span class=\"operator\">;<\/span><span class=\"flow\">\r\n            if<\/span><span class=\"operator\">(<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">() &gt;<\/span> mnWinHeight<span class=\"operator\"> )<\/span>\r\n                mnWinHeight<span class=\"operator\"> =<\/span> aRect<span class=\"operator\">.<\/span>GetHeight<span class=\"operator\">();\r\n        }\r\n    }<\/span><span class=\"flow\">\r\n\r\n    if<\/span><span class=\"operator\"> ( !<\/span> mpData<span class=\"operator\">-&gt;<\/span>m_aItems<span class=\"operator\">.<\/span>empty<span class=\"operator\">() )\r\n    {<\/span>\r\n        std<span class=\"operator\">::<\/span>vector<span class=\"operator\">&lt;<\/span> ImplToolItem<span class=\"operator\"> &gt;::<\/span>iterator it<span class=\"operator\"> =<\/span> mpData<span class=\"operator\">-&gt;<\/span>m_aItems<span class=\"operator\">.<\/span>begin<span class=\"operator\">();<\/span><span class=\"flow\">\r\n        while<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\"> !=<\/span> mpData<span class=\"operator\">-&gt;<\/span>m_aItems<span class=\"operator\">.<\/span>end<span class=\"operator\">() )\r\n        {<\/span><span class=\"type\">\r\n            bool<\/span> bImage<span class=\"operator\">;<\/span><span class=\"type\">\r\n            bool<\/span> bText<span class=\"operator\">;<\/span><span class=\"comment\">\r\n\r\n\t     \/\/ indicates if text will definitely be drawn, influences dropdown pos\r\n<\/span>            it<span class=\"operator\">-&gt;<\/span>mbVisibleText<span class=\"operator\"> =<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n\r\n            if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>meType<span class=\"operator\"> ==<\/span> TOOLBOXITEM_BUTTON<span class=\"operator\"> )\r\n            {<\/span><span class=\"comment\">\r\n                \/\/ check if image and\/or text exists\r\n<\/span><span class=\"flow\">                if<\/span><span class=\"operator\"> ( !(<\/span>it<span class=\"operator\">-&gt;<\/span>maImage<span class=\"operator\">) )<\/span>\r\n                    bImage<span class=\"operator\"> =<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n                else<\/span>\r\n                    bImage<span class=\"operator\"> =<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n                if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>maText<span class=\"operator\">.<\/span>isEmpty<span class=\"operator\">() )<\/span>\r\n                    bText<span class=\"operator\"> =<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n                else<\/span>\r\n                    bText<span class=\"operator\"> =<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;<\/span><span class=\"comment\">\r\n\t\t \/\/ default to toolbox setting\r\n<\/span>                ButtonType tmpButtonType<span class=\"operator\"> =<\/span> determineButtonType<span class=\"operator\">( &amp;(*<\/span>it<span class=\"operator\">),<\/span> meButtonType<span class=\"operator\"> );<\/span><span class=\"flow\"> \r\n                if<\/span><span class=\"operator\"> (<\/span> bImage<span class=\"operator\"> ||<\/span> bText<span class=\"operator\"> )\r\n                {<\/span>\r\n\r\n                    it<span class=\"operator\">-&gt;<\/span>mbEmptyBtn<span class=\"operator\"> =<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n\r\n                    if<\/span><span class=\"operator\"> (<\/span> tmpButtonType<span class=\"operator\"> ==<\/span> BUTTON_SYMBOL<span class=\"operator\"> )\r\n                    {<\/span><span class=\"comment\">\r\n                        \/\/ we're drawing images only\r\n<\/span><span class=\"flow\">                        if<\/span><span class=\"operator\"> (<\/span> bImage<span class=\"operator\"> || !<\/span>bText<span class=\"operator\"> )\r\n                        {<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maImage<span class=\"operator\">.<\/span>GetSizePixel<span class=\"operator\">();\r\n                        }<\/span><span class=\"flow\">\r\n                        else<\/span><span class=\"operator\">\r\n                        {<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\"> =<\/span> Size<span class=\"operator\">(<\/span> GetCtrlTextWidth<span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>maText<span class=\"operator\"> )+<\/span>TB_TEXTOFFSET<span class=\"operator\">,<\/span>\r\n                                                   GetTextHeight<span class=\"operator\">() );<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>mbVisibleText<span class=\"operator\"> =<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;\r\n                        }\r\n                    }<\/span><span class=\"flow\">\r\n                    else if<\/span><span class=\"operator\"> (<\/span> tmpButtonType<span class=\"operator\"> ==<\/span> BUTTON_TEXT<span class=\"operator\"> )\r\n                    {<\/span><span class=\"comment\">\r\n                        \/\/ we're drawing text only\r\n<\/span><span class=\"flow\">                        if<\/span><span class=\"operator\"> (<\/span> bText<span class=\"operator\"> || !<\/span>bImage<span class=\"operator\"> )\r\n                        {<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\"> =<\/span> Size<span class=\"operator\">(<\/span> GetCtrlTextWidth<span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>maText<span class=\"operator\"> )+<\/span>TB_TEXTOFFSET<span class=\"operator\">,<\/span>\r\n                                                   GetTextHeight<span class=\"operator\">() );<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>mbVisibleText<span class=\"operator\"> =<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;\r\n                        }<\/span><span class=\"flow\">\r\n                        else<\/span><span class=\"operator\">\r\n                        {<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maImage<span class=\"operator\">.<\/span>GetSizePixel<span class=\"operator\">();\r\n                        }\r\n                    }<\/span><span class=\"flow\">\r\n                    else<\/span><span class=\"operator\">\r\n                    {<\/span><span class=\"comment\">\r\n                        \/\/ we're drawing images and text\r\n<\/span>                        it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() =<\/span> bText<span class=\"operator\"> ?<\/span> GetCtrlTextWidth<span class=\"operator\">(<\/span>it<span class=\"operator\">-&gt;<\/span>maText<span class=\"operator\">)+<\/span>TB_TEXTOFFSET<span class=\"operator\">:<\/span><span class=\"int\">0<\/span><span class=\"operator\">;<\/span>\r\n                        it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() =<\/span> bText<span class=\"operator\"> ?<\/span> GetTextHeight<span class=\"operator\">() :<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">;<\/span><span class=\"comment\">\r\n\r\n                        \/\/ leave space between image and text\r\n<\/span><span class=\"flow\">                        if<\/span><span class=\"operator\">(<\/span> bText<span class=\"operator\"> )<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() +=<\/span> TB_IMAGETEXTOFFSET<span class=\"operator\">;<\/span><span class=\"comment\">\r\n\r\n                        \/\/ image and text side by side\r\n<\/span>                        it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() +=<\/span> it<span class=\"operator\">-&gt;<\/span>maImage<span class=\"operator\">.<\/span>GetSizePixel<span class=\"operator\">().<\/span>Width<span class=\"operator\">();<\/span><span class=\"flow\">\r\n                        if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>maImage<span class=\"operator\">.<\/span>GetSizePixel<span class=\"operator\">().<\/span>Height<span class=\"operator\">() &gt;<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() )<\/span>\r\n                            it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() =<\/span> it<span class=\"operator\">-&gt;<\/span>maImage<span class=\"operator\">.<\/span>GetSizePixel<span class=\"operator\">().<\/span>Height<span class=\"operator\">();<\/span>\r\n\r\n                        it<span class=\"operator\">-&gt;<\/span>mbVisibleText<span class=\"operator\"> =<\/span> bText<span class=\"operator\">;\r\n                    }\r\n                }<\/span><span class=\"flow\">\r\n                else<\/span><span class=\"operator\">\r\n                {<\/span><span class=\"comment\">   \/\/ no image and no text\r\n<\/span>                    it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\"> =<\/span> Size<span class=\"operator\">(<\/span> <span style=\"color: #ff0000;\">nDefWidth<\/span><span class=\"operator\">,<\/span> <span style=\"color: #ff0000;\">nDefHeight<\/span><span class=\"operator\"> );<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>mbEmptyBtn<span class=\"operator\"> =<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;\r\n                }<\/span><span class=\"comment\">\r\n\r\n                \/\/ save the content size\r\n<\/span>                it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">;<\/span><span class=\"comment\">\r\n\r\n                \/\/ if required, take window height into consideration\r\n<\/span><span class=\"flow\">                if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>mpWindow<span class=\"operator\"> )\r\n                {<\/span><span class=\"type\">\r\n                    long<\/span> nHeight<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>mpWindow<span class=\"operator\">-&gt;<\/span>GetSizePixel<span class=\"operator\">().<\/span>Height<span class=\"operator\">();<\/span><span class=\"flow\">\r\n                    if<\/span><span class=\"operator\"> (<\/span> nHeight<span class=\"operator\"> &gt;<\/span> mnWinHeight<span class=\"operator\"> )<\/span>\r\n                        mnWinHeight<span class=\"operator\"> =<\/span> nHeight<span class=\"operator\">;\r\n                }<\/span><span class=\"comment\">\r\n\r\n                \/\/ add in drop down arrow\r\n<\/span><span class=\"flow\">                if<\/span><span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>mnBits<span class=\"operator\"> &amp;<\/span> TIB_DROPDOWN<span class=\"operator\"> )\r\n                {<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() +=<\/span> nDropDownArrowWidth<span class=\"operator\">;<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>mnDropDownArrowWidth<span class=\"operator\"> =<\/span> nDropDownArrowWidth<span class=\"operator\">;\r\n                }<\/span><span class=\"comment\">\r\n\r\n                \/\/ text items will be rotated in vertical mode\r\n                \/\/ -&gt; swap width and height\r\n<\/span><span class=\"flow\">                if<\/span><span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>mbVisibleText<span class=\"operator\"> &amp;&amp; !<\/span>mbHorz<span class=\"operator\"> )\r\n                {<\/span><span class=\"type\">\r\n                    long<\/span> tmp<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">();<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() =<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">();<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() =<\/span> tmp<span class=\"operator\">;<\/span>\r\n\r\n                    tmp<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">();<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() =<\/span> it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">();<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() =<\/span> tmp<span class=\"operator\">;\r\n                }\r\n            }<\/span><span class=\"flow\">\r\n            else if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>meType<span class=\"operator\"> ==<\/span> TOOLBOXITEM_SPACE<span class=\"operator\"> )\r\n            {<\/span>\r\n                it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\"> =<\/span> Size<span class=\"operator\">(<\/span> <span style=\"color: #ff0000;\">nDefWidth<\/span><span class=\"operator\">,<\/span> <span style=\"color: #ff0000;\">nDefHeight<\/span><span class=\"operator\"> );<\/span>\r\n                it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">;\r\n            }<\/span><span class=\"flow\">\r\n\r\n            if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>meType<span class=\"operator\"> ==<\/span> TOOLBOXITEM_BUTTON<span class=\"operator\"> ||<\/span> it<span class=\"operator\">-&gt;<\/span>meType<span class=\"operator\"> ==<\/span> TOOLBOXITEM_SPACE<span class=\"operator\"> )\r\n            {<\/span><span class=\"comment\">\r\n                \/\/ add borders\r\n<\/span>                ImplAddButtonBorder<span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">(),<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">(),<\/span>\r\n\t\t\t\t\tmpData<span class=\"operator\">-&gt;<\/span>mbNativeButtons<span class=\"operator\"> );<\/span><span class=\"flow\">\r\n\r\n                if<\/span><span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>meType<span class=\"operator\"> ==<\/span> TOOLBOXITEM_BUTTON<span class=\"operator\"> )\r\n                {<\/span><span class=\"type\">\r\n                    long<\/span> nMinW<span class=\"operator\"> =<\/span> std<span class=\"operator\">::<\/span>max<span class=\"operator\">(<\/span>nMinWidth<span class=\"operator\">,<\/span> it<span class=\"operator\">-&gt;<\/span>maMinimalItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">());<\/span><span class=\"type\">\r\n                    long<\/span> nMinH<span class=\"operator\"> =<\/span> std<span class=\"operator\">::<\/span>max<span class=\"operator\">(<\/span>nMinHeight<span class=\"operator\">,<\/span> it<span class=\"operator\">-&gt;<\/span>maMinimalItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">());<\/span><span class=\"type\">\r\n\r\n                    long<\/span> nGrowContentWidth<span class=\"operator\"> =<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">;<\/span><span class=\"type\">\r\n                    long<\/span> nGrowContentHeight<span class=\"operator\"> =<\/span><span class=\"int\"> 0<\/span><span class=\"operator\">;<\/span><span class=\"flow\">\r\n\r\n                    if<\/span><span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() &lt;<\/span> nMinW<span class=\"operator\"> )\r\n                    {<\/span>\r\n                        nGrowContentWidth<span class=\"operator\"> =<\/span> nMinW<span class=\"operator\"> -<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">();<\/span>\r\n                        it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() =<\/span> nMinW<span class=\"operator\">;\r\n                    }<\/span><span class=\"flow\">\r\n                    if<\/span><span class=\"operator\">(<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() &lt;<\/span> nMinH<span class=\"operator\"> )\r\n                    {<\/span>\r\n                        nGrowContentHeight<span class=\"operator\"> =<\/span> nMinH<span class=\"operator\"> -<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">();<\/span>\r\n                        it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() =<\/span> nMinH<span class=\"operator\">;\r\n                    }<\/span><span class=\"comment\">\r\n\r\n                    \/\/ grow the content size by the additional available space\r\n<\/span>                    it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() +=<\/span> nGrowContentWidth<span class=\"operator\">;<\/span>\r\n                    it<span class=\"operator\">-&gt;<\/span>maContentSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() +=<\/span> nGrowContentHeight<span class=\"operator\">;\r\n                }<\/span><span class=\"comment\">\r\n\r\n                \/\/ keep track of max item size\r\n<\/span><span class=\"flow\">                if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">() &gt;<\/span> nMaxWidth<span class=\"operator\"> )<\/span>\r\n                    nMaxWidth<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Width<span class=\"operator\">();<\/span><span class=\"flow\">\r\n                if<\/span><span class=\"operator\"> (<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">() &gt;<\/span> nMaxHeight<span class=\"operator\"> )<\/span>\r\n                    nMaxHeight<span class=\"operator\"> =<\/span> it<span class=\"operator\">-&gt;<\/span>maItemSize<span class=\"operator\">.<\/span>Height<span class=\"operator\">();\r\n            }\r\n\r\n            ++<\/span>it<span class=\"operator\">;\r\n        }\r\n    }<\/span><span class=\"flow\">\r\n    else<\/span><span class=\"operator\">\r\n    {<\/span>\r\n        nMaxWidth<span class=\"operator\">  =<\/span> <span style=\"color: #ff0000;\">nDefWidth<\/span><span class=\"operator\">;<\/span>\r\n        nMaxHeight<span class=\"operator\"> =<\/span> <span style=\"color: #ff0000;\">nDefHeight<\/span><span class=\"operator\">;<\/span>\r\n\r\n        ImplAddButtonBorder<span class=\"operator\">(<\/span> nMaxWidth<span class=\"operator\">,<\/span> nMaxHeight<span class=\"operator\">,<\/span> mpData<span class=\"operator\">-&gt;<\/span>mbNativeButtons<span class=\"operator\"> );\r\n    }<\/span><span class=\"flow\">\r\n\r\n    if<\/span><span class=\"operator\">( !<\/span>ImplIsFloatingMode<span class=\"operator\">() &amp;&amp;<\/span> GetToolboxButtonSize<span class=\"operator\">() !=<\/span> TOOLBOX_BUTTONSIZE_DONTCARE<span class=\"operator\"> )\r\n    {<\/span><span class=\"comment\">\r\n        \/\/ make sure all vertical toolbars have the same width and horizontal have the same height\r\n        \/\/ this depends on the used button sizes\r\n        \/\/ as this is used for alignement of multiple toolbars\r\n        \/\/ it is only required for docked toolbars\r\n<\/span><span class=\"type\">\r\n        long<\/span> nFixedWidth<span class=\"operator\"> =<\/span> <span style=\"color: #ff0000;\">nDefWidth<\/span><span class=\"operator\">+<\/span>nDropDownArrowWidth<span class=\"operator\">;<\/span><span class=\"type\">\r\n        long<\/span> nFixedHeight<span class=\"operator\"> =<\/span> <span style=\"color: #ff0000;\">nDefHeight<\/span><span class=\"operator\">;<\/span>\r\n        ImplAddButtonBorder<span class=\"operator\">(<\/span> nFixedWidth<span class=\"operator\">,<\/span> nFixedHeight<span class=\"operator\">,<\/span> mpData<span class=\"operator\">-&gt;<\/span>mbNativeButtons<span class=\"operator\"> );<\/span><span class=\"flow\">\r\n\r\n        if<\/span><span class=\"operator\">(<\/span> mbHorz<span class=\"operator\"> )<\/span>\r\n            nMaxHeight<span class=\"operator\"> =<\/span> nFixedHeight<span class=\"operator\">;<\/span><span class=\"flow\">\r\n        else<\/span>\r\n            nMaxWidth<span class=\"operator\"> =<\/span> nFixedWidth<span class=\"operator\">;\r\n    }<\/span>\r\n\r\n    mbCalc<span class=\"operator\"> =<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;<\/span>\r\n    mbFormat<span class=\"operator\"> =<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;<\/span><span class=\"comment\">\r\n\r\n    \/\/ do we have to recalc the sizes ?\r\n<\/span><span class=\"flow\">    if<\/span><span class=\"operator\"> ( (<\/span>nMaxWidth<span class=\"operator\"> !=<\/span> mnMaxItemWidth<span class=\"operator\">) || (<\/span>nMaxHeight<span class=\"operator\"> !=<\/span> mnMaxItemHeight<span class=\"operator\">) )\r\n    {<\/span>\r\n        mnMaxItemWidth<span class=\"operator\">  =<\/span> nMaxWidth<span class=\"operator\">;<\/span>\r\n        mnMaxItemHeight<span class=\"operator\"> =<\/span> nMaxHeight<span class=\"operator\">;<\/span><span class=\"flow\">\r\n\r\n        return<\/span><span class=\"bool\"> true<\/span><span class=\"operator\">;\r\n    }<\/span><span class=\"flow\">\r\n    else\r\n        return<\/span><span class=\"bool\"> false<\/span><span class=\"operator\">;\r\n}<\/span><\/pre>\n<p>So I looked through the code, but didn&#8217;t understand it and didn&#8217;t want to. However, it was easy to see the change was reasonable and helpful in some cases. So I <a href=\"https:\/\/gerrit.libreoffice.org\/#\/c\/8637\/\">submitted it to Gerrit<\/a> to see if it could get it reviewed and approved. If I can sneak it into a daily build, then maybe I could convince someone to try it out. So I submitted and waited for input. 3 days later, Caol\u00e1n McNamara of Red Hat reviewed and accepted the patch. In fact, Caol\u00e1n appears to be an email alias that 3 developers are attached to. I think Arch is a better distro for me than Fedora, but I am very grateful for the useful investments that Red Hat is making.<\/p>\n<p>Once my patch got into the daily builds, I emailed the tester asking he could try one out, but he replied that he didn&#8217;t have time. So I was stuck and frustrated again. I couldn&#8217;t know if the change fixed the bug, which made me uncomfortable to ask for a patch to be triple-reviewed and back-ported. Blind-fixes to stable branches are generally not a good way to work.<\/p>\n<p>I also didn&#8217;t know how to submit changes to anything other than the master branch. The LibreOffice wiki is great for new developers, but didn&#8217;t cover that specific topic. So I decided to ask Caol\u00e1n if he could submit them to Gerrit to get them in before the 4.2.3 release. Caol\u00e1n did that and even sent me the Git incantations so I can do it in the future.<\/p>\n<p>With some reviews from <span style=\"font-weight: normal;\">Norbert and Miklos Vajna<\/span>, the patch got into the 4.2.3 branch. So I was very happy, but not for very long. Because I soon noticed that the final 4.2.3 RC build had already been made. You can still push changes to the Git branch, but it doesn&#8217;t matter, the digital equivalent of air guitar. It is possible to mark bugs as release critical and delay the release, but this didn&#8217;t meet the bar. I should just have been happy that the issue was likely now fixed, but instead I was upset that after all my stress it had missed the train by a few hours.<\/p>\n<p>However, the Heartbleed bug and a few other important ones showed up, and so another RC was made. I&#8217;m probably the only person on the Internet, other than the NSA, who was happy for Heartbleed.<\/p>\n<h1 class=\"western\">KDE Regression<\/h1>\n<p>Just as LibreOffice 4.2.3 was shipping, <span style=\"font-weight: normal;\"><a href=\"https:\/\/bugs.freedesktop.org\/show_bug.cgi?id=77059\">another bug<\/a> <\/span>showed up from a KDE Ubuntu user:<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/launchpadlibrarian.net\/171457355\/libreOfficeIcons1.png\" alt=\"\" \/><\/p>\n<p>Someone with a 1920&#215;1080 15.6\u201d monitor was seeing the HiDPI mode kick in. This is a bad bug because it is a regression. The goal of the feature is to improve the experience for HiDPI users, not break it for everyone else. Degrading a product for other people is the fastest way to get your code reverted.<\/p>\n<p>This would have been stressful for me, but several weeks earlier I had studied the Linux DPI detection code and multi-monitor support. Since I knew exactly what 4.2.3 was doing here, I didn&#8217;t worry about being able to quickly solve the problem. I just needed to figure out what data LibreOffice was getting from the OS. You can stare at code as much as you want, but if you depend on hardware-specific information, you can&#8217;t prove it correct until you test on other computers.<\/p>\n<p>I had taken the time to learn the code because <span style=\"font-weight: normal;\"><a href=\"http:\/\/cgit.freedesktop.org\/libreoffice\/core\/commit\/?id=9f308fbc02439e25f8932314a9374c205ebdbc4c\">I submitted a patch<\/a> <\/span>to LibreOffice for 4.3 that simplifies it to only fetch from xrdb and never bother to fetch from X Windows. I found the information unreliable for my laptop. On my machine, X tells me it is 96 DPI on a 33\u201d by 18\u201d monitor. It is pretty impressive to squeeze all that into a 13.3\u201d screen. The patch to ignore X isn&#8217;t in 4.2.x, but that wasn&#8217;t a problem because the hard part is understanding the code. The tester was very helpful in quickly giving me the information I needed.<\/p>\n<p>The problem is simple to describe. The monitor was 141 DPI, but X said it was 139&#215;144. Of course it is crazy with bad data of different DPI values in the X and Y direction, but that was irrelevant here. The issue was that LibreOffice&#8217;s doubling kicked in at 144 DPI in the Y direction:<\/p>\n<p><span style=\"font-family: DejaVu Sans Mono,monospace;\"><span style=\"font-size: xx-small;\"><b>mnDPIScaleFactor = std::max((sal_Int32)1, (mpWindowImpl-&gt;mpFrameData-&gt;mnDPIY + 48) \/ 96);<\/b><\/span><\/span><\/p>\n<p><strong>144 + 48 == 192 \/ 96 == 2<\/strong><\/p>\n<p>I could think of several fixes, but I wasn&#8217;t sure what was best, so I decided to ask Kendy who had written that line of code. Within a few days, he submitted an improvement that will not cause this new mode to kick in until at least 168 DPI. That fixes the problem for this machine, and hopefully others. So with these fixes, things are in decent shape. The next issue is Unity, which is currently broken.<\/p>\n<h1 class=\"western\">Unity<\/h1>\n<p>While LibreOffice can look good with Gnome, KDE, and Xfce, I hadn&#8217;t tried Unity. It is difficult to get it running on Arch because it has <a href=\"https:\/\/github.com\/chenxiaolong\/Unity-for-Arch\">patches to a lot of key components<\/a> they&#8217;ve not convinced upstreams to accept. And so I&#8217;d have to replace a lot of system packages, and I didn&#8217;t want to deal that risk for my personal laptop.<\/p>\n<p>Unity isn&#8217;t even the only environment Ubuntu supports, but it is their premier one and so I had been curious. The Unity team had done a bunch of HiDPI work for version 8, and so I hoped it would work. Ubuntu 14.04 is shipping 4.2.3 with the LibreOffice icons prominently placed on the dock.<\/p>\n<p>After hearing nothing for months, I tried out a live USB image of the final Ubuntu 14.04. Unfortunately, I discovered that even though they based some of their work on the Gnome 3.10 design, they didn&#8217;t fix the xrdb values. I could also find no way to force apps to be 192 DPI, as the other environments enable. Apparently there are new Unity APIs.<\/p>\n<p>I wish Unity would fix their xrdb values. I don&#8217;t know where the Unity documentation is or how to write Ubuntu-specific code on LibreOffice. I recommended to Ubuntu&#8217;s developer, Bjoern Michaelson, to requisition a new machine. For now, it doesn&#8217;t work on Unity and the fix is unknown.<\/p>\n<h1 class=\"western\">The end, for now<\/h1>\n<p>This story ends, but there is plenty more that can be done. <span style=\"font-weight: normal;\">It would be great to have higher-resolution toolbar bitmaps, but it isn&#8217;t high priority because only a few are pixelated. The Mac is still broken. It appears that the OS doesn&#8217;t work in pixels on retina displays. Good luck fixing that.<\/span><\/p>\n<p><span style=\"font-weight: normal;\">The splash screen is a little embarrassing, but is is only visible for a moment. I found the relevant code in <a href=\"http:\/\/opengrok.libreoffice.org\/xref\/core\/desktop\/unx\/source\/splashx.c\">splashx.c<\/a>, but didn\u2019t find an easy fix because this early code apparently can&#8217;t use the BitmapEx class with its scaling rou<\/span>tines. In fact, it often draws bitmaps pixel by pixel. Maybe someone can just make a bigger splash screen and fix the progress control.<\/p>\n<p>The status bar still needs to be improved. The bitmaps look fine but because the layout is done in pixels and stored in an XML file, there is no way currently to make it be different widths for normal and HiDPI screens.<\/p>\n<p>The hyperlink dialog box has a few problems:<\/p>\n<p><a href=\"http:\/\/keithcu.com\/wordpress\/wp-content\/uploads\/2014\/04\/HyperlinkLO423.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3589\" src=\"http:\/\/keithcu.com\/wordpress\/wp-content\/uploads\/2014\/04\/HyperlinkLO423.png\" alt=\"HyperlinkLO423\" width=\"894\" height=\"393\" \/><\/a><\/p>\n<p>The Insert-special characters dialog needs to be taller by default. The letters are all much too small. I had spent some time looking through the code but never managed to find the place to make a fix. Fortunately, the dialog box is resizable so this isn&#8217;t a big problem.<\/p>\n<p>It also needs testing on Windows 7, although from my casual re-reading of the MSDN documentation, it should work.<\/p>\n<p>The underline wave character property isn&#8217;t scaling yet. I didn&#8217;t bother with that because it is very little used compared to mis-spellings, and is a more complicated codepath.<\/p>\n<p>The line styles toolbar dropdown preview draws lines too thin. I looked around the code, but it was very voluminous. Kohei Yoshida spent a couple of weeks re-working it recently so I&#8217;m hoping when he gets a new laptop, he&#8217;ll quickly notice and be able to fix it.<\/p>\n<p>It doesn&#8217;t appear that multiple monitors of different resolutions is handled properly in LibreOffice. Fixing that could be tricky. So the work continues!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wrote my story about getting some HiDPI patches into LibreOffice, but it was an unfinished one because while the code had gotten accepted into the main Master branch, there was a lot remaining. It hadn&#8217;t shipped, I&#8217;d only tested it on Gnome and KDE, it hadn&#8217;t been tried on Windows, and didn\u2019t work on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3580","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3580"}],"version-history":[{"count":1,"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3580\/revisions"}],"predecessor-version":[{"id":3608,"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3580\/revisions\/3608"}],"wp:attachment":[{"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keithcu.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}