2 * common__ob_controls.cpp
4 * Created on: 28 avr. 2009
14 #include "common__ob_controls.h"
15 #include "common__ob_object.h"
16 #include "common__object_stage.h"
21 //****************************************************
22 std::map
<wxString
,ob_property
*> ob_props
;
23 //****************************************************
25 //-------------------------------------------------------------
28 ANN__new_atom( const wxString
& tag
)
30 atom_path
* t
= new atom_path
;
36 //-------------------------------------------------------------
39 ANN__new_atom( int num_token
)
41 atom_path
* t
= new atom_path
;
43 t
->num_token
= num_token
;
47 //-------------------------------------------------------------
50 ANN__new_atom( atom_path
* at
)
55 atom_path
* t
= new atom_path
;
57 t
->num_token
= at
->num_token
;
61 //****************************************************
62 ob_token_path::ob_token_path( const wxString
& tag
, int num_token
)
64 l_atoms
.push_back( ANN__new_atom(tag
) );
66 l_atoms
.push_back( ANN__new_atom(num_token
) );
69 //-------------------------------------------------------------
71 ob_token_path::operator=( const ob_token_path
& obtp
)
74 std::list
<atom_path
*>::const_iterator
it(obtp
.l_atoms
.begin())
75 , it_end (obtp
.l_atoms
.end());
76 for( ; it
!= it_end
; it
++ )
77 l_atoms
.push_back( ANN__new_atom( *it
));
81 //-------------------------------------------------------------
82 ob_token_path::ob_token_path(const ob_token_path
& ob_tp
, const wxString
& subtag
,int num_sub_token
)
85 if( subtag
!= wxString() )
87 l_atoms
.push_back( ANN__new_atom( subtag
) );
88 if( num_sub_token
>= 0 )
89 l_atoms
.push_back( ANN__new_atom(num_sub_token
) );
93 //-------------------------------------------------------------
94 ob_token_path::ob_token_path( ob_token_path
& src
)
96 std::list
<atom_path
*>::iterator
it(src
.l_atoms
.begin())
97 , it_end (src
.l_atoms
.end());
98 for( ; it
!= it_end
; it
++ )
99 l_atoms
.push_back( ANN__new_atom( *it
));
102 //-------------------------------------------------------------
103 ob_token_path::~ob_token_path()
108 //-------------------------------------------------------------
110 ob_token_path::Clear_l_atoms()
112 while( l_atoms
.empty() == false )
114 atom_path
* at
= l_atoms
.front();
121 //-------------------------------------------------------------
123 ob_token_path::IsEmpty()
125 return l_atoms
.empty();
128 //-------------------------------------------------------------
130 ob_token_path::GetPath()
133 std::list
<atom_path
*>::iterator
it(l_atoms
.begin())
134 , it_end (l_atoms
.end());
135 for( ; it
!= it_end
; it
++ )
139 if( (*it
)->tag
!= wxString() )
144 res
+= wxT(">") + (*it
)->tag
;
148 res
+= wxT("=") + IntToStr((*it
)->num_token
);
156 //-------------------------------------------------------------
158 ob_token_path::BuildPath_Sibling_Token( int decal
)
160 if( l_atoms
.size() < 2 )
162 ob_token_path
* res
= new ob_token_path
;
163 std::list
<atom_path
*>::iterator
it(l_atoms
.begin())
164 , it_end (l_atoms
.end());
167 for( ; it
!= it_end
; it
++ )
173 res
->l_atoms
.push_back( ANN__new_atom(*it
) );
174 if( (*it
)->tag
== wxString() )
181 if( nb_tokens
!= 1 || b_ok
== false )
186 atom_path
* last_atom
= res
->l_atoms
.back();
187 last_atom
->num_token
+= decal
;
188 if( last_atom
->num_token
<= 0 )
197 //-------------------------------------------------------------
199 ob_token_path::Append__SubToken( int num_sub_token
)
201 if( num_sub_token
<= 0 )
203 if( l_atoms
.size() < 1 )
205 if( l_atoms
.back()->tag
!= wxString() )
207 l_atoms
.push_back( ANN__new_atom( num_sub_token
));
211 //-------------------------------------------------------------
213 ob_token_path::Append__SubTag( const wxString
& subtag
)
215 if( subtag
== wxString() );
217 if( l_atoms
.back()->tag
== wxString() )
219 l_atoms
.push_back( ANN__new_atom( subtag
));
223 //-------------------------------------------------------------
225 ob_token_path::Resolve_With( ob_object
* _o
)
228 std::list
<atom_path
*>::iterator
it(l_atoms
.begin())
229 , it_end (l_atoms
.end());
230 for( ; it
!= it_end
; it
++ )
234 atom_path
* at
= (*it
);
235 if( at
->tag
!= wxString() )
236 res
= res
->GetSubObject( at
->tag
);
243 //-------------------------------------------------------------
245 ob_token_path::Get_With( ob_object
* _o
)
247 if( l_atoms
.back()->tag
!= wxString() )
250 ob_object
* subobj
= Resolve_With( _o
);
253 return subobj
->GetToken( l_atoms
.back()->num_token
);
256 //-------------------------------------------------------------
258 ob_token_path::Set_To( ob_object
* _o
, wxString
& val
)
265 //****************************************************
266 //****************************************************
267 //****************************************************
268 //****************************************************
269 //****************************************************
270 //****************************************************
271 //****************************************************
272 //****************************************************
273 //****************************************************
275 //*********** new event
276 DEFINE_EVENT_TYPE(wxEVT_OBPROP_CHANGE
)
278 wxColour
ob_property::default_values_color( 200,200,255);
280 //****************************************************
281 ob_property::ob_property( const wxString
& _tag
,const int _num_token
283 , const wxString
& _def_val
, int _do_on_default
)
285 int ind_dblpt
= _tag
.Find( wxT(":") );
286 if( ind_dblpt
!= wxNOT_FOUND
)
288 prefix
= _tag
.Left(ind_dblpt
);
289 tag
= _tag
.Right(_tag
.Len()-ind_dblpt
-1);
296 num_token
= _num_token
;
297 type_prop
= _type_prop
;
299 do_on_default
= _do_on_default
;
303 //-------------------------------------------------------------
304 ob_property::~ob_property()
308 //-------------------------------------------------------------
310 ob_property::SetRange(wxWindow
* _comboBox
, int min
,int max
)
315 wxComboBox
* comboBox
= (wxComboBox
*) _comboBox
;
318 for( int i
= min
; i
<= max
; i
++ )
320 wxStringClientData
*_data
= new wxStringClientData();
321 _data
->SetData( IntToStr( i
) );
322 comboBox
->Append( IntToStr( i
), _data
);
326 //-------------------------------------------------------------
328 ob_property::SetEnums(wxWindow
* _comboBox
, const wxArrayString
& _displayed
, const wxArrayString
& _values
)
330 if( _displayed
.Count() != _values
.Count() )
332 wxMessageBox( wxT("BUG!!!\nob_property::SetEnums\n counts doesn't match !\n") );
336 wxComboBox
* comboBox
= (wxComboBox
*) _comboBox
;
339 for( size_t i
= 0; i
< _displayed
.Count(); i
++ )
341 wxStringClientData
*_data
= new wxStringClientData();
342 _data
->SetData( _values
[i
] );
343 comboBox
->Append( _displayed
[i
], _data
);
347 //-------------------------------------------------------------
349 ob_property::BuildControls(
353 , const wxString
& ctrlName
, int ctrl_w
354 , const wxString
& str_label
, int label_w
358 wxValidator
* validator
= NULL
;
362 case PROPTYPE_STRING
:
364 validator
= (wxValidator
*) wxDefaultValidator
.Clone();
366 case PROPTYPE_STRING_NO_WS
:
368 validator
= new wxTextValidator_NoWhiteSpace();
370 case PROPTYPE_NUMBER
:
372 validator
= new wxValidator_Restrict_Range('0','9');
374 case PROPTYPE_NEGATIVENUMBER
:
376 validator
= new wxValidator_Restrict_Range('0','9');
378 case PROPTYPE_RELATIVENUMBER
:
380 validator
= new wxValidatorIntegerRelative();
384 validator
= new wxValidatorFloat();
386 case PROPTYPE_FLOAT_POSITIVE
:
388 validator
= new wxValidatorFloatPositive();
392 case PROPTYPE_OBFILE
:
397 case PROPTYPE_BOOL_EXSISTENCE
:
409 wxSizer
* sizer_sub
= NULL
;
410 wxWindow
* label
= NULL
;
414 sizer_sub
= new wxBoxSizer( wxHORIZONTAL
);
416 if( str_label
!= wxString() )
418 label
= new wxStaticText( parent
, wxID_ANY
, str_label
419 ,wxDefaultPosition
,wxSize(label_w
,-1) );
420 sizer_sub
->Add(label
, 0, wxALIGN_CENTER
);
423 theCtrl
= new wxTextCtrl(
424 parent
, wxID_ANY
, wxString()
425 , wxDefaultPosition
, wxSize(ctrl_w
,-1)
426 , wxBORDER_SUNKEN
|wxTE_PROCESS_ENTER
|more_styles
430 wxEVT_COMMAND_TEXT_UPDATED
431 , wxCommandEventHandler(ob_property::Evt_TxtChange
)
433 sizer_sub
->Add( theCtrl
);
436 else if( _type
== 1 )
438 sizer_sub
= new wxBoxSizer( wxHORIZONTAL
);
439 if( str_label
!= wxString() )
441 label
= new wxStaticText( parent
, wxID_ANY
, str_label
442 ,wxDefaultPosition
,wxSize(label_w
,-1)
444 sizer_sub
->Add(label
, 0, wxALIGN_CENTER
);
447 theCtrl
= new prObFileChooserCtrl(
453 theCtrl
->SetName( ctrlName
);
455 wxEVT_OBFILECHOOSER_CHANGE
456 , wxCommandEventHandler(ob_property::Evt_FileChange
)
458 sizer_sub
->Add( theCtrl
);
460 else if( _type
== 2 )
462 sizer_sub
= new wxBoxSizer( wxHORIZONTAL
);
463 theCtrl
= new wxCheckBox(
464 parent
, wxID_ANY
, str_label
465 , wxDefaultPosition
, wxSize(ctrl_w
,-1)
466 , wxBORDER_SUNKEN
|more_styles
470 wxEVT_COMMAND_CHECKBOX_CLICKED
471 , wxCommandEventHandler(ob_property::Evt_ChckChange
)
473 sizer_sub
->Add( theCtrl
);
475 else if( _type
== 3 )
477 sizer_sub
= new wxBoxSizer( wxHORIZONTAL
);
478 label
= new wxStaticText( parent
, wxID_ANY
, str_label
479 ,wxDefaultPosition
,wxSize(label_w
,-1) );
480 sizer_sub
->Add(label
, 0, wxALIGN_CENTER
);
482 theCtrl
= new wxComboBox(
483 parent
, wxID_ANY
, wxString()
484 , wxDefaultPosition
, wxSize( ctrl_w
, -1 )
490 wxEVT_COMMAND_COMBOBOX_SELECTED
491 , wxCommandEventHandler(ob_property::Evt_Combo
)
493 sizer_sub
->Add( theCtrl
);
496 if( theCtrl
!= NULL
)
497 theCtrl
->SetClientData( (void*) obj
);
499 if( validator
!= NULL
)
504 //-------------------------------------------------------------
506 ob_property::Get_SpecialDefault_Val(ob_object
* _o
)
508 if( referer_path
.IsEmpty() == true )
511 if( ob_stage::Is_Stage_Spawn_Type( _o
) == true )
513 ob_spawn
* o
= (ob_spawn
*) _o
;
514 if( o
->entity_ref
== NULL
|| o
->entity_ref
->obj_container
== NULL
)
517 return referer_path
.Get_With( o
->entity_ref
->obj_container
);
523 //-------------------------------------------------------------
525 ob_property::Have_SpecialDefault_Val(ob_object
* _o
)
527 if( referer_path
.IsEmpty() == true )
529 if( ob_stage::Is_Stage_Spawn_Type( _o
) == true )
531 ob_spawn
* o
= (ob_spawn
*) _o
;
532 if( o
->entity_ref
== NULL
|| o
->entity_ref
->obj_container
== NULL
)
535 return referer_path
.Resolve_With( o
->entity_ref
->obj_container
) != NULL
;
541 //-------------------------------------------------------------
543 ob_property::Get_Default_Val(ob_object
* _o
)
547 wxString res
= Get_SpecialDefault_Val( _o
);
548 if( res
!= wxString() )
553 //-------------------------------------------------------------
555 ob_property::Get_Curr_Value(ob_object
* _o
)
557 if( tag
.Upper() == _o
->name
.Upper() || tag
== wxString() )
558 return _o
->GetToken( num_token
);
560 ob_object
* subobj
= _o
->GetSubObject( tag
);
564 return subobj
->GetToken( num_token
);
567 //-------------------------------------------------------------
569 ob_property::Update_CtrlVal( wxWindow
* ctrl
)
571 // Some sanity checks
574 ob_object
* obj
= (ob_object
*) ctrl
->GetClientData();
577 wxString w_name
= ctrl
->GetName();
578 wxString typ_Ctrl
= w_name
.Left(2);
579 if( typ_Ctrl
!= wxT("TC")
580 && typ_Ctrl
!= wxT("CO")
581 && typ_Ctrl
!= wxT("CH")
585 // Get the curr val for the object
586 wxString val
= Get_Curr_Value( obj
);
588 if( typ_Ctrl
== wxT("TC") )
590 wxTextCtrl
* t
= ((wxTextCtrl
*)ctrl
);
591 if( t
->GetValue() == val
)
593 obj
->SetEdited( true );
594 t
->ChangeValue( val
);
598 if( typ_Ctrl
== wxT("CO") )
600 wxComboBox
* t
= ((wxComboBox
*)ctrl
);
601 int curr_ind
= t
->GetCurrentSelection();
603 int new_ind
= wxNOT_FOUND
;
604 for( size_t i
= 0 ; i
< t
->GetCount() ; i
++)
606 wxStringClientData
* scd
=
607 (wxStringClientData
*)t
->GetClientObject(i
);
608 if( scd
->GetData().Upper() == val
.Upper() )
614 if( new_ind
== curr_ind
)
617 obj
->SetEdited( true );
618 t
->SetSelection( new_ind
);
622 if( typ_Ctrl
== wxT("CH") )
624 wxCheckBox
* t
= ((wxCheckBox
*)ctrl
);
625 if( t
->GetValue() == (val
== wxT("1")) )
628 obj
->SetEdited( true );
629 t
->SetValue( ! t
->GetValue() );
637 //-------------------------------------------------------------
639 ob_property::CreateDefaultObject(ob_object
* o
)
641 ob_object
* subobj
= new ob_object( tag
);
643 if( prefix
!= wxString() )
644 pref
= prefix
+ wxT(":") + pref
;
645 // Insert default values
646 for( int i
= 0; i
< num_token
- 1; i
++ )
648 wxString t_tag
= pref
+ wxT("=") + IntToStr(i
);
649 if( ob_props
.find(t_tag
) == ob_props
.end() ||ob_props
[t_tag
] == NULL
)
651 subobj
->SetToken( i
, wxT("0") );
655 subobj
->SetToken( i
, ob_props
[t_tag
]->Get_Default_Val(o
) );
658 subobj
->SetToken( num_token
, Get_Default_Val(o
) );
662 //-------------------------------------------------------------
664 ob_property::Signal_Modified( ob_object
* obj
, wxWindow
* theCtrl
)
670 if( obj
->parent
!= NULL
)
671 obj
->parent
->edited
= true;
672 wxCommandEvent
evt(wxEVT_OBPROP_CHANGE
, theCtrl
->GetId());
673 theCtrl
->ProcessEvent(evt
);
676 //-------------------------------------------------------------
678 ob_property::MayTruncate(ob_object
* obj
, ob_object
* subobj
, wxWindow
* theCtrl
)
680 size_t i
= num_token
+ 1;
682 if( prefix
!= wxString() )
683 pref
= prefix
+ wxT(":") + pref
;
684 wxString t_tag
= pref
+ wxT("=") + IntToStr(i
);
685 while( ob_props
.find(t_tag
) != ob_props
.end() && ob_props
[t_tag
] != NULL
)
687 // Subobject deny truncation
688 if( ob_props
[t_tag
]->do_on_default
!= OBPROP_TRUNCATE
)
691 // Subobject is not on default val
692 if( ob_props
[t_tag
]->Get_Default_Val(obj
)
693 != subobj
->GetToken( i
) )
697 wxString t_tag
= pref
+ wxT("=") + IntToStr(i
);
700 // truncate the uppers tokens
701 if( (int) subobj
->nb_tokens
> num_token
)
703 Signal_Modified( obj
, theCtrl
);
704 subobj
->nb_tokens
= num_token
;
707 // truncate the lowers tokens
708 for( i
= num_token
;i
>= 0; i
-- )
710 wxString t_tag
= pref
+ wxT("=") + IntToStr(i
);
711 if( ob_props
.find(t_tag
) != ob_props
.end() && ob_props
[t_tag
] != NULL
)
714 if( ob_props
[t_tag
]->do_on_default
!= OBPROP_TRUNCATE
)
717 // Subobject is not on default val
718 if( ob_props
[t_tag
]->Get_Default_Val(obj
)
719 != subobj
->GetToken( i
)
723 if( subobj
->nb_tokens
> i
-1 )
725 Signal_Modified( obj
, theCtrl
);
726 subobj
->nb_tokens
= i
-1;
731 //-------------------------------------------------------------
733 ob_property::pUpdate( ob_object
* obj
, wxWindow
* theCtrl
, const wxString
& val
)
736 ob_object
* subobj
= NULL
;
737 if( tag
.Upper() != obj
->name
.Upper() && tag
!= wxString() )
739 subobj
= obj
->GetSubObject( tag
);
740 if( subobj
== NULL
&& val
== Get_Default_Val(obj
) )
746 if( subobj
!= NULL
&& val
== Get_Default_Val(obj
) )
748 switch (do_on_default
& OBPROP_DEF_MASK
)
751 Signal_Modified( obj
, theCtrl
);
754 case OBPROP_TRUNCATE
:
755 subobj
->SetToken( num_token
, val
);
756 MayTruncate(obj
,subobj
,theCtrl
);
763 subobj
= CreateDefaultObject(obj
);
764 obj
->Add_SubObj( subobj
);
765 Signal_Modified( obj
, theCtrl
);
769 prec_val
= subobj
->GetToken( num_token
);
770 if( prec_val
== val
)
774 subobj
->SetToken( num_token
, val
);
775 Signal_Modified( obj
, theCtrl
);
778 //-------------------------------------------------------------
780 ob_property::Evt_TxtChange(wxCommandEvent
& evt
)
782 wxTextCtrl
* _ctrl
= (wxTextCtrl
*) evt
.GetEventObject();
785 ob_object
* obj
= (ob_object
*) _ctrl
->GetClientData();
789 wxString val
= _ctrl
->GetValue();
790 if( val
== wxString() && (do_on_default
& OBPROP_SETDEF_IFEMPTY
) != 0 )
792 val
= Get_Default_Val(obj
);
793 _ctrl
->ChangeValue( val
);
796 if( val
== Get_SpecialDefault_Val(obj
) && Have_SpecialDefault_Val(obj
) == true )
797 _ctrl
->SetBackgroundColour( default_values_color
);
799 _ctrl
->SetBackgroundColour( *wxWHITE
);
801 pUpdate( obj
, _ctrl
, val
);
806 //-------------------------------------------------------------
808 ob_property::Evt_FileChange(wxCommandEvent
& evt
)
810 prObFileChooserCtrl
* _ctrl
= (prObFileChooserCtrl
*) evt
.GetEventObject();
813 ob_object
* obj
= (ob_object
*) _ctrl
->GetClientData();
817 pUpdate( obj
, _ctrl
, _ctrl
->GetObPath() );
821 //-------------------------------------------------------------
823 ob_property::Evt_ChckChange(wxCommandEvent
& evt
)
825 wxCheckBox
* _ctrl
= (wxCheckBox
*) evt
.GetEventObject();
828 ob_object
* obj
= (ob_object
*) _ctrl
->GetClientData();
832 pUpdate( obj
, _ctrl
, BoolToStr(_ctrl
->GetValue()) );
837 //-------------------------------------------------------------
839 ob_property::Evt_Combo(wxCommandEvent
& evt
)
841 wxComboBox
* _ctrl
= (wxComboBox
*) evt
.GetEventObject();
844 ob_object
* obj
= (ob_object
*) _ctrl
->GetClientData();
848 if( _ctrl
->GetSelection() == wxNOT_FOUND
)
849 pUpdate( obj
, _ctrl
, Get_Default_Val(obj
) );
852 wxStringClientData
* _data
=
853 (wxStringClientData
*) _ctrl
->GetClientObject(_ctrl
->GetSelection());
854 pUpdate( obj
, _ctrl
, _data
->GetData() );
860 //****************************************************
861 //****************************************************
862 //****************************************************
863 KalachnikofButton::KalachnikofButton(wxWindow
* parent
, wxWindowID id
, const wxBitmap
& bitmap
, const size_t _clicks_interval
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
, const wxString
& name
)
864 :wxBitmapButton( parent
, id
, bitmap
, pos
,size
,style
,validator
, name
)
866 clicks_interval
= _clicks_interval
;
867 theTimer
= new wxTimer( this, 1 );
871 //------------------------------------------------------------------------
872 KalachnikofButton::~KalachnikofButton()
878 //------------------------------------------------------------------------
880 KalachnikofButton::EvtTimerOut( wxTimerEvent
& event
)
882 if( b_clickedOn
== true )
884 // AutoProcess the event to permit Connect() functions to work
885 wxCommandEvent
_evt( wxEVT_COMMAND_BUTTON_CLICKED
);
886 _evt
.SetEventObject( this );
887 _evt
.SetId( GetId() );
888 GetEventHandler()->ProcessEvent( _evt
);
895 //------------------------------------------------------------------------
897 KalachnikofButton::EvtMouseSomething( wxMouseEvent
& event
)
899 if( event
.LeftDown() == true )
901 if( theTimer
->IsRunning() == false )
904 theTimer
->Start( clicks_interval
);
907 else if( event
.Leaving() == true || event
.LeftUp() == true )
916 //------------------------------------------------------------------------
917 BEGIN_EVENT_TABLE(KalachnikofButton
, wxBitmapButton
)
918 EVT_MOUSE_EVENTS( KalachnikofButton::EvtMouseSomething
)
919 EVT_TIMER(1, KalachnikofButton::EvtTimerOut
)
923 //****************************************************
924 //****************************************************
925 //****************************************************
926 //*********** new event
927 DEFINE_EVENT_TYPE(wxEVT_OBFILECHOOSER_CHANGE
)
930 //****************************************************
932 const int fileTextMinW
= 150;
933 const int fileTextMaxH
= 50;
934 const int filePickerW
= 30;
935 const int filePickerH
= 30;
937 //****************************************************
938 //****************************************************
941 BEGIN_EVENT_TABLE(prObFileChooserCtrl
, wxControl
)
942 EVT_PAINT(prObFileChooserCtrl::EvtPaint
)
943 EVT_SIZE(prObFileChooserCtrl::EvtSize
)
944 EVT_SET_FOCUS(prObFileChooserCtrl::EvtGetFocus
)
947 //****************************************************
948 //****************************************************
949 //****************************************************
951 prObFileChooserCtrl::prObFileChooserCtrl(
954 , const wxString
& _File_or_Directory
955 , const bool _b_file_must_exist
959 :wxControl( _parent
, _id
, wxDefaultPosition
, wxDefaultSize
,
960 _style
| wxBORDER_SIMPLE
| wxTE_PROCESS_TAB
963 b_file_must_exist
= _b_file_must_exist
;
964 File_or_Directory
= _File_or_Directory
;
968 //******************************************
969 txtCtrl_file
= new wxTextCtrl(this, wxID_ANY
, wxString(),wxDefaultPosition
, wxDefaultSize
,
970 wxTE_PROCESS_ENTER
| wxTE_PROCESS_TAB
| wxTE_RIGHT
);
971 txtCtrl_file
->SetInsertionPointEnd();
972 txtCtrl_file
->Connect( wxID_ANY
, wxEVT_KEY_DOWN
, wxKeyEventHandler(prObFileChooserCtrl::EvtCharPress
), NULL
, this );
974 if( _width
== wxDefaultCoord
)
975 minWidth
= fileTextMinW
+ filePickerW
;
979 int txtW
= minWidth
- filePickerW
;
981 txtCtrl_file
->SetMinSize( wxSize( txtW
, wxDefaultCoord
) );
982 txtCtrl_file
->SetSize( wxSize( txtW
, wxDefaultCoord
) );
983 txtCtrl_file
->Move( 0, 0 );
986 //******************************************
987 int fp_style
= wxFLP_OPEN
| wxFLP_CHANGE_DIR
;
988 if( _b_file_must_exist
)
989 fp_style
|= wxFLP_FILE_MUST_EXIST
;
990 filePck_file
= new wxFilePickerCtrl( this, wxID_ANY
,
991 dataDirPath
.GetFullPath(), wxT("Select custom selection screen file"), wxT("*.*"),
992 wxDefaultPosition
, wxDefaultSize
, fp_style
);
993 filePck_file
->SetMaxSize( wxSize(30, wxDefaultCoord
));
994 filePck_file
->SetInitialSize(wxSize(filePickerW
, filePickerH
));
995 filePck_file
->Move( txtW
, 0 );
997 filePck_file
->Connect(wxEVT_COMMAND_FILEPICKER_CHANGED
, wxFileDirPickerEventHandler(prObFileChooserCtrl::EvtImgPickerChg
), NULL
, this );
998 filePck_file
->Connect(wxEVT_ENTER_WINDOW
, wxMouseEventHandler(prObFileChooserCtrl::EvtImgPickerClick
), NULL
, this );
1003 //****************************************************
1005 prObFileChooserCtrl::~prObFileChooserCtrl()
1010 //****************************************************
1012 void prObFileChooserCtrl::EvtSize(wxSizeEvent
& event
)
1015 wxSize _s
= event
.GetSize();
1016 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, _s
.GetWidth(), _s
.GetHeight() );
1022 //****************************************************
1024 void prObFileChooserCtrl::EvtGetFocus( wxFocusEvent
& evt
)
1026 txtCtrl_file
->SetFocus();
1031 //****************************************************
1033 void prObFileChooserCtrl::EvtCharPress( wxKeyEvent
& event
)
1035 int kc
= event
.GetKeyCode();
1038 wxNavigationKeyEvent new_event
;
1039 new_event
.SetEventObject( GetParent() );
1040 new_event
.SetDirection( !event
.ShiftDown() );
1041 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1042 new_event
.SetWindowChange( event
.ControlDown() );
1043 new_event
.SetCurrentFocus( this );
1044 GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1047 else if( kc
== WXK_RETURN
|| kc
== WXK_NUMPAD_ENTER
)
1049 int err
= Update(false);
1053 wxMessageBox( wxT("Not a valid OB file !"), wxT("WARNING"), wxOK
| wxICON_EXCLAMATION
, this );
1055 wxMessageBox( wxT("File doesn't exist !"), wxT("WARNING"), wxOK
| wxICON_EXCLAMATION
, this );
1057 txtCtrl_file
->SetBackgroundColour( wxColour( 255, 200,200));
1060 txtCtrl_file
->SetBackgroundColour( wxColour( 255, 255,255));
1068 //****************************************************
1070 void prObFileChooserCtrl::EvtImgPickerChg(wxFileDirPickerEvent
& event
)
1072 int err
= Update(true);
1076 wxMessageBox( wxT("Not a valid OB file !"), wxT("WARNING"), wxOK
| wxICON_EXCLAMATION
, this );
1078 wxMessageBox( wxT("File doesn't exist !"), wxT("WARNING"), wxOK
| wxICON_EXCLAMATION
, this );
1083 //****************************************************
1085 void prObFileChooserCtrl::EvtPaint( wxPaintEvent
& event
)
1092 //****************************************************
1094 void prObFileChooserCtrl::EvtImgPickerClick( wxMouseEvent
& event
)
1100 //****************************************************
1102 //****************************************************
1104 void prObFileChooserCtrl::DoSetSize(int x
, int y
, int width
, int height
)
1106 int txtW
= width
- filePickerW
;
1110 int _th
= (height
> fileTextMaxH
) ? fileTextMaxH
: height
;
1111 txtCtrl_file
->SetSize( txtW
, _th
);
1113 txtCtrl_file
->Move( 0, (height
- _th
) / 2 );
1115 int fpY
= (height
- filePickerH
) /2 ;
1118 filePck_file
->Move( txtW
, fpY
);
1119 wxControl::DoSetSize( x
,y
,width
,height
);
1121 // wxMessageBox( "W : " + IntToStr( width ) + "\nH" + IntToStr( height ) );
1125 //****************************************************
1127 wxSize
prObFileChooserCtrl::DoGetBestSize() const
1129 return wxSize( fileTextMaxH
, filePickerH
);
1132 //****************************************************
1134 prObFileChooserCtrl::GetMinSize() const
1136 return wxSize( minWidth
, filePickerH
);
1141 //****************************************************
1143 prObFileChooserCtrl::Update(bool b_filePicker
)
1145 if( b_updating
== true )
1153 fn
= Convert_To_Ob_Path( filePck_file
->GetPath() );
1155 // Not a valid obpath
1156 if( fn
== wxString() )
1162 txtCtrl_file
->SetValue( fn
);
1166 fn
= txtCtrl_file
->GetValue();
1168 wxFileName wfn
= GetObFile( fn
);
1169 wxString f_p
= wfn
.GetFullPath();
1171 if( b_file_must_exist
&& wfn
.FileExists() == false )
1177 filePck_file
->SetPath( f_p
);
1180 File_or_Directory
= filePck_file
->GetPath();
1182 // AutoProcess the event to permit Connect() functions to work
1183 wxCommandEvent
_evt( wxEVT_OBFILECHOOSER_CHANGE
);
1184 _evt
.SetEventObject( this );
1185 _evt
.SetId( GetId() );
1186 GetEventHandler()->ProcessEvent( _evt
);
1193 //****************************************************
1195 prObFileChooserCtrl::SetFullPath( const wxString
& _file
)
1197 return SetObPath( Convert_To_Ob_Path( _file
) );
1201 //****************************************************
1203 bool prObFileChooserCtrl::SetObPath( const wxString
& _file
)
1205 wxString prev_fn
= txtCtrl_file
->GetValue();
1206 txtCtrl_file
->SetValue( _file
);
1207 if( Update(false) != 0 )
1209 txtCtrl_file
->SetValue( prev_fn
);
1215 //****************************************************
1217 wxFileName
prObFileChooserCtrl::GetFileName()
1219 return GetObFile( txtCtrl_file
->GetValue() );
1223 //****************************************************
1225 wxString
prObFileChooserCtrl::GetFullPath()
1227 return Convert_To_Ob_Path( txtCtrl_file
->GetValue() );
1231 //****************************************************
1233 wxString
prObFileChooserCtrl::GetObPath()
1235 return txtCtrl_file
->GetValue();
1238 //******************************************
1240 void prObFileChooserCtrl::Init()
1247 if( File_or_Directory
!= wxString() )
1248 if( SetFullPath( File_or_Directory
) )
1251 if( dataDirPath
.DirExists() )
1253 wxString dummy_file
= wxDir::FindFirst( dataDirPath
.GetFullPath(), wxT("*"), wxDIR_FILES
);
1254 if( wxFileName( dummy_file
).FileExists() )
1256 filePck_file
->SetPath( dummy_file
);
1257 // wxMessageBox( dummy_file , "WARNING", wxOK | wxICON_EXCLAMATION, this );
1261 wxMessageBox( wxT("DataDir path invalid : <") + dataDirPath
.GetFullPath() + wxT(">"), wxT("WARNING"), wxOK
| wxICON_EXCLAMATION
, this );
1267 //****************************************************
1268 //****************************************************
1269 //****************************************************
1270 //****************************************************
1271 //****************************************************
1272 //****************************************************
1273 //****************************************************
1274 //****************************************************
1275 //****************************************************
1276 // THE SCROLL PANNEL
1277 //****************************************************
1279 AScrollPanel::AScrollPanel( wxWindow
*_parent
)
1280 : wxScrolledWindow( _parent
, wxID_ANY
, wxDefaultPosition
,wxDefaultSize
,
1281 wxTAB_TRAVERSAL
| wxVSCROLL
| wxHSCROLL
|wxFULL_REPAINT_ON_RESIZE
)
1285 SetScrollRate( 15, 15 );
1286 EnableScrolling(!b_fix_H
, !b_fix_V
);
1287 SetAutoLayout( true );
1292 //************************************************************************************
1294 AScrollPanel::~AScrollPanel()
1298 //************************************************************************************
1300 void AScrollPanel::EvtSize( wxSizeEvent
& event
)
1302 // wxSize size = GetBestVirtualSize();
1303 // // wxSize s = event.GetSize();
1305 // SetVirtualSize( size );
1316 //************************************************************************************
1318 bool AScrollPanel::Layout()
1320 // AdjustScrollbars();
1321 return wxScrolledWindow::Layout();
1326 //************************************************************************************
1328 wxSize
AScrollPanel::GetMinSize()const
1330 wxSizer
*m_sizer
= GetSizer();
1331 if( m_sizer
== NULL
)
1332 return wxScrolledWindow::GetMinSize();
1334 wxSize s
= m_sizer
->GetMinSize();
1344 // wxMessageBox( "Size : " + IntToStr( s.x ) + "," + IntToStr(s.y ) );
1345 if( b_fix_V
&& HasScrollbar( wxHORIZONTAL
))
1348 if( b_fix_H
&& HasScrollbar( wxVERTICAL
))
1356 //************************************************************************************
1358 wxSize
AScrollPanel::DoGetBestSize() const
1360 return GetVirtualSize();
1364 //************************************************************************************
1366 void AScrollPanel::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1368 wxScrolledWindow::DoSetSize( x
,y
,width
,height
,sizeFlags
);
1372 //************************************************************************************
1374 void AScrollPanel::DoGetClientSize( int* width
, int* height
) const
1376 wxScrolledWindow::DoGetClientSize( width
, height
);
1381 //************************************************************************************
1383 void AScrollPanel::Set_FixedDirections( bool b_H
, bool b_V
)
1387 EnableScrolling(!b_fix_H
, !b_fix_V
);
1392 //************************************************************************************
1394 void AScrollPanel::OnPaint( wxPaintEvent
&event
)
1396 // wxPaintDC dc( this );
1398 wxSize s = GetClientSize();
1399 dc.DrawLine( 0, 0, s.x, s.y );
1404 //************************************************************************************
1405 //************************************************************************************
1406 //************************************************************************************
1407 //************************************************************************************
1409 BEGIN_EVENT_TABLE(AScrollPanel
, wxScrolledWindow
)
1410 EVT_SIZE(AScrollPanel::EvtSize
)
1411 EVT_PAINT(AScrollPanel::OnPaint
)