1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2008-2022. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%%-------------------------------------------------------------------
%%% File : wx_class_SUITE.erl
%%% Author : Dan Gudmundsson <dan.gudmundsson@ericsson.com>
%%% Description :
%%%
%%% Created : 13 Nov 2008 by Dan Gudmundsson <dan.gudmundsson@ericsson.com>
%%%-------------------------------------------------------------------
-module(wx_class_SUITE).
-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
init_per_suite/1, end_per_suite/1,
init_per_testcase/2, end_per_testcase/2]).
-export([calendarCtrl/1, treeCtrl/1, notebook/1, staticBoxSizer/1,
clipboard/1, helpFrame/1, htmlWindow/1, listCtrlSort/1, listCtrlVirtual/1,
radioBox/1, systemSettings/1, taskBarIcon/1, toolbar/1, popup/1, modal/1,
textCtrl/1, locale/1]).
-include("wx_test_lib.hrl").
%% Initialization functions.
init_per_suite(Config) ->
wx_test_lib:init_per_suite(Config).
end_per_suite(Config) ->
wx_test_lib:end_per_suite(Config).
init_per_testcase(Func,Config) ->
wx_test_lib:init_per_testcase(Func,Config).
end_per_testcase(Func,Config) ->
wx_test_lib:end_per_testcase(Func,Config).
%% SUITE specification
suite() -> [{ct_hooks,[ts_install_cth]}, {timetrap,{minutes,2}}].
all() ->
[calendarCtrl, treeCtrl, notebook, staticBoxSizer,
clipboard, helpFrame, htmlWindow, listCtrlSort, listCtrlVirtual,
radioBox, systemSettings, taskBarIcon, toolbar, popup, modal,
textCtrl, locale].
groups() ->
[].
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, Config) ->
Config.
%% The test cases
%% create and test a calendar, especially the DateAttr no-deletition.
calendarCtrl(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
calendarCtrl(Config) ->
Wx = ?mr(wx_ref, wx:new()),
Frame = ?mt(wxFrame, wxFrame:new(Wx, 1, "Calendar", [])),
Panel = wxPanel:new(Frame),
Sz = wxBoxSizer:new(?wxVERTICAL),
{YMD={_,_,Day},_} = DateTime = calendar:now_to_datetime(os:timestamp()),
Cal = ?mt(wxCalendarCtrl, wxCalendarCtrl:new(Panel, ?wxID_ANY,
[{date,DateTime}
])),
wxSizer:add(Sz,Cal),
DateAttr0 = ?mt(wxCalendarDateAttr, wxCalendarCtrl:getAttr(Cal,Day)),
case wx:is_null(DateAttr0) of
true ->
?log("DateAttr is null~n",[]);
false ->
?log("DateAttr is usable~n",[]),
DateAttr = ?mt(wxCalendarDateAttr, wxCalendarDateAttr:new()),
wxCalendarDateAttr:setBackgroundColour(DateAttr, {0,243,0}),
wxCalendarCtrl:setAttr(Cal, Day, DateAttr),
DateAttr1 = ?mt(wxCalendarDateAttr, wxCalendarCtrl:getAttr(Cal,Day)),
io:format("DateAttr ~p~n",[DateAttr1]),
?m({0,243,0,255}, wxCalendarDateAttr:getBackgroundColour(DateAttr1))
end,
?m({YMD, _},wxCalendarCtrl:getDate(Cal)),
wxCalendarCtrl:connect(Cal, calendar_weekday_clicked),
wxCalendarCtrl:connect(Cal, calendar_day_changed),
wxCalendarCtrl:connect(Cal, calendar_month_changed),
wxCalendarCtrl:connect(Cal, calendar_year_changed),
wxCalendarCtrl:connect(Cal, calendar_doubleclicked),
wxCalendarCtrl:connect(Cal, calendar_sel_changed),
wxWindow:setSizer(Panel,Sz),
wxSizer:setSizeHints(Sz,Frame),
wxWindow:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
treeCtrl(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
treeCtrl(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
Panel = wxPanel:new(Frame, []),
Tree = ?mt(wxTreeCtrl,wxTreeCtrl:new(Panel, [{style , ?wxTR_HAS_BUTTONS}])),
Root = wxTreeCtrl:addRoot(Tree, "Root", []),
?m(true, is_integer(Root)),
Item1 = wxTreeCtrl:appendItem(Tree, Root, "Item1", []),
?m(true, is_integer(Item1)),
?m(ok, wxTreeCtrl:setItemData(Tree, Item1, {data, item1})),
Item2 = wxTreeCtrl:appendItem(Tree, Root, "Item2", []),
?m(ok, wxTreeCtrl:setItemData(Tree, Item2, {data, item2})),
Item3 = wxTreeCtrl:appendItem(Tree, Root, "Item3", []),
?m(ok, wxTreeCtrl:setItemData(Tree, Item3, {data, item3})),
Sizer = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sizer, Tree, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxWindow:setSizerAndFit(Panel, Sizer),
wxFrame:show(Frame),
ok = wxTreeCtrl:expand(Tree, Root),
?m([], wxTreeCtrl:getItemData(Tree, Root)),
?m({data,item1}, wxTreeCtrl:getItemData(Tree, Item1)),
?m({data,item2}, wxTreeCtrl:getItemData(Tree, Item2)),
?m({data,item3}, wxTreeCtrl:getItemData(Tree, Item3)),
{true, {X0,Y0,W0,H0}} = ?m({_,_},wxTreeCtrl:getBoundingRect(Tree, Item1, [{textOnly, true}])),
?m({true, {_,Y1,_,_}} when Y1 > Y0, wxTreeCtrl:getBoundingRect(Tree, Item2)),
?m({Item1, _}, wxTreeCtrl:hitTest(Tree, {X0+W0 div 2, Y0+H0 div 2})),
?m(true, wxTreeCtrl:isTreeItemIdOk(Item1)),
?m({0, _}, wxTreeCtrl:hitTest(Tree, {X0+W0+W0, Y0+H0+4*H0})),
?m(false, wxTreeCtrl:isTreeItemIdOk(0)),
wxFrame:connect(Tree, command_tree_item_expanded),
wxFrame:connect(Tree, command_tree_item_collapsed),
wxFrame:connect(Frame, close_window),
wxTreeCtrl:editLabel(Tree, Root),
wx_test_lib:wx_destroy(Frame,Config).
notebook(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
notebook(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
Panel = wxPanel:new(Frame, []),
Book = wxNotebook:new(Panel, ?wxID_ANY, []),
Panel1 = wxPanel:new(Book, []),
List1 = wxListBox:new(Panel1,
?wxID_ANY,
[{choices, ["aaa1", "bb1", "c1"]},
{style,
?wxLB_SORT bor
?wxLB_NEEDED_SB bor
?wxLB_EXTENDED}]),
wxNotebook:addPage(Book, Panel1, "List1", []),
Sizer1 = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sizer1, List1, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxWindow:setSizer(Panel1, Sizer1),
Panel2 = wxPanel:new(Book, []),
List2 = wxListBox:new(Panel2,
?wxID_ANY,
[{choices, ["aaa2", "bb2", "c2"]},
{style,
?wxLB_SORT bor
?wxLB_NEEDED_SB bor
?wxLB_EXTENDED}]),
wxNotebook:addPage(Book, Panel2, "List2", []),
Sizer2 = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sizer2, List2, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxWindow:setSizer(Panel2, Sizer2),
Panel3 = wxPanel:new(Book, []),
List3 = wxListBox:new(Panel3,
?wxID_ANY,
[{choices, ["aaa3", "bb3", "c3"]},
{style,
?wxLB_SORT bor
?wxLB_NEEDED_SB bor
?wxLB_EXTENDED}]),
wxNotebook:addPage(Book, Panel3, "List3", []),
Sizer3 = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sizer3, List3, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxWindow:setSizer(Panel3, Sizer3),
Sizer = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sizer, Book, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxWindow:setSizer(Panel, Sizer),
wxSizer:fit(Sizer, Frame),
wxSizer:setSizeHints(Sizer, Frame),
wxFrame:show(Frame),
wxFrame:connect(Frame, close_window),
wx_test_lib:wx_destroy(Frame,Config).
staticBoxSizer(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
staticBoxSizer(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
Panel = wxPanel:new(Frame, []),
InclSizer = ?mt(wxStaticBoxSizer,
wxStaticBoxSizer:new(?wxVERTICAL, Panel,
[{label, "Module inclusion policy"}])),
Sizer = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sizer, InclSizer,
[{border, 2}, {flag, ?wxALL bor ?wxEXPAND}, {proportion, 1}]),
wxWindow:setSizerAndFit(Panel, Sizer),
wxWindow:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
clipboard(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
clipboard(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Main Frame"),
Ctrl = wxTextCtrl:new(Frame, ?wxID_ANY, [{size, {600,400}}, {style, ?wxTE_MULTILINE}]),
wxTextCtrl:connect(Ctrl, command_text_copy, [{skip, true}]),
wxTextCtrl:connect(Ctrl, command_text_cut, [{skip, true}]),
wxTextCtrl:connect(Ctrl, command_text_paste, [{skip, true}]),
wxWindow:show(Frame),
CB = ?mt(wxClipboard, wxClipboard:get()),
wxClipboard:usePrimarySelection(CB),
?m(false, wx:is_null(CB)),
case wxClipboard:open(CB) of
true ->
case wxClipboard:isSupported(CB, ?wxDF_TEXT) of
false ->
?log("No text on the clipboard~n",[]);
true ->
Text = ?mt(wxTextDataObject, wxTextDataObject:new()),
case wxClipboard:getData(CB,Text) of
true ->
?log("PASTE: ~s ~n", [wxTextDataObject:getText(Text)]);
false ->
?log("Couldn't access clipboard~n",[])
end,
wxTextDataObject:destroy(Text)
end,
wxClipboard:close(CB);
false ->
?log("Clipboard open failed~n",[])
end,
case wxClipboard:open(CB) of
true ->
Paste = ?mt(wxTextDataObject, wxTextDataObject:new([{text,"From Erlang"}])),
case wxClipboard:addData(CB,Paste) of
true ->
?log("Put text on clipboard~n", []);
false ->
?log("Couldn't copy data to clipboard~n",[])
end,
wxClipboard:close(CB);
false ->
?log("Clipboard open failed~n",[])
end,
?log("Flushing ~n",[]),
wxClipboard:flush(CB),
?log("Stopping ~n",[]),
wx_test_lib:wx_destroy(Frame,Config).
helpFrame(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
helpFrame(Config) ->
Wx = wx:new(),
MFrame = wx:batch(fun() ->
MFrame = wxFrame:new(Wx, ?wxID_ANY, "Main Frame"),
wxPanel:new(MFrame, [{size, {600,400}}]),
wxFrame:connect(MFrame, show),
wxWindow:show(MFrame),
MFrame
end),
receive #wx{event=#wxShow{}} -> ok
after 1000 -> exit(show_timeout)
end,
{X0, Y0} = wxWindow:getScreenPosition(MFrame),
{X, Y, W,H} = wxWindow:getScreenRect(MFrame),
io:format("Pos0: ~p ~p ~p Pos: ~p:~p Size: ~p:~p ~n",
[X0,Y0, wxWindow:clientToScreen(MFrame, {0,0}), X,Y,W,H]),
Pos = {X+5, Y+(H div 2)},
Size = {W-10, (H div 2) - 5},
Comp = wxFrame:new(MFrame, ?wxID_ANY, "Completion Window",
[{pos, Pos}, {size, Size},
{style, ?wxFRAME_FLOAT_ON_PARENT}]),
LB = wxListBox:new(Comp, 42, [{style, ?wxLB_SINGLE},
{size, Size}]),
Items = ["Item " ++ integer_to_list(N) || N <- lists:seq(1, 10)],
wxListBox:insertItems(LB,Items,0),
wxWindow:show(Comp),
wx_test_lib:wx_destroy(MFrame,Config).
htmlWindow(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
htmlWindow(Config) ->
Wx = wx:new(),
{MFrame,HPanel} =
wx:batch(fun() ->
MFrame = wxFrame:new(Wx, ?wxID_ANY, "Main Frame"),
HPanel = wxHtmlWindow:new(MFrame, [{size, {600,400}}]),
wxWindow:show(MFrame),
{MFrame, HPanel}
end),
timer:sleep(9),
WxMod = code:which(wx),
WxDir = filename:split(filename:dirname(WxMod)) -- ["ebin"],
Html = filename:join(filename:join(WxDir),filename:join("doc", "html")),
Index = filename:join(Html, "wx.html"),
?m(ok, wxHtmlWindow:connect(HPanel, command_html_link_clicked,
[{callback,
fun(Ev,_) ->
io:format("Link clicked: ~p~n",[Ev])
end}])),
case filelib:is_file(Index) of
true ->
?m(true, wxHtmlWindow:loadFile(HPanel, Index)),
ok;
false ->
ok
end,
wx_test_lib:wx_destroy(MFrame,Config).
listCtrlSort(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
listCtrlSort(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
LC = wxListCtrl:new(Frame, [{style, ?wxLC_REPORT}]),
%% must be done crashes in wxwidgets otherwise.
wxListCtrl:insertColumn(LC, 0, "Column"),
Add = fun(Int) ->
wxListCtrl:insertItem(LC, Int, "ABC " ++ integer_to_list(Int)),
%% ItemData Can only be integers currently
wxListCtrl:setItemData(LC, Int, abs(50-Int))
end,
wx:foreach(Add, lists:seq(0,50)),
wxWindow:show(Frame),
timer:sleep(1000),
Sort = fun() ->
wxListCtrl:sortItems(LC, fun(A, B) ->
%% io:format("S ~p ~p ~n",[A,B]),
if A =:= B -> 0;
A < B -> -1;
true -> 1
end
end)
end,
Time = timer:tc(erlang, apply, [Sort,[]]),
io:format("Sorted ~p ~n",[Time]),
Item = wxListItem:new(),
%% Test that wx-asserts are sent to error logger
%% Force an assert on 3.0 (when debug compiled which it is by default)
wxListItem:setId(Item, 200),
case os:type() of
{win32, _} ->
wxListItem:setColumn(Item, 3),
io:format("Got ~p ~n", [wxListCtrl:insertItem(LC, Item)]),
wxListItem:setColumn(Item, 0);
_ -> %% Uses generic listctrl
%% we can't use the code above on linux with wx-2.8.8 because it segfaults.
io:format("Got ~p ~n", [wxListCtrl:getItem(LC, Item)])
end,
wxListItem:setMask(Item, ?wxLIST_MASK_TEXT),
_List = wx:map(fun(Int) ->
wxListItem:setId(Item, Int),
?m(true, wxListCtrl:getItem(LC, Item)),
io:format("~p: ~s~n",[Int, wxListItem:getText(Item)])
end, lists:seq(0,10)),
wx_test_lib:wx_destroy(Frame,Config).
listCtrlVirtual(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
listCtrlVirtual(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
IA = wxListItemAttr:new(),
wxListItemAttr:setTextColour(IA, {190, 25, 25}),
Style = ?wxLC_SINGLE_SEL bor ?wxLC_REPORT bor ?wxLC_VIRTUAL bor
?wxLC_HRULES bor ?wxHSCROLL bor ?wxVSCROLL,
%% Assert signed consts (wxVSCROLL)
Style = wxe_util:get_const(wxLC_SINGLE_SEL) bor wxe_util:get_const(wxLC_REPORT) bor
wxe_util:get_const(wxLC_VIRTUAL) bor wxe_util:get_const(wxLC_HRULES) bor wxe_util:get_const(wxHSCROLL)
bor wxe_util:get_const(wxVSCROLL),
LC = wxListCtrl:new(Frame,
[{style, Style},
{onGetItemText, fun(_This, Item, 0) ->
"Row " ++ integer_to_list(Item);
(_, Item, 1) when Item rem 5 == 0 ->
"Column 2";
(_, _, _) -> ""
end},
{onGetItemAttr, fun(_This, Item) when Item rem 3 == 0 ->
IA;
(_This, _Item) ->
wx:typeCast(wx:null(), wxListItemAttr)
end},
{onGetItemColumnImage, fun(_This, Item, 1) ->
Item rem 4;
(_, _, _) ->
-1
end}
]),
IL = wxImageList:new(16,16),
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_COPY", [{size, {16,16}}])),
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_MISSING_IMAGE", [{size, {16,16}}])),
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_TICK_MARK", [{size, {16,16}}])),
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_CROSS_MARK", [{size, {16,16}}])),
wxListCtrl:assignImageList(LC, IL, ?wxIMAGE_LIST_SMALL),
wxListCtrl:insertColumn(LC, 0, "Column 1"),
wxListCtrl:insertColumn(LC, 1, "Column 2"),
wxListCtrl:setColumnWidth(LC, 0, 200),
wxListCtrl:setColumnWidth(LC, 1, 200),
wxListCtrl:setItemCount(LC, 1000000),
wxWindow:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
radioBox(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
radioBox(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
TrSortRadioBox = wxRadioBox:new(Frame, ?wxID_ANY, "Sort by:",
{100, 100},{100, 100},
["Timestamp", "Session", "FooBar"]),
io:format("TrSortRadioBox ~p ~n", [TrSortRadioBox]),
wxRadioBox:setSelection(TrSortRadioBox, 2),
wxRadioBox:setItemToolTip(TrSortRadioBox, 2, "Test"),
TT0 = ?mt(wxToolTip,wxRadioBox:getItemToolTip(TrSortRadioBox, 0)),
TT1 = ?mt(wxToolTip,wxRadioBox:getItemToolTip(TrSortRadioBox, 2)),
?m(true, wx:is_null(TT0)),
?m("Test", wxToolTip:getTip(TT1)),
wxWindow:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
systemSettings(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
systemSettings(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
?m({_,_,_,_}, wxSystemSettings:getColour(?wxSYS_COLOUR_DESKTOP)),
?mt(wxFont, wxSystemSettings:getFont(?wxSYS_SYSTEM_FONT)),
?m(true, is_integer(wxSystemSettings:getMetric(?wxSYS_MOUSE_BUTTONS))),
?m(true, is_integer(wxSystemSettings:getScreenType())),
wxWindow:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
textCtrl(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
textCtrl(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
TC = ?mt(wxTextCtrl, wxTextCtrl:new(Frame, ?wxID_ANY, [{style, ?wxTE_MULTILINE bor ?wxTE_RICH2}])),
wxTextCtrl:appendText(TC, "This line is in default color\n"),
Attr = ?mt(wxTextAttr, wxTextAttr:new(?wxRED)),
wxTextCtrl:setDefaultStyle(TC, Attr),
wxTextCtrl:appendText(TC, "This line is in ?wxRED color\n"),
wxTextAttr:setTextColour(Attr, ?wxBLACK),
wxTextCtrl:setDefaultStyle(TC, Attr),
wxTextCtrl:appendText(TC, "This line is in ?wxBLACK color\n"),
Default = wxSystemSettings:getColour(?wxSYS_COLOUR_WINDOWTEXT),
wxTextAttr:setTextColour(Attr, Default),
wxTextCtrl:setDefaultStyle(TC, Attr),
wxTextCtrl:appendText(TC, "This line is in default color\n"),
wxTextAttr:destroy(Attr),
wxWindow:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
taskBarIcon(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
taskBarIcon(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
TBI = wxTaskBarIcon:new(),
Image = wxImage:new(filename:join(code:priv_dir(debugger), "erlang_bug.png")),
io:format("Image ~p~n",[wxImage:ok(Image)]),
Icon = wxIcon:new(filename:join(code:priv_dir(debugger), "erlang_bug.png"), [{type, ?wxBITMAP_TYPE_PNG}]),
wxTaskBarIcon:setIcon(TBI, Icon, [{tooltip, "Testing wxTaskBarIcon"}]),
wxWindow:show(Frame),
wxTaskBarIcon:connect(TBI, taskbar_left_down, [{callback, fun(Ev,_) -> io:format("Left clicked: ~p~n",[Ev]) end}]),
wxTaskBarIcon:connect(TBI, taskbar_right_down, [{callback,fun(Ev,_) -> io:format("Right clicked: ~p~n",[Ev]) end}]),
wx_test_lib:wx_destroy(Frame,Config).
toolbar(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
toolbar(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
TB = wxFrame:createToolBar(Frame),
BM1 = wxArtProvider:getBitmap("wxART_COPY", [{size, {16,16}}, {client, "wxART_TOOLBAR"}]),
BM2 = wxArtProvider:getBitmap("wxART_TICK_MARK", [{size, {16,16}}, {client, "wxART_TOOLBAR"}]),
wxToolBar:addTool(TB, 747, "PressMe", BM1,
[{shortHelp, "Press Me"}]),
catch wxToolBar:addStretchableSpace(TB), %% wxWidgets 3.0 only
Add = fun(#wx{}, _) ->
wxToolBar:addTool(TB, -1, "Added", BM2,
[{shortHelp, "Test 2 popup text"}]),
catch wxToolBar:addStretchableSpace(TB), %% wxWidgets 3.0 only
wxToolBar:realize(TB)
end,
wxToolBar:realize(TB),
wxFrame:connect(Frame, command_menu_selected, [{callback, Add}, {id, 747}]),
wxFrame:show(Frame),
wx_test_lib:wx_destroy(Frame,Config).
popup(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
popup(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, "Frame"),
TB = wxFrame:createToolBar(Frame),
wxToolBar:addTool(TB, 747, "PressMe", wxArtProvider:getBitmap("wxART_COPY", [{size, {16,16}}]),
[{shortHelp, "Press Me"}]),
Log = fun(#wx{id=Id, event=Ev}, Obj) ->
io:format("Got ~p from ~p~n", [Ev, Id]),
wxEvent:skip(Obj)
end,
CreatePopup = fun() ->
Pop = wxPopupTransientWindow:new(Frame),
Panel = wxPanel:new(Pop),
Sz = wxBoxSizer:new(?wxVERTICAL),
wxSizer:add(Sz, wxButton:new(Panel, 42, [{label, "A button"}])),
wxSizer:add(Sz, Txt = wxStaticText:new(Panel, 43, "Some static text")),
wxSizer:add(Sz, wxButton:new(Panel, 44, [{label, "B button"}])),
wxPanel:setSizerAndFit(Panel, Sz),
wxSizer:setSizeHints(Sz, Pop),
wxWindow:connect(Pop, command_button_clicked, [{callback, Log}]),
wxWindow:connect(Txt, left_up, [{callback, Log}]),
wxWindow:connect(Txt, middle_up, [{callback, Log}]),
wxWindow:connect(Txt, right_up, [{callback, Log}]),
wxWindow:connect(Pop, show, [{callback, Log}]),
Pos = wx_misc:getMousePosition(),
wxPopupTransientWindow:position(Pop, Pos, {-1, -1}),
wxPopupTransientWindow:popup(Pop),
Pop
end,
wxFrame:connect(Frame, command_menu_selected, [{id, 747}]),
wxFrame:connect(Frame, show),
wxFrame:show(Frame),
receive #wx{event=#wxShow{}} -> ok
after 1000 -> exit(show_timeout)
end,
Pop = CreatePopup(),
Scale = case wx_test_lib:user_available(Config) of
true -> 25;
false -> 1
end,
receive
#wx{} -> CreatePopup()
after 200*Scale ->
wxPopupTransientWindow:dismiss(Pop)
end,
wx_test_lib:wx_destroy(Frame,Config).
locale(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
locale(_Config) ->
wx:new(),
io:format("SystemEncoding: ~p~n",[wxLocale:getSystemEncoding()]),
io:format("SystemEncodingName: ~ts~n",[wxLocale:getSystemEncodingName()]),
io:format("SystemLanguage: ~p~n",[wxLocale:getSystemLanguage()]),
io:format("SystemLanguageName: ~p~n",[wxLocale:getLanguageName(wxLocale:getSystemLanguage())]),
lang_env(),
LC = wxLocale:new(),
%% wxLocale:addCatalog(LC, "wxstd"),
io:format("Swedish: ~p~n",[wxLocale:getLanguageName(?wxLANGUAGE_SWEDISH)]),
R0 = wxLocale:init(LC, [{language, ?wxLANGUAGE_SWEDISH}, {flags, 0}]),
io:format("initiated ~p~n",[R0]),
lang_env(),
ok.
%% wx_test_lib:wx_destroy(Frame,Config).
lang_env() ->
Env0 = os:getenv(),
Env = [[R,"\n"]||R <- Env0],
%%io:format("~p~n",[lists:sort(Env)]),
Opts = [global, multiline, {capture, all, list}, unicode],
format_env(re:run(Env, "LC_ALL.*", Opts)),
format_env(re:run(Env, "^LANG.*=.*$", Opts)),
ok.
format_env({match, List}) ->
[io:format(" ~ts~n",[L]) || L <- List];
format_env(nomatch) -> ok.
%% Add a testcase that tests that we can recurse in showModal
%% because it hangs in observer if object are not destroyed correctly
%% when popping the stack
modal(Config) ->
Wx = wx:new(),
Frame = wxFrame:new(Wx, -1, "Test Modal windows"),
wxFrame:show(Frame),
Env = wx:get_env(),
Upd = wxUpdateUIEvent:getUpdateInterval(),
wxUpdateUIEvent:setUpdateInterval(200),
Tester = spawn_link(fun() -> modal_test(Env) end),
D1 = wxTextEntryDialog:new(Frame, "Dialog 1"),
ShowCB = fun(#wx{event=Ev},_) ->
case Ev of
#wxShow{show=true} ->
Tester ! {dialog, self(), D1},
receive continue ->
D2 = wxTextEntryDialog:new(Frame, "Dialog 2"),
Tester ! {dialog, self(), D2},
Tester ! {dialog_done, self(), wxDialog:showModal(D2)}
end;
_ ->
ignore
end
end,
wxDialog:connect(D1, show, [{callback, ShowCB}]),
?wxID_OK = wxDialog:showModal(D1),
wxUpdateUIEvent:setUpdateInterval(Upd),
wx_test_lib:wx_destroy(Frame,Config).
%%
%% Add sleep before continuing so we recurse from
%% wxe_impl::dispatch_cb() to wxe_impl::dispatch() (with idle commands)
%% and handle events there so the queue should be reset and started from 0.
%%
modal_test(Env) ->
wx:set_env(Env),
receive
{dialog, CBpid, D1} ->
timer:sleep(500),
CBpid ! continue,
?wxID_CANCEL = modal_test2(CBpid),
wxDialog:endModal(D1, ?wxID_OK)
end.
modal_test2(CBpid) ->
receive
{dialog, CBpid, D2} ->
timer:sleep(500),
wxDialog:endModal(D2, ?wxID_CANCEL),
receive {dialog_done, CBpid, Res} -> Res end
end.
|