]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/stattext.mm
fixing multiple extensions in one filter, turning off temporarily sheets code
[wxWidgets.git] / src / osx / cocoa / stattext.mm
CommitLineData
f033830e
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/cocoa/stattext.mm
3// Purpose: wxStaticText
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id: stattext.cpp 54845 2008-07-30 14:52:41Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_STATTEXT
15
16#include "wx/stattext.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dc.h"
22 #include "wx/dcclient.h"
23 #include "wx/settings.h"
24#endif // WX_PRECOMP
25
f033830e
SC
26#include "wx/osx/private.h"
27
28#include <stdio.h>
29
f1c40652 30@interface wxNSStaticTextView : NSTextField
c2a4d428
KO
31{
32 wxWidgetCocoaImpl* impl;
33}
c2a4d428 34@end
f1c40652 35
c2a4d428
KO
36@implementation wxNSStaticTextView
37
38+ (void)initialize
39{
40 static BOOL initialized = NO;
41 if (!initialized)
42 {
43 initialized = YES;
44 wxOSXCocoaClassAddWXMethods( self );
45 }
46}
47
c2a4d428
KO
48@end
49
a4e32492
KO
50class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
51{
52public:
f1c40652 53 wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w)
a4e32492 54 {
f1c40652 55 m_lineBreak = lineBreak;
a4e32492
KO
56 }
57
58 virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
59 {
60 wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
61 wxWindow* wxpeer = GetWXPeer();
f1c40652
SC
62 NSCell* cell = [v cell];
63 wxCFStringRef text( title , wxpeer->GetFont().GetEncoding() );
64
65 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
66 [paragraphStyle setLineBreakMode:m_lineBreak];
a4e32492 67 int style = wxpeer->GetWindowStyleFlag();
a4e32492 68 if (style & wxALIGN_CENTER)
f1c40652 69 [paragraphStyle setAlignment: NSCenterTextAlignment];
a4e32492 70 else if (style & wxALIGN_RIGHT)
f1c40652
SC
71 [paragraphStyle setAlignment: NSRightTextAlignment];
72
73 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
74 NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
75 [cell setAttributedStringValue:attrstring];
76 [attrstring release];
77 [paragraphStyle release];
a4e32492 78 }
f1c40652
SC
79private :
80 NSLineBreakMode m_lineBreak;
a4e32492 81};
c2a4d428 82
f033830e
SC
83wxSize wxStaticText::DoGetBestSize() const
84{
f1c40652 85 return wxWindowMac::DoGetBestSize() ;
f033830e
SC
86}
87
6e7a89af
FM
88wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
89 wxWindowMac* parent,
90 wxWindowID id,
f033830e 91 const wxString& label,
6e7a89af 92 const wxPoint& pos,
f033830e 93 const wxSize& size,
6e7a89af
FM
94 long style,
95 long extraStyle)
f033830e 96{
dbeddfb9 97 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
c2a4d428 98 wxNSStaticTextView* v = [[wxNSStaticTextView alloc] initWithFrame:r];
f033830e 99
f033830e
SC
100 [v setEditable:NO];
101 [v setDrawsBackground:NO];
44ca06dd 102 [v setSelectable: NO];
f1c40652
SC
103 [v setBezeled:NO];
104 [v setBordered:NO];
105
106 NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
107 if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
f033830e 108 {
f033830e 109 if ( style & wxST_ELLIPSIZE_MIDDLE )
f1c40652
SC
110 linebreak = NSLineBreakByTruncatingMiddle;
111 else if (style & wxST_ELLIPSIZE_END )
112 linebreak = NSLineBreakByTruncatingTail;
113 else if (style & wxST_ELLIPSIZE_START )
114 linebreak = NSLineBreakByTruncatingHead;
f033830e 115 }
f1c40652
SC
116 else
117 {
118 [[v cell] setWraps:YES];
119 }
120
121 wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
122 return c;
f033830e
SC
123}
124
125#endif //if wxUSE_STATTEXT