From 99d4c955567235eecea43d179ef27aa654cdc561 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 22 Apr 2008 17:16:37 +0000 Subject: [PATCH] Monotone-Parent: 4da2e2aa68da3f6c69bddae3167041872607c9d2 Monotone-Revision: 589cbe87a5260166298c57c4fa50494edb7b9fbd Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-04-22T17:16:37 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 ++ UI/Scheduler/UIxCalendarSelector.m | 48 ++++++++++++++++++- .../SchedulerUI/UIxCalendarSelector.wox | 2 +- UI/WebServerResources/SchedulerUI.js | 35 ++------------ UI/WebServerResources/generic.js | 17 +++++++ 5 files changed, 74 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef99e9b12..327220f8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2008-04-22 Wolfgang Sourdeau + * UI/Scheduler/UIxCalendarSelector.m ([UIxCalendarSelector + -contrastingTextColor]): new method (code taken from Lightning) + that returns a foreground color easily readible based on the + brightness of the background color. + * SoObjects/SOGo/SOGoGCSFolder.m ([SOGoGCSFolder -setDavDisplayName:newName]): deny the renaming of the folder if not owner. diff --git a/UI/Scheduler/UIxCalendarSelector.m b/UI/Scheduler/UIxCalendarSelector.m index 820865478..a4ec65ef3 100644 --- a/UI/Scheduler/UIxCalendarSelector.m +++ b/UI/Scheduler/UIxCalendarSelector.m @@ -36,6 +36,35 @@ #import "UIxCalendarSelector.h" +static inline unsigned int +_intValueFromHexChar (unichar hexChar) +{ + unichar base; + + if (hexChar >= '0' && hexChar <= '9') + base = '0'; + else if (hexChar >= 'A' && hexChar <= 'F') + base = 'A' - 10; + else + base = 'a' - 10; + + return (hexChar - base); +} + +static inline unsigned int +_intValueFromHex (NSString *hexString) +{ + unsigned int value, count, max; + + value = 0; + max = [hexString length]; + for (count = 0; count < max; count++) + value = (value * 16 + + _intValueFromHexChar([hexString characterAtIndex: count])); + + return value; +} + @implementation UIxCalendarSelector - (id) init @@ -87,8 +116,7 @@ forKey: @"id"]; [calendar setObject: fDisplayName forKey: @"displayName"]; [calendar setObject: folderName forKey: @"folder"]; - [calendar setObject: [folder calendarColor] - forKey: @"color"]; + [calendar setObject: [folder calendarColor] forKey: @"color"]; isActive = [NSNumber numberWithBool: [folder isActive]]; [calendar setObject: isActive forKey: @"active"]; [calendar setObject: [folder ownerInContext: context] @@ -124,6 +152,22 @@ keysWithFormat: @"color: %{color}; background-color: %{color};"]; } +/* code taken from Lightning 0.7 */ +- (NSString *) contrastingTextColor +{ + NSString *bgColor; + unsigned int red, green, blue; + float brightness; + + bgColor = [[currentCalendar objectForKey: @"color"] substringFromIndex: 1]; + red = _intValueFromHex ([bgColor substringFromRange: NSMakeRange (0, 2)]); + green = _intValueFromHex ([bgColor substringFromRange: NSMakeRange (2, 2)]); + blue = _intValueFromHex ([bgColor substringFromRange: NSMakeRange (4, 2)]); + brightness = (0.299 * red) + (0.587 * green) + (0.114 * blue); + + return ((brightness < 144) ? @"white" : @"black"); +} + - (WOResponse *) calendarsListAction { WOResponse *response; diff --git a/UI/Templates/SchedulerUI/UIxCalendarSelector.wox b/UI/Templates/SchedulerUI/UIxCalendarSelector.wox index a02893ffa..245f7a8f3 100644 --- a/UI/Templates/SchedulerUI/UIxCalendarSelector.wox +++ b/UI/Templates/SchedulerUI/UIxCalendarSelector.wox @@ -9,7 +9,7 @@