compiler/libec: (#205) Corrections to integer promotions
[sdk] / ecere / src / gui / controls / Menu.ec
index f8421ee..d3d5185 100644 (file)
@@ -27,7 +27,7 @@ class InsertedFlags { bool deleteLink:1, deleteItem:1, cleanItem:1, placed:1; };
 #define INTERIM_MENU (isMenuBar || interim)
 //#define INTERIM_MENU interim
 
-static int strcmpTillTab(char * a, char * b)
+static int strcmpTillTab(const char * a, const char * b)
 {
    if(a && !b) return 1;
    else if(b && !a) return -1;
@@ -59,13 +59,13 @@ public:
          }
       }
    };
-   property char * text
+   property const char * text
    {
       set
       {
          if(copyText)
          {
-            delete text;
+            delete (char *)text;
             text = CopyString(value);
          }
          else
@@ -99,7 +99,7 @@ public:
                strcat(accelString, "0");
             else if(value.code >= k1 && value.code <= k9)
             {
-               accelString[strlen(accelString)] = '1' + (char)(value.code - k1);
+               accelString[strlen(accelString)] = (char)('1' + value.code - k1);
                accelString[strlen(accelString)+1] = 0;
             }
             else
@@ -107,7 +107,7 @@ public:
                Key accel = value.code;
                bool needClass = false;
                char tempString[50];
-               char * result = accel.OnGetString(tempString, null, &needClass);
+               const char * result = accel.OnGetString(tempString, null, &needClass);
                int len = strlen(accelString);
                if(result) strcpy(accelString + len, result);
                // accelString[len] = toupper(accelString[len]);
@@ -123,7 +123,7 @@ public:
             memcpy(newText, text, length);
             newText[length] = 0;
             strcat(newText, accelString);
-            if(copyText) delete text;
+            if(copyText) delete (void *)text;
             text = newText;
             copyText = true;
          }
@@ -199,8 +199,8 @@ public:
          }
          else
          {
-            if(text && copyText)
-               delete text;
+            if(copyText)
+               delete (void *)text;
          }
          copyText = value;
       }
@@ -216,7 +216,7 @@ private:
    uint64 id;
    Key hotKey;
    Key accelerator;
-   char * text;
+   const char * text;
    BitmapResource bitmaps[3];
    bool checkable, radio;
    bool checked;
@@ -231,7 +231,7 @@ private:
    {
       if(copyText)
          // delete ITEM_TEXT(this);
-         delete text;
+         delete (void *)text;
       delete subMenu;
       delete bitmaps[0];
       delete bitmaps[1];
@@ -259,7 +259,7 @@ public class MenuPlacement : MenuItem
 public:
 /*
    property Menu parent { set {} };
-   property char * text { set {} };
+   property const char * text { set {} };
    property Key hotKey { set {} };
 */
 };
@@ -542,7 +542,7 @@ public:
                   }
                }
 
-               if(!beingMergedItem.isDivider || (previous.item && !previous.item.isDivider))
+               if(!beingMergedItem.isDivider || !previous || (previous.item && !previous.item.isDivider))
                {
                   mergeIntoItemPtr = ItemPtr { };
                   items.Insert(previous, mergeIntoItemPtr);
@@ -589,7 +589,7 @@ public:
       }
    }
 
-   Menu FindMenu(char * name)
+   Menu FindMenu(const char * name)
    {
       ItemPtr ptr;
 
@@ -604,7 +604,7 @@ public:
    }
 
    property Menu parent { set { if(value) value.AddSubMenu(this); } };
-   property char * text { set { text = value; /* CopyString(value);*/ } };
+   property const char * text { set { text = (char *)value; /* CopyString(value);*/ } };
    property Key hotKey { set { hotKey = value; } };
    property bool hasMargin { set { hasMargin = value; } };
 
@@ -645,7 +645,7 @@ public class PopupMenu : Window
    bool mouseInput;
    Time unpressedTime;
 
-   void (* FontExtent)(Display display, Font font, char * text, int len, int * width, int * height);
+   void (* FontExtent)(Display display, Font font, const char * text, int len, int * width, int * height);
 
    FontResource boldFont { faceName = font.faceName, font.size, bold = true, window = this };
    BitmapResource subArrow { fileName = "<:ecere>elements/arrowRight.png", window = this };
@@ -665,7 +665,6 @@ public class PopupMenu : Window
    {
       bool result;
       PopupMenu window = this, master;
-      PopupMenu popupMenu;
 
       for(; (master = (PopupMenu)window.master); window = master)
       {
@@ -967,7 +966,7 @@ public class PopupMenu : Window
             }
             else
             {
-               char * text = ITEM_TEXT(item);
+               const char * text = ITEM_TEXT(item);
                FontExtent(display, fontObject, text, text ? strlen(text) : 0, &len, null);
                if((mx >= x - 16 && mx < x + len + 16))
                {
@@ -1022,6 +1021,7 @@ public class PopupMenu : Window
       bool systemButtons = activeClient && activeClient.state == maximized;
       int bitmapOffset = 0;
       bool hasBitmap = false;
+      bool isRadio = false;
 
       surface.TextFont(fontObject);
       surface.TextExtent(" ", 1, null, &height);
@@ -1040,12 +1040,23 @@ public class PopupMenu : Window
                   break;
                }
             }
+
+            for(ptr = menu.items.first; ptr; ptr = ptr.next)
+            {
+               if(ptr.item.radio)
+               {
+                  isRadio = true;
+                  break;
+               }
+            }
          }
 
          if(guiApp.textMode)
             bitmapOffset = 16;
          else
             bitmapOffset = hasMargin ? 27 : (hasBitmap ? 18 : 12);
+         if(hasBitmap && isRadio)
+            bitmapOffset += 18;
       }
       else if(guiApp.textMode)
          bitmapOffset = 8;
@@ -1150,7 +1161,7 @@ public class PopupMenu : Window
                   {
                      Bitmap icon = bitmap.bitmap;
                      if(icon)
-                        surface.Blit(icon, x + hasMargin ? 5 : 3, y + (rh - icon.height)/2, 0,0, icon.width, icon.height);
+                        surface.Blit(icon, x + (isRadio ? 18 : 0) + (hasMargin ? 5 : 3), y + (rh - icon.height)/2, 0,0, icon.width, icon.height);
                   }
 
                   if(item.bold)
@@ -1595,6 +1606,8 @@ public class PopupMenu : Window
                   if(strstr(ITEM_TEXT(item), "\t"))
                      width += 8;
                }
+               if(item.bitmap && item.radio)
+                  width += 20;
                if(item.subMenu) width += 20;
                if(!guiApp.textMode)
                   height += 6;
@@ -1706,8 +1719,11 @@ public class PopupMenu : Window
    bool OnMouseMove(int mx, int my, Modifiers mods)
    {
       int selectedX, selectedY;
+      ItemPtr selected;
+
+      if(mods.isSideEffect) return true;
 
-      ItemPtr selected = FindSelected(mx, my, &selectedX, &selectedY);
+      selected = FindSelected(mx, my, &selectedX, &selectedY);
 
       if((!mods.isSideEffect || !this.selected) && (/*selected && */
          selected != this.selected && (!selected || !ITEM_DISABLED(selected.item)) && (selected || !keyboardFocus)))
@@ -1744,7 +1760,6 @@ public class PopupMenu : Window
    {
       if(isMenuBar)
       {
-         Time t = GetTime(), u = unpressedTime;
          // Had to boost this to 0.1 for Windows Basic / XP theme / Remote Desktop
          // Aero & Classic were fast enough for 0.01
          if(GetTime() - unpressedTime < 0.1)