FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DFL StatusBar,in the rough,Help,Chris!

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Wed Mar 21, 2007 6:59 am    Post subject: DFL StatusBar,in the rough,Help,Chris! Reply with quote

Hi Christopher:


Thank you hard work for DFL.

I write a status bar for DFL,many code from Stewart's D Windows Framework statusbar.

when i use the statusbar, it display info ok, but Message don't work(in MDI Child Form,Button don't effect).

please help me! I love DFL! thank you again!!!


Code:
// Written by Christopher E. Miller
// See the included license.txt for copyright and license details.


///
module dfl.statusbar;

private import dfl.base, dfl.control, dfl.drawing, dfl.application,
   dfl.event;
private import dfl.internal.winapi,dfl.internal.utf;


private extern(Windows) void _initStatusbar();

enum  : uint {
   SIZEGRIP = 256  /*!< include a sizing widget
                 (don't use this style with any that overrides CCS.BOTTOM) */
}

enum SBT : uint {
   DEFAULT    = 0,       //!< sunken border
   NOBORDERS  = 0x0100,  //!< no border around the part
   POPOUT     = 0x0200,  //!< raised border
   RTLREADING = 0x0400,
   TOOLTIPS   = 0x0800,
   OWNERDRAW  = 0x1000
}

enum : uint {
   SB_SETTEXTA = WM_USER + 1,
   SB_GETTEXTA,
   SB_GETTEXTLENGTHA,
   SB_SETPARTS,
   SB_GETPARTS = WM_USER + 6,
   SB_GETBORDERS,
   SB_SETMINHEIGHT,
   SB_SIMPLE,
   SB_GETRECT,
   SB_SETTEXTW,
   SB_GETTEXTLENGTHW,
   SB_GETTEXTW
}

///
class StatusBar: ControlSuperClass
{
   this(int id, int[] pw = null)   
  in {
      assert (pw.length <= 255);
   }
   body {
      
    _initStatusbar();      
    //windowStyle = WS.CHILD | SBARS.SIZEGRIP;
     wexstyle |= SIZEGRIP;
     wclassStyle = statusbarClassStyle;
     this.dock = DockStyle.BOTTOM;      
      _partWidths = pw.dup;
      _parts.length = pw.length;
   }      
   
   
   
   override void dock(DockStyle ds) // setter
   {      
      super.dock(DockStyle.BOTTOM);
   }
   
   alias Control.dock dock; // Overload.
   
   
   ///
   bool simple()
   {
     return _simple;
   }
   
   bool simple(bool v)
   {
     //sendMessageA(SB_SIMPLE, s);
     //prevwproc(SB_SIMPLE, v, 0);
     if(created)
     {
       prevwproc(SB_SIMPLE, v, 0);
     }    
     return _simple = v;
   }   
   
   
   int[] partWidths() {
         return _partWidths.dup;
   }
   
   int[] partWidths(int[] pw)
     in {
         assert (pw.length <= 255);
      }
      body {
         if (created) {            
              prevwproc(SB_SETPARTS, pw.length, cast(int) pw.ptr);
         }

         _partWidths = pw.dup;

         if (_parts.length > _partWidths.length) {
            foreach (part; _parts[_partWidths.length..$]) {
               if (part !is null) part._container = null;
            }
         }

         _parts.length = pw.length;
         return pw;
      }
   
   override char[] text() {
         return _simplePart.text;
      }

      //!   The text displayed by this status bar in simple mode.
      /*!
       *   Setting this property automatically activates simple mode.
       */
      override void text(char[] t) {
         //simple = true;
         return simplePart.text = t;
      }

      //!   The part corresponding to the simple mode of this status bar.
      /*!
       *   \status  done
       */
      StatusBarPart simplePart() {
         return lazyConstruct(_simplePart, 255);
      }

      //!   The part corresponding to the simple mode of this status bar.
      /*!
       *   \param sp  a StatusBarPart with the desired style and text.
       *   \return    the part that has been set.  This will be either sp
       *              or a copy of it, depending on whether sp is already in
       *              a status bar.
       */
      StatusBarPart simplePart(StatusBarPart sp) {
         simple = true;
         return assign(_simplePart, sp, 255);
      }

      //!   Sets the text displayed by this status bar in simple mode.
      /*!
       *   \return  the part corresponding to the simple mode of this status
       *            bar.
       */
      StatusBarPart simplePart(char[] t) {
         StatusBarPart sp = simplePart;

         //simple = true;
         sp.text = t;
         return sp;
      }
      //@}  end prop

      //!   \name   Operators
      //@{
      //!   Returns the specified part of the status bar.
      /*!
       *   (Implementation of <tt>this[index]</tt>.)
       *
       *   \param index  the zero-based index of the part.
       */
      StatusBarPart opIndex(uint index)
      in {
         assert (index < _partWidths.length);
      }
      body {
         return lazyConstruct(_parts[index], index);
      }

      //!   Sets the specified part of the status bar.
      /*!
       *   (Implementation of <tt>this[index] = sp</tt>.)
       *
       *   \param index  the zero-based index of the part.
       *   \param sp     the new contents of the part.
       *   \return       the part that has been set.  This will be either sp
       *                 or a copy of it, depending on whether sp is already
       *                 in a status bar.
       *   \return       the part that has been set.
       *
       *   \status       done
       */
      StatusBarPart opIndexAssign(StatusBarPart sp, uint index)
      in {
         assert (index < _partWidths.length);
      }
      body {
         return assign(_parts[index], sp, index);
      }

      //!   Sets the text in the specified part of the status bar.
      /*!
       *   (Implementation of <tt>this[index] = t</tt>.)
       *
       *   \status  done
       */
      StatusBarPart opIndexAssign(char[] t, uint index)
      in {
         assert (index < _partWidths.length);
      }
      body {
         StatusBarPart sp = this[index];
         sp.text = t;
         return sp;
      }

      //!   Returns a range of parts of the status bar.
      /*!
       *   (Implementation of <tt>this[begin..end]</tt>.)
       *
       *   \status  done
       */
      StatusBarPart[] opSlice(uint begin, uint end)
      in {
         assert (begin <= end);
         assert (end <= _partWidths.length);
      }
      body {
         foreach (index, inout StatusBarPart part; _parts[begin..end]) {
            lazyConstruct(part, index + begin);
         }
         return _parts[begin..end].dup;
      }

      //!   Returns an array consisting of this status bar's parts.
      /*!
       *   (Implementation of <tt>this[]</tt>.)
       */
      StatusBarPart[] opSlice() {
         return this[0.._partWidths.length];
      }
   
   protected override void createParams(inout CreateParams cp)
   {
      super.createParams(cp);
      
      cp.className = STATUSBAR_CLASSNAME;
      /*/add by lpf
      if (_partWidths.length != 0) {
            prevwproc(SB_SETPARTS,  _partWidths.length, cast(int) _partWidths.ptr);
         }

      _parts.length = _partWidths.length;*/
   }
   
   
   protected override void prevWndProc(inout Message msg)
   {
      //msg.result = CallWindowProcA(progressbarPrevWndProc, msg.hWnd, msg.msg, msg.wParam, msg.lParam);
      msg.result = dfl.internal.utf.callWindowProc(statusbarPrevWndProc, msg.hWnd, msg.msg, msg.wParam, msg.lParam);
   }
   
   
   private:
   
   char[] _text;   
   int[] _partWidths;
   bool _simple;
   StatusBarPart[] _parts;
   StatusBarPart _simplePart;
   
   
   StatusBarPart lazyConstruct(inout StatusBarPart sp, uint i) {
         if (sp is null) {
            sp = new StatusBarPart;
            uint styLen = prevwproc(SB_GETTEXTLENGTHA, 255,0);

            with (sp) {
               _container = this;
               _text.length = (styLen & 0xFFFF) + 1;
               prevwproc(SB_GETTEXTA, i, cast(int) _text.ptr);
               _text = std.string.toString(_text.ptr);
               _styleAndIndex = styLen >> 16;
               _index = i;
            }
         }
         return sp;
      }

      StatusBarPart assign(inout StatusBarPart to, StatusBarPart from,
           uint i) {
         
         if (from is to) return to;
         if (from._container !is null) {
            from = from.dup;
            //debug MessageBoxA(null, "Duplicated part", "Debug", MB.OK);
         }
         if (to !is null) to._container = null;
         with (from) {
            _container = this;
            _index = i;
            update();
         }
         return to = from;
      }
      
   package:
   final:
   LRESULT prevwproc(UINT msg, WPARAM wparam, LPARAM lparam)
   {
      //return CallWindowProcA(progressbarPrevWndProc, hwnd, msg, wparam, lparam);
      return dfl.internal.utf.callWindowProc(statusbarPrevWndProc, hwnd, msg, wparam, lparam);
   }
}



class StatusBarPart {
   public {
      //!   \name  Properties
      //@{
      //!   The status bar in which this part has been placed.
      StatusBar container() { return _container; }

      //!   The index of this part within its status bar.
      /*!
       *   \pre  The part must be actually in a status bar.
       */
      ubyte index()
      in {
         assert (container !is null);
      }
      body {
         return _index;
      }

      //!   The style of this status bar part.
      /*!
       *   \status  done
       */
      SBT style() { return cast(SBT) (_styleAndIndex & ~0xFF); }

      //!   The style of this status bar part.
      /*!
       *   \note    If the style SBT.NOBORDERS is set, the part will not
       *            automatically repaint to remove the existing border.
       *            To do so, one must call repaint(true) on the status bar.
       *
       *   \status  done
       */
      SBT style(SBT s) {
         _styleAndIndex = _index | s;
         update();
         return s;
      }

      //!   The text displayed by this status bar part.
      /*!
       *   \status  done
       */
      char[] text() {
         return _text.dup;
      }

      //!   The text displayed by this status bar part.
      /*!
       *   \status  done
       */
      char[] text(char[] t) {
         _text = t.dup;

         update();
         return t;
      }

      //!   Makes a copy of this StatusBarPart.
      /*!
       *   The copy will not be assigned to any status bar until it is
       *   placed in one.
       */
      StatusBarPart dup() {
         StatusBarPart result = new StatusBarPart;

         result._styleAndIndex = style;
         result._text = _text;
         return result;
      }
      //@}  end prop
   }

   private {
      StatusBar _container;
      union {
         uint _styleAndIndex;
         ubyte _index;
      }
      char[] _text;

      void update() {
         if (_container !is null) {
            if (_index == 255) _container.simple = true;
            try {
               _container.prevwproc(SB_SETTEXTA,   _styleAndIndex, cast(int) _text.ptr);
            } catch (Exception e) {
               //throw new ControlException(
                 //"Status bar operation failed - not yet created");
            }
         }
      }
   }
}


________
strawberry cough


Last edited by ideage on Wed Feb 02, 2011 5:07 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Wed Mar 21, 2007 1:51 pm    Post subject: Re: DFL StatusBar,in the rough,Help,Chris! Reply with quote

Can you explain the problem more...

I tested it and it seems to work, though incomplete; the control handle had to be created to set the simple part text.

I started on DFL's own StatusBar a while back but haven't completed it yet. Our code is very different. You may want to name yours something else so it doesn't conflict with my official one. Sorry if you wanted yours in DFL; I can at least look at it for help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group