1 /** DGui project file. 2 3 Copyright: Trogu Antonio Davide 2011-2013 4 5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 7 Authors: Trogu Antonio Davide 8 */ 9 module dguihub.core.controls.textcontrol; 10 11 public import dguihub.core.controls.subclassedcontrol; 12 13 abstract class TextControl : SubclassedControl { 14 public Event!(Control, EventArgs) textChanged; 15 16 public void appendText(string s) { 17 if (this.created) { 18 this.sendMessage(EM_REPLACESEL, true, cast(LPARAM)toUTFz!(wchar*)(s)); 19 } else { 20 this._text ~= s; 21 } 22 } 23 24 @property public final bool readOnly() { 25 return cast(bool)(this.getStyle() & ES_READONLY); 26 } 27 28 @property public final void readOnly(bool b) { 29 this.setStyle(ES_READONLY, b); 30 } 31 32 public void undo() { 33 this.sendMessage(EM_UNDO, 0, 0); 34 } 35 36 public void cut() { 37 this.sendMessage(WM_CUT, 0, 0); 38 } 39 40 public void copy() { 41 this.sendMessage(WM_COPY, 0, 0); 42 } 43 44 public void paste() { 45 this.sendMessage(WM_PASTE, 0, 0); 46 } 47 48 public void selectAll() { 49 this.sendMessage(EM_SETSEL, 0, -1); 50 } 51 52 public void clear() { 53 this.sendMessage(WM_CLEAR, 0, 0); 54 } 55 56 @property public bool modified() { 57 if (this.created) { 58 return cast(bool)this.sendMessage(EM_GETMODIFY, 0, 0); 59 } 60 61 return false; 62 } 63 64 @property public void modified(bool b) { 65 this.sendMessage(EM_SETMODIFY, b, 0); 66 } 67 68 @property public int textLength() { 69 if (this.created) { 70 return getWindowTextLength(this._handle); 71 } 72 73 return this._text.length; 74 } 75 76 @property public final string selectedText() { 77 CHARRANGE chrg = void; //Inizializzata sotto 78 79 this.sendMessage(EM_EXGETSEL, 0, cast(LPARAM)&chrg); 80 return this.text[chrg.cpMin .. chrg.cpMax]; 81 } 82 83 @property public final int selectionStart() { 84 CHARRANGE chrg = void; //Inizializzata sotto 85 86 this.sendMessage(EM_EXGETSEL, 0, cast(LPARAM)&chrg); 87 return chrg.cpMin; 88 } 89 90 @property public final int selectionLength() { 91 CHARRANGE chrg = void; //Inizializzata sotto 92 93 this.sendMessage(EM_EXGETSEL, 0, cast(LPARAM)&chrg); 94 return chrg.cpMax - chrg.cpMin; 95 } 96 97 protected override void createControlParams(ref CreateControlParams ccp) { 98 this.setStyle(WS_TABSTOP, true); 99 ccp.defaultBackColor = SystemColors.colorWindow; 100 101 super.createControlParams(ccp); 102 } 103 104 protected override void onReflectedMessage(ref Message m) { 105 if (m.msg == WM_COMMAND && HIWORD(m.wParam) == EN_CHANGE 106 && TextControl.hasBit(this._cBits, ControlBits.canNotify)) { 107 this.onTextChanged(EventArgs.empty); 108 } 109 110 super.onReflectedMessage(m); 111 } 112 113 protected override void onHandleCreated(EventArgs e) { 114 this.modified = false; // Force to 'False' 115 116 super.onHandleCreated(e); 117 } 118 119 protected void onTextChanged(EventArgs e) { 120 this.textChanged(this, e); 121 } 122 }