Monotone-Parent: 4da2e2aa68da3f6c69bddae3167041872607c9d2

Monotone-Revision: 589cbe87a5260166298c57c4fa50494edb7b9fbd

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2008-04-22T17:16:37
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2008-04-22 17:16:37 +00:00
parent 092b303a45
commit 99d4c95556
5 changed files with 74 additions and 33 deletions
+5
View File
@@ -1,5 +1,10 @@
2008-04-22 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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.
+46 -2
View File
@@ -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;
@@ -9,7 +9,7 @@
<style type="text/css">
<var:foreach list="calendars" item="currentCalendar">
.calendarFolder<var:string value="currentCalendar.folder" />
{ background-color: <var:string value="currentCalendar.color" /> !important; }
{ background-color: <var:string value="currentCalendar.color" /> !important; color: <var:string value="contrastingTextColor" /> !important; }
div.colorBox.calendarFolder<var:string value="currentCalendar.folder" />
{ color: <var:string value="currentCalendar.color" /> !important; }
</var:foreach>
+5 -30
View File
@@ -4,7 +4,6 @@ var listFilter = 'view_today';
var listOfSelection = null;
var selectedCalendarCell;
var calendarColorIndex = null;
var showCompletedTasks = 0;
@@ -1689,32 +1688,6 @@ function appendCalendar(folderName, folderPath) {
li.setAttribute("id", folderPath);
li.setAttribute("owner", owner);
// Generate new color
if (calendarColorIndex == null)
calendarColorIndex = items.length;
calendarColorIndex++;
var colorTable = [1, 1, 1];
var color;
var currentValue = calendarColorIndex;
var index = 0;
while (currentValue) {
if (currentValue & 1)
colorTable[index]++;
if (index == 3)
index = 0;
currentValue >>= 1;
index++;
}
colorTable[0] = parseInt(255 / colorTable[0]) - 1;
colorTable[1] = parseInt(255 / colorTable[1]) - 1;
colorTable[2] = parseInt(255 / colorTable[2]) - 1;
color = "#"
+ colorTable[2].toString(16)
+ colorTable[1].toString(16)
+ colorTable[0].toString(16);
//log ("color = " + color);
var checkBox = document.createElement("input");
checkBox.setAttribute("type", "checkbox");
li.appendChild(checkBox);
@@ -1738,12 +1711,13 @@ function appendCalendar(folderName, folderPath) {
triggerAjaxRequest(url, calendarEntryCallback, folderPath);
// Update CSS for events color
appendStyleElement(folderPath, color);
appendStyleElement(folderPath, "#AAAAAA");
}
}
function appendStyleElement(folderPath, color) {
if (document.styleSheets) {
if (document.styleSheets) {
var fgColor = getContrastingTextColor(color);
var styleElement = document.createElement("style");
styleElement.type = "text/css";
var selectors = [
@@ -1751,7 +1725,8 @@ function appendStyleElement(folderPath, color) {
'div.colorBox.calendarFolder' + folderPath.substr(1)
];
var rules = [
' { background-color: ' + color + ' !important; }',
' { background-color: ' + color + ' !important;'
+ ' color: ' + fgColor + ' !important; }',
' { color: ' + color + ' !important; }'
];
for (var i = 0; i < rules.length; i++)
+17
View File
@@ -307,6 +307,23 @@ function onAjaxRequestStateChange(http) {
}
}
/* taken from Lightning */
function getContrastingTextColor(bgColor) {
var calcColor = bgColor.substring(1);
var red = parseInt(calcColor.substring(0, 2), 16);
var green = parseInt(calcColor.substring(2, 4), 16);
var blue = parseInt(calcColor.substring(4, 6), 16);
// Calculate the brightness (Y) value using the YUV color system.
var brightness = (0.299 * red) + (0.587 * green) + (0.114 * blue);
// Consider all colors with less than 56% brightness as dark colors and
// use white as the foreground color, otherwise use black.
return ((brightness < 144)
? "white"
: "black");
}
function triggerAjaxRequest(url, callback, userdata, content, headers) {
var http = createHTTPClient();