ecere/gui/DropBox: Added lastRow property
[sdk] / ecere / src / gui / controls / DropBox.ec
index f582fa1..9f56dbf 100644 (file)
@@ -24,19 +24,16 @@ public class DropBox : CommonControl
 
    class_property(icon) = "<:ecere>controls/dropBox.png";
 
-   watch(foreground)
-   {
-      listBox.foreground = foreground;
-   };
-   watch(background)
-   {
-      listBox.background = background;
-   };
+   watch(foreground)     { listBox.foreground = foreground;         if(editBox) editBox.foreground = foreground; };
+   watch(background)     { listBox.background = background;         if(editBox) editBox.background = background; };
+   watch(selectionColor) { listBox.selectionColor = selectionColor; if(editBox) editBox.selectionColor = selectionColor; };
+   watch(selectionText)  { listBox.selectionText = selectionText;   if(editBox) editBox.selectionText = selectionText; };
+   watch(opacity)        { listBox.opacity = opacity;               if(editBox) editBox.opacity = opacity; };
 
 public:
    property bool activeStipple
    {
-      property_category $"Appearance" 
+      property_category $"Appearance"
       set
       {
          style.noStipple = !value;
@@ -46,7 +43,7 @@ public:
    };
    property bool showButton
    {
-      property_category $"Appearance" 
+      property_category $"Appearance"
       set
       {
          button.visible = value;
@@ -56,7 +53,7 @@ public:
    };
    property Alignment alignment
    {
-      property_category $"Appearance" 
+      property_category $"Appearance"
       set
       {
          alignment = value;
@@ -67,7 +64,7 @@ public:
    };
    property bool noHighlight
    {
-      property_category $"Appearance" 
+      property_category $"Appearance"
       set
       {
          if(this)
@@ -81,7 +78,7 @@ public:
    };
    property bool activeColor
    {
-      property_category $"Appearance" 
+      property_category $"Appearance"
       set
       {
          if(this)
@@ -94,7 +91,7 @@ public:
    };
    property DataRow currentRow
    {
-      property_category $"Private" 
+      property_category $"Private"
       set
       {
          if(this)
@@ -105,10 +102,10 @@ public:
             {
                char tempString[4096];
                if(currentRow)
-                  editBox.contents = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, currentRow.GetData(null), tempString, null, null);
+                  editBox.contents = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, currentRow.GetData(null), tempString, null, null);
                else
                   editBox.contents = "";
-            }                  
+            }
             Update(null);
             if(style.editText)
             {
@@ -124,10 +121,11 @@ public:
       get { return currentRow; }
    };
    property DataRow firstRow { get { return this ? listBox.firstRow : null; } };
-   property char * contents { property_category $"Data" set { if(editBox) editBox.contents = value; } get { return editBox ? editBox.contents : null; } };
+   property DataRow lastRow { get { return this ? listBox.lastRow : null; } };
+   property const char * contents { property_category $"Data" set { if(editBox) editBox.contents = value; } get { return editBox ? editBox.contents : null; } };
    property bool editText
    {
-      property_category $"Behavior" 
+      property_category $"Behavior"
       set
       {
          if(this)
@@ -141,11 +139,15 @@ public:
                      this, textHorzScroll = true, borderStyle = 0;
                      anchor = Anchor { left = 0, top = 0, right = BTN_WIDTH, bottom = 0 };
                      // visible = false, modifyVirtualArea = false;
+                     foreground = foreground;
+                     background = background;
+                     selectionColor = selectionColor;
+                     selectionText = selectionText;
                   };
                   incref editBox;
                   editBox.Create();
                   button.inactive = false;
-               }      
+               }
                style.editText = true;
                tabCycle = false;
             }
@@ -168,7 +170,7 @@ public:
    property int rowHeight { property_category $"Appearance" set { listBox.rowHeight = value; } get { return listBox.rowHeight; } };
    property int maxShown
    {
-      property_category $"Behavior" 
+      property_category $"Behavior"
       set
       {
          listBoxMaxShown = value;
@@ -201,6 +203,7 @@ public:
       get { return style.showNone; }
    }
    property Color selectionColor { set { selectionColor = value; } get { return selectionColor; } isset { return selectionColor ? true : false; } };
+   property Color selectionText  { set { selectionText = value; } get { return selectionText; } isset { return selectionText ? true : false; } };
    property bool changeContents
    {
       set { style.changeContents = value; }
@@ -209,11 +212,13 @@ public:
 
    property ListBox listBox { get { return listBox; } }
 
+   property int rowCount { get { return listBox.rowCount; } }
+
    // Notifications
    virtual bool Window::NotifySelect(DropBox dropBox, DataRow row, Modifiers mods);
    virtual bool Window::NotifyClose(DropBox dropBox);
    virtual bool Window::NotifyHighlight(DropBox dropBox, DataRow row, Modifiers mods);
-   virtual bool Window::NotifyTextEntry(DropBox dropBox, char * string, bool confirmed);
+   virtual bool Window::NotifyTextEntry(DropBox dropBox, const char * string, bool confirmed);
 
    virtual Window OnDropDown()
    {
@@ -225,7 +230,7 @@ public:
 
       ResizeListbox();
       // listBox.visible = true;
-      return listBox;   
+      return listBox;
    }
 
    virtual void OnCloseDropDown(Window pullDown)
@@ -239,7 +244,7 @@ public:
    }
 
    // Methods
-   DataRow AddStringf(char * format, ...)
+   DataRow AddStringf(const char * format, ...)
    {
       if(this)
       {
@@ -260,7 +265,7 @@ public:
       return null;
    }
 
-   DataRow AddString(char * string)
+   DataRow AddString(const char * string)
    {
       if(this)
       {
@@ -300,12 +305,7 @@ public:
 
    any_object GetData(DataField field)
    {
-      if(this)
-      {
-         // TODO: Fix this shouldn't be required (memguard?)
-         return (void *)currentRow.GetData(field);
-      }
-      return null;
+      return this ? currentRow.GetData(field) : null;
    }
 
    void Sort(DataField field, int order)
@@ -319,7 +319,7 @@ public:
       {
          if(!field)
             field = DataField { alignment = alignment };
-         
+
          listBox.AddField(field);
          this.field = listBox.firstField;
          dataType = this.field.dataType;
@@ -383,7 +383,7 @@ public:
       return null;
    }
 
-   DataRow FindSubRow(int tag)
+   DataRow FindSubRow(int64 tag)
    {
       if(this)
       {
@@ -402,10 +402,10 @@ public:
          {
             char tempString[4096];
             if(currentRow)
-               editBox.contents = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, currentRow.GetData(null), tempString, null, null);
+               editBox.contents = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, currentRow.GetData(null), tempString, null, null);
             else
                editBox.contents = "";
-         }                  
+         }
          listBox.SelectRow(currentRow ? currentRow : (style.showNone ? noneRow : null));
 
          Update(null);
@@ -464,7 +464,7 @@ private:
             if(ly + height > availHeight)
                height = ((availHeight - ly) / ROW_HEIGHT) * ROW_HEIGHT;
          }
-            
+
          if(!pulledWindow.initSize.w)
             pulledWindow.size.w = size.w;
          else
@@ -536,8 +536,8 @@ private:
                OnPosition(position.x, position.y, clientSize.w, clientSize.h);
                if(pulledWindow) pulledWindow.visible = true;
                button.checked = true;
-            }         
-            Update(null);         
+            }
+            Update(null);
             return false;
          case enter:
          case keyPadEnter:
@@ -564,7 +564,7 @@ private:
                pulledWindow = null;
                button.checked = false;
                Update(null);
-               
+
                if(!NotifyClose(master, this))
                {
                   delete this;
@@ -578,14 +578,14 @@ private:
                {
                   char tempString[4096];
                   if(currentRow)
-                     editBox.contents = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, currentRow.GetData(null), tempString, null, null);
+                     editBox.contents = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, currentRow.GetData(null), tempString, null, null);
                   else
                      editBox.contents = "";
-               }                  
+               }
 
                NotifySelect(master, this, currentRow, key.modifiers | { closingDropDown = true });
-               
-               delete this;               
+
+               delete this;
                return false;
             }
             return false;
@@ -600,7 +600,7 @@ private:
       button.anchor = { right = 0, top = 0, bottom = 0 };
       button.size = { guiApp.textMode ? 8 : BTN_WIDTH, 0 };
    }
-   
+
    /*Timer timer
    {
       window = this, delay = 0.01;
@@ -633,14 +633,14 @@ private:
          if(!isEnabled)
             surface.SetForeground(Color { 85,85,85 } );
          else
-            surface.SetForeground((active && style.activeColor && !pulledWindow /*listBox.visible*/) ? SELECTION_TEXT : foreground);
+            surface.SetForeground((active && style.activeColor && !pulledWindow /*listBox.visible*/) ? selectionText : foreground);
          surface.TextOpacity(true);
 
          if(currentRow)
          {
             DataDisplayFlags displayFlags { active = active, current = true, dropBox = true, selected = true, fullRow = true };
-            dataType._vTbl[__ecereVMethodID_class_OnDisplay](dataType, currentRow.GetData(null), surface, 3, 
-               1+(clientSize.h - listBox.rowHeight) / 2, clientSize.w - (button.visible ? button.size.w : 0) - 3, 
+            ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)dataType._vTbl[__ecereVMethodID_class_OnDisplay])(dataType, currentRow.GetData(null), surface, 3,
+               1+(clientSize.h - listBox.rowHeight) / 2, clientSize.w - (button.visible ? button.size.w : 0) - 3,
                field.userData, alignment, displayFlags);
          }
          else
@@ -665,7 +665,7 @@ private:
    {
       int rowHeight = 0;
 
-      display.FontExtent(fontObject, "W", 1, null, &rowHeight); 
+      display.FontExtent(fontObject, "W", 1, null, &rowHeight);
       rowHeight = Max(rowHeight, 16);
 
       if(!*width) *width = Max(*width, rowHeight * 100 / 16);
@@ -692,7 +692,7 @@ private:
          OnCloseDropDown(pulledWindow);
          button.checked = false;
          pulledWindow = null;
-      
+
          if(!NotifyClose(master, this))
             return false;
       }
@@ -712,7 +712,7 @@ private:
    bool OnKeyHit(Key key, unichar ch)
    {
       DataRow currentRow = this.currentRow;
-      
+
       if(!pulledWindow /*listBox.visible*/)
       {
          int c;
@@ -875,12 +875,12 @@ private:
          {
             char tempString[4096];
             if(currentRow)
-               editBox.contents = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, currentRow.GetData(null), tempString, null, null);
+               editBox.contents = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, currentRow.GetData(null), tempString, null, null);
             else
                editBox.contents = "";
             if(active)
                editBox.SelectAll();
-         }                  
+         }
          button.Deactivate();
          return NotifySelect(master, this, currentRow, mods);
       }
@@ -913,5 +913,8 @@ private:
    EditBox editBox;
    Alignment alignment;
    DataRow noneRow;
-   Color selectionColor;
+   ColorAlpha selectionColor, selectionText;
+
+   selectionColor = SELECTION_COLOR;
+   selectionText = SELECTION_TEXT;
 };