File 3101-Added-wxTaskBarIcon-new-1.patch of Package erlang

From 7fee2e1b84bc42a9e174403348bef2b15d04cd2b Mon Sep 17 00:00:00 2001
From: Dominic Letz <dominic@diode.io>
Date: Mon, 7 Sep 2020 17:45:05 +0200
Subject: [PATCH 1/2] Added wxTaskBarIcon:new/1

---
 lib/wx/api_gen/wx_extra/wxTaskBarIcon.c_src |  46 ++++++
 lib/wx/api_gen/wx_extra/wxTaskBarIcon.erl   |  42 +++++
 lib/wx/api_gen/wxapi.conf                   |   2 +-
 lib/wx/c_src/gen/wxe_derived_dest.h         |   9 +-
 lib/wx/c_src/gen/wxe_funcs.cpp              |  10 +-
 lib/wx/c_src/wxe_callback_impl.cpp          |  20 +++
 lib/wx/examples/simple/taskbar.erl          | 168 ++++++++++++++++++++
 lib/wx/src/gen/wxTaskBarIcon.erl            |  21 ++-
 8 files changed, 310 insertions(+), 8 deletions(-)
 create mode 100644 lib/wx/api_gen/wx_extra/wxTaskBarIcon.c_src
 create mode 100644 lib/wx/api_gen/wx_extra/wxTaskBarIcon.erl
 create mode 100644 lib/wx/examples/simple/taskbar.erl

diff --git a/lib/wx/api_gen/wx_extra/wxTaskBarIcon.c_src b/lib/wx/api_gen/wx_extra/wxTaskBarIcon.c_src
new file mode 100644
index 0000000000..1b1f37486c
--- /dev/null
+++ b/lib/wx/api_gen/wx_extra/wxTaskBarIcon.c_src
@@ -0,0 +1,46 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2011-2016. 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%
+%%
+
+<<wxTaskBarIcon_class
+class EwxTaskBarIcon : public wxTaskBarIcon {
+ public: ~EwxTaskBarIcon() {((WxeApp *)wxTheApp)->clearPtr(this);};
+ EwxTaskBarIcon() : wxTaskBarIcon() {};
+
+ int createPopupMenu;
+ ErlDrvTermData port;
+
+ private:
+ virtual wxMenu* CreatePopupMenu();
+};
+wxTaskBarIcon_class>>
+
+<<wxTaskBarIcon_new
+case ~s: { // wxTaskBarIcon::wxTaskBarIcon
+ EwxTaskBarIcon * Result = new EwxTaskBarIcon();
+ Result->port = Ecmd.port;
+ if ( * (int*) bp) {
+   Result->createPopupMenu = *(int *) bp;
+ }
+
+ newPtr((void *) Result, 1, memenv);
+ rt.addRef(getRef((void *)Result,memenv), "wxTaskBarIcon");
+ break;
+}
+wxTaskBarIcon_new>>
diff --git a/lib/wx/api_gen/wx_extra/wxTaskBarIcon.erl b/lib/wx/api_gen/wx_extra/wxTaskBarIcon.erl
new file mode 100644
index 0000000000..71e756157f
--- /dev/null
+++ b/lib/wx/api_gen/wx_extra/wxTaskBarIcon.erl
@@ -0,0 +1,42 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2011-2016. 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%
+%%
+
+<<EXPORT:wxTaskBarIcon new/0, new/1 wxTaskBarIcon:EXPORT>>
+
+<<wxTaskBarIcon_new
+%% @doc See <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxtaskbaricon.html#wxtaskbariconwxtaskbaricon">external documentation</a>.
+-spec new() -> wxTaskBarIcon().
+new() ->
+  wxe_util:construct(~s, <<0:32>>).
+
+
+%% @doc Creates a TaskBarIcon with a callback function for CreatePopupMenu:
+%%   <pre>Callback() -> term()</pre>
+%%
+%% See <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxtaskbaricon.html#wxtaskbariconwxtaskbaricon">external documentation</a>.
+-spec new(function()) -> wxTaskBarIcon().
+new(F) when is_function(F)->
+  Fun = fun([_]) -> 
+    #wx_ref{type=wxMenu,ref=ThisRef} = F(),
+    <<ThisRef:32/?UI>>
+  end,
+  BinFun = <<(wxe_util:get_cbId(Fun)):32/?UI, 0:32>>,
+  wxe_util:construct(?wxTaskBarIcon_new, BinFun).
+wxTaskBarIcon_new>>
diff --git a/lib/wx/api_gen/wxapi.conf b/lib/wx/api_gen/wxapi.conf
index cd53a25c40..d2f8cac4c1 100644
--- a/lib/wx/api_gen/wxapi.conf
+++ b/lib/wx/api_gen/wxapi.conf
@@ -2005,7 +2005,7 @@
  [wxLogNull, '~wxLogNull']}.
 
 {class, wxTaskBarIcon, wxEvtHandler, [],
- [wxTaskBarIcon,'~wxTaskBarIcon',
+ [{wxTaskBarIcon, [{where, taylormade}]},'~wxTaskBarIcon',
   %%'CreatePopupMenu', virtual overridded is a callback
   %% 'IsIconInstalled', 'IsOk', not available on mac
   'PopupMenu','RemoveIcon','SetIcon']}.
diff --git a/lib/wx/c_src/gen/wxe_derived_dest.h b/lib/wx/c_src/gen/wxe_derived_dest.h
index a7114eb188..52a1460a79 100644
--- a/lib/wx/c_src/gen/wxe_derived_dest.h
+++ b/lib/wx/c_src/gen/wxe_derived_dest.h
@@ -1,7 +1,7 @@
 /*
  * %CopyrightBegin%
  *
- * Copyright Ericsson AB 2008-2018. All Rights Reserved.
+ * Copyright Ericsson AB 2008-2020. 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.
@@ -766,9 +766,16 @@ class EwxHtmlWindow : public wxHtmlWindow {
  EwxHtmlWindow() : wxHtmlWindow() {};
 };
 
+
 class EwxTaskBarIcon : public wxTaskBarIcon {
  public: ~EwxTaskBarIcon() {((WxeApp *)wxTheApp)->clearPtr(this);};
  EwxTaskBarIcon() : wxTaskBarIcon() {};
+
+ int createPopupMenu;
+ ErlDrvTermData port;
+
+ private:
+ virtual wxMenu* CreatePopupMenu();
 };
 
 class EwxLocale : public wxLocale {
diff --git a/lib/wx/c_src/gen/wxe_funcs.cpp b/lib/wx/c_src/gen/wxe_funcs.cpp
index 747201fe78..4304cdda91 100644
--- a/lib/wx/c_src/gen/wxe_funcs.cpp
+++ b/lib/wx/c_src/gen/wxe_funcs.cpp
@@ -1,7 +1,7 @@
 /*
  * %CopyrightBegin%
  *
- * Copyright Ericsson AB 2008-2019. All Rights Reserved.
+ * Copyright Ericsson AB 2008-2020. 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.
@@ -31773,8 +31773,14 @@ case wxLogNull_destroy: { // wxLogNull::destroy
    delete This;}
  break;
 }
+
 case wxTaskBarIcon_new: { // wxTaskBarIcon::wxTaskBarIcon
- wxTaskBarIcon * Result = new EwxTaskBarIcon();
+ EwxTaskBarIcon * Result = new EwxTaskBarIcon();
+ Result->port = Ecmd.port;
+ if ( * (int*) bp) {
+   Result->createPopupMenu = *(int *) bp;
+ }
+
  newPtr((void *) Result, 1, memenv);
  rt.addRef(getRef((void *)Result,memenv), "wxTaskBarIcon");
  break;
diff --git a/lib/wx/c_src/wxe_callback_impl.cpp b/lib/wx/c_src/wxe_callback_impl.cpp
index 77359e9256..09c9f2630a 100644
--- a/lib/wx/c_src/wxe_callback_impl.cpp
+++ b/lib/wx/c_src/wxe_callback_impl.cpp
@@ -309,6 +309,26 @@ int wxCALLBACK wxEListCtrlCompare(wxeIntPtr item1, wxeIntPtr item2, wxeIntPtr ca
 }
 
 
+/* *****************************************************************/
+// TaskBarIcon with callbacks for VIRTUAL_TABLES
+
+wxMenu* EwxTaskBarIcon::CreatePopupMenu() {
+  if(createPopupMenu) {
+    INVOKE_CALLBACK(port, createPopupMenu, "wxTaskBarIcon");
+    char * bp = ((WxeApp *) wxTheApp)->cb_buff;
+    wxeMemEnv * memenv =  ((WxeApp *) wxTheApp)->getMemEnv(port);
+    if(bp) {
+      wxMenu * result = (wxMenu *)((WxeApp *) wxTheApp)->getPtr(bp, memenv);
+      driver_free(((WxeApp *) wxTheApp)->cb_buff);
+      ((WxeApp *) wxTheApp)->cb_buff = NULL;
+      return result;
+    }
+  }
+  return NULL;
+}
+
+
+
 // tools
 
 void clear_cb(ErlDrvTermData port, int callback)
diff --git a/lib/wx/examples/simple/taskbar.erl b/lib/wx/examples/simple/taskbar.erl
new file mode 100644
index 0000000000..850a88c9bd
--- /dev/null
+++ b/lib/wx/examples/simple/taskbar.erl
@@ -0,0 +1,168 @@
+%%
+%% %CopyrightBegin%
+%% 
+%% Copyright Ericsson AB 2009-2018. 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    : menus.erl
+%%% Author  : Matthew Harrison <harryhuk at users.sourceforge.net>
+%%% Description : Test of menus
+%%%
+%%% Created :  18 Sep 2008 by  Matthew Harrison <harryhuk at users.sourceforge.net>
+%%%-------------------------------------------------------------------
+-module(taskbar).
+
+-include_lib("wx/include/wx.hrl").
+
+-export([start/0]).
+
+%%%Lots of IDs to declare!
+-define(menuID_FILE_QUIT,           ?wxID_EXIT).
+-define(menuID_FILE_CLEAR_LOG,      100).
+
+-define(menuID_MENUBAR_TOGGLE,      200).
+-define(menuID_MENUBAR_APPEND,      201).
+-define(menuID_MENUBAR_INSERT,      202).
+-define(menuID_MENUBAR_DELETE,      203).
+-define(menuID_MENUBAR_ENABLE,      204).
+-define(menuID_MENUBAR_GET_LABEL,   206).
+-define(menuID_MENUBAR_SET_LABEL,   207).
+-define(menuID_MENUBAR_FIND_MENU,   208).
+
+-define(menuID_MENU_APPEND,         300).
+-define(menuID_MENU_APPEND_SUB,     301).
+-define(menuID_MENU_INSERT,         302).
+-define(menuID_MENU_DELETE,         303).
+-define(menuID_MENU_ENABLE,         304).
+-define(menuID_MENU_CHECK,          305).
+-define(menuID_MENU_GET_LABEL,      306).
+-define(menuID_MENU_SET_LABEL,      307).
+-define(menuID_MENU_GET_INFO,       308).
+-define(menuID_MENU_FIND_ITEM,      309).
+
+-define(menuID_TEST_NORMAL,         400).
+-define(menuID_TEST_CHECK,          401).
+-define(menuID_TEST_RADIO_1,        402).
+-define(menuID_TEST_RADIO_2,        403).
+-define(menuID_TEST_RADIO_3,        404).
+
+-define(menuID_SUBMENU,             450).
+-define(menuID_SUBMENU_NORMAL,      451).
+-define(menuID_SUBMENU_CHECK,       452).
+-define(menuID_SUBMENU_RADIO_1,     453).
+-define(menuID_SUBMENU_RADIO_2,     454).
+-define(menuID_SUBMENU_RADIO_3,     455).
+
+-define(menuID_DUMMY_FIRST,         500).
+-define(menuID_DUMMY_SECOND,        501).
+-define(menuID_DUMMY_THIRD,         502).
+-define(menuID_DUMMY_FOURTH,        503).
+-define(menuID_DUMMY_LAST,          504).
+
+-define(menuID_HELP_ABOUT,          ?wxID_ABOUT).
+
+-define(menuID_POPUP_TO_BE_DELETED, 2000).
+-define(menuID_POPUP_TO_BE_GREYED,  2001).
+-define(menuID_POPUP_TO_BE_CHECKED, 2002).
+-define(menuID_POPUP_TO_BE_SUBMENU, 2003).
+
+-define(wID_LOG_TEXT_CTRL, 3000).
+
+-record(state, {dummyMenuCount=0, fileMenu=undefined}).
+
+%%    
+%%    
+%%    
+start() ->
+    Wx = wx:new(),
+    wx:batch(fun() -> create_frame(Wx) end),
+    Taskbar = wxTaskBarIcon:new(fun() ->
+        create_menu()
+    end),
+    Path = filename:dirname(code:which(?MODULE)),
+    wxTaskBarIcon:setIcon(Taskbar,  wxIcon:new(filename:join(Path,"sample.xpm"), [{type, ?wxBITMAP_TYPE_XPM}])),
+    
+    loop(#state{}),
+    ok.
+
+
+%%    
+%%    
+%%    
+create_frame(Wx) ->
+    Frame = wxFrame:new(Wx, -1, "wxErlang menu sample", [{size, {600,400}}]),
+
+    Path = filename:dirname(code:which(?MODULE)),    
+    wxFrame:setIcon(Frame,  wxIcon:new(filename:join(Path,"sample.xpm"), [{type, ?wxBITMAP_TYPE_XPM}])),
+
+    wxFrame:createStatusBar(Frame,[]),
+    wxFrame:connect(Frame, close_window),
+
+    Frame.
+
+%%    
+%%    
+%%    
+create_menu() ->
+    % unlike wxwidgets the stock menu items still need text to be given, 
+    % although help text does appear
+    StockSubMenu = wxMenu:new(),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_ADD      }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_CANCEL   }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_CLEAR    }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_CLOSE    }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_COPY     }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_CUT      }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_DELETE   }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_FIND     }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_REPLACE  }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_BACKWARD }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_DOWN     }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_FORWARD  }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_UP       }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_HELP     }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_HOME     }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_INDENT   }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_INDEX    }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_ITALIC   }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_NEW              }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_NO               }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_OK               }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_OPEN             }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_PASTE            }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_PREFERENCES      }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_PRINT            }])),
+    wxMenu:append(StockSubMenu,  wxMenuItem:new([{id,    ?wxID_EXIT             }])),
+
+    StockSubMenu.
+
+loop(State) ->
+    receive 
+  	#wx{event=#wxClose{}, obj=Frame} ->
+  	    io:format("~p Closing window ~n",[self()]),
+  	    wxWindow:destroy(Frame); %onClose(Frame); 
+	#wx{id=?menuID_FILE_QUIT, obj=Frame, event=#wxCommand{type=command_menu_selected}} ->
+  	    io:format("~p Closing window ~n",[self()]),
+  	    wxWindow:destroy(Frame); %onClose(Frame); 
+  	    
+	Msg ->
+	    io:format("Got ~p ~n", [Msg]),
+	    loop(State)
+    after 5000 ->
+	    loop(State)
+    end.
+    
diff --git a/lib/wx/src/gen/wxTaskBarIcon.erl b/lib/wx/src/gen/wxTaskBarIcon.erl
index af4859fb88..66888abcd1 100644
--- a/lib/wx/src/gen/wxTaskBarIcon.erl
+++ b/lib/wx/src/gen/wxTaskBarIcon.erl
@@ -1,7 +1,7 @@
 %%
 %% %CopyrightBegin%
 %%
-%% Copyright Ericsson AB 2008-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2008-2020. 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.
@@ -28,7 +28,7 @@
 
 -module(wxTaskBarIcon).
 -include("wxe.hrl").
--export([destroy/1,new/0,popupMenu/2,removeIcon/1,setIcon/2,setIcon/3]).
+-export([ new/0, new/1 ,destroy/1,popupMenu/2,removeIcon/1,setIcon/2,setIcon/3]).
 
 %% inherited exports
 -export([connect/2,connect/3,disconnect/1,disconnect/2,disconnect/3,parent_class/1]).
@@ -39,12 +39,25 @@ parent_class(wxEvtHandler) -> true;
 parent_class(_Class) -> erlang:error({badtype, ?MODULE}).
 
 -type wxTaskBarIcon() :: wx:wx_object().
+
 %% @doc See <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxtaskbaricon.html#wxtaskbariconwxtaskbaricon">external documentation</a>.
 -spec new() -> wxTaskBarIcon().
 new() ->
-  wxe_util:construct(?wxTaskBarIcon_new,
-  <<>>).
+  wxe_util:construct(?wxTaskBarIcon_new, <<0:32>>).
+
 
+%% @doc Creates a TaskBarIcon with a callback function for CreatePopupMenu:
+%%   <pre>Callback() -> term()</pre>
+%%
+%% See <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxtaskbaricon.html#wxtaskbariconwxtaskbaricon">external documentation</a>.
+-spec new(function()) -> wxTaskBarIcon().
+new(F) when is_function(F)->
+  Fun = fun([_]) -> 
+    #wx_ref{type=wxMenu,ref=ThisRef} = F(),
+    <<ThisRef:32/?UI>>
+  end,
+  BinFun = <<(wxe_util:get_cbId(Fun)):32/?UI, 0:32>>,
+  wxe_util:construct(?wxTaskBarIcon_new, BinFun).
 %% @doc See <a href="http://www.wxwidgets.org/manuals/2.8.12/wx_wxtaskbaricon.html#wxtaskbariconpopupmenu">external documentation</a>.
 -spec popupMenu(This, Menu) -> boolean() when
 	This::wxTaskBarIcon(), Menu::wxMenu:wxMenu().
-- 
2.26.2

openSUSE Build Service is sponsored by