partial implementation of wxTLW's decorations

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11683 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2001-09-23 22:42:57 +00:00
parent 038072e2f1
commit 24a23c3573
6 changed files with 726 additions and 10 deletions

View File

@@ -27,6 +27,10 @@
#include "wx/defs.h"
#include "wx/toplevel.h"
#include "wx/univ/renderer.h"
#include "wx/dcclient.h"
#include "wx/bitmap.h"
#include "wx/image.h"
// ----------------------------------------------------------------------------
@@ -35,13 +39,20 @@
IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
BEGIN_EVENT_TABLE(wxTopLevelWindow, wxTopLevelWindowNative)
EVT_NC_PAINT(wxTopLevelWindow::OnNcPaint)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
int wxTopLevelWindow::ms_drawDecorations = -1;
void wxTopLevelWindow::Init()
{
m_isActive = FALSE;
}
bool wxTopLevelWindow::Create(wxWindow *parent,
@@ -52,13 +63,35 @@ bool wxTopLevelWindow::Create(wxWindow *parent,
long style,
const wxString &name)
{
long styleOrig, exstyleOrig;
if ( ms_drawDecorations == -1 )
ms_drawDecorations = TRUE;
// FIXME_MGL -- this is temporary; we assume for now that native TLW
// can't do decorations, which is not true
if ( ms_drawDecorations )
{
styleOrig = style;
exstyleOrig = GetExtraStyle();
style &= ~(wxCAPTION | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
wxSYSTEM_MENU | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW |
wxTHICK_FRAME);
style = wxSIMPLE_BORDER;
SetExtraStyle(exstyleOrig &
~(wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP));
}
if ( !wxTopLevelWindowNative::Create(parent, id, title, pos,
sizeOrig, style, name) )
return FALSE;
// FIXME_MGL -- this is temporary; we assume for now that native TLW
// can do decorations, which is not true for MGL
if ( ms_drawDecorations )
{
m_windowStyle = styleOrig;
m_exStyle = exstyleOrig;
}
return TRUE;
}
@@ -72,3 +105,135 @@ bool wxTopLevelWindow::ShowFullScreen(bool show, long style)
// native decorations mode
}
long wxTopLevelWindow::GetDecorationsStyle() const
{
long style = 0;
if ( m_windowStyle & wxCAPTION )
{
style |= wxTOPLEVEL_TITLEBAR | wxTOPLEVEL_CLOSE_BUTTON;
if ( m_windowStyle & wxMINIMIZE_BOX )
style |= wxTOPLEVEL_MINIMIZE_BUTTON;
if ( m_windowStyle & wxMAXIMIZE_BOX )
style |= wxTOPLEVEL_MAXIMIZE_BUTTON;
if ( m_exStyle & (wxFRAME_EX_CONTEXTHELP | wxDIALOG_EX_CONTEXTHELP))
style |= wxTOPLEVEL_HELP_BUTTON;
}
if ( (m_windowStyle & (wxSIMPLE_BORDER | wxNO_BORDER)) == 0 )
style |= wxTOPLEVEL_BORDER;
if ( m_windowStyle & (wxRESIZE_BORDER | wxTHICK_FRAME) )
style |= wxTOPLEVEL_RESIZEABLE;
if ( IsMaximized() )
style |= wxTOPLEVEL_MAXIMIZED;
if ( GetIcon().Ok() )
style |= wxTOPLEVEL_ICON;
if ( /*m_isActive*/ 1 /* FIXME_MGL*/ )
style |= wxTOPLEVEL_ACTIVE;
return style;
}
// ----------------------------------------------------------------------------
// client area handling
// ----------------------------------------------------------------------------
wxPoint wxTopLevelWindow::GetClientAreaOrigin() const
{
if ( ms_drawDecorations )
{
int w, h;
wxTopLevelWindowNative::DoGetClientSize(&w, &h);
wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
wxSize(w, h));
rect = m_renderer->GetFrameClientArea(rect,
GetDecorationsStyle());
return rect.GetPosition();
}
else
{
return wxTopLevelWindowNative::GetClientAreaOrigin();
}
}
void wxTopLevelWindow::DoGetClientSize(int *width, int *height) const
{
if ( ms_drawDecorations )
{
int w, h;
wxTopLevelWindowNative::DoGetClientSize(&w, &h);
wxRect rect = wxRect(wxTopLevelWindowNative::GetClientAreaOrigin(),
wxSize(w, h));
rect = m_renderer->GetFrameClientArea(rect,
GetDecorationsStyle());
if ( width )
*width = rect.width;
if ( height )
*height = rect.height;
}
else
wxTopLevelWindowNative::DoGetClientSize(width, height);
}
void wxTopLevelWindow::DoSetClientSize(int width, int height)
{
if ( ms_drawDecorations )
{
wxSize size = m_renderer->GetFrameTotalSize(wxSize(width, height),
GetDecorationsStyle());
wxTopLevelWindowNative::DoSetClientSize(size.x, size.y);
}
else
wxTopLevelWindowNative::DoSetClientSize(width, height);
}
void wxTopLevelWindow::OnNcPaint(wxPaintEvent& event)
{
if ( !ms_drawDecorations || !m_renderer )
event.Skip();
else
{
// get the window rect
wxRect rect;
wxSize size = GetSize();
rect.x =
rect.y = 0;
rect.width = size.x;
rect.height = size.y;
wxWindowDC dc(this);
m_renderer->DrawFrameTitleBar(dc, rect,
GetTitle(), m_titlebarIcon,
GetDecorationsStyle());
}
}
// ----------------------------------------------------------------------------
// icons
// ----------------------------------------------------------------------------
void wxTopLevelWindow::SetIcon(const wxIcon& icon)
{
wxTopLevelWindowNative::SetIcon(icon);
if ( !m_renderer ) return;
wxSize size = m_renderer->GetFrameIconSize();
if ( !icon.Ok() || size.x == -1 )
m_titlebarIcon = icon;
else
{
wxBitmap bmp1;
bmp1.CopyFromIcon(icon);
if ( !bmp1.Ok() )
m_titlebarIcon = wxNullIcon;
else if ( bmp1.GetWidth() == size.x && bmp1.GetHeight() == size.y )
m_titlebarIcon = icon;
else
{
wxImage img = bmp1.ConvertToImage();
img.Rescale(size.x, size.y);
m_titlebarIcon.CopyFromBitmap(wxBitmap(img));
}
}
}