187 lines
4.9 KiB
C++
187 lines
4.9 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
*
|
|
* The contents of this file are subject to the Netscape Public License
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
* http://www.mozilla.org/NPL/
|
|
*
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
* for the specific language governing rights and limitations under the
|
|
* NPL.
|
|
*
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
* Communications Corporation. Portions created by Netscape are
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
* Reserved.
|
|
*/
|
|
|
|
#include "nsRadioButton.h"
|
|
#include "nsToolkit.h"
|
|
#include "nsColor.h"
|
|
#include "nsGUIEvent.h"
|
|
#include "nsStringUtil.h"
|
|
|
|
#include <windows.h>
|
|
NS_IMPL_ADDREF(nsRadioButton)
|
|
NS_IMPL_RELEASE(nsRadioButton)
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// nsRadioButton constructor
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
nsRadioButton::nsRadioButton() : nsWindow(), nsIRadioButton()
|
|
{
|
|
NS_INIT_REFCNT();
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// nsRadioButton destructor
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
nsRadioButton::~nsRadioButton()
|
|
{
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// Query interface implementation
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
nsresult nsRadioButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
{
|
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
|
|
|
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
|
|
if (result == NS_NOINTERFACE && aIID.Equals(kIRadioButtonIID)) {
|
|
*aInstancePtr = (void*) ((nsIRadioButton*)this);
|
|
NS_ADDREF_THIS();
|
|
result = NS_OK;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// Sets the state of the nsRadioButton
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
NS_METHOD nsRadioButton::SetState(const PRBool aState)
|
|
{
|
|
fState = aState;
|
|
::SendMessage(GetWindowHandle(), BM_SETCHECK, (WPARAM)(fState), 0L);
|
|
return NS_OK;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// Set this button label
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
NS_METHOD nsRadioButton::GetState(PRBool& aState)
|
|
{
|
|
aState = fState;
|
|
return NS_OK;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// Set this button label
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
NS_METHOD nsRadioButton::SetLabel(const nsString& aText)
|
|
{
|
|
char label[256];
|
|
aText.ToCString(label, 256);
|
|
label[255] = '\0';
|
|
VERIFY(::SetWindowText(mWnd, label));
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// Get this button label
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
NS_METHOD nsRadioButton::GetLabel(nsString& aBuffer)
|
|
{
|
|
int actualSize = ::GetWindowTextLength(mWnd)+1;
|
|
NS_ALLOC_CHAR_BUF(label, 256, actualSize);
|
|
::GetWindowText(mWnd, label, actualSize);
|
|
aBuffer.SetLength(0);
|
|
aBuffer.Append(label);
|
|
NS_FREE_CHAR_BUF(label);
|
|
return NS_OK;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// move, paint, resizes message - ignore
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
PRBool nsRadioButton::OnMove(PRInt32, PRInt32)
|
|
{
|
|
return PR_FALSE;
|
|
}
|
|
|
|
PRBool nsRadioButton::OnPaint()
|
|
{
|
|
return PR_FALSE;
|
|
}
|
|
|
|
PRBool nsRadioButton::OnResize(nsRect &aWindowRect)
|
|
{
|
|
return PR_FALSE;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// return the window class name and initialize the class if needed
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
LPCTSTR nsRadioButton::WindowClass()
|
|
{
|
|
return "BUTTON";
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// return window styles
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
DWORD nsRadioButton::WindowStyle()
|
|
{
|
|
return BS_RADIOBUTTON | WS_CHILD | WS_CLIPSIBLINGS;
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// return window extended styles
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
DWORD nsRadioButton::WindowExStyle()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
//
|
|
// get position/dimensions
|
|
//
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsRadioButton::GetBounds(nsRect &aRect)
|
|
{
|
|
nsWindow::GetBounds(aRect);
|
|
}
|
|
|
|
|