4
%% Copyright Ericsson AB 2009. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
-include_lib("wx/include/wx.hrl").
23
-behavoiur(wx_object).
25
-export([start/1, init/1, terminate/2, code_change/3,
26
handle_info/2, handle_call/3, handle_event/2]).
36
wx_object:start_link(?MODULE, Config, []).
38
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
wx:batch(fun() -> do_init(Config) end).
42
Parent = proplists:get_value(parent, Config),
43
Panel = wxPanel:new(Parent, []),
46
MainSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
47
[{label, "wxListCtrl"}]),
49
Notebook = wxNotebook:new(Panel, 1, [{style, ?wxBK_DEFAULT}]),
52
ListCtrl1 = wxListCtrl:new(Notebook, [{style, ?wxLC_LIST}]),
53
[wxListCtrl:insertItem(ListCtrl1, Int, "Item "++integer_to_list(Int)) ||
54
Int <- lists:seq(0,50)],
55
ListCtrl2 = create_list_ctrl(Notebook, [{style, ?wxLC_REPORT bor
57
IL = wxImageList:new(16,16),
58
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_COPY", [{size, {16,16}}])),
59
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_MISSING_IMAGE", [{size, {16,16}}])),
60
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_TICK_MARK", [{size, {16,16}}])),
61
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_CROSS_MARK", [{size, {16,16}}])),
62
wxListCtrl:assignImageList(ListCtrl2, IL, ?wxIMAGE_LIST_SMALL),
67
wxListCtrl:setItemBackgroundColour(ListCtrl2, Item, {240,240,240,255}),
68
wxListCtrl:setItemImage(ListCtrl2, Item, 0);
69
1 -> wxListCtrl:setItemImage(ListCtrl2, Item, 1);
70
2 -> wxListCtrl:setItemImage(ListCtrl2, Item, 2),
71
wxListCtrl:setItemBackgroundColour(ListCtrl2, Item, {240,240,240,255});
72
_ -> wxListCtrl:setItemImage(ListCtrl2, Item, 3)
75
wx:foreach(Fun, lists:seq(0,50)),
77
ListCtrl3 = create_list_ctrl(Notebook, [{style, ?wxLC_REPORT}]),
78
wxListCtrl:setTextColour(ListCtrl3, ?wxBLUE),
79
wxListCtrl:setItemBackgroundColour(ListCtrl3,5,?wxRED),
80
wxListCtrl:setItemBackgroundColour(ListCtrl3,3,?wxGREEN),
81
wxListCtrl:setItemBackgroundColour(ListCtrl3,0,?wxCYAN),
83
wxNotebook:addPage(Notebook, ListCtrl1, "List", []),
84
wxNotebook:addPage(Notebook, ListCtrl2, "Report", []),
85
wxNotebook:addPage(Notebook, ListCtrl3, "Colored multiselect", []),
87
wxListCtrl:connect(ListCtrl1, command_list_item_selected, []),
88
wxListCtrl:connect(ListCtrl2, command_list_item_selected, []),
89
wxListCtrl:connect(ListCtrl3, command_list_item_selected, []),
91
wxSizer:add(MainSizer, Notebook, [{proportion, 1},
94
wxPanel:setSizer(Panel, MainSizer),
95
{Panel, #state{parent=Panel, config=Config,
96
notebook = Notebook}}.
100
%% Callbacks handled as normal gen_server callbacks
101
handle_info(Msg, State) ->
102
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
105
handle_call(Msg, _From, State) ->
106
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
109
%% Async Events are handled in handle_event as in handle_info
110
handle_event(#wx{obj = _ListCtrl,
111
event = #wxList{itemIndex = Item}},
113
demo:format(State#state.config,"Item ~p selected.\n",[Item]),
115
handle_event(Ev = #wx{}, State = #state{}) ->
116
demo:format(State#state.config,"Got Event ~p\n",[Ev]),
119
code_change(_, _, State) ->
120
{stop, ignore, State}.
122
terminate(_Reason, _State) ->
125
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
-define(FIRST_COL, 0).
129
-define(SECOND_COL, 1).
130
-define(THIRD_COL, 2).
132
create_list_ctrl(Win, Options) ->
133
ListCtrl = wxListCtrl:new(Win, Options),
134
wxListCtrl:insertColumn(ListCtrl, ?FIRST_COL, "First Col", []),
135
wxListCtrl:insertColumn(ListCtrl, ?SECOND_COL, "Second Col", []),
136
wxListCtrl:insertColumn(ListCtrl, ?THIRD_COL, "Third Col", []),
139
Name = integer_to_list(Int),
140
wxListCtrl:insertItem(ListCtrl, Int, ""),
141
wxListCtrl:setItem(ListCtrl, Int, ?FIRST_COL, "First "++Name),
142
wxListCtrl:setItem(ListCtrl, Int, ?SECOND_COL, "Second "++Name),
143
wxListCtrl:setItem(ListCtrl, Int, ?THIRD_COL, "Third "++Name)
145
wx:foreach(Fun, lists:seq(0,50)),