зеркало из https://github.com/mozilla/gecko-dev.git
color picker widget
This commit is contained in:
Родитель
ebdceed6af
Коммит
8d9a80c92a
|
@ -60,6 +60,7 @@ CPPSRCS = \
|
||||||
nsScrollbarButtonFrame.cpp \
|
nsScrollbarButtonFrame.cpp \
|
||||||
nsSliderFrame.cpp \
|
nsSliderFrame.cpp \
|
||||||
nsColorPickerFrame.cpp \
|
nsColorPickerFrame.cpp \
|
||||||
|
nsStdColorPicker.cpp \
|
||||||
nsFontPickerFrame.cpp \
|
nsFontPickerFrame.cpp \
|
||||||
nsToolbarItemFrame.cpp \
|
nsToolbarItemFrame.cpp \
|
||||||
nsMenuPopupFrame.cpp \
|
nsMenuPopupFrame.cpp \
|
||||||
|
|
|
@ -48,6 +48,7 @@ CPPSRCS= \
|
||||||
nsScrollbarButtonFrame.cpp \
|
nsScrollbarButtonFrame.cpp \
|
||||||
nsSliderFrame.cpp \
|
nsSliderFrame.cpp \
|
||||||
nsColorPickerFrame.cpp \
|
nsColorPickerFrame.cpp \
|
||||||
|
nsStdColorPicker.cpp \
|
||||||
nsFontPickerFrame.cpp \
|
nsFontPickerFrame.cpp \
|
||||||
nsMenuPopupFrame.cpp \
|
nsMenuPopupFrame.cpp \
|
||||||
nsMenuFrame.cpp \
|
nsMenuFrame.cpp \
|
||||||
|
@ -81,6 +82,7 @@ CPP_OBJS= \
|
||||||
.\$(OBJDIR)\nsScrollbarButtonFrame.obj \
|
.\$(OBJDIR)\nsScrollbarButtonFrame.obj \
|
||||||
.\$(OBJDIR)\nsSliderFrame.obj \
|
.\$(OBJDIR)\nsSliderFrame.obj \
|
||||||
.\$(OBJDIR)\nsColorPickerFrame.obj \
|
.\$(OBJDIR)\nsColorPickerFrame.obj \
|
||||||
|
.\$(OBJDIR)\nsStdColorPicker.obj \
|
||||||
.\$(OBJDIR)\nsFontPickerFrame.obj \
|
.\$(OBJDIR)\nsFontPickerFrame.obj \
|
||||||
.\$(OBJDIR)\nsMenuPopupFrame.obj \
|
.\$(OBJDIR)\nsMenuPopupFrame.obj \
|
||||||
.\$(OBJDIR)\nsMenuFrame.obj \
|
.\$(OBJDIR)\nsMenuFrame.obj \
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public
|
||||||
|
* License Version 1.1 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS
|
||||||
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||||
|
* implied. See the License for the specific language governing
|
||||||
|
* rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Mozilla browser.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||||
|
* Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Stuart Parmenter <pavlov@netscape.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 1936f892-1dd2-11b2-aba4-bd254241f938
|
||||||
|
#define NS_DEFCOLORPICKER_CID \
|
||||||
|
{ 0x1936f892, 0x1dd2, 0x11b2, \
|
||||||
|
{0xab, 0xa4, 0xbd, 0x25, 0x42, 0x41, 0xf9, 0x38} }
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "nsColorPickerFrame.h"
|
#include "nsColorPickerFrame.h"
|
||||||
|
|
||||||
|
#include "nsIDOMElement.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "prtypes.h"
|
#include "prtypes.h"
|
||||||
#include "nsIAtom.h"
|
#include "nsIAtom.h"
|
||||||
|
@ -26,8 +27,10 @@
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsCSSRendering.h"
|
#include "nsCSSRendering.h"
|
||||||
#include "nsINameSpaceManager.h"
|
#include "nsINameSpaceManager.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsStdColorPicker.h"
|
||||||
|
#include "nsColorPickerCID.h"
|
||||||
//
|
//
|
||||||
// NS_NewColorPickerFrame
|
// NS_NewColorPickerFrame
|
||||||
//
|
//
|
||||||
|
@ -47,28 +50,96 @@ NS_NewColorPickerFrame(nsIFrame** aNewFrame)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kDefColorPickerCID, NS_DEFCOLORPICKER_CID);
|
||||||
|
|
||||||
//
|
//
|
||||||
// nsColorPickerFrame cntr
|
// nsColorPickerFrame cntr
|
||||||
//
|
//
|
||||||
nsColorPickerFrame::nsColorPickerFrame()
|
nsColorPickerFrame::nsColorPickerFrame()
|
||||||
{
|
{
|
||||||
|
mColorPicker = new nsStdColorPicker();
|
||||||
|
}
|
||||||
|
|
||||||
} // cntr
|
nsColorPickerFrame::~nsColorPickerFrame()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsColorPickerFrame::HandleEvent(nsIPresContext& aPresContext,
|
||||||
|
nsGUIEvent* aEvent,
|
||||||
|
nsEventStatus& aEventStatus)
|
||||||
|
{
|
||||||
|
aEventStatus = nsEventStatus_eConsumeDoDefault;
|
||||||
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN)
|
||||||
|
HandleMouseDownEvent(aPresContext, aEvent, aEventStatus);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsColorPickerFrame::HandleMouseDownEvent(nsIPresContext& aPresContext,
|
||||||
|
nsGUIEvent* aEvent,
|
||||||
|
nsEventStatus& aEventStatus)
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
char *color;
|
||||||
|
// figure out what color we just picked
|
||||||
|
|
||||||
|
printf("got mouse down.. x = %i, y = %i\n", aEvent->refPoint.x, aEvent->refPoint.y);
|
||||||
|
|
||||||
|
x = aEvent->refPoint.x;
|
||||||
|
y = aEvent->refPoint.y;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMElement> node( do_QueryInterface(mContent) );
|
||||||
|
|
||||||
|
mColorPicker->GetColor(x, y, &color);
|
||||||
|
|
||||||
|
if (!color)
|
||||||
|
node->RemoveAttribute("color");
|
||||||
|
else
|
||||||
|
node->SetAttribute("color", color);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Paint
|
// Paint
|
||||||
//
|
//
|
||||||
// Overidden to handle ???
|
|
||||||
//
|
//
|
||||||
NS_METHOD
|
NS_METHOD
|
||||||
nsColorPickerFrame::Paint(nsIPresContext& aPresContext,
|
nsColorPickerFrame::Paint(nsIPresContext& aPresContext,
|
||||||
nsIRenderingContext& aRenderingContext,
|
nsIRenderingContext& aRenderingContext,
|
||||||
const nsRect& aDirtyRect,
|
const nsRect& aDirtyRect,
|
||||||
nsFramePaintLayer aWhichLayer)
|
nsFramePaintLayer aWhichLayer)
|
||||||
{
|
{
|
||||||
return nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
||||||
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
||||||
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
||||||
|
|
||||||
|
// if we aren't visible then we are done.
|
||||||
|
if (!disp->mVisible)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
// if we are visible then tell our superclass to paint
|
||||||
|
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,
|
||||||
|
aWhichLayer);
|
||||||
|
|
||||||
|
// get our border
|
||||||
|
const nsStyleSpacing* spacing =
|
||||||
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
||||||
|
nsMargin border(0,0,0,0);
|
||||||
|
spacing->CalcBorderFor(this, border);
|
||||||
|
|
||||||
|
const nsStyleColor* colorStyle =
|
||||||
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
||||||
|
|
||||||
|
nscolor color = colorStyle->mColor;
|
||||||
|
|
||||||
|
mColorPicker->Paint(&aPresContext, &aRenderingContext);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,12 +149,16 @@ nsColorPickerFrame::Paint(nsIPresContext& aPresContext,
|
||||||
// For now, be as big as CSS wants us to be, or some small default size.
|
// For now, be as big as CSS wants us to be, or some small default size.
|
||||||
//
|
//
|
||||||
void
|
void
|
||||||
nsColorPickerFrame :: GetDesiredSize(nsIPresContext* aPresContext,
|
nsColorPickerFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||||
const nsHTMLReflowState& aReflowState,
|
const nsHTMLReflowState& aReflowState,
|
||||||
nsHTMLReflowMetrics& aDesiredLayoutSize)
|
nsHTMLReflowMetrics& aDesiredLayoutSize)
|
||||||
{
|
{
|
||||||
|
float p2t;
|
||||||
|
|
||||||
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||||
|
|
||||||
const int CSS_NOTSET = -1;
|
const int CSS_NOTSET = -1;
|
||||||
const int ATTR_NOTSET = -1;
|
// const int ATTR_NOTSET = -1;
|
||||||
|
|
||||||
nsSize styleSize;
|
nsSize styleSize;
|
||||||
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
|
||||||
|
@ -100,6 +175,8 @@ nsColorPickerFrame :: GetDesiredSize(nsIPresContext* aPresContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
// subclasses should always override this method, but if not and no css, make it small
|
// subclasses should always override this method, but if not and no css, make it small
|
||||||
|
// XXX ???
|
||||||
|
/*
|
||||||
aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 200;
|
aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 200;
|
||||||
aDesiredLayoutSize.height = (styleSize.height > CSS_NOTSET) ? styleSize.height : 200;
|
aDesiredLayoutSize.height = (styleSize.height > CSS_NOTSET) ? styleSize.height : 200;
|
||||||
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
|
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
|
||||||
|
@ -108,5 +185,18 @@ nsColorPickerFrame :: GetDesiredSize(nsIPresContext* aPresContext,
|
||||||
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
|
aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width;
|
||||||
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
|
aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
PRInt32 width, height;
|
||||||
|
|
||||||
|
mColorPicker->GetSize(&width, &height);
|
||||||
|
|
||||||
|
// convert to twips
|
||||||
|
|
||||||
|
aDesiredLayoutSize.width = nscoord(width * p2t);
|
||||||
|
aDesiredLayoutSize.height = nscoord(height * p2t);
|
||||||
|
aDesiredLayoutSize.ascent = nscoord(height * p2t);
|
||||||
|
aDesiredLayoutSize.descent = 0;
|
||||||
|
|
||||||
|
|
||||||
} // GetDesiredSize
|
} // GetDesiredSize
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "prtypes.h"
|
#include "prtypes.h"
|
||||||
#include "nsIAtom.h"
|
#include "nsIAtom.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIColorPicker.h"
|
||||||
|
|
||||||
class nsString;
|
class nsString;
|
||||||
|
|
||||||
|
@ -39,22 +40,35 @@ class nsColorPickerFrame : public nsLeafFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsColorPickerFrame();
|
nsColorPickerFrame();
|
||||||
|
virtual ~nsColorPickerFrame();
|
||||||
|
|
||||||
// nsIFrame overrides
|
// nsIFrame overrides
|
||||||
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
||||||
return MakeFrameName("ColorPickerFrame", aResult);
|
return MakeFrameName("ColorPickerFrame", aResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
|
||||||
|
nsGUIEvent* aEvent,
|
||||||
|
nsEventStatus& aEventStatus);
|
||||||
|
nsresult HandleMouseDownEvent(nsIPresContext& aPresContext,
|
||||||
|
nsGUIEvent* aEvent,
|
||||||
|
nsEventStatus& aEventStatus);
|
||||||
|
|
||||||
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
||||||
nsIRenderingContext& aRenderingContext,
|
nsIRenderingContext& aRenderingContext,
|
||||||
const nsRect& aDirtyRect,
|
const nsRect& aDirtyRect,
|
||||||
nsFramePaintLayer aWhichLayer);
|
nsFramePaintLayer aWhichLayer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void GetDesiredSize(nsIPresContext* aPresContext,
|
virtual void GetDesiredSize(nsIPresContext* aPresContext,
|
||||||
const nsHTMLReflowState& aReflowState,
|
const nsHTMLReflowState& aReflowState,
|
||||||
nsHTMLReflowMetrics& aDesiredSize) ;
|
nsHTMLReflowMetrics& aDesiredSize) ;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsIColorPicker *mColorPicker;
|
||||||
|
|
||||||
}; // class nsColorPickerFrame
|
}; // class nsColorPickerFrame
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public
|
||||||
|
* License Version 1.1 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS
|
||||||
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||||
|
* implied. See the License for the specific language governing
|
||||||
|
* rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Mozilla browser.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||||
|
* Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Stuart Parmenter <pavlov@netscape.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __nsIColorPicker_h__
|
||||||
|
#define __nsIColorPicker_h__
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsrootidl.h"
|
||||||
|
#include "nsIPresContext.h"
|
||||||
|
#include "nsIRenderingContext.h"
|
||||||
|
|
||||||
|
/* starting interface: nsIColorPicker */
|
||||||
|
|
||||||
|
#define NS_ICOLORPICKER_IID_STR "ed133d04-1dd1-11b2-957f-a04e70608d6e"
|
||||||
|
|
||||||
|
#define NS_ICOLORPICKER_IID \
|
||||||
|
{0xed133d04, 0x1dd1, 0x11b2, \
|
||||||
|
{ 0x95, 0x7f, 0xa0, 0x4e, 0x70, 0x60, 0x8d, 0x6e }}
|
||||||
|
|
||||||
|
class nsIColorPicker : public nsISupports {
|
||||||
|
public:
|
||||||
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOLORPICKER_IID)
|
||||||
|
|
||||||
|
/* void Paint (in nsIPresContext aPresContext, in nsIRenderingContext aRenderingContext); */
|
||||||
|
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) = 0;
|
||||||
|
|
||||||
|
/* void GetColor (in PRInt32 aX, in PRInt32 aY, out string aColor); */
|
||||||
|
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) = 0;
|
||||||
|
|
||||||
|
/* void GetSize (out PRInt32 aWidth, out PRInt32 aHeight); */
|
||||||
|
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Use this macro when declaring classes that implement this interface. */
|
||||||
|
#define NS_DECL_NSICOLORPICKER \
|
||||||
|
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext); \
|
||||||
|
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor); \
|
||||||
|
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight);
|
||||||
|
|
||||||
|
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||||
|
#define NS_FORWARD_NSICOLORPICKER(_to) \
|
||||||
|
NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) { return _to ## Paint(aPresContext, aRenderingContext); } \
|
||||||
|
NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) { return _to ## GetColor(aX, aY, aColor); } \
|
||||||
|
NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) { return _to ## GetSize(aWidth, aHeight); }
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __nsIColorPicker_h__ */
|
|
@ -0,0 +1,134 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public
|
||||||
|
* License Version 1.1 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS
|
||||||
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||||
|
* implied. See the License for the specific language governing
|
||||||
|
* rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Mozilla browser.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||||
|
* Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Stuart Parmenter <pavlov@netscape.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsStdColorPicker.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsCRT.h"
|
||||||
|
|
||||||
|
#include "nsIDOMElement.h"
|
||||||
|
#include "nsIContent.h"
|
||||||
|
#include "prtypes.h"
|
||||||
|
#include "nsIAtom.h"
|
||||||
|
#include "nsIPresContext.h"
|
||||||
|
#include "nsIStyleContext.h"
|
||||||
|
#include "nsCSSRendering.h"
|
||||||
|
#include "nsINameSpaceManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
static char* StandardPalette[] = {
|
||||||
|
"#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF",
|
||||||
|
"#CCCCCC","#FF6666","#FFCC33","#FFFF66","#FFFF99","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF",
|
||||||
|
"#CCCCCC","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC",
|
||||||
|
"#999999","#CC0000","#FF6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC",
|
||||||
|
"#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399",
|
||||||
|
"#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366",
|
||||||
|
"#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
static int nColors = sizeof(StandardPalette) / sizeof(char *);
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS1(nsStdColorPicker, nsIColorPicker)
|
||||||
|
|
||||||
|
nsStdColorPicker::nsStdColorPicker()
|
||||||
|
{
|
||||||
|
mNumRows = 0;
|
||||||
|
mNumCols = 0;
|
||||||
|
mFrameWidth = 0;
|
||||||
|
mFrameHeight = 0;
|
||||||
|
mBlockWidth = 20;
|
||||||
|
mBlockHeight = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsStdColorPicker::~nsStdColorPicker()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsStdColorPicker::Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int row = 0;
|
||||||
|
int col = 0;
|
||||||
|
nscolor color = 0;
|
||||||
|
float p2t;
|
||||||
|
PRInt32 width, height;
|
||||||
|
|
||||||
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
||||||
|
|
||||||
|
width = NSToIntRound(mBlockWidth * p2t);
|
||||||
|
height = NSToIntRound(mBlockHeight * p2t);
|
||||||
|
|
||||||
|
printf("number of columns: %i\n", mNumCols);
|
||||||
|
|
||||||
|
aRenderingContext->SetColor(0);
|
||||||
|
aRenderingContext->FillRect(0, 0, (mNumCols+1)*width, mNumRows*height);
|
||||||
|
|
||||||
|
mFrameWidth = (mNumCols+1) * width;
|
||||||
|
mFrameHeight = mNumRows * height;
|
||||||
|
|
||||||
|
for (i=0;i<nColors;i++)
|
||||||
|
{
|
||||||
|
NS_LooseHexToRGB(StandardPalette[i], &color);
|
||||||
|
|
||||||
|
aRenderingContext->SetColor(color);
|
||||||
|
aRenderingContext->FillRect(col*width, row*height, width, height);
|
||||||
|
|
||||||
|
if (col == mNumCols)
|
||||||
|
{
|
||||||
|
col = 0;
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsStdColorPicker::GetColor(PRInt32 aX, PRInt32 aY, char **aColor)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = (mNumCols*(aY/mBlockHeight))+(aX/mBlockWidth);
|
||||||
|
|
||||||
|
if (i > nColors)
|
||||||
|
*aColor = nsnull;
|
||||||
|
|
||||||
|
*aColor = nsCRT::strdup(StandardPalette[i]);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsStdColorPicker::GetSize(PRInt32 *aWidth, PRInt32 *aHeight)
|
||||||
|
{
|
||||||
|
mNumCols = 9; // NSToIntRound(sqrt(nColors));
|
||||||
|
mNumRows = NSToIntRound(nColors/mNumCols);
|
||||||
|
mFrameWidth = NSToIntRound((mNumCols+1) * mBlockWidth);
|
||||||
|
mFrameHeight = NSToIntRound(mNumRows * mBlockHeight);
|
||||||
|
|
||||||
|
*aWidth = mFrameWidth;
|
||||||
|
*aHeight = mFrameHeight;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public
|
||||||
|
* License Version 1.1 (the "License"); you may not use this file
|
||||||
|
* except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS
|
||||||
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||||
|
* implied. See the License for the specific language governing
|
||||||
|
* rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Mozilla browser.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||||
|
* Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Stuart Parmenter <pavlov@netscape.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __nsStdColorPicker_h__
|
||||||
|
#define __nsStdColorPicker_h__
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsrootidl.h"
|
||||||
|
#include "nsIPresContext.h"
|
||||||
|
#include "nsIRenderingContext.h"
|
||||||
|
#include "nsIColorPicker.h"
|
||||||
|
|
||||||
|
class nsStdColorPicker : public nsIColorPicker {
|
||||||
|
public:
|
||||||
|
nsStdColorPicker();
|
||||||
|
virtual ~nsStdColorPicker();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_DECL_NSICOLORPICKER
|
||||||
|
|
||||||
|
private:
|
||||||
|
PRInt32 mNumCols;
|
||||||
|
PRInt32 mNumRows;
|
||||||
|
PRInt32 mBlockWidth;
|
||||||
|
PRInt32 mBlockHeight;
|
||||||
|
PRInt32 mFrameWidth;
|
||||||
|
PRInt32 mFrameHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __nsStdColorPicker_h__ */
|
Загрузка…
Ссылка в новой задаче