Guest User

Control class code

a guest
May 25th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 3.21 KB | None | 0 0
  1. module winglib.controls;
  2.  
  3. private import core.runtime;
  4. private import core.sys.windows.windows;
  5. private import std.stdio;
  6.  
  7. private import winglib.fonts;
  8.  
  9.  
  10.  
  11. /// A base class for all controls
  12. class Control {
  13.    
  14.     import winglib.window : Window;
  15.     import winglib.enums : ControlType ;  
  16.    
  17.  
  18.     /// Set the text of control
  19.     @property void text(string value) {this.mText = value ;}
  20.  
  21.     /// Returns the control text
  22.     @property string text() {return this.mText ;}
  23.  
  24.     /// Set the width of the control
  25.     @property void width(int value) {this.mWidth = value ;}
  26.  
  27.     /// Return the width of control
  28.     @property int width() {return this.mWidth ;}
  29.  
  30.     /// Set the height of control
  31.     @property void height(int value) {this.mHeight = value ; }
  32.  
  33.     /// Returns the height of control
  34.     @property int height() {return this.mHeight ;}
  35.  
  36.     /// Set the X position of control
  37.     @property void xPos(int value) {this.mXpos = value ;}
  38.  
  39.     /// Return the x position of control
  40.     @property int xPos() {return this.mXpos ; }
  41.  
  42.     /// Set the y position of control
  43.     @property void yPos(int value) {this.mYpos = value ;}
  44.  
  45.     /// Returns the y position of control
  46.     @property int yPos() {return this.mYpos ;}
  47.  
  48.    /// Returns the window handle
  49.     @property HWND handle() {return this.mHandle ;}
  50.  
  51.  
  52.     /// Set the name of the control
  53.     @property void name(string value) {this.mName = value ;}
  54.  
  55.     /// Return the name of control
  56.     @property string name() {return this.mName ; }
  57.  
  58.     ///
  59.     @property void parent(Window value) {this.mParent = value ;}
  60.  
  61.     ///
  62.     @property Window parent() {return this.mParent ;}
  63.  
  64.     @property ControlType controlType() {return this.mControlType;}
  65.  
  66.     @property Font font() {return this.mFont;}
  67.     @property void font(Font value) {
  68.         this.mFont = value;
  69.         if(this.misHandleCreated) {
  70.             this.setFont();     // This will create a font handle and send the WM_SETFONT msg to control/window.
  71.         }        
  72.     }
  73.  
  74.     @property bool isHandleCreated() {return this.misHandleCreated;}
  75.     //-------------------------------------------------------------------
  76.  
  77.     void hide(){ ShowWindow(this.mHandle, SW_HIDE);}
  78.     void show(){ShowWindow(this.mHandle, SW_SHOW);}
  79.     protected void setFont() {
  80.         import winglib.commons : sendMsg;
  81.              
  82.         HFONT fontHandle = createFontHandle(this.mHandle,
  83.                                             this.mFont.name,
  84.                                             this.mFont.size,
  85.                                             this.mFont.fontWeight,
  86.                                             this.mFont.italics,
  87.                                             this.mFont.underline);
  88.         sendMsg(this.mHandle, WM_SETFONT, fontHandle, true);
  89.     }
  90.     //-------------------------------------------------------------
  91.  
  92.     protected :
  93.             string mText ;
  94.             int mWidth ;
  95.             int mHeight ;
  96.             int mXpos ;
  97.             int mYpos ;
  98.             HWND mHandle ;            
  99.             string mName ;
  100.             Window mParent ;
  101.             Font mFont;
  102.             bool misHandleCreated;
  103.             ControlType mControlType;
  104.  
  105. }
Add Comment
Please, Sign In to add comment