~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/webshell/tests/viewer/os2/nsCheckButton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include "nsCheckButton.h"
 
39
#include "nsToolkit.h"
 
40
#include "nsColor.h"
 
41
#include "nsGUIEvent.h"
 
42
#include "nsString.h"
 
43
#include "nsStringUtil.h"
 
44
#include <os2.h>
 
45
 
 
46
#include "nsILookAndFeel.h"
 
47
#include "nsWidgetsCID.h"
 
48
#include "nsIComponentManager.h"
 
49
 
 
50
#include "nsIDeviceContext.h"
 
51
 
 
52
#define IDM_BUTTON 701
 
53
 
 
54
//-------------------------------------------------------------------------
 
55
nsresult
 
56
NS_NewCheckButton(nsICheckButton** aControl)
 
57
{
 
58
  NS_PRECONDITION(aControl, "null OUT ptr");
 
59
  if (nsnull == aControl) {
 
60
    return NS_ERROR_NULL_POINTER;
 
61
  }
 
62
  nsCheckButton* it = new nsCheckButton;
 
63
  if (!it) {
 
64
    return NS_ERROR_OUT_OF_MEMORY;
 
65
  }
 
66
  NS_ADDREF(it);
 
67
  *aControl = (nsICheckButton*)it;
 
68
  return NS_OK;
 
69
}
 
70
 
 
71
 
 
72
NS_IMPL_ADDREF(nsCheckButton)
 
73
NS_IMPL_RELEASE(nsCheckButton)
 
74
 
 
75
//-------------------------------------------------------------------------
 
76
//
 
77
// nsCheckButton constructor
 
78
//
 
79
//-------------------------------------------------------------------------
 
80
nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton(),
 
81
  mState(PR_FALSE)
 
82
{
 
83
}
 
84
 
 
85
 
 
86
//-------------------------------------------------------------------------
 
87
//
 
88
// nsCheckButton destructor
 
89
//
 
90
//-------------------------------------------------------------------------
 
91
nsCheckButton::~nsCheckButton()
 
92
{
 
93
}
 
94
 
 
95
 
 
96
/**
 
97
 * Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
 
98
 * @modify gpk 8/4/98
 
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)
 
102
 * 
 
103
*/ 
 
104
nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 
105
{
 
106
    if (NULL == aInstancePtr) {
 
107
        return NS_ERROR_NULL_POINTER;
 
108
    }
 
109
 
 
110
    static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
 
111
    if (aIID.Equals(kICheckButtonIID)) {
 
112
        *aInstancePtr = (void*) ((nsICheckButton*)this);
 
113
        NS_ADDREF_THIS();
 
114
        return NS_OK;
 
115
    }
 
116
    return nsWindow::QueryInterface(aIID,aInstancePtr);
 
117
}
 
118
 
 
119
 
 
120
//-------------------------------------------------------------------------
 
121
//
 
122
// Set this button label
 
123
//
 
124
//-------------------------------------------------------------------------
 
125
NS_METHOD nsCheckButton::SetState(const PRBool aState)
 
126
{
 
127
  mState = aState;
 
128
  if (mWnd) {
 
129
    USHORT chkState;
 
130
    if (aState)
 
131
       chkState = 1;
 
132
    else
 
133
       chkState = 0;
 
134
    WinCheckButton(mWnd, IDM_BUTTON, chkState);
 
135
  }
 
136
  return NS_OK;
 
137
}
 
138
 
 
139
//-------------------------------------------------------------------------
 
140
//
 
141
// Set this button label
 
142
//
 
143
//-------------------------------------------------------------------------
 
144
NS_METHOD nsCheckButton::GetState(PRBool& aState)
 
145
{
 
146
  USHORT chkState = WinQueryButtonCheckstate(mWnd, IDM_BUTTON);
 
147
  if (chkState == 1)
 
148
      aState = PR_TRUE;
 
149
  else
 
150
      aState = PR_FALSE;
 
151
  return NS_OK;
 
152
}
 
153
 
 
154
//-------------------------------------------------------------------------
 
155
//
 
156
// Set this button label
 
157
//
 
158
//-------------------------------------------------------------------------
 
159
NS_METHOD nsCheckButton::SetLabel(const nsString& aText)
 
160
{
 
161
  char label[256];
 
162
  aText.ToCString(label, 256);
 
163
  label[255] = '\0';
 
164
  ::WinSetWindowText(mWnd, label);
 
165
  return NS_OK;
 
166
}
 
167
 
 
168
 
 
169
//-------------------------------------------------------------------------
 
170
//
 
171
// Get this button label
 
172
//
 
173
//-------------------------------------------------------------------------
 
174
NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
 
175
{
 
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);
 
182
  return NS_OK;
 
183
}
 
184
 
 
185
//-------------------------------------------------------------------------
 
186
//
 
187
// move, paint, resizes message - ignore
 
188
//
 
189
//-------------------------------------------------------------------------
 
190
PRBool nsCheckButton::OnMove(PRInt32, PRInt32)
 
191
{
 
192
  return PR_FALSE;
 
193
}
 
194
 
 
195
PRBool nsCheckButton::OnPaint()
 
196
{
 
197
    return PR_FALSE;
 
198
}
 
199
 
 
200
PRBool nsCheckButton::OnResize(nsRect &aWindowRect)
 
201
{
 
202
    return PR_FALSE;
 
203
}
 
204
 
 
205
//-------------------------------------------------------------------------
 
206
//
 
207
// return the window class name and initialize the class if needed
 
208
//
 
209
//-------------------------------------------------------------------------
 
210
PCSZ nsCheckButton::WindowClass()
 
211
{
 
212
    return WC_BUTTON_STRING;
 
213
}
 
214
 
 
215
 
 
216
//-------------------------------------------------------------------------
 
217
//
 
218
// return window styles
 
219
//
 
220
//-------------------------------------------------------------------------
 
221
ULONG nsCheckButton::WindowStyle()
 
222
{
 
223
    return BS_CHECKBOX | WS_CLIPSIBLINGS; 
 
224
}
 
225
 
 
226
 
 
227
//-------------------------------------------------------------------------
 
228
//
 
229
// return window extended styles
 
230
//
 
231
//-------------------------------------------------------------------------
 
232
ULONG nsCheckButton::WindowExStyle()
 
233
{
 
234
    return 0;
 
235
}
 
236
 
 
237
 
 
238
 
 
239
/**
 
240
 * Renders the CheckButton for Printing
 
241
 *
 
242
 **/
 
243
NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext,
 
244
                               const nsRect&        aDirtyRect)
 
245
{
 
246
  nsRect rect;
 
247
  float  appUnits;
 
248
  float  scale;
 
249
  nsIDeviceContext * context;
 
250
  aRenderingContext.GetDeviceContext(context);
 
251
 
 
252
  context->GetCanonicalPixelScale(scale);
 
253
  appUnits = context->DevUnitsToAppUnits();
 
254
 
 
255
  GetBoundsAppUnits(rect, appUnits);
 
256
 
 
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);
 
264
 
 
265
  rect.x      += three;
 
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);
 
269
 
 
270
  aRenderingContext.SetColor(NS_RGB(0,0,0));
 
271
 
 
272
  nscoord onePixel  = nscoord((appUnits+0.6F));
 
273
  DrawScaledRect(aRenderingContext, rect, scale, appUnits);
 
274
  nscoord x = rect.x;
 
275
  nscoord y = rect.y;
 
276
 
 
277
  if (mState) {
 
278
    nscoord inc   = nscoord(PRFloat64(rect.height) *   0.75/20.0);
 
279
    nscoord yy = 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);
 
286
    }
 
287
  }
 
288
 
 
289
  NS_RELEASE(context);
 
290
  return NS_OK;
 
291
}
 
292