22using System . Collections . Generic ;
33using System . Drawing ;
44using System . Windows . Forms ;
5+ using KeePass . UI ;
56using KeePassLib ;
67
78namespace KPEntryTemplates {
@@ -23,6 +24,7 @@ private void InitializeGridView(TabPage page) {
2324 return ;
2425 }
2526
27+ page . HorizontalScroll . Enabled = false ;
2628 page . SuspendLayout ( ) ;
2729 dataGridView = new DataGridView ( ) ;
2830 colTitle = new DataGridViewTextBoxColumn ( ) ;
@@ -44,15 +46,18 @@ private void InitializeGridView(TabPage page) {
4446 dataGridView . DefaultValuesNeeded += dataGridView_DefaultValuesNeeded ;
4547 dataGridView . ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode . AutoSize ;
4648 dataGridView . Columns . AddRange ( new DataGridViewColumn [ ] {
47- colTitle ,
49+ colTitle ,
4850 colField ,
49- colFieldName ,
50- colType ,
51+ colFieldName ,
52+ colType ,
5153 colOpt , colOptionValue } ) ;
5254 dataGridView . Location = new Point ( 0 , 0 ) ;
5355 dataGridView . Name = "dataGridView" ;
54- dataGridView . Size = new System . Drawing . Size ( TAB_WIDTH , TAB_HEIGHT ) ;
55- dataGridView . TabIndex = 0 ;
56+ dataGridView . TabIndex = 0 ;
57+ SetBaseSizes ( page ) ;
58+ var template = new EntryTemplate ( null , null , "DataGridView" , 0 , null ) ; //used just for the conrol sizing
59+ SetControlSizing ( template , dataGridView ) ;
60+ dataGridView . ScrollBars = ScrollBars . None ;
5661 dataGridView . DragDrop += dataGridView_DragDrop ;
5762 dataGridView . DragOver += dataGridView_DragOver ;
5863 dataGridView . MouseDown += dataGridView_MouseDown ;
@@ -77,17 +82,17 @@ private void InitializeGridView(TabPage page) {
7782 //
7883 colField . HeaderText = "Field" ;
7984 colField . Items . AddRange ( new object [ ] {
80- "Custom" ,
81- "Title" ,
82- "Username" ,
83- "Password" ,
85+ "Custom" ,
86+ "Title" ,
87+ "Username" ,
88+ "Password" ,
8489 "Password Confirmation" ,
8590 "URL" ,
8691 "Notes" ,
8792 "Override URL" ,
8893 "Expiry Date" } ) ;
8994 colField . Name = "colField" ;
90- colField . Width = 105 ;
95+ colField . Width = DpiUtil . ScaleIntX ( 105 ) ;
9196 colField . DropDownWidth = 180 ;
9297
9398
@@ -98,56 +103,59 @@ private void InitializeGridView(TabPage page) {
98103 colFieldName . HeaderText = "Field Name" ;
99104 colFieldName . Name = "colFieldName" ;
100105 colFieldName . SortMode = DataGridViewColumnSortMode . NotSortable ;
101- colFieldName . Width = 75 ;
106+ colFieldName . Width = DpiUtil . ScaleIntX ( 75 ) ;
102107 //
103108 // colType
104109 //
105110 colType . HeaderText = "Type" ;
106111 colType . Name = "colType" ;
107- colType . Width = 100 ;
112+ colType . Width = DpiUtil . ScaleIntX ( 100 ) ;
108113 colType . Items . AddRange ( new object [ ] {
109- "Inline" ,
114+ "Inline" ,
110115 "Inline URL" ,
111- "Popout" ,
112- "Protected Inline" ,
113- "Protected Popout" ,
116+ "Popout" ,
117+ "Protected Inline" ,
118+ "Protected Popout" ,
114119 "Date" ,
115120 "Time" ,
116121 "Date Time" ,
117122 "Checkbox" ,
118123 "Divider" ,
119- "Listbox"
124+ "Listbox" ,
125+ "RichTextbox"
120126 } ) ;
121127 colType . DropDownWidth = 150 ;
122- colOpt . HeaderText = "Opt " ;
128+ colOpt . HeaderText = "Npt " ;
123129 colOpt . Name = "colOpt" ;
124- colOpt . Width = 40 ;
130+ colOpt . Width = DpiUtil . ScaleIntX ( 40 ) ;
125131 colOpt . UseColumnTextForButtonValue = true ;
126132 colOpt . Text = "Opt" ;
127133 colOpt . ToolTipText = "Option" ;
128134 colOptionValue . AutoSizeMode = DataGridViewAutoSizeColumnMode . None ;
129135 colOptionValue . Visible = false ;
130136 colOptionValue . Name = "colOptionValue" ;
131137 colOptionValue . Width = 0 ;
132-
133-
138+
139+
134140 page . Controls . Add ( dataGridView ) ;
135141 remove_as_template_button = new Button ( ) ;
136142 remove_as_template_button . Text = "Remove As Template" ;
137- remove_as_template_button . Width = TAB_WIDTH - 140 - 45 ;
138- remove_as_template_button . Left = 115 ;
143+ remove_as_template_button . Height = BUTTON_HEIGHT ;
144+ remove_as_template_button . Width = PAGE_WIDTH - DpiUtil . ScaleIntX ( 140 ) - DpiUtil . ScaleIntX ( 45 ) ;
145+ remove_as_template_button . Left = DpiUtil . ScaleIntX ( 85 ) ;
139146 //remove_as_template_button.Height = 28;
140147 remove_as_template_button . UseVisualStyleBackColor = true ;
141- dataGridView . Size = new Size ( TAB_WIDTH , TAB_HEIGHT - remove_as_template_button . Height - 10 ) ; //have to set its size before setting the buttons size
142- remove_as_template_button . Top = dataGridView . Height + 5 ;
148+
149+ dataGridView . Tag = template ;
150+
151+ remove_as_template_button . Tag = template ;
143152 remove_as_template_button . Click += remove_as_template_button_Click ;
153+ SetControlSizing ( template , remove_as_template_button ) ;
144154 page . Controls . Add ( remove_as_template_button ) ;
145- form . AutoScaleDimensions = new System . Drawing . SizeF ( 6F , 13F ) ;
146- form . AutoScaleMode = AutoScaleMode . Font ;
147155 page . ResumeLayout ( ) ;
148-
156+
149157 }
150- private void dataGridView_CellClick ( object sender , DataGridViewCellEventArgs e ) {
158+ private void dataGridView_CellClick ( object sender , DataGridViewCellEventArgs e ) {
151159 if ( e . ColumnIndex != dataGridView . Columns [ "colOpt" ] . Index )
152160 return ;
153161 DataGridViewRow row = dataGridView . Rows [ e . RowIndex ] ;
@@ -157,14 +165,15 @@ private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e){
157165 String msg = "" ;
158166 switch ( type ) {
159167 case "Inline" :
168+ case "RichTextbox" : //CustomRichTextBoxEx
160169 case "Protected Inline" :
161170 msg = "How many lines to show for the textbox(1-100)?" ;
162171 break ;
163172 case "Listbox" :
164173 msg = "Listbox Items, seperate with each with a comma" ;
165174 break ;
166175 }
167- String ret = OptionsForm . GetOption ( msg , ( string ) row . Cells [ "colOptionValue" ] . Value ) ;
176+ String ret = OptionsForm . GetOption ( msg , ( string ) row . Cells [ "colOptionValue" ] . Value ) ;
168177 if ( ret != null )
169178 row . Cells [ "colOptionValue" ] . Value = ret ;
170179 }
@@ -190,7 +199,7 @@ void dataGridView_EditingControlShowing(object sender, DataGridViewEditingContro
190199 else if ( cell . OwningColumn . Name == "colType" ) {
191200 box . SelectedIndexChanged += col_type_box_SelectedIndexChanged ;
192201 }
193- if ( box != null ) {
202+ if ( box != null ) {
194203 box . DropDown += box_DropDown ;
195204 box . SelectedIndexChanged += box_SelectedIndexChanged ;
196205 }
@@ -204,19 +213,20 @@ void box_SelectedIndexChanged(object sender, EventArgs e) {
204213 void box_DropDown ( object sender , EventArgs e ) {
205214 ( ( DataGridViewComboBoxEditingControl ) sender ) . BackColor = Color . White ;
206215 }
207- private void SetRowOptionEnabled ( DataGridViewRow row , String type ) {
216+ private void SetRowOptionEnabled ( DataGridViewRow row , String type ) {
208217 bool opt_enabled = false ;
209218 switch ( type ) {
210219 case "Inline" :
211220 case "Protected Inline" :
221+ case "RichTextbox" :
212222 case "Listbox" :
213223 opt_enabled = true ;
214224 break ;
215225 }
216226
217227 ( row . Cells [ "colOpt" ] as DataGridViewDisableButtonCell ) . Enabled = opt_enabled ;
218228 }
219- private void col_type_box_SelectedIndexChanged ( object sender , EventArgs e ) {
229+ private void col_type_box_SelectedIndexChanged ( object sender , EventArgs e ) {
220230 DataGridViewCell cell = dataGridView . CurrentCell ;
221231 String type = cell . EditedFormattedValue . ToString ( ) ;
222232 SetRowOptionEnabled ( cell . OwningRow , type ) ;
@@ -260,7 +270,7 @@ void col_field_box_SelectedIndexChanged(object sender, EventArgs e) {
260270 break ;
261271 case "Notes" :
262272 fieldName = PwDefs . NotesField ;
263- type = conf . ProtectNotes ? "Protected Inline" : "Inline " ;
273+ type = conf . ProtectNotes ? "Protected Inline" : "RichTextbox " ;
264274 break ;
265275 default :
266276 type = "" ;
@@ -274,13 +284,13 @@ void col_field_box_SelectedIndexChanged(object sender, EventArgs e) {
274284 return ;
275285 }
276286 row . Cells [ "colType" ] . ReadOnly = row . Cells [ "colFieldName" ] . ReadOnly = read_only ;
277- if ( type != "" ) {
287+ if ( type != "" ) {
278288 row . Cells [ "colType" ] . Value = type ;
279289 SetRowOptionEnabled ( row , type ) ;
280290 }
281291 if ( fieldName != "" )
282292 row . Cells [ "colFieldName" ] . Value = fieldName ;
283-
293+
284294
285295 }
286296
@@ -293,7 +303,7 @@ void dataGridView_SelectionChanged(object sender, EventArgs e) {
293303 to_del = null ;
294304
295305 }
296- private void RemoveToDel ( ) {
306+ private void RemoveToDel ( ) {
297307 if ( to_del != null ) {
298308 if ( dataGridView . Rows . Contains ( to_del ) )
299309 dataGridView . Rows . Remove ( to_del ) ;
@@ -369,8 +379,7 @@ void dataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e
369379 if ( res != DialogResult . Retry ) {
370380 dataGridView . CancelEdit ( ) ;
371381 to_del = row ;
372- }
373- else {
382+ } else {
374383 e . Cancel = true ;
375384 row . ErrorText = old_row_err ;
376385 }
@@ -448,8 +457,7 @@ private void init_data_table() {
448457 row . Cells [ "colOptionValue" ] . Value = t . options ;
449458 }
450459
451- }
452- catch ( Exception e ) {
460+ } catch ( Exception e ) {
453461 MessageBox . Show ( e . Message ) ;
454462 }
455463 }
@@ -481,8 +489,7 @@ private void dataGridView_MouseDown(object sender, MouseEventArgs e) {
481489 Size dragSize = SystemInformation . DragSize ;
482490 dragBoxFromMouseDown = new Rectangle ( new Point ( e . X - ( dragSize . Width / 2 ) , e . Y - ( dragSize . Height / 2 ) ) ,
483491 dragSize ) ;
484- }
485- else
492+ } else
486493 dragBoxFromMouseDown = Rectangle . Empty ;
487494 }
488495
0 commit comments