Permalink
Browse files

Working for wxWidgets 2.8.12 on Windows 7.

Ignore-this: 1ec0b058132651f3a7f9d4321ef38e59

darcs-hash:20120101234845-75908-3ad6e2c8d1bde4da79d9abb2c913684e0adb7fe3.gz
  • Loading branch information...
jodonoghue committed Jan 1, 2012
1 parent 0c86da7 commit ef9abd787c4d9c1b3657413c45012998e9c1a19c
View
@@ -58,3 +58,6 @@
(^|/)\.waf-[[:digit:].]+-[[:digit:]]+($|/)
(^|/)\.lock-wscript$
^\.darcs-temp-mail$
+(^|/)dist$
+(^|/)cabal-dev$
+(^|/)patches$
View
@@ -45,9 +45,11 @@ gui
,("Size", AlignRight, -1)
,("Date", AlignRight, -1)]
,items := [[name,size,date] | (name,size,date) <- entries]
- ,on listEvent := onListEvent
]
+
+ set l [on listEvent := onListEvent l]
+
-- specify layout
set f [layout := container p $ margin 10 $
column 5 [ fill $ widget l
@@ -56,9 +58,10 @@ gui
,clientSize := sz 400 300
]
return ()
- where
- onListEvent eventList
- = case eventList of
- ListItemSelected idx -> logMessage ("item selected: " ++ show idx)
- ListItemDeselected idx -> logMessage ("item de-selected: " ++ show idx)
- other -> logMessage ("list control event.")
+
+onListEvent list eventList
+ = case eventList of
+ ListItemSelected idx -> listCtrlGetItemText list idx >>= logMessage . (++) "item selected: "
+ ListItemDeselected idx -> logMessage ("item de-selected: " ++ show idx)
+ other -> logMessage ("list control event.")
+
View
@@ -0,0 +1,26 @@
+{--------------------------------------------------------------------------------
+ List view demo.
+--------------------------------------------------------------------------------}
+module Main where
+
+import Graphics.UI.WX
+import Graphics.UI.WXCore
+
+entries :: [Int]
+entries = [-1,1,-123,123]
+
+main :: IO ()
+main = start gui
+
+gui :: IO ()
+gui = do
+ f <- frame [text := "List view Sample"]
+ p <- panel f []
+
+ l <- listView p ["n", "n >= 0"] (\n-> [show n, show (n >= 0)])
+ listViewSetItems l entries
+
+ -- specify layout
+ set f [layout := container p . fill . widget . listViewCtrl $ l, clientSize := sz 230 400]
+ return ()
+
@@ -22,7 +22,7 @@ helloWorld
-- create top frame
f <- frameCreate objectNull idAny "Hello world" rectZero frameDefaultStyle
windowSetBackgroundColour f white
- windowSetClientSize f (sz 300 250)
+ windowSetClientSize f (sz 600 250)
-- set status bar with 1 field
frameCreateStatusBar f 1 0
@@ -39,7 +39,8 @@ helloWorld
return ()
where
onAbout f
- = do messageDialog f "About 'Hello World'" "This is a wxHaskell sample" (wxOK + wxICON_INFORMATION)
+ = do version <- versionNumber
+ messageDialog f "About 'Hello World'" ("This is a wxHaskell " ++ show version ++ " sample") (wxOK + wxICON_INFORMATION)
return ()
onQuit f
@@ -1,3 +1,4 @@
+
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable #-}
--------------------------------------------------------------------------------
{-| Module : Controls
@@ -48,7 +49,8 @@ module Graphics.UI.WX.Controls
-- ** Tree control
, TreeCtrl, treeCtrl, treeCtrlEx, treeEvent, treeCtrlRes
-- ** List control
- , ListCtrl, listCtrl, listCtrlEx, listCtrlRes, listEvent, columns
+ , ListCtrl, listCtrl, listCtrlEx, listCtrlRes, listCtrlSetColumnWidths, listEvent, columns
+ , ListView(..), listViewLayout, listViewSetHandler, listViewSelectHandle, listViewSetItems, listViewGetItems, listViewAddItem, listView
-- ** Static text
, StaticText, staticText, staticTextRes
-- ** SplitterWindow
@@ -69,8 +71,10 @@ import Graphics.UI.WX.Classes
import Graphics.UI.WX.Events
import Graphics.UI.WX.Layout
import Graphics.UI.WX.Media (Media(..))
+import Graphics.UI.WX.Variable (variable)
import Graphics.UI.WX.Window
+import Control.Monad (forM_)
import Data.Dynamic -- for "alignment"
@@ -1101,6 +1105,60 @@ listCtrlRes parent name props =
set l props
return l
+-- TODO: figure out how to set a resize handler in addition to the
+-- default one. this will allow us to expand as needed upon resize
+-- events.
+listCtrlSetColumnWidths :: ListCtrl () -> Int -> IO ()
+listCtrlSetColumnWidths ctrl w = do
+-- size <- (realToFrac.sizeW) `fmap` get ctrl clientSize
+ cols <- listCtrlGetColumnCount ctrl
+-- let w = 65 --ceiling $ size / realToFrac cols
+ forM_ [0 .. cols - 1] $ \i -> listCtrlSetColumnWidth ctrl i w
+
+-- | A small wrapper over WX's ListCtrl, allowing us to keep the data
+-- we're representing as well as its string form (shown to the user as
+-- rows).
+data ListView a = ListView {
+ listViewCtrl :: ListCtrl (),
+ listViewItems :: Var [a],
+ listViewToRow :: a -> [String]
+}
+
+listViewLayout :: ListView a -> Layout
+listViewLayout = fill . widget . listViewCtrl
+
+listViewSetHandler :: ListView a -> (EventList -> IO ()) -> IO ()
+listViewSetHandler list handler =
+ set (listViewCtrl list) [on listEvent := handler]
+
+listViewSelectHandle :: ListView a -> (Maybe a -> IO ()) -> EventList -> IO ()
+listViewSelectHandle _ _ (ListItemActivated (-1)) = propagateEvent
+listViewSelectHandle list end (ListItemActivated n ) = end . Just =<< (!! n) `fmap` listViewGetItems list
+listViewSelectHandle _ _ _ = propagateEvent
+
+listViewSetItems :: ListView a -> [a] -> IO ()
+listViewSetItems list its = do
+ set (listViewItems list) [value := its]
+ set (listViewCtrl list) [items := map (listViewToRow list) its]
+
+listViewGetItems :: ListView a -> IO [a]
+listViewGetItems list = get (listViewItems list) value
+
+listViewAddItem :: ListView a -> a -> IO ()
+listViewAddItem list it = do
+ its <- (it:) `fmap` get (listViewItems list) value
+ listViewSetItems list its
+
+listViewSetColumnWidths :: ListView a -> Int -> IO ()
+listViewSetColumnWidths list w = do
+ listCtrlSetColumnWidths (listViewCtrl list) w
+
+listView :: Window b -> [String] -> (a -> [String]) -> IO (ListView a)
+listView parent cols toRow = do
+ ctrl <- listCtrl parent [columns := map (\n -> (n, AlignLeft, -1)) cols]
+ var <- variable [value := []]
+ return $ ListView ctrl var toRow
+
{--------------------------------------------------------------------------------
SplitterWindow
--------------------------------------------------------------------------------}
@@ -1225,4 +1283,4 @@ styledTextCtrlEx parent style props
initialContainer $ \id rect -> \props flags ->
do s <- styledTextCtrlCreate parent id "" rect style
set s props
- return s
+ return s
View
@@ -1,5 +1,5 @@
Name: wx
-Version: 0.13.1
+Version: 0.13.2
License: OtherLicense
License-file: license.txt
Homepage: http://haskell.org/haskellwiki/WxHaskell
View
@@ -7,6 +7,7 @@ import Distribution.Simple.Setup (ConfigFlags)
import System.Cmd (system)
import System.FilePath.Posix ((</>), (<.>))
import System.Directory (createDirectoryIfMissing)
+import System.Info (os)
import System.Process (readProcess)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@@ -48,13 +49,14 @@ myConfHook (pkg0, pbi) flags = do
system $ "wxdirect -d --wxc " ++ sourceDirectory ++ " -o " ++ wxcoreDirectory ++ " " ++ intercalate " " eiffelFiles
ver <- fmap (head . drop 1 . splitBy (== '.')) (readProcess "wx-config" ["--version"] "")
- let extra_wx_libs = if ver == "9"
- then [ "-lwxmsw29ud_xrc", "-lwxmsw29ud_stc", "-lwxmsw29ud_aui", "-lwxmsw29ud_media"
- , "-lwxmsw29ud_ribbon", "-lwxmsw29ud_propgrid", "-lwxmsw29ud_richtext"
- , "-lwxmsw29ud_gl" , "-lstdc++"]
- else [ "-lwxmsw28ud_media", "-lwxmsw28ud_richtext", "-lwxmsw28ud_aui"
+ let extra_wx_libs = if os == "mingw32"
+ then [ "-lwxmsw28ud_media", "-lwxmsw28ud_richtext", "-lwxmsw28ud_aui"
, "-lwxmsw28ud_xrc", "-lstdc++" ]
- wx <- fmap parseWxConfig (readProcess "wx-config" ["--libs", "--cppflags"] "")
+ else [ "-lstdc++" ]
+ wx_cfg_parms = if os == "mingw32"
+ then [ "--libs", "gl,stc", "--cppflags" ]
+ else [ "--libs", "all", "--cppflags" ]
+ wx <- fmap parseWxConfig (readProcess "wx-config" wx_cfg_parms "")
lbi <- confHook simpleUserHooks (pkg0, pbi) flags
let lpd = localPkgDescr lbi
@@ -8,17 +8,17 @@ extern "C" {
-----------------------------------------------------------------------------*/
EWXWEXPORT(wxDragImage*,wxDragImage_Create)(wxBitmap* image,int x,int y)
{
- return new wxDragImage(*image, wxNullCursor, wxPoint(x, y));
+ return new wxDragImage(*image, wxNullCursor);
}
EWXWEXPORT(wxDragImage*,wxDragIcon)(wxIcon* icon,int x,int y)
{
- return new wxDragImage(*icon, wxNullCursor, wxPoint(x, y));
+ return new wxDragImage(*icon, wxNullCursor);
}
EWXWEXPORT(wxDragImage*,wxDragString)(wxString* text,int x,int y)
{
- return new wxDragImage(*text, wxNullCursor, wxPoint(x, y));
+ return new wxDragImage(*text, wxNullCursor);
}
EWXWEXPORT(wxDragImage*,wxDragTreeItem)(wxTreeCtrl* treeCtrl,wxTreeItemId* id)
@@ -1530,10 +1530,12 @@ MAKE_EVENT_WRAPPER(EVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
#endif
// from power.h
+#ifdef wxHAS_POWER_EVENTS
MAKE_EVENT_WRAPPER(EVT_POWER_SUSPENDING)
MAKE_EVENT_WRAPPER(EVT_POWER_SUSPENDED)
MAKE_EVENT_WRAPPER(EVT_POWER_SUSPEND_CANCEL)
MAKE_EVENT_WRAPPER(EVT_POWER_RESUME)
+#endif
// from process.h
MAKE_EVENT_WRAPPER(EVT_END_PROCESS)
@@ -15,7 +15,11 @@ EWXWEXPORT(void*,wxPen_CreateFromColour)(wxColour* col,int width,int style)
EWXWEXPORT(void*,wxPen_CreateFromBitmap)(wxBitmap* stipple,int width)
{
+#ifdef __WXGTK__
+ return 0;
+#else
return new wxPen(*stipple, width);
+#endif
}
EWXWEXPORT(void*,wxPen_CreateFromStock)(int id)
@@ -828,7 +828,7 @@ EWXWEXPORT(void,wxPostScriptDC_Delete)(wxPostScriptDC* self)
EWXWEXPORT(void,wxPostScriptDC_SetResolution)(wxPostScriptDC* self,int ppi)
{
-#ifdef wxUSE_POSTSCRIPT
+#if (defined(wxUSE_POSTSCRIPT)) && (wxVERSION_NUMBER < 2900)
self->SetResolution(ppi);
#endif
}
View
@@ -1210,7 +1210,7 @@ EWXWEXPORT(void,wxString_Delete)(wxString* s)
EWXWEXPORT(int,wxString_GetString)(wxString* s,wxChar* buffer)
{
- if (buffer) memcpy (buffer, s->c_str(), s->Length() * sizeof(wxChar));
+ if (buffer) memcpy (buffer, s->wc_str(), s->Length() * sizeof(wxChar));
return s->Length();
}
@@ -223,7 +223,13 @@ EWXWEXPORT(void,wxGraphicsContext_DrawLines)( wxGraphicsContext* self, size_t n,
for (size_t i = 0; i < n; i++)
points[i] = wxPoint2DDouble(x[i], y[i]);
- self->DrawLines(n, points, fillStyle);
+ #if (wxVERSION_NUMBER >= 2900)
+ wxPolygonFillMode pfm_fillStyle = (wxPolygonFillMode) fillStyle;
+ #else
+ int pfm_fillStyle = fillStyle;
+ #endif
+
+ self->DrawLines(n, points, pfm_fillStyle);
free (points);
#endif
@@ -233,7 +239,13 @@ EWXWEXPORT(void,wxGraphicsContext_DrawPath)( wxGraphicsContext* self,
const wxGraphicsPath* path, int fillStyle )
{
#ifdef wxUSE_GRAPHICS_CONTEXT
- self->DrawPath(*path, fillStyle);
+ #if (wxVERSION_NUMBER >= 2900)
+ wxPolygonFillMode pfm_fillStyle = (wxPolygonFillMode) fillStyle;
+ #else
+ int pfm_fillStyle = fillStyle;
+ #endif
+
+ self->DrawPath(*path, pfm_fillStyle);
#endif
}
@@ -274,7 +286,13 @@ EWXWEXPORT(void,wxGraphicsContext_FillPath)( wxGraphicsContext* self,
const wxGraphicsPath* path, int fillStyle )
{
#ifdef wxUSE_GRAPHICS_CONTEXT
- self->FillPath(*path, fillStyle);
+ #if (wxVERSION_NUMBER >= 2900)
+ wxPolygonFillMode pfm_fillStyle = (wxPolygonFillMode) fillStyle;
+ #else
+ int pfm_fillStyle = fillStyle;
+ #endif
+
+ self->FillPath(*path, pfm_fillStyle);
#endif
}
@@ -722,7 +740,13 @@ EWXWEXPORT(void,wxGraphicsPath_CloseSubpath)( wxGraphicsPath* self )
EWXWEXPORT(void,wxGraphicsPath_Contains)( wxGraphicsPath* self, wxDouble x, wxDouble y, int fillStyle )
{
#ifdef wxUSE_GRAPHICS_CONTEXT
- self->Contains(x, y, fillStyle);
+ #if (wxVERSION_NUMBER >= 2900)
+ wxPolygonFillMode pfm_fillStyle = (wxPolygonFillMode) fillStyle;
+ #else
+ int pfm_fillStyle = fillStyle;
+ #endif
+
+ self->Contains(x, y, pfm_fillStyle);
#endif
}
@@ -41,13 +41,15 @@ extern "C" {
// Event Handlers
////////////////////////////////////////////////////////////////////////////////
+#ifdef wxUSE_MEDIACTRL
#pragma message "wxWidgets mediacontrol event wrappers generated"
MAKE_EVENT_WRAPPER(EVT_MEDIA_FINISHED)
MAKE_EVENT_WRAPPER(EVT_MEDIA_STOP)
MAKE_EVENT_WRAPPER(EVT_MEDIA_LOADED)
MAKE_EVENT_WRAPPER(EVT_MEDIA_STATECHANGED)
MAKE_EVENT_WRAPPER(EVT_MEDIA_PLAY)
MAKE_EVENT_WRAPPER(EVT_MEDIA_PAUSE)
+#endif
////////////////////////////////////////////////////////////////////////////////
// Wrappers
@@ -190,6 +190,7 @@ module Graphics.UI.WXCore.Events
-- * TaskBar icon events
, EventTaskBarIcon(..)
+
-- * Current event
, propagateEvent
, skipCurrentEvent
@@ -241,7 +242,7 @@ import Foreign.Marshal.Array
import Foreign.Marshal.Utils
import Data.Char ( chr ) -- used in stc
-import Data.Maybe ( fromMaybe )
+import Data.Maybe ( fromMaybe, fromJust )
import Control.Concurrent.MVar
import System.IO.Unsafe( unsafePerformIO )
@@ -2371,7 +2372,6 @@ evtHandlerGetOnTaskBarIconEvent window id evt
skipCurrentEvent
-
------------------------------------------------------------------------------------------
-- TimerEx is handled specially.
------------------------------------------------------------------------------------------
@@ -1,4 +1,5 @@
{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE FlexibleInstances #-}
-----------------------------------------------------------------------------------------
{-| Module : Layout
Copyright : (c) Daan Leijen & Wijnand van Suijlen 2003
@@ -25,9 +25,3 @@ TInt64 wxMediaCtrl_Tell(TSelf(wxMediaCtrl) self);
TClassDefExtend(wxMediaEvent,wxNotifyEvent);
/* The wxMediaEvent's events */
-int expEVT_MEDIA_LOADED();
-int expEVT_MEDIA_STOP();
-int expEVT_MEDIA_FINISHED();
-int expEVT_MEDIA_STATECHANGED();
-int expEVT_MEDIA_PLAY();
-int expEVT_MEDIA_PAUSE();
Oops, something went wrong.

0 comments on commit ef9abd7

Please sign in to comment.