diff options
author | Dan Gudmundsson <[email protected]> | 2011-07-07 10:33:56 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2011-07-07 10:33:56 +0200 |
commit | 98a0a3a7c3d24144c773629dd827bb06ea6cf5c1 (patch) | |
tree | 24c5ab39d95362b1b58a5b333ece3174598c96f7 /lib/wx/c_src/wxePrintout.cpp | |
parent | 7c9696df18f70cc0431fbb6ea67a25277fe2b2d2 (diff) | |
download | otp-98a0a3a7c3d24144c773629dd827bb06ea6cf5c1.tar.gz otp-98a0a3a7c3d24144c773629dd827bb06ea6cf5c1.tar.bz2 otp-98a0a3a7c3d24144c773629dd827bb06ea6cf5c1.zip |
Add support for virtual listctrls
Diffstat (limited to 'lib/wx/c_src/wxePrintout.cpp')
-rw-r--r-- | lib/wx/c_src/wxePrintout.cpp | 254 |
1 files changed, 136 insertions, 118 deletions
diff --git a/lib/wx/c_src/wxePrintout.cpp b/lib/wx/c_src/wxePrintout.cpp index ea1c76edcc..1bcbc5f1a4 100644 --- a/lib/wx/c_src/wxePrintout.cpp +++ b/lib/wx/c_src/wxePrintout.cpp @@ -1,41 +1,62 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2008-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2008-2011. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * - * %CopyrightEnd% + * + * %CopyrightEnd% */ #include <wx/wx.h> #include "wxe_impl.h" #include "wxe_return.h" +#include "gen/wxe_macros.h" +#include "gen/wxe_derived_dest.h" /* *****************************************************************/ /* Special Class impls */ +#define INVOKE_CALLBACK_INIT(port, callback, class_str) \ + { \ + wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); \ + wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); \ + rt.addInt(callback); \ + rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), class_str); + +#define INVOKE_CALLBACK_END(port, args) \ + rt.endList(1 + (args)); \ + rt.addAtom("_wx_invoke_cb_"); \ + rt.addTupleCount(3); \ + rt.send(); \ + handle_callback_batch(port); \ + } + +#define INVOKE_CALLBACK(port, callback, class_str) \ + INVOKE_CALLBACK_INIT(port, callback, class_str); \ + INVOKE_CALLBACK_END(port, 0) +/* *****************************************************************/ /* Printing special */ wxEPrintout::~wxEPrintout() { - clear_cb(onPrintPage); - clear_cb(onPreparePrinting); - clear_cb(onBeginPrinting); - clear_cb(onEndPrinting); - clear_cb(onBeginDocument); - clear_cb(onEndDocument); - clear_cb(hasPage); - clear_cb(getPageInfo); + clear_cb(port, onPrintPage); + clear_cb(port, onPreparePrinting); + clear_cb(port, onBeginPrinting); + clear_cb(port, onEndPrinting); + clear_cb(port, onBeginDocument); + clear_cb(port, onEndDocument); + clear_cb(port, hasPage); + clear_cb(port, getPageInfo); ((WxeApp *)wxTheApp)->clearPtr(this); } @@ -43,73 +64,42 @@ wxEPrintout::~wxEPrintout() { bool wxEPrintout::OnBeginDocument(int startPage, int endPage) { if(onBeginDocument) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - char * bp = ((WxeApp *) wxTheApp)->cb_buff; - - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(onBeginDocument); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); + INVOKE_CALLBACK_INIT(port, onBeginDocument, "wxPrintout"); rt.addInt(startPage); rt.addInt(endPage); - rt.endList(3); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); - return *(int*) bp; - } else { - return wxPrintout::OnBeginDocument(startPage,endPage); - } + INVOKE_CALLBACK_END(port, 2); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + char * bp = ((WxeApp *) wxTheApp)->cb_buff; + return *(int*) bp; + } + } + return wxPrintout::OnBeginDocument(startPage,endPage); } -void wxEPrintout::OnEndDocument() +void wxEPrintout::OnEndDocument() { if(onEndDocument) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(onEndDocument); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); - rt.endList(1); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); + INVOKE_CALLBACK(port, onEndDocument, "wxPrintout"); } else { wxPrintout::OnEndDocument(); - } + } } -void wxEPrintout::OnBeginPrinting() +void wxEPrintout::OnBeginPrinting() { if(onBeginPrinting) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(onBeginPrinting); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); - rt.endList(1); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); + INVOKE_CALLBACK(port, onBeginPrinting, "wxPrintout"); } else { wxPrintout::OnBeginPrinting(); - } + } } -void wxEPrintout::OnEndPrinting() +void wxEPrintout::OnEndPrinting() { if(onEndPrinting) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(onEndPrinting); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); - rt.endList(1); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); + INVOKE_CALLBACK(port, onEndPrinting, "wxPrintout"); } else { wxPrintout::OnEndPrinting(); } @@ -119,92 +109,120 @@ void wxEPrintout::OnPreparePrinting() { if(onPreparePrinting) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(onPreparePrinting); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); - rt.endList(1); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); + INVOKE_CALLBACK(port, onPreparePrinting, "wxPrintout"); } else { wxPrintout::OnPreparePrinting(); - } + } } -bool wxEPrintout::HasPage(int page) +bool wxEPrintout::HasPage(int page) { if(hasPage) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(hasPage); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); + INVOKE_CALLBACK_INIT(port, hasPage, "wxPrintout"); rt.addInt(page); - rt.endList(2); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - char * bp = ((WxeApp *) wxTheApp)->cb_buff; - handle_callback_batch(port); - return *(int*) bp; - } else { - return wxPrintout::HasPage(page); - } + INVOKE_CALLBACK_END(port, 1); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + char * bp = ((WxeApp *) wxTheApp)->cb_buff; + return *(int*) bp; + } + } + return wxPrintout::HasPage(page); } bool wxEPrintout::OnPrintPage(int page) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(onPrintPage); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); + INVOKE_CALLBACK_INIT(port, onPrintPage, "wxPrintout"); rt.addInt(page); - rt.endList(2); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); - //fprintf(stderr,"%d ", __LINE__);handle_callback_batch(port); fprintf(stderr,"%d\r\n", __LINE__); - char * bp = ((WxeApp *) wxTheApp)->cb_buff; - return *(int*) bp; + INVOKE_CALLBACK_END(port, 1); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + char * bp = ((WxeApp *) wxTheApp)->cb_buff; + return *(int*) bp; + } + return FALSE; } - + void wxEPrintout::GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) { if(getPageInfo) { - wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); - wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - rt.addInt(getPageInfo); - rt.addRef(((WxeApp *) wxTheApp)->getRef((void *)this, memenv), "wxPrintout"); - rt.endList(1); - rt.addAtom("_wx_invoke_cb_"); - rt.addTupleCount(3); - rt.send(); - handle_callback_batch(port); - //fprintf(stderr,"%d ", __LINE__);handle_callback_batch(port); fprintf(stderr,"%d\r\n", __LINE__); + INVOKE_CALLBACK(port, getPageInfo, "wxPrintout"); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + char * bp = ((WxeApp *) wxTheApp)->cb_buff; + *minPage = *(int *) bp; bp += 4; + *maxPage = *(int *) bp; bp += 4; + *pageFrom = *(int *) bp; bp += 4; + *pageTo = *(int *) bp; bp += 4; + } + } + wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); +} + +/* *****************************************************************/ +// ListCtrl with callbacks for VIRTUAL_TABLES + +wxString EwxListCtrl::OnGetItemText(long item, long col) const { + if(onGetItemText) { + INVOKE_CALLBACK_INIT(port, onGetItemText, "wxListCtrl"); + rt.addInt(item); + rt.addInt(col); + INVOKE_CALLBACK_END(port, 2); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + char * bp = ((WxeApp *) wxTheApp)->cb_buff; + wxString str = wxString(bp, wxConvUTF8); + return str; + } + } + return wxT("OnGetItemText not correctly defined"); +} +wxListItemAttr* EwxListCtrl::OnGetItemAttr(long item) const { + if(onGetItemAttr) { + INVOKE_CALLBACK_INIT(port, onGetItemAttr, "wxListCtrl"); + rt.addInt(item); + INVOKE_CALLBACK_END(port, 1); char * bp = ((WxeApp *) wxTheApp)->cb_buff; - *minPage = *(int *) bp; bp += 4; - *maxPage = *(int *) bp; bp += 4; - *pageFrom = *(int *) bp; bp += 4; - *pageTo = *(int *) bp; bp += 4; - } else { - wxPrintout::GetPageInfo(minPage, maxPage, pageFrom, pageTo); + wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + return (wxListItemAttr *) ((WxeApp *) wxTheApp)->getPtr(bp, memenv); + } + } + return NULL; +} + +int EwxListCtrl::OnGetItemImage(long item) const { + return OnGetItemColumnImage(item, 0); +} + +int EwxListCtrl::OnGetItemColumnImage(long item, long col) const { + if(onGetItemColumnImage) { + INVOKE_CALLBACK_INIT(port, onGetItemColumnImage, "wxListCtrl"); + rt.addInt(item); + rt.addInt(col); + INVOKE_CALLBACK_END(port, 2); + if(((WxeApp *) wxTheApp)->cb_len > 0) { + char * bp = ((WxeApp *) wxTheApp)->cb_buff; + return *(int *) bp; + } } + return -1; +} + +EwxListCtrl::~EwxListCtrl() { + clear_cb(port, onGetItemText); + clear_cb(port, onGetItemAttr); + clear_cb(port, onGetItemColumnImage); + ((WxeApp *)wxTheApp)->clearPtr(this); } +// tools -void wxEPrintout::clear_cb(int callback) +void clear_cb(ErlDrvPort port, int callback) { if(callback > 0) { wxeMemEnv * memenv = ((WxeApp *) wxTheApp)->getMemEnv(port); wxeReturn rt = wxeReturn(WXE_DRV_PORT, memenv->owner, false); - // NOTE: Remove this later when changing from funs to gen_server rt.addAtom("wx_delete_cb"); rt.addInt(callback); rt.addTupleCount(2); rt.send(); } } - |