I attach a patch. Please let me know if it is suitable.

Tim

On 28/01/12 00:19, Axel Simon wrote:
Hi Tim,

On 27.01.2012, at 13:42, Tim Docker wrote:

Hi,

I am attempting to use widgetModifyBase to change the background of a
text entry, and then restore it again later. It's not clear to me how
the restore should be done. It looks like the function should be taking
(Maybe Color), and indeed the comment suggests this - see below.

According to the gtk c library documentation, a null pointer for color
should be passed in to undo previous calls.

Am I missing something, or is this an oversight in the implementation?


Yes, this is an oversight. The right thing would be to add widgetRestoreBase, widgetRestoreText, widgetRestoreFg, widgetRestorBg in order not to break the existing API. In case you feel like implementing them (with docs, please) then we'll gladly apply a patch.

Cheers,
Axel

Thanks,

Tim


widgetModifyBase :: WidgetClass self => self
 -> StateType -- ^ @state@ - the state for which to set the base color.
 -> Color     -- ^ @color@ - the color to assign (does not need to be
              -- allocated), or @Nothing@ to undo the effect of
previous calls
              -- to of 'widgetModifyBase'.
 -> IO ()
widgetModifyBase self state color =
  with color $ \colorPtr ->
  {# call gtk_widget_modify_base #}
    (toWidget self)
    ((fromIntegral . fromEnum) state)
    (castPtr colorPtr)


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel


1 patch for repository http://code.haskell.org/gtk2hs:

Mon Jan 30 08:38:06 EST 2012  t...@dockerz.net
  * added widgetRestoreFg, widgetRestoreBg, widgetRestoreText, widgetRestoreBase
  
  These new functions undo the effects of previous calls are to
  widgetModifyFg, widgetModifyBg, widgetModifyText, and
  widgetModifyBase. Whilst it may have been preferable to implement this
  behaviour by having the existing functions take a Maybe type (as this
  would be consitent with both widgetModifyFont and the underlying gtk
  API), new functions were added so as to preserve the current API.
  

New patches:

[added widgetRestoreFg, widgetRestoreBg, widgetRestoreText, widgetRestoreBase
t...@dockerz.net**20120129213806
 Ignore-this: dc8a919c680a57799abbd1f19b40825d
 
 These new functions undo the effects of previous calls are to
 widgetModifyFg, widgetModifyBg, widgetModifyText, and
 widgetModifyBase. Whilst it may have been preferable to implement this
 behaviour by having the existing functions take a Maybe type (as this
 would be consitent with both widgetModifyFont and the underlying gtk
 API), new functions were added so as to preserve the current API.
 
] hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 161
   widgetModifyText,
   widgetModifyBase,
   widgetModifyFont,
+  widgetRestoreFg,
+  widgetRestoreBg,
+  widgetRestoreText,
+  widgetRestoreBase,
   widgetCreatePangoContext,
   widgetGetPangoContext,
   widgetCreateLayout,
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1391
 widgetModifyFg :: WidgetClass self => self
  -> StateType -- ^ @state@ - the state for which to set the foreground color.
  -> Color     -- ^ @color@ - the color to assign (does not need to be
-              -- allocated), or @Nothing@ to undo the effect of previous calls
-              -- to of 'widgetModifyFg'.
+              -- allocated)
  -> IO ()
 widgetModifyFg self state color =
   with color $ \colorPtr ->
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1400
     ((fromIntegral . fromEnum) state)
     (castPtr colorPtr)
 
+-- | Restores the foreground color for a widget in a particular state. This
+-- undoes the effects of previous calls to `widgetModifyFg'.
+--
+widgetRestoreFg :: WidgetClass self => self
+ -> StateType -- ^ @state@ - the state for which to restore the foreground color.
+ -> IO ()
+widgetRestoreFg self state =
+  {# call gtk_widget_modify_fg #}
+    (toWidget self)
+    ((fromIntegral . fromEnum) state)
+    nullPtr
+
 -- %hash c:2c5
 -- | Sets the background color for a widget in a particular state. All other
 -- style values are left untouched. See also 'widgetModifyStyle'.
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1426
 widgetModifyBg :: WidgetClass self => self
  -> StateType -- ^ @state@ - the state for which to set the background color.
  -> Color     -- ^ @color@ - the color to assign (does not need to be
-              -- allocated), or @Nothing@ to undo the effect of previous calls
-              -- to of 'widgetModifyBg'.
+              -- allocated).
  -> IO ()
 widgetModifyBg self state color =
   with color $ \colorPtr ->
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1435
     ((fromIntegral . fromEnum) state)
     (castPtr colorPtr)
 
+-- | Restores the background color for a widget in a particular state. This
+-- undoes the effects of previous calls to `widgetModifyBg'.
+--
+widgetRestoreBg :: WidgetClass self => self
+ -> StateType -- ^ @state@ - the state for which to restore the background color.
+ -> IO ()
+widgetRestoreBg self state =
+  {# call gtk_widget_modify_bg #}
+    (toWidget self)
+    ((fromIntegral . fromEnum) state)
+    nullPtr
+
 -- %hash c:d2ba
 -- | Sets the text color for a widget in a particular state. All other style
 -- values are left untouched. The text color is the foreground color used along
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1456
 widgetModifyText :: WidgetClass self => self
  -> StateType -- ^ @state@ - the state for which to set the text color.
  -> Color     -- ^ @color@ - the color to assign (does not need to be
-              -- allocated), or @Nothing@ to undo the effect of previous calls
-              -- to of 'widgetModifyText'.
+              -- allocated).
  -> IO ()
 widgetModifyText self state color =
   with color $ \colorPtr ->
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1465
     ((fromIntegral . fromEnum) state)
     (castPtr colorPtr)
 
+-- | Restores the text color for a widget in a particular state. This
+-- undoes the effects of previous calls to `widgetModifyText'.
+--
+widgetRestoreText :: WidgetClass self => self
+ -> StateType -- ^ @state@ - the state for which to restore the text color.
+ -> IO ()
+widgetRestoreText self state =
+  {# call gtk_widget_modify_text #}
+    (toWidget self)
+    ((fromIntegral . fromEnum) state)
+    nullPtr
+
 -- %hash c:ac08
 -- | Sets the base color for a widget in a particular state. All other style
 -- values are left untouched. The base color is the background color used along
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1493
 widgetModifyBase :: WidgetClass self => self
  -> StateType -- ^ @state@ - the state for which to set the base color.
  -> Color     -- ^ @color@ - the color to assign (does not need to be
-              -- allocated), or @Nothing@ to undo the effect of previous calls
-              -- to of 'widgetModifyBase'.
+              -- allocated).
  -> IO ()
 widgetModifyBase self state color =
   with color $ \colorPtr ->
hunk ./gtk/Graphics/UI/Gtk/Abstract/Widget.chs 1502
     ((fromIntegral . fromEnum) state)
     (castPtr colorPtr)
 
+-- | Restores the base color for a widget in a particular state. This undoes
+-- the effects of previous calls to widgetModifyBase.
+--
+widgetRestoreBase :: WidgetClass self => self
+ -> StateType -- ^ @state@ - the state for which to restore the base color.
+ -> IO ()
+widgetRestoreBase self state =
+  {# call gtk_widget_modify_base #}
+    (toWidget self)
+    ((fromIntegral . fromEnum) state)
+    nullPtr
+
+
 -- %hash c:38d7
 -- | Sets the font to use for a widget. All other style values are left
 -- untouched. See also 'widgetModifyStyle'.

Context:

[add a boring file
Daniel Wagner <dan...@wagner-home.com>**20120129003327
 Ignore-this: dc0f7fd6a875a6ee32f5097dac468c44
] 
[switch from null-terminated string connection to (string,length) connection in bufferInsertText
Daniel Wagner <dan...@wagner-home.com>**20110610175442
 Ignore-this: 4ed4d2fee993ceb3a959efb1647affd9
] 
[Fix the type generator for GHC 7.4
Duncan Coutts <dun...@community.haskell.org>**20120120065006
 Ignore-this: e28ed526c725b8b57473ce2b8b0ebd6d
 GHC 7.4 is stricter about FFI imports with newtypes, the newtype
 constructor must be visible at the point of import.
] 
[Fix cairo for GHC 7.4
Duncan Coutts <dun...@community.haskell.org>**20120120064243
 Ignore-this: 934841cfaea0d33a579f03e527be631a
 Changes in Num type class
] 
[Fix glib for change in RTS API in GHC 7.4
Duncan Coutts <dun...@community.haskell.org>**20120120064020
 Ignore-this: a27001c378bda1249de4ecd2b94bfeaa
] 
[handle property notificaiton correctly
axel.si...@in.tum.de**20111216130816
 Ignore-this: c3fd3153e90ece000baf94b638fcbe67
] 
[Make Setup more robust when checking for installed gtk2hsC2hs. Bump version numbers of all pacckages to 0.12.2
axel.si...@in.tum.de**20111113220056
 Ignore-this: 9dd93388949b4e433ab175e3ca27b4a0
] 
[Bump version numbers
axel.si...@in.tum.de**20111113212032
 Ignore-this: d621d5510265d852ab2eb824b0d61519
] 
[inline c2hs conversion functions
axel.si...@in.tum.de**20111103074015
 Ignore-this: 74a5fc8a351707890e396a4b7305c548
] 
[Fix bug in pangoShape that always shaped the whole string passed to pangoItemize.
axel.si...@in.tum.de**20111031082433
 Ignore-this: 462a4676bc3a7a1f804ce05878119d5e
] 
[Fix Entry to build with 2.12.
axel.si...@in.tum.de**20111024151012
 Ignore-this: 54932aa12ce1664e6ca2ff20aa53dd29
] 
[Try to fix printer settings to compile with Gtk 2.12.
axel.si...@in.tum.de**20111024141939
 Ignore-this: 6c9a2eac399e4f882893297d7233a944
] 
[Make compile with glib 2.20.
axel.si...@in.tum.de**20111012131316
 Ignore-this: 7e1b3cfd8012d11316b53907bb49fe05
] 
[Haddock fixes.
axel.si...@in.tum.de**20111006063053
 Ignore-this: 217edb2f7815d8be9fb586adb0f82a73
] 
[TAG 0.12.1
Duncan Coutts <dun...@community.haskell.org>**20110912114758
 Ignore-this: 9edd3aeab3701dfaafabaaf7d819e4
] 
Patch bundle hash:
cc35d249452122c6ee837c4094c50f1df0b949fc
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to