Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved editor widget #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_executable (${PROJECT_NAME} ${PLATFORM}
datablock.cpp
datafile.cpp
exportdlg.cpp
FXEditor.cpp
FXFileDialogEx.cpp
fxhelper.cpp
FXMenuSeparatorEx.cpp
Expand Down
22 changes: 22 additions & 0 deletions FXEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "FXEditor.h"

FXDEFMAP(FXEditor) MessageMap[]=
{
FXMAPFUNC(SEL_KEYPRESS, 0, FXEditor::onKeyPress)
};

FXIMPLEMENT(FXEditor, FXText, MessageMap, ARRAYNUMBER(MessageMap))

FXEditor::FXEditor(FXComposite *p, FXObject * tgt, FXSelector sel,
FXuint opts, FXint x, FXint y, FXint w, FXint h) :
FXText(p, tgt, sel, opts, x, y, w, h)
{
};

long FXEditor::onKeyPress(FXObject *sender, FXSelector sel, void *ptr)
{
if (isEnabled()) {
FXEvent* event=(FXEvent*)ptr;
}
return FXText::onKeyPress(sender, sel, ptr);
}
20 changes: 20 additions & 0 deletions FXEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <fx.h>
#include <FXText.h>

class FXEditor: public FXText {

FXDECLARE(FXEditor)

public:
FXEditor(FXComposite *p, FXObject * tgt=NULL, FXSelector sel=0,
FXuint opts = 0, FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0);
virtual ~FXEditor() {}

virtual long onKeyPress(FXObject *sender, FXSelector sel, void *ptr);
protected:
FXEditor() {};
FXEditor(const FXEditor&) {};
};

35 changes: 28 additions & 7 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ FXDEFMAP(FXCommands) MessageMap[]=
FXMAPFUNC(SEL_UPDATE, FXCommands::ID_ROWCOL, FXCommands::updRowCol),
};

FXIMPLEMENT(FXCommands,FXText,MessageMap, ARRAYNUMBER(MessageMap))
FXIMPLEMENT(FXCommands,FXEditor,MessageMap, ARRAYNUMBER(MessageMap))

FXCommands::FXCommands(FXComposite* p, FXObject* tgt,FXSelector sel, FXuint opts, FXint x,FXint y,FXint w,FXint h)
: FXText(p, tgt,sel, opts, x,y,w,h)
: FXEditor(p, tgt,sel, opts, x,y,w,h)
{
// initial visible rows & tab stop
setVisibleRows(6);
Expand All @@ -42,7 +42,7 @@ FXCommands::FXCommands(FXComposite* p, FXObject* tgt,FXSelector sel, FXuint opts
textStyles[i].selectForeColor = getApp()->getSelforeColor();
textStyles[i].selectBackColor = getApp()->getSelbackColor();
textStyles[i].hiliteForeColor = getApp()->getHiliteColor();
textStyles[i].hiliteBackColor = FXRGB(255, 128, 128); // from FXText.cpp
textStyles[i].hiliteBackColor = FXRGB(255, 128, 128); // from FXEditor.cpp
textStyles[i].activeBackColor = getApp()->getBackColor();
textStyles[i].style = 0; // no underline, italic, bold
}
Expand Down Expand Up @@ -79,7 +79,7 @@ FXCommands::FXCommands(FXComposite* p, FXObject* tgt,FXSelector sel, FXuint opts

void FXCommands::create()
{
FXText::create();
FXEditor::create();
disable();
setBackColor(getApp()->getBaseColor());
}
Expand Down Expand Up @@ -234,7 +234,28 @@ long FXCommands::onKeyPress(FXObject* sender,FXSelector sel,void* ptr)
{
FXEvent* event=(FXEvent*)ptr;
if (!isEnabled())
return FXText::onKeyPress(sender, sel, ptr);
return FXEditor::onKeyPress(sender, sel, ptr);
else if (event->code == KEY_Return || event->code == KEY_KP_Enter)
{
// Keeps the indentation level, when you go to the next line
int curs = getCursorPos();
int begin = lineStart(curs);

FXString line;
extractText(line, begin, curs-begin);

int pos = line.find_first_not_of(" \t");
if (pos != -1)
line.erase(pos, line.length() - pos);

if (!line.empty())
{
long res = FXEditor::onKeyPress(sender, sel, ptr);
if (res)
insertText(lineStart(getCursorPos()), line);
return res;
}
}
else if (event->code == KEY_Tab || event->code == KEY_KP_Tab)
{
int curs = getCursorPos();
Expand All @@ -255,7 +276,7 @@ long FXCommands::onKeyPress(FXObject* sender,FXSelector sel,void* ptr)
return 1;
}
}
return FXText::onKeyPress(sender, sel, ptr);
return FXEditor::onKeyPress(sender, sel, ptr);
}

long FXCommands::onUpdate(FXObject* sender,FXSelector sel,void* ptr)
Expand All @@ -266,7 +287,7 @@ long FXCommands::onUpdate(FXObject* sender,FXSelector sel,void* ptr)
saveCommands();
}
mapShowRoute();
return FXText::onUpdate(sender, sel, ptr);
return FXEditor::onUpdate(sender, sel, ptr);
}

long FXCommands::updConfirmed(FXObject* sender, FXSelector, void*) {
Expand Down
6 changes: 4 additions & 2 deletions commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

#include <fx.h>

#include "FXEditor.h"

#include <vector>

class FXCommands : public FXText
class FXCommands : public FXEditor
{
FXDECLARE(FXCommands)

Expand Down Expand Up @@ -42,7 +44,7 @@ class FXCommands : public FXText
public:
enum
{
ID_ROWCOL = FXText::ID_LAST,
ID_ROWCOL = FXEditor::ID_LAST,
ID_UNIT_CONFIRM,
ID_UNIT_ADD,
ID_LAST
Expand Down
Loading