Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal support for wxSimplebook #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions wx/src/Graphics/UI/WX/Controls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Graphics.UI.WX.Controls
, Panel, panel, panelEx
, Notebook, notebook
, focusOn
, Simplebook, simplebook
-- * Controls
-- ** Button
, Button, button, buttonEx, smallButton, buttonRes
Expand Down Expand Up @@ -163,6 +164,21 @@ notebook parent props
set nb props_
return nb


-- | Create a 'Simplebook'. Layout is managed with the 'tabs' combinator.
--
-- * Instances: 'Dimensions', 'Colored', 'Visible', 'Child',
-- 'Able', 'Tipped', 'Identity', 'Styled',
-- 'Textual', 'Literate', 'Reactive', 'Paint'
simplebook :: Window a -> [Prop (Simplebook ())] -> IO (Simplebook ())
simplebook parent props
= feed2 props defaultStyle $
initialContainer $ \id rect' -> \props_ flags ->
do sb <- simplebookCreate parent id rect' flags
set sb props_
return sb


{--------------------------------------------------------------------------------
Button
--------------------------------------------------------------------------------}
Expand Down
21 changes: 21 additions & 0 deletions wxc/src/cpp/eljsimplebook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "wrapper.h"

extern "C"
{

EWXWEXPORT(void*, wxSimplebook_Create)(wxWindow* _prt,int _id,int _lft,int _top,int _wdt,int _hgt,int _stl)
{
return (void*) new wxSimplebook (_prt, _id, wxPoint(_lft, _top), wxSize(_wdt, _hgt), _stl);
}

EWXWEXPORT(int,wxSimplebook_SetSelection)(wxSimplebook* self,int nPage)
{
return self->SetSelection(nPage);
}

EWXWEXPORT(bool,wxSimplebook_AddPage)(wxSimplebook* self,wxWindow* pPage,wxString* strText,bool bSelect)
{
return self->AddPage( pPage,* strText, bSelect, wxBookCtrlBase::NO_IMAGE);
}

}
1 change: 1 addition & 0 deletions wxc/src/include/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef int intptr_t;
#include "wx/tabctrl.h"
#endif
#include "wx/notebook.h"
#include "wx/simplebook.h"
#include "wx/spinctrl.h"
#include "wx/statline.h"
#include "wx/checklst.h"
Expand Down
6 changes: 6 additions & 0 deletions wxc/src/include/wxc_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -4819,6 +4819,12 @@ void wxShowEvent_CopyObject( TSelf(wxShowEvent) _obj, TClass(wxObject) obj
TBool wxShowEvent_IsShown( TSelf(wxShowEvent) _obj );
void wxShowEvent_SetShow( TSelf(wxShowEvent) _obj, TBool show );

/* wxSimplebook */
TClassDefExtend(wxSimplebook,wxControl)
TBool wxSimplebook_AddPage( TSelf(wxSimplebook) _obj, TClass(wxWindow) pPage, TClass(wxString) strText, TBool bSelect );
TClass(wxSimplebook) wxSimplebook_Create( TClass(wxWindow) _prt, int _id, TRect(_lft,_top,_wdt,_hgt), int _stl );
int wxSimplebook_SetSelection( TSelf(wxSimplebook) _obj, int nPage );

/* wxSimpleHelpProvider */
TClassDefExtend(wxSimpleHelpProvider,wxHelpProvider)
TClass(wxSimpleHelpProvider) wxSimpleHelpProvider_Create( );
Expand Down
2 changes: 2 additions & 0 deletions wxc/wxc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ extra-source-files:
src/cpp/eljscrollbar.cpp
src/cpp/eljscrolledwindow.cpp
src/cpp/eljsingleinst.cpp
src/cpp/eljsimplebook.cpp
src/cpp/eljsizer.cpp
src/cpp/eljslider.cpp
src/cpp/eljspinctrl.cpp
Expand Down Expand Up @@ -258,6 +259,7 @@ library
src/cpp/eljsplash.cpp
src/cpp/eljscrollbar.cpp
src/cpp/eljscrolledwindow.cpp
src/cpp/eljsimplebook.cpp
src/cpp/eljsingleinst.cpp
src/cpp/eljsizer.cpp
src/cpp/eljslider.cpp
Expand Down
49 changes: 45 additions & 4 deletions wxcore/src/haskell/Graphics/UI/WXCore/Layout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ according to a relative weight, but unfortunately, that entails implementing a b
-----------------------------------------------------------------------------------------
module Graphics.UI.WXCore.Layout( -- * Types
Layout, sizerFromLayout
, TabPage
, TabPage, SimplePage
-- * Window
, windowSetLayout, layoutFromWindow
, windowReFit, windowReFitMinimal
Expand All @@ -134,7 +134,7 @@ module Graphics.UI.WXCore.Layout( -- * Types
, Widget, widget, label, rule, hrule, vrule, sizer
-- ** Containers
, row, column
, grid, boxed, container, tab, imageTab, tabs
, grid, boxed, container, tab, imageTab, tabs, page, pages
, hsplit, vsplit
-- ** Glue
, glue, hglue, vglue
Expand Down Expand Up @@ -699,6 +699,27 @@ tabs notebook pages'
hashstretch = all stretchH [options layout | (_,_,layout) <- pages']
hasfill = if (hasvstretch || hashstretch) then Fill else FillNone

-- | A page in a simplebook: a title and a layout.
type SimplePage = (String,Layout)

-- | Create a simple page with a certain title and layout.
page :: String -> Layout -> SimplePage
page title layout
= (title,layout)

-- | Create a simplebook layout.
-- The pages /always/ need to be embedded inside a 'container' (normally a 'Panel').
-- Just like a 'grid', the horizontal or vertical stretch of the child layout determines
-- the stretch and expansion mode of the notebook.
pages :: Simplebook a -> [SimplePage] -> Layout
pages simplebook pages'
= Simplebook optionsDefault{ stretchV = hasvstretch, stretchH = hashstretch, fillMode = hasfill }
(downcastSimplebook simplebook) pages'
where
hasvstretch = all stretchV [options layout | (_,layout) <- pages']
hashstretch = all stretchH [options layout | (_,layout) <- pages']
hasfill = if (hasvstretch || hashstretch) then Fill else FillNone

-- | Add a horizontal sash bar between two windows. The two integer
-- arguments specify the width of the sash bar (5) and the initial
-- height of the top pane respectively.
Expand Down Expand Up @@ -738,7 +759,8 @@ data Layout = Grid { options :: LayoutOptions, gap :: Size, rows :: [[Layo
| Line { options :: LayoutOptions, linesize :: Size }
| XSizer { options :: LayoutOptions, xsizer :: Sizer () }
| WidgetContainer{ options :: LayoutOptions, win :: Window (), content :: Layout }
| XNotebook { options :: LayoutOptions, nbook :: Notebook (), pages :: [(String,Bitmap (),Layout)] }
| XNotebook { options :: LayoutOptions, nbook :: Notebook (), npages :: [(String,Bitmap (),Layout)] }
| Simplebook { options :: LayoutOptions, sbook :: Simplebook (), spages :: [(String,Layout)] }
| Splitter { options :: LayoutOptions, splitter :: SplitterWindow ()
, pane1 :: Layout, pane2 :: Layout
, splitHorizontal :: Bool, sashWidth :: Int, paneWidth :: Int }
Expand Down Expand Up @@ -792,7 +814,10 @@ nullLayouts =
, content = nullLayout
}
, XNotebook { options = nullLayoutOptions, nbook = objectNull
, pages = [("", objectNull, nullLayout)]
, npages = [("", objectNull, nullLayout)]
}
, Simplebook { options = nullLayoutOptions, sbook = objectNull
, spages = [("", nullLayout)]
}
, Splitter { options = nullLayoutOptions, splitter = objectNull
, pane1 = nullLayout, pane2 = nullLayout
Expand Down Expand Up @@ -988,6 +1013,22 @@ sizerFromLayout parent layout
return il


insert container' (Simplebook options' sbook' pages')
= do mapM_ addPage pages'
sizerAddWindowWithOptions container' sbook' options'
return container'
where
addPage (title,WidgetContainer _options win' layout')
= do pagetitle <- if (null title)
then windowGetLabel win'
else return title
_ <- simplebookAddPage sbook' win' pagetitle False
windowSetLayout win' layout' -- recursively set layout'

addPage (_title, _other)
= error "Graphics.UI.WXCore.sizerFromLayout: simplebook page needs to be a 'container' layout!"


stretchRow g (i,stretch')
= when stretch' (flexGridSizerAddGrowableRow g i)

Expand Down