From f6183703b29e015710b2d3396d744b02ae036663 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 23 Feb 2010 19:28:57 -0800 Subject: [PATCH] ui: add a "system-alert" hook that can raise a system modal dialog without involving any potentially stripped gadget, io, or debugger code --- basis/cocoa/cocoa.factor | 1 + basis/ui/backend/cocoa/cocoa.factor | 10 ++++++++++ basis/ui/backend/windows/windows.factor | 3 +++ basis/ui/backend/x11/x11.factor | 12 ++++++++++++ basis/ui/ui.factor | 2 ++ 5 files changed, 28 insertions(+) diff --git a/basis/cocoa/cocoa.factor b/basis/cocoa/cocoa.factor index 34bac0a505..fb21843c0f 100644 --- a/basis/cocoa/cocoa.factor +++ b/basis/cocoa/cocoa.factor @@ -39,6 +39,7 @@ SYNTAX: IMPORT: scan [ ] import-objc-class ; [ { + "NSAlert" "NSApplication" "NSArray" "NSAutoreleasePool" diff --git a/basis/ui/backend/cocoa/cocoa.factor b/basis/ui/backend/cocoa/cocoa.factor index 8eeca89c2f..6e64c35e49 100644 --- a/basis/ui/backend/cocoa/cocoa.factor +++ b/basis/ui/backend/cocoa/cocoa.factor @@ -213,6 +213,16 @@ M: cocoa-ui-backend offscreen-pixels ( world -- alien w h ) M: cocoa-ui-backend beep ( -- ) NSBeep ; +M: cocoa-ui-backend system-alert + NSAlert -> alloc -> init -> autorelease [ + { + [ swap -> setInformativeText: ] + [ swap -> setMessageText: ] + [ "OK" -> addButtonWithTitle: drop ] + [ -> runModal drop ] + } cleave + ] [ 2drop ] if* ; + CLASS: { { +superclass+ "NSObject" } { +name+ "FactorApplicationDelegate" } diff --git a/basis/ui/backend/windows/windows.factor b/basis/ui/backend/windows/windows.factor index 69b09dcba0..5863d3f39d 100644 --- a/basis/ui/backend/windows/windows.factor +++ b/basis/ui/backend/windows/windows.factor @@ -783,6 +783,9 @@ M: windows-ui-backend (with-ui) M: windows-ui-backend beep ( -- ) 0 MessageBeep drop ; +M: windows-ui-backend system-alert + [ f ] 2dip swap MB_OK MessageBox drop ; + : fullscreen-RECT ( hwnd -- RECT ) MONITOR_DEFAULTTONEAREST MonitorFromWindow MONITORINFOEX diff --git a/basis/ui/backend/x11/x11.factor b/basis/ui/backend/x11/x11.factor index 74d911ef90..ee6eb813b0 100644 --- a/basis/ui/backend/x11/x11.factor +++ b/basis/ui/backend/x11/x11.factor @@ -8,6 +8,7 @@ strings ui ui.backend ui.clipboards ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats ui.pixel-formats.private ui.private x11 x11.clipboard x11.constants x11.events x11.glx x11.io x11.windows x11.xim x11.xlib ; +FROM: unix.ffi => system ; IN: ui.backend.x11 SINGLETON: x11-ui-backend @@ -326,6 +327,17 @@ M: x11-ui-backend (with-ui) ( quot -- ) M: x11-ui-backend beep ( -- ) dpy get 100 XBell drop ; + + +M: x11-ui-backend system-alert + "\n\n" glue xmessage ; + : black ( -- xcolor ) 0 0 0 0 0 0 XColor ; inline M:: x11-ui-backend (grab-input) ( handle -- ) diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index e0fa560935..824ffb8351 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -243,6 +243,8 @@ M: object close-window HOOK: beep ui-backend ( -- ) +HOOK: system-alert ui-backend ( caption text -- ) + : parse-main-window-attributes ( class -- attributes ) "{" expect dup all-slots parse-tuple-literal-slots ;