-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.

module Reflex.GI.Gtk.Widget.Ord
  ( OrdWidget(..)
  ) where

import Data.Coerce (coerce)
import Data.Function (on)
import Data.GI.Base ( GObject
                    , ManagedPtr(managedForeignPtr)
                    )
import Foreign.ForeignPtr (ForeignPtr)

newtype OrdWidget w = OrdWidget
  { OrdWidget w -> w
fromOrdWidget :: w
  }
  deriving (OrdWidget w -> OrdWidget w -> Bool
(OrdWidget w -> OrdWidget w -> Bool)
-> (OrdWidget w -> OrdWidget w -> Bool) -> Eq (OrdWidget w)
forall w. Eq w => OrdWidget w -> OrdWidget w -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrdWidget w -> OrdWidget w -> Bool
$c/= :: forall w. Eq w => OrdWidget w -> OrdWidget w -> Bool
== :: OrdWidget w -> OrdWidget w -> Bool
$c== :: forall w. Eq w => OrdWidget w -> OrdWidget w -> Bool
Eq)

foreignPtrFromWidget :: (GObject w) => w -> ForeignPtr ()
foreignPtrFromWidget :: w -> ForeignPtr ()
foreignPtrFromWidget = ManagedPtr () -> ForeignPtr ()
forall a. ManagedPtr a -> ForeignPtr a
managedForeignPtr (ManagedPtr () -> ForeignPtr ())
-> (w -> ManagedPtr ()) -> w -> ForeignPtr ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w -> ManagedPtr ()
forall a b. Coercible a b => a -> b
coerce

foreignPtrFromOrdWidget :: (GObject w) => OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget :: OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget (OrdWidget w :: w
w) = w -> ForeignPtr ()
forall w. GObject w => w -> ForeignPtr ()
foreignPtrFromWidget w
w

instance (GObject w, Eq w) => Ord (OrdWidget w) where
  compare :: OrdWidget w -> OrdWidget w -> Ordering
compare = ForeignPtr () -> ForeignPtr () -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (ForeignPtr () -> ForeignPtr () -> Ordering)
-> (OrdWidget w -> ForeignPtr ())
-> OrdWidget w
-> OrdWidget w
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` OrdWidget w -> ForeignPtr ()
forall w. GObject w => OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget
  < :: OrdWidget w -> OrdWidget w -> Bool
(<) = ForeignPtr () -> ForeignPtr () -> Bool
forall a. Ord a => a -> a -> Bool
(<) (ForeignPtr () -> ForeignPtr () -> Bool)
-> (OrdWidget w -> ForeignPtr ())
-> OrdWidget w
-> OrdWidget w
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` OrdWidget w -> ForeignPtr ()
forall w. GObject w => OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget
  <= :: OrdWidget w -> OrdWidget w -> Bool
(<=) = ForeignPtr () -> ForeignPtr () -> Bool
forall a. Ord a => a -> a -> Bool
(<=) (ForeignPtr () -> ForeignPtr () -> Bool)
-> (OrdWidget w -> ForeignPtr ())
-> OrdWidget w
-> OrdWidget w
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` OrdWidget w -> ForeignPtr ()
forall w. GObject w => OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget
  > :: OrdWidget w -> OrdWidget w -> Bool
(>) = ForeignPtr () -> ForeignPtr () -> Bool
forall a. Ord a => a -> a -> Bool
(>) (ForeignPtr () -> ForeignPtr () -> Bool)
-> (OrdWidget w -> ForeignPtr ())
-> OrdWidget w
-> OrdWidget w
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` OrdWidget w -> ForeignPtr ()
forall w. GObject w => OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget
  >= :: OrdWidget w -> OrdWidget w -> Bool
(>=) = ForeignPtr () -> ForeignPtr () -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (ForeignPtr () -> ForeignPtr () -> Bool)
-> (OrdWidget w -> ForeignPtr ())
-> OrdWidget w
-> OrdWidget w
-> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` OrdWidget w -> ForeignPtr ()
forall w. GObject w => OrdWidget w -> ForeignPtr ()
foreignPtrFromOrdWidget