📄 iwtmscolorpicker.pas.~1~
字号:
procedure TTIWCustomColorPicker.SetRectHeight(const Value: Word);
begin
if FRectHeight = Value then
Exit;
FRectHeight := Value;
Invalidate;
end;
procedure TTIWCustomColorPicker.MoveColors(newColCount: Word);
var
i,j,minCol: Integer;
begin
minCol := Min(FColCount,newColCount)-1;
if FColCount < newColCount then
SetLength(ColorArray,FRowCount*newColCount);
for i := FRowCount - 1 downto 0 do
for j := minCol downto 0 do
ColorArray[i*newColCount+j] := ColorArray[i*FColCount+j];
if FColCount < newColCount then
for i := 0 to FRowCount-1 do
for j := FColCount to newColCount - 1 do
ColorArray[i*newColCount+j] := clNone
else
SetLength(ColorArray,FRowCount*newColCount);
end;
procedure TTIWCustomColorPicker.HTMLColorChange(index: word);
begin
if index < (FRowCount*FColCount) then
begin
FColor := ColorArray[index];
DoColorChanged;
end;
end;
procedure TTIWCustomColorPicker.HTMLColorChange(x, y: word);
begin
HTMLColorChange(y*FColCount+x);
end;
procedure TTIWCustomColorPicker.SetDefaultColWidth(const Value: Word);
begin
FDefaultColWidth := Value;
Invalidate;
end;
procedure TTIWCustomColorPicker.SetDefaultRowHeight(const Value: Word);
begin
FDefaultRowHeight := Value;
Invalidate;
end;
procedure TTIWCustomColorPicker.Submit(const AValue: string);
var
Decode: string;
cul:Tcolor;
begin
Decode := AValue;
if AnsiPos(HTMLName+tagcol,Decode) = 1 then
Delete(decode,1,Length(HTMLName)+Length(tagcol));
try
cul := StrToInt(decode);
HTMLColorChange(cul);
except
on Exception do;
end;
end;
function TTIWCustomColorPicker.HTMLClr(color: TColor):string;
begin
Result := ColorToRGBString(color);
end;
{$IFDEF TMSIW6}
procedure TTIWCustomColorPicker.RenderCustomHTML(var html,picker:string;Widthcontrol:word; AContext: TIWBaseComponentContext);
{$ELSE}
procedure TTIWCustomColorPicker.RenderCustomHTML(var html,picker:string;Widthcontrol:word);
{$ENDIF}
var
i,j,WidthDiv,HeightDiv:integer;
begin
WidthDiv := DefaultColWidth * ColCount;
HeightDiv := DefaultRowHeight * RowCount + 4;
{$IFDEF TMSIW6}
TIWComponent40Context(AContext).AddToInitProc('FindElem(''' + HTMLName + ''').value="' + IntToStr(ColorIndex(Color)) + '";' + EOL);
{$ELSE}
TIWAppForm(Form).AddToInitProc('FindElem(''' + HTMLName + ''').value="' + IntToStr(ColorIndex(Color)) + '";' + EOL);
{$ENDIF}
html := '<SCRIPT>'#13
+ 'var ' + HTMLName + 'hideWindowedControls = true;'#13
+ 'var ' + HTMLName + 'DivStartLeft;'#13
+ 'var ' + HTMLName + 'DivEndLeft;'#13
+ 'var ' + HTMLName + 'DivStartTop;'#13
+ 'var ' + HTMLName + 'DivEndTop;'#13
+ 'var ' + HTMLName + 'isIE;'#13
+ 'var ' + HTMLName + 'BUTTONTop;'#13
+ 'var ' + HTMLName + 'BUTTONETop;'#13
+ 'var ' + HTMLName + 'BUTTONLeft;'#13
+ 'var ' + HTMLName + 'BUTTONELeft;'#13
+ 'function ' + HTMLName + 'showWindowedObjects(show) {'#13
+ HTMLName + 'getPositionDiv();'#13
+ HTMLName + 'isIE = navigator.appName.indexOf("Microsoft") != -1;'#13
+ ' if (' + HTMLName + 'hideWindowedControls) {'#13
+ ' var windowedObjectTags = new Array("SELECT", "IFRAME", "OBJECT", "APPLET","EMBED");'#13
+ ' var windowedObjects = new Array();'#13
+ ' var j=0;'#13
+ ' if (' + HTMLName + 'isIE == true) {'#13
+ ' for (var i=0; i<windowedObjectTags.length; i++) {'#13
+ ' var tmpTags = document.all.tags(windowedObjectTags[i]);'#13
+ ' if (tmpTags.length > 0) {'#13
+ ' for (var k=0; k<tmpTags.length; k++) {'#13
+ ' windowedObjects[j++] = tmpTags[k];'#13
+ ' }'#13
+ ' }'#13
+ ' }'#13
+ ' }'#13
+ 'else {'#13
+ 'for (var i=0; i<windowedObjectTags.length; i++) {'#13
+ 'var tmpTags = document.getElementsByTagName(windowedObjectTags[i]);'#13
+ 'if (tmpTags.length > 0) {'#13
+ 'for (var k=0; k<tmpTags.length; k++) {'#13
+ 'windowedObjects[j++] = tmpTags[k];'#13
+ '}'#13
+ '}'#13
+ '}'#13
+ '}'#13
+ 'for (var i=0; i<windowedObjects.length; i++) {'#13
+ 'if (show)'#13
+ 'windowedObjects[i].style.visibility = "visible";'#13
+ 'else {'#13
+ 'var topObject = document.getElementById(windowedObjects[i].id).style.top;'#13
+ 'var leftObject = document.getElementById(windowedObjects[i].id).style.left;'#13
+ 'var topInt = parseInt(topObject.substring(0,topObject.length - 2));'#13
+ 'var leftInt = parseInt(leftObject.substring(0,leftObject.length - 2));'#13
+ 'if (' + HTMLName + 'isIE == true) {'#13
+ 'var widthObject = document.getElementById(windowedObjects[i].id).offsetWidth;'#13
+ 'var heightObject = document.getElementById(windowedObjects[i].id).offsetHeight;'#13
+ 'var rightInt = leftInt + parseInt(widthObject);'#13
+ 'var bottomInt = topInt + parseInt(heightObject);'#13
+ '}'#13
+ 'else {'#13
+ 'var widthObject = document.getElementById(windowedObjects[i].id).offsetWidth;'#13
+ 'var heightObject = document.getElementById(windowedObjects[i].id).offsetHeight;'#13
+ 'var rightInt = leftInt + parseInt(widthObject);'#13
+ 'var bottomInt = topInt + parseInt(heightObject);'#13
+ '}'#13
+ 'if ((((leftInt >= ' + HTMLName + 'DivStartLeft) && (leftInt <= ' + HTMLName + 'DivEndLeft)) | ((rightInt >= ' + HTMLName + 'DivStartLeft) && (rightInt <= ' + HTMLName + 'DivEndLeft)) | ((leftInt <= ' + HTMLName + 'DivStartLeft) && (rightInt >= ' + HTMLName + 'DivStartLeft))) && (((topInt >= ' + HTMLName + 'DivStartTop) && (topInt <= ' + HTMLName + 'DivEndTop)) | ((bottomInt >= ' + HTMLName + 'DivStartTop) && (bottomInt <= ' + HTMLName + 'DivEndTop))))'#13
+ 'windowedObjects[i].style.visibility = "hidden";'#13
+ '}'#13
+ '}'#13
+ '}'#13
+'}'#13
+ 'function ' + HTMLName + 'ColorChange(color,colorpick)'#13
+ '{'#13
+ ' FindElem(''' + HTMLName + ''').value=colorpick;'#13
+ ' var pickerObj = document.getElementById("Picker' + HTMLName + '");'#13
+ ' pickerObj.style.visibility = "hidden";'#13
+ ' var divPickerObj = document.getElementById("DivPicker' + HTMLName + '");'#13
+ ' divPickerObj.style.height = "0px";'#13
+ ' divPickerObj.style.width = "0px";'#13
+ ' var rectObj = document.getElementById("Rect' + HTMLName + '");'#13
+ ' rectObj.style.backgroundColor = color;'#13
+ IIF(Assigned(OnColorChanged),' return SubmitClick('#39 + HTMLName + #39 + ',' + #39 + HTMLName + tagcol + #39'+colorpick,'#39'false'#39');'#13,'')
+ '}'#13
+ 'function ' + HTMLName + 'ShowPicker() {'#13
+ ' var obj = document.getElementById("Picker' + HTMLName + '");'#13
+ ' obj.style.visibility = "visible";'#13
+ HTMLName + 'showWindowedObjects(false);'#13
+ ' var divObj = document.getElementById("DivPicker' + HTMLName + '");'#13
+ ' divObj.style.height = "' + IntToStr(HeightDiv) + 'px";'#13
+ ' divObj.style.width = "' + IntToStr(WidthDiv) + 'px";'#13
+ ' if (' + HTMLName + 'isIE == false) {'#13
+ ' document.captureEvents(Event.MOUSEUP);'#13
+' }'#13
+ ' document.onmouseup=' + HtmlName + 'onMouseUp;'#13
+ '}'#13
+ 'function ' + HTMLName + 'getPositionDiv() {'#13
+ ' var divObject = document.getElementById("Button' + HtmlName + '");'#13
+ ' var colorPicker = document.getElementById("Picker' + HTMLName + '");'#13
+ HTMLName + 'DivStartLeft = parseInt(' + IntToStr(Left) + '+' + IntToStr(Width) + ');'#13
+ HTMLName + 'DivStartTop = ' + IntToStr(Top) + ';'#13
+ HTMLName + 'DivEndLeft = ' + HTMLName + 'DivStartLeft + colorPicker.offsetWidth;'#13
+ HTMLName + 'DivEndTop = ' + HTMLName + 'DivStartTop + colorPicker.offsetHeight;'#13
+ ' var cell = document.getElementById("Button' + HTMLName + '");'#13
+ ' var leftBegin = 0;'#13
+ ' var topBegin = 0;'#13
+ ' var elem = cell;'#13
+ ' do '#13
+ ' {'#13
+ ' leftBegin += elem.offsetLeft;'#13
+ ' topBegin += elem.offsetTop;'#13
+ ' }'#13
+ ' while ((elem = elem.offsetParent));'#13
+ ' ' + HTMLName + 'BUTTONLeft = leftBegin;'#13
+ ' ' + HTMLName + 'BUTTONTop = topBegin;'#13
+ ' ' + HTMLName + 'BUTTONELeft = parseInt(leftBegin) + parseInt(cell.style.width);'#13
+ ' ' + HTMLName + 'BUTTONETop = parseInt(topBegin) + parseInt(cell.style.height);'#13
+ '}'#13
+ 'function ' + HTMLName + 'onMouseUp(e) {'#13
+ ' var pickerObj = document.getElementById("Picker' + HTMLName + '");'#13
+ ' var divPickerObj = document.getElementById("DivPicker' + HTMLName + '");'#13
+ ' if (' + HTMLName + 'isIE == true) {'#13
+ ' if ((pickerObj.style.visibility == "visible") & ((window.event.x < ' + HTMLName + 'DivStartLeft) | (' + HTMLName + 'DivEndLeft < window.event.x) | (window.event.y < ' + HTMLName + 'DivStartTop) | ('+ HTMLName + 'DivEndTop < window.event.y))) {'#13
+ ' if (!window.opera) {'#13
+ ' pickerObj.style.visibility = "hidden";'#13
+ ' divPickerObj.style.height = "0px";'#13
+ ' divPickerObj.style.width = "0px";'#13
+ ' }'#13
+ ' else {'#13
+ ' if ((window.event.x < ' + HTMLName + 'BUTTONLeft) | (window.event.x > ' + HTMLName + 'BUTTONELeft) | (window.event.y < ' + HTMLName + 'BUTTONTop) | (window.event.y > ' + HTMLName + 'BUTTONETop)) {'#13
+ ' pickerObj.style.visibility = "hidden";'#13
+ ' divPickerObj.style.height = "0px";'#13
+ ' divPickerObj.style.width = "0px";'#13
+ ' }'#13
+ ' }'#13
+ ' }'#13
+ ' }'#13
+ ' else {'#13
+ ' if ((pickerObj.style.visibility == "visible") & ((e.pageX < ' + HTMLName + 'DivStartLeft) | (' + HTMLName + 'DivEndLeft < e.pageX) | (e.pageY < ' + HTMLName + 'DivStartTop) | ('+ HTMLName + 'DivEndTop < e.pageY))) {'#13
+ ' pickerObj.style.visibility = "hidden";'#13
+ ' divPickerObj.style.height = "0px";'#13
+ ' divPickerObj.style.width = "0px";'#13
+ ' }'#13
+ ' }'#13
+ HTMLName + 'showWindowedObjects(true);'#13
+ '}'#13
+ '</SCRIPT>'#13
+ '<TABLE id="Rect' + HTMLName +'" border="' + IntToStr(FLineWidth)+'" '
+ 'bordercolor=' + HTMLClr(LineColor)+' style="height:' + IntToStr(RectHeight) + ';'#13
+ ' border-collapse:collapse; border-width:'+inttostr(FLineWidth) + '; background-color:' + HTMLClr(Color)+';'#13
+ ' width:' + IntToStr(WidthControl)+';'
+ IIF(PreviewVisible,'visibility:visible','visibility:hidden')
+ '">'#13
+ '<TR>'#13
+ '<TD> </TD>'#13
+ '</TR>'#13
+ '</TABLE>'#13;
if PickerVisible then
picker := '<div id="DivPicker' + HtmlName + '" style="overflow:hidden;height:' + IntToStr(HeightDiv)
+ 'px;width:' + IntToStr(WidthDiv) + 'px">'
else
picker := '<div id="DivPicker' + HtmlName + '" style="overflow:hidden;height:0px;width:0px">';
picker := picker + '<DIV id="Picker' + HTMLName + '" style="background-color:#ffffff;'
+ IIF(PickerVisible,'visibility:visible','visibility:hidden') + ';'
+ 'zIndex:0;height:' + IntToStr(DefaultRowHeight * RowCount)
+ ';width:' + IntToStr(DefaultColWidth * ColCount) + ';">'
+ '<TABLE cellpadding="0" cellspacing="1" border="' + IntToStr(FLineWidth) + '" '#13
+ 'bordercolor="' + HTMLClr(LineColor) + '" '#13
+ 'style="'
+ 'height:' + IntToStr(DefaultRowHeight * RowCount)
+ ';width:' + IntToStr(DefaultColWidth * ColCount) + ';'#13
+ '">'#13;
for j := 0 to RowCount - 1 do
begin
picker := picker + ' <TR>'#13;
for i := 0 to ColCount - 1 do
begin
// picker := picker + ' <TD width="' + IntToStr(WidthDiv) + 'px" onclick="' + HTMLName + 'ColorChange(''' + HTMLClr(PaletteColors[i,j])+''','+inttostr(j*ColCount+i)+')" '
picker := picker + ' <TD width="' + IntToStr(WidthDiv) + 'px" onclick="' + HTMLName + 'ColorChange('#39 + HTMLClr(PaletteColors[i,j]) + #39 + ',' + IntToStr(j * ColCount + i) + ')" '
+ 'style="cursor:hand;background-color:'+HTMLClr(PaletteColors[i,j])+';'#13
+ '"'
+ '> </TD>'#13
// + '><span style="cursor:hand;" onclick="' + HTMLName + 'ColorChange(''' + HTMLClr(PaletteColors[i,j])+''','+inttostr(j*ColCount+i)+')"> </span></TD>'#13
end;
picker := picker + ' </TR>'#13;
end;
picker := picker + ' </TABLE></DIV></div>'#13;
end;
constructor TIWTMSButton.Create;
begin
FWidth := 75;
FHeight := 25;
FCaption := 'Choose Color';
FFont := TIWfont.Create;
FFont.FontName := 'Arial';
FFont.Color := clBlack;
FFont.Size := 8;
FFont.OnChange := FontChanged;
Fcolor := clBtnFace;
end;
destructor TIWTMSButton.Destroy;
begin
FreeAndNil(FFont);
end;
procedure TIWTMSButton.SetCaption(const Value: String);
begin
FCaption := Value;
DoButtonChange;
end;
procedure TIWTMSButton.SetHeight(const Value: Word);
begin
if FHeight = Value then
Exit;
FHeight := Value;
DoButtonChange;
end;
procedure TIWTMSButton.SetWidth(const Value: Word);
begin
if FWidth = Value then
Exit;
FWidth := Value;
DoButtonChange;
end;
procedure TIWTMSButton.SetFont(const Value: TIWFont);
begin
FFont.Assign(Value);
DoButtonChange;
end;
procedure TIWTMSButton.SetColor(const Value: Tcolor);
begin
FColor := Value;
DoButtonChange;
end;
procedure TIWTMSButton.FontChanged(Sender: TObject);
begin
DoButtonChange;
end;
procedure TTIWColorPicker.AdjustSize;
begin
inherited;
if not Assigned(FButton) then
Exit;
if FPickerVisible then
begin
if FPreviewVisible then
Height := Max(FRowCount*FDefaultRowHeight,FButton.Height+FRectHeight)
else
Height := Max(FRowCount*FDefaultRowHeight,FButton.Height);
Width := FButton.Width + FColCount*FDefaultColWidth;
end
else
begin
if FPreviewVisible then
Height := FButton.Height + FRectHeight
else
Height := FButton.Height;
Width := Button.Width;
end;
end;
{$IFDEF TMSIW6}
procedure TTIWColorPicker.IWPaint;
{$ELSE}
procedure TTIWColorPicker.Paint;
{$ENDIF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -