]> git.saurik.com Git - wxWidgets.git/blame - src/generic/statusbr.cpp
adding special case for Carbon DataBrowser Checkbox
[wxWidgets.git] / src / generic / statusbr.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
a71d815b 2// Name: src/generic/statusbr.cpp
ed791986 3// Purpose: wxStatusBarGeneric class implementation
c801d85f 4// Author: Julian Smart
c94bdf2a 5// Modified by: Francesco Montorsi
c801d85f
KB
6// Created: 01/02/97
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
c801d85f
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
76b49cf4 16 #pragma hdrstop
c801d85f
KB
17#endif
18
1e6feb95 19#if wxUSE_STATUSBAR
ed791986 20
3304646d
WS
21#include "wx/statusbr.h"
22
c801d85f 23#ifndef WX_PRECOMP
76b49cf4
WS
24 #include "wx/settings.h"
25 #include "wx/dcclient.h"
a0125cfc 26 #include "wx/toplevel.h"
c34d2f35 27 #include "wx/control.h"
c801d85f
KB
28#endif
29
2b5f62a0 30#ifdef __WXGTK20__
53b6d7a2 31 #include <gtk/gtk.h>
c94bdf2a 32 #include "wx/gtk/private.h"
2b5f62a0
VZ
33#endif
34
84f68c21
VZ
35// we only have to do it here when we use wxStatusBarGeneric in addition to the
36// standard wxStatusBar class, if wxStatusBarGeneric is the same as
37// wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in
38// common/statbar.cpp
39#if defined(__WXMAC__) || \
40 (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR)
b64a8473 41 #include "wx/generic/statusbr.h"
c801d85f 42
b64a8473
VZ
43 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow)
44#endif // wxUSE_NATIVE_STATUSBAR
ed791986 45
7b6fefbe
FM
46// Default status border dimensions
47#define wxTHICK_LINE_BORDER 2
48
78612fa6
FM
49// Margin between the field text and the field rect
50#define wxFIELD_TEXT_MARGIN 2
51
c94bdf2a
FM
52// ----------------------------------------------------------------------------
53// GTK+ signal handler
54// ----------------------------------------------------------------------------
55
2d0a9aa4
FM
56#if defined( __WXGTK20__ )
57#if GTK_CHECK_VERSION(2,12,0)
c94bdf2a
FM
58extern "C" {
59static
c4c178c1 60gboolean statusbar_query_tooltip(GtkWidget* WXUNUSED(widget),
c94bdf2a
FM
61 gint x,
62 gint y,
c4c178c1 63 gboolean WXUNUSED(keyboard_mode),
c94bdf2a
FM
64 GtkTooltip *tooltip,
65 wxStatusBar* statbar)
66{
67 int n = statbar->GetFieldFromPoint(wxPoint(x,y));
68 if (n == wxNOT_FOUND)
69 return FALSE;
70
71 // should we show the tooltip for the n-th pane of the statusbar?
72 if (!statbar->GetField(n).IsEllipsized())
73 return FALSE; // no, it's not useful
74
c4c178c1
FM
75 const wxString& str = statbar->GetStatusText(n);
76 if (str.empty())
77 return FALSE;
78
79 gtk_tooltip_set_text(tooltip, wxGTK_CONV_SYS(str));
c94bdf2a
FM
80 return TRUE;
81}
82}
83#endif
2d0a9aa4 84#endif
7b6fefbe
FM
85
86// ----------------------------------------------------------------------------
87// wxStatusBarGeneric
88// ----------------------------------------------------------------------------
89
ed791986
VZ
90BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
91 EVT_PAINT(wxStatusBarGeneric::OnPaint)
ba4589db 92 EVT_SIZE(wxStatusBarGeneric::OnSize)
2b5f62a0
VZ
93 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown)
94 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown)
ed791986 95 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged)
c801d85f 96END_EVENT_TABLE()
c801d85f 97
390015c0 98void wxStatusBarGeneric::Init()
c801d85f 99{
48f7ffbe
WS
100 m_borderX = wxTHICK_LINE_BORDER;
101 m_borderY = wxTHICK_LINE_BORDER;
c801d85f
KB
102}
103
ed791986 104wxStatusBarGeneric::~wxStatusBarGeneric()
c801d85f 105{
c801d85f
KB
106}
107
ed791986 108bool wxStatusBarGeneric::Create(wxWindow *parent,
76880b87
RL
109 wxWindowID id,
110 long style,
111 const wxString& name)
c801d85f 112{
53b6d7a2 113 style |= wxTAB_TRAVERSAL | wxFULL_REPAINT_ON_RESIZE;
48f7ffbe
WS
114 if ( !wxWindow::Create(parent, id,
115 wxDefaultPosition, wxDefaultSize,
53b6d7a2 116 style, name) )
48f7ffbe 117 return false;
c801d85f 118
48f7ffbe
WS
119 // The status bar should have a themed background
120 SetThemeEnabled( true );
121
122 InitColours();
f90566f5 123
1ca21594 124#ifdef __WXPM__
48f7ffbe 125 SetFont(*wxSMALL_FONT);
1ca21594 126#endif
c801d85f 127
ba4589db 128 int height = (int)((11*GetCharHeight())/10 + 2*GetBorderY());
48f7ffbe 129 SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, height);
71e03035 130
48f7ffbe 131 SetFieldsCount(1);
c94bdf2a 132
2d0a9aa4
FM
133#if defined( __WXGTK20__ )
134#if GTK_CHECK_VERSION(2,12,0)
c4c178c1 135 if (HasFlag(wxSTB_SHOW_TIPS) && !gtk_check_version(2,12,0))
c94bdf2a
FM
136 {
137 g_object_set(m_widget, "has-tooltip", TRUE, NULL);
138 g_signal_connect(m_widget, "query-tooltip",
139 G_CALLBACK(statusbar_query_tooltip), this);
140 }
2d0a9aa4 141#endif
c94bdf2a 142#endif
8aa2cea1 143
48f7ffbe 144 return true;
c801d85f
KB
145}
146
595a9493
RD
147wxSize wxStatusBarGeneric::DoGetBestSize() const
148{
149 int width, height;
150
151 // best width is the width of the parent
ba4589db
FM
152 if (GetParent())
153 GetParent()->GetClientSize(&width, NULL);
154 else
155 width = 80; // a dummy value
595a9493 156
9a6aafe0 157 // best height is as calculated above in Create()
ba4589db 158 height = (int)((11*GetCharHeight())/10 + 2*GetBorderY());
595a9493
RD
159
160 return wxSize(width, height);
ca65c044 161}
595a9493 162
cc56206f 163void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths)
c801d85f 164{
390015c0 165 wxASSERT_MSG( number >= 0, _T("negative number of fields in wxStatusBar?") );
76880b87 166
0cd15959
FM
167 // this will result in a call to SetStatusWidths() and thus an update to our
168 // m_widthsAbs cache
d64b1c76 169 wxStatusBarBase::SetFieldsCount(number, widths);
c801d85f
KB
170}
171
ed791986 172void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
c801d85f 173{
7b6fefbe 174 wxCHECK_RET( (number >= 0) && ((size_t)number < m_panes.GetCount()),
633d67bb 175 _T("invalid status bar field index") );
c801d85f 176
0cd15959 177 wxString oldText = GetStatusText(number);
87ff599d
JS
178 if (oldText != text)
179 {
0cd15959 180 wxStatusBarBase::SetStatusText(text, number);
c801d85f 181
87ff599d
JS
182 wxRect rect;
183 GetFieldRect(number, rect);
e715f4e7 184
e5e0c727
VZ
185 Refresh(true, &rect);
186
187 // it's common to show some text in the status bar before starting a
188 // relatively lengthy operation, ensure that the text is shown to the
189 // user immediately and not after the lengthy operation end
190 Update();
87ff599d 191 }
c801d85f
KB
192}
193
ed791986 194void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[])
c801d85f 195{
7b6fefbe
FM
196 // only set status widths when n == number of statuswindows
197 wxCHECK_RET( (size_t)n == m_panes.GetCount(), _T("status bar field count mismatch") );
633d67bb 198
1f361cdd 199 wxStatusBarBase::SetStatusWidths(n, widths_field);
0cd15959
FM
200
201 // update cache
202 int width;
203 GetClientSize(&width, &m_lastClientHeight);
204 m_widthsAbs = CalculateAbsWidths(width);
c801d85f
KB
205}
206
7422d7c4
VZ
207bool wxStatusBarGeneric::ShowsSizeGrip() const
208{
c4c178c1 209 if ( !HasFlag(wxSTB_SIZEGRIP) )
7422d7c4
VZ
210 return false;
211
212 wxTopLevelWindow * const
213 tlw = wxDynamicCast(wxGetTopLevelParent(GetParent()), wxTopLevelWindow);
214 return tlw && !tlw->IsMaximized() && tlw->HasFlag(wxRESIZE_BORDER);
215}
216
ba4589db 217void wxStatusBarGeneric::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int textHeight)
c801d85f 218{
ba4589db
FM
219 wxString text(GetStatusText(i));
220 if (text.empty())
221 return; // optimization
c801d85f 222
ba4589db
FM
223 int xpos = rect.x + wxFIELD_TEXT_MARGIN,
224 maxWidth = rect.width - 2*wxFIELD_TEXT_MARGIN,
225 ypos = (int) (((rect.height - textHeight) / 2) + rect.y + 0.5);
78612fa6
FM
226
227 if (ShowsSizeGrip())
228 {
229 // don't write text over the size grip:
230 // NOTE: overloading DoGetClientSize() and GetClientAreaOrigin() wouldn't
231 // work because the adjustment needs to be done only when drawing
232 // the field text and not also when drawing the background, the
233 // size grip itself, etc
ba4589db
FM
234 if ((GetLayoutDirection() == wxLayout_RightToLeft && i == 0) ||
235 (GetLayoutDirection() != wxLayout_RightToLeft &&
236 i == (int)m_panes.GetCount()-1))
78612fa6 237 {
ba4589db 238 const wxRect& gripRc = GetSizeGripRect();
78612fa6 239
ba4589db
FM
240 // NOTE: we don't need any special treatment wrt to the layout direction
241 // since DrawText() will automatically adjust the origin of the
242 // text accordingly to the layout in use
78612fa6 243
ba4589db 244 maxWidth -= gripRc.width;
78612fa6
FM
245 }
246 }
247
248 // eventually ellipsize the text so that it fits the field width
c4c178c1
FM
249
250 wxEllipsizeMode ellmode = (wxEllipsizeMode)-1;
251 if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START;
252 else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE;
253 else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END;
254
255 if (ellmode == (wxEllipsizeMode)-1)
256 {
257 // if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if
258 // we don't ellipsize the text but just truncate it
259 if (HasFlag(wxSTB_SHOW_TIPS))
260 SetEllipsizedFlag(i, dc.GetTextExtent(text).GetWidth() > maxWidth);
c801d85f 261
c4c178c1
FM
262 dc.SetClippingRegion(rect);
263 }
264 else
265 {
266 text = wxControl::Ellipsize(text, dc,
267 ellmode,
268 maxWidth,
269 wxELLIPSIZE_EXPAND_TAB);
270 // Ellipsize() will do something only if necessary
271
272 // update the ellipsization status for this pane; this is used later to
273 // decide whether a tooltip should be shown or not for this pane
274 // (if we have wxSTB_SHOW_TIPS)
275 SetEllipsizedFlag(i, text != GetStatusText(i));
276 }
c94bdf2a 277
7c74e7fe 278#if defined( __WXGTK__ ) || defined(__WXMAC__)
48f7ffbe
WS
279 xpos++;
280 ypos++;
92976ab6 281#endif
c801d85f 282
78612fa6 283 // draw the text
48f7ffbe 284 dc.DrawText(text, xpos, ypos);
c4c178c1
FM
285
286 if (ellmode == (wxEllipsizeMode)-1)
287 dc.DestroyClippingRegion();
c801d85f
KB
288}
289
ba4589db 290void wxStatusBarGeneric::DrawField(wxDC& dc, int i, int textHeight)
c801d85f 291{
2b5f62a0
VZ
292 wxRect rect;
293 GetFieldRect(i, rect);
c801d85f 294
ba4589db
FM
295 if (rect.GetWidth() <= 0)
296 return; // happens when the status bar is shrinked in a very small area!
297
b31eaa5c 298 int style = m_panes[i].GetStyle();
c2919ab3
VZ
299 if (style != wxSB_FLAT)
300 {
301 // Draw border
c94bdf2a
FM
302 // For wxSB_NORMAL: paint a grey background, plus 3-d border (one black rectangle)
303 // Inside this, left and top sides (dark grey). Bottom and right (white).
c2919ab3
VZ
304 // Reverse it for wxSB_RAISED
305
306 dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen);
307
9a6aafe0 308#ifndef __WXPM__
c2919ab3
VZ
309
310 // Right and bottom lines
311 dc.DrawLine(rect.x + rect.width, rect.y,
312 rect.x + rect.width, rect.y + rect.height);
313 dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
314 rect.x, rect.y + rect.height);
315
316 dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
317
318 // Left and top lines
319 dc.DrawLine(rect.x, rect.y + rect.height,
320 rect.x, rect.y);
321 dc.DrawLine(rect.x, rect.y,
322 rect.x + rect.width, rect.y);
9a6aafe0 323#else
c2919ab3
VZ
324
325 dc.DrawLine(rect.x + rect.width, rect.height + 2,
326 rect.x, rect.height + 2);
327 dc.DrawLine(rect.x + rect.width, rect.y,
328 rect.x + rect.width, rect.y + rect.height);
329
330 dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
331 dc.DrawLine(rect.x, rect.y,
332 rect.x + rect.width, rect.y);
333 dc.DrawLine(rect.x, rect.y + rect.height,
c94bdf2a 334 rect.x, rect.y);
b34590eb 335#endif
c2919ab3 336 }
c801d85f 337
ba4589db 338 DrawFieldText(dc, rect, i, textHeight);
c801d85f
KB
339}
340
ed791986 341bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
c801d85f 342{
7b6fefbe 343 wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), false,
390015c0 344 _T("invalid status bar field index") );
c801d85f 345
ba4589db
FM
346 if (m_widthsAbs.IsEmpty())
347 return false;
c801d85f 348
390015c0
VZ
349 rect.x = 0;
350 for ( int i = 0; i < n; i++ )
390015c0 351 rect.x += m_widthsAbs[i];
390015c0 352 rect.x += m_borderX;
c801d85f 353
ba4589db 354 rect.y = m_borderY;
390015c0 355 rect.width = m_widthsAbs[n] - 2*m_borderX;
ba4589db 356 rect.height = m_lastClientHeight - 2*m_borderY;
c801d85f 357
ca65c044 358 return true;
c801d85f
KB
359}
360
c94bdf2a
FM
361int wxStatusBarGeneric::GetFieldFromPoint(const wxPoint& pt) const
362{
363 if (m_widthsAbs.IsEmpty())
364 return wxNOT_FOUND;
365
366 // NOTE: we explicitely don't take in count the borders since they are only
367 // useful when rendering the status text, not for hit-test computations
368
369 if (pt.y <= 0 || pt.y >= m_lastClientHeight)
370 return wxNOT_FOUND;
371
372 int x = 0;
373 for ( size_t i = 0; i < m_panes.GetCount(); i++ )
374 {
375 if (pt.x > x && pt.x < x+m_widthsAbs[i])
376 return i;
377
378 x += m_widthsAbs[i];
379 }
380
381 return wxNOT_FOUND;
382}
383
ed791986 384void wxStatusBarGeneric::InitColours()
c801d85f 385{
ba959d4c 386#if defined(__WXPM__)
c34d2f35 387 m_mediumShadowPen = wxPen(wxColour(127, 127, 127));
b0fa2187 388 m_hilightPen = *wxWHITE_PEN;
dd7d1435 389
b0fa2187
PC
390 SetBackgroundColour(*wxLIGHT_GREY);
391 SetForegroundColour(*wxBLACK);
ba959d4c
VZ
392#else // !__WXPM__
393 m_mediumShadowPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
394 m_hilightPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT));
395#endif // __WXPM__/!__WXPM__
c801d85f
KB
396}
397
ed791986
VZ
398void wxStatusBarGeneric::SetMinHeight(int height)
399{
400 // check that this min height is not less than minimal height for the
ba4589db
FM
401 // current font (min height is as calculated above in Create() except for border)
402 int minHeight = (int)((11*GetCharHeight())/10);
ed791986 403
ba4589db 404 if ( height > minHeight )
422d0ff0 405 SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, height + 2*m_borderY);
ed791986
VZ
406}
407
78612fa6
FM
408wxRect wxStatusBarGeneric::GetSizeGripRect() const
409{
410 int width, height;
411 wxWindow::DoGetClientSize(&width, &height);
412
413 if (GetLayoutDirection() == wxLayout_RightToLeft)
414 return wxRect(2, 2, height-2, height-4);
415 else
416 return wxRect(width-height-2, 2, height-2, height-4);
417}
9a6aafe0
FM
418
419// ----------------------------------------------------------------------------
420// wxStatusBarGeneric - event handlers
421// ----------------------------------------------------------------------------
422
423void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
424{
425 wxPaintDC dc(this);
426
427#ifdef __WXGTK20__
428 // Draw grip first
429 if ( ShowsSizeGrip() )
430 {
78612fa6
FM
431 const wxRect& rc = GetSizeGripRect();
432 GdkWindowEdge edge =
433 GetLayoutDirection() == wxLayout_RightToLeft ? GDK_WINDOW_EDGE_SOUTH_WEST :
434 GDK_WINDOW_EDGE_SOUTH_EAST;
435 gtk_paint_resize_grip( m_widget->style,
436 GTKGetDrawingWindow(),
437 (GtkStateType) GTK_WIDGET_STATE (m_widget),
438 NULL,
439 m_widget,
440 "statusbar",
441 edge,
442 rc.x, rc.y, rc.width, rc.height );
9a6aafe0
FM
443 }
444#endif // __WXGTK20__
445
446 if (GetFont().IsOk())
447 dc.SetFont(GetFont());
448
ba4589db
FM
449 // compute char height only once for all panes:
450 int textHeight = dc.GetCharHeight();
9a6aafe0 451
ba4589db 452 dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
9a6aafe0 453 for (size_t i = 0; i < m_panes.GetCount(); i ++)
ba4589db 454 DrawField(dc, i, textHeight);
9a6aafe0
FM
455}
456
9a6aafe0
FM
457void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event)
458{
459 InitColours();
460
461 // Propagate the event to the non-top-level children
462 wxWindow::OnSysColourChanged(event);
463}
464
2b5f62a0 465void wxStatusBarGeneric::OnLeftDown(wxMouseEvent& event)
390015c0 466{
2b5f62a0
VZ
467#ifdef __WXGTK20__
468 int width, height;
469 GetClientSize(&width, &height);
8aa2cea1 470
7422d7c4 471 if ( ShowsSizeGrip() && (event.GetX() > width-height) )
2b5f62a0
VZ
472 {
473 GtkWidget *ancestor = gtk_widget_get_toplevel( m_widget );
474
475 if (!GTK_IS_WINDOW (ancestor))
476 return;
390015c0 477
08f53168 478 GdkWindow *source = GTKGetDrawingWindow();
2b5f62a0
VZ
479
480 int org_x = 0;
481 int org_y = 0;
482 gdk_window_get_origin( source, &org_x, &org_y );
483
fc2d4209
RR
484 if (GetLayoutDirection() == wxLayout_RightToLeft)
485 {
486 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
487 GDK_WINDOW_EDGE_SOUTH_WEST,
488 1,
489 org_x - event.GetX() + GetSize().x ,
490 org_y + event.GetY(),
491 0);
492 }
493 else
494 {
495 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
2b5f62a0
VZ
496 GDK_WINDOW_EDGE_SOUTH_EAST,
497 1,
8aa2cea1
RD
498 org_x + event.GetX(),
499 org_y + event.GetY(),
2b5f62a0 500 0);
fc2d4209 501 }
2b5f62a0
VZ
502 }
503 else
504 {
ca65c044 505 event.Skip( true );
2b5f62a0
VZ
506 }
507#else
ca65c044 508 event.Skip( true );
2b5f62a0
VZ
509#endif
510}
511
512void wxStatusBarGeneric::OnRightDown(wxMouseEvent& event)
513{
514#ifdef __WXGTK20__
515 int width, height;
516 GetClientSize(&width, &height);
8aa2cea1 517
7422d7c4 518 if ( ShowsSizeGrip() && (event.GetX() > width-height) )
2b5f62a0
VZ
519 {
520 GtkWidget *ancestor = gtk_widget_get_toplevel( m_widget );
521
522 if (!GTK_IS_WINDOW (ancestor))
523 return;
524
08f53168 525 GdkWindow *source = GTKGetDrawingWindow();
2b5f62a0
VZ
526
527 int org_x = 0;
528 int org_y = 0;
529 gdk_window_get_origin( source, &org_x, &org_y );
8aa2cea1 530
2b5f62a0
VZ
531 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
532 2,
8aa2cea1
RD
533 org_x + event.GetX(),
534 org_y + event.GetY(),
2b5f62a0
VZ
535 0);
536 }
537 else
538 {
ca65c044 539 event.Skip( true );
2b5f62a0
VZ
540 }
541#else
ca65c044 542 event.Skip( true );
2b5f62a0 543#endif
390015c0
VZ
544}
545
ba4589db
FM
546void wxStatusBarGeneric::OnSize(wxSizeEvent& WXUNUSED(event))
547{
548 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
549 int width;
550#ifdef __WXPM__
551 GetSize(&width, &m_lastClientHeight);
552#else
553 GetClientSize(&width, &m_lastClientHeight);
554#endif
555
556 // recompute the cache of the field widths if the status bar width has changed
557 m_widthsAbs = CalculateAbsWidths(width);
558}
559
1e6feb95 560#endif // wxUSE_STATUSBAR