]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/stattext.mm
update button style to include BS_MULTILINE when a multiline label is set
[wxWidgets.git] / src / cocoa / stattext.mm
CommitLineData
fb896a32 1/////////////////////////////////////////////////////////////////////////////
ccdc11bb 2// Name: src/cocoa/stattext.mm
fb896a32
DE
3// Purpose: wxStaticText
4// Author: David Elliott
5// Modified by:
6// Created: 2003/02/15
ccdc11bb 7// RCS-ID: $Id$
fb896a32 8// Copyright: (c) 2003 David Elliott
ccdc11bb 9// Licence: wxWidgets licence
fb896a32
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673 12#include "wx/wxprec.h"
ccdc11bb
WS
13
14#include "wx/stattext.h"
15
449c5673
DE
16#ifndef WX_PRECOMP
17 #include "wx/app.h"
b9d29922 18 #include "wx/log.h"
449c5673 19#endif //WX_PRECOMP
fb896a32 20
7fc77f30 21#include "wx/cocoa/autorelease.h"
b0c0a393 22#include "wx/cocoa/string.h"
b9d29922 23#include "wx/cocoa/log.h"
7fc77f30 24
fb896a32
DE
25#import <Foundation/NSString.h>
26#import <AppKit/NSTextField.h>
1c54c792 27#include <math.h>
fb896a32
DE
28
29IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
30BEGIN_EVENT_TABLE(wxStaticText, wxControl)
31END_EVENT_TABLE()
32WX_IMPLEMENT_COCOA_OWNER(wxStaticText,NSTextField,NSControl,NSView)
33
34bool wxStaticText::Create(wxWindow *parent, wxWindowID winid,
35 const wxString& label,
36 const wxPoint& pos,
37 const wxSize& size,
38 long style,
39 const wxString& name)
40{
7fc77f30 41 wxAutoNSAutoreleasePool pool;
fb896a32
DE
42 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
43 return false;
44 m_cocoaNSView = NULL;
8d656ea9 45 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
fb896a32 46 [m_cocoaNSView release];
c978d28a 47 [GetNSTextField() setStringValue:wxNSStringWithWxString(wxStripMenuCodes(label, wxStrip_Mnemonics))];
fb896a32
DE
48// [GetNSTextField() setBordered: NO];
49 [GetNSTextField() setBezeled: NO];
50 [GetNSTextField() setEditable: NO];
51 [GetNSTextField() setDrawsBackground: NO];
1c54c792 52
fb896a32 53 [GetNSControl() sizeToFit];
1c54c792
DE
54 // Round-up to next integer size
55 NSRect nsrect = [m_cocoaNSView frame];
56 nsrect.size.width = ceil(nsrect.size.width);
57 [m_cocoaNSView setFrameSize: nsrect.size];
58
fb896a32
DE
59 if(m_parent)
60 m_parent->CocoaAddChild(this);
8d656ea9
DE
61 SetInitialFrameRect(pos,size);
62
fb896a32
DE
63 return true;
64}
65
66wxStaticText::~wxStaticText()
67{
911e17c6 68 DisassociateNSTextField(GetNSTextField());
fb896a32
DE
69}
70
71void wxStaticText::SetLabel(const wxString& label)
72{
c978d28a 73 [GetNSTextField() setStringValue:wxNSStringWithWxString(wxStripMenuCodes(label, wxStrip_Mnemonics))];
b9d29922
DE
74 NSRect oldFrameRect = [GetNSTextField() frame];
75 NSView *superview = [GetNSTextField() superview];
2e11bb42 76 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel Old Position: (%d,%d)"), GetPosition().x, GetPosition().y);
b9d29922
DE
77 [GetNSTextField() sizeToFit];
78 NSRect newFrameRect = [GetNSTextField() frame];
e9247fda
DE
79 // Ensure new size is an integer so GetSize returns valid data
80 newFrameRect.size.height = ceil(newFrameRect.size.height);
81 newFrameRect.size.width = ceil(newFrameRect.size.width);
b9d29922
DE
82 if(![superview isFlipped])
83 {
84 newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height;
b9d29922 85 }
e9247fda
DE
86 [GetNSTextField() setFrame:newFrameRect];
87 // New origin (wx coords) should always match old origin
2e11bb42 88 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel New Position: (%d,%d)"), GetPosition().x, GetPosition().y);
b9d29922
DE
89
90 [[GetNSTextField() superview] setNeedsDisplayInRect:oldFrameRect];
91 [[GetNSTextField() superview] setNeedsDisplayInRect:newFrameRect];
fb896a32
DE
92}
93
d174f457
VZ
94wxString wxStaticText::GetLabel() const
95{
96 wxAutoNSAutoreleasePool pool;
97 return wxStringWithNSString([GetNSTextField() stringValue]);
98}
99
fb896a32
DE
100void wxStaticText::Cocoa_didChangeText(void)
101{
102}