Ben,
Would help (a lot) if you posted examples that were complete enough to
actually compile.
Anyway, hacked at your code fragment: see below.
This appears to work fine, so I don't know what is wrong with your code.
Have you asked gdb what it thinks is wrong?
I was getting segfaults from my (initial) attempt to make your code
buildable, so there may be something there...
//
// fltk2-config --compile test.cxx
//
#include <cstdlib>
#include <climits>
#include <cstdio>
#include <cctype>
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Widget.h>
#include <fltk/Button.h>
#include <fltk/Input.h>
#include <fltk/Browser.h>
#include <fltk/TextDisplay.h>
#include <fltk/ask.h>
using namespace fltk;
#define TARGET_LENGTH 9
#define NUM_COLS 3
#define NUM_ROWS 3
#define MIN_LENGTH 4
// input grid is the nine letter grid
class inputGrid {
Input* inbox[TARGET_LENGTH];
void inputCallBack(Input* w);
static void inputCallBack(Widget* w, void* v){
((inputGrid*)v)->inputCallBack((Input*)w); }
public:
inputGrid(int x, int y, int width, int height, const char* label =
0);
bool isLegal();
void setTarget();
};
class TargetWindow : public Window {
inputGrid* inbox;
Button* go;
TextDisplay *outputDisplay;
void buttonCallBack();
static void buttonCallBack(Widget*, void* v){
((TargetWindow*)v)->buttonCallBack();
}
inline void windowCallBack(TargetWindow* v) const {
v->hide();
}
static void windowCallBack(Widget*, void* v) {
((TargetWindow*)v)->windowCallBack((TargetWindow*)v);
}
public:
// constructor
TargetWindow(const char* label) :
Window(USEDEFAULT, USEDEFAULT, 720, 300, label, true)
{
begin();
// inbox is the grid of letters
inbox = new inputGrid(330, 20, 90, 90);
go = new Button(470, 50, 150, 25, "Generate words!");
outputDisplay = new TextDisplay(150, 130, 470, 120, "Valid
words:");
go->callback((Callback*)buttonCallBack, this);
callback(windowCallBack, this);
end();
}
};
// basic cropping of the input boxes and alphabetical sanity checking
void inputGrid::inputCallBack(Input* w) {
char current;
if (w->size() > 1) {
w->cut(w->size() - 1, w->size());
}
if (w->size() > 0) {
current = w->value()[w->size() - 1];
if (!(isalpha(current))) {
w->cut(w->size() - 1, w->size());
}
}
}
// create the input grid
inputGrid::inputGrid (int x, int y, int width, int height, const char*
label) {
int idx;
for (idx = 0; idx < TARGET_LENGTH; idx++) {
if (idx < NUM_COLS) {// first row
inbox[idx] = new Input ((x + ((idx % NUM_COLS) * (width /
NUM_COLS))), y, (width / NUM_COLS), (height / NUM_ROWS));
} else if (idx < (2 * NUM_COLS)) { // second row
if (idx == NUM_COLS) { // first col in second row
inbox[idx] = new Input ((x + ((idx % NUM_COLS) * (width /
NUM_COLS))), (y + (height / NUM_ROWS)), (width / NUM_COLS), (height /
NUM_ROWS), "Input your Target Word here:");
} else {
inbox[idx] = new Input((x + ((idx % NUM_COLS) * (width /
NUM_COLS))), (y + (height / NUM_ROWS)), (width / NUM_COLS), (height /
NUM_ROWS));
}
} else { //third row
inbox[idx] = new Input((x + ((idx % NUM_COLS) * (width /
NUM_COLS))), y + (2 * (height / NUM_ROWS)), (width / NUM_COLS), (height
/ NUM_ROWS));
}
inbox[idx]->callback(inputCallBack, this);
inbox[idx]->when(WHEN_CHANGED);
inbox[idx]->color(BLACK); // cell colours are black
inbox[idx]->textcolor(WHITE); // cell text colours are white
}
inbox[MIN_LENGTH]->color(RED); /* middle grid cell colour is red */
}
// go button callback
void TargetWindow::buttonCallBack(){
int idx;
static int sval = 1;
this->outputDisplay->buffer()->remove(0, INT_MAX);
for (idx = 0; idx < 123; idx++){
char text[15];
sprintf(text, "V %d\n", sval++);
this->outputDisplay->append(text);
}
}
int main(int argc, char **argv) {
TargetWindow win("Browser Example");
win.end();
win.show(argc,argv);
fltk::run();
return 0;
}
/* end of file */
SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14
3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk