Changeset f9263dd in thomson


Ignore:
Timestamp:
Jan 29, 2012, 9:06:29 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
192e299
Parents:
c7b4218
Message:

Final version (?) of iup++, which handles callbacks with arguments. Needs C++11.

git-svn-id: svn://localhost/thomson@14 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

Location:
elec/CrO2/software
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/Makefile

    rc7b4218 rf9263dd  
    1414
    1515CC              = g++
    16 CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -g
     16CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -g -std=c++0x
    1717LIBS    = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32
    1818
  • elec/CrO2/software/gui.cpp

    rc7b4218 rf9263dd  
    1111
    1212#include <stdint.h>
    13 #include <iup.h>
    1413#include <iupcontrols.h>
    15 
    16 ///////////////////////////////////////////////////////////////////////////////
    17 // Super awesome extended powerful ultimate deluxe C++ IUP callback system ;)
    18 
    19 typedef int (Gui::*Callee)();
    20 
    21 class Callback
    22 {
    23         public:
    24                 static int call(Ihandle* that);
    25                 static int destroy(Ihandle* that);
    26                 static void create(Ihandle* handle, const char* name, Gui* self, Callee what);
    27 
    28         private:
    29                 Callback(Gui* self, Callee what);
    30                 Callback(); // do not use
    31 
    32                 Gui* self;
    33                 Callee what;
    34 };
    35 
    36 void Callback::create(Ihandle* handle,const char* name, Gui* self, Callee what)
    37 {
    38         Callback* cb = new Callback(self, what);
    39         IupSetAttribute(handle, "LCALLBACK", (char*)cb);
    40         IupSetCallback(handle, name, Callback::call);
    41         IupSetCallback(handle, "LDESTROY_CB", Callback::destroy);
    42 }
    43 
    44 Callback::Callback(Gui* self, Callee what)
    45 {
    46         this->self = self;
    47         this->what = what;
    48 }
    49 
    50 int Callback::call(Ihandle* that)
    51 {
    52         Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
    53         return ((call->self)->*(call->what))();
    54 }
    55 
    56 int Callback::destroy(Ihandle* that)
    57 {
    58         Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
    59         delete call;
    60         return IUP_DEFAULT;
    61 }
    62 
    63 ///////////////////////////////////////////////////////////////////////////////
    6414
    6515        // Start status poller "thread"
     
    8838/* UI */
    8939
    90 int menu_exit(Ihandle* that)
     40int Gui::menu_exit()
    9141{
    9242        return IUP_CLOSE;
    9343}
    94 
    95 
    9644
    9745Gui::Gui(int* argc, char*** argv)
     
    10250//      IupControlsOpen();
    10351
    104         IupSetFunction("EXIT", menu_exit);
    105 
    10652        Ihandle* menu_open = IupItem("Open", NULL);
    107         Callback::create(menu_open, "ACTION", this, &Gui::menu_open);
     53        Ihandle* menu_exit = IupItem("Exit", NULL);
     54        Callback<Gui>::create(menu_open, "ACTION", this, &Gui::menu_open);
     55        Callback<Gui>::create(menu_exit, "ACTION", this, &Gui::menu_exit);
    10856
    10957        Ihandle* menu = IupMenu(
     
    11159                        IupMenu(
    11260                                menu_open,             
    113                                 IupItem("Exit", "EXIT"),
     61                                menu_exit,
    11462                                NULL
    11563                        )
  • elec/CrO2/software/gui.h

    rc7b4218 rf9263dd  
    55 */
    66
    7 #include <iup.h>
     7#include "iupplusplus.h"
     8
     9#include <cstdio>
    810
    911class K5;
     
    1618        private:
    1719                int menu_open();
     20                int menu_exit();
    1821
    1922                K5* file;
Note: See TracChangeset for help on using the changeset viewer.