-
Notifications
You must be signed in to change notification settings - Fork 1
/
alifstudio.cpp
6451 lines (5184 loc) · 183 KB
/
alifstudio.cpp
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* - - - - - - - - - - - - - - - - - - - - -
* The Alif Arabic Programming Language
*
* Alif Studio 2 (IDE)
* (C)2018-2020 Hassan DRAGA.
* www.aliflang.org
* - - - - - - - - - - - - - - - - - - - - -
*/
/*
- This file is part of the Alif Studio 2 project (https://github.com/hassandraga/alif).
- Copyright (C) 2018-2020 Hassan DRAGA.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, version 3.
-
- This program 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// ------------------------------------------------
#define UNICODE
#define _UNICODE
#define wxDEBUG_LEVEL 0
#define wxUSE_UNICODE_MSLU 1
#if __APPLE__
// Fix: /include/wx/wxcrt.h:576:14:
// error: call to 'wcsstr' is ambiguous
#define _WCHAR_H_CPLUSPLUS_98_CONFORMANCE_
// Fix: macOS STC low support,
// using wxTextCtrl instead of wxStyledTextCtrl
// waiting for next macOS version of STC lib
#define AlifStudio_DisableSTC
#endif
// ------------------------------------------------
// C++ Include
// ------------------------------------------------
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <ctime>
using namespace std;
#include <utf8.h>
// ------------------------------------------------
// WX Include
// ------------------------------------------------
#ifdef WX_PRECOMP
#include <wx/wxprec.h>
#else
#include <wx/wx.h>
#endif
#include <wx/event.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>
#include <wx/splitter.h>
#include <wx/toolbar.h>
#include <wx/artprov.h>
#include <wx/busyinfo.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <wx/textfile.h>
#include <wx/treectrl.h>
#include <wx/dir.h>
#include <wx/dialog.h>
#include <wx/utils.h>
#include <wx/propgrid/propgrid.h>
#include <wx/splash.h>
#include <wx/utils.h>
#include <wx/textdlg.h>
#include <wx/fontdlg.h>
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include <wx/msgdlg.h>
#include <wx/aboutdlg.h>
#include <wx/webview.h>
#include <wx/aui/aui.h>
#include <wx/dc.h> // Debuging crash in linux...
#include <wx/glcanvas.h> // Debuging crash in linux...
//#include "img.h" // Debuging crash in linux...
// XPM
#include <wx/image.h>
#include <wx/imaglist.h>
#include "xpm/button_21.xpm"
#include "xpm/text_ctrl_21.xpm"
#include "xpm/static_text_21.xpm"
#include "xpm/folder_open_bleu_32.xpm"
#include "xpm/file_bleu_32.xpm"
#include "xpm/file_red_32.xpm"
#include "xpm/multi_window_21.xpm"
#include "xpm/window_21.xpm"
// XML (Color schemes)
#include "pugixml/pugixml.cpp"
// ------------------------------------------------
// IDE Version
// ------------------------------------------------
const static wxString Alif_Studio_Version = wxT("2.0.14");
wxString Alif_Compiler_Version = wxT("0");
// ------------------------------------------------
// Todo list - Alif lang.
// ------------------------------------------------
// TODO: When click on STC, last find_position must be updated imidiatly.
// TODO: STC for macOS need extra work or waiting for next update.
// TODO: CODE_DROP() Need work to drop files into IDE
// ------------------------------------------------
// Tools methods
// ------------------------------------------------
// WX Reserved: 4999 to 5999.
int gID = 5901;
int GET_ID(){
gID++;
return gID;
}
string CONVERT_INT_TO_STRING(int INT_VAL)
{
// Int --> String
stringstream STRING_STREAM_BUFFER;
STRING_STREAM_BUFFER << INT_VAL;
string STRING_BUFFER = STRING_STREAM_BUFFER.str();
return STRING_BUFFER;
}
string CONVERT_DOUBLE_TO_STRING(double INT_VAL)
{
// Int --> String
stringstream STRING_STREAM_BUFFER;
STRING_STREAM_BUFFER << INT_VAL;
string STRING_BUFFER = STRING_STREAM_BUFFER.str();
return STRING_BUFFER;
}
string CONVERT_STRING_ARRAY_TO_STRING(string STRING_ARRAY_VAL[2048], unsigned LONG)
{
// string[123] --> String
stringstream STRING_STREAM_BUFFER;
for (unsigned p = 0; p <= LONG; p++)
{
STRING_STREAM_BUFFER << STRING_ARRAY_VAL[p];
}
string STRING_BUFFER = STRING_STREAM_BUFFER.str();
return STRING_BUFFER;
}
int CONVERT_STRING_TO_INT(wxString STRING)
{
// string --> int
return wxAtoi(STRING);
}
string CONVERT_WCHAT_T_TO_STRING(wchar_t* WCHART_T_VAL)
{
// wchar_t --> String
wstring W_STRING_BUFFER (WCHART_T_VAL);
string STRING_BUFFER (W_STRING_BUFFER.begin(), W_STRING_BUFFER.end());
return STRING_BUFFER;
}
string CONVERT_CHAR_TO_STRING(char* CHART_VAL)
{
// Char --> String
string STRING_BUFFER(CHART_VAL);
return STRING_BUFFER;
}
// ------------------------------------------------
// Scintilla (STC)
// ------------------------------------------------
// Windows / Linux
#define SCI_WORDRIGHTEND 2441
#define SCI_CHARRIGHT 2306
#define SCI_CHARRIGHTEXTEND 2307
#define SCI_WORDRIGHTENDEXTEND 2442
#define SCI_SETMARGINRIGHT 2157
#define SCI_WORDRIGHT 2310
#define SCI_WORDRIGHTEXTEND 2311
#define SCI_DELWORDRIGHT 2336
#define SCI_DELWORDRIGHTEND 2518
#define SCI_WORDPARTRIGHT 2392
#define SCI_WORDPARTRIGHTEXTEND 2393
/*
// Tray RTL for macOS by STC (not working right now)
//#define EM_SETBIDIOPTIONS
//#define EM_SETEDITSTYLE
//#define SC_TECHNOLOGY_DIRECTWRITE
//#define SC_TECHNOLOGY_DIRECTWRITERETAIN
//#define SC_TECHNOLOGY_DIRECTWRITEDC
//#define SCI_SETBIDIRECTIONAL(SC_BIDIRECTIONAL_R2L)
//#define SCI_SETBIDIRECTIONAL 1
//#define SC_BIDIRECTIONAL_R2L
*/
#include <wx/stc/stc.h> // Scintilla (STC)
// ------------------------------------------------
// GLOBAL ID
// ------------------------------------------------
enum {
ID_WINDOW_MAIN,
ID_MENU_REPLACE_ALL,
ID_MENU_LTR,
ID_MENU_RTL,
ID_MENU_SETTING_IDE,
ID_MENU_SETTING_FONT,
ID_MENU_SETTING_COMPILER,
ID_MENU_UPDATE,
//ID_MENU_UPDATE_BY_FILE,
ID_MENU_LEARN_PDF,
ID_MENU_LEARN_HTML,
ID_MENU_ABOUT_IDE,
ID_MENU_ABOUT_BUG,
ID_MENU_FIND_NEXT,
ID_MENU_BUILD,
ID_MENU_COMPILE,
ID_MENU_RUN,
ID_MENU_LEARN_ONLINE,
ID_CODE,
ID_TOOLBAR_NEW,
ID_TOOLBAR_OPEN,
ID_TOOLBAR_SAVE,
ID_TOOLBAR_BUILD,
ID_TOOLBAR_UPDATE,
ID_TOOLBAR_HELP,
ID_TREE_FILES,
ID_TREE_WINDOWS,
ID_TREE_CONTROLS,
ID_PROPERTIES
};
// ------------------------------------------------
// Global methods definition
// ------------------------------------------------
bool SAVE_FILE_UTF8(wxString TXT, wxString PATH, bool OuverWrite);
void SET_NEW_FILE(wxString PATH);
void Exit();
void SET_TREE_FILES_LIST();
void UI_PARSE_SOURCE();
void UI_MANAGER(unsigned int ID_FILE);
void UI_UPDATE_SETTINGS(unsigned int ID);
void UI_EMPTY_SETTINGS();
void UI_GENERAT_ALIF_CODE();
void UI_MOVE_CONTROL(int ID);
void UI_RESIZE_CONTROL(int ID);
void UI_CONTROL_CAPTION_UPDATE(int ID);
void UI_DRAW_NEW_CONTROL(wxString TYPE, int X, int Y);
void UI_REMOVE_CONTROL(unsigned int ID);
void UI_DesignerShow(bool DesignerShow, bool WebUIShow);
// ------------------------------------------------
// Window Main Definition
// ------------------------------------------------
class Window_Main : public wxFrame
{
public:
// ------------------------------------------------
// Window Main Class Close
// ------------------------------------------------
void OnClose(wxCloseEvent& event);
// ------------------------------------------------
// Window Main Class Constructor
// ------------------------------------------------
Window_Main ();
// ------------------------------------------------
// Window Main Class Destructor
// ------------------------------------------------
virtual ~Window_Main();
// ------------------------------------------------
// Window Main User Functions Declaration
// ------------------------------------------------
// Menu
void OnOpen(wxCommandEvent &event);
void OnSave(wxCommandEvent &event);
void OnSaveAs(wxCommandEvent &event);
void OnCloseMenu(wxCommandEvent& event);
void EDIT_UNDO(wxCommandEvent& event);
void EDIT_REDO(wxCommandEvent& event);
void EDIT_CUT(wxCommandEvent& event);
void EDIT_COPY(wxCommandEvent& event);
void EDIT_PASTE(wxCommandEvent& event);
void EDIT_DELETE(wxCommandEvent& event);
void FIND(wxCommandEvent& event);
void FIND_NEXT(wxCommandEvent& event);
void REPLACE(wxCommandEvent& event);
void REPLACE_ALL(wxCommandEvent& event);
void CODE_RTL(wxCommandEvent &event);
void CODE_LTR(wxCommandEvent &event);
void BUILD(wxCommandEvent &event);
void COMPILE(wxCommandEvent& event);
bool COMPILE_NOW();
void RUN(wxCommandEvent& event);
void PROP_IDE(wxCommandEvent& event);
void PROP_FONT(wxCommandEvent& event);
void PROP_COMPILER(wxCommandEvent& event);
void UPDATE(wxCommandEvent& event);
//void UPDATE_BY_FILE(wxCommandEvent& event);
void HELP_PDF(wxCommandEvent& event);
//void HELP_HTML(wxCommandEvent& event);
void HELP_ONLINE(wxCommandEvent& event);
void ABOUT_IDE(wxCommandEvent& event);
void ABOUT_BUG(wxCommandEvent& event);
#if __APPLE__
// Mac About
void OnAbout(wxCommandEvent &event);
#endif
// Tool bar
void OnNew(wxCommandEvent &event);
void SET_BINARY_PATH();
void UPDATE_NOW(wxCommandEvent &event);
void TREE_FILES_DCLICK(wxTreeEvent& event);
void TREE_WINDOW_DCLICK(wxTreeEvent& event);
void TREE_WINDOW_RCLICK(wxTreeEvent& event);
void TREE_CONTROLES_DCLICK(wxTreeEvent& event);
void PROPERTIES_CHANGED(wxPropertyGridEvent& event);
#ifdef AlifStudio_DisableSTC
//void CODE_CHARADDED(wxCommandEvent& event); // Onlly KeyDown.
void CODE_KEYDOWN(wxKeyEvent& event);
#else
//void CODE_CHANGE(wxStyledTextEvent& event);
void CODE_CHARADDED(wxStyledTextEvent& event);
void CODE_AUTOCOMP_COMPLETED(wxStyledTextEvent& event);
#endif
//void CODE_DROP(wxDropFilesEvent& event);
// ------------------------------------------------
wxAuiManager AUI_MANAGER;
private:
DECLARE_NO_COPY_CLASS(Window_Main) // To Search in google...
DECLARE_EVENT_TABLE() // Déclaration d'une table STATIQUE d'évènements
};
// ------------------------------------------------
// UI Window Definition
// ------------------------------------------------
class Window_UI : public wxDialog
{
public:
// ------------------------------------------------
// UI Window Class Close
// ------------------------------------------------
void OnClose(wxCloseEvent& event);
// ------------------------------------------------
// UI Window Class Constructor
// ------------------------------------------------
Window_UI(wxString CAPTION, wxPoint pos, wxSize size);
// ------------------------------------------------
// UI Window Class Destructor
// ------------------------------------------------
virtual ~Window_UI();
// ------------------------------------------------
// UI Window Functions
// ------------------------------------------------
virtual bool AcceptsFocusFromKeyboard() const { return false; } // Disable Keyboard Tab
void OnNavigationKey(wxNavigationKeyEvent& event);
void OnResize(wxSizeEvent& event);
private:
DECLARE_NO_COPY_CLASS(Window_UI)
DECLARE_EVENT_TABLE()
};
// ------------------------------------------------
// Global declaration
// ------------------------------------------------
// General
wxString ID_UI_CONTROL_CURRENT_TYPE;
// Window
int ID_UI_WINDOW = GET_ID();
bool WINDOW_IS_CONSTRUCTED = false;
wxString ID_UI_WINDOW_NAME_CURRENT;
unsigned int ID_UI_WINDOW_CURRENT =0;
wxString UI_WINDOW_IDENTIFIER[64];
wxString UI_WINDOW_CAPTION[64];
int UI_WINDOW_X[64];
int UI_WINDOW_Y[64];
int UI_WINDOW_W[64];
int UI_WINDOW_H[64];
static std::map<wxString, bool> UI_WINDOW_IS_SET;
// Control
unsigned int UI_CONTROL_TOTAL = 0;
wxString UI_CONTROL_WINDOW[64];
wxString UI_CONTROL_TYPE[64];
wxString UI_CONTROL_IDENTIFIER[64];
wxString UI_CONTROL_CAPTION[64];
int UI_CONTROL_X[64];
int UI_CONTROL_Y[64];
int UI_CONTROL_W[64];
int UI_CONTROL_H[64];
std::map<wxString, bool> UI_CONTROL_INSIDE_WINDOW_IS_SET;
static std::map<wxString, bool> UI_CONTROL_IS_SET;
unsigned int ID_UI_CONTROL_CURRENT =0;
// Tree
wxTreeItemId TREE_ID_WINDOW_ROOT;
wxTreeItemId TREE_ID_WINDOW_ITEM[64];
unsigned int TREE_WINDOW_TOTAL_ITEM;
wxTreeItemId TREE_ID_WINDOW_LAST_BOLD;
// wxAui Panels
//wxAuiManager* AUI_MANAGER;
int ID_CODE_ERROR_INDICATOR = 8; // or any number between 8 and 32
//int CODE_ERROR_INDICATOR_START; // to clear error when new compile
//int CODE_ERROR_INDICATOR_LEN; // to clear error when new compile
//int CODE_ERROR_INDICATOR_LINE_NUMBER = -1; // to clear error when new compile
bool CODE_ERROR_INDICATOR = false; // to clear error when new compile
wxString FIND_WORD;
bool IS_FOUND = false;
int FIND_LAST_POS = 0;
size_t FIND_LEN;
bool UILOG_ERROR = false;
std::string INSTALL_PATH;
bool PATH_CONTAIN_SPACE = false;
wxString PATH_TEMP;
wxString PATH_FULL_ALIF_COMPILER;
wxString PATH_FULL_SOURCE;
wxString PATH_FULL_EXECUTABLE;
wxString PATH_FULL_LOG;
wxString PATH_FULL_UPDATE;
wxString PATH_DIRECTORY;
wxString CURRENT_FILE_EXTENSION;
wxString PATH_FULL_PDF;
wxString SOURCE_FILE_NAME;
#ifdef AlifStudio_DisableSTC
bool CODE_MODIFIED = false;
#endif
bool IGNORE_UPDATE_SETTINGS_EVENT = false;
bool WINDOW_RESIZING_BY_SYSTEM = false;
wxTreeItemId TREE_ID_FILES_ROOT;
wxTreeItemId TREE_ID_FILES_ITEM[64];
wxTreeItemId TREE_ID_FILES_LAST_BOLD;
wxString TREE_FILES_PATH[64];
wxString TREE_FILES_TYPE[64];
unsigned int TREE_FILES_TOTAL_ITEM;
bool TREE_FILES_HAVE_ITEM;
wxTreeItemId TREE_ID_CONTROL_ROOT;
wxTreeItemId TREE_ID_CONTROL_ITEM_BUTTON;
wxTreeItemId TREE_ID_CONTROL_ITEM_TXT;
wxTreeItemId TREE_ID_CONTROL_ITEM_LABEL;
bool DRAW_CONTROL = false;
wxString DRAW_TYPE;
bool FIRST_GENERATED_CODE = false;
bool ARG_OPEN_FILE = false;
wxString ARG_OPEN_FILE_PATH;
Window_Main* OBJ_CLASS_WINDOW_MAIN;
Window_UI* OBJ_UI_CLASS_WINDOW;
wxMenuBar* MENU_BAR;
wxMenu* MENU_FILE;
wxMenu* MENU_EDIT;
wxMenu* MENU_SEARCH;
wxMenu* MENU_VIEW;
wxMenu* MENU_COMPILE;
wxMenu* MENU_SETTINGS;
wxMenu* MENU_UPDATE;
wxMenu* MENU_LEARN;
wxMenu* MENU_ABOUT;
#if __APPLE__
// Mac Help
wxMenu *menuHelp = new wxMenu;
#endif
wxToolBar* OBJ_TOOLBAR;
#ifdef AlifStudio_DisableSTC
wxTextCtrl* obj_CODE;
#else
wxStyledTextCtrl* obj_CODE;
#endif
wxTextCtrl* OBJ_LOG;
wxTreeCtrl* OBJ_TREE_FILES_LIST;
wxTreeCtrl* OBJ_TREE_WINDOW;
wxTreeCtrl* OBJ_TREE_CONTROLS;
wxPropertyGrid* OBJ_PROPERTIES;
wxWebView* obj_WebUI;
string XML_Path;
// --------------------------------
// DrawPanel Definition
// --------------------------------
class DrawPanel : public wxPanel
{
public:
DrawPanel(wxDialog* parent);
void OnPaintEvent(wxPaintEvent & evt); // Called by System, when re-drawing is needed.
void render(wxDC& dc); // re-drawing
virtual bool AcceptsFocusFromKeyboard() const { return false; } // Disable Keyboard Tab
void OnClick(wxMouseEvent& event); // UI Window clicked
void OnRightClick(wxMouseEvent& event);
void OnEnter(wxMouseEvent& event);
void OnLeave(wxMouseEvent& event);
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(DrawPanel, wxPanel)
EVT_PAINT (DrawPanel::OnPaintEvent)
//EVT_LEFT_DOWN (DrawPanel::OnClick)
EVT_LEFT_UP (DrawPanel::OnClick)
EVT_RIGHT_UP (DrawPanel::OnRightClick)
EVT_ENTER_WINDOW (DrawPanel::OnEnter)
EVT_LEAVE_WINDOW (DrawPanel::OnLeave)
END_EVENT_TABLE()
void DrawPanel::OnRightClick(wxMouseEvent& event)
{
event.Skip();
this->SetCursor( wxNullCursor );
DRAW_CONTROL = false;
}
void DrawPanel::OnEnter(wxMouseEvent& event)
{
event.Skip();
// List : http://docs.wxwidgets.org/2.8.8/wx_wxcursor.html#wxcursor
/*
// not workin!
if (UI_WINDOW_W[ID_UI_WINDOW_CURRENT] != OBJ_UI_CLASS_WINDOW->GetSize().x ||
UI_WINDOW_H[ID_UI_WINDOW_CURRENT] != OBJ_UI_CLASS_WINDOW->GetSize().y)
{
UI_WINDOW_W[ID_UI_WINDOW_CURRENT] = OBJ_UI_CLASS_WINDOW->GetSize().x;
UI_WINDOW_H[ID_UI_WINDOW_CURRENT] = OBJ_UI_CLASS_WINDOW->GetSize().y;
UI_UPDATE_SETTINGS(0);
UI_GENERAT_ALIF_CODE();
}
*/
/*
// annuler bcs window start at center in gui designer!
if (UI_WINDOW_X[ID_UI_WINDOW_CURRENT] != OBJ_UI_CLASS_WINDOW->GetPosition().x ||
UI_WINDOW_Y[ID_UI_WINDOW_CURRENT] != OBJ_UI_CLASS_WINDOW->GetPosition().y)
{
UI_WINDOW_X[ID_UI_WINDOW_CURRENT] = OBJ_UI_CLASS_WINDOW->GetPosition().x;
UI_WINDOW_Y[ID_UI_WINDOW_CURRENT] = OBJ_UI_CLASS_WINDOW->GetPosition().y;
UI_UPDATE_SETTINGS(0);
UI_GENERAT_ALIF_CODE();
}
*/
if (DRAW_CONTROL)
{
this->SetCursor( wxCURSOR_SIZING );
}
else
{
this->SetCursor( wxNullCursor );
}
}
void DrawPanel::OnLeave(wxMouseEvent& event)
{
event.Skip();
if (!DRAW_CONTROL)
{
this->SetCursor( wxNullCursor );
}
}
void DrawPanel::OnClick(wxMouseEvent& event)
{
event.Skip();
this->SetCursor( wxNullCursor );
if (DRAW_CONTROL)
{
DRAW_CONTROL = false;
UI_DRAW_NEW_CONTROL(DRAW_TYPE, event.GetX(), event.GetY());
}
else
{
if (ID_UI_CONTROL_CURRENT_TYPE != "WINDOW")
{
ID_UI_CONTROL_CURRENT_TYPE = "WINDOW";
ID_UI_CONTROL_CURRENT = 0;
// 0 Mean is Window, not Control,
// ID of Window already set when User double click on Window List
UI_UPDATE_SETTINGS(0);
}
}
}
DrawPanel::DrawPanel(wxDialog* parent) : wxPanel(parent, wxID_ANY)
{
// Construction
}
void DrawPanel::OnPaintEvent(wxPaintEvent & evt) // Called by System, when re-drawing is needed.
{
evt.Skip();
wxPaintDC dc(this);
render(dc);
}
void DrawPanel::render(wxDC& dc)
{
wxSize size = this->GetSize();
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen( wxPen( *wxBLACK, 2, wxPENSTYLE_DOT ) );
for (int x=0; x < size.GetWidth(); x += 8)
{
for (int y=0; y < size.GetHeight(); y += 8)
{
dc.DrawPoint(x-1, y-1);
}
}
}
// --------------------------------
// Base Panell to hold all ctrls
// --------------------------------
DrawPanel* OBJ_WINDOW_BASE_PANEL;
// --------------------------------
// Class Movable Controls
// --------------------------------
template <class T>
class Movable : public T
{
// Move Var
bool dragging;
int x,y;
int height, width;
int top, left, topScreen, leftScreen;
wxPanel* LOCAL_PARENT;
unsigned int LOCAL_ID;
// Resize VAR
enum
{ NONE, RIGHTBOTTOM, RIGHT, BOTTOM } m_sizing;
int m_curX, m_curY, m_difX, m_difY;
int m_resizeBorder = 10;
wxSize m_minSize = wxSize(10, 10);
// VAR
bool IS_RESIZE = false;
bool IS_MOVE = false;
private:
// ...
protected:
// Attach the event handler manually
void ConnectEvents()
{
this->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(Movable<T>::onMouseDown));
this->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(Movable<T>::onMouseUp));
this->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(Movable<T>::onMouseRightUp));
this->Connect(wxEVT_MOTION, wxMouseEventHandler(Movable<T>::onMove));
this->Connect(wxEVT_SET_CURSOR, wxSetCursorEventHandler(Movable<T>::OnSetCursor));
}
public:
virtual bool AcceptsFocusFromKeyboard() const { return false; } // Disable Keyboard Tab
// -------------------------------------------------------------
// Instantiation
// -------------------------------------------------------------
Movable(unsigned int ID, wxString CAPTION, wxPoint pos, wxSize size, long style) : T (OBJ_WINDOW_BASE_PANEL, ID, CAPTION, pos, size, style)
//wxTE_READONLY)
{
// Base
Movable::LOCAL_PARENT = OBJ_WINDOW_BASE_PANEL;
LOCAL_ID = ID;
ConnectEvents();
// VAR
IS_RESIZE = false;
IS_MOVE = false;
// Move VAR
dragging = false;
// Resize VAR
m_sizing = NONE;
m_curX = -1;
m_curY = -1;
m_minSize = wxSize(10, 10);
m_resizeBorder = 10;
}
// -------------------------------------------------------------
void OnSetCursor(wxSetCursorEvent& e)
{
if (e.GetX() >= this->GetSize().x - m_resizeBorder && e.GetY() >= this->GetSize().y - m_resizeBorder)
{
e.SetCursor(wxCursor(wxCURSOR_SIZENWSE));
IS_RESIZE = true;
IS_MOVE = false;
}
else if (e.GetX() >= this->GetSize().x - m_resizeBorder)
{
e.SetCursor(wxCursor(wxCURSOR_SIZEWE));
IS_RESIZE = true;
IS_MOVE = false;
}
else if (e.GetY() >= this->GetSize().y - m_resizeBorder)
{
e.SetCursor(wxCursor(wxCURSOR_SIZENS));
IS_RESIZE = true;
IS_MOVE = false;
}
else
{
e.SetCursor(*wxSTANDARD_CURSOR);
IS_RESIZE = false;
IS_MOVE = true;
}
}
// -------------------------------------------------------------
void onMouseDown(wxMouseEvent& e)
{
if (DRAW_CONTROL)
DRAW_CONTROL = false;
if(IS_RESIZE)
{
if (m_sizing == NONE)
{
if (e.GetX() >= this->GetSize().x - m_resizeBorder && e.GetY() >= this->GetSize().y - m_resizeBorder)
m_sizing = RIGHTBOTTOM;
else if (e.GetX() >= this->GetSize().x - m_resizeBorder)
m_sizing = RIGHT;
else if (e.GetY() >= this->GetSize().y - m_resizeBorder)
m_sizing = BOTTOM;
if (m_sizing != NONE)
{
m_difX = this->GetSize().x - e.GetX();
m_difY = this->GetSize().y - e.GetY();
#ifdef _WIN32
this->CaptureMouse();
#else
// Infinity loop Crash
//this->CaptureMouse();
#endif
onMove(e);
}
}
}
else if(IS_MOVE)
{
this->SetCursor( wxCURSOR_SIZING );
#ifdef _WIN32
this->CaptureMouse();
#else
// Infinity loop Crash
//this->CaptureMouse();
#endif
x = e.GetX();
y = e.GetY();
LOCAL_PARENT->GetScreenPosition(&topScreen, &leftScreen);
dragging=true;
}
}
// -------------------------------------------------------------
void onMouseRightUp(wxMouseEvent& e)
{
e.Skip(false);
UI_REMOVE_CONTROL(LOCAL_ID);
}
// -------------------------------------------------------------
void onMouseUp(wxMouseEvent& e)
{
e.Skip();
if(IS_RESIZE)
{
if (m_sizing != NONE)
{
m_sizing = NONE;
this->ReleaseMouse();
wxScreenDC dc;
wxPen pen(*wxBLACK, 1, wxPENSTYLE_DOT_DASH);
dc.SetPen(pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetLogicalFunction(wxINVERT);
//wxPoint pos = ClientToScreen(wxPoint(0, 0));
wxPoint pos = this->GetParent()->ClientToScreen(this->GetPosition());
dc.DrawRectangle(pos.x, pos.y, m_curX, m_curY);
dc.SetLogicalFunction(wxCOPY);
dc.SetPen(wxNullPen);
dc.SetBrush(wxNullBrush);
this->SetSize(m_curX, m_curY);
//wxCommandEvent event(wxEVT_PANEL_RESIZED, this->GetId());
//event.SetEventObject(this);
//GetEventHandler()->ProcessEvent(event);
}
}
else if(IS_MOVE)
{
this->SetCursor( wxNullCursor );
this->ReleaseMouse();
dragging=false;
}
if (this->GetPosition().x != UI_CONTROL_X[LOCAL_ID] || this->GetPosition().y != UI_CONTROL_Y[LOCAL_ID])
{
OBJ_UI_CLASS_WINDOW->Refresh();
OBJ_UI_CLASS_WINDOW->Update();
UI_CONTROL_X[LOCAL_ID] = this->GetPosition().x;
UI_CONTROL_Y[LOCAL_ID] = this->GetPosition().y;
ID_UI_CONTROL_CURRENT_TYPE = "CONTROL";
ID_UI_CONTROL_CURRENT = LOCAL_ID;
UI_UPDATE_SETTINGS(LOCAL_ID);
UI_GENERAT_ALIF_CODE();
}
else if (this->GetSize().x != UI_CONTROL_W[LOCAL_ID] || this->GetSize().y != UI_CONTROL_H[LOCAL_ID])
{
OBJ_UI_CLASS_WINDOW->Refresh();
OBJ_UI_CLASS_WINDOW->Update();
UI_CONTROL_W[LOCAL_ID] = this->GetSize().x;
UI_CONTROL_H[LOCAL_ID] = this->GetSize().y;
ID_UI_CONTROL_CURRENT_TYPE = "CONTROL";
ID_UI_CONTROL_CURRENT = LOCAL_ID;
UI_UPDATE_SETTINGS(LOCAL_ID);
UI_GENERAT_ALIF_CODE();
}
else if (ID_UI_CONTROL_CURRENT != LOCAL_ID)
{
OBJ_UI_CLASS_WINDOW->Refresh();
OBJ_UI_CLASS_WINDOW->Update();
ID_UI_CONTROL_CURRENT_TYPE = "CONTROL";
ID_UI_CONTROL_CURRENT = LOCAL_ID;
UI_UPDATE_SETTINGS(LOCAL_ID);
}
this->SetFocus();
m_curX = m_curY = -1;
}
// -------------------------------------------------------------
void onMove(wxMouseEvent& e)
{
e.Skip();
if(IS_RESIZE)
{
if (m_sizing != NONE)
{
wxScreenDC dc;
wxPen pen(*wxBLACK, 1, wxPENSTYLE_DOT_DASH);
dc.SetPen(pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetLogicalFunction(wxINVERT);
//wxPoint pos = ClientToScreen(wxPoint(0, 0));
wxPoint pos = this->GetParent()->ClientToScreen(this->GetPosition());
if (m_curX >= 0 && m_curY >= 0)
dc.DrawRectangle(pos.x, pos.y, m_curX, m_curY);
if (m_sizing == RIGHT || m_sizing == RIGHTBOTTOM)