Author Topic: Refixed: pull-down-menus-images-not-changing-state Issue  (Read 18304 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Refixed: pull-down-menus-images-not-changing-state Issue
« on: January 10, 2007, 01:54:36 pm »
FYI:

I have started troubleshooting the cause of the toolbar images not changing state Issue.

Edit: correction I worked on the pull-down menus images not changing state Issue.

Tim S
« Last Edit: January 22, 2007, 07:07:04 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Troubleshooting toolbar-images-not-changing-state Issue
« Reply #1 on: January 10, 2007, 02:37:10 pm »
FYI:

I have started troubleshooting the cause of the toolbar images not changing state Issue.

Tim S

Many moons ago, I futz around with this problem.

 Look at the wierd ugly "redish" first debugger icon that I made. I noticed that when only two colors were used and the primary color was marked as transparent, windows would not change the icon state, or any icon that followed it in the toolbar.

Also notice that the compiler icons work fine, but they are colored. So using that idea, I colored the first debugger icon, and the others then changed state.

I was never able to figure out why, and found no info on the i'net.

Just a note that might help

pecan
« Last Edit: January 10, 2007, 02:40:55 pm by Pecan »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Troubleshooting toolbar-images-not-changing-state Issue
« Reply #2 on: January 10, 2007, 05:32:19 pm »
Patch to wxWidgets 2.6_Branch to fix menuitem images not changing state
Needs tested and verified it works, I have been up for over 24 hours so use with care.

NOTE: Fixed the small issue of calling SetDisabledBitmap
Note: Added guard of defined(__WXMSW__) on most of added code.
Note: I need to fix my fix of the keybinder code also. Can't use SetBitMap must use SetBitMaps instead.
        The fix of keybinder is NOT needed for this code to work right, but will be needed after my patch of the xrc method used to load wxMenuItem. I have not yet decided if fixing the xrc is something I want to do.

Tim S

Code
Index: include/wx/ownerdrw.h
===================================================================
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/include/wx/ownerdrw.h,v
retrieving revision 1.26
diff --unified -r1.26 ownerdrw.h
--- include/wx/ownerdrw.h 2005/06/07 18:28:47 1.26
+++ include/wx/ownerdrw.h 2007/01/10 16:27:36
@@ -169,6 +169,12 @@
   size_t    m_nHeight,      // font height
             m_nMinHeight,   // minimum height, as determined by user's system settings
             m_nMarginWidth; // space occupied by bitmap to the left of the item
+
+#if defined(__WXMSW__)
+  // Helper function for creating the image for disabled buttons
+  bool wxCreateGreyedImage(const wxImage& in, wxImage& out) ;
+#endif
+
 };

 #endif // wxUSE_OWNER_DRAWN
Index: src/msw/ownerdrw.cpp
===================================================================
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/src/msw/ownerdrw.cpp,v
retrieving revision 1.62.2.3
diff --unified -r1.62.2.3 ownerdrw.cpp
--- src/msw/ownerdrw.cpp 2006/05/29 17:35:00 1.62.2.3
+++ src/msw/ownerdrw.cpp 2007/01/10 17:20:11
@@ -36,6 +36,7 @@
 #include "wx/menuitem.h"
 #include "wx/fontutil.h"
 #include "wx/module.h"
+#include "wx/image.h"

 #if wxUSE_OWNER_DRAWN

@@ -443,6 +444,18 @@
         if ( st & wxODDisabled )
         {
             bmp = GetDisabledBitmap();
+#if defined(__WXMSW__) && wxUSE_IMAGE && wxUSE_WXDIB
+            if ( !bmp.Ok() && m_bmpChecked.Ok() )
+            {
+                // no disabled bitmap specified but we still need to
+                // fill the space in the image list with something, so
+                // we grey out the normal bitmap
+                wxImage imgGreyed;
+                wxCreateGreyedImage(m_bmpChecked.ConvertToImage(), imgGreyed);
+                bmp = wxBitmap(imgGreyed);
+                SetDisabledBitmap(bmp);
+            }
+#endif // defined(__WXMSW__) && wxUSE_IMAGE && wxUSE_WXDIB
         }

         if ( !bmp.Ok() )
@@ -488,6 +501,75 @@
     return true;
 }

+
+#if defined(__WXMSW__) && wxUSE_IMAGE
+
+/*
+ * Make a greyed-out image suitable for disabled buttons.
+ * Code copied from common/tbarbase.cpp method wxCreateGreyedImage.
+ */
+
+bool wxOwnerDrawn::wxCreateGreyedImage(const wxImage& src, wxImage& dst)
+{
+    dst = src.Copy();
+
+    unsigned char rBg, gBg, bBg;
+    if ( src.HasMask() )
+    {
+        src.GetOrFindMaskColour(&rBg, &gBg, &bBg);
+        dst.SetMaskColour(rBg, gBg, bBg);
+    }
+    else // assuming the pixels along the edges are of the background color
+    {
+        rBg = src.GetRed(0, 0);
+        gBg = src.GetGreen(0, 0);
+        bBg = src.GetBlue(0, 0);
+    }
+
+    const wxColour colBg(rBg, gBg, bBg);
+
+    const wxColour colDark = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
+    const wxColour colLight = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
+
+    // Second attempt, just making things monochrome
+    const int width = src.GetWidth();
+    const int height = src.GetHeight();
+
+    for ( int x = 0; x < width; x++ )
+    {
+        for ( int y = 0; y < height; y++ )
+        {
+            const int r = src.GetRed(x, y);
+            const int g = src.GetGreen(x, y);
+            const int b = src.GetBlue(x, y);
+
+            if ( r == rBg && g == gBg && b == bBg )
+            {
+                // Leave the background colour as-is
+                continue;
+            }
+
+            // Change light things to the background colour
+            wxColour col;
+            if ( r >= (colLight.Red() - 50) &&
+                    g >= (colLight.Green() - 50) &&
+                        b >= (colLight.Blue() - 50) )
+            {
+                col = colBg;
+            }
+            else // Change dark things to really dark
+            {
+                col = colDark;
+            }
+
+            dst.SetRGB(x, y, col.Red(), col.Green(), col.Blue());
+        }
+    }
+
+    return true;
+}
+
+#endif // defined(__WXMSW__) && wxUSE_IMAGE

 #endif // wxUSE_OWNER_DRAWN

« Last Edit: January 10, 2007, 10:31:12 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Fix for: toolbar-images-not-changing-state Issue
« Reply #3 on: January 11, 2007, 05:04:42 am »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #4 on: January 11, 2007, 07:32:19 am »
Thanks Tim,

I will test this out today on windows. I will continue to patch our already patched 263 dll.
However I am gonna change 2 things to your patch :
1) not a method of the class, doesn't need the state, so make it a free function, not being part at all of the interface (sp only cpp needs to be changed) --> less recompiling since no sign of it in the header
2) in the for loop x/y : x++ --> ++x  and y++ --> ++y   ;-)

PS : we have another issue with toolbar buttons, have a look at the find toolbar (16*16, [the 22*22 icon itself is not correct]), find and replace are the same icon, but not in the search menu .... and on linux also on the toolbar they are nicely different.
So our beloved wx expert, what do you think ??
« Last Edit: January 11, 2007, 07:35:42 am by killerbot »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #5 on: January 11, 2007, 10:12:20 am »
PS : we have another issue with toolbar buttons, have a look at the find toolbar (16*16, [the 22*22 icon itself is not correct]), find and replace are the same icon, but not in the search menu .... and on linux also on the toolbar they are nicely different.
So our beloved wx expert, what do you think ??

My eyesight is NOT the best to see differences like this. I know that Linux uses 22*22 and windows uses 16*16. Is the problem that the Linux ones are too small? I don't see the same icons unless you mean that the window icons are showing up on the Linux setup. Is that the problem?

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #6 on: January 11, 2007, 10:15:10 am »
I see the problem now, I had to set the Linux icons to 22*22 first.
This is only the third time I had andLinux running codeblocks.
Tim S

I think I found the cause on the Find and Replace being the same in size 22*22.
Right now one of my setups has the same icons for Find and Replace and the other setup has them different for 16*16 icons.

Tim S
« Last Edit: January 11, 2007, 10:40:54 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #7 on: January 11, 2007, 11:00:27 am »
for 22*22 it is normal they are the same : the 22*22 replace one is not correct (the png itself).
But when they are shown on 16*16 (linux does that too !!!) then on linux both are correct (notice the presence or absence of the R), but on windows the replace one shown in the toolbar is incorrect, it shows the find one (so for 16*16 _ > Env Setings : View : Toolbar icons size).

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #8 on: January 11, 2007, 12:03:12 pm »
src\src\resources\images\searchreplace.png

attached edited image from smaller size 16*16 to bigger 22*22 size

There seems to be no reason for this issue; it must be something that we are all imaging since there seems to be no cause.

Tim S

[attachment deleted by admin]
« Last Edit: January 11, 2007, 02:20:50 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #9 on: January 12, 2007, 12:17:01 am »
Started new thread to work on bitmap in menu toolbar NOT display correct bitmap
http://forums.codeblocks.org/index.php?topic=4926.0
Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #10 on: January 12, 2007, 02:54:36 am »
Thanks Tim,

I will test this out today on windows. I will continue to patch our already patched 263 dll.
However I am gonna change 2 things to your patch :
1) not a method of the class, doesn't need the state, so make it a free function, not being part at all of the interface (sp only cpp needs to be changed) --> less recompiling since no sign of it in the header
2) in the for loop x/y : x++ --> ++x  and y++ --> ++y   ;-)


Did the fix work for you?

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #11 on: January 12, 2007, 08:50:03 am »
ws out of the office, still have to apply it. By the way, can anyone pinpoint me to an example where the error is/was visible ?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #12 on: January 12, 2007, 09:00:31 am »
Bring up build menu without project open
The following choices are disabled with the words grayed out.
Build
Run
Build and Run
Rebuild
Abort

The icons are NOT grayed out.

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #13 on: January 12, 2007, 10:39:08 am »
tried it out, the icons are grayed out now (back ported your patch on wx263pl2) BUT it's darn ugly. It's just like a grid has been put on top of them, you can see the icon anymore (at least for some you can hardly see them anymore), only when you mouse over that menu entry the icon is visible again (and grayed out).

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: FIXED: toolbar-images-not-changing-state Issue
« Reply #14 on: January 12, 2007, 10:51:50 am »
tried it out, the icons are grayed out now (back ported your patch on wx263pl2) BUT it's darn ugly. It's just like a grid has been put on top of them, you can see the icon anymore (at least for some you can hardly see them anymore), only when you mouse over that menu entry the icon is visible again (and grayed out).

I will see if I can make it look better, I found some other code to Gray out bitmaps on the Search/File icon patch.

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org