-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathInsertSlideLibrarySlide.frm
More file actions
487 lines (367 loc) · 17 KB
/
InsertSlideLibrarySlide.frm
File metadata and controls
487 lines (367 loc) · 17 KB
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
Attribute VB_Name = "InsertSlideLibrarySlide"
Attribute VB_Base = "0{921588DB-461A-4D69-A578-17A03108E8B7}{527067C2-41FA-46FA-B518-F83563C7AC88}"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Attribute VB_TemplateDerived = False
Attribute VB_Customizable = False
'MIT License
'Copyright (c) 2021 - 2026 iappyx
'Permission is hereby granted, free of charge, to any person obtaining a copy
'of this software and associated documentation files (the "Software"), to deal
'in the Software without restriction, including without limitation the rights
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'copies of the Software, and to permit persons to whom the Software is
'furnished to do so, subject to the following conditions:
'The above copyright notice and this permission notice shall be included in all
'copies or substantial portions of the Software.
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
'SOFTWARE.
Dim ButtonHandlers As Collection
Public Sub ToggleCheckBox(ByVal tagValue As Integer)
Dim ctrl As control
For Each Page In MultiPageThumbnailGrid.Pages
For Each ctrl In Page.Controls
If TypeName(ctrl) = "CheckBox" And ctrl.Tag = CStr(tagValue) Then
ctrl.value = Not ctrl.value
Exit For
End If
Next ctrl
Next Page
SelectedCount = ReturnSelectedCount
If SelectedCount > 0 Then
InsertSlideKeepSourceButton.enabled = True
InsertSlideButton.enabled = True
If SelectedCount = 1 Then
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting"
InsertSlideButton.caption = "Insert selected slide"
Else
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting (" & SelectedCount & ")"
InsertSlideButton.caption = "Insert selected slides (" & SelectedCount & ")"
End If
Else
InsertSlideKeepSourceButton.enabled = False
InsertSlideButton.enabled = False
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting"
InsertSlideButton.caption = "Insert selected slide"
End If
End Sub
Private Sub ZoomInButton_Click()
NumberOfColumns = GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryMaxColumns", 3) - 1
If NumberOfColumns = 0 Then NumberOfColumns = 1
SaveSetting "Instrumenta", "SlideLibrary", "SlideLibraryMaxColumns", NumberOfColumns
RepaintThumbnails (NumberOfColumns)
End Sub
Private Sub ZoomOutButton_Click()
NumberOfColumns = GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryMaxColumns", 3) + 1
If NumberOfColumns = 11 Then NumberOfColumns = 10
SaveSetting "Instrumenta", "SlideLibrary", "SlideLibraryMaxColumns", NumberOfColumns
RepaintThumbnails (NumberOfColumns)
End Sub
Private Sub InsertSlideKeepSourceButton_Click()
Dim LibraryPresentation As PowerPoint.Presentation
Dim PresentationSlide As PowerPoint.Slide
Dim TempPath As String
Set MyDocument = Application.ActiveWindow
Set Testdocument = Application.ActiveWindow.Presentation
#If Mac Then
Set LibraryPresentation = PowerPoint.Presentations.Open(GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", ""))
#Else
Set LibraryPresentation = PowerPoint.Presentations.Open(GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", ""), , , msoFalse)
#End If
For Each Page In MultiPageThumbnailGrid.Pages
For Each ctrl In Page.Controls
If TypeName(ctrl) = "CheckBox" Then
If ctrl.value = True Then
LibraryPresentation.Slides.Item(CInt(ctrl.Tag)).Copy
Testdocument.Windows(1).Activate
Testdocument.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
DoEvents
End If
End If
Next ctrl
Next Page
LibraryPresentation.Close
Set LibraryPresentation = Nothing
InsertSlideLibrarySlide.Hide
Unload Me
End Sub
Private Sub CancelButton_Click()
InsertSlideLibrarySlide.Hide
Unload Me
End Sub
Private Sub OpenSlideLibrary_Click()
InsertSlideLibrarySlide.Hide
Unload Me
OpenSlideLibraryFile
End Sub
Private Function ReturnSelectedCount() As Integer
SelectedCount = 0
For Each Page In MultiPageThumbnailGrid.Pages
For Each ctrl In Page.Controls
If TypeName(ctrl) = "CheckBox" Then
If (ctrl.value = True) Then
SelectedCount = SelectedCount + 1
End If
End If
Next ctrl
Next Page
ReturnSelectedCount = SelectedCount
End Function
Private Sub SelectAllButton_Click()
For Each ctrl In MultiPageThumbnailGrid.Pages(MultiPageThumbnailGrid.value).Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.value = True
End If
Next ctrl
SelectedCount = ReturnSelectedCount
If SelectedCount > 0 Then
InsertSlideKeepSourceButton.enabled = True
InsertSlideButton.enabled = True
If SelectedCount = 1 Then
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting"
InsertSlideButton.caption = "Insert selected slide"
Else
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting (" & SelectedCount & ")"
InsertSlideButton.caption = "Insert selected slides (" & SelectedCount & ")"
End If
Else
InsertSlideKeepSourceButton.enabled = False
InsertSlideButton.enabled = False
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting"
InsertSlideButton.caption = "Insert selected slide"
End If
End Sub
Private Sub SelectNoneButton_Click()
For Each ctrl In MultiPageThumbnailGrid.Pages(MultiPageThumbnailGrid.value).Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.value = False
End If
Next ctrl
SelectedCount = ReturnSelectedCount
If SelectedCount > 0 Then
InsertSlideKeepSourceButton.enabled = True
InsertSlideButton.enabled = True
If SelectedCount = 1 Then
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting"
InsertSlideButton.caption = "Insert selected slide"
Else
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting (" & SelectedCount & ")"
InsertSlideButton.caption = "Insert selected slides (" & SelectedCount & ")"
End If
Else
InsertSlideKeepSourceButton.enabled = False
InsertSlideButton.enabled = False
InsertSlideKeepSourceButton.caption = "Insert selected and maintain source formatting"
InsertSlideButton.caption = "Insert selected slide"
End If
#If Mac Then
InsertSlideKeepSourceButton.enabled = True
InsertSlideButton.enabled = True
#End If
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim TempPath As String
#If Mac Then
TempPath = MacScript("return posix path of (path To temporary items) As string")
#Else
TempPath = Environ("TEMP") & "\"
#End If
For Each Page In MultiPageThumbnailGrid.Pages
For Each ctrl In Page.Controls
If TypeName(ctrl) = "CheckBox" Then
Kill (TempPath & "tmp.Slide" & ctrl.Tag & ".jpg")
End If
Next ctrl
Next Page
InsertSlideLibrarySlide.Hide
Unload Me
End Sub
Private Sub InsertSlideButton_Click()
Dim LibraryPresentation As PowerPoint.Presentation
Dim PresentationSlide As PowerPoint.Slide
Dim TempPath As String
Set MyDocument = Application.ActiveWindow
#If Mac Then
Set LibraryPresentation = PowerPoint.Presentations.Open(GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", ""))
#Else
Set LibraryPresentation = PowerPoint.Presentations.Open(GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", ""), , , msoFalse)
#End If
For Each Page In MultiPageThumbnailGrid.Pages
For Each ctrl In Page.Controls
If TypeName(ctrl) = "CheckBox" Then
If ctrl.value = True Then
LibraryPresentation.Slides.Item(CInt(ctrl.Tag)).Copy
MyDocument.Presentation.Slides.Paste
End If
End If
Next ctrl
Next Page
LibraryPresentation.Close
Set LibraryPresentation = Nothing
InsertSlideLibrarySlide.Hide
Unload Me
End Sub
Sub RepaintThumbnails(NewThumbnailGridMaxCols As Integer)
Dim Page As MSForms.Page
Dim ctrl As control
Dim row As Integer
Dim col As Integer
Dim ThumbnailWidth As Integer
Dim ThumbnailHeight As Integer
Dim i As Integer
ThumbnailWidth = (650 - (NewThumbnailGridMaxCols * 10)) / NewThumbnailGridMaxCols
ThumbnailHeight = ThumbnailWidth / 16 * 9
For Each Page In MultiPageThumbnailGrid.Pages
row = 0
col = 0
i = 0
For Each ctrl In Page.Controls
If TypeName(ctrl) = "Image" Then
ctrl.left = 10 + col * (ThumbnailWidth + 10)
ctrl.Top = 10 + row * (ThumbnailHeight + 10)
ctrl.width = ThumbnailWidth
ctrl.height = ThumbnailHeight
Dim checkCtrl As control
For Each checkCtrl In Page.Controls
If TypeName(checkCtrl) = "CheckBox" And checkCtrl.Tag = ctrl.Tag Then
checkCtrl.left = ctrl.left + ctrl.width - 15
checkCtrl.Top = ctrl.Top + ctrl.height - 15
End If
Next checkCtrl
Dim buttonCtrl As control
For Each buttonCtrl In Page.Controls
If TypeName(buttonCtrl) = "CommandButton" And buttonCtrl.Tag = ctrl.Tag Then
buttonCtrl.left = ctrl.left
buttonCtrl.Top = ctrl.Top
buttonCtrl.width = ctrl.width
buttonCtrl.height = ctrl.height
End If
Next buttonCtrl
col = col + 1
If col >= NewThumbnailGridMaxCols Then
col = 0
row = row + 1
End If
i = i + 1
End If
Next ctrl
Page.ScrollHeight = 10 + (row + 1) * (ThumbnailHeight + 10)
Page.Repaint
Next Page
End Sub
Private Sub UserForm_Activate()
MultiPageThumbnailGrid.visible = False
If GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", "") = "" Then
InsertSlideLibrarySlide.Hide
MsgBox "No slide library file set. Please Set the file in Instrumenta settings."
SettingsForm.Show
Else
'Needed to enable OLE automation for this
Dim LibraryPresentation As PowerPoint.Presentation
Dim PresentationSlide As PowerPoint.Slide
Dim TempPath As String
#If Mac Then
Set LibraryPresentation = PowerPoint.Presentations.Open(GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", ""))
#Else
Set LibraryPresentation = PowerPoint.Presentations.Open(GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryFile", ""), , , msoFalse)
#End If
#If Mac Then
TempPath = MacScript("return posix path of (path To temporary items) As string")
#Else
TempPath = Environ("TEMP") & "\"
#End If
NumberOfSlides = LibraryPresentation.Slides.count
slideHeight = 500
slideWidth = (LibraryPresentation.PageSetup.slideWidth / LibraryPresentation.PageSetup.slideHeight) * slideHeight
Dim Thumbnail As MSForms.image
Dim ThumbnailGridMaxCols As Integer
Dim ThumbnailWidth As Integer
Dim ThumbnailHeight As Integer
ThumbnailGridMaxCols = GetSetting("Instrumenta", "SlideLibrary", "SlideLibraryMaxColumns", 3)
ThumbnailWidth = (650 - (ThumbnailGridMaxCols * 10)) / ThumbnailGridMaxCols
ThumbnailHeight = ThumbnailWidth / 16 * 9
MultiPageThumbnailGrid.Pages.Clear
CurrentPageIndex = 0
Dim CurrentPage As MSForms.Page
For Each PresentationSlide In LibraryPresentation.Slides
i = i + 1
CurrentSectionIndex = PresentationSlide.sectionIndex
If CurrentSectionIndex <> CurrentPageIndex Then
row = 0
col = 0
If LibraryPresentation.SectionProperties.count = 0 Then
CurrentSectionName = "Default section" & " (" & LibraryPresentation.Slides.count & ")"
Else
CurrentSectionName = LibraryPresentation.SectionProperties.name(PresentationSlide.sectionIndex) & " (" & LibraryPresentation.SectionProperties.SlidesCount(PresentationSlide.sectionIndex) & ")"
End If
Set CurrentPage = MultiPageThumbnailGrid.Pages.Add("NewPage" & CurrentSectionIndex, CurrentSectionName)
CurrentPageIndex = CurrentSectionIndex
CurrentPage.ScrollBars = fmScrollBarsVertical
End If
PresentationSlide.Export TempPath & "tmp.Slide" & PresentationSlide.SlideNumber & ".jpg", "JPG", slideWidth, slideHeight
Set Thumbnail = CurrentPage.Controls.Add("Forms.Image.1", "Thumbnail" & i)
With Thumbnail
.left = 10 + col * (ThumbnailWidth + 10)
.Top = 10 + row * (ThumbnailHeight + 10)
.width = ThumbnailWidth
.height = ThumbnailHeight
.Picture = LoadPicture(TempPath & "tmp.Slide" & i & ".jpg")
.Tag = i
.PictureSizeMode = fmPictureSizeModeZoom
End With
Set ThumbnailCheck = CurrentPage.Controls.Add("Forms.CheckBox.1", "CheckBox" & i)
With ThumbnailCheck
.left = Thumbnail.left + Thumbnail.width - 15
.Top = Thumbnail.Top + Thumbnail.height - 15
.width = 15
.height = 15
.Tag = i
.BackStyle = fmBackStyleTransparent
End With
#If Mac Then
'Mac does not support transparent overlay buttons
#Else
Dim ClickOverlay As MSForms.CommandButton
Set ClickOverlay = CurrentPage.Controls.Add("Forms.CommandButton.1", "ClickOverlay" & i)
With ClickOverlay
.left = Thumbnail.left
.Top = Thumbnail.Top
.width = Thumbnail.width
.height = Thumbnail.height
.caption = ""
.Tag = i
.BackStyle = fmBackStyleTransparent
End With
If ButtonHandlers Is Nothing Then Set ButtonHandlers = New Collection
Dim ButtonObj As ThumbnailButtonHandler
Set ButtonObj = New ThumbnailButtonHandler
Set ButtonObj.ClickOverlay = ClickOverlay
ButtonHandlers.Add ButtonObj
#End If
col = col + 1
If col >= ThumbnailGridMaxCols Then
col = 0
row = row + 1
End If
NewScrollHeight = 10 + (row + 1) * (ThumbnailHeight + 10)
' Repaint before setting new ScrollHeight needed on Mac
CurrentPage.Repaint
CurrentPage.ScrollHeight = NewScrollHeight
CurrentPage.Repaint
Next
LibraryPresentation.Close
Set LibraryPresentation = Nothing
End If
MultiPageThumbnailGrid.visible = True
#If Mac Then
InsertSlideKeepSourceButton.enabled = True
InsertSlideButton.enabled = True
#End If
End Sub