]> git.saurik.com Git - wxWidgets.git/blob - src/osx/textctrl_osx.cpp
4021966024a197c35e133e216e09e09b6306056f
[wxWidgets.git] / src / osx / textctrl_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/textctrl_osx.cpp
3 // Purpose: wxTextCtrl
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
6 // Created: 1998-01-01
7 // RCS-ID: $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_TEXTCTRL
15
16 #include "wx/textctrl.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/app.h"
21 #include "wx/utils.h"
22 #include "wx/dc.h"
23 #include "wx/button.h"
24 #include "wx/menu.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
28 #endif
29
30 #ifdef __DARWIN__
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #else
34 #include <stat.h>
35 #endif
36
37 #if wxUSE_STD_IOSTREAM
38 #if wxUSE_IOSTREAMH
39 #include <fstream.h>
40 #else
41 #include <fstream>
42 #endif
43 #endif
44
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
48
49 #include "wx/osx/private.h"
50
51 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
52
53 BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
54 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
55 EVT_CHAR(wxTextCtrl::OnChar)
56 EVT_KEY_DOWN(wxTextCtrl::OnKeyDown)
57 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
58 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
59 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
60 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
61 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
62 EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete)
63 EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll)
64
65 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu)
66
67 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
68 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
69 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
70 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
71 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
72 EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete)
73 EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll)
74 END_EVENT_TABLE()
75
76
77 void wxTextCtrl::Init()
78 {
79 m_dirty = false;
80
81 m_privateContextMenu = NULL;
82 m_triggerUpdateEvents = true ;
83 }
84
85 wxTextCtrl::~wxTextCtrl()
86 {
87 #if wxUSE_MENUS
88 delete m_privateContextMenu;
89 #endif
90 }
91
92 bool wxTextCtrl::Create( wxWindow *parent,
93 wxWindowID id,
94 const wxString& str,
95 const wxPoint& pos,
96 const wxSize& size,
97 long style,
98 const wxValidator& validator,
99 const wxString& name )
100 {
101 m_macIsUserPane = false ;
102 m_editable = true ;
103
104 if ( ! (style & wxNO_BORDER) )
105 style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ;
106
107 if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
108 return false;
109
110 if ( m_windowStyle & wxTE_MULTILINE )
111 {
112 // always turn on this style for multi-line controls
113 m_windowStyle |= wxTE_PROCESS_ENTER;
114 style |= wxTE_PROCESS_ENTER ;
115 }
116
117
118 m_peer = wxWidgetImpl::CreateTextControl( this, GetParent(), GetId(), str, pos, size, style, GetExtraStyle() );
119
120 MacPostControlCreate(pos, size) ;
121
122 #if wxOSX_USE_COCOA
123 // under carbon everything can already be set before the MacPostControlCreate embedding takes place
124 // but under cocoa for single line textfields this only works after everything has been set up
125 GetTextPeer()->SetStringValue(str);
126 #endif
127
128 // only now the embedding is correct and we can do a positioning update
129
130 MacSuperChangedPosition() ;
131
132 if ( m_windowStyle & wxTE_READONLY)
133 SetEditable( false ) ;
134
135 SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ;
136
137 return true;
138 }
139
140 void wxTextCtrl::MacSuperChangedPosition()
141 {
142 wxWindow::MacSuperChangedPosition() ;
143 #if wxOSX_USE_CARBON
144 GetPeer()->SuperChangedPosition() ;
145 #endif
146 }
147
148 void wxTextCtrl::MacVisibilityChanged()
149 {
150 #if wxOSX_USE_CARBON
151 GetPeer()->VisibilityChanged( GetPeer()->IsVisible() );
152 #endif
153 }
154
155 void wxTextCtrl::MacCheckSpelling(bool check)
156 {
157 GetTextPeer()->CheckSpelling(check);
158 }
159
160 void wxTextCtrl::SetMaxLength(unsigned long len)
161 {
162 m_maxLength = len ;
163 }
164
165 bool wxTextCtrl::SetFont( const wxFont& font )
166 {
167 if ( !wxTextCtrlBase::SetFont( font ) )
168 return false ;
169
170 GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle(), false /* dont ignore black */ ) ;
171
172 return true ;
173 }
174
175 bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
176 {
177 if (GetTextPeer())
178 GetTextPeer()->SetStyle( start , end , style ) ;
179
180 return true ;
181 }
182
183 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style)
184 {
185 wxTextCtrlBase::SetDefaultStyle( style ) ;
186 SetStyle( -1 /*current selection*/ , -1 /*current selection*/ , GetDefaultStyle() ) ;
187
188 return true ;
189 }
190
191 bool wxTextCtrl::IsModified() const
192 {
193 return m_dirty;
194 }
195
196 bool wxTextCtrl::AcceptsFocus() const
197 {
198 // we don't want focus if we can't be edited
199 return /*IsEditable() && */ wxControl::AcceptsFocus();
200 }
201
202 wxSize wxTextCtrl::DoGetBestSize() const
203 {
204 if (GetTextPeer())
205 {
206 wxSize size = GetTextPeer()->GetBestSize();
207 if (size.x > 0 && size.y > 0)
208 return size;
209 }
210
211 int wText, hText;
212
213 // these are the numbers from the HIG:
214 // we reduce them by the borders first
215 wText = 100 ;
216
217 switch ( m_windowVariant )
218 {
219 case wxWINDOW_VARIANT_NORMAL :
220 hText = 22 - 6 ;
221 break ;
222
223 case wxWINDOW_VARIANT_SMALL :
224 hText = 19 - 6 ;
225 break ;
226
227 case wxWINDOW_VARIANT_MINI :
228 hText = 15 - 6 ;
229 break ;
230
231 default :
232 hText = 22 - 6;
233 break ;
234 }
235
236 // as the above numbers have some free space around the text
237 // we get 5 lines like this anyway
238 if ( m_windowStyle & wxTE_MULTILINE )
239 hText *= 5 ;
240
241 if ( !HasFlag(wxNO_BORDER) )
242 hText += 6 ;
243
244 return wxSize(wText, hText);
245 }
246
247 bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
248 {
249 return GetTextPeer()->GetStyle(position, style);
250 }
251
252 void wxTextCtrl::MarkDirty()
253 {
254 m_dirty = true;
255 }
256
257 void wxTextCtrl::DiscardEdits()
258 {
259 m_dirty = false;
260 }
261
262 int wxTextCtrl::GetNumberOfLines() const
263 {
264 return GetTextPeer()->GetNumberOfLines() ;
265 }
266
267 long wxTextCtrl::XYToPosition(long x, long y) const
268 {
269 return GetTextPeer()->XYToPosition( x , y ) ;
270 }
271
272 bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
273 {
274 return GetTextPeer()->PositionToXY( pos , x , y ) ;
275 }
276
277 void wxTextCtrl::ShowPosition(long pos)
278 {
279 return GetTextPeer()->ShowPosition(pos) ;
280 }
281
282 int wxTextCtrl::GetLineLength(long lineNo) const
283 {
284 return GetTextPeer()->GetLineLength(lineNo) ;
285 }
286
287 wxString wxTextCtrl::GetLineText(long lineNo) const
288 {
289 return GetTextPeer()->GetLineText(lineNo) ;
290 }
291
292 void wxTextCtrl::Remove(long from, long to)
293 {
294 wxTextEntry::Remove(from, to);
295 if ( m_triggerUpdateEvents )
296 SendTextUpdatedEvent();
297 }
298
299 void wxTextCtrl::WriteText(const wxString& str)
300 {
301 wxTextEntry::WriteText( str ) ;
302 if ( m_triggerUpdateEvents )
303 SendTextUpdatedEvent();
304 }
305
306 void wxTextCtrl::Clear()
307 {
308 wxTextEntry::Clear() ;
309 SendTextUpdatedEvent();
310 }
311
312 void wxTextCtrl::Copy()
313 {
314 if (CanCopy())
315 {
316 wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_COPY, GetId());
317 evt.SetEventObject(this);
318 if (!GetEventHandler()->ProcessEvent(evt))
319 {
320 wxTextEntry::Copy();
321 }
322 }
323 }
324
325 void wxTextCtrl::Cut()
326 {
327 if (CanCut())
328 {
329 wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_CUT, GetId());
330 evt.SetEventObject(this);
331 if (!GetEventHandler()->ProcessEvent(evt))
332 {
333 wxTextEntry::Cut();
334
335 SendTextUpdatedEvent();
336 }
337 }
338 }
339
340 void wxTextCtrl::Paste()
341 {
342 if (CanPaste())
343 {
344 wxClipboardTextEvent evt(wxEVT_COMMAND_TEXT_PASTE, GetId());
345 evt.SetEventObject(this);
346 if (!GetEventHandler()->ProcessEvent(evt))
347 {
348 wxTextEntry::Paste();
349
350 // TODO: eventually we should add setting the default style again
351 SendTextUpdatedEvent();
352 }
353 }
354 }
355
356 void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
357 {
358 // By default, load the first file into the text window.
359 if (event.GetNumberOfFiles() > 0)
360 LoadFile( event.GetFiles()[0] );
361 }
362
363 void wxTextCtrl::OnKeyDown(wxKeyEvent& event)
364 {
365 if ( event.GetModifiers() == wxMOD_CMD )
366 {
367 switch( event.GetKeyCode() )
368 {
369 case 'A':
370 SelectAll();
371 return;
372 case 'C':
373 if ( CanCopy() )
374 Copy() ;
375 return;
376 case 'V':
377 if ( CanPaste() )
378 Paste() ;
379 return;
380 case 'X':
381 if ( CanCut() )
382 Cut() ;
383 return;
384 default:
385 break;
386 }
387 }
388 // no, we didn't process it
389 event.Skip();
390 }
391
392 void wxTextCtrl::OnChar(wxKeyEvent& event)
393 {
394 int key = event.GetKeyCode() ;
395 bool eat_key = false ;
396 long from, to;
397
398 if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) &&
399 !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
400 // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
401 )
402 {
403 // eat it
404 return ;
405 }
406
407 // Check if we have reached the max # of chars (if it is set), but still
408 // allow navigation and deletion
409 GetSelection( &from, &to );
410 if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength &&
411 !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) &&
412 !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) &&
413 from == to )
414 {
415 // eat it, we don't want to add more than allowed # of characters
416
417 // TODO: generate EVT_TEXT_MAXLEN()
418 return;
419 }
420
421 // assume that any key not processed yet is going to modify the control
422 m_dirty = true;
423
424 switch ( key )
425 {
426 case WXK_RETURN:
427 if (m_windowStyle & wxTE_PROCESS_ENTER)
428 {
429 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
430 event.SetEventObject( this );
431 event.SetString( GetValue() );
432 if ( HandleWindowEvent(event) )
433 return;
434 }
435
436 if ( !(m_windowStyle & wxTE_MULTILINE) )
437 {
438 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
439 if ( tlw && tlw->GetDefaultItem() )
440 {
441 wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
442 if ( def && def->IsEnabled() )
443 {
444 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
445 event.SetEventObject(def);
446 def->Command(event);
447
448 return ;
449 }
450 }
451
452 // this will make wxWidgets eat the ENTER key so that
453 // we actually prevent line wrapping in a single line text control
454 eat_key = true;
455 }
456 break;
457
458 case WXK_TAB:
459 if ( !(m_windowStyle & wxTE_PROCESS_TAB))
460 {
461 int flags = 0;
462 if (!event.ShiftDown())
463 flags |= wxNavigationKeyEvent::IsForward ;
464 if (event.ControlDown())
465 flags |= wxNavigationKeyEvent::WinChange ;
466 Navigate(flags);
467
468 return;
469 }
470 else
471 {
472 // This is necessary (don't know why);
473 // otherwise the tab will not be inserted.
474 WriteText(wxT("\t"));
475 eat_key = true;
476 }
477 break;
478
479 default:
480 break;
481 }
482
483 if (!eat_key)
484 {
485 // perform keystroke handling
486 event.Skip(true) ;
487 }
488
489 // osx_cocoa sends its event upon insertText
490 #if wxOSX_USE_CARBON
491 if ( ( key >= 0x20 && key < WXK_START ) ||
492 ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) ||
493 key == WXK_RETURN ||
494 key == WXK_DELETE ||
495 key == WXK_BACK)
496 {
497 wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
498 event1.SetEventObject( this );
499 wxPostEvent( GetEventHandler(), event1 );
500 }
501 #endif
502 }
503
504 void wxTextCtrl::Command(wxCommandEvent & event)
505 {
506 SetValue(event.GetString());
507 ProcessCommand(event);
508 }
509
510 // ----------------------------------------------------------------------------
511 // standard handlers for standard edit menu events
512 // ----------------------------------------------------------------------------
513
514 // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment
515
516 void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
517 {
518 Cut();
519 }
520
521 void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
522 {
523 Copy();
524 }
525
526 void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
527 {
528 Paste();
529 }
530
531 void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
532 {
533 Undo();
534 }
535
536 void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
537 {
538 Redo();
539 }
540
541 void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event))
542 {
543 long from, to;
544
545 GetSelection( &from, &to );
546 if (from != -1 && to != -1)
547 Remove( from, to );
548 }
549
550 void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event))
551 {
552 SetSelection(-1, -1);
553 }
554
555 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
556 {
557 event.Enable( CanCut() );
558 }
559
560 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
561 {
562 event.Enable( CanCopy() );
563 }
564
565 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
566 {
567 event.Enable( CanPaste() );
568 }
569
570 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
571 {
572 event.Enable( CanUndo() );
573 }
574
575 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
576 {
577 event.Enable( CanRedo() );
578 }
579
580 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event)
581 {
582 long from, to;
583
584 GetSelection( &from, &to );
585 event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ;
586 }
587
588 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
589 {
590 event.Enable(GetLastPosition() > 0);
591 }
592
593 void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event)
594 {
595 if ( GetTextPeer()->HasOwnContextMenu() )
596 {
597 event.Skip() ;
598 return ;
599 }
600
601 #if wxUSE_MENUS
602 if (m_privateContextMenu == NULL)
603 {
604 m_privateContextMenu = new wxMenu;
605 m_privateContextMenu->Append(wxID_UNDO, _("&Undo"));
606 m_privateContextMenu->Append(wxID_REDO, _("&Redo"));
607 m_privateContextMenu->AppendSeparator();
608 m_privateContextMenu->Append(wxID_CUT, _("Cu&t"));
609 m_privateContextMenu->Append(wxID_COPY, _("&Copy"));
610 m_privateContextMenu->Append(wxID_PASTE, _("&Paste"));
611 m_privateContextMenu->Append(wxID_CLEAR, _("&Delete"));
612 m_privateContextMenu->AppendSeparator();
613 m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All"));
614 }
615
616 PopupMenu(m_privateContextMenu);
617 #endif
618 }
619
620 bool wxTextCtrl::MacSetupCursor( const wxPoint& pt )
621 {
622 if ( !GetTextPeer()->SetupCursor( pt ) )
623 return wxWindow::MacSetupCursor( pt ) ;
624 else
625 return true ;
626 }
627
628 // ----------------------------------------------------------------------------
629 // implementation base class
630 // ----------------------------------------------------------------------------
631
632 bool wxTextWidgetImpl::GetStyle(long WXUNUSED(position),
633 wxTextAttr& WXUNUSED(style))
634 {
635 return false;
636 }
637
638 void wxTextWidgetImpl::SetStyle(long WXUNUSED(start),
639 long WXUNUSED(end),
640 const wxTextAttr& WXUNUSED(style))
641 {
642 }
643
644 void wxTextWidgetImpl::Copy()
645 {
646 }
647
648 void wxTextWidgetImpl::Cut()
649 {
650 }
651
652 void wxTextWidgetImpl::Paste()
653 {
654 }
655
656 bool wxTextWidgetImpl::CanPaste() const
657 {
658 return false ;
659 }
660
661 void wxTextWidgetImpl::SetEditable(bool WXUNUSED(editable))
662 {
663 }
664
665 long wxTextWidgetImpl::GetLastPosition() const
666 {
667 return GetStringValue().length() ;
668 }
669
670 void wxTextWidgetImpl::Replace( long from , long to , const wxString &val )
671 {
672 SetSelection( from , to ) ;
673 WriteText( val ) ;
674 }
675
676 void wxTextWidgetImpl::Remove( long from , long to )
677 {
678 SetSelection( from , to ) ;
679 WriteText( wxEmptyString) ;
680 }
681
682 void wxTextWidgetImpl::Clear()
683 {
684 SetStringValue( wxEmptyString ) ;
685 }
686
687 bool wxTextWidgetImpl::CanUndo() const
688 {
689 return false ;
690 }
691
692 void wxTextWidgetImpl::Undo()
693 {
694 }
695
696 bool wxTextWidgetImpl::CanRedo() const
697 {
698 return false ;
699 }
700
701 void wxTextWidgetImpl::Redo()
702 {
703 }
704
705 long wxTextWidgetImpl::XYToPosition(long WXUNUSED(x), long WXUNUSED(y)) const
706 {
707 return 0 ;
708 }
709
710 bool wxTextWidgetImpl::PositionToXY(long WXUNUSED(pos),
711 long *WXUNUSED(x),
712 long *WXUNUSED(y)) const
713 {
714 return false ;
715 }
716
717 void wxTextWidgetImpl::ShowPosition( long WXUNUSED(pos) )
718 {
719 }
720
721 int wxTextWidgetImpl::GetNumberOfLines() const
722 {
723 wxString content = GetStringValue() ;
724 ItemCount lines = 1;
725
726 for (size_t i = 0; i < content.length() ; i++)
727 {
728 #if wxOSX_USE_COCOA
729 if (content[i] == '\n')
730 #else
731 if (content[i] == '\r')
732 #endif
733 lines++;
734 }
735
736 return lines ;
737 }
738
739 wxString wxTextWidgetImpl::GetLineText(long lineNo) const
740 {
741 // TODO: change this if possible to reflect real lines
742 wxString content = GetStringValue() ;
743
744 // Find line first
745 int count = 0;
746 for (size_t i = 0; i < content.length() ; i++)
747 {
748 if (count == lineNo)
749 {
750 // Add chars in line then
751 wxString tmp;
752
753 for (size_t j = i; j < content.length(); j++)
754 {
755 if (content[j] == '\n')
756 return tmp;
757
758 tmp += content[j];
759 }
760
761 return tmp;
762 }
763
764 if (content[i] == '\n')
765 count++;
766 }
767
768 return wxEmptyString ;
769 }
770
771 int wxTextWidgetImpl::GetLineLength(long lineNo) const
772 {
773 // TODO: change this if possible to reflect real lines
774 wxString content = GetStringValue() ;
775
776 // Find line first
777 int count = 0;
778 for (size_t i = 0; i < content.length() ; i++)
779 {
780 if (count == lineNo)
781 {
782 // Count chars in line then
783 count = 0;
784 for (size_t j = i; j < content.length(); j++)
785 {
786 count++;
787 if (content[j] == '\n')
788 return count;
789 }
790
791 return count;
792 }
793
794 if (content[i] == '\n')
795 count++;
796 }
797
798 return 0 ;
799 }
800
801 #endif // wxUSE_TEXTCTRL