/usr/include/mffm/X/fieldInterface.H is in mffm-timecode-dev 1.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
mffm Time Code
Time Code for multimedia systems
Copyright (C) 2000, 2001 Matt R. Flax <flatmax@ieee.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You have received a copy of the GNU Lesser General Public License
along with this library.
*/
#ifndef FIELDINTERFACE_H_
#define FIELDINTERFACE_H_
#include <iostream>
#include "../../X/gtkInterface.H"
#include "../field.H"
#include "commonTimeCodeX.H"
#include "XPMDigits.H"
class FieldInterface : public field, public HBox {
GtkPixmap **digitsGtk; /// The digit GtkPixmaps
GtkWidget **digitsEventBox; /// The event box for handling button presses
void eventSetup(void){
for (int i=0; i<digitCnt();i++){
gtk_widget_add_events(digitsEventBox[i], GDK_BUTTON_RELEASE_MASK);
gtk_signal_connect (GTK_OBJECT(digitsEventBox[i]), "button-release-event", GTK_SIGNAL_FUNC(digitPress), this);
}
}
public:
FieldInterface(int minVal, int startVal, int maxVal): field (minVal, startVal, maxVal){
#if DEBUG > 1
std::cout<<"FieldInterface::FieldInterface(minVal, startVal, maxVal)"<<std::endl;
#endif
//Init the Gtk pixmaps
digitsGtk =new GtkPixmap*[digitCnt()];
if (!digitsGtk){
std::cerr <<"XPM Alloc b: Out of memory"<<std::endl;
exit(-1);
}
for (int i=0;i<digitCnt();i++)
digitsGtk[i]=NULL;
// Init the GtkEventBoxs
digitsEventBox = new GtkWidget*[digitCnt()];
if (!digitsEventBox){
std::cerr <<"XPM Alloc a: Out of memory"<<std::endl;
exit(-1);
}
for (int i=0;i<digitCnt();i++)
digitsEventBox[i]=(GtkWidget*)NULL;
for (int i=0;i<digitCnt();i++){
digitsGtk[i]=(GtkPixmap*)gtk_pixmap_new(digitsGdk[10], digitsMasks[10]);
if (!digitsGtk[i]) {
std::cerr <<"XPM Alloc 1a: Out of memory"<<std::endl;
exit(-1);
}
//flatmax
gtk_object_ref(GTK_OBJECT(digitsGtk[i]));
gtk_object_sink(GTK_OBJECT(digitsGtk[i]));
digitsEventBox[i]=gtk_event_box_new();
if (!digitsEventBox[i]) {
std::cerr <<"XPM Alloc 1: Out of memory"<<std::endl;
exit(-1);
}
//flatmax
gtk_object_ref(GTK_OBJECT(digitsEventBox[i]));
gtk_object_sink(GTK_OBJECT(digitsEventBox[i]));
gtk_widget_show(digitsEventBox[i]);
gtk_container_add (GTK_CONTAINER (digitsEventBox[i]), GTK_WIDGET(digitsGtk[i]));
gtk_widget_show(GTK_WIDGET(digitsGtk[i]));
}
// Layout the pixmaps ...
for (int i=0;i<digitCnt();i++)
*this<<digitsEventBox[i];
eventSetup(); // Set up the digit press events
show();
update();
}
~FieldInterface(void){
#if DEBUG > 1
std::cout<<"FieldInterface::~FieldInterface"<<std::endl;
#endif
for (int i=0;i<digitCnt();i++){
gtk_object_unref(GTK_OBJECT(digitsGtk[i]));
gtk_object_unref(GTK_OBJECT(digitsEventBox[i]));
}
/* for (int i=0;i<digitCnt();i++)
if (digitsGtk[i]) gtk_widget_destroy(digitsGtk[i]);
*/
if (digitsGtk) delete [] digitsGtk;
/*for (int i=0;i<digitCnt();i++)
if (digitsEventBox[i]) gtk_widget_destroy(digitsEventBox[i]);
*/
if (digitsEventBox) delete [] digitsEventBox;
}
void update(void){
//#if DEBUG > 1
//std::cout <<"FieldInterface::update"<<std::endl;
///*for (int i=0;i<digitCnt();i++)
// std::cout<<digitsGtk[i]<<'\t';
//std::cout<<std::endl;
//*/
//#endif
int which;
for (int i=0;i<digitCnt();i++){
which=field::digits[digitCnt()-i-1];
gtk_pixmap_set(GTK_PIXMAP(digitsGtk[i]), digitsGdk[which], digitsMasks[which]);
}
}
void eventReSetup(GtkSignalFunc func, gpointer data){
// First disconnect the events
for (int i=0; i<digitCnt();i++){
gtk_signal_disconnect_by_func(GTK_OBJECT(digitsEventBox[i]), GTK_SIGNAL_FUNC(digitPress),this);
gtk_signal_connect (GTK_OBJECT(digitsEventBox[i]), "button-release-event", GTK_SIGNAL_FUNC(func), data);
}
}
void eventReSetup(GtkSignalFunc func, GtkSignalFunc oldFunc, gpointer data, gpointer oldData){
// First disconnect the events
for (int i=0; i<digitCnt();i++){
gtk_signal_disconnect_by_func(GTK_OBJECT(digitsEventBox[i]), GTK_SIGNAL_FUNC(oldFunc), oldData);
gtk_signal_connect (GTK_OBJECT(digitsEventBox[i]), "button-release-event", GTK_SIGNAL_FUNC(func), data);
}
}
inline int whichDigit(GtkWidget *widget, unsigned int button){
int cnt=digitCnt(), which=0;
for (int i=0;i<cnt;i++)
if (digitsEventBox[i]==widget){
which =(int)rint(pow(10.0,(double)(cnt-i-1)));
i=cnt;
}
if (button==DOWNBUTTON) return -which;
return which;
}
// The digit press callback function
static int digitPress(GtkWidget *widget, GdkEventButton *event, gpointer data){
//std::cout<<"FieldInterface: digitPress"<<std::endl;
FieldInterface *fi=(FieldInterface *)data;
// Find which digit has been clicked
int which=fi->whichDigit(widget, event->button);
if (which !=0){
if (which>0)
(*fi)+=which;
else
(*fi)-=-which;
}
return which;
}
FieldInterface& operator =(const counter& f){field::operator =(f); update(); return *this;}
FieldInterface& operator =(const int& f){field::operator =(f); update(); return *this;}
FieldInterface& operator+=(const counter& f){field::operator+=(f); update(); return *this;}
FieldInterface& operator+=(const int& f){field::operator+=(f); update(); return *this;}
FieldInterface& operator-=(const counter& f){field::operator-=(f); update(); return *this;}
FieldInterface& operator-=(const int& f){field::operator-=(f); update(); return *this;}
FieldInterface& operator*=(const counter& f){field::operator*=(f); update(); return *this;}
FieldInterface& operator*=(const int& f){field::operator*=(f); update(); return *this;}
FieldInterface& operator/=(const counter& f){field::operator/=(f); update(); return *this;}
FieldInterface& operator/=(const int& f){field::operator/=(f); update(); return *this;}
};
#endif //FIELDINTERFACE_H_
|