Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331948

Summary: setBackground does not work in DateTime with SWT.CALENDAR
Product: [Eclipse Project] Platform Reporter: Bogdan Gheorghe <gheorghe>
Component: SWTAssignee: Arun Thondapu <arunkumar.thondapu>
Status: RESOLVED FIXED QA Contact: Carolyn MacLeod <carolynmacleod4>
Severity: normal    
Priority: P3 CC: carolynmacleod4
Version: 3.7   
Target Milestone: 4.2 M3   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Proposed patch
none
Updated patch
none
new patch that follows framework pattern and includes getter
none
modified patch none

Description Bogdan Gheorghe CLA 2010-12-06 15:35:26 EST
Only the header of the calendar changes, not the content. It should be the other way around. We need to set the base color (not the bg color) in the handle when used with SWT.CALENDAR.
Comment 1 Bogdan Gheorghe CLA 2010-12-06 16:55:54 EST
Arun, please take a look at this.
Comment 2 Arun Thondapu CLA 2011-01-18 03:27:10 EST
Created attachment 186976 [details]
Proposed patch
Comment 3 Arun Thondapu CLA 2011-01-18 03:40:22 EST
I had to override the setBackgroundColor method to get the desired behavior as stated in the Description, specifically to ensure that the calendar header doesn't change its color.
I have tested the patch with GTK 2.20. Please review the changes, thanks!
Comment 4 Bogdan Gheorghe CLA 2011-02-22 12:48:23 EST
In setBackgroundColor, you get gtk_rc_style_get_color_flags but don't do anything with it in the end. Is this needed?
Comment 5 Arun Thondapu CLA 2011-02-25 15:42:46 EST
Created attachment 189852 [details]
Updated patch

The flags variable is indeed not being used and is not required. I missed it somehow while creating the patch, I have removed the relevant portions of code now. Thanks for pointing it out!

Please review the revised patch. Thanks!
Comment 6 Carolyn MacLeod CLA 2011-03-04 14:49:39 EST
Created attachment 190437 [details]
new patch that follows framework pattern and includes getter

Hi, Arun. Here is the patch I would like to go with. It overrides Control's setBackgroundColor and getBackgroundColor, and is similar to overrides that have been done in Text, Spinner, Table, List, etc. to set the base color.
I will release this after you have finished updating the patch in bug 329291.
Comment 7 Arun Thondapu CLA 2011-03-07 14:11:42 EST
Thanks for the new patch Carolyn!
I just realized there is a JUnit failure with this patch and I'll look into it.(In reply to comment #6)
> Created attachment 190437 [details]
> new patch that follows framework pattern and includes getter
> 
> Hi, Arun. Here is the patch I would like to go with. It overrides Control's
> setBackgroundColor and getBackgroundColor, and is similar to overrides that
> have been done in Text, Spinner, Table, List, etc. to set the base color.
> I will release this after you have finished updating the patch in bug 329291.
Comment 8 Arun Thondapu CLA 2011-03-14 14:30:45 EDT
The patch works as expected when a proper color is chosen but it doesn't work when the color is set to null (doesn't revert to default). This is what is causing the JUnit failure too.
I'm trying to figure out how to fix this.

(In reply to comment #7)
> Thanks for the new patch Carolyn!
> I just realized there is a JUnit failure with this patch and I'll look into
> it.(In reply to comment #6)
> > Created attachment 190437 [details] [details]
> > new patch that follows framework pattern and includes getter
> > 
> > Hi, Arun. Here is the patch I would like to go with. It overrides Control's
> > setBackgroundColor and getBackgroundColor, and is similar to overrides that
> > have been done in Text, Spinner, Table, List, etc. to set the base color.
> > I will release this after you have finished updating the patch in bug 329291.
Comment 9 Arun Thondapu CLA 2011-03-21 07:35:05 EDT
Created attachment 191604 [details]
modified patch

Hi Carolyn,

I modified your patch by adding a separate check for color being set to null.

In the original patch, the overridden setBackgroundColor method doesn't get called when the color is being set to null and so the background color doesn't get updated.
The reason the overridden method is not getting called is that the following statement of code in Control#setBackground(Color) method doesn't get evaluated to true.
set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_BG) != 0;

I tried adding code to set the flags appropriately in the overridden methods but that did not give me the desired effect.
I decided to add this separate check for null since I didn't want to change any code in the Control class.

All JUnit tests pass.

Please let me know your comments/suggestions. Thanks!
Comment 10 Carolyn MacLeod CLA 2011-09-22 16:05:00 EDT
Fixed http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=8d66c54f1806e5f4886545c525b731676efd0ad4

Thanks, Arun! I committed the patch in comment 9, except that I added an extra pair of { .. } for the new if statement.

Sorry to take so long to commit this - I spent quite a bit of time getting up to speed with git......
Comment 11 Arun Thondapu CLA 2011-09-23 07:31:34 EDT
Thanks Carolyn!