]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/choice.cpp
removed USE_SHARED_LIBRARIES
[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
SC
19
20#if !USE_SHARED_LIBRARY
21IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
22#endif
23
24bool wxChoice::Create(wxWindow *parent, wxWindowID id,
25 const wxPoint& pos,
26 const wxSize& size,
519cb848
SC
27 int n, const wxString choices[],
28 long style,
e9576ca5
SC
29 const wxValidator& validator,
30 const wxString& name)
31{
e9576ca5 32 m_noStrings = n;
e9576ca5 33
519cb848
SC
34 Rect bounds ;
35 Str255 title ;
36
37 MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
38
39 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0,
40 kControlPopupButtonProc , (long) this ) ;
41
42 m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
43 SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
44 for ( int i = 0 ; i < n ; i++ )
45 {
46 appendmenu( m_macPopUpMenuHandle , choices[i] ) ;
47 }
48 SetControlMinimum( m_macControl , 0 ) ;
49 SetControlMaximum( m_macControl , m_noStrings) ;
50 SetControlValue( m_macControl , 1 ) ;
51
52 MacPostControlCreate() ;
53
54 return TRUE;
e9576ca5
SC
55}
56
57void wxChoice::Append(const wxString& item)
58{
519cb848 59 appendmenu( m_macPopUpMenuHandle , item ) ;
e9576ca5 60 m_noStrings ++;
519cb848 61 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
62}
63
64void wxChoice::Delete(int n)
65{
519cb848
SC
66 wxASSERT( n < m_noStrings ) ;
67 ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ;
e9576ca5 68 m_noStrings --;
519cb848 69 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
70}
71
72void wxChoice::Clear()
73{
519cb848
SC
74 for ( int i = 0 ; i < m_noStrings ; i++ )
75 {
76 ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ;
77 }
e9576ca5 78 m_noStrings = 0;
519cb848 79 SetControlMaximum( m_macControl , m_noStrings) ;
e9576ca5
SC
80}
81
82int wxChoice::GetSelection() const
83{
519cb848 84 return GetControlValue( m_macControl ) -1 ;
e9576ca5
SC
85}
86
519cb848
SC
87void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
88{
89 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId );
90 event.SetInt(GetSelection());
91 event.SetEventObject(this);
7c551d95 92 event.SetString(GetStringSelection());
519cb848 93 ProcessCommand(event);
519cb848
SC
94}
95
96
e9576ca5
SC
97void wxChoice::SetSelection(int n)
98{
519cb848 99 SetControlValue( m_macControl , n + 1 ) ;
e9576ca5
SC
100}
101
102int wxChoice::FindString(const wxString& s) const
103{
519cb848
SC
104 for( int i = 0 ; i < m_noStrings ; i++ )
105 {
106 if ( GetString( i ) == s )
107 return i ;
108 }
109 return -1;
e9576ca5
SC
110}
111
112wxString wxChoice::GetString(int n) const
113{
519cb848
SC
114 Str255 text ;
115 ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ;
116 p2cstr( text ) ;
117 return wxString( text );
e9576ca5
SC
118}
119
120void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
121{
519cb848 122 wxControl::SetSize( x,y,width,height,sizeFlags ) ;
e9576ca5
SC
123}
124
125wxString wxChoice::GetStringSelection () const
126{
127 int sel = GetSelection ();
128 if (sel > -1)
129 return wxString(this->GetString (sel));
130 else
131 return wxString("");
132}
133
134bool wxChoice::SetStringSelection (const wxString& s)
135{
136 int sel = FindString (s);
137 if (sel > -1)
138 {
139 SetSelection (sel);
140 return TRUE;
141 }
142 else
143 return FALSE;
144}
145
146void wxChoice::Command(wxCommandEvent & event)
147{
148 SetSelection (event.GetInt());
149 ProcessCommand (event);
150}
151