This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
/
roadmap_address_tc.c
1429 lines (1136 loc) · 37 KB
/
roadmap_address_tc.c
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
/*
* LICENSE:
*
* Copyright 2008 PazO
*
* RoadMap is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License V2 as published by
* the Free Software Foundation.
*
* RoadMap 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 RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "roadmap.h"
#ifndef TOUCH_SCREEN
#include <string.h>
#include <stdlib.h>
#include "ssd/ssd_combobox.h"
#include "ssd/ssd_tabcontrol.h"
#include "ssd/ssd_container.h"
#include "ssd/ssd_text.h"
#include "ssd/ssd_contextmenu.h"
#include "ssd/ssd_confirm_dialog.h"
#include "roadmap_input_type.h"
#include "roadmap_street.h"
#include "roadmap_history.h"
#include "roadmap_street.h"
#include "roadmap_locator.h"
#include "roadmap_address.h"
#include "roadmap_geocode.h"
#include "roadmap_trip.h"
#include "roadmap_display.h"
#include "roadmap_lang.h"
#include "roadmap_main.h"
#include "roadmap_history.h"
#include "roadmap_messagebox.h"
#include "roadmap_editbox.h"
#include "ssd/ssd_keyboard_dialog.h"
#include "roadmap_address_tc_defs.h"
extern void navigate_main_stop_navigation(void);
static int on_options(SsdWidget widget, const char *new_value, void *context);
static list_items s_history;
static RoadMapAddressNav s_navigator = NULL;
static BOOL s_history_was_loaded = FALSE;
static BOOL s_viewing_history = FALSE;
static BOOL s_context_menu_is_active= FALSE;
static on_text_changed_ctx s_on_text_changed_ctx;
// Context menu items:
static ssd_cm_item main_menu_items[] =
{
// Label , Item-ID
SSD_CM_INIT_ITEM ( "Navigate", cmi_navigate),
SSD_CM_INIT_ITEM ( "Show on map", cmi_show),
SSD_CM_INIT_ITEM ( "Add to favorites", cmi_add_to_favorites),
SSD_CM_INIT_ITEM ( "Exit_key", cmi_exit)
};
// Context menu:
static ssd_contextmenu context_menu = SSD_CM_INIT_MENU( main_menu_items);
///////////////////////////////////////
///////////////////////////////////////
void roadmap_address_register_nav( RoadMapAddressNav navigate)
{ s_navigator = navigate;}
///////////////////////////////////////
// Cached data of the ssd_list content
void list_items_init( list_items_ptr this)
{ memset( this, 0, sizeof(list_items));}
void list_items_free( list_items_ptr this)
{
int i;
// Free previously allocated strings:
for( i = 0; i < this->size; i++)
{
FREE( this->labels[i])
this->values[i] = NULL;
}
this->size = 0;
}
///////////////////////////////////////
// Single tab info //////////////////
void atc_tab_info_init( atc_tab_info_ptr this, tabid id, void* parent)
{
this->id = id;
this->tab = NULL;
list_items_init( &(this->items));
this->list_is_empty = TRUE;
this->parent = parent;
}
void atc_tab_info_free( atc_tab_info_ptr this)
{
list_items_free( &(this->items));
this->list_is_empty = TRUE;
}
///////////////////////////////////////
// Module context /////////////////////
void atcctx_init( atcctx_ptr this)
{
int i;
memset( this, 0, sizeof(atcctx));
for( i=0; i<tab__count; i++)
atc_tab_info_init( (this->tab_info + i), i, this);
}
void atcctx_free( atcctx_ptr this)
{
int i;
for( i=0; i<tab__count; i++)
atc_tab_info_free( this->tab_info + i);
}
///////////////////////////////////////
///////////////////////////////////////
void on_text_changed_ctx_copy( on_text_changed_ctx_ptr this,
const char* new_text,
void* context)
{
on_text_changed_ctx_free( this);
this->context = context;
if( new_text && (*new_text))
{
this->new_text= malloc( strlen( new_text) + 1);
strcpy( this->new_text, new_text);
}
}
void on_text_changed_ctx_free( on_text_changed_ctx_ptr this)
{
FREE(this->new_text)
this->context = NULL;
}
void on_text_changed_ctx_init( on_text_changed_ctx_ptr this)
{ memset( this, 0, sizeof(on_text_changed_ctx));}
///////////////////////////////////////
///////////////////////////////////////
static void hide_our_dialogs( int exit_code)
{
ssd_dialog_hide( ATC_NAME, exit_code);
ssd_dialog_hide( "Main Menu", exit_code);
ssd_dialog_hide( "Search", exit_code);
}
static void empty_list( SsdWidget tab)
{
atc_tab_info_ptr ti = ssd_combobox_get_context(tab);
list_items_free( &(ti->items));
if( ti->list_is_empty)
return;
ssd_combobox_update_list( tab,
0,
NULL,
NULL,
NULL);
ti->list_is_empty = TRUE;
}
static void populate_list( SsdWidget tab,
int count,
char** labels,
void** values)
{
atc_tab_info_ptr ti = NULL;
if( !count)
{
empty_list( tab);
return;
}
ssd_combobox_update_list( tab,
count,
(const char **)labels,
(const void **)values,
NULL);
ti = ssd_combobox_get_context(tab);
ti->list_is_empty = FALSE;
}
static BOOL create_address_string( char* address,
const char* city,
const char* street,
const char* house)
{
if( street && house && city && (*street) && (*house) && (*city))
snprintf(address,
ADDRESS_STRING_MAX_SIZE,
"%s %s, %s", street, house, city);
else if( street && city && (*street) && (*city))
snprintf(address,
ADDRESS_STRING_MAX_SIZE,
"%s, %s", street, city);
else if( city && (*city))
snprintf(address,
ADDRESS_STRING_MAX_SIZE,
"%s", city);
else if( street && (*street))
snprintf(address,
ADDRESS_STRING_MAX_SIZE,
"%s, ", street);
else
return FALSE;
return TRUE;
}
static int get_house_number_from_address( const char* address)
{
const char* p = NULL;
int power = 1;
int value = 0;
if( !address || !(*address))
return -1;
p = strchr( address, ',');
if( !p)
return -1;
p--;
if(((*p) < '0') || ('9' < (*p)))
return -1;
do
{
if( ((*p) < '0') || ('9' < (*p)))
return value;
value += (power * ((*p) - '0'));
power *= 10;
} while( --p != address);
return value;
}
static const char* get_city_name_from_address( const char* address)
{
const char* p = NULL;
if( !address || !(*address))
return NULL;
p = strchr( address, ',');
if( !p)
return address;
while( (*p) && ((' '==(*p)) || (','==(*p)) || ('\t'==(*p))))
p++;
return p;
}
static const char* get_street_name_from_address( const char* address, char* street)
{
int size;
const char* p = NULL;
if( !address || !(*address) || !street)
return NULL;
(*street) = '\0';
p = strchr( address, ',');
if( !p)
return NULL;
p--;
while( (p != address) && ((('0' <= (*p)) && ((*p) <= '9')) || (' '==(*p)) || ('\t'==(*p))))
p--;
if( p == address)
return NULL;
size = p - address + 1;
if( ADDRESS_STREET_NAME_MAX_SIZE < size)
{
assert(0);
return NULL;
}
strncpy( street, address, size);
street[size] = '\0';
return street;
}
static SsdWidget get_house_number_widget()
{
atcctx_ptr tc = get_atcctx();
SsdWidget tab= ssd_tabcontrol_get_tab( tc->tabcontrol, tab_house);
return ssd_widget_get( tab, ATC_HOUSETAB_NM_EDIT);
}
static const char* get_house_number()
{
SsdWidget house_number_widget = get_house_number_widget();
return house_number_widget->value;
}
static void set_house_number( const char* number)
{
SsdWidget house_number_widget = get_house_number_widget();
house_number_widget->set_value( house_number_widget, number);
}
static void invalidate_house_number()
{ set_house_number( "");}
static void invalidate_street()
{
atcctx_ptr tc = get_atcctx();
SsdWidget tab= ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street);
empty_list( tab);
ssd_combobox_set_text( tab, "");
invalidate_house_number();
}
static void invalidate_city()
{
atcctx_ptr tc = get_atcctx();
SsdWidget tab= ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city);
empty_list( tab);
ssd_combobox_set_text( tab, "");
invalidate_street();
s_viewing_history = FALSE;
}
static void invalidate_all()
{
atcctx_ptr tc = get_atcctx();
invalidate_city();
ssd_tabcontrol_set_active_tab ( tc->tabcontrol, tab_city);
ssd_tabcontrol_set_title ( tc->tabcontrol, roadmap_lang_get(ATC_TITLE));
}
int on_city_found( RoadMapString index, const char* item, void* data)
{
list_items_ptr li = data;
if( ATC_LIST_MAX_SIZE == li->size)
return 0;
li->labels[li->size++] = strdup(item);
return 1;
}
static void update_title()
{
atcctx_ptr tc = get_atcctx();
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
const char* street= ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street));
const char* house = get_house_number();
char address[128];
if( create_address_string( address, city, street, house) && address[0])
ssd_tabcontrol_set_title( tc->tabcontrol, address);
else
ssd_tabcontrol_set_title( tc->tabcontrol, roadmap_lang_get(ATC_TITLE));
}
static void verify_child_data_is_valid( int tab)
{
atcctx_ptr tc = get_atcctx();
atc_tab_info_ptr ti = &(tc->tab_info[tab]);
if( tab_street == tab)
{
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
if( strlen(ti->last_ctx_val) && (0 != strcmp( city, ti->last_ctx_val)))
invalidate_street();
}
else if( tab_house == tab)
{
const char* street = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street));
if( strlen(ti->last_ctx_val) && (0 != strcmp( street, ti->last_ctx_val)))
invalidate_house_number();
}
}
static void add_address_to_history( int category,
const char* city,
const char* street,
const char* house,
const char *name)
{
const char* address[ahi__count];
address[ahi_city] = city;
address[ahi_street] = street;
address[ahi_house_number] = house;
address[ahi_state] = ADDRESS_HISTORY_STATE;
if(name)
address[ahi_name] = name;
else
address[ahi_name] = "";
roadmap_history_add( category, address);
roadmap_history_save();
}
static BOOL navigate( BOOL take_me_there)
{
int i;
PluginLine line;
PluginStreet street_info;
int count = 0;
RoadMapGeocode* selections = NULL;
atcctx_ptr tc = get_atcctx();
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
const char* street = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street));
const char* house = get_house_number();
count = roadmap_geocode_address( &selections,
house,
street,
city,
ADDRESS_HISTORY_STATE);
if( count <= 0)
{
roadmap_log(ROADMAP_ERROR,
"address_tabcontrol::navigate() - 'roadmap_geocode_address()' returned %d", count);
FREE( selections)
roadmap_messagebox (roadmap_lang_get ("Warning"),
roadmap_geocode_last_error_string());
return FALSE;
}
add_address_to_history(ADDRESS_HISTORY_CATEGORY, city, street, house, NULL);
roadmap_locator_activate( selections->fips);
roadmap_plugin_set_line( &line, ROADMAP_PLUGIN_ID, selections->line, -1,
selections->square, selections->fips);
roadmap_trip_set_point ("Selection",&selections->position);
roadmap_trip_set_point ("Address", &selections->position);
if( s_navigator && take_me_there)
{
address_info ai;
ai.state = NULL;
ai.country = NULL;
ai.city =city;
ai.street = street;
ai.house = house;
if( -1 == s_navigator( &selections->position, &line, 0, &ai))
return FALSE;
}
else
{
roadmap_trip_set_focus ("Address");
roadmap_display_activate( "Selected Street", &line, &selections->position, &street_info);
roadmap_screen_redraw ();
}
for( i=0; i<count; i++)
FREE(selections[i].name)
FREE(selections)
return TRUE;
}
void on_text_changed__city( atc_tab_info_ptr ti, const char* new_text)
{
if( new_text && (*new_text))
{
list_items_ptr li = &(ti->items);
s_viewing_history = FALSE;
empty_list( ti->tab);
roadmap_locator_search_city( new_text, on_city_found, li);
if( !li->size)
return;
populate_list( ti->tab, li->size, (char **)li->labels, (void **)li->values);
}
else
insert_history_into_city_list( FALSE);
}
int on_street_found( RoadMapString index, const char* item, void* data)
{
atcctx_ptr tc = get_atcctx();
list_items_ptr li = data;
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
const char* street= NULL;
char buffer[ADDRESS_STREET_NAME_MAX_SIZE+1];
if( ATC_LIST_MAX_SIZE == li->size)
return 0;
if( strlen(city))
street = get_street_name_from_address( item, buffer);
if( street)
li->labels[li->size++] = strdup(street);
else
li->labels[li->size++] = strdup(item);
return 1;
}
// If string terminate with a comma or spaces - remove them:
void remove_string_last_decorations( char* str)
{
char* p;
if( !str || !(*str))
return;
p = str + strlen(str);
while( --p != str)
{
if( ((*p) != ',')&&((*p) != ' ')&&((*p) != '\t'))
return;
(*p) = '\0';
}
}
void on_text_changed__street( atc_tab_info_ptr ti, const char* new_text)
{
atcctx_ptr tc = get_atcctx();
list_items_ptr li = &(ti->items);
const char* city = NULL;
int count = 0;
int i;
empty_list( ti->tab);
if( !new_text || !(*new_text))
{
insert_city_history_into_street_list();
return;
}
city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
count = roadmap_street_search( city, new_text, ATC_LIST_MAX_SIZE, on_street_found, li);
if( !count)
{
assert( !li->size);
return;
}
assert(li->size);
for( i=0; i<li->size; i++)
remove_string_last_decorations( li->labels[i]);
populate_list( ti->tab, li->size, li->labels, li->values);
}
void on_timer__on_text_changed(void)
{
atc_tab_info_ptr tab_info = s_on_text_changed_ctx.context;
roadmap_main_remove_periodic( on_timer__on_text_changed);
switch( tab_info->id)
{
case tab_city:
on_text_changed__city ( tab_info, s_on_text_changed_ctx.new_text);
verify_child_data_is_valid( tab_street);
break;
case tab_street:
on_text_changed__street ( tab_info, s_on_text_changed_ctx.new_text);
verify_child_data_is_valid( tab_house);
break;
default:
assert(0);
}
update_title();
roadmap_screen_redraw();
on_text_changed_ctx_free( &s_on_text_changed_ctx);
}
void on_text_changed(const char* new_text, void* context)
{
on_text_changed_ctx_copy( &s_on_text_changed_ctx, new_text, context);
roadmap_main_remove_periodic( on_timer__on_text_changed);
roadmap_main_set_periodic( 1200, on_timer__on_text_changed);
}
void distribute_address_sections_between_tabs( const char* address,
int calling_tab)
{
char buffer[ADDRESS_STREET_NAME_MAX_SIZE + 1];
const char* city = get_city_name_from_address ( address);
const char* street= get_street_name_from_address ( address, buffer);
int house = get_house_number_from_address ( address);
atcctx_ptr tc = get_atcctx();
SsdWidget tab = NULL;
tab = ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city);
if( tab_city != calling_tab)
empty_list(tab);
if( city)
ssd_combobox_set_text( tab, city);
else
ssd_combobox_set_text( tab, "");
tab = ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street);
if( tab_street != tab_street)
empty_list(tab);
tc->tab_info[tab_street].last_ctx_val[0] = '\0';
if( street)
{
ssd_combobox_set_text( tab, street);
if( city && (*city))
strcpy( tc->tab_info[tab_street].last_ctx_val, city);
}
else
ssd_combobox_set_text( tab, "");
tab = ssd_tabcontrol_get_tab( tc->tabcontrol, tab_house);
tc->tab_info[tab_house].last_ctx_val[0] = '\0';
if( -1 != house)
{
if( street && (*street))
strcpy( tc->tab_info[tab_house].last_ctx_val, street);
sprintf( buffer, "%d", house);
}
else
buffer[0] = '\0';
set_house_number( buffer);
}
void on_timer__on_select(void)
{
atcctx_ptr tc = get_atcctx();
roadmap_main_remove_periodic( on_timer__on_select);
switch(tc->active_tab)
{
case tab_city:
{
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
if( city && (*city))
{
ssd_tabcontrol_set_active_tab ( tc->tabcontrol, tab_street);
roadmap_screen_redraw();
}
break;
}
case tab_street:
{
const char* street = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street));
if( street && (*street))
{
ssd_tabcontrol_set_active_tab ( tc->tabcontrol, tab_house);
roadmap_screen_redraw();
}
break;
}
case tab_house:
on_options( NULL, NULL, NULL);
break;
default:
break;
}
}
int on_list_selection_city(SsdWidget widget, const char *new_value, const void *value)
{
if( !new_value || !(*new_value))
return -1;
distribute_address_sections_between_tabs(new_value,tab_city);
update_title();
if( s_viewing_history)
{
on_options( NULL, NULL, NULL);
}
else
{
roadmap_main_remove_periodic( on_timer__on_select);
roadmap_main_set_periodic( 300, on_timer__on_select);
}
return 0;
}
int on_list_selection_street(SsdWidget widget, const char *new_value, const void *value)
{
atcctx_ptr tc = get_atcctx();
SsdWidget tab= ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street);
if( !new_value || !(*new_value))
return -1;
if( strchr( new_value, ','))
distribute_address_sections_between_tabs(new_value,tab_street);
else
ssd_combobox_set_text( tab, new_value);
update_title();
roadmap_main_remove_periodic( on_timer__on_select);
roadmap_main_set_periodic( 500, on_timer__on_select);
return 0;
}
void on_erase_history_item( int exit_code, void *context)
{
if( dec_yes != exit_code)
return;
roadmap_history_delete_entry( context);
insert_history_into_city_list( TRUE);
}
static void erase_history_entry()
{
atcctx_ptr tc = get_atcctx();
SsdWidget list = ssd_combobox_get_list( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
const void* selected = ssd_list_selected_value ( list);
const char* string = ssd_list_selected_string( list);
if( !selected || !string || !(*string))
return;
ssd_confirm_dialog( string,
"Are you sure you want to remove item from history?",
FALSE,
on_erase_history_item,
(void*)selected);
}
BOOL on_tab_loose_focus(int tab)
{
atcctx_ptr tc = get_atcctx();
atc_tab_info_ptr ti = &(tc->tab_info[tab]);
if( tab_street == tab)
{
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
if( strlen(city) < ADDRESS_STRING_MAX_SIZE)
strcpy( ti->last_ctx_val, city);
}
else if( tab_house == tab)
{
const char* street = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street));
if( strlen(street) < ADDRESS_STRING_MAX_SIZE)
strcpy( ti->last_ctx_val, street);
}
return TRUE;
}
void on_tab_gain_focus(int tab)
{
atcctx_ptr tc = get_atcctx();
tc->active_tab = tab;
verify_child_data_is_valid( tab);
if( tab_street == tab)
{
const char* city = ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_city));
const char* street= ssd_combobox_get_text( ssd_tabcontrol_get_tab( tc->tabcontrol, tab_street));
if( tc->tab_info[tab_street].list_is_empty && !(*street) && (*city))
insert_city_history_into_street_list();
}
update_title();
}
int on_delete_history_item( SsdWidget widget, const char *new_value, const void *value)
{
if( s_viewing_history)
{
erase_history_entry();
return TRUE;
}
return FALSE;
}
static SsdWidget create_tab__city( atcctx_ptr tc)
{
atc_tab_info_ptr ti = (tc->tab_info + tab_city);
ti->tab = ssd_container_new(
"citytabcontainer",
NULL,
SSD_MAX_SIZE,
SSD_MAX_SIZE,
0);
ssd_combobox_new( ti->tab,
NULL,
0,
NULL,
NULL,
NULL,
on_text_changed, // User modified edit-box text
on_list_selection_city, // User selected iterm from list
on_delete_history_item, // User is trying to delete an item from the list
inputtype_alpha_spaces, // inputtype_<xxx> from 'roadmap_input_type.h'
ti);
return ti->tab;
}
static SsdWidget create_tab__street( atcctx_ptr tc)
{
atc_tab_info_ptr ti = (tc->tab_info + tab_street);
ti->tab = ssd_container_new(
"streettabcontainer",
NULL,
SSD_MAX_SIZE,
SSD_MAX_SIZE,
0);
ssd_combobox_new( ti->tab,
NULL,
0,
NULL,
NULL,
NULL,
on_text_changed, // User modified edit-box text
on_list_selection_street, // User selected iterm from list
NULL, // User is trying to delete an item from the list
inputtype_alpha_spaces, // inputtype_<xxx> from 'roadmap_input_type.h'
ti);
return ti->tab;
}
static BOOL on_key_pressed__delegate_to_editbox(
SsdWidget this,
const char* utf8char,
uint32_t flags)
{
SsdWidget editbox = this->children;
BOOL handled = FALSE;
if( editbox->key_pressed( editbox, utf8char, flags))
{
handled = TRUE;
update_title();
}
if( KEY_IS_ENTER)
{
on_options( NULL, NULL, NULL);
handled = TRUE;
}
return handled;
}
static SsdWidget create_tab__house( atcctx_ptr tc)
{
SsdWidget cont;
SsdWidget label;
SsdWidget ecnt;
SsdWidget edit;
atc_tab_info_ptr ti = (tc->tab_info + tab_house);
ti->tab = ssd_container_new(
ATC_HOUSETAB_NM_TAB,
NULL,
SSD_MAX_SIZE,
SSD_MAX_SIZE,
0);
cont = ssd_container_new(
ATC_HOUSETAB_NM_CONT,
NULL,
SSD_MAX_SIZE,
20,
SSD_END_ROW);
label= ssd_text_new( ATC_HOUSETAB_NM_LABL,
roadmap_lang_get("House number"),
18,
SSD_TEXT_LABEL);
ecnt = ssd_container_new(
ATC_HOUSETAB_NM_ECNT,
NULL,
SSD_MAX_SIZE,
20,
SSD_CONTAINER_BORDER|SSD_WS_TABSTOP);
edit = ssd_text_new( ATC_HOUSETAB_NM_EDIT,
"",
18,
0);
ssd_text_set_input_type( edit, inputtype_numeric);
ssd_text_set_readonly ( edit, FALSE);
// Delegate the 'on key pressed' event to the child edit-box:
ecnt->key_pressed = on_key_pressed__delegate_to_editbox;
ssd_widget_add( ecnt, edit);
ssd_widget_add( cont, label);
ssd_widget_add( cont, ecnt);
ssd_widget_add( ti->tab, cont);
return ti->tab;
}
void on_tabcontrol_closed( int exit_code, void* context)
{
atcctx_ptr tc = get_atcctx();
if(tc->on_tabcontrol_closed)
tc->on_tabcontrol_closed();
list_items_free( &s_history);
}
// If tab cannot handle key pressed, move focus to tab default widget:
static BOOL on_unhandled_key_pressed(
int tab,
const char* utf8char,
uint32_t flags)
{
atcctx_ptr tc = get_atcctx();
SsdWidget active_tab = tc->tab_info[tab].tab;
SsdWidget default_widget = NULL;
switch(tab)
{
case tab_city: