1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.*; 15 import org.eclipse.swt.internal.win32.*; 16 import org.eclipse.swt.*; 17 import org.eclipse.swt.graphics.*; 18 19 33 34 public class ColorDialog extends Dialog { 35 Display display; 36 int width, height; 37 RGB rgb; 38 39 56 public ColorDialog (Shell parent) { 57 this (parent, SWT.PRIMARY_MODAL); 58 } 59 60 88 public ColorDialog (Shell parent, int style) { 89 super (parent, style); 90 checkSubclass (); 91 } 92 93 int CCHookProc (int hdlg, int uiMsg, int lParam, int lpData) { 94 switch (uiMsg) { 95 case OS.WM_INITDIALOG: { 96 RECT rect = new RECT (); 97 OS.GetWindowRect (hdlg, rect); 98 width = rect.right - rect.left; 99 height = rect.bottom - rect.top; 100 if (title != null && title.length () != 0) { 101 102 TCHAR buffer = new TCHAR (0, title, true); 103 OS.SetWindowText (hdlg, buffer); 104 } 105 break; 106 } 107 case OS.WM_DESTROY: { 108 RECT rect = new RECT (); 109 OS.GetWindowRect (hdlg, rect); 110 int newWidth = rect.right - rect.left; 111 int newHeight = rect.bottom - rect.top; 112 if (newWidth < width || newHeight < height) { 113 } else { 115 if (newWidth > width || newHeight > height) { 116 } 118 } 119 break; 120 } 121 } 122 return 0; 123 } 124 125 132 public RGB getRGB () { 133 return rgb; 134 } 135 136 149 public RGB open () { 150 151 152 int hwndOwner = parent.handle; 153 154 155 Callback callback = new Callback (this, "CCHookProc", 4); int lpfnHook = callback.getAddress (); 157 if (lpfnHook == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); 158 159 160 display = parent.display; 161 if (display.lpCustColors == 0) { 162 int hHeap = OS.GetProcessHeap (); 163 display.lpCustColors = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 16 * 4); 164 } 165 166 167 CHOOSECOLOR lpcc = new CHOOSECOLOR (); 168 lpcc.lStructSize = CHOOSECOLOR.sizeof; 169 lpcc.Flags = OS.CC_ANYCOLOR | OS.CC_ENABLEHOOK; 170 lpcc.lpfnHook = lpfnHook; 172 lpcc.hwndOwner = hwndOwner; 173 lpcc.lpCustColors = display.lpCustColors; 174 if (rgb != null) { 175 lpcc.Flags |= OS.CC_RGBINIT; 176 int red = rgb.red & 0xFF; 177 int green = (rgb.green << 8) & 0xFF00; 178 int blue = (rgb.blue << 16) & 0xFF0000; 179 lpcc.rgbResult = red | green | blue; 180 } 181 182 183 Shell oldModal = null; 184 if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) { 185 oldModal = display.getModalDialogShell (); 186 display.setModalDialogShell (parent); 187 } 188 189 190 boolean success = OS.ChooseColor (lpcc); 191 192 193 if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) { 194 display.setModalDialogShell (oldModal); 195 } 196 197 if (success) { 198 int red = lpcc.rgbResult & 0xFF; 199 int green = (lpcc.rgbResult >> 8) & 0xFF; 200 int blue = (lpcc.rgbResult >> 16) & 0xFF; 201 rgb = new RGB (red, green, blue); 202 } 203 204 205 callback.dispose (); 206 207 208 214 216 222 224 if (!success) return null; 225 return rgb; 226 } 227 228 236 public void setRGB (RGB rgb) { 237 this.rgb = rgb; 238 } 239 240 } 241 | Popular Tags |