]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/button.cpp
warning fix
[wxWidgets.git] / src / mac / button.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
3// Purpose: wxButton
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "button.h"
14#endif
15
16#include "wx/button.h"
17#include "wx/panel.h"
18
19#if !USE_SHARED_LIBRARY
20IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
21#endif
22
23#include <wx/mac/uma.h>
24// Button
25
26
27bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
28 const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator,
31 const wxString& name)
32{
33 Rect bounds ;
34 Str255 title ;
35
36 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
37
38 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 1,
39 kControlPushButtonProc , (long) this ) ;
40 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
41
42 MacPostControlCreate() ;
43
44 return TRUE;
45}
46
47void wxButton::SetDefault()
48{
49 wxWindow *parent = GetParent();
50 wxButton *btnOldDefault = NULL;
51 wxPanel *panel = wxDynamicCast(parent, wxPanel);
52 if ( panel )
53 {
54 btnOldDefault = panel->GetDefaultItem();
55 panel->SetDefaultItem(this);
56 }
57
58#ifdef __UNIX__
59 Boolean inData;
60 if ( btnOldDefault && btnOldDefault->m_macControl )
61 {
62 inData = 0;
63 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
64 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
65 }
66 if ( m_macControl )
67 {
68 inData = 1;
69 UMASetControlData( m_macControl , kControlButtonPart ,
70 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
71 }
72#else
73 if ( btnOldDefault && btnOldDefault->m_macControl )
74 {
75 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
76 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ;
77 }
78 if ( m_macControl )
79 {
80 UMASetControlData( m_macControl , kControlButtonPart ,
81 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ;
82 }
83#endif
84}
85
86wxSize wxButton::DoGetBestSize() const
87{
88 wxSize sz = GetDefaultSize() ;
89
90 int wBtn = m_label.Length() * 8 + 12 ;
91 int hBtn = 20 ;
92
93 if (wBtn > sz.x) sz.x = wBtn;
94 if (hBtn > sz.y) sz.y = hBtn;
95
96 return sz ;
97}
98
99wxSize wxButton::GetDefaultSize()
100{
101 int wBtn = 70 /* + 2 * m_macHorizontalBorder */ ;
102 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
103
104 return wxSize(wBtn, hBtn);
105}
106
107void wxButton::Command (wxCommandEvent & event)
108{
109 if ( m_macControl )
110 {
111 HiliteControl( m_macControl , kControlButtonPart ) ;
112 unsigned long finalTicks ;
113 Delay( 8 , &finalTicks ) ;
114 HiliteControl( m_macControl , 0 ) ;
115 }
116 ProcessCommand (event);
117}
118
119void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
120{
121 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
122 event.SetEventObject(this);
123 ProcessCommand(event);
124}
125