sdk: const correctness
[sdk] / ecere / src / gui / controls / StatusBar.ec
index ac09ec5..3f9c990 100644 (file)
@@ -10,7 +10,7 @@ public class StatusBar : Window
 {
    class_property(icon) = "<:ecere>controls/statusBar.png";
 
-   background = activeBorder;
+   background = formColor;
    nonClient = true;
    inactive = true;
    anchor = Anchor { left = 0, right = 0, bottom = 0 };
@@ -32,7 +32,7 @@ public:
    {
       if(this && field)
       {
-         field._statusBar = null; 
+         field._statusBar = null;
          width -= field.width + (guiApp.textMode ? 0 : 6);
          fields.Remove(field);
          delete field;
@@ -53,7 +53,7 @@ public:
 private:
    StatusBar()
    {
-      fields.offset = (uint)&((StatusField)0).prev;
+      fields.offset = (uint)(uintptr)&((StatusField)0).prev;
    }
 
    ~StatusBar()
@@ -61,6 +61,8 @@ private:
       Clear();
    }
 
+   FontResource boldFont { font.faceName, font.size, true, window = this };
+
    bool OnLoadGraphics()
    {
       StatusField field;
@@ -72,7 +74,7 @@ private:
 
    bool OnResizing(int * w, int * h)
    {
-      *h = Max(*h, 18);
+      *h = Max(*h, statusBarHeight);
       if(!*w) *w = 80;
       return true;
    }
@@ -81,12 +83,12 @@ private:
    {
       StatusField field;
       int position = Max(clientSize.w, MIN_INFO_WIDTH + width)-1-2;
-      Box clip { 2, 2, MIN_INFO_WIDTH, 17 };
+      Box clip { 2, 2, MIN_INFO_WIDTH, statusBarHeight-1 };
       Window parent = this.parent;
 
       if(!guiApp.textMode)
          surface.ThinBevel(false, -1,0, clientSize.w+2, clientSize.h+1);
-      
+
       for(field = fields.first; field; field = field.next)
       {
          int x = position - field.width;
@@ -94,7 +96,7 @@ private:
          surface.SetBackground(white);
          if(!guiApp.textMode)
          {
-            surface.ThinBevel(true, x - 2, 2, field.width + 4, 16);
+            surface.ThinBevel(true, x - 2, 2, field.width + 4, statusBarHeight-2);
             surface.SetForeground(field.colorSet ? field.color : foreground);
          }
          else
@@ -106,12 +108,18 @@ private:
          }
          if(field.text)
          {
-            Box clip { x, 2, x + field.width - 1, 17 };
+            Box clip { x, 2, x + field.width - 1, statusBarHeight-3 };
             int tw;
             surface.Clip(clip);
+            if(field.backColor)
+            {
+               surface.SetBackground(field.backColor);
+               surface.Clear(colorBuffer);
+            }
+            surface.font = field.bold ? boldFont.font : fontObject;
             surface.TextExtent(field.text, strlen(field.text), &tw, null);
             surface.WriteTextf(x + (field.width - tw) / 2, 2, field.text);
-            surface.Clip(null);         
+            surface.Clip(null);
          }
          position -= field.width + (guiApp.textMode ? 0 : 6);
       }
@@ -123,18 +131,18 @@ private:
          surface.SetForeground(white);
       else
          surface.SetForeground(foreground);
-         
+
       surface.WriteTextf(2, 2, text);
       surface.Clip(null);
    }
 
-   watch(text)
+   watch(caption)
    {
       text = property::text;
       Update(null);
    };
 
-   char * text;
+   const char * text;
    OldList fields;
    int width;
 };
@@ -159,7 +167,7 @@ public:
    }
    property Color color
    {
-      set 
+      set
       {
          if(this)
          {
@@ -170,8 +178,28 @@ public:
          }
       }
    }
+   property ColorAlpha backColor
+   {
+      set
+      {
+         if(this)
+         {
+            backColor = value;
+            colorSet = true;
+            if(_statusBar)
+               _statusBar.Update(null);
+         }
+      }
+   }
+   property bool bold
+   {
+      set
+      {
+         if(this) this.bold = value;
+      }
+   }
 
-   property char * text
+   property const char * text
    {
       set
       {
@@ -207,25 +235,21 @@ public:
       }
    }
 
-   void SetTextf(char * format, ...)
+   void SetTextf(const char * format, ...)
    {
       if(this)
       {
+         delete text;
          if(format)
          {
             char tempText[MAX_F_STRING];
-            int len;
             va_list args;
             va_start(args, format);
-            vsprintf(tempText, format, args);
+            vsnprintf(tempText, sizeof(tempText), format, args);
+            tempText[sizeof(tempText)-1] = 0;
             va_end(args);
-            len = strlen(tempText);
-
-            text = renew text char[len + 1];
-            CopyBytes(text, tempText, len + 1);
+            text = CopyString(tempText);
          }
-         else
-            delete text;
          if(_statusBar)
             _statusBar.Update(null);
       }
@@ -241,6 +265,8 @@ private:
    char * text;
    int width;
    Color color;
+   ColorAlpha backColor;
    StatusBar _statusBar;
    bool colorSet;
+   bool bold;
 };