javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/ColorDialog.java
changeset 80 d6dafc5d983f
parent 21 2a9601315dfc
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
   102  * @see PaletteData#getRGBs
   102  * @see PaletteData#getRGBs
   103  */
   103  */
   104 public RGB getRGB () {
   104 public RGB getRGB () {
   105     return rgb;
   105     return rgb;
   106 }
   106 }
       
   107 
   107 /**
   108 /**
   108  * Makes the receiver visible and brings it to the front
   109  * Makes the receiver visible and brings it to the front
   109  * of the display.
   110  * of the display.
   110  *
   111  *
   111  * @return the selected color, or null if the dialog was
   112  * @return the selected color, or null if the dialog was
   115  * @exception SWTException <ul>
   116  * @exception SWTException <ul>
   116  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
   117  *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
   117  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
   118  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
   118  * </ul>
   119  * </ul>
   119  */
   120  */
   120 public RGB open () {
   121 public RGB open() {
   121    int colorHandle = 0;
   122     int r = 0;
   122    colorHandle = OS.QColor_new();
   123     int g = 0;
   123    if (rgb != null ){
   124     int b = 0;
   124        OS.QColor_setRed(colorHandle, rgb.red);
   125     if (rgb != null) {
   125        OS.QColor_setGreen(colorHandle, rgb.green);
   126         r = rgb.red;
   126        OS.QColor_setBlue(colorHandle, rgb.blue);
   127         g = rgb.green;
   127    }
   128         b = rgb.blue;
   128    
   129     }
   129    DisposeListener listener = new DisposeListener() {
   130 
   130        public void widgetDisposed(DisposeEvent e) {
   131     DisposeListener listener = new DisposeListener() {
   131            if (e.widget == parent) {
   132         public void widgetDisposed(DisposeEvent e) {
   132                // Close dialogs which are opened on top of parent.
   133             if (e.widget == parent) {
   133                OS.QDialog_swt_closeDialogs(parent.handle, dialogID);
   134                 // Close dialogs which are opened on top of parent.
   134            }
   135                 OS.QDialog_swt_closeDialogs(parent.handle, dialogID);
   135        }
   136             }
   136    };
   137         }
   137    parent.addDisposeListener(listener);
   138     };
   138    int qtLayoutDirection = (style & SWT.RIGHT_TO_LEFT) != 0 ? OS.QT_RIGHTTOLEFT
   139     parent.addDisposeListener(listener);
   139            : OS.QT_LEFTTORIGHT;
   140 
   140    
   141     int newColorHandle = 0;
   141    int color = OS.QColorDialog_getColor( colorHandle,parent.handle, dialogID, qtLayoutDirection );
   142     try {
   142    
   143         // Open the dialog
   143    if (parent != null && !parent.isDisposed()) {
   144         newColorHandle = OS.QColorDialog_getColor(r, g, b, parent.handle, dialogID, 
   144        parent.removeDisposeListener(listener);
   145             (style & SWT.RIGHT_TO_LEFT) != 0 ? OS.QT_RIGHTTOLEFT : OS.QT_LEFTTORIGHT);
   145    }
   146     }
   146    
   147     finally {
   147    OS.QColor_delete( colorHandle );
   148         if (parent != null && !parent.isDisposed()) {
   148    if (color == 0 || !OS.QColor_isValid(color) ){
   149             parent.removeDisposeListener(listener);
   149        return null;
   150         }
   150    }
   151     }
   151    int red = OS.QColor_red(color);    
   152     
   152    int blue = OS.QColor_blue( color );
   153     if (newColorHandle == 0) {
   153    int green = OS.QColor_green( color );
   154         return null;
   154    rgb = new RGB(red,green,blue);
   155     }
   155    return rgb;
   156     
       
   157     try {
       
   158         if (OS.QColor_isValid(newColorHandle)) {
       
   159             int red = OS.QColor_red(newColorHandle);
       
   160             int blue = OS.QColor_blue(newColorHandle);
       
   161             int green = OS.QColor_green(newColorHandle);
       
   162             rgb = new RGB(red, green, blue);
       
   163         }
       
   164     }
       
   165     finally {
       
   166         OS.QColor_delete(newColorHandle);
       
   167     }
       
   168     
       
   169     return rgb;
   156 }
   170 }
       
   171 
   157 /**
   172 /**
   158  * Sets the receiver's selected color to be the argument.
   173  * Sets the receiver's selected color to be the argument.
   159  *
   174  *
   160  * @param rgb the new RGB value for the selected color, may be
   175  * @param rgb the new RGB value for the selected color, may be
   161  *        null to let the platform select a default when
   176  *        null to let the platform select a default when