Skip to content

Commit

Permalink
Custom Widgets.
Browse files Browse the repository at this point in the history
  • Loading branch information
deech committed Mar 3, 2017
1 parent 4bb3c07 commit d97b613
Show file tree
Hide file tree
Showing 117 changed files with 8,754 additions and 1,120 deletions.
96 changes: 85 additions & 11 deletions c-src/DerivedText_Editor.cpp
Expand Up @@ -5,13 +5,24 @@
DerivedText_Editor::Key_Binding_With_Callback* DerivedText_Editor::global_key_bindings = 0;
#endif

DerivedText_Editor::DerivedText_Editor(int X, int Y, int W, int H, const char *l, fl_Widget_Virtual_Funcs* funcs) : Fl_Text_Editor(X,Y,W,H,l){
overriddenFuncs = funcs;
other_data = (void*)0;
}
DerivedText_Editor::DerivedText_Editor(int X, int Y, int W, int H, fl_Widget_Virtual_Funcs* funcs):Fl_Text_Editor(X,Y,W,H){
overriddenFuncs = funcs;
other_data = (void*)0;
}
DerivedText_Editor::~DerivedText_Editor(){
free(overriddenFuncs);
}
DerivedText_Editor::DerivedText_Editor(int x,int y,int w,int h,const char* t) : Fl_Text_Editor(x,y,w,h,t){
key_bindings = 0;
key_bindings = get_default_keybindings();
curr_callback_context = 0;
default_callback_context_ = 0;
default_key_function_ = C_to_Fl_Callback::intercept;
}
key_bindings = 0;
key_bindings = get_default_keybindings();
curr_callback_context = 0;
default_callback_context_ = 0;
default_key_function_ = C_to_Fl_Callback::intercept;
}
C_to_Fl_Callback* DerivedText_Editor::get_curr_callback_context(){
return curr_callback_context;
}
Expand All @@ -34,9 +45,9 @@ void DerivedText_Editor::replace_key_bindings(Key_Binding_With_Callback** l) {
replace_key_bindings(&key_bindings, l);
}
void DerivedText_Editor::add_key_binding(int key,
int state,
C_to_Fl_Callback* callback_context,
Key_Binding_With_Callback** list){
int state,
C_to_Fl_Callback* callback_context,
Key_Binding_With_Callback** list){
Key_Binding_With_Callback* curr = *list;
// iterate to the last binding
while(curr->next){curr = curr->next;}
Expand Down Expand Up @@ -94,7 +105,7 @@ void DerivedText_Editor::remove_key_binding(int key, int state, Key_Binding_With
Key_Binding_With_Callback* curr = *list;
Key_Binding_With_Callback* last = NULL;
for (;curr;last = curr, curr = curr->next){
if (curr->key == key && curr->state == state) break;
if (curr->key == key && curr->state == state) break;
}
if (!curr) return;
if (last) last->next = curr->next;
Expand Down Expand Up @@ -127,7 +138,7 @@ int DerivedText_Editor::handle_key(){
if (Fl::compose_state) {
int pos = this->insert_position();
this->buffer()->select(pos - Fl::compose_state, pos);
}
}
#endif
show_insert_position();
set_changed();
Expand All @@ -145,3 +156,66 @@ int DerivedText_Editor::handle_key(){
if (default_key_function_ && !state) return default_key_function_(c, this);
return 0;
}

void DerivedText_Editor::draw(){
if (this->overriddenFuncs->draw != NULL) {
this->overriddenFuncs->draw((fl_Text_Editor) this);
}
else {
Fl_Text_Editor::draw();
}
}

void DerivedText_Editor::draw_super(){
Fl_Text_Editor::draw();
}

int DerivedText_Editor::handle(int event){
int i;
if (this->overriddenFuncs->handle != NULL) {
i = this->overriddenFuncs->handle((fl_Text_Editor) this,event);
}
else {
i = Fl_Text_Editor::handle(event);
}
return i;
}
int DerivedText_Editor::handle_super(int event){
return Fl_Text_Editor::handle(event);
}

void DerivedText_Editor::resize(int x, int y, int w, int h){
if (this->overriddenFuncs->resize != NULL) {
this->overriddenFuncs->resize((fl_Text_Editor) this,x,y,w,h);
}
else {
Fl_Text_Editor::resize(x,y,w,h);
}
}

void DerivedText_Editor::resize_super(int x, int y, int w, int h){
Fl_Text_Editor::resize(x,y,w,h);
}
void DerivedText_Editor::show(){
if (this->overriddenFuncs->show != NULL) {
this->overriddenFuncs->show((fl_Text_Editor) this);
}
else {
Fl_Text_Editor::show();
}
}
void DerivedText_Editor::show_super(){
Fl_Text_Editor::show();
}

void DerivedText_Editor::hide(){
if (this->overriddenFuncs->hide != NULL) {
this->overriddenFuncs->hide((fl_Text_Editor) this);
}
else {
Fl_Text_Editor::hide();
}
}
void DerivedText_Editor::hide_super(){
Fl_Text_Editor::hide();
}
22 changes: 18 additions & 4 deletions c-src/DerivedText_Editor.h
Expand Up @@ -2,12 +2,14 @@
#define __DERIVEDTEXT_EDITOR__
#include "FL/Fl.H"
#include "FL/Fl_Text_Editor.H"

#include "Fl_Types.h"
class C_to_Fl_Callback;

class DerivedText_Editor : public Fl_Text_Editor {
private:
C_to_Fl_Callback* curr_callback_context;
fl_Widget_Virtual_Funcs* overriddenFuncs;
void* other_data;
public:
typedef int (*Key_Func)(int key, DerivedText_Editor* editor);
struct Key_Binding_With_Callback {
Expand All @@ -32,10 +34,10 @@ class DerivedText_Editor : public Fl_Text_Editor {

// Unlike Fl_Text_Editor a new binding is appended rather than prepended
void add_key_binding(int key, int state, C_to_Fl_Callback* callback_context,
Key_Binding_With_Callback** list);
Key_Binding_With_Callback** list);

void add_key_binding(Key_Binding_With_Callback* new_bindings,
Key_Binding_With_Callback** old_bindings){
Key_Binding_With_Callback** old_bindings){
Key_Binding_With_Callback* curr = *old_bindings;
// iterate to the last binding
while(curr->next){curr = curr->next;}
Expand All @@ -58,11 +60,23 @@ class DerivedText_Editor : public Fl_Text_Editor {
C_to_Fl_Callback* get_curr_callback_context();
C_to_Fl_Callback* get_default_callback_context();
DerivedText_Editor(int x,int y,int w,int h,const char* t=0);
DerivedText_Editor(int X, int Y, int W, int H, const char *l, fl_Widget_Virtual_Funcs* funcs);
DerivedText_Editor(int X, int Y, int W, int H, fl_Widget_Virtual_Funcs* funcs);
virtual void draw();
void draw_super();
virtual int handle(int event);
int handle_super(int event);
virtual void resize(int x, int y, int w, int h);
void resize_super(int x, int y, int w, int h);
virtual void show();
void show_super();
virtual void hide();
void hide_super();
~DerivedText_Editor();
protected:
int handle_key();
Key_Func default_key_function_;
static Key_Binding_With_Callback* global_key_bindings;
C_to_Fl_Callback* default_callback_context_;
};

#endif /* __DERIVEDTEXT_EDITOR__ */
144 changes: 125 additions & 19 deletions c-src/Fl_AdjusterC.cpp
@@ -1,7 +1,81 @@
#include "Fl_AdjusterC.h"
#ifdef __cplusplus
EXPORT {
#endif
Fl_DerivedAdjuster::Fl_DerivedAdjuster(int X, int Y, int W, int H, const char *l, fl_Widget_Virtual_Funcs* funcs) : Fl_Adjuster(X,Y,W,H,l){
overriddenFuncs = funcs;
other_data = (void*)0;
}
Fl_DerivedAdjuster::Fl_DerivedAdjuster(int X, int Y, int W, int H, fl_Widget_Virtual_Funcs* funcs):Fl_Adjuster(X,Y,W,H){
overriddenFuncs = funcs;
other_data = (void*)0;
}
Fl_DerivedAdjuster::~Fl_DerivedAdjuster(){
free(overriddenFuncs);
}
void Fl_DerivedAdjuster::draw(){
if (this->overriddenFuncs->draw != NULL) {
this->overriddenFuncs->draw((fl_Adjuster) this);
}
else {
Fl_Adjuster::draw();
}
}

void Fl_DerivedAdjuster::draw_super(){
Fl_Adjuster::draw();
}

int Fl_DerivedAdjuster::handle(int event){
int i;
if (this->overriddenFuncs->handle != NULL) {
i = this->overriddenFuncs->handle((fl_Adjuster) this,event);
}
else {
i = Fl_Adjuster::handle(event);
}
return i;
}
int Fl_DerivedAdjuster::handle_super(int event){
return Fl_Adjuster::handle(event);
}

void Fl_DerivedAdjuster::resize(int x, int y, int w, int h){
if (this->overriddenFuncs->resize != NULL) {
this->overriddenFuncs->resize((fl_Adjuster) this,x,y,w,h);
}
else {
Fl_Adjuster::resize(x,y,w,h);
}
}

void Fl_DerivedAdjuster::resize_super(int x, int y, int w, int h){
Fl_Adjuster::resize(x,y,w,h);
}
void Fl_DerivedAdjuster::show(){
if (this->overriddenFuncs->show != NULL) {
this->overriddenFuncs->show((fl_Adjuster) this);
}
else {
Fl_Adjuster::show();
}
}
void Fl_DerivedAdjuster::show_super(){
Fl_Adjuster::show();
}

void Fl_DerivedAdjuster::hide(){
if (this->overriddenFuncs->hide != NULL) {
this->overriddenFuncs->hide((fl_Adjuster) this);
}
else {
Fl_Adjuster::hide();
}
}
void Fl_DerivedAdjuster::hide_super(){
Fl_Adjuster::hide();
}

#endif
FL_EXPORT_C(fl_Group,Fl_Adjuster_parent)(fl_Adjuster adjuster){
return (static_cast<Fl_Adjuster*>(adjuster))->parent();
}
Expand Down Expand Up @@ -152,12 +226,6 @@ EXPORT {
FL_EXPORT_C(int,Fl_Adjuster_visible_r)(fl_Adjuster adjuster){
return (static_cast<Fl_Adjuster*>(adjuster))->visible_r();
}
FL_EXPORT_C(void,Fl_Adjuster_show)(fl_Adjuster adjuster){
(static_cast<Fl_Adjuster*>(adjuster))->show();
}
FL_EXPORT_C(void,Fl_Adjuster_hide)(fl_Adjuster adjuster){
(static_cast<Fl_Adjuster*>(adjuster))->hide();
}
FL_EXPORT_C(void,Fl_Adjuster_set_visible)(fl_Adjuster adjuster){
(static_cast<Fl_Adjuster*>(adjuster))->visible();
}
Expand Down Expand Up @@ -254,9 +322,6 @@ EXPORT {
FL_EXPORT_C(fl_Gl_Window,Fl_Adjuster_as_gl_window)(fl_Adjuster adjuster){
return (static_cast<Fl_Adjuster*>(adjuster))->as_gl_window();
}
FL_EXPORT_C(void,Fl_Adjuster_resize)(fl_Adjuster adjuster,int X,int Y,int W,int H){
(static_cast<Fl_Adjuster*>(adjuster))->resize(X,Y,W,H);
}
FL_EXPORT_C(void,Fl_Adjuster_bounds)(fl_Adjuster adjuster,double a,double b){
(static_cast<Fl_Adjuster*>(adjuster))->bounds(a,b);
}
Expand Down Expand Up @@ -308,14 +373,6 @@ EXPORT {
FL_EXPORT_C(double,Fl_Adjuster_increment)(fl_Adjuster adjuster,double v,int n){
return (static_cast<Fl_Adjuster*>(adjuster))->increment(v,n);
}
FL_EXPORT_C(fl_Adjuster,Fl_Adjuster_New_WithLabel)(int x,int y,int w,int h,const char* label){
Fl_Adjuster* adjuster = new Fl_Adjuster(x,y,w,h,label);
return (fl_Adjuster) adjuster;
}
FL_EXPORT_C(fl_Adjuster,Fl_Adjuster_New)(int x,int y,int w,int h){
Fl_Adjuster* adjuster = new Fl_Adjuster(x,y,w,h);
return (fl_Adjuster) adjuster;
}
FL_EXPORT_C(void,Fl_Adjuster_Destroy)(fl_Adjuster adjuster){
delete (static_cast<Fl_Adjuster*>(adjuster));
}
Expand All @@ -325,6 +382,55 @@ EXPORT {
FL_EXPORT_C(void,Fl_Adjuster_set_soft)(fl_Adjuster adjuster,int soft){
(static_cast<Fl_Adjuster*>(adjuster))->soft(soft);
}
FL_EXPORT_C(fl_Adjuster, Fl_Adjuster_New)(int X, int Y, int W, int H){
fl_Widget_Virtual_Funcs* fs = Fl_Widget_default_virtual_funcs();
Fl_DerivedAdjuster* w = new Fl_DerivedAdjuster(X,Y,W,H,fs);
return (fl_Adjuster)w;
}
FL_EXPORT_C(fl_Adjuster, Fl_Adjuster_New_WithLabel)(int X, int Y, int W, int H, const char* label){
fl_Widget_Virtual_Funcs* fs = Fl_Widget_default_virtual_funcs();
Fl_DerivedAdjuster* w = new Fl_DerivedAdjuster(X,Y,W,H,label,fs);
return (fl_Adjuster)w;
}
FL_EXPORT_C(fl_Adjuster, Fl_OverriddenAdjuster_New)(int X, int Y, int W, int H,fl_Widget_Virtual_Funcs* fs){
Fl_DerivedAdjuster* w = new Fl_DerivedAdjuster(X,Y,W,H,fs);
return (fl_Adjuster)w;
}
FL_EXPORT_C(fl_Adjuster, Fl_OverriddenAdjuster_New_WithLabel)(int X, int Y, int W, int H, const char* label, fl_Widget_Virtual_Funcs* fs){
Fl_DerivedAdjuster* w = new Fl_DerivedAdjuster(X,Y,W,H,label,fs);
return (fl_Adjuster)w;
}
FL_EXPORT_C(void, Fl_Adjuster_draw)(fl_Adjuster o){
(static_cast<Fl_DerivedAdjuster*>(o))->draw();
}
FL_EXPORT_C(void, Fl_Adjuster_draw_super)(fl_Adjuster o){
(static_cast<Fl_DerivedAdjuster*>(o))->draw_super();
}
FL_EXPORT_C(int, Fl_Adjuster_handle)(fl_Adjuster o, int event){
return (static_cast<Fl_DerivedAdjuster*>(o))->handle(event);
}
FL_EXPORT_C(int, Fl_Adjuster_handle_super)(fl_Adjuster o, int event){
return (static_cast<Fl_DerivedAdjuster*>(o))->handle_super(event);
}
FL_EXPORT_C(void, Fl_Adjuster_resize)(fl_Adjuster o, int x, int y, int w, int h){
(static_cast<Fl_DerivedAdjuster*>(o))->resize(x,y,w,h);
}
FL_EXPORT_C(void, Fl_Adjuster_resize_super)(fl_Adjuster o, int x, int y, int w, int h){
(static_cast<Fl_DerivedAdjuster*>(o))->resize_super(x,y,w,h);
}
FL_EXPORT_C(void, Fl_Adjuster_show)(fl_Adjuster o){
(static_cast<Fl_DerivedAdjuster*>(o))->show();
}
FL_EXPORT_C(void, Fl_Adjuster_show_super)(fl_Adjuster o){
(static_cast<Fl_DerivedAdjuster*>(o))->show_super();
}
FL_EXPORT_C(void, Fl_Adjuster_hide)(fl_Adjuster o){
(static_cast<Fl_DerivedAdjuster*>(o))->hide();
}
FL_EXPORT_C(void, Fl_Adjuster_hide_super)(fl_Adjuster o){
(static_cast<Fl_DerivedAdjuster*>(o))->hide_super();
}

#ifdef __cplusplus
}
#endif
#endif

0 comments on commit d97b613

Please sign in to comment.