changed ShowWithEffects() to use directional wxSHOW_EFFECT_XXX flags instead of additional wxDirection argument that doesn't always make sense; this also means the direction is never implicit

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53499 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2008-05-08 21:56:26 +00:00
parent f992f2ae26
commit eed04c9999
5 changed files with 165 additions and 110 deletions

View File

@@ -61,16 +61,14 @@ public:
virtual bool Show(bool show = true); virtual bool Show(bool show = true);
virtual bool ShowWithEffect(wxShowEffect effect, virtual bool ShowWithEffect(wxShowEffect effect,
unsigned timeout = 0, unsigned timeout = 0)
wxDirection dir = wxBOTTOM)
{ {
return MSWShowWithEffect(true, effect, timeout, dir); return MSWShowWithEffect(true, effect, timeout);
} }
virtual bool HideWithEffect(wxShowEffect effect, virtual bool HideWithEffect(wxShowEffect effect,
unsigned timeout = 0, unsigned timeout = 0)
wxDirection dir = wxBOTTOM)
{ {
return MSWShowWithEffect(false, effect, timeout, dir); return MSWShowWithEffect(false, effect, timeout);
} }
virtual void SetFocus(); virtual void SetFocus();
@@ -431,8 +429,7 @@ public:
// common part of Show/HideWithEffect() // common part of Show/HideWithEffect()
bool MSWShowWithEffect(bool show, bool MSWShowWithEffect(bool show,
wxShowEffect effect, wxShowEffect effect,
unsigned timeout, unsigned timeout);
wxDirection dir);
// Responds to colour changes: passes event on to children. // Responds to colour changes: passes event on to children.
void OnSysColourChanged(wxSysColourChangedEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event);

View File

@@ -118,8 +118,14 @@ enum wxWindowVariant
// valid values for Show/HideWithEffect() // valid values for Show/HideWithEffect()
enum wxShowEffect enum wxShowEffect
{ {
wxSHOW_EFFECT_ROLL, wxSHOW_EFFECT_ROLL_TO_LEFT,
wxSHOW_EFFECT_SLIDE, wxSHOW_EFFECT_ROLL_TO_RIGHT,
wxSHOW_EFFECT_ROLL_TO_TOP,
wxSHOW_EFFECT_ROLL_TO_BOTTOM,
wxSHOW_EFFECT_SLIDE_TO_LEFT,
wxSHOW_EFFECT_SLIDE_TO_RIGHT,
wxSHOW_EFFECT_SLIDE_TO_TOP,
wxSHOW_EFFECT_SLIDE_TO_BOTTOM,
wxSHOW_EFFECT_BLEND, wxSHOW_EFFECT_BLEND,
wxSHOW_EFFECT_EXPAND, wxSHOW_EFFECT_EXPAND,
wxSHOW_EFFECT_MAX wxSHOW_EFFECT_MAX
@@ -538,27 +544,15 @@ public:
// //
// timeout specifies how long the animation should take, in ms, the // timeout specifies how long the animation should take, in ms, the
// default value of 0 means to use the default (system-dependent) value // default value of 0 means to use the default (system-dependent) value
// virtual bool ShowWithEffect(wxShowEffect WXUNUSED(effect),
// direction is only used with wxSHOW_EFFECT_ROLL and SLIDE values unsigned WXUNUSED(timeout) = 0)
virtual bool ShowWithEffect(wxShowEffect effect,
unsigned timeout = 0,
wxDirection dir = wxBOTTOM)
{ {
wxUnusedVar(effect);
wxUnusedVar(timeout);
wxUnusedVar(dir);
return Show(); return Show();
} }
virtual bool HideWithEffect(wxShowEffect effect, virtual bool HideWithEffect(wxShowEffect WXUNUSED(effect),
unsigned timeout = 0, unsigned WXUNUSED(timeout) = 0)
wxDirection dir = wxBOTTOM)
{ {
wxUnusedVar(effect);
wxUnusedVar(timeout);
wxUnusedVar(dir);
return Hide(); return Hide();
} }

View File

@@ -1255,17 +1255,16 @@ public:
bool Hide(); bool Hide();
/** /**
This function hides a window, like Hide(), but using a This function hides a window, like Hide(), but using a special visual
special visual effect if possible. effect if possible.
The parameters of this function are the same as for
ShowWithEffect(), please see their The parameters of this function are the same as for ShowWithEffect(),
description there. please see their description there.
@since 2.9.0 @since 2.9.0
*/ */
virtual bool HideWithEffect(wxShowEffect effect, virtual bool HideWithEffect(wxShowEffect effect,
unsigned timeout = 0, unsigned timeout = 0);
wxDirection dir = wxBOTTOM);
/** /**
This function is (or should be, in case of custom controls) called during This function is (or should be, in case of custom controls) called during
@@ -2455,42 +2454,26 @@ public:
virtual bool Show(bool show = true); virtual bool Show(bool show = true);
/** /**
This function shows a window, like Show(), but using a This function shows a window, like Show(), but using a special visual
special visual effect if possible. effect if possible.
Possible values for @a effect are:
wxSHOW_EFFECT_ROLL @param effect
The effect to use.
Roll window effect @param timeout
The @a timeout parameter specifies the time of the animation, in
milliseconds. If the default value of 0 is used, the default
animation time for the current platform is used.
wxSHOW_EFFECT_SLIDE @note Currently this function is only implemented in wxMSW and does the
same thing as Show() in the other ports.
Sliding window effect
wxSHOW_EFFECT_BLEND
Fade in or out effect
wxSHOW_EFFECT_EXPAND
Expanding or collapsing effect
For the roll and slide effects the @a dir parameter specifies the animation
direction: it can be one of @c wxTOP, @c wxBOTTOM, @c wxLEFT
or @c wxRIGHT. For the other effects, this parameter is unused.
The @a timeout parameter specifies the time of the animation, in
milliseconds. If the default value of 0 is used, the default animation time
for the current platform is used.
Currently this function is only implemented in wxMSW and does the same thing as
Show() in the other ports.
@since 2.9.0 @since 2.9.0
@see HideWithEffect() @see HideWithEffect()
*/ */
virtual bool ShowWithEffect(wxShowEffect effect, virtual bool ShowWithEffect(wxShowEffect effect,
unsigned timeout = 0, unsigned timeout = 0);
wxDirection dir = wxBOTTOM);
/** /**
Reenables window updating after a previous call to Freeze(). Reenables window updating after a previous call to Freeze().
@@ -2634,6 +2617,32 @@ public:
}; };
/// Valid values for wxWindow::ShowWithEffect() and wxWindow::HideWithEffect().
enum wxShowEffect
{
/// Roll window to the left
wxSHOW_EFFECT_ROLL_TO_LEFT,
/// Roll window to the right
wxSHOW_EFFECT_ROLL_TO_RIGHT,
/// Roll window to the top
wxSHOW_EFFECT_ROLL_TO_TOP,
/// Roll window to the bottom
wxSHOW_EFFECT_ROLL_TO_BOTTOM,
/// Slide window to the left
wxSHOW_EFFECT_SLIDE_TO_LEFT,
/// Slide window to the right
wxSHOW_EFFECT_SLIDE_TO_RIGHT,
/// Slide window to the top
wxSHOW_EFFECT_SLIDE_TO_TOP,
/// Slide window to the bottom
wxSHOW_EFFECT_SLIDE_TO_BOTTOM,
/// Fade in or out effect
wxSHOW_EFFECT_BLEND,
/// Expanding or collapsing effect
wxSHOW_EFFECT_EXPAND
};
// ============================================================================ // ============================================================================
// Global functions/macros // Global functions/macros

View File

@@ -40,6 +40,7 @@
#include "wx/dcclient.h" #include "wx/dcclient.h"
#include "wx/image.h" #include "wx/image.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -152,15 +153,13 @@ public:
wxShowEffect effect, wxShowEffect effect,
// TODO: add menu command to the main frame to allow changing // TODO: add menu command to the main frame to allow changing
// these parameters // these parameters
unsigned timeout = 1000, unsigned timeout = 1000)
wxDirection dir = wxBOTTOM)
: wxFrame(parent, wxID_ANY, : wxFrame(parent, wxID_ANY,
wxString::Format("Frame shown with %s effect", wxString::Format("Frame shown with %s effect",
GetEffectName(effect)), GetEffectName(effect)),
wxDefaultPosition, wxSize(450, 300)), wxDefaultPosition, wxSize(450, 300)),
m_effect(effect), m_effect(effect),
m_timeout(timeout), m_timeout(timeout)
m_dir(dir)
{ {
new wxStaticText(this, wxID_ANY, new wxStaticText(this, wxID_ANY,
wxString::Format("Effect: %s", GetEffectName(effect)), wxString::Format("Effect: %s", GetEffectName(effect)),
@@ -169,7 +168,7 @@ public:
wxString::Format("Timeout: %ums", m_timeout), wxString::Format("Timeout: %ums", m_timeout),
wxPoint(20, 60)); wxPoint(20, 60));
ShowWithEffect(m_effect, m_timeout, m_dir); ShowWithEffect(m_effect, m_timeout);
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(EffectFrame::OnClose)); Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(EffectFrame::OnClose));
} }
@@ -179,7 +178,16 @@ private:
{ {
static const char *names[] = static const char *names[] =
{ {
"roll", "slide", "fade", "expand", "roll to left",
"roll to right",
"roll to top",
"roll to bottom",
"slide to left",
"slide to right",
"slide to top",
"slide to bottom",
"fade",
"expand",
}; };
wxCOMPILE_TIME_ASSERT( WXSIZEOF(names) == wxSHOW_EFFECT_MAX, wxCOMPILE_TIME_ASSERT( WXSIZEOF(names) == wxSHOW_EFFECT_MAX,
EffectNamesMismatch ); EffectNamesMismatch );
@@ -189,14 +197,13 @@ private:
void OnClose(wxCloseEvent& event) void OnClose(wxCloseEvent& event)
{ {
HideWithEffect(m_effect, m_timeout, m_dir); HideWithEffect(m_effect, m_timeout);
event.Skip(); event.Skip();
} }
wxShowEffect m_effect; wxShowEffect m_effect;
unsigned m_timeout; unsigned m_timeout;
wxDirection m_dir;
}; };
// ============================================================================ // ============================================================================
@@ -271,12 +278,70 @@ void MainFrame::OnShowTransparent(wxCommandEvent& WXUNUSED(event))
void MainFrame::OnShowEffect(wxCommandEvent& event) void MainFrame::OnShowEffect(wxCommandEvent& event)
{ {
int effect = wxSHOW_EFFECT_ROLL + event.GetId() - Show_Effect_Roll; int effect = event.GetId();
static wxDirection direction = wxLEFT; static wxDirection direction = wxLEFT;
direction = (wxDirection)(((int)direction)<< 1); direction = (wxDirection)(((int)direction)<< 1);
if ( direction > wxDOWN ) if ( direction > wxDOWN )
direction = wxLEFT ; direction = wxLEFT ;
new EffectFrame(this, wx_static_cast(wxShowEffect, effect),1000,direction);
wxShowEffect eff;
switch ( effect )
{
case Show_Effect_Roll:
switch ( direction )
{
case wxLEFT:
eff = wxSHOW_EFFECT_ROLL_TO_LEFT;
break;
case wxRIGHT:
eff = wxSHOW_EFFECT_ROLL_TO_RIGHT;
break;
case wxTOP:
eff = wxSHOW_EFFECT_ROLL_TO_TOP;
break;
case wxBOTTOM:
eff = wxSHOW_EFFECT_ROLL_TO_BOTTOM;
break;
default:
wxFAIL_MSG( "invalid direction" );
return;
}
break;
case Show_Effect_Slide:
switch ( direction )
{
case wxLEFT:
eff = wxSHOW_EFFECT_SLIDE_TO_LEFT;
break;
case wxRIGHT:
eff = wxSHOW_EFFECT_SLIDE_TO_RIGHT;
break;
case wxTOP:
eff = wxSHOW_EFFECT_SLIDE_TO_TOP;
break;
case wxBOTTOM:
eff = wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
break;
default:
wxFAIL_MSG( "invalid direction" );
return;
}
break;
case Show_Effect_Blend:
eff = wxSHOW_EFFECT_BLEND;
break;
case Show_Effect_Expand:
eff = wxSHOW_EFFECT_EXPAND;
break;
default:
wxFAIL_MSG( "invalid effect" );
return;
}
new EffectFrame(this, eff,1000);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -732,8 +732,7 @@ bool wxWindowMSW::Show(bool show)
bool bool
wxWindowMSW::MSWShowWithEffect(bool show, wxWindowMSW::MSWShowWithEffect(bool show,
wxShowEffect effect, wxShowEffect effect,
unsigned timeout, unsigned timeout)
wxDirection dir)
{ {
if ( !wxWindowBase::Show(show) ) if ( !wxWindowBase::Show(show) )
return false; return false;
@@ -762,16 +761,39 @@ wxWindowMSW::MSWShowWithEffect(bool show,
timeout = 200; // this is the default animation timeout, per MSDN timeout = 200; // this is the default animation timeout, per MSDN
DWORD dwFlags = show ? 0 : AW_HIDE; DWORD dwFlags = show ? 0 : AW_HIDE;
bool needsDir = false;
switch ( effect ) switch ( effect )
{ {
case wxSHOW_EFFECT_ROLL: case wxSHOW_EFFECT_ROLL_TO_LEFT:
needsDir = true; dwFlags |= AW_HOR_NEGATIVE;
break; break;
case wxSHOW_EFFECT_SLIDE: case wxSHOW_EFFECT_ROLL_TO_RIGHT:
needsDir = true; dwFlags |= AW_HOR_POSITIVE;
dwFlags |= AW_SLIDE; break;
case wxSHOW_EFFECT_ROLL_TO_TOP:
dwFlags |= AW_VER_NEGATIVE;
break;
case wxSHOW_EFFECT_ROLL_TO_BOTTOM:
dwFlags |= AW_VER_POSITIVE;
break;
case wxSHOW_EFFECT_SLIDE_TO_LEFT:
dwFlags |= AW_SLIDE | AW_HOR_NEGATIVE;
break;
case wxSHOW_EFFECT_SLIDE_TO_RIGHT:
dwFlags |= AW_SLIDE | AW_HOR_POSITIVE;
break;
case wxSHOW_EFFECT_SLIDE_TO_TOP:
dwFlags |= AW_SLIDE | AW_VER_NEGATIVE;
break;
case wxSHOW_EFFECT_SLIDE_TO_BOTTOM:
dwFlags |= AW_SLIDE | AW_VER_POSITIVE;
break; break;
case wxSHOW_EFFECT_BLEND: case wxSHOW_EFFECT_BLEND:
@@ -792,38 +814,6 @@ wxWindowMSW::MSWShowWithEffect(bool show,
return false; return false;
} }
if ( needsDir )
{
switch ( dir )
{
case wxTOP:
dwFlags |= AW_VER_NEGATIVE;
break;
case wxBOTTOM:
dwFlags |= AW_VER_POSITIVE;
break;
case wxLEFT:
dwFlags |= AW_HOR_NEGATIVE;
break;
case wxRIGHT:
dwFlags |= AW_HOR_POSITIVE;
break;
default:
wxFAIL_MSG( _T("unknown window effect direction") );
return false;
}
}
else // animation effect which doesn't need the direction
{
wxASSERT_MSG( dir == wxBOTTOM,
_T("non-default direction used unnecessarily") );
}
if ( !(*s_pfnAnimateWindow)(GetHwnd(), timeout, dwFlags) ) if ( !(*s_pfnAnimateWindow)(GetHwnd(), timeout, dwFlags) )
{ {
wxLogLastError(_T("AnimateWindow")); wxLogLastError(_T("AnimateWindow"));