1998-06-28 11:32:14 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-03-20 00:14:35 +00:00
|
|
|
// Name: src/msw/gauge.cpp
|
2008-03-15 16:53:06 +00:00
|
|
|
// Purpose: wxGauge class
|
1998-06-28 11:32:14 +00:00
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 01/02/97
|
2003-03-17 11:23:28 +00:00
|
|
|
// Copyright: (c) Julian Smart
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-06-28 11:32:14 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-06-28 11:32:14 +00:00
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2003-09-22 12:31:58 +00:00
|
|
|
#pragma hdrstop
|
1998-06-28 11:32:14 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-18 09:56:17 +00:00
|
|
|
#if wxUSE_GAUGE
|
|
|
|
|
2006-06-06 22:02:01 +00:00
|
|
|
#include "wx/gauge.h"
|
|
|
|
|
1998-06-28 11:32:14 +00:00
|
|
|
#ifndef WX_PRECOMP
|
2006-09-10 12:23:44 +00:00
|
|
|
#include "wx/app.h"
|
|
|
|
|
2006-09-07 19:01:45 +00:00
|
|
|
#include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
|
1998-06-28 11:32:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/msw/private.h"
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// old commctrl.h (< 4.71) don't have those
|
|
|
|
#ifndef PBS_SMOOTH
|
|
|
|
#define PBS_SMOOTH 0x01
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PBS_VERTICAL
|
|
|
|
#define PBS_VERTICAL 0x04
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PBM_SETBARCOLOR
|
|
|
|
#define PBM_SETBARCOLOR (WM_USER+9)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PBM_SETBKCOLOR
|
|
|
|
#define PBM_SETBKCOLOR 0x2001
|
|
|
|
#endif
|
|
|
|
|
2006-09-09 13:36:54 +00:00
|
|
|
#ifndef PBS_MARQUEE
|
|
|
|
#define PBS_MARQUEE 0x08
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PBM_SETMARQUEE
|
|
|
|
#define PBM_SETMARQUEE (WM_USER+10)
|
|
|
|
#endif
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ============================================================================
|
2008-03-15 16:53:06 +00:00
|
|
|
// wxGauge implementation
|
2000-07-15 19:51:35 +00:00
|
|
|
// ============================================================================
|
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-15 16:53:06 +00:00
|
|
|
// wxGauge creation
|
2003-09-22 12:31:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
bool wxGauge::Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
int range,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxValidator& validator,
|
|
|
|
const wxString& name)
|
2003-09-22 12:31:58 +00:00
|
|
|
{
|
|
|
|
if ( !CreateControl(parent, id, pos, size, style, validator, name) )
|
|
|
|
return false;
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) )
|
|
|
|
return false;
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
SetRange(range);
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2006-09-09 13:36:54 +00:00
|
|
|
// in case we need to emulate indeterminate mode...
|
|
|
|
m_nDirection = wxRIGHT;
|
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const
|
2003-09-22 12:31:58 +00:00
|
|
|
{
|
|
|
|
WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
if ( style & wxGA_VERTICAL )
|
|
|
|
msStyle |= PBS_VERTICAL;
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
if ( style & wxGA_SMOOTH )
|
|
|
|
msStyle |= PBS_SMOOTH;
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
return msStyle;
|
1998-06-28 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-15 16:53:06 +00:00
|
|
|
// wxGauge geometry
|
2003-09-22 12:31:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
wxSize wxGauge::DoGetBestSize() const
|
1998-06-28 11:32:14 +00:00
|
|
|
{
|
2010-02-10 13:31:58 +00:00
|
|
|
// Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx)
|
|
|
|
// suggest progress bar size of "107 or 237 x 8 dialog units". Let's use
|
|
|
|
// the smaller one.
|
|
|
|
|
2004-05-04 02:38:09 +00:00
|
|
|
if (HasFlag(wxGA_VERTICAL))
|
2010-02-10 13:31:58 +00:00
|
|
|
return ConvertDialogToPixels(wxSize(8, 107));
|
2004-04-17 02:00:24 +00:00
|
|
|
else
|
2010-02-10 13:31:58 +00:00
|
|
|
return ConvertDialogToPixels(wxSize(107, 8));
|
1998-06-28 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-15 16:53:06 +00:00
|
|
|
// wxGauge setters
|
2003-09-22 12:31:58 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
void wxGauge::SetRange(int r)
|
1998-06-28 11:32:14 +00:00
|
|
|
{
|
2010-06-20 17:43:02 +00:00
|
|
|
// Changing range implicitly means we're using determinate mode.
|
|
|
|
if ( IsInIndeterminateMode() )
|
|
|
|
SetDeterminateMode();
|
2006-09-09 13:36:54 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
m_rangeMax = r;
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2003-09-22 11:36:48 +00:00
|
|
|
#ifdef PBM_SETRANGE32
|
2003-09-22 12:31:58 +00:00
|
|
|
::SendMessage(GetHwnd(), PBM_SETRANGE32, 0, r);
|
2003-09-22 11:36:48 +00:00
|
|
|
#else // !PBM_SETRANGE32
|
2003-09-22 12:31:58 +00:00
|
|
|
// fall back to PBM_SETRANGE (limited to 16 bits)
|
|
|
|
::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
|
2003-09-22 11:36:48 +00:00
|
|
|
#endif // PBM_SETRANGE32/!PBM_SETRANGE32
|
1998-06-28 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
void wxGauge::SetValue(int pos)
|
1998-06-28 11:32:14 +00:00
|
|
|
{
|
2010-06-20 17:43:02 +00:00
|
|
|
// Setting the value implicitly means that we're using determinate mode.
|
|
|
|
if ( IsInIndeterminateMode() )
|
|
|
|
SetDeterminateMode();
|
2009-09-24 10:18:15 +00:00
|
|
|
|
2010-06-20 17:43:02 +00:00
|
|
|
if ( GetValue() != pos )
|
|
|
|
{
|
|
|
|
m_gaugePos = pos;
|
1998-06-28 11:32:14 +00:00
|
|
|
|
2010-06-20 17:43:02 +00:00
|
|
|
::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0);
|
|
|
|
}
|
1998-06-28 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
bool wxGauge::SetForegroundColour(const wxColour& col)
|
1998-06-28 11:32:14 +00:00
|
|
|
{
|
1999-05-10 00:42:57 +00:00
|
|
|
if ( !wxControl::SetForegroundColour(col) )
|
2003-09-22 12:31:58 +00:00
|
|
|
return false;
|
1999-05-10 00:42:57 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
::SendMessage(GetHwnd(), PBM_SETBARCOLOR, 0, (LPARAM)wxColourToRGB(col));
|
1999-05-10 00:42:57 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
return true;
|
1998-06-28 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
bool wxGauge::SetBackgroundColour(const wxColour& col)
|
1998-06-28 11:32:14 +00:00
|
|
|
{
|
1999-05-10 00:42:57 +00:00
|
|
|
if ( !wxControl::SetBackgroundColour(col) )
|
2003-09-22 12:31:58 +00:00
|
|
|
return false;
|
1999-05-10 00:42:57 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
::SendMessage(GetHwnd(), PBM_SETBKCOLOR, 0, (LPARAM)wxColourToRGB(col));
|
1999-05-10 00:42:57 +00:00
|
|
|
|
2003-09-22 12:31:58 +00:00
|
|
|
return true;
|
1998-06-28 11:32:14 +00:00
|
|
|
}
|
|
|
|
|
2010-06-20 17:43:02 +00:00
|
|
|
bool wxGauge::IsInIndeterminateMode() const
|
2006-09-09 13:36:54 +00:00
|
|
|
{
|
2010-06-20 17:43:02 +00:00
|
|
|
return (::GetWindowLong(GetHwnd(), GWL_STYLE) & PBS_MARQUEE) != 0;
|
|
|
|
}
|
2006-09-09 13:36:54 +00:00
|
|
|
|
2010-06-20 17:43:02 +00:00
|
|
|
void wxGauge::SetIndeterminateMode()
|
|
|
|
{
|
|
|
|
// Switch the control into indeterminate mode if necessary.
|
|
|
|
if ( !IsInIndeterminateMode() )
|
|
|
|
{
|
|
|
|
const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
|
|
|
|
::SetWindowLong(GetHwnd(), GWL_STYLE, style | PBS_MARQUEE);
|
|
|
|
::SendMessage(GetHwnd(), PBM_SETMARQUEE, TRUE, 0);
|
|
|
|
}
|
2006-09-09 13:36:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
void wxGauge::SetDeterminateMode()
|
2006-09-09 13:36:54 +00:00
|
|
|
{
|
2010-06-20 17:43:02 +00:00
|
|
|
if ( IsInIndeterminateMode() )
|
|
|
|
{
|
|
|
|
const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
|
|
|
|
::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0);
|
2006-09-09 13:36:54 +00:00
|
|
|
::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE);
|
2010-06-20 17:43:02 +00:00
|
|
|
}
|
2006-09-09 13:36:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 16:53:06 +00:00
|
|
|
void wxGauge::Pulse()
|
2006-09-09 13:36:54 +00:00
|
|
|
{
|
|
|
|
if (wxApp::GetComCtl32Version() >= 600)
|
|
|
|
{
|
|
|
|
// switch to indeterminate mode if required
|
|
|
|
SetIndeterminateMode();
|
|
|
|
|
2010-06-20 17:43:02 +00:00
|
|
|
SendMessage(GetHwnd(), PBM_STEPIT, 0, 0);
|
2006-09-09 13:36:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// emulate indeterminate mode
|
|
|
|
wxGaugeBase::Pulse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-25 13:28:52 +00:00
|
|
|
#endif // wxUSE_GAUGE
|