Changeset 190:df4e66472aff

Show
Ignore:
Timestamp:
10/26/08 10:04:41 (3 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

novocode line endings, indention

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwtx/novocode/CustomSeparator.d

    r188 r190  
    11/** 
    2         Original: com.novocode.naf.swt.custom.CustomSeparator 
    3 ***/ 
     2Original: com.novocode.naf.swt.custom.CustomSeparator 
     3 ***/ 
    44 
    55/******************************************************************************* 
     
    5151class CustomSeparator : Canvas 
    5252{ 
    53   private int lineSize; 
    54   private int style; 
     53    private int lineSize; 
     54    private int style; 
    5555 
    5656 
    57   this(Composite parent, int style) 
    58  
    59     super(parent, style = checkStyle (style)); 
     57    this(Composite parent, int style) 
     58   
     59        super(parent, style = checkStyle (style)); 
    6060 
    61     this.style = style; 
     61        this.style = style; 
    6262 
    63     if((style & DWT.SHADOW_IN) !is 0 || (style & DWT.SHADOW_OUT) !is 0) lineSize = 2; 
    64     else lineSize = 1; 
     63        if((style & DWT.SHADOW_IN) !is 0 || (style & DWT.SHADOW_OUT) !is 0) lineSize = 2; 
     64        else lineSize = 1; 
    6565 
    66     /**addPaintListener(new class() PaintListener 
    67    
    68       public void paintControl(PaintEvent event) { onPaint(event); } 
    69     });*/ 
    70     addListener(DWT.Paint, dgListener(&onPaint)); 
    71  
     66        /**addPaintListener(new class() PaintListener 
     67         
     68          public void paintControl(PaintEvent event) { onPaint(event); } 
     69          });*/ 
     70        addListener(DWT.Paint, dgListener(&onPaint)); 
     71   
    7272 
    7373 
    74   private int checkStyle(int style) 
    75  
    76     int mask = DWT.SHADOW_IN | DWT.SHADOW_OUT| DWT.SHADOW_NONE | DWT.HORIZONTAL | DWT.VERTICAL; 
    77     style &= mask; 
    78     if((style & (DWT.SHADOW_IN | DWT.SHADOW_OUT| DWT.SHADOW_NONE)) is 0) style |= DWT.SHADOW_IN; 
    79     if((style & (DWT.HORIZONTAL | DWT.VERTICAL)) is 0) style |= DWT.VERTICAL; 
    80     return style; 
    81  
     74    private int checkStyle(int style) 
     75   
     76        int mask = DWT.SHADOW_IN | DWT.SHADOW_OUT| DWT.SHADOW_NONE | DWT.HORIZONTAL | DWT.VERTICAL; 
     77        style &= mask; 
     78        if((style & (DWT.SHADOW_IN | DWT.SHADOW_OUT| DWT.SHADOW_NONE)) is 0) style |= DWT.SHADOW_IN; 
     79        if((style & (DWT.HORIZONTAL | DWT.VERTICAL)) is 0) style |= DWT.VERTICAL; 
     80        return style; 
     81   
    8282 
    8383 
    84   public Point computeSize(int wHint, int hHint, bool changed) 
    85   { 
    86     checkWidget(); 
    87     if(wHint is DWT.DEFAULT) wHint = lineSize; 
    88     if(hHint is DWT.DEFAULT) hHint = lineSize; 
    89     return new Point(wHint, hHint); 
    90   } 
    91    
    92  
    93   public bool setFocus() 
    94   { 
    95     checkWidget(); 
    96     return false; 
    97   } 
     84    public Point computeSize(int wHint, int hHint, bool changed) 
     85    { 
     86        checkWidget(); 
     87        if(wHint is DWT.DEFAULT) wHint = lineSize; 
     88        if(hHint is DWT.DEFAULT) hHint = lineSize; 
     89        return new Point(wHint, hHint); 
     90    } 
    9891 
    9992 
    100   private void onPaint(PaintEvent event) 
    101   { 
    102     Rectangle r = getClientArea(); 
    103     if(r.width is 0 || r.height is 0) return; 
    104     bool horiz = ((style & DWT.HORIZONTAL) !is 0); 
    105     int mid = horiz ? r.y + (r.height/2) : r.x + (r.width/2); 
     93    public bool setFocus() 
     94    { 
     95        checkWidget(); 
     96        return false; 
     97    } 
    10698 
    107     Display disp = getDisplay(); 
    108     event.gc.setLineWidth(1); 
    10999 
    110     if((style & DWT.SHADOW_IN) !is 0
     100    private void onPaint(PaintEvent event
    111101    { 
    112       Color shadow = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 
    113       Color highlight = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 
    114       event.gc.setForeground(shadow); 
    115       if(horiz) event.gc.drawLine(r.x, mid-1, r.x+r.width-1, mid-1); 
    116       else event.gc.drawLine(mid-1, r.y, mid-1, r.y+r.height-1); 
    117       event.gc.setForeground(highlight); 
    118       if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); 
    119       else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); 
     102        Rectangle r = getClientArea(); 
     103        if(r.width is 0 || r.height is 0) return; 
     104        bool horiz = ((style & DWT.HORIZONTAL) !is 0); 
     105        int mid = horiz ? r.y + (r.height/2) : r.x + (r.width/2); 
     106 
     107        Display disp = getDisplay(); 
     108        event.gc.setLineWidth(1); 
     109 
     110        if((style & DWT.SHADOW_IN) !is 0) 
     111        { 
     112            Color shadow = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 
     113            Color highlight = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 
     114            event.gc.setForeground(shadow); 
     115            if(horiz) event.gc.drawLine(r.x, mid-1, r.x+r.width-1, mid-1); 
     116            else event.gc.drawLine(mid-1, r.y, mid-1, r.y+r.height-1); 
     117            event.gc.setForeground(highlight); 
     118            if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); 
     119            else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); 
     120        } 
     121        else if((style & DWT.SHADOW_OUT) !is 0) 
     122        { 
     123            Color shadow = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 
     124            Color highlight = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 
     125            event.gc.setForeground(highlight); 
     126            if(horiz) event.gc.drawLine(r.x, mid-1, r.x+r.width-1, mid-1); 
     127            else event.gc.drawLine(mid-1, r.y, mid-1, r.y+r.height-1); 
     128            event.gc.setForeground(shadow); 
     129            if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); 
     130            else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); 
     131        } 
     132        else 
     133        { 
     134            event.gc.setForeground(getForeground()); 
     135            if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); 
     136            else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); 
     137        } 
    120138    } 
    121     else if((style & DWT.SHADOW_OUT) !is 0) 
    122     { 
    123       Color shadow = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 
    124       Color highlight = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 
    125       event.gc.setForeground(highlight); 
    126       if(horiz) event.gc.drawLine(r.x, mid-1, r.x+r.width-1, mid-1); 
    127       else event.gc.drawLine(mid-1, r.y, mid-1, r.y+r.height-1); 
    128       event.gc.setForeground(shadow); 
    129       if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); 
    130       else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); 
    131     } 
    132     else 
    133     { 
    134       event.gc.setForeground(getForeground()); 
    135       if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); 
    136       else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); 
    137     } 
    138   } 
    139139} 
  • dwtx/novocode/ScaledImage.d

    r188 r190  
    3535class ScaledImage : Canvas 
    3636{ 
    37   private const Rectangle DEFAULT_BOUNDS; 
    38    
    39   public static const int IMAGE_PLACEMENT_STRETCH = 0; 
    40   public static const int IMAGE_PLACEMENT_TILE    = 1; 
    41  
    42   private Image image; 
    43  
    44   private Color[] gradientColors; 
    45  
    46   private int[] gradientPercents; 
    47  
    48   private bool gradientVertical; 
    49    
    50   private int imagePlacement = IMAGE_PLACEMENT_STRETCH; 
    51  
    52  
    53   this(Composite parent, int style) 
    54  
    55     super(parent, style | DWT.NO_BACKGROUND); 
    56     this.DEFAULT_BOUNDS = new Rectangle(0, 0, 32, 32); 
    57  
    58     addListener(DWT.Paint, dgListener(&onPaint)); 
    59  
    60  
    61  
    62   private void onPaint(Event event) 
    63  
     37    private const Rectangle DEFAULT_BOUNDS; 
     38 
     39    public static const int IMAGE_PLACEMENT_STRETCH = 0; 
     40    public static const int IMAGE_PLACEMENT_TILE    = 1; 
     41 
     42    private Image image; 
     43 
     44    private Color[] gradientColors; 
     45 
     46    private int[] gradientPercents; 
     47 
     48    private bool gradientVertical; 
     49 
     50    private int imagePlacement = IMAGE_PLACEMENT_STRETCH; 
     51 
     52 
     53    this(Composite parent, int style) 
     54   
     55        super(parent, style | DWT.NO_BACKGROUND); 
     56        this.DEFAULT_BOUNDS = new Rectangle(0, 0, 32, 32); 
     57 
     58        addListener(DWT.Paint, dgListener(&onPaint)); 
     59   
     60 
     61 
     62    private void onPaint(Event event) 
     63   
    6464        Rectangle rect = getClientArea(); 
    6565        GC gc = event.gc; 
    6666        if(image is null 
    67           || image.getImageData().getTransparencyType() !is DWT.TRANSPARENCY_NONE) 
    68         { 
    69  
    70           if(gradientColors !is null) 
    71           { 
    72             // draw a gradient behind the text 
    73             Color oldBackground = gc.getBackground(); 
    74             if(gradientColors.length is 1) 
    75             { 
    76               if(gradientColors[0] !is null) gc.setBackground(gradientColors[0]); 
    77               gc.fillRectangle(0, 0, rect.width, rect.height); 
     67                || image.getImageData().getTransparencyType() !is DWT.TRANSPARENCY_NONE) 
     68        { 
     69 
     70            if(gradientColors !is null) 
     71            { 
     72                // draw a gradient behind the text 
     73                Color oldBackground = gc.getBackground(); 
     74                if(gradientColors.length is 1) 
     75                { 
     76                    if(gradientColors[0] !is null) gc.setBackground(gradientColors[0]); 
     77                    gc.fillRectangle(0, 0, rect.width, rect.height); 
     78                } 
     79                else 
     80                { 
     81                    Color oldForeground = gc.getForeground(); 
     82                    Color lastColor = gradientColors[0]; 
     83                    if(lastColor is null) lastColor = oldBackground; 
     84                    int pos = 0; 
     85                    for(int i = 0; i < gradientPercents.length; ++i) 
     86                    { 
     87                        gc.setForeground(lastColor); 
     88                        lastColor = gradientColors[i + 1]; 
     89                        if(lastColor is null) lastColor = oldBackground; 
     90                        gc.setBackground(lastColor); 
     91                        if(gradientVertical) 
     92                        { 
     93                            int gradientHeight = (gradientPercents[i] * rect.height / 100) 
     94                                - pos; 
     95                            gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, 
     96                                    true); 
     97                            pos += gradientHeight; 
     98                        } 
     99                        else 
     100                        { 
     101                            int gradientWidth = (gradientPercents[i] * rect.width / 100) 
     102                                - pos; 
     103                            gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, 
     104                                    false); 
     105                            pos += gradientWidth; 
     106                        } 
     107                    } 
     108                    if(gradientVertical && pos < rect.height) 
     109                    { 
     110                        gc.setBackground(getBackground()); 
     111                        gc.fillRectangle(0, pos, rect.width, rect.height - pos); 
     112                    } 
     113                    if(!gradientVertical && pos < rect.width) 
     114                    { 
     115                        gc.setBackground(getBackground()); 
     116                        gc.fillRectangle(pos, 0, rect.width - pos, rect.height); 
     117                    } 
     118                    gc.setForeground(oldForeground); 
     119                } 
     120                gc.setBackground(oldBackground); 
    78121            } 
    79122            else 
    80123            { 
    81               Color oldForeground = gc.getForeground(); 
    82               Color lastColor = gradientColors[0]; 
    83               if(lastColor is null) lastColor = oldBackground; 
    84               int pos = 0; 
    85               for(int i = 0; i < gradientPercents.length; ++i) 
    86               { 
    87                 gc.setForeground(lastColor); 
    88                 lastColor = gradientColors[i + 1]; 
    89                 if(lastColor is null) lastColor = oldBackground; 
    90                 gc.setBackground(lastColor); 
    91                 if(gradientVertical) 
    92                 { 
    93                   int gradientHeight = (gradientPercents[i] * rect.height / 100) 
    94                     - pos; 
    95                   gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, 
    96                     true); 
    97                   pos += gradientHeight; 
    98                 } 
    99                 else 
    100                 { 
    101                   int gradientWidth = (gradientPercents[i] * rect.width / 100) 
    102                     - pos; 
    103                   gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, 
    104                     false); 
    105                   pos += gradientWidth; 
    106                 } 
    107               } 
    108               if(gradientVertical && pos < rect.height) 
    109               { 
    110                 gc.setBackground(getBackground()); 
    111                 gc.fillRectangle(0, pos, rect.width, rect.height - pos); 
    112               } 
    113               if(!gradientVertical && pos < rect.width) 
    114               { 
    115                 gc.setBackground(getBackground()); 
    116                 gc.fillRectangle(pos, 0, rect.width - pos, rect.height); 
    117               } 
    118               gc.setForeground(oldForeground); 
    119             } 
    120             gc.setBackground(oldBackground); 
    121           } 
    122           else 
    123           { 
    124             if((getStyle() & DWT.NO_BACKGROUND) !is 0) 
    125             { 
    126               gc.setBackground(getBackground()); 
    127               gc.fillRectangle(rect); 
    128             } 
    129           } 
     124                if((getStyle() & DWT.NO_BACKGROUND) !is 0) 
     125                { 
     126                    gc.setBackground(getBackground()); 
     127                    gc.fillRectangle(rect); 
     128                } 
     129            } 
    130130 
    131131        } 
    132132        if(image !is null) 
    133133        { 
    134           Rectangle ib = image.getBounds(); 
    135           if(imagePlacement is IMAGE_PLACEMENT_TILE) 
    136          
    137             int maxStartX = rect.x + rect.width; 
    138             int maxStartY = rect.y + rect.height; 
    139             for(int x = rect.x; x < maxStartX; x += ib.width) 
    140               for(int y = rect.y; y < maxStartY; y += ib.height) 
    141                 event.gc.drawImage(image, x, y); 
    142          
    143           else // IMAGE_PLACEMENT_STRETCH 
    144          
    145             event.gc.drawImage(image, ib.x, ib.y, ib.width, ib.height, rect.x, 
    146               rect.y, rect.width, rect.height); 
    147          
    148         } 
    149  
    150  
    151  
    152   public void setImage(Image image) 
    153  
    154     this.image = image; 
    155     redraw(); 
    156  
    157    
    158    
    159   public void setImagePlacement(int imagePlacement) 
    160  
    161     this.imagePlacement = imagePlacement; 
    162     redraw(); 
    163  
    164  
    165  
    166   public Point computeSize(int wHint, int hHint, bool changed) 
    167  
    168     checkWidget(); 
    169     Rectangle ib = image !is null ? image.getBounds() : DEFAULT_BOUNDS; 
    170     if(wHint == DWT.DEFAULT) wHint = ib.width; 
    171     if(hHint == DWT.DEFAULT) hHint = ib.height; 
    172     return new Point(wHint, hHint); 
    173  
    174  
    175  
    176   public void setBackground(Color color) 
    177  
    178     super.setBackground(color); 
    179     // Are these settings the same as before? 
    180     if(color !is null && gradientColors is null && gradientPercents is null) 
    181    
    182       Color background = getBackground(); 
    183       if(color is background) 
    184      
    185         return; 
    186      
    187    
    188     gradientColors = null; 
    189     gradientPercents = null; 
    190     redraw(); 
    191  
    192  
    193  
    194   public void setBackground(Color[] colors, int[] percents) 
    195  
    196     setBackground(colors, percents, false); 
    197  
    198  
    199  
    200   public void setBackground(Color[] colors, int[] percents, bool vertical) 
    201  
    202     checkWidget(); 
    203     if(colors !is null) 
    204    
    205       if(percents is null || percents.length !is colors.length - 1) 
    206      
    207         DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    208      
    209       if(getDisplay().getDepth() < 15) 
    210      
    211         // Don't use gradients on low color displays 
    212         colors = [ colors[colors.length - 1] ]; 
    213         percents = []; 
    214      
    215       for(int i = 0; i < percents.length; i++) 
    216      
    217         if(percents[i] < 0 || percents[i] > 100) 
    218        
    219           DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    220        
    221         if(i > 0 && percents[i] < percents[i - 1]) 
    222        
    223           DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    224        
    225      
    226    
    227  
    228     // Are these settings the same as before? 
    229     Color background = getBackground(); 
    230     if((gradientColors !is null) && (colors !is null) 
    231       && (gradientColors.length is colors.length)) 
    232    
    233       bool same = false; 
    234       for(int i = 0; i < gradientColors.length; i++) 
    235      
    236         same = (gradientColors[i] is colors[i]) 
    237           || ((gradientColors[i] is null) && (colors[i] is background)) 
    238           || ((gradientColors[i] is background) && (colors[i] is null)); 
    239         if(!same) break; 
    240      
    241       if(same) 
    242      
    243         for(int i = 0; i < gradientPercents.length; i++) 
    244        
    245           same = gradientPercents[i] is percents[i]; 
    246           if(!same) break; 
    247        
    248      
    249       if(same && this.gradientVertical is vertical) return; 
    250    
    251     // Store the new settings 
    252     if(colors is null) 
    253    
    254       gradientColors = null; 
    255       gradientPercents = null; 
    256       gradientVertical = false; 
    257    
    258     else 
    259    
    260       gradientColors = new Color[colors.length]; 
    261       for(int i = 0; i < colors.length; ++i) 
    262         gradientColors[i] = (colors[i] !is null) ? colors[i] : background; 
    263       gradientPercents = new int[percents.length]; 
    264       for(int i = 0; i < percents.length; ++i) 
    265         gradientPercents[i] = percents[i]; 
    266       gradientVertical = vertical; 
    267    
    268     // Refresh with the new settings 
    269     redraw(); 
    270  
     134            Rectangle ib = image.getBounds(); 
     135            if(imagePlacement is IMAGE_PLACEMENT_TILE) 
     136           
     137                int maxStartX = rect.x + rect.width; 
     138                int maxStartY = rect.y + rect.height; 
     139                for(int x = rect.x; x < maxStartX; x += ib.width) 
     140                    for(int y = rect.y; y < maxStartY; y += ib.height) 
     141                        event.gc.drawImage(image, x, y); 
     142           
     143            else // IMAGE_PLACEMENT_STRETCH 
     144           
     145                event.gc.drawImage(image, ib.x, ib.y, ib.width, ib.height, rect.x, 
     146                        rect.y, rect.width, rect.height); 
     147           
     148        } 
     149   
     150 
     151 
     152    public void setImage(Image image) 
     153   
     154        this.image = image; 
     155        redraw(); 
     156   
     157 
     158 
     159    public void setImagePlacement(int imagePlacement) 
     160   
     161        this.imagePlacement = imagePlacement; 
     162        redraw(); 
     163   
     164 
     165 
     166    public Point computeSize(int wHint, int hHint, bool changed) 
     167   
     168        checkWidget(); 
     169        Rectangle ib = image !is null ? image.getBounds() : DEFAULT_BOUNDS; 
     170        if(wHint == DWT.DEFAULT) wHint = ib.width; 
     171        if(hHint == DWT.DEFAULT) hHint = ib.height; 
     172        return new Point(wHint, hHint); 
     173   
     174 
     175 
     176    public void setBackground(Color color) 
     177   
     178        super.setBackground(color); 
     179        // Are these settings the same as before? 
     180        if(color !is null && gradientColors is null && gradientPercents is null) 
     181       
     182            Color background = getBackground(); 
     183            if(color is background) 
     184           
     185                return; 
     186           
     187       
     188        gradientColors = null; 
     189        gradientPercents = null; 
     190        redraw(); 
     191   
     192 
     193 
     194    public void setBackground(Color[] colors, int[] percents) 
     195   
     196        setBackground(colors, percents, false); 
     197   
     198 
     199 
     200    public void setBackground(Color[] colors, int[] percents, bool vertical) 
     201   
     202        checkWidget(); 
     203        if(colors !is null) 
     204       
     205            if(percents is null || percents.length !is colors.length - 1) 
     206           
     207                DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     208           
     209            if(getDisplay().getDepth() < 15) 
     210           
     211                // Don't use gradients on low color displays 
     212                colors = [ colors[colors.length - 1] ]; 
     213                percents = []; 
     214           
     215            for(int i = 0; i < percents.length; i++) 
     216           
     217                if(percents[i] < 0 || percents[i] > 100) 
     218               
     219                    DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     220               
     221                if(i > 0 && percents[i] < percents[i - 1]) 
     222               
     223                    DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     224               
     225           
     226       
     227 
     228        // Are these settings the same as before? 
     229        Color background = getBackground(); 
     230        if((gradientColors !is null) && (colors !is null) 
     231                && (gradientColors.length is colors.length)) 
     232       
     233            bool same = false; 
     234            for(int i = 0; i < gradientColors.length; i++) 
     235           
     236                same = (gradientColors[i] is colors[i]) 
     237                    || ((gradientColors[i] is null) && (colors[i] is background)) 
     238                    || ((gradientColors[i] is background) && (colors[i] is null)); 
     239                if(!same) break; 
     240           
     241            if(same) 
     242           
     243                for(int i = 0; i < gradientPercents.length; i++) 
     244               
     245                    same = gradientPercents[i] is percents[i]; 
     246                    if(!same) break; 
     247               
     248           
     249            if(same && this.gradientVertical is vertical) return; 
     250       
     251        // Store the new settings 
     252        if(colors is null) 
     253       
     254            gradientColors = null; 
     255            gradientPercents = null; 
     256            gradientVertical = false; 
     257       
     258        else 
     259       
     260            gradientColors = new Color[colors.length]; 
     261            for(int i = 0; i < colors.length; ++i) 
     262                gradientColors[i] = (colors[i] !is null) ? colors[i] : background; 
     263            gradientPercents = new int[percents.length]; 
     264            for(int i = 0; i < percents.length; ++i) 
     265                gradientPercents[i] = percents[i]; 
     266            gradientVertical = vertical; 
     267       
     268        // Refresh with the new settings 
     269        redraw(); 
     270   
    271271} 
  • dwtx/novocode/SizeBorder.d

    r188 r190  
    4747class SizeBorder : Canvas 
    4848{ 
    49   private static const long UPDATE_DELAY = 25; 
    50    
    51   private static const int AREA_NONE = 0; 
    52   private static const int AREA_N    = 1; 
    53   private static const int AREA_S    = 2; 
    54   private static const int AREA_E    = 4; 
    55   private static const int AREA_W    = 8; 
    56   private static const int AREA_NW   = 9; 
    57   private static const int AREA_NE   = 5; 
    58   private static const int AREA_SE   = 6; 
    59   private static const int AREA_SW   = 10; 
    60    
    61   private Rectangle snapBack; 
    62   private bool cancelled = true; 
    63   private /**volatile*/ long lastUpdate; 
    64   private Timer timer; 
    65   private TimerTask timerTask; 
    66   private Composite resizableParent; 
    67   private Point minSize, mouseDownOffset; 
    68   private int borderWidth = 4, cornerSize = 16; 
    69   private Display display; 
    70   private Cursor cursor, cursorNWSE, cursorNESW, cursorWE, cursorNS; 
    71   private int currentArea; 
    72   private Color highlightShadowColor, lightShadowColor, normalShadowColor,darkShadowColor; 
    73  
    74  
    75   this(Composite parent, int style) 
    76  
    77     this(parent, parent.getShell(), style); 
    78  
    79  
    80    
    81   this(Composite parent, Composite resizableParent, int style) 
    82  
    83     super(parent, checkStyle (style)); 
    84     this.timer = new Timer(true); 
    85     this.resizableParent = resizableParent; 
    86     this.display = getDisplay(); 
    87  
    88     cursorNWSE = new Cursor(getDisplay(), DWT.CURSOR_SIZENWSE); 
    89     cursorNESW = new Cursor(getDisplay(), DWT.CURSOR_SIZENESW); 
    90     cursorWE = new Cursor(getDisplay(), DWT.CURSOR_SIZEWE); 
    91     cursorNS = new Cursor(getDisplay(), DWT.CURSOR_SIZENS); 
    92  
    93     addListener(DWT.Dispose, dgListener(&onDispose)); 
    94  
    95     if((style & DWT.BORDER) !is 0) 
    96    
    97       highlightShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 
    98       lightShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_LIGHT_SHADOW); 
    99       normalShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 
    100       darkShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_DARK_SHADOW); 
    101    
    102       addListener(DWT.Paint, dgListener(&onPaint)); 
    103    
    104  
    105     addListener(DWT.MouseDown, dgListener(&onMouseDown)); 
    106  
    107     addListener(DWT.MouseMove, dgListener(&onMouseMove)); 
    108      
    109     addListener(DWT.MouseUp, dgListener(&onMouseUp)); 
    110      
    111     addListener(DWT.Show, dgListener(&onShow)); 
    112  
    113  
    114   private void onDispose(Event event) 
    115  
     49    private static const long UPDATE_DELAY = 25; 
     50 
     51    private static const int AREA_NONE = 0; 
     52    private static const int AREA_N    = 1; 
     53    private static const int AREA_S    = 2; 
     54    private static const int AREA_E    = 4; 
     55    private static const int AREA_W    = 8; 
     56    private static const int AREA_NW   = 9; 
     57    private static const int AREA_NE   = 5; 
     58    private static const int AREA_SE   = 6; 
     59    private static const int AREA_SW   = 10; 
     60 
     61    private Rectangle snapBack; 
     62    private bool cancelled = true; 
     63    private /**volatile*/ long lastUpdate; 
     64    private Timer timer; 
     65    private TimerTask timerTask; 
     66    private Composite resizableParent; 
     67    private Point minSize, mouseDownOffset; 
     68    private int borderWidth = 4, cornerSize = 16; 
     69    private Display display; 
     70    private Cursor cursor, cursorNWSE, cursorNESW, cursorWE, cursorNS; 
     71    private int currentArea; 
     72    private Color highlightShadowColor, lightShadowColor, normalShadowColor,darkShadowColor; 
     73 
     74 
     75    this(Composite parent, int style) 
     76   
     77        this(parent, parent.getShell(), style); 
     78   
     79 
     80 
     81    this(Composite parent, Composite resizableParent, int style) 
     82   
     83        super(parent, checkStyle (style)); 
     84        this.timer = new Timer(true); 
     85        this.resizableParent = resizableParent; 
     86        this.display = getDisplay(); 
     87 
     88        cursorNWSE = new Cursor(getDisplay(), DWT.CURSOR_SIZENWSE); 
     89        cursorNESW = new Cursor(getDisplay(), DWT.CURSOR_SIZENESW); 
     90        cursorWE = new Cursor(getDisplay(), DWT.CURSOR_SIZEWE); 
     91        cursorNS = new Cursor(getDisplay(), DWT.CURSOR_SIZENS); 
     92 
     93        addListener(DWT.Dispose, dgListener(&onDispose)); 
     94 
     95        if((style & DWT.BORDER) !is 0) 
     96       
     97            highlightShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); 
     98            lightShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_LIGHT_SHADOW); 
     99            normalShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); 
     100            darkShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_DARK_SHADOW); 
     101 
     102            addListener(DWT.Paint, dgListener(&onPaint)); 
     103       
     104 
     105        addListener(DWT.MouseDown, dgListener(&onMouseDown)); 
     106 
     107        addListener(DWT.MouseMove, dgListener(&onMouseMove)); 
     108 
     109        addListener(DWT.MouseUp, dgListener(&onMouseUp)); 
     110 
     111        addListener(DWT.Show, dgListener(&onShow)); 
     112   
     113 
     114    private void onDispose(Event event) 
     115   
    116116        cursorNWSE.dispose(); 
    117117        cursorNESW.dispose(); 
     
    120120 
    121121        timer.cancel(); 
    122  
    123  
    124  
    125   private void onPaint(Event event) 
    126  
    127           Rectangle r = getClientArea(); 
    128           if(r.width is 0 || r.height is 0) return; 
    129           drawBevelRect(event.gc, r.x, r.y, r.width-1, r.height-1, lightShadowColor, darkShadowColor); 
    130           drawBevelRect(event.gc, r.x+1, r.y+1, r.width-3, r.height-3, highlightShadowColor, normalShadowColor); 
    131  
    132  
    133  
    134   private void onMouseDown(Event event) 
    135  
     122   
     123 
     124 
     125    private void onPaint(Event event) 
     126   
     127        Rectangle r = getClientArea(); 
     128        if(r.width is 0 || r.height is 0) return; 
     129        drawBevelRect(event.gc, r.x, r.y, r.width-1, r.height-1, lightShadowColor, darkShadowColor); 
     130        drawBevelRect(event.gc, r.x+1, r.y+1, r.width-3, r.height-3, highlightShadowColor, normalShadowColor); 
     131   
     132 
     133 
     134    private void onMouseDown(Event event) 
     135   
    136136        if(event.button is 1) 
    137137        { 
    138           currentArea = areaAtPoint(event.x, event.y); 
    139           if(currentArea is AREA_NONE) return; 
    140           if(cast(Shell)resizableParent !is null) 
    141             mouseDownOffset = toDisplay(event.x, event.y); 
    142           else 
    143             mouseDownOffset = display.map(/**SizeBorder.this*/getSizeBorder(), resizableParent.getParent(), event.x, event.y); 
    144           snapBack = resizableParent.getBounds(); 
    145           cancelled = false; 
     138            currentArea = areaAtPoint(event.x, event.y); 
     139            if(currentArea is AREA_NONE) return; 
     140            if(cast(Shell)resizableParent !is null) 
     141                mouseDownOffset = toDisplay(event.x, event.y); 
     142            else 
     143                mouseDownOffset = display.map(/**SizeBorder.this*/getSizeBorder(), resizableParent.getParent(), event.x, event.y); 
     144            snapBack = resizableParent.getBounds(); 
     145            cancelled = false; 
    146146        } 
    147147        else if(event.button is 3 && (event.stateMask & DWT.BUTTON1) !is 0) // chord click 
    148148        { 
    149           if(snapBack !is null) 
    150          
    151             resizableParent.setBounds(snapBack); 
    152             snapBack = null; 
    153             cancelled = true; 
    154          
    155         } 
    156  
    157  
    158  
    159   private void onMouseMove(Event event) 
    160  
     149            if(snapBack !is null) 
     150           
     151                resizableParent.setBounds(snapBack); 
     152                snapBack = null; 
     153                cancelled = true; 
     154           
     155        } 
     156   
     157 
     158 
     159    private void onMouseMove(Event event) 
     160   
    161161        if((event.stateMask & DWT.BUTTON1) is 0) updateCursor(areaAtPoint(event.x, event.y)); 
    162162 
    163163        if(!cancelled && (event.stateMask & DWT.BUTTON1) !is 0) 
    164164        { 
    165           if(timerTask !is null) 
    166           { 
     165            if(timerTask !is null) 
     166            { 
     167                timerTask.cancel(); 
     168                timerTask = null; 
     169            } 
     170            long now = System.currentTimeMillis(); 
     171            if(lastUpdate + UPDATE_DELAY < now) 
     172            { 
     173                performResize(event); 
     174                lastUpdate = now; 
     175            } 
     176            else 
     177            { 
     178                timerTask = new class() TimerTask 
     179                { 
     180                    public void run() 
     181                    { 
     182                        TimerTask executingTask = this; 
     183                        event.display.asyncExec(new class() Runnable 
     184                            { 
     185                                public void run() 
     186                                { 
     187                                    if(executingTask !is timerTask) return; 
     188                                    performResize(event); 
     189                                } 
     190                            }); 
     191                    } 
     192                }; 
     193                timer.schedule(timerTask, UPDATE_DELAY); 
     194            } 
     195        } 
     196    } 
     197 
     198 
     199    private void onMouseUp(Event event) 
     200    { 
     201        if(timerTask !is null) 
     202        { 
    167203            timerTask.cancel(); 
    168204            timerTask = null; 
    169           } 
    170           long now = System.currentTimeMillis(); 
    171           if(lastUpdate + UPDATE_DELAY < now) 
    172           { 
     205        } 
     206        if(!cancelled && (event.stateMask & DWT.BUTTON1) !is 0) 
     207        { 
    173208            performResize(event); 
    174             lastUpdate = now; 
    175           } 
    176           else 
    177           { 
    178             timerTask = new class() TimerTask 
    179             { 
    180               public void run() 
    181               { 
    182                 TimerTask executingTask = this; 
    183                 event.display.asyncExec(new class() Runnable 
    184                 { 
    185                   public void run() 
    186                   { 
    187                     if(executingTask !is timerTask) return; 
    188                     performResize(event); 
    189                   } 
    190                 }); 
    191               } 
    192             }; 
    193             timer.schedule(timerTask, UPDATE_DELAY); 
    194           } 
    195         } 
    196   } 
    197  
    198  
    199   private void onMouseUp(Event event) 
    200   { 
    201         if(timerTask !is null) 
    202         { 
    203           timerTask.cancel(); 
    204           timerTask = null; 
    205         } 
    206         if(!cancelled && (event.stateMask & DWT.BUTTON1) !is 0) 
    207         { 
    208           performResize(event); 
    209         } 
    210   } 
    211  
    212  
    213   private void onShow(Event event) 
    214   { 
     209        } 
     210    } 
     211 
     212 
     213    private void onShow(Event event) 
     214    { 
    215215        Point p = toControl(display.getCursorLocation()); 
    216216        updateCursor(areaAtPoint(p.x, p.y)); 
    217  
    218  
    219  
    220   private SizeBorder getSizeBorder() 
    221  
    222       return this; 
    223  
    224  
    225   private static int checkStyle(int style) 
    226  
    227     //int mask = DWT.NONE; 
    228     //style &= mask; 
    229     style = DWT.NO_FOCUS; 
    230     return style; 
    231  
    232  
    233  
    234   private void performResize(Event event) 
    235  
    236     // Make sure we stay within the container parent's client area 
    237     Rectangle ca; 
    238     if(cast(Shell)resizableParent !is null) ca = getDisplay().getClientArea(); 
    239     else ca = getDisplay().map(resizableParent.getParent(), null, resizableParent.getParent().getClientArea()); 
    240     Point caOffset = toControl(ca.x, ca.y); 
    241     event.x = Math.max(Math.min(event.x, caOffset.x + ca.width - 1), caOffset.x); 
    242     event.y = Math.max(Math.min(event.y, caOffset.y + ca.height - 1), caOffset.y); 
    243  
    244     // Compute movement relative to position at MouseDown event 
    245     Point movement = (cast(Shell)resizableParent !is null) 
    246       ? toDisplay(event.x, event.y) 
    247       : display.map(this, resizableParent.getParent(), event.x, event.y); 
    248     movement.x -= mouseDownOffset.x; 
    249     movement.y -= mouseDownOffset.y; 
    250      
    251