1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#include "nsCheckButton.h"
39
#include "nsToolkit.h"
41
#include "nsGUIEvent.h"
43
#include "nsStringUtil.h"
46
#include "nsILookAndFeel.h"
47
#include "nsWidgetsCID.h"
48
#include "nsIComponentManager.h"
50
#include "nsIDeviceContext.h"
52
#define IDM_BUTTON 701
54
//-------------------------------------------------------------------------
56
NS_NewCheckButton(nsICheckButton** aControl)
58
NS_PRECONDITION(aControl, "null OUT ptr");
59
if (nsnull == aControl) {
60
return NS_ERROR_NULL_POINTER;
62
nsCheckButton* it = new nsCheckButton;
64
return NS_ERROR_OUT_OF_MEMORY;
67
*aControl = (nsICheckButton*)it;
72
NS_IMPL_ADDREF(nsCheckButton)
73
NS_IMPL_RELEASE(nsCheckButton)
75
//-------------------------------------------------------------------------
77
// nsCheckButton constructor
79
//-------------------------------------------------------------------------
80
nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton(),
86
//-------------------------------------------------------------------------
88
// nsCheckButton destructor
90
//-------------------------------------------------------------------------
91
nsCheckButton::~nsCheckButton()
97
* Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
99
* @param aIID The name of the class implementing the method
100
* @param _classiiddef The name of the #define symbol that defines the IID
101
* for the class (e.g. NS_ISUPPORTS_IID)
104
nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
106
if (NULL == aInstancePtr) {
107
return NS_ERROR_NULL_POINTER;
110
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
111
if (aIID.Equals(kICheckButtonIID)) {
112
*aInstancePtr = (void*) ((nsICheckButton*)this);
116
return nsWindow::QueryInterface(aIID,aInstancePtr);
120
//-------------------------------------------------------------------------
122
// Set this button label
124
//-------------------------------------------------------------------------
125
NS_METHOD nsCheckButton::SetState(const PRBool aState)
134
WinCheckButton(mWnd, IDM_BUTTON, chkState);
139
//-------------------------------------------------------------------------
141
// Set this button label
143
//-------------------------------------------------------------------------
144
NS_METHOD nsCheckButton::GetState(PRBool& aState)
146
USHORT chkState = WinQueryButtonCheckstate(mWnd, IDM_BUTTON);
154
//-------------------------------------------------------------------------
156
// Set this button label
158
//-------------------------------------------------------------------------
159
NS_METHOD nsCheckButton::SetLabel(const nsString& aText)
162
aText.ToCString(label, 256);
164
::WinSetWindowText(mWnd, label);
169
//-------------------------------------------------------------------------
171
// Get this button label
173
//-------------------------------------------------------------------------
174
NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
176
int actualSize = ::WinQueryWindowTextLength(mWnd)+1;
177
NS_ALLOC_CHAR_BUF(label, 256, actualSize);
178
::WinQueryWindowText(mWnd, actualSize, label);
179
aBuffer.SetLength(0);
180
aBuffer.AppendWithConversion(label);
181
NS_FREE_CHAR_BUF(label);
185
//-------------------------------------------------------------------------
187
// move, paint, resizes message - ignore
189
//-------------------------------------------------------------------------
190
PRBool nsCheckButton::OnMove(PRInt32, PRInt32)
195
PRBool nsCheckButton::OnPaint()
200
PRBool nsCheckButton::OnResize(nsRect &aWindowRect)
205
//-------------------------------------------------------------------------
207
// return the window class name and initialize the class if needed
209
//-------------------------------------------------------------------------
210
PCSZ nsCheckButton::WindowClass()
212
return WC_BUTTON_STRING;
216
//-------------------------------------------------------------------------
218
// return window styles
220
//-------------------------------------------------------------------------
221
ULONG nsCheckButton::WindowStyle()
223
return BS_CHECKBOX | WS_CLIPSIBLINGS;
227
//-------------------------------------------------------------------------
229
// return window extended styles
231
//-------------------------------------------------------------------------
232
ULONG nsCheckButton::WindowExStyle()
240
* Renders the CheckButton for Printing
243
NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext,
244
const nsRect& aDirtyRect)
249
nsIDeviceContext * context;
250
aRenderingContext.GetDeviceContext(context);
252
context->GetCanonicalPixelScale(scale);
253
appUnits = context->DevUnitsToAppUnits();
255
GetBoundsAppUnits(rect, appUnits);
257
nscoord one = nscoord(PRFloat64(rect.height) * 1.0/20.0);
258
nscoord three = nscoord(PRFloat64(rect.width) * 3.0/20.0);
259
nscoord five = nscoord(PRFloat64(rect.width) * 5.0/20.0);
260
nscoord six = nscoord(PRFloat64(rect.height) * 5.0/20.0);
261
nscoord eight = nscoord(PRFloat64(rect.height) * 7.0/20.0);
262
nscoord nine = nscoord(PRFloat64(rect.width) * 9.0/20.0);
263
nscoord ten = nscoord(PRFloat64(rect.height) * 9.0/20.0);
266
rect.y += nscoord(PRFloat64(rect.height) * 3.5 /20.0);
267
rect.width = nscoord(PRFloat64(rect.width) * 12.0/20.0);
268
rect.height = nscoord(PRFloat64(rect.height) * 12.0/20.0);
270
aRenderingContext.SetColor(NS_RGB(0,0,0));
272
nscoord onePixel = nscoord((appUnits+0.6F));
273
DrawScaledRect(aRenderingContext, rect, scale, appUnits);
278
nscoord inc = nscoord(PRFloat64(rect.height) * 0.75/20.0);
280
for (nscoord i=0;i<4;i++) {
281
DrawScaledLine(aRenderingContext, x+three, y+eight+yy, x+five, y+ten+yy, scale, appUnits, PR_FALSE); // top
282
DrawScaledLine(aRenderingContext, x+five, y+ten+yy, x+nine, y+six+yy, scale, appUnits, PR_FALSE); // top
283
//aRenderingContext.DrawLine(x+three, y+eight+yy, x+five, y+ten+yy);
284
//aRenderingContext.DrawLine(x+five, y+ten+yy, x+nine, y+six+yy);
285
yy += nscoord(scale);