├── .editorconfig
├── .gitignore
├── .texlife.profile
├── .travis.yml
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── images
├── programming_haiku_vol1-001.png
├── programming_haiku_vol1-015.png
├── programming_haiku_vol1-022.png
├── programming_haiku_vol1-171.png
└── programming_with_haiku_logo.png
├── include
├── css
│ └── style.css
├── haiku
│ └── haikulogov2.png
├── latex
│ ├── after_body.tex
│ ├── before_body.tex
│ ├── chapter_break.tex
│ └── preamble.tex
└── pandoc
│ ├── eisvogel.latex
│ └── eisvogel_mod.latex
├── psd
└── volume1-cover.psd
├── volume1
├── Makefile
├── Sources
│ ├── 15ClickMe
│ │ ├── App.cpp
│ │ ├── App.h
│ │ ├── ClickMe.pld
│ │ ├── MainWindow.cpp
│ │ └── MainWindow.h
│ ├── 17MenuColors
│ │ ├── App.cpp
│ │ ├── App.h
│ │ ├── MainWindow.cpp
│ │ ├── MainWindow.h
│ │ ├── MenuColors
│ │ └── MenuColors.pld
│ ├── 18ListTitle
│ │ ├── App.cpp
│ │ ├── App.h
│ │ ├── ListTitle.pld
│ │ ├── MainWindow.cpp
│ │ └── MainWindow.h
│ ├── 19Emo
│ │ ├── App.cpp
│ │ ├── App.h
│ │ ├── Emo.pld
│ │ ├── MainWindow.cpp
│ │ ├── MainWindow.h
│ │ ├── PictureView.cpp
│ │ ├── PictureView.h
│ │ └── Resources.rsrc
│ ├── 20ListDir
│ │ ├── App.cpp
│ │ └── ListDir.pld
│ ├── 22HaikuFortune
│ │ ├── App.cpp
│ │ ├── App.h
│ │ ├── FortuneFunctions.cpp
│ │ ├── FortuneFunctions.h
│ │ ├── HaikuFortune.pld
│ │ ├── HaikuFortune.rsrc
│ │ ├── HaikuFortune16.png
│ │ ├── HaikuFortune32.png
│ │ ├── MainWindow.cpp
│ │ ├── MainWindow.h
│ │ └── Resources.rsrc
│ └── DropMe
│ │ ├── App.cpp
│ │ ├── App.h
│ │ ├── DropMe
│ │ ├── DropMe.pld
│ │ ├── DropView.cpp
│ │ ├── DropView.h
│ │ ├── MainWindow.cpp
│ │ └── MainWindow.h
├── chapters
│ ├── answers.Md
│ ├── conclusions.Md
│ ├── disclaimer.Md
│ ├── lesson01.Md
│ ├── lesson02.Md
│ ├── lesson03.Md
│ ├── lesson04.Md
│ ├── lesson05.Md
│ ├── lesson06.Md
│ ├── lesson07.Md
│ ├── lesson08.Md
│ ├── lesson09.Md
│ ├── lesson10.Md
│ ├── lesson11.Md
│ ├── lesson12.Md
│ ├── lesson13.Md
│ ├── lesson14.Md
│ ├── lesson15.Md
│ ├── lesson16.Md
│ ├── lesson17.Md
│ ├── lesson18.Md
│ ├── lesson19.Md
│ ├── lesson20.Md
│ ├── lesson21.Md
│ ├── lesson22.Md
│ └── lesson23.Md
├── images
│ ├── cc-by-nc-sa.png
│ ├── cover.png
│ ├── filetypes.png
│ ├── myfirstappshot.png
│ ├── paladin2.png
│ └── quickres.png
└── metadata.yml
└── volume2
├── Makefile
├── Programming with Haiku -- GDB.odt
├── Programming with Haiku Lesson 1.odt
├── Programming with Haiku Lesson 10.odt
├── Programming with Haiku Lesson 11.odt
├── Programming with Haiku Lesson 12.odt
├── Programming with Haiku Lesson 13.odt
├── Programming with Haiku Lesson 14.odt
├── Programming with Haiku Lesson 15.odt
├── Programming with Haiku Lesson 16.odt
├── Programming with Haiku Lesson 17.odt
├── Programming with Haiku Lesson 18.odt
├── Programming with Haiku Lesson 19.odt
├── Programming with Haiku Lesson 2.odt
├── Programming with Haiku Lesson 20.odt
├── Programming with Haiku Lesson 21.odt
├── Programming with Haiku Lesson 22.odt
├── Programming with Haiku Lesson 23.odt
├── Programming with Haiku Lesson 24.odt
├── Programming with Haiku Lesson 25.odt
├── Programming with Haiku Lesson 26.odt
├── Programming with Haiku Lesson 27 (unfinished).odt
├── Programming with Haiku Lesson 28 (unfinished).odt
├── Programming with Haiku Lesson 3.odt
├── Programming with Haiku Lesson 4.odt
├── Programming with Haiku Lesson 5.odt
├── Programming with Haiku Lesson 6.odt
├── Programming with Haiku Lesson 7.odt
├── Programming with Haiku Lesson 8.odt
├── Programming with Haiku Lesson 9.odt
├── Programming with Haiku Unit 1 Review.odt
├── Programming with Haiku Unit 2 Review.odt
├── Programming with Haiku Unit 3 Review.odt
├── Scripting Suites.txt
├── Sources
├── AutoTextControl.cpp
├── AutoTextControl.h
├── BQuery Example.cpp
├── ColorWell - Draft.cpp
├── ColorWell - Draft.h
├── ColorWell - L17.cpp
├── ColorWell - L17.h
├── ColorWell - L19.cpp
├── ColorWell - L19.h
├── ColorWell - L20.cpp
├── ColorWell - L20.h
├── DragView.cpp
├── DragView.h
├── FontDemo
│ ├── App.cpp
│ ├── App.h
│ ├── FontDemo1.pld
│ ├── MainView.cpp
│ ├── MainView.h
│ ├── MainWindow.cpp
│ └── MainWindow.h
├── GetEmailName.cpp
├── LibWindow.cpp
├── LibWindow.h
├── Push BQuery Example.cpp
├── QuickEdit - L22
│ ├── App.cpp
│ ├── App.h
│ ├── MainWindow.cpp
│ ├── MainWindow.h
│ ├── QuickEdit L22.pld
│ ├── QuickEdit.pld
│ └── Resources.rsrc
├── QuickEdit - L23
│ ├── App.cpp
│ ├── App.h
│ ├── EditView.cpp
│ ├── EditView.h
│ ├── MainWindow.cpp
│ ├── MainWindow.h
│ ├── QuickEdit.pld
│ └── Resources.rsrc
├── ReadProject.cpp
├── Resource Template.rdef
├── Scripting Explorer
│ ├── .hg
│ │ ├── 00changelog.i
│ │ ├── branchheads.cache
│ │ ├── dirstate
│ │ ├── last-message.txt
│ │ ├── requires
│ │ ├── store
│ │ │ ├── 00changelog.i
│ │ │ ├── 00manifest.i
│ │ │ ├── data
│ │ │ │ ├── .hgignore.i
│ │ │ │ ├── _prop_dump.cpp.i
│ │ │ │ ├── _prop_dump.h.i
│ │ │ │ ├── _script_view.cpp.i
│ │ │ │ ├── _script_view.h.i
│ │ │ │ ├── _script_window.cpp.i
│ │ │ │ ├── _script_window.h.i
│ │ │ │ ├── _script_world.cpp.i
│ │ │ │ ├── _script_world.h.i
│ │ │ │ ├── _script_world.pld.i
│ │ │ │ ├── _script_world.rsrc.i
│ │ │ │ ├── _send_panel.cpp.i
│ │ │ │ └── _send_panel.h.i
│ │ │ ├── fncache
│ │ │ └── undo
│ │ ├── tags.cache
│ │ ├── undo.branch
│ │ ├── undo.desc
│ │ └── undo.dirstate
│ ├── .hgignore
│ ├── PropDump.cpp
│ ├── PropDump.h
│ ├── ScriptView.cpp
│ ├── ScriptView.h
│ ├── ScriptWindow.cpp
│ ├── ScriptWindow.h
│ ├── ScriptWorld.cpp
│ ├── ScriptWorld.pld
│ ├── ScriptWorld.rsrc
│ ├── SendPanel.cpp
│ └── SendPanel.h
├── SetMime.cpp
├── SetPermissions.cpp
├── TrackerAddon.cpp
├── TrackerAddon.h
├── TrackerAddon.pld
├── TrackerAddon.rsrc
├── TranslatorDemo
│ ├── .hg
│ │ ├── 00changelog.i
│ │ ├── cache
│ │ │ └── branchheads
│ │ ├── dirstate
│ │ ├── last-message.txt
│ │ ├── requires
│ │ ├── store
│ │ │ ├── 00changelog.i
│ │ │ ├── 00manifest.i
│ │ │ ├── data
│ │ │ │ ├── _app.cpp.i
│ │ │ │ ├── _app.h.i
│ │ │ │ ├── _bitmap_view.cpp.i
│ │ │ │ ├── _bitmap_view.h.i
│ │ │ │ ├── _bitmap_window.cpp.i
│ │ │ │ ├── _bitmap_window.h.i
│ │ │ │ ├── _main_window.cpp.i
│ │ │ │ ├── _main_window.h.i
│ │ │ │ └── _translator_demo.pld.i
│ │ │ ├── fncache
│ │ │ └── undo
│ │ ├── undo.branch
│ │ ├── undo.desc
│ │ └── undo.dirstate
│ ├── App.cpp
│ ├── App.h
│ ├── BitmapView.cpp
│ ├── BitmapView.h
│ ├── BitmapWindow.cpp
│ ├── BitmapWindow.h
│ ├── MainWindow.cpp
│ ├── MainWindow.h
│ └── TranslatorDemo.pld
├── overlayimage
│ ├── .svn
│ │ ├── entries
│ │ └── text-base
│ │ │ ├── Jamfile.svn-base
│ │ │ ├── OverlayApp.cpp.svn-base
│ │ │ ├── OverlayApp.h.svn-base
│ │ │ ├── OverlayImage.rdef.svn-base
│ │ │ ├── OverlayView.cpp.svn-base
│ │ │ ├── OverlayView.h.svn-base
│ │ │ ├── OverlayWindow.cpp.svn-base
│ │ │ └── OverlayWindow.h.svn-base
│ ├── Jamfile
│ ├── OverlayApp.cpp
│ ├── OverlayApp.h
│ ├── OverlayImage.rdef
│ ├── OverlayView.cpp
│ ├── OverlayView.h
│ ├── OverlayWindow.cpp
│ └── OverlayWindow.h
├── printres.cpp
└── scripting_code_samples.cpp
├── chapters
├── disclaimer.Md
└── lesson01.Md
├── images
├── ColorWellDemo1.png
├── FileType.png
├── FontDemo1.png
├── Icon-O-Matic.png
├── QuickRes.png
├── ResEdit.png
├── cc-by-nc-sa.png
└── cover.png
├── metadata.yml
├── rc help.txt
└── xres help.txt
/.editorconfig:
--------------------------------------------------------------------------------
1 | # See http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf8
6 | end_of_line = lf
7 | insert_final_newline = true
8 | indent_style = space
9 | trim_trailing_whitespace = true
10 |
11 | [*.{r,R,md,Rmd}]
12 | indent_size = 2
13 |
14 | [{NEWS.md,DESCRIPTION,LICENSE,CHANGELOG}]
15 | max_line_length = 80
16 |
17 | [Makefile]
18 | indent_style = tab
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | *.log
3 | .DS_Store
4 | ~*.odt
5 |
--------------------------------------------------------------------------------
/.texlife.profile:
--------------------------------------------------------------------------------
1 | selected_scheme scheme-basic
2 | instopt_adjustpath 1
3 | collection-basic 1
4 | collection-bibtexextra 0
5 | collection-fontsextra 0
6 | collection-fontsrecommended 1
7 | collection-langchinese 0
8 | collection-latex 1
9 | collection-latexextra 0
10 | collection-latexrecommended 1
11 | collection-mathscience 0
12 | collection-xetex 1
13 | tlpdbopt_autobackup 0
14 | tlpdbopt_install_docfiles 0
15 | tlpdbopt_install_srcfiles 0
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | os: linux
2 | dist: bionic
3 | language: java
4 | before_install:
5 | # default pandoc is too old -> install a newer version manually
6 | - PANDOC_VERSION="2.9.2"
7 | - pandoc_deb="pandoc-${PANDOC_VERSION}-1-amd64.deb"
8 | - wget "https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/${pandoc_deb}"
9 | - sudo dpkg -i ${pandoc_deb}
10 | - rm ${pandoc_deb}
11 |
12 | # default textlife from apt-get is too old
13 | # install the latest texlife version manually
14 | - REMOTE="http://mirror.ctan.org/systems/texlive/tlnet"
15 | - INSTALL="/tmp/install-texlive"
16 | - mkdir -p $INSTALL
17 | - curl -sSL $REMOTE/install-tl-unx.tar.gz | tar -xzv -C $INSTALL --strip-components=1
18 | - sudo $INSTALL/install-tl -no-gui -profile .texlife.profile
19 | - VERSION=$($INSTALL/install-tl --version | grep 'version' | grep -o '[0-9]\{4\}')
20 | - PLATFORM=$($INSTALL/install-tl --print-platform)
21 | - TEXLIVE_DIR="/usr/local/texlive/${VERSION}"
22 | - TEXBIN="/usr/local/texlive/${VERSION}/bin/${PLATFORM}"
23 | - export "PATH=$TEXBIN:$PATH"
24 |
25 | # initialization for tlmgr
26 | - sudo apt-get install xzdec
27 | - tlmgr init-usertree
28 |
29 | # install pdftoppm for rendering the PDFs
30 | - sudo apt-get install poppler-utils
31 |
32 | # for executing python based pandoc filters install python and pip
33 | - sudo apt-get install python3
34 | - sudo apt-get install python3-pip
35 | - sudo pip3 install --upgrade setuptools
36 | - sudo pip3 install wheel
37 |
38 | # for converting to mobi
39 | - sudo apt-get install calibre
40 |
41 | # install python filters
42 | - pip3 install pandoc-latex-environment
43 |
44 |
45 | - sudo chown -hR $(whoami) "$TEXLIVE_DIR"
46 | # packages specified in the template
47 | - tlmgr install adjustbox background bidi csquotes footmisc footnotebackref fvextra mdframed pagecolor sourcecodepro sourcesanspro titling ulem upquote xurl
48 |
49 | # trial and error
50 | - tlmgr install letltxmacro zref everypage framed collectbox
51 |
52 | # packages needed for the template
53 | - tlmgr install xecjk filehook unicode-math ucharcat ly1 mweights mdframed needspace
54 |
55 | # packages needed for the books
56 | - tlmgr install awesomebox fontawesome5 newunicodechar
57 | script:
58 | - make -C volume1 all
59 | - make -C volume1 png
60 | deploy:
61 | provider: releases
62 | api_key:
63 | secure: "BAXn+qMv1FR0bfpB5pLNJmkN82Xi13CLyOwE/+1Ua3oDO7f3NsPLULowGIZsV6jU8qBlXQPOD7qnE0Ww0VEDvxNtzU/5TymkRboTFcoC3lcSOKf0q6bgN9R8NVBzZaj3jK65+peGOGtaoXOkiqAZF6qQd415iCen5/kIcH+R5EszffaOGfnz0NJsSf39fSHKPB3LvCHAE6n6Y3v8x+NGvWDald0iwVtYMpL9YbcCtXthQRi0+BggRtstvk+97SgRPa1AwaRT5NIzYLESi9Jm/gEYf3QXwmv+qgiK3D3PPh6YGUfTGxu1RpSNK4R4e1F6zbmyYRQR07Z6AHt0lSb0XVtxokT7iMsK5LddEbsE+aNydfztt0r6Gx2TrisF4LqYpT16kJg3hpIIjBEZV9ulqdq0D/oqtP35wyc7yr7ThGgfnyCrjs+14xMzE4HwKEZwWCPltyBiHeqQbILvA3yag6Wp08t/y6/3gtX7jMSUTi6boMoZFB0ziTA/8t99Jmt9xrsvebvgM0SUO+fycZOIqNaHGpEd9fg7Y3dgIi4D/oNyuiELcTyX1f4EV8i9jGaB/ldimujx+l7oh/6ElxHhgLDGghHvrcIZBFvX0RaHTJS7uX482jPtyj+z/zyPWFW2/PtaoBO4gX3LcxTpxdMppDb+YBsbJ+7+xrKzEOWKbEY="
64 | file_glob: true
65 | file:
66 | - "$TRAVIS_BUILD_DIR/volume1/build/**/*.{epub,html.tar.gz,mobi,pdf}"
67 | skip_cleanup: true
68 | on:
69 | tags: true
70 | repo: theclue/programming-with-haiku
71 | all_branches: true
72 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ivotron/pandoc
2 | ENV TZ="Europe/Rome"
3 |
4 | RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections \
5 | && apt-get update \
6 | && apt-get install -y --no-install-recommends tzdata curl calibre \
7 | && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
8 | && dpkg-reconfigure --frontend noninteractive tzdata \
9 | && apt-get clean \
10 | && rm -rf /var/lib/apt/lists/
11 |
12 | WORKDIR /app
13 | COPY . .
14 |
15 | CMD ["make", "all"]
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This work is licensed under the
2 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
3 |
4 | To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/
5 | or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
6 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | BUILD = build
2 | MAKEFILE = Makefile
3 | OUTPUT_FILENAME = ProgrammingHaiku
4 | METADATA = metadata.yml
5 | CHAPTERS = chapters/*.md
6 | TOC = --toc --toc-depth=2
7 | IMAGES_FOLDER = images
8 | IMAGES = $(IMAGES_FOLDER)/*
9 | COVER_IMAGE = $(IMAGES_FOLDER)/cover.png
10 | LATEX_CLASS = report
11 | MATH_FORMULAS = --webtex
12 | CSS_FILE = style.css
13 | CSS_ARG = --css=$(CSS_FILE)
14 | METADATA_ARG = --metadata-file=$(METADATA)
15 | ARGS = $(TOC) $(MATH_FORMULAS) $(CSS_ARG) $(METADATA_ARG)
16 |
17 | CDIR := .
18 | ODIR := .
19 | ADOC_SRCS := $(wildcard $(CDIR)/*.adoc)
20 | ADOC_OBJS := $(SRCS:$(CDIR)/%.adoc=$(ODIR)/%.xml)
21 |
22 | all: book
23 |
24 | book: epub html pdf mobi
25 |
26 | clean:
27 | rm -r $(BUILD)
28 |
29 | DOCBOOKS := lesson1.adoc lesson2.adoc lessob3.adic
30 |
31 | docbooks: $(OBJECTS)
32 |
33 |
34 | %.xml : %.adoc
35 | asciidoc -b docbook lesson1.adoc
36 |
37 | mobi: $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi
38 |
39 | epub: $(BUILD)/epub/$(OUTPUT_FILENAME).epub
40 |
41 | html: $(BUILD)/html/$(OUTPUT_FILENAME).html
42 |
43 | pdf: $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf
44 |
45 | $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi: epub
46 | mkdir -p $(BUILD)/mobi
47 | ebook-convert $(BUILD)/epub/$(OUTPUT_FILENAME).epub $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi
48 |
49 | $(BUILD)/epub/$(OUTPUT_FILENAME).epub: $(MAKEFILE) $(METADATA) $(CHAPTERS) $(CSS_FILE) $(IMAGES) \
50 | $(COVER_IMAGE)
51 | mkdir -p $(BUILD)/epub
52 | pandoc $(ARGS) --epub-cover-image=$(COVER_IMAGE) -o $@ $(CHAPTERS)
53 |
54 | $(BUILD)/html/$(OUTPUT_FILENAME).html: $(MAKEFILE) $(METADATA) $(CHAPTERS) $(CSS_FILE) $(IMAGES)
55 | mkdir -p $(BUILD)/html
56 | pandoc $(ARGS) --standalone --to=html5 -o $@ $(CHAPTERS)
57 | cp -R $(IMAGES_FOLDER)/ $(BUILD)/html/$(IMAGES_FOLDER)/
58 | cp $(CSS_FILE) $(BUILD)/html/$(CSS_FILE)
59 |
60 | $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf: $(MAKEFILE) $(METADATA) $(CHAPTERS) $(CSS_FILE) $(IMAGES)
61 | mkdir -p $(BUILD)/pdf
62 | pandoc $(ARGS) -V documentclass=$(LATEX_CLASS) -o $@ $(CHAPTERS)
63 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/theclue/programming-with-haiku) [](https://www.codacy.com/manual/theclue/programming-with-haiku?utm_source=github.com&utm_medium=referral&utm_content=theclue/programming-with-haiku&utm_campaign=Badge_Grade) [](https://github.com/theclue/programming-with-haiku/pulls?q=is%3Apr+is%3Aclosed) [](https://github.com/theclue/programming-with-haiku/releases)
2 |
3 | ***
4 |
5 |

6 |
7 | These are the original classics from Jon Yoder, in a new set of open formats.
8 |
9 | ## Showcases
10 |
11 |    
12 |
--------------------------------------------------------------------------------
/images/programming_haiku_vol1-001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/images/programming_haiku_vol1-001.png
--------------------------------------------------------------------------------
/images/programming_haiku_vol1-015.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/images/programming_haiku_vol1-015.png
--------------------------------------------------------------------------------
/images/programming_haiku_vol1-022.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/images/programming_haiku_vol1-022.png
--------------------------------------------------------------------------------
/images/programming_haiku_vol1-171.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/images/programming_haiku_vol1-171.png
--------------------------------------------------------------------------------
/images/programming_with_haiku_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/images/programming_with_haiku_logo.png
--------------------------------------------------------------------------------
/include/haiku/haikulogov2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/include/haiku/haikulogov2.png
--------------------------------------------------------------------------------
/include/latex/after_body.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/include/latex/after_body.tex
--------------------------------------------------------------------------------
/include/latex/before_body.tex:
--------------------------------------------------------------------------------
1 | % you may need to leave a few empty pages before the dedication page
2 |
3 | \cleardoublepage\newpage
4 | \thispagestyle{empty}
5 |
6 | \begin{center}
7 | To Melody, for putting up with me.
8 |
9 | \end{center}
10 |
11 | \setlength{\abovedisplayskip}{-5pt}
12 | \setlength{\abovedisplayshortskip}{-5pt}
13 |
14 | \cleardoublepage
--------------------------------------------------------------------------------
/include/latex/chapter_break.tex:
--------------------------------------------------------------------------------
1 | \usepackage{sectsty}
2 | \sectionfont{\clearpage}
--------------------------------------------------------------------------------
/include/latex/preamble.tex:
--------------------------------------------------------------------------------
1 | \usepackage{booktabs}
2 | \usepackage{longtable}
3 |
4 | \usepackage{awesomebox}
5 |
6 | \definecolor{errorboxcolor}{RGB}{188,0,0}
7 | \definecolor{bughuntboxcolor}{RGB}{188,0,0}
8 | \definecolor{warningboxcolor}{RGB}{188,50,0}
9 |
10 | \newenvironment{questionblock}
11 | {\begin{awesomeblock}[black]{\aweboxrulewidth}{\faQuestion[regular]}{black}}
12 | {\end{awesomeblock}}
13 |
14 | \newenvironment{assignmentblock}
15 | {\begin{awesomeblock}[black]{\aweboxrulewidth}{\faPen[regular]}{black}}
16 | {\end{awesomeblock}}
17 |
18 | \newenvironment{toughblock}
19 | {\begin{awesomeblock}[black]{\aweboxrulewidth}{\faCogs[regular]}{black}}
20 | {\end{awesomeblock}}
21 |
22 | \newenvironment{errorblock}
23 | {\begin{awesomeblock}[errorboxcolor]{\aweboxrulewidth}{\faTimes[regular]}{errorboxcolor}}
24 | {\end{awesomeblock}}
25 |
26 | \newenvironment{shellerrorblock}
27 | {\begin{awesomeblock}[errorboxcolor]{\aweboxrulewidth}{\faTimes[regular]}{errorboxcolor}\texttt\bgroup}
28 | {\egroup\end{awesomeblock}}
29 |
30 | \newenvironment{bughuntblock}
31 | {\begin{awesomeblock}[bughuntboxcolor]{\aweboxrulewidth}{\faBug[regular]}{bughuntboxcolor}\texttt\bgroup}
32 | {\egroup\end{awesomeblock}}
33 |
34 | \newenvironment{bugwarningblock}
35 | {\begin{awesomeblock}[warningboxcolor]{\aweboxrulewidth}{\faBug[regular]}{warningboxcolor}}
36 | {\end{awesomeblock}}
37 |
38 |
39 | \usepackage{framed,color}
40 |
41 | % tweak deafult fonts
42 | \usepackage{fontspec}
43 | \usepackage{xltxtra,xunicode}
44 | \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
45 |
46 | % Place links inline
47 | \let\oldhref\href
48 | \renewcommand{\href}[2]{#2 (\url{#1})}
49 |
50 | \renewenvironment{quote}%
51 | {\list{}{\leftmargin=0.5in\rightmargin=0.5in}\item[]\begin{itshape}}%
52 | {\end{itshape}\endlist}
53 |
54 | % No widow lines
55 | \widowpenalty=10000
56 | \clubpenalty=10000
57 |
58 | \urlstyle{tt}
59 |
60 |
61 | \frontmatter
62 |
--------------------------------------------------------------------------------
/psd/volume1-cover.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/psd/volume1-cover.psd
--------------------------------------------------------------------------------
/volume1/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY = docbooks clean
2 |
3 | BUILD = build
4 | MAKEFILE = Makefile
5 | OUTPUT_FILENAME = Jon_Yoder_-_Programming_with_Haiku_Volume_1
6 |
7 | INCLUDE_DIR = ../include
8 | IMAGES_DIR = images
9 | IMAGES = $(IMAGES_DIR)/*
10 | COVER_IMAGE = $(IMAGES_DIR)/cover.png
11 |
12 | METADATA = metadata.yml
13 | TOC = --toc --toc-depth=2 -V toc-title='Table of contents' -V toc-own-page:true
14 | CSS_FILE = $(INCLUDE_DIR)/css/style.css
15 | CSS_ARG = --css=$(CSS_FILE)
16 | METADATA_ARG = --metadata-file=$(METADATA)
17 | MATH_FORMULAS = --webtex
18 |
19 | PDF_ENGINE=xelatex
20 | ARGS = $(MATH_FORMULAS) $(CSS_ARG) $(METADATA_ARG)
21 |
22 | MARKDOWN_FORMAT = markdown-pipe_tables+backtick_code_blocks+fancy_lists+table_captions+smart+fenced_divs
23 |
24 | CHAPTERS_DIR = ./chapters
25 | CHAPTERS := disclaimer.Md lesson01.Md lesson02.Md lesson03.Md lesson04.Md \
26 | lesson05.Md lesson06.Md lesson07.Md lesson08.Md \
27 | lesson09.Md lesson10.Md lesson11.Md lesson12.Md \
28 | lesson13.Md lesson14.Md lesson15.Md lesson16.Md \
29 | lesson17.Md lesson18.Md lesson19.Md lesson20.Md \
30 | lesson21.Md lesson22.Md lesson23.Md answers.Md conclusions.Md
31 |
32 | CHAPTERS_TARGETS = $(addprefix $(CHAPTERS_DIR)/,$(CHAPTERS))
33 |
34 | all: book
35 |
36 | book: epub html pdf mobi
37 |
38 | clean:
39 | rm -rf $(BUILD)
40 |
41 | markdown: $(BUILD)/markdown/$(OUTPUT_FILENAME).Md
42 |
43 | mobi: $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi
44 |
45 | epub: $(BUILD)/epub/$(OUTPUT_FILENAME).epub
46 |
47 | html: $(BUILD)/html/$(OUTPUT_FILENAME).html.tar.gz
48 |
49 | pdf: $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf
50 |
51 | png: pdf
52 | mkdir -p $(BUILD)/png
53 | pdftoppm -png -r 42 -aa yes $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf $(BUILD)/png/$(OUTPUT_FILENAME)
54 |
55 | $(BUILD)/markdown/$(OUTPUT_FILENAME).Md: $(CHAPTERS_TARGETS)
56 | mkdir -p $(BUILD)/markdown
57 | mdmerge $(CHAPTERS_TARGETS) -o $(BUILD)/markdown/$(OUTPUT_FILENAME).Md
58 |
59 | $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi: epub
60 | mkdir -p $(BUILD)/mobi
61 | ebook-convert $(BUILD)/epub/$(OUTPUT_FILENAME).epub $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi
62 |
63 | $(BUILD)/epub/$(OUTPUT_FILENAME).epub: $(MAKEFILE) $(METADATA) $(CHAPTERS_TARGETS) $(CSS_FILE) $(IMAGES) \
64 | $(COVER_IMAGE)
65 | mkdir -p $(BUILD)/epub
66 | pandoc $(ARGS) --epub-cover-image=$(COVER_IMAGE) -f $(MARKDOWN_FORMAT) -t epub -o $@ -s $(CHAPTERS_TARGETS)
67 |
68 | $(BUILD)/html/$(OUTPUT_FILENAME).html.tar.gz : $(MAKEFILE) $(METADATA) $(CHAPTERS_TARGETS) $(CSS_FILE) $(IMAGES)
69 | mkdir -p $(BUILD)/html_tmp
70 | mkdir -p $(BUILD)/html
71 | pandoc $(ARGS) --standalone --to=html5 -o $(BUILD)/html_tmp/$(OUTPUT_FILENAME).html $(CHAPTERS_TARGETS)
72 | cp -R $(IMAGES_DIR)/ $(BUILD)/html_tmp/$(IMAGES_DIR)/
73 | tar -zcvf $(BUILD)/html/$(OUTPUT_FILENAME).html.tar.gz -C $(BUILD)/html_tmp .
74 | rm -r $(BUILD)/html_tmp
75 |
76 | $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf: $(CHAPTERS_TARGETS) $(CSS_FILE)
77 | mkdir -p $(BUILD)/markdown
78 | mkdir -p $(BUILD)/pdf
79 | pandoc $(ARGS) \
80 | $(TOC) \
81 | --template=$(INCLUDE_DIR)/pandoc/eisvogel.latex \
82 | --metadata=abstract:" " \
83 | -V geometry:a4paper -V geometry:"left=2.54cm,right=2.54cm,top=1.91cm,bottom=1.91cm" \
84 | -V titlepage:true -V titlepage-color:"FFFFFF" -V titlepage-rule-height:0 -V titlepage-rule-color:"d8dbdc" \
85 | -V titlepage-background:$(COVER_IMAGE) \
86 | -V title:"" -V subtitle:"" -V author:"" \
87 | -V header-left:"Programming with Haiku" -V header-right:"Volume 1" \
88 | -V footer-left:"Jon Yoder" \
89 | -V links-as-notes:true \
90 | -V lot:true \
91 | -V footnotes-pretty:true \
92 | --listing -V listings-disable-line-numbers:true \
93 | -V book:true --top-level-division=chapter \
94 | --pdf-engine=$(PDF_ENGINE) \
95 | --include-in-header $(INCLUDE_DIR)/latex/preamble.tex \
96 | --include-before-body $(INCLUDE_DIR)/latex/before_body.tex \
97 | --include-after-body $(INCLUDE_DIR)/latex/after_body.tex \
98 | --filter pandoc-latex-environment \
99 | --number-offset=1 \
100 | -f $(MARKDOWN_FORMAT) \
101 | -s $(CHAPTERS_TARGETS) \
102 | -o $@
103 |
104 | %.xml : %.adoc
105 | asciidoctor -v -d book -b docbook -s $< -o $@
106 |
107 | $(CHAPTERS_DIR)/%.Md : %.xml
108 | mkdir -p $(CHAPTERS_DIR)
109 | pandoc --highlight-style=pygments --wrap=none -f docbook -t $(MARKDOWN_FORMAT) --shift-heading-level-by=1 $< -o $@
110 |
111 |
--------------------------------------------------------------------------------
/volume1/Sources/15ClickMe/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-ClickMe")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume1/Sources/15ClickMe/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume1/Sources/15ClickMe/ClickMe.pld:
--------------------------------------------------------------------------------
1 | NAME=ClickMe
2 | TARGETNAME=ClickMe
3 | GROUP=Source Files
4 | EXPANDGROUP=yes
5 | SOURCEFILE=App.cpp
6 | DEPENDENCY=/boot/home/projects/ButtonDemo/App.cpp| /boot/home/projects/ButtonDemo/App.h| /boot/home/projects/ButtonDemo/MainWindow.
7 | SOURCEFILE=MainWindow.cpp
8 | DEPENDENCY=/boot/home/projects/ButtonDemo/MainWindow.cpp| /boot/home/projects/ButtonDemo/MainWindow.
9 | LOCALINCLUDE=/boot/home/projects/ButtonDemo/.
10 | SYSTEMINCLUDE=/boot/develop/headers/be
11 | SYSTEMINCLUDE=/boot/develop/headers/cpp
12 | SYSTEMINCLUDE=/boot/develop/headers/posix
13 | SYSTEMINCLUDE=/boot/home/config/include
14 | LIBRARY=/boot/develop/lib/x86/libroot.so
15 | LIBRARY=/boot/develop/lib/x86/libbe.so
16 | LIBRARY=/boot/system/lib/libsupc++.so
17 | RUNARGS=
18 | CCDEBUG=no
19 | CCPROFILE=no
20 | CCOPSIZE=no
21 | CCOPLEVEL=0
22 | CCTARGETTYPE=0
23 | CCEXTRA=
24 | LDEXTRA=
25 |
--------------------------------------------------------------------------------
/volume1/Sources/15ClickMe/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | // Button.h adds the class definiton for the BButton control
4 | #include
5 |
6 | // The BView class is the generic class for creating controls and drawing things inside
7 | // a window
8 | #include
9 |
10 | // The BString class is a phenomenally useful class which eliminates
11 | // almost all hassle associated with manipulating strings.
12 | #include
13 |
14 | // This defines the identifier for the message that our button will send. The letters
15 | // inside the single quotes are translated into an integer. The value for M_BUTTON_CLICKED
16 | // is arbitrary, so as long as it's unique, it's not too important what it is.
17 | enum
18 | {
19 | M_BUTTON_CLICKED = 'btcl'
20 | };
21 |
22 |
23 | MainWindow::MainWindow(void)
24 | : BWindow(BRect(100,100,300,200),"ClickMe",B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS |
25 | B_QUIT_ON_WINDOW_CLOSE),
26 | fCount(0)
27 | {
28 | // Create a button in pretty much the same way that we did the label in
29 | // the last lesson. The BRect() call inside the BButton constructor is a quick
30 | // shortcut that eliminates creating a variable.
31 | BButton *button = new BButton(BRect(10,10,11,11),"button","Click Me!",
32 | new BMessage(M_BUTTON_CLICKED));
33 |
34 | // Like with last lesson's label, make the button choose how big it should be.
35 | button->ResizeToPreferred();
36 |
37 | // Add our button to the window
38 | AddChild(button);
39 | }
40 |
41 |
42 | void
43 | MainWindow::MessageReceived(BMessage *msg)
44 | {
45 | // The way that BMessages are identified is by the public property 'what'.
46 | switch (msg->what)
47 | {
48 | // If the message was the one sent to the window by the button
49 | case M_BUTTON_CLICKED:
50 | {
51 | fCount++;
52 |
53 | BString labelString("Clicks: ");
54 |
55 | // This adds the value of fCount to the end of labelString. More on this later.
56 | labelString << fCount;
57 |
58 | // Set the window's title to the new string we've made
59 | SetTitle(labelString.String());
60 | break;
61 | }
62 | default:
63 | {
64 | // If the message doesn't match one of the ones we explicitly define, it must
65 | // be some sort of system message, so we will call the version of MessageReceived()
66 | // created for BWindow so that it can handle them. THIS IS REQUIRED if you want
67 | // your window to act the way that you expect it to.
68 | BWindow::MessageReceived(msg);
69 | break;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/volume1/Sources/15ClickMe/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | class MainWindow : public BWindow
7 | {
8 | public:
9 | MainWindow(void);
10 |
11 | // We are implementing the virtual BWindow method MessageReceived so that we
12 | // can handle the message that the button will send to the window
13 | void MessageReceived(BMessage *msg);
14 |
15 | private:
16 | // This property will hold the number of times the button has been clicked.
17 | int32 fCount;
18 | };
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/volume1/Sources/17MenuColors/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-MenuColors")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume1/Sources/17MenuColors/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume1/Sources/17MenuColors/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | enum
9 | {
10 | M_SET_COLOR_RED = 'sred',
11 | M_SET_COLOR_GREEN = 'sgrn',
12 | M_SET_COLOR_BLUE = 'sblu',
13 | M_SET_COLOR_BLACK = 'sblk'
14 | };
15 |
16 | MainWindow::MainWindow(void)
17 | : BWindow(BRect(100,100,500,400),"MenuColors",B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS |
18 | B_QUIT_ON_WINDOW_CLOSE)
19 | {
20 | BRect r(Bounds());
21 | r.bottom = 20;
22 |
23 | BMenuBar *menuBar = new BMenuBar(r,"menubar");
24 | AddChild(menuBar);
25 |
26 | BMenu *menu = new BMenu("Colors");
27 | menu->AddItem(new BMenuItem("Red",new BMessage(M_SET_COLOR_RED),'R'));
28 | menu->AddItem(new BMenuItem("Green",new BMessage(M_SET_COLOR_GREEN),'G'));
29 | menu->AddItem(new BMenuItem("Blue",new BMessage(M_SET_COLOR_BLUE),'B'));
30 | menu->AddItem(new BMenuItem("Black",new BMessage(M_SET_COLOR_BLACK),'K'));
31 | menuBar->AddItem(menu);
32 |
33 | BView *view = new BView(BRect(100,100,300,200),"colorview",B_FOLLOW_ALL, B_WILL_DRAW);
34 | AddChild(view);
35 | view->SetViewColor(0,0,160);
36 | }
37 |
38 |
39 | void
40 | MainWindow::MessageReceived(BMessage *msg)
41 | {
42 | BView *view = FindView("colorview");
43 |
44 | switch (msg->what)
45 | {
46 | case M_SET_COLOR_RED:
47 | {
48 | view->SetViewColor(160,0,0);
49 | view->Invalidate();
50 | break;
51 | }
52 | case M_SET_COLOR_GREEN:
53 | {
54 | view->SetViewColor(0,160,0);
55 | view->Invalidate();
56 | break;
57 | }
58 | case M_SET_COLOR_BLUE:
59 | {
60 | view->SetViewColor(0,0,160);
61 | view->Invalidate();
62 | break;
63 | }
64 | case M_SET_COLOR_BLACK:
65 | {
66 | view->SetViewColor(0,0,0);
67 | view->Invalidate();
68 | break;
69 | }
70 | default:
71 | {
72 | BWindow::MessageReceived(msg);
73 | break;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/volume1/Sources/17MenuColors/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | class MainWindow : public BWindow
7 | {
8 | public:
9 | MainWindow(void);
10 | void MessageReceived(BMessage *msg);
11 | };
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/volume1/Sources/17MenuColors/MenuColors:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/17MenuColors/MenuColors
--------------------------------------------------------------------------------
/volume1/Sources/17MenuColors/MenuColors.pld:
--------------------------------------------------------------------------------
1 | NAME=MenuColors
2 | TARGETNAME=MenuColors
3 | PLATFORM=Zeta
4 | GROUP=Source Files
5 | EXPANDGROUP=yes
6 | SOURCEFILE=App.cpp
7 | DEPENDENCY=/BeOS/develop/projects/Programming Lessons/MenuColors/App.cpp|/BeOS/develop/projects/Programming Lessons/MenuColors/App.h|/BeOS/develop/projects/Programming Lessons/MenuColors/MainWindow.h
8 | SOURCEFILE=MainWindow.cpp
9 | DEPENDENCY=/BeOS/develop/projects/Programming Lessons/MenuColors/MainWindow.cpp|/BeOS/develop/projects/Programming Lessons/MenuColors/MainWindow.h
10 | LOCALINCLUDE=/boot/home/projects/MenuColors/.
11 | SYSTEMINCLUDE=/boot/develop/headers/be
12 | SYSTEMINCLUDE=/boot/develop/headers/cpp
13 | SYSTEMINCLUDE=/boot/develop/headers/posix
14 | SYSTEMINCLUDE=/boot/home/config/include
15 | LIBRARY=/boot/develop/lib/x86/libroot.so
16 | LIBRARY=/boot/develop/lib/x86/libbe.so
17 | RUNARGS=
18 | CCDEBUG=no
19 | CCPROFILE=no
20 | CCOPSIZE=no
21 | CCOPLEVEL=0
22 | CCTARGETTYPE=0
23 | CCEXTRA=
24 | LDEXTRA=
25 |
--------------------------------------------------------------------------------
/volume1/Sources/18ListTitle/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-ListColors")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume1/Sources/18ListTitle/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume1/Sources/18ListTitle/ListTitle.pld:
--------------------------------------------------------------------------------
1 | NAME=ListTitle
2 | TARGETNAME=ListTitle
3 | PLATFORM=Zeta
4 | GROUP=Source Files
5 | EXPANDGROUP=yes
6 | SOURCEFILE=App.cpp
7 | DEPENDENCY=/BeOS/develop/projects/Programming Lessons/MenuColors/App.cpp|/BeOS/develop/projects/Programming Lessons/MenuColors/App.h|/BeOS/develop/projects/Programming Lessons/MenuColors/MainWindow.h
8 | SOURCEFILE=MainWindow.cpp
9 | DEPENDENCY=/BeOS/develop/projects/Programming Lessons/MenuColors/MainWindow.cpp|/BeOS/develop/projects/Programming Lessons/MenuColors/MainWindow.h
10 | LOCALINCLUDE=/boot/home/projects/MenuColors/.
11 | SYSTEMINCLUDE=/boot/develop/headers/be
12 | SYSTEMINCLUDE=/boot/develop/headers/cpp
13 | SYSTEMINCLUDE=/boot/develop/headers/posix
14 | SYSTEMINCLUDE=/boot/home/config/include
15 | LIBRARY=/boot/develop/lib/x86/libroot.so
16 | LIBRARY=/boot/develop/lib/x86/libbe.so
17 | RUNARGS=
18 | CCDEBUG=no
19 | CCPROFILE=no
20 | CCOPSIZE=no
21 | CCOPLEVEL=0
22 | CCTARGETTYPE=0
23 | CCEXTRA=
24 | LDEXTRA=
25 |
--------------------------------------------------------------------------------
/volume1/Sources/18ListTitle/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | enum
8 | {
9 | M_RESET_WINDOW = 'rswn',
10 | M_SET_TITLE = 'sttl'
11 | };
12 |
13 | MainWindow::MainWindow(void)
14 | : BWindow(BRect(100,100,500,400),"The Weird World of Sports",B_TITLED_WINDOW,
15 | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
16 | {
17 | // Here we will make a BView that covers the white area so that we can set the
18 | // "background color"
19 | BRect r(Bounds());
20 | BView *top = new BView(r,"topview",B_FOLLOW_ALL,B_WILL_DRAW);
21 | AddChild(top);
22 |
23 | // ui_color() returns a system color, such as the window tab color, menu text color,
24 | // and so forth.
25 | top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
26 |
27 | // Create a button and place it at the bottom right corner of the window. The empty BRect
28 | // that we use for the BButton's frame is because we're going to have it resize itself and
29 | // then move it to the corner based on the actual size of the button
30 | BButton *reset = new BButton(BRect(),"resetbutton","Reset", new BMessage(M_RESET_WINDOW),
31 | B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
32 | top->AddChild(reset);
33 | reset->ResizeToPreferred();
34 |
35 | // Bottom right corner of the window with 10 pixels of padding between the button and the
36 | // window edge. 10 pixels is kind of a de facto standard for control padding.
37 | reset->MoveTo(Bounds().right - reset->Bounds().Width() - 10.0,
38 | Bounds().bottom - reset->Bounds().Height() - 10.0);
39 |
40 | r = Bounds();
41 | r.InsetBy(10.0,10.0);
42 |
43 | // When working with BScrollViews, you must compensate for the width/height of the scrollbars.
44 | // B_V_SCROLL_BAR_WIDTH is a defined constant for the width of the vertical scroll bar.
45 | r.right -= B_V_SCROLL_BAR_WIDTH;
46 |
47 | // Frame() works like Bounds() except that it returns the size and location of the control
48 | // in the coordinate space of the parent view. This will make fListView's bottom stop 10
49 | // pixels above the button.
50 | r.bottom = reset->Frame().top - 10.0 - B_H_SCROLL_BAR_HEIGHT;
51 |
52 | // Most of these parameters are exactly the same as for BView except that we can also
53 | // specify whether the user is able to select just 1 item in the list or multiple items by
54 | // clicking on items while holding a modifier key on the keyboard.
55 | fListView = new BListView(r,"sportlist",B_SINGLE_SELECTION_LIST,B_FOLLOW_ALL);
56 |
57 | // We didn't call AddChild on fListView because our BScrollView will do that for us. When
58 | // created, it creates scrollbars and targets the specified view for any scrolling they do.
59 | // When the BScrollView is attached to the window, it calls AddChild on fListView for us.
60 |
61 | // If we call AddChild on fListView before we create this scrollview, our program will drop
62 | // to the debugger when we call AddChild on the BScrollView -- a BView can have only one parent.
63 | BScrollView *scrollView = new BScrollView("scrollview",fListView, B_FOLLOW_ALL, 0,true,true);
64 | top->AddChild(scrollView);
65 |
66 | // A BListView's selection message is sent to the window any time that the list's selection
67 | // changes.
68 | fListView->SetSelectionMessage(new BMessage(M_SET_TITLE));
69 |
70 | fListView->AddItem(new BStringItem("Toe Wrestling"));
71 | fListView->AddItem(new BStringItem("Electric Toilet Racing"));
72 | fListView->AddItem(new BStringItem("Bog Snorkeling"));
73 | fListView->AddItem(new BStringItem("Chess Boxing"));
74 | fListView->AddItem(new BStringItem("Cheese Rolling"));
75 | fListView->AddItem(new BStringItem("Unicycle Polo"));
76 | }
77 |
78 |
79 | void
80 | MainWindow::MessageReceived(BMessage *msg)
81 | {
82 | switch (msg->what)
83 | {
84 | case M_RESET_WINDOW:
85 | {
86 | fListView->DeselectAll();
87 | break;
88 | }
89 | case M_SET_TITLE:
90 | {
91 | int32 selection = fListView->CurrentSelection();
92 |
93 | if (selection < 0)
94 | {
95 | // This code is here because when we press the Reset button, the selection
96 | // changes and an M_SET_TITLE message is sent, but because nothing is
97 | // selected, CurrentSelection() returns -1.
98 | SetTitle("The Weird World of Sports");
99 | break;
100 | }
101 |
102 | BStringItem *item = dynamic_cast(fListView->ItemAt(selection));
103 | if (item)
104 | SetTitle(item->Text());
105 | break;
106 | }
107 | default:
108 | {
109 | BWindow::MessageReceived(msg);
110 | break;
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/volume1/Sources/18ListTitle/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | class MainWindow : public BWindow
8 | {
9 | public:
10 | MainWindow(void);
11 | void MessageReceived(BMessage *msg);
12 |
13 | private:
14 | BListView *fListView;
15 | };
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-Emo")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/Emo.pld:
--------------------------------------------------------------------------------
1 | NAME=Emo
2 | TARGETNAME=Emo
3 | PLATFORM=Zeta
4 | GROUP=Source Files
5 | EXPANDGROUP=yes
6 | SOURCEFILE=App.cpp
7 | DEPENDENCY=/BeData/projects/Emo/MainWindow.h
8 | SOURCEFILE=MainWindow.cpp
9 | DEPENDENCY=/BeData/projects/Emo/MainWindow.h
10 | SOURCEFILE=PictureView.cpp
11 | DEPENDENCY=/BeData/projects/Emo/PictureView.h
12 | SOURCEFILE=Resources.rsrc
13 | LOCALINCLUDE=/boot/home/projects/Emo/.
14 | SYSTEMINCLUDE=/boot/develop/headers/be
15 | SYSTEMINCLUDE=/boot/develop/headers/cpp
16 | SYSTEMINCLUDE=/boot/develop/headers/posix
17 | SYSTEMINCLUDE=/boot/home/config/include
18 | LIBRARY=/boot/develop/lib/x86/libroot.so
19 | LIBRARY=/boot/develop/lib/x86/libbe.so
20 | LIBRARY=/boot/develop/lib/x86/libtranslation.so
21 | RUNARGS=
22 | CCDEBUG=no
23 | CCPROFILE=no
24 | CCOPSIZE=no
25 | CCOPLEVEL=0
26 | CCTARGETTYPE=0
27 | CCEXTRA=
28 | LDEXTRA=
29 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | #include
4 | #include
5 |
6 | #include "PictureView.h"
7 |
8 | MainWindow::MainWindow(void)
9 | : BWindow(BRect(300,300,450,450),"Emo",B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
10 | {
11 | // Once again, we will make a background view to make things look nice
12 | BView *top = new BView(Bounds(),"top",B_FOLLOW_ALL,B_WILL_DRAW);
13 | top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
14 | AddChild(top);
15 |
16 | // This is our own BView subclass which draws one of several pictures
17 | PictureView *picview = new PictureView();
18 |
19 | // Note that we have the background view add our picture view as a child.
20 | // Unpredictable drawing results will result when views overlap each other. You
21 | // can also run into problems where a view which is drawn on the screen doesn't
22 | // receive mouse events and other bizarre situations.
23 | top->AddChild(picview);
24 |
25 | // Move our picture view to the center of the window. This code right here is
26 | // very common, so get used to seeing and/or using it.
27 | picview->MoveTo((Bounds().Width() - picview->Bounds().Width()) / 2.0,
28 | (Bounds().Height() - picview->Bounds().Height()) / 2.0);
29 | }
30 |
31 |
32 | // QuitRequested() is a BWindow hook function which is called when the window is asked
33 | // to close. When it returns true, the window is given "permission" to quit and it does.
34 | // If QuitRequested() returns false, the window just keeps on running as if nothing
35 | // happened. Implementing this hook to send a quit message to the global application
36 | // instance is the old way of making an app quit when the main window is closed. It is
37 | // included here because legacy apps do it this way instead of using the
38 | // B_QUIT_ON_WINDOW_CLOSE flag in the constructor. This function also has its uses for
39 | // situations where you need to ask the user "Would you like to save your changes?" and
40 | // giving the user a chance to cancel the window closing altogether.
41 | bool
42 | MainWindow::QuitRequested(void)
43 | {
44 | be_app->PostMessage(B_QUIT_REQUESTED);
45 | return true;
46 | }
47 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | class MainWindow : public BWindow
7 | {
8 | public:
9 | MainWindow(void);
10 | bool QuitRequested(void);
11 | };
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/PictureView.cpp:
--------------------------------------------------------------------------------
1 | #include "PictureView.h"
2 | #include
3 | #include
4 |
5 | // This class is our own special control. It loads five images from the application
6 | // resources and places them in an array. Once loaded, it resizes itself to exactly
7 | // fit the first bitmap. Since they are all the same size, this assumption is OK.
8 | PictureView::PictureView(void)
9 | : BView(BRect(0,0,100,100), "picview", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW),
10 | fBitmapIndex(0)
11 | {
12 | // Load up all our pictures using a loop. There are 5 different versions of
13 | // BTranslationUtils::GetBitmap. This is one of two which load images from program
14 | // resources.
15 | for (int8 i = 1; i <= 5; i++)
16 | {
17 | BBitmap *smiley = BTranslationUtils::GetBitmap(B_PNG_FORMAT,i);
18 | fBitmaps[i - 1] = (smiley && smiley->IsValid()) ? smiley : NULL;
19 | }
20 |
21 | if (fBitmaps[0] && fBitmaps[0]->IsValid())
22 | ResizeTo(fBitmaps[0]->Bounds().Width(),fBitmaps[0]->Bounds().Height());
23 | }
24 |
25 |
26 | PictureView::~PictureView(void)
27 | {
28 | }
29 |
30 |
31 | // The BView's Draw() function is called whenever it is asked to draw itself
32 | // on the screen. This is one of the few places where its drawing commands can be
33 | // called.
34 | void
35 | PictureView::Draw(BRect rect)
36 | {
37 | // Alpha transparency is ignored in the default drawing mode for performance reasons,
38 | // so we will set the drawing mode to utilizes transparency information.
39 | SetDrawingMode(B_OP_ALPHA);
40 |
41 | // Set the foreground color of the BView to white
42 | SetHighColor(255,255,255);
43 |
44 | // Fill the BView's area with white. Like with most BView drawing commands, the last
45 | // argument is the color to use which defaults to the high color. Other color choices are
46 | // B_SOLID_LOW, which uses the background color, and B_MIXED_COLORS, which mixes the high
47 | // and low colors.
48 | FillRect(Bounds());
49 |
50 | // Draw the current bitmap on the screen
51 | if (fBitmaps[fBitmapIndex])
52 | DrawBitmap(fBitmaps[fBitmapIndex]);
53 |
54 | // Set the foreground color to black
55 | SetHighColor(0,0,0);
56 |
57 | // Draw a black border around the view
58 | StrokeRect(Bounds());
59 | }
60 |
61 |
62 | // Mouse handling is kinda funny. BView has three hook functions for it: MouseDown(), which is
63 | // called whenever the user presses down a mouse button while the pointer is over the view, MouseUp,
64 | // which is called whenever the user releases a mouse button while the pointer is over the view,
65 | // and MouseMoved(), which is called whenever the mouse changes position while over the view. This
66 | // gives you, the developer, a great deal of control over how your view reacts to any kind of mouse
67 | // event.
68 | void
69 | PictureView::MouseUp(BPoint pt)
70 | {
71 | // Go to the next image in the array or loop around to the beginning if at the end.
72 | if (fBitmapIndex == sizeof(*fBitmaps))
73 | fBitmapIndex = 0;
74 | else
75 | fBitmapIndex++;
76 |
77 | // Force a redraw of the entire view because we've changed pictures
78 | Invalidate();
79 | }
80 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/PictureView.h:
--------------------------------------------------------------------------------
1 | #ifndef PICTUREVIEW_H
2 | #define PICTUREVIEW_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class PictureView : public BView
10 | {
11 | public:
12 | PictureView(void);
13 | ~PictureView(void);
14 |
15 | void Draw(BRect rect);
16 | void MouseUp(BPoint pt);
17 |
18 | private:
19 | BBitmap *fBitmaps[5];
20 | int8 fBitmapIndex;
21 | };
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/volume1/Sources/19Emo/Resources.rsrc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/19Emo/Resources.rsrc
--------------------------------------------------------------------------------
/volume1/Sources/20ListDir/App.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | // It's better to use constant global integers instead of #defines because constants
8 | // provide strong typing and don't lead to weird errors like #defines can.
9 | const uint16 BYTES_PER_KB = 1024;
10 | const uint32 BYTES_PER_MB = 1048576;
11 | const uint64 BYTES_PER_GB = 1099511627776ULL;
12 |
13 | int ListDirectory(const entry_ref &dirRef);
14 | BString MakeSizeString(const uint64 &size);
15 |
16 |
17 | int
18 | main(int argc, char **argv)
19 | {
20 | // We want to require one argument in addition to the program name when invoked
21 | // from the command line.
22 | if (argc != 2)
23 | {
24 | printf("Usage: listdir \n");
25 | return 0;
26 | }
27 |
28 | // Here we'll do some sanity checks to make sure that the path we were given
29 | // actually exists and it's not a file.
30 |
31 | BEntry entry(argv[1]);
32 | if (!entry.Exists())
33 | {
34 | printf("%s does not exist\n",argv[1]);
35 | return 1;
36 | }
37 |
38 | if (!entry.IsDirectory())
39 | {
40 | printf("%s is not a directory\n",argv[1]);
41 | return 1;
42 | }
43 |
44 | // An entry_ref is a typedef'ed structure which points to a file, directory, or
45 | // symlink on disk. The entry must actually exist, but unlike a BFile or BEntry, it
46 | // doesn't use up a file handle.
47 | entry_ref ref;
48 | entry.GetRef(&ref);
49 | return ListDirectory(ref);
50 | }
51 |
52 |
53 | int
54 | ListDirectory(const entry_ref &dirRef)
55 | {
56 | // This function does all the work of the program
57 |
58 | BDirectory dir(&dirRef);
59 | if (dir.InitCheck() != B_OK)
60 | {
61 | printf("Couldn't read directory %s\n",dirRef.name);
62 | return 1;
63 | }
64 |
65 | // First thing we'll do is quickly scan the directory to find the length of the
66 | // longest entry name. This makes it possible to left justify the file sizes
67 | int32 entryCount = 0;
68 | uint32 maxChars = 0;
69 | entry_ref ref;
70 |
71 | // Calling Rewind() moves the BDirectory's index to the beginning of the list.
72 | dir.Rewind();
73 |
74 | // GetNextRef() will return B_ERROR when the BDirectory has gotten to the end of
75 | // its list of entries.
76 | while (dir.GetNextRef(&ref) == B_OK)
77 | {
78 | if (ref.name)
79 | maxChars = MAX(maxChars,strlen(ref.name));
80 | }
81 | maxChars++;
82 | char padding[maxChars];
83 |
84 | BEntry entry;
85 | dir.Rewind();
86 |
87 | // Here we'll call GetNextEntry() instead of GetNextRef() because a BEntry will
88 | // enable us to get certain information about each entry, such as the entry's size.
89 | // Also, because it inherits from BStatable, we can differentiate between
90 | // directories and files with just one function call.
91 | while (dir.GetNextEntry(&entry) == B_OK)
92 | {
93 | char name[B_FILE_NAME_LENGTH];
94 | entry.GetName(name);
95 |
96 | BString formatString;
97 | formatString << "%s";
98 |
99 | unsigned int length = strlen(name);
100 | if (length < maxChars)
101 | {
102 | uint32 padLength = maxChars - length;
103 | memset(padding, ' ', padLength);
104 | padding[padLength - 1] = '\0';
105 | formatString << padding;
106 | }
107 |
108 | if (entry.IsDirectory())
109 | {
110 | // We'll display the "size" of a directory by listing how many
111 | // entries it contains
112 | BDirectory subdir(&entry);
113 | formatString << "\t" << subdir.CountEntries() << " items";
114 | }
115 | else
116 | {
117 | off_t fileSize;
118 | entry.GetSize(&fileSize);
119 | formatString << "\t" << MakeSizeString(fileSize);
120 | }
121 | formatString << "\n";
122 | printf(formatString.String(),name);
123 | entryCount++;
124 | }
125 | printf("%ld entries\n",entryCount);
126 | return 0;
127 | }
128 |
129 |
130 | BString
131 | MakeSizeString(const uint64 &size)
132 | {
133 | // This function just makes converts the raw byte counts provided by
134 | // BEntry's GetSize() method into something more people-friendly.
135 | BString sizeString;
136 | if (size < BYTES_PER_KB)
137 | sizeString << size << " bytes";
138 | else if (size < BYTES_PER_MB)
139 | sizeString << (float(size) / float(BYTES_PER_KB)) << " KB";
140 | else if (size < BYTES_PER_GB)
141 | sizeString << (float(size) / float(BYTES_PER_MB)) << " MB";
142 | else
143 | sizeString << (float(size) / float(BYTES_PER_GB)) << " GB";
144 | return sizeString;
145 | }
146 |
147 |
--------------------------------------------------------------------------------
/volume1/Sources/20ListDir/ListDir.pld:
--------------------------------------------------------------------------------
1 | NAME=ListDir
2 | TARGETNAME=listdir
3 | PLATFORM=Zeta
4 | GROUP=Source Files
5 | EXPANDGROUP=yes
6 | SOURCEFILE=App.cpp
7 | DEPENDENCY=/BeData/projects/Programming Lessons/ListDir/App.h
8 | LOCALINCLUDE=/boot/home/projects/ListDir/.
9 | SYSTEMINCLUDE=/boot/develop/headers/be
10 | SYSTEMINCLUDE=/boot/develop/headers/cpp
11 | SYSTEMINCLUDE=/boot/develop/headers/posix
12 | SYSTEMINCLUDE=/boot/home/config/include
13 | LIBRARY=/boot/develop/lib/x86/libroot.so
14 | LIBRARY=/boot/develop/lib/x86/libbe.so
15 | RUNARGS=
16 | CCDEBUG=yes
17 | CCPROFILE=no
18 | CCOPSIZE=no
19 | CCOPLEVEL=0
20 | CCTARGETTYPE=0
21 | CCEXTRA=
22 | LDEXTRA=
23 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "FortuneFunctions.h"
9 | #include "MainWindow.h"
10 |
11 | App::App(void)
12 | : BApplication("application/x-vnd.test-HaikuFortune")
13 | {
14 | BPath path;
15 |
16 | // We have to use an #ifdef here because the fortune files under R5
17 | // and Zeta are in the system/etc/ directory, but in Haiku they're
18 | // kept in the system/data directory.
19 | #ifdef __HAIKU__
20 | find_directory(B_SYSTEM_DATA_DIRECTORY,&path);
21 | #else
22 | find_directory(B_BEOS_ETC_DIRECTORY,&path);
23 | #endif
24 |
25 | path.Append("fortunes");
26 | gFortunePath = path.Path();
27 |
28 | // If we want the rand() function to actually be pretty close to random
29 | // we will need to seed the random number generator with the time. If we
30 | // don't, we will get the same "random" numbers each time the program is
31 | // run.
32 | srand(system_time());
33 |
34 | MainWindow *win = new MainWindow();
35 | win->Show();
36 | }
37 |
38 |
39 | int
40 | main(void)
41 | {
42 | srand(system_time());
43 |
44 | App *app = new App();
45 | app->Run();
46 | delete app;
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/FortuneFunctions.cpp:
--------------------------------------------------------------------------------
1 | #include "FortuneFunctions.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | // Initialize the global path to a hardcoded value just in case.
14 | // This happens to be different under Haiku than under previous versions
15 | // of BeOS
16 | BString gFortunePath = "/boot/system/data/fortunes";
17 |
18 |
19 | FortuneAccess::FortuneAccess(void)
20 | {
21 | }
22 |
23 |
24 | FortuneAccess::FortuneAccess(const char *folder)
25 | {
26 | SetFolder(folder);
27 | }
28 |
29 |
30 | FortuneAccess::~FortuneAccess(void)
31 | {
32 | // We have to call MakeEmpty because the BList class
33 | // does not delete any items that it contains
34 | MakeEmpty();
35 | }
36 |
37 |
38 | status_t
39 | FortuneAccess::SetFolder(const char *folder)
40 | {
41 | if (!folder)
42 | return B_BAD_VALUE;
43 |
44 | fPath = folder;
45 | ScanFolder();
46 |
47 | return B_OK;
48 | }
49 |
50 |
51 | status_t
52 | FortuneAccess::GetFortune(BString &target)
53 | {
54 | // Here's the meat of this class:
55 | if (fPath.CountChars() == 0)
56 | return B_NO_INIT;
57 |
58 | if (fRefList.CountItems() < 1)
59 | return B_ERROR;
60 |
61 | int32 index = int32(float(rand()) / RAND_MAX * fRefList.CountItems());
62 |
63 | entry_ref *ref = static_cast(fRefList.ItemAt(index));
64 |
65 | BFile file(ref,B_READ_ONLY);
66 | if (file.InitCheck() != B_OK)
67 | return file.InitCheck();
68 |
69 | fLastFile = ref->name;
70 |
71 | off_t size;
72 | file.GetSize(&size);
73 |
74 | if (size < 1)
75 | return B_ERROR;
76 |
77 | BString data;
78 | char *buffer = data.LockBuffer(size + 10);
79 | file.Read(buffer, size);
80 | data.UnlockBuffer();
81 | buffer = NULL;
82 |
83 | // We can't depend on a .dat file, so calculate the number of entries manually
84 | int32 entrycount = 0;
85 | int32 entrystart = 0;
86 | do
87 | {
88 | entrystart = data.FindFirst("%\n", entrystart + 1);
89 | entrycount++;
90 | } while (entrystart > 0);
91 |
92 | int32 entry = int32(float(rand()) / RAND_MAX * (entrycount - 1));
93 |
94 | entrystart = 0;
95 | for (int32 i = 0; i < entry; i++)
96 | entrystart = data.FindFirst("%\n",entrystart + 1);
97 |
98 | BString entrydata;
99 | entrydata = data.String() + entrystart + 2;
100 | int32 entrylength = entrydata.FindFirst("%\n");
101 | if (entrylength > 0)
102 | entrydata.Truncate(entrylength);
103 |
104 | target = entrydata;
105 | return B_OK;
106 | }
107 |
108 |
109 | void
110 | FortuneAccess::ScanFolder(void)
111 | {
112 | // Scan the directory that the object was set to and create a list of all
113 | // of the names of the files in the directory.
114 | BDirectory dir(fPath.String());
115 | if (dir.InitCheck() != B_OK)
116 | return;
117 |
118 | MakeEmpty();
119 | entry_ref ref;
120 | while (dir.GetNextRef(&ref) == B_OK)
121 | {
122 | BEntry entry(&ref);
123 | if (entry.IsFile())
124 | fRefList.AddItem(new entry_ref(ref));
125 | }
126 | }
127 |
128 |
129 | void
130 | FortuneAccess::MakeEmpty(void)
131 | {
132 | // This method is needed because BList doesn't free the memory of the items
133 | // that it holds.
134 | for (int32 i = 0; i < fRefList.CountItems(); i++)
135 | {
136 | entry_ref *ref = (entry_ref*)fRefList.ItemAt(i);
137 | delete ref;
138 | }
139 | fRefList.MakeEmpty();
140 | }
141 |
142 |
143 | int32
144 | FortuneAccess::CountFiles(void) const
145 | {
146 | return fRefList.CountItems();
147 | }
148 |
149 |
150 | status_t
151 | FortuneAccess::LastFilename(BString &target)
152 | {
153 | // This function exists so that outside code can find out the name of the file
154 | // the most recent fortune came from.
155 | if (fPath.CountChars() == 0)
156 | return B_NO_INIT;
157 |
158 | target = fLastFile;
159 |
160 | return B_OK;
161 | }
162 |
163 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/FortuneFunctions.h:
--------------------------------------------------------------------------------
1 | #ifndef FORTUNEFUNCTIONS_H
2 | #define FORTUNEFUNCTIONS_H
3 |
4 | #include
5 | #include
6 |
7 | extern BString gFortunePath;
8 |
9 | class FortuneAccess
10 | {
11 | public:
12 | FortuneAccess(void);
13 | FortuneAccess(const char *folder);
14 | ~FortuneAccess(void);
15 |
16 | status_t SetFolder(const char *folder);
17 | status_t GetFortune(BString &target);
18 | int32 CountFiles(void) const;
19 | status_t LastFilename(BString &target);
20 |
21 | private:
22 | void ScanFolder(void);
23 | void MakeEmpty(void);
24 |
25 | BString fPath,
26 | fLastFile;
27 | BList fRefList;
28 | };
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/HaikuFortune.pld:
--------------------------------------------------------------------------------
1 | NAME=HaikuFortune
2 | TARGETNAME=HaikuFortune
3 | PLATFORM=Zeta
4 | GROUP=Fortuna
5 | EXPANDGROUP=yes
6 | SOURCEFILE=App.cpp
7 | DEPENDENCY=/BeData/projects/Programming Lessons/HaikuFortune/App.h|/BeData/projects/Programming Lessons/HaikuFortune/FortuneFunctions.h|/BeData/projects/Programming Lessons/HaikuFortune/MainWindow.h
8 | SOURCEFILE=FortuneFunctions.cpp
9 | DEPENDENCY=/boot/home/Desktop/Fortuna/FortuneFunctions.h
10 | SOURCEFILE=MainWindow.cpp
11 | DEPENDENCY=/BeData/projects/Programming Lessons/HaikuFortune/MainWindow.cpp|/BeData/projects/Programming Lessons/HaikuFortune/MainWindow.h|/BeData/projects/Programming Lessons/HaikuFortune/FortuneFunctions.h
12 | SOURCEFILE=Resources.rsrc
13 | LOCALINCLUDE=/boot/home/projects/Fortuna/.
14 | SYSTEMINCLUDE=/boot/develop/headers/be
15 | SYSTEMINCLUDE=/boot/develop/headers/cpp
16 | SYSTEMINCLUDE=/boot/develop/headers/posix
17 | SYSTEMINCLUDE=/boot/home/config/include
18 | LIBRARY=/boot/develop/lib/x86/libroot.so
19 | LIBRARY=/boot/develop/lib/x86/libbe.so
20 | RUNARGS=
21 | CCDEBUG=no
22 | CCPROFILE=no
23 | CCOPSIZE=no
24 | CCOPLEVEL=0
25 | CCTARGETTYPE=0
26 | CCEXTRA=
27 | LDEXTRA=
28 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/HaikuFortune.rsrc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/22HaikuFortune/HaikuFortune.rsrc
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/HaikuFortune16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/22HaikuFortune/HaikuFortune16.png
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/HaikuFortune32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/22HaikuFortune/HaikuFortune32.png
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | enum
11 | {
12 | M_GET_ANOTHER_FORTUNE = 'gafn',
13 | M_ABOUT_REQUESTED = 'abrq'
14 | };
15 |
16 |
17 | MainWindow::MainWindow(void)
18 | : BWindow(BRect(0,0,300,300), "HaikuFortune", B_DOCUMENT_WINDOW,
19 | B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
20 | fFortune(gFortunePath.String())
21 | {
22 | // Create all of the controls for our window.
23 | BView *back = new BView(Bounds(), "background", B_FOLLOW_ALL, B_WILL_DRAW);
24 | back->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
25 | AddChild(back);
26 |
27 | BButton *close = new BButton(BRect(0,0,1,1), "closebutton", "Close",
28 | new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
29 | close->ResizeToPreferred();
30 | close->MoveTo(Bounds().right - 15 - close->Frame().Width(),
31 | Bounds().bottom - 15 - close->Frame().Height());
32 | back->AddChild(close);
33 | close->MakeDefault(true);
34 |
35 | BButton *next = new BButton(BRect(0,0,1,1), "nextbutton", "Get Another",
36 | new BMessage(M_GET_ANOTHER_FORTUNE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
37 | next->ResizeToPreferred();
38 | next->MoveTo(close->Frame().left - 15 - next->Frame().Width(),
39 | Bounds().bottom - 15 - next->Frame().Height());
40 | back->AddChild(next);
41 |
42 | BButton *about = new BButton(BRect(0,0,1,1), "aboutbutton", "About…",
43 | new BMessage(M_ABOUT_REQUESTED), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
44 | about->ResizeToPreferred();
45 | about->MoveTo(next->Frame().left - 15 - about->Frame().Width(),
46 | Bounds().bottom - 15 - about->Frame().Height());
47 | back->AddChild(about);
48 |
49 |
50 | BRect r(15,15,Bounds().right - B_V_SCROLL_BAR_WIDTH - 15, next->Frame().top - 15);
51 | fTextView = new BTextView(r, "textview", r.OffsetToCopy(0,0).InsetByCopy(10,10), B_FOLLOW_ALL,
52 | B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS);
53 | fTextView->MakeEditable(false);
54 |
55 | // BScrollViews are a little weird. You can't create one without having created its target.
56 | // It also automatically calls AddChild() to attach its target to itself, so all that is
57 | // necessary is to instantiate it and attach it to the window. It's not even necessary (or
58 | // possible) to specify the size of the BScrollView because it calculates its size based
59 | // on that of its target.
60 | BScrollView *sv = new BScrollView("scrollview", fTextView, B_FOLLOW_ALL, 0, false, true);
61 | back->AddChild(sv);
62 |
63 | BString fortune;
64 | status_t status = fFortune.GetFortune(fortune);
65 | if (status == B_OK)
66 | {
67 | BString title;
68 | title.Prepend("Fortune: ");
69 | SetTitle(title.String());
70 |
71 | fTextView->SetText(fortune.String());
72 | }
73 | else
74 | {
75 | fTextView->SetText("HaikuFortune had a problem getting a fortune.\n\n"
76 | "Please make sure that you have installed fortune files to "
77 | "the folder ");
78 | fTextView->Insert(gFortunePath.String());
79 | }
80 |
81 | // This line is for working around a problem in Zeta. BButton::MakeDefault doesn't
82 | // do anything except change the focus. The idea is to be able to press Enter to close
83 | // HaikuFortune and the space bar to get another fortune. Zeta doesn't let us do this, so
84 | // we'll leave focus on the Close button.
85 | if (B_BEOS_VERSION <= B_BEOS_VERSION_5)
86 | next->MakeFocus(true);
87 |
88 | // Calculate a good width for the window and center it
89 | SetSizeLimits(45 + close->Bounds().Width() + next->Bounds().Width(), 30000, 200, 30000) ;
90 | r = BScreen().Frame();
91 | MoveTo((r.Width()-Bounds().Width()) / 2.0, r.Height() / 4.0);
92 | }
93 |
94 |
95 | void
96 | MainWindow::MessageReceived(BMessage *msg)
97 | {
98 | switch (msg->what)
99 | {
100 | case M_GET_ANOTHER_FORTUNE:
101 | {
102 | BString fortune;
103 | status_t status = fFortune.GetFortune(fortune);
104 | if (status == B_OK)
105 | {
106 | BString title;
107 | fFortune.LastFilename(title);
108 | title.Prepend("Fortune: ");
109 | SetTitle(title.String());
110 |
111 | fTextView->SetText(fortune.String());
112 | }
113 | else
114 | {
115 | fTextView->SetText("HaikuFortune had a problem getting a fortune.\n\n"
116 | "Please make sure that you have installed fortune files to "
117 | "the folder ");
118 | fTextView->Insert(gFortunePath.String());
119 | }
120 | break;
121 | }
122 | case M_ABOUT_REQUESTED:
123 | {
124 | // Using a BAlert for the About window is a common occurrence. They take
125 | // care of all of the layout, so all that needs done is write the text that
126 | // goes in the alert.
127 | BAlert *alert = new BAlert("HaikuFortune",
128 | "A graphical fortune program for Haiku.\n\n",
129 | "OK");
130 | alert->Go();
131 | break;
132 | }
133 | default:
134 | {
135 | BWindow::MessageReceived(msg);
136 | break;
137 | }
138 | }
139 | }
140 |
141 |
142 | void
143 | MainWindow::FrameResized(float w, float h)
144 | {
145 | // The BWindow::FrameResized() method is called whenever the window is resized.
146 | // In this case, we change the size of the text rectangle in the text view used
147 | // for the fortune. We have to do this because it won't do it itself. Lazy.
148 | BRect textrect = fTextView->TextRect();
149 |
150 | textrect.right = textrect.left + (w - B_V_SCROLL_BAR_WIDTH - 40);
151 | fTextView->SetTextRect(textrect);
152 | }
153 |
154 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include "FortuneFunctions.h"
7 |
8 | class MainWindow : public BWindow
9 | {
10 | public:
11 | MainWindow(void);
12 | void MessageReceived(BMessage *msg);
13 | void FrameResized(float w, float h);
14 |
15 | private:
16 | BTextView *fTextView;
17 | FortuneAccess fFortune;
18 | };
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/volume1/Sources/22HaikuFortune/Resources.rsrc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/22HaikuFortune/Resources.rsrc
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-DropMe")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/DropMe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/Sources/DropMe/DropMe
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/DropMe.pld:
--------------------------------------------------------------------------------
1 | NAME=DropMe
2 | TARGETNAME=DropMe
3 | GROUP=Source Files
4 | EXPANDGROUP=yes
5 | SOURCEFILE=App.cpp
6 | DEPENDENCY=/boot/home/projects/DropMe/App.cpp| /boot/home/projects/DropMe/App.h| /boot/home/projects/DropMe/MainWindow.
7 | SOURCEFILE=DropView.cpp
8 | DEPENDENCY=/boot/home/projects/DropMe/DropView.cpp| /boot/home/projects/DropMe/DropView.
9 | SOURCEFILE=MainWindow.cpp
10 | DEPENDENCY=/boot/home/projects/DropMe/MainWindow.cpp| /boot/home/projects/DropMe/MainWindow.h| /boot/home/projects/DropMe/DropView.
11 | LOCALINCLUDE=/boot/home/projects/DropMe/.
12 | SYSTEMINCLUDE=/boot/develop/headers/be
13 | SYSTEMINCLUDE=/boot/develop/headers/cpp
14 | SYSTEMINCLUDE=/boot/develop/headers/posix
15 | SYSTEMINCLUDE=/boot/home/config/include
16 | LIBRARY=/boot/develop/lib/x86/libroot.so
17 | LIBRARY=/boot/develop/lib/x86/libbe.so
18 | LIBRARY=/boot/system/lib/libsupc++.so
19 | RUNARGS=
20 | CCDEBUG=no
21 | CCPROFILE=no
22 | CCOPSIZE=no
23 | CCOPLEVEL=0
24 | CCTARGETTYPE=0
25 | CCEXTRA=
26 | LDEXTRA=
27 |
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/DropView.cpp:
--------------------------------------------------------------------------------
1 | #include "DropView.h"
2 |
3 | // This header is needed for the definition of the entry_ref structure
4 | #include
5 |
6 | // This is for the methods we need to work with BMessages in MessageReceived
7 | #include
8 |
9 |
10 | DropView::DropView(const BRect &frame)
11 | : BView(frame, "dropview", B_FOLLOW_ALL, B_WILL_DRAW)
12 | {
13 | SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
14 |
15 | // Once again, create a label, this time to display the file's name
16 | fLabel = new BStringView(BRect(10,10,11,11),"label","Drag a file here");
17 | fLabel->ResizeToPreferred();
18 | AddChild(fLabel);
19 | }
20 |
21 |
22 | void
23 | DropView::MessageReceived(BMessage *msg)
24 | {
25 | switch (msg->what)
26 | {
27 | case B_SIMPLE_DATA:
28 | {
29 | // This message is the constant give to us whenever something is dropped
30 | // on a view from Tracker.
31 |
32 | // An entry_ref is a lightweight structure that identifies a file on disk
33 | // A file dropped on our BView will generate a message with the identifier
34 | // B_SIMPLE_DATA and attached data. The attached data takes the form of a
35 | // series of entry_refs with the field name "refs"
36 | entry_ref ref;
37 |
38 | // If FindRef is successful, the information about the file dropped on the
39 | // view will be copied into ref.
40 | if (msg->FindRef("refs",&ref) == B_OK)
41 | {
42 | // Most of the information in an entry_ref isn't very useful, but the
43 | // name property contains the file's name or NULL if the entry_ref is
44 | // empty
45 | fLabel->SetText(ref.name);
46 | }
47 | break;
48 | }
49 | default:
50 | {
51 | BView::MessageReceived(msg);
52 | break;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/DropView.h:
--------------------------------------------------------------------------------
1 | #ifndef DROPVIEW_H
2 | #define DROPVIEW_H
3 |
4 | #include
5 | #include
6 |
7 | class DropView : public BView
8 | {
9 | public:
10 | DropView(const BRect &frame);
11 | void MessageReceived(BMessage *msg);
12 |
13 | private:
14 | BStringView *fLabel;
15 | };
16 |
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | #include
4 |
5 | #include "DropView.h"
6 |
7 | MainWindow::MainWindow(void)
8 | : BWindow(BRect(100,100,400,300),"DropMe",B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS |
9 | B_QUIT_ON_WINDOW_CLOSE)
10 | {
11 | DropView *view = new DropView(Bounds());
12 | AddChild(view);
13 | }
14 |
15 |
16 | void
17 | MainWindow::MessageReceived(BMessage *msg)
18 | {
19 | switch (msg->what)
20 | {
21 | default:
22 | {
23 | BWindow::MessageReceived(msg);
24 | break;
25 | }
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/volume1/Sources/DropMe/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | class MainWindow : public BWindow
7 | {
8 | public:
9 | MainWindow(void);
10 | void MessageReceived(BMessage *msg);
11 |
12 | private:
13 | };
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/volume1/chapters/conclusions.Md:
--------------------------------------------------------------------------------
1 | # Where to Go from Here
2 |
3 | We have covered an enormous amount of information since Lesson 1. Amazingly, there is still a lot of ground to go if you would like to go beyond being a beginner. The best way to improve is to write code and keep learning as you go. What you know now will give you the ability to write a many different kinds of programs for Haiku and will also give you the tools to learn the rest of the Haiku API and other aspects of programming in C++. Here are some topics that you are encouraged to explore:
4 |
5 | ## C++
6 |
7 | - Exceptions
8 | - Templates and the Standard Template Library
9 | - Multiple Inheritance
10 |
11 | ## Usability
12 |
13 | - *The Design of Everyday Things*, Donald Norman
14 | - *The Humane Interface*, Jef Raskin
15 |
16 | ## Good Programming
17 |
18 | - *Design Patterns: Elements of Reusable Object-Oriented Software*, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
19 |
20 | ## Programming for BeOS / Haiku
21 |
22 | - *Programming the Be Operating System*, Dan Parks Sydow. This is out-of-print but is available from O'Reilly's website as a free PDF.
23 | - The BeOS sample code projects and accompanying articles
24 | - *The Be Book*. This is the authoritative manual on the BeOS / Haiku API.
25 |
--------------------------------------------------------------------------------
/volume1/chapters/disclaimer.Md:
--------------------------------------------------------------------------------
1 | # Disclaimer {.unnumbered}
2 |
3 | **Original title: Learning to Program with Haiku**
4 |
5 | *Copyright © 2010 by Jon Yoder*
6 |
7 | ### Notice of liability {.unnumbered}
8 |
9 | Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an "as is" basis. The author and Lulu.com shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
10 |
11 | ### Trademarks {.unnumbered}
12 |
13 | Haiku and the Haiku logo are trademarks of Haiku, Inc. Be, BeOS, and the Be and BeOS logos are registered trademarks of Be Incorporated in the United States of America and other countries. All other products and company names mentioned in this book may be trademarks of their respective owners. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
14 |
15 | ### License {.unnumbered}
16 |
17 | This work is licensed under the
18 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
19 |
20 | To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
21 |
22 | 
23 |
24 | ISBN: 978-0-557-53969-7
25 |
--------------------------------------------------------------------------------
/volume1/images/cc-by-nc-sa.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/images/cc-by-nc-sa.png
--------------------------------------------------------------------------------
/volume1/images/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/images/cover.png
--------------------------------------------------------------------------------
/volume1/images/filetypes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/images/filetypes.png
--------------------------------------------------------------------------------
/volume1/images/myfirstappshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/images/myfirstappshot.png
--------------------------------------------------------------------------------
/volume1/images/paladin2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/images/paladin2.png
--------------------------------------------------------------------------------
/volume1/images/quickres.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume1/images/quickres.png
--------------------------------------------------------------------------------
/volume1/metadata.yml:
--------------------------------------------------------------------------------
1 | ---
2 | title: Programming with Haiku
3 | subtitle: The Basics
4 | author: Jon Yoder
5 | rights: Creative Commons Attribution 4.0 International
6 | language: en-US
7 | abstract: |
8 | This beginning programming guide takes the reader from know next to nothing
9 | about developing applications for the Haiku operating system to knowing the
10 | basics and having the skills to go beyond the fundamentals. It begins with
11 | a traditional "Hello, world! approach, moves through C programming, and
12 | expands into C++ and programming graphical applications for Haiku.
13 | Instead of attempting to be an exhaustive C/C++ programming book using Haiku,
14 | it focuses on application development using the C++ language.
15 | The Haiku operating system is a great platform for aspiring developers.
16 | Those who have struggled with learning application development under Linux,
17 | Microsoft Windows, or Macintosh will find writing programs under Haiku to be
18 | sensible and easy. The free Paladin integrated development environment for
19 | Haiku is used for examples in the book.
20 | pandoc-latex-environment:
21 | noteblock: [note]
22 | tipblock: [tip]
23 | warningblock: [warning]
24 | cautionblock: [caution]
25 | importantblock: [important]
26 | questionblock: [question]
27 | errorblock: [error]
28 | shellerrorblock: [shellerror]
29 | assignmentblock: [assignment]
30 | toughblock: [tough]
31 | bughuntblock: [bughunt]
32 | bugwarningblock: [bugwarning]
33 | ...
34 |
--------------------------------------------------------------------------------
/volume2/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY = docbooks clean
2 |
3 | BUILD = build
4 | MAKEFILE = Makefile
5 | OUTPUT_FILENAME = Jon_Yoder_-_Programming_with_Haiku_Volume_2
6 |
7 | INCLUDE_DIR = ../include
8 | IMAGES_DIR = images
9 | IMAGES = $(IMAGES_DIR)/*
10 | COVER_IMAGE = $(IMAGES_DIR)/cover.png
11 |
12 | METADATA = metadata.yml
13 | TOC = --toc --toc-depth=2 -V toc-title='Table of contents' -V toc-own-page:true
14 | CSS_FILE = $(INCLUDE_DIR)/css/style.css
15 | CSS_ARG = --css=$(CSS_FILE)
16 | METADATA_ARG = --metadata-file=$(METADATA)
17 | MATH_FORMULAS = --webtex
18 |
19 | PDF_ENGINE=xelatex
20 | ARGS = $(MATH_FORMULAS) $(CSS_ARG) $(METADATA_ARG)
21 |
22 | MARKDOWN_FORMAT = markdown-pipe_tables+backtick_code_blocks+fancy_lists+table_captions+smart+fenced_divs
23 |
24 | CHAPTERS_DIR = ./chapters
25 | CHAPTERS := disclaimer.Md lesson01.Md
26 |
27 | CHAPTERS_TARGETS = $(addprefix $(CHAPTERS_DIR)/,$(CHAPTERS))
28 |
29 | all: book
30 |
31 | book: epub html pdf mobi
32 |
33 | clean:
34 | rm -rf $(BUILD)
35 |
36 | markdown: $(BUILD)/markdown/$(OUTPUT_FILENAME).Md
37 |
38 | mobi: $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi
39 |
40 | epub: $(BUILD)/epub/$(OUTPUT_FILENAME).epub
41 |
42 | html: $(BUILD)/html/$(OUTPUT_FILENAME).html.tar.gz
43 |
44 | pdf: $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf
45 |
46 | png: pdf
47 | mkdir -p $(BUILD)/png
48 | pdftoppm -png -r 42 -aa yes $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf $(BUILD)/png/$(OUTPUT_FILENAME)
49 |
50 | $(BUILD)/markdown/$(OUTPUT_FILENAME).Md: $(CHAPTERS_TARGETS)
51 | mkdir -p $(BUILD)/markdown
52 | mdmerge $(CHAPTERS_TARGETS) -o $(BUILD)/markdown/$(OUTPUT_FILENAME).Md
53 |
54 | $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi: epub
55 | mkdir -p $(BUILD)/mobi
56 | ebook-convert $(BUILD)/epub/$(OUTPUT_FILENAME).epub $(BUILD)/mobi/$(OUTPUT_FILENAME).mobi
57 |
58 | $(BUILD)/epub/$(OUTPUT_FILENAME).epub: $(MAKEFILE) $(METADATA) $(CHAPTERS_TARGETS) $(CSS_FILE) $(IMAGES) \
59 | $(COVER_IMAGE)
60 | mkdir -p $(BUILD)/epub
61 | pandoc $(ARGS) --epub-cover-image=$(COVER_IMAGE) -f $(MARKDOWN_FORMAT) -t epub -o $@ -s $(CHAPTERS_TARGETS)
62 |
63 | $(BUILD)/html/$(OUTPUT_FILENAME).html.tar.gz : $(MAKEFILE) $(METADATA) $(CHAPTERS_TARGETS) $(CSS_FILE) $(IMAGES)
64 | mkdir -p $(BUILD)/html_tmp
65 | mkdir -p $(BUILD)/html
66 | pandoc $(ARGS) --standalone --to=html5 -o $(BUILD)/html_tmp/$(OUTPUT_FILENAME).html $(CHAPTERS_TARGETS)
67 | cp -R $(IMAGES_DIR)/ $(BUILD)/html_tmp/$(IMAGES_DIR)/
68 | tar -zcvf $(BUILD)/html/$(OUTPUT_FILENAME).html.tar.gz -C $(BUILD)/html_tmp .
69 | rm -r $(BUILD)/html_tmp
70 |
71 | $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf: $(CHAPTERS_TARGETS) $(CSS_FILE)
72 | mkdir -p $(BUILD)/markdown
73 | mkdir -p $(BUILD)/pdf
74 | pandoc $(ARGS) \
75 | $(TOC) \
76 | --template=$(INCLUDE_DIR)/pandoc/eisvogel.latex \
77 | --metadata=abstract:" " \
78 | -V geometry:a4paper -V geometry:"left=2.54cm,right=2.54cm,top=1.91cm,bottom=1.91cm" \
79 | -V titlepage:true -V titlepage-color:"FFFFFF" -V titlepage-rule-height:0 -V titlepage-rule-color:"d8dbdc" \
80 | -V titlepage-background:$(COVER_IMAGE) \
81 | -V title:"" -V subtitle:"" -V author:"" \
82 | -V header-left:"Programming with Haiku" -V header-right:"Volume 2" \
83 | -V footer-left:"Jon Yoder" \
84 | -V links-as-notes:true \
85 | -V lot:true \
86 | -V footnotes-pretty:true \
87 | --listing -V listings-disable-line-numbers:true \
88 | -V book:true --top-level-division=chapter \
89 | --pdf-engine=$(PDF_ENGINE) \
90 | --include-in-header $(INCLUDE_DIR)/latex/preamble.tex \
91 | --include-before-body $(INCLUDE_DIR)/latex/before_body.tex \
92 | --include-after-body $(INCLUDE_DIR)/latex/after_body.tex \
93 | --filter pandoc-latex-environment \
94 | --number-offset=1 \
95 | -f $(MARKDOWN_FORMAT) \
96 | -s $(CHAPTERS_TARGETS) \
97 | -o $@
98 |
99 | %.xml : %.adoc
100 | asciidoctor -v -d book -b docbook -s $< -o $@
101 |
102 | $(CHAPTERS_DIR)/%.Md : %.xml
103 | mkdir -p $(CHAPTERS_DIR)
104 | pandoc --highlight-style=pygments --wrap=none -f docbook -t $(MARKDOWN_FORMAT) --shift-heading-level-by=1 $< -o $@
105 |
106 |
--------------------------------------------------------------------------------
/volume2/Programming with Haiku -- GDB.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku -- GDB.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 1.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 1.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 10.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 10.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 11.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 11.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 12.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 12.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 13.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 13.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 14.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 14.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 15.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 15.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 16.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 16.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 17.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 17.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 18.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 18.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 19.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 19.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 2.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 2.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 20.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 20.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 21.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 21.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 22.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 22.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 23.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 23.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 24.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 24.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 25.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 25.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 26.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 26.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 27 (unfinished).odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 27 (unfinished).odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 28 (unfinished).odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 28 (unfinished).odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 3.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 3.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 4.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 4.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 5.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 5.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 6.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 6.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 7.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 7.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 8.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 8.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Lesson 9.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Lesson 9.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Unit 1 Review.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Unit 1 Review.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Unit 2 Review.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Unit 2 Review.odt
--------------------------------------------------------------------------------
/volume2/Programming with Haiku Unit 3 Review.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Programming with Haiku Unit 3 Review.odt
--------------------------------------------------------------------------------
/volume2/Sources/AutoTextControl.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | AutoTextControl.cpp: A BTextControl which notifies on each keypress
3 | Written by DarkWyrm , Copyright 2007
4 | Released under the MIT license.
5 | */
6 | #include "AutoTextControl.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | static property_info sProperties[] = {
14 | { "CharacterLimit", { B_GET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 },
15 | "Returns the maximum number of characters that the AutoTextControl will allow.",
16 | 0, { B_INT32_TYPE }
17 | },
18 |
19 | { "CharacterLimit", { B_SET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0},
20 | "Sets the maximum number of characters that the AutoTextControl will allow.",
21 | 0, { B_INT32_TYPE }
22 | },
23 | };
24 |
25 | AutoTextControl::AutoTextControl(const BRect &frame, const char *name, const char *label,
26 | const char *text, BMessage *msg, uint32 resize, uint32 flags)
27 | : BTextControl(frame,name,label,text,msg,resize,flags),
28 | fFilter(NULL),
29 | fCharLimit(0)
30 | {
31 | SetFilter(new AutoTextControlFilter(this));
32 | }
33 |
34 |
35 | AutoTextControl::~AutoTextControl(void)
36 | {
37 | if (Window())
38 | Window()->RemoveCommonFilter(fFilter);
39 |
40 | delete fFilter;
41 | }
42 |
43 |
44 | AutoTextControl::AutoTextControl(BMessage *data)
45 | : BTextControl(data)
46 | {
47 | if (data->FindInt32("_charlimit",(int32*)&fCharLimit) != B_OK)
48 | fCharLimit = 0;
49 | }
50 |
51 |
52 | BArchivable *
53 | AutoTextControl::Instantiate(BMessage *data)
54 | {
55 | if (validate_instantiation(data, "AutoTextControl"))
56 | return new AutoTextControl(data);
57 |
58 | return NULL;
59 | }
60 |
61 |
62 | status_t
63 | AutoTextControl::Archive(BMessage *data, bool deep) const
64 | {
65 | status_t status = BTextControl::Archive(data,deep);
66 |
67 | if (status == B_OK)
68 | status = data->AddInt32("_charlimit",fCharLimit);
69 |
70 | if (status == B_OK)
71 | status = data->AddString("class","AutoTextControl");
72 |
73 | return status;
74 | }
75 |
76 |
77 | status_t
78 | AutoTextControl::GetSupportedSuites(BMessage *msg)
79 | {
80 | msg->AddString("suites","suite/vnd.DW-autotextcontrol");
81 |
82 | BPropertyInfo prop_info(sProperties);
83 | msg->AddFlat("messages",&prop_info);
84 | return BTextControl::GetSupportedSuites(msg);
85 | }
86 |
87 |
88 | BHandler *
89 | AutoTextControl::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
90 | int32 form, const char *property)
91 | {
92 | return BControl::ResolveSpecifier(msg, index, specifier, form, property);
93 | }
94 |
95 |
96 | void
97 | AutoTextControl::AttachedToWindow(void)
98 | {
99 | BTextControl::AttachedToWindow();
100 | if (fFilter)
101 | Window()->AddCommonFilter(fFilter);
102 | }
103 |
104 |
105 | void
106 | AutoTextControl::DetachedFromWindow(void)
107 | {
108 | if (fFilter)
109 | Window()->RemoveCommonFilter(fFilter);
110 | BTextControl::DetachedFromWindow();
111 | }
112 |
113 |
114 | void
115 | AutoTextControl::SetCharacterLimit(const uint32 &limit)
116 | {
117 | fCharLimit = limit;
118 | }
119 |
120 |
121 | uint32
122 | AutoTextControl::GetCharacterLimit(const uint32 &limit)
123 | {
124 | return fCharLimit;
125 | }
126 |
127 |
128 | void
129 | AutoTextControl::AllowCharacters(const char *string)
130 | {
131 | uint32 i = 0;
132 | while (string[i])
133 | TextView()->AllowChar(string[i++]);
134 | }
135 |
136 |
137 | void
138 | AutoTextControl::DisallowCharacters(const char *string)
139 | {
140 | uint32 i = 0;
141 | while (string[i])
142 | TextView()->DisallowChar(string[i++]);
143 | }
144 |
145 |
146 | void
147 | AutoTextControl::SetFilter(AutoTextControlFilter *filter)
148 | {
149 | if (fFilter) {
150 | if (Window())
151 | Window()->RemoveCommonFilter(fFilter);
152 | delete fFilter;
153 | }
154 |
155 | fFilter = filter;
156 | if (Window())
157 | Window()->AddCommonFilter(fFilter);
158 | }
159 |
160 | AutoTextControlFilter::AutoTextControlFilter(AutoTextControl *box)
161 | : BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE,B_KEY_DOWN),
162 | fBox(box),
163 | fCurrentMessage(NULL)
164 | {
165 | }
166 |
167 |
168 | AutoTextControlFilter::~AutoTextControlFilter(void)
169 | {
170 | }
171 |
172 |
173 | filter_result
174 | AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
175 | {
176 | int32 rawchar,mod;
177 | msg->FindInt32("raw_char",&rawchar);
178 | msg->FindInt32("modifiers",&mod);
179 |
180 | BView *view = dynamic_cast(*target);
181 | if (!view || strcmp("_input_",view->Name()) != 0)
182 | return B_DISPATCH_MESSAGE;
183 |
184 | AutoTextControl *text = dynamic_cast(view->Parent());
185 | if (!text || text != fBox)
186 | return B_DISPATCH_MESSAGE;
187 |
188 | fCurrentMessage = msg;
189 | filter_result result = KeyFilter(rawchar,mod);
190 | fCurrentMessage = NULL;
191 |
192 | if (fBox->fCharLimit && result == B_DISPATCH_MESSAGE) {
193 | // See to it that we still allow shortcut keys
194 | if (mod & B_COMMAND_KEY)
195 | return B_DISPATCH_MESSAGE;
196 |
197 | // We don't use strlen() because it is not UTF-8 aware, which can affect
198 | // how many characters can be typed.
199 | if (isprint(rawchar) &&
200 | (uint32)BString(text->Text()).CountChars() == text->fCharLimit)
201 | return B_SKIP_MESSAGE;
202 | }
203 |
204 | return result;
205 | }
206 |
207 |
208 | filter_result
209 | AutoTextControlFilter::KeyFilter(const int32 &rawchar, const int32 &mod)
210 | {
211 | if (fBox)
212 | fBox->Invoke();
213 |
214 | return B_DISPATCH_MESSAGE;
215 | }
216 |
217 |
--------------------------------------------------------------------------------
/volume2/Sources/AutoTextControl.h:
--------------------------------------------------------------------------------
1 | /*
2 | AutoTextControl.h: A BTextControl which notifies on each keypress
3 | Written by DarkWyrm , Copyright 2007
4 | Released under the MIT license.
5 | */
6 | #ifndef AUTO_TEXT_CONTROL_H
7 | #define AUTO_TEXT_CONTROL_H
8 |
9 | #include
10 | #include
11 |
12 | class AutoTextControlFilter;
13 |
14 | /*
15 | The AutoTextControl provides realtime updates to any changes made to it.
16 | It also provides the ability to limit the text to a certain number of
17 | characters.
18 |
19 | If, for some reason, you want to disable the updates-per-keypress, pass
20 | a regular BMessageFilter to the SetFilter method.
21 | */
22 |
23 | class AutoTextControl : public BTextControl
24 | {
25 | public:
26 | AutoTextControl(const BRect &frame, const char *name,
27 | const char *label, const char *text,
28 | BMessage *msg,
29 | uint32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
30 | uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
31 |
32 | AutoTextControl(BMessage *data);
33 | static BArchivable * Instantiate(BMessage *data);
34 | virtual status_t Archive(BMessage *data, bool deep = true) const;
35 |
36 | virtual status_t GetSupportedSuites(BMessage *msg);
37 | virtual BHandler * ResolveSpecifier(BMessage *msg, int32 index,
38 | BMessage *specifier, int32 form,
39 | const char *property);
40 |
41 | virtual ~AutoTextControl(void);
42 |
43 | virtual void AttachedToWindow(void);
44 | virtual void DetachedFromWindow(void);
45 |
46 | void SetFilter(AutoTextControlFilter *filter);
47 | AutoTextControlFilter * GetFilter(void) { return fFilter; }
48 |
49 | void SetCharacterLimit(const uint32 &limit);
50 | uint32 GetCharacterLimit(const uint32 &limit);
51 |
52 | void AllowCharacters(const char *string);
53 | void DisallowCharacters(const char *string);
54 | private:
55 | friend class AutoTextControlFilter;
56 |
57 | AutoTextControlFilter *fFilter;
58 | uint32 fCharLimit;
59 | };
60 |
61 | /*
62 | This class does all of the heavy lifting for AutoTextControl's realtime
63 | updates.
64 |
65 | You can further customize input and updates by subclassing the
66 | KeyFilter hook function. When doing so, the current key message can
67 | be accessed by way of GetCurrentMessage(). However, it will return NULL
68 | when called from any other method.
69 | */
70 | class AutoTextControlFilter : public BMessageFilter
71 | {
72 | public:
73 | AutoTextControlFilter(AutoTextControl *checkview);
74 | ~AutoTextControlFilter(void);
75 | virtual filter_result Filter(BMessage *msg, BHandler **target);
76 | virtual filter_result KeyFilter(const int32 &key, const int32 &mod);
77 |
78 | AutoTextControl * TextControl(void) const { return fBox; }
79 | BMessage * GetCurrentMessage(void) { return fCurrentMessage; }
80 | private:
81 | AutoTextControl *fBox;
82 | BMessage *fCurrentMessage;
83 | };
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/volume2/Sources/BQuery Example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int
8 | main(void)
9 | {
10 | // Get a BVolume object which represents the boot volume. A BQuery
11 | // object will require one.
12 | BVolumeRoster volRoster;
13 | BVolume bootVolume;
14 | volRoster.GetBootVolume(&bootVolume);
15 |
16 | // A quick summary for using BQuery:
17 | // 1) Make the BQuery object.
18 | // 2) Set the target volume with SetVolume().
19 | // 3) Specify the search terms with SetPredicate().
20 | // 4) Call Fetch() to start the search
21 | // 5) Iterate over the results list using GetNextEntry(),
22 | // GetNextRef(), or GetNextDirents().
23 |
24 | BString predicate("MAIL:subject == *");
25 | BQuery query;
26 | query.SetVolume(&bootVolume);
27 | query.SetPredicate(predicate.String());
28 | if (query.Fetch() == B_OK)
29 | {
30 | printf("Results of query \"%s\":\n");
31 | entry_ref ref;
32 | while (query.GetNextRef(&ref) == B_OK)
33 | printf("\t%s\n",ref.name);
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/volume2/Sources/ColorWell - Draft.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2007, Haiku. All rights reserved.
3 | * Distributed under the terms of the MIT License.
4 | *
5 | * Authors:
6 | * DarkWyrm (darkwyrm@gmail.com)
7 | */
8 | #ifndef COLOR_WELL_H_
9 | #define COLOR_WELL_H_
10 |
11 | #include
12 |
13 | enum
14 | {
15 | COLORWELL_SQUARE_WELL,
16 | COLORWELL_ROUND_WELL,
17 | };
18 |
19 | class ColorWell : public BControl
20 | {
21 | public:
22 | ColorWell(BRect frame, const char *name,
23 | BMessage *msg,
24 | int32 resize = B_FOLLOW_LEFT |
25 | B_FOLLOW_TOP,
26 | int32 flags = B_WILL_DRAW,
27 | int32 style = COLORWELL_SQUARE_WELL);
28 | ColorWell(BMessage *data);
29 | ~ColorWell(void);
30 |
31 | static BArchivable * Instantiate(BMessage *data);
32 | virtual status_t Archive(BMessage *data, bool deep = true) const;
33 |
34 | virtual status_t GetSupportedSuites(BMessage *msg);
35 | virtual BHandler * ResolveSpecifier(BMessage *msg, int32 index,
36 | BMessage *specifier, int32 form,
37 | const char *property);
38 |
39 | virtual void SetValue(int32 value);
40 | virtual void SetValue(const rgb_color &color);
41 | virtual void SetValue(const uint8 &r, const uint8 &g,
42 | const uint8 &b);
43 | rgb_color ValueAsColor(void) const;
44 |
45 | virtual void SetStyle(const int32 &style);
46 | int32 Style(void) const;
47 |
48 | virtual void MessageReceived(BMessage *msg);
49 | virtual void Draw(BRect update);
50 |
51 | private:
52 | void DrawRound(void);
53 | void DrawSquare(void);
54 |
55 | rgb_color fDisabledColor,
56 | fColor;
57 |
58 | int32 fStyle;
59 | };
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/volume2/Sources/ColorWell - L17.cpp:
--------------------------------------------------------------------------------
1 | #include "ColorWell.h"
2 |
3 | ColorWell::ColorWell(BRect frame, const char *name, BMessage *message,
4 | int32 resize, int32 flags, int32 style)
5 | : BControl(frame,name,NULL,message, resize, flags)
6 | {
7 | SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
8 | SetLowColor(0,0,0);
9 |
10 | fColor.red = 0;
11 | fColor.green = 0;
12 | fColor.blue = 0;
13 | fColor.alpha = 255;
14 |
15 | fDisabledColor.red = 190;
16 | fDisabledColor.green = 190;
17 | fDisabledColor.blue = 190;
18 | fDisabledColor.alpha = 255;
19 | }
20 |
21 |
22 | ColorWell::~ColorWell(void)
23 | {
24 | }
25 |
26 |
27 | void
28 | ColorWell::SetValue(int32 value)
29 | {
30 | BControl::SetValue(value);
31 |
32 | fColor.red = (value & 0xFF000000) >> 24;
33 | fColor.green = (value & 0x00FF0000) >> 16;
34 | fColor.blue = (value & 0x0000FF00) >> 8;
35 | fColor.alpha = 255;
36 |
37 | SetHighColor(fColor);
38 | Draw(Bounds());
39 | Invalidate();
40 | }
41 |
42 |
43 | void
44 | ColorWell::SetValue(const rgb_color &col)
45 | {
46 | fColor = col;
47 | fColor.alpha = 255;
48 | fColor.alpha = 255;
49 |
50 | SetHighColor(col);
51 | Draw(Bounds());
52 | Invalidate();
53 | }
54 |
55 |
56 | void
57 | ColorWell::SetValue(const uint8 &r,const uint8 &g, const uint8 &b)
58 | {
59 | fColor.red = r;
60 | fColor.green = g;
61 | fColor.blue = b;
62 |
63 | SetHighColor(r,g,b);
64 | Draw(Bounds());
65 | Invoke();
66 | }
67 |
68 |
69 | void
70 | ColorWell::SetStyle(const int32 &style)
71 | {
72 | if (style != fStyle) {
73 | fStyle = style;
74 | Invalidate();
75 | }
76 | }
77 |
78 |
79 | int32
80 | ColorWell::Style(void) const
81 | {
82 | return fStyle;
83 | }
84 |
85 |
86 | void
87 | ColorWell::Draw(BRect update)
88 | {
89 | if (fStyle == COLORWELL_SQUARE_WELL)
90 | DrawSquare();
91 | else
92 | DrawRound();
93 | }
94 |
95 |
96 | rgb_color
97 | ColorWell::ValueAsColor(void) const
98 | {
99 | return fColor;
100 | }
101 |
102 |
103 | void
104 | ColorWell::DrawRound(void)
105 | {
106 | BRect r(Bounds().InsetByCopy(1,1));
107 |
108 | if (IsEnabled())
109 | {
110 | SetHighColor(fColor);
111 | FillEllipse(Bounds());
112 |
113 | SetHighColor(0,0,0);
114 | StrokeEllipse(Bounds());
115 |
116 | }
117 | else
118 | {
119 | SetHighColor(fDisabledColor);
120 | FillEllipse(Bounds());
121 |
122 | SetHighColor(160,160,160);
123 | StrokeEllipse(Bounds());
124 | }
125 | }
126 |
127 |
128 | void
129 | ColorWell::DrawSquare(void)
130 | {
131 | BRect r(Bounds());
132 |
133 | if (IsEnabled())
134 | {
135 | SetHighColor(fColor);
136 | FillRect(Bounds());
137 |
138 | SetHighColor(0,0,0);
139 | StrokeRect(Bounds());
140 |
141 | }
142 | else
143 | {
144 | SetHighColor(fDisabledColor);
145 | FillRect(Bounds());
146 |
147 | SetHighColor(160,160,160);
148 | StrokeRect(Bounds());
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/volume2/Sources/ColorWell - L17.h:
--------------------------------------------------------------------------------
1 | #ifndef COLOR_WELL_H
2 | #define COLOR_WELL_H
3 |
4 | #include
5 |
6 | enum
7 | {
8 | COLORWELL_SQUARE_WELL,
9 | COLORWELL_ROUND_WELL,
10 | };
11 |
12 | class ColorWell : public BControl
13 | {
14 | public:
15 | ColorWell(BRect frame, const char *name,
16 | BMessage *msg,
17 | int32 resize = B_FOLLOW_LEFT |
18 | B_FOLLOW_TOP,
19 | int32 flags = B_WILL_DRAW,
20 | int32 style = COLORWELL_SQUARE_WELL);
21 | ~ColorWell(void);
22 |
23 | virtual void SetValue(int32 value);
24 | virtual void SetValue(const rgb_color &color);
25 | virtual void SetValue(const uint8 &r, const uint8 &g,
26 | const uint8 &b);
27 | rgb_color ValueAsColor(void) const;
28 |
29 | virtual void SetStyle(const int32 &style);
30 | int32 Style(void) const;
31 |
32 | virtual void Draw(BRect update);
33 |
34 | private:
35 | void DrawRound(void);
36 | void DrawSquare(void);
37 |
38 | rgb_color fDisabledColor,
39 | fColor;
40 |
41 | int32 fStyle;
42 | };
43 |
44 | #endif
45 |
46 |
--------------------------------------------------------------------------------
/volume2/Sources/ColorWell - L19.h:
--------------------------------------------------------------------------------
1 | #ifndef COLORWELL_H
2 | #define COLORWELL_H
3 |
4 | #include
5 |
6 | enum
7 | {
8 | COLORWELL_SQUARE_WELL,
9 | COLORWELL_ROUND_WELL,
10 | };
11 |
12 | class ColorWell : public BControl
13 | {
14 | public:
15 | ColorWell(BRect frame, const char *name,
16 | BMessage *msg,
17 | int32 resize = B_FOLLOW_LEFT |
18 | B_FOLLOW_TOP,
19 | int32 flags = B_WILL_DRAW,
20 | int32 style = COLORWELL_SQUARE_WELL);
21 | ColorWell(BMessage *data);
22 | ~ColorWell(void);
23 |
24 | virtual status_t GetSupportedSuites(BMessage *msg);
25 | virtual BHandler * ResolveSpecifier(BMessage *msg, int32 index,
26 | BMessage *specifier, int32 form,
27 | const char *property);
28 |
29 | virtual void SetValue(int32 value);
30 | virtual void SetValue(const rgb_color &color);
31 | virtual void SetValue(const uint8 &r, const uint8 &g,
32 | const uint8 &b);
33 | rgb_color ValueAsColor(void) const;
34 |
35 | virtual void SetStyle(const int32 &style);
36 | int32 Style(void) const;
37 |
38 | virtual void MessageReceived(BMessage *msg);
39 | virtual void Draw(BRect update);
40 |
41 | private:
42 | void DrawRound(void);
43 | void DrawSquare(void);
44 |
45 | rgb_color fDisabledColor,
46 | fColor;
47 |
48 | int32 fStyle;
49 | };
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/volume2/Sources/ColorWell - L20.h:
--------------------------------------------------------------------------------
1 | #ifndef COLORWELL_H
2 | #define COLORWELL_H
3 |
4 | #include
5 |
6 | enum
7 | {
8 | COLORWELL_SQUARE_WELL,
9 | COLORWELL_ROUND_WELL,
10 | };
11 |
12 | class ColorWell : public BControl
13 | {
14 | public:
15 | ColorWell(BRect frame, const char *name,
16 | BMessage *msg,
17 | int32 resize = B_FOLLOW_LEFT |
18 | B_FOLLOW_TOP,
19 | int32 flags = B_WILL_DRAW,
20 | int32 style = COLORWELL_SQUARE_WELL);
21 | ColorWell(BMessage *data);
22 | ~ColorWell(void);
23 |
24 | virtual status_t GetSupportedSuites(BMessage *msg);
25 | virtual BHandler * ResolveSpecifier(BMessage *msg, int32 index,
26 | BMessage *specifier, int32 form,
27 | const char *property);
28 |
29 | virtual void SetValue(int32 value);
30 | virtual void SetValue(const rgb_color &color);
31 | virtual void SetValue(const uint8 &r, const uint8 &g,
32 | const uint8 &b);
33 | rgb_color ValueAsColor(void) const;
34 |
35 | virtual void SetStyle(const int32 &style);
36 | int32 Style(void) const;
37 |
38 | virtual void MouseDown(BPoint pt);
39 | virtual void MessageReceived(BMessage *msg);
40 | virtual void Draw(BRect update);
41 |
42 | private:
43 | void DrawRound(void);
44 | void DrawSquare(void);
45 |
46 | rgb_color fDisabledColor,
47 | fColor;
48 |
49 | int32 fStyle;
50 | };
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/volume2/Sources/DragView.cpp:
--------------------------------------------------------------------------------
1 | #include "DragView.h"
2 |
3 | enum
4 | {
5 | M_DRAG = 'drag'
6 | };
7 |
8 |
9 | DragView::DragView(BRect frame)
10 | : BView(frame, "dragview", B_FOLLOW_LEFT | B_FOLLOW_TOP,
11 | B_WILL_DRAW),
12 | fDragRect(10, 10, 50, 50)
13 | {
14 | }
15 |
16 |
17 | void
18 | DragView::MouseDown(BPoint pt)
19 | {
20 | // For our example, we only support dragging with the left button
21 | BPoint temp;
22 | uint32 buttons;
23 | GetMouse(&temp, &buttons);
24 |
25 | if (fDragRect.Contains(temp))
26 | {
27 | // SetMouseEventMask can only be called from within
28 | // MouseDown(). It forces all mouse events to be sent to this
29 | // view until the button is released. This saves us from having
30 | // to manually code the mouse tracking.
31 | SetMouseEventMask(B_POINTER_EVENTS, 0);
32 |
33 | BMessage dragMsg(M_DRAG);
34 | dragMsg.AddInt32("buttons", buttons);
35 | DragMessage(&dragMsg, fDragRect);
36 |
37 | // If you allocate the drag message on the heap, make sure
38 | // you delete it after DragMessage() returns. If you use a
39 | // BBitmap version of DrawMessage(), DON'T delete the bitmap
40 | // after calling DragMessage() because the system will do
41 | // that for you.
42 | }
43 |
44 | }
45 |
46 |
47 | void
48 | DragView::Draw(BRect update)
49 | {
50 | SetHighColor(0, 0, 160);
51 | FillRect(fDragRect);
52 |
53 | DrawString("Try dragging the square", BPoint(fDragRect.left,
54 | fDragRect.bottom + 50));
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/volume2/Sources/DragView.h:
--------------------------------------------------------------------------------
1 | #ifndef DRAGVIEW_H
2 | #define DRAGVIEW_H
3 |
4 | #include
5 |
6 | class DragView : public BView
7 | {
8 | public:
9 | DragView(BRect frame);
10 | void MouseDown(BPoint pt);
11 | void Draw(BRect update);
12 |
13 | private:
14 | BRect fDragRect;
15 | };
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.test-FontDemo1")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/FontDemo1.pld:
--------------------------------------------------------------------------------
1 | NAME=FontDemo1
2 | TARGETNAME=FontDemo1
3 | PLATFORM=Haiku
4 | SCM=none
5 | GROUP=Source Files
6 | EXPANDGROUP=yes
7 | SOURCEFILE=App.cpp
8 | DEPENDENCY=/boot/home/Desktop/BookSources/FontDemo1/App.h|/boot/home/Desktop/BookSources/FontDemo1/MainWindow.h
9 | SOURCEFILE=MainView.cpp
10 | DEPENDENCY=/boot/home/Desktop/BookSources/FontDemo1/MainView.h
11 | SOURCEFILE=MainWindow.cpp
12 | DEPENDENCY=/boot/home/Desktop/BookSources/FontDemo1/MainWindow.h|/boot/home/Desktop/BookSources/FontDemo1/MainView.h
13 | SYSTEMINCLUDE=/boot/develop/headers/be
14 | SYSTEMINCLUDE=/boot/develop/headers/cpp
15 | SYSTEMINCLUDE=/boot/develop/headers/posix
16 | SYSTEMINCLUDE=/boot/home/config/include
17 | LIBRARY=/boot/develop/lib/x86/libroot.so
18 | LIBRARY=/boot/develop/lib/x86/libbe.so
19 | RUNARGS=
20 | CCDEBUG=no
21 | CCPROFILE=no
22 | CCOPSIZE=no
23 | CCOPLEVEL=0
24 | CCTARGETTYPE=0
25 | CCEXTRA=
26 | LDEXTRA=
27 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/MainView.cpp:
--------------------------------------------------------------------------------
1 | #include "MainView.h"
2 |
3 | MainView::MainView(const BRect &frame)
4 | : BView(frame, "textview", B_FOLLOW_ALL, B_WILL_DRAW)
5 | {
6 | }
7 |
8 |
9 | void
10 | MainView::Draw(BRect update)
11 | {
12 | // The Draw hook function is called whenever a BView is asked to redraw
13 | // itself on the screen. We will just write some code to draw some text.
14 | BFont font;
15 | font.SetSize(18.0);
16 |
17 | // Just setting values to our font object isn't enough. We have to assign
18 | // the BView's font settings to the values kept in our font object.
19 | SetFont(&font);
20 |
21 | // DrawString uses the BView's current font settings, draw mode, and
22 | // color to draw the text. Note that the point specified is the left
23 | // end of the baseline, so calculating where to draw text can be a
24 | // little backwards when compared to drawing anything else.
25 | DrawString("This is some text", BPoint(50,50));
26 | }
27 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/MainView.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINVIEW_H
2 | #define MAINVIEW_H
3 |
4 | #include
5 |
6 | class MainView : public BView
7 | {
8 | public:
9 | MainView(const BRect &frame);
10 | void Draw(BRect update);
11 | };
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/MainWindow.cpp:
--------------------------------------------------------------------------------
1 | #include "MainWindow.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "MainView.h"
8 |
9 | MainWindow::MainWindow(void)
10 | : BWindow(BRect(100,100,500,400),"Font Demo #1",B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
11 | {
12 | BRect r(Bounds());
13 | r.bottom = 20;
14 | fMenuBar = new BMenuBar(r,"menubar");
15 | AddChild(fMenuBar);
16 |
17 | r = Bounds();
18 | r.top = 20;
19 | MainView *view = new MainView(r);
20 | AddChild(view);
21 | }
22 |
23 |
24 | void
25 | MainWindow::MessageReceived(BMessage *msg)
26 | {
27 | switch (msg->what)
28 | {
29 | default:
30 | {
31 | BWindow::MessageReceived(msg);
32 | break;
33 | }
34 | }
35 | }
36 |
37 |
38 | bool
39 | MainWindow::QuitRequested(void)
40 | {
41 | be_app->PostMessage(B_QUIT_REQUESTED);
42 | return true;
43 | }
44 |
--------------------------------------------------------------------------------
/volume2/Sources/FontDemo/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | class MainWindow : public BWindow
8 | {
9 | public:
10 | MainWindow(void);
11 | void MessageReceived(BMessage *msg);
12 | bool QuitRequested(void);
13 |
14 | private:
15 | BMenuBar *fMenuBar;
16 | };
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/volume2/Sources/GetEmailName.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | BString
6 | GetEmailName(const char *path)
7 | {
8 | BString out;
9 | BNode node(path);
10 | if (node.InitCheck() != B_OK)
11 | return out;
12 |
13 | // This is to make sure that the attribute exists and what
14 | // its size is.
15 | attr_info attrInfo;
16 | if (node.GetAttrInfo("META:name", &attrInfo) != B_OK)
17 | return out;
18 |
19 | // BString::LockBuffer() and UnlockBuffer() allow us to have
20 | // direct access to the internal character buffer that the BString
21 | // uses. LockBuffer() takes one parameter which is the maximum
22 | // size that the character buffer needs to be.
23 | char *nameBuffer = out.LockBuffer(attrInfo.size + 1);
24 | node.ReadAttr("META:name", attrInfo.type, 0, nameBuffer,
25 | attrInfo.size);
26 | nameBuffer[attrInfo.size] = '\0';
27 | out.UnlockBuffer();
28 |
29 | return out;
30 | }
31 |
32 | int
33 | main(void)
34 | {
35 | }
36 |
--------------------------------------------------------------------------------
/volume2/Sources/LibWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBWINDOW_H
2 | #define LIBWINDOW_H
3 |
4 | #include "DWindow.h"
5 | #include
6 |
7 | class Project;
8 |
9 | #define M_LIBWIN_CLOSED 'lwcl'
10 |
11 | class LibraryWindow : public DWindow
12 | {
13 | public:
14 | LibraryWindow(BRect frame, const BMessenger &parent,
15 | Project *project);
16 | ~LibraryWindow(void);
17 | bool QuitRequested(void);
18 | void MessageReceived(BMessage *msg);
19 |
20 | private:
21 | BView * AddHeader(BPoint location, const char *label);
22 | BRect ScanFolder(BPoint location, const char *dir, float *maxwidth);
23 | static int32 ScanThread(void *data);
24 |
25 | BView *fCheckList;
26 |
27 | BMessenger fParent;
28 | Project *fProject;
29 | BList fSystemLibs,
30 | fUserLibs;
31 | thread_id fScanThread;
32 | };
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/volume2/Sources/Push BQuery Example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | int
9 | main(void)
10 | {
11 | // Get a BVolume object which represents the boot volume. A BQuery
12 | // object will require one.
13 | BVolumeRoster volRoster;
14 | BVolume bootVolume;
15 | volRoster.GetBootVolume(&bootVolume);
16 |
17 | // A quick summary for using BQuery:
18 | // 1) Make the BQuery object.
19 | // 2) Set the target volume with SetVolume().
20 | // 3) Specify the search terms with SetPredicate().
21 | // 4) Call Fetch() to start the search
22 | // 5) Iterate over the results list using GetNextEntry(),
23 | // GetNextRef(), or GetNextDirents().
24 |
25 | BString predicate("MAIL:subject == *");
26 | BQuery query;
27 | query.SetVolume(&bootVolume);
28 | query.PushAttr("MAIL:subject");
29 | query.PushString("*");
30 | query.PushOp(B_EQ);
31 | if (query.Fetch() == B_OK)
32 | {
33 | printf("Results of query \"%s\":\n", predicate.String());
34 | entry_ref ref;
35 | while (query.GetNextRef(&ref) == B_OK)
36 | printf("\t%s\n",ref.name);
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L22/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-QuickEdit")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L22/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L22/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | class MainWindow : public BWindow
13 | {
14 | public:
15 | MainWindow(void);
16 | ~MainWindow(void);
17 |
18 | void MessageReceived(BMessage *msg);
19 | bool QuitRequested(void);
20 |
21 | void OpenFile(const entry_ref &ref);
22 | void SaveFile(const char *path);
23 |
24 | void FrameResized(float w, float h);
25 | private:
26 | void UpdateTextRect(void);
27 |
28 | BMenuBar *fMenuBar;
29 | BTextView *fTextView;
30 | BFilePanel *fOpenPanel,
31 | *fSavePanel;
32 |
33 | BString fFilePath;
34 | };
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L22/QuickEdit L22.pld:
--------------------------------------------------------------------------------
1 | NAME=QuickEdit L22
2 | TARGETNAME=QuickEdit
3 | PLATFORM=HaikuGCC4
4 | SCM=none
5 | GROUP=Source Files
6 | EXPANDGROUP=yes
7 | SOURCEFILE=App.cpp
8 | DEPENDENCY=/boot/home/projects/PrintWorld/App.h|/boot/home/projects/PrintWorld/MainWindow.h
9 | SOURCEFILE=MainWindow.cpp
10 | DEPENDENCY=/boot/home/projects/PrintWorld/MainWindow.h|/boot/home/projects/PrintWorld/MainView.h
11 | SOURCEFILE=Resources.rsrc
12 | SYSTEMINCLUDE=/boot/develop/headers/be
13 | SYSTEMINCLUDE=/boot/develop/headers/cpp
14 | SYSTEMINCLUDE=/boot/develop/headers/posix
15 | SYSTEMINCLUDE=/boot/home/config/include
16 | LIBRARY=/boot/develop/lib/x86/libroot.so
17 | LIBRARY=/boot/develop/lib/x86/libbe.so
18 | LIBRARY=/boot/develop/lib/x86/libsupc++.so
19 | LIBRARY=/boot/system/lib/libsupc++.so
20 | LIBRARY=/boot/develop/lib/x86/libtranslation.so
21 | LIBRARY=/boot/develop/lib/x86/libtracker.so
22 | RUNARGS=
23 | CCDEBUG=no
24 | CCPROFILE=no
25 | CCOPSIZE=no
26 | CCOPLEVEL=0
27 | CCTARGETTYPE=0
28 | CCEXTRA=
29 | LDEXTRA=
30 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L22/QuickEdit.pld:
--------------------------------------------------------------------------------
1 | NAME=QuickEdit
2 | TARGETNAME=QuickEdit
3 | PLATFORM=HaikuGCC4
4 | SCM=hg
5 | GROUP=Source Files
6 | EXPANDGROUP=yes
7 | SOURCEFILE=App.cpp
8 | DEPENDENCY=/boot/home/projects/PrintWorld/App.h|/boot/home/projects/PrintWorld/MainWindow.h
9 | SOURCEFILE=EditView.cpp
10 | DEPENDENCY=/boot/home/projects/QuickEdit/EditView.h
11 | SOURCEFILE=MainWindow.cpp
12 | DEPENDENCY=/boot/home/projects/PrintWorld/MainWindow.h|/boot/home/projects/PrintWorld/MainView.h
13 | SOURCEFILE=Resources.rsrc
14 | SYSTEMINCLUDE=/boot/develop/headers/be
15 | SYSTEMINCLUDE=/boot/develop/headers/cpp
16 | SYSTEMINCLUDE=/boot/develop/headers/posix
17 | SYSTEMINCLUDE=/boot/home/config/include
18 | LIBRARY=/boot/develop/lib/x86/libroot.so
19 | LIBRARY=/boot/develop/lib/x86/libbe.so
20 | LIBRARY=/boot/develop/lib/x86/libsupc++.so
21 | LIBRARY=/boot/system/lib/libsupc++.so
22 | LIBRARY=/boot/develop/lib/x86/libtranslation.so
23 | LIBRARY=/boot/develop/lib/x86/libtracker.so
24 | RUNARGS=
25 | CCDEBUG=no
26 | CCPROFILE=no
27 | CCOPSIZE=no
28 | CCOPLEVEL=0
29 | CCTARGETTYPE=0
30 | CCEXTRA=
31 | LDEXTRA=
32 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L22/Resources.rsrc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Sources/QuickEdit - L22/Resources.rsrc
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/App.cpp:
--------------------------------------------------------------------------------
1 | #include "App.h"
2 | #include "MainWindow.h"
3 |
4 |
5 | App::App(void)
6 | : BApplication("application/x-vnd.dw-QuickEdit")
7 | {
8 | MainWindow *mainwin = new MainWindow();
9 | mainwin->Show();
10 | }
11 |
12 |
13 | int
14 | main(void)
15 | {
16 | App *app = new App();
17 | app->Run();
18 | delete app;
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/App.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 |
6 | class App : public BApplication
7 | {
8 | public:
9 | App(void);
10 | };
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/EditView.cpp:
--------------------------------------------------------------------------------
1 | #include "EditView.h"
2 |
3 | EditView::EditView(const BRect &frame, const char *name, const int32 &resize)
4 | : BTextView(frame, name, frame, resize),
5 | fNotifyChanges(true)
6 | {
7 | SetFlags(Flags() | B_FRAME_EVENTS);
8 | UpdateTextRect();
9 |
10 | SetMessage(new BMessage(M_TEXT_CHANGED));
11 | }
12 |
13 |
14 | void
15 | EditView::FrameResized(float w, float h)
16 | {
17 | UpdateTextRect();
18 | }
19 |
20 |
21 | void
22 | EditView::UpdateTextRect(void)
23 | {
24 | BRect r(Bounds());
25 | r.InsetBy(5, 5);
26 |
27 | SetTextRect(r);
28 | }
29 |
30 |
31 | void
32 | EditView::InsertText(const char *inText, int32 inLength, int32 inOffset,
33 | const text_run_array *inRuns)
34 | {
35 | BTextView::InsertText(inText, inLength, inOffset, inRuns);
36 |
37 | if (IsNotifyingChanges())
38 | Invoke();
39 | }
40 |
41 |
42 | void
43 | EditView::DeleteText(int32 fromOffset, int32 toOffset)
44 | {
45 | BTextView::DeleteText(fromOffset, toOffset);
46 |
47 | if (IsNotifyingChanges())
48 | Invoke();
49 | }
50 |
51 |
52 | void
53 | EditView::SetChangeNotifications(bool value)
54 | {
55 | fNotifyChanges = value;
56 | }
57 |
58 |
59 | bool
60 | EditView::IsNotifyingChanges(void) const
61 | {
62 | return fNotifyChanges;
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/EditView.h:
--------------------------------------------------------------------------------
1 | #ifndef EDITVIEW_H
2 | #define EDITVIEW_H
3 |
4 | #include
5 | #include
6 |
7 | enum
8 | {
9 | M_TEXT_CHANGED = 'txch'
10 | };
11 |
12 | class EditView : public BTextView, public BInvoker
13 | {
14 | public:
15 | EditView(const BRect &frame, const char *name,
16 | const int32 &resize);
17 |
18 | void FrameResized(float w, float h);
19 |
20 | virtual void InsertText(const char *inText, int32 inLength,
21 | int32 inOffset,
22 | const text_run_array *inRuns);
23 |
24 | virtual void DeleteText(int32 fromOffset, int32 toOffset);
25 |
26 | void SetChangeNotifications(bool value);
27 | bool IsNotifyingChanges(void) const;
28 | private:
29 | void UpdateTextRect(void);
30 |
31 | bool fNotifyChanges;
32 | };
33 |
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | class EditView;
12 |
13 | class MainWindow : public BWindow
14 | {
15 | public:
16 | MainWindow(void);
17 | ~MainWindow(void);
18 |
19 | void MessageReceived(BMessage *msg);
20 | bool QuitRequested(void);
21 |
22 | void OpenFile(const entry_ref &ref);
23 | void SaveFile(const char *path);
24 |
25 | private:
26 | bool AlertChanges(void);
27 | void DoPageSetup(void);
28 | void DoPrint(void);
29 |
30 | BMenuBar *fMenuBar;
31 | EditView *fTextView;
32 | BFilePanel *fOpenPanel,
33 | *fSavePanel;
34 |
35 | BMessage *fPageSetup;
36 |
37 | BString fFilePath;
38 | bool fChanged;
39 | bool fQuitAfterSave;
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/QuickEdit.pld:
--------------------------------------------------------------------------------
1 | NAME=QuickEdit
2 | TARGETNAME=QuickEdit
3 | PLATFORM=HaikuGCC4
4 | SCM=hg
5 | GROUP=Source Files
6 | EXPANDGROUP=yes
7 | SOURCEFILE=App.cpp
8 | DEPENDENCY=/boot/home/projects/PrintWorld/App.h|/boot/home/projects/PrintWorld/MainWindow.h
9 | SOURCEFILE=EditView.cpp
10 | DEPENDENCY=/boot/home/projects/QuickEdit/EditView.h
11 | SOURCEFILE=MainWindow.cpp
12 | DEPENDENCY=/boot/home/projects/PrintWorld/MainWindow.h|/boot/home/projects/PrintWorld/MainView.h
13 | SOURCEFILE=Resources.rsrc
14 | SYSTEMINCLUDE=/boot/develop/headers/be
15 | SYSTEMINCLUDE=/boot/develop/headers/cpp
16 | SYSTEMINCLUDE=/boot/develop/headers/posix
17 | SYSTEMINCLUDE=/boot/home/config/include
18 | LIBRARY=/boot/develop/lib/x86/libroot.so
19 | LIBRARY=/boot/develop/lib/x86/libbe.so
20 | LIBRARY=/boot/develop/lib/x86/libsupc++.so
21 | LIBRARY=/boot/system/lib/libsupc++.so
22 | LIBRARY=/boot/develop/lib/x86/libtranslation.so
23 | LIBRARY=/boot/develop/lib/x86/libtracker.so
24 | RUNARGS=
25 | CCDEBUG=no
26 | CCPROFILE=no
27 | CCOPSIZE=no
28 | CCOPLEVEL=0
29 | CCTARGETTYPE=0
30 | CCEXTRA=
31 | LDEXTRA=
32 |
--------------------------------------------------------------------------------
/volume2/Sources/QuickEdit - L23/Resources.rsrc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theclue/programming-with-haiku/7117a657d8071ebfb98baf4d9431ec4c108379ae/volume2/Sources/QuickEdit - L23/Resources.rsrc
--------------------------------------------------------------------------------
/volume2/Sources/ReadProject.cpp:
--------------------------------------------------------------------------------
1 | // This is intended to be a cross-platform way of reading Paladin
2 | // projects, so we won't be using the Haiku API. This is strictly
3 | // C++ methods.
4 |
5 | #include
6 | #include
7 | #include
8 | #include