1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.win32.*; 15 import org.eclipse.swt.*; 16 import org.eclipse.swt.graphics.*; 17 18 31 32 public class TabItem extends Item { 33 TabFolder parent; 34 Control control; 35 String toolTipText; 36 37 67 public TabItem (TabFolder parent, int style) { 68 super (parent, style); 69 this.parent = parent; 70 parent.createItem (this, parent.getItemCount ()); 71 } 72 73 105 public TabItem (TabFolder parent, int style, int index) { 106 super (parent, style); 107 this.parent = parent; 108 parent.createItem (this, index); 109 } 110 111 void _setText (int index, String string) { 112 119 if (OS.COMCTL32_MAJOR >= 6 && image != null) { 120 if (string.indexOf ('&') != -1) { 121 int length = string.length (); 122 char[] text = new char [length]; 123 string.getChars ( 0, length, text, 0); 124 int i = 0, j = 0; 125 for (i=0; i<length; i++) { 126 if (text[i] != '&') text [j++] = text [i]; 127 } 128 if (j < i) string = new String (text, 0, j); 129 } 130 } 131 int hwnd = parent.handle; 132 int hHeap = OS.GetProcessHeap (); 133 TCHAR buffer = new TCHAR (parent.getCodePage (), string, true); 134 int byteCount = buffer.length () * TCHAR.sizeof; 135 int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 136 OS.MoveMemory (pszText, buffer, byteCount); 137 TCITEM tcItem = new TCITEM (); 138 tcItem.mask = OS.TCIF_TEXT; 139 tcItem.pszText = pszText; 140 OS.SendMessage (hwnd, OS.TCM_SETITEM, index, tcItem); 141 OS.HeapFree (hHeap, 0, pszText); 142 } 143 144 protected void checkSubclass () { 145 if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); 146 } 147 148 void destroyWidget () { 149 parent.destroyItem (this); 150 releaseHandle (); 151 } 152 153 165 public Control getControl () { 166 checkWidget(); 167 return control; 168 } 169 170 180 public TabFolder getParent () { 181 checkWidget(); 182 return parent; 183 } 184 185 196 public String getToolTipText () { 197 checkWidget(); 198 return toolTipText; 199 } 200 201 void releaseHandle () { 202 super.releaseHandle (); 203 parent = null; 204 } 205 206 void releaseParent () { 207 super.releaseParent (); 208 int index = parent.indexOf (this); 209 if (index == parent.getSelectionIndex ()) { 210 if (control != null) control.setVisible (false); 211 } 212 } 213 214 void releaseWidget () { 215 super.releaseWidget (); 216 control = null; 217 } 218 219 234 public void setControl (Control control) { 235 checkWidget(); 236 if (control != null) { 237 if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); 238 if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT); 239 } 240 if (this.control != null && this.control.isDisposed ()) { 241 this.control = null; 242 } 243 Control oldControl = this.control, newControl = control; 244 this.control = control; 245 int index = parent.indexOf (this); 246 if (index != parent.getSelectionIndex ()) { 247 if (newControl != null) newControl.setVisible (false); 248 return; 249 } 250 if (newControl != null) { 251 newControl.setBounds (parent.getClientArea ()); 252 newControl.setVisible (true); 253 } 254 if (oldControl != null) oldControl.setVisible (false); 255 } 256 257 public void setImage (Image image) { 258 checkWidget(); 259 int index = parent.indexOf (this); 260 if (index == -1) return; 261 super.setImage (image); 262 270 if (OS.COMCTL32_MAJOR >= 6) { 271 if (text.indexOf ('&') != -1) _setText (index, text); 272 } 273 int hwnd = parent.handle; 274 TCITEM tcItem = new TCITEM (); 275 tcItem.mask = OS.TCIF_IMAGE; 276 tcItem.iImage = parent.imageIndex (image); 277 OS.SendMessage (hwnd, OS.TCM_SETITEM, index, tcItem); 278 } 279 305 public void setText (String string) { 306 checkWidget(); 307 if (string == null) error (SWT.ERROR_NULL_ARGUMENT); 308 if (string.equals (text)) return; 309 int index = parent.indexOf (this); 310 if (index == -1) return; 311 super.setText (string); 312 _setText (index, string); 313 } 314 315 326 public void setToolTipText (String string) { 327 checkWidget(); 328 toolTipText = string; 329 } 330 331 } 332 | Popular Tags |