]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/choice.cpp
Fixed bug that was giving the wrong size of wxCustomDataObjects to the receiver.
[wxWidgets.git] / src / mac / carbon / choice.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: choice.cpp
3// Purpose: wxChoice
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 "choice.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/choice.h"
519cb848 18#include "wx/mac/uma.h"
e9576ca5 19
2f1ae414 20#if !USE_SHARED_LIBRARY
e9576ca5 21IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
2f1ae414 22#endif
e9576ca5 23
5b781a67
SC
24short nextMenuId = 100 ; // wxMenu takes the lower ids
25
26wxChoice::~wxChoice()
27{
28 // DeleteMenu( m_macPopUpMenuId ) ;
29 DisposeMenu( m_macPopUpMenuHandle ) ;
30}
31
e9576ca5
SC
32bool wxChoice::Create(wxWindow *parent, wxWindowID id,
33 const wxPoint& pos,
34 const wxSize& size,
519cb848
SC
35 int n, const wxString choices[],
36 long style,
e9576ca5
SC
37 const wxValidator& validator,
38 const wxString& name)
39{
e9576ca5 40
519cb848
SC
41 Rect bounds ;
42 Str255 title ;
43
44 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
2f1ae414 45
5b781a67 46 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
8208e181
SC
47 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 ,
48 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
519cb848
SC
49
50 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
51 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
52 for ( int i = 0 ; i < n ; i++ )
53 {
2f1ae414
SC
54 Str255 label;
55 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
56 AppendMenu( m_macPopUpMenuHandle , label ) ;
57 m_strings.Add( choices[i] ) ;
519cb848
SC
58 }
59 SetControlMinimum( m_macControl , 0 ) ;
2f1ae414
SC
60 SetControlMaximum( m_macControl , Number()) ;
61 if ( n > 0 )
62 SetControlValue( m_macControl , 1 ) ;
519cb848
SC
63
64 MacPostControlCreate() ;
65
66 return TRUE;
e9576ca5
SC
67}
68
69void wxChoice::Append(const wxString& item)
70{
2f1ae414
SC
71 Str255 label;
72 wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
73 AppendMenu( m_macPopUpMenuHandle , label ) ;
74 m_strings.Add( item ) ;
75 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
76}
77
78void wxChoice::Delete(int n)
79{
519cb848 80 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
2f1ae414
SC
81 m_strings.Remove( n ) ;
82 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
83}
84
85void wxChoice::Clear()
86{
2f1ae414 87 for ( int i = 0 ; i < Number() ; i++ )
519cb848
SC
88 {
89 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
90 }
2f1ae414
SC
91 m_strings.Clear() ;
92 SetControlMaximum( m_macControl , Number()) ;
e9576ca5
SC
93}
94
95int wxChoice::GetSelection() const
96{
519cb848 97 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
98}
99
519cb848
SC
100void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
101{
102 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
103 event.SetInt(GetSelection());
104 event.SetEventObject(this);
7c551d95 105 event.SetString(GetStringSelection());
519cb848 106 ProcessCommand(event);
519cb848
SC
107}
108
109
e9576ca5
SC
110void wxChoice::SetSelection(int n)
111{
519cb848 112 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
113}
114
115int wxChoice::FindString(const wxString& s) const
116{
2f1ae414 117 for( int i = 0 ; i < Number() ; i++ )
519cb848
SC
118 {
119 if ( GetString( i ) == s )
120 return i ;
121 }
122 return -1;
e9576ca5
SC
123}
124
125wxString wxChoice::GetString(int n) const
126{
2f1ae414 127 return m_strings[n] ;
e9576ca5
SC
128}
129
130void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
131{
519cb848 132 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
e9576ca5
SC
133}
134
135wxString wxChoice::GetStringSelection () const
136{
137 int sel = GetSelection ();
138 if (sel > -1)
139 return wxString(this->GetString (sel));
140 else
141 return wxString("");
142}
143
144bool wxChoice::SetStringSelection (const wxString& s)
145{
146 int sel = FindString (s);
147 if (sel > -1)
148 {
149 SetSelection (sel);
150 return TRUE;
151 }
152 else
153 return FALSE;
154}
155
156void wxChoice::Command(wxCommandEvent & event)
157{
158 SetSelection (event.GetInt());
159 ProcessCommand (event);
160}
161