]> git.saurik.com Git - wxWidgets.git/blame_incremental - 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
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"
18#include "wx/mac/uma.h"
19
20#if !USE_SHARED_LIBRARY
21IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
22#endif
23
24short nextMenuId = 100 ; // wxMenu takes the lower ids
25
26wxChoice::~wxChoice()
27{
28 // DeleteMenu( m_macPopUpMenuId ) ;
29 DisposeMenu( m_macPopUpMenuHandle ) ;
30}
31
32bool wxChoice::Create(wxWindow *parent, wxWindowID id,
33 const wxPoint& pos,
34 const wxSize& size,
35 int n, const wxString choices[],
36 long style,
37 const wxValidator& validator,
38 const wxString& name)
39{
40
41 Rect bounds ;
42 Str255 title ;
43
44 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
45
46 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
47 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 ,
48 kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ;
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 {
54 Str255 label;
55 wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
56 AppendMenu( m_macPopUpMenuHandle , label ) ;
57 m_strings.Add( choices[i] ) ;
58 }
59 SetControlMinimum( m_macControl , 0 ) ;
60 SetControlMaximum( m_macControl , Number()) ;
61 if ( n > 0 )
62 SetControlValue( m_macControl , 1 ) ;
63
64 MacPostControlCreate() ;
65
66 return TRUE;
67}
68
69void wxChoice::Append(const wxString& item)
70{
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()) ;
76}
77
78void wxChoice::Delete(int n)
79{
80 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
81 m_strings.Remove( n ) ;
82 SetControlMaximum( m_macControl , Number()) ;
83}
84
85void wxChoice::Clear()
86{
87 for ( int i = 0 ; i < Number() ; i++ )
88 {
89 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
90 }
91 m_strings.Clear() ;
92 SetControlMaximum( m_macControl , Number()) ;
93}
94
95int wxChoice::GetSelection() const
96{
97 return GetControlValue( m_macControl ) -1 ;
98}
99
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);
105 event.SetString(GetStringSelection());
106 ProcessCommand(event);
107}
108
109
110void wxChoice::SetSelection(int n)
111{
112 SetControlValue( m_macControl , n + 1 ) ;
113}
114
115int wxChoice::FindString(const wxString& s) const
116{
117 for( int i = 0 ; i < Number() ; i++ )
118 {
119 if ( GetString( i ) == s )
120 return i ;
121 }
122 return -1;
123}
124
125wxString wxChoice::GetString(int n) const
126{
127 return m_strings[n] ;
128}
129
130void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
131{
132 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
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