[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] gvars3 gvars3/GUI_Fltk2.h gvars3/GUI_Motif.h sr...
From: |
Edward Rosten |
Subject: |
[libcvd-members] gvars3 gvars3/GUI_Fltk2.h gvars3/GUI_Motif.h sr... |
Date: |
Tue, 12 May 2009 16:37:41 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: gvars3
Changes by: Edward Rosten <edrosten> 09/05/12 16:37:41
Modified files:
gvars3 : GUI_Fltk2.h GUI_Motif.h
src : GUI_Fltk.cc GUI_Fltk2.cc GUI_Motif.cc
Log message:
Regularize GUI interface by adding spin and label.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gvars3/gvars3/GUI_Fltk2.h?cvsroot=libcvd&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gvars3/gvars3/GUI_Motif.h?cvsroot=libcvd&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/GUI_Fltk.cc?cvsroot=libcvd&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/GUI_Fltk2.cc?cvsroot=libcvd&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/GUI_Motif.cc?cvsroot=libcvd&r1=1.4&r2=1.5
Patches:
Index: gvars3/GUI_Fltk2.h
===================================================================
RCS file: /cvsroot/libcvd/gvars3/gvars3/GUI_Fltk2.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- gvars3/GUI_Fltk2.h 22 Nov 2005 18:33:27 -0000 1.4
+++ gvars3/GUI_Fltk2.h 12 May 2009 16:37:41 -0000 1.5
@@ -56,6 +56,7 @@
void AddSlider(std::string cmd, std::string args);
void AddSpin(std::string cmd, std::string args);
void AddSmallToggle(std::string cmd, std::string args);
+ void AddLabel(std::string cmd, std::string args);
std::string remove_suffix(std::string cmd, std::string suffix);
bool check_window(std::string win_name, std::string fname);
@@ -84,6 +85,7 @@
static void AddMonitorCB(void*, std::string, std::string);
static void AddSpinCB(void*, std::string, std::string);
static void AddSmallToggleCB(void*, std::string, std::string);
+ static void AddLabelCB(void*, std::string, std::string);
static void* do_stuff_CB(void*);
};
Index: gvars3/GUI_Motif.h
===================================================================
RCS file: /cvsroot/libcvd/gvars3/gvars3/GUI_Motif.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- gvars3/GUI_Motif.h 20 Feb 2008 19:03:58 -0000 1.6
+++ gvars3/GUI_Motif.h 12 May 2009 16:37:41 -0000 1.7
@@ -23,6 +23,7 @@
#define GVARS3_INCLUDE_GUI_MOTIF_H
#include <gvars3/GUI.h>
+#include <list>
#include <Xm/Xm.h>
namespace GVars3
@@ -40,6 +41,8 @@
void AddMonitor(std::string sCommand, std::string sParams);
void AddSlider(std::string sCommand, std::string sParams);
void AddWindow(std::string sParams);
+ void AddLabel(std::string sCommand, std::string sParams);
+ void AddSpin(std::string sCommand, std::string sParams);
void DestroyWindow(std::string sCommand);
void poll();
void start_thread();
@@ -58,10 +61,14 @@
static void AddWindowCB(void*, std::string, std::string);
static void AddToggleButtonCB(void*, std::string, std::string);
static void AddMonitorCB(void*, std::string, std::string);
+ static void AddLabelCB(void*, std::string, std::string);
+ static void AddSpinCB(void*, std::string, std::string);
static void DestroyCB(void*, std::string, std::string);
static void* GUI_Motif_Thread_CB(void* ptr);
static void ButtonHandlerCB(Widget, XtPointer, XtPointer);
void ButtonHandler(Widget, XtPointer);
+ static void TextBoxCB(Widget, XtPointer, XtPointer);
+ void TextBox(Widget, XtPointer);
void GUI_Motif_Thread();
static void RemoveWindowCB(Widget, void*, void*);
@@ -92,6 +99,8 @@
} GUIWindowStruct;
std::map<std::string, GUIWindowStruct> mmWindows;
+ std::list<std::string> labels;
+ std::map<Widget, std::pair<std::string, std::string> > SpinMap;
};
Index: src/GUI_Fltk.cc
===================================================================
RCS file: /cvsroot/libcvd/gvars3/src/GUI_Fltk.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- src/GUI_Fltk.cc 20 Oct 2008 15:47:13 -0000 1.9
+++ src/GUI_Fltk.cc 12 May 2009 16:37:41 -0000 1.10
@@ -272,7 +272,6 @@
GUI.RegisterCommand(vs[0] + ".AddMonitor", AddMonitorCB, this);
GUI.RegisterCommand(vs[0] + ".AddSpin", AddSpinCB, this);
GUI.RegisterCommand(vs[0] + ".AddLabel", AddLabelCB, this);
- //gui->RegisterCommand(vs[0] + ".AddSmallToggleButton",
AddSmallToggleCB, this);
}
void GUI_Fltk::DestroyWindowCB(void* ptr, string cmd, string args)
@@ -296,7 +295,6 @@
GUI.UnRegisterCommand(win_name + ".AddMonitor");
GUI.UnRegisterCommand(win_name + ".AddSpin");
GUI.UnRegisterCommand(win_name + ".AddLabel");
- //gui->UnRegisterCommand(win_name + ".AddSmallToggleButton");
delete windows[win_name].win;
Index: src/GUI_Fltk2.cc
===================================================================
RCS file: /cvsroot/libcvd/gvars3/src/GUI_Fltk2.cc,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- src/GUI_Fltk2.cc 22 Apr 2009 10:10:54 -0000 1.13
+++ src/GUI_Fltk2.cc 12 May 2009 16:37:41 -0000 1.14
@@ -267,6 +267,7 @@
gui->RegisterCommand(vs[0] + ".AddSlider", AddSliderCB, this);
gui->RegisterCommand(vs[0] + ".AddMonitor", AddMonitorCB, this);
gui->RegisterCommand(vs[0] + ".AddSpin", AddSpinCB, this);
+ gui->RegisterCommand(vs[0] + ".AddLabel", AddLabelCB, this);
gui->RegisterCommand(vs[0] + ".AddSmallToggleButton", AddSmallToggleCB,
this);
}
@@ -291,6 +292,7 @@
gui->UnRegisterCommand(win_name + ".AddMonitor");
gui->UnRegisterCommand(win_name + ".AddSpin");
gui->UnRegisterCommand(win_name + ".AddSmallToggleButton");
+ gui->UnRegisterCommand(win_name + ".AddLabel");
windows[win_name].win->destroy();
//delete windows[win_name].win;
@@ -774,6 +776,55 @@
w.win->add(b);
}
+////////////////////////////////////////////////////////////////////////////////
+//
+// Labels
+//
+
+
+void GUI_Fltk2::AddLabelCB(void* ptr, string cmd, string args)
+{
+ fltk::lock();
+ UI.AddLabel(cmd, args);
+ fltk::unlock();
+}
+
+class label: public fltk::Widget
+{
+ public:
+ label(string t)
+ :fltk::Widget(0, 0, 1, 1), title(t)
+ {
+ align(fltk::ALIGN_CENTER);
+ fltk::Widget::label(title.c_str());
+ }
+ private:
+ string title;
+};
+
+
+void GUI_Fltk2::AddLabel(string cmd, string args)
+{
+ string win_name = remove_suffix(cmd, ".AddLabel");
+
+ vector<string> vs = ChopAndUnquoteString(args);
+ if(vs.size() != 1)
+ {
+ cout << "! GUI_Fltk::AddLabel: Need 1 params (label)." << endl;
+ return;
+ }
+
+ if(!check_window(win_name, "AddLabel"))
+ return;
+
+ window& w = windows[win_name];
+
+ fltk::Widget* m = new label(vs[0]);
+ w.win->add(m);
+}
+
+
+
//Instantiations
class GUI_Fltk2 GUI_Fltk2_instance(&GUI, &GV2);
Index: src/GUI_Motif.cc
===================================================================
RCS file: /cvsroot/libcvd/gvars3/src/GUI_Motif.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- src/GUI_Motif.cc 20 Feb 2008 19:03:59 -0000 1.4
+++ src/GUI_Motif.cc 12 May 2009 16:37:41 -0000 1.5
@@ -27,6 +27,7 @@
#include <Xm/Label.h>
#include <Xm/ScrollBar.h>
#include <Xm/ToggleB.h>
+#include <Xm/TextF.h>
#include <Xm/Protocols.h>
#include <Xm/AtomMgr.h>
#include <pthread.h>
@@ -47,12 +48,12 @@
}
-void GUI_Motif::InitXInterfaceCB(void* ptr, string sCommand, string sParams)
+void GUI_Motif::InitXInterfaceCB(void* ptr, string , string sParams)
{
((GUI_Motif*)(ptr))->InitXInterface(sParams);
}
-void GUI_Motif::AddWindowCB(void* ptr, string sCommand, string sParams)
+void GUI_Motif::AddWindowCB(void* ptr, string , string sParams)
{
((GUI_Motif*)(ptr))->AddWindow(sParams);
}
@@ -106,8 +107,6 @@
pthread_mutex_lock((pthread_mutex_t*)mpMutex);
- int argc=1;
- char* argv[] = {""};
Arg al[10];
int ac = 0;
gws.wTopLevel=XtAppCreateShell(sCaption.c_str(), sCaption.c_str(),
applicationShellWidgetClass, mpDisplay, al, ac);
@@ -119,7 +118,7 @@
XtSetArg(al[ac], XmNresizeHeight, True); ac++;
XtSetArg(al[ac], XmNresizeWidth, False); ac++;
- gws.wRowCol=XmCreateRowColumn(gws.wTopLevel,"GUI_Motif_rowcol",al,ac);
+ gws.wRowCol=XmCreateRowColumn(gws.wTopLevel,("GUI_Motif_rowcol"),al,ac);
XtManageChild(gws.wRowCol);
XtRealizeWidget(gws.wTopLevel);
@@ -134,7 +133,7 @@
Atom delwinAtom1;
- delwinAtom1 = XmInternAtom (mpDisplay,"WM_DELETE_WINDOW", False);
+ delwinAtom1 = XmInternAtom (mpDisplay,("WM_DELETE_WINDOW"), False);
XmAddWMProtocolCallback (gws.wTopLevel, delwinAtom1, RemoveWindowCB, this);
XtVaSetValues(gws.wTopLevel, XmNdeleteResponse, XmDO_NOTHING, NULL);
@@ -143,7 +142,9 @@
mpGUI->RegisterCommand(vs[0] + ".AddPushButton", AddPushButtonCB, this);
mpGUI->RegisterCommand(vs[0] + ".AddToggleButton", AddToggleButtonCB, this);
mpGUI->RegisterCommand(vs[0] + ".AddMonitor", AddMonitorCB, this);
+ mpGUI->RegisterCommand(vs[0] + ".AddLabel", AddLabelCB, this);
mpGUI->RegisterCommand(vs[0] + ".AddSlider", AddSliderCB, this);
+ mpGUI->RegisterCommand(vs[0] + ".AddSpin", AddSpinCB, this);
mpGUI->RegisterCommand(vs[0] + ".Destroy", DestroyCB, this);
pthread_mutex_unlock((pthread_mutex_t*)mpMutex);
@@ -184,9 +185,7 @@
// Ok, set up some widgets!
int argc=1;
- char* argv[] = {""};
- Arg al[10];
- int ac = 0;
+ char* argv[] = {0};
XtToolkitInitialize();
mxtac=XtCreateApplicationContext();
@@ -219,12 +218,12 @@
}
-void GUI_Motif::RemoveWindowCB(Widget w, void* client_data, void* call_data)
+void GUI_Motif::RemoveWindowCB(Widget w, void* client_data, void* )
{
((GUI_Motif *) client_data)->RemoveWindow(w);
}
-void GUI_Motif::DestroyCB(void* ptr, string sCommand, string sParams)
+void GUI_Motif::DestroyCB(void* ptr, string sCommand, string)
{
((GUI_Motif*)(ptr))->DestroyWindow(sCommand);
}
@@ -237,6 +236,7 @@
mpGUI->UnRegisterCommand(sWindowName + ".AddPushButton");
mpGUI->UnRegisterCommand(sWindowName + ".AddToggleButton");
mpGUI->UnRegisterCommand(sWindowName + ".AddMonitor");
+ mpGUI->UnRegisterCommand(sWindowName + ".AddLabel");
mpGUI->UnRegisterCommand(sWindowName + ".Destroy");
XtUnrealizeWidget(mmWindows[sWindowName].wTopLevel);
mmWindows.erase(sWindowName);
@@ -244,6 +244,10 @@
};
+////////////////////////////////////////////////////////////////////////////////
+//
+// Push buttons
+//
void GUI_Motif::AddPushButtonCB(void* ptr, string sCommand, string sParams)
{
@@ -262,8 +266,6 @@
};
- Widget *pwTopLevel;
- Widget *pwRowCol;
string sWindowName = sCommand;
string sCommandSuffix(".AddPushButton");
@@ -308,6 +310,105 @@
}
+////////////////////////////////////////////////////////////////////////////////
+//
+// Text input boxes
+//
+
+void GUI_Motif::AddSpinCB(void* ptr, string sCommand, string sParams)
+{
+ ((GUI_Motif*)(ptr))->AddSpin(sCommand, sParams);
+}
+
+
+void GUI_Motif::AddSpin(string sCommand, string sParams)
+{
+
+ vector<string> vs = ChopAndUnquoteString(sParams);
+ if(vs.size() < 3 || vs.size() > 4)
+ {
+ cout << "! GUI_Motif::AddSpin: Need 3--4 params (gvar, min, max [,
title])." << endl;
+ return;
+ };
+
+
+ string sWindowName = sCommand;
+ string sCommandSuffix(".AddSpin");
+ sWindowName.resize(sCommand.length() - sCommandSuffix.length());
+ Widget w;
+
+ Arg al[10];
+ int ac = 0;
+ char szName[1000];
+ for(int i=0;i<1000;i++) szName[i]=0;
+ vs[0].copy(szName,999);
+
+ pthread_mutex_lock((pthread_mutex_t*)mpMutex);
+
+
+ w = XmCreateTextField(mmWindows[sWindowName].wRowCol, szName,al,ac);
+ SpinMap[w] = make_pair(vs[0], string(""));
+ XtManageChild(w);
+
+ XtAddCallback(w, XmNvalueChangedCallback, TextBoxCB, this);
+
+ XWindowAttributes window_attributes_return;
+ XGetWindowAttributes(mpDisplay, XtWindow(w), &window_attributes_return);
+ int nButtonHeight = window_attributes_return.height;
+ XGetWindowAttributes(mpDisplay, XtWindow(mmWindows[sWindowName].wTopLevel),
&window_attributes_return);
+ mmWindows[sWindowName].nWidth = (mmWindows[sWindowName].nWidth >
window_attributes_return.width) ? mmWindows[sWindowName].nWidth :
window_attributes_return.width;
+ mmWindows[sWindowName].nHeight = (mmWindows[sWindowName].nHeight >
window_attributes_return.height) ? mmWindows[sWindowName].nHeight :
window_attributes_return.height;
+ mmWindows[sWindowName].nHeight += (nButtonHeight + 3);
+ XResizeWindow(mpDisplay, XtWindow(mmWindows[sWindowName].wTopLevel),
+ mmWindows[sWindowName].nWidth,
+ mmWindows[sWindowName].nHeight);
+ DoMotifEvents();
+ pthread_mutex_unlock((pthread_mutex_t*)mpMutex);
+
+}
+
+void GUI_Motif::TextBoxCB(Widget w, XtPointer ptrMe, XtPointer xtpCall)
+{
+ ((GUI_Motif*)ptrMe) -> TextBox(w, xtpCall);
+}
+
+
+
+// Handles the actual callback work
+void GUI_Motif::TextBox(Widget w, XtPointer xtpCall)
+{
+
+ if(SpinMap.count(w))
+ {
+ char* c;
+ XmTextPosition p;
+ XtVaGetValues(w, XmNvalue, &c, XmNcursorPosition, &p, NULL);
+
+ string cs(c);
+ if(cs == "")
+ cs = "0";
+
+ p=1;
+
+ GV3::set_var(SpinMap[w].first, cs.c_str());
+ string s = GV3::get_var(SpinMap[w].first);
+
+ if(s != c)
+ {
+ SpinMap[w].second = s;
+ XtRemoveCallback(w, XmNvalueChangedCallback, TextBoxCB, this);
+ p = min((int)p, (int)s.size());
+ XtVaSetValues(w, XmNvalue, s.c_str(), XmNcursorPosition, p, NULL);
+ XtAddCallback(w, XmNvalueChangedCallback, TextBoxCB, this);
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+//
+//
+
void GUI_Motif::AddToggleButtonCB(void* ptr, string sCommand, string sParams)
{
((GUI_Motif*)(ptr))->AddToggleButton(sCommand, sParams);
@@ -339,10 +440,12 @@
tms.sName = vs[0];
int nDefault = 0;
if(vs.size()==3)
+ {
if(vs[2]=="true")
nDefault = 1;
else
nDefault = 0;
+ }
mpGV2->Register(tms.gvn,vs[1],nDefault,true);
tms.nCache = *tms.gvn;
@@ -378,7 +481,10 @@
}
-
+////////////////////////////////////////////////////////////////////////////////
+//
+// Monitor
+//
void GUI_Motif::AddMonitorCB(void* ptr, string sCommand, string sParams)
{
((GUI_Motif*)(ptr))->AddMonitor(sCommand, sParams);
@@ -452,6 +558,58 @@
}
+////////////////////////////////////////////////////////////////////////////////
+//
+// Label
+//
+void GUI_Motif::AddLabelCB(void* ptr, string sCommand, string sParams)
+{
+ ((GUI_Motif*)(ptr))->AddLabel(sCommand, sParams);
+}
+
+
+void GUI_Motif::AddLabel(string sCommand, string sParams)
+{
+ if(!mpDisplay)
+ {
+ cout << "! GUI_Motif::AddMonitor: GUI_Motif not initialised. " << endl;
+ return;
+ }
+ vector<string> vs = ChopAndUnquoteString(sParams);
+ if(vs.size() != 1)
+ {
+ cout << "! GUI_Motif::AddMonitor: Need 1 params: label " << endl;
+ return;
+ };
+ string sWindowName = sCommand;
+ string sCommandSuffix(".AddLabel");
+ sWindowName.resize(sCommand.length() - sCommandSuffix.length());
+
+ pthread_mutex_lock((pthread_mutex_t*)mpMutex);
+
+ labels.push_back(vs[0]);
+
+ Widget w;
+ Arg al[10];
+ int ac = 0;
+ w =
XmCreateLabel(mmWindows[sWindowName].wRowCol,const_cast<char*>(labels.back().c_str()),al,ac);
+ XtManageChild(w);
+
+ XWindowAttributes window_attributes_return;
+ XGetWindowAttributes(mpDisplay, XtWindow(w), &window_attributes_return);
+ int nButtonHeight = window_attributes_return.height;
+ XGetWindowAttributes(mpDisplay, XtWindow(mmWindows[sWindowName].wTopLevel),
&window_attributes_return);
+ mmWindows[sWindowName].nWidth = (mmWindows[sWindowName].nWidth >
window_attributes_return.width) ? mmWindows[sWindowName].nWidth :
window_attributes_return.width;
+ mmWindows[sWindowName].nHeight = (mmWindows[sWindowName].nHeight >
window_attributes_return.height) ? mmWindows[sWindowName].nHeight :
window_attributes_return.height;
+ mmWindows[sWindowName].nHeight += (nButtonHeight + 3);
+ XResizeWindow(mpDisplay, XtWindow(mmWindows[sWindowName].wTopLevel),
+ mmWindows[sWindowName].nWidth,
+ mmWindows[sWindowName].nHeight);
+ DoMotifEvents();
+ pthread_mutex_unlock((pthread_mutex_t*)mpMutex);
+
+}
+
void GUI_Motif::AddSliderCB(void* ptr, string sCommand, string sParams)
{
@@ -593,8 +751,7 @@
ost << (dRawValue / 300.0) * (sms.dMax-sms.dMin) + sms.dMin;
mpGV2->SetVar(sms.sVarName, ost.str(), 1);
sms.sCachedValue = mpGV2->StringValue(sms.sVarName);
- };
- //
+ }
};
}
@@ -672,11 +829,28 @@
};
DoMotifEvents();
+ for(map<Widget, pair<string, string> >::iterator i=SpinMap.begin(); i !=
SpinMap.end(); i++)
+ {
+ if(i->second.second != GV3::get_var(i->second.first))
+ {
+ XmTextPosition p;
+ XtVaGetValues(i->first, XmNcursorPosition, &p, NULL);
+
+ string s = GV3::get_var(i->second.first);
+
+ i->second.second = s;
+ XtRemoveCallback(i->first, XmNvalueChangedCallback, TextBoxCB,
this);
+ p = min((int)p, (int)s.size());
+ XtVaSetValues(i->first, XmNvalue, s.c_str(), XmNcursorPosition,
p, NULL);
+ XtAddCallback(i->first, XmNvalueChangedCallback, TextBoxCB, this);
+ }
+ }
}
void* GUI_Motif::GUI_Motif_Thread_CB(void* ptr)
{
((GUI_Motif*) ptr)->GUI_Motif_Thread();
+ return 0;
}
void GUI_Motif::DoMotifEvents()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] gvars3 gvars3/GUI_Fltk2.h gvars3/GUI_Motif.h sr...,
Edward Rosten <=