]> git.saurik.com Git - wxWidgets.git/blame - src/common/bmpbtncmn.cpp
only set native window level, when not using a wrapped native window, see #14739
[wxWidgets.git] / src / common / bmpbtncmn.cpp
CommitLineData
e1d3601a
PC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/bmpbtncmn.cpp
3// Purpose: wxBitmapButton common code
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#if wxUSE_BMPBUTTON
20
21#include "wx/bmpbuttn.h"
22
23#ifndef WX_PRECOMP
24 #include "wx/log.h"
25 #include "wx/dcmemory.h"
26 #include "wx/image.h"
27#endif
28
be7a086c
VZ
29#include "wx/artprov.h"
30#include "wx/renderer.h"
31
e1d3601a
PC
32// ----------------------------------------------------------------------------
33// XTI
34// ----------------------------------------------------------------------------
35
36wxDEFINE_FLAGS( wxBitmapButtonStyle )
37wxBEGIN_FLAGS( wxBitmapButtonStyle )
38 // new style border flags, we put them first to
39 // use them for streaming out
40 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
41 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
42 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
43 wxFLAGS_MEMBER(wxBORDER_RAISED)
44 wxFLAGS_MEMBER(wxBORDER_STATIC)
45 wxFLAGS_MEMBER(wxBORDER_NONE)
46
47 // old style border flags
48 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
49 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
50 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
51 wxFLAGS_MEMBER(wxRAISED_BORDER)
52 wxFLAGS_MEMBER(wxSTATIC_BORDER)
53 wxFLAGS_MEMBER(wxBORDER)
54
55 // standard window styles
56 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
57 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
58 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
59 wxFLAGS_MEMBER(wxWANTS_CHARS)
60 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
61 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
62 wxFLAGS_MEMBER(wxVSCROLL)
63 wxFLAGS_MEMBER(wxHSCROLL)
64
65 wxFLAGS_MEMBER(wxBU_AUTODRAW)
66 wxFLAGS_MEMBER(wxBU_LEFT)
67 wxFLAGS_MEMBER(wxBU_RIGHT)
68 wxFLAGS_MEMBER(wxBU_TOP)
69 wxFLAGS_MEMBER(wxBU_BOTTOM)
70wxEND_FLAGS( wxBitmapButtonStyle )
71
72wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxBitmapButton, wxButton, "wx/bmpbuttn.h")
73
74wxBEGIN_PROPERTIES_TABLE(wxBitmapButton)
75 wxPROPERTY_FLAGS( WindowStyle, wxBitmapButtonStyle, long, \
76 SetWindowStyleFlag, GetWindowStyleFlag, \
77 wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), \
78 wxT("group")) // style
79wxEND_PROPERTIES_TABLE()
80
81wxEMPTY_HANDLERS_TABLE(wxBitmapButton)
82
83wxCONSTRUCTOR_5( wxBitmapButton, wxWindow*, Parent, wxWindowID, Id, \
84 wxBitmap, Bitmap, wxPoint, Position, wxSize, Size )
85
86/*
87TODO PROPERTIES :
88
89long "style" , wxBU_AUTODRAW
90bool "default" , 0
91bitmap "selected" ,
92bitmap "focus" ,
93bitmap "disabled" ,
94*/
95
be7a086c
VZ
96namespace
97{
98
99#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
100
101wxBitmap
102GetCloseButtonBitmap(wxWindow *win,
103 const wxSize& size,
104 const wxColour& colBg,
105 int flags = 0)
106{
107 wxBitmap bmp(size);
108 wxMemoryDC dc(bmp);
109 dc.SetBackground(colBg);
110 dc.Clear();
111 wxRendererNative::Get().
112 DrawTitleBarBitmap(win, dc, size, wxTITLEBAR_BUTTON_CLOSE, flags);
113 return bmp;
114}
115
116#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
117
118} // anonymous namespace
119
120/* static */
121wxBitmapButton*
122wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid)
123{
124 wxCHECK_MSG( parent, NULL, wxS("Must have a valid parent") );
125
126 const wxColour colBg = parent->GetBackgroundColour();
127
128#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
129 const wxSize sizeBmp = wxArtProvider::GetSizeHint(wxART_BUTTON);
130 wxBitmap bmp = GetCloseButtonBitmap(parent, sizeBmp, colBg);
131#else // !wxHAS_DRAW_TITLE_BAR_BITMAP
132 wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
133#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
134
135 wxBitmapButton* const button = new wxBitmapButton
136 (
137 parent,
138 winid,
139 bmp,
140 wxDefaultPosition,
141 wxDefaultSize,
142 wxBORDER_NONE
143 );
144
145#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
146 button->SetBitmapPressed(
147 GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_PRESSED));
148
149 button->SetBitmapCurrent(
150 GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_CURRENT));
151#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
152
153 // The button should blend with its parent background.
154 button->SetBackgroundColour(colBg);
155
156 return button;
157}
158
e1d3601a 159#endif // wxUSE_BMPBUTTON